public static function PostingBulk_handler($data, $website, &$output) { if (preg_match('/<mainwp>(.*)<\\/mainwp>/', $data, $results) > 0) { $result = $results[1]; $information = unserialize(base64_decode($result)); if (isset($information['added'])) { $output->ok[$website->id] = '1'; if (isset($information['link'])) { $output->link[$website->id] = $information['link']; } if (isset($information['added_id'])) { $output->added_id[$website->id] = $information['added_id']; } } else { if (isset($information['error'])) { $output->errors[$website->id] = __('Error - ', 'mainwp') . $information['error']; } else { $output->errors[$website->id] = __('Undefined error - please reinstall the MainWP Child plugin on the client', 'mainwp'); } } } else { $output->errors[$website->id] = MainWPErrorHelper::getErrorMessage(new MainWPException('NOMAINWP', $website->url)); } }
public static function PagesSearch_handler($data, $website, &$output) { if (preg_match('/<mainwp>(.*)<\\/mainwp>/', $data, $results) > 0) { $pages = unserialize(base64_decode($results[1])); unset($results); foreach ($pages as $page) { if (isset($page['dts'])) { if (!stristr($page['dts'], '-')) { $page['dts'] = MainWPUtility::formatTimestamp(MainWPUtility::getTimestamp($page['dts'])); } } if (!isset($page['title']) || $page['title'] == '') { $page['title'] = '(No Title)'; } ob_start(); ?> <tr id="page-1" class="page-1 page type-page status-publish format-standard hentry category-uncategorized alternate iedit author-self" valign="top"> <th scope="row" class="check-column"><input type="checkbox" name="page[]" value="1"></th> <td class="page-title page-title column-title"> <input class="pageId" type="hidden" name="id" value="<?php echo $page['id']; ?> "/> <input class="allowedBulkActions" type="hidden" name="allowedBulkActions" value="|trash|delete|<?php if ($page['status'] == 'trash') { echo 'restore|'; } ?> "/> <input class="websiteId" type="hidden" name="id" value="<?php echo $website->id; ?> "/> <strong> <abbr title="<?php echo $page['title']; ?> "> <?php if ($page['status'] != 'trash') { ?> <a class="row-title" href="admin.php?page=SiteOpen&websiteid=<?php echo $website->id; ?> &location=<?php echo base64_encode('post.php?post=' . $page['id'] . '&action=edit'); ?> " title="Edit '<?php echo $page['title']; ?> '?"><?php echo $page['title']; ?> </a> <?php } else { ?> <?php echo $page['title']; ?> <?php } ?> </abbr> </strong> <div class="row-actions"> <?php if ($page['status'] != 'trash') { ?> <span class="edit"><a href="admin.php?page=SiteOpen&websiteid=<?php echo $website->id; ?> &location=<?php echo base64_encode('post.php?post=' . $page['id'] . '&action=edit'); ?> " title="Edit this item"><?php _e('Edit', 'mainwp'); ?> </a></span> <span class="trash"> | <a class="page_submitdelete" title="Move this item to the Trash" href="#"><?php _e('Trash', 'mainwp'); ?> </a> </span> <?php } ?> <?php if ($page['status'] == 'publish') { ?> <span class="view"> | <a href="<?php echo $website->url . (substr($website->url, -1) != '/' ? '/' : '') . '?p=' . $page['id']; ?> " target="_blank" title="View '<?php echo $page['title']; ?> '?" rel="permalink"><?php _e('View', 'mainwp'); ?> </a></span> <?php } ?> <?php if ($page['status'] == 'trash') { ?> <span class="restore"> <a class="page_submitrestore" title="Restore this item" href="#"><?php _e('Restore', 'mainwp'); ?> </a> </span> <span class="trash"> | <a class="page_submitdelete_perm" title="Delete this item permanently" href="#"><?php _e('Delete Permanently', 'mainwp'); ?> </a> </span> <?php } ?> </div> <div class="row-actions-working"><i class="fa fa-spinner fa-pulse"></i> <?php _e('Please wait', 'mainwp'); ?> </div> </td> <td class="author column-author"> <?php echo $page['author']; ?> </td> <td class="comments column-comments"> <div class="page-com-count-wrapper"> <a href="#" title="0 pending" class="post-com-count"><span class="comment-count"><abbr title="<?php echo $page['comment_count']; ?> "><?php echo $page['comment_count']; ?> </abbr></span></a> </div> </td> <td class="date column-date"><abbr title="<?php echo $page['dts']; ?> "><?php echo $page['dts']; ?> </abbr> </td> <td class="status column-status"><?php echo self::getStatus($page['status']); ?> </td> <td class="categories column-categories"> <a href="<?php echo $website->url; ?> " target="_blank"><?php echo $website->url; ?> </a> <div class="row-actions"> <span class="edit"><a href="admin.php?page=managesites&dashboard=<?php echo $website->id; ?> "><?php _e('Dashboard', 'mainwp'); ?> </a> | <a href="admin.php?page=SiteOpen&websiteid=<?php echo $website->id; ?> "><?php _e('WP Admin', 'mainwp'); ?> </a></span> </div> </td> </tr> <?php $newOutput = ob_get_clean(); echo $newOutput; MainWPCache::addBody('Page', $newOutput); $output->pages++; } unset($pages); } else { $output->errors[$website->id] = MainWPErrorHelper::getErrorMessage(new MainWPException('NOMAINWP', $website->url)); } }
public static function UsersSearch_handler($data, $website, &$output) { if (preg_match('/<mainwp>(.*)<\\/mainwp>/', $data, $results) > 0) { $users = unserialize(base64_decode($results[1])); unset($results); $output->users += self::usersSearchHandlerRenderer($users, $website); unset($users); } else { $output->errors[$website->id] = MainWPErrorHelper::getErrorMessage(new MainWPException('NOMAINWP', $website->url)); } }
public static function fetchChildServerInformation($siteId) { try { $website = MainWPDB::Instance()->getWebsiteById($siteId); if (!MainWPUtility::can_edit_website($website)) { return 'This is not your website.'; } $serverInformation = MainWPUtility::fetchUrlAuthed($website, 'serverInformation'); ?> <h2><i class="fa fa-server"></i> <strong><?php echo stripslashes($website->name); ?> </strong> <?php _e('Server Information'); ?> </h2> <?php echo $serverInformation['information']; ?> <h2><i class="fa fa-server"></i> <strong><?php echo stripslashes($website->name); ?> </strong> <?php _e('Cron Schedules'); ?> </h2> <?php echo $serverInformation['cron']; ?> <?php if (isset($serverInformation['wpconfig'])) { ?> <h2><i class="fa fa-server"></i> <strong><?php echo stripslashes($website->name); ?> </strong> <?php _e('WP-Config File'); ?> </h2> <?php echo $serverInformation['wpconfig']; ?> <h2><i class="fa fa-server"></i> <strong><?php echo stripslashes($website->name); ?> </strong> <?php _e('Error Log'); ?> </h2> <?php echo $serverInformation['error']; ?> <?php } ?> <?php } catch (MainWPException $e) { die(MainWPErrorHelper::getErrorMessage($e)); } catch (Exception $e) { die('Something went wrong processing your request.'); } die; }
public static function executeBackupTask($task, $nrOfSites = 0, $updateRun = true) { if ($updateRun) { MainWPDB::Instance()->updateBackupRun($task->id); } $task = MainWPDB::Instance()->getBackupTaskById($task->id); $completed_sites = $task->completed_sites; if ($completed_sites != '') { $completed_sites = json_decode($completed_sites, true); } if (!is_array($completed_sites)) { $completed_sites = array(); } $sites = array(); if ($task->groups == '') { if ($task->sites != '') { $sites = explode(',', $task->sites); } } else { $groups = explode(',', $task->groups); foreach ($groups as $groupid) { $group_sites = MainWPDB::Instance()->getWebsitesByGroupId($groupid); foreach ($group_sites as $group_site) { if (in_array($group_site->id, $sites)) { continue; } $sites[] = $group_site->id; } } } $errorOutput = null; $lastStartNotification = $task->lastStartNotificationSent; if ($updateRun && get_option('mainwp_notificationOnBackupStart') == 1 && $lastStartNotification < $task->last_run) { $email = MainWPDB::Instance()->getUserNotificationEmail($task->userid); if ($email != '') { $output = 'A scheduled backup has started with MainWP on ' . MainWPUtility::formatTimestamp(MainWPUtility::getTimestamp(time())) . ' for the following ' . count($sites) . ' sites:<br />'; foreach ($sites as $siteid) { $website = MainWPDB::Instance()->getWebsiteById($siteid); $output .= ' • <a href="' . $website->url . '">' . MainWPUtility::getNiceURL($website->url) . '</a><br />'; } $output .= '<br />Backup Details:<br /><br />'; $output .= '<strong>Backup Task</strong>' . ' - ' . $task->name . '<br />'; $output .= '<strong>Backup Type</strong>' . ' - ' . ($task->type == 'db' ? 'DATABASE BACKUP' : 'FULL BACKUP') . '<br />'; $output .= '<strong>Backup Schedule</strong>' . ' - ' . strtoupper($task->schedule) . '<br />'; wp_mail($email, 'A Scheduled Backup has been Started - MainWP', MainWPUtility::formatEmail($email, $output), 'content-type: text/html'); MainWPDB::Instance()->updateBackupTaskWithValues($task->id, array('lastStartNotificationSent' => time())); } } $currentCount = 0; foreach ($sites as $siteid) { if (isset($completed_sites[$siteid]) && $completed_sites[$siteid] == true) { continue; } $website = MainWPDB::Instance()->getWebsiteById($siteid); try { $subfolder = str_replace('%task%', MainWPUtility::sanitize($task->name), $task->subfolder); $backupResult = MainWPManageSites::backupSite($siteid, $task, $subfolder); //When we receive a timeout, we return false.. if ($backupResult === false) { continue; } if ($errorOutput == null) { $errorOutput = ''; } $error = false; $tmpErrorOutput = ''; if (isset($backupResult['error'])) { $tmpErrorOutput .= $backupResult['error'] . '<br />'; $error = true; } if (isset($backupResult['ftp']) && $backupResult['ftp'] != 'success') { $tmpErrorOutput .= 'FTP: ' . $backupResult['ftp'] . '<br />'; $error = true; } if (isset($backupResult['dropbox']) && $backupResult['dropbox'] != 'success') { $tmpErrorOutput .= 'Dropbox: ' . $backupResult['dropbox'] . '<br />'; $error = true; } if (isset($backupResult['amazon']) && $backupResult['amazon'] != 'success') { $tmpErrorOutput .= 'Amazon: ' . $backupResult['amazon'] . '<br />'; $error = true; } if ($error) { $errorOutput .= 'Site: <strong>' . MainWPUtility::getNiceURL($website->url) . '</strong><br />'; $errorOutput .= $tmpErrorOutput . '<br />'; } } catch (Exception $e) { if ($errorOutput == null) { $errorOutput = ''; } $errorOutput .= 'Site: <strong>' . MainWPUtility::getNiceURL($website->url) . '</strong><br />'; $errorOutput .= MainWPErrorHelper::getErrorMessage($e) . '<br />'; $_error_output = MainWPErrorHelper::getErrorMessage($e); } $_backup_result = isset($backupResult) ? $backupResult : (isset($_error_output) ? $_error_output : ""); do_action('mainwp_managesite_schedule_backup', $website, array('type' => $task->type), $_backup_result); $currentCount++; $task = MainWPDB::Instance()->getBackupTaskById($task->id); $completed_sites = $task->completed_sites; if ($completed_sites != '') { $completed_sites = json_decode($completed_sites, true); } if (!is_array($completed_sites)) { $completed_sites = array(); } $completed_sites[$siteid] = true; MainWPDB::Instance()->updateCompletedSites($task->id, $completed_sites); if ($nrOfSites != 0 && $nrOfSites <= $currentCount) { break; } } //update completed sites if ($errorOutput != null) { MainWPDB::Instance()->updateBackupErrors($task->id, $errorOutput); } if (count($completed_sites) == count($sites)) { MainWPDB::Instance()->updateBackupCompleted($task->id); if (get_option('mainwp_notificationOnBackupFail') == 1) { $email = MainWPDB::Instance()->getUserNotificationEmail($task->userid); if ($email != '') { $task = MainWPDB::Instance()->getBackupTaskById($task->id); if ($task->backup_errors != '') { $errorOutput = 'Errors occurred while executing task: <strong>' . $task->name . '</strong><br /><br />' . $task->backup_errors; wp_mail($email, 'A Scheduled Backup had an Error - MainWP', MainWPUtility::formatEmail($email, $errorOutput), 'content-type: text/html'); MainWPDB::Instance()->updateBackupErrors($task->id, ''); } } } } return $errorOutput == ''; }
public function getErrorMessage($msg, $extra) { return MainWPErrorHelper::getErrorMessage(new MainWPException($msg, $extra)); }
public static function ThemesSearch_handler($data, $website, &$output) { if (preg_match('/<mainwp>(.*)<\\/mainwp>/', $data, $results) > 0) { $themes = unserialize(base64_decode($results[1])); unset($results); if (isset($themes['error'])) { $output->errors[$website->id] = MainWPErrorHelper::getErrorMessage(new MainWPException($themes['error'], $website->url)); return; } foreach ($themes as $theme) { if (!isset($theme['name'])) { continue; } $theme['websiteid'] = $website->id; $theme['websiteurl'] = $website->url; $output->themes[] = $theme; } unset($themes); } else { $output->errors[$website->id] = MainWPErrorHelper::getErrorMessage(new MainWPException('NOMAINWP', $website->url)); } }
public static function PostsGetTerms_handler($data, $website, &$output) { if (preg_match('/<mainwp>(.*)<\\/mainwp>/', $data, $results) > 0) { $result = $results[1]; $cats = unserialize(base64_decode($result)); $output->cats[$website->id] = is_array($cats) ? $cats : array(); } else { $output->errors[$website->id] = MainWPErrorHelper::getErrorMessage(new MainWPException('NOMAINWP', $website->url)); } }