Exemple #1
0
 function upgradePluginTheme()
 {
     try {
         $websiteId = $type = null;
         $slugs = array();
         if (isset($_POST['websiteId'])) {
             $websiteId = $_POST['websiteId'];
         }
         if (isset($_POST['slugs'])) {
             $slugs = $_POST['slugs'];
         }
         if (isset($_POST['type'])) {
             $type = $_POST['type'];
         }
         $error = '';
         if ($type == 'plugin' && !mainwp_current_user_can('dashboard', 'update_plugins')) {
             $error = mainwp_do_not_have_permissions(__('update plugins', 'mainwp'), false);
         } else {
             if ($type == 'theme' && !mainwp_current_user_can('dashboard', 'update_themes')) {
                 $error = mainwp_do_not_have_permissions(__('update themes', 'mainwp'), false);
             }
         }
         if (!empty($error)) {
             die(json_encode(array('error' => $error)));
         }
         if (MainWP_Utility::ctype_digit($websiteId)) {
             $website = MainWP_DB::Instance()->getWebsiteById($websiteId);
             if (MainWP_Utility::can_edit_website($website)) {
                 $information = MainWP_Utility::fetchUrlAuthed($website, 'upgradeplugintheme', array('type' => $type, 'list' => urldecode(implode(',', $slugs))));
                 die(json_encode($information));
             }
         }
     } catch (MainWP_Exception $e) {
         die(json_encode(array('error' => $e->getMessage())));
     }
     die;
 }
 public static function hookFetchUrlAuthed($pluginFile, $key, $websiteId, $what, $params)
 {
     if (!self::hookVerify($pluginFile, $key)) {
         return false;
     }
     try {
         $website = MainWP_DB::Instance()->getWebsiteById($websiteId);
         if (!MainWP_Utility::can_edit_website($website)) {
             throw new MainWP_Exception('You can not edit this website.');
         }
         return MainWP_Utility::fetchUrlAuthed($website, $what, $params);
     } catch (MainWP_Exception $e) {
         return array('error' => $e->getMessage());
     }
 }
 public static function action($pAction)
 {
     $plugin = $_POST['plugin'];
     $websiteIdEnc = $_POST['websiteId'];
     if (empty($plugin)) {
         die(json_encode(array('error' => 'Invalid Request.')));
     }
     $websiteId = $websiteIdEnc;
     if (!MainWP_Utility::ctype_digit($websiteId)) {
         die(json_encode(array('error' => 'Invalid Request.')));
     }
     $website = MainWP_DB::Instance()->getWebsiteById($websiteId);
     if (!MainWP_Utility::can_edit_website($website)) {
         die(json_encode(array('error' => 'You can not edit this website.')));
     }
     try {
         $information = MainWP_Utility::fetchUrlAuthed($website, 'plugin_action', array('action' => $pAction, 'plugin' => $plugin));
     } catch (MainWP_Exception $e) {
         die(json_encode(array('error' => $e->getMessage())));
     }
     if (!isset($information['status']) || $information['status'] != 'SUCCESS') {
         die(json_encode(array('error' => 'Unexpected error.')));
     }
 }
 function mainwp_cronupdatescheck_action()
 {
     MainWP_Logger::Instance()->info('CRON :: updates check');
     @ignore_user_abort(true);
     @set_time_limit(0);
     $mem = '512M';
     @ini_set('memory_limit', $mem);
     @ini_set('max_execution_time', 0);
     MainWP_Utility::update_option('mainwp_cron_last_updatescheck', time());
     $mainwpAutomaticDailyUpdate = get_option('mainwp_automaticDailyUpdate');
     $mainwpLastAutomaticUpdate = get_option('mainwp_updatescheck_last');
     if ($mainwpLastAutomaticUpdate == date('d/m/Y')) {
         MainWP_Logger::Instance()->debug('CRON :: updates check :: already updated today');
         return;
     }
     $websites = MainWP_DB::Instance()->getWebsitesCheckUpdates(4);
     MainWP_Logger::Instance()->debug('CRON :: updates check :: found ' . count($websites) . ' websites');
     $userid = null;
     foreach ($websites as $website) {
         $websiteValues = array('dtsAutomaticSyncStart' => time());
         if ($userid == null) {
             $userid = $website->userid;
         }
         MainWP_DB::Instance()->updateWebsiteSyncValues($website->id, $websiteValues);
     }
     if (count($websites) == 0) {
         $busyCounter = MainWP_DB::Instance()->getWebsitesCountWhereDtsAutomaticSyncSmallerThenStart();
         if ($busyCounter == 0) {
             MainWP_Logger::Instance()->debug('CRON :: updates check :: got to the mail part');
             //Send the email & update all to this time!
             $mail = '';
             $sendMail = false;
             $sitesCheckCompleted = null;
             if (get_option('mainwp_backup_before_upgrade') == 1) {
                 $sitesCheckCompleted = get_option('mainwp_automaticUpdate_backupChecks');
                 if (!is_array($sitesCheckCompleted)) {
                     $sitesCheckCompleted = null;
                 }
             }
             $pluginsNewUpdate = get_option('mainwp_updatescheck_mail_update_plugins_new');
             if (!is_array($pluginsNewUpdate)) {
                 $pluginsNewUpdate = array();
             }
             $pluginsToUpdate = get_option('mainwp_updatescheck_mail_update_plugins');
             if (!is_array($pluginsToUpdate)) {
                 $pluginsToUpdate = array();
             }
             $ignoredPluginsNewUpdate = get_option('mainwp_updatescheck_mail_ignore_plugins_new');
             if (!is_array($ignoredPluginsNewUpdate)) {
                 $ignoredPluginsNewUpdate = array();
             }
             $ignoredPluginsToUpdate = get_option('mainwp_updatescheck_mail_ignore_plugins');
             if (!is_array($ignoredPluginsToUpdate)) {
                 $ignoredPluginsToUpdate = array();
             }
             if (count($pluginsNewUpdate) != 0 || count($pluginsToUpdate) != 0) {
                 $sendMail = true;
                 $mail .= '<div><strong>WordPress Plugin Updates</strong></div>';
                 $mail .= '<ul>';
                 $mail .= $this->print_updates_array_lines($pluginsNewUpdate, null);
                 $mail .= $this->print_updates_array_lines($pluginsToUpdate, $sitesCheckCompleted);
                 //					$mail .= $this->print_updates_array_lines( $ignoredPluginsNewUpdate, null );
                 //					$mail .= $this->print_updates_array_lines( $ignoredPluginsToUpdate, null );
                 $mail .= '</ul>';
             }
             $themesNewUpdate = get_option('mainwp_updatescheck_mail_update_themes_new');
             if (!is_array($themesNewUpdate)) {
                 $themesNewUpdate = array();
             }
             $themesToUpdate = get_option('mainwp_updatescheck_mail_update_themes');
             if (!is_array($themesToUpdate)) {
                 $themesToUpdate = array();
             }
             $ignoredThemesNewUpdate = get_option('mainwp_updatescheck_mail_ignore_themes_new');
             if (!is_array($ignoredThemesNewUpdate)) {
                 $ignoredThemesNewUpdate = array();
             }
             $ignoredThemesToUpdate = get_option('mainwp_updatescheck_mail_ignore_themes');
             if (!is_array($ignoredThemesToUpdate)) {
                 $ignoredThemesToUpdate = array();
             }
             if (count($themesNewUpdate) != 0 || count($themesToUpdate) != 0) {
                 $sendMail = true;
                 $mail .= '<div><strong>WordPress Themes Updates</strong></div>';
                 $mail .= '<ul>';
                 $mail .= $this->print_updates_array_lines($themesNewUpdate, null);
                 $mail .= $this->print_updates_array_lines($themesToUpdate, $sitesCheckCompleted);
                 //					$mail .= $this->print_updates_array_lines( $ignoredThemesNewUpdate, null );
                 //					$mail .= $this->print_updates_array_lines( $ignoredThemesToUpdate, null );
                 $mail .= '</ul>';
             }
             $coreNewUpdate = get_option('mainwp_updatescheck_mail_update_core_new');
             if (!is_array($coreNewUpdate)) {
                 $coreNewUpdate = array();
             }
             $coreToUpdate = get_option('mainwp_updatescheck_mail_update_core');
             if (!is_array($coreToUpdate)) {
                 $coreToUpdate = array();
             }
             $ignoredCoreNewUpdate = get_option('mainwp_updatescheck_mail_ignore_core_new');
             if (!is_array($ignoredCoreNewUpdate)) {
                 $ignoredCoreNewUpdate = array();
             }
             $ignoredCoreToUpdate = get_option('mainwp_updatescheck_mail_ignore_core');
             if (!is_array($ignoredCoreToUpdate)) {
                 $ignoredCoreToUpdate = array();
             }
             if (count($coreNewUpdate) != 0 || count($coreToUpdate) != 0 || count($ignoredCoreNewUpdate) != 0 || count($ignoredCoreToUpdate) != 0) {
                 $sendMail = true;
                 $mail .= '<div><strong>WordPress Core Updates</strong></div>';
                 $mail .= '<ul>';
                 $mail .= $this->print_updates_array_lines($coreNewUpdate, null);
                 $mail .= $this->print_updates_array_lines($coreToUpdate, $sitesCheckCompleted);
                 $mail .= $this->print_updates_array_lines($ignoredCoreNewUpdate, null);
                 $mail .= $this->print_updates_array_lines($ignoredCoreToUpdate, null);
                 $mail .= '</ul>';
             }
             $pluginConflicts = get_option('mainwp_updatescheck_mail_pluginconflicts');
             if ($pluginConflicts === false) {
                 $pluginConflicts = '';
             }
             if ($pluginConflicts != '') {
                 $sendMail = true;
                 $mail .= '<div><strong>WordPress Plugin Conflicts</strong></div>';
                 $mail .= '<ul>';
                 $mail .= $pluginConflicts;
                 $mail .= '</ul>';
             }
             $themeConflicts = get_option('mainwp_updatescheck_mail_themeconflicts');
             if ($themeConflicts === false) {
                 $themeConflicts = '';
             }
             if ($themeConflicts != '') {
                 $sendMail = true;
                 $mail .= '<div><strong>WordPress Theme Conflicts</strong></div>';
                 $mail .= '<ul>';
                 $mail .= $themeConflicts;
                 $mail .= '</ul>';
             }
             MainWP_Utility::update_option('mainwp_automaticUpdate_backupChecks', '');
             MainWP_Utility::update_option('mainwp_updatescheck_mail_update_core_new', '');
             MainWP_Utility::update_option('mainwp_updatescheck_mail_update_plugins_new', '');
             MainWP_Utility::update_option('mainwp_updatescheck_mail_update_themes_new', '');
             MainWP_Utility::update_option('mainwp_updatescheck_mail_update_core', '');
             MainWP_Utility::update_option('mainwp_updatescheck_mail_update_plugins', '');
             MainWP_Utility::update_option('mainwp_updatescheck_mail_update_themes', '');
             MainWP_Utility::update_option('mainwp_updatescheck_mail_ignore_core', '');
             MainWP_Utility::update_option('mainwp_updatescheck_mail_ignore_plugins', '');
             MainWP_Utility::update_option('mainwp_updatescheck_mail_ignore_themes', '');
             MainWP_Utility::update_option('mainwp_updatescheck_mail_ignore_core_new', '');
             MainWP_Utility::update_option('mainwp_updatescheck_mail_ignore_plugins_new', '');
             MainWP_Utility::update_option('mainwp_updatescheck_mail_ignore_themes_new', '');
             MainWP_Utility::update_option('mainwp_updatescheck_mail_pluginconflicts', '');
             MainWP_Utility::update_option('mainwp_updatescheck_mail_themeconflicts', '');
             MainWP_Utility::update_option('mainwp_updatescheck_last', date('d/m/Y'));
             if (!$sendMail) {
                 MainWP_Logger::Instance()->debug('CRON :: updates check :: sendMail is false');
                 return;
             }
             if ($mainwpAutomaticDailyUpdate !== false && $mainwpAutomaticDailyUpdate != 0) {
                 //Create a nice email to send
                 $email = get_option('mainwp_updatescheck_mail_email');
                 MainWP_Logger::Instance()->debug('CRON :: updates check :: send mail to ' . $email);
                 if ($email != false && $email != '') {
                     $mail = '<div>We noticed the following updates are available on your MainWP Dashboard. (<a href="' . site_url() . '">' . site_url() . '</a>)</div>
                              <div></div>
                              ' . $mail . '
                              Update Key: (<strong><span style="color:#008000">Trusted</span></strong>) will be auto updated within 24 hours. (<strong><span style="color:#ff0000">Not Trusted</span></strong>) you will need to log into your Main Dashboard and update
                              <div> </div>
                              <div>If your MainWP is configured to use Auto Updates these upgrades will be installed in the next 24 hours. To find out how to enable automatic updates please see the FAQs below.</div>
                              <div><a href="http://docs.mainwp.com/marking-a-plugin-as-trusted/" style="color:#446200" target="_blank">http://docs.mainwp.com/marking-a-plugin-as-trusted/</a></div>
                              <div><a href="http://docs.mainwp.com/marking-a-theme-as-trusted/" style="color:#446200" target="_blank">http://docs.mainwp.com/marking-a-theme-as-trusted/</a></div>
                              <div><a href="http://docs.mainwp.com/marking-a-sites-wp-core-updates-as-trusted/" style="color:#446200" target="_blank">http://docs.mainwp.com/marking-a-sites-wp-core-updates-as-trusted/</a></div>';
                     wp_mail($email, 'MainWP - Trusted Updates', MainWP_Utility::formatEmail($email, $mail), array('From: "' . get_option('admin_email') . '" <' . get_option('admin_email') . '>', 'content-type: text/html'));
                 }
             }
         }
     } else {
         $userExtension = MainWP_DB::Instance()->getUserExtensionByUserId($userid);
         $decodedIgnoredPlugins = json_decode($userExtension->ignored_plugins, true);
         if (!is_array($decodedIgnoredPlugins)) {
             $decodedIgnoredPlugins = array();
         }
         $trustedPlugins = json_decode($userExtension->trusted_plugins, true);
         if (!is_array($trustedPlugins)) {
             $trustedPlugins = array();
         }
         $decodedIgnoredThemes = json_decode($userExtension->ignored_themes, true);
         if (!is_array($decodedIgnoredThemes)) {
             $decodedIgnoredThemes = array();
         }
         $trustedThemes = json_decode($userExtension->trusted_themes, true);
         if (!is_array($trustedThemes)) {
             $trustedThemes = array();
         }
         $coreToUpdateNow = array();
         $coreToUpdate = array();
         $coreNewUpdate = array();
         $ignoredCoreToUpdate = array();
         $ignoredCoreNewUpdate = array();
         $pluginsToUpdateNow = array();
         $pluginsToUpdate = array();
         $pluginsNewUpdate = array();
         $ignoredPluginsToUpdate = array();
         $ignoredPluginsNewUpdate = array();
         $themesToUpdateNow = array();
         $themesToUpdate = array();
         $themesNewUpdate = array();
         $ignoredThemesToUpdate = array();
         $ignoredThemesNewUpdate = array();
         $pluginConflicts = '';
         $themeConflicts = '';
         $allWebsites = array();
         $infoTrustedText = ' (<span style="color:#008000"><strong>Trusted</strong></span>)';
         $infoNotTrustedText = ' (<strong><span style="color:#ff0000">Not Trusted</span></strong>)';
         foreach ($websites as $website) {
             $websiteDecodedIgnoredPlugins = json_decode($website->ignored_plugins, true);
             if (!is_array($websiteDecodedIgnoredPlugins)) {
                 $websiteDecodedIgnoredPlugins = array();
             }
             $websiteDecodedIgnoredThemes = json_decode($website->ignored_themes, true);
             if (!is_array($websiteDecodedIgnoredThemes)) {
                 $websiteDecodedIgnoredThemes = array();
             }
             //Perform check & update
             if (!MainWP_Sync::syncSite($website, false, true)) {
                 $websiteValues = array('dtsAutomaticSync' => time());
                 MainWP_DB::Instance()->updateWebsiteSyncValues($website->id, $websiteValues);
                 continue;
             }
             $website = MainWP_DB::Instance()->getWebsiteById($website->id);
             /** Check core upgrades **/
             $websiteLastCoreUpgrades = json_decode(MainWP_DB::Instance()->getWebsiteOption($website, 'last_wp_upgrades'), true);
             $websiteCoreUpgrades = json_decode(MainWP_DB::Instance()->getWebsiteOption($website, 'wp_upgrades'), true);
             //Run over every update we had last time..
             if (isset($websiteCoreUpgrades['current'])) {
                 $infoTxt = '<a href="' . admin_url('admin.php?page=managesites&dashboard=' . $website->id) . '">' . stripslashes($website->name) . '</a> - ' . $websiteCoreUpgrades['current'] . ' to ' . $websiteCoreUpgrades['new'];
                 $infoNewTxt = '*NEW* <a href="' . admin_url('admin.php?page=managesites&dashboard=' . $website->id) . '">' . stripslashes($website->name) . '</a> - ' . $websiteCoreUpgrades['current'] . ' to ' . $websiteCoreUpgrades['new'];
                 $newUpdate = !(isset($websiteLastCoreUpgrades['current']) && $websiteLastCoreUpgrades['current'] == $websiteCoreUpgrades['current'] && $websiteLastCoreUpgrades['new'] == $websiteCoreUpgrades['new']);
                 if ($website->automatic_update == 1) {
                     if ($newUpdate) {
                         $coreNewUpdate[] = array($website->id, $infoNewTxt, $infoTrustedText);
                     } else {
                         //Check ignore ? $ignoredCoreToUpdate
                         $coreToUpdateNow[] = $website->id;
                         $allWebsites[$website->id] = $website;
                         $coreToUpdate[] = array($website->id, $infoTxt, $infoTrustedText);
                     }
                 } else {
                     if ($newUpdate) {
                         $ignoredCoreNewUpdate[] = array($website->id, $infoNewTxt, $infoNotTrustedText);
                     } else {
                         $ignoredCoreToUpdate[] = array($website->id, $infoTxt, $infoNotTrustedText);
                     }
                 }
             }
             /** Check plugins **/
             $websiteLastPlugins = json_decode(MainWP_DB::Instance()->getWebsiteOption($website, 'last_plugin_upgrades'), true);
             $websitePlugins = json_decode($website->plugin_upgrades, true);
             /** Check themes **/
             $websiteLastThemes = json_decode(MainWP_DB::Instance()->getWebsiteOption($website, 'last_theme_upgrades'), true);
             $websiteThemes = json_decode($website->theme_upgrades, true);
             $decodedPremiumUpgrades = json_decode(MainWP_DB::Instance()->getWebsiteOption($website, 'premium_upgrades'), true);
             if (is_array($decodedPremiumUpgrades)) {
                 foreach ($decodedPremiumUpgrades as $slug => $premiumUpgrade) {
                     if ($premiumUpgrade['type'] == 'plugin') {
                         if (!is_array($websitePlugins)) {
                             $websitePlugins = array();
                         }
                         $websitePlugins[$slug] = $premiumUpgrade;
                     } else {
                         if ($premiumUpgrade['type'] == 'theme') {
                             if (!is_array($websiteThemes)) {
                                 $websiteThemes = array();
                             }
                             $websiteThemes[$slug] = $premiumUpgrade;
                         }
                     }
                 }
             }
             //Run over every update we had last time..
             foreach ($websitePlugins as $pluginSlug => $pluginInfo) {
                 if (isset($decodedIgnoredPlugins[$pluginSlug]) || isset($websiteDecodedIgnoredPlugins[$pluginSlug])) {
                     continue;
                 }
                 $infoTxt = '<a href="' . admin_url('admin.php?page=managesites&dashboard=' . $website->id) . '">' . stripslashes($website->name) . '</a> - ' . $pluginInfo['Name'] . ' ' . $pluginInfo['Version'] . ' to ' . $pluginInfo['update']['new_version'];
                 $infoNewTxt = '*NEW* <a href="' . admin_url('admin.php?page=managesites&dashboard=' . $website->id) . '">' . stripslashes($website->name) . '</a> - ' . $pluginInfo['Name'] . ' ' . $pluginInfo['Version'] . ' to ' . $pluginInfo['update']['new_version'];
                 $newUpdate = !(isset($websiteLastPlugins[$pluginSlug]) && $pluginInfo['Version'] == $websiteLastPlugins[$pluginSlug]['Version'] && $pluginInfo['update']['new_version'] == $websiteLastPlugins[$pluginSlug]['update']['new_version']);
                 //update this..
                 if (in_array($pluginSlug, $trustedPlugins)) {
                     //Trusted
                     if ($newUpdate) {
                         $pluginsNewUpdate[] = array($website->id, $infoNewTxt, $infoTrustedText);
                     } else {
                         $pluginsToUpdateNow[$website->id][] = $pluginSlug;
                         $allWebsites[$website->id] = $website;
                         $pluginsToUpdate[] = array($website->id, $infoTxt, $infoTrustedText);
                     }
                 } else {
                     //Not trusted
                     if ($newUpdate) {
                         $ignoredPluginsNewUpdate[] = array($website->id, $infoNewTxt, $infoNotTrustedText);
                     } else {
                         $ignoredPluginsToUpdate[] = array($website->id, $infoTxt, $infoNotTrustedText);
                     }
                 }
             }
             //Run over every update we had last time..
             foreach ($websiteThemes as $themeSlug => $themeInfo) {
                 if (isset($decodedIgnoredThemes[$themeSlug]) || isset($websiteDecodedIgnoredThemes[$themeSlug])) {
                     continue;
                 }
                 $infoTxt = '<a href="' . admin_url('admin.php?page=managesites&dashboard=' . $website->id) . '">' . stripslashes($website->name) . '</a> - ' . $themeInfo['Name'] . ' ' . $themeInfo['Version'] . ' to ' . $themeInfo['update']['new_version'];
                 $infoNewTxt = '*NEW* <a href="' . admin_url('admin.php?page=managesites&dashboard=' . $website->id) . '">' . stripslashes($website->name) . '</a> - ' . $themeInfo['Name'] . ' ' . $themeInfo['Version'] . ' to ' . $themeInfo['update']['new_version'];
                 $newUpdate = !(isset($websiteLastThemes[$themeSlug]) && $themeInfo['Version'] == $websiteLastThemes[$themeSlug]['Version'] && $themeInfo['update']['new_version'] == $websiteLastThemes[$themeSlug]['update']['new_version']);
                 //update this..
                 if (in_array($themeSlug, $trustedThemes)) {
                     //Trusted
                     if ($newUpdate) {
                         $themesNewUpdate[] = array($website->id, $infoNewTxt, $infoTrustedText);
                     } else {
                         $themesToUpdateNow[$website->id][] = $themeSlug;
                         $allWebsites[$website->id] = $website;
                         $themesToUpdate[] = array($website->id, $infoTxt, $infoTrustedText);
                     }
                 } else {
                     //Not trusted
                     if ($newUpdate) {
                         $ignoredThemesNewUpdate[] = array($website->id, $infoNewTxt, $infoNotTrustedText);
                     } else {
                         $ignoredThemesToUpdate[] = array($website->id, $infoTxt, $infoNotTrustedText);
                     }
                 }
             }
             /**
              * Show plugin conflicts
              */
             $sitePluginConflicts = json_decode($website->pluginConflicts, true);
             if (count($sitePluginConflicts) > 0) {
                 $infoTxt = '<a href="' . admin_url('admin.php?page=managesites&dashboard=' . $website->id) . '">' . stripslashes($website->name) . '</a> - ';
                 $pluginConflicts .= '<li>' . $infoTxt;
                 $added = false;
                 foreach ($sitePluginConflicts as $sitePluginConflict) {
                     if ($added) {
                         $pluginConflicts .= ', ';
                     }
                     $pluginConflicts .= $sitePluginConflict;
                     $added = true;
                 }
                 $pluginConflicts .= '</li>' . "\n";
             }
             /**
              * Show theme conflicts
              */
             $siteThemeConflicts = json_decode($website->themeConflicts, true);
             if (count($siteThemeConflicts) > 0) {
                 $infoTxt = '<a href="' . admin_url('admin.php?page=managesites&dashboard=' . $website->id) . '">' . stripslashes($website->name) . '</a> - ';
                 $themeConflicts .= '<li>' . $infoTxt;
                 $added = false;
                 foreach ($siteThemeConflicts as $siteThemeConflict) {
                     if ($added) {
                         $themeConflicts .= ', ';
                     }
                     $themeConflicts .= $siteThemeConflict;
                     $added = true;
                 }
                 $themeConflicts .= '</li>' . "\n";
             }
             //Loop over last plugins & current plugins, check if we need to upgrade them..
             $user = get_userdata($website->userid);
             $email = MainWP_Utility::getNotificationEmail($user);
             MainWP_Utility::update_option('mainwp_updatescheck_mail_email', $email);
             MainWP_DB::Instance()->updateWebsiteSyncValues($website->id, array('dtsAutomaticSync' => time()));
             MainWP_DB::Instance()->updateWebsiteOption($website, 'last_wp_upgrades', json_encode($websiteCoreUpgrades));
             MainWP_DB::Instance()->updateWebsiteOption($website, 'last_plugin_upgrades', $website->plugin_upgrades);
             MainWP_DB::Instance()->updateWebsiteOption($website, 'last_theme_upgrades', $website->theme_upgrades);
         }
         if (count($coreNewUpdate) != 0) {
             $coreNewUpdateSaved = get_option('mainwp_updatescheck_mail_update_core_new');
             MainWP_Utility::update_option('mainwp_updatescheck_mail_update_core_new', MainWP_Utility::array_merge($coreNewUpdateSaved, $coreNewUpdate));
         }
         if (count($pluginsNewUpdate) != 0) {
             $pluginsNewUpdateSaved = get_option('mainwp_updatescheck_mail_update_plugins_new');
             MainWP_Utility::update_option('mainwp_updatescheck_mail_update_plugins_new', MainWP_Utility::array_merge($pluginsNewUpdateSaved, $pluginsNewUpdate));
         }
         if (count($themesNewUpdate) != 0) {
             $themesNewUpdateSaved = get_option('mainwp_updatescheck_mail_update_themes_new');
             MainWP_Utility::update_option('mainwp_updatescheck_mail_update_themes_new', MainWP_Utility::array_merge($themesNewUpdateSaved, $themesNewUpdate));
         }
         if (count($coreToUpdate) != 0) {
             $coreToUpdateSaved = get_option('mainwp_updatescheck_mail_update_core');
             MainWP_Utility::update_option('mainwp_updatescheck_mail_update_core', MainWP_Utility::array_merge($coreToUpdateSaved, $coreToUpdate));
         }
         if (count($pluginsToUpdate) != 0) {
             $pluginsToUpdateSaved = get_option('mainwp_updatescheck_mail_update_plugins');
             MainWP_Utility::update_option('mainwp_updatescheck_mail_update_plugins', MainWP_Utility::array_merge($pluginsToUpdateSaved, $pluginsToUpdate));
         }
         if (count($themesToUpdate) != 0) {
             $themesToUpdateSaved = get_option('mainwp_updatescheck_mail_update_themes');
             MainWP_Utility::update_option('mainwp_updatescheck_mail_update_themes', MainWP_Utility::array_merge($themesToUpdateSaved, $themesToUpdate));
         }
         if (count($ignoredCoreToUpdate) != 0) {
             $ignoredCoreToUpdateSaved = get_option('mainwp_updatescheck_mail_ignore_core');
             MainWP_Utility::update_option('mainwp_updatescheck_mail_ignore_core', MainWP_Utility::array_merge($ignoredCoreToUpdateSaved, $ignoredCoreToUpdate));
         }
         if (count($ignoredCoreNewUpdate) != 0) {
             $ignoredCoreNewUpdateSaved = get_option('mainwp_updatescheck_mail_ignore_core_new');
             MainWP_Utility::update_option('mainwp_updatescheck_mail_ignore_core_new', MainWP_Utility::array_merge($ignoredCoreNewUpdateSaved, $ignoredCoreNewUpdate));
         }
         if (count($ignoredPluginsToUpdate) != 0) {
             $ignoredPluginsToUpdateSaved = get_option('mainwp_updatescheck_mail_ignore_plugins');
             MainWP_Utility::update_option('mainwp_updatescheck_mail_ignore_plugins', MainWP_Utility::array_merge($ignoredPluginsToUpdateSaved, $ignoredPluginsToUpdate));
         }
         if (count($ignoredPluginsNewUpdate) != 0) {
             $ignoredPluginsNewUpdateSaved = get_option('mainwp_updatescheck_mail_ignore_plugins_new');
             MainWP_Utility::update_option('mainwp_updatescheck_mail_ignore_plugins_new', MainWP_Utility::array_merge($ignoredPluginsNewUpdateSaved, $ignoredPluginsNewUpdate));
         }
         if (count($ignoredThemesToUpdate) != 0) {
             $ignoredThemesToUpdateSaved = get_option('mainwp_updatescheck_mail_ignore_themes');
             MainWP_Utility::update_option('mainwp_updatescheck_mail_ignore_themes', MainWP_Utility::array_merge($ignoredThemesToUpdateSaved, $ignoredThemesToUpdate));
         }
         if (count($ignoredThemesNewUpdate) != 0) {
             $ignoredThemesNewUpdateSaved = get_option('mainwp_updatescheck_mail_ignore_themes_new');
             MainWP_Utility::update_option('mainwp_updatescheck_mail_ignore_themes_new', MainWP_Utility::array_merge($ignoredThemesNewUpdateSaved, $ignoredThemesNewUpdate));
         }
         if ($pluginConflicts != '') {
             $pluginConflictsSaved = get_option('mainwp_updatescheck_mail_pluginconflicts');
             if ($pluginConflictsSaved == false) {
                 $pluginConflictsSaved = '';
             }
             MainWP_Utility::update_option('mainwp_updatescheck_mail_pluginconflicts', $pluginConflictsSaved . $pluginConflicts);
         }
         if ($themeConflicts != '') {
             $themeConflictsSaved = get_option('mainwp_updatescheck_mail_themeconflicts');
             if ($themeConflictsSaved == false) {
                 $themeConflictsSaved = '';
             }
             MainWP_Utility::update_option('mainwp_updatescheck_mail_themeconflicts', $themeConflictsSaved . $themeConflicts);
         }
         if (count($coreToUpdate) == 0 && count($pluginsToUpdate) == 0 && count($themesToUpdate) == 0 && count($ignoredCoreToUpdate) == 0 && count($ignoredCoreNewUpdate) == 0 && $pluginConflicts == '' && $themeConflicts == '') {
             return;
         }
         if (get_option('mainwp_automaticDailyUpdate') != 1) {
             return;
         }
         //Check if backups are required!
         if (get_option('mainwp_backup_before_upgrade') == 1) {
             $sitesCheckCompleted = get_option('mainwp_automaticUpdate_backupChecks');
             if (!is_array($sitesCheckCompleted)) {
                 $sitesCheckCompleted = array();
             }
             $websitesToCheck = array();
             foreach ($pluginsToUpdateNow as $websiteId => $slugs) {
                 $websitesToCheck[$websiteId] = true;
             }
             foreach ($themesToUpdateNow as $websiteId => $slugs) {
                 $websitesToCheck[$websiteId] = true;
             }
             foreach ($coreToUpdateNow as $websiteId) {
                 $websitesToCheck[$websiteId] = true;
             }
             foreach ($websitesToCheck as $siteId => $bool) {
                 if ($allWebsites[$siteId]->backup_before_upgrade == 0) {
                     $sitesCheckCompleted[$siteId] = true;
                 }
                 if (isset($sitesCheckCompleted[$siteId])) {
                     continue;
                 }
                 $dir = MainWP_Utility::getMainWPSpecificDir($siteId);
                 //Check if backup ok
                 $lastBackup = -1;
                 if (file_exists($dir) && ($dh = opendir($dir))) {
                     while (($file = readdir($dh)) !== false) {
                         if ($file != '.' && $file != '..') {
                             $theFile = $dir . $file;
                             if (MainWP_Utility::isArchive($file) && !MainWP_Utility::isSQLArchive($file) && filemtime($theFile) > $lastBackup) {
                                 $lastBackup = filemtime($theFile);
                             }
                         }
                     }
                     closedir($dh);
                 }
                 $backupRequired = $lastBackup < time() - 7 * 24 * 60 * 60 ? true : false;
                 if (!$backupRequired) {
                     $sitesCheckCompleted[$siteId] = true;
                     MainWP_Utility::update_option('mainwp_automaticUpdate_backupChecks', $sitesCheckCompleted);
                     continue;
                 }
                 try {
                     $result = MainWP_Manage_Sites::backup($siteId, 'full', '', '', 0, 0, 0, 0);
                     MainWP_Manage_Sites::backupDownloadFile($siteId, 'full', $result['url'], $result['local']);
                     $sitesCheckCompleted[$siteId] = true;
                     MainWP_Utility::update_option('mainwp_automaticUpdate_backupChecks', $sitesCheckCompleted);
                 } catch (Exception $e) {
                     $sitesCheckCompleted[$siteId] = false;
                     MainWP_Utility::update_option('mainwp_automaticUpdate_backupChecks', $sitesCheckCompleted);
                 }
             }
         } else {
             $sitesCheckCompleted = null;
         }
         //Update plugins
         foreach ($pluginsToUpdateNow as $websiteId => $slugs) {
             if ($sitesCheckCompleted != null && $sitesCheckCompleted[$websiteId] == false) {
                 continue;
             }
             try {
                 MainWP_Utility::fetchUrlAuthed($allWebsites[$websiteId], 'upgradeplugintheme', array('type' => 'plugin', 'list' => urldecode(implode(',', $slugs))));
                 if (isset($information['sync']) && !empty($information['sync'])) {
                     MainWP_Sync::syncInformationArray($allWebsites[$websiteId], $information['sync']);
                 }
             } catch (Exception $e) {
             }
         }
         //Update themes
         foreach ($themesToUpdateNow as $websiteId => $slugs) {
             if ($sitesCheckCompleted != null && $sitesCheckCompleted[$websiteId] == false) {
                 continue;
             }
             try {
                 MainWP_Utility::fetchUrlAuthed($allWebsites[$websiteId], 'upgradeplugintheme', array('type' => 'theme', 'list' => urldecode(implode(',', $slugs))));
                 if (isset($information['sync']) && !empty($information['sync'])) {
                     MainWP_Sync::syncInformationArray($allWebsites[$websiteId], $information['sync']);
                 }
             } catch (Exception $e) {
             }
         }
         //Update core
         foreach ($coreToUpdateNow as $websiteId) {
             if ($sitesCheckCompleted != null && $sitesCheckCompleted[$websiteId] == false) {
                 continue;
             }
             try {
                 MainWP_Utility::fetchUrlAuthed($allWebsites[$websiteId], 'upgrade');
             } catch (Exception $e) {
             }
         }
         do_action('mainwp_cronupdatecheck_action', $pluginsNewUpdate, $pluginsToUpdate, $pluginsToUpdateNow, $themesNewUpdate, $themesToUpdate, $themesToUpdateNow, $coreNewUpdate, $coreToUpdate, $coreToUpdateNow);
     }
 }
