4 * Take the generated JSON files and convert them to HTML for a browser
6 * @author Christian Weiske <cweiske@cweiske.de>
8 require_once __DIR__ . '/functions.php';
10 $wwwDir = __DIR__ . '/../www/';
11 $discoverDir = __DIR__ . '/../www/api/v1/discover-data/';
12 $wwwDiscoverDir = $wwwDir . 'discover/';
13 $gameDetailsDir = __DIR__ . '/../www/api/v1/details-data/';
14 $wwwGameDir = $wwwDir . 'game/';
16 if (!is_dir($wwwDiscoverDir)) {
17 mkdir($wwwDiscoverDir, 0755);
19 if (!is_dir($wwwGameDir)) {
20 mkdir($wwwGameDir, 0755);
23 foreach (glob($gameDetailsDir . '*.json') as $gameDataFile) {
24 $htmlFile = basename($gameDataFile, '.json') . '.htm';
26 $wwwGameDir . $htmlFile,
27 renderGameFile($gameDataFile)
31 foreach (glob($discoverDir . '*.json') as $discoverFile) {
32 $htmlFile = basename($discoverFile, '.json') . '.htm';
33 if ($htmlFile == 'discover.htm') {
34 $htmlFile = 'index.htm';
37 $wwwDiscoverDir . $htmlFile,
38 renderDiscoverFile($discoverFile)
42 function renderDiscoverFile($discoverFile)
44 $json = json_decode(file_get_contents($discoverFile));
46 $title = $json->title;
48 foreach ($json->rows as $row) {
50 'title' => $row->title,
53 foreach ($row->tiles as $tileId) {
54 $tileData = $json->tiles[$tileId];
55 if ($tileData->type == 'app') {
56 $section->tiles[] = (object) [
57 'type' => $tileData->type,//app
58 'thumb' => $tileData->image,
59 'title' => $tileData->title,
60 'rating' => $tileData->rating->average,
61 'ratingCount' => $tileData->rating->count,
62 'detailUrl' => '../game/' . str_replace(
63 'ouya://launcher/details?app=',
69 $section->tiles[] = (object) [
70 'type' => $tileData->type,//discover
71 'thumb' => $tileData->image,
72 'title' => $tileData->title,
73 'detailUrl' => str_replace(
74 'ouya://launcher/discover/',
81 $sections[] = $section;
85 if ($title == 'DISCOVER') {
86 $navLinks['../'] = 'back';
88 $navLinks['./'] = 'discover';
91 $discoverTemplate = __DIR__ . '/../data/templates/discover.tpl.php';
93 include $discoverTemplate;
94 $html = ob_get_contents();
100 function renderGameFile($gameDataFile)
102 $json = json_decode(file_get_contents($gameDataFile));
104 $appsDir = dirname($gameDataFile, 2) . '/apps/';
105 $appsFile = $appsDir . $json->version->uuid . '.json';
106 $appsJson = json_decode(file_get_contents($appsFile));
108 $downloadJson = json_decode(
110 $appsDir . $json->version->uuid . '-download.json'
113 $apkDownloadUrl = $downloadJson->app->downloadLink;
116 foreach ($json->genres as $genreTitle) {
117 $url = '../discover/' . categoryPath($genreTitle) . '.htm';
118 $navLinks[$url] = $genreTitle;
121 $gameTemplate = __DIR__ . '/../data/templates/game.tpl.php';
123 include $gameTemplate;
124 $html = ob_get_contents();