diff --git a/include/version.inc b/include/version.inc index eb82d3b3b0..2d6afaacfa 100644 --- a/include/version.inc +++ b/include/version.inc @@ -92,76 +92,3 @@ $RELEASES = (function () { } return $ret; })(); - -// Get latest release version and info. -function release_get_latest() { - global $RELEASES; - - $version = '0.0.0'; - $current = null; - foreach ($RELEASES as $versions) { - foreach ($versions as $ver => $info) { - if (version_compare($ver, $version) > 0) { - $version = $ver; - $current = $info; - } - } - } - - return [$version, $current]; -} - -function show_source_releases() -{ - global $RELEASES; - - $SHOW_COUNT = 4; - - $current_uri = htmlspecialchars($_SERVER['REQUEST_URI'], ENT_QUOTES, 'UTF-8'); - - $i = 0; foreach ($RELEASES as $MAJOR => $major_releases): /* major releases loop start */ - $releases = array_slice($major_releases, 0, $SHOW_COUNT); -?> - - $a): ?> - - - -

- - PHP - (Changelog) -

-
- - - - GPG Keys for PHP -
- - -

Source Code

- +showSource(); ?>

GPG Keys

diff --git a/public/error.php b/public/error.php index 34b0e0a51f..140b26bdcf 100644 --- a/public/error.php +++ b/public/error.php @@ -11,6 +11,7 @@ use phpweb\I18n\Languages; use phpweb\ProjectGlobals; +use phpweb\Releases\Releases; use phpweb\UserPreferences; // Ensure that our environment is set up @@ -145,7 +146,7 @@ $df = $dlinfo[1]; if (strpos($df, "7-LATEST") !== false) { require_once __DIR__ . "/../include/version.inc"; - [$latest] = release_get_latest(); + [$latest] = new Releases()->getLatest(); $df = str_replace("7-LATEST", $latest, $df); } diff --git a/public/mirror-info.php b/public/mirror-info.php index 6d56628866..0c684fa7f3 100644 --- a/public/mirror-info.php +++ b/public/mirror-info.php @@ -1,8 +1,9 @@ getLatest(); $dist = $latest['source'][0]; $filename = ProjectGlobals::getPublicRoot() . "/distributions/{$dist['filename']}"; if (!file_exists($filename)) { diff --git a/src/Releases/Releases.php b/src/Releases/Releases.php new file mode 100644 index 0000000000..d978eebdb5 --- /dev/null +++ b/src/Releases/Releases.php @@ -0,0 +1,94 @@ +|null} + */ + public function getLatest(): array { + global $RELEASES; + + $version = '0.0.0'; + $current = null; + foreach ($RELEASES as $versions) { + foreach ($versions as $ver => $info) { + if (version_compare($ver, $version) > 0) { + $version = $ver; + $current = $info; + } + } + } + + return [$version, $current]; + } + + public function showSource(): void + { + global $RELEASES; + + $SHOW_COUNT = 4; + + $current_uri = htmlspecialchars($_SERVER['REQUEST_URI'], ENT_QUOTES, 'UTF-8'); + + $i = 0; foreach ($RELEASES as $MAJOR => $major_releases): /* major releases loop start */ + $releases = array_slice($major_releases, 0, $SHOW_COUNT); +?> + + $a): ?> + + + +

+ + PHP + (Changelog) +

