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 //default configuration values
11 $GLOBALS['pushToMyOuyaUrl'] = '../push-to-my-ouya.php';
12 $cfgFile = __DIR__ . '/../config.php';
13 if (file_exists($cfgFile)) {
17 $wwwDir = __DIR__ . '/../www/';
18 $discoverDir = __DIR__ . '/../www/api/v1/discover-data/';
19 $wwwDiscoverDir = $wwwDir . 'discover/';
20 $gameDetailsDir = __DIR__ . '/../www/api/v1/details-data/';
21 $wwwGameDir = $wwwDir . 'game/';
23 if (!is_dir($wwwDiscoverDir)) {
24 mkdir($wwwDiscoverDir, 0755);
26 if (!is_dir($wwwGameDir)) {
27 mkdir($wwwGameDir, 0755);
30 foreach (glob($gameDetailsDir . '*.json') as $gameDataFile) {
31 $htmlFile = basename($gameDataFile, '.json') . '.htm';
33 $wwwGameDir . $htmlFile,
34 renderGameFile($gameDataFile)
38 foreach (glob($discoverDir . '*.json') as $discoverFile) {
39 $htmlFile = basename($discoverFile, '.json') . '.htm';
40 if ($htmlFile == 'discover.htm') {
41 $htmlFile = 'index.htm';
44 $wwwDiscoverDir . $htmlFile,
45 renderDiscoverFile($discoverFile)
50 $wwwDiscoverDir . 'allgames.htm',
51 renderAllGamesList(glob($gameDetailsDir . '*.json'))
55 function renderAllGamesList($detailsFiles)
58 foreach ($detailsFiles as $gameDataFile) {
59 $json = json_decode(file_get_contents($gameDataFile));
61 'packageName' => basename($gameDataFile, '.json'),
62 'title' => $json->title,
63 'genres' => $json->genres,
64 'developer' => $json->developer->name,
65 'developerUrl' => $json->stouyapi->{'developer-url'} ?? null,
66 'suggestedAge' => $json->suggestedAge,
67 'apkVersion' => $json->version->number,
68 'apkTimestamp' => $json->version->publishedAt,
69 'players' => $json->gamerNumbers,
70 'detailUrl' => '../game/' . str_replace(
71 'ouya://launcher/details?app=',
73 basename($gameDataFile, '.json')
81 $allGamesTemplate = __DIR__ . '/../data/templates/allgames.tpl.php';
83 include $allGamesTemplate;
84 $html = ob_get_contents();
90 function renderDiscoverFile($discoverFile)
92 $json = json_decode(file_get_contents($discoverFile));
94 $title = $json->title . ' OUYA games';
96 foreach ($json->rows as $row) {
98 'title' => $row->title,
101 foreach ($row->tiles as $tileId) {
102 $tileData = $json->tiles[$tileId];
103 if ($tileData->type == 'app') {
104 $section->tiles[] = (object) [
105 'type' => $tileData->type,//app
106 'thumb' => $tileData->image,
107 'title' => $tileData->title,
108 'rating' => $tileData->rating->average,
109 'ratingCount' => $tileData->rating->count,
110 'detailUrl' => '../game/' . str_replace(
111 'ouya://launcher/details?app=',
117 $section->tiles[] = (object) [
118 'type' => $tileData->type,//discover
119 'thumb' => $tileData->image,
120 'title' => $tileData->title,
121 'detailUrl' => str_replace(
122 'ouya://launcher/discover/',
129 $sections[] = $section;
133 if ($json->title == 'DISCOVER') {
134 $navLinks['../'] = 'back';
135 $navLinks['allgames.htm'] = 'all games';
136 $title = 'OUYA games list';
138 $navLinks['./'] = 'discover';
141 $discoverTemplate = __DIR__ . '/../data/templates/discover.tpl.php';
143 include $discoverTemplate;
144 $html = ob_get_contents();
150 function renderGameFile($gameDataFile)
152 $json = json_decode(file_get_contents($gameDataFile));
154 $appsDir = dirname($gameDataFile, 2) . '/apps/';
155 $appsFile = $appsDir . $json->version->uuid . '.json';
156 $appsJson = json_decode(file_get_contents($appsFile));
158 $downloadJson = json_decode(
160 $appsDir . $json->version->uuid . '-download.json'
164 $apkDownloadUrl = $downloadJson->app->downloadLink;
166 if (isset($json->premium) && $json->premium) {
167 $apkDownloadUrl = null;
171 $internetArchiveUrl = $json->stouyapi->{'internet-archive'} ?? null;
172 $developerUrl = $json->stouyapi->{'developer-url'} ?? null;
174 $pushUrl = $GLOBALS['pushToMyOuyaUrl']
175 . '?game=' . urlencode($json->apk->package);
178 foreach ($json->genres as $genreTitle) {
179 $url = '../discover/' . categoryPath($genreTitle) . '.htm';
180 $navLinks[$url] = $genreTitle;
183 $gameTemplate = __DIR__ . '/../data/templates/game.tpl.php';
185 include $gameTemplate;
186 $html = ob_get_contents();