Skip to content

Commit e00746f

Browse files
committed
First stab at a prototype for revamping the download instructions page
1 parent 61be9d7 commit e00746f

File tree

5 files changed

+291
-45
lines changed

5 files changed

+291
-45
lines changed

downloads-get-instructions.php

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
<?php
2+
if ($_GET['os'] === 'windows' && $_GET['osvariant'] === 'windows-wsl') {
3+
$_GET['os'] = 'linux';
4+
$_GET['osvariant'] = 'linux-deb-bookworm';
5+
$_GET['multiversion'] = 'true';
6+
}
7+
if ($_GET['os'] === 'osx') {
8+
$version = match($_GET['version']) {
9+
'php84' => '@8.4',
10+
'php83' => '@8.3',
11+
'php82' => '@8.2',
12+
'php81' => '@8.1',
13+
default => ''
14+
};
15+
16+
$versionDir = match($_GET['version']) {
17+
'php84' => '8.4',
18+
'php83' => '8.3',
19+
'php82' => '8.2',
20+
'php81' => '8.1',
21+
default => '8.4'
22+
};
23+
24+
echo <<<ENDOSX
25+
<p>
26+
On the OSX command line shell, enter:
27+
</p>
28+
<div class="example"><div class="example-contents screen"><pre>
29+
brew install php{$version}
30+
</pre></div></div>
31+
<p>
32+
To enable PHP in Apache add the following to httpd.conf and restart Apache:
33+
</p>
34+
<div class="example"><div class="example-contents screen"><pre>
35+
LoadModule php_module \$HOMEBREW_PREFIX/opt/php/lib/httpd/modules/libphp.so
36+
37+
&lt;FilesMatch \.php$>
38+
SetHandler application/x-httpd-php
39+
&lt;/FilesMatch>
40+
</pre></div></div>
41+
<p>
42+
Finally, check DirectoryIndex includes index.php
43+
</p>
44+
<div class="example"><div class="example-contents screen"><pre>
45+
DirectoryIndex index.php index.html
46+
</pre></div></div>
47+
<p>
48+
The php.ini and php-fpm.ini file can be found in:
49+
</p>
50+
<div class="example"><div class="example-contents screen"><pre>
51+
\$HOMEBREW_PREFIX/etc/php/{$versionDir}/
52+
</pre></div></div>
53+
</p>
54+
ENDOSX;
55+
return;
56+
}
57+
?>
58+
<?php
59+
if ($_GET['os'] === 'linux' && str_starts_with($_GET['osvariant'], 'linux-deb')) {
60+
if ($_GET['version'] === 'default' && $_GET['multiversion'] != 'true') {
61+
echo <<<ENDAPT
62+
<p>
63+
On the command line shell, enter:
64+
</p>
65+
<div class="example"><div class="example-contents screen"><pre>
66+
sudo apt-get update
67+
sudo apt-get install php
68+
</pre></div></div>
69+
ENDAPT;
70+
} else {
71+
$version = match($_GET['version']) {
72+
'php84' => '8.4',
73+
'php83' => '8.3',
74+
'php82' => '8.2',
75+
'php81' => '8.1',
76+
default => '8.4'
77+
};
78+
echo <<<ENDAPT
79+
<p>
80+
On the command line shell, enter:
81+
</p>
82+
<div class="example"><div class="example-contents screen"><pre>
83+
sudo apt -y install software-properties-common
84+
sudo add-apt-repository ppa:ondrej/php
85+
sudo apt update
86+
sudo apt install php{$version}
87+
</pre></div></div>
88+
ENDAPT;
89+
}
90+
return;
91+
}
92+
?>
93+
<p>
94+
There are no instructions yet.
95+
</p>
96+
97+
<?php var_dump($_GET); ?>

downloads.php

Lines changed: 71 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
// Try to make this page non-cached
88
header_nocache();
99

