function CopyDirectory($srcdir, $destdir) { if (substr($srcdir, -1) == "/") { $srcdir = substr($srcdir, 0, -1); } if (substr($destdir, -1) == "/") { $destdir = substr($destdir, 0, -1); } @mkdir($destdir); $dir = opendir($srcdir); if ($dir) { while (($file = readdir($dir)) !== false) { if ($file != "." && $file != "..") { if (is_dir($srcdir . "/" . $file)) { CopyDirectory($srcdir . "/" . $file, $destdir . "/" . $file); } else { if (is_file($srcdir . "/" . $file)) { @copy($srcdir . "/" . $file, $destdir . "/" . $file); } } } } closedir($dir); } }
/** * Copy * Copy an autoresponder along with attachments, images etc. * * @param Int $oldid Autoresponderid of the autoresponder to copy. * * @see Load * @see Create * @see CopyDirectory * @see Save * * @return Boolean True if it copied the autoresponder, false otherwise. */ function Copy($oldid=0) { if ($oldid <= 0) { return array(false, false); } if (!$this->Load($oldid)) { return array(false, false); } $this->name = GetLang('CopyPrefix') . $this->name; $newid = $this->Create(); if (!$newid) { return array(false, false); } $this->Load($newid); $this->createdate = $this->GetServerTime(); $olddir = TEMP_DIRECTORY . '/autoresponders/' . $oldid; $newdir = TEMP_DIRECTORY . '/autoresponders/' . $newid; $status = CopyDirectory($olddir, $newdir); $this->textbody = str_replace('autoresponders/' . $oldid, 'autoresponders/' . $newid, $this->textbody); $this->htmlbody = str_replace('autoresponders/' . $oldid, 'autoresponders/' . $newid, $this->htmlbody); $this->Save(); return array(true, $status); }
/** * CopyFiles * @return Void Returns nothing */ function CopyFiles() { if (SENDSTUDIO_SAFE_MODE) { ?> <script> self.parent.parent.location = 'index.php?Page=Upgrade&Step=3'; </script> <?php return; } $dirs_to_copy = IEM::sessionGet('DirectoriesToCopy'); if (!$dirs_to_copy) { $dirs_to_copy = list_directories($GLOBALS['ROOTDIR'] . 'temp/images', null, true); IEM::sessionSet('DirectoriesToCopy', $dirs_to_copy); $dirs_copied = array(); IEM::sessionSet('DirectoriesCopied', $dirs_copied); $dirs_not_copied = array(); IEM::sessionSet('DirectoriesNotCopied', $dirs_not_copied); } $dirs_to_copy = IEM::sessionGet('DirectoriesToCopy'); $dirs_copied = IEM::sessionGet('DirectoriesCopied'); // Check if there is anything to copy if (count($dirs_to_copy) == 0) { ?> <script> self.parent.parent.location = 'index.php?Page=Upgrade&Step=3'; </script> <?php } if ($dirs_to_copy == $dirs_copied) { // copy attachments last. there won't be too many of these so we'll do it all in one step. $all_attachments = array(); $query = "SELECT AttachmentID, AttachmentFilename, AttachmentName FROM " . $GLOBALS['TABLEPREFIX'] . "attachments"; $result = mysql_query($query); while ($row = mysql_fetch_assoc($result)) { $all_attachments[$row['AttachmentID']] = array('filename' => $row['AttachmentFilename'], 'realname' => $row['AttachmentName']); } if (!empty($all_attachments)) { $query = "select ComposedID, AttachmentIDs from " . $GLOBALS['TABLEPREFIX'] . "composed_emails where attachmentids != ''"; $result = mysql_query($query); while ($row = mysql_fetch_assoc($result)) { $new_folder = TEMP_DIRECTORY . '/newsletters/' . $row['ComposedID']; CreateDirectory($new_folder); $attachments = explode(':', stripslashes($row['AttachmentIDs'])); foreach ($attachments as $k => $attachid) { $fname = basename($all_attachments[$attachid]['filename']); $file = $GLOBALS['ROOTDIR'] . 'temp/attachments/' . $fname; $realname = $all_attachments[$attachid]['realname']; copy($file, $new_folder . '/' . $realname); if (!SENDSTUDIO_SAFE_MODE) { @chmod($new_folder . '/' . $realname, 0644); } } } $query = "select AutoresponderID, AttachmentIDs from " . $GLOBALS['TABLEPREFIX'] . "autoresponders where attachmentids != ''"; $result = mysql_query($query); while ($row = mysql_fetch_assoc($result)) { $new_folder = TEMP_DIRECTORY . '/autoresponders/' . $row['ComposedID']; CreateDirectory($new_folder); $attachments = explode(':', stripslashes($row['AttachmentIDs'])); foreach ($attachments as $k => $attachid) { $fname = basename($all_attachments[$attachid]['filename']); $file = $GLOBALS['ROOTDIR'] . 'temp/attachments/' . $fname; $realname = $all_attachments[$attachid]['realname']; copy($file, $new_folder . '/' . $realname); if (!SENDSTUDIO_SAFE_MODE) { @chmod($new_folder . '/' . $realname, 0644); } } } } ?> <script> self.parent.parent.location = 'index.php?Page=Upgrade&Step=3'; </script> <?php return; } $listProcessed = count($dirs_copied); $listTotal = count($dirs_to_copy); $percentProcessed = 0; foreach ($dirs_to_copy as $p => $dir) { if (in_array($dir, $dirs_copied)) { continue; } $percentProcessed = ceil(($listProcessed / $listTotal)*100); echo "<script>\n"; echo sprintf("self.parent.UpdateStatusReport('%s');", "Files copied: {$listProcessed}/{$listTotal}"); echo sprintf("self.parent.UpdateStatus('%s', %d);", "Copying directory \\'{$dir}\\' to new location ...", $percentProcessed); echo "</script>\n"; flush(); echo 'Copying directory ' . str_replace($GLOBALS['ROOTDIR'], '', $dir) . ' to new location...<br/>'; $new_dir = str_replace($GLOBALS['ROOTDIR'] . 'temp/images', TEMP_DIRECTORY . '/user', $dir); $copied = CopyDirectory($dir, $new_dir); if (!$copied) { $dirs_not_copied[] = $dir; IEM::sessionSet('DirectoriesNotCopied', $dirs_not_copied); } $dirs_copied[] = $dir; IEM::sessionSet('DirectoriesCopied', $dirs_copied); $listProcessed++; } ?> <script> setTimeout('window.location="index.php?Page=Upgrade&Action=CopyFiles"', 1); </script> <?php }
/** * Copy * Copy a template along with attachments, images etc. * * @param Int $oldid Templateid of the template to copy. * * @see Load * @see Create * @see CopyDirectory * @see Save * * @return Boolean True if it copied the template, false otherwise. */ function Copy($oldid=0) { $oldid = (int)$oldid; if ($oldid <= 0) { return array(false, 'No ID'); } if (!$this->Load($oldid)) { return array(false, 'Unable to load old template.'); } $this->name = GetLang('CopyPrefix') . $this->name; $newid = $this->Create(); if (!$newid) { return array(false, 'Unable to create new template'); } $this->Load($newid); $olddir = TEMP_DIRECTORY . '/templates/' . $oldid; $newdir = TEMP_DIRECTORY . '/templates/' . $newid; $status = CopyDirectory($olddir, $newdir); $this->textbody = str_replace('templates/' . $oldid, 'templates/' . $newid, $this->textbody); $this->htmlbody = str_replace('templates/' . $oldid, 'templates/' . $newid, $this->htmlbody); $this->Save(); return array(true, $newid, $status); }
$data = str_replace(array("c:/Apache24/htdocs", "c:/Apache24", "DirectoryIndex index.html", "#ServerName www.example.com:80"), array($apache_docroot, $apache_root, "DirectoryIndex index.html index.php", "ServerName localhost"), $data); $pos = strpos($data, "LoadModule xml2enc_module modules/mod_xml2enc.so" . $lineend); if ($pos !== false) { $pos += strlen("LoadModule xml2enc_module modules/mod_xml2enc.so" . $lineend); $data2 = "LoadModule php5_module \"" . $basepath . "php/php5apache2_4.dll\"" . $lineend; $data2 .= "AddHandler application/x-httpd-php .php" . $lineend; $data2 .= $lineend; $data2 .= "PHPIniDir \"" . $basepath . "php\"" . $lineend; $data = substr($data, 0, $pos) . $data2 . substr($data, $pos); } file_put_contents($basepath2 . "apache/conf/httpd.conf", $data); } if (!is_dir($basepath2 . "apache/htdocs")) { CopyDirectory($basepath2 . "apache/orig-htdocs", $basepath2 . "apache/htdocs"); } if (!is_dir($basepath2 . "apache/logs")) { CopyDirectory($basepath2 . "apache/orig-logs", $basepath2 . "apache/logs"); } // Maria DB. if (!is_dir($basepath2 . "maria_db/data")) { CopyDirectory($basepath2 . "maria_db/orig-data", $basepath2 . "maria_db/data"); } if (!is_file($basepath2 . "maria_db/my.ini")) { copy($basepath2 . "maria_db/" . $maria_db_config, $basepath2 . "maria_db/my.ini"); } // PHP. if (!is_file($basepath2 . "php/php.ini")) { copy($basepath2 . "php/" . $php_config, $basepath2 . "php/php.ini"); } echo "Done.\n"; sleep(3);
$data = str_replace(array("c:/Apache24/htdocs", "c:/Apache24", "DirectoryIndex index.html", "#ServerName www.example.com:80"), array($apache_docroot, $apache_root, "DirectoryIndex index.html index.php", "ServerName localhost"), $data); $pos = strpos($data, "LoadModule xml2enc_module modules/mod_xml2enc.so" . $lineend); if ($pos !== false) { $pos += strlen("LoadModule xml2enc_module modules/mod_xml2enc.so" . $lineend); $data2 = "LoadModule php5_module \"" . $basepath . "php/php5apache2_4.dll\"" . $lineend; $data2 .= "AddHandler application/x-httpd-php .php" . $lineend; $data2 .= $lineend; $data2 .= "PHPIniDir \"" . $basepath . "php\"" . $lineend; $data = substr($data, 0, $pos) . $data2 . substr($data, $pos); } file_put_contents($basepath2 . "apache/conf/httpd.conf", $data); } if (!is_dir($basepath2 . "apache/htdocs")) { CopyDirectory($basepath2 . "apache/orig-htdocs", $basepath2 . "apache/htdocs"); } if (!is_dir($basepath2 . "apache/logs")) { CopyDirectory($basepath2 . "apache/orig-logs", $basepath2 . "apache/logs"); } // MySQL. if (!is_dir($basepath2 . "mysql/data")) { CopyDirectory($basepath2 . "mysql/orig-data", $basepath2 . "mysql/data"); } if (!is_file($basepath2 . "mysql/my.ini")) { copy($basepath2 . "mysql/" . $mysql_config, $basepath2 . "mysql/my.ini"); } // PHP. if (!is_file($basepath2 . "php/php.ini")) { copy($basepath2 . "php/" . $php_config, $basepath2 . "php/php.ini"); } echo "Done.\n"; sleep(3);
/** * MoveFiles * Moves uploaded images from temporary storage under a user's id - to it's final location - under the type and it's id. Eg newsletter/1. * * @param String $destination The destination (eg newsletter or template). * @param Int $id The destinations id. * * @see CreateDirectory * @see list_files * * @return Boolean Returns false if it can't create the paths or it can't copy the necessary files. Returns true if everything worked ok. */ function MoveFiles($destination=false, $id=0) { if (!$destination) {return false;} if($id <= 0){ return false; } $user = IEM::userGetCurrent(); $tempid = $user->userid . "_tmp"; $destinationdir = TEMP_DIRECTORY . '/' . $destination . '/' . $id; $tempdir = TEMP_DIRECTORY . '/' . $destination . '/' . $tempid; if(!file_exists($destinationdir)){ $createdir = CreateDirectory($destinationdir,TEMP_DIRECTORY,0777); if (!$createdir) {return false;} } //Get files from the 'temporary' folder, /destination/userid_tmp/, and move them to the final location if(CopyDirectory($tempdir, $destinationdir)){remove_directory($tempdir);} return true; }
function ProcessImageDirectory($mode) { echo "<h4>Processing Images</h4>\n<blockquote>\n"; CreateDir(TARGET_IMAGE_DIR); if ($mode == "docs" || $mode == 'print') { CopyFile(NUNIT_IMAGE_DIR, TARGET_IMAGE_DIR, "logo.gif"); CopyFile(NUNIT_IMAGE_DIR, TARGET_IMAGE_DIR, "langfilter.gif"); CopyFile(NUNIT_IMAGE_DIR, TARGET_IMAGE_DIR, "bulletOn.gif"); CopyFile(NUNIT_IMAGE_DIR, TARGET_IMAGE_DIR, "bulletOff.gif"); } else { CopyDirectory(NUNIT_IMAGE_DIR, TARGET_IMAGE_DIR); } echo "</blockquote>\n"; }
/** * CopyDirectory * Copies an entire directory structure from source to destination. Works recursively. * * @param String $source Source directory to copy. * @param String $destination Destination directory to create and copy to. * * @return Boolean Returns true if all files were worked ok, otherwise false. */ function CopyDirectory($source='', $destination='') { if (!$source || !$destination) { return false; } if (!is_dir($source)) { return false; } if (!CreateDirectory($destination)) { return false; } $files_to_copy = list_files($source, null, true); $status = true; if (is_array($files_to_copy)) { foreach ($files_to_copy as $pos => $name) { if (is_array($name)) { $dir = $pos; $status = CopyDirectory($source . '/' . $dir, $destination . '/' . $dir); } if (!is_array($name)) { $copystatus = copy($source . '/' . $name, $destination . '/' . $name); if ($copystatus) { chmod($destination . '/' . $name, 0644); } $status = $copystatus; } } return $status; } return false; }
/** * MoveFiles * Moves uploaded images from temporary storage under a user's id - to it's final location - under the type and it's id. Eg newsletter/1. * * @param String $destination The destination (eg newsletter or template). * @param Int $id The destinations id. * * @see CreateDirectory * @see list_files * * @return Boolean Returns false if it can't create the paths or it can't copy the necessary files. Returns true if everything worked ok. */ function MoveFiles($destination = false, $id = 0) { if (!$destination || !$id) { return false; } $destinationdir = TEMP_DIRECTORY . '/' . $destination . '/' . $id; $createdir = CreateDirectory($destinationdir); if (!$createdir) { return false; } $user = IEM::getCurrentUser(); $sourcedir = TEMP_DIRECTORY . '/user/' . $user->userid; $file_list = list_files($sourcedir); $dir_list = list_directories($sourcedir); if (empty($file_list) && empty($dir_list)) { return true; } $result = true; foreach ($file_list as $p => $filename) { if (!copy($sourcedir . '/' . $filename, $destinationdir . '/' . $filename)) { $result = false; } } if ($result) { foreach ($dir_list as $dir) { $dirname = str_replace($sourcedir, '', $dir); if ($dirname == 'attachments') { continue; } $copy_dir_result = CopyDirectory($dir, $destinationdir . $dirname); if (!$copy_dir_result) { $resut = false; } } } return $result; }
} else { if ($result["response"]["code"] != 200) { DownloadFailed("Error retrieving URL. Server returned: " . $result["response"]["code"] . " " . $result["response"]["meaning"]); } } $baseurl = $result["url"]; $html->load($result["body"]); $rows = $html->find("a[href]"); foreach ($rows as $row) { if (preg_match('/^\\/downloads\\/releases\\/php-(5\\.5\\.\\d+)-Win32-VC11-x86.zip$/', $row->href, $matches)) { echo "Found: " . $row->href . "\n"; echo "Latest version: " . $matches[1] . "\n"; echo "Currently installed: " . (isset($installed["php"]) ? $installed["php"] : "Not installed") . "\n"; if (!isset($installed["php"]) || $matches[1] != $installed["php"]) { DownloadAndExtract("php", ConvertRelativeToAbsoluteURL($baseurl, $row->href)); $extractpath = dirname(FindExtractedFile($stagingpath, "php.exe")) . "/"; @copy($installpath . "vc_redist/msvcr110.dll", $extractpath . "bin/msvcr110.dll"); echo "Copying staging files to final location...\n"; CopyDirectory($extractpath, $installpath . "php"); echo "Cleaning up...\n"; ResetStagingArea($stagingpath); $installed["php"] = $matches[1]; SaveInstalledData(); echo "PHP binaries updated to " . $matches[1] . ".\n\n"; } break; } } ResetStagingArea($stagingpath); rmdir($stagingpath); echo "Updating finished.\n\n";