Skip to content

Instantly share code, notes, and snippets.

@nielsnuebel
Created April 18, 2018 21:49
Show Gist options
  • Save nielsnuebel/8f96bee3a13c18e1ec18a050924e02e5 to your computer and use it in GitHub Desktop.
Save nielsnuebel/8f96bee3a13c18e1ec18a050924e02e5 to your computer and use it in GitHub Desktop.
<?php
$filetyp = 'zip';
if (isset($_GET['filetyp']))
{
switch ($_GET['filetyp']) {
case 'zip':
$filetyp = 'zip';
break;
case 'targz':
$filetyp = 'tar.gz';
break;
case 'tarbz2':
$filetyp = 'tar.bz2';
break;
defaul:
$filetyp = 'zip';
break;
}
}
// Fetch the current 3.x version from the downloads site API
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, 'https://downloads.joomla.org/api/v1/latest/cms');
$result = curl_exec($ch);
curl_close($ch);
if ($result === false) {
echo 'Could not fetch version data, please check your connection.' . PHP_EOL;
exit(1);
}
$data = json_decode($result, true);
foreach ($data['branches'] as $branch) {
if ($branch['branch'] === 'Joomla! 3') {
$version = $branch['version'];
}
}
if (!isset($version)) {
echo 'Joomla! 3.x version data not included in API response.' . PHP_EOL;
exit(1);
}
$urlVersion = str_replace('.', '-', $version);
$filename = "Joomla_$version-Stable-Full_Package." . $filetyp;
$fullFilePath = "https://downloads.joomla.org/cms/joomla3/$urlVersion/$filename";
header("Cache-Control: public, must-revalidate");
header('Cache-Control: pre-check=0, post-check=0, max-age=0');
header("Pragma: private");
header("Expires: 0");
header("Content-Description: File Transfer");
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
header("Content-Type: application/octet-stream");
header('Content-Disposition: attachment; filename="latest.' . $filetyp .'"');
header("Content-Transfer-Encoding: binary");
readfile($fullFilePath);
exit;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment