'; foreach ($iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source, RecursiveDirectoryIterator::SKIP_DOTS),RecursiveIteratorIterator::SELF_FIRST) as $item) { if (strpos($source.DIRECTORY_SEPARATOR.$iterator->getSubPathName(),"oldVersion")==false) { // Don't move backups, plugins or .git away $testPath = $source.DIRECTORY_SEPARATOR.$iterator->getSubPathName(); $testPath = str_replace("\\","/",$testPath); if (strpos($testPath,"/data/backups/")==false && strpos($testPath,"/plugins/")==false && strpos($testPath,"/.git/")==false) { if (!is_writeable($item)) { array_push($cantMoveArray,substr($item,count($source)+2)); } } } } if (count($cantMoveArray) > 0) { echo '
Sorry, there are dirs/files that cannot be moved. Please set write permissions on them so ICEcoder may move the old version, to make way for the new.

You can reload this page after making perms changes to check the list again.

'; for ($i=0; $i"; } die('
<< Back to ICEcoder'); } renameOldVersion(); } function renameOldVersion() { if (is_dir(PATH)) { echo 'Postfixing oldVersion dir with a timestamp...
'; rename(PATH,trim(PATH,"/")."-".time()); } copyOldVersion(); } function copyOldVersion() { if (!is_dir(PATH)) { echo 'Creating new oldVersion dir...
'; mkdir(PATH); } $source = "../"; $dest = PATH; echo 'Moving current ICEcoder files...
'; foreach ($iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source, RecursiveDirectoryIterator::SKIP_DOTS),RecursiveIteratorIterator::SELF_FIRST) as $item) { if (strpos($source.DIRECTORY_SEPARATOR.$iterator->getSubPathName(),"oldVersion")==false) { // Don't move backups, plugins or .git away $testPath = $source.DIRECTORY_SEPARATOR.$iterator->getSubPathName(); $testPath = str_replace("\\","/",$testPath); if (strpos($testPath,"/data/backups/")==false && strpos($testPath,"/plugins/")==false && strpos($testPath,"/.git/")==false) { if ($item->isDir()) { mkdir($dest.DIRECTORY_SEPARATOR.$iterator->getSubPathName(), 0755); } else { rename($item, $dest.DIRECTORY_SEPARATOR.$iterator->getSubPathName()); } } } } $icv_url = "https://icecoder.net/latest-version.txt"; echo 'Detecting current version of ICEcoder...
'; $icvInfo = getData($icv_url,'curl','Sorry, couldn\'t figure out latest version.'); echo 'Latest version of ICEcoder is '.$icvInfo.'
'; openZipNew($icvInfo); } function openZipNew($icvInfo) { echo 'Retrieving zip from ICEcoder site...
'; $source = 'ICEcoder v'.$icvInfo; $target = '../'; $remoteFile = 'https://icecoder.net/ICEcoder-v'.(str_replace(" beta", "-beta",$icvInfo)).'.zip'; $file = "../tmp/new-version.zip"; $fileData = getData($remoteFile,'curl','Sorry, couldn\'t get latest version zip file.'); echo 'Storing zip file...
'; file_put_contents($file, $fileData); $zip = new ZipArchive; $zip->open($file); echo 'Copying over zip dirs & files...
'; for($i=0; $i<$zip->numFiles; $i++) { $name = $zip->getNameIndex($i); // Skip files not in $source if (strpos($name, "{$source}/") !== 0) continue; // Determine output filename (removing the $source prefix and trimming traiing slashes) $file = $target.substr($name, strlen($source)+1); // Create the directories if necessary $dir = dirname($file); if (!is_dir($dir)) mkdir($dir, 0777, true); // Read from Zip and write to disk $fpr = $zip->getStream($name); if (!is_dir($file)) { $fpw = fopen($file, 'w'); while ($data = fread($fpr, 1024)) { fwrite($fpw, $data); } fclose($fpw); } fclose($fpr); } echo 'Finished copying over zip dirs & files...
'; copyOverSettings($icvInfo); } function transposeSettings($oldFile,$newFile,$saveFile) { echo '- Getting old and new settings...
'; // Get old and new settings and start a new $contents $oldSettingsContent = getData($oldFile); $oldSettingsArray = explode("\n",$oldSettingsContent); $newSettingsContent = getData($newFile); $newSettingsArray = explode("\n",$newSettingsContent); $contents = ""; echo '- Transposing settings...
'; // Now need to copy the old settings over to new settings... for ($i=0; $i -1) { $thisKey = explode('"',$newSettingsArray[$i]); } if (is_array($thisKey)) { $thisKey = $thisKey[1]; } // We set the new line to begin with $contentLine = $newSettingsArray[$i].PHP_EOL; for ($j=0; $j -1) { $contentLine = $oldSettingsArray[$j].PHP_EOL; // If the old setting we're copying over isn't replacing the last line and doesn't end in a comma (after an rtrim to remove line endings), and doesn't contain a comment, add one if ($i != count($newSettingsArray)-1 && substr(rtrim($contentLine),-1) != "," && strpos($contentLine,"//") == -1) { $contentLine = str_replace(PHP_EOL,",".PHP_EOL,$contentLine); } } } $contents .= $contentLine; } echo '- Saving old settings to new settings file...
'; $fh = fopen($saveFile, 'w') or die("Sorry, cannot update ".$saveFile); fwrite($fh, $contents); fclose($fh); } function copyOverSettings($icvInfo) { global $updateDone, $configSettings; // System settings echo 'Transposing system settings...
'; // Create a new config file if it doesn't exist yet. // The reason we create it, is so it has PHP write permissions, meaning we can update it later if (!file_exists(dirname(__FILE__)."/../data/".$configSettings)) { echo 'Creating new settings file...
'; // Include our params to make use of (as $newConfigSettingsFile) include(dirname(__FILE__)."/settings-system-params.php"); if ($fConfigSettings = fopen(dirname(__FILE__)."/../data/".$configSettings, 'w')) { fwrite($fConfigSettings, $newConfigSettingsFile); fclose($fConfigSettings); } else { die("Cannot update config file data/".$configSettings.". Please check write permissions on data/ and try again"); } } transposeSettings(PATH."data/template-system.php","config-settings.php","config-settings.php"); // Users template settings echo 'Transposing users template settings...
'; transposeSettings(PATH."data/template-users.php","template-users.php","template-users.php"); // Users settings files $fileList = scanDir(PATH."data/"); for ($i=0; $i -1) { echo 'Transposing users settings file '.$fileList[$i].'...
'; transposeSettings(PATH."data/".$fileList[$i],"template-users.php",$fileList[$i]); } } echo 'All update tasks completed...
'; $updateDone = true; } startUpdate(); if ($updateDone) { echo 'Updated successfully!

'; echo 'Restarting ICEcoder...'; echo ''; } else { echo 'Something appears to have gone wrong :-/

'; echo 'Please report bugs at https://github.com/ICEcoder/ICEcoder

'; echo 'You can recover the old version from ICEcoder\'s tmp dir'; } ?>