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)
49 function renderDiscoverFile($discoverFile)
51 $json = json_decode(file_get_contents($discoverFile));
53 $title = $json->title;
55 foreach ($json->rows as $row) {
57 'title' => $row->title,
60 foreach ($row->tiles as $tileId) {
61 $tileData = $json->tiles[$tileId];
62 if ($tileData->type == 'app') {
63 $section->tiles[] = (object) [
64 'type' => $tileData->type,//app
65 'thumb' => $tileData->image,
66 'title' => $tileData->title,
67 'rating' => $tileData->rating->average,
68 'ratingCount' => $tileData->rating->count,
69 'detailUrl' => '../game/' . str_replace(
70 'ouya://launcher/details?app=',
76 $section->tiles[] = (object) [
77 'type' => $tileData->type,//discover
78 'thumb' => $tileData->image,
79 'title' => $tileData->title,
80 'detailUrl' => str_replace(
81 'ouya://launcher/discover/',
88 $sections[] = $section;
92 if ($title == 'DISCOVER') {
93 $navLinks['../'] = 'back';
95 $navLinks['./'] = 'discover';
98 $discoverTemplate = __DIR__ . '/../data/templates/discover.tpl.php';
100 include $discoverTemplate;
101 $html = ob_get_contents();
107 function renderGameFile($gameDataFile)
109 $json = json_decode(file_get_contents($gameDataFile));
111 $appsDir = dirname($gameDataFile, 2) . '/apps/';
112 $appsFile = $appsDir . $json->version->uuid . '.json';
113 $appsJson = json_decode(file_get_contents($appsFile));
115 $downloadJson = json_decode(
117 $appsDir . $json->version->uuid . '-download.json'
120 $apkDownloadUrl = $downloadJson->app->downloadLink;
121 $pushUrl = $GLOBALS['pushToMyOuyaUrl']
122 . '?game=' . urlencode($json->apk->package);
125 foreach ($json->genres as $genreTitle) {
126 $url = '../discover/' . categoryPath($genreTitle) . '.htm';
127 $navLinks[$url] = $genreTitle;
130 $gameTemplate = __DIR__ . '/../data/templates/game.tpl.php';
132 include $gameTemplate;
133 $html = ob_get_contents();