diff --git a/class/class-mainwp-child-back-up-buddy.php b/class/class-mainwp-child-back-up-buddy.php index ca8d86c..52c6482 100644 --- a/class/class-mainwp-child-back-up-buddy.php +++ b/class/class-mainwp-child-back-up-buddy.php @@ -27,6 +27,8 @@ class MainWP_Child_Back_Up_Buddy { return; } + add_filter( 'mainwp-site-sync-others-data', array( $this, 'syncOthersData' ), 10, 2 ); + add_action( 'wp_ajax_mainwp_backupbuddy_download_archive', array( $this, 'download_archive' ) ); add_action( 'mainwp_child_site_stats', array( $this, 'do_site_stats' ) ); @@ -79,7 +81,7 @@ class MainWP_Child_Back_Up_Buddy { $this->do_reports_log('backupbuddy'); } } - + // ok function do_reports_log($ext = '') { if ($ext !== 'backupbuddy') return; @@ -87,83 +89,106 @@ class MainWP_Child_Back_Up_Buddy { if (!$this->is_backupbuddy_installed) { return; } + + try { + + MainWP_Helper::check_methods( 'pb_backupbuddy', array( 'plugin_path' )); - if ( ! class_exists( 'backupbuddy_core' ) ) { - require_once( pb_backupbuddy::plugin_path() . '/classes/core.php' ); - } - - // Backup type. - $pretty_type = array( - 'full' => 'Full', - 'db' => 'Database', - 'files' => 'Files', - ); - - $recentBackups_list = glob( backupbuddy_core::getLogDirectory() . 'fileoptions/*.txt' ); - - foreach( $recentBackups_list as $backup_fileoptions ) { - - require_once( pb_backupbuddy::plugin_path() . '/classes/fileoptions.php' ); - pb_backupbuddy::status( 'details', 'Fileoptions instance #1.' ); - $backup = new pb_backupbuddy_fileoptions( $backup_fileoptions, $read_only = true ); - if ( true !== ( $result = $backup->is_ok() ) ) { - continue; + if ( ! class_exists( 'backupbuddy_core' ) ) { + if ( file_exists(pb_backupbuddy::plugin_path() . '/classes/core.php') ) + require_once( pb_backupbuddy::plugin_path() . '/classes/core.php' ); } - $backup = &$backup->options; + if (file_exists(pb_backupbuddy::plugin_path() . '/classes/fileoptions.php')) + require_once( pb_backupbuddy::plugin_path() . '/classes/fileoptions.php' ); - if ( !isset( $backup['serial'] ) || ( $backup['serial'] == '' ) ) { - continue; - } + MainWP_Helper::check_classes_exists(array( 'backupbuddy_core', 'pb_backupbuddy_fileoptions' )); + MainWP_Helper::check_methods('backupbuddy_core', 'getLogDirectory'); + + // Backup type. + $pretty_type = array( + 'full' => 'Full', + 'db' => 'Database', + 'files' => 'Files', + ); - if ( ( $backup['finish_time'] >= $backup['start_time'] ) && ( 0 != $backup['start_time'] ) ) { - // it is ok - } else { - continue; - } + $recentBackups_list = glob( backupbuddy_core::getLogDirectory() . 'fileoptions/*.txt' ); - if ( isset( $backup['profile'] ) && isset( $backup['profile']['type'] ) ) { - $backupType = pb_backupbuddy::$format->prettify( $backup['profile']['type'], $pretty_type ); - } else { - $backupType = backupbuddy_core::pretty_backup_type( backupbuddy_core::getBackupTypeFromFile( $backup['archive_file'] ) ); - } - if ( '' == $backupType ) { - $backupType = 'Unknown'; - } + foreach( $recentBackups_list as $backup_fileoptions ) { - $finish_time = $backup['finish_time']; - $message = 'BackupBuddy ' . $backupType . ' finished'; - if (!empty($finish_time)) { - do_action( 'mainwp_reports_backupbuddy_backup', $message, $backupType, $finish_time); - MainWP_Helper::update_lasttime_backup('backupbuddy', $finish_time); // to support backup before update feature - } + $backup = new pb_backupbuddy_fileoptions( $backup_fileoptions, $read_only = true ); + if ( method_exists($backup, 'is_ok') && true !== ( $result = $backup->is_ok() ) ) { + continue; + } + + $backup = &$backup->options; + + if ( !isset( $backup['serial'] ) || ( $backup['serial'] == '' ) ) { + continue; + } + + if ( ( $backup['finish_time'] >= $backup['start_time'] ) && ( 0 != $backup['start_time'] ) ) { + // it is ok + } else { + continue; + } + + $backupType = ''; + if ( isset( $backup['profile'] ) && isset( $backup['profile']['type'] ) ) { + if (true === MainWP_Helper::check_properties('pb_backupbuddy', 'format', true)) { + if (true === MainWP_Helper::check_methods(pb_backupbuddy::$format, array( 'prettify' ), true)) { + $backupType = pb_backupbuddy::$format->prettify( $backup['profile']['type'], $pretty_type ); + } + } + } else { + if (true === MainWP_Helper::check_methods('backupbuddy_core', array( 'pretty_backup_type', 'getBackupTypeFromFile' ), true)) { + $backupType = backupbuddy_core::pretty_backup_type( backupbuddy_core::getBackupTypeFromFile( $backup['archive_file'] ) ); + } + } + + if ( '' == $backupType ) { + $backupType = 'Unknown'; + } + + $finish_time = $backup['finish_time']; + $message = 'BackupBuddy ' . $backupType . ' finished'; + if (!empty($finish_time)) { + do_action( 'mainwp_reports_backupbuddy_backup', $message, $backupType, $finish_time); + MainWP_Helper::update_lasttime_backup('backupbuddy', $finish_time); // to support backup before update feature + } + } + + if ( file_exists(pb_backupbuddy::plugin_path() . '/destinations/live/live_periodic.php') ) { + require_once( pb_backupbuddy::plugin_path() . '/destinations/live/live_periodic.php' ); + + MainWP_Helper::check_classes_exists(array( 'backupbuddy_live_periodic' )); + MainWP_Helper::check_methods('backupbuddy_live_periodic', 'get_stats'); + + $state = backupbuddy_live_periodic::get_stats(); + if (is_array($state) && isset($state['stats'])) { + + if ( is_array($state['stats'] ) && isset( $state['stats']['last_remote_snapshot'] )) { + if (isset( $state['stats']['last_remote_snapshot_response'] )) { + $resp = $state['stats']['last_remote_snapshot_response']; + if ( isset( $resp['success'] ) && $resp['success']) { + $finish_time = $state['stats']['last_remote_snapshot']; + $backupType = 'Live Backup to cloud'; + $message = 'BackupBuddy ' . $backupType . ' finished'; + if (!empty($finish_time)) { + do_action( 'mainwp_reports_backupbuddy_backup', $message, $backupType, $finish_time); + MainWP_Helper::update_lasttime_backup('backupbuddy', $finish_time); // to support backup before update feature + } + + } + } + } + + } + } + } catch( Exception $e ) { + } - - if ( file_exists(pb_backupbuddy::plugin_path() . '/destinations/live/live_periodic.php') ) { - require_once( pb_backupbuddy::plugin_path() . '/destinations/live/live_periodic.php' ); - - $state = backupbuddy_live_periodic::get_stats(); - if (is_array($state) && isset($state['stats'])) { - - if ( is_array($state['stats'] ) && isset( $state['stats']['last_remote_snapshot'] )) { - if (isset( $state['stats']['last_remote_snapshot_response'] )) { - $resp = $state['stats']['last_remote_snapshot_response']; - if ( isset( $resp['success'] ) && $resp['success']) { - $finish_time = $state['stats']['last_remote_snapshot']; - $backupType = 'Live Backup to cloud'; - $message = 'BackupBuddy ' . $backupType . ' finished'; - if (!empty($finish_time)) { - do_action( 'mainwp_reports_backupbuddy_backup', $message, $backupType, $finish_time); - MainWP_Helper::update_lasttime_backup('backupbuddy', $finish_time); // to support backup before update feature - } - - } - } - } - - } - } } public function action() { @@ -341,7 +366,7 @@ class MainWP_Child_Back_Up_Buddy { $type = isset($_POST['type']) ? $_POST['type'] : ''; if ($type !== 'general_settings' && $type !== 'advanced_settings' && $type !== 'all' ) { - return array('error' => __('Invalid data!'), 'extra' => 'Invalid settings data!'); + return array('error' => __('Invalid data. Please check and try again.') ); } $filter_advanced_settings = array( @@ -697,26 +722,47 @@ class MainWP_Child_Back_Up_Buddy { return $information; } - - public function get_sync_data() { - if ( ! class_exists( 'backupbuddy_core' ) ) { - if (class_exists( 'pb_backupbuddy' ) && file_exists(pb_backupbuddy::plugin_path() . '/classes/core.php')) - require_once( pb_backupbuddy::plugin_path() . '/classes/core.php' ); - else - return false; - } - - if (!function_exists('backupbuddy_core::get_plugins_root')) - return false; - - $information = array(); - $information['plugins_root'] = backupbuddy_core::get_plugins_root(); - $information['themes_root'] = backupbuddy_core::get_themes_root(); - $information['media_root'] = backupbuddy_core::get_media_root(); - $information['additional_tables'] = $this->pb_additional_tables(); - $information['abspath'] = ABSPATH; + // ok + public function syncOthersData( $information, $data = array() ) { + if ( isset( $data['syncBackupBuddy'] ) && $data['syncBackupBuddy'] ) { + try { + $information['syncBackupBuddy'] = $this->get_sync_data(); + } catch(Exception $e) { + + } + } return $information; } + + // ok + public function get_sync_data() { + + try { + if ( ! class_exists( 'backupbuddy_core' ) ) { + MainWP_Helper::check_classes_exists('pb_backupbuddy'); + MainWP_Helper::check_methods('pb_backupbuddy', array( 'plugin_path' ) ); + + $plugin_path = pb_backupbuddy::plugin_path(); + if (file_exists($plugin_path . '/classes/core.php')) + require_once( $plugin_path . '/classes/core.php' ); + } + + MainWP_Helper::check_classes_exists('backupbuddy_core'); + MainWP_Helper::check_methods('backupbuddy_core', array( 'get_plugins_root', 'get_themes_root', 'get_media_root' ) ); + + $data = array(); + $data['plugins_root'] = backupbuddy_core::get_plugins_root(); + $data['themes_root'] = backupbuddy_core::get_themes_root(); + $data['media_root'] = backupbuddy_core::get_media_root(); + $data['additional_tables'] = $this->pb_additional_tables(); + $data['abspath'] = ABSPATH; + return $data; + } catch(Exception $e) { + // not exit here + } + + return false; + } function backup_list() { require_once( pb_backupbuddy::plugin_path() . '/destinations/bootstrap.php' ); @@ -970,9 +1016,15 @@ class MainWP_Child_Back_Up_Buddy { } - + // ok function pb_additional_tables( $display_size = false ) { - + + MainWP_Helper::check_classes_exists('pb_backupbuddy'); + MainWP_Helper::check_methods('pb_backupbuddy', 'plugin_url'); + MainWP_Helper::check_properties('pb_backupbuddy', 'format'); + MainWP_Helper::check_methods(pb_backupbuddy::$format, 'file_size'); + + $return = ''; $size_string = ''; @@ -2456,7 +2508,7 @@ class MainWP_Child_Back_Up_Buddy { backupbuddy_live::send_trim_settings(); return array('ok' => 1); } else { - $error = 'Invalid data.'; + $error = 'Invalid data. Please check and try again.'; } return array('error' => $error); } @@ -2475,7 +2527,7 @@ class MainWP_Child_Back_Up_Buddy { require_once( pb_backupbuddy::plugin_path() . '/destinations/live/init.php' ); delete_transient( pb_backupbuddy_destination_live::LIVE_ACTION_TRANSIENT_NAME ); } else { - $error = 'Error: Not found.'; + $error = 'Error: destination not found.'; } $return['ok'] = 1; } else { diff --git a/class/class-mainwp-child-back-up-wordpress.php b/class/class-mainwp-child-back-up-wordpress.php index 816c0e1..63c7f74 100644 --- a/class/class-mainwp-child-back-up-wordpress.php +++ b/class/class-mainwp-child-back-up-wordpress.php @@ -14,11 +14,18 @@ class MainWP_Child_Back_Up_Wordpress { public function __construct() { require_once( ABSPATH . 'wp-admin/includes/plugin.php' ); if ( is_plugin_active( 'backupwordpress/backupwordpress.php' ) ) { - $this->is_plugin_installed = true; + $this->is_plugin_installed = true; + if ( version_compare( phpversion(), '5.3', '>=' ) ) { + add_filter( 'mainwp-site-sync-others-data', array( $this, 'syncOthersData' ), 10, 2 ); + } } + } public function init() { + if ( version_compare( phpversion(), '5.3', '<' ) ) { + return; + } if ( get_option( 'mainwp_backupwordpress_ext_enabled' ) !== 'Y' ) return; if (!$this->is_plugin_installed) return; @@ -115,25 +122,38 @@ class MainWP_Child_Back_Up_Wordpress { return $schedule_id; } - - public function syncData() { - if ( ! self::isActivated() ) { - return ''; - } - - return $this->get_sync_data(); + // ok + public function syncOthersData( $information, $data = array() ) { + if ( isset( $data['syncBackUpWordPress'] ) && $data['syncBackUpWordPress'] ) { + try { + $information['syncBackUpWordPress'] = $this->get_sync_data(); + } catch(Exception $e) { + + } + } + return $information; } - + + // ok private function get_sync_data() { + MainWP_Helper::check_classes_exists('HM\BackUpWordPress\Schedules'); + MainWP_Helper::check_methods('HM\BackUpWordPress\Schedules', array( 'get_instance', 'refresh_schedules', 'get_schedules' ) ); + HM\BackUpWordPress\Schedules::get_instance()->refresh_schedules(); $schedules = HM\BackUpWordPress\Schedules::get_instance()->get_schedules(); $backups_time = array(); - foreach ( $schedules as $sche ) { - $existing_backup = $sche->get_backups(); - if ( ! empty( $existing_backup ) ) { - $backups_time = array_merge( $backups_time, array_keys( $existing_backup ) ); - } - } + + if (is_array($schedules) && count($schedules)) { + $check = current($schedules); + MainWP_Helper::check_methods($check, array( 'get_backups' ) ); + + foreach ( $schedules as $sche ) { + $existing_backup = $sche->get_backups(); + if ( ! empty( $existing_backup ) ) { + $backups_time = array_merge( $backups_time, array_keys( $existing_backup ) ); + } + } + } $lasttime_backup = 0; if ( ! empty( $backups_time ) ) { @@ -152,28 +172,41 @@ class MainWP_Child_Back_Up_Wordpress { $this->do_reports_log('backupwordpress'); } } - + + // ok public function do_reports_log($ext = '') { if ( $ext !== 'backupwordpress' ) return; if (!$this->is_plugin_installed) return; - - // Refresh the schedules from the database to make sure we have the latest changes - HM\BackUpWordPress\Schedules::get_instance()->refresh_schedules(); - $schedules = HM\BackUpWordPress\Schedules::get_instance()->get_schedules(); - foreach($schedules as $schedule) { - foreach ( $schedule->get_backups() as $file ) { - $backup_type = $schedule->get_type(); - $message = "BackupWordpres backup " . $backup_type . ' finished'; - $destination = "N/A"; - if ( file_exists( $file ) ) { - $date = @filemtime( $file ); - if ( !empty( $date ) ) { - do_action( "backupwordpress_backup", $destination, $message, 'finished', $backup_type, $date ); - MainWP_Helper::update_lasttime_backup('backupwordpress', $date); // to support backup before update feature + + try { + MainWP_Helper::check_classes_exists('HM\BackUpWordPress\Schedules'); + MainWP_Helper::check_methods('HM\BackUpWordPress\Schedules', array( 'get_instance', 'refresh_schedules', 'get_schedules' )); + + // Refresh the schedules from the database to make sure we have the latest changes + HM\BackUpWordPress\Schedules::get_instance()->refresh_schedules(); + $schedules = HM\BackUpWordPress\Schedules::get_instance()->get_schedules(); + if (is_array($schedules) && count($schedules) > 0) { + $check = current($schedules); + MainWP_Helper::check_methods($check, array( 'get_backups', 'get_type' )); + + foreach($schedules as $schedule) { + foreach ( $schedule->get_backups() as $file ) { + $backup_type = $schedule->get_type(); + $message = "BackupWordpres backup " . $backup_type . ' finished'; + $destination = "N/A"; + if ( file_exists( $file ) ) { + $date = @filemtime( $file ); + if ( !empty( $date ) ) { + do_action( "backupwordpress_backup", $destination, $message, 'finished', $backup_type, $date ); + MainWP_Helper::update_lasttime_backup('backupwordpress', $date); // to support backup before update feature + } + } } } } - } + } catch(Exception $e) { + + } } function set_showhide() { @@ -348,7 +381,7 @@ class MainWP_Child_Back_Up_Wordpress { function hmbkp_request_delete_backup() { if ( ! isset( $_POST['hmbkp_backuparchive'] ) || empty( $_POST['hmbkp_backuparchive'] ) ) { - return array( 'error' => __( 'Invalid data!', 'mainwp-child' ) ); + return array( 'error' => __( 'Invalid data. Please check and try again.', 'mainwp-child' ) ); } $schedule_id = $this->check_schedule(); diff --git a/class/class-mainwp-child-back-wp-up.php b/class/class-mainwp-child-back-wp-up.php index 82b7916..acac5ac 100644 --- a/class/class-mainwp-child-back-wp-up.php +++ b/class/class-mainwp-child-back-wp-up.php @@ -51,25 +51,38 @@ class MainWP_Child_Back_WP_Up { public function __construct() { require_once( ABSPATH . 'wp-admin/includes/plugin.php' ); + + try { + + if ( is_plugin_active( 'backwpup-pro/backwpup.php' ) && file_exists( plugin_dir_path( __FILE__ ) . '../../backwpup-pro/backwpup.php' ) ) { + $file_path1 = plugin_dir_path( __FILE__ ) . '../../backwpup-pro/backwpup.php'; + $file_path2 = plugin_dir_path( __FILE__ ) . '../../backwpup-pro/inc/pro/class-pro.php'; + MainWP_Helper::check_files_exists(array( $file_path1, $file_path2 )); + require_once( $file_path1 ); + require_once( $file_path2 ); + $this->is_backwpup_installed = true; + $this->is_backwpup_pro = true; + } else if ( is_plugin_active( 'backwpup/backwpup.php' ) && file_exists( plugin_dir_path( __FILE__ ) . '../../backwpup/backwpup.php' ) ) { + $file_path = plugin_dir_path( __FILE__ ) . '../../backwpup/backwpup.php'; + MainWP_Helper::check_files_exists(array( $file_path )); + require_once( $file_path ); + $this->is_backwpup_installed = true; + } - if ( is_plugin_active( 'backwpup-pro/backwpup.php' ) && file_exists( plugin_dir_path( __FILE__ ) . '../../backwpup-pro/backwpup.php' ) ) { - require_once( plugin_dir_path( __FILE__ ) . '../../backwpup-pro/backwpup.php' ); - require_once( plugin_dir_path( __FILE__ ) . '../../backwpup-pro/inc/pro/class-pro.php' ); - BackWPup::get_instance(); - $this->is_backwpup_installed = true; - $this->is_backwpup_pro = true; - } else if ( is_plugin_active( 'backwpup/backwpup.php' ) && file_exists( plugin_dir_path( __FILE__ ) . '../../backwpup/backwpup.php' ) ) { - require_once( plugin_dir_path( __FILE__ ) . '../../backwpup/backwpup.php' ); - BackWPup::get_instance(); - $this->is_backwpup_installed = true; - } - - if ( $this->is_backwpup_installed ) { - add_action( 'wp_ajax_mainwp_backwpup_download_backup', array( $this, 'download_backup' ) ); - add_filter( 'mainwp-site-sync-others-data', array( $this, 'syncOthersData' ), 10, 2 ); - } + if ($this->is_backwpup_installed) { + MainWP_Helper::check_classes_exists('BackWPup'); + MainWP_Helper::check_methods('get_instance'); + BackWPup::get_instance(); + + add_action( 'wp_ajax_mainwp_backwpup_download_backup', array( $this, 'download_backup' ) ); + add_filter( 'mainwp-site-sync-others-data', array( $this, 'syncOthersData' ), 10, 2 ); + } + } catch ( Exception $e) { + // do not exit() + $this->is_backwpup_installed = false; + } } - + public function action() { if ( ! $this->is_backwpup_installed ) { MainWP_Helper::write( array( 'error' => __( 'Please install BackWPup plugin on child website', $this->plugin_translate ) ) ); @@ -203,53 +216,68 @@ class MainWP_Child_Back_WP_Up { $this->do_reports_log('backwpup'); } } - + // ok public function do_reports_log($ext = '') { if ( $ext !== 'backwpup' ) return; if (!$this->is_backwpup_installed) return; + + try { + MainWP_Helper::check_classes_exists(array('BackWPup')); + MainWP_Helper::check_methods('BackWPup', array( 'get_registered_destinations', 'get_destination' )); + + $destinations = BackWPup::get_registered_destinations(); + $jobdests = $this->get_destinations_list(); - $destinations = BackWPup::get_registered_destinations(); - $jobdests = $this->get_destinations_list(); - - if ( !empty( $jobdests ) ) { - foreach ($jobdests as $jobdest) { - list( $jobid, $dest ) = explode( '_', $jobdest ); - if ( ! empty( $destinations[ $dest ][ 'class' ] ) ) { - $dest_object = BackWPup::get_destination( $dest ); - $items = $dest_object->file_get_list( $jobdest ); - //if no items brake - if ( $items ) { - foreach ( $items as $ma ) { - if (isset($ma['time'])) { - $backup_time = $ma[ "time" ]; - $message = 'BackWPup backup finished'; - $backup_type = 'BackWPup'; - $destination = "N/A"; - if (!empty($backup_time)) { - do_action( 'mainwp_backwpup_backup', $message, $backup_type, $backup_time ); - MainWP_Helper::update_lasttime_backup( 'backwpup', $backup_time ); // to support backup before update feature - } - } - } - } - } - } - } + if ( !empty( $jobdests ) ) { + foreach ($jobdests as $jobdest) { + list( $jobid, $dest ) = explode( '_', $jobdest ); + if ( ! empty( $destinations[ $dest ][ 'class' ] ) ) { + $dest_object = BackWPup::get_destination( $dest ); + $items = $dest_object->file_get_list( $jobdest ); + //if no items brake + if ( $items ) { + foreach ( $items as $ma ) { + if (isset($ma['time'])) { + $backup_time = $ma[ "time" ]; + $message = 'BackWPup backup finished'; + $backup_type = 'BackWPup'; + $destination = "N/A"; + if (!empty($backup_time)) { + do_action( 'mainwp_backwpup_backup', $message, $backup_type, $backup_time ); + MainWP_Helper::update_lasttime_backup( 'backwpup', $backup_time ); // to support backup before update feature + } + } + } + } + } + } + } + } catch (Exception $ex) { + + } } + // ok function syncOthersData( $information, $data = array() ) { - if ( isset( $data['syncBackwpupData'] ) ) { - $lastbackup = MainWP_Helper::get_lasttime_backup('backwpup'); - $information['syncBackwpupData'] = array( - 'lastbackup' => $lastbackup - ); + if ( isset( $data['syncBackwpupData'] ) && $data['syncBackwpupData'] ) { + try{ + $lastbackup = MainWP_Helper::get_lasttime_backup('backwpup'); + $information['syncBackwpupData'] = array( + 'lastbackup' => $lastbackup + ); + } catch(Exception $e) { + + } } return $information; } function get_destinations_list() { - + MainWP_Helper::check_classes_exists(array('BackWPup', 'BackWPup_Option')); + MainWP_Helper::check_methods('BackWPup', array( 'get_registered_destinations', 'get_destination' )); + MainWP_Helper::check_methods('BackWPup_Option', array( 'get_job_ids', 'get' )); + $jobdest = array(); $jobids = BackWPup_Option::get_job_ids(); $destinations = BackWPup::get_registered_destinations(); @@ -262,11 +290,14 @@ class MainWP_Child_Back_WP_Up { if ( ! $destinations[ $dest ][ 'class' ] ) { continue; } + $dest_class = BackWPup::get_destination( $dest ); - $can_do_dest = $dest_class->file_get_list( $jobid . '_' . $dest ); - if ( ! empty( $can_do_dest ) ) { - $jobdest[ ] = $jobid . '_' . $dest; - } + if ($dest_class && method_exists($dest_class, 'file_get_list')) { + $can_do_dest = $dest_class->file_get_list( $jobid . '_' . $dest ); + if ( ! empty( $can_do_dest ) ) { + $jobdest[ ] = $jobid . '_' . $dest; + } + } } } diff --git a/class/class-mainwp-child-branding.php b/class/class-mainwp-child-branding.php index 842758d..628f73c 100644 --- a/class/class-mainwp-child-branding.php +++ b/class/class-mainwp-child-branding.php @@ -132,6 +132,8 @@ class MainWP_Child_Branding { 'remove_widget_activity' => $settings['child_remove_widget_activity'], 'remove_widget_quick' => $settings['child_remove_widget_quick'], 'remove_widget_news' => $settings['child_remove_widget_news'], + 'login_image_link' => $settings['child_login_image_link'], + 'login_image_title' => $settings['child_login_image_title'], 'site_generator' => $settings['child_site_generator'], 'generator_link' => $settings['child_generator_link'], 'admin_css' => $settings['child_admin_css'], @@ -339,6 +341,8 @@ class MainWP_Child_Branding { add_action( 'login_enqueue_scripts', array( &$this, 'custom_login_css' ) ); add_filter( 'gettext', array( &$this, 'custom_gettext' ), 99, 3 ); add_action( 'login_head', array( &$this, 'custom_login_logo' ) ); + add_filter( 'login_headerurl', array( &$this, 'custom_login_headerurl' ) ); + add_filter( 'login_headertitle', array( &$this, 'custom_login_headertitle' ) ); add_action( 'wp_head', array( &$this, 'custom_favicon_frontend' ) ); if ( isset( $extra_setting['dashboard_footer'] ) && ! empty( $extra_setting['dashboard_footer'] ) ) { //remove_filter( 'update_footer', 'core_update_footer' ); @@ -564,6 +568,26 @@ class MainWP_Child_Branding { } } + function custom_login_headerurl( $value ) { + + $extra_setting = $this->settings['extra_settings']; + if ( isset( $extra_setting['login_image_link'] ) && ! empty( $extra_setting['login_image_link'] ) ) { + return $extra_setting['login_image_link']; + } + + return $value; + } + + function custom_login_headertitle( $value ) { + + $extra_setting = $this->settings['extra_settings']; + if ( isset( $extra_setting['login_image_title'] ) && ! empty( $extra_setting['login_image_title'] ) ) { + return $extra_setting['login_image_title']; + } + + return $value; + } + function custom_gettext( $translations, $text, $domain = 'default' ) { $extra_setting = $this->settings['extra_settings']; $texts_replace = $extra_setting['texts_replace']; diff --git a/class/class-mainwp-child-ithemes-security.php b/class/class-mainwp-child-ithemes-security.php index 2d3a5f6..c6c6cc2 100644 --- a/class/class-mainwp-child-ithemes-security.php +++ b/class/class-mainwp-child-ithemes-security.php @@ -23,18 +23,17 @@ class MainWP_Child_iThemes_Security { add_filter( 'mainwp-site-sync-others-data', array( $this, 'syncOthersData' ), 10, 2 ); } - + // ok function syncOthersData( $information, $data = array() ) { if ( is_array( $data ) && isset( $data['ithemeExtActivated'] ) && ( 'yes' === $data['ithemeExtActivated'] ) ) { - $information['syncIThemeData'] = array( - 'users_and_roles' => $this->get_available_admin_users_and_roles() - ); - //MainWP_Helper::update_option( 'mainwp_ithemes_ext_activated', 'Y' ); - return $information; - - } else { - //MainWP_Helper::update_option( 'mainwp_ithemes_ext_activated', '' ); - } + try{ + $information['syncIThemeData'] = array( + 'users_and_roles' => $this->get_available_admin_users_and_roles() + ); + } catch(Exception $e) { + error_log($e->getMessage()); + } + } return $information; } @@ -58,9 +57,6 @@ class MainWP_Child_iThemes_Security { case 'save_settings': $information = $this->save_settings(); break; -// case 'whitelist': -// $information = $this->whitelist(); -// break; case 'whitelist_release': $information = $this->whitelist_release(); break; @@ -73,18 +69,12 @@ class MainWP_Child_iThemes_Security { case 'database_prefix': $information = $this->change_database_prefix(); break; -// case 'api_key': -// $information = $this->api_key(); -// break; case 'reset_api_key': $information = $this->reset_api_key(); break; case 'malware_scan': $information = $this->malware_scan(); break; -// case 'malware_get_scan_results': -// $information = $this->malware_get_scan_results(); -// break; case 'clear_all_logs': $information = $this->purge_logs(); break; @@ -134,6 +124,11 @@ class MainWP_Child_iThemes_Security { add_filter( 'all_plugins', array( $this, 'all_plugins' ) ); add_action( 'admin_menu', array( $this, 'remove_menu' ) ); add_action( 'admin_init', array( $this, 'admin_init' ) ); + add_action( 'admin_head', array( &$this, 'custom_admin_css' ) ); + if ( isset($_GET['page']) && ($_GET['page'] == 'itsec' || $_GET['page'] == 'itsec-logs' || $_GET['page'] == 'itsec-security-check') ) { + wp_redirect( get_option( 'siteurl' ) . '/wp-admin/index.php' ); + exit(); + } } } @@ -156,6 +151,16 @@ class MainWP_Child_iThemes_Security { remove_menu_page( 'itsec' ); } + function custom_admin_css() { + ?> + + is_plugin_installed = true; } + + if ( !$this->is_plugin_installed ) + return; + + add_filter( 'mainwp-site-sync-others-data', array( $this, 'syncOthersData' ), 10, 2 ); + } public function action() { @@ -27,38 +33,44 @@ class MainWP_Child_Links_Checker { MainWP_Helper::write( $information ); } blc_init(); - if ( isset( $_POST['mwp_action'] ) ) { - switch ( $_POST['mwp_action'] ) { - case 'set_showhide': - $information = $this->set_showhide(); - break; - case 'sync_data': - $information = $this->sync_data(); - break; - case 'sync_links_data': - $information = $this->sync_links_data(); - break; - case 'edit_link': - $information = $this->edit_link(); - break; - case 'unlink': - $information = $this->unlink(); - break; - case 'set_dismiss': - $information = $this->set_link_dismissed(); - break; - case 'discard': - $information = $this->discard(); - break; - case 'save_settings': - $information = $this->save_settings(); - break; - case 'force_recheck': - $information = $this->force_recheck(); - break; - } - } - MainWP_Helper::write( $information ); + + // need this try() + try { + if ( isset( $_POST['mwp_action'] ) ) { + switch ( $_POST['mwp_action'] ) { + case 'set_showhide': + $information = $this->set_showhide(); + break; + case 'sync_data': + $information = $this->get_sync_data(); + break; + case 'sync_links_data': + $information = $this->get_links_data(); + break; + case 'edit_link': + $information = $this->edit_link(); + break; + case 'unlink': + $information = $this->unlink(); + break; + case 'set_dismiss': + $information = $this->set_link_dismissed(); + break; + case 'discard': + $information = $this->discard(); + break; + case 'save_settings': + $information = $this->save_settings(); + break; + case 'force_recheck': + $information = $this->force_recheck(); + break; + } + } + MainWP_Helper::write( $information ); + } catch(Exception $e) { + MainWP_Helper::write( array('error' => $e->getMessage()) ); + } } @@ -182,7 +194,20 @@ class MainWP_Child_Links_Checker { return $information; } - function sync_data( $strategy = '' ) { + // ok + public function syncOthersData( $information, $data = array() ) { + if ( isset( $data['syncBrokenLinksCheckerData'] ) && $data['syncBrokenLinksCheckerData'] ) { + try{ + $information['syncBrokenLinksCheckerData'] = $this->get_sync_data(); + } catch(Exception $e) { + + } + } + return $information; + } + + + function get_sync_data( $strategy = '' ) { $information = array(); $data = $this->get_count_links(); if (is_array($data)) @@ -190,12 +215,24 @@ class MainWP_Child_Links_Checker { return $information; } - function sync_links_data() { + function get_links_data() { + if (!defined('BLC_DIRECTORY')) return; - require_once BLC_DIRECTORY . '/includes/link-query.php'; - require_once BLC_DIRECTORY . '/includes/modules.php'; + + $file_path1 = BLC_DIRECTORY . '/includes/link-query.php'; + $file_path2 = BLC_DIRECTORY . '/includes/modules.php'; + MainWP_Helper::check_files_exists(array( $file_path1, $file_path2 )); + + require_once $file_path1; + require_once $file_path2; + MainWP_Helper::check_classes_exists('blcLinkQuery'); + MainWP_Helper::check_methods('blcLinkQuery', 'getInstance'); + $blc_link_query = blcLinkQuery::getInstance(); + + MainWP_Helper::check_methods($blc_link_query, 'get_filter_links'); + $total = $blc_link_query->get_filter_links( 'all', array( 'count_only' => true ) ); @@ -213,7 +250,7 @@ class MainWP_Child_Links_Checker { $params['offset'] = $offset; } - $link_data = $this->do_sync_links_data($params); + $link_data = $this->links_checker_data($params); $total_sync = 0; if ($offset){ @@ -241,12 +278,23 @@ class MainWP_Child_Links_Checker { function get_count_links() { if (!defined('BLC_DIRECTORY')) return; + + $file_path1 = BLC_DIRECTORY . '/includes/link-query.php'; + $file_path2 = BLC_DIRECTORY . '/includes/modules.php'; + + MainWP_Helper::check_files_exists(array( $file_path1, $file_path2 )); + + require_once $file_path1; + require_once $file_path2; - require_once BLC_DIRECTORY . '/includes/link-query.php'; - require_once BLC_DIRECTORY . '/includes/modules.php'; - + MainWP_Helper::check_classes_exists('blcLinkQuery'); + MainWP_Helper::check_methods('blcLinkQuery', 'getInstance'); + $data = array(); $blc_link_query = blcLinkQuery::getInstance(); + + MainWP_Helper::check_methods($blc_link_query, 'get_filter_links'); + $data['broken'] = $blc_link_query->get_filter_links( 'broken', array( 'count_only' => true ) ); $data['redirects'] = $blc_link_query->get_filter_links( 'redirects', array( 'count_only' => true ) ); $data['dismissed'] = $blc_link_query->get_filter_links( 'dismissed', array( 'count_only' => true ) ); @@ -255,8 +303,11 @@ class MainWP_Child_Links_Checker { return $data; } - function do_sync_links_data($params) { + function links_checker_data($params) { + MainWP_Helper::check_functions('blc_get_links'); + MainWP_Helper::check_classes_exists('blcLink'); + $links = blc_get_links( $params ); $filter_fields = array( @@ -320,22 +371,29 @@ class MainWP_Child_Links_Checker { $get_link = new blcLink( intval( $link->link_id ) ); if ( $get_link->valid() ) { + MainWP_Helper::check_methods($get_link, 'get_instances'); $instances = $get_link->get_instances(); } if ( ! empty( $instances ) ) { - - $first_instance = reset( $instances ); + $first_instance = reset( $instances ); + + MainWP_Helper::check_methods($first_instance, array( 'ui_get_link_text', 'get_container', 'is_link_text_editable', 'is_url_editable') ); + $new_link->link_text = $first_instance->ui_get_link_text(); $extra_info['count_instance'] = count( $instances ); $container = $first_instance->get_container(); /** @var blcContainer $container */ - if ( ! empty( $container ) /* && ($container instanceof blcAnyPostContainer) */ ) { - $extra_info['container_type'] = $container->container_type; - $extra_info['container_id'] = $container->container_id; - $extra_info['source_data'] = $this->ui_get_source( $container, $first_instance->container_field ); + if ( ! empty( $container ) /* && ($container instanceof blcAnyPostContainer) */ ) { + if (true === MainWP_Helper::check_properties($first_instance, array( 'container_field' ), true )) { + if (true === MainWP_Helper::check_properties($container, array( 'container_type', 'container_id' ), true )) { + $extra_info['container_type'] = $container->container_type; + $extra_info['container_id'] = $container->container_id; + $extra_info['source_data'] = $this->ui_get_source( $container, $first_instance->container_field ); + } + } } $can_edit_text = false; @@ -584,8 +642,11 @@ class MainWP_Child_Links_Checker { } else { $image = 'font-awesome/font-awesome-comment-alt.png'; } - - $comment = $container->get_wrapped_object(); + + if (true !== MainWP_Helper::check_methods($container, array( 'get_wrapped_object'), true )) + return false; + + $comment = $container->get_wrapped_object(); //Display a small text sample from the comment $text_sample = strip_tags( $comment->comment_content ); diff --git a/class/class-mainwp-child-pagespeed.php b/class/class-mainwp-child-pagespeed.php index 8c2514c..e06a553 100644 --- a/class/class-mainwp-child-pagespeed.php +++ b/class/class-mainwp-child-pagespeed.php @@ -18,7 +18,12 @@ class MainWP_Child_Pagespeed { if ( is_plugin_active( 'google-pagespeed-insights/google-pagespeed-insights.php' ) ) { $this->is_plugin_installed = true; } - + + if (!$this->is_plugin_installed) + return; + + add_filter( 'mainwp-site-sync-others-data', array( $this, 'syncOthersData' ), 10, 2 ); + add_action( 'mainwp_child_deactivation', array( $this, 'child_deactivation' ) ); } @@ -38,7 +43,7 @@ class MainWP_Child_Pagespeed { $information = $this->set_showhide(); break; case 'sync_data': - $information = $this->sync_data(); + $information = $this->get_sync_data(); break; case "check_pages": $information = $this->check_pages(); @@ -61,8 +66,7 @@ class MainWP_Child_Pagespeed { if ( get_option( 'mainwp_pagespeed_hide_plugin' ) === 'hide' ) { add_filter( 'all_plugins', array( $this, 'hide_plugin' ) ); - add_action('admin_menu', array($this, 'hide_menu'), 999); - //add_filter( 'update_footer', array( &$this, 'update_footer' ), 15 ); + add_action('admin_menu', array($this, 'hide_menu'), 999); } $this->init_cron(); } @@ -212,7 +216,7 @@ class MainWP_Child_Pagespeed { $strategy = $current_values['strategy']; - $result = $this->sync_data( $strategy ); + $result = $this->get_sync_data( $strategy ); if ( isset( $_POST['doaction'] ) && ( 'check_new_pages' === $_POST['doaction'] || 'recheck_all_pages' === $_POST['doaction'] ) ) { if ( 'recheck_all_pages' === $_POST['doaction'] ) { @@ -257,7 +261,18 @@ class MainWP_Child_Pagespeed { return $information; } - public function sync_data( $strategy = '' ) { + public function syncOthersData( $information, $data = array() ) { + if ( isset( $data['syncPageSpeedData'] ) && $data['syncPageSpeedData'] ) { + try{ + $information['syncPageSpeedData'] = $this->get_sync_data(); + } catch(Exception $e) { + + } + } + return $information; + } + // ok + public function get_sync_data( $strategy = '' ) { if ( empty( $strategy ) ) { $strategy = 'both'; } diff --git a/class/class-mainwp-child-skeleton-key.php b/class/class-mainwp-child-skeleton-key.php index 4918364..d6175c0 100644 --- a/class/class-mainwp-child-skeleton-key.php +++ b/class/class-mainwp-child-skeleton-key.php @@ -186,7 +186,7 @@ class MainWP_Child_Skeleton_Key { $settings = isset($_POST['settings']) ? $_POST['settings'] : array(); if (!is_array($settings) || empty($settings)) - return array('error' => 'Invalid data'); + return array('error' => 'Invalid data. Please check and try again.'); $whitelist_options = array( 'general' => array( 'blogname', 'blogdescription', 'gmt_offset', 'date_format', 'time_format', 'start_of_week', 'timezone_string', 'WPLANG' ), diff --git a/class/class-mainwp-child-staging.php b/class/class-mainwp-child-staging.php index 1aa5040..3666be2 100644 --- a/class/class-mainwp-child-staging.php +++ b/class/class-mainwp-child-staging.php @@ -20,7 +20,8 @@ class MainWP_Child_Staging { if (!$this->is_plugin_installed) return; - + + add_filter( 'mainwp-site-sync-others-data', array( $this, 'syncOthersData' ), 10, 2 ); } @@ -30,9 +31,7 @@ class MainWP_Child_Staging { if (!$this->is_plugin_installed) return; - - //add_action( 'mainwp_child_site_stats', array( $this, 'do_site_stats' ) ); - + if ( get_option( 'mainwp_wp_staging_hide_plugin' ) === 'hide' ) { add_filter( 'all_plugins', array( $this, 'all_plugins' ) ); add_action( 'admin_menu', array( $this, 'remove_menu' ) ); @@ -40,6 +39,17 @@ class MainWP_Child_Staging { } } + public function syncOthersData( $information, $data = array() ) { + if ( isset( $data['syncWPStaging'] ) && $data['syncWPStaging'] ) { + try{ + $information['syncWPStaging'] = $this->get_sync_data(); + } catch(Exception $e) { + // do not exit + } + } + return $information; + } + // ok public function get_sync_data() { return $this->get_overview(); } diff --git a/class/class-mainwp-child-timecapsule.php b/class/class-mainwp-child-timecapsule.php new file mode 100644 index 0000000..a3202be --- /dev/null +++ b/class/class-mainwp-child-timecapsule.php @@ -0,0 +1,1235 @@ +is_plugin_installed = true; + } + + if (!$this->is_plugin_installed) + return; + + add_filter( 'mainwp-site-sync-others-data', array( $this, 'syncOthersData' ), 10, 2 ); + + } + + + public function init() { + if ( get_option( 'mainwp_time_capsule_ext_enabled' ) !== 'Y' ) + return; + + if (!$this->is_plugin_installed) + return; + + add_action( 'mainwp_child_site_stats', array( $this, 'do_site_stats' ) ); + add_action( 'record_auto_backup_complete', array( $this, 'do_report_backups_logging' ) ); + + if ( get_option( 'mainwp_time_capsule_hide_plugin' ) === 'hide' ) { + add_filter( 'all_plugins', array( $this, 'all_plugins' ) ); + add_action( 'admin_menu', array( $this, 'remove_menu' ) ); + add_filter( 'site_transient_update_plugins', array( &$this, 'remove_update_nag' ) ); + } + } + + + public function action() { + if (!$this->is_plugin_installed) { + MainWP_Helper::write( array('error' => 'Please install WP Time Capsule plugin on child website') ); + } + + try { + $this->require_files(); + } catch ( Exception $e) { + $error = $e->getMessage(); + MainWP_Helper::write( array('error' => $error) ); + } + + $information = array(); + if (get_option( 'mainwp_time_capsule_ext_enabled' ) !== 'Y') + MainWP_Helper::update_option( 'mainwp_time_capsule_ext_enabled', 'Y', 'yes' ); + + $options_helper = new Wptc_Options_Helper(); + $options = WPTC_Factory::get('config'); + $is_user_logged_in = $options->get_option('is_user_logged_in'); + $privileges_wptc = $options_helper->get_unserialized_privileges(); + + + + if ( isset( $_POST['mwp_action'] ) ) { + + if (( + $_POST['mwp_action'] == 'save_settings' || + $_POST['mwp_action'] == 'get_staging_details_wptc' || + $_POST['mwp_action'] == 'progress_wptc' + ) && (!$is_user_logged_in || !$privileges_wptc ) + ) { + MainWP_Helper::write( array('error' => 'You are not login to your WP Time Capsule account.') ); + } + + switch ( $_POST['mwp_action'] ) { + case 'set_showhide': + $information = $this->set_showhide(); + break; + case 'get_root_files': + $information = $this->get_root_files(); + break; + case 'get_tables': + $information = $this->get_tables(); + break; + case 'exclude_file_list': + $information = $this->exclude_file_list(); + break; + case 'exclude_table_list': + $information = $this->exclude_table_list(); + break; + case 'include_table_list': + $information = $this->include_table_list(); + break; + case 'include_table_structure_only': + $information = $this->include_table_structure_only(); + break; + case 'include_file_list': + $information = $this->include_file_list(); + break; + case 'get_files_by_key': + $information = $this->get_files_by_key(); + break; + case 'wptc_login': + $information = $this->process_wptc_login(); + break; + case 'get_installed_plugins': + $information = $this->get_installed_plugins(); + break; + case 'get_installed_themes': + $information = $this->get_installed_themes(); + break; + case 'is_staging_need_request': + $information = $this->is_staging_need_request(); + break; + case 'get_staging_details_wptc': + $information = $this->get_staging_details_wptc(); + break; + case 'start_fresh_staging_wptc': + $information = $this->start_fresh_staging_wptc(); + break; + case 'get_staging_url_wptc': + $information = $this->get_staging_url_wptc(); + break; + case 'stop_staging_wptc': + $information = $this->stop_staging_wptc(); + break; + case 'continue_staging_wptc': + $information = $this->continue_staging_wptc(); + break; + case 'delete_staging_wptc': + $information = $this->delete_staging_wptc(); + break; + case 'copy_staging_wptc': + $information = $this->copy_staging_wptc(); + break; + case 'get_staging_current_status_key': + $information = $this->get_staging_current_status_key(); + break; + case 'wptc_sync_purchase': + $information = $this->wptc_sync_purchase(); + break; + case 'init_restore': + $information = $this->init_restore(); + break; + case 'save_settings': + $information = $this->save_settings_wptc(); + break; + case 'analyze_inc_exc': + $information = $this->analyze_inc_exc(); + break; + case 'get_enabled_plugins': + $information = $this->get_enabled_plugins(); + break; + case 'get_enabled_themes': + $information = $this->get_enabled_themes(); + break; + case 'get_system_info': + $information = $this->get_system_info(); + break; + case 'update_vulns_settings': + $information = $this->update_vulns_settings(); + break; + case 'start_fresh_backup': + $information = $this->start_fresh_backup_tc_callback_wptc(); + break; + case 'save_manual_backup_name': + $information = $this->save_manual_backup_name_wptc(); + break; + case 'progress_wptc': + $information = $this->progress_wptc(); + break; + case 'stop_fresh_backup': + $information = $this->stop_fresh_backup_tc_callback_wptc(); + break; + case 'wptc_cron_status': + $information = $this->wptc_cron_status(); + break; + case 'get_this_backups_html': + $information = $this->get_this_backups_html(); + break; + case 'start_restore_tc_wptc': + $information = $this->start_restore_tc_callback_wptc(); + break; + case 'get_sibling_files': + $information = $this->get_sibling_files_callback_wptc(); + break; + case 'get_logs_rows': + $information = $this->get_logs_rows(); + break; + case 'clear_logs': + $information = $this->clear_wptc_logs(); + break; + case 'send_issue_report': + $information = $this->send_issue_report(); + break; + case 'lazy_load_activity_log': + $information = $this->lazy_load_activity_log_wptc(); + break; + } + } + MainWP_Helper::write( $information ); + } + + + public function require_files() { + if (! class_exists('WPTC_Base_Factory') && defined('WPTC_PLUGIN_DIR') ) { + if ( MainWP_Helper::check_files_exists(WPTC_PLUGIN_DIR . 'Base/Factory.php') ) { + include_once WPTC_PLUGIN_DIR.'Base/Factory.php'; + } + } + if ( ! class_exists('Wptc_Options_Helper') && defined('WPTC_PLUGIN_DIR') ) { + if ( MainWP_Helper::check_files_exists(WPTC_PLUGIN_DIR . 'Views/wptc-options-helper.php') ) { + include_once WPTC_PLUGIN_DIR . 'Views/wptc-options-helper.php'; + } + } + } + + function set_showhide() { + $hide = isset( $_POST['showhide'] ) && ( 'hide' === $_POST['showhide'] ) ? 'hide' : ''; + MainWP_Helper::update_option( 'mainwp_time_capsule_hide_plugin', $hide, 'yes' ); + $information['result'] = 'SUCCESS'; + return $information; + } + + // ok + public function syncOthersData( $information, $data = array() ) { + if ( isset( $data['syncWPTimeCapsule'] ) && $data['syncWPTimeCapsule'] ) { + $information['syncWPTimeCapsule'] = $this->get_sync_data(); + } + return $information; + } + + // ok + public function get_sync_data() { + try { + $this->require_files(); + MainWP_Helper::check_classes_exists(array('Wptc_Options_Helper', 'WPTC_Base_Factory', 'WPTC_Factory')); + + $config = WPTC_Factory::get('config'); + MainWP_Helper::check_methods($config, 'get_option'); + + $main_account_email_var = $config->get_option('main_account_email'); + $last_backup_time = $config->get_option('last_backup_time'); + $wptc_settings = WPTC_Base_Factory::get('Wptc_Settings'); + + $options_helper = new Wptc_Options_Helper(); + + MainWP_Helper::check_methods($options_helper, array( 'get_plan_interval_from_subs_info', 'get_is_user_logged_in')); + MainWP_Helper::check_methods($wptc_settings, array( 'get_connected_cloud_info')); + + $return = array( + 'main_account_email' => $main_account_email_var, + 'signed_in_repos' => $wptc_settings->get_connected_cloud_info(), + 'plan_name' => $options_helper->get_plan_interval_from_subs_info(), + 'plan_interval' => $options_helper->get_plan_interval_from_subs_info(), + 'lastbackup_time' => !empty($last_backup_time) ? $last_backup_time : 0, + 'is_user_logged_in' => $options_helper->get_is_user_logged_in() + ); + return $return; + } catch ( Exception $e) { + // do not exit here + } + return false; + } + + public function get_tables() { + $category = $_POST['category']; + $exclude_class_obj = new Wptc_ExcludeOption($category); + $exclude_class_obj->get_tables(); + die(); + } + + public function exclude_file_list(){ + if (!isset($_POST['data'])) { + wptc_die_with_json_encode( array('status' => 'no data found') ); + } + $category = $_POST['category']; + $exclude_class_obj = new Wptc_ExcludeOption($category); + $exclude_class_obj->exclude_file_list($_POST['data']); + die(); + } + + function progress_wptc() { + + $config = WPTC_Factory::get('config'); + global $wpdb; + if (!$config->get_option('in_progress')) { + spawn_cron(); + } + + $processed_files = WPTC_Factory::get('processed-files'); + + $return_array = array(); + $return_array['stored_backups'] = $processed_files->get_stored_backups(); + $return_array['backup_progress'] = array(); + $return_array['starting_first_backup'] = $config->get_option('starting_first_backup'); + $return_array['meta_data_backup_process'] = $config->get_option('meta_data_backup_process'); + $return_array['backup_before_update_progress'] = $config->get_option('backup_before_update_progress'); + $return_array['is_staging_running'] = apply_filters('is_any_staging_process_going_on', ''); + $cron_status = $config->get_option('wptc_own_cron_status'); + + if (!empty($cron_status)) { + $return_array['wptc_own_cron_status'] = unserialize($cron_status); + $return_array['wptc_own_cron_status_notified'] = (int) $config->get_option('wptc_own_cron_status_notified'); + } + + $start_backups_failed_server = $config->get_option('start_backups_failed_server'); + if (!empty($start_backups_failed_server)) { + $return_array['start_backups_failed_server'] = unserialize($start_backups_failed_server); + $config->set_option('start_backups_failed_server', false); + } + + $processed_files->get_current_backup_progress($return_array); + + $return_array['user_came_from_existing_ver'] = (int) $config->get_option('user_came_from_existing_ver'); + $return_array['show_user_php_error'] = $config->get_option('show_user_php_error'); + $return_array['bbu_setting_status'] = apply_filters('get_backup_before_update_setting_wptc', ''); + $return_array['bbu_note_view'] = apply_filters('get_bbu_note_view', ''); + $return_array['staging_status'] = apply_filters('staging_status_wptc', ''); + + $processed_files = WPTC_Factory::get('processed-files'); + $last_backup_time = $config->get_option('last_backup_time'); + + if (!empty($last_backup_time)) { + $user_time = $config->cnvt_UTC_to_usrTime($last_backup_time); + $processed_files->modify_schedule_backup_time($user_time); + $formatted_date = date("M d @ g:i a", $user_time); + $return_array['last_backup_time'] = $formatted_date; + } else { + $return_array['last_backup_time'] = 'No Backup Taken'; + } + + return array( 'result' => $return_array ); + + } + + function wptc_cron_status(){ + $config = WPTC_Factory::get('config'); + wptc_own_cron_status(); + $status = array(); + $cron_status = $config->get_option('wptc_own_cron_status'); + if (!empty($cron_status)) { + $cron_status = unserialize($cron_status); + + if ($cron_status['status'] == 'success') { + $status['status'] = 'success'; + } else { + $status['status'] = 'failed'; + $status['status_code'] = $cron_status['statusCode']; + $status['err_msg'] = $cron_status['body']; + $status['cron_url'] = $cron_status['cron_url']; + $status['ips'] = $cron_status['ips']; + } + return array('result' => $status); + } + return false; + } + + function get_this_backups_html() { + $this_backup_ids = $_POST['this_backup_ids']; + $specific_dir = $_POST['specific_dir']; + $type = $_POST['type']; + $treeRecursiveCount = $_POST['treeRecursiveCount']; + $processed_files = WPTC_Factory::get('processed-files'); + + $result = $processed_files->get_this_backups_html($this_backup_ids, $specific_dir, $type, $treeRecursiveCount); + return array( 'result' => $result ); + } + + +function start_restore_tc_callback_wptc() { + + if (apply_filters('is_restore_to_staging_wptc', '')) { + $request = apply_filters('get_restore_to_staging_request_wptc', ''); + } else { + $request = $_POST['data']; + } + + include_once ( WPTC_CLASSES_DIR . 'class-prepare-restore-bridge.php' ); + + new WPTC_Prepare_Restore_Bridge($request); +} + +function get_sibling_files_callback_wptc() { + //note that we are getting the ajax function data via $_POST. + $file_name = $_POST['data']['file_name']; + $file_name = wp_normalize_path($file_name); + $backup_id = $_POST['data']['backup_id']; + $recursive_count = $_POST['data']['recursive_count']; + // //getting the backups + + $processed_files = WPTC_Factory::get('processed-files'); + echo $processed_files->get_this_backups_html($backup_id, $file_name, $type = 'sibling', (int) $recursive_count); + die(); +} + + function send_issue_report() { + WPTC_Base_Factory::get('Wptc_App_Functions')->send_report(); + die(); + } + + + function get_logs_rows() { + $result = $this->prepare_items(); + $result['display_rows'] = base64_encode(serialize($this->get_display_rows($result['items']))); + return $result; + } + + function prepare_items() { + global $wpdb; + + if (isset($_POST['type'])) { + $type = $_POST['type']; + switch ($type) { + case 'backups': + $query = "SELECT * FROM " . $wpdb->base_prefix . "wptc_activity_log WHERE type LIKE '%backup%' AND show_user = 1 GROUP BY action_id"; + break; + case 'restores': + $query = "SELECT * FROM " . $wpdb->base_prefix . "wptc_activity_log WHERE type LIKE 'restore%' GROUP BY action_id"; + break; + case 'staging': + $query = "SELECT * FROM " . $wpdb->base_prefix . "wptc_activity_log WHERE type LIKE 'staging%' GROUP BY action_id"; + break; + case 'backup_and_update': + $query = "SELECT * FROM " . $wpdb->base_prefix . "wptc_activity_log WHERE type LIKE 'backup_and_update%' GROUP BY action_id"; + break; + case 'auto_update': + $query = "SELECT * FROM " . $wpdb->base_prefix . "wptc_activity_log WHERE type LIKE 'auto_update%' GROUP BY action_id"; + break; + case 'others': + $query = "SELECT * FROM " . $wpdb->base_prefix . "wptc_activity_log WHERE type NOT LIKE 'restore%' AND type NOT LIKE 'backup%' AND show_user = 1"; + break; + default: + $query = "SELECT * FROM " . $wpdb->base_prefix . "wptc_activity_log GROUP BY action_id UNION SELECT * FROM " . $wpdb->base_prefix . "wptc_activity_log WHERE action_id='' AND show_user = 1"; + break; + } + } else { + $query = "SELECT * FROM " . $wpdb->base_prefix . "wptc_activity_log WHERE show_user = 1 GROUP BY action_id "; + } + /* -- Preparing your query -- */ + + /* -- Ordering parameters -- */ + //Parameters that are going to be used to order the result + $orderby = !empty($_POST["orderby"]) ? mysql_real_escape_string($_POST["orderby"]) : 'id'; + $order = !empty($_POST["order"]) ? mysql_real_escape_string($_POST["order"]) : 'DESC'; + if (!empty($orderby) & !empty($order)) {$query .= ' ORDER BY ' . $orderby . ' ' . $order;} + + /* -- Pagination parameters -- */ + //Number of elements in your table? + $totalitems = $wpdb->query($query); //return the total number of affected rows + //How many to display per page? + $perpage = 20; + //Which page is this? + $paged = !empty($_POST["paged"]) ? $_POST["paged"] : ''; + if (empty($paged) || !is_numeric($paged) || $paged <= 0) {$paged = 1;} //Page Number + //How many pages do we have in total? + $totalpages = ceil($totalitems / $perpage); //Total number of pages + //adjust the query to take pagination into account + if (!empty($paged) && !empty($perpage)) { + $offset = ($paged - 1) * $perpage; + $query .= ' LIMIT ' . (int) $offset . ',' . (int) $perpage; + } + + return array( 'items' => $wpdb->get_results($query) , + 'totalitems' => $totalitems, + 'perpage' => $perpage + ); + } + + + function lazy_load_activity_log_wptc(){ + + if (!isset($_POST['data'])) { + return false; + } + + $data = $_POST['data']; + + if (!isset($data['action_id']) || !isset($data['limit'])) { + return false; + } + global $wpdb; + + $action_id = $data['action_id']; + $from_limit = $data['limit']; + $detailed = ''; + $load_more = false; + $current_limit = WPTC_Factory::get('config')->get_option('activity_log_lazy_load_limit'); + $to_limit = $from_limit + $current_limit; + + $sql = "SELECT * FROM " . $wpdb->base_prefix . "wptc_activity_log WHERE action_id=" . $action_id . ' AND show_user = 1 ORDER BY id DESC LIMIT '.$from_limit.' , '.$current_limit; + + $sub_records = $wpdb->get_results($sql); + $row_count = count($sub_records); + + if ($row_count == $current_limit) { + $load_more = true; + } + + $detailed = $this->get_activity_log($sub_records); + + if (isset($load_more) && $load_more) { + $detailed .= 'Load more'; + } + + return array( 'result' => $detailed); + + //die($detailed); + } + + + function get_display_rows($records) { + global $wpdb; + //Get the records registered in the prepare_items method + if (!is_array($records)) + return ''; + + $i=0; + $limit = WPTC_Factory::get('config')->get_option('activity_log_lazy_load_limit'); + //Get the columns registered in the get_columns and get_sortable_columns methods + // $columns = $this->get_columns(); + $timezone = WPTC_Factory::get('config')->get_option('wptc_timezone'); + if (count($records) > 0) { + + foreach ($records as $key => $rec) { + $html = ''; + + $more_logs = false; + $load_more = false; + if ($rec->action_id != '') { + $sql = "SELECT * FROM " . $wpdb->base_prefix . "wptc_activity_log WHERE action_id=" . $rec->action_id . ' AND show_user = 1 ORDER BY id DESC LIMIT 0 , '.$limit; + $sub_records = $wpdb->get_results($sql); + $row_count = count($sub_records); + if ($row_count == $limit) { + $load_more = true; + } + + if ($row_count > 0) { + $more_logs = true; + $detailed = ''; + $detailed .= $this->get_activity_log($sub_records); + if (isset($load_more) && $load_more) { + $detailed .= ''; + } + $detailed .= '
Load more
'; + + } + } + //Open the line + $html .= ''; + $Ldata = unserialize($rec->log_data); + $user_time = WPTC_Factory::get('config')->cnvt_UTC_to_usrTime($Ldata['log_time']); + WPTC_Factory::get('processed-files')->modify_schedule_backup_time($user_time); + // $user_tz = new DateTime('@' . $Ldata['log_time'], new DateTimeZone(date_default_timezone_get())); + // $user_tz->setTimeZone(new DateTimeZone($timezone)); + // $user_tz_now = $user_tz->format("M d, Y @ g:i:s a"); + $user_tz_now = date("M d, Y @ g:i:s a", $user_time); + $msg = ''; + if (!(strpos($rec->type, 'backup') === false)) { + //Backup process + $msg = 'Backup Process'; + } else if (!(strpos($rec->type, 'restore') === false)) { + //Restore Process + $msg = 'Restore Process'; + } else if (!(strpos($rec->type, 'staging') === false)) { + //Restore Process + $msg = 'Staging Process'; + } else { + if ($row_count < 2) { + $more_logs = false; + } + $msg = $Ldata['msg']; + } + $html .= '' . $user_tz_now . '' . $msg; + if ($more_logs) { + $html .= "    View details"; + } else { + $html .= ""; + } + $html .= 'Send report to plugin developer'; + if ($more_logs) { + + $html .= "" . $detailed . ""; + } else { + $html .= ""; + } + //Close the line + $html .= ''; + + $display_rows[$key] = $html; + } + + } + return $display_rows; + } + + + function get_activity_log($sub_records){ + if (count($sub_records) < 1) { + return false; + } + $detailed = ''; + $timezone = WPTC_Factory::get('config')->get_option('wptc_timezone'); + foreach ($sub_records as $srec) { + $Moredata = unserialize($srec->log_data); + $user_tmz = new DateTime('@' . $Moredata['log_time'], new DateTimeZone(date_default_timezone_get())); + $user_tmz->setTimeZone(new DateTimeZone($timezone)); + $user_tmz_now = $user_tmz->format("M d @ g:i:s a"); + $detailed .= '' . $user_tmz_now . '' . $Moredata['msg'] . ''; + } + return $detailed; + } + + function clear_wptc_logs() { + global $wpdb; + if ($wpdb->query("TRUNCATE TABLE `" . $wpdb->base_prefix . "wptc_activity_log`")) { + $result = 'yes'; + } else { + $result = 'no'; + } + return array('result' => $result); + } + + function stop_fresh_backup_tc_callback_wptc() { + //for backup during update + $deactivated_plugin = null; + $backup = new WPTC_BackupController(); + $backup->stop($deactivated_plugin); + return array('result' => 'ok'); + } + + + function get_root_files() { + $category = $_POST['category']; + $exclude_class_obj = new Wptc_ExcludeOption($category); + $exclude_class_obj->get_root_files(); + die(); + } + + + public function exclude_table_list(){ + if (!isset($_POST['data'])) { + wptc_die_with_json_encode( array('status' => 'no data found') ); + } + $category = $_POST['data']['category']; + $exclude_class_obj = new Wptc_ExcludeOption($category); + $exclude_class_obj->exclude_table_list($_POST['data']); + die(); + } + + function do_report_backups_logging($backup_id) { + $backup_time = time(); // may be difference a bit with WTC logging + $message = 'WP Time Capsule backup finished'; + $backup_type = 'WP Time Capsule'; + do_action( 'mainwp_wptimecapsule_backup', $message, $backup_type, $backup_time ); + } + + function do_site_stats() { + if (has_action('mainwp_child_reports_log')) { + do_action( 'mainwp_child_reports_log', 'wptimecapsule'); + } else { + $this->do_reports_log('wptimecapsule'); + } + } + + // ok + public function do_reports_log($ext = '') { + if ( $ext !== 'wptimecapsule' ) return; + if (!$this->is_plugin_installed) + return; + try { + MainWP_Helper::check_classes_exists(array( 'WPTC_Base_Factory', 'Wptc_Exclude_Config')); + + $config = WPTC_Base_Factory::get('Wptc_Exclude_Config'); + + MainWP_Helper::check_methods($config, 'get_option'); + + $backup_time = $config->get_option('last_backup_time'); + if (!empty($backup_time)) { + MainWP_Helper::update_lasttime_backup( 'wptimecapsule', $backup_time ); // to support backup before update feature + } + } catch(Exception $e) { + + } + } + + public function include_table_list(){ + if (!isset($_POST['data'])) { + wptc_die_with_json_encode( array('status' => 'no data found') ); + } + $category = $_POST['data']['category']; + $exclude_class_obj = new Wptc_ExcludeOption($category); + $exclude_class_obj->include_table_list($_POST['data']); + die(); + } + + public function include_table_structure_only(){ + + if (!isset($_POST['data'])) { + wptc_die_with_json_encode( array('status' => 'no data found') ); + } + + $category = $_POST['data']['category']; + $exclude_class_obj = new Wptc_ExcludeOption($category); + $exclude_class_obj->include_table_structure_only($_POST['data']); + die(); + } + + public function include_file_list(){ + + if (!isset($_POST['data'])) { + wptc_die_with_json_encode( array('status' => 'no data found') ); + } + $category = $_POST['category']; + $exclude_class_obj = new Wptc_ExcludeOption($category); + $exclude_class_obj->include_file_list($_POST['data']); + die(); + } + + public function get_files_by_key() { + $key = $_POST['key']; + $category = $_POST['category']; + $exclude_class_obj = new Wptc_ExcludeOption($category); + $exclude_class_obj->get_files_by_key($key); + die(); + } + + private function process_wptc_login() { + $options_helper = new Wptc_Options_Helper(); + + if($options_helper->get_is_user_logged_in()){ + return array( + 'result' => 'is_user_logged_in', + 'sync_data' => $this->get_sync_data() + ); + } + + $email = $_POST['acc_email']; + $pwd = $_POST['acc_pwd']; + + if (empty( $email ) || empty($pwd)) { + return array('error' => 'Username and password cannot be empty'); + } + + + $config = WPTC_Base_Factory::get('Wptc_InitialSetup_Config'); + $options = WPTC_Factory::get('config'); + + $config->set_option('wptc_main_acc_email_temp', base64_encode($email)); + $config->set_option('wptc_main_acc_pwd_temp', base64_encode(md5(trim( wp_unslash( $pwd ) )))); + $config->set_option('wptc_token', false); + + $options->request_service( + array( + 'email' => $email, + 'pwd' => trim( wp_unslash( $pwd )), + 'return_response' => false, + 'sub_action' => false, + 'login_request' => true, + 'reset_login_if_failed' => true, + ) + ); + + + $is_user_logged_in = $options->get_option('is_user_logged_in'); + + if (!$is_user_logged_in) { + return array('error' => 'Login failed.'); + } + return array('result' => 'ok', 'sync_data' => $this->get_sync_data()); + } + + function get_installed_plugins(){ + + $backup_before_auto_update_settings = WPTC_Pro_Factory::get('Wptc_Backup_Before_Auto_Update_Settings'); + $plugins = $backup_before_auto_update_settings->get_installed_plugins(); + + if ($plugins) { + return array('results' =>$plugins ); + } + return array( 'results' => array()); + } + + function get_installed_themes(){ + + $backup_before_auto_update_settings = WPTC_Pro_Factory::get('Wptc_Backup_Before_Auto_Update_Settings'); + + $plugins = $backup_before_auto_update_settings->get_installed_themes(); + if ($plugins) { + return array('results' =>$plugins ); + } + return array('results' => array() ) ; + } + + function is_staging_need_request(){ + $staging = WPTC_Pro_Factory::get('Wptc_Staging'); + $staging->is_staging_need_request(); + die(); + } + + function get_staging_details_wptc(){ + $staging = WPTC_Pro_Factory::get('Wptc_Staging'); + $details = $staging->get_staging_details(); + $details['is_running'] = $staging->is_any_staging_process_going_on(); + wptc_die_with_json_encode( $details, 1 ); + } + + function start_fresh_staging_wptc(){ + $staging = WPTC_Pro_Factory::get('Wptc_Staging'); + + if (empty($_POST['path'])) { + wptc_die_with_json_encode( array('status' => 'error', 'msg' => 'path is missing') ); + } + + $staging->choose_action($_POST['path'], $reqeust_type = 'fresh'); + die(); + } + + function get_staging_url_wptc(){ + $staging = WPTC_Pro_Factory::get('Wptc_Staging'); + $staging->get_staging_url_wptc(); + die(); + } + + function stop_staging_wptc(){ + $staging = WPTC_Pro_Factory::get('Wptc_Staging'); + $staging->stop_staging_wptc(); + die(); + } + + function continue_staging_wptc(){ + $staging = WPTC_Pro_Factory::get('Wptc_Staging'); + $staging->choose_action(); + die(); + } + + function delete_staging_wptc(){ + $staging = WPTC_Pro_Factory::get('Wptc_Staging'); + $staging->delete_staging_wptc(); + die(); + } + + function copy_staging_wptc(){ + $staging = WPTC_Pro_Factory::get('Wptc_Staging'); + $staging->choose_action(false, $reqeust_type = 'copy'); + die(); + } + + function get_staging_current_status_key(){ + $staging = WPTC_Pro_Factory::get('Wptc_Staging'); + $staging->get_staging_current_status_key(); + die(); + } + + function wptc_sync_purchase(){ + $config = WPTC_Factory::get('config'); + + $config->request_service( + array( + 'email' => false, + 'pwd' => false, + 'return_response' => false, + 'sub_action' => 'sync_all_settings_to_node', + 'login_request' => true, + ) + ); + die(); + } + + public function init_restore() { + + if (empty($_POST)) { + return ( array('error' => 'Backup id is empty !') ); + } + $restore_to_staging = WPTC_Base_Factory::get('Wptc_Restore_To_Staging'); + $restore_to_staging->init_restore($_POST); + + die(); + } + + function save_settings_wptc(){ + + $options_helper = new Wptc_Options_Helper(); + + if( !$options_helper->get_is_user_logged_in() ){ + return array( + 'sync_data' => $this->get_sync_data(), + 'error' => 'Login to your WP Time Capsule account first' + ); + } + + $data = unserialize(base64_decode($_POST['data'])); + + $tabName = $_POST['tabname']; + $is_general = $_POST['is_general']; + + + $saved = false; + + $config = WPTC_Factory::get('config'); + + if ( $tabName == 'backup' ) { // save_backup_settings_wptc() + + $config->set_option('user_excluded_extenstions', $data['user_excluded_extenstions']); + $config->set_option('user_excluded_files_more_than_size', $data['user_excluded_files_more_than_size']); + + if (!empty($data['backup_slot'])) { + $config->set_option('old_backup_slot', $config->get_option('backup_slot')); + $config->set_option('backup_slot', $data['backup_slot']); + } + + $config->set_option('backup_db_query_limit', $data['backup_db_query_limit']); + $config->set_option('database_encrypt_settings', $data['database_encrypt_settings']); + $config->set_option('wptc_timezone', $data['wptc_timezone']); + $config->set_option('schedule_time_str', $data['schedule_time_str']); + + if(!empty($data['schedule_time_str']) && !empty($data['wptc_timezone']) ){ + if (function_exists('wptc_modify_schedule_backup')) + wptc_modify_schedule_backup(); + } + + $notice = apply_filters('check_requirements_auto_backup_wptc', ''); + + if (!empty($data['revision_limit']) && !$notice ) { + $notice = apply_filters('save_settings_revision_limit_wptc', $data['revision_limit']); + } + + $saved = true; + + } else if ( $tabName == 'backup_auto' ) { // update_auto_update_settings() + + $config->set_option('backup_before_update_setting', $data['backup_before_update_setting']); + + $current = $config->get_option('wptc_auto_update_settings'); + $current = unserialize($current); + $new = unserialize($data['wptc_auto_update_settings']); + + $current['update_settings']['status'] = $new['update_settings']['status']; + $current['update_settings']['schedule']['enabled'] = $new['update_settings']['schedule']['enabled']; + $current['update_settings']['schedule']['time'] = $new['update_settings']['schedule']['time']; + $current['update_settings']['core']['major']['status'] = $new['update_settings']['core']['major']['status']; + $current['update_settings']['core']['minor']['status'] = $new['update_settings']['core']['minor']['status']; + $current['update_settings']['themes']['status'] = $new['update_settings']['themes']['status']; + $current['update_settings']['plugins']['status'] = $new['update_settings']['plugins']['status']; + + if (!$is_general) { + if (isset($new['update_settings']['plugins']['included'])) + $current['update_settings']['plugins']['included'] = $new['update_settings']['plugins']['included']; + else + $current['update_settings']['plugins']['included'] = array(); + + if (isset($new['update_settings']['themes']['included'])) + $current['update_settings']['themes']['included'] = $new['update_settings']['themes']['included']; + else + $current['update_settings']['themes']['included'] = array(); + } + $config->set_option('wptc_auto_update_settings', serialize($current)); + $saved = true; + + } else if ( $tabName == 'vulns_update' ) { + $current = $config->get_option('vulns_settings'); + $current = unserialize($current); + $new = unserialize($data['vulns_settings']); + + $current['status'] = $new['status']; + $current['core']['status'] = $new['core']['status']; + $current['themes']['status'] = $new['themes']['status']; + $current['plugins']['status'] = $new['plugins']['status']; + + if (!$is_general) { + $vulns_plugins_included = !empty($new['plugins']['vulns_plugins_included']) ? $new['plugins']['vulns_plugins_included'] : array(); + + $plugin_include_array = array(); + + if (!empty($vulns_plugins_included)) { + $plugin_include_array = explode(',', $vulns_plugins_included); + $plugin_include_array = !empty($plugin_include_array) ? $plugin_include_array : array() ; + } + + wptc_log($plugin_include_array, '--------$plugin_include_array--------'); + + + + $included_plugins = $this->filter_plugins($plugin_include_array); + + + + wptc_log($included_plugins, '--------$included_plugins--------'); + + $current['plugins']['excluded'] = serialize($included_plugins); + + + $vulns_themes_included = !empty($new['themes']['vulns_themes_included']) ? $new['themes']['vulns_themes_included'] : array(); + + $themes_include_array = array(); + + if (!empty($vulns_themes_included)) { + $themes_include_array = explode(',', $vulns_themes_included); + } + + $included_themes = $this->filter_themes($themes_include_array); + $current['themes']['excluded'] = serialize($included_themes); + } + $config->set_option('vulns_settings', serialize($current)); + + $saved = true; + + } else if ( $tabName == 'staging_opts' ) { + $config->set_option('internal_staging_db_rows_copy_limit', $data['internal_staging_db_rows_copy_limit']); + $config->set_option('internal_staging_file_copy_limit', $data['internal_staging_file_copy_limit']); + $config->set_option('internal_staging_deep_link_limit', $data['internal_staging_deep_link_limit']); + $config->set_option('internal_staging_enable_admin_login', $data['internal_staging_enable_admin_login']); + + $saved = true; + } + + if ( ! $saved ) { + return array('error' => 'Error: Not saved settings'); + } + + return array('result' => 'ok'); + } + + private function filter_plugins($included_plugins){ + $app_functions = WPTC_Base_Factory::get('Wptc_App_Functions'); + $plugins_data = $app_functions->get_all_plugins_data($specific = true, $attr = 'slug'); + $not_included_plugin = array_diff($plugins_data, $included_plugins); + wptc_log($plugins_data, '--------$plugins_data--------'); + wptc_log($not_included_plugin, '--------$not_included_plugin--------'); + return $not_included_plugin; + } + + + private function filter_themes($included_themes){ + $app_functions = WPTC_Base_Factory::get('Wptc_App_Functions'); + $themes_data = $app_functions->get_all_themes_data($specific = true, $attr = 'slug'); + $not_included_theme = array_diff($themes_data, $included_themes); + wptc_log($themes_data, '--------$themes_data--------'); + wptc_log($not_included_theme, '--------$not_included_theme--------'); + return $not_included_theme; + } + + + public function analyze_inc_exc(){ + $exclude_opts_obj = WPTC_Base_Factory::get('Wptc_ExcludeOption'); + $exclude_opts_obj = $exclude_opts_obj->analyze_inc_exc(); // raw response + die(); + } + + public function get_enabled_plugins(){ + $vulns_obj = WPTC_Base_Factory::get('Wptc_Vulns'); + + $plugins = $vulns_obj->get_enabled_plugins(); + $plugins = WPTC_Base_Factory::get('Wptc_App_Functions')->fancytree_format($plugins, 'plugins'); + + return array('results' => $plugins); + } + + public function get_enabled_themes(){ + $vulns_obj = WPTC_Base_Factory::get('Wptc_Vulns'); + $themes = $vulns_obj->get_enabled_themes(); + $themes = WPTC_Base_Factory::get('Wptc_App_Functions')->fancytree_format($themes, 'themes'); + return array('results' => $themes); + } + + public function get_system_info(){ + global $wpdb; + + $wptc_settings = WPTC_Base_Factory::get('Wptc_Settings'); + + ob_start(); + + echo ''; + echo ''; + echo ''; + echo ''; + + $bit = ''; + if ( PHP_INT_SIZE === 4 ) { + $bit = ' (32bit)'; + } + if ( PHP_INT_SIZE === 8 ) { + $bit = ' (64bit)'; + } + + echo ''; + echo ''; + + if ( function_exists( 'curl_version' ) ) { + $curlversion = curl_version(); + echo ''; + echo ''; + } + else { + echo ''; + } + + echo ''; + echo ''; + echo ''; + echo ''; + + $php_user = __( 'Function Disabled', 'wp-time-capsule' ); + if ( function_exists( 'get_current_user' ) ) { + $php_user = get_current_user(); + } + + echo ''; + echo ''; + + if ( defined( 'FS_CHMOD_DIR' ) ) + echo ''; + else + echo ''; + + $now = localtime( time(), TRUE ); + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + + //disabled PHP functions + $disabled = esc_html( ini_get( 'disable_functions' ) ); + if ( ! empty( $disabled ) ) { + $disabledarry = explode( ',', $disabled ); + echo ''; + } + + //Loaded PHP Extensions + echo ''; + echo '
' . __( 'Setting', 'wp-time-capsule' ) . '' . __( 'Value', 'wp-time-capsule' ) . '
' . __( 'WordPress version', 'wp-time-capsule' ) . '' . esc_html( $wptc_settings->get_plugin_data( 'wp_version' ) ) . '
' . __( 'WP Time Capsule version', 'wp-time-capsule' ) . '' . esc_html( $wptc_settings->get_plugin_data( 'Version' ) ) . '
' . __( 'PHP version', 'wp-time-capsule' ) . '' . esc_html( PHP_VERSION . ' ' . $bit ) . '
' . __( 'MySQL version', 'wp-time-capsule' ) . '' . esc_html( $wpdb->get_var( "SELECT VERSION() AS version" ) ) . '
' . __( 'cURL version', 'wp-time-capsule' ) . '' . esc_html( $curlversion[ 'version' ] ) . '
' . __( 'cURL SSL version', 'wp-time-capsule' ) . '' . esc_html( $curlversion[ 'ssl_version' ] ) . '
' . __( 'cURL version', 'wp-time-capsule' ) . '' . __( 'unavailable', 'wp-time-capsule' ) . '
' . __( 'Server', 'wp-time-capsule' ) . '' . esc_html( $_SERVER[ 'SERVER_SOFTWARE' ] ) . '
' . __( 'Operating System', 'wp-time-capsule' ) . '' . esc_html( PHP_OS ) . '
' . __( 'PHP SAPI', 'wp-time-capsule' ) . '' . esc_html( PHP_SAPI ) . '
' . __( 'Current PHP user', 'wp-time-capsule' ) . '' . esc_html( $php_user ) . '
' . __( 'Maximum execution time', 'wp-time-capsule' ) . '' . esc_html( ini_get( 'max_execution_time' ) ) . ' ' . __( 'seconds', 'wp-time-capsule' ) . '
' . __( 'CHMOD Dir', 'wp-time-capsule' ) . '' . esc_html( FS_CHMOD_DIR ) . '
' . __( 'CHMOD Dir', 'wp-time-capsule' ) . '0755
' . __( 'Server Time', 'wp-time-capsule' ) . '' . esc_html( $now[ 'tm_hour' ] . ':' . $now[ 'tm_min' ] ) . '
' . __( 'Blog Time', 'wp-time-capsule' ) . '' . date( 'H:i', current_time( 'timestamp' ) ) . '
' . __( 'Blog language', 'wp-time-capsule' ) . '' . get_bloginfo( 'language' ) . '
' . __( 'MySQL Client encoding', 'wp-time-capsule' ) . ''; + echo defined( 'DB_CHARSET' ) ? DB_CHARSET : ''; + echo '
' . __( 'Blog charset', 'wp-time-capsule' ) . '' . get_bloginfo( 'charset' ) . '
' . __( 'PHP Memory limit', 'wp-time-capsule' ) . '' . esc_html( ini_get( 'memory_limit' ) ) . '
' . __( 'WP memory limit', 'wp-time-capsule' ) . '' . esc_html( WP_MEMORY_LIMIT ) . '
' . __( 'WP maximum memory limit', 'wp-time-capsule' ) . '' . esc_html( WP_MAX_MEMORY_LIMIT ) . '
' . __( 'Memory in use', 'wp-time-capsule' ) . '' . size_format( @memory_get_usage( TRUE ), 2 ) . '
' . __( 'Disabled PHP Functions:', 'wp-time-capsule' ) . ''; + echo implode( ', ', $disabledarry ); + echo '
' . __( 'Loaded PHP Extensions:', 'wp-time-capsule' ) . ''; + $extensions = get_loaded_extensions(); + sort( $extensions ); + echo esc_html( implode( ', ', $extensions ) ); + echo '
'; + + $html = ob_get_clean(); + return array( 'result' => $html); + } + + + public function update_vulns_settings(){ + + $vulns_obj = WPTC_Base_Factory::get('Wptc_Vulns'); + + $data = isset($_POST['data']) ? $_POST['data'] : array() ; + $vulns_obj->update_vulns_settings($data); + + return array( 'success' => 1 ); + } + + function start_fresh_backup_tc_callback_wptc() { + start_fresh_backup_tc_callback_wptc($type = '', $args = null, $test_connection = true, $ajax_check = false); + return array('result' => 'success'); + } + + public function save_manual_backup_name_wptc() { + $backup_name = $_POST['backup_name']; + $processed_files = WPTC_Factory::get('processed-files'); + $processed_files->save_manual_backup_name_wptc($backup_name); + die(); + } + + function send_response_wptc($status = null, $type = null, $data = null, $is_log =0) { + if (!is_wptc_server_req() && !is_wptc_node_server_req()) { + return false; + } + $config = WPTC_Factory::get('config'); + + if (empty($is_log)) { + $post_arr['status'] = $status; + $post_arr['type'] = $type; + $post_arr['version'] = WPTC_VERSION; + $post_arr['source'] = 'WPTC'; + $post_arr['scheduled_time'] = $config->get_option('schedule_time_str'); + $post_arr['timezone'] = $config->get_option('wptc_timezone'); + $post_arr['last_backup_time'] = $config->get_option('last_backup_time'); + if (!empty($data)) { + $post_arr['progress'] = $data; + } + } else { + $post_arr = $data; + } + + + return array( 'result' => 'success', 'data' => "".json_encode($post_arr)."" ); + } + + + public function all_plugins( $plugins ) { + foreach ( $plugins as $key => $value ) { + $plugin_slug = basename( $key, '.php' ); + if ( 'wp-time-capsule' === $plugin_slug ) { + unset( $plugins[ $key ] ); + } + } + + return $plugins; + } + + public function remove_menu() { + remove_menu_page( 'wp-time-capsule-monitor' ); + $pos = stripos( $_SERVER['REQUEST_URI'], 'admin.php?page=wp-time-capsule-monitor' ); + if ( false !== $pos ) { + wp_redirect( get_option( 'siteurl' ) . '/wp-admin/index.php' ); + exit(); + } + } + + function remove_update_nag( $value ) { + if ( isset( $_POST['mainwpsignature'] ) ) { + return $value; + } + if ( isset( $value->response['wp-time-capsule/wp-time-capsule.php'] ) ) { + unset( $value->response['wp-time-capsule/wp-time-capsule.php'] ); + } + + return $value; + } +} + diff --git a/class/class-mainwp-child-updraft-plus-backups.php b/class/class-mainwp-child-updraft-plus-backups.php index 08056cd..6c671e7 100644 --- a/class/class-mainwp-child-updraft-plus-backups.php +++ b/class/class-mainwp-child-updraft-plus-backups.php @@ -2,8 +2,8 @@ class MainWP_Child_Updraft_Plus_Backups { public static $instance = null; - - static function Instance() { + public $is_plugin_installed = false; + static function Instance() { if ( null === MainWP_Child_Updraft_Plus_Backups::$instance ) { MainWP_Child_Updraft_Plus_Backups::$instance = new MainWP_Child_Updraft_Plus_Backups(); } @@ -11,7 +11,15 @@ class MainWP_Child_Updraft_Plus_Backups { return MainWP_Child_Updraft_Plus_Backups::$instance; } - public function __construct() { + public function __construct() { + require_once( ABSPATH . 'wp-admin/includes/plugin.php' ); + if ( is_plugin_active( 'updraftplus/updraftplus.php' ) && defined('UPDRAFTPLUS_DIR')) { + $this->is_plugin_installed = true; + } + + if (!$this->is_plugin_installed) + return; + add_filter( 'mainwp-site-sync-others-data', array( $this, 'syncOthersData' ), 10, 2 ); add_filter('updraftplus_save_last_backup', array( __CLASS__, 'hookUpdraftplusSaveLastBackup' )); } @@ -26,108 +34,119 @@ class MainWP_Child_Updraft_Plus_Backups { } return $last_backup; } - + // ok function syncOthersData( $information, $data = array() ) { - if ( isset( $data['syncUpdraftData'] ) && $data['syncUpdraftData'] ) { - if ( self::isActivatedUpdraftplus() ) { - $information['syncUpdraftData'] = $this->syncData(); - } - } - if ( isset( $data['sync_Updraftvault_quota_text'] ) && $data['sync_Updraftvault_quota_text'] ) { - if ( self::isActivatedUpdraftplus() ) { - $information['sync_Updraftvault_quota_text'] = $this->connected_html(); - } - } + try{ + if ( isset( $data['syncUpdraftData'] ) && $data['syncUpdraftData'] ) { + if ( $this->is_plugin_installed ) { + $information['syncUpdraftData'] = $this->get_sync_data(); + } + } + if ( isset( $data['sync_Updraftvault_quota_text'] ) && $data['sync_Updraftvault_quota_text'] ) { + if ( $this->is_plugin_installed ) { + $information['sync_Updraftvault_quota_text'] = $this->connected_html(); + } + } + } catch(Exception $e) { + + } + return $information; } public function action() { $information = array(); - if ( ! self::isActivatedUpdraftplus() ) { + if ( ! $this->is_plugin_installed ) { $information['error'] = 'NO_UPDRAFTPLUS'; MainWP_Helper::write( $information ); } + $this->required_files(); + global $updraftplus; if ( empty( $updraftplus ) && class_exists( 'UpdraftPlus' ) ) { $updraftplus = new UpdraftPlus(); } if ( empty( $updraftplus ) ) { - $information['error'] = 'Error empty object'; + $information['error'] = 'Error empty updraftplus'; MainWP_Helper::write( $information ); } - + if ( isset( $_POST['mwp_action'] ) ) { if ( get_option( 'mainwp_updraftplus_ext_enabled' ) !== 'Y' ) { MainWP_Helper::update_option( 'mainwp_updraftplus_ext_enabled', 'Y', 'yes' ); } - - switch ( $_POST['mwp_action'] ) { - case 'set_showhide': - $information = $this->set_showhide(); - break; - case 'save_settings': - $information = $this->save_settings(); - break; - case 'addons_connect': - $information = $this->addons_connect(); - break; - case 'backup_now': - $information = $this->backup_now(); - break; - case 'activejobs_list': - $information = $this->activejobs_list(); - break; - case 'diskspaceused': - $information = $this->diskspaceused(); - break; - case 'last_backup_html': - $information = $this->last_backup_html(); - break; - case 'reload_data': - $information = $this->get_updraft_data(); - break; - case 'next_scheduled_backups': - $information = $this->next_scheduled_backups(); - break; - case 'forcescheduledresumption': - $information = $this->forceScheduledResumption(); - break; - case 'fetch_updraft_log': - $information = $this->fetch_updraft_log(); - break; - case 'activejobs_delete': - $information = $this->activejobs_delete(); - break; - case 'historystatus': - $information = $this->historystatus(); - break; - case 'deleteset': - $information = $this->deleteset(); - break; - case 'updraft_download_backup': - $information = $this->updraft_download_backup(); - break; - case 'restore_alldownloaded': - $information = $this->restore_alldownloaded(); - break; - case 'restorebackup': - $information = $this->restoreBackup(); - break; - case 'extradbtestconnection': - $information = $this->extradb_testconnection(); - break; - case 'delete_old_dirs': - $information = $this->delete_old_dirs_go(); - break; - case 'vault_connect': - $information = $this->do_vault_connect(); - break; - case 'vault_disconnect': - $information = $this->vault_disconnect(); - break; - } + + try { + switch ( $_POST['mwp_action'] ) { + case 'set_showhide': + $information = $this->set_showhide(); + break; + case 'save_settings': + $information = $this->save_settings(); + break; + case 'addons_connect': + $information = $this->addons_connect(); + break; + case 'backup_now': + $information = $this->backup_now(); + break; + case 'activejobs_list': + $information = $this->activejobs_list(); + break; + case 'diskspaceused': + $information = $this->diskspaceused(); + break; + case 'last_backup_html': + $information = $this->last_backup_html(); + break; + case 'reload_data': + $information = $this->get_updraft_data(); + break; + case 'next_scheduled_backups': + $information = $this->next_scheduled_backups(); + break; + case 'forcescheduledresumption': + $information = $this->forceScheduledResumption(); + break; + case 'fetch_updraft_log': + $information = $this->fetch_updraft_log(); + break; + case 'activejobs_delete': + $information = $this->activejobs_delete(); + break; + case 'historystatus': + $information = $this->historystatus(); + break; + case 'deleteset': + $information = $this->deleteset(); + break; + case 'updraft_download_backup': + $information = $this->updraft_download_backup(); + break; + case 'restore_alldownloaded': + $information = $this->restore_alldownloaded(); + break; + case 'restorebackup': // not used + $information = $this->restoreBackup(); + break; + case 'extradbtestconnection': + $information = $this->extradb_testconnection(); + break; + case 'delete_old_dirs': + $information = $this->delete_old_dirs_go(); + break; + case 'vault_connect': + $information = $this->do_vault_connect(); + break; + case 'vault_disconnect': + $information = $this->vault_disconnect(); + break; + } + } catch(Exception $e) { + $information = array('error' => $e->getMessage()); + } } MainWP_Helper::write( $information ); } @@ -140,23 +159,6 @@ class MainWP_Child_Updraft_Plus_Backups { return $information; } - public static function isActivatedUpdraftplus() { - if ( ! defined( 'UPDRAFTPLUS_DIR' ) ) { - return false; - } - - if ( ! class_exists( 'UpdraftPlus' ) ) { - require_once( UPDRAFTPLUS_DIR . '/class-updraftplus.php' ); - } - - if ( ! class_exists( 'UpdraftPlus_Options' ) ) { - require_once( UPDRAFTPLUS_DIR . '/options.php' ); - } - - return true; - } - - private function get_settings_keys() { return array( 'updraft_autobackup_default', @@ -245,6 +247,9 @@ class MainWP_Child_Updraft_Plus_Backups { private function connected_html() { + MainWP_Helper::check_classes_exists('UpdraftPlus_Options'); + MainWP_Helper::check_methods('UpdraftPlus_Options', 'get_updraft_option'); + $vault_settings = UpdraftPlus_Options::get_updraft_option( 'updraft_updraftvault' ); if ( !is_array( $vault_settings ) || empty( $vault_settings['token'] ) || empty( $vault_settings['email'] ) ) { return ''; @@ -372,6 +377,18 @@ class MainWP_Child_Updraft_Plus_Backups { } } + function required_files() { + if (defined('UPDRAFTPLUS_DIR')) { + if ( ! class_exists( 'UpdraftPlus' ) && file_exists( UPDRAFTPLUS_DIR . '/class-updraftplus.php') ) { + require_once( UPDRAFTPLUS_DIR . '/class-updraftplus.php' ); + } + + if ( ! class_exists( 'UpdraftPlus_Options' ) && file_exists( UPDRAFTPLUS_DIR . '/options.php' ) ) { + require_once( UPDRAFTPLUS_DIR . '/options.php' ); + } + } + } + function save_settings() { $settings = maybe_unserialize( base64_decode( $_POST['settings'] ) ); @@ -385,6 +402,8 @@ class MainWP_Child_Updraft_Plus_Backups { $settings_key = null; if ( 'updraft_dropbox' === $key && is_array($settings[ $key ])) { $opts = UpdraftPlus_Options::get_updraft_option( 'updraft_dropbox' ); + if (!is_array($opts)) + $opts = array(); if(is_array($opts) && isset($opts['settings'])) { $settings_key = key($opts['settings']); if (isset($settings['is_general']) && !empty($settings['is_general'])){ @@ -406,6 +425,8 @@ class MainWP_Child_Updraft_Plus_Backups { UpdraftPlus_Options::update_updraft_option( $key, $opts ); } else if ( 'updraft_googledrive' === $key ) { $opts = UpdraftPlus_Options::get_updraft_option( 'updraft_googledrive' ); + if (!is_array($opts)) + $opts = array(); if(is_array($opts) && isset($opts['settings'])) { $settings_key = key($opts['settings']); // $opts['settings'][$settings_key]['clientid'] = $settings[ $key ]['clientid']; @@ -419,6 +440,8 @@ class MainWP_Child_Updraft_Plus_Backups { UpdraftPlus_Options::update_updraft_option( $key, $opts ); } else if ( 'updraft_googlecloud' === $key ) { $opts = UpdraftPlus_Options::get_updraft_option( $key ); + if (!is_array($opts)) + $opts = array(); if(is_array($opts) && isset($opts['settings'])) { $settings_key = key($opts['settings']); // $opts['settings'][$settings_key]['clientid'] = $settings[ $key ]['clientid']; @@ -438,6 +461,8 @@ class MainWP_Child_Updraft_Plus_Backups { UpdraftPlus_Options::update_updraft_option( $key, $opts ); } else if ( 'updraft_onedrive' === $key ) { $opts = UpdraftPlus_Options::get_updraft_option( 'updraft_onedrive' ); + if (!is_array($opts)) + $opts = array(); if(is_array($opts) && isset($opts['settings'])) { $settings_key = key($opts['settings']); // $opts['settings'][$settings_key]['clientid'] = $settings[ $key ]['clientid']; @@ -461,6 +486,8 @@ class MainWP_Child_Updraft_Plus_Backups { UpdraftPlus_Options::update_updraft_option( $key, $value ); } else if ( 'updraft_s3' === $key ) { $opts = UpdraftPlus_Options::get_updraft_option( 'updraft_s3' ); + if (!is_array($opts)) + $opts = array(); if(is_array($opts) && isset($opts['settings'])) { $settings_key = key($opts['settings']); $opts['settings'][$settings_key]['accesskey'] = $settings[ $key ]['accesskey']; @@ -489,6 +516,8 @@ class MainWP_Child_Updraft_Plus_Backups { UpdraftPlus_Options::update_updraft_option( $key, $opts ); } else if ( 'updraft_s3generic' === $key ) { $opts = UpdraftPlus_Options::get_updraft_option( 'updraft_s3generic' ); + if (!is_array($opts)) + $opts = array(); if(is_array($opts) && isset($opts['settings'])) { $settings_key = key($opts['settings']); $opts['settings'][$settings_key]['endpoint'] = $settings[ $key ]['endpoint']; @@ -505,6 +534,8 @@ class MainWP_Child_Updraft_Plus_Backups { UpdraftPlus_Options::update_updraft_option( $key, $opts ); } else if ( 'updraft_dreamobjects' === $key ) { $opts = UpdraftPlus_Options::get_updraft_option( 'updraft_dreamobjects' ); + if (!is_array($opts)) + $opts = array(); if(is_array($opts) && isset($opts['settings'])) { $settings_key = key($opts['settings']); $opts['settings'][$settings_key]['path'] = $this->replace_tokens($settings[ $key ]['path']); @@ -514,6 +545,8 @@ class MainWP_Child_Updraft_Plus_Backups { UpdraftPlus_Options::update_updraft_option( $key, $opts ); } else if ( 'updraft_ftp' === $key ) { $opts = UpdraftPlus_Options::get_updraft_option( 'updraft_ftp' ); + if (!is_array($opts)) + $opts = array(); if(is_array($opts) && isset($opts['settings'])) { $settings_key = key($opts['settings']); if ( isset( $settings[ $key ]['path'] ) ) { @@ -536,6 +569,8 @@ class MainWP_Child_Updraft_Plus_Backups { UpdraftPlus_Options::update_updraft_option( $key, $opts ); } else if ( 'updraft_sftp_settings' === $key ) { $opts = UpdraftPlus_Options::get_updraft_option( 'updraft_sftp' ); + if (!is_array($opts)) + $opts = array(); if(is_array($opts) && isset($opts['settings'])) { $settings_key = key($opts['settings']); if ( isset( $settings[ $key ]['path'] ) ) { @@ -560,7 +595,9 @@ class MainWP_Child_Updraft_Plus_Backups { } UpdraftPlus_Options::update_updraft_option( 'updraft_sftp', $opts ); } else if ( 'updraft_backblaze' === $key ) { - $opts = UpdraftPlus_Options::get_updraft_option( 'updraft_backblaze' ); + $opts = UpdraftPlus_Options::get_updraft_option( 'updraft_backblaze' ); + if (!is_array($opts)) + $opts = array(); if (is_array($opts) && isset($opts['settings'])) { $settings_key = key($opts['settings']); $opts['settings'][$settings_key]['account_id'] = $settings[ $key ]['account_id']; @@ -987,7 +1024,7 @@ class MainWP_Child_Updraft_Plus_Backups { if ( empty( $updraftplus ) ) { return false; } - + // UNIX timestamp $next_scheduled_backup = wp_next_scheduled( 'updraft_backup' ); $next_scheduled_backup_gmt = $next_scheduled_backup_database_gmt = 0; @@ -1000,6 +1037,11 @@ class MainWP_Child_Updraft_Plus_Backups { $next_scheduled_backup = 'Nothing currently scheduled'; } + + MainWP_Helper::check_classes_exists('UpdraftPlus_Options'); + MainWP_Helper::check_methods('UpdraftPlus_Options', 'get_updraft_option'); + MainWP_Helper::check_methods($updraftplus, array( 'backups_dir_location', 'really_is_writable' )); + $next_scheduled_backup_database = wp_next_scheduled( 'updraft_backup_database' ); if ( UpdraftPlus_Options::get_updraft_option( 'updraft_interval_database', UpdraftPlus_Options::get_updraft_option( 'updraft_interval' ) ) === UpdraftPlus_Options::get_updraft_option( 'updraft_interval' ) ) { $next_scheduled_backup_database = ( 'Nothing currently scheduled' === $next_scheduled_backup ) ? $next_scheduled_backup : __( 'At the same time as the files backup', 'updraftplus' ); @@ -1259,8 +1301,12 @@ class MainWP_Child_Updraft_Plus_Backups { } public function build_historystatus() { - $backup_history = UpdraftPlus_Options::get_updraft_option( 'updraft_backup_history' ); - $backup_history = ( is_array( $backup_history ) ) ? $backup_history : array(); + + MainWP_Helper::check_classes_exists('UpdraftPlus_Backup_History'); + MainWP_Helper::check_methods('UpdraftPlus_Backup_History', 'get_history'); + + $backup_history = UpdraftPlus_Backup_History::get_history(); + $output = $this->existing_backup_table( $backup_history ); if ( ! empty( $messages ) && is_array( $messages ) ) { @@ -1285,8 +1331,7 @@ class MainWP_Child_Updraft_Plus_Backups { $messages = $this->rebuildBackupHistory( $remotescan ); } - $backup_history = UpdraftPlus_Options::get_updraft_option( 'updraft_backup_history' ); - $backup_history = ( is_array( $backup_history ) ) ? $backup_history : array(); + $backup_history = UpdraftPlus_Backup_History::get_history(); $output = $this->existing_backup_table( $backup_history ); if ( ! empty( $messages ) && is_array( $messages ) ) { @@ -1547,7 +1592,11 @@ class MainWP_Child_Updraft_Plus_Backups { if ( isset( $elements['db'] ) ) { // Analyse the header of the database file + display results - list ( $mess2, $warn2, $err2, $info ) = $this->analyse_db_file( $timestamp, $res ); + if ( class_exists( 'UpdraftPlus_Encryption' )) { + list ( $mess2, $warn2, $err2, $info ) = $updraftplus->analyse_db_file( $timestamp, $res ); + } else { + list ( $mess2, $warn2, $err2, $info ) = $this->analyse_db_file_old( $timestamp, $res ); + } $mess = array_merge( $mess, $mess2 ); $warn = array_merge( $warn, $warn2 ); $err = array_merge( $err, $err2 ); @@ -1652,7 +1701,8 @@ class MainWP_Child_Updraft_Plus_Backups { ); } } - + + // not used public function restoreBackup() { global $updraftplus_admin, $updraftplus; @@ -1699,13 +1749,15 @@ class MainWP_Child_Updraft_Plus_Backups { } + // not used // Return values: false = 'not yet' (not necessarily terminal); WP_Error = terminal failure; true = success private function restore_backup( $timestamp ) { @set_time_limit( 900 ); global $wp_filesystem, $updraftplus; - $backup_history = UpdraftPlus_Options::get_updraft_option( 'updraft_backup_history' ); +// $backup_history = UpdraftPlus_Options::get_updraft_option( 'updraft_backup_history' ); + $backup_history = UpdraftPlus_Backup_History::get_history(); if ( ! is_array( $backup_history[ $timestamp ] ) ) { echo wp_kses_post( '

