X-Git-Url: https://git.cweiske.de/stouyapi.git/blobdiff_plain/5060373c18331dbd58af36c81b930c1cdaf66961..HEAD:/bin/build-html.php diff --git a/bin/build-html.php b/bin/build-html.php index b4561e6..5f601bf 100755 --- a/bin/build-html.php +++ b/bin/build-html.php @@ -7,6 +7,13 @@ */ require_once __DIR__ . '/functions.php'; +//default configuration values +$GLOBALS['pushToMyOuyaUrl'] = '../push-to-my-ouya.php'; +$cfgFile = __DIR__ . '/../config.php'; +if (file_exists($cfgFile)) { + include $cfgFile; +} + $wwwDir = __DIR__ . '/../www/'; $discoverDir = __DIR__ . '/../www/api/v1/discover-data/'; $wwwDiscoverDir = $wwwDir . 'discover/'; @@ -24,7 +31,7 @@ foreach (glob($gameDetailsDir . '*.json') as $gameDataFile) { $htmlFile = basename($gameDataFile, '.json') . '.htm'; file_put_contents( $wwwGameDir . $htmlFile, - renderGameFile($gameDataFile) + renderGameFile($gameDataFile, 'game/' . $htmlFile) ); } @@ -35,15 +42,59 @@ foreach (glob($discoverDir . '*.json') as $discoverFile) { } file_put_contents( $wwwDiscoverDir . $htmlFile, - renderDiscoverFile($discoverFile) + renderDiscoverFile($discoverFile, 'discover/' . $htmlFile) ); } -function renderDiscoverFile($discoverFile) +file_put_contents( + $wwwDiscoverDir . 'allgames.htm', + renderAllGamesList(glob($gameDetailsDir . '*.json'), 'discover/allgames.htm') +); + + +function renderAllGamesList($detailsFiles, $path) +{ + $games = []; + foreach ($detailsFiles as $gameDataFile) { + $json = json_decode(file_get_contents($gameDataFile)); + $games[] = (object) [ + 'packageName' => basename($gameDataFile, '.json'), + 'title' => $json->title, + 'genres' => $json->genres, + 'developer' => $json->developer->name, + 'developerUrl' => $json->stouyapi->{'developer-url'} ?? null, + 'suggestedAge' => $json->suggestedAge, + 'apkVersion' => $json->version->number, + 'apkTimestamp' => $json->version->publishedAt, + 'players' => $json->gamerNumbers, + 'detailUrl' => '../game/' . str_replace( + 'ouya://launcher/details?app=', + '', + basename($gameDataFile, '.json') + ) . '.htm', + ]; + } + $navLinks = [ + './' => 'back', + ]; + $canonicalUrl = $GLOBALS['baseUrl'] . $path; + + $allGamesTemplate = __DIR__ . '/../data/templates/allgames.tpl.php'; + ob_start(); + include $allGamesTemplate; + $html = ob_get_contents(); + ob_end_clean(); + + return $html; +} + +function renderDiscoverFile($discoverFile, $path) { $json = json_decode(file_get_contents($discoverFile)); - $title = $json->title; + $title = $json->title . ' OUYA games'; + $subtitle = $json->stouyapi->subtitle ?? null; + $sections = []; foreach ($json->rows as $row) { $section = (object) [ @@ -82,12 +133,19 @@ function renderDiscoverFile($discoverFile) } $navLinks = []; - if ($title == 'DISCOVER') { + if ($json->title == 'DISCOVER') { $navLinks['../'] = 'back'; + $navLinks['allgames.htm'] = 'all games'; + $title = 'OUYA games list'; } else { $navLinks['./'] = 'discover'; } + if ($path === 'discover/index.htm') { + $path = 'discover/'; + } + $canonicalUrl = $GLOBALS['baseUrl'] . $path; + $discoverTemplate = __DIR__ . '/../data/templates/discover.tpl.php'; ob_start(); include $discoverTemplate; @@ -97,7 +155,7 @@ function renderDiscoverFile($discoverFile) return $html; } -function renderGameFile($gameDataFile) +function renderGameFile($gameDataFile, $path) { $json = json_decode(file_get_contents($gameDataFile)); @@ -110,7 +168,28 @@ function renderGameFile($gameDataFile) $appsDir . $json->version->uuid . '-download.json' ) ); + $apkDownloadUrl = $downloadJson->app->downloadLink; + /* + if (isset($json->premium) && $json->premium) { + $apkDownloadUrl = null; + } + */ + $developerDetailsUrl = null; + if (isset($json->developer->url) && $json->developer->url) { + $developerDetailsUrl = '../discover/' . str_replace( + 'ouya://launcher/discover/', + '', + $json->developer->url + ) . '.htm'; + } + + $internetArchiveUrl = $json->stouyapi->{'internet-archive'} ?? null; + $developerUrl = $json->stouyapi->{'developer-url'} ?? null; + $canonicalUrl = $GLOBALS['baseUrl'] . $path; + + $pushUrl = $GLOBALS['pushToMyOuyaUrl'] + . '?game=' . urlencode($json->apk->package); $navLinks = []; foreach ($json->genres as $genreTitle) {