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, 'game/' . $htmlFile)
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, 'discover/' . $htmlFile)
50 $wwwDiscoverDir . 'allgames.htm',
51 renderAllGamesList(glob($gameDetailsDir . '*.json'), 'discover/allgames.htm')
55 function renderAllGamesList($detailsFiles, $path)
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')
80 $canonicalUrl = $GLOBALS['baseUrl'] . $path;
82 $allGamesTemplate = __DIR__ . '/../data/templates/allgames.tpl.php';
84 include $allGamesTemplate;
85 $html = ob_get_contents();
91 function renderDiscoverFile($discoverFile, $path)
93 $json = json_decode(file_get_contents($discoverFile));
95 $title = $json->title . ' OUYA games';
96 $subtitle = $json->stouyapi->subtitle ?? null;
99 foreach ($json->rows as $row) {
100 $section = (object) [
101 'title' => $row->title,
104 foreach ($row->tiles as $tileId) {
105 $tileData = $json->tiles[$tileId];
106 if ($tileData->type == 'app') {
107 $section->tiles[] = (object) [
108 'type' => $tileData->type,//app
109 'thumb' => $tileData->image,
110 'title' => $tileData->title,
111 'rating' => $tileData->rating->average,
112 'ratingCount' => $tileData->rating->count,
113 'detailUrl' => '../game/' . str_replace(
114 'ouya://launcher/details?app=',
120 $section->tiles[] = (object) [
121 'type' => $tileData->type,//discover
122 'thumb' => $tileData->image,
123 'title' => $tileData->title,
124 'detailUrl' => str_replace(
125 'ouya://launcher/discover/',
132 $sections[] = $section;
136 if ($json->title == 'DISCOVER') {
137 $navLinks['../'] = 'back';
138 $navLinks['allgames.htm'] = 'all games';
139 $title = 'OUYA games list';
141 $navLinks['./'] = 'discover';
144 if ($path === 'discover/index.htm') {
147 $canonicalUrl = $GLOBALS['baseUrl'] . $path;
149 $discoverTemplate = __DIR__ . '/../data/templates/discover.tpl.php';
151 include $discoverTemplate;
152 $html = ob_get_contents();
158 function renderGameFile($gameDataFile, $path)
160 $json = json_decode(file_get_contents($gameDataFile));
162 $appsDir = dirname($gameDataFile, 2) . '/apps/';
163 $appsFile = $appsDir . $json->version->uuid . '.json';
164 $appsJson = json_decode(file_get_contents($appsFile));
166 $downloadJson = json_decode(
168 $appsDir . $json->version->uuid . '-download.json'
172 $apkDownloadUrl = $downloadJson->app->downloadLink;
174 if (isset($json->premium) && $json->premium) {
175 $apkDownloadUrl = null;
178 $developerDetailsUrl = null;
179 if (isset($json->developer->url) && $json->developer->url) {
180 $developerDetailsUrl = '../discover/' . str_replace(
181 'ouya://launcher/discover/',
183 $json->developer->url
187 $internetArchiveUrl = $json->stouyapi->{'internet-archive'} ?? null;
188 $developerUrl = $json->stouyapi->{'developer-url'} ?? null;
189 $canonicalUrl = $GLOBALS['baseUrl'] . $path;
191 $pushUrl = $GLOBALS['pushToMyOuyaUrl']
192 . '?game=' . urlencode($json->apk->package);
195 foreach ($json->genres as $genreTitle) {
196 $url = '../discover/' . categoryPath($genreTitle) . '.htm';
197 $navLinks[$url] = $genreTitle;
200 $gameTemplate = __DIR__ . '/../data/templates/game.tpl.php';
202 include $gameTemplate;
203 $html = ob_get_contents();