xref: /web-php/releases/index.php (revision 59c070f5)
1<?php
2
3$_SERVER['BASE_PAGE'] = 'releases/index.php';
4include_once __DIR__ . '/../include/prepend.inc';
5include_once __DIR__ . "/../include/branches.inc";
6
7if (isset($_GET["serialize"]) || isset($_GET["json"])) {
8    $RELEASES = $RELEASES + $OLDRELEASES;
9
10    $machineReadable = [];
11
12    $supportedVersions = [];
13    foreach (get_active_branches(false) as $major => $releases) {
14        $supportedVersions[$major] = array_keys($releases);
15    }
16
17    if (isset($_GET["version"])) {
18        $versionArray = version_array($_GET["version"]);
19        $ver = $versionArray[0];
20
21        if (isset($RELEASES[$ver])) {
22            $combinedReleases = array_replace_recursive($RELEASES, $OLDRELEASES);
23
24            $max = (int) ($_GET['max'] ?? 1);
25            if ($max == -1) {
26                $max = PHP_INT_MAX;
27            }
28
29            $count = 0;
30            foreach ($combinedReleases[$ver] as $version => $release) {
31                if ($max <= $count) {
32                    break;
33                }
34
35                if (compare_version($versionArray, $version) == 0) {
36                    if (!isset($_GET['max'])) {
37                        $release['supported_versions'] = $supportedVersions[$ver] ?? [];
38                    }
39                    $machineReadable[$version] = $release;
40                    $count++;
41                }
42            }
43
44            if (!isset($_GET['max']) && !empty($machineReadable)) {
45                $version = key($machineReadable);
46                $machineReadable = current($machineReadable);
47                $machineReadable["version"] = $version;
48            }
49        }
50
51        if (empty($machineReadable)) {
52            $machineReadable = ["error" => "Unknown version"];
53        }
54    } else {
55        foreach ($RELEASES as $major => $release) {
56            $version = key($release);
57            $r = current($release);
58            $r["version"] = $version;
59            $r['supported_versions'] = $supportedVersions[$major] ?? [];
60            $machineReadable[$major] = $r;
61        }
62    }
63
64    if (isset($_GET["serialize"])) {
65        header('Content-type: text/plain');
66        echo serialize($machineReadable);
67    } elseif (isset($_GET["json"])) {
68        header('Content-Type: application/json');
69        echo json_encode($machineReadable);
70    }
71    return;
72}
73
74// Human Readable.
75site_header("Releases", [
76    'current' => 'downloads',
77    'css' => '/styles/releases.css',
78]);
79
80echo "<h1>Unsupported Historical Releases</h1>\n\n";
81echo "<p>
82 We have collected all the official information and code available for
83 past PHP releases. You can find more details on the current release
84 on <a href=\"/downloads.php\">our downloads page</a>. Please note that
85 <em>older releases are listed for archival purposes only, and
86 they are no longer supported</em>.
87</p>\n";
88
89$active_majors = array_keys($RELEASES);
90$latest = max($active_majors);
91foreach ($OLDRELEASES as $major => $a) {
92    echo '<a id="v' . $major . '"></a>';
93    if (!in_array($major, $active_majors, false)) {
94        echo "\n<br>\n";
95        echo "<p>Support for PHP $major has been <b style=\"color: red;\">discontinued</b> ";
96        echo "since <b>" . current($a)['date'] . '</b>.';
97        echo "Please consider upgrading to $latest.</p>\n";
98    }
99
100    $i = 0;
101    foreach ($a as $ver => $release) {
102        $i++;
103        mk_rel(
104            $major,
105            $ver,
106            $release["date"],
107            $release["announcement"] ?? false,
108            $release["source"] ?? [],
109            $release["windows"] ?? [],
110            $release["museum"] ?? ($i >= 3),
111        );
112    }
113}
114
115site_footer(['sidebar' =>
116'<div class="panel">
117  <a class="headline" href="/supported-versions.php">Supported Versions</a>
118  <div class="body">
119    Check the <a href="/supported-versions.php">supported versions</a> page for
120    more information on the support lifetime of each version of PHP.
121  </div>
122</div>
123
124<div class="panel">
125  <a class="headline" href="/eol.php">End of Life Dates</a>
126  <div class="body">
127    <p>The most recent branches to reach end of life status are:</p>
128    <ul>' . recentEOLBranchesHTML() . '</ul>
129  </div>
130</div>
131
132<p class="panel">
133 <a href="/ChangeLog-7.php">PHP 7 ChangeLog</a>
134</p>
135<p class="panel">
136 <a href="/ChangeLog-5.php">PHP 5 ChangeLog</a>
137</p>
138<p class="panel">
139 <a href="/ChangeLog-4.php">PHP 4 ChangeLog</a>
140</p>
141
142<div class="panel">
143 <a href="http://museum.php.net/">PHP Museum</a>
144</div>
145
146<div class="panel">
147  <div class="headline">Want a PHP serialized list of the PHP releases?</div>
148  <div class="body">
149    <ul>
150      <li>Add <a href="?serialize">?serialize</a> to the url</li>
151      <li>Only want PHP 5 releases? <a href="?serialize&amp;version=5">&amp;version=5</a></li>
152      <li>The last 3? <a href="?serialize&amp;version=5&amp;max=3">&amp;max=3</a></li>
153    </ul>
154  </div>
155</div>
156
157<div class="panel">
158  <div class="headline">Want a JSON list of the PHP releases?</div>
159  <div class="body">
160    <ul>
161      <li>Add <a href="?json">?json</a> to the url</li>
162      <li>Only want PHP 5 releases? <a href="?json&amp;version=5">&amp;version=5</a></li>
163      <li>The last 3? <a href="?json&amp;version=5&amp;max=3">&amp;max=3</a></li>
164    </ul>
165  </div>
166</div>
167', ]);
168
169function recentEOLBranchesHTML(): string {
170    $eol = [];
171    foreach (get_eol_branches() as $branches) {
172        foreach ($branches as $branch => $detail) {
173            $detail_date = $detail['date'];
174            while (isset($eol[$detail_date])) $detail_date++;
175            $eol[$detail_date] = sprintf('<li>%s: %s</li>', $branch, date('j M Y', $detail_date));
176        }
177    }
178    krsort($eol);
179    return implode('', array_slice($eol, 0, 2));
180}
181
182/**
183 * @param bool|array $announcement
184 */
185function mk_rel(int $major,
186                string $ver,
187                string $date,
188                $announcement,
189                array $source,
190                array $windows,
191                bool $museum): void {
192    printf("<a id=\"%s\"></a>\n<h2>%1\$s</h2>\n<ul>\n <li>Released: %s</li>\n <li>Announcement: ",
193           ($pos = strpos($ver, " ")) ? substr($ver, 0, $pos) : $ver,
194           $date);
195
196    if ($announcement) {
197        if (is_array($announcement)) {
198            foreach ($announcement as $ann => $url) {
199                echo "<a href=\"$url\">$ann</a> ";
200            }
201        } else {
202            $url = str_replace(".", "_", $ver);
203            echo "<a href=\"/releases/{$url}.php\">English</a>";
204        }
205    } else {
206        echo "None";
207    }
208    echo "</li>\n";
209
210    if ($major > 3) {
211        echo " <li><a href=\"/ChangeLog-{$major}.php#{$ver}\">ChangeLog</a></li>";
212    }
213    echo "\n <li>\n  Download:\n";
214    echo "<ul>\n";
215
216    if (!$museum) {
217        foreach (array_merge($source, $windows) as $src) {
218            echo " <li>\n";
219            if (isset($src['filename'])) {
220                download_link($src["filename"], $src["name"]); echo "<br>\n";
221                $linebreak = '';
222                foreach (['md5', 'sha256'] as $cs) {
223                    if (isset($src[$cs])) {
224                        echo $linebreak;
225                        echo "<span class=\"{$cs}sum\">{$cs}: {$src[$cs]}</span>\n";
226                        $linebreak = "<br/>";
227                    }
228                }
229            } else {
230                echo "<a href=\"{$src['link']}\">{$src['name']}</a>";
231            }
232            echo " </li>\n";
233        }
234
235    } else { /* $museum */
236        foreach ($source as $src) {
237            if (!isset($src["filename"])) {
238                continue;
239            }
240            printf('<li><a href="http://museum.php.net/php%d/%s">%s</a></li>',
241                   $major, $src["filename"], $src["name"]);
242        }
243        foreach ($windows as $src) {
244            printf('<li><a href="http://museum.php.net/%s/%s">%s</a></li>',
245                   ($major == 5 ? "php5" : "win32"), $src["filename"], $src["name"]);
246        }
247    }
248
249    echo "</ul>\n";
250    echo "</li>\n";
251    echo "</ul>\n";
252}
253