Created
November 17, 2019 08:20
-
-
Save delphinpro/65d5865c486fab94e9af504e290aee31 to your computer and use it in GitHub Desktop.
Загрузчик инсталлятора Evo2.0
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$InstallData = EvoInstaller::getPackageInfo(); | |
EvoInstaller::doInstall('2.0'); | |
class EvoInstaller{ | |
static public function downloadFile ($url, $path) { | |
$newfname = $path; | |
$rs = file_get_contents($url); | |
if($rs) $rs = file_put_contents($newfname,$rs); | |
return $rs; | |
} | |
static public function moveFiles($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) && $object->isFile()) { | |
rename((string)$name, $dest.$startsAt.'/'.basename($name)); | |
} | |
} | |
} | |
static public function mmkDir($folder, $perm=0777) { | |
if(!is_dir($folder)) { | |
mkdir($folder, $perm); | |
} | |
} | |
static public function doInstall($ver) { | |
echo 'Download installer...'.PHP_EOL; | |
$InstallData = SELF::getPackageInfo(); | |
$rowInstall = $InstallData[$ver]; | |
$base_dir = str_replace('\\','/',__DIR__); | |
$temp_dir = str_replace('\\','/',__DIR__).'/_temp'.md5(time()); | |
//run unzip and install | |
SELF::downloadFile($rowInstall['link'] ,'evo.zip'); | |
$zip = new ZipArchive; | |
$res = $zip->open($base_dir.'/evo.zip'); | |
$zip->extractTo($temp_dir); | |
$zip->close(); | |
unlink($base_dir.'/evo.zip'); | |
if ($handle = opendir($temp_dir)) { | |
while (false !== ($name = readdir($handle))) { | |
if ($name != '.' && $name != '..') $dir = $name; | |
} | |
closedir($handle); | |
} | |
SELF::moveFiles($temp_dir.'/'.$dir, $base_dir.'/'); | |
SELF::rmdirs($temp_dir); | |
unlink(__FILE__); | |
echo 'Complete'.PHP_EOL; | |
exit; | |
} | |
static public function rmdirs($dir) { | |
if (is_dir($dir)) { | |
$objects = scandir($dir); | |
foreach ($objects as $object) { | |
if ($object != "." && $object != "..") { | |
if (is_dir($dir."/".$object) && !is_link($dir."/".$object)) | |
self::rmdirs($dir."/".$object); | |
else | |
unlink($dir."/".$object); | |
} | |
} | |
rmdir($dir); | |
} | |
} | |
static public function getPackageInfo() { | |
return array( | |
'2.0' => array( | |
'tree' => 'Evolution', | |
'name' => 'Evolution CMS 2.0', | |
'link' => 'https://github.com/evolution-cms/evolution/archive/2.0.zip', | |
'location' => 'install/index.php' | |
), | |
'2.0.x' => array( | |
'tree' => 'Evolution', | |
'name' => 'Evolution CMS 2(2.0.x develop version)', | |
'link' => 'https://github.com/evolution-cms/evolution/archive/2.0.x.zip', | |
'location' => 'install/index.php' | |
), | |
'1.4.10' => array( | |
'tree' => 'Evolution', | |
'name' => 'Evolution CMS 1.4.10', | |
'link' => 'https://github.com/evolution-cms/evolution/archive/1.4.10.zip', | |
'location' =>'install/index.php' | |
), | |
'1.4.x' => array( | |
'tree' => 'Evolution', | |
'name' => 'Evolution CMS (1.4.x develop version)', | |
'link' => 'https://github.com/evolution-cms/evolution/archive/1.4.x.zip', | |
'location' => 'install/index.php' | |
), | |
); | |
} | |
static public function hasDirPerm() { | |
$s = basename(__FILE__); | |
$r = __DIR__.'/_index_tmp.php'; | |
if ($s !== 'install.php') return false; | |
if (!@ copy(__FILE__,$r)) return false; | |
if (!@ unlink(__FILE__)) return false; | |
if (!@ copy($r,__FILE__)) return false; | |
if (!@ unlink($r)) return false; | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment