Author: Derick Rethans (derickr) Date: 2025-06-10T12:15:00+01:00 Commit: https://github.com/php/web-php/commit/e00746fec855bf1976a263110a6dbdfd9dbb590c Raw diff: https://github.com/php/web-php/commit/e00746fec855bf1976a263110a6dbdfd9dbb590c.diff
First stab at a prototype for revamping the download instructions page Changed paths: A downloads-get-instructions.php A js/version-choice.js M downloads.php M include/header.inc M include/version.inc Diff: diff --git a/downloads-get-instructions.php b/downloads-get-instructions.php new file mode 100644 index 0000000000..768600cee4 --- /dev/null +++ b/downloads-get-instructions.php @@ -0,0 +1,97 @@ +<?php +if ($_GET['os'] === 'windows' && $_GET['osvariant'] === 'windows-wsl') { + $_GET['os'] = 'linux'; + $_GET['osvariant'] = 'linux-deb-bookworm'; + $_GET['multiversion'] = 'true'; +} +if ($_GET['os'] === 'osx') { + $version = match($_GET['version']) { + 'php84' => '@8.4', + 'php83' => '@8.3', + 'php82' => '@8.2', + 'php81' => '@8.1', + default => '' + }; + + $versionDir = match($_GET['version']) { + 'php84' => '8.4', + 'php83' => '8.3', + 'php82' => '8.2', + 'php81' => '8.1', + default => '8.4' + }; + + echo <<<ENDOSX +<p> + On the OSX command line shell, enter: +</p> +<div class="example"><div class="example-contents screen"><pre> +brew install php{$version} +</pre></div></div> +<p> +To enable PHP in Apache add the following to httpd.conf and restart Apache: +</p> +<div class="example"><div class="example-contents screen"><pre> +LoadModule php_module \$HOMEBREW_PREFIX/opt/php/lib/httpd/modules/libphp.so + +<FilesMatch \.php$> +SetHandler application/x-httpd-php +</FilesMatch> +</pre></div></div> +<p> +Finally, check DirectoryIndex includes index.php +</p> +<div class="example"><div class="example-contents screen"><pre> +DirectoryIndex index.php index.html +</pre></div></div> +<p> +The php.ini and php-fpm.ini file can be found in: +</p> +<div class="example"><div class="example-contents screen"><pre> +\$HOMEBREW_PREFIX/etc/php/{$versionDir}/ +</pre></div></div> +</p> +ENDOSX; + return; +} +?> +<?php +if ($_GET['os'] === 'linux' && str_starts_with($_GET['osvariant'], 'linux-deb')) { + if ($_GET['version'] === 'default' && $_GET['multiversion'] != 'true') { + echo <<<ENDAPT +<p> + On the command line shell, enter: +</p> +<div class="example"><div class="example-contents screen"><pre> +sudo apt-get update +sudo apt-get install php +</pre></div></div> +ENDAPT; + } else { + $version = match($_GET['version']) { + 'php84' => '8.4', + 'php83' => '8.3', + 'php82' => '8.2', + 'php81' => '8.1', + default => '8.4' + }; + echo <<<ENDAPT +<p> + On the command line shell, enter: +</p> +<div class="example"><div class="example-contents screen"><pre> +sudo apt -y install software-properties-common +sudo add-apt-repository ppa:ondrej/php +sudo apt update +sudo apt install php{$version} +</pre></div></div> +ENDAPT; + } + return; +} +?> +<p> +There are no instructions yet. +</p> + +<?php var_dump($_GET); ?> diff --git a/downloads.php b/downloads.php index 5468da840f..ad5a1a118e 100644 --- a/downloads.php +++ b/downloads.php @@ -7,8 +7,6 @@ // Try to make this page non-cached header_nocache(); -$SHOW_COUNT = 4; - $SIDEBAR_DATA = ' <div class="panel"> <a href="/supported-versions.php">Supported Versions</a> @@ -37,15 +35,85 @@ ], ], "current" => "downloads", + "js_files" => [ + "/js/version-choice.js", + ], ], ); + +function option(string $id, string $value, string $desc) +{ + $selected = ''; + if (array_key_exists($id, $_GET) && $_GET[$id] === $value) { + $selected = ' selected'; + } + + echo <<<ENDOPT + <option value="{$value}"{$selected}>{$desc}</option> + +ENDOPT; +} ?> <h1>Downloads & Installation Instructions</h1> +<form> +Get PHP for +<select id="os" name="os"> + <?= option('os', 'linux', 'Linux'); ?> + <?= option('os', 'osx', 'OSX'); ?> + <?= option('os', 'windows', 'Windows'); ?> +</select> + +<select id="osvariant" name="osvariant"> + <?= option('osvariant', 'linux-deb-buster', 'Debian Buster'); ?> + <?= option('osvariant', 'linux-deb-bullseye', 'Debian Bullseye'); ?> + <?= option('osvariant', 'linux-deb-bookworm', 'Debian Bookworm'); ?> + <?= option('osvariant', 'linux-rpm-fedora41', 'Fedora 41'); ?> + <?= option('osvariant', 'linux-rpm-fedora42', 'Fedora 42'); ?> + <?= option('osvariant', 'linux-rpm-redhat', 'RedHat'); ?> + <?= option('osvariant', 'osx-latest', 'Latest'); ?> + <?= option('osvariant', 'windows-wsl', 'with WSL'); ?> + <?= option('osvariant', 'windows-normal', 'without WSL'); ?> +</select> + +to work on +<select id="usage" name="usage"> + <?= option('usage', 'web', 'Web Development'); ?> + <?= option('usage', 'cli', 'Command Line Libraries'); ?> + <?= option('usage', 'fw-drupal', 'Drupal'); ?> + <?= option('usage', 'fw-laravel', 'Laravel'); ?> + <?= option('usage', 'fw-symfony', 'Symfony'); ?> +</select> + +with +<select id="version" name="version"> + <?= option('version', 'php84', 'version 8.4'); ?> + <?= option('version', 'php83', 'version 8.3'); ?> + <?= option('version', 'php82', 'version 8.2'); ?> + <?= option('version', 'php81', 'version 8.1'); ?> + <?= option('version', 'default', 'OS default version'); ?> +</select> + +<input type='submit' value="Go!"></input> + +<br/> + +I want to have multiple versions at the same time: +<input type="checkbox" id="multiversion" name="multiversion" label="I want to have multiple versions at the same time"> +</input> +</form> + +<h2>Instructions</h2> +<div id="instructions"> +<?php include 'downloads-get-instructions.php'; ?> +</div> + +<!-- <p> <a href="/manual/install.general.php">Installing PHP</a> is covered thoroughly in the PHP documentation. </p> +--> <h2>Binaries</h2> @@ -66,49 +134,7 @@ </p> <h2>Source Code</h2> -<?php $i = 0; foreach ($RELEASES as $MAJOR => $major_releases): /* major releases loop start */ - $releases = array_slice($major_releases, 0, $SHOW_COUNT); -?> -<a id="v<?php echo $MAJOR; ?>"></a> -<?php foreach ($releases as $v => $a): ?> - <?php $mver = substr($v, 0, strrpos($v, '.')); ?> - <?php $stable = $i++ === 0 ? "Current Stable" : "Old Stable"; ?> - - <h3 id="v<?php echo $v; ?>" class="title"> - <span class="release-state"><?php echo $stable; ?></span> - PHP <?php echo $v; ?> - (<a href="/ChangeLog-<?php echo $MAJOR; ?>.php#<?php echo urlencode($v); ?>" class="changelog">Changelog</a>) - </h3> - <div class="content-box"> - - <ul> - <?php foreach ($a['source'] as $rel): ?> - <li> - <?php download_link($rel['filename'], $rel['filename']); ?> - <span class="releasedate"><?php echo date('d M Y', strtotime($rel['date'])); ?></span> - <?php - if (isset($rel['md5'])) echo '<span class="md5sum">', $rel['md5'], '</span>'; - if (isset($rel['sha256'])) echo '<span class="sha256">', $rel['sha256'], '</span>'; - ?> - <?php if (isset($rel['note']) && $rel['note']): ?> - <p> - <strong>Note:</strong> - <?php echo $rel['note']; ?> - </p> - <?php endif; ?> - </li> - <?php endforeach; ?> - <li> - <a href="https://windows.php.net/download#php-<?php echo urlencode($mver); ?>"> - Windows downloads - </a> - </li> - </ul> - - <a href="#gpg-<?php echo $mver; ?>">GPG Keys for PHP <?php echo $mver; ?></a> - </div> -<?php endforeach; ?> -<?php endforeach; /* major releases loop end */ ?> +<?php show_source_releases(); ?> <hr> <h2>GPG Keys</h2> diff --git a/include/header.inc b/include/header.inc index 2f33d64c55..4ba558fb17 100644 --- a/include/header.inc +++ b/include/header.inc @@ -23,6 +23,13 @@ foreach($css_files as $filename) { $CSS[$filename] = @filemtime($path); } +if (isset($config["js_files"])) { + foreach($config['js_files'] as $filename) { + $path = dirname(__DIR__) . $filename; + $JS[$filename] = @filemtime($path); + } +} + if (isset($shortname) && $shortname) { header("Link: <$shorturl>; rel=shorturl"); } @@ -85,6 +92,10 @@ if (!isset($config["languages"])) { <link rel="stylesheet" type="text/css" href="/cached.php?t=<?php echo $modified?>&f=<?php echo $filename?>" media="screen"> <?php endforeach ?> +<?php foreach($JS as $filename => $modified): ?> +<script type="text/javascript" src="/cached.php?t=<?php echo $modified?>&f=<?php echo $filename?>"></script> +<?php endforeach ?> + <?php if (!empty($_SERVER["BASE_HREF"])): ?> <base href="<?php echo $_SERVER["BASE_HREF"] ?>"> <?php endif ?> diff --git a/include/version.inc b/include/version.inc index fccf77370e..4ba37501a5 100644 --- a/include/version.inc +++ b/include/version.inc @@ -107,3 +107,55 @@ function release_get_latest() { return [$version, $current]; } + +function show_source_releases() +{ + global $RELEASES; + + $SHOW_COUNT = 4; + + $i = 0; foreach ($RELEASES as $MAJOR => $major_releases): /* major releases loop start */ + $releases = array_slice($major_releases, 0, $SHOW_COUNT); +?> + <a id="v<?php echo $MAJOR; ?>"></a> + <?php foreach ($releases as $v => $a): ?> + <?php $mver = substr($v, 0, strrpos($v, '.')); ?> + <?php $stable = $i++ === 0 ? "Current Stable" : "Old Stable"; ?> + + <h3 id="v<?php echo $v; ?>" class="title"> + <span class="release-state"><?php echo $stable; ?></span> + PHP <?php echo $v; ?> + (<a href="/ChangeLog-<?php echo $MAJOR; ?>.php#<?php echo urlencode($v); ?>" class="changelog">Changelog</a>) + </h3> + <div class="content-box"> + + <ul> + <?php foreach ($a['source'] as $rel): ?> + <li> + <?php download_link($rel['filename'], $rel['filename']); ?> + <span class="releasedate"><?php echo date('d M Y', strtotime($rel['date'])); ?></span> + <?php + if (isset($rel['md5'])) echo '<span class="md5sum">', $rel['md5'], '</span>'; + if (isset($rel['sha256'])) echo '<span class="sha256">', $rel['sha256'], '</span>'; + ?> + <?php if (isset($rel['note']) && $rel['note']): ?> + <p> + <strong>Note:</strong> + <?php echo $rel['note']; ?> + </p> + <?php endif; ?> + </li> + <?php endforeach; ?> + <li> + <a href="https://windows.php.net/download#php-<?php echo urlencode($mver); ?>"> + Windows downloads + </a> + </li> + </ul> + + <a href="#gpg-<?php echo $mver; ?>">GPG Keys for PHP <?php echo $mver; ?></a> + </div> + <?php endforeach; ?> + <?php endforeach; /* major releases loop end */ ?> +<?php +} diff --git a/js/version-choice.js b/js/version-choice.js new file mode 100644 index 0000000000..142a4065b4 --- /dev/null +++ b/js/version-choice.js @@ -0,0 +1,60 @@ +function setSelectBoxes() { + let instructionsDiv = document.getElementById("instructions") + let osSelector = document.getElementById("os") + let variantSelector = document.getElementById("osvariant") + let usageSelector = document.getElementById("usage") + let versionSelector = document.getElementById("version") + let multiversionBox = document.getElementById("multiversion") + + const url = '/downloads-get-instructions.php' + + '?os=' + osSelector.options[osSelector.selectedIndex].value + + '&osvariant=' + variantSelector.options[variantSelector.selectedIndex].value + + '&usage=' + usageSelector.options[usageSelector.selectedIndex].value + + '&version=' + versionSelector.options[versionSelector.selectedIndex].value + + '&multiversion=' + multiversionBox.checked + + fetch(url) + .then(response => { + if (response.ok) { + return response.text() + } else { + throw new Error("Couldn't fetch instructions"); + } + }) + .then(data => { + instructionsDiv.innerHTML = data + }) + .catch(error => console.error("Couldn't fetch instructions: ", error)); +} + +function setSelectOsBoxes() { + let osSelector = document.getElementById("os") + let variantSelector = document.getElementById("osvariant") + + for (var i = variantSelector.length - 1; i >= 0; i--) { + if (!variantSelector.options[i].value.startsWith(osSelector.options[osSelector.selectedIndex].value + "-")) { + variantSelector.options[i].disabled = true + } else { + variantSelector.options[i].disabled = false + variantSelector.selectedIndex = i + } + } + + setSelectBoxes(); +} + +window.onload = function() { + let osSelector = document.getElementById("os") + let variantSelector = document.getElementById("osvariant") + let usageSelector = document.getElementById("usage") + let versionSelector = document.getElementById("version") + let multiversionBox = document.getElementById("multiversion") + + osSelector.addEventListener("change", setSelectOsBoxes) + variantSelector.addEventListener("change", setSelectBoxes) + usageSelector.addEventListener("change", setSelectBoxes) + versionSelector.addEventListener("change", setSelectBoxes) + multiversionBox.addEventListener("change", setSelectBoxes) + + setSelectOsBoxes() +}