array( 'tree' => 'Revolution', 'name' => 'MODX Revolution 2.8.3 Traditional (05.28.2021)', 'link' => 'https://modx.com/download/direct/modx-2.8.3-pl.zip', 'location' => 'setup/index.php' ), 'revo2.8.3-ad' => array( 'tree' => 'Revolution', 'name' => 'MODX Revolution 2.8.3 Advanced (05.28.2021)', 'link' => 'https://modx.com/download/direct/modx-2.8.3-pl-advanced.zip', 'location' => 'setup/index.php' ), 'revo2.8.3-sdk' => array( 'tree' => 'Revolution', 'name' => 'MODX Revolution 2.8.3 SDK (05.28.2021)', 'link' => 'https://modx.com/download/direct/modx-2.8.3-pl-sdk.zip', 'location' => 'setup/index.php' ), 'revo2.8.2-pl' => array( 'tree' => 'Revolution', 'name' => 'MODX Revolution 2.8.2 Traditional (04.28.2021)', 'link' => 'https://modx.com/download/direct/modx-2.8.2-pl.zip', 'location' => 'setup/index.php' ), 'revo2.8.2-ad' => array( 'tree' => 'Revolution', 'name' => 'MODX Revolution 2.8.2 Advanced (04.28.2021)', 'link' => 'https://modx.com/download/direct/modx-2.8.2-pl-advanced.zip', 'location' => 'setup/index.php' ), 'revo2.8.2-sdk' => array( 'tree' => 'Revolution', 'name' => 'MODX Revolution 2.8.2 SDK (04.28.2021)', 'link' => 'https://modx.com/download/direct/modx-2.8.2-pl-sdk.zip', 'location' => 'setup/index.php' ), 'revo2.8.1-pl' => array( 'tree' => 'Revolution', 'name' => 'MODX Revolution 2.8.1 Traditional (10.22.2020)', 'link' => 'https://modx.com/download/direct/modx-2.8.1-pl.zip', 'location' => 'setup/index.php' ), 'revo2.8.1-ad' => array( 'tree' => 'Revolution', 'name' => 'MODX Revolution 2.8.1 Advanced (10.22.2020)', 'link' => 'https://modx.com/download/direct/modx-2.8.1-pl-advanced.zip', 'location' => 'setup/index.php' ), 'revo2.8.1-sdk' => array( 'tree' => 'Revolution', 'name' => 'MODX Revolution 2.8.1 SDK (10.22.2020)', 'link' => 'https://modx.com/download/direct/modx-2.8.1-pl-sdk.zip', 'location' => 'setup/index.php' ), 'revo2.8.0-pl' => array( 'tree' => 'Revolution', 'name' => 'MODX Revolution 2.8.0 Traditional (10.06.2020)', 'link' => 'https://modx.com/download/direct/modx-2.8.0-pl.zip', 'location' => 'setup/index.php' ), 'revo2.8.0-ad' => array( 'tree' => 'Revolution', 'name' => 'MODX Revolution 2.8.0 Advanced (10.06.2020)', 'link' => 'https://modx.com/download/direct/modx-2.8.0-pl-advanced.zip', 'location' => 'setup/index.php' ), 'revo2.8.0-sdk' => array( 'tree' => 'Revolution', 'name' => 'MODX Revolution 2.8.0 SDK (10.06.2020)', 'link' => 'https://modx.com/download/direct/modx-2.8.0-pl-sdk.zip', 'location' => 'setup/index.php' ) ); class ModxInstaller { static public function downloadFile($url, $path, $method) { $newfname = $path; $newf = null; $file = null; if ($method == 'fopen') { try { $file = fopen($url, "rb"); if ($file) { $newf = fopen($newfname, "wb"); if ($newf) { while (!feof($file)) { fwrite($newf, fread($file, 1024 * 8), 1024 * 8); } } } } catch (Exception $e) { return 'ERROR:Download ' . $e->getMessage(); } if ($file) { fclose($file); } if ($newf) { fclose($newf); } return true; } elseif ($method == 'curl') { $newf = fopen($path, "wb"); if ($newf) { $ch = curl_init(str_replace(" ", "%20", $url)); curl_setopt($ch, CURLOPT_TIMEOUT, 50); curl_setopt($ch, CURLOPT_FILE, $newf); $safeMode = @ini_get('safe_mode'); $openBasedir = @ini_get('open_basedir'); if (empty($safeMode) && empty($openBasedir)) { curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); } else { curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false); $rch = curl_copy_handle($ch); $newurl = $url; curl_setopt($rch, CURLOPT_URL, $newurl); $header = curl_exec($rch); if (curl_errno($rch)) { $code = 0; } else { $code = curl_getinfo($rch, CURLINFO_HTTP_CODE); if ($code == 301 || $code == 302) { preg_match('/Location:(.*?)\n/i', $header, $matches); $newurl = trim(array_pop($matches)); } curl_close($rch); curl_setopt($ch, CURLOPT_URL, $newurl); } } $data = curl_exec($ch); curl_close($ch); } else { return ("Cannot create target file."); } } else { return 'Invalid method in call to downloadFile()'; } return true; } static public function removeFolder($path) { $dir = realpath($path); if (!is_dir($dir)) { return; } $it = new RecursiveDirectoryIterator($dir); $files = new RecursiveIteratorIterator($it, RecursiveIteratorIterator::CHILD_FIRST); foreach ($files as $file) { if ($file->getFilename() === '.' || $file->getFilename() === '..') { continue; } if ($file->isDir()) { rmdir($file->getRealPath()); } else { unlink($file->getRealPath()); } } rmdir($dir); } static public function copyFolder($src, $dest) { $path = realpath($src); $dest = realpath($dest); $objects = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path), RecursiveIteratorIterator::SELF_FIRST); foreach ($objects as $name => $object) { $startsAt = substr(dirname($name), strlen($path)); self::mmkDir($dest . $startsAt); if ($object->isDir()) { self::mmkDir($dest . substr($name, strlen($path))); } if (is_writable($dest . $startsAt) and $object->isFile()) { copy((string) $name, $dest . $startsAt . DIRECTORY_SEPARATOR . basename($name)); } } } static public function mmkDir($folder, $perm = 0755) { if (!is_dir($folder)) { mkdir($folder, $perm); } } } if (!empty($_GET['modx']) && is_scalar($_GET['modx']) && isset($InstallData[$_GET['modx']])) { $rowInstall = $InstallData[$_GET['modx']]; //run unzip and install $success = ModxInstaller::downloadFile($rowInstall['link'], "modx.zip", $method); if ($success !== true) { die($success); } $zip = new ZipArchive; $success = $zip->open(dirname(__FILE__) . "/modx.zip"); if ($success !== true) { die('Failed to open zip file'); } if (! is_dir(dirname(__FILE__) . '/temp')) { ModxInstaller::mmkDir(dirname(__FILE__) . '/temp'); } $success = $zip->extractTo(dirname(__FILE__) . '/temp/'); if ($success !== true) { $zip->close(); die('Failed to extract from zip file'); } $zip->close(); unlink(dirname(__FILE__) . '/modx.zip'); if ($handle = opendir(dirname(__FILE__) . '/temp')) { while (false !== ($name = readdir($handle))) { if ($name != "." && $name != "..") { $dir = $name; } } closedir($handle); } ModxInstaller::copyFolder(dirname(__FILE__) . '/temp/' . $dir, dirname(__FILE__) . '/'); ModxInstaller::removeFolder(dirname(__FILE__) . '/temp'); unlink(basename(__FILE__)); header('Location: ' . $rowInstall['location']); } else { $ItemGrid = array(); foreach ($InstallData as $ver => $item) { $ItemGrid[$item['tree']][$ver] = $item; } //@TODO : add check installer version echo ' MODX Installer v' . $version . '

MODXMODX Installer v' . $version . '

GitHub
'; echo '

Choose MODX version for Install

'; foreach ($ItemGrid as $tree => $item) { echo '

' . strtoupper($tree) . '

'; foreach ($item as $version => $itemInfo) { echo '
'; } echo '
'; } if ($method) { echo "

Using " . $method . "

"; echo '
'; } else { echo '

Cannot download the files - allow_url_fopen is not enabled on this server.

'; } echo '
'; } ?>