-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.php
75 lines (69 loc) · 2.36 KB
/
build.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
$start_time = microtime(true);
include_once __DIR__.'/functions.php';
// copy the content of the /static/ folder into the output directory
copy_dir(__DIR__.'/static', $output_dir);
// do stuff
$movie_ids = [];
$popular_data = getPopularMovies();
$popular_movies = [
'time' => time(),
'source' => 'https://developers.themoviedb.org/',
'movies' => []
];
foreach($popular_data['results'] as $movie){
if(!in_array($movie['id'], $movie_ids)){ // prevent duplicates
$movie_ids[] = $movie['id'];
$popular_movies['movies'][] = [
'id' => $movie['id'],
'title' => $movie['title'],
'description' => $movie['overview'],
'release_date' => $movie['release_date'],
'popularity' => $movie['popularity'],
'votes' => [
'avg' => $movie['vote_average'],
'count' => $movie['vote_count']
],
'images' => [
'backdrop' => $movie['backdrop_path'],
'poster' => $movie['poster_path']
]
];
}
}
$upcoming_data = getUpcomingMovies();
$upcoming_movies = [
'time' => time(),
'source' => 'https://developers.themoviedb.org/',
'movies' => []
];
foreach($upcoming_data['results'] as $movie){
if(!in_array($movie['id'], $movie_ids)){ // prevent duplicates
$movie_ids[] = $movie['id'];
$upcoming_movies['movies'][] = [
'id' => $movie['id'],
'title' => $movie['title'],
'description' => $movie['overview'],
'release_date' => $movie['release_date'],
'popularity' => $movie['popularity'],
'votes' => [
'avg' => $movie['vote_average'],
'count' => $movie['vote_count']
],
'images' => [
'backdrop' => $movie['backdrop_path'],
'poster' => $movie['poster_path']
]
];
}
}
$html = file_get_contents($output_dir.'/index.html');
$data = addslashes(json_encode($popular_movies));
$html = preg_replace('/{{\s*popular_data\s*}}/', addslashes(json_encode($popular_movies)), $html);
$html = preg_replace('/{{\s*upcoming_data\s*}}/', addslashes(json_encode($upcoming_movies)), $html);
$html = preg_replace('/{{\s*date\s*}}/', date('Y-m-d'), $html); // insert current date
$html = preg_replace('/{{\s*base\s*}}/', $base, $html); // set base URL
saveFile($output_dir.'/index.html', $html);
$time_elapsed = round((microtime(true) - $start_time), 6); // execution time in seconds
echo 'OK - Site built successfully in '.$time_elapsed.'s'.PHP_EOL;
exit;