public static function backup($pSiteId, $pType, $pSubfolder, $pExclude, $excludebackup, $excludecache, $excludenonwp, $excludezip, $pFilename = null, $pFileNameUID = '', $pArchiveFormat = false, $pMaximumFileDescriptorsOverride = false, $pMaximumFileDescriptorsAuto = false, $pMaximumFileDescriptors = false, $pLoadFilesBeforeZip = false, $pid = false, $append = false) { if (trim($pFilename) == '') { $pFilename = null; } $backup_result = array(); //Creating a backup $website = MainWPDB::Instance()->getWebsiteById($pSiteId); $subfolder = str_replace('%sitename%', MainWPUtility::sanitize($website->name), $pSubfolder); $subfolder = str_replace('%url%', MainWPUtility::sanitize(MainWPUtility::getNiceURL($website->url)), $subfolder); $subfolder = str_replace('%type%', $pType, $subfolder); $subfolder = str_replace('%date%', MainWPUtility::date('Ymd'), $subfolder); $subfolder = str_replace('%task%', '', $subfolder); $subfolder = str_replace('%', '', $subfolder); $subfolder = MainWPUtility::removePreSlashSpaces($subfolder); $subfolder = MainWPUtility::normalize_filename($subfolder); if (!MainWPUtility::can_edit_website($website)) { throw new MainWPException('You are not allowed to backup this site'); } $websiteCleanUrl = $website->url; if (substr($websiteCleanUrl, -1) == '/') { $websiteCleanUrl = substr($websiteCleanUrl, 0, -1); } $websiteCleanUrl = str_replace(array('http://', 'https://', '/'), array('', '', '-'), $websiteCleanUrl); //Normal flow: use website & fallback to global if ($pMaximumFileDescriptorsOverride == false) { if ($website->maximumFileDescriptorsOverride == 1) { $maximumFileDescriptorsAuto = $website->maximumFileDescriptorsAuto == 1; $maximumFileDescriptors = $website->maximumFileDescriptors; } else { $maximumFileDescriptorsAuto = get_option('mainwp_maximumFileDescriptorsAuto'); $maximumFileDescriptors = get_option('mainwp_maximumFileDescriptors'); $maximumFileDescriptors = $maximumFileDescriptors === false ? 150 : $maximumFileDescriptors; } } else { if ($pArchiveFormat != 'global' && $pMaximumFileDescriptorsOverride == 1) { $maximumFileDescriptorsAuto = $pMaximumFileDescriptorsAuto == 1; $maximumFileDescriptors = $pMaximumFileDescriptors; } else { $maximumFileDescriptorsAuto = get_option('mainwp_maximumFileDescriptorsAuto'); $maximumFileDescriptors = get_option('mainwp_maximumFileDescriptors'); $maximumFileDescriptors = $maximumFileDescriptors === false ? 150 : $maximumFileDescriptors; } } $file = str_replace(array('%sitename%', '%url%', '%date%', '%time%', '%type%'), array(MainWPUtility::sanitize($website->name), $websiteCleanUrl, MainWPUtility::date('m-d-Y'), MainWPUtility::date('G\\hi\\ms\\s'), $pType), $pFilename); $file = str_replace('%', '', $file); $file = MainWPUtility::normalize_filename($file); //Normal flow: check site settings & fallback to global if ($pLoadFilesBeforeZip == false) { $loadFilesBeforeZip = $website->loadFilesBeforeZip; if ($loadFilesBeforeZip == 1) { $loadFilesBeforeZip = get_option('mainwp_options_loadFilesBeforeZip'); $loadFilesBeforeZip = $loadFilesBeforeZip == 1 || $loadFilesBeforeZip === false; } else { $loadFilesBeforeZip = $loadFilesBeforeZip == 2; } } else { if ($pArchiveFormat == 'global' || $pLoadFilesBeforeZip == 1) { $loadFilesBeforeZip = get_option('mainwp_options_loadFilesBeforeZip'); $loadFilesBeforeZip = $loadFilesBeforeZip == 1 || $loadFilesBeforeZip === false; } else { $loadFilesBeforeZip = $pLoadFilesBeforeZip == 2; } } //Nomral flow: check site settings & fallback to global if ($pArchiveFormat == false) { $archiveFormat = MainWPUtility::getCurrentArchiveExtension($website); } else { if ($pArchiveFormat == 'global') { $archiveFormat = MainWPUtility::getCurrentArchiveExtension(); } else { $archiveFormat = $pArchiveFormat; } } MainWPUtility::endSession(); $information = MainWPUtility::fetchUrlAuthed($website, 'backup', array('type' => $pType, 'exclude' => $pExclude, 'excludebackup' => $excludebackup, 'excludecache' => $excludecache, 'excludenonwp' => $excludenonwp, 'excludezip' => $excludezip, 'ext' => $archiveFormat, 'file_descriptors_auto' => $maximumFileDescriptorsAuto, 'file_descriptors' => $maximumFileDescriptors, 'loadFilesBeforeZip' => $loadFilesBeforeZip, MainWPUtility::getFileParameter($website) => $file, 'fileUID' => $pFileNameUID, 'pid' => $pid, 'append' => $append ? 1 : 0), false, false, false); do_action('mainwp_managesite_backup', $website, array('type' => $pType), $information); if (isset($information['error'])) { throw new MainWPException($information['error']); } else { if ($pType == 'db' && !$information['db']) { throw new MainWPException('Database backup failed.'); } else { if ($pType == 'full' && !$information['full']) { throw new MainWPException('Full backup failed.'); } else { if (isset($information['db'])) { if ($information['db'] != false) { $backup_result['url'] = $information['db']; $backup_result['type'] = 'db'; } else { if ($information['full'] != false) { $backup_result['url'] = $information['full']; $backup_result['type'] = 'full'; } } if (isset($information['size'])) { $backup_result['size'] = $information['size']; } $backup_result['subfolder'] = $subfolder; $dir = MainWPUtility::getMainWPSpecificDir($pSiteId); $fm_date = MainWPUtility::sanitize_file_name(MainWPUtility::date(get_option('date_format'))); $fm_time = MainWPUtility::sanitize_file_name(MainWPUtility::date(get_option('time_format'))); if ($pType == 'db') { $localBackupFile = $dir . 'db-' . $websiteCleanUrl . '-' . $fm_date . '-' . $fm_time . MainWPUtility::getRealExtension($information['db']); $localRegexFile = 'db-' . $websiteCleanUrl . '-(.*)-(.*).sql(\\.zip|\\.tar|\\.tar\\.gz|\\.tar\\.bz2)?'; } else { $localBackupFile = $dir . 'full-' . $websiteCleanUrl . '-' . $fm_date . '-' . $fm_time . MainWPUtility::getRealExtension($information['full']); $localRegexFile = 'full-' . $websiteCleanUrl . '-(.*)-(.*).(zip|tar|tar.gz|tar.bz2)'; } if ($pFilename != null) { $filename = str_replace(array('%sitename%', '%url%', '%date%', '%time%', '%type%'), array(MainWPUtility::sanitize($website->name), $websiteCleanUrl, $fm_date, $fm_time, $pType), $pFilename); $filename = str_replace('%', '', $filename); $localBackupFile = $dir . $filename; $localBackupFile = MainWPUtility::normalize_filename($localBackupFile); if ($pType == 'db') { $localBackupFile .= MainWPUtility::getRealExtension($information['db']); } else { $localBackupFile .= MainWPUtility::getRealExtension($information['full']); } } $backup_result['local'] = $localBackupFile; $backup_result['regexfile'] = $localRegexFile; return $backup_result; } else { throw new MainWPException('Database backup failed due to an undefined error'); } } } } }
public static function backup($pTaskId, $pSiteId, $pFileNameUID) { $backupTask = MainWPDB::Instance()->getBackupTaskById($pTaskId); $subfolder = str_replace('%task%', MainWPUtility::sanitize($backupTask->name), $backupTask->subfolder); if ($backupTask->archiveFormat == 'site') { $loadFilesBeforeZip = false; $maximumFileDescriptorsOverride = false; $maximumFileDescriptorsAuto = false; $maximumFileDescriptors = 150; $archiveFormat = false; } else { if ($backupTask->archiveFormat == 'global') { $loadFilesBeforeZip = false; $maximumFileDescriptorsOverride = false; $maximumFileDescriptorsAuto = false; $maximumFileDescriptors = 150; $archiveFormat = 'global'; } else { $loadFilesBeforeZip = $backupTask->loadFilesBeforeZip; $maximumFileDescriptorsOverride = $backupTask->archiveFormat == 'zip' && $backupTask->maximumFileDescriptorsOverride == 1; $maximumFileDescriptorsAuto = $backupTask->archiveFormat == 'zip' && $backupTask->maximumFileDescriptorsAuto == 1; $maximumFileDescriptors = $backupTask->maximumFileDescriptors; $archiveFormat = $backupTask->archiveFormat; } } return MainWPManageSites::backup($pSiteId, $backupTask->type, $subfolder, $backupTask->exclude, $backupTask->excludebackup, $backupTask->excludecache, $backupTask->excludenonwp, $backupTask->excludezip, $backupTask->filename, $pFileNameUID, $archiveFormat, $maximumFileDescriptorsOverride, $maximumFileDescriptorsAuto, $maximumFileDescriptors, $loadFilesBeforeZip); }
public static function render() { $news = get_option('mainwp_news'); $newstimestamp = get_option('mainwp_news_timestamp'); if ($newstimestamp === false || time() - $newstimestamp > 60 * 60 * 24) { try { $result = MainWPUtility::http_post("do=news", "mainwp.com", "/versioncontrol/rqst.php", 80, 'main', true); } catch (Exception $e) { MainWPLogger::Instance()->warning('An error occured when trying to reach the MainWP server: ' . $e->getMessage()); } //get news.. if (isset($result[1])) { $news = json_decode($result[1], true); MainWPUtility::update_option('mainwp_news', $news); MainWPUtility::update_option('mainwp_news_timestamp', time()); } } if (!is_array($news) || count($news) == 0) { //No news.. ?> <div>No news items found.</div> <?php return; } ?> <div> <div id="mainwp-news-tabs" class="mainwp-row" style="border-top: 0px"> <?php $newsCategories = array(); foreach ($news as $newsItem) { if (!in_array($newsItem['category'], $newsCategories)) { $newsCategories[] = $newsItem['category']; } } for ($i = 0; $i < count($newsCategories); $i++) { $category = $newsCategories[$i]; /** @var $class string */ if (count($newsCategories) == 1) { $class = 'single'; } else { if ($i == count($newsCategories) - 1) { $class = 'right'; } else { if ($i == 0) { $class = 'left'; } else { $class = 'mid'; } } } if ($category == 'MainWP') { $class .= ' mainwp_action_down'; } ?> <a class="mainwp_action <?php echo $class; ?> mainwp-news-tab" href="#" name="<?php echo MainWPUtility::sanitize($category); ?> "><?php _e($category, 'mainwp'); ?> </a><?php } ?> </div> <div id="mainwp-news-list"> <?php $category = ''; foreach ($news as $newsItem) { if ($category != $newsItem['category']) { if ($category != '') { echo '</div>'; } echo '<div class="mainwp-news-items" name="' . MainWPUtility::sanitize($newsItem['category']) . '" ' . ($newsItem['category'] == 'MainWP' ? '' : 'style="display: none;"') . '>'; } ?> <div class="mainwp-news-item" title="<?php echo MainWPUtility::sanitize($newsItem['title']); ?> "> <strong><?php echo $newsItem['title']; ?> </strong><br /> <?php echo $newsItem['body']; ?> <div style="text-align: right"><em>Submitted <?php if (isset($newsItem['submitter']) && $newsItem['submitter'] != '') { echo 'by <strong>' . $newsItem['submitter'] . '</strong> '; } ?> at <strong><?php echo MainWPUtility::formatTimestamp(MainWPUtility::getTimestamp($newsItem['timestamp'])); ?> </strong></em></div> </div> <?php if ($category != $newsItem['category']) { $category = $newsItem['category']; } } if ($category != '') { echo '</div>'; } ?> </div> </div> <?php }