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 'suggestedAge' => $json->suggestedAge,
66 'apkVersion' => $json->version->number,
67 'apkTimestamp' => $json->version->publishedAt,
68 'players' => $json->gamerNumbers,
69 'detailUrl' => '../game/' . str_replace(
70 'ouya://launcher/details?app=',
72 basename($gameDataFile, '.json')
80 $allGamesTemplate = __DIR__ . '/../data/templates/allgames.tpl.php';
82 include $allGamesTemplate;
83 $html = ob_get_contents();
89 function renderDiscoverFile($discoverFile)
91 $json = json_decode(file_get_contents($discoverFile));
93 $title = $json->title . ' OUYA games';
95 foreach ($json->rows as $row) {
97 'title' => $row->title,
100 foreach ($row->tiles as $tileId) {
101 $tileData = $json->tiles[$tileId];
102 if ($tileData->type == 'app') {
103 $section->tiles[] = (object) [
104 'type' => $tileData->type,//app
105 'thumb' => $tileData->image,
106 'title' => $tileData->title,
107 'rating' => $tileData->rating->average,
108 'ratingCount' => $tileData->rating->count,
109 'detailUrl' => '../game/' . str_replace(
110 'ouya://launcher/details?app=',
116 $section->tiles[] = (object) [
117 'type' => $tileData->type,//discover
118 'thumb' => $tileData->image,
119 'title' => $tileData->title,
120 'detailUrl' => str_replace(
121 'ouya://launcher/discover/',
128 $sections[] = $section;
132 if ($json->title == 'DISCOVER') {
133 $navLinks['../'] = 'back';
134 $navLinks['allgames.htm'] = 'all games';
135 $title = 'OUYA games list';
137 $navLinks['./'] = 'discover';
140 $discoverTemplate = __DIR__ . '/../data/templates/discover.tpl.php';
142 include $discoverTemplate;
143 $html = ob_get_contents();
149 function renderGameFile($gameDataFile)
151 $json = json_decode(file_get_contents($gameDataFile));
153 $appsDir = dirname($gameDataFile, 2) . '/apps/';
154 $appsFile = $appsDir . $json->version->uuid . '.json';
155 $appsJson = json_decode(file_get_contents($appsFile));
157 $downloadJson = json_decode(
159 $appsDir . $json->version->uuid . '-download.json'
163 $apkDownloadUrl = $downloadJson->app->downloadLink;
165 if (isset($json->premium) && $json->premium) {
166 $apkDownloadUrl = null;
170 $internetArchiveUrl = $json->stouyapi->{'internet-archive'} ?? null;
172 $pushUrl = $GLOBALS['pushToMyOuyaUrl']
173 . '?game=' . urlencode($json->apk->package);
176 foreach ($json->genres as $genreTitle) {
177 $url = '../discover/' . categoryPath($genreTitle) . '.htm';
178 $navLinks[$url] = $genreTitle;
181 $gameTemplate = __DIR__ . '/../data/templates/game.tpl.php';
183 include $gameTemplate;
184 $html = ob_get_contents();