diff --git a/.gitignore b/.gitignore index 51a7bdd..bea9a88 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ .idea/vcs.xml .idea/dictionaries/keith.xml .idea/dictionaries/keith.xml +.idea/inspectionProfiles/Project_Default.xml diff --git a/class/class-mainwp-child-back-wp-up.php b/class/class-mainwp-child-back-wp-up.php index 17cb023..246b4a4 100644 --- a/class/class-mainwp-child-back-wp-up.php +++ b/class/class-mainwp-child-back-wp-up.php @@ -1,5 +1,9 @@ array( - 'cronminutes', - 'cronhours', - 'cronmday', - 'cronmon', - 'cronwday', - 'moncronminutes', - 'moncronhours', - 'moncronmday', - 'weekcronminutes', - 'weekcronhours', - 'weekcronwday', - 'daycronminutes', - 'daycronhours', - 'hourcronminutes', - 'cronbtype', - ), - 'dest-EMAIL' => array( 'emailpass' ), - 'dest-DBDUMP' => array( 'dbdumpspecialsetalltables' ), - 'dest-FTP' => array( 'ftppass' ), - 'dest-S3' => array( 's3secretkey' ), - 'dest-MSAZURE' => array( 'msazurekey' ), - 'dest-SUGARSYNC' => array( 'sugaremail', 'sugarpass', 'sugarrefreshtoken' ), - 'dest-GDRIVE' => array( 'gdriverefreshtoken' ), - 'dest-RSC' => array( 'rscapikey' ), - 'dest-GLACIER' => array( 'glaciersecretkey' ), - ); - - public static function instance() { - if ( null == self::$instance ) { - self::$instance = new self(); - } - - return self::$instance; - } - - 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'; - - if ( ! file_exists( $file_path2 ) ) { - $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; - } elseif ( 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 ( $this->is_backwpup_installed ) { - MainWP_Helper::check_classes_exists( '\BackWPup' ); - MainWP_Helper::check_methods( 'get_instance' ); - \BackWPup::get_instance(); - - add_action( 'admin_init', array( $this, 'init_download_backup' ) ); - add_filter( 'mainwp_site_sync_others_data', array( $this, 'sync_others_data' ), 10, 2 ); - } - } catch ( \Exception $e ) { - $this->is_backwpup_installed = false; - } - } - - function mainwp_backwpup_handle_fatal_error() { - $error = error_get_last(); - $info = self::$information; - if ( isset( $error['type'] ) && E_ERROR === $error['type'] && isset( $error['message'] ) ) { - MainWP_Helper::write( array( 'error' => 'MainWP_Child fatal error : ' . $error['message'] . ' Line: ' . $error['line'] . ' File: ' . $error['file'] ) ); - } elseif ( ! empty( $info ) ) { - MainWP_Helper::write( self::$information ); - } else { - MainWP_Helper::write( array( 'error' => 'Missing information array inside fatal_error' ) ); - } - } - - public function action() { - if ( ! $this->is_backwpup_installed ) { - MainWP_Helper::write( array( 'error' => __( 'Please install BackWPup plugin on child website', 'mainwp-child' ) ) ); - return; - } - register_shutdown_function( 'self::mainwp_backwpup_handle_fatal_error' ); - - $information = array(); - - if ( ! isset( $_POST['action'] ) ) { - $information = array( 'error' => __( 'Missing action.', 'mainwp-child' ) ); - } else { - - switch ( $_POST['action'] ) { - case 'backwpup_update_settings': - $information = $this->update_settings(); - break; - - case 'backwpup_insert_or_update_jobs': - $information = $this->insert_or_update_jobs(); - break; - - case 'backwpup_insert_or_update_jobs_global': - $information = $this->insert_or_update_jobs_global(); - break; - - case 'backwpup_get_child_tables': - $information = $this->get_child_tables(); - break; - - case 'backwpup_get_job_files': - $information = $this->get_job_files(); - break; - - case 'backwpup_destination_email_check_email': - $information = $this->destination_email_check_email(); - break; - - case 'backwpup_backup_now': - $information = $this->backup_now(); - break; - - case 'backwpup_ajax_working': - $information = $this->ajax_working(); - break; - - case 'backwpup_backup_abort': - $information = $this->backup_abort(); - break; - - case 'backwpup_tables': - $information = $this->tables(); - break; - - case 'backwpup_view_log': - $information = $this->view_log(); - break; - - case 'backwpup_delete_log': - $information = $this->delete_log(); - break; - - case 'backwpup_delete_job': - $information = $this->delete_job(); - break; - - case 'backwpup_delete_backup': - $information = $this->delete_backup(); - break; - - case 'backwpup_information': - $information = $this->information(); - break; - - case 'backwpup_wizard_system_scan': - $information = $this->wizard_system_scan(); - break; - - case 'backwpup_is_pro': - $information = array( 'is_pro' => $this->is_backwpup_pro ); - break; - - case 'backwpup_show_hide': - $information = $this->show_hide(); - break; - - default: - $information = array( 'error' => __( 'Wrong action.', 'mainwp-child' ) ); - } - } - - self::$information = $information; - exit(); - } - - public function init() { - - if ( ! $this->is_backwpup_installed ) { - return; - } - - add_action( 'mainwp_child_site_stats', array( $this, 'do_site_stats' ) ); - - if ( get_option( 'mainwp_backwpup_hide_plugin' ) === 'hide' ) { - add_filter( 'all_plugins', array( $this, 'all_plugins' ) ); - add_action( 'admin_menu', array( $this, 'remove_menu' ) ); - } - } - - public function do_site_stats() { - if ( has_action( 'mainwp_child_reports_log' ) ) { - do_action( 'mainwp_child_reports_log', 'backwpup' ); - } else { - $this->do_reports_log( 'backwpup' ); - } - } - - public function do_reports_log( $ext = '' ) { - if ( 'backwpup' !== $ext ) { - return; - } - if ( ! $this->is_backwpup_installed ) { - return; - } - - try { - - MainWP_Helper::check_classes_exists( array( '\BackWPup_File', '\BackWPup_Job' ) ); - MainWP_Helper::check_methods( '\BackWPup_File', array( 'get_absolute_path' ) ); - MainWP_Helper::check_methods( '\BackWPup_Job', array( 'read_logheader' ) ); - $lasttime_logged = MainWP_Utility::get_lasttime_backup( 'backwpup' ); - $log_folder = get_site_option( 'backwpup_cfg_logfolder' ); - $log_folder = \BackWPup_File::get_absolute_path( $log_folder ); - $log_folder = untrailingslashit( $log_folder ); - - $logfiles = array(); - $dir = opendir( $log_folder ); - if ( is_readable( $log_folder ) && $dir ) { - while ( ( $file = readdir( $dir ) ) !== false ) { - $log_file = $log_folder . '/' . $file; - if ( is_file( $log_file ) && is_readable( $log_file ) && false !== strpos( $file, 'backwpup_log_' ) && false !== strpos( $file, '.html' ) ) { - $logfiles[] = $file; - } - } - closedir( $dir ); - } - - $log_items = array(); - foreach ( $logfiles as $mtime => $logfile ) { - $meta = \BackWPup_Job::read_logheader( $log_folder . '/' . $logfile ); - if ( ! isset( $meta['logtime'] ) || $meta['logtime'] < $lasttime_logged ) { - continue; - } - - if ( isset( $meta['errors'] ) && ! empty( $meta['errors'] ) ) { - continue; - } - - $log_items[ $mtime ] = $meta; - $log_items[ $mtime ]['file'] = $logfile; - } - - if ( ! empty( $log_items ) ) { - $job_types = array( - 'DBDUMP' => __( 'Database backup', 'mainwp-child' ), - 'FILE' => __( 'File backup', 'mainwp-child' ), - 'WPEXP' => __( 'WordPress XML export', 'mainwp-child' ), - 'WPPLUGIN' => __( 'Installed plugins list', 'mainwp-child' ), - 'DBCHECK' => __( 'Check database tables', 'mainwp-child' ), - ); - - $new_lasttime_logged = $lasttime_logged; - - foreach ( $log_items as $log ) { - $backup_time = $log['logtime']; - if ( $backup_time < $lasttime_logged ) { - continue; - } - $job_job_types = explode( '+', $log['type'] ); - $backup_type = ''; - foreach ( $job_job_types as $typeid ) { - if ( isset( $job_types[ $typeid ] ) ) { - $backup_type .= ' + ' . $job_types[ $typeid ]; - } - } - - if ( empty( $backup_type ) ) { - continue; - } else { - $backup_type = ltrim( $backup_type, ' + ' ); - } - $message = 'BackWPup backup finished (' . $backup_type . ')'; - do_action( 'mainwp_reports_backwpup_backup', $message, $backup_type, $backup_time ); - - if ( $new_lasttime_logged < $backup_time ) { - $new_lasttime_logged = $backup_time; - } - } - - if ( $new_lasttime_logged > $lasttime_logged ) { - MainWP_Utility::update_lasttime_backup( 'backwpup', $new_lasttime_logged ); // to support backup before update feature. - } - } - } catch ( \Exception $ex ) { - // ok! - } - } - - public function sync_others_data( $information, $data = array() ) { - if ( isset( $data['syncBackwpupData'] ) && $data['syncBackwpupData'] ) { - try { - $lastbackup = MainWP_Utility::get_lasttime_backup( 'backwpup' ); - $information['syncBackwpupData'] = array( - 'lastbackup' => $lastbackup, - ); - } catch ( \Exception $e ) { - // ok! - } - } - return $information; - } - - public 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(); - foreach ( $jobids as $jobid ) { - if ( \BackWPup_Option::get( $jobid, 'backuptype' ) === 'sync' ) { - continue; - } - $dests = \BackWPup_Option::get( $jobid, 'destinations' ); - foreach ( $dests as $dest ) { - if ( ! $destinations[ $dest ]['class'] ) { - continue; - } - - $dest_class = \BackWPup::get_destination( $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; - } - } - } - } - - return $jobdest; - } - - public function all_plugins( $plugins ) { - foreach ( $plugins as $key => $value ) { - $plugin_slug = basename( $key, '.php' ); - if ( 'backwpup' === $plugin_slug ) { - unset( $plugins[ $key ] ); - } - } - - return $plugins; - } - - public function remove_menu() { - global $submenu; - - if ( isset( $submenu['backwpup'] ) ) { - unset( $submenu['backwpup'] ); - } - - remove_menu_page( 'backwpup' ); - - $pos = stripos( $_SERVER['REQUEST_URI'], 'admin.php?page=backwpup' ); - if ( false !== $pos ) { - wp_safe_redirect( get_option( 'siteurl' ) . '/wp-admin/index.php' ); - exit(); - } - } - - protected function show_hide() { - - $hide = isset( $_POST['show_hide'] ) && ( '1' === $_POST['show_hide'] ) ? 'hide' : ''; - - MainWP_Helper::instance()->update_option( 'mainwp_backwpup_hide_plugin', $hide, 'yes' ); - - return array( 'success' => 1 ); - } - - protected function information() { - global $wpdb; - // Copied from BackWPup_Page_Settings. - ob_start(); - echo ''; - echo ''; - echo ''; - echo ''; - if ( ! class_exists( '\BackWPup_Pro', false ) ) { - echo ''; - } else { - echo ''; - } - - echo ''; - echo ''; - if ( function_exists( 'curl_version' ) ) { - $curlversion = curl_version(); - echo ''; - echo ''; - } else { - echo ''; - } - echo ''; - - echo ''; - - echo ''; - - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - $text = version_compare( phpversion(), '5.3.0' ) < 0 && (bool) ini_get( 'safe_mode' ) ? __( 'On', 'mainwp-child' ) : __( 'Off', 'mainwp-child' ); - echo ''; - echo ''; - if ( defined( 'ALTERNATE_WP_CRON' ) && ALTERNATE_WP_CRON ) { - echo ''; - } else { - echo ''; - } - if ( defined( 'DISABLE_WP_CRON' ) && DISABLE_WP_CRON ) { - echo ''; - } else { - echo ''; - } - if ( defined( 'FS_CHMOD_DIR' ) ) { - echo ''; - } else { - echo ''; - } - - $now = localtime( time(), true ); - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - - $disabled = ini_get( 'disable_functions' ); - if ( ! empty( $disabled ) ) { - $disabledarry = explode( ',', $disabled ); - echo ''; - } - - echo ''; - echo '
' . __( 'Setting', 'mainwp-child' ) . '' . __( 'Value', 'mainwp-child' ) . '
' . __( 'Setting', 'mainwp-child' ) . '' . __( 'Value', 'mainwp-child' ) . '
' . __( 'WordPress version', 'mainwp-child' ) . '' . esc_html( \BackWPup::get_plugin_data( 'wp_version' ) ) . '
' . __( 'BackWPup version', 'mainwp-child' ) . '' . esc_html( \BackWPup::get_plugin_data( 'Version' ) ) . ' ' . __( 'Get pro.', 'mainwp-child' ) . '
' . __( 'BackWPup Pro version', 'mainwp-child' ) . '' . esc_html( \BackWPup::get_plugin_data( 'Version' ) ) . '
' . __( 'PHP version', 'mainwp-child' ) . '' . esc_html( PHP_VERSION ) . '
' . __( 'MySQL version', 'mainwp-child' ) . '' . esc_html( $wpdb->get_var( 'SELECT VERSION() AS version' ) ) . '
' . __( 'cURL version', 'mainwp-child' ) . '' . esc_html( $curlversion['version'] ) . '
' . __( 'cURL SSL version', 'mainwp-child' ) . '' . esc_html( $curlversion['ssl_version'] ) . '
' . __( 'cURL version', 'mainwp-child' ) . '' . __( 'unavailable', 'mainwp-child' ) . '
' . __( 'WP-Cron url:', 'mainwp-child' ) . '' . esc_html( site_url( 'wp-cron.php' ) ) . '
' . __( 'Server self connect:', 'mainwp-child' ) . ''; - $raw_response = \BackWPup_Job::get_jobrun_url( 'test' ); - $test_result = ''; - if ( is_wp_error( $raw_response ) ) { - $test_result .= sprintf( __( 'The HTTP response test get an error "%s"', 'mainwp-child' ), esc_html( $raw_response->get_error_message() ) ); - } elseif ( 200 !== (int) wp_remote_retrieve_response_code( $raw_response ) && 204 !== (int) wp_remote_retrieve_response_code( $raw_response ) ) { - $test_result .= sprintf( __( 'The HTTP response test get a false http status (%s)', 'mainwp-child' ), esc_html( wp_remote_retrieve_response_code( $raw_response ) ) ); - } - $headers = wp_remote_retrieve_headers( $raw_response ); - if ( isset( $headers['x-backwpup-ver'] ) && \BackWPup::get_plugin_data( 'version' ) !== $headers['x-backwpup-ver'] ) { - $test_result .= sprintf( __( 'The BackWPup HTTP response header returns a false value: "%s"', 'mainwp-child' ), esc_html( $headers['x-backwpup-ver'] ) ); - } - - if ( empty( $test_result ) ) { - esc_html_e( 'Response Test O.K.', 'mainwp-child' ); - } else { - echo esc_html( $test_result ); - } - echo '
' . __( 'Temp folder:', 'mainwp-child' ) . ''; - if ( ! is_dir( \BackWPup::get_plugin_data( 'TEMP' ) ) ) { - echo sprintf( __( 'Temp folder %s doesn\'t exist.', 'mainwp-child' ), esc_html( \BackWPup::get_plugin_data( 'TEMP' ) ) ); - } elseif ( ! is_writable( \BackWPup::get_plugin_data( 'TEMP' ) ) ) { - echo sprintf( __( 'Temporary folder %s is not writable.', 'mainwp-child' ), esc_html( \BackWPup::get_plugin_data( 'TEMP' ) ) ); - } else { - echo esc_html( \BackWPup::get_plugin_data( 'TEMP' ) ); - } - echo '
' . __( 'Log folder:', 'mainwp-child' ) . ''; - - $log_folder = \BackWPup_File::get_absolute_path( get_site_option( 'backwpup_cfg_logfolder' ) ); - - if ( ! is_dir( $log_folder ) ) { - echo sprintf( __( 'Logs folder %s not exist.', 'mainwp-child' ), esc_html( $log_folder ) ); - } elseif ( ! is_writable( $log_folder ) ) { - echo sprintf( __( 'Log folder %s is not writable.', 'mainwp-child' ), esc_html( $log_folder ) ); - } else { - echo esc_html( $log_folder ); - } - echo '
' . __( 'Server', 'mainwp-child' ) . '' . esc_html( $_SERVER['SERVER_SOFTWARE'] ) . '
' . __( 'Operating System', 'mainwp-child' ) . '' . esc_html( PHP_OS ) . '
' . __( 'PHP SAPI', 'mainwp-child' ) . '' . esc_html( PHP_SAPI ) . '
' . __( 'Current PHP user', 'mainwp-child' ) . '' . esc_html( get_current_user() ) . '
' . __( 'Safe Mode', 'mainwp-child' ) . '' . $text . '
' . __( 'Maximum execution time', 'mainwp-child' ) . '' . ini_get( 'max_execution_time' ) . ' ' . __( 'seconds', 'mainwp-child' ) . '
' . __( 'Alternative WP Cron', 'mainwp-child' ) . '' . __( 'On', 'mainwp-child' ) . '
' . __( 'Alternative WP Cron', 'mainwp-child' ) . '' . __( 'Off', 'mainwp-child' ) . '
' . __( 'Disabled WP Cron', 'mainwp-child' ) . '' . __( 'On', 'mainwp-child' ) . '
' . __( 'Disabled WP Cron', 'mainwp-child' ) . '' . __( 'Off', 'mainwp-child' ) . '
' . __( 'CHMOD Dir', 'mainwp-child' ) . '' . FS_CHMOD_DIR . '
' . __( 'CHMOD Dir', 'mainwp-child' ) . '0755
' . __( 'Server Time', 'mainwp-child' ) . '' . esc_html( $now['tm_hour'] ) . ':' . esc_html( $now['tm_min'] ) . '
' . __( 'Blog Time', 'mainwp-child' ) . '' . esc_html( date_i18n( 'H:i' ) ) . '
' . __( 'Blog Timezone', 'mainwp-child' ) . '' . esc_html( get_option( 'timezone_string' ) ) . '
' . __( 'Blog Time offset', 'mainwp-child' ) . '' . sprintf( __( '%s hours', 'mainwp-child' ), esc_html( get_option( 'gmt_offset' ) ) ) . '
' . __( 'Blog language', 'mainwp-child' ) . '' . esc_html( get_bloginfo( 'language' ) ) . '
' . __( 'MySQL Client encoding', 'mainwp-child' ) . ''; - echo defined( 'DB_CHARSET' ) ? esc_html( DB_CHARSET ) : ''; - echo '
' . __( 'Blog charset', 'mainwp-child' ) . '' . esc_html( get_bloginfo( 'charset' ) ) . '
' . __( 'PHP Memory limit', 'mainwp-child' ) . '' . esc_html( ini_get( 'memory_limit' ) ) . '
' . __( 'WP memory limit', 'mainwp-child' ) . '' . esc_html( WP_MEMORY_LIMIT ) . '
' . __( 'WP maximum memory limit', 'mainwp-child' ) . '' . esc_html( WP_MAX_MEMORY_LIMIT ) . '
' . __( 'Memory in use', 'mainwp-child' ) . '' . esc_html( size_format( memory_get_usage( true ), 2 ) ) . '
' . __( 'Disabled PHP Functions:', 'mainwp-child' ) . ''; - echo esc_html( implode( ', ', $disabledarry ) ); - echo '
' . __( 'Loaded PHP Extensions:', 'mainwp-child' ) . ''; - $extensions = get_loaded_extensions(); - sort( $extensions ); - echo esc_html( implode( ', ', $extensions ) ); - echo '
'; - - $output = ob_get_contents(); - - ob_end_clean(); - - return array( - 'success' => 1, - 'response' => $output, - ); - } - - protected function delete_log() { - if ( ! isset( $_POST['settings']['logfile'] ) || ! is_array( $_POST['settings']['logfile'] ) ) { - return array( 'error' => __( 'Missing logfile.', 'mainwp-child' ) ); - } - - $dir = get_site_option( 'backwpup_cfg_logfolder' ); - $dir = \BackWPup_File::get_absolute_path( $dir ); - - foreach ( $_POST['settings']['logfile'] as $logfile ) { - $logfile = basename( $logfile ); - - if ( ! is_writeable( $dir ) ) { - return array( 'error' => __( 'Directory not writable:', 'mainwp-child' ) . $dir ); - } - if ( ! is_file( $dir . $logfile ) ) { - return array( 'error' => __( 'Not file:', 'mainwp-child' ) . $dir . $logfile ); - } - - unlink( $dir . $logfile ); - - } - - return array( 'success' => 1 ); - } - - protected function delete_job() { - if ( ! isset( $_POST['job_id'] ) ) { - return array( 'error' => __( 'Missing job_id.', 'mainwp-child' ) ); - } - - $job_id = (int) $_POST['job_id']; - - wp_clear_scheduled_hook( 'backwpup_cron', array( 'id' => $job_id ) ); - if ( ! \BackWPup_Option::delete_job( $job_id ) ) { - return array( 'error' => __( 'Cannot delete job', 'mainwp-child' ) ); - } - - return array( 'success' => 1 ); - } - - protected function delete_backup() { - if ( ! isset( $_POST['settings']['backupfile'] ) ) { - return array( 'error' => __( 'Missing backupfile.', 'mainwp-child' ) ); - } - - if ( ! isset( $_POST['settings']['dest'] ) ) { - return array( 'error' => __( 'Missing dest.', 'mainwp-child' ) ); - } - - $backupfile = $_POST['settings']['backupfile']; - $dest = $_POST['settings']['dest']; - - list( $dest_id, $dest_name ) = explode( '_', $dest ); - - $dest_class = \BackWPup::get_destination( $dest_name ); - - if ( is_null( $dest_class ) ) { - return array( 'error' => __( 'Invalid dest class.', 'mainwp-child' ) ); - } - - $files = $dest_class->file_get_list( $dest ); - - foreach ( $files as $file ) { - if ( is_array( $file ) && $file['file'] == $backupfile ) { - $dest_class->file_delete( $dest, $backupfile ); - - return array( - 'success' => 1, - 'response' => 'DELETED', - ); - } - } - - return array( - 'success' => 1, - 'response' => 'Not found', - ); - } - - protected function view_log() { - if ( ! isset( $_POST['settings']['logfile'] ) ) { - return array( 'error' => __( 'Missing logfile.', 'mainwp-child' ) ); - } - - $log_folder = get_site_option( 'backwpup_cfg_logfolder' ); - $log_folder = \BackWPup_File::get_absolute_path( $log_folder ); - $log_file = $log_folder . basename( $_POST['settings']['logfile'] ); - - if ( ! is_readable( $log_file ) && ! is_readable( $log_file . '.gz' ) && ! is_readable( $log_file . '.bz2' ) ) { - $output = __( 'Log file doesn\'t exists', 'mainwp-child' ); - } else { - if ( ! file_exists( $log_file ) && file_exists( $log_file . '.gz' ) ) { - $log_file = $log_file . '.gz'; - } - - if ( ! file_exists( $log_file ) && file_exists( $log_file . '.bz2' ) ) { - $log_file = $log_file . '.bz2'; - } - - if ( '.gz' == substr( $log_file, - 3 ) ) { - $output = file_get_contents( 'compress.zlib://' . $log_file, false ); - } else { - $output = file_get_contents( $log_file, false ); - } - } - - return array( - 'success' => 1, - 'response' => $output, - ); - } - - protected function tables() { - if ( ! isset( $_POST['settings']['type'] ) ) { - return array( 'error' => __( 'Missing type.', 'mainwp-child' ) ); - } - - if ( ! isset( $_POST['settings']['website_id'] ) ) { - return array( 'error' => __( 'Missing website id.', 'mainwp-child' ) ); - } - - $type = $_POST['settings']['type']; - $website_id = $_POST['settings']['website_id']; - - $this->wp_list_table_dependency(); - - $array = array(); - - switch ( $type ) { - case 'logs': - $log_folder = get_site_option( 'backwpup_cfg_logfolder' ); - $log_folder = \BackWPup_File::get_absolute_path( $log_folder ); - $log_folder = untrailingslashit( $log_folder ); - - if ( ! is_dir( $log_folder ) ) { - return array( - 'success' => 1, - 'response' => $array, - ); - } - update_user_option( get_current_user_id(), 'backwpuplogs_per_page', 99999999 ); - $output = new \BackWPup_Page_Logs(); - $output->prepare_items(); - break; - - case 'backups': - update_user_option( get_current_user_id(), 'backwpupbackups_per_page', 99999999 ); - $output = new \BackWPup_Page_Backups(); - $output->items = array(); - - $jobids = \BackWPup_Option::get_job_ids(); - - if ( ! empty( $jobids ) ) { - foreach ( $jobids as $jobid ) { - if ( \BackWPup_Option::get( $jobid, 'backuptype' ) == 'sync' ) { - continue; - } - - $dests = \Option::get( $jobid, 'destinations' ); - foreach ( $dests as $dest ) { - $dest_class = \BackWPup::get_destination( $dest ); - if ( is_null( $dest_class ) ) { - continue; - } - $items = $dest_class->file_get_list( $jobid . '_' . $dest ); - if ( ! empty( $items ) ) { - foreach ( $items as $item ) { - $temp_single_item = $item; - $temp_single_item['dest'] = $jobid . '_' . $dest; - $temp_single_item['timeloc'] = sprintf( __( '%1$s at %2$s', 'mainwp-child' ), date_i18n( get_option( 'date_format' ), $temp_single_item['time'], true ), date_i18n( get_option( 'time_format' ), $temp_single_item['time'], true ) ); - $output->items[] = $temp_single_item; - } - } - } - } - } - - break; - - case 'jobs': - $output = new \BackWPup_Page_Jobs(); - $output->prepare_items(); - break; - } - - if ( is_array( $output->items ) ) { - if ( 'jobs' == $type ) { - foreach ( $output->items as $key => $val ) { - $temp_array = array(); - $temp_array['id'] = $val; - $temp_array['name'] = \BackWPup_Option::get( $val, 'name' ); - $temp_array['type'] = \BackWPup_Option::get( $val, 'type' ); - $temp_array['destinations'] = \BackWPup_Option::get( $val, 'destinations' ); - - if ( $this->is_backwpup_pro ) { - $temp_array['export'] = str_replace( '&', '&', wp_nonce_url( network_admin_url( 'admin.php' ) . '?page=backwpupjobs&action=export&jobs[]=' . $val, 'bulk-jobs' ) ); - } - - if ( \BackWPup_Option::get( $val, 'activetype' ) == 'wpcron' ) { - $nextrun = wp_next_scheduled( 'backwpup_cron', array( 'id' => $val ) ); - if ( $nextrun + ( get_option( 'gmt_offset' ) * 3600 ) ) { - $temp_array['nextrun'] = sprintf( __( '%1$s at %2$s by WP-Cron', 'mainwp-child' ), date_i18n( get_option( 'date_format' ), $nextrun, true ), date_i18n( get_option( 'time_format' ), $nextrun, true ) ); - } else { - $temp_array['nextrun'] = __( 'Not scheduled!', 'mainwp-child' ); - } - } else { - $temp_array['nextrun'] = __( 'Inactive', 'mainwp-child' ); - } - if ( \BackWPup_Option::get( $val, 'lastrun' ) ) { - $lastrun = \BackWPup_Option::get( $val, 'lastrun' ); - $temp_array['lastrun'] = sprintf( __( '%1$s at %2$s', 'mainwp-child' ), date_i18n( get_option( 'date_format' ), $lastrun, true ), date_i18n( get_option( 'time_format' ), $lastrun, true ) ); - if ( \BackWPup_Option::get( $val, 'lastruntime' ) ) { - $temp_array['lastrun'] .= ' ' . sprintf( __( 'Runtime: %d seconds', 'mainwp-child' ), \BackWPup_Option::get( $val, 'lastruntime' ) ); - } - } else { - $temp_array['lastrun'] = __( 'not yet', 'mainwp-child' ); - } - - $temp_array['website_id'] = $website_id; - $array[] = $temp_array; - } - } elseif ( 'backups' == $type ) { - $without_dupes = array(); - foreach ( $output->items as $key ) { - $temp_array = $key; - $temp_array['downloadurl'] = str_replace( - array( - '&', - network_admin_url( 'admin.php' ) . '?page=backwpupbackups&action=', - ), - array( - '&', - admin_url( 'admin-ajax.php' ) . '?action=mainwp_backwpup_download_backup&type=', - ), - $temp_array['downloadurl'] . '&_wpnonce=' . $this->create_nonce_without_session( 'mainwp_download_backup' ) - ); - - $temp_array['downloadurl_id'] = '/wp-admin/admin.php?page=backwpupbackups'; - if ( preg_match( '/.*&jobid=([^&]+)&.*/is', $temp_array['downloadurl'], $matches ) ) { - if ( ! empty( $matches[1] ) && is_numeric( $matches[1] ) ) { - $temp_array['downloadurl_id'] .= '&download_click_id=' . $matches[1]; - } - } - - $temp_array['website_id'] = $website_id; - - if ( ! isset( $without_dupes[ $temp_array['file'] ] ) ) { - $array[] = $temp_array; - $without_dupes[ $temp_array['file'] ] = 1; - } - } - } else { - foreach ( $output->items as $key => $val ) { - $array[] = $val; - } - } - } - - return array( - 'success' => 1, - 'response' => $array, - ); - } - - public function init_download_backup() { - if ( ! isset( $_GET['page'] ) || 'backwpupbackups' !== $_GET['page'] || ! isset( $_GET['download_click_id'] ) || empty( $_GET['download_click_id'] ) ) { - return; - } - ?> - - verify_nonce_without_session( $_GET['_wpnonce'], 'mainwp_download_backup' ) ) { - die( '-3' ); - } - - $dest = strtoupper( str_replace( 'download', '', $_GET['type'] ) ); - if ( ! empty( $dest ) && strstr( $_GET['type'], 'download' ) ) { - $dest_class = \BackWPup::get_destination( $dest ); - if ( is_null( $dest_class ) ) { - die( '-4' ); - } - - $dest_class->file_download( (int) $_GET['jobid'], $_GET['file'] ); - } else { - die( '-5' ); - } - - die(); - } - - protected function create_nonce_without_session( $action = - 1 ) { - $user = wp_get_current_user(); - $uid = (int) $user->ID; - if ( ! $uid ) { - $uid = apply_filters( 'nonce_user_logged_out', $uid, $action ); - } - - $i = wp_nonce_tick(); - - return substr( wp_hash( $i . '|' . $action . '|' . $uid, 'nonce' ), - 12, 10 ); - } - - protected function verify_nonce_without_session( $nonce, $action = - 1 ) { - $nonce = (string) $nonce; - $user = wp_get_current_user(); - $uid = (int) $user->ID; - if ( ! $uid ) { - $uid = apply_filters( 'nonce_user_logged_out', $uid, $action ); - } - - if ( empty( $nonce ) ) { - return false; - } - - $i = wp_nonce_tick(); - - $expected = substr( wp_hash( $i . '|' . $action . '|' . $uid, 'nonce' ), - 12, 10 ); - if ( hash_equals( $expected, $nonce ) ) { - return 1; - } - - $expected = substr( wp_hash( ( $i - 1 ) . '|' . $action . '|' . $uid, 'nonce' ), - 12, 10 ); - if ( hash_equals( $expected, $nonce ) ) { - return 2; - } - - return false; - } - - protected function ajax_working() { - - if ( ! isset( $_POST['settings'] ) || ! is_array( $_POST['settings'] ) || ! isset( $_POST['settings']['logfile'] ) || ! isset( $_POST['settings']['logpos'] ) ) { - return array( 'error' => __( 'Missing logfile or logpos.', 'mainwp-child' ) ); - } - - $_GET['logfile'] = $_POST['settings']['logfile']; - $_GET['logpos'] = $_POST['settings']['logpos']; - $_REQUEST['_wpnonce'] = wp_create_nonce( 'backwpupworking_ajax_nonce' ); - - $this->wp_list_table_dependency(); - - function mainwp_backwpup_wp_die_ajax_handler( $message ) { - return 'mainwp_backwpup_wp_die_ajax_handler'; - } - - // We do this in order to not die when using wp_die. - if ( ! defined( 'DOING_AJAX' ) ) { - define( 'DOING_AJAX', true ); - } - - add_filter( 'wp_die_ajax_handler', 'mainwp_backwpup_wp_die_ajax_handler' ); - remove_filter( 'wp_die_ajax_handler', '_ajax_wp_die_handler' ); - - ob_start(); - \BackWPup_Page_Jobs::ajax_working(); - - $output = ob_get_contents(); - - ob_end_clean(); - - return array( - 'success' => 1, - 'response' => $output, - ); - } - - protected function backup_now() { - - if ( ! isset( $_POST['settings']['job_id'] ) ) { - return array( 'error' => __( 'Missing job_id', 'mainwp-child' ) ); - } - - // Simulate http://wp/wp-admin/admin.php?jobid=1&page=backwpupjobs&action=runnow. - $_GET['jobid'] = $_POST['settings']['job_id']; - - $_REQUEST['action'] = 'runnow'; - $_REQUEST['_wpnonce'] = wp_create_nonce( 'backwpup_job_run-runnowlink' ); - - update_site_option( 'backwpup_messages', array() ); - - $this->wp_list_table_dependency(); - - ob_start(); - \BackWPup_Page_Jobs::load(); - ob_end_clean(); - - $output = $this->check_backwpup_messages(); - - if ( isset( $output['error'] ) ) { - return array( 'error' => '\BackWPup_Page_Jobs::load fail: ' . $output['error'] ); - } else { - $job_object = \BackWPup_Job::get_working_data(); - if ( is_object( $job_object ) ) { - return array( - 'success' => 1, - 'response' => $output['message'], - 'logfile' => basename( $job_object->logfile ), - ); - } else { - return array( - 'success' => 1, - 'response' => $output['message'], - ); - } - } - } - - protected function backup_abort() { - $_REQUEST['action'] = 'abort'; - $_REQUEST['_wpnonce'] = wp_create_nonce( 'abort-job' ); - - update_site_option( 'backwpup_messages', array() ); - - $this->wp_list_table_dependency(); - - ob_start(); - \BackWPup_Page_Jobs::load(); - ob_end_clean(); - - $output = $this->check_backwpup_messages(); - - if ( isset( $output['error'] ) ) { - return array( 'error' => 'Cannot abort: ' . $output['error'] ); - } else { - return array( - 'success' => 1, - 'response' => $output['message'], - ); - } - } - - protected function wp_list_table_dependency() { - if ( ! function_exists( 'convert_to_screen' ) ) { - // We need this because BackWPup_Page_Jobs extends WP_List_Table which uses convert_to_screen. - function convert_to_screen( $hook_name ) { - return new MainWP_Fake_Wp_Screen(); - } - } - - if ( ! function_exists( 'add_screen_option' ) ) { - function add_screen_option( $option, $args = array() ) { - } - } - - if ( ! class_exists( '\WP_List_Table' ) ) { - require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; - } - } - - protected function wizard_system_scan() { - if ( class_exists( '\BackWPup_Pro_Wizard_SystemTest' ) ) { - ob_start(); - - $system_test = new \BackWPup_Pro_Wizard_SystemTest(); - $system_test->execute( null ); - - $output = ob_get_contents(); - - ob_end_clean(); - - return array( - 'success' => 1, - 'response' => $output, - ); - } else { - return array( 'error' => 'Missing BackWPup_Pro_Wizard_SystemTest' ); - } - } - - protected function destination_email_check_email() { - $settings = $_POST['settings']; - - $message = ''; - - $emailmethod = ( isset( $settings['emailmethod'] ) ? $settings['emailmethod'] : '' ); - $emailsendmail = ( isset( $settings['emailsendmail'] ) ? $settings['emailsendmail'] : '' ); - $emailhost = ( isset( $settings['emailhost'] ) ? $settings['emailhost'] : '' ); - $emailhostport = ( isset( $settings['emailhostport'] ) ? $settings['emailhostport'] : '' ); - $emailsecure = ( isset( $settings['emailsecure'] ) ? $settings['emailsecure'] : '' ); - $emailuser = ( isset( $settings['emailuser'] ) ? $settings['emailuser'] : '' ); - $emailpass = ( isset( $settings['emailpass'] ) ? $settings['emailpass'] : '' ); - - if ( ! isset( $settings['emailaddress'] ) || strlen( $settings['emailaddress'] ) < 2 ) { - $message = __( 'Missing email address.', 'mainwp-child' ); - } else { - if ( $emailmethod ) { - global $phpmailer; - if ( ! is_object( $phpmailer ) || ! $phpmailer instanceof PHPMailer ) { - require_once ABSPATH . WPINC . '/class-phpmailer.php'; - require_once ABSPATH . WPINC . '/class-smtp.php'; - $phpmailer = new PHPMailer( true ); // phpcs:ignore -- to custom init PHP mailer - } - if ( is_object( $phpmailer ) ) { - do_action_ref_array( 'phpmailer_init', array( &$phpmailer ) ); - $emailmethod = $phpmailer->Mailer; - $emailsendmail = $phpmailer->Sendmail; - $emailhost = $phpmailer->Host; - $emailhostport = $phpmailer->Port; - $emailsecure = $phpmailer->SMTPSecure; - $emailuser = $phpmailer->Username; - $emailpass = $phpmailer->Password; - } - } - - if ( ! class_exists( '\Swift', false ) ) { - require \BackWPup::get_plugin_data( 'plugindir' ) . '/vendor/SwiftMailer/swift_required.php'; - } - - if ( function_exists( 'mb_internal_encoding' ) && ( (int) ini_get( 'mbstring.func_overload' ) ) & 2 ) { - $mbEncoding = mb_internal_encoding(); - mb_internal_encoding( 'ASCII' ); - } - - try { - // Create the Transport. - if ( 'smtp' == $emailmethod ) { - $transport = Swift_SmtpTransport::newInstance( $emailhost, $emailhostport ); - $transport->setUsername( $emailuser ); - $transport->setPassword( $emailpass ); - if ( 'ssl' == $emailsecure ) { - $transport->setEncryption( 'ssl' ); - } - if ( 'tls' == $emailsecure ) { - $transport->setEncryption( 'tls' ); - } - } elseif ( 'sendmail' == $emailmethod ) { - $transport = Swift_SendmailTransport::newInstance( $emailsendmail ); - } else { - $transport = Swift_MailTransport::newInstance(); - } - $emailer = Swift_Mailer::newInstance( $transport ); - - $message = Swift_Message::newInstance( __( 'BackWPup archive sending TEST Message', 'mainwp-child' ) ); - $message->setFrom( array( ( isset( $settings['emailsndemail'] ) ? $settings['emailsndemail'] : 'from@example.com' ) => isset( $settings['emailsndemailname'] ) ? $settings['emailsndemailname'] : '' ) ); - $message->setTo( array( $settings['emailaddress'] ) ); - $message->setBody( __( 'If this message reaches your inbox, sending backup archives via email should work for you.', 'mainwp-child' ) ); - - $result = $emailer->send( $message ); - } catch ( \Exception $e ) { - $message = 'Swift Mailer: ' . $e->getMessage(); - } - - if ( isset( $mbEncoding ) ) { - mb_internal_encoding( $mbEncoding ); - } - - if ( ! isset( $result ) || ! $result ) { - $message = __( 'Error while sending email!', 'mainwp-child' ); - } else { - $message = __( 'Email sent.', 'mainwp-child' ); - } - } - - return array( - 'success' => 1, - 'message' => $message, - ); - } - - protected function get_job_files() { - // From BackWPup_JobType_File::get_exclude_dirs. - function mainwp_backwpup_get_exclude_dirs( $folder ) { - $folder = trailingslashit( str_replace( '\\', '/', realpath( $folder ) ) ); - $exclude_dir_array = array(); - - if ( false !== strpos( trailingslashit( str_replace( '\\', '/', realpath( ABSPATH ) ) ), $folder ) && trailingslashit( str_replace( '\\', '/', realpath( ABSPATH ) ) ) != $folder ) { - $exclude_dir_array[] = trailingslashit( str_replace( '\\', '/', realpath( ABSPATH ) ) ); - } - if ( false !== strpos( trailingslashit( str_replace( '\\', '/', realpath( WP_CONTENT_DIR ) ) ), $folder ) && trailingslashit( str_replace( '\\', '/', realpath( WP_CONTENT_DIR ) ) ) != $folder ) { - $exclude_dir_array[] = trailingslashit( str_replace( '\\', '/', realpath( WP_CONTENT_DIR ) ) ); - } - if ( false !== strpos( trailingslashit( str_replace( '\\', '/', realpath( WP_PLUGIN_DIR ) ) ), $folder ) && trailingslashit( str_replace( '\\', '/', realpath( WP_PLUGIN_DIR ) ) ) != $folder ) { - $exclude_dir_array[] = trailingslashit( str_replace( '\\', '/', realpath( WP_PLUGIN_DIR ) ) ); - } - if ( false !== strpos( trailingslashit( str_replace( '\\', '/', realpath( get_theme_root() ) ) ), $folder ) && trailingslashit( str_replace( '\\', '/', realpath( get_theme_root() ) ) ) != $folder ) { - $exclude_dir_array[] = trailingslashit( str_replace( '\\', '/', realpath( get_theme_root() ) ) ); - } - if ( false !== strpos( trailingslashit( str_replace( '\\', '/', realpath( \BackWPup_File::get_upload_dir() ) ) ), $folder ) && trailingslashit( str_replace( '\\', '/', realpath( \BackWPup_File::get_upload_dir() ) ) ) != $folder ) { - $exclude_dir_array[] = trailingslashit( str_replace( '\\', '/', realpath( \BackWPup_File::get_upload_dir() ) ) ); - } - - return array_unique( $exclude_dir_array ); - } - - $return = array(); - - $folders = array( - 'abs' => ABSPATH, - 'content' => WP_CONTENT_DIR, - 'plugin' => WP_PLUGIN_DIR, - 'theme' => get_theme_root(), - 'upload' => \BackWPup_File::get_upload_dir(), - ); - - foreach ( $folders as $key => $folder ) { - $return_temp = array(); - $main_folder_name = realpath( $folder ); - - if ( $main_folder_name ) { - $main_folder_name = untrailingslashit( str_replace( '\\', '/', $main_folder_name ) ); - $main_folder_size = '(' . size_format( \BackWPup_File::get_folder_size( $main_folder_name, false ), 2 ) . ')'; - - $dir = opendir( $main_folder_name ); - if ( $dir ) { - while ( false !== ( $file = readdir( $dir ) ) ) { - if ( ! in_array( $file, array( '.', '..' ) ) && is_dir( $main_folder_name . '/' . $file ) && ! in_array( trailingslashit( $main_folder_name . '/' . $file ), mainwp_backwpup_get_exclude_dirs( $main_folder_name ) ) ) { - $folder_size = ' (' . size_format( \BackWPup_File::get_folder_size( $main_folder_name . '/' . $file ), 2 ) . ')'; - $return_temp[] = array( - 'size' => $folder_size, - 'name' => $file, - ); - - } - } - - closedir( $dir ); - } - - $return[ $key ] = array( - 'size' => $main_folder_size, - 'name' => $folder, - 'folders' => $return_temp, - ); - } - } - - return array( - 'success' => 1, - 'folders' => $return, - ); - } - - protected function get_child_tables() { - global $wpdb; - - $return = array(); - - $settings = $_POST['settings']; - - if ( ! empty( $settings['dbhost'] ) && ! empty( $settings['dbuser'] ) ) { - $mysqli = new mysqli( $settings['dbhost'], $settings['dbuser'], ( isset( $settings['dbpassword'] ) ? $settings['dbpassword'] : '' ) ); // phpcs:ignore -- third party code. - - if ( $mysqli->connect_error ) { - $return['message'] = $mysqli->connect_error; - } else { - if ( ! empty( $settings['dbname'] ) ) { - $res = $mysqli->query( 'SHOW FULL TABLES FROM `' . $mysqli->real_escape_string( $settings['dbname'] ) . '`' ); - if ( $res ) { - $tables_temp = array(); - while ( $table = $res->fetch_array( MYSQLI_NUM ) ) { // phpcs:ignore -- third party code. - $tables_temp[] = $table[0]; - } - - $res->close(); - $return['tables'] = $tables_temp; - } - } - - if ( empty( $settings['dbname'] ) || ! empty( $settings['first'] ) ) { - $res = $mysqli->query( 'SHOW DATABASES' ); - if ( $res ) { - $databases_temp = array(); - while ( $db = $res->fetch_array() ) { - $databases_temp[] = $db['Database']; - } - - $res->close(); - $return['databases'] = $databases_temp; - } - } - } - $mysqli->close(); - } else { - $tables_temp = array(); - - $tables = $wpdb->get_results( 'SHOW FULL TABLES FROM `' . DB_NAME . '`', ARRAY_N ); // phpcs:ignore -- safe query. - foreach ( $tables as $table ) { - $tables_temp[] = $table[0]; - } - - $return['tables'] = $tables_temp; - } - - if ( isset( $settings['job_id'] ) ) { - $return['dbdumpexclude'] = \BackWPup_Option::get( $settings['job_id'], 'dbdumpexclude' ); - } - return array( - 'success' => 1, - 'return' => $return, - ); - } - - protected function insert_or_update_jobs_global() { - $settings = $_POST['settings']; - - if ( ! is_array( $settings ) ) { - return array( 'error' => __( 'Missing array settings', 'mainwp-child' ) ); - } - - if ( ! isset( $settings['job_id'] ) ) { - return array( 'error' => __( 'Missing job_id', 'mainwp-child' ) ); - } - - if ( $settings['job_id'] > 0 ) { - $new_job_id = intval( $settings['job_id'] ); - } else { - $new_job_id = null; - } - - $changes_array = array(); - $message_array = array(); - - foreach ( $settings['value'] as $key => $val ) { - $temp_array = array(); - $temp_array['tab'] = $key; - $temp_array['value'] = $val; - if ( ! is_null( $new_job_id ) ) { - $temp_array['job_id'] = $new_job_id; - } else { - $temp_array['job_id'] = $settings['job_id']; - } - - $_POST['settings'] = $temp_array; - $return = $this->insert_or_update_jobs(); - - if ( is_null( $new_job_id ) ) { - if ( ! isset( $return['job_id'] ) ) { - return array( 'error' => __( 'Missing new job_id', 'mainwp-child' ) ); - } - - $new_job_id = $return['job_id']; - } - - // We want to exit gracefully. - if ( isset( $return['error_message'] ) ) { - $message_array[ $return['error_message'] ] = 1; - } - - if ( isset( $return['changes'] ) ) { - $changes_array = array_merge( $changes_array, $return['changes'] ); - } - - if ( isset( $return['message'] ) ) { - foreach ( $return['message'] as $message ) { - if ( ! isset( $message_array[ $message ] ) ) { - $message_array[ $message ] = 1; - } - } - } - } - - return array( - 'success' => 1, - 'job_id' => $new_job_id, - 'changes' => $changes_array, - 'message' => array_keys( $message_array ), - ); - } - - // From BackWPup_JobType_File::edit_form_post_save with some tweaks. - public function edit_form_post_save( $post_data, $id ) { - // Parse and save files to exclude. - $exclude_input = $post_data['fileexclude']; - $to_exclude_list = $exclude_input ? str_replace( array( "\r\n", "\r" ), ',', $exclude_input ) : array(); - if ( $to_exclude_list ) { - $to_exclude_list = sanitize_text_field( stripslashes( $to_exclude_list ) ); - } - $to_exclude = $to_exclude_list ? explode( ',', $to_exclude_list ) : array(); - $to_exclude_parsed = array(); - foreach ( $to_exclude as $key => $value ) { - $normalized = wp_normalize_path( trim( $value ) ); - if ( $normalized ) { - $to_exclude_parsed[ $key ] = $normalized; - } - } - sort( $to_exclude_parsed ); - \BackWPup_Option::update( $id, 'fileexclude', implode( ',', $to_exclude_parsed ) ); - unset( $exclude_input, $to_exclude_list, $to_exclude, $to_exclude_parsed, $normalized ); - - // Parse and save folders to include. - $include_input = $post_data['dirinclude']; - $include_list = $include_input ? str_replace( array( "\r\n", "\r" ), ',', $include_input ) : array(); - $to_include = $include_list ? explode( ',', $include_list ) : array(); - $to_include_parsed = array(); - foreach ( $to_include as $key => $value ) { - $normalized = trailingslashit( wp_normalize_path( trim( $value ) ) ); - if ( $normalized ) { - $normalized = filter_var( $normalized, FILTER_SANITIZE_URL ); - } - $realpath = $normalized && '/' !== $normalized ? realpath( $normalized ) : false; - if ( $realpath ) { - $to_include_parsed[ $key ] = $realpath; - } - } - sort( $to_include_parsed ); - \BackWPup_Option::update( $id, 'dirinclude', implode( ',', $to_include_parsed ) ); - unset( $include_input, $include_list, $to_include, $to_include_parsed, $normalized, $realpath ); - - // Parse and save boolean fields. - $boolean_fields_def = array( - 'backupexcludethumbs' => FILTER_VALIDATE_BOOLEAN, - 'backupspecialfiles' => FILTER_VALIDATE_BOOLEAN, - 'backuproot' => FILTER_VALIDATE_BOOLEAN, - 'backupabsfolderup' => FILTER_VALIDATE_BOOLEAN, - 'backupcontent' => FILTER_VALIDATE_BOOLEAN, - 'backupplugins' => FILTER_VALIDATE_BOOLEAN, - 'backupthemes' => FILTER_VALIDATE_BOOLEAN, - 'backupuploads' => FILTER_VALIDATE_BOOLEAN, - ); - - foreach ( $boolean_fields_def as $key => $value ) { - \BackWPup_Option::update( $id, $key, ! empty( $post_data[ $key ] ) ); - } - // Parse and save directories to exclude. - $exclude_dirs_def = array( - 'backuprootexcludedirs' => array( - 'filter' => FILTER_SANITIZE_URL, - 'flags' => FILTER_FORCE_ARRAY, - ), - 'backuppluginsexcludedirs' => array( - 'filter' => FILTER_SANITIZE_URL, - 'flags' => FILTER_FORCE_ARRAY, - ), - 'backupcontentexcludedirs' => array( - 'filter' => FILTER_SANITIZE_URL, - 'flags' => FILTER_FORCE_ARRAY, - ), - 'backupthemesexcludedirs' => array( - 'filter' => FILTER_SANITIZE_URL, - 'flags' => FILTER_FORCE_ARRAY, - ), - 'backupuploadsexcludedirs' => array( - 'filter' => FILTER_SANITIZE_URL, - 'flags' => FILTER_FORCE_ARRAY, - ), - ); - foreach ( $exclude_dirs_def as $key => $filter ) { - $value = ! empty( $post_data[ $key ] ) && is_array( $post_data[ $key ] ) ? $post_data[ $key ] : array(); - \BackWPup_Option::update( $id, $key, $value ); - } - } - - protected function insert_or_update_jobs() { - - $settings = $_POST['settings']; - - if ( ! is_array( $settings ) || ! isset( $settings['value'] ) ) { - return array( 'error' => __( 'Missing array settings', 'mainwp-child' ) ); - } - - if ( ! isset( $settings['tab'] ) ) { - return array( 'error' => __( 'Missing tab', 'mainwp-child' ) ); - } - - if ( ! isset( $settings['job_id'] ) ) { - return array( 'error' => __( 'Missing job_id', 'mainwp-child' ) ); - } - - if ( ! class_exists( '\BackWPup' ) ) { - return array( 'error' => __( 'Install BackWPup on child website', 'mainwp-child' ) ); - } - - if ( $settings['job_id'] > 0 ) { - $job_id = intval( $settings['job_id'] ); - } else { - // generate jobid if not exists. - $newjobid = \BackWPup_Option::get_job_ids(); - sort( $newjobid ); - $job_id = end( $newjobid ) + 1; - } - - update_site_option( 'backwpup_messages', array() ); - - if ( isset( $settings['value']['backupdir'] ) && empty( $settings['value']['backupdir'] ) ) { - $backupdir = \BackWPup_Option::get( (int) $job_id, 'backupdir' ); - if ( ! empty( $backupdir ) ) { - $settings['value']['backupdir'] = $backupdir; - } - } - - foreach ( $settings['value'] as $key => $val ) { - $_POST[ $key ] = $val; - } - - if ( 'jobtype-FILE' == $settings['tab'] ) { - $this->edit_form_post_save( $settings['value'], $job_id ); - $messages = \BackWPup_Admin::get_messages(); - if ( empty( $messages['error'] ) ) { - $url = \BackWPup_Job::get_jobrun_url( 'runnowlink', $job_id ); - \BackWPup_Admin::message( sprintf( __( 'Changes for job %s saved.', 'mainwp-child' ), \BackWPup_Option::get( $job_id, 'name' ) ) . ' ' . __( 'Jobs overview', 'mainwp-child' ) . ' | ' . __( 'Run now', 'mainwp-child' ) . '' ); - } - } elseif ( 'dest-DROPBOX' == $settings['tab'] ) { - unset( $settings['value'] ); - \BackWPup_Page_Editjob::save_post_form( $settings['tab'], $job_id ); - } else { - \BackWPup_Page_Editjob::save_post_form( $settings['tab'], $job_id ); - } - - $return = $this->check_backwpup_messages(); - - if ( isset( $return['error'] ) ) { - return array( - 'success' => 1, - 'error_message' => __( 'Cannot save jobs: ' . $return['error'], 'mainwp-child' ), - ); - } - - if ( isset( $settings['value']['sugarrefreshtoken'] ) ) { - \BackWPup_Option::update( $job_id, 'sugarrefreshtoken', $settings['value']['sugarrefreshtoken'] ); - } - - if ( isset( $settings['value']['gdriverefreshtoken'] ) ) { - \BackWPup_Option::update( $job_id, 'gdriverefreshtoken', $settings['value']['gdriverefreshtoken'] ); - } - - if ( isset( $settings['value']['dbdumpspecialsetalltables'] ) && $settings['value']['dbdumpspecialsetalltables'] ) { - \BackWPup_Option::update( $job_id, 'dbdumpexclude', array() ); - } - - if ( isset( $settings['value']['dropboxtoken'] ) && isset( $settings['value']['dropboxroot'] ) ) { - \BackWPup_Option::update( $job_id, 'dropboxtoken', $settings['value']['dropboxtoken'] ); - \Option::update( $job_id, 'dropboxroot', $settings['value']['dropboxroot'] ); - } - - $changes_array = array(); - - foreach ( $settings['value'] as $key => $val ) { - $temp_value = \BackWPup_Option::get( $job_id, $key ); - if ( is_string( $temp_value ) ) { - if ( isset( $this->exclusions[ $settings['tab'] ] ) ) { - if ( ! in_array( $key, $this->exclusions[ $settings['tab'] ] ) && strcmp( $temp_value, $val ) != 0 ) { - $changes_array[ $key ] = $temp_value; - } - } elseif ( strcmp( $temp_value, $val ) != 0 ) { - $changes_array[ $key ] = $temp_value; - } - } - } - - return array( - 'success' => 1, - 'job_id' => $job_id, - 'changes' => $changes_array, - 'message' => $return['message'], - ); - } - - - protected function update_settings() { - $settings = $_POST['settings']; - - if ( ! is_array( $settings ) || ! isset( $settings['value'] ) ) { - return array( 'error' => __( 'Missing array settings', 'mainwp-child' ) ); - } - - if ( ! class_exists( '\BackWPup' ) ) { - return array( 'error' => __( 'Install BackWPup on child website', 'mainwp-child' ) ); - } - - if ( isset( $settings['value']['is_premium'] ) && 1 == $settings['value']['is_premium'] && false == $this->is_backwpup_pro ) { - return array( 'error' => __( 'You try to use pro version settings in non pro plugin version. Please install pro version on child and try again.', 'mainwp-child' ) ); - } - - foreach ( $settings['value'] as $key => $val ) { - $_POST[ $key ] = $val; - } - - update_site_option( 'backwpup_messages', array() ); - - $settings_views = array(); - $settings_updaters = array(); - - $backwpup = new \BackWPup_Page_Settings( $settings_views, $settings_updaters ); - $backwpup->save_post_form(); - - if ( class_exists( '\BackWPup_Pro' ) ) { - $pro_settings = \BackWPup_Pro_Settings_APIKeys::get_instance(); - $pro_settings->save_form(); - - } - $return = $this->check_backwpup_messages(); - - if ( isset( $return['error'] ) ) { - return array( 'error' => __( 'Cannot save settings: ' . $return['error'], 'mainwp-child' ) ); - } - - $exclusions = array( - 'is_premium', - 'dropboxappsecret', - 'dropboxsandboxappsecret', - 'sugarsyncsecret', - 'googleclientsecret', - 'override', - 'httpauthpassword', - ); - - $changes_array = array(); - - foreach ( $settings['value'] as $key => $val ) { - - $temp_value = get_site_option( 'backwpup_cfg_' . $key, '' ); - if ( ! in_array( $key, $exclusions ) && strcmp( $temp_value, $val ) != 0 ) { - $changes_array[ $key ] = $temp_value; - } - } - - return array( - 'success' => 1, - 'changes' => $changes_array, - 'message' => $return['message'], - ); - } - - protected function check_backwpup_messages() { - $message = get_site_option( 'backwpup_messages', array() ); - update_site_option( 'backwpup_messages', array() ); - - if ( isset( $message['error'] ) ) { - return array( 'error' => implode( ', ', $message['error'] ) ); - } elseif ( isset( $message['updated'] ) ) { - return array( 'message' => $message['updated'] ); - } else { - return array( 'error' => 'Generic error' ); - } - } + + /** + * @var bool Whether or not BackWPup plugin is installed. Default: false. + */ + public $is_backwpup_installed = false; + + /** + * @var bool Whether or not BackWPup is Pro version. Default: false. + */ + public $is_backwpup_pro = false; + + /** + * @var string Plugin slug translation string. + */ + public $plugin_translate = 'mainwp-backwpup-extension'; + + /** + * @static + * @var null Holds the Public static instance of MainWP_Child_Back_WP_Up + */ + public static $instance = null; + + /** @var string Software version. */ + protected $software_version = '0.1'; + + /** @var array Returned response array for MainWP BackWPup Extension actions. */ + public static $information = array(); + + /** @var string[][] backwpup_cfg variables. */ + protected $exclusions = array( + 'cron' => array( + 'cronminutes', + 'cronhours', + 'cronmday', + 'cronmon', + 'cronwday', + 'moncronminutes', + 'moncronhours', + 'moncronmday', + 'weekcronminutes', + 'weekcronhours', + 'weekcronwday', + 'daycronminutes', + 'daycronhours', + 'hourcronminutes', + 'cronbtype', + ), + 'dest-EMAIL' => array( 'emailpass' ), + 'dest-DBDUMP' => array( 'dbdumpspecialsetalltables' ), + 'dest-FTP' => array( 'ftppass' ), + 'dest-S3' => array( 's3secretkey' ), + 'dest-MSAZURE' => array( 'msazurekey' ), + 'dest-SUGARSYNC' => array( 'sugaremail', 'sugarpass', 'sugarrefreshtoken' ), + 'dest-GDRIVE' => array( 'gdriverefreshtoken' ), + 'dest-RSC' => array( 'rscapikey' ), + 'dest-GLACIER' => array( 'glaciersecretkey' ), + ); + + /** + * Create a public static instance of MainWP_Child_Back_WP_Up. + * + * @return MainWP_Child_Back_WP_Up|null + */ + public static function instance() { + if ( null == self::$instance ) { + self::$instance = new self(); + } + + return self::$instance; + } + + /** + * MainWP_Child_Back_WP_Up constructor. + * + * @uses MainWP_Helper::check_files_exists() + * @uses MainWP_Helper::check_classes_exists() + * @uses MainWP_Helper::check_methods() + * @uses \BackWPup::get_instance() + * @uses \Exception + */ + 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'; + + if ( ! file_exists( $file_path2 ) ) { + $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; + } elseif ( 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 ( $this->is_backwpup_installed ) { + MainWP_Helper::check_classes_exists( '\BackWPup' ); + MainWP_Helper::check_methods( 'get_instance' ); + \BackWPup::get_instance(); + + add_action( 'admin_init', array( $this, 'init_download_backup' ) ); + add_filter( 'mainwp_site_sync_others_data', array( $this, 'sync_others_data' ), 10, 2 ); + } + } catch ( \Exception $e ) { + $this->is_backwpup_installed = false; + } + } + + /** + * MainWP BackWPup fatal error handler. + * + * @uses MainWP_Child_Back_WP_Up::$information + * @uses MainWP_Helper::write() + */ + function mainwp_backwpup_handle_fatal_error() { + + $error = error_get_last(); + $info = self::$information; + + if ( isset( $error['type'] ) && E_ERROR === $error['type'] && isset( $error['message'] ) ) { + MainWP_Helper::write( array( 'error' => 'MainWP_Child fatal error : ' . $error['message'] . ' Line: ' . $error['line'] . ' File: ' . $error['file'] ) ); + } elseif ( ! empty( $info ) ) { + MainWP_Helper::write( self::$information ); + } else { + MainWP_Helper::write( array( 'error' => 'Missing information array inside fatal_error' ) ); + } + } + + /** + * MainWP BackWPup Extension actions. + * + * @uses MainWP_Child_Back_WP_Up::update_settings() + * @uses MainWP_Child_Back_WP_Up::insert_or_update_jobs() + * @uses MainWP_Child_Back_WP_Up::insert_or_update_jobs_global() + * @uses MainWP_Child_Back_WP_Up::get_child_tables() + * @uses MainWP_Child_Back_WP_Up::get_job_files() + * @uses MainWP_Child_Back_WP_Up::destination_email_check_email() + * @uses MainWP_Child_Back_WP_Up::backup_now() + * @uses MainWP_Child_Back_WP_Up::ajax_working() + * @uses MainWP_Child_Back_WP_Up::backup_abort() + * @uses MainWP_Child_Back_WP_Up::tables() + * @uses MainWP_Child_Back_WP_Up::view_log() + * @uses MainWP_Child_Back_WP_Up::delete_log() + * @uses MainWP_Child_Back_WP_Up::delete_job() + * @uses MainWP_Child_Back_WP_Up::delete_backup() + * @uses MainWP_Child_Back_WP_Up::wizard_system_scan() + * @uses MainWP_Child_Back_WP_Up::is_backwpup_pro() + * @uses MainWP_Child_Back_WP_Up::show_hide() + * @uses MainWP_Child_Back_WP_Up::$information + */ + public function action() { + if ( ! $this->is_backwpup_installed ) { + MainWP_Helper::write( array( 'error' => __( 'Please install BackWPup plugin on child website', 'mainwp-child' ) ) ); + return; + } + register_shutdown_function( 'self::mainwp_backwpup_handle_fatal_error' ); + + $information = array(); + + if ( ! isset( $_POST['action'] ) ) { + $information = array( 'error' => __( 'Missing action.', 'mainwp-child' ) ); + } else { + + switch ( $_POST['action'] ) { + case 'backwpup_update_settings': + $information = $this->update_settings(); + break; + + case 'backwpup_insert_or_update_jobs': + $information = $this->insert_or_update_jobs(); + break; + + case 'backwpup_insert_or_update_jobs_global': + $information = $this->insert_or_update_jobs_global(); + break; + + case 'backwpup_get_child_tables': + $information = $this->get_child_tables(); + break; + + case 'backwpup_get_job_files': + $information = $this->get_job_files(); + break; + + case 'backwpup_destination_email_check_email': + $information = $this->destination_email_check_email(); + break; + + case 'backwpup_backup_now': + $information = $this->backup_now(); + break; + + case 'backwpup_ajax_working': + $information = $this->ajax_working(); + break; + + case 'backwpup_backup_abort': + $information = $this->backup_abort(); + break; + + case 'backwpup_tables': + $information = $this->tables(); + break; + + case 'backwpup_view_log': + $information = $this->view_log(); + break; + + case 'backwpup_delete_log': + $information = $this->delete_log(); + break; + + case 'backwpup_delete_job': + $information = $this->delete_job(); + break; + + case 'backwpup_delete_backup': + $information = $this->delete_backup(); + break; + + case 'backwpup_information': + $information = $this->information(); + break; + + case 'backwpup_wizard_system_scan': + $information = $this->wizard_system_scan(); + break; + + case 'backwpup_is_pro': + $information = array( 'is_pro' => $this->is_backwpup_pro ); + break; + + case 'backwpup_show_hide': + $information = $this->show_hide(); + break; + + default: + $information = array( 'error' => __( 'Wrong action.', 'mainwp-child' ) ); + } + } + + self::$information = $information; + exit(); + } + + /** + * MainWP BackWPup Extension initiation. + */ + public function init() { + + if ( ! $this->is_backwpup_installed ) { + return; + } + + add_action( 'mainwp_child_site_stats', array( $this, 'do_site_stats' ) ); + + if ( get_option( 'mainwp_backwpup_hide_plugin' ) === 'hide' ) { + add_filter( 'all_plugins', array( $this, 'all_plugins' ) ); + add_action( 'admin_menu', array( $this, 'remove_menu' ) ); + } + } + + /** + * Record BackWPup MainWP Child Reports log. + * + * @uses MainWP_Child_Back_WP_Up::do_reports_log() + */ + public function do_site_stats() { + if ( has_action( 'mainwp_child_reports_log' ) ) { + do_action( 'mainwp_child_reports_log', 'backwpup' ); + } else { + $this->do_reports_log( 'backwpup' ); + } + } + + /** + * Create BackWPup MainWP Client Reports log. + * + * @uses MainWP_Child_Back_WP_Up::is_backwpup_installed() + * @uses MainWP_Helper::check_classes_exists() + * @uses MainWP_Helper::check_methods() + * @uses \BackWPup_File::get_absolute_path() + * @uses \BackWPup_Job::read_logheader() + * @uses MainWP_Utility::update_lasttime_backup() + * @uses \Exception + * + * @param string $ext Extension to create log for. + */ + public function do_reports_log($ext = '' ) { + if ( 'backwpup' !== $ext ) { + return; + } + if ( ! $this->is_backwpup_installed ) { + return; + } + + try { + + MainWP_Helper::check_classes_exists( array( '\BackWPup_File', '\BackWPup_Job' ) ); + MainWP_Helper::check_methods( '\BackWPup_File', array( 'get_absolute_path' ) ); + MainWP_Helper::check_methods( '\BackWPup_Job', array( 'read_logheader' ) ); + $lasttime_logged = MainWP_Utility::get_lasttime_backup( 'backwpup' ); + $log_folder = get_site_option( 'backwpup_cfg_logfolder' ); + $log_folder = \BackWPup_File::get_absolute_path( $log_folder ); + $log_folder = untrailingslashit( $log_folder ); + + $logfiles = array(); + $dir = opendir( $log_folder ); + if ( is_readable( $log_folder ) && $dir ) { + while ( ( $file = readdir( $dir ) ) !== false ) { + $log_file = $log_folder . '/' . $file; + if ( is_file( $log_file ) && is_readable( $log_file ) && false !== strpos( $file, 'backwpup_log_' ) && false !== strpos( $file, '.html' ) ) { + $logfiles[] = $file; + } + } + closedir( $dir ); + } + + $log_items = array(); + foreach ( $logfiles as $mtime => $logfile ) { + $meta = \BackWPup_Job::read_logheader( $log_folder . '/' . $logfile ); + if ( ! isset( $meta['logtime'] ) || $meta['logtime'] < $lasttime_logged ) { + continue; + } + + if ( isset( $meta['errors'] ) && ! empty( $meta['errors'] ) ) { + continue; + } + + $log_items[ $mtime ] = $meta; + $log_items[ $mtime ]['file'] = $logfile; + } + + if ( ! empty( $log_items ) ) { + $job_types = array( + 'DBDUMP' => __( 'Database backup', 'mainwp-child' ), + 'FILE' => __( 'File backup', 'mainwp-child' ), + 'WPEXP' => __( 'WordPress XML export', 'mainwp-child' ), + 'WPPLUGIN' => __( 'Installed plugins list', 'mainwp-child' ), + 'DBCHECK' => __( 'Check database tables', 'mainwp-child' ), + ); + + $new_lasttime_logged = $lasttime_logged; + + foreach ( $log_items as $log ) { + $backup_time = $log['logtime']; + if ( $backup_time < $lasttime_logged ) { + continue; + } + $job_job_types = explode( '+', $log['type'] ); + $backup_type = ''; + foreach ( $job_job_types as $typeid ) { + if ( isset( $job_types[ $typeid ] ) ) { + $backup_type .= ' + ' . $job_types[ $typeid ]; + } + } + + if ( empty( $backup_type ) ) { + continue; + } else { + $backup_type = ltrim( $backup_type, ' + ' ); + } + $message = 'BackWPup backup finished (' . $backup_type . ')'; + do_action( 'mainwp_reports_backwpup_backup', $message, $backup_type, $backup_time ); + + if ( $new_lasttime_logged < $backup_time ) { + $new_lasttime_logged = $backup_time; + } + } + + if ( $new_lasttime_logged > $lasttime_logged ) { + MainWP_Utility::update_lasttime_backup( 'backwpup', $new_lasttime_logged ); // to support backup before update feature. + } + } + } catch ( \Exception $ex ) { + // ok! + } + } + + /** + * Sync other data from $data[] and merge with $information[] + * + * @param array $information Returned response array for MainWP BackWPup Extension actions. + * @param array $data Other data to sync to $information array. + * @return array $information Returned information array with both sets of data. + */ + public function sync_others_data($information, $data = array() ) { + if ( isset( $data['syncBackwpupData'] ) && $data['syncBackwpupData'] ) { + try { + $lastbackup = MainWP_Utility::get_lasttime_backup( 'backwpup' ); + $information['syncBackwpupData'] = array( + 'lastbackup' => $lastbackup, + ); + } catch ( \Exception $e ) { + // ok! + } + } + return $information; + } + + /** + * Get backup destinations list. + * + * @uses MainWP_Helper::check_classes_exists() + * @uses MainWP_Helper::check_methods() + * @uses \BackWPup_Option::get_job_ids() + * @uses \BackWPup::get_registered_destinations() + * @uses \BackWPup_Option::get() + * @uses \BackWPup::get_destination() + * @uses \BackWPup::get_destination::file_get_list() + * + * @return array $jobdest Backup destination list. + * @throws Exception Error Message. + */ + public 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(); + foreach ( $jobids as $jobid ) { + if ( \BackWPup_Option::get( $jobid, 'backuptype' ) === 'sync' ) { + continue; + } + $dests = \BackWPup_Option::get( $jobid, 'destinations' ); + foreach ( $dests as $dest ) { + if ( ! $destinations[ $dest ]['class'] ) { + continue; + } + + $dest_class = \BackWPup::get_destination( $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; + } + } + } + } + + return $jobdest; + } + + /** + * Hide BackWPup Plugin from the WordPress Installed plugin list. + * + * @param array $plugins Installed plugins. + * @return array $plugins Installed plugins without BackWPup Plugin on the list. + */ + public function all_plugins( $plugins ) { + foreach ( $plugins as $key => $value ) { + $plugin_slug = basename( $key, '.php' ); + if ( 'backwpup' === $plugin_slug ) { + unset( $plugins[ $key ] ); + } + } + + return $plugins; + } + + /** + * Remove BackWPup Plugin from the WordPress Admin. + */ + public function remove_menu() { + + /** global $submenu WordPress Sub Menu global variable. */ + global $submenu; + + // Remove the WordPress Admin SubMenu. + if ( isset( $submenu['backwpup'] ) ) { + unset( $submenu['backwpup'] ); + } + + // Remove the WordPress Admin Page. + remove_menu_page( 'backwpup' ); + + // Create a WP Safe Redirect for the page URL. + $pos = stripos( $_SERVER['REQUEST_URI'], 'admin.php?page=backwpup' ); + if ( false !== $pos ) { + wp_safe_redirect( get_option( 'siteurl' ) . '/wp-admin/index.php' ); + exit(); + } + } + + /** + * Show/Hide BackWPup Plugin. + * + * @uses MainWP_Helper::instance()::update_option() + * + * @return int[]|string Return 1 on HIDE, Empty string on SHOW. + */ + protected function show_hide() { + + $hide = isset( $_POST['show_hide'] ) && ( '1' === $_POST['show_hide'] ) ? 'hide' : ''; + + MainWP_Helper::instance()->update_option( 'mainwp_backwpup_hide_plugin', $hide, 'yes' ); + + return array( 'success' => 1 ); + } + + /** + * Build the MainWP BackWPup Page Settings. + * @return array $output Returned information array. + */ + protected function information() { + + /** @global $wpdb wpdb */ + global $wpdb; + + // Copied from BackWPup_Page_Settings. + ob_start(); + echo ''; + echo ''; + echo ''; + echo ''; + if ( ! class_exists( '\BackWPup_Pro', false ) ) { + echo ''; + } else { + echo ''; + } + + echo ''; + echo ''; + if ( function_exists( 'curl_version' ) ) { + $curlversion = curl_version(); + echo ''; + echo ''; + } else { + echo ''; + } + echo ''; + + echo ''; + + echo ''; + + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + $text = version_compare( phpversion(), '5.3.0' ) < 0 && (bool) ini_get( 'safe_mode' ) ? __( 'On', 'mainwp-child' ) : __( 'Off', 'mainwp-child' ); + echo ''; + echo ''; + if ( defined( 'ALTERNATE_WP_CRON' ) && ALTERNATE_WP_CRON ) { + echo ''; + } else { + echo ''; + } + if ( defined( 'DISABLE_WP_CRON' ) && DISABLE_WP_CRON ) { + echo ''; + } else { + echo ''; + } + if ( defined( 'FS_CHMOD_DIR' ) ) { + echo ''; + } else { + echo ''; + } + + $now = localtime( time(), true ); + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + + $disabled = ini_get( 'disable_functions' ); + if ( ! empty( $disabled ) ) { + $disabledarry = explode( ',', $disabled ); + echo ''; + } + + echo ''; + echo '
' . __( 'Setting', 'mainwp-child' ) . '' . __( 'Value', 'mainwp-child' ) . '
' . __( 'Setting', 'mainwp-child' ) . '' . __( 'Value', 'mainwp-child' ) . '
' . __( 'WordPress version', 'mainwp-child' ) . '' . esc_html( \BackWPup::get_plugin_data( 'wp_version' ) ) . '
' . __( 'BackWPup version', 'mainwp-child' ) . '' . esc_html( \BackWPup::get_plugin_data( 'Version' ) ) . ' ' . __( 'Get pro.', 'mainwp-child' ) . '
' . __( 'BackWPup Pro version', 'mainwp-child' ) . '' . esc_html( \BackWPup::get_plugin_data( 'Version' ) ) . '
' . __( 'PHP version', 'mainwp-child' ) . '' . esc_html( PHP_VERSION ) . '
' . __( 'MySQL version', 'mainwp-child' ) . '' . esc_html( $wpdb->get_var( 'SELECT VERSION() AS version' ) ) . '
' . __( 'cURL version', 'mainwp-child' ) . '' . esc_html( $curlversion['version'] ) . '
' . __( 'cURL SSL version', 'mainwp-child' ) . '' . esc_html( $curlversion['ssl_version'] ) . '
' . __( 'cURL version', 'mainwp-child' ) . '' . __( 'unavailable', 'mainwp-child' ) . '
' . __( 'WP-Cron url:', 'mainwp-child' ) . '' . esc_html( site_url( 'wp-cron.php' ) ) . '
' . __( 'Server self connect:', 'mainwp-child' ) . ''; + $raw_response = \BackWPup_Job::get_jobrun_url( 'test' ); + $test_result = ''; + if ( is_wp_error( $raw_response ) ) { + $test_result .= sprintf( __( 'The HTTP response test get an error "%s"', 'mainwp-child' ), esc_html( $raw_response->get_error_message() ) ); + } elseif ( 200 !== (int) wp_remote_retrieve_response_code( $raw_response ) && 204 !== (int) wp_remote_retrieve_response_code( $raw_response ) ) { + $test_result .= sprintf( __( 'The HTTP response test get a false http status (%s)', 'mainwp-child' ), esc_html( wp_remote_retrieve_response_code( $raw_response ) ) ); + } + $headers = wp_remote_retrieve_headers( $raw_response ); + if ( isset( $headers['x-backwpup-ver'] ) && \BackWPup::get_plugin_data( 'version' ) !== $headers['x-backwpup-ver'] ) { + $test_result .= sprintf( __( 'The BackWPup HTTP response header returns a false value: "%s"', 'mainwp-child' ), esc_html( $headers['x-backwpup-ver'] ) ); + } + + if ( empty( $test_result ) ) { + esc_html_e( 'Response Test O.K.', 'mainwp-child' ); + } else { + echo esc_html( $test_result ); + } + echo '
' . __( 'Temp folder:', 'mainwp-child' ) . ''; + if ( ! is_dir( \BackWPup::get_plugin_data( 'TEMP' ) ) ) { + echo sprintf( __( 'Temp folder %s doesn\'t exist.', 'mainwp-child' ), esc_html( \BackWPup::get_plugin_data( 'TEMP' ) ) ); + } elseif ( ! is_writable( \BackWPup::get_plugin_data( 'TEMP' ) ) ) { + echo sprintf( __( 'Temporary folder %s is not writable.', 'mainwp-child' ), esc_html( \BackWPup::get_plugin_data( 'TEMP' ) ) ); + } else { + echo esc_html( \BackWPup::get_plugin_data( 'TEMP' ) ); + } + echo '
' . __( 'Log folder:', 'mainwp-child' ) . ''; + + $log_folder = \BackWPup_File::get_absolute_path( get_site_option( 'backwpup_cfg_logfolder' ) ); + + if ( ! is_dir( $log_folder ) ) { + echo sprintf( __( 'Logs folder %s not exist.', 'mainwp-child' ), esc_html( $log_folder ) ); + } elseif ( ! is_writable( $log_folder ) ) { + echo sprintf( __( 'Log folder %s is not writable.', 'mainwp-child' ), esc_html( $log_folder ) ); + } else { + echo esc_html( $log_folder ); + } + echo '
' . __( 'Server', 'mainwp-child' ) . '' . esc_html( $_SERVER['SERVER_SOFTWARE'] ) . '
' . __( 'Operating System', 'mainwp-child' ) . '' . esc_html( PHP_OS ) . '
' . __( 'PHP SAPI', 'mainwp-child' ) . '' . esc_html( PHP_SAPI ) . '
' . __( 'Current PHP user', 'mainwp-child' ) . '' . esc_html( get_current_user() ) . '
' . __( 'Safe Mode', 'mainwp-child' ) . '' . $text . '
' . __( 'Maximum execution time', 'mainwp-child' ) . '' . ini_get( 'max_execution_time' ) . ' ' . __( 'seconds', 'mainwp-child' ) . '
' . __( 'Alternative WP Cron', 'mainwp-child' ) . '' . __( 'On', 'mainwp-child' ) . '
' . __( 'Alternative WP Cron', 'mainwp-child' ) . '' . __( 'Off', 'mainwp-child' ) . '
' . __( 'Disabled WP Cron', 'mainwp-child' ) . '' . __( 'On', 'mainwp-child' ) . '
' . __( 'Disabled WP Cron', 'mainwp-child' ) . '' . __( 'Off', 'mainwp-child' ) . '
' . __( 'CHMOD Dir', 'mainwp-child' ) . '' . FS_CHMOD_DIR . '
' . __( 'CHMOD Dir', 'mainwp-child' ) . '0755
' . __( 'Server Time', 'mainwp-child' ) . '' . esc_html( $now['tm_hour'] ) . ':' . esc_html( $now['tm_min'] ) . '
' . __( 'Blog Time', 'mainwp-child' ) . '' . esc_html( date_i18n( 'H:i' ) ) . '
' . __( 'Blog Timezone', 'mainwp-child' ) . '' . esc_html( get_option( 'timezone_string' ) ) . '
' . __( 'Blog Time offset', 'mainwp-child' ) . '' . sprintf( __( '%s hours', 'mainwp-child' ), esc_html( get_option( 'gmt_offset' ) ) ) . '
' . __( 'Blog language', 'mainwp-child' ) . '' . esc_html( get_bloginfo( 'language' ) ) . '
' . __( 'MySQL Client encoding', 'mainwp-child' ) . ''; + echo defined( 'DB_CHARSET' ) ? esc_html( DB_CHARSET ) : ''; + echo '
' . __( 'Blog charset', 'mainwp-child' ) . '' . esc_html( get_bloginfo( 'charset' ) ) . '
' . __( 'PHP Memory limit', 'mainwp-child' ) . '' . esc_html( ini_get( 'memory_limit' ) ) . '
' . __( 'WP memory limit', 'mainwp-child' ) . '' . esc_html( WP_MEMORY_LIMIT ) . '
' . __( 'WP maximum memory limit', 'mainwp-child' ) . '' . esc_html( WP_MAX_MEMORY_LIMIT ) . '
' . __( 'Memory in use', 'mainwp-child' ) . '' . esc_html( size_format( memory_get_usage( true ), 2 ) ) . '
' . __( 'Disabled PHP Functions:', 'mainwp-child' ) . ''; + echo esc_html( implode( ', ', $disabledarry ) ); + echo '
' . __( 'Loaded PHP Extensions:', 'mainwp-child' ) . ''; + $extensions = get_loaded_extensions(); + sort( $extensions ); + echo esc_html( implode( ', ', $extensions ) ); + echo '
'; + + $output = ob_get_contents(); + + ob_end_clean(); + + return array( + 'success' => 1, + 'response' => $output, + ); + } + + /** + * Delete BackWPup Log. + * + * @uses \BackWPup_File::get_absolute_path() + * + * @return int[]|string[] On success return success[1] & error[] message on failure. + */ + protected function delete_log() { + if ( ! isset( $_POST['settings']['logfile'] ) || ! is_array( $_POST['settings']['logfile'] ) ) { + return array( 'error' => __( 'Missing logfile.', 'mainwp-child' ) ); + } + + $dir = get_site_option( 'backwpup_cfg_logfolder' ); + $dir = \BackWPup_File::get_absolute_path( $dir ); + + foreach ( $_POST['settings']['logfile'] as $logfile ) { + $logfile = basename( $logfile ); + + if ( ! is_writeable( $dir ) ) { + return array( 'error' => __( 'Directory not writable:', 'mainwp-child' ) . $dir ); + } + if ( ! is_file( $dir . $logfile ) ) { + return array( 'error' => __( 'Not file:', 'mainwp-child' ) . $dir . $logfile ); + } + + unlink( $dir . $logfile ); + + } + + return array( 'success' => 1 ); + } + + /** + * Delete backup job. + * + * @uses \BackWPup_Option::delete_job() + * + * @return array|int[]|string[] On success return success[1] & error['message'] on failure. + */ + protected function delete_job() { + if ( ! isset( $_POST['job_id'] ) ) { + return array( 'error' => __( 'Missing job_id.', 'mainwp-child' ) ); + } + + $job_id = (int) $_POST['job_id']; + + wp_clear_scheduled_hook( 'backwpup_cron', array( 'id' => $job_id ) ); + if ( ! \BackWPup_Option::delete_job( $job_id ) ) { + return array( 'error' => __( 'Cannot delete job', 'mainwp-child' ) ); + } + + return array( 'success' => 1 ); + } + + /** + * Delete backup. + * + * @uses \BackWPup::get_destination() + * @uses \BackWPup::get_destination::file_get_list() + * @uses \BackWPup::get_destination::file_delete() + * + * @return array|int[]|string[] On success return success[1] response['DELETED'] & error['message'] on failure. + */ + protected function delete_backup() { + if ( ! isset( $_POST['settings']['backupfile'] ) ) { + return array( 'error' => __( 'Missing backupfile.', 'mainwp-child' ) ); + } + + if ( ! isset( $_POST['settings']['dest'] ) ) { + return array( 'error' => __( 'Missing dest.', 'mainwp-child' ) ); + } + + $backupfile = $_POST['settings']['backupfile']; + $dest = $_POST['settings']['dest']; + + list( $dest_id, $dest_name ) = explode( '_', $dest ); + + $dest_class = \BackWPup::get_destination( $dest_name ); + + if ( is_null( $dest_class ) ) { + return array( 'error' => __( 'Invalid dest class.', 'mainwp-child' ) ); + } + + $files = $dest_class->file_get_list( $dest ); + + foreach ( $files as $file ) { + if ( is_array( $file ) && $file['file'] == $backupfile ) { + $dest_class->file_delete( $dest, $backupfile ); + + return array( + 'success' => 1, + 'response' => 'DELETED', + ); + } + } + + return array( + 'success' => 1, + 'response' => 'Not found', + ); + } + + /** + * View BackWPup log. + * + * @return array|int[]|string[] On success return $output[] & error['message'] on failure. + */ + protected function view_log() { + if ( ! isset( $_POST['settings']['logfile'] ) ) { + return array( 'error' => __( 'Missing logfile.', 'mainwp-child' ) ); + } + + $log_folder = get_site_option( 'backwpup_cfg_logfolder' ); + $log_folder = \BackWPup_File::get_absolute_path( $log_folder ); + $log_file = $log_folder . basename( $_POST['settings']['logfile'] ); + + if ( ! is_readable( $log_file ) && ! is_readable( $log_file . '.gz' ) && ! is_readable( $log_file . '.bz2' ) ) { + $output = __( 'Log file doesn\'t exists', 'mainwp-child' ); + } else { + if ( ! file_exists( $log_file ) && file_exists( $log_file . '.gz' ) ) { + $log_file = $log_file . '.gz'; + } + + if ( ! file_exists( $log_file ) && file_exists( $log_file . '.bz2' ) ) { + $log_file = $log_file . '.bz2'; + } + + if ( '.gz' == substr( $log_file, - 3 ) ) { + $output = file_get_contents( 'compress.zlib://' . $log_file, false ); + } else { + $output = file_get_contents( $log_file, false ); + } + } + + return array( + 'success' => 1, + 'response' => $output, + ); + } + + /** + * Build Tables. + * + * @uses MainWP_Child_Back_WP_Up::wp_list_table_dependency() + * @uses \BackWPup_File::get_absolute_path() + * @uses \BackWPup_Page_Logs() + * @uses \BackWPup_Page_Backups() + * @uses \BackWPup_Option::get_job_ids() + * @uses \BackWPup_Option::get() + * @uses \BackWPup::get_destination() + * @uses \BackWPup::get_destination::file_get_list() + * @uses \Option::get() + * + * @return array Return table array or error['message'] on failure. + */ + protected function tables() { + if ( ! isset( $_POST['settings']['type'] ) ) { + return array( 'error' => __( 'Missing type.', 'mainwp-child' ) ); + } + + if ( ! isset( $_POST['settings']['website_id'] ) ) { + return array( 'error' => __( 'Missing website id.', 'mainwp-child' ) ); + } + + $type = $_POST['settings']['type']; + $website_id = $_POST['settings']['website_id']; + + $this->wp_list_table_dependency(); + + $array = array(); + + switch ( $type ) { + case 'logs': + $log_folder = get_site_option( 'backwpup_cfg_logfolder' ); + $log_folder = \BackWPup_File::get_absolute_path( $log_folder ); + $log_folder = untrailingslashit( $log_folder ); + + if ( ! is_dir( $log_folder ) ) { + return array( + 'success' => 1, + 'response' => $array, + ); + } + update_user_option( get_current_user_id(), 'backwpuplogs_per_page', 99999999 ); + $output = new \BackWPup_Page_Logs(); + $output->prepare_items(); + break; + + case 'backups': + update_user_option( get_current_user_id(), 'backwpupbackups_per_page', 99999999 ); + $output = new \BackWPup_Page_Backups(); + $output->items = array(); + + $jobids = \BackWPup_Option::get_job_ids(); + + if ( ! empty( $jobids ) ) { + foreach ( $jobids as $jobid ) { + if ( \BackWPup_Option::get( $jobid, 'backuptype' ) == 'sync' ) { + continue; + } + + $dests = \Option::get( $jobid, 'destinations' ); + foreach ( $dests as $dest ) { + $dest_class = \BackWPup::get_destination( $dest ); + if ( is_null( $dest_class ) ) { + continue; + } + $items = $dest_class->file_get_list( $jobid . '_' . $dest ); + if ( ! empty( $items ) ) { + foreach ( $items as $item ) { + $temp_single_item = $item; + $temp_single_item['dest'] = $jobid . '_' . $dest; + $temp_single_item['timeloc'] = sprintf( __( '%1$s at %2$s', 'mainwp-child' ), date_i18n( get_option( 'date_format' ), $temp_single_item['time'], true ), date_i18n( get_option( 'time_format' ), $temp_single_item['time'], true ) ); + $output->items[] = $temp_single_item; + } + } + } + } + } + + break; + + case 'jobs': + $output = new \BackWPup_Page_Jobs(); + $output->prepare_items(); + break; + } + + if ( is_array( $output->items ) ) { + if ( 'jobs' == $type ) { + foreach ( $output->items as $key => $val ) { + $temp_array = array(); + $temp_array['id'] = $val; + $temp_array['name'] = \BackWPup_Option::get( $val, 'name' ); + $temp_array['type'] = \BackWPup_Option::get( $val, 'type' ); + $temp_array['destinations'] = \BackWPup_Option::get( $val, 'destinations' ); + + if ( $this->is_backwpup_pro ) { + $temp_array['export'] = str_replace( '&', '&', wp_nonce_url( network_admin_url( 'admin.php' ) . '?page=backwpupjobs&action=export&jobs[]=' . $val, 'bulk-jobs' ) ); + } + + if ( \BackWPup_Option::get( $val, 'activetype' ) == 'wpcron' ) { + $nextrun = wp_next_scheduled( 'backwpup_cron', array( 'id' => $val ) ); + if ( $nextrun + ( get_option( 'gmt_offset' ) * 3600 ) ) { + $temp_array['nextrun'] = sprintf( __( '%1$s at %2$s by WP-Cron', 'mainwp-child' ), date_i18n( get_option( 'date_format' ), $nextrun, true ), date_i18n( get_option( 'time_format' ), $nextrun, true ) ); + } else { + $temp_array['nextrun'] = __( 'Not scheduled!', 'mainwp-child' ); + } + } else { + $temp_array['nextrun'] = __( 'Inactive', 'mainwp-child' ); + } + if ( \BackWPup_Option::get( $val, 'lastrun' ) ) { + $lastrun = \BackWPup_Option::get( $val, 'lastrun' ); + $temp_array['lastrun'] = sprintf( __( '%1$s at %2$s', 'mainwp-child' ), date_i18n( get_option( 'date_format' ), $lastrun, true ), date_i18n( get_option( 'time_format' ), $lastrun, true ) ); + if ( \BackWPup_Option::get( $val, 'lastruntime' ) ) { + $temp_array['lastrun'] .= ' ' . sprintf( __( 'Runtime: %d seconds', 'mainwp-child' ), \BackWPup_Option::get( $val, 'lastruntime' ) ); + } + } else { + $temp_array['lastrun'] = __( 'not yet', 'mainwp-child' ); + } + + $temp_array['website_id'] = $website_id; + $array[] = $temp_array; + } + } elseif ( 'backups' == $type ) { + $without_dupes = array(); + foreach ( $output->items as $key ) { + $temp_array = $key; + $temp_array['downloadurl'] = str_replace( + array( + '&', + network_admin_url( 'admin.php' ) . '?page=backwpupbackups&action=', + ), + array( + '&', + admin_url( 'admin-ajax.php' ) . '?action=mainwp_backwpup_download_backup&type=', + ), + $temp_array['downloadurl'] . '&_wpnonce=' . $this->create_nonce_without_session( 'mainwp_download_backup' ) + ); + + $temp_array['downloadurl_id'] = '/wp-admin/admin.php?page=backwpupbackups'; + if ( preg_match( '/.*&jobid=([^&]+)&.*/is', $temp_array['downloadurl'], $matches ) ) { + if ( ! empty( $matches[1] ) && is_numeric( $matches[1] ) ) { + $temp_array['downloadurl_id'] .= '&download_click_id=' . $matches[1]; + } + } + + $temp_array['website_id'] = $website_id; + + if ( ! isset( $without_dupes[ $temp_array['file'] ] ) ) { + $array[] = $temp_array; + $without_dupes[ $temp_array['file'] ] = 1; + } + } + } else { + foreach ( $output->items as $key => $val ) { + $array[] = $val; + } + } + } + + return array( + 'success' => 1, + 'response' => $array, + ); + } + + /** + * Initiate download link. + */ + public function init_download_backup() { + if ( ! isset( $_GET['page'] ) || 'backwpupbackups' !== $_GET['page'] || ! isset( $_GET['download_click_id'] ) || empty( $_GET['download_click_id'] ) ) { + return; + } + ?> + + verify_nonce_without_session( $_GET['_wpnonce'], 'mainwp_download_backup' ) ) { + die( '-3' ); + } + + $dest = strtoupper( str_replace( 'download', '', $_GET['type'] ) ); + if ( ! empty( $dest ) && strstr( $_GET['type'], 'download' ) ) { + $dest_class = \BackWPup::get_destination( $dest ); + if ( is_null( $dest_class ) ) { + die( '-4' ); + } + + $dest_class->file_download( (int) $_GET['jobid'], $_GET['file'] ); + } else { + die( '-5' ); + } + + die(); + } + + /** + * Create security nounce without session. + * + * @param int $action Action performing. + * + * @return string|false Return nonce or FALSE on failure. + */ + protected function create_nonce_without_session( $action = - 1 ) { + $user = wp_get_current_user(); + $uid = (int) $user->ID; + if ( ! $uid ) { + $uid = apply_filters( 'nonce_user_logged_out', $uid, $action ); + } + + $i = wp_nonce_tick(); + + return substr( wp_hash( $i . '|' . $action . '|' . $uid, 'nonce' ), - 12, 10 ); + } + + /** + * Verify nonce without session. + * + * @param string $nonce Nonce to verify. + * @param int $action Action to perform. + * + * @return bool|int FALSE on failure. 1 or 2 on success. + */ + protected function verify_nonce_without_session($nonce, $action = - 1 ) { + $nonce = (string) $nonce; + $user = wp_get_current_user(); + $uid = (int) $user->ID; + if ( ! $uid ) { + $uid = apply_filters( 'nonce_user_logged_out', $uid, $action ); + } + + if ( empty( $nonce ) ) { + return false; + } + + $i = wp_nonce_tick(); + + $expected = substr( wp_hash( $i . '|' . $action . '|' . $uid, 'nonce' ), - 12, 10 ); + if ( hash_equals( $expected, $nonce ) ) { + return 1; + } + + $expected = substr( wp_hash( ( $i - 1 ) . '|' . $action . '|' . $uid, 'nonce' ), - 12, 10 ); + if ( hash_equals( $expected, $nonce ) ) { + return 2; + } + + return false; + } + + /** + * BackWPup Ajax Working. + * + * @uses MainWP_Child_Back_WP_Up::wp_list_table_dependency() + * @uses \BackWPup_Page_Jobs::ajax_working() + * + * @return array Return success array[ success, response ] + */ + protected function ajax_working() { + + if ( ! isset( $_POST['settings'] ) || ! is_array( $_POST['settings'] ) || ! isset( $_POST['settings']['logfile'] ) || ! isset( $_POST['settings']['logpos'] ) ) { + return array( 'error' => __( 'Missing logfile or logpos.', 'mainwp-child' ) ); + } + + $_GET['logfile'] = $_POST['settings']['logfile']; + $_GET['logpos'] = $_POST['settings']['logpos']; + $_REQUEST['_wpnonce'] = wp_create_nonce( 'backwpupworking_ajax_nonce' ); + + $this->wp_list_table_dependency(); + + /** + * MainWP BackWPup WP Die ajax handler. + * + * @param string $message Error message container. + * @return string Error message. + */ + function mainwp_backwpup_wp_die_ajax_handler( $message ) { + return 'mainwp_backwpup_wp_die_ajax_handler'; + } + + // We do this in order to not die when using wp_die. + if ( ! defined( 'DOING_AJAX' ) ) { + define( 'DOING_AJAX', true ); + } + + add_filter( 'wp_die_ajax_handler', 'mainwp_backwpup_wp_die_ajax_handler' ); + remove_filter( 'wp_die_ajax_handler', '_ajax_wp_die_handler' ); + + ob_start(); + \BackWPup_Page_Jobs::ajax_working(); + + $output = ob_get_contents(); + + ob_end_clean(); + + return array( + 'success' => 1, + 'response' => $output, + ); + } + + /** + * Backup now. + * + * @uses MainWP_Child_Back_WP_Up::wp_list_table_dependency() + * @uses MainWP_Child_Back_WP_Up::check_backwpup_messages() + * @uses \BackWPup_Page_Jobs::load() + * @uses \BackWPup_Job::get_working_data() + * + * @return array Response array[ success, response, logfile ] or array[ error ] + */ + protected function backup_now() { + + if ( ! isset( $_POST['settings']['job_id'] ) ) { + return array( 'error' => __( 'Missing job_id', 'mainwp-child' ) ); + } + + // Simulate http://wp/wp-admin/admin.php?jobid=1&page=backwpupjobs&action=runnow. + $_GET['jobid'] = $_POST['settings']['job_id']; + + $_REQUEST['action'] = 'runnow'; + $_REQUEST['_wpnonce'] = wp_create_nonce( 'backwpup_job_run-runnowlink' ); + + update_site_option( 'backwpup_messages', array() ); + + $this->wp_list_table_dependency(); + + ob_start(); + \BackWPup_Page_Jobs::load(); + ob_end_clean(); + + $output = $this->check_backwpup_messages(); + + if ( isset( $output['error'] ) ) { + return array( 'error' => '\BackWPup_Page_Jobs::load fail: ' . $output['error'] ); + } else { + $job_object = \BackWPup_Job::get_working_data(); + if ( is_object( $job_object ) ) { + return array( + 'success' => 1, + 'response' => $output['message'], + 'logfile' => basename( $job_object->logfile ), + ); + } else { + return array( + 'success' => 1, + 'response' => $output['message'], + ); + } + } + } + + /** + * Abort backup. + * + * @uses MainWP_Child_Back_WP_Up::wp_list_table_dependency() + * @uses MainWP_Child_Back_WP_Up::check_backwpup_messages() + * @uses \BackWPup_Page_Jobs::load() + * + * @return array|string[] Return array or error[message] on failure. + */ + protected function backup_abort() { + $_REQUEST['action'] = 'abort'; + $_REQUEST['_wpnonce'] = wp_create_nonce( 'abort-job' ); + + update_site_option( 'backwpup_messages', array() ); + + $this->wp_list_table_dependency(); + + ob_start(); + \BackWPup_Page_Jobs::load(); + ob_end_clean(); + + $output = $this->check_backwpup_messages(); + + if ( isset( $output['error'] ) ) { + return array( 'error' => 'Cannot abort: ' . $output['error'] ); + } else { + return array( + 'success' => 1, + 'response' => $output['message'], + ); + } + } + + /** + * WordPress list table dependency. + * + * @uses MainWP_Child_Back_WP_Up::MainWP_Fake_Wp_Screen() + */ + protected function wp_list_table_dependency() { + if ( ! function_exists( 'convert_to_screen' ) ) { + + /** + * Convert to screen + * + * We need this because BackWPup_Page_Jobs extends WP_List_Table + * which uses convert_to_screen. + * + * @param $hook_name Hook name. + * @return MainWP_Fake_Wp_Screen + */ + function convert_to_screen( $hook_name ) { + return new MainWP_Fake_Wp_Screen(); + } + } + + if ( ! function_exists( 'add_screen_option' ) ) { + /** + * Adds the WP Fake Screen option. + * + * @param mixed $option Options. + * @param array $args Arguments. + */ + function add_screen_option( $option, $args = array() ) { + } + } + + if ( ! class_exists( '\WP_List_Table' ) ) { + require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; + } + } + + /** + * Wizard system scan. + * + * @uses \BackWPup_Pro_Wizard_SystemTest() + * + * @return array|string[] Return array or error[message] on failure. + */ + protected function wizard_system_scan() { + if ( class_exists( '\BackWPup_Pro_Wizard_SystemTest' ) ) { + ob_start(); + + $system_test = new \BackWPup_Pro_Wizard_SystemTest(); + $system_test->execute( null ); + + $output = ob_get_contents(); + + ob_end_clean(); + + return array( + 'success' => 1, + 'response' => $output, + ); + } else { + return array( 'error' => 'Missing BackWPup_Pro_Wizard_SystemTest' ); + } + } + + /** + * Check destination email. + * + * @uses PHPMailer() + * @uses \BackWPup::get_plugin_data() + * @uses Swift_SmtpTransport::newInstance() + * @uses Swift_SendmailTransport::newInstance() + * @uses Swift_MailTransport::newInstance() + * @uses Swift_Mailer::newInstance() + * @uses Swift_Message::newInstance() + * @uses \Exception + * + * @return array|\Exception Return response array. + */ + protected function destination_email_check_email() { + $settings = $_POST['settings']; + + $message = ''; + + $emailmethod = ( isset( $settings['emailmethod'] ) ? $settings['emailmethod'] : '' ); + $emailsendmail = ( isset( $settings['emailsendmail'] ) ? $settings['emailsendmail'] : '' ); + $emailhost = ( isset( $settings['emailhost'] ) ? $settings['emailhost'] : '' ); + $emailhostport = ( isset( $settings['emailhostport'] ) ? $settings['emailhostport'] : '' ); + $emailsecure = ( isset( $settings['emailsecure'] ) ? $settings['emailsecure'] : '' ); + $emailuser = ( isset( $settings['emailuser'] ) ? $settings['emailuser'] : '' ); + $emailpass = ( isset( $settings['emailpass'] ) ? $settings['emailpass'] : '' ); + + if ( ! isset( $settings['emailaddress'] ) || strlen( $settings['emailaddress'] ) < 2 ) { + $message = __( 'Missing email address.', 'mainwp-child' ); + } else { + if ( $emailmethod ) { + global $phpmailer; + if ( ! is_object( $phpmailer ) || ! $phpmailer instanceof PHPMailer ) { + require_once ABSPATH . WPINC . '/class-phpmailer.php'; + require_once ABSPATH . WPINC . '/class-smtp.php'; + $phpmailer = new PHPMailer( true ); // phpcs:ignore -- to custom init PHP mailer + } + if ( is_object( $phpmailer ) ) { + do_action_ref_array( 'phpmailer_init', array( &$phpmailer ) ); + $emailmethod = $phpmailer->Mailer; + $emailsendmail = $phpmailer->Sendmail; + $emailhost = $phpmailer->Host; + $emailhostport = $phpmailer->Port; + $emailsecure = $phpmailer->SMTPSecure; + $emailuser = $phpmailer->Username; + $emailpass = $phpmailer->Password; + } + } + + if ( ! class_exists( '\Swift', false ) ) { + require \BackWPup::get_plugin_data( 'plugindir' ) . '/vendor/SwiftMailer/swift_required.php'; + } + + if ( function_exists( 'mb_internal_encoding' ) && ( (int) ini_get( 'mbstring.func_overload' ) ) & 2 ) { + $mbEncoding = mb_internal_encoding(); + mb_internal_encoding( 'ASCII' ); + } + + try { + // Create the Transport. + if ( 'smtp' == $emailmethod ) { + $transport = Swift_SmtpTransport::newInstance( $emailhost, $emailhostport ); + $transport->setUsername( $emailuser ); + $transport->setPassword( $emailpass ); + if ( 'ssl' == $emailsecure ) { + $transport->setEncryption( 'ssl' ); + } + if ( 'tls' == $emailsecure ) { + $transport->setEncryption( 'tls' ); + } + } elseif ( 'sendmail' == $emailmethod ) { + $transport = Swift_SendmailTransport::newInstance( $emailsendmail ); + } else { + $transport = Swift_MailTransport::newInstance(); + } + $emailer = Swift_Mailer::newInstance( $transport ); + + $message = Swift_Message::newInstance( __( 'BackWPup archive sending TEST Message', 'mainwp-child' ) ); + $message->setFrom( array( ( isset( $settings['emailsndemail'] ) ? $settings['emailsndemail'] : 'from@example.com' ) => isset( $settings['emailsndemailname'] ) ? $settings['emailsndemailname'] : '' ) ); + $message->setTo( array( $settings['emailaddress'] ) ); + $message->setBody( __( 'If this message reaches your inbox, sending backup archives via email should work for you.', 'mainwp-child' ) ); + + $result = $emailer->send( $message ); + } catch ( \Exception $e ) { + $message = 'Swift Mailer: ' . $e->getMessage(); + } + + if ( isset( $mbEncoding ) ) { + mb_internal_encoding( $mbEncoding ); + } + + if ( ! isset( $result ) || ! $result ) { + $message = __( 'Error while sending email!', 'mainwp-child' ); + } else { + $message = __( 'Email sent.', 'mainwp-child' ); + } + } + + return array( + 'success' => 1, + 'message' => $message, + ); + } + + /** + * Get job files. + * + * @uses BackWPup_File::get_upload_dir() + * @uses BackWPup_File::get_folder_size() + * @return array Response array containing folder locations and size. + */ + protected function get_job_files() { + /** + * Taken from BackWPup_JobType_File::get_exclude_dirs. + * + * @param array $folder Folders to exclude. + * @return array Return folders list. + */ + function mainwp_backwpup_get_exclude_dirs( $folder ) { + $folder = trailingslashit( str_replace( '\\', '/', realpath( $folder ) ) ); + $exclude_dir_array = array(); + + if ( false !== strpos( trailingslashit( str_replace( '\\', '/', realpath( ABSPATH ) ) ), $folder ) && trailingslashit( str_replace( '\\', '/', realpath( ABSPATH ) ) ) != $folder ) { + $exclude_dir_array[] = trailingslashit( str_replace( '\\', '/', realpath( ABSPATH ) ) ); + } + if ( false !== strpos( trailingslashit( str_replace( '\\', '/', realpath( WP_CONTENT_DIR ) ) ), $folder ) && trailingslashit( str_replace( '\\', '/', realpath( WP_CONTENT_DIR ) ) ) != $folder ) { + $exclude_dir_array[] = trailingslashit( str_replace( '\\', '/', realpath( WP_CONTENT_DIR ) ) ); + } + if ( false !== strpos( trailingslashit( str_replace( '\\', '/', realpath( WP_PLUGIN_DIR ) ) ), $folder ) && trailingslashit( str_replace( '\\', '/', realpath( WP_PLUGIN_DIR ) ) ) != $folder ) { + $exclude_dir_array[] = trailingslashit( str_replace( '\\', '/', realpath( WP_PLUGIN_DIR ) ) ); + } + if ( false !== strpos( trailingslashit( str_replace( '\\', '/', realpath( get_theme_root() ) ) ), $folder ) && trailingslashit( str_replace( '\\', '/', realpath( get_theme_root() ) ) ) != $folder ) { + $exclude_dir_array[] = trailingslashit( str_replace( '\\', '/', realpath( get_theme_root() ) ) ); + } + if ( false !== strpos( trailingslashit( str_replace( '\\', '/', realpath( \BackWPup_File::get_upload_dir() ) ) ), $folder ) && trailingslashit( str_replace( '\\', '/', realpath( \BackWPup_File::get_upload_dir() ) ) ) != $folder ) { + $exclude_dir_array[] = trailingslashit( str_replace( '\\', '/', realpath( \BackWPup_File::get_upload_dir() ) ) ); + } + + return array_unique( $exclude_dir_array ); + } + + $return = array(); + + $folders = array( + 'abs' => ABSPATH, + 'content' => WP_CONTENT_DIR, + 'plugin' => WP_PLUGIN_DIR, + 'theme' => get_theme_root(), + 'upload' => \BackWPup_File::get_upload_dir(), + ); + + foreach ( $folders as $key => $folder ) { + $return_temp = array(); + $main_folder_name = realpath( $folder ); + + if ( $main_folder_name ) { + $main_folder_name = untrailingslashit( str_replace( '\\', '/', $main_folder_name ) ); + $main_folder_size = '(' . size_format( \BackWPup_File::get_folder_size( $main_folder_name, false ), 2 ) . ')'; + + $dir = opendir( $main_folder_name ); + if ( $dir ) { + while ( false !== ( $file = readdir( $dir ) ) ) { + if ( ! in_array( $file, array( '.', '..' ) ) && is_dir( $main_folder_name . '/' . $file ) && ! in_array( trailingslashit( $main_folder_name . '/' . $file ), mainwp_backwpup_get_exclude_dirs( $main_folder_name ) ) ) { + $folder_size = ' (' . size_format( \BackWPup_File::get_folder_size( $main_folder_name . '/' . $file ), 2 ) . ')'; + $return_temp[] = array( + 'size' => $folder_size, + 'name' => $file, + ); + + } + } + + closedir( $dir ); + } + + $return[ $key ] = array( + 'size' => $main_folder_size, + 'name' => $folder, + 'folders' => $return_temp, + ); + } + } + + return array( + 'success' => 1, + 'folders' => $return, + ); + } + + /** + * Get Child Site Tables. + * + * @uses BackWPup_Option::get() + * + * @return array Query response containing the tables. + */ + protected function get_child_tables() { + + /** @global $wpdb wpdb */ + global $wpdb; + + $return = array(); + + $settings = $_POST['settings']; + + if ( ! empty( $settings['dbhost'] ) && ! empty( $settings['dbuser'] ) ) { + $mysqli = new mysqli( $settings['dbhost'], $settings['dbuser'], ( isset( $settings['dbpassword'] ) ? $settings['dbpassword'] : '' ) ); // phpcs:ignore -- third party code. + + if ( $mysqli->connect_error ) { + $return['message'] = $mysqli->connect_error; + } else { + if ( ! empty( $settings['dbname'] ) ) { + $res = $mysqli->query( 'SHOW FULL TABLES FROM `' . $mysqli->real_escape_string( $settings['dbname'] ) . '`' ); + if ( $res ) { + $tables_temp = array(); + while ( $table = $res->fetch_array( MYSQLI_NUM ) ) { // phpcs:ignore -- third party code. + $tables_temp[] = $table[0]; + } + + $res->close(); + $return['tables'] = $tables_temp; + } + } + + if ( empty( $settings['dbname'] ) || ! empty( $settings['first'] ) ) { + $res = $mysqli->query( 'SHOW DATABASES' ); + if ( $res ) { + $databases_temp = array(); + while ( $db = $res->fetch_array() ) { + $databases_temp[] = $db['Database']; + } + + $res->close(); + $return['databases'] = $databases_temp; + } + } + } + $mysqli->close(); + } else { + $tables_temp = array(); + + $tables = $wpdb->get_results( 'SHOW FULL TABLES FROM `' . DB_NAME . '`', ARRAY_N ); // phpcs:ignore -- safe query. + foreach ( $tables as $table ) { + $tables_temp[] = $table[0]; + } + + $return['tables'] = $tables_temp; + } + + if ( isset( $settings['job_id'] ) ) { + $return['dbdumpexclude'] = \BackWPup_Option::get( $settings['job_id'], 'dbdumpexclude' ); + } + return array( + 'success' => 1, + 'return' => $return, + ); + } + + /** + * Insert or update global jobs. + * + * @uses MainWP_Child_Back_WP_Up::insert_or_update_jobs() + * + * @return array Response array containing job_id, changes & message array. + */ + protected function insert_or_update_jobs_global() { + $settings = $_POST['settings']; + + if ( ! is_array( $settings ) ) { + return array( 'error' => __( 'Missing array settings', 'mainwp-child' ) ); + } + + if ( ! isset( $settings['job_id'] ) ) { + return array( 'error' => __( 'Missing job_id', 'mainwp-child' ) ); + } + + if ( $settings['job_id'] > 0 ) { + $new_job_id = intval( $settings['job_id'] ); + } else { + $new_job_id = null; + } + + $changes_array = array(); + $message_array = array(); + + foreach ( $settings['value'] as $key => $val ) { + $temp_array = array(); + $temp_array['tab'] = $key; + $temp_array['value'] = $val; + if ( ! is_null( $new_job_id ) ) { + $temp_array['job_id'] = $new_job_id; + } else { + $temp_array['job_id'] = $settings['job_id']; + } + + $_POST['settings'] = $temp_array; + $return = $this->insert_or_update_jobs(); + + if ( is_null( $new_job_id ) ) { + if ( ! isset( $return['job_id'] ) ) { + return array( 'error' => __( 'Missing new job_id', 'mainwp-child' ) ); + } + + $new_job_id = $return['job_id']; + } + + // We want to exit gracefully. + if ( isset( $return['error_message'] ) ) { + $message_array[ $return['error_message'] ] = 1; + } + + if ( isset( $return['changes'] ) ) { + $changes_array = array_merge( $changes_array, $return['changes'] ); + } + + if ( isset( $return['message'] ) ) { + foreach ( $return['message'] as $message ) { + if ( ! isset( $message_array[ $message ] ) ) { + $message_array[ $message ] = 1; + } + } + } + } + + return array( + 'success' => 1, + 'job_id' => $new_job_id, + 'changes' => $changes_array, + 'message' => array_keys( $message_array ), + ); + } + + /** + * Edit form post save. + * + * Parses & saves files, folders, boolean fields excluding any unwanted files or directories. + * [Taken from BackWPup_JobType_File::edit_form_post_save with some tweaks]. + * + * @uses BackWPup_Option::update() + * + * @param $post_data Post data to save. + * @param $id Post ID. + */ + public function edit_form_post_save($post_data, $id ) { + // Parse and save files to exclude. + $exclude_input = $post_data['fileexclude']; + $to_exclude_list = $exclude_input ? str_replace( array( "\r\n", "\r" ), ',', $exclude_input ) : array(); + if ( $to_exclude_list ) { + $to_exclude_list = sanitize_text_field( stripslashes( $to_exclude_list ) ); + } + $to_exclude = $to_exclude_list ? explode( ',', $to_exclude_list ) : array(); + $to_exclude_parsed = array(); + foreach ( $to_exclude as $key => $value ) { + $normalized = wp_normalize_path( trim( $value ) ); + if ( $normalized ) { + $to_exclude_parsed[ $key ] = $normalized; + } + } + sort( $to_exclude_parsed ); + \BackWPup_Option::update( $id, 'fileexclude', implode( ',', $to_exclude_parsed ) ); + unset( $exclude_input, $to_exclude_list, $to_exclude, $to_exclude_parsed, $normalized ); + + // Parse and save folders to include. + $include_input = $post_data['dirinclude']; + $include_list = $include_input ? str_replace( array( "\r\n", "\r" ), ',', $include_input ) : array(); + $to_include = $include_list ? explode( ',', $include_list ) : array(); + $to_include_parsed = array(); + foreach ( $to_include as $key => $value ) { + $normalized = trailingslashit( wp_normalize_path( trim( $value ) ) ); + if ( $normalized ) { + $normalized = filter_var( $normalized, FILTER_SANITIZE_URL ); + } + $realpath = $normalized && '/' !== $normalized ? realpath( $normalized ) : false; + if ( $realpath ) { + $to_include_parsed[ $key ] = $realpath; + } + } + sort( $to_include_parsed ); + \BackWPup_Option::update( $id, 'dirinclude', implode( ',', $to_include_parsed ) ); + unset( $include_input, $include_list, $to_include, $to_include_parsed, $normalized, $realpath ); + + // Parse and save boolean fields. + $boolean_fields_def = array( + 'backupexcludethumbs' => FILTER_VALIDATE_BOOLEAN, + 'backupspecialfiles' => FILTER_VALIDATE_BOOLEAN, + 'backuproot' => FILTER_VALIDATE_BOOLEAN, + 'backupabsfolderup' => FILTER_VALIDATE_BOOLEAN, + 'backupcontent' => FILTER_VALIDATE_BOOLEAN, + 'backupplugins' => FILTER_VALIDATE_BOOLEAN, + 'backupthemes' => FILTER_VALIDATE_BOOLEAN, + 'backupuploads' => FILTER_VALIDATE_BOOLEAN, + ); + + foreach ( $boolean_fields_def as $key => $value ) { + \BackWPup_Option::update( $id, $key, ! empty( $post_data[ $key ] ) ); + } + // Parse and save directories to exclude. + $exclude_dirs_def = array( + 'backuprootexcludedirs' => array( + 'filter' => FILTER_SANITIZE_URL, + 'flags' => FILTER_FORCE_ARRAY, + ), + 'backuppluginsexcludedirs' => array( + 'filter' => FILTER_SANITIZE_URL, + 'flags' => FILTER_FORCE_ARRAY, + ), + 'backupcontentexcludedirs' => array( + 'filter' => FILTER_SANITIZE_URL, + 'flags' => FILTER_FORCE_ARRAY, + ), + 'backupthemesexcludedirs' => array( + 'filter' => FILTER_SANITIZE_URL, + 'flags' => FILTER_FORCE_ARRAY, + ), + 'backupuploadsexcludedirs' => array( + 'filter' => FILTER_SANITIZE_URL, + 'flags' => FILTER_FORCE_ARRAY, + ), + ); + foreach ( $exclude_dirs_def as $key => $filter ) { + $value = ! empty( $post_data[ $key ] ) && is_array( $post_data[ $key ] ) ? $post_data[ $key ] : array(); + \BackWPup_Option::update( $id, $key, $value ); + } + } + + /** + * Insert or update jobs. + * + * @uses BackWPup_Option::get_job_ids() + * @uses BackWPup_Option::get() + * @uses BackWPup_Option::update() + * @uses BackWPup_Admin::get_messages() + * @uses BackWPup_Admin::message() + * @uses BackWPup_Job::get_jobrun_url() + * @uses BackWPup_Page_Editjob::save_post_form() + * @uses MainWP_Child_Back_WP_Up::edit_form_post_save() + * @uses MainWP_Child_Back_WP_Up::check_backwpup_messages() + * + * @return array Response array containing job_id, changes & message array. + */ + protected function insert_or_update_jobs() { + + $settings = $_POST['settings']; + + if ( ! is_array( $settings ) || ! isset( $settings['value'] ) ) { + return array( 'error' => __( 'Missing array settings', 'mainwp-child' ) ); + } + + if ( ! isset( $settings['tab'] ) ) { + return array( 'error' => __( 'Missing tab', 'mainwp-child' ) ); + } + + if ( ! isset( $settings['job_id'] ) ) { + return array( 'error' => __( 'Missing job_id', 'mainwp-child' ) ); + } + + if ( ! class_exists( '\BackWPup' ) ) { + return array( 'error' => __( 'Install BackWPup on child website', 'mainwp-child' ) ); + } + + if ( $settings['job_id'] > 0 ) { + $job_id = intval( $settings['job_id'] ); + } else { + // generate jobid if not exists. + $newjobid = \BackWPup_Option::get_job_ids(); + sort( $newjobid ); + $job_id = end( $newjobid ) + 1; + } + + update_site_option( 'backwpup_messages', array() ); + + if ( isset( $settings['value']['backupdir'] ) && empty( $settings['value']['backupdir'] ) ) { + $backupdir = \BackWPup_Option::get( (int) $job_id, 'backupdir' ); + if ( ! empty( $backupdir ) ) { + $settings['value']['backupdir'] = $backupdir; + } + } + + foreach ( $settings['value'] as $key => $val ) { + $_POST[ $key ] = $val; + } + + if ( 'jobtype-FILE' == $settings['tab'] ) { + $this->edit_form_post_save( $settings['value'], $job_id ); + $messages = \BackWPup_Admin::get_messages(); + if ( empty( $messages['error'] ) ) { + $url = \BackWPup_Job::get_jobrun_url( 'runnowlink', $job_id ); + \BackWPup_Admin::message( sprintf( __( 'Changes for job %s saved.', 'mainwp-child' ), \BackWPup_Option::get( $job_id, 'name' ) ) . ' ' . __( 'Jobs overview', 'mainwp-child' ) . ' | ' . __( 'Run now', 'mainwp-child' ) . '' ); + } + } elseif ( 'dest-DROPBOX' == $settings['tab'] ) { + unset( $settings['value'] ); + \BackWPup_Page_Editjob::save_post_form( $settings['tab'], $job_id ); + } else { + \BackWPup_Page_Editjob::save_post_form( $settings['tab'], $job_id ); + } + + $return = $this->check_backwpup_messages(); + + if ( isset( $return['error'] ) ) { + return array( + 'success' => 1, + 'error_message' => __( 'Cannot save jobs: ' . $return['error'], 'mainwp-child' ), + ); + } + + if ( isset( $settings['value']['sugarrefreshtoken'] ) ) { + \BackWPup_Option::update( $job_id, 'sugarrefreshtoken', $settings['value']['sugarrefreshtoken'] ); + } + + if ( isset( $settings['value']['gdriverefreshtoken'] ) ) { + \BackWPup_Option::update( $job_id, 'gdriverefreshtoken', $settings['value']['gdriverefreshtoken'] ); + } + + if ( isset( $settings['value']['dbdumpspecialsetalltables'] ) && $settings['value']['dbdumpspecialsetalltables'] ) { + \BackWPup_Option::update( $job_id, 'dbdumpexclude', array() ); + } + + if ( isset( $settings['value']['dropboxtoken'] ) && isset( $settings['value']['dropboxroot'] ) ) { + \BackWPup_Option::update( $job_id, 'dropboxtoken', $settings['value']['dropboxtoken'] ); + \Option::update( $job_id, 'dropboxroot', $settings['value']['dropboxroot'] ); + } + + $changes_array = array(); + + foreach ( $settings['value'] as $key => $val ) { + $temp_value = \BackWPup_Option::get( $job_id, $key ); + if ( is_string( $temp_value ) ) { + if ( isset( $this->exclusions[ $settings['tab'] ] ) ) { + if ( ! in_array( $key, $this->exclusions[ $settings['tab'] ] ) && strcmp( $temp_value, $val ) != 0 ) { + $changes_array[ $key ] = $temp_value; + } + } elseif ( strcmp( $temp_value, $val ) != 0 ) { + $changes_array[ $key ] = $temp_value; + } + } + } + + return array( + 'success' => 1, + 'job_id' => $job_id, + 'changes' => $changes_array, + 'message' => $return['message'], + ); + } + + + /** + * Update settings. + * + * @uses BackWPup_Page_Settings() + * @uses BackWPup_Page_Settings::save_post_form() + * @uses BackWPup_Pro_Settings_APIKeys::get_instance() + * @uses BackWPup_Pro_Settings_APIKeys::save_form() + * @uses MainWP_Child_Back_WP_Up::check_backwpup_messages() + * + * @return array Response array success, changes, message[]. + */ + protected function update_settings() { + $settings = $_POST['settings']; + + if ( ! is_array( $settings ) || ! isset( $settings['value'] ) ) { + return array( 'error' => __( 'Missing array settings', 'mainwp-child' ) ); + } + + if ( ! class_exists( '\BackWPup' ) ) { + return array( 'error' => __( 'Install BackWPup on child website', 'mainwp-child' ) ); + } + + if ( isset( $settings['value']['is_premium'] ) && 1 == $settings['value']['is_premium'] && false == $this->is_backwpup_pro ) { + return array( 'error' => __( 'You try to use pro version settings in non pro plugin version. Please install pro version on child and try again.', 'mainwp-child' ) ); + } + + foreach ( $settings['value'] as $key => $val ) { + $_POST[ $key ] = $val; + } + + update_site_option( 'backwpup_messages', array() ); + + $settings_views = array(); + $settings_updaters = array(); + + $backwpup = new \BackWPup_Page_Settings( $settings_views, $settings_updaters ); + $backwpup->save_post_form(); + + if ( class_exists( '\BackWPup_Pro' ) ) { + $pro_settings = \BackWPup_Pro_Settings_APIKeys::get_instance(); + $pro_settings->save_form(); + + } + $return = $this->check_backwpup_messages(); + + if ( isset( $return['error'] ) ) { + return array( 'error' => __( 'Cannot save settings: ' . $return['error'], 'mainwp-child' ) ); + } + + $exclusions = array( + 'is_premium', + 'dropboxappsecret', + 'dropboxsandboxappsecret', + 'sugarsyncsecret', + 'googleclientsecret', + 'override', + 'httpauthpassword', + ); + + $changes_array = array(); + + foreach ( $settings['value'] as $key => $val ) { + + $temp_value = get_site_option( 'backwpup_cfg_' . $key, '' ); + if ( ! in_array( $key, $exclusions ) && strcmp( $temp_value, $val ) != 0 ) { + $changes_array[ $key ] = $temp_value; + } + } + + return array( + 'success' => 1, + 'changes' => $changes_array, + 'message' => $return['message'], + ); + } + + /** + * Check BackWPup Message. + * + * @return array|string[] Returns an empty array or Error[], Message[]. + */ + protected function check_backwpup_messages() { + $message = get_site_option( 'backwpup_messages', array() ); + update_site_option( 'backwpup_messages', array() ); + + if ( isset( $message['error'] ) ) { + return array( 'error' => implode( ', ', $message['error'] ) ); + } elseif ( isset( $message['updated'] ) ) { + return array( 'message' => $message['updated'] ); + } else { + return array( 'error' => 'Generic error' ); + } + } } // phpcs:disable Generic.Files.OneObjectStructurePerFile -- fake class if ( ! class_exists( 'MainWP_Fake_Wp_Screen' ) ) { - class MainWP_Fake_Wp_Screen { - public $action; - public $base; - public $id; - } -} + /** + * Class MainWP_Fake_Wp_Screen + * + * @used-by MainWP_Child_Back_WP_Up::wp_list_table_dependency() + */ + class MainWP_Fake_Wp_Screen { + /** @var string Action. */ + public $action; + /** @var string Base url. */ + public $base; + /** @var int ID*/ + public $id; + } +} \ No newline at end of file diff --git a/class/class-mainwp-child-install.php b/class/class-mainwp-child-install.php index 7d985c8..5571633 100644 --- a/class/class-mainwp-child-install.php +++ b/class/class-mainwp-child-install.php @@ -17,15 +17,13 @@ namespace MainWP\Child; class MainWP_Child_Install { /** - * Public static variable to hold the single instance of the class. + * Public static variable to hold the single instance of MainWP_Child_Install. * * @var mixed Default null */ protected static $instance = null; /** - * Method get_class_name() - * * Get class name. * * @return string __CLASS__ Class name. @@ -35,19 +33,17 @@ class MainWP_Child_Install { } /** - * Method __construct() + * MainWP_Child_Install constructor * - * Run any time MainWP_Child is called. + * Run any time new MainWP_Child_Install is created. */ public function __construct() { } /** - * Method get_instance() + * Create a public static instance of MainWP_Child_Install. * - * Create a public static instance. - * - * @return mixed Class instance. + * @return MainWP_Child_Install|mixed|null */ public static function get_instance() { if ( null === self::$instance ) { @@ -376,9 +372,6 @@ class MainWP_Child_Install { * @used-by install_plugin_theme() Plugin & Theme Installation functions. */ private function after_installed( $result ) { - if ( empty( $result ) || is_wp_error( $result ) ) { - return false; - } $args = array( 'success' => 1, 'action' => 'install', diff --git a/class/class-mainwp-child-posts.php b/class/class-mainwp-child-posts.php index 6f909ce..fcc0409 100644 --- a/class/class-mainwp-child-posts.php +++ b/class/class-mainwp-child-posts.php @@ -1,33 +1,59 @@ comments_and_clauses = ''; $this->posts_where_suffix = ''; } + /** + * Create a public static instance of MainWP_Child_Posts. + * + * @return MainWP_Child_Posts|null + */ public static function get_instance() { if ( null === self::$instance ) { self::$instance = new self(); @@ -37,7 +63,18 @@ class MainWP_Child_Posts { } - + /** + * Get recent posts. + * + * @param array $pAllowedStatuses Array of allowed post statuses. + * @param int $pCount Number of posts. + * @param string $type Post type. + * @param null $extra Extra tokens. + * + * @uses \MainWP\Child\MainWP_Child_Posts::get_recent_posts_int() + * + * @return array $allPost Return array of recent posts. + */ public function get_recent_posts( $pAllowedStatuses, $pCount, $type = 'post', $extra = null ) { $allPosts = array(); if ( null !== $pAllowedStatuses ) { @@ -51,6 +88,24 @@ class MainWP_Child_Posts { return $allPosts; } + /** + * Initiate get recent posts. + * + * @param string $status Post status. + * @param int $pCount Number of posts. + * @param string $type Post type. + * @param array $allPosts All posts array. + * @param null $extra Extra tokens. + * + * @return array $allPosts[] Array of all posts. + * + * @uses \WPSEO_Link_Column_Count() + * @uses \WPSEO_Meta() + * @uses \MainWP_WordPress_SEO::instance()::parse_column_score() + * @uses \MainWP_WordPress_SEO::instance()->parse_column_score_readability() + * + * @uses \MainWP\Child\MainWP_Child_Posts::get_out_post() + */ public function get_recent_posts_int( $status, $pCount, $type = 'post', &$allPosts, $extra = null ) { $args = array( @@ -92,8 +147,7 @@ class MainWP_Child_Posts { $post_ids[] = $post->ID; } - /* - * + /** * Credits * * Plugin-Name: Yoast SEO @@ -104,7 +158,6 @@ class MainWP_Child_Posts { * * The code is used for the MainWP WordPress SEO Extension * Extension URL: https://mainwp.com/extension/wordpress-seo/ - * */ $link_count = new \WPSEO_Link_Column_Count(); $link_count->set( $post_ids ); @@ -124,6 +177,14 @@ class MainWP_Child_Posts { } } + /** + * Build Post. + * + * @param array $post Post array. + * @param string $extra Post date & time. + * @param array $tokens Post tokens. + * @return array $outPost Return completed post. + */ private function get_out_post( $post, $extra, $tokens ) { $outPost = array(); $outPost['id'] = $post->ID; @@ -178,15 +239,33 @@ class MainWP_Child_Posts { return $outPost; } + /** + * Get all posts. + * + * @uses \MainWP\Child\MainWP_Child_Posts::get_all_posts_by_type() + */ public function get_all_posts() { $post_type = ( isset( $_POST['post_type'] ) ? $_POST['post_type'] : 'post' ); $this->get_all_posts_by_type( $post_type ); } + /** + * Get all pages. + * + * @uses \MainWP\Child\MainWP_Child_Posts::get_all_posts_by_type() + */ public function get_all_pages() { $this->get_all_posts_by_type( 'page' ); } + /** + * Append the Post's SQL WHERE clause suffix. + * + * @param $where Post's SQL WHERE clause. + * @return string $where The full SQL WHERE clause with the appended suffix. + * + * @uses \MainWP\Child\MainWP_Child_Posts::posts_where_suffix() + */ public function posts_where( $where ) { if ( $this->posts_where_suffix ) { $where .= ' ' . $this->posts_where_suffix; @@ -195,7 +274,17 @@ class MainWP_Child_Posts { return $where; } + /** + * Get all posts by type. + * + * @param string $type Post type. + * + * @uses \MainWP\Child\MainWP_Child_Posts::posts_where_suffix() + * @uses \MainWP\Child\MainWP_Helper::write() + */ public function get_all_posts_by_type( $type ) { + + /** @global $wpdb wpdb */ global $wpdb; add_filter( 'posts_where', array( &$this, 'posts_where' ) ); @@ -260,6 +349,13 @@ class MainWP_Child_Posts { MainWP_Helper::write( $rslt ); } + /** + * Build New Post. + * + * @uses \MainWP\Child\MainWP_Child_Posts::create_post() + * @uses \MainWP\Child\ainWP_Helper::error() + * @uses \MainWP\Child\MainWP_Helper::write() + */ public function new_post() { $new_post = maybe_unserialize( base64_decode( $_POST['new_post'] ) ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for http encode compatible.. $post_custom = maybe_unserialize( base64_decode( $_POST['post_custom'] ) ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for http encode compatible.. @@ -293,6 +389,14 @@ class MainWP_Child_Posts { MainWP_Helper::write( $information ); } + /** + * Post Action. + * + * @uses \MainWP\Child\MainWP_Child_Links_Checker() + * @uses \MainWP\Child\MainWP_Child_Posts::get_post_edit() + * @uses \MainWP\Child\MainWP_Child_Posts::get_page_edit() + * @uses \MainWP\Child\MainWP_Helper::write() + */ public function post_action() { $action = $_POST['action']; $postId = $_POST['id']; @@ -369,6 +473,13 @@ class MainWP_Child_Posts { MainWP_Helper::write( $information ); } + /** + * Get post edit data. + * + * @param string $id Post ID. + * + * @return array|bool Return $post_data or FALSE on failure. + */ public function get_post_edit( $id ) { $post = get_post( $id ); if ( $post ) { @@ -456,6 +567,13 @@ class MainWP_Child_Posts { return false; } + /** + * Get page edit data. + * + * @param string $id Page ID. + * + * @return array|bool Return $post_data or FALSE on failure. + */ public function get_page_edit( $id ) { $post = get_post( $id ); if ( $post ) { @@ -487,18 +605,18 @@ class MainWP_Child_Posts { $post_gallery_images = array(); if ( is_array( $galleries ) && isset( $galleries['ids'] ) ) { - $attached_images = explode( ',', $galleries['ids'] ); + $attached_images = explode( ',', $galleries['ids'] ); foreach ( $attached_images as $attachment_id ) { - $attachment = get_post( $attachment_id ); + $attachment = get_post( $attachment_id ); if ( $attachment ) { - $post_gallery_images[] = array( - 'id' => $attachment_id, - 'alt' => get_post_meta( $attachment->ID, '_wp_attachment_image_alt', true ), - 'caption' => $attachment->post_excerpt, - 'description' => $attachment->post_content, - 'src' => $attachment->guid, - 'title' => $attachment->post_title, - ); + $post_gallery_images[] = array( + 'id' => $attachment_id, + 'alt' => get_post_meta( $attachment->ID, '_wp_attachment_image_alt', true ), + 'caption' => $attachment->post_excerpt, + 'description' => $attachment->post_content, + 'src' => $attachment->guid, + 'title' => $attachment->post_title, + ); } } } @@ -518,7 +636,34 @@ class MainWP_Child_Posts { return false; } - private function create_post( $new_post, $post_custom, $post_category, $post_featured_image, $upload_dir, $post_tags, $others = array() ) { + /** + * Create new post. + * + * @param array $new_post Post data array. + * @param array $post_custom Post custom meta data. + * @param string $post_category Post categories. + * @param string $post_featured_image Post featured image. + * @param string $upload_dir Upload directory. + * @param string $post_tags Post tags. + * @param array $others Other data. + * + * @return array|string[] $ret Return success array, permalink & Post ID. + * + * @uses \MainWP\Child\MainWP_Child_Posts::set_post_custom_data() + * @uses \MainWP\Child\MainWP_Child_Posts::update_found_images() + * @uses \MainWP\Child\MainWP_Child_Posts::create_has_shortcode_gallery() + * @uses \MainWP\Child\MainWP_Child_Posts::create_post_plus() + * @uses \MainWP\Child\MainWP_Child_Posts::update_post_data() + */ + private function create_post( + $new_post, + $post_custom, + $post_category, + $post_featured_image, + $upload_dir, + $post_tags, + $others = array() + ) { /** * Hook: `mainwp_before_post_update` @@ -531,10 +676,14 @@ class MainWP_Child_Posts { * @param string $post_tags � Post tags. */ do_action( 'mainwp_before_post_update', $new_post, $post_custom, $post_category, $post_tags ); + $edit_post_id = 0; $is_post_plus = false; + $this->set_post_custom_data( $new_post, $post_custom, $post_tags, $edit_post_id, $is_post_plus ); + require_once ABSPATH . 'wp-admin/includes/post.php'; + if ( $edit_post_id ) { $user_id = wp_check_post_lock( $edit_post_id ); if ( $user_id ) { @@ -543,17 +692,23 @@ class MainWP_Child_Posts { return array( 'error' => $error ); } } - $check_image_existed = $edit_post_id ? true : false; // if editing post then will check if image existed. + + // if editing post then will check if image existed. + $check_image_existed = $edit_post_id ? true : false; + $this->update_found_images( $new_post, $upload_dir, $check_image_existed ); $this->create_has_shortcode_gallery( $new_post ); + if ( $is_post_plus ) { $this->create_post_plus( $new_post, $post_custom ); } + // Save the post to the WP. remove_filter( 'content_save_pre', 'wp_filter_post_kses' ); // to fix brake scripts or html. $post_status = $new_post['post_status']; // save post_status. $new_post['post_status'] = 'auto-draft'; // to fix reports, to log as created post. - // update post. + + // Update post. if ( $edit_post_id ) { // check if post existed. $current_post = get_post( $edit_post_id ); @@ -591,6 +746,17 @@ class MainWP_Child_Posts { return $ret; } + /** + * Set custom post data. + * + * @param array $new_post Post data array. + * @param array $post_custom Post custom meta data. + * @param string $post_tags Post tags. + * @param string $edit_post_id Edit Post ID. + * @param bool $is_post_plus TRUE|FALSE, Whether or not this came from MainWP Post Plus Extension. + * + * @uses \MainWP\Child\MainWP_Child_Posts::update_wp_rocket_custom_post() + */ private function set_post_custom_data( &$new_post, $post_custom, $post_tags, &$edit_post_id, &$is_post_plus ) { global $current_user; @@ -600,8 +766,7 @@ class MainWP_Child_Posts { // current user may be connected admin or alternative admin. $current_uid = $current_user->ID; - // Set up a new post (adding addition information). - + // Set up a new post (adding additional information). $new_post['post_author'] = isset( $new_post['post_author'] ) && ! empty( $new_post['post_author'] ) ? $new_post['post_author'] : $current_uid; if ( isset( $new_post['custom_post_author'] ) && ! empty( $new_post['custom_post_author'] ) ) { @@ -633,6 +798,23 @@ class MainWP_Child_Posts { } } + /** + * Update post data. + * + * @param string $new_post_id New post ID. + * @param array $post_custom Post custom meta data. + * @param string $post_category Post categories. + * @param string $post_featured_image Post featured image. + * @param bool $check_image_existed TRUE|FALSE, Whether or not featured image already exists. + * @param bool $is_post_plus TRUE|FALSE, Whether or not this came from MainWP Post Plus Extension. + * + * @uses \MainWP\Child\MainWP_Child_Posts::set_custom_post_fields() + * @uses \MainWP\Child\MainWP_Child_Posts::create_seo_extension_activated() + * @uses \MainWP\Child\MainWP_Child_Posts::create_set_categories() + * @uses \MainWP\Child\MainWP_Child_Posts::create_featured_image() + * @uses \MainWP\Child\MainWP_Child_Posts::post_plus_update_author() + * @uses \MainWP\Child\MainWP_Child_Posts::post_plus_update_categories() + */ private function update_post_data( $new_post_id, $post_custom, $post_category, $post_featured_image, $check_image_existed, $is_post_plus ) { $seo_ext_activated = false; @@ -670,6 +852,14 @@ class MainWP_Child_Posts { } } + /** + * Update WPRocket custom post. + * + * @param array $post_custom Post custom meta data. + * + * @uses \MainWP\Child\MainWP_Child_WP_Rocket::instance()::is_activated() + * @uses \get_rocket_option() + */ private function update_wp_rocket_custom_post( &$post_custom ) { // Options fields. $wprocket_fields = array( @@ -705,9 +895,19 @@ class MainWP_Child_Posts { } } + /** + * Search for all the images added to the new post. + * + * @param array $new_post Post data array. + * @param string $upload_dir Upload directory. + * @param bool $check_image_existed TRUE|FALSE, Whether or not featured image already exists. + * + * @uses \MainWP\Child\MainWP_Utility::upload_image() + * @uses \MainWP\Child\MainWP_Helper::log_debug() + */ private function update_found_images( &$new_post, $upload_dir, $check_image_existed ) { - // Search for all the images added to the new post. Some images have a href tag to click to navigate to the image.. we need to replace this too. + // Some images have a href tag to click to navigate to the image.. we need to replace this too. $foundMatches = preg_match_all( '/(]+href=\"(.*?)\"[^>]*>)?(\/]*src=\"((.*?)(png|gif|jpg|jpeg))\")/ix', $new_post['post_content'], $matches, PREG_SET_ORDER ); if ( $foundMatches > 0 ) { // We found images, now to download them so we can start balbal. @@ -751,6 +951,14 @@ class MainWP_Child_Posts { } } + /** + * Create shortcode image gallery. + * + * @param array $new_post Post data array. + * + * @uses \MainWP\Child\MainWP_Utility::upload_image() + * @uses \Exception() + */ private function create_has_shortcode_gallery( &$new_post ) { if ( has_shortcode( $new_post['post_content'], 'gallery' ) ) { @@ -760,7 +968,7 @@ class MainWP_Child_Posts { $post_gallery_images = unserialize( base64_decode( $_POST['post_gallery_images'] ) ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for http encode compatible.. if ( is_array( $post_gallery_images ) ) { foreach ( $post_gallery_images as $gallery ) { - if ( isset( $gallery['src'] ) ) { + if \ Exception ( isset( $gallery['src'] ) ) { try { $upload = MainWP_Utility::upload_image( $gallery['src'], $gallery ); // Upload image to WP. if ( null !== $upload ) { @@ -793,6 +1001,12 @@ class MainWP_Child_Posts { } } + /** + * Create post plus post. + * + * @param array $new_post Post data array. + * @param array $post_custom Post custom meta data. + */ private function create_post_plus( &$new_post, $post_custom ) { $random_publish_date = isset( $post_custom['_saved_draft_random_publish_date'] ) ? $post_custom['_saved_draft_random_publish_date'] : false; $random_publish_date = is_array( $random_publish_date ) ? current( $random_publish_date ) : null; @@ -829,6 +1043,12 @@ class MainWP_Child_Posts { } } + /** + * Update post plus author. + * + * @param string $new_post_id New post ID. + * @param array $post_custom Post custom meta data. + */ private function post_plus_update_author( $new_post_id, $post_custom ) { $random_privelege = isset( $post_custom['_saved_draft_random_privelege'] ) ? $post_custom['_saved_draft_random_privelege'] : null; $random_privelege = is_array( $random_privelege ) ? current( $random_privelege ) : null; @@ -856,6 +1076,12 @@ class MainWP_Child_Posts { } } + /** + * Update post plus categories. + * + * @param string $new_post_id New post ID. + * @param array $post_custom Post custom meta data. + */ private function post_plus_update_categories( $new_post_id, $post_custom ) { $random_category = isset( $post_custom['_saved_draft_random_category'] ) ? $post_custom['_saved_draft_random_category'] : false; $random_category = is_array( $random_category ) ? current( $random_category ) : null; @@ -880,6 +1106,11 @@ class MainWP_Child_Posts { } } + /** + * @param string $new_post_id New post ID. + * @param string $post_category Post category. + * @param bool $post_to_only TRUE|FALSE, Whether or not to post only to this category. + */ private function create_set_categories( $new_post_id, $post_category, $post_to_only ) { // If categories exist, create them (second parameter of wp_create_categories adds the categories to the post). @@ -905,6 +1136,14 @@ class MainWP_Child_Posts { } } + /** + * Set custom post fields. + * + * @param string $new_post_id New post ID. + * @param array $post_custom Post custom meta data. + * @param bool $seo_ext_activated TRUE|FALSE, Whether or not Yoast SEO is activateed or not. + * @param bool $post_to_only TRUE|FALSE, Whether or not to post only to this category. + */ private function set_custom_post_fields( $new_post_id, $post_custom, $seo_ext_activated, &$post_to_only ) { // Set custom fields. @@ -970,6 +1209,16 @@ class MainWP_Child_Posts { } } + /** + * Update Yoast SEO Extension meta. + * + * @param string $new_post_id New post ID. + * @param array $post_custom Post custom meta data. + * + * @uses \MainWP\Child\MainWP_Utility::upload_image() + * @uses \WPSEO_Meta::$meta_prefix() + * @uses \Exception() + */ private function create_seo_extension_activated( $new_post_id, $post_custom ) { $_seo_opengraph_image = isset( $post_custom[ \WPSEO_Meta::$meta_prefix . 'opengraph-image' ] ) ? $post_custom[ \WPSEO_Meta::$meta_prefix . 'opengraph-image' ] : array(); @@ -993,6 +1242,16 @@ class MainWP_Child_Posts { } } + /** + * Create featured image. + * + * @param string $new_post_id New post ID. + * @param string $post_featured_image Post featured image. + * @param bool $check_image_existed TRUE|FALSE, Whether or not featured image already exists. + * + * @uses \MainWP\Child\MainWP_Utility::upload_image() + * @uses \Excepsion() + */ private function create_featured_image( $new_post_id, $post_featured_image, $check_image_existed ) { $featured_image_exist = false; diff --git a/class/class-mainwp-child-updraft-plus-backups.php b/class/class-mainwp-child-updraft-plus-backups.php index b233b3d..c8e6bb3 100644 --- a/class/class-mainwp-child-updraft-plus-backups.php +++ b/class/class-mainwp-child-updraft-plus-backups.php @@ -1,4 +1,13 @@ is_plugin_installed = true; @@ -42,7 +66,11 @@ class MainWP_Child_Updraft_Plus_Backups { add_filter( 'updraftplus_save_last_backup', array( __CLASS__, 'hook_updraft_plus_save_last_backup' ) ); } - public static function hook_updraft_plus_save_last_backup( $last_backup ) { + /** + * @param $last_backup + * @return array + */ + public static function hook_updraft_plus_save_last_backup($last_backup ) { if ( ! is_array( $last_backup ) ) { return $last_backup; } @@ -56,7 +84,12 @@ class MainWP_Child_Updraft_Plus_Backups { return $last_backup; } - public function sync_others_data( $information, $data = array() ) { + /** + * @param $information + * @param array $data + * @return mixed + */ + public function sync_others_data($information, $data = array() ) { try { if ( isset( $data['syncUpdraftData'] ) ) { $info = $data['syncUpdraftData']; @@ -80,7 +113,10 @@ class MainWP_Child_Updraft_Plus_Backups { return $information; } - public function action() { + /** + * + */ + public function action() { $information = array(); if ( ! $this->is_plugin_installed ) { $information['error'] = 'NO_UPDRAFTPLUS'; @@ -169,7 +205,10 @@ class MainWP_Child_Updraft_Plus_Backups { MainWP_Helper::write( $information ); } - public function set_showhide() { + /** + * @return mixed + */ + public function set_showhide() { $hide = isset( $_POST['showhide'] ) && ( 'hide' === $_POST['showhide'] ) ? 'hide' : ''; MainWP_Helper::update_option( 'mainwp_updraftplus_hide_plugin', $hide ); $information['result'] = 'SUCCESS'; @@ -177,7 +216,10 @@ class MainWP_Child_Updraft_Plus_Backups { return $information; } - private function get_settings_keys() { + /** + * @return string[] + */ + private function get_settings_keys() { return array( 'updraft_autobackup_default', 'updraftplus_dismissedautobackup', @@ -236,7 +278,10 @@ class MainWP_Child_Updraft_Plus_Backups { ); } - private function do_vault_connect() { + /** + * @return array + */ + private function do_vault_connect() { $vault_settings = UpdraftPlus_Options::get_updraft_option( 'updraft_updraftvault' ); if ( is_array( $vault_settings ) && ! empty( $vault_settings['token'] ) && ! empty( $vault_settings['email'] ) ) { return array( @@ -265,7 +310,11 @@ class MainWP_Child_Updraft_Plus_Backups { } - private function connected_html() { + /** + * @return string + * @throws Exception + */ + private function connected_html() { MainWP_Helper::check_classes_exists( 'UpdraftPlus_Options' ); MainWP_Helper::check_methods( 'UpdraftPlus_Options', 'get_updraft_option' ); @@ -295,7 +344,13 @@ class MainWP_Child_Updraft_Plus_Backups { // Returns either true (in which case the Vault token will be stored), or false|\WP_Error. - private function vault_connect( $email, $password ) { + + /** + * @param $email + * @param $password + * @return bool|WP_Error + */ + private function vault_connect($email, $password ) { global $updraftplus; $vault_mothership = 'https://vault.updraftplus.com/plugin-info/'; @@ -372,7 +427,11 @@ class MainWP_Child_Updraft_Plus_Backups { } // This method also gets called directly, so don't add code that assumes that it's definitely an AJAX situation. - public function vault_disconnect() { + + /** + * @throws Exception + */ + public function vault_disconnect() { $vault_settings = UpdraftPlus_Options::get_updraft_option( 'updraft_updraftvault' ); UpdraftPlus_Options::update_updraft_option( 'updraft_updraftvault', array() ); global $updraftplus; @@ -411,7 +470,10 @@ class MainWP_Child_Updraft_Plus_Backups { } } - public function required_files() { + /** + * + */ + public 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'; @@ -423,7 +485,10 @@ class MainWP_Child_Updraft_Plus_Backups { } } - public function save_settings() { + /** + * @return array + */ + public function save_settings() { $settings = maybe_unserialize( base64_decode( $_POST['settings'] ) ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for http encode compatible.. $keys_filter = $this->get_settings_keys(); @@ -651,7 +716,11 @@ class MainWP_Child_Updraft_Plus_Backups { return $out; } - public function replace_tokens( $str = '' ) { + /** + * @param string $str + * @return string|string[] + */ + public function replace_tokens($str = '' ) { if ( stripos( $str, '%sitename%' ) !== false ) { $replace_token = get_bloginfo( 'name' ); $replace_token = sanitize_file_name( $replace_token ); @@ -668,7 +737,10 @@ class MainWP_Child_Updraft_Plus_Backups { return $str; } - public function addons_connect() { + /** + * @return array|string[] + */ + public function addons_connect() { if ( ! defined( 'UDADDONS2_SLUG' ) ) { if ( is_file( UPDRAFTPLUS_DIR . '/udaddons/updraftplus-addons.php' ) ) { require_once UPDRAFTPLUS_DIR . '/udaddons/updraftplus-addons.php'; @@ -693,7 +765,11 @@ class MainWP_Child_Updraft_Plus_Backups { return $out; } - public function update_wpmu_options( $value ) { + /** + * @param $value + * @return bool|void + */ + public function update_wpmu_options($value ) { if ( ! UpdraftPlus_Options::user_can_manage() ) { return; @@ -713,7 +789,12 @@ class MainWP_Child_Updraft_Plus_Backups { } // Funnelling through here a) allows for future flexibility and b) allows us to migrate elegantly from the previous non-MU-friendly setup. - public function addons2_get_option( $option ) { + + /** + * @param $option + * @return mixed + */ + public function addons2_get_option($option ) { $val = get_site_option( $option ); // On multisite, migrate options into the site options. if ( false === $val && is_multisite() ) { @@ -740,11 +821,20 @@ class MainWP_Child_Updraft_Plus_Backups { return $val; } - public function addons2_update_option( $option, $val ) { + /** + * @param $option + * @param $val + * @return mixed + */ + public function addons2_update_option($option, $val ) { return update_site_option( $option, $val ); } - public function options_validate( $input ) { + /** + * @param $input + * @return mixed + */ + public function options_validate($input ) { // See: http://codex.wordpress.org/Function_Reference/add_settings_error. // When the options are re-saved, clear any previous cache of the connection status. $ehash = substr( md5( $input['email'] ), 0, 23 ); @@ -882,11 +972,18 @@ class MainWP_Child_Updraft_Plus_Backups { ); } - private function cb_get_name_base_type( $a ) { + /** + * @param $a + * @return mixed + */ + private function cb_get_name_base_type($a ) { return $a[0]; } - public function backup_now() { + /** + * + */ + public function backup_now() { global $updraftplus; $backupnow_nocloud = ( empty( $_REQUEST['backupnow_nocloud'] ) ) ? false : true; $event = ( ! empty( $_REQUEST['backupnow_nofiles'] ) ) ? 'updraft_backupnow_backup_database' : ( ( ! empty( $_REQUEST['backupnow_nodb'] ) ) ? 'updraft_backupnow_backup' : 'updraft_backupnow_backup_all' ); @@ -917,7 +1014,10 @@ class MainWP_Child_Updraft_Plus_Backups { die; } - public function activejobs_list() { + /** + * @return array + */ + public function activejobs_list() { global $updraftplus; $download_status = array(); if ( ! empty( $_REQUEST['downloaders'] ) ) { @@ -964,7 +1064,10 @@ class MainWP_Child_Updraft_Plus_Backups { } - private function last_backup_html() { + /** + * @return array + */ + private function last_backup_html() { global $updraftplus; @@ -1021,7 +1124,12 @@ class MainWP_Child_Updraft_Plus_Backups { ); } - private function get_updraft_data( $with_hist = true ) { + /** + * @param bool $with_hist + * @return array|bool + * @throws Exception + */ + private function get_updraft_data($with_hist = true ) { global $updraftplus; if ( empty( $updraftplus ) && class_exists( 'UpdraftPlus' ) ) { @@ -1103,7 +1211,11 @@ class MainWP_Child_Updraft_Plus_Backups { } - private function next_scheduled_backups() { + /** + * @return array + * @throws Exception + */ + private function next_scheduled_backups() { global $updraftplus; // UNIX timestamp. $next_scheduled_backup = wp_next_scheduled( 'updraft_backup' ); @@ -1187,7 +1299,10 @@ class MainWP_Child_Updraft_Plus_Backups { return $out; } - private function deleteset() { + /** + * @return array + */ + private function deleteset() { global $updraftplus; if ( method_exists( $updraftplus, 'get_backup_history' ) ) { @@ -1318,7 +1433,11 @@ class MainWP_Child_Updraft_Plus_Backups { ); } - public function build_historystatus() { + /** + * @return array + * @throws Exception + */ + public function build_historystatus() { MainWP_Helper::check_classes_exists( 'UpdraftPlus_Backup_History' ); MainWP_Helper::check_methods( 'UpdraftPlus_Backup_History', 'get_history' ); @@ -1342,7 +1461,12 @@ class MainWP_Child_Updraft_Plus_Backups { ); } - public function historystatus( $remotescan = null, $rescan = null ) { + /** + * @param null $remotescan + * @param null $rescan + * @return array + */ + public function historystatus($remotescan = null, $rescan = null ) { global $updraftplus; $remotescan = ( null !== $remotescan ) ? $remotescan : $_POST['remotescan']; @@ -1373,7 +1497,10 @@ class MainWP_Child_Updraft_Plus_Backups { } - public function updraft_download_backup() { + /** + * @return array|string|string[] + */ + public function updraft_download_backup() { set_time_limit( 900 ); @@ -1530,7 +1657,13 @@ class MainWP_Child_Updraft_Plus_Backups { } // Pass only a single service, as a string, into this function. - private function download_file( $file, $service ) { + + /** + * @param $file + * @param $service + * @return bool + */ + private function download_file($file, $service ) { global $updraftplus; @@ -1557,7 +1690,12 @@ class MainWP_Child_Updraft_Plus_Backups { } // This options filter removes ABSPATH off the front of updraft_dir, if it is given absolutely and contained within it. - public function prune_updraft_dir_prefix( $updraft_dir ) { + + /** + * @param $updraft_dir + * @return false|string + */ + public function prune_updraft_dir_prefix($updraft_dir ) { if ( '/' == substr( $updraft_dir, 0, 1 ) || '\\' === substr( $updraft_dir, 0, 1 ) || preg_match( '/^[a-zA-Z]:/', $updraft_dir ) ) { $wcd = trailingslashit( WP_CONTENT_DIR ); if ( strpos( $updraft_dir, $wcd ) === 0 ) { @@ -1569,7 +1707,10 @@ class MainWP_Child_Updraft_Plus_Backups { } - public function restore_alldownloaded() { // phpcs:ignore -- third party credit. + /** + * @return array + */ + public function restore_alldownloaded() { // phpcs:ignore -- third party credit. global $updraftplus; if ( method_exists( $updraftplus, 'get_backup_history' ) ) { @@ -1734,36 +1875,59 @@ class MainWP_Child_Updraft_Plus_Backups { } } - public function option_filter_template( $val ) { + /** + * @param $val + * @return mixed + */ + public function option_filter_template($val ) { global $updraftplus; return $updraftplus->option_filter_get( 'template' ); } - public function option_filter_stylesheet( $val ) { + /** + * @param $val + * @return mixed + */ + public function option_filter_stylesheet($val ) { global $updraftplus; return $updraftplus->option_filter_get( 'stylesheet' ); } - public function option_filter_template_root( $val ) { + /** + * @param $val + * @return mixed + */ + public function option_filter_template_root($val ) { global $updraftplus; return $updraftplus->option_filter_get( 'template_root' ); } - public function option_filter_stylesheet_root( $val ) { + /** + * @param $val + * @return mixed + */ + public function option_filter_stylesheet_root($val ) { global $updraftplus; return $updraftplus->option_filter_get( 'stylesheet_root' ); } - private function print_delete_old_dirs_form() { + /** + * + */ + private function print_delete_old_dirs_form() { echo '' . esc_html__( 'Delete Old Directories', 'updraftplus' ) . ''; } - private function delete_old_dirs_go( $show_return = true ) { + /** + * @param bool $show_return + * @return array + */ + private function delete_old_dirs_go($show_return = true ) { ob_start(); echo ( $show_return ) ? '

UpdraftPlus - ' . esc_html__( 'Remove old directories', 'updraftplus' ) . '

' : '

' . esc_html__( 'Remove old directories', 'updraftplus' ) . '

'; @@ -1785,7 +1949,11 @@ class MainWP_Child_Updraft_Plus_Backups { } // deletes the -old directories that are created when a backup is restored. - private function delete_old_dirs() { + + /** + * @return bool + */ + private function delete_old_dirs() { global $wp_filesystem, $updraftplus; $credentials = request_filesystem_credentials( wp_nonce_url( UpdraftPlus_Options::admin_page_url() . '?page=updraftplus&action=updraft_delete_old_dirs', 'updraftplus-credentialtest-nonce' ) ); WP_Filesystem( $credentials ); @@ -1822,7 +1990,12 @@ class MainWP_Child_Updraft_Plus_Backups { return $ret && $ret3 && $ret4; } - private function delete_old_dirs_dir( $dir, $wpfs = true ) { + /** + * @param $dir + * @param bool $wpfs + * @return bool + */ + private function delete_old_dirs_dir($dir, $wpfs = true ) { $dir = trailingslashit( $dir ); @@ -1866,11 +2039,22 @@ class MainWP_Child_Updraft_Plus_Backups { } - public function show_admin_warning( $message, $class = 'updated' ) { + /** + * @param $message + * @param string $class + */ + public function show_admin_warning($message, $class = 'updated' ) { echo '
' . "

$message

"; } - private function analyse_db_file_old( $timestamp, $res, $db_file = false, $header_only = false ) { // phpcs:ignore -- third party credit. + /** + * @param $timestamp + * @param $res + * @param bool $db_file + * @param bool $header_only + * @return array[] + */ + private function analyse_db_file_old($timestamp, $res, $db_file = false, $header_only = false ) { // phpcs:ignore -- third party credit. $mess = array(); $warn = array(); @@ -2102,7 +2286,14 @@ class MainWP_Child_Updraft_Plus_Backups { } - public function analyse_db_file( $timestamp, $res, $db_file = false, $header_only = false ) { // phpcs:ignore -- third party credit. + /** + * @param $timestamp + * @param $res + * @param bool $db_file + * @param bool $header_only + * @return array[] + */ + public function analyse_db_file($timestamp, $res, $db_file = false, $header_only = false ) { // phpcs:ignore -- third party credit. global $updraftplus; $mess = array(); @@ -2511,7 +2702,13 @@ class MainWP_Child_Updraft_Plus_Backups { } - private function gzopen_for_read( $file, &$warn, &$err ) { + /** + * @param $file + * @param $warn + * @param $err + * @return bool|false|resource + */ + private function gzopen_for_read($file, &$warn, &$err ) { if ( ! function_exists( 'gzopen' ) || ! function_exists( 'gzread' ) ) { $missing = ''; if ( ! function_exists( 'gzopen' ) ) { @@ -2600,7 +2797,12 @@ class MainWP_Child_Updraft_Plus_Backups { return $what_to_return; } - private function existing_backup_table( $backup_history = false ) { // phpcs:ignore -- third party credit. + /** + * @param bool $backup_history + * @return string + * @throws Exception + */ + private function existing_backup_table($backup_history = false ) { // phpcs:ignore -- third party credit. global $updraftplus; @@ -2731,7 +2933,14 @@ ENDHERE; return $ret; } - private function restore_button( $backup, $key, $pretty_date, $entities ) { + /** + * @param $backup + * @param $key + * @param $pretty_date + * @param $entities + * @return string + */ + private function restore_button($backup, $key, $pretty_date, $entities ) { $ret = <<
@@ -2750,13 +2959,27 @@ ENDHERE; return $ret; } - private function delete_button( $key, $nonce, $backup ) { + /** + * @param $key + * @param $nonce + * @param $backup + * @return string + */ + private function delete_button($key, $nonce, $backup ) { $sval = ( ( isset( $backup['service'] ) && 'email' !== $backup['service'] && 'none' !== $backup['service'] ) ) ? '1' : '0'; return '' . __( 'Delete', 'updraftplus' ) . ''; } - private function date_label( $pretty_date, $key, $backup, $jobdata, $nonce ) { + /** + * @param $pretty_date + * @param $key + * @param $backup + * @param $jobdata + * @param $nonce + * @return string + */ + private function date_label($pretty_date, $key, $backup, $jobdata, $nonce ) { $ret = apply_filters( 'updraftplus_showbackup_date', $pretty_date, $backup, $jobdata, (int) $key, false ); if ( is_array( $jobdata ) && ! empty( $jobdata['resume_interval'] ) && ( empty( $jobdata['jobstatus'] ) || 'finished' !== $jobdata['jobstatus'] ) ) { $ret .= apply_filters( 'updraftplus_msg_unfinishedbackup', '
' . __( '(Not finished)', 'updraftplus' ) . '', $jobdata, $nonce ); @@ -2765,7 +2988,16 @@ ENDHERE; return $ret; } - private function download_db_button( $bkey, $key, $esc_pretty_date, $nonce_field, $backup, $accept = array() ) { + /** + * @param $bkey + * @param $key + * @param $esc_pretty_date + * @param $nonce_field + * @param $backup + * @param array $accept + * @return string + */ + private function download_db_button($bkey, $key, $esc_pretty_date, $nonce_field, $backup, $accept = array() ) { if ( ! empty( $backup['meta_foreign'] ) && isset( $accept[ $backup['meta_foreign'] ] ) ) { $desc_source = $accept[ $backup['meta_foreign'] ]['desc']; @@ -2797,7 +3029,17 @@ ENDHERE; } // Go through each of the file entities. - private function download_buttons( $backup, $key, $accept, &$entities, $esc_pretty_date, $nonce_field ) { // phpcs:ignore -- third party credit. + + /** + * @param $backup + * @param $key + * @param $accept + * @param $entities + * @param $esc_pretty_date + * @param $nonce_field + * @return string + */ + private function download_buttons($backup, $key, $accept, &$entities, $esc_pretty_date, $nonce_field ) { // phpcs:ignore -- third party credit. global $updraftplus; $ret = ''; $backupable_entities = $updraftplus->get_backupable_file_entities( true, true ); @@ -2897,7 +3139,19 @@ ENDHERE; } - private function download_button( $type, $key, $findex, $info, $nonce_field, $ide, $pdescrip, $esc_pretty_date, $set_contents ) { + /** + * @param $type + * @param $key + * @param $findex + * @param $info + * @param $nonce_field + * @param $ide + * @param $pdescrip + * @param $esc_pretty_date + * @param $set_contents + * @return string + */ + private function download_button($type, $key, $findex, $info, $nonce_field, $ide, $pdescrip, $esc_pretty_date, $set_contents ) { $ret = << @@ -2914,7 +3168,11 @@ ENDHERE; return $ret; } - private function log_button( $backup ) { + /** + * @param $backup + * @return string + */ + private function log_button($backup ) { global $updraftplus; $updraft_dir = $updraftplus->backups_dir_location(); $ret = ''; @@ -2937,7 +3195,11 @@ ENDHERE; } } - private function rebuild_backup_history( $remotescan = false ) { + /** + * @param bool $remotescan + * @return |null + */ + private function rebuild_backup_history($remotescan = false ) { global $updraftplus_admin, $updraftplus; $messages = null; if ( method_exists( $updraftplus, 'rebuild_backup_history' ) ) { @@ -2949,7 +3211,10 @@ ENDHERE; return $messages; } - private function force_scheduled_resumption() { + /** + * @return array|bool[] + */ + private function force_scheduled_resumption() { global $updraftplus; // Casting $resumption to int is absolutely necessary, as the WP cron system uses a hashed serialisation of the parameters for identifying jobs. Different type => different hash => does not match. $resumption = (int) $_REQUEST['resumption']; @@ -2970,7 +3235,10 @@ ENDHERE; } - public function diskspaceused() { + /** + * @return array + */ + public function diskspaceused() { global $updraftplus; $out = array(); if ( 'updraft' === $_POST['entity'] ) { @@ -2991,7 +3259,14 @@ ENDHERE; } // If $basedirs is passed as an array, then $directorieses must be too. - private function recursive_directory_size( $directorieses, $exclude = array(), $basedirs = '' ) { + + /** + * @param $directorieses + * @param array $exclude + * @param string $basedirs + * @return string + */ + private function recursive_directory_size($directorieses, $exclude = array(), $basedirs = '' ) { $size = 0; @@ -3032,7 +3307,13 @@ ENDHERE; } } - private function recursive_directory_size_raw( $prefix_directory, &$exclude = array(), $suffix_directory = '' ) { + /** + * @param $prefix_directory + * @param array $exclude + * @param string $suffix_directory + * @return false|int + */ + private function recursive_directory_size_raw($prefix_directory, &$exclude = array(), $suffix_directory = '' ) { $directory = $prefix_directory . ( '' === $suffix_directory ? '' : '/' . $suffix_directory ); $size = 0; @@ -3074,7 +3355,11 @@ ENDHERE; return $size; } - private function get_cron( $job_id = false ) { + /** + * @param bool $job_id + * @return array|bool + */ + private function get_cron($job_id = false ) { $cron = get_option( 'cron' ); if ( ! is_array( $cron ) ) { @@ -3099,7 +3384,12 @@ ENDHERE; } // A value for $this_job_only also causes something to always be returned (to allow detection of the job having started on the front-end). - private function print_active_jobs( $this_job_only = false ) { + + /** + * @param bool $this_job_only + * @return string + */ + private function print_active_jobs($this_job_only = false ) { $cron = $this->get_cron(); $ret = ''; @@ -3128,7 +3418,14 @@ ENDHERE; return $ret; } - private function print_active_job( $job_id, $is_oneshot = false, $time = false, $next_resumption = false ) { // phpcs:ignore -- third party credit. + /** + * @param $job_id + * @param bool $is_oneshot + * @param bool $time + * @param bool $next_resumption + * @return string + */ + private function print_active_job($job_id, $is_oneshot = false, $time = false, $next_resumption = false ) { // phpcs:ignore -- third party credit. $ret = ''; @@ -3308,13 +3605,19 @@ ENDHERE; return $ret; } - private function fetch_updraft_log() { + /** + * @return array|string[] + */ + private function fetch_updraft_log() { $backup_nonce = $_POST['backup_nonce']; return $this->fetch_log( $backup_nonce ); } - private function activejobs_delete() { + /** + * @return array|string[] + */ + private function activejobs_delete() { $jobid = $_POST['jobid']; if ( empty( $jobid ) ) { return array( 'error' => 'Error: empty job id.' ); @@ -3350,7 +3653,12 @@ ENDHERE; return array(); } - public function fetch_log( $backup_nonce, $log_pointer = 0 ) { + /** + * @param $backup_nonce + * @param int $log_pointer + * @return array|string[] + */ + public function fetch_log($backup_nonce, $log_pointer = 0 ) { global $updraftplus; if ( empty( $backup_nonce ) ) { @@ -3405,7 +3713,13 @@ ENDHERE; return $ret_array; } - private function download_status( $timestamp, $type, $findex ) { + /** + * @param $timestamp + * @param $type + * @param $findex + * @return string[] + */ + private function download_status($timestamp, $type, $findex ) { global $updraftplus; $response = array( 'm' => $updraftplus->jobdata_get( 'dlmessage_' . $timestamp . '_' . $type . '_' . $findex ) . '
' ); $file = $updraftplus->jobdata_get( 'dlfile_' . $timestamp . '_' . $type . '_' . $findex ); @@ -3454,7 +3768,10 @@ ENDHERE; return $response; } - private function close_browser_connection( $txt = '' ) { + /** + * @param string $txt + */ + private function close_browser_connection($txt = '' ) { if ( isset( $_REQUEST['json_result'] ) && true == $_REQUEST['json_result'] ) : $output = wp_json_encode( $txt ); @@ -3478,7 +3795,10 @@ ENDHERE; flush(); } - public function updraftplus_init() { + /** + * + */ + public function updraftplus_init() { if ( ! $this->is_plugin_installed ) { return; } @@ -3493,7 +3813,10 @@ ENDHERE; } } - public function remove_notices() { + /** + * + */ + public function remove_notices() { $remove_hooks['all_admin_notices'] = array( 'UpdraftPlus' => array( 'show_admin_warning_unreadablelog' => 10, @@ -3543,8 +3866,11 @@ ENDHERE; return false; } - - public function wp_before_admin_bar_render() { + + /** + * + */ + public function wp_before_admin_bar_render() { global $wp_admin_bar; $nodes = $wp_admin_bar->get_nodes(); @@ -3561,12 +3887,20 @@ ENDHERE; } } - public function hide_update_notice( $slugs ) { + /** + * @param $slugs + * @return mixed + */ + public function hide_update_notice($slugs ) { $slugs[] = 'updraftplus/updraftplus.php'; return $slugs; } - public function remove_update_nag( $value ) { + /** + * @param $value + * @return mixed + */ + public function remove_update_nag($value ) { if ( isset( $_POST['mainwpsignature'] ) ) { return $value; } @@ -3581,12 +3915,21 @@ ENDHERE; return $value; } - public function get_sync_data( $with_hist = false ) { + /** + * @param bool $with_hist + * @return array|bool + * @throws Exception + */ + public function get_sync_data($with_hist = false ) { $this->required_files(); return $this->get_updraft_data( $with_hist ); } - public function all_plugins( $plugins ) { + /** + * @param $plugins + * @return mixed + */ + public function all_plugins($plugins ) { foreach ( $plugins as $key => $value ) { $plugin_slug = basename( $key, '.php' ); if ( 'updraftplus' === $plugin_slug ) { @@ -3597,7 +3940,10 @@ ENDHERE; return $plugins; } - public function remove_menu() { + /** + * + */ + public function remove_menu() { global $submenu; if ( isset( $submenu['options-general.php'] ) ) { foreach ( $submenu['options-general.php'] as $index => $item ) { diff --git a/class/class-mainwp-clone-install.php b/class/class-mainwp-clone-install.php index 8056d8e..c15c9ab 100644 --- a/class/class-mainwp-clone-install.php +++ b/class/class-mainwp-clone-install.php @@ -40,11 +40,11 @@ class MainWP_Clone_Install { protected $archiver; /** - * Method __construct( $file ) + * Method __construct() * - * Run any time MainWP_Child is called. + * Run any time new MainWP_Clone_Install is created. * - * @param string $file Contains the file name. + * @param string $file Archive file. */ public function __construct( $file ) { require_once ABSPATH . 'wp-admin/includes/class-pclzip.php';