X-Git-Url: https://git.cweiske.de/stouyapi.git/blobdiff_plain/eeb83bc96525bfcb38d614eb4f84f83b8e26a708..d557e7dc63f31c671bfcbf8f5c6c78ebc101bce8:/bin/build-html.php diff --git a/bin/build-html.php b/bin/build-html.php index e1f533f..581df02 100644 --- a/bin/build-html.php +++ b/bin/build-html.php @@ -4,13 +4,28 @@ * * @author Christian Weiske */ +require_once __DIR__ . '/functions.php'; + $wwwDir = __DIR__ . '/../www/'; $discoverDir = __DIR__ . '/../www/api/v1/discover-data/'; $wwwDiscoverDir = $wwwDir . 'discover/'; +$gameDetailsDir = __DIR__ . '/../www/api/v1/details-data/'; +$wwwGameDir = $wwwDir . 'game/'; if (!is_dir($wwwDiscoverDir)) { mkdir($wwwDiscoverDir, 0755); } +if (!is_dir($wwwGameDir)) { + mkdir($wwwGameDir, 0755); +} + +foreach (glob($gameDetailsDir . '*.json') as $gameDataFile) { + $htmlFile = basename($gameDataFile, '.json') . '.htm'; + file_put_contents( + $wwwGameDir . $htmlFile, + renderGameFile($gameDataFile) + ); +} foreach (glob($discoverDir . '*.json') as $discoverFile) { $htmlFile = basename($discoverFile, '.json') . '.htm'; @@ -65,6 +80,13 @@ function renderDiscoverFile($discoverFile) $sections[] = $section; } + $navLinks = []; + if ($title == 'DISCOVER') { + $navLinks['../'] = 'back'; + } else { + $navLinks['./'] = 'discover'; + } + $discoverTemplate = __DIR__ . '/../data/templates/discover.tpl.php'; ob_start(); include $discoverTemplate; @@ -73,4 +95,30 @@ function renderDiscoverFile($discoverFile) return $html; } + +function renderGameFile($gameDataFile) +{ + $json = json_decode(file_get_contents($gameDataFile)); + $appsDir = dirname($gameDataFile, 2) . '/apps/'; + $downloadJson = json_decode( + file_get_contents( + $appsDir . $json->version->uuid . '-download.json' + ) + ); + $apkDownloadUrl = $downloadJson->app->downloadLink; + + $navLinks = []; + foreach ($json->genres as $genreTitle) { + $url = '../discover/' . categoryPath($genreTitle) . '.htm'; + $navLinks[$url] = $genreTitle; + } + + $gameTemplate = __DIR__ . '/../data/templates/game.tpl.php'; + ob_start(); + include $gameTemplate; + $html = ob_get_contents(); + ob_end_clean(); + + return $html; +} ?>