' . esc_html__( 'This backup does not exist in the backup history - restoration aborted. Timestamp:', 'updraftplus' ) . " $timestamp


" ); @@ -2064,8 +2116,7 @@ class MainWP_Child_Updraft_Plus_Backups { return true; } - - + public function option_filter_template( $val ) { global $updraftplus; @@ -2201,7 +2252,7 @@ class MainWP_Child_Updraft_Plus_Backups { echo '
' . "

$message

"; } - private function analyse_db_file( $timestamp, $res, $db_file = false, $header_only = false ) { + private function analyse_db_file_old( $timestamp, $res, $db_file = false, $header_only = false ) { $mess = array(); $warn = array(); @@ -2436,7 +2487,441 @@ class MainWP_Child_Updraft_Plus_Backups { } + + public function analyse_db_file($timestamp, $res, $db_file = false, $header_only = false) { + global $updraftplus; + + $mess = array(); + $warn = array(); + $err = array(); + $info = array(); + $wp_version = $updraftplus->get_wordpress_version(); + global $wpdb; + $updraft_dir = $updraftplus->backups_dir_location(); + + if (false === $db_file) { + // This attempts to raise the maximum packet size. This can't be done within the session, only globally. Therefore, it has to be done before the session starts; in our case, during the pre-analysis. + $updraftplus->get_max_packet_size(); + + $backup = UpdraftPlus_Backup_History::get_history($timestamp); + if (!isset($backup['nonce']) || !isset($backup['db'])) return array($mess, $warn, $err, $info); + + $db_file = (is_string($backup['db'])) ? $updraft_dir.'/'.$backup['db'] : $updraft_dir.'/'.$backup['db'][0]; + } + + if (!is_readable($db_file)) return array($mess, $warn, $err, $info); + + // Encrypted - decrypt it + if (UpdraftPlus_Encryption::is_file_encrypted($db_file)) { + + $encryption = empty($res['updraft_encryptionphrase']) ? UpdraftPlus_Options::get_updraft_option('updraft_encryptionphrase') : $res['updraft_encryptionphrase']; + + if (!$encryption) { + if (class_exists('UpdraftPlus_Addon_MoreDatabase')) { + $err[] = sprintf(__('Error: %s', 'updraftplus'), __('Decryption failed. The database file is encrypted, but you have no encryption key entered.', 'updraftplus')); + } else { + $err[] = sprintf(__('Error: %s', 'updraftplus'), __('Decryption failed. The database file is encrypted.', 'updraftplus')); + } + return array($mess, $warn, $err, $info); + } + + $decrypted_file = UpdraftPlus_Encryption::decrypt($db_file, $encryption); + + if (is_array($decrypted_file)) { + $db_file = $decrypted_file['fullpath']; + } else { + $err[] = __('Decryption failed. The most likely cause is that you used the wrong key.', 'updraftplus'); + return array($mess, $warn, $err, $info); + } + } + + // Even the empty schema when gzipped comes to 1565 bytes; a blank WP 3.6 install at 5158. But we go low, in case someone wants to share single tables. + if (filesize($db_file) < 1000) { + $err[] = sprintf(__('The database is too small to be a valid WordPress database (size: %s Kb).', 'updraftplus'), round(filesize($db_file)/1024, 1)); + return array($mess, $warn, $err, $info); + } + + $is_plain = ('.gz' == substr($db_file, -3, 3)) ? false : true; + + $dbhandle = ($is_plain) ? fopen($db_file, 'r') : $this->gzopen_for_read($db_file, $warn, $err); + if (!is_resource($dbhandle)) { + $err[] = __('Failed to open database file.', 'updraftplus'); + return array($mess, $warn, $err, $info); + } + + $info['timestamp'] = $timestamp; + + // Analyse the file, print the results. + + $line = 0; + $old_siteurl = ''; + $old_home = ''; + $old_table_prefix = ''; + $old_siteinfo = array(); + $gathering_siteinfo = true; + $old_wp_version = ''; + $old_php_version = ''; + + $tables_found = array(); + $db_charsets_found = array(); + + // TODO: If the backup is the right size/checksum, then we could restore the $line <= 100 in the 'while' condition and not bother scanning the whole thing? Or better: sort the core tables to be first so that this usually terminates early + + $wanted_tables = array('terms', 'term_taxonomy', 'term_relationships', 'commentmeta', 'comments', 'links', 'options', 'postmeta', 'posts', 'users', 'usermeta'); + + $migration_warning = false; + $processing_create = false; + $db_version = $wpdb->db_version(); + + // Don't set too high - we want a timely response returned to the browser + // Until April 2015, this was always 90. But we've seen a few people with ~1GB databases (uncompressed), and 90s is not enough. Note that we don't bother checking here if it's compressed - having a too-large timeout when unexpected is harmless, as it won't be hit. On very large dbs, they're expecting it to take a while. + // "120 or 240" is a first attempt at something more useful than just fixed at 90 - but should be sufficient (as 90 was for everyone without ~1GB databases) + $default_dbscan_timeout = (filesize($db_file) < 31457280) ? 120 : 240; + $dbscan_timeout = (defined('UPDRAFTPLUS_DBSCAN_TIMEOUT') && is_numeric(UPDRAFTPLUS_DBSCAN_TIMEOUT)) ? UPDRAFTPLUS_DBSCAN_TIMEOUT : $default_dbscan_timeout; + @set_time_limit($dbscan_timeout); + + // We limit the time that we spend scanning the file for character sets + $db_charset_collate_scan_timeout = (defined('UPDRAFTPLUS_DB_CHARSET_COLLATE_SCAN_TIMEOUT') && is_numeric(UPDRAFTPLUS_DB_CHARSET_COLLATE_SCAN_TIMEOUT)) ? UPDRAFTPLUS_DB_CHARSET_COLLATE_SCAN_TIMEOUT : 10; + $charset_scan_start_time = microtime(true); + $db_supported_character_sets_res = $GLOBALS['wpdb']->get_results('SHOW CHARACTER SET', OBJECT_K); + $db_supported_character_sets = (null !== $db_supported_character_sets_res) ? $db_supported_character_sets_res : array(); + $db_charsets_found = array(); + $db_supported_collations_res = $GLOBALS['wpdb']->get_results('SHOW COLLATION', OBJECT_K); + $db_supported_collations = (null !== $db_supported_collations_res) ? $db_supported_collations_res : array(); + $db_charsets_found = array(); + $db_collates_found = array(); + $db_supported_charset_related_to_unsupported_collation = false; + $db_supported_charsets_related_to_unsupported_collations = array(); + while ((($is_plain && !feof($dbhandle)) || (!$is_plain && !gzeof($dbhandle))) && ($line<100 || (!$header_only && count($wanted_tables)>0) || ((microtime(true) - $charset_scan_start_time) < $db_charset_collate_scan_timeout && !empty($db_supported_character_sets)))) { + $line++; + // Up to 1MB + $buffer = ($is_plain) ? rtrim(fgets($dbhandle, 1048576)) : rtrim(gzgets($dbhandle, 1048576)); + // Comments are what we are interested in + if (substr($buffer, 0, 1) == '#') { + $processing_create = false; + if ('' == $old_siteurl && preg_match('/^\# Backup of: (http(.*))$/', $buffer, $matches)) { + $old_siteurl = untrailingslashit($matches[1]); + $mess[] = __('Backup of:', 'updraftplus').' '.htmlspecialchars($old_siteurl).((!empty($old_wp_version)) ? ' '.sprintf(__('(version: %s)', 'updraftplus'), $old_wp_version) : ''); + // Check for should-be migration + if (untrailingslashit(site_url()) != $old_siteurl) { + if (!$migration_warning) { + $migration_warning = true; + $info['migration'] = true; + // && !class_exists('UpdraftPlus_Addons_Migrator') + if (UpdraftPlus_Manipulation_Functions::normalise_url($old_siteurl) == UpdraftPlus_Manipulation_Functions::normalise_url(site_url())) { + // Same site migration with only http/https difference + $info['same_url'] = false; + $old_siteurl_parsed = parse_url($old_siteurl); + $actual_siteurl_parsed = parse_url(site_url()); + if ((stripos($old_siteurl_parsed['host'], 'www.') === 0 && stripos($actual_siteurl_parsed['host'], 'www.') !== 0) || (stripos($old_siteurl_parsed['host'], 'www.') !== 0 && stripos($actual_siteurl_parsed['host'], 'www.') === 0)) { + $powarn = sprintf(__('The website address in the backup set (%s) is slightly different from that of the site now (%s). This is not expected to be a problem for restoring the site, as long as visits to the former address still reach the site.', 'updraftplus'), $old_siteurl, site_url()).' '; + } else { + $powarn = ''; + } + if (('https' == $old_siteurl_parsed['scheme'] && 'http' == $actual_siteurl_parsed['scheme']) || ('http' == $old_siteurl_parsed['scheme'] && 'https' == $actual_siteurl_parsed['scheme'])) { + $powarn .= sprintf(__('This backup set is of this site, but at the time of the backup you were using %s, whereas the site now uses %s.', 'updraftplus'), $old_siteurl_parsed['scheme'], $actual_siteurl_parsed['scheme']); + if ('https' == $old_siteurl_parsed['scheme']) { + $powarn .= ' '.apply_filters('updraftplus_https_to_http_additional_warning', sprintf(__('This restoration will work if you still have an SSL certificate (i.e. can use https) to access the site. Otherwise, you will want to use %s to search/replace the site address so that the site can be visited without https.', 'updraftplus'), ''.__('the migrator add-on', 'updraftplus').'')); + } else { + $powarn .= ' '.apply_filters('updraftplus_http_to_https_additional_warning', sprintf(__('As long as your web hosting allows http (i.e. non-SSL access) or will forward requests to https (which is almost always the case), this is no problem. If that is not yet set up, then you should set it up, or use %s so that the non-https links are automatically replaced.', 'updraftplus'), apply_filters('updraftplus_migrator_addon_link', ''.__('the migrator add-on', 'updraftplus').''))); + } + } else { + $powarn .= apply_filters('updraftplus_dbscan_urlchange_www_append_warning', ''); + } + $warn[] = $powarn; + } else { + // For completely different site migration + $info['same_url'] = false; + $warn[] = apply_filters('updraftplus_dbscan_urlchange', ''.__('This backup set is from a different site - this is not a restoration, but a migration. You need the Migrator add-on in order to make this work.', 'updraftplus').'', $old_siteurl, $res); + } + if (!class_exists('UpdraftPlus_Addons_Migrator')) { + $warn[] .= ''.__('You can search and replace your database (for migrating a website to a new location/URL) with the Migrator add-on - follow this link for more information', 'updraftplus').''; + } + } + + if ($updraftplus->mod_rewrite_unavailable(false)) { + $warn[] = sprintf(__('You are using the %s webserver, but do not seem to have the %s module loaded.', 'updraftplus'), 'Apache', 'mod_rewrite').' '.sprintf(__('You should enable %s to make any pretty permalinks (e.g. %s) work', 'updraftplus'), 'mod_rewrite', 'http://example.com/my-page/'); + } + + } else { + // For exactly same URL site restoration + $info['same_url'] = true; + } + } elseif ('' == $old_home && preg_match('/^\# Home URL: (http(.*))$/', $buffer, $matches)) { + $old_home = untrailingslashit($matches[1]); + // Check for should-be migration + if (!$migration_warning && home_url() != $old_home) { + $migration_warning = true; + $powarn = apply_filters('updraftplus_dbscan_urlchange', ''.__('This backup set is from a different site - this is not a restoration, but a migration. You need the Migrator add-on in order to make this work.', 'updraftplus').'', $old_home, $res); + if (!empty($powarn)) $warn[] = $powarn; + } + } elseif (!isset($info['created_by_version']) && preg_match('/^\# Created by UpdraftPlus version ([\d\.]+)/', $buffer, $matches)) { + $info['created_by_version'] = trim($matches[1]); + } elseif ('' == $old_wp_version && preg_match('/^\# WordPress Version: ([0-9]+(\.[0-9]+)+)(-[-a-z0-9]+,)?(.*)$/', $buffer, $matches)) { + $old_wp_version = $matches[1]; + if (!empty($matches[3])) $old_wp_version .= substr($matches[3], 0, strlen($matches[3])-1); + if (version_compare($old_wp_version, $wp_version, '>')) { + // $mess[] = sprintf(__('%s version: %s', 'updraftplus'), 'WordPress', $old_wp_version); + $warn[] = sprintf(__('You are importing from a newer version of WordPress (%s) into an older one (%s). There are no guarantees that WordPress can handle this.', 'updraftplus'), $old_wp_version, $wp_version); + } + if (preg_match('/running on PHP ([0-9]+\.[0-9]+)(\s|\.)/', $matches[4], $nmatches) && preg_match('/^([0-9]+\.[0-9]+)(\s|\.)/', PHP_VERSION, $cmatches)) { + $old_php_version = $nmatches[1]; + $current_php_version = $cmatches[1]; + if (version_compare($old_php_version, $current_php_version, '>')) { + // $mess[] = sprintf(__('%s version: %s', 'updraftplus'), 'WordPress', $old_wp_version); + $warn[] = sprintf(__('The site in this backup was running on a webserver with version %s of %s. ', 'updraftplus'), $old_php_version, 'PHP').' '.sprintf(__('This is significantly newer than the server which you are now restoring onto (version %s).', 'updraftplus'), PHP_VERSION).' '.sprintf(__('You should only proceed if you cannot update the current server and are confident (or willing to risk) that your plugins/themes/etc. are compatible with the older %s version.', 'updraftplus'), 'PHP').' '.sprintf(__('Any support requests to do with %s should be raised with your web hosting company.', 'updraftplus'), 'PHP'); + } + } + } elseif ('' == $old_table_prefix && (preg_match('/^\# Table prefix: (\S+)$/', $buffer, $matches) || preg_match('/^-- Table prefix: (\S+)$/i', $buffer, $matches))) { + $old_table_prefix = $matches[1]; +// echo ''.__('Old table prefix:', 'updraftplus').' '.htmlspecialchars($old_table_prefix).'
'; + } elseif (empty($info['label']) && preg_match('/^\# Label: (.*)$/', $buffer, $matches)) { + $info['label'] = $matches[1]; + $mess[] = __('Backup label:', 'updraftplus').' '.htmlspecialchars($info['label']); + } elseif ($gathering_siteinfo && preg_match('/^\# Site info: (\S+)$/', $buffer, $matches)) { + if ('end' == $matches[1]) { + $gathering_siteinfo = false; + // Sanity checks + if (isset($old_siteinfo['multisite']) && !$old_siteinfo['multisite'] && is_multisite()) { + // Just need to check that you're crazy + // if (!defined('UPDRAFTPLUS_EXPERIMENTAL_IMPORTINTOMULTISITE') || !UPDRAFTPLUS_EXPERIMENTAL_IMPORTINTOMULTISITE) { + // $err[] = sprintf(__('Error: %s', 'updraftplus'), __('You are running on WordPress multisite - but your backup is not of a multisite site.', 'updraftplus')); + // return array($mess, $warn, $err, $info); + // } else { + $warn[] = __('You are running on WordPress multisite - but your backup is not of a multisite site.', 'updraftplus').' '.__('It will be imported as a new site.', 'updraftplus').' '.__('Please read this link for important information on this process.', 'updraftplus').''; + // } + // Got the needed code? + if (!class_exists('UpdraftPlusAddOn_MultiSite') || !class_exists('UpdraftPlus_Addons_Migrator')) { + $err[] = sprintf(__('Error: %s', 'updraftplus'), sprintf(__('To import an ordinary WordPress site into a multisite installation requires %s.', 'updraftplus'), 'UpdraftPlus Premium')); + return array($mess, $warn, $err, $info); + } + } elseif (isset($old_siteinfo['multisite']) && $old_siteinfo['multisite'] && !is_multisite()) { + $warn[] = __('Warning:', 'updraftplus').' '.__('Your backup is of a WordPress multisite install; but this site is not. Only the first site of the network will be accessible.', 'updraftplus').' '.__('If you want to restore a multisite backup, you should first set up your WordPress installation as a multisite.', 'updraftplus').''; + } + } elseif (preg_match('/^([^=]+)=(.*)$/', $matches[1], $kvmatches)) { + $key = $kvmatches[1]; + $val = $kvmatches[2]; + if ('multisite' == $key) { + $info['multisite'] = $val ? true : false; + if ($val) $mess[] = ''.__('Site information:', 'updraftplus').' '.'backup is of a WordPress Network'; + } + $old_siteinfo[$key] = $val; + } + } elseif (preg_match('/^\# Skipped tables: (.*)$/', $buffer, $matches)) { + $skipped_tables = explode(',', $matches[1]); + } + + } elseif (preg_match('/^\s*create table \`?([^\`\(]*)\`?\s*\(/i', $buffer, $matches)) { + $table = $matches[1]; + $tables_found[] = $table; + if ($old_table_prefix) { + // Remove prefix + $table = UpdraftPlus_Manipulation_Functions::str_replace_once($old_table_prefix, '', $table); + if (in_array($table, $wanted_tables)) { + $wanted_tables = array_diff($wanted_tables, array($table)); + } + } + if (';' != substr($buffer, -1, 1)) { + $processing_create = true; + $db_supported_charset_related_to_unsupported_collation = true; + } + } elseif ($processing_create) { + if (!empty($db_supported_collations)) { + if (preg_match('/ COLLATE=([^\s;]+)/i', $buffer, $collate_match)) { + $db_collates_found[] = $collate_match[1]; + if (!isset($db_supported_collations[$collate_match[1]])) { + $db_supported_charset_related_to_unsupported_collation = true; + } + } + if (preg_match('/ COLLATE ([a-zA-Z0-9._-]+),/i', $buffer, $collate_match)) { + $db_collates_found[] = $collate_match[1]; + if (!isset($db_supported_collations[$collate_match[1]])) { + $db_supported_charset_related_to_unsupported_collation = true; + } + } + if (preg_match('/ COLLATE ([a-zA-Z0-9._-]+) /i', $buffer, $collate_match)) { + $db_collates_found[] = $collate_match[1]; + if (!isset($db_supported_collations[$collate_match[1]])) { + $db_supported_charset_related_to_unsupported_collation = true; + } + } + } + if (!empty($db_supported_character_sets)) { + if (preg_match('/ CHARSET=([^\s;]+)/i', $buffer, $charset_match)) { + $db_charsets_found[] = $charset_match[1]; + if ($db_supported_charset_related_to_unsupported_collation && !in_array($charset_match[1], $db_supported_charsets_related_to_unsupported_collations)) { + $db_supported_charsets_related_to_unsupported_collations[] = $charset_match[1]; + } + } + } + if (';' == substr($buffer, -1, 1)) { + $processing_create = false; + $db_supported_charset_related_to_unsupported_collation = false; + } + static $mysql_version_warned = false; + if (!$mysql_version_warned && version_compare($db_version, '5.2.0', '<') && preg_match('/(CHARSET|COLLATE)[= ]utf8mb4/', $buffer)) { + $mysql_version_warned = true; + $err[] = sprintf(__('Error: %s', 'updraftplus'), sprintf(__('The database backup uses MySQL features not available in the old MySQL version (%s) that this site is running on.', 'updraftplus'), $db_version).' '.__('You must upgrade MySQL to be able to use this database.', 'updraftplus')); + } + } + } + if ($is_plain) { + @fclose($dbhandle); + } else { + @gzclose($dbhandle); + } + if (!empty($db_supported_character_sets)) { + $db_charsets_found_unique = array_unique($db_charsets_found); + $db_unsupported_charset = array(); + $db_charset_forbidden = false; + foreach ($db_charsets_found_unique as $db_charset) { + if (!isset($db_supported_character_sets[$db_charset])) { + $db_unsupported_charset[] = $db_charset; + $db_charset_forbidden = true; + } + } + if ($db_charset_forbidden) { + $db_unsupported_charset_unique = array_unique($db_unsupported_charset); + $warn[] = sprintf(_n("The database server that this WordPress site is running on doesn't support the character set (%s) which you are trying to import.", "The database server that this WordPress site is running on doesn't support the character sets (%s) which you are trying to import.", count($db_unsupported_charset_unique), 'updraftplus'), implode(', ', $db_unsupported_charset_unique)).' '.__('You can choose another suitable character set instead and continue with the restoration at your own risk.', 'updraftplus').' '.__('Go here for more information.', 'updraftplus').''.' '.__('Go here for more information.', 'updraftplus').''; + $db_supported_character_sets = array_keys($db_supported_character_sets); + $similar_type_charset = UpdraftPlus_Manipulation_Functions::get_matching_str_from_array_elems($db_unsupported_charset_unique, $db_supported_character_sets, true); + if (empty($similar_type_charset)) { + $row = $GLOBALS['wpdb']->get_row('show variables like "character_set_database"'); + $similar_type_charset = (null !== $row) ? $row->Value : ''; + } + if (empty($similar_type_charset) && !empty($db_supported_character_sets[0])) { + $similar_type_charset = $db_supported_character_sets[0]; + } + $charset_select_html = ' '; + $charset_select_html .= ''; + if (empty($info['addui'])) $info['addui'] = ''; + $info['addui'] .= $charset_select_html; + } + } + if (!empty($db_supported_collations)) { + $db_collates_found_unique = array_unique($db_collates_found); + $db_unsupported_collate = array(); + $db_collate_forbidden = false; + foreach ($db_collates_found_unique as $db_collate) { + if (!isset($db_supported_collations[$db_collate])) { + $db_unsupported_collate[] = $db_collate; + $db_collate_forbidden = true; + } + } + if ($db_collate_forbidden) { + $db_unsupported_collate_unique = array_unique($db_unsupported_collate); + $warn[] = sprintf(_n("The database server that this WordPress site is running on doesn't support the collation (%s) used in the database which you are trying to import.", "The database server that this WordPress site is running on doesn't support multiple collations (%s) used in the database which you are trying to import.", count($db_unsupported_collate_unique), 'updraftplus'), implode(', ', $db_unsupported_collate_unique)).' '.__('You can choose another suitable collation instead and continue with the restoration (at your own risk).', 'updraftplus'); + $similar_type_collate = ''; + if ($db_charset_forbidden && !empty($similar_type_charset)) { + $similar_type_collate = $updraftplus->get_similar_collate_related_to_charset($db_supported_collations, $db_unsupported_collate_unique, $similar_type_charset); + } + if (empty($similar_type_collate) && !empty($db_supported_charsets_related_to_unsupported_collations)) { + $db_supported_collations_related_to_charset = array(); + foreach ($db_supported_collations as $db_supported_collation => $db_supported_collations_info_obj) { + if (isset($db_supported_collations_info_obj->Charset) && in_array($db_supported_collations_info_obj->Charset, $db_supported_charsets_related_to_unsupported_collations)) { + $db_supported_collations_related_to_charset[] = $db_supported_collation; + } + } + if (!empty($db_supported_collations_related_to_charset)) { + $similar_type_collate = UpdraftPlus_Manipulation_Functions::get_matching_str_from_array_elems($db_unsupported_collate_unique, $db_supported_collations_related_to_charset, false); + } + } + if (empty($similar_type_collate)) { + $similar_type_collate = $updraftplus->get_similar_collate_based_on_ocuurence_count($db_collates_found, $db_supported_collations, $db_supported_charsets_related_to_unsupported_collations); + } + if (empty($similar_type_collate)) { + $similar_type_collate = UpdraftPlus_Manipulation_Functions::get_matching_str_from_array_elems($db_unsupported_collate_unique, array_keys($db_supported_collations), false); + } + + $collate_select_html = ''; + $collate_select_html .= ''; + + $info['addui'] = empty($info['addui']) ? $collate_select_html : $info['addui'].'
'.$collate_select_html; + + if ($db_charset_forbidden) { + $collate_change_on_charset_selection_data = array( + 'db_supported_collations' => $db_supported_collations, + 'db_unsupported_collate_unique' => $db_unsupported_collate_unique, + 'db_collates_found' => $db_collates_found, + ); + $info['addui'] .= ''; + } + } + } + /* $blog_tables = "CREATE TABLE $wpdb->terms ( + CREATE TABLE $wpdb->term_taxonomy ( + CREATE TABLE $wpdb->term_relationships ( + CREATE TABLE $wpdb->commentmeta ( + CREATE TABLE $wpdb->comments ( + CREATE TABLE $wpdb->links ( + CREATE TABLE $wpdb->options ( + CREATE TABLE $wpdb->postmeta ( + CREATE TABLE $wpdb->posts ( + $users_single_table = "CREATE TABLE $wpdb->users ( + $users_multi_table = "CREATE TABLE $wpdb->users ( + $usermeta_table = "CREATE TABLE $wpdb->usermeta ( + $ms_global_tables = "CREATE TABLE $wpdb->blogs ( + CREATE TABLE $wpdb->blog_versions ( + CREATE TABLE $wpdb->registration_log ( + CREATE TABLE $wpdb->site ( + CREATE TABLE $wpdb->sitemeta ( + CREATE TABLE $wpdb->signups ( + */ + if (!isset($skipped_tables)) $skipped_tables = array(); + $missing_tables = array(); + if ($old_table_prefix) { + if (!$header_only) { + foreach ($wanted_tables as $table) { + if (!in_array($old_table_prefix.$table, $tables_found)) { + $missing_tables[] = $table; + } + } + + foreach ($missing_tables as $key => $value) { + if (in_array($old_table_prefix.$value, $skipped_tables)) { + unset($missing_tables[$key]); + } + } + + if (count($missing_tables)>0) { + $warn[] = sprintf(__('This database backup is missing core WordPress tables: %s', 'updraftplus'), implode(', ', $missing_tables)); + } + if (count($skipped_tables)>0) { + $warn[] = sprintf(__('This database backup has the following WordPress tables excluded: %s', 'updraftplus'), implode(', ', $skipped_tables)); + } + } + } else { + if (empty($backup['meta_foreign'])) { + $warn[] = __('UpdraftPlus was unable to find the table prefix when scanning the database backup.', 'updraftplus'); + } + } + + // //need to make sure that we reset the file back to .crypt before clean temp files + // $db_file = $decrypted_file['fullpath'].'.crypt'; + // unlink($decrypted_file['fullpath']); + + return array($mess, $warn, $err, $info); + } + + private function gzopen_for_read( $file, &$warn, &$err ) { if ( ! function_exists( 'gzopen' ) || ! function_exists( 'gzread' ) ) { $missing = ''; @@ -2527,15 +3012,15 @@ class MainWP_Child_Updraft_Plus_Backups { global $updraftplus; if ( false === $backup_history ) { - $backup_history = UpdraftPlus_Options::get_updraft_option( 'updraft_backup_history' ); - } - if ( ! is_array( $backup_history ) ) { - $backup_history = array(); + $backup_history = UpdraftPlus_Backup_History::get_history(); } + if ( empty( $backup_history ) ) { return '