10-
$SHOW_COUNT = 4;
11-
1210
$SIDEBAR_DATA = '
1311
<div class="panel">
1412
<a href="/supported-versions.php">Supported Versions</a>
@@ -37,15 +35,85 @@
3735
],
3836
],
3937
"current" => "downloads",
38+
"js_files" => [
39+
"/js/version-choice.js",
40+
],
4041
],
4142
);
43+
44+
function option(string $id, string $value, string $desc)
45+
{
46+
$selected = '';
47+
if (array_key_exists($id, $_GET) && $_GET[$id] === $value) {
48+
$selected = ' selected';
49+
}
50+
51+
echo <<<ENDOPT
52+
<option value="{$value}"{$selected}>{$desc}</option>
53+
54+
ENDOPT;
55+
}
4256
?>
4357
<h1>Downloads &amp; Installation Instructions</h1>
4458

59+
<form>
60+
Get PHP for
61+
<select id="os" name="os">
62+
<?= option('os', 'linux', 'Linux'); ?>
63+
<?= option('os', 'osx', 'OSX'); ?>
64+
<?= option('os', 'windows', 'Windows'); ?>
65+
</select>
66+
67+
<select id="osvariant" name="osvariant">
68+
<?= option('osvariant', 'linux-deb-buster', 'Debian Buster'); ?>
69+
<?= option('osvariant', 'linux-deb-bullseye', 'Debian Bullseye'); ?>
70+
<?= option('osvariant', 'linux-deb-bookworm', 'Debian Bookworm'); ?>
71+
<?= option('osvariant', 'linux-rpm-fedora41', 'Fedora 41'); ?>
72+
<?= option('osvariant', 'linux-rpm-fedora42', 'Fedora 42'); ?>
73+
<?= option('osvariant', 'linux-rpm-redhat', 'RedHat'); ?>
74+
<?= option('osvariant', 'osx-latest', 'Latest'); ?>
75+
<?= option('osvariant', 'windows-wsl', 'with WSL'); ?>
76+
<?= option('osvariant', 'windows-normal', 'without WSL'); ?>
77+
</select>
78+
79+
to work on
80+
<select id="usage" name="usage">
81+
<?= option('usage', 'web', 'Web Development'); ?>
82+
<?= option('usage', 'cli', 'Command Line Libraries'); ?>
83+
<?= option('usage', 'fw-drupal', 'Drupal'); ?>
84+
<?= option('usage', 'fw-laravel', 'Laravel'); ?>
85+
<?= option('usage', 'fw-symfony', 'Symfony'); ?>
86+
</select>
87+
88+
with
89+
<select id="version" name="version">
90+
<?= option('version', 'php84', 'version 8.4'); ?>
91+
<?= option('version', 'php83', 'version 8.3'); ?>
92+
<?= option('version', 'php82', 'version 8.2'); ?>
93+
<?= option('version', 'php81', 'version 8.1'); ?>
94+
<?= option('version', 'default', 'OS default version'); ?>
95+
</select>
96+
97+
<input type='submit' value="Go!"></input>
98+
99+
<br/>
100+
101+
I want to have multiple versions at the same time:
102+
<input type="checkbox" id="multiversion" name="multiversion" label="I want to have multiple versions at the same time">
103+
</input>
104+
</form>
105+
106+
<h2>Instructions</h2>
107+
<div id="instructions">
108+
<?php include 'downloads-get-instructions.php'; ?>
109+
</div>
110+
111+
<!--
45112
<p>
46113
<a href="/manual/install.general.php">Installing PHP</a> is covered
47114
thoroughly in the PHP documentation.
48115
</p>
116+
-->
49117

50118
<h2>Binaries</h2>
51119

@@ -66,49 +134,7 @@
66134
</p>
67135

