3 * Take the generated JSON files and convert them to HTML for a browser
5 * @author Christian Weiske <cweiske@cweiske.de>
7 require_once __DIR__ . '/functions.php';
9 $wwwDir = __DIR__ . '/../www/';
10 $discoverDir = __DIR__ . '/../www/api/v1/discover-data/';
11 $wwwDiscoverDir = $wwwDir . 'discover/';
12 $gameDetailsDir = __DIR__ . '/../www/api/v1/details-data/';
13 $wwwGameDir = $wwwDir . 'game/';
15 if (!is_dir($wwwDiscoverDir)) {
16 mkdir($wwwDiscoverDir, 0755);
18 if (!is_dir($wwwGameDir)) {
19 mkdir($wwwGameDir, 0755);
22 foreach (glob($gameDetailsDir . '*.json') as $gameDataFile) {
23 $htmlFile = basename($gameDataFile, '.json') . '.htm';
25 $wwwGameDir . $htmlFile,
26 renderGameFile($gameDataFile)
30 foreach (glob($discoverDir . '*.json') as $discoverFile) {
31 $htmlFile = basename($discoverFile, '.json') . '.htm';
32 if ($htmlFile == 'discover.htm') {
33 $htmlFile = 'index.htm';
36 $wwwDiscoverDir . $htmlFile,
37 renderDiscoverFile($discoverFile)
41 function renderDiscoverFile($discoverFile)
43 $json = json_decode(file_get_contents($discoverFile));
45 $title = $json->title;
47 foreach ($json->rows as $row) {
49 'title' => $row->title,
52 foreach ($row->tiles as $tileId) {
53 $tileData = $json->tiles[$tileId];
54 if ($tileData->type == 'app') {
55 $section->tiles[] = (object) [
56 'type' => $tileData->type,//app
57 'thumb' => $tileData->image,
58 'title' => $tileData->title,
59 'rating' => $tileData->rating->average,
60 'ratingCount' => $tileData->rating->count,
61 'detailUrl' => '../game/' . str_replace(
62 'ouya://launcher/details?app=',
68 $section->tiles[] = (object) [
69 'type' => $tileData->type,//discover
70 'thumb' => $tileData->image,
71 'title' => $tileData->title,
72 'detailUrl' => str_replace(
73 'ouya://launcher/discover/',
80 $sections[] = $section;
84 if ($title == 'DISCOVER') {
85 $navLinks['../'] = 'back';
87 $navLinks['./'] = 'discover';
90 $discoverTemplate = __DIR__ . '/../data/templates/discover.tpl.php';
92 include $discoverTemplate;
93 $html = ob_get_contents();
99 function renderGameFile($gameDataFile)
101 $json = json_decode(file_get_contents($gameDataFile));
102 $appsDir = dirname($gameDataFile, 2) . '/apps/';
103 $downloadJson = json_decode(
105 $appsDir . $json->version->uuid . '-download.json'
108 $apkDownloadUrl = $downloadJson->app->downloadLink;
111 foreach ($json->genres as $genreTitle) {
112 $url = '../discover/' . categoryPath($genreTitle) . '.htm';
113 $navLinks[$url] = $genreTitle;
116 $gameTemplate = __DIR__ . '/../data/templates/game.tpl.php';
118 include $gameTemplate;
119 $html = ob_get_contents();