array(), 'latest' => '' ); /** * Load cache */ public function __construct() { // Load cache if exists and is fresh (not older then hour) $path = __DIR__.'/getjoomla.cache'; if ( file_exists($path) AND filemtime($path) > (time() - (60 * 15)) AND $buffer = json_decode(file_get_contents($path)) ) { $this->cache = $this->objectToArray($buffer); } } /** * Converts object to multidimensional array * * @param Object $object Object to conver * * @return Array */ protected function objectToArray($object) { $buffer = array(); foreach ($object AS $variable => $data) { if (is_object($data)) { $buffer[$variable] = $this->objectToArray($data); } else { $buffer[$variable] = $data; } } return $buffer; } /** * Get contents of a file via URL (http) * * @param String $url URL of a file. * * @return String */ protected function getURLContents($url){ if( function_exists('curl_init') ) { // Prepre CURL connection $this->prepareConnection($url); // Return response $buffer = curl_exec ($this->connection); } else { $options = $file_get_contents_options = array( 'ssl' => array( "verify_peer" => false, "verify_peer_name" => false ), 'http' => array( 'user_agent' => $_SERVER['HTTP_USER_AGENT'] ) ); $buffer = file_get_contents( $url, false, stream_context_create($options) ); } return $buffer; } /** * Prepare CURL connection. * * @param String $url URL to be used in connection. * @param String $handle File handle to be used in connection. */ protected function prepareConnection($url = null, $handle = null){ // Connection needs to be created if( !is_resource($this->connection) ) { // Initialise connection $this->connection = curl_init(); // Configure CURL curl_setopt($this->connection, CURLOPT_RETURNTRANSFER, true); curl_setopt($this->connection, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($this->connection, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); } // Set URL if( !is_null($url) ) { curl_setopt($this->connection, CURLOPT_URL, $url); } // Set File Handle if( !is_null($handle) ) { curl_setopt($this->connection, CURLOPT_TIMEOUT, 100); curl_setopt($this->connection, CURLOPT_FILE, $handle); curl_setopt($this->connection, CURLOPT_FOLLOWLOCATION, true); } } /** * Download a file to local filesystem. * * @param type $url * @param type $path * * @throws Exception */ protected function downloadFile($url, $path) { if( function_exists('curl_init') ) { // Create file handle $handle = fopen ($path, 'w+'); // Prepare CURL connection $this->prepareConnection($url, $handle); // Run CURL curl_exec($this->connection); $error = curl_error($this->connection); if( !empty($error) ) { throw new Exception('(Curl) '.$error, 502); } // Close file handle fclose($handle); // Close CURL connection curl_close($this->connection); } else { $options = $file_get_contents_options = array( 'ssl' => array( "verify_peer" => false, "verify_peer_name" => false ), 'http' => array( 'user_agent' => $_SERVER['HTTP_USER_AGENT'] ) ); file_put_contents( $path, file_get_contents( $url, false, stream_context_create($options) ) ); } } /** * Store cache */ public function __destruct() { if (!empty($this->cache['versions'])) { file_put_contents(__DIR__.'/getjoomla.cache', json_encode($this->cache)); } } /** * Get list of available Joomla! Releases * * @return Array */ public function getVersions() { if (empty($this->cache['versions'])) { $buffer = $this->getURLContents('https://api.github.com/repos/joomla/joomla-cms/releases'); $list = json_decode($buffer); // Search for full installation asset foreach ($list AS $version) { foreach( $version->assets AS $asset ) { if( stripos($asset->name, 'Full_Package.zip') ) { $url = $asset->browser_download_url; } } $this->cache['versions'][$version->name] = $url; } } return $this->cache['versions']; } /** * Get informations about latest Joomla! release * * @return String */ public function getLatestVersion() { if (empty($this->cache['latest'])) { $buffer = $this->getURLContents('https://api.github.com/repos/joomla/joomla-cms/releases/latest'); $tmp = json_decode($buffer); $this->cache['latest'] = $tmp->name; } return $this->cache['latest']; } /** * Download package, unpack it, install and redirect to * Joomla! installation page. * * @global String $baseURL Base URL for script. * @param String $url_zip URL to Joomla! installation package. * * @throws Exception */ public function prepare($url_zip){ global $baseURL; // Download zip $this->downloadFile($url_zip, __DIR__.'/joomla.zip'); // Remove this script unlink(__FILE__); unlink(__DIR__.'/getjoomla.cache'); // Unpack $package = new ZipArchive; if ($package->open(__DIR__.'/joomla.zip') === TRUE) { $package->extractTo(__DIR__); $package->close(); // Remove package unlink(__DIR__.'/joomla.zip'); $this->cache = null; } else { throw new Exception('Cannot extract joomla.zip', 502); } // Clone htaccess copy(__DIR__.'/htaccess.txt', __DIR__.'/.htaccess'); // Redierct to installation header('Location: '.$baseURL.'installation/index.php'); } /** * Check Class requirements * * @throws Exception */ public function checkRequirements(){ // Check if PHP can get remote contect if( !ini_get('allow_url_fopen') OR !function_exists('curl_init') ) { throw new Exception('This class require CURL or allow_url_fopen have to be enabled in PHP configuration.', 502); } // Check if server allow to extract zip files if( !class_exists('ZipArchive')) { throw new Exception('Class ZipArchive is not available in current PHP configuration.', 502); } } } // Create new Installer instance $installer = new Installer; // Run tasks try { // First check if server meets requirements $installer->checkRequirements(); // Get versions data $versions = $installer->getVersions(); $latest = $installer->getLatestVersion(); // If this is install task if (isset($_GET['install'])) { $installer->prepare($_GET['install']); } } catch (Exception $e) { die('ERROR: '.$e->getMessage()); } ?>
Just a crazy fast script to download and prepare Joomla! installation.
This script downloads selected release from Joomla! Github repository, unpacks it, creates .htaccess
, removes itself and then redirects you to Joomla! installation. In short: just select version and click install to run Joomla! installer.
This script is free for everyone. Im not responsible for any damage it can make. Remember to always have a copy of files you have on this server.
This script is released under GNU/GPL 3.0 license. Free for commercial and non-commercial usage.