68136
<h2>Source Code</h2>
69-
<?php $i = 0; foreach ($RELEASES as $MAJOR => $major_releases): /* major releases loop start */
70-
$releases = array_slice($major_releases, 0, $SHOW_COUNT);
71-
?>
72-
<a id="v<?php echo $MAJOR; ?>"></a>
73-
<?php foreach ($releases as $v => $a): ?>
74-
<?php $mver = substr($v, 0, strrpos($v, '.')); ?>
75-
<?php $stable = $i++ === 0 ? "Current Stable" : "Old Stable"; ?>
76-
77-
<h3 id="v<?php echo $v; ?>" class="title">
78-
<span class="release-state"><?php echo $stable; ?></span>
79-
PHP <?php echo $v; ?>
80-
(<a href="/ChangeLog-<?php echo $MAJOR; ?>.php#<?php echo urlencode($v); ?>" class="changelog">Changelog</a>)
81-
</h3>
82-
<div class="content-box">
83-
84-
<ul>
85-
<?php foreach ($a['source'] as $rel): ?>
86-
<li>
87-
<?php download_link($rel['filename'], $rel['filename']); ?>
88-
<span class="releasedate"><?php echo date('d M Y', strtotime($rel['date'])); ?></span>
89-
<?php
90-
if (isset($rel['md5'])) echo '<span class="md5sum">', $rel['md5'], '</span>';
91-
if (isset($rel['sha256'])) echo '<span class="sha256">', $rel['sha256'], '</span>';
92-
?>
93-
<?php if (isset($rel['note']) && $rel['note']): ?>
94-
<p>
95-
<strong>Note:</strong>
96-
<?php echo $rel['note']; ?>
97-
</p>
98-
<?php endif; ?>
99-
</li>
100-
<?php endforeach; ?>
101-
<li>
102-
<a href="https://windows.php.net/download#php-<?php echo urlencode($mver); ?>">
103-
Windows downloads
104-
</a>
105-
</li>
106-
</ul>
107-
108-
<a href="#gpg-<?php echo $mver; ?>">GPG Keys for PHP <?php echo $mver; ?></a>
109-
</div>
110-
<?php endforeach; ?>
111-
<?php endforeach; /* major releases loop end */ ?>
137+
<?php show_source_releases(); ?>
112138

113139
<hr>
114140
<h2>GPG Keys</h2>

include/header.inc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@ foreach($css_files as $filename) {
2323
$CSS[$filename] = @filemtime($path);
2424
}
2525

26+
if (isset($config["js_files"])) {
27+
foreach($config['js_files'] as $filename) {
28+
$path = dirname(__DIR__) . $filename;
29+
$JS[$filename] = @filemtime($path);
30+
}
31+
}
32+
2633
if (isset($shortname) && $shortname) {
2734
header("Link: <$shorturl>; rel=shorturl");
2835
}
@@ -85,6 +92,10 @@ if (!isset($config["languages"])) {
8592
<link rel="stylesheet" type="text/css" href="/cached.php?t=<?php echo $modified?>&amp;f=<?php echo $filename?>" media="screen">
8693
<?php endforeach ?>
8794

95+
<?php foreach($JS as $filename => $modified): ?>
96+
<script type="text/javascript" src="/cached.php?t=<?php echo $modified?>&amp;f=<?php echo $filename?>"></script>
97+
<?php endforeach ?>
98+
8899
<?php if (!empty($_SERVER["BASE_HREF"])): ?>
89100
<base href="<?php echo $_SERVER["BASE_HREF"] ?>">
90101
<?php endif ?>

include/version.inc

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,3 +107,55 @@ function release_get_latest() {
107107

108108
return [$version, $current];
109109
}
110+
111+
function show_source_releases()
112+
{
113+
global $RELEASES;
114+
115+
$SHOW_COUNT = 4;
116+
117+
$i = 0; foreach ($RELEASES as $MAJOR => $major_releases): /* major releases loop start */
118+
$releases = array_slice($major_releases, 0, $SHOW_COUNT);
119+
?>
120+
<a id="v<?php echo $MAJOR; ?>"></a>
121+
<?php foreach ($releases as $v => $a): ?>
122+
<?php $mver = substr($v, 0, strrpos($v, '.')); ?>
123+
<?php $stable = $i++ === 0 ? "Current Stable" : "Old Stable"; ?>
124+
125+
<h3 id="v<?php echo $v; ?>" class="title">
126+
<span class="release-state"><?php echo $stable; ?></span>
127+
PHP <?php echo $v; ?>
128+
(<a href="/ChangeLog-<?php echo $MAJOR; ?>.php#<?php echo urlencode($v); ?>" class="changelog">Changelog</a>)
129+
</h3>
130+
<div class="content-box">
131+
132+
<ul>
133+
<?php foreach ($a['source'] as $rel): ?>
134+
<li>
135+
<?php download_link($rel['filename'], $rel['filename']); ?>
136+
<span class="releasedate"><?php echo date('d M Y', strtotime($rel['date'])); ?></span>
137+
<?php
138+
if (isset($rel['md5'])) echo '<span class="md5sum">', $rel['md5'], '</span>';
139+
if (isset($rel['sha256'])) echo '<span class="sha256">', $rel['sha256'], '</span>';
140+
?>
141+
<?php if (isset($rel['note']) && $rel['note']): ?>
142+
<p>
143+
<strong>Note:</strong>
144+
<?php echo $rel['note']; ?>
145+
</p>
146+
<?php endif; ?>
147+
</li>
148+
<?php endforeach; ?>
149+
<li>
150+
<a href="https://windows.php.net/download#php-<?php echo urlencode($mver); ?>">
151+
Windows downloads
152+
</a>
153+
</li>
154+
</ul>
155+
156+
<a href="#gpg-<?php echo $mver; ?>">GPG Keys for PHP <?php echo $mver; ?></a>
157+
</div>
158+
<?php endforeach; ?>
159+
<?php endforeach; /* major releases loop end */ ?>
160+
<?php
161+
}

js/version-choice.js

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
function setSelectBoxes() {
2+
let instructionsDiv = document.getElementById("instructions")
3+
let osSelector = document.getElementById("os")
4+
let variantSelector = document.getElementById("osvariant")
5+
let usageSelector = document.getElementById("usage")
6+
let versionSelector = document.getElementById("version")
7+
let multiversionBox = document.getElementById("multiversion")
8+
9+
const url = '/downloads-get-instructions.php' +
10+
'?os=' + osSelector.options[osSelector.selectedIndex].value +
11+
'&osvariant=' + variantSelector.options[variantSelector.selectedIndex].value +
12+
'&usage=' + usageSelector.options[usageSelector.selectedIndex].value +
13+
'&version=' + versionSelector.options[versionSelector.selectedIndex].value +
14+
'&multiversion=' + multiversionBox.checked
15+
16+
fetch(url)
17+
.then(response => {
18+
if (response.ok) {
19+
return response.text()
20+
} else {
21+
throw new Error("Couldn't fetch instructions");
22+
}
23+
})
24+
.then(data => {
25+
instructionsDiv.innerHTML = data
26+
})
27+
.catch(error => console.error("Couldn't fetch instructions: ", error));
28+
}
29+
30+
function setSelectOsBoxes() {
31+
let osSelector = document.getElementById("os")
32+
let variantSelector = document.getElementById("osvariant")
33+
34+
for (var i = variantSelector.length - 1; i >= 0; i--) {
35+
if (!variantSelector.options[i].value.startsWith(osSelector.options[osSelector.selectedIndex].value + "-")) {
36+
variantSelector.options[i].disabled = true
37+
} else {
38+
variantSelector.options[i].disabled = false
39+
variantSelector.selectedIndex = i
40+
}
41+
}
42+
43+
setSelectBoxes();
44+
}
45+
46+
window.onload = function() {
47+
let osSelector = document.getElementById("os")
48+
let variantSelector = document.getElementById("osvariant")
49+
let usageSelector = document.getElementById("usage")
50+
let versionSelector = document.getElementById("version")
51+
let multiversionBox = document.getElementById("multiversion")
52+
53+
osSelector.addEventListener("change", setSelectOsBoxes)
54+
variantSelector.addEventListener("change", setSelectBoxes)
55+
usageSelector.addEventListener("change", setSelectBoxes)
56+
versionSelector.addEventListener("change", setSelectBoxes)
57+
multiversionBox.addEventListener("change", setSelectBoxes)
58+
59+
setSelectOsBoxes()
60+
}

0 commit comments

Comments
 (0)