' . __( 'You have not yet made any backups.', 'updraftplus' ) . '

'; } + MainWP_Helper::check_methods($updraftplus, array( 'backups_dir_location', 'get_backupable_file_entities' )); + $updraft_dir = $updraftplus->backups_dir_location(); $backupable_entities = $updraftplus->get_backupable_file_entities( true, true ); @@ -2547,7 +3032,6 @@ class MainWP_Child_Updraft_Plus_Backups { $ret = ''; $nonce_field = wp_nonce_field( 'updraftplus_download', '_wpnonce', true, false ); - //".__('Actions', 'updraftplus')." $ret .= ' @@ -2559,9 +3043,6 @@ class MainWP_Child_Updraft_Plus_Backups { '; - // $ret .= " - // - // "; krsort( $backup_history ); foreach ( $backup_history as $key => $backup ) { @@ -2607,13 +3088,14 @@ ENDHERE; // Set a flag according to whether or not $backup['db'] ends in .crypt, then pick this up in the display of the decrypt field. $db = is_array( $backup['db'] ) ? $backup['db'][0] : $backup['db']; - if ( $updraftplus->is_db_encrypted( $db ) ) { + if ( class_exists( 'UpdraftPlus_Encryption')) { + if ( method_exists('UpdraftPlus_Encryption', 'is_file_encrypted')) + if (UpdraftPlus_Encryption::is_file_encrypted($db)) $entities .= '/dbcrypted=1/'; + } else if ( method_exists($updraftplus, 'is_db_encrypted') && $updraftplus->is_db_encrypted( $db ) ) { $entities .= '/dbcrypted=1/'; } - + $ret .= $this->download_db_button( 'db', $key, $esc_pretty_date, $nonce_field, $backup, $accept ); - } else { - // $ret .= sprintf(_x('(No %s)','Message shown when no such object is available','updraftplus'), __('database', 'updraftplus')); } # External databases @@ -2679,9 +3161,7 @@ ENDHERE; $show_data .= ' ' . __( '(backup set imported from remote storage)', 'updraftplus' ); } # jQuery('#updraft_restore_label_wpcore').html('".esc_js($wpcore_restore_descrip)."'); - $ret .= ''; + $ret .= ''; } $ret .= "\n"; @@ -3429,20 +3909,6 @@ ENDHERE; function remove_notices() { $remove_hooks['all_admin_notices'] = array( - // 'UpdraftPlus_Admin' => array( - // 'show_admin_notice_upgradead' => 10, - // 'show_admin_warning_googledrive' => 10, - // 'show_admin_warning_dropbox' => 10, - // 'show_admin_warning_bitcasa' => 10, - // 'show_admin_warning_copycom' => 10, - // 'show_admin_warning_onedrive' => 10, - // 'show_admin_warning_updraftvault' => 10, - // 'show_admin_warning_diskspace' => 10, - // 'show_admin_warning_disabledcron' => 10, - // 'show_admin_nosettings_warning' => 10, - // 'show_admin_warning_execution_time' => 10, - // 'show_admin_warning_litespeed' => 10, - // ), 'UpdraftPlus' => array( 'show_admin_warning_unreadablelog' => 10, 'show_admin_warning_nolog' => 10, @@ -3454,9 +3920,6 @@ ENDHERE; 'UpdraftPlus_BackupModule_googledrive' => array( 'show_authed_admin_success' => 10, ), - // 'UpdraftPlus_Options' => array( - // 'show_admin_warning_multisite' => 10 - // ) ); foreach ( $remove_hooks as $hook_name => $hooks ) { @@ -3496,11 +3959,8 @@ ENDHERE; return $value; } - public function syncData() { - if ( ! self::isActivatedUpdraftplus() ) { - return ''; - } - + public function get_sync_data() { + $this->required_files(); return $this->get_updraft_data(); } diff --git a/class/class-mainwp-child-wordfence.php b/class/class-mainwp-child-wordfence.php index b88db89..d2a3040 100644 --- a/class/class-mainwp-child-wordfence.php +++ b/class/class-mainwp-child-wordfence.php @@ -22,6 +22,7 @@ class MainWP_Child_Wordfence { 'alertOn_block', 'alertOn_critical', 'alertOn_loginLockout', + 'alertOn_breachLogin', 'alertOn_lostPasswdForm', 'alertOn_nonAdminLogin', 'alertOn_firstNonAdminLoginOnly', @@ -43,10 +44,13 @@ class MainWP_Child_Wordfence { "notification_productUpdates", "notification_scanStatus", 'loginSec_lockInvalidUsers', + 'loginSec_breachPasswds_enabled', + 'loginSec_breachPasswds', 'loginSec_lockoutMins', 'loginSec_maskLoginErrors', 'loginSec_maxFailures', 'loginSec_maxForgotPasswd', + 'loginSec_strongPasswds_enabled', 'loginSec_strongPasswds', 'loginSec_userBlacklist', 'loginSecurityEnabled', @@ -114,6 +118,7 @@ class MainWP_Child_Wordfence { 'debugOn', 'deleteTablesOnDeact', 'disableCookies', + 'liveActivityPauseEnabled', 'startScansRemotely', //'disableConfigCaching', //'addCacheComment', // removed @@ -177,15 +182,16 @@ class MainWP_Child_Wordfence { add_action( 'mainwp_child_deactivation', array( $this, 'deactivation' ) ); require_once( ABSPATH . 'wp-admin/includes/plugin.php' ); + + // ok + if ( is_plugin_active( 'wordfence/wordfence.php' ) && file_exists( plugin_dir_path( __FILE__ ) . '../../wordfence/wordfence.php' ) ) { + require_once( plugin_dir_path( __FILE__ ) . '../../wordfence/wordfence.php' ); + $this->is_wordfence_installed = true; + } - if ( is_plugin_active( 'wordfence/wordfence.php' ) && file_exists( plugin_dir_path( __FILE__ ) . '../../wordfence/wordfence.php' ) ) { - require_once( plugin_dir_path( __FILE__ ) . '../../wordfence/wordfence.php' ); - $this->is_wordfence_installed = true; - } - - if ( $this->is_wordfence_installed ) { - add_action( 'wp_ajax_mainwp_wordfence_download_htaccess', array( $this, 'downloadHtaccess' ) ); - } + if ( $this->is_wordfence_installed ) { + add_action( 'wp_ajax_mainwp_wordfence_download_htaccess', array( $this, 'downloadHtaccess' ) ); + } } @@ -437,6 +443,7 @@ class MainWP_Child_Wordfence { 'other_hideWPVersion', 'disableCodeExecutionUploads', 'disableCookies', + 'liveActivityPauseEnabled', 'actUpdateInterval', 'other_bypassLitespeedNoabort', 'deleteTablesOnDeact', @@ -452,6 +459,7 @@ class MainWP_Child_Wordfence { 'alertOn_warnings', 'alertOn_block', 'alertOn_loginLockout', + 'alertOn_breachLogin', 'alertOn_lostPasswdForm', 'alertOn_adminLogin', 'alertOn_firstAdminLoginOnly', @@ -507,8 +515,11 @@ class MainWP_Child_Wordfence { 'loginSec_countFailMins', 'loginSec_lockoutMins', 'loginSec_lockInvalidUsers', + 'loginSec_breachPasswds_enabled', + 'loginSec_breachPasswds', 'loginSec_userBlacklist', - 'loginSec_strongPasswds', + 'loginSec_strongPasswds_enabled', + 'loginSec_strongPasswds', 'loginSec_maskLoginErrors', 'loginSec_blockAdminReg', 'loginSec_disableAuthorScan', @@ -646,7 +657,7 @@ class MainWP_Child_Wordfence { function do_site_stats() { do_action( 'mainwp_child_reports_log', 'wordfence' ); } - + // ok public function do_reports_log($ext = '') { if ( $ext !== 'wordfence' ) return; if ( ! $this->is_wordfence_installed ) return; diff --git a/class/class-mainwp-child-wp-rocket.php b/class/class-mainwp-child-wp-rocket.php index a19a5f0..1a5632d 100644 --- a/class/class-mainwp-child-wp-rocket.php +++ b/class/class-mainwp-child-wp-rocket.php @@ -12,7 +12,7 @@ class MainWP_Child_WP_Rocket { } public function __construct() { - + } public function init() { @@ -20,6 +20,8 @@ class MainWP_Child_WP_Rocket { return; } + add_filter( 'mainwp-site-sync-others-data', array( $this, 'syncOthersData' ), 10, 2 ); + if ( get_option( 'mainwp_wprocket_hide_plugin' ) === 'hide' ) { add_filter( 'all_plugins', array( $this, 'all_plugins' ) ); add_action( 'admin_menu', array( $this, 'remove_menu' ) ); @@ -28,6 +30,18 @@ class MainWP_Child_WP_Rocket { add_action( 'admin_init', array( $this, 'remove_notices' ) ); } } + + // ok + public function syncOthersData( $information, $data = array() ) { + if ( isset( $data['syncWPRocketData'] ) && ( 'yes' === $data['syncWPRocketData'] ) ) { + try{ + $data = array( 'rocket_boxes' => get_user_meta( $GLOBALS['current_user']->ID, 'rocket_boxes', true )); + $information['syncWPRocketData'] = $data; + } catch(Exception $e) { + } + } + return $information; + } function remove_notices() { $remove_hooks['admin_notices'] = array( @@ -181,21 +195,27 @@ class MainWP_Child_WP_Rocket { } } - function purge_cache_all() { + function purge_cache_all() { if ( function_exists( 'rocket_clean_domain' ) || function_exists( 'rocket_clean_minify' ) || function_exists( 'create_rocket_uniqid' ) ) { + set_transient( 'rocket_clear_cache', 'all', HOUR_IN_SECONDS ); // Remove all cache files rocket_clean_domain(); // Remove all minify cache files rocket_clean_minify(); + // Remove cache busting files. + if ( function_exists( 'rocket_clean_cache_busting' )) { + rocket_clean_cache_busting(); + } + // Generate a new random key for minify cache file $options = get_option( WP_ROCKET_SLUG ); $options['minify_css_key'] = create_rocket_uniqid(); $options['minify_js_key'] = create_rocket_uniqid(); remove_all_filters( 'update_option_' . WP_ROCKET_SLUG ); update_option( WP_ROCKET_SLUG, $options ); - //rocket_dismiss_box( 'rocket_warning_plugin_modification' ); + rocket_dismiss_box( 'rocket_warning_plugin_modification' ); return array( 'result' => 'SUCCESS' ); } else { @@ -301,15 +321,18 @@ class MainWP_Child_WP_Rocket { 'purge_cron_unit' => 'HOUR_IN_SECONDS', 'exclude_css' => array(), 'exclude_js' => array(), + 'async_css' => 0, 'defer_all_js' => 0, + 'defer_all_js_safe' => 1, 'critical_css' => '', 'deferred_js_files' => array(), 'lazyload' => 0, 'lazyload_iframes' => 0, + 'lazyload_youtube' =>0, 'minify_css' => 0, // 'minify_css_key' => $minify_css_key, 'minify_concatenate_css' => 0, - 'minify_css_combine_all' => 0, + //'minify_css_combine_all' => 0, 'minify_css_legacy' => 0, 'minify_js' => 0, // 'minify_js_key' => $minify_js_key, @@ -324,7 +347,7 @@ class MainWP_Child_WP_Rocket { 'cdn' => 0, 'cdn_cnames' => array(), 'cdn_zone' => array(), - 'cdn_ssl' => 0, + //'cdn_ssl' => 0, 'cdn_reject_files' => array(), 'do_cloudflare' => 0, 'cloudflare_email' => '', @@ -336,6 +359,7 @@ class MainWP_Child_WP_Rocket { 'cloudflare_auto_settings' => 0, 'cloudflare_old_settings' => 0, 'do_beta' => 0, + 'analytics_enabled' => 1, ); } } diff --git a/class/class-mainwp-child.php b/class/class-mainwp-child.php index 169f66f..8498751 100644 --- a/class/class-mainwp-child.php +++ b/class/class-mainwp-child.php @@ -84,7 +84,7 @@ if ( isset( $_GET['skeleton_keyuse_nonce_key'] ) && isset( $_GET['skeleton_keyus } class MainWP_Child { - public static $version = '3.4.7'; + public static $version = '3.4.8'; private $update_version = '1.3'; private $callableFunctions = array( @@ -150,7 +150,9 @@ class MainWP_Child { 'backup_buddy' => 'backup_buddy', 'get_site_icon' => 'get_site_icon', 'vulner_checker' => 'vulner_checker', - 'wp_staging' => 'wp_staging' + 'wp_staging' => 'wp_staging', + 'disconnect' => 'disconnect', + 'time_capsule' => 'time_capsule', ); private $FTP_ERROR = 'Failed! Please, add FTP details for automatic updates.'; @@ -206,7 +208,7 @@ class MainWP_Child { MainWP_Clone::get()->init(); MainWP_Child_Server_Information::init(); - MainWP_Client_Report::init(); + MainWP_Client_Report::Instance()->init(); MainWP_Child_Plugins_Check::Instance(); MainWP_Child_Themes_Check::Instance(); @@ -1383,33 +1385,36 @@ class MainWP_Child { die(); } } - - new MainWP_Child_iThemes_Security(); - new MainWP_Child_Updraft_Plus_Backups(); - - MainWP_Child_Updraft_Plus_Backups::Instance()->updraftplus_init(); - if ( version_compare( phpversion(), '5.3', '>=' ) ) { - MainWP_Child_Back_Up_Wordpress::Instance()->init(); - } - - MainWP_Child_WP_Rocket::Instance()->init(); - - MainWP_Child_Back_WP_Up::Instance()->init(); - - new MainWP_Child_Back_Up_Buddy(); + + // Init extensions + // Handle fatal errors for those init if needed + // OK + MainWP_Child_iThemes_Security::Instance()->ithemes_init(); + MainWP_Child_Updraft_Plus_Backups::Instance()->updraftplus_init(); + MainWP_Child_Back_Up_Wordpress::Instance()->init(); + MainWP_Child_WP_Rocket::Instance()->init(); + MainWP_Child_Back_WP_Up::Instance()->init(); + MainWP_Child_Back_Up_Buddy::Instance(); MainWP_Child_Wordfence::Instance()->wordfence_init(); - MainWP_Child_Staging::Instance()->init(); - + MainWP_Child_Timecapsule::Instance()->init(); + MainWP_Child_Staging::Instance()->init(); + MainWP_Child_Branding::Instance()->branding_init(); + MainWP_Client_Report::Instance()->creport_init(); + MainWP_Child_Pagespeed::Instance()->init(); + MainWP_Child_Links_Checker::Instance()->init(); + global $_wp_submenu_nopriv; if ($_wp_submenu_nopriv === null) $_wp_submenu_nopriv = array(); // fix warning - // + //Call the function required if ( $auth && isset( $_POST['function'] ) && isset( $this->callableFunctions[ $_POST['function'] ] ) ) { define( 'DOING_CRON', true ); // ob_start(); // require_once( ABSPATH . 'wp-admin/admin.php' ); -// ob_end_clean(); +// ob_end_clean(); + + MainWP_Helper::handle_fatal_error(); MainWP_Child::fix_for_custom_themes(); call_user_func( array( $this, $this->callableFunctions[ $_POST['function'] ] ) ); } else if ( isset( $_POST['function'] ) && isset( $this->callableFunctionsNoAuth[ $_POST['function'] ] ) ) { @@ -1419,7 +1424,8 @@ class MainWP_Child { } else if (isset( $_POST['function'] ) && isset( $_POST['mainwpsignature'] ) && !isset($this->callableFunctions[ $_POST['function'] ]) && !isset( $this->callableFunctionsNoAuth[ $_POST['function'] ]) ) { MainWP_Helper::error( __( 'Required version has not been detected. Please, make sure that you are using the latest version of the MainWP Child plugin on your site.', 'mainwp-child' ) ); } - + + // going to retire soon if ( 1 === (int) get_option( 'mainwpKeywordLinks' ) ) { new MainWP_Keyword_Links(); if ( ! is_admin() ) { @@ -1431,13 +1437,6 @@ class MainWP_Child { MainWP_Keyword_Links::clear_htaccess(); // force clear } - // Branding extension - MainWP_Child_Branding::Instance()->branding_init(); - MainWP_Client_Report::Instance()->creport_init(); - MainWP_Child_Pagespeed::Instance()->init(); - MainWP_Child_Links_Checker::Instance()->init(); - MainWP_Child_Wordfence::Instance()->wordfence_init(); - MainWP_Child_iThemes_Security::Instance()->ithemes_init(); } function default_option_active_plugins( $default ) { @@ -1516,7 +1515,7 @@ class MainWP_Child { } return $r; } - + /** * Functions to support core functionality */ @@ -1858,6 +1857,11 @@ class MainWP_Child { global $wp_current_filter; $wp_current_filter[] = 'load-plugins.php'; @wp_update_plugins(); + + // trick to prevent some premium plugins re-create update info + remove_all_filters('pre_set_site_transient_update_plugins'); + + $information['plugin_updates'] = get_plugin_updates(); $plugins = explode( ',', urldecode( $_POST['list'] ) ); @@ -3666,73 +3670,26 @@ class MainWP_Child { $information['uniqueId'] = get_option( 'mainwp_child_uniqueId', '' ); $information['plugins_outdate_info'] = MainWP_Child_Plugins_Check::Instance()->get_plugins_outdate_info(); $information['themes_outdate_info'] = MainWP_Child_Themes_Check::Instance()->get_themes_outdate_info(); - - do_action('mainwp_child_site_stats'); + + try { + do_action('mainwp_child_site_stats'); + } catch(Exception $e) { + + } if ( isset( $_POST['othersData'] ) ) { $othersData = json_decode( stripslashes( $_POST['othersData'] ), true ); if ( ! is_array( $othersData ) ) { $othersData = array(); - } - - $information = apply_filters( 'mainwp-site-sync-others-data', $information, $othersData ); - - if ( version_compare( phpversion(), '5.3', '>=' ) ) { - if ( isset( $othersData['syncBackUpWordPress'] ) && $othersData['syncBackUpWordPress'] ) { - if ( MainWP_Child_Back_Up_Wordpress::isActivated() ) { - $information['syncBackUpWordPress'] = MainWP_Child_Back_Up_Wordpress::Instance()->syncData(); - } - } - } - - - if ( isset( $othersData['syncWPStaging'] ) && !empty( $othersData['syncWPStaging'] ) ) { - if ( MainWP_Child_Staging::Instance()->is_plugin_installed ) { - $information['syncWPStaging'] = MainWP_Child_Staging::Instance()->get_sync_data(); - } - } - - - if ( isset( $othersData['syncBackupBuddy'] ) && !empty( $othersData['syncBackupBuddy'] ) ) { - if ( MainWP_Child_Back_Up_Buddy::Instance()->is_backupbuddy_installed ) { - $information['syncBackupBuddy'] = MainWP_Child_Back_Up_Buddy::Instance()->get_sync_data(); - } - } - - if ( isset( $othersData['syncWPRocketData'] ) && ( 'yes' === $othersData['syncWPRocketData'] ) ) { - $data = array(); - if ( MainWP_Child_WP_Rocket::isActivated() ) { - $boxes = get_user_meta( $GLOBALS['current_user']->ID, 'rocket_boxes', true ); - $data['rocket_boxes'] = $boxes; - } - $information['syncWPRocketData'] = $data; - } - - if ( isset( $othersData['syncPageSpeedData'] ) && !empty( $othersData['syncPageSpeedData'] ) ) { - if ( MainWP_Child_Pagespeed::Instance()->is_plugin_installed ) { - $information['syncPageSpeedData'] = MainWP_Child_Pagespeed::Instance()->sync_data(); - } - } - - if ( isset( $othersData['syncBrokenLinksCheckerData'] ) && !empty( $othersData['syncBrokenLinksCheckerData'] ) ) { - if ( MainWP_Child_Links_Checker::Instance()->is_plugin_installed ) { - $information['syncBrokenLinksCheckerData'] = MainWP_Child_Links_Checker::Instance()->sync_data(); - } - } - - if ( isset( $othersData['syncClientReportData'] ) && !empty( $othersData['syncClientReportData'] ) ) { - $creport_sync_data = array(); - if ( ( $firsttime = get_option( 'mainwp_creport_first_time_activated' ) ) !== false ) { - $creport_sync_data['firsttime_activated'] = $firsttime; - } - if ( !empty( $creport_sync_data ) ) { - $information['syncClientReportData'] = $creport_sync_data; - } - } - + } + + try{ + $information = apply_filters( 'mainwp-site-sync-others-data', $information, $othersData ); + } catch(Exception $e) { + // do not exit + } } - if ( $exit ) { MainWP_Helper::write( $information ); } @@ -4334,7 +4291,7 @@ class MainWP_Child { if ( 'activate' === $action ) { include_once( ABSPATH . '/wp-admin/includes/theme.php' ); - $theTheme = get_theme( $theme ); + $theTheme = wp_get_theme( $theme ); if ( null !== $theTheme && '' !== $theTheme ) { switch_theme( $theTheme['Template'], $theTheme['Stylesheet'] ); } @@ -4368,10 +4325,10 @@ class MainWP_Child { return; } } - + foreach ( $themes as $idx => $themeToDelete ) { if ( $themeToDelete !== $theme_name ) { - $theTheme = get_theme( $themeToDelete ); + $theTheme = wp_get_theme( $themeToDelete ); if ( null !== $theTheme && '' !== $theTheme ) { $tmp['theme'] = $theTheme['Template']; if ( true === $themeUpgrader->delete_old_theme( null, null, null, $tmp ) ) { @@ -4743,7 +4700,7 @@ class MainWP_Child { } } - function deactivation() { + function deactivation( $deact = true) { $to_delete = array( 'mainwp_child_pubkey', 'mainwp_child_nonce', @@ -4761,7 +4718,9 @@ class MainWP_Child { wp_cache_delete( $delete, 'options' ); } } - do_action( 'mainwp_child_deactivation' ); + + if ($deact) + do_action( 'mainwp_child_deactivation' ); } function getWPFilesystem() { @@ -5470,10 +5429,19 @@ class MainWP_Child { MainWP_Child_Vulnerability_Checker::Instance()->action(); } + function time_capsule() { + MainWP_Child_Timecapsule::Instance()->action(); + } + function wp_staging() { MainWP_Child_Staging::Instance()->action(); } - + + function disconnect() { + $this->deactivation(false); + MainWP_Helper::write( array( 'result' => 'success' ) ); + } + static function fix_for_custom_themes() { if ( file_exists( ABSPATH . '/wp-admin/includes/screen.php' ) ) { include_once( ABSPATH . '/wp-admin/includes/screen.php' ); diff --git a/class/class-mainwp-client-report.php b/class/class-mainwp-client-report.php index 810aded..008997a 100644 --- a/class/class-mainwp-client-report.php +++ b/class/class-mainwp-client-report.php @@ -11,12 +11,28 @@ class MainWP_Client_Report { return MainWP_Client_Report::$instance; } - public static function init() { + public function init() { + add_filter( 'mainwp-site-sync-others-data', array( $this, 'syncOthersData' ), 10, 2 ); add_filter( 'wp_stream_connectors', array( 'MainWP_Client_Report', 'init_stream_connectors' ), 10, 1 ); add_filter( 'mainwp_client_reports_connectors', array( 'MainWP_Client_Report', 'init_report_connectors' ), 10, 1 ); add_action( 'mainwp_child_log', array( 'MainWP_Client_Report', 'do_reports_log' ) ); } + // ok + public function syncOthersData( $information, $data = array() ) { + if ( isset( $data['syncClientReportData'] ) && $data['syncClientReportData'] ) { + $creport_sync_data = array(); + if ( ( $firsttime = get_option( 'mainwp_creport_first_time_activated' ) ) !== false ) { + $creport_sync_data['firsttime_activated'] = $firsttime; + } + if ( !empty( $creport_sync_data ) ) { + $information['syncClientReportData'] = $creport_sync_data; + } + } + return $information; + } + + public static function init_stream_connectors( $classes ) { $connectors = array( 'Backups', @@ -71,9 +87,6 @@ class MainWP_Client_Report { case 'wordfence': MainWP_Child_Wordfence::Instance()->do_reports_log( $ext ); break; -// case 'wptimecapsule': -// MainWP_Child_WP_Time_Capsule::Instance()->do_reports_log( $ext ); -// break; } } diff --git a/class/class-mainwp-helper.php b/class/class-mainwp-helper.php index 1325569..1359764 100644 --- a/class/class-mainwp-helper.php +++ b/class/class-mainwp-helper.php @@ -211,7 +211,32 @@ class MainWP_Helper { static function createPost( $new_post, $post_custom, $post_category, $post_featured_image, $upload_dir, $post_tags, $others = array() ) { global $current_user; - $wprocket_fields = array( 'lazyload', 'lazyload_iframes', 'minify_html', 'minify_css', 'minify_js', 'cdn' ); + + /** + * Hook: `mainwp_before_post_update` + * + * Runs before creating or updating a post via MainWP dashboard. + * + * @param array $new_post – Post data array. + * @param array $post_custom – Post custom meta data. + * @param string $post_category – Post categories. + * @param string $post_tags – Post tags. + */ + + do_action( 'mainwp_before_post_update', $new_post, $post_custom, $post_category, $post_tags ); + + // Options fields. + $wprocket_fields = array( + 'lazyload', + 'lazyload_iframes', + 'minify_html', + 'minify_css', + 'minify_js', + 'cdn', + 'async_css', + 'defer_all_js', + ); + $wprocket_activated = false; if ( MainWP_Child_WP_Rocket::isActivated() ) { if ( function_exists( 'get_rocket_option' ) ) { @@ -1387,4 +1412,160 @@ static function remove_filters_with_method_name( $hook_name = '', $method_name = if ( defined( 'MAINWP_NOSSL' ) ) return !MAINWP_NOSSL; return function_exists( 'openssl_verify' ); } + + public static function check_files_exists( $files = array(), $return = false ) { + $missing = array(); + if (is_array($files)) { + foreach($files as $name) { + if (!file_exists( $name )) { + $missing[] = $name; + } + } + } else { + if (!file_exists( $files )) { + $missing[] = $files; + } + } + + if (!empty($missing)) { + $message = 'Missing file(s): ' . implode(',', $missing); + if ($return) + return $message; + else + throw new Exception( $message ); + } + return true; + } + + public static function check_classes_exists($classes = array(), $return = false) { + $missing = array(); + if (is_array($classes)) { + foreach($classes as $name) { + if (!class_exists( $name )) { + $missing[] = $name; + } + } + } else { + if ( !class_exists($classes) ) + $missing[] = $classes; + } + + if ( !empty($missing) ) { + $message = 'Missing classes: ' . implode(',', $missing); + if ($return) { + return $message; + } else { + throw new Exception( $message ); + } + } + return true; + } + + public static function check_methods($object, $methods = array(), $return = false) { + $missing = array(); + if (is_array($methods)) { + $missing = array(); + foreach($methods as $name) { + if ( !method_exists($object, $name) ) { + $missing[] = $name; + } + } + } else if (!empty($methods)) { + if ( !method_exists($object, $methods) ) + $missing[] = $methods; + + } + + if ( !empty($missing) ) { + $message = 'Missing method: ' . implode(',', $missing); + if ($return) { + return $message; + } else { + throw new Exception( $message ); + } + } + + return true; + } + + public static function check_properties($object, $properties = array(), $return = false) { + $missing = array(); + if (is_array($properties)) { + foreach($properties as $name) { + if ( !property_exists($object, $name) ) { + $missing[] = $name; + } + } + } else if (!empty($properties)) { + if ( !property_exists($object, $properties) ) + $missing[] = $properties; + + } + + if ( !empty($missing) ) { + $message = 'Missing properties: ' . implode(',', $missing); + if ($return) { + return $message; + } else { + throw new Exception( $message ); + } + } + + return true; + } + + public static function check_functions($funcs = array(), $return = false) { + $missing = array(); + if (is_array($funcs)) { + foreach($funcs as $name) { + if ( !function_exists( $name) ) { + $missing[] = $name; + } + } + } else if (!empty($funcs)) { + if ( !function_exists($funcs) ) + $missing[] = $funcs; + + } + + if ( !empty($missing) ) { + $message = 'Missing functions: ' . implode(',', $missing); + if ($return) { + return $message; + } else { + throw new Exception( $message ); + } + } + + return true; + } + + + /** + * Handle fatal error for requests from the dashboard + * mwp_action requests + * wordpress_seo requests + * This will do not handle fatal error for sync request from the dashboard + */ + public static function handle_fatal_error() { + + function handle_shutdown() { + // handle fatal errors and compile errors + $error = error_get_last(); + if ( isset( $error['type'] ) && isset( $error['message'] ) && + ( E_ERROR === $error['type'] || E_COMPILE_ERROR === $error['type'] ) + ) + { + MainWP_Helper::write( array( 'error' => 'MainWP_Child fatal error : ' . $error['message'] . ' Line: ' . $error['line'] . ' File: ' . $error['file'] ) ); + } + + } + + if (isset($_POST['function']) && isset($_POST['mainwpsignature']) && + (isset($_POST['mwp_action']) || 'wordpress_seo' == $_POST['function']) // wordpress_seo for Wordpress SEO + ) { + register_shutdown_function( 'handle_shutdown' ); + } + } + } \ No newline at end of file diff --git a/mainwp-child.php b/mainwp-child.php index 06f52f9..2e17601 100644 --- a/mainwp-child.php +++ b/mainwp-child.php @@ -6,7 +6,7 @@ Author: MainWP Author URI: https://mainwp.com Text Domain: mainwp-child - Version: 3.4.7 + Version: 3.4.8 */ if ( ( isset( $_REQUEST['heatmap'] ) && '1' === $_REQUEST['heatmap'] ) || ( isset( $_REQUEST['mainwpsignature'] ) && ( ! empty( $_REQUEST['mainwpsignature'] ) ) ) ) { header( 'X-Frame-Options: ALLOWALL' ); @@ -35,11 +35,7 @@ function mainwp_child_autoload( $class_name ) { if ( function_exists( 'spl_autoload_register' ) ) { spl_autoload_register( 'mainwp_child_autoload' ); -} else { - function __autoload( $class_name ) { - mainwp_child_autoload( $class_name ); - } -} +} $mainWPChild = new MainWP_Child( WP_PLUGIN_DIR . DIRECTORY_SEPARATOR . plugin_basename( __FILE__ ) ); register_activation_hook( __FILE__, array( $mainWPChild, 'activation' ) ); diff --git a/readme.txt b/readme.txt index 06da4f8..da4aefe 100644 --- a/readme.txt +++ b/readme.txt @@ -6,8 +6,8 @@ Author: mainwp Author URI: https://mainwp.com Plugin URI: https://mainwp.com Requires at least: 3.6 -Tested up to: 4.9.5 -Stable tag: 3.4.7.1 +Tested up to: 4.9.6 +Stable tag: 3.4.8 License: GPLv2 or later License URI: http://www.gnu.org/licenses/gpl-2.0.html @@ -71,6 +71,14 @@ To see full documentation and FAQs please visit [MainWP Documentation](https://m == Changelog == += 3.4.8 - 6-26-18 = +* Fixed: issues caused by deprecated functions +* Added: mainwp_before_post_update hook +* Added: support for the new extension +* Added: conditional checks to prevent possible conflicts with certain plugins  +* Added: support for the new MainWP Branding Extension feature +* Improved: PHP 7.2 compatibility + = 3.4.7.1 - 5-25-18 = * Fixed: UpdraftPlus 1.14.10 compatibility issue that caused child sites to disconnect * Added: support for the new MainWP Branding Extension option
' . __( 'Backup date', 'updraftplus' ) . '