Exemple #5
0
 public static function action($pAction, $theme)
 {
     $websiteIdEnc = $_POST['websiteId'];
     $websiteId = $websiteIdEnc;
     if (!MainWP_Utility::ctype_digit($websiteId)) {
         die('FAIL');
     }
     $website = MainWP_DB::Instance()->getWebsiteById($websiteId);
     if (!MainWP_Utility::can_edit_website($website)) {
         die('FAIL');
     }
     try {
         $information = MainWP_Utility::fetchUrlAuthed($website, 'theme_action', array('action' => $pAction, 'theme' => $theme));
     } catch (MainWP_Exception $e) {
         die('FAIL');
     }
     if (!isset($information['out']) || !isset($information['status']) || $information['status'] != 'SUCCESS') {
         die('FAIL');
     }
     die($information['out']);
 }
    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>&nbsp;<?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>&nbsp;<?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>&nbsp;<?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>&nbsp;<?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;
    }
Exemple #7
0
 public static function getPostMeta($postId, $keys, $value, $websiteId)
 {
     if (!MainWP_Utility::ctype_digit($postId)) {
         return;
     }
     if (!MainWP_Utility::ctype_digit($websiteId)) {
         return;
     }
     $website = MainWP_DB::Instance()->getWebsiteById($websiteId);
     if (!MainWP_Utility::can_edit_website($website)) {
         return;
     }
     try {
         $results = MainWP_Utility::fetchUrlAuthed($website, 'get_post_meta', array('id' => base64_encode($postId), 'keys' => base64_encode($keys), 'value' => base64_encode($value)));
     } catch (MainWP_Exception $e) {
         return;
     }
     return $results;
 }
 function mainwp_force_destroy_sessions()
 {
     $this->secure_request('mainwp_force_destroy_sessions');
     $website_id = isset($_POST['website_id']) ? (int) $_POST['website_id'] : 0;
     if (!MainWP_DB::Instance()->getWebsiteById($website_id)) {
         die(json_encode(array('error' => array('message' => __('This website does not exist', 'mainwp')))));
     }
     $website = MainWP_DB::Instance()->getWebsiteById($website_id);
     if (!MainWP_Utility::can_edit_website($website)) {
         die(json_encode(array('error' => array('message' => __('You cannot edit this website', 'mainwp')))));
     }
     try {
         $information = MainWP_Utility::fetchUrlAuthed($website, 'settings_tools', array('action' => 'force_destroy_sessions'));
         global $mainWP;
         if ($mainWP->getVersion() == '2.0.22' || $mainWP->getVersion() == '2.0.23') {
             if (get_option('mainwp_fixed_security_2022') != 1) {
                 update_option('mainwp_fixed_security_2022', 1);
             }
         }
     } catch (Exception $e) {
         $information = array('error' => __('fetchUrlAuthed exception', 'mainwp'));
     }
     die(json_encode($information));
 }
 public static function upgradePluginTheme($id, $type, $list)
 {
     if (isset($id) && MainWP_Utility::ctype_digit($id)) {
         $website = MainWP_DB::Instance()->getWebsiteById($id);
         if (MainWP_Utility::can_edit_website($website)) {
             $information = MainWP_Utility::fetchUrlAuthed($website, 'upgradeplugintheme', array('type' => $type, 'list' => urldecode($list)));
             if (isset($information['upgrades'])) {
                 $tmp = array();
                 //todo: 20130718: the syncing in else branch may be removed in the future, it now works with the sync below (just here for older childs..)
                 if (isset($information['sync'])) {
                     foreach ($information['upgrades'] as $k => $v) {
                         $tmp[urlencode($k)] = $v;
                     }
                 } else {
                     $decodedPluginUpgrades = json_decode($website->plugin_upgrades, true);
                     $decodedThemeUpgrades = json_decode($website->theme_upgrades, true);
                     $decodedPremiumUpgrades = json_decode(MainWP_DB::Instance()->getWebsiteOption($website, 'premium_upgrades'), true);
                     if (is_array($decodedPremiumUpgrades)) {
                         foreach ($decodedPremiumUpgrades as $crrSlug => $premiumUpgrade) {
                             if ($premiumUpgrade['type'] == 'plugin') {
                                 if (!is_array($decodedPluginUpgrades)) {
                                     $decodedPluginUpgrades = array();
                                 }
                                 $decodedPluginUpgrades[$crrSlug] = $premiumUpgrade;
                             } else {
                                 if ($premiumUpgrade['type'] == 'theme') {
                                     if (!is_array($decodedThemeUpgrades)) {
                                         $decodedThemeUpgrades = array();
                                     }
                                     $decodedThemeUpgrades[$crrSlug] = $premiumUpgrade;
                                 }
                             }
                         }
                     }
                     foreach ($information['upgrades'] as $k => $v) {
                         $tmp[urlencode($k)] = $v;
                         if ($v == 1) {
                             if ($type == 'plugin') {
                                 if (isset($decodedPluginUpgrades[$k])) {
                                     unset($decodedPluginUpgrades[$k]);
                                 }
                             }
                             if ($type == 'theme') {
                                 if (isset($decodedThemeUpgrades[$k])) {
                                     unset($decodedThemeUpgrades[$k]);
                                 }
                             }
                         }
                     }
                     if ($type == 'plugin') {
                         MainWP_DB::Instance()->updateWebsiteValues($website->id, array('plugin_upgrades' => json_encode($decodedPluginUpgrades)));
                     }
                     if ($type == 'theme') {
                         MainWP_DB::Instance()->updateWebsiteValues($website->id, array('theme_upgrades' => json_encode($decodedThemeUpgrades)));
                     }
                 }
                 return $tmp;
             } else {
                 if (isset($information['error'])) {
                     throw new MainWP_Exception('WPERROR', $information['error']);
                 } else {
                     throw new MainWP_Exception('ERROR', 'Invalid response from site');
                 }
             }
         }
     }
     throw new MainWP_Exception('ERROR', __('Invalid request', 'mainwp'));
 }
 public static function action_update($pAction)
 {
     $postId = $_POST['postId'];
     $websiteIdEnc = $_POST['websiteId'];
     $post_data = $_POST['post_data'];
     if (!MainWP_Utility::ctype_digit($postId)) {
         die('FAIL');
     }
     $websiteId = $websiteIdEnc;
     if (!MainWP_Utility::ctype_digit($websiteId)) {
         die('FAIL');
     }
     $website = MainWP_DB::Instance()->getWebsiteById($websiteId);
     if (!MainWP_Utility::can_edit_website($website)) {
         die('FAIL');
     }
     try {
         $information = MainWP_Utility::fetchUrlAuthed($website, 'post_action', array('action' => $pAction, 'id' => $postId, 'post_data' => $post_data));
     } catch (MainWP_Exception $e) {
         die('FAIL');
     }
     if (!isset($information['status']) || $information['status'] != 'SUCCESS') {
         die('FAIL');
     }
 }