+
+ + + + GPG Keys for PHP +
+ + +getLatest()); + } + + public function testGetLatest(): void + { + $GLOBALS['RELEASES'] = $this->getReleasesGlobal(); + + $expected = [ + '8.5.11', + [ + 'announcement' => true, + 'tags' => ['security'], + 'date' => '24 Sep 2026', + 'source' => [ + [ + 'filename' => 'php-8.5.11.tar.gz', + 'name' => 'PHP 8.5.11 (tar.gz)', + 'sha256' => '338630ba9450f0b938bef8d740162c61c33bf64a1b421c6333c01df8a9fdb0ab', + 'date' => '24 Sep 2026', + ], + [ + 'filename' => 'php-8.5.11.tar.bz2', + 'name' => 'PHP 8.5.11 (tar.bz2)', + 'sha256' => 'dc940716a8c73e531c0078eecb955d595d321ec2cc9d47149cf0089ea6e18f64', + 'date' => '24 Sep 2026', + ], + [ + 'filename' => 'php-8.5.11.tar.xz', + 'name' => 'PHP 8.5.11 (tar.xz)', + 'sha256' => 'd9be75c08e8c316f4c8f4194d8fbe1750a15f6a6d9d4e3fe72082abeeb800360', + 'date' => '24 Sep 2026', + ], + ], + ], + ]; + self::assertSame($expected, new Releases()->getLatest()); + } + + public function testShowSource(): void + { + $_SERVER['REQUEST_URI'] = '/downloads.php?os=linux&osvariant=linux-debian&version=default&source=Y'; + $MYSITE = 'https://www.php.net/'; + + require_once __DIR__ . '/../../../include/layout.inc'; + + $GLOBALS['RELEASES'] = $this->getReleasesGlobal(); + + new Releases()->showSource(); + + $expected = <<<"HTML" + + \n

+ Current Stable + PHP 8.5.11 (Changelog) +

+
+ + + + GPG Keys for PHP 8.5 +
+ \n

+ Old Stable + PHP 8.4.26 (Changelog) +

+
+ + + + GPG Keys for PHP 8.4 +
+ \n

+ Old Stable + PHP 8.3.35 (Changelog) +

+
+ + + + GPG Keys for PHP 8.3 +
+ \n

+ Old Stable + PHP 8.2.34 (Changelog) +

+
+ + + + GPG Keys for PHP 8.2 +
+ +HTML; + + self::assertSame($expected, $this->getActualOutputForAssertion()); + } + + /** @return array>> */ + private function getReleasesGlobal(): array + { + return [ + 8 => [ + '8.5.11' => [ + 'announcement' => true, + 'tags' => ['security'], + 'date' => '24 Sep 2026', + 'source' => [ + [ + 'filename' => 'php-8.5.11.tar.gz', + 'name' => 'PHP 8.5.11 (tar.gz)', + 'sha256' => '338630ba9450f0b938bef8d740162c61c33bf64a1b421c6333c01df8a9fdb0ab', + 'date' => '24 Sep 2026', + ], + [ + 'filename' => 'php-8.5.11.tar.bz2', + 'name' => 'PHP 8.5.11 (tar.bz2)', + 'sha256' => 'dc940716a8c73e531c0078eecb955d595d321ec2cc9d47149cf0089ea6e18f64', + 'date' => '24 Sep 2026', + ], + [ + 'filename' => 'php-8.5.11.tar.xz', + 'name' => 'PHP 8.5.11 (tar.xz)', + 'sha256' => 'd9be75c08e8c316f4c8f4194d8fbe1750a15f6a6d9d4e3fe72082abeeb800360', + 'date' => '24 Sep 2026', + ], + ], + ], + '8.4.26' => [ + 'announcement' => true, + 'tags' => ['security'], + 'date' => '24 Sep 2026', + 'source' => [ + [ + 'filename' => 'php-8.4.26.tar.gz', + 'name' => 'PHP 8.4.26 (tar.gz)', + 'sha256' => 'c248abaebc4bb777b80968f0760da0da8e989836e896c9ff637b6775d7d37662', + 'date' => '24 Sep 2026', + ], + [ + 'filename' => 'php-8.4.26.tar.bz2', + 'name' => 'PHP 8.4.26 (tar.bz2)', + 'sha256' => '4209694d7b0f63c45a3773e07cdc2bbfc71249265a5d951b1ff53e1147edc5ca', + 'date' => '24 Sep 2026', + ], + [ + 'filename' => 'php-8.4.26.tar.xz', + 'name' => 'PHP 8.4.26 (tar.xz)', + 'sha256' => '32a2de53862ad44ed4a5005244ce4f1b50c271e74dced215449a4443b40569f1', + 'date' => '24 Sep 2026', + ], + ], + ], + '8.3.35' => [ + 'announcement' => true, + 'tags' => ['security'], + 'date' => '24 Sep 2026', + 'source' => [ + [ + 'filename' => 'php-8.3.35.tar.gz', + 'name' => 'PHP 8.3.35 (tar.gz)', + 'sha256' => 'e60396276fd57e8210f88919d9acd4aab98d65fbb7f431c13285ca1fb04ff205', + 'date' => '24 Sep 2026', + ], + [ + 'filename' => 'php-8.3.35.tar.bz2', + 'name' => 'PHP 8.3.35 (tar.bz2)', + 'sha256' => 'e279d9ec90d9bcab900d146816e5b11d3e8924b80e2ba36c7d7dae7d71dcbf2d', + 'date' => '24 Sep 2026', + ], + [ + 'filename' => 'php-8.3.35.tar.xz', + 'name' => 'PHP 8.3.35 (tar.xz)', + 'sha256' => 'ff4630fbbbd94359134b7d3c223db59329905bdc4f5a9ef93d257b48e358619a', + 'date' => '24 Sep 2026', + ], + ], + ], + '8.2.34' => [ + 'announcement' => true, + 'tags' => ['security'], + 'date' => '24 Sep 2026', + 'source' => [ + [ + 'filename' => 'php-8.2.34.tar.gz', + 'name' => 'PHP 8.2.34 (tar.gz)', + 'sha256' => 'b42a58817acdf3e672d497a8f5314c1ee801b4ca94ebae41878bd29cf7764105', + 'date' => '24 Sep 2026', + ], + [ + 'filename' => 'php-8.2.34.tar.bz2', + 'name' => 'PHP 8.2.34 (tar.bz2)', + 'sha256' => '0467d63a819016811d35fd14f734764813ab149750379790634294c723cd7562', + 'date' => '24 Sep 2026', + ], + [ + 'filename' => 'php-8.2.34.tar.xz', + 'name' => 'PHP 8.2.34 (tar.xz)', + 'sha256' => '5351330c54de240f54f7527c26ef292e239749e6fe11db0330acb5317e02bb39', + 'date' => '24 Sep 2026', + ], + ], + ], + ], + ]; + } +}