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] = MainWP_Error_Helper::getErrorMessage(new MainWP_Exception('NOMAINWP', $website->url)); } }
public function getErrorMessage($msg, $extra) { return MainWP_Error_Helper::getErrorMessage(new MainWP_Exception($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] = MainWP_Error_Helper::getErrorMessage(new MainWP_Exception($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] = MainWP_Error_Helper::getErrorMessage(new MainWP_Exception('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] = MainWP_Error_Helper::getErrorMessage(new MainWP_Exception('NOMAINWP', $website->url)); } }
public static function fetchChildServerInformation($siteId) { try { $website = MainWP_DB::Instance()->getWebsiteById($siteId); if (!MainWP_Utility::can_edit_website($website)) { return __('This is not your website.', 'mainwp'); } $serverInformation = MainWP_Utility::fetchUrlAuthed($website, 'serverInformation'); ?> <div id="mainwp-server-information-section"> <h2><i class="fa fa-server"></i> <strong><?php echo stripslashes($website->name); ?> </strong> <?php _e('Server Information'); ?> </h2> <?php echo $serverInformation['information']; ?> </div> <div id="mainwp-cron-schedules-section"> <h2><i class="fa fa-server"></i> <strong><?php echo stripslashes($website->name); ?> </strong> <?php _e('Cron Schedules', 'mainwp'); ?> </h2> <?php echo $serverInformation['cron']; ?> </div> <?php if (isset($serverInformation['wpconfig'])) { ?> <div id="mainwp-wp-config-section"> <h2><i class="fa fa-server"></i> <strong><?php echo stripslashes($website->name); ?> </strong> <?php _e('WP-Config File', 'mainwp'); ?> </h2> <?php echo $serverInformation['wpconfig']; ?> </div> <div id="mainwp-error-log-section"> <h2><i class="fa fa-server"></i> <strong><?php echo stripslashes($website->name); ?> </strong> <?php _e('Error Log', 'mainwp'); ?> </h2> <?php echo $serverInformation['error']; ?> </div> <?php } ?> <?php } catch (MainWP_Exception $e) { die(MainWP_Error_Helper::getErrorMessage($e)); } catch (Exception $e) { die('Something went wrong processing your request.'); } die; }
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] = MainWP_Error_Helper::getErrorMessage(new MainWP_Exception('NOMAINWP', $website->url)); } }
public static function executeBackupTask($task, $nrOfSites = 0, $updateRun = true) { if ($updateRun) { MainWP_DB::Instance()->updateBackupRun($task->id); } $task = MainWP_DB::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 = MainWP_DB::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 = MainWP_DB::Instance()->getUserNotificationEmail($task->userid); if ($email != '') { $output = 'A scheduled backup has started with MainWP on ' . MainWP_Utility::formatTimestamp(MainWP_Utility::getTimestamp(time())) . ' for the following ' . count($sites) . ' sites:<br />'; foreach ($sites as $siteid) { $website = MainWP_DB::Instance()->getWebsiteById($siteid); $output .= ' • <a href="' . $website->url . '">' . MainWP_Utility::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', MainWP_Utility::formatEmail($email, $output), 'content-type: text/html'); MainWP_DB::Instance()->updateBackupTaskWithValues($task->id, array('lastStartNotificationSent' => time())); } } $currentCount = 0; foreach ($sites as $siteid) { if (isset($completed_sites[$siteid]) && $completed_sites[$siteid] == true) { continue; } $website = MainWP_DB::Instance()->getWebsiteById($siteid); try { $subfolder = str_replace('%task%', MainWP_Utility::sanitize($task->name), $task->subfolder); $backupResult = MainWP_Manage_Sites::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>' . MainWP_Utility::getNiceURL($website->url) . '</strong><br />'; $errorOutput .= $tmpErrorOutput . '<br />'; } } catch (Exception $e) { if ($errorOutput == null) { $errorOutput = ''; } $errorOutput .= 'Site: <strong>' . MainWP_Utility::getNiceURL($website->url) . '</strong><br />'; $errorOutput .= MainWP_Error_Helper::getErrorMessage($e) . '<br />'; $_error_output = MainWP_Error_Helper::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 = MainWP_DB::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; MainWP_DB::Instance()->updateCompletedSites($task->id, $completed_sites); if ($nrOfSites != 0 && $nrOfSites <= $currentCount) { break; } } //update completed sites if ($errorOutput != null) { MainWP_DB::Instance()->updateBackupErrors($task->id, $errorOutput); } if (count($completed_sites) == count($sites)) { MainWP_DB::Instance()->updateBackupCompleted($task->id); if (get_option('mainwp_notificationOnBackupFail') == 1) { $email = MainWP_DB::Instance()->getUserNotificationEmail($task->userid); if ($email != '') { $task = MainWP_DB::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', MainWP_Utility::formatEmail($email, $errorOutput), 'content-type: text/html'); MainWP_DB::Instance()->updateBackupErrors($task->id, ''); } } } } return $errorOutput == ''; }
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'] = MainWP_Utility::formatTimestamp(MainWP_Utility::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; MainWP_Cache::addBody('Page', $newOutput); $output->pages++; } unset($pages); } else { $output->errors[$website->id] = MainWP_Error_Helper::getErrorMessage(new MainWP_Exception('NOMAINWP', $website->url)); } }