Exemple #11
0
 public static function action($pAction, $extra = '')
 {
     $userId = $_POST['userId'];
     $userName = $_POST['userName'];
     $websiteIdEnc = $_POST['websiteId'];
     $pass = $_POST['update_password'];
     if (!MainWP_Utility::ctype_digit($userId)) {
         die(json_encode(array('error' => 'Invalid Request.')));
     }
     $websiteId = $websiteIdEnc;
     if (!MainWP_Utility::ctype_digit($websiteId)) {
         die(json_encode(array('error' => 'Invalid Request.')));
     }
     $website = MainWP_DB::Instance()->getWebsiteById($websiteId);
     if (!MainWP_Utility::can_edit_website($website)) {
         die(json_encode(array('error' => 'You can not edit this website.')));
     }
     if ($pAction == 'delete' && $website->adminname == $userName) {
         die(json_encode(array('error' => __('This user is used for our secure link, it can not be deleted.', 'mainwp'))));
     }
     if ($pAction == 'changeRole' && $website->adminname == $userName) {
         die(json_encode(array('error' => __('This user is used for our secure link, you can not change the role.', 'mainwp'))));
     }
     try {
         $information = MainWP_Utility::fetchUrlAuthed($website, 'user_action', array('action' => $pAction, 'id' => $userId, 'extra' => $extra, 'user_pass' => $pass));
     } catch (MainWP_Exception $e) {
         die(json_encode(array('error' => $e->getMessage())));
     }
     if (!isset($information['status']) || $information['status'] != 'SUCCESS') {
         die(json_encode(array('error' => 'Unexpected error.')));
     }
 }
 public static function scan()
 {
     if (!isset($_POST['childId'])) {
         die(json_encode(array('error' => 'Wrong request')));
     }
     $website = MainWP_DB::Instance()->getWebsiteById($_POST['childId']);
     if (!$website) {
         die(json_encode(array('error' => 'Site not found')));
     }
     try {
         $post_data = array('search' => 'mainwp-child-id-*', 'search_columns' => 'user_login,display_name,user_email');
         $rslt = MainWP_Utility::fetchUrlAuthed($website, 'search_users', $post_data);
         $usersfound = !(is_array($rslt) && count($rslt) == 0);
         if (!$usersfound) {
             //fallback to plugin search
             $post_data = array('keyword' => 'WordPress admin security');
             $post_data['status'] = 'active';
             $post_data['filter'] = true;
             $rslt = MainWP_Utility::fetchUrlAuthed($website, 'get_all_plugins', $post_data);
             $pluginfound = !(is_array($rslt) && count($rslt) == 0);
             if (!$pluginfound) {
                 die(json_encode(array('success' => 'No issues found.')));
             }
         }
         die(json_encode(array('success' => 'mainwp-child-id users found (<a href="http://docs.mainwp.com/mainwp-cleanup/" target="_blank">solution</a>)')));
     } catch (Exception $e) {
         die('error');
     }
 }
 public static function unfixSecurityIssue()
 {
     if (!isset($_REQUEST['id']) || !MainWP_Utility::ctype_digit($_REQUEST['id'])) {
         return '';
     }
     $website = MainWP_DB::Instance()->getWebsiteById($_REQUEST['id']);
     if (!MainWP_Utility::can_edit_website($website)) {
         return '';
     }
     $information = MainWP_Utility::fetchUrlAuthed($website, 'securityUnFix', array('feature' => $_REQUEST['feature']));
     if (isset($information['sync']) && !empty($information['sync'])) {
         MainWP_Sync::syncInformationArray($website, $information['sync']);
         unset($information['sync']);
     }
     return $information;
 }
 public static function updateChildsiteValue()
 {
     if (isset($_POST['site_id']) && MainWP_Utility::ctype_digit($_POST['site_id'])) {
         $website = MainWP_DB::Instance()->getWebsiteById($_POST['site_id']);
         if (MainWP_Utility::can_edit_website($website)) {
             $error = '';
             $uniqueId = isset($_POST['unique_id']) ? $_POST['unique_id'] : '';
             try {
                 $information = MainWP_Utility::fetchUrlAuthed($website, 'update_values', array('uniqueId' => $uniqueId));
             } catch (MainWP_Exception $e) {
                 $error = $e->getMessage();
             }
             if ($error != '') {
                 die(json_encode(array('error' => $error)));
             } else {
                 if (isset($information['result']) && $information['result'] == 'ok') {
                     die(json_encode(array('result' => 'SUCCESS')));
                 } else {
                     die(json_encode(array('undefined_error' => true)));
                 }
             }
         }
     }
     die(json_encode(array('error' => 'NO_SIDE_ID')));
 }
Exemple #15
0
 public static function syncSite(&$pWebsite = null, $pForceFetch = false, $pAllowDisconnect = true)
 {
     if ($pWebsite == null) {
         return false;
     }
     $userExtension = MainWP_DB::Instance()->getUserExtensionByUserId($pWebsite->userid);
     if ($userExtension == null) {
         return false;
     }
     MainWP_Utility::endSession();
     try {
         $pluginDir = $pWebsite->pluginDir;
         if ($pluginDir == '') {
             $pluginDir = $userExtension->pluginDir;
         }
         $cloneEnabled = apply_filters('mainwp_clone_enabled', false);
         $cloneSites = array();
         if ($cloneEnabled) {
             $disallowedCloneSites = get_option('mainwp_clone_disallowedsites');
             if ($disallowedCloneSites === false) {
                 $disallowedCloneSites = array();
             }
             $websites = MainWP_DB::Instance()->query(MainWP_DB::Instance()->getSQLWebsitesForCurrentUser());
             if ($websites) {
                 while ($websites && ($website = @MainWP_DB::fetch_object($websites))) {
                     if (in_array($website->id, $disallowedCloneSites)) {
                         continue;
                     }
                     if ($website->id == $pWebsite->id) {
                         continue;
                     }
                     $cloneSites[$website->id] = array('name' => $website->name, 'url' => $website->url, 'extauth' => $website->extauth, 'size' => $website->totalsize);
                 }
                 @MainWP_DB::free_result($websites);
             }
         }
         $pluginConflicts = get_option('mainwp_pluginConflicts');
         if ($pluginConflicts !== false) {
             $pluginConflicts = array_keys($pluginConflicts);
         }
         $themeConflicts = get_option('mainwp_themeConflicts');
         if ($themeConflicts !== false) {
             $themeConflicts = array_keys($themeConflicts);
         }
         $othersData = apply_filters('mainwp-sync-others-data', array(), $pWebsite);
         $information = MainWP_Utility::fetchUrlAuthed($pWebsite, 'stats', array('optimize' => get_option('mainwp_optimize') == 1 ? 1 : 0, 'heatMap' => MainWP_Extensions::isExtensionAvailable('mainwp-heatmap-extension') ? $userExtension->heatMap : 0, 'pluginDir' => $pluginDir, 'cloneSites' => !$cloneEnabled ? 0 : urlencode(json_encode($cloneSites)), 'pluginConflicts' => json_encode($pluginConflicts), 'themeConflicts' => json_encode($themeConflicts), 'othersData' => json_encode($othersData), 'server' => get_admin_url(), 'numberdaysOutdatePluginTheme' => get_option('mainwp_numberdays_Outdate_Plugin_Theme', 365)), true, $pForceFetch);
         $return = self::syncInformationArray($pWebsite, $information, '', 1, false, $pAllowDisconnect);
         return $return;
     } catch (MainWP_Exception $e) {
         $sync_errors = '';
         $offline_check_result = 1;
         if ($e->getMessage() == 'HTTPERROR') {
             $sync_errors = __('HTTP error', 'mainwp') . ($e->getMessageExtra() != null ? ' - ' . $e->getMessageExtra() : '');
             $offline_check_result = -1;
         } else {
             if ($e->getMessage() == 'NOMAINWP') {
                 $sync_errors = __('MainWP not detected', 'mainwp');
                 $offline_check_result = 1;
             }
         }
         return self::syncInformationArray($pWebsite, $information, $sync_errors, $offline_check_result, true, $pAllowDisconnect);
     }
 }
 public static function upgradePluginThemeTranslation($id, $type, $list)
 {
     if (isset($id) && MainWP_Utility::ctype_digit($id)) {
         $website = MainWP_DB::Instance()->getWebsiteById($id);
         if (MainWP_Utility::can_edit_website($website)) {
             $information = MainWP_Utility::fetchUrlAuthed($website, 'translation' === $type ? 'upgradetranslation' : 'upgradeplugintheme', array('type' => $type, 'list' => urldecode($list)));
             if (isset($information['upgrades'])) {
                 $tmp = array();
                 if (isset($information['upgrades'])) {
                     foreach ($information['upgrades'] as $k => $v) {
                         $tmp[urlencode($k)] = $v;
                     }
                 }
                 return $tmp;
             } else {
                 if (isset($information['error'])) {
                     throw new MainWP_Exception('WPERROR', $information['error']);
                 } else {
                     throw new MainWP_Exception('ERROR', 'Invalid response from site');
                 }
             }
         }
     }
     throw new MainWP_Exception('ERROR', __('Invalid request', 'mainwp'));
 }