|
35 | 35 | ],
|
36 | 36 | ],
|
37 | 37 | "current" => "downloads",
|
38 |
| - "js_files" => [ |
39 |
| - "/js/version-choice.js", |
40 |
| - ], |
41 | 38 | ],
|
42 | 39 | );
|
43 | 40 |
|
44 |
| -function option(string $id, string $value, string $desc) |
| 41 | +function option(string $value, string $desc, $attributes = []): string |
45 | 42 | {
|
46 |
| - $selected = ''; |
47 |
| - if (array_key_exists($id, $_GET) && $_GET[$id] === $value) { |
48 |
| - $selected = ' selected'; |
49 |
| - } |
| 43 | + return '<option value="' . $value . '"' . implode(' ', array_keys(array_filter($attributes))) . '>' . $desc . '</option>'; |
| 44 | +} |
50 | 45 |
|
51 |
| - echo <<<ENDOPT |
52 |
| - <option value="{$value}"{$selected}>{$desc}</option> |
| 46 | +$usage = [ |
| 47 | + 'web' => 'Web Development', |
| 48 | + 'cli' => 'Command Line Libraries', |
| 49 | + 'fw-drupal' => 'Drupal', |
| 50 | + 'fw-laravel' => 'Laravel', |
| 51 | + 'fw-symfony' => 'Symfony', |
| 52 | +]; |
| 53 | + |
| 54 | +$os = [ |
| 55 | + 'linux' => [ |
| 56 | + 'name' => 'Linux', |
| 57 | + 'variants' => [ |
| 58 | + 'linux-deb-buster' => 'Debian Buster', |
| 59 | + 'linux-deb-bullseye' => 'Debian Bullseye', |
| 60 | + 'linux-deb-bookworm' => 'Debian Bookworm', |
| 61 | + 'linux-rpm-fedora41' => 'Fedora 41', |
| 62 | + 'linux-rpm-fedora42' => 'Fedora 42', |
| 63 | + 'linux-rpm-redhat' => 'RedHat', |
| 64 | + ], |
| 65 | + ], |
| 66 | + 'osx' => [ |
| 67 | + 'name' => 'macOS', |
| 68 | + 'variants' => [ |
| 69 | + 'osx-latest' => 'macOS Latest', |
| 70 | + ], |
| 71 | + ], |
| 72 | + 'windows' => [ |
| 73 | + 'name' => 'Windows', |
| 74 | + 'variants' => [ |
| 75 | + 'windows-wsl' => 'Windows with WSL', |
| 76 | + 'windows-normal' => 'Windows without WSL', |
| 77 | + ], |
| 78 | + ], |
| 79 | +]; |
| 80 | + |
| 81 | +$defaults = [ |
| 82 | + 'os' => 'linux', |
| 83 | + 'version' => 'php84', |
| 84 | + 'usage' => 'web', |
| 85 | +]; |
53 | 86 |
|
54 |
| -ENDOPT; |
| 87 | +$options = array_merge($defaults, $_GET); |
| 88 | +if (!array_key_exists('osvariant', $options) || !array_key_exists($options['osvariant'], $os[$options['os']]['variants'])) { |
| 89 | + $options['osvariant'] = array_key_first($os[$options['os']]['variants']); |
55 | 90 | }
|
56 | 91 | ?>
|
57 | 92 | <h1>Downloads & Installation Instructions</h1>
|
58 | 93 |
|
59 |
| -<form class="instructions-form"> |
| 94 | + <form class="instructions-form" id="instructions-form"> |
60 | 95 | <div class="instructions-row">
|
61 | 96 | I want to use PHP for
|
62 | 97 | <select id="usage" name="usage">
|
63 |
| - <?= option('usage', 'web', 'Web Development'); ?> |
64 |
| - <?= option('usage', 'cli', 'Command Line Libraries'); ?> |
65 |
| - <?= option('usage', 'fw-drupal', 'Drupal'); ?> |
66 |
| - <?= option('usage', 'fw-laravel', 'Laravel'); ?> |
67 |
| - <?= option('usage', 'fw-symfony', 'Symfony'); ?> |
| 98 | + <?php foreach ($usage as $value => $description) { ?> |
| 99 | + <?= option($value, $description); ?> |
| 100 | + <?php } ?> |
68 | 101 | </select>.
|
69 | 102 | </div>
|
70 | 103 |
|
71 | 104 | <div class="instructions-row">
|
72 | 105 | I work with
|
73 | 106 | <select id="os" name="os">
|
74 |
| - <?= option('os', 'linux', 'Linux'); ?> |
75 |
| - <?= option('os', 'osx', 'OSX'); ?> |
76 |
| - <?= option('os', 'windows', 'Windows'); ?> |
| 107 | + <?php foreach ($os as $value => $item) { ?> |
| 108 | + <?= option($value, $item['name'], [ |
| 109 | + 'selected' => array_key_exists('os', $options) && $options['os'] === $value, |
| 110 | + ]); ?> |
| 111 | + <?php } ?> |
77 | 112 | </select>
|
78 |
| - <select id="osvariant" name="osvariant"> |
79 |
| - <?= option('osvariant', 'linux-deb-buster', 'Debian Buster'); ?> |
80 |
| - <?= option('osvariant', 'linux-deb-bullseye', 'Debian Bullseye'); ?> |
81 |
| - <?= option('osvariant', 'linux-deb-bookworm', 'Debian Bookworm'); ?> |
82 |
| - <?= option('osvariant', 'linux-rpm-fedora41', 'Fedora 41'); ?> |
83 |
| - <?= option('osvariant', 'linux-rpm-fedora42', 'Fedora 42'); ?> |
84 |
| - <?= option('osvariant', 'linux-rpm-redhat', 'RedHat'); ?> |
85 |
| - <?= option('osvariant', 'osx-latest', 'Latest'); ?> |
86 |
| - <?= option('osvariant', 'windows-wsl', 'with WSL'); ?> |
87 |
| - <?= option('osvariant', 'windows-normal', 'without WSL'); ?> |
88 |
| - </select>, |
| 113 | + |
| 114 | + <?php if (array_key_exists('os', $options) && array_key_exists('osvariant', $options)) { ?> |
| 115 | + <select id="osvariant" name="osvariant"> |
| 116 | + <?php foreach ($os[$options['os']]['variants'] as $value => $description) { ?> |
| 117 | + <?= option($value, $description, [ |
| 118 | + 'selected' => $options['osvariant'] === $value, |
| 119 | + ]); ?> |
| 120 | + <?php } ?> |
| 121 | + </select> |
| 122 | + <?php } ?>, |
89 | 123 | and use
|
90 | 124 | <select id="version" name="version">
|
91 |
| - <?= option('version', 'php84', 'version 8.4'); ?> |
92 |
| - <?= option('version', 'php83', 'version 8.3'); ?> |
93 |
| - <?= option('version', 'php82', 'version 8.2'); ?> |
94 |
| - <?= option('version', 'php81', 'version 8.1'); ?> |
95 |
| - <?= option('version', 'default', 'OS default version'); ?> |
| 125 | + <?= option('php84', 'version 8.4'); ?> |
| 126 | + <?= option('php83', 'version 8.3'); ?> |
| 127 | + <?= option('php82', 'version 8.2'); ?> |
| 128 | + <?= option('php81', 'version 8.1'); ?> |
| 129 | + <?= option('default', 'OS default version'); ?> |
96 | 130 | </select>
|
97 | 131 | </div>
|
98 | 132 |
|
99 | 133 | <label for="multiversion" class="instructions-label">
|
100 | 134 | I want to be able to use multiple PHP versions:
|
101 | 135 | <input type="checkbox" id="multiversion" name="multiversion" value="Y"
|
102 |
| - <?= array_key_exists('multiversion', $_GET) && $_GET['multiversion'] === 'Y' ? 'checked' : '' ?>/> |
| 136 | + <?= array_key_exists('multiversion', $options) && $options['multiversion'] === 'Y' ? 'checked' : '' ?>/> |
103 | 137 | </label>
|
104 | 138 |
|
105 | 139 | <label for="source" class="instructions-label">
|
106 | 140 | I want to compile everything from source:
|
107 | 141 | <input type="checkbox" id="source" name="source" value="Y"
|
108 |
| - <?= array_key_exists('source', $_GET) && $_GET['source'] === 'Y' ? 'checked' : '' ?>/> |
| 142 | + <?= array_key_exists('source', $options) && $options['source'] === 'Y' ? 'checked' : '' ?>/> |
109 | 143 | </label>
|
110 | 144 |
|
111 |
| - <div> |
112 |
| - <button type="submit" class="button">Get Instructions</button> |
113 |
| - </div> |
| 145 | + <noscript> |
| 146 | + <button type="submit" class="button">Update Instructions</button> |
| 147 | + </noscript> |
114 | 148 | </form>
|
115 | 149 |
|
116 | 150 | <h2>Instructions</h2>
|
@@ -156,5 +190,15 @@ function option(string $id, string $value, string $desc)
|
156 | 190 | </a>
|
157 | 191 | </p>
|
158 | 192 |
|
| 193 | + <script> |
| 194 | + window.onload = function () { |
| 195 | + let form = document.getElementById("instructions-form") |
| 196 | + |
| 197 | + form.addEventListener('change', function () { |
| 198 | + form.submit(); |
| 199 | + }); |
| 200 | + } |
| 201 | + </script> |
| 202 | + |
159 | 203 | <?php
|
160 | 204 | site_footer(['sidebar' => $SIDEBAR_DATA]);
|
0 commit comments