From 9955068c6d11fc9717f63498d81e1599f94fcd44 Mon Sep 17 00:00:00 2001 From: Marc Durdin Date: Tue, 6 Oct 2026 08:29:18 +0200 Subject: [PATCH] fix: set correct version for /downloads/releases pages Fixes: #846 Follows: #840 Test-bot: skip --- .../downloads/releases/_version_downloads.php | 3 +- _includes/2020/DownloadUI.php | 56 ++++++++++++------- 2 files changed, 38 insertions(+), 21 deletions(-) diff --git a/_content/downloads/releases/_version_downloads.php b/_content/downloads/releases/_version_downloads.php index a32a5508..bea86d23 100644 --- a/_content/downloads/releases/_version_downloads.php +++ b/_content/downloads/releases/_version_downloads.php @@ -33,7 +33,8 @@ function array_key_first(array $arr) { } // note: we currently ignore the tier parameter - $versions = @json_decode(Util::call_downloads_keyman_com("/api/version/2.0?targetVersion=$version", 'downloads.keyman.com-api_version_2.0.json')); + + $versions = DownloadUI::setVersion($version); if(empty($versions->android)) $tier = 'unknown'; diff --git a/_includes/2020/DownloadUI.php b/_includes/2020/DownloadUI.php index 77fa5fab..45e06006 100644 --- a/_includes/2020/DownloadUI.php +++ b/_includes/2020/DownloadUI.php @@ -7,10 +7,14 @@ use Keyman\Site\com\keyman\Util; Locale::definePageScope('LOCALE_DOWNLOADS', 'downloads'); - global $versions; - $versions = @json_decode(Util::call_downloads_keyman_com('/api/version/2.0', 'downloads.keyman.com-api_version_2.0.json')); - class DownloadUI { + private static $versions; + + public static function setVersion($version) { + DownloadUI::$versions = @json_decode(Util::call_downloads_keyman_com("/api/version/2.0?targetVersion=$version", 'downloads.keyman.com-api_version_2.0.json')); + return DownloadUI::$versions; + } + private static function formatSizeUnits($bytes) { if ($bytes >= 1073741824) { $bytes = number_format($bytes / 1073741824, 2) . ' GB'; @@ -30,7 +34,6 @@ private static function formatSizeUnits($bytes) { } private static function filenamePatterns($target, $tier) { - global $versions; switch($target) { case 'android': return 'keyman-$version.apk'; case 'android-engine': return 'keyman-engine-android-$version.zip'; @@ -89,23 +92,35 @@ public static function downloadSection($platform, $tiers = '', $target = '') { } } + private static function initVersions() { + if(empty(DownloadUI::$versions)) { + DownloadUI::$versions = @json_decode(Util::call_downloads_keyman_com('/api/version/2.0', 'downloads.keyman.com-api_version_2.0.json')); + if(empty(DownloadUI::$versions)) { + return false; + } + } + return true; + } + private static function downloadLinks($platform, $tier, $filepatterns) { - global $versions; + if(!DownloadUI::initVersions()) { + return false; + } $product = DownloadUI::productName($platform); echo sprintf("

%s

\n