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)); } }
/** * List information about theme upgrades * * ## OPTIONS * * [<websiteid>] * : The id (or ids, comma separated) of the child sites that need to be listed/upgraded, when omitted all childsites are used. * * [--list] * : Get a list of themes with available upgrades * * [--upgrade=<theme>] * : Upgrade the themes * * [--upgrade-all] * : Upgrade all themes * * ## EXAMPLES * * wp mainwp theme 2,5 --list * wp mainwp theme --list * wp mainwp theme 2,5 --upgrade-all * wp mainwp theme 2,5 --upgrade=twentysixteen * * @synopsis [<websiteid>] [--list] [--upgrade=<theme>] [--upgrade-all] */ public function theme($args, $assoc_args) { $sites = array(); if (count($args) > 0) { $args_exploded = explode(',', $args[0]); foreach ($args_exploded as $arg) { if (!is_numeric(trim($arg))) { WP_CLI::error('Child site ids should be numeric.'); } $sites[] = trim($arg); } } if (isset($assoc_args['list'])) { $websites = MainWP_DB::Instance()->query(MainWP_DB::Instance()->getSQLWebsitesForCurrentUser()); $userExtension = MainWP_DB::Instance()->getUserExtension(); $websites_to_upgrade = array(); while ($websites && ($website = @MainWP_DB::fetch_object($websites))) { if (count($sites) > 0 && !in_array($website->id, $sites)) { continue; } $theme_upgrades = json_decode($website->theme_upgrades, true); if (is_array($theme_upgrades)) { $ignored_themes = json_decode($website->ignored_themes, true); if (is_array($ignored_themes)) { $theme_upgrades = array_diff_key($theme_upgrades, $ignored_themes); } $ignored_themes = json_decode($userExtension->ignored_themes, true); if (is_array($ignored_themes)) { $theme_upgrades = array_diff_key($theme_upgrades, $ignored_themes); } $tmp = array(); foreach ($theme_upgrades as $theme_upgrade) { $tmp[] = array('name' => $theme_upgrade['update']['theme'], 'version' => $theme_upgrade['Version'], 'new_version' => $theme_upgrade['update']['new_version']); } $websites_to_upgrade[] = array('id' => $website->id, 'name' => $website->name, 'themes' => $tmp); } } $idLength = strlen('id'); $nameLength = strlen('name'); $themeLength = strlen('theme'); $oldVersionLength = strlen('version'); $newVersionLength = strlen('new version'); foreach ($websites_to_upgrade as $website_to_upgrade) { if ($idLength < strlen($website_to_upgrade['id'])) { $idLength = strlen($website_to_upgrade['id']); } if ($nameLength < strlen($website_to_upgrade['name'])) { $nameLength = strlen($website_to_upgrade['name']); } foreach ($website_to_upgrade['themes'] as $theme_to_upgrade) { if ($themeLength < strlen($theme_to_upgrade['name'])) { $themeLength = strlen($theme_to_upgrade['name']); } if ($oldVersionLength < strlen($theme_to_upgrade['version'])) { $oldVersionLength = strlen($theme_to_upgrade['version']); } if ($newVersionLength < strlen($theme_to_upgrade['new_version'])) { $newVersionLength = strlen($theme_to_upgrade['new_version']); } } } WP_CLI::line(sprintf("+%'--" . ($idLength + 2) . "s+%'--" . ($nameLength + 2) . "s+%'--" . ($themeLength + 2) . "s+%'--" . ($oldVersionLength + 2) . "s+%'--" . ($newVersionLength + 2) . "s+", '', '', '', '', '')); WP_CLI::line(sprintf("| %-" . $idLength . "s | %-" . $nameLength . "s | %-" . $themeLength . "s | %-" . $oldVersionLength . "s | %-" . $newVersionLength . "s |", 'id', 'name', 'theme', 'version', 'new version')); WP_CLI::line(sprintf("+%'--" . ($idLength + 2) . "s+%'--" . ($nameLength + 2) . "s+%'--" . ($themeLength + 2) . "s+%'--" . ($oldVersionLength + 2) . "s+%'--" . ($newVersionLength + 2) . "s+", '', '', '', '', '')); foreach ($websites_to_upgrade as $website_to_upgrade) { if ($idLength < strlen($website_to_upgrade['id'])) { $idLength = strlen($website_to_upgrade['id']); } if ($nameLength < strlen($website_to_upgrade['name'])) { $nameLength = strlen($website_to_upgrade['name']); } $i = 0; foreach ($website_to_upgrade['themes'] as $theme_to_upgrade) { if ($i == 0) { WP_CLI::line(sprintf("| %-" . $idLength . "s | %-" . $nameLength . "s | %-" . $themeLength . "s | %-" . $oldVersionLength . "s | %-" . $newVersionLength . "s |", $website_to_upgrade['id'], $website_to_upgrade['name'], $theme_to_upgrade['name'], $theme_to_upgrade['version'], $theme_to_upgrade['new_version'])); } else { WP_CLI::line(sprintf("| %-" . $idLength . "s | %-" . $nameLength . "s | %-" . $themeLength . "s | %-" . $oldVersionLength . "s | %-" . $newVersionLength . "s |", '', '', $theme_to_upgrade['name'], $theme_to_upgrade['version'], $theme_to_upgrade['new_version'])); } $i++; } } WP_CLI::line(sprintf("+%'--" . ($idLength + 2) . "s+%'--" . ($nameLength + 2) . "s+%'--" . ($themeLength + 2) . "s+%'--" . ($oldVersionLength + 2) . "s+%'--" . ($newVersionLength + 2) . "s+", '', '', '', '', '')); } else { if (isset($assoc_args['upgrade']) || isset($assoc_args['upgrade-all'])) { //slugs to upgrade $themeSlugs = array(); if (isset($assoc_args['upgrade'])) { $themeSlugs = explode(',', $assoc_args['upgrade']); } $websites = MainWP_DB::Instance()->query(MainWP_DB::Instance()->getSQLWebsitesForCurrentUser()); $userExtension = MainWP_DB::Instance()->getUserExtension(); while ($websites && ($website = @MainWP_DB::fetch_object($websites))) { if (count($sites) > 0 && !in_array($website->id, $sites)) { continue; } $theme_upgrades = json_decode($website->theme_upgrades, true); if (is_array($theme_upgrades)) { $ignored_themes = json_decode($website->ignored_themes, true); if (is_array($ignored_themes)) { $theme_upgrades = array_diff_key($theme_upgrades, $ignored_themes); } $ignored_themes = json_decode($userExtension->ignored_themes, true); if (is_array($ignored_themes)) { $theme_upgrades = array_diff_key($theme_upgrades, $ignored_themes); } $tmp = array(); foreach ($theme_upgrades as $key => $theme_upgrade) { if (count($themeSlugs) > 0 && !in_array($theme_upgrade['update']['slug'], $themeSlugs)) { continue; } $tmp[] = $key; } if (count($tmp) == 0) { WP_CLI::line('No available theme upgrades for ' . $website->name); continue; } WP_CLI::line('Upgrading ' . count($tmp) . ' themes for ' . $website->name); try { MainWP_Right_Now::upgradePluginThemeTranslation($website->id, 'theme', implode(',', $tmp)); WP_CLI::success('Upgrades completed'); } catch (Exception $e) { WP_CLI::error('Upgrades failed: ' . MainWP_Error_Helper::getConsoleErrorMessage($e)); } } } } } }
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)); } }