diff --git a/class/class-mainwp-child-back-up-wordpress.php b/class/class-mainwp-child-back-up-wordpress.php index 15c9bf5..ddffa30 100644 --- a/class/class-mainwp-child-back-up-wordpress.php +++ b/class/class-mainwp-child-back-up-wordpress.php @@ -63,6 +63,9 @@ class MainWP_Child_Back_Up_Wordpress { case 'run_schedule': $information = $this->run_schedule(); break; + case 'save_all_schedules': + $information = $this->save_all_schedules(); + break; case 'update_schedule': $information = $this->update_schedule(); break; @@ -157,17 +160,35 @@ class MainWP_Child_Back_Up_Wordpress { $schedule_id = $this->check_schedule(); $schedule = new HM\BackUpWordPress\Scheduled_Backup( sanitize_text_field( urldecode( $schedule_id ) ) ); + // Delete the running backup - if ( $schedule->get_running_backup_filename() && file_exists( trailingslashit( hmbkp_path() ) . $schedule->get_running_backup_filename() ) ) { - unlink( trailingslashit( hmbkp_path() ) . $schedule->get_running_backup_filename() ); + if (method_exists($schedule, 'get_running_backup_filename' )) { + if ( $schedule->get_running_backup_filename() && file_exists( trailingslashit( hmbkp_path() ) . $schedule->get_running_backup_filename() ) ) { + unlink( trailingslashit( hmbkp_path() ) . $schedule->get_running_backup_filename() ); + } + if ( $schedule->get_schedule_running_path() && file_exists( $schedule->get_schedule_running_path() ) ) { + unlink( $schedule->get_schedule_running_path() ); + } + } else { + $status = $schedule->get_status(); + // Delete the running backup + if ( $status->get_backup_filename() && file_exists( trailingslashit( HM\BackUpWordPress\Path::get_path() ) . $status->get_backup_filename() ) ) { + unlink( trailingslashit( HM\BackUpWordPress\Path::get_path() ) . $status->get_backup_filename() ); + } + if ( file_exists( $status->get_status_filepath() ) ) { + unlink( $status->get_status_filepath() ); + } + } - if ( $schedule->get_schedule_running_path() && file_exists( $schedule->get_schedule_running_path() ) ) { - unlink( $schedule->get_schedule_running_path() ); - } HM\BackUpWordPress\Path::get_instance()->cleanup(); - $information['scheduleStatus'] = $schedule->get_status(); + if ($status === null) { + $information['scheduleStatus'] = $schedule->get_status(); + } else { + $information['scheduleStatus'] = $status->get_status(); + } + $information['result'] = 'SUCCESS'; return $information; @@ -179,7 +200,13 @@ class MainWP_Child_Back_Up_Wordpress { HM\BackUpWordPress\Path::get_instance()->cleanup(); - $information['scheduleStatus'] = $schedule->get_status(); + if (method_exists($schedule, 'get_running_backup_filename' )) { + $information['scheduleStatus'] = $schedule->get_status(); + } else { + $status = $schedule->get_status(); + $information['scheduleStatus'] = $status->get_status(); + } + $information['result'] = 'SUCCESS'; return $information; @@ -187,19 +214,13 @@ class MainWP_Child_Back_Up_Wordpress { function run_schedule() { $schedule_id = $this->check_schedule(); - HM\BackUpWordPress\Path::get_instance()->cleanup(); - // Fixes an issue on servers which only allow a single session per client - session_write_close(); - - $task = new \HM\Backdrop\Task( 'hmbkp_run_schedule_async', $schedule_id ); - - $task->schedule(); - $schedule = new HM\BackUpWordPress\Scheduled_Backup( sanitize_text_field( urldecode( $schedule_id ) ) ); - - $information['scheduleStatus'] = $schedule->get_status(); - $information['file_size_text'] = $this->hmbkp_get_site_size_text( $schedule ); - $information['started_ago'] = human_time_diff( $schedule->get_schedule_running_start_time() ); - + if (function_exists('hmbkp_run_schedule_async')) { + hmbkp_run_schedule_async($schedule_id); + } else if (function_exists('\HM\BackUpWordPress\run_schedule_async')) { + $task = new \HM\Backdrop\Task( '\HM\BackUpWordPress\run_schedule_async', $schedule_id ); + $task->schedule(); + } else + return array( 'error' => __('Error run schedule', 'mainwp-child') ); return array( 'result' => 'SUCCESS' ); } @@ -224,15 +245,21 @@ class MainWP_Child_Back_Up_Wordpress { } $schedule = new HM\BackUpWordPress\Scheduled_Backup( sanitize_text_field( urldecode( $schedule_id ) ) ); - + $started_ago = method_exists($schedule, 'get_schedule_running_start_time') ? $schedule->get_schedule_running_start_time() : $schedule->get_schedule_start_time(); $out = array( 'b' => $this->get_backupslist_html( $schedule ), 'count' => count( $schedule->get_backups() ), 'file_size_text' => $this->hmbkp_get_site_size_text( $schedule ), - 'scheduleStatus' => $schedule->get_status(), - 'started_ago' => human_time_diff( $schedule->get_schedule_running_start_time() ), + 'started_ago' => human_time_diff( $started_ago ), ); + if (method_exists($schedule, 'get_running_backup_filename' )) { + $out['scheduleStatus'] = $schedule->get_status(); + } else { + $status = $schedule->get_status(); + $out['scheduleStatus'] = $status->get_status(); + } + $information['backups'][ $schedule_id ] = $out; } @@ -245,19 +272,31 @@ class MainWP_Child_Back_Up_Wordpress { $current_option = get_option( 'hmbkp_schedule_' . $sch_id ); if ( is_array( $current_option ) ) { unset( $current_option['excludes'] ); // not send this value + $started_ago = method_exists($schedule, 'get_schedule_running_start_time') ? $schedule->get_schedule_running_start_time() : $schedule->get_schedule_start_time(); $send_back_schedules[ $sch_id ] = array( 'options' => $current_option, 'b' => $this->get_backupslist_html( $schedule ), 'count' => count( $schedule->get_backups() ), 'file_size_text' => $this->hmbkp_get_site_size_text( $schedule ), 'scheduleStatus' => $schedule->get_status(), - 'started_ago' => human_time_diff( $schedule->get_schedule_running_start_time() ), + 'started_ago' => human_time_diff( $started_ago ), ); + if (method_exists($schedule, 'get_running_backup_filename' )) { + $send_back_schedules['scheduleStatus'] = $schedule->get_status(); + } else { + $status = $schedule->get_status(); + $send_back_schedules['scheduleStatus'] = $status->get_status(); + } } } } - $information['backups_path'] = str_replace( HM\BackUpWordPress\Backup::get_home_path(), '', hmbkp_path() ); + if (function_exists('HM\BackUpWordPress\Backup::get_home_path')) + $backups_path = str_replace( HM\BackUpWordPress\Backup::get_home_path(), '', hmbkp_path() ); + else + $backups_path = str_replace( HM\BackUpWordPress\Path::get_home_path(), '', HM\BackUpWordPress\Path::get_path() ); + + $information['backups_path'] = $backups_path; $information['send_back_schedules'] = $send_back_schedules; $information['result'] = 'SUCCESS'; @@ -273,19 +312,25 @@ class MainWP_Child_Back_Up_Wordpress { $schedule = new HM\BackUpWordPress\Scheduled_Backup( sanitize_text_field( urldecode( $schedule_id ) ) ); - $deleted = $schedule->delete_backup( sanitize_text_field( base64_decode( $_POST['hmbkp_backuparchive'] ) ) ); + $deleted = $schedule->delete_backup(base64_decode( urldecode($_POST['hmbkp_backuparchive'] ))); if ( is_wp_error( $deleted ) ) { return array( 'error' => $deleted->get_error_message() ); } - return array( + $ret = array( 'result' => 'SUCCESS', 'b' => $this->get_backupslist_html( $schedule ), 'count' => count( $schedule->get_backups() ), 'file_size_text' => $this->hmbkp_get_site_size_text( $schedule ), - 'scheduleStatus' => $schedule->get_status(), ); + if (method_exists($schedule, 'get_running_backup_filename' )) { + $ret['scheduleStatus'] = $schedule->get_status(); + } else { + $status = $schedule->get_status(); + $ret['scheduleStatus'] = $status->get_status(); + } + return $ret; } function get_backupslist_html( $schedule ) { @@ -297,7 +342,7 @@ class MainWP_Child_Back_Up_Wordpress {
%s
)', esc_attr( $schedule->get_formatted_site_size() ) );
-
+ if (method_exists($schedule, 'is_site_size_cached')) {
+ if ( ( 'database' === $schedule->get_type() ) || $schedule->is_site_size_cached() ) {
+ return sprintf( '(%s
)', esc_attr( $schedule->get_formatted_site_size() ) );
+ }
} else {
-
- return sprintf( '(' . __( 'calculating the size of your backup…', 'mainwp-backupwordpress-extension' ) . '
)' );
-
+ $site_size = new HM\BackUpWordPress\Site_Size( $schedule->get_type(), $schedule->get_excludes() );
+ if ( ( 'database' === $schedule->get_type() ) || $site_size->is_site_size_cached() ) {
+ return sprintf( '(%s
)', esc_attr( $site_size->get_formatted_site_size() ) );
+ }
}
+ return sprintf( '(' . __( 'calculating the size of your backup…', 'mainwp-backupwordpress-extension' ) . '
)' );
+
}
function hmbkp_get_backup_row( $file, HM\BackUpWordPress\Scheduled_Backup $schedule ) {
@@ -371,19 +418,29 @@ class MainWP_Child_Back_Up_Wordpress {
- '; - // $start = microtime(true); +// error_reporting(E_ALL); +// ini_set('display_errors', TRUE); +// ini_set('display_startup_errors', TRUE); +// echo ''); } //Register does not require auth, so we register here.. @@ -1162,12 +1178,12 @@ class MainWP_Child { } if ( is_wp_error( $result ) ) { + $err_code = $result->get_error_code(); if ( $result->get_error_data() && is_string( $result->get_error_data() ) ) { $error = $result->get_error_data(); - MainWP_Helper::error( $error ); + MainWP_Helper::error( $error, $err_code ); } else { - $error = $result->get_error_code(); - MainWP_Helper::error( implode( ', ', $error ) ); + MainWP_Helper::error( implode( ', ', $error ), $err_code ); } } } @@ -1323,6 +1339,53 @@ class MainWP_Child { MainWP_Helper::write( $information ); } + function upgradeTranslation() { + //Prevent disable/re-enable at upgrade + define( 'DOING_CRON', true ); + + MainWP_Helper::getWPFilesystem(); + include_once( ABSPATH . '/wp-admin/includes/class-wp-upgrader.php' ); + if ( file_exists( ABSPATH . '/wp-admin/includes/screen.php' ) ) { + include_once( ABSPATH . '/wp-admin/includes/screen.php' ); + } + if ( file_exists( ABSPATH . '/wp-admin/includes/template.php' ) ) { + include_once( ABSPATH . '/wp-admin/includes/template.php' ); + } + if ( file_exists( ABSPATH . '/wp-admin/includes/misc.php' ) ) { + include_once( ABSPATH . '/wp-admin/includes/misc.php' ); + } + include_once( ABSPATH . '/wp-admin/includes/file.php' ); + + include_once( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' ); + + $upgrader = new Language_Pack_Upgrader( new Language_Pack_Upgrader_Skin( compact( 'url', 'nonce', 'title', 'context' ) ) ); + $translations = explode( ',', urldecode( $_POST['list'] ) ); + $all_language_updates = wp_get_translation_updates(); + + $language_updates = array(); + foreach ( $all_language_updates as $current_language_update ) { + if ( in_array( $current_language_update->slug, $translations ) ) { + $language_updates[] = $current_language_update; + } + } + + $result = count( $language_updates ) == 0 ? false : $upgrader->bulk_upgrade( $language_updates ); + if ( ! empty( $result ) ) { + for ( $i = 0; $i < count( $result ); $i++ ) { + if ( empty( $result[$i] ) || is_wp_error( $result[$i] ) ) { + $information['upgrades'][ $language_updates[$i]->slug ] = false; + } else { + $information['upgrades'][ $language_updates[$i]->slug ] = true; + } + } + } else { + MainWP_Helper::error( __( 'Bad request', 'mainwp-child' ) ); + } + + $information['sync'] = $this->getSiteStats( array(), false ); + MainWP_Helper::write( $information ); + } + /** * Expects $_POST['type'] == plugin/theme * $_POST['list'] == 'theme1,theme2' or 'plugin1,plugin2' @@ -1433,10 +1496,17 @@ class MainWP_Child { remove_filter( 'pre_site_transient_update_plugins', $this->filterFunction, 99 ); } } else if ( isset( $_POST['type'] ) && 'theme' === $_POST['type'] ) { + + $last_update = get_site_transient( 'update_themes' ); + include_once( ABSPATH . '/wp-admin/includes/update.php' ); if ( null !== $this->filterFunction ) { add_filter( 'pre_site_transient_update_themes', $this->filterFunction, 99 ); } + +// $last_update = get_site_transient( 'update_themes' ); +// $originalLastChecked = !empty( $last_update ) && property_exists( $last_update, 'last_checked' ) ? $last_update->last_checked : 0; + @wp_update_themes(); include_once( ABSPATH . '/wp-admin/includes/theme.php' ); $information['theme_updates'] = $this->upgrade_get_theme_updates(); @@ -1464,8 +1534,26 @@ class MainWP_Child { } //@see wp-admin/update.php + if ( null !== $this->filterFunction ) { + remove_filter( 'pre_site_transient_update_plugins', $this->filterFunction, 99 ); + } + + $last_update2 = get_site_transient( 'update_themes' ); + set_site_transient( 'update_themes', $last_update ); +// if ( !empty( $last_update ) && property_exists( $last_update, 'last_checked' ) ) { +// $last_update->last_checked = $originalLastChecked; +// set_site_transient( 'update_themes', $last_update ); +// } + +// @wp_update_themes(); + $upgrader = new Theme_Upgrader( new Bulk_Theme_Upgrader_Skin( compact( 'nonce', 'url' ) ) ); $result = $upgrader->bulk_upgrade( $themes ); + if ( null !== $this->filterFunction ) { + add_filter( 'pre_site_transient_update_themes', $this->filterFunction, 99 ); + } + + set_site_transient( 'update_themes', $last_update2 ); if ( $addFilterToFixUpdate_optimizePressTheme ) { remove_filter( 'site_transient_update_themes', array( @@ -1486,6 +1574,15 @@ class MainWP_Child { MainWP_Helper::error( __( 'Bad request', 'mainwp-child' ) ); } } + +// $last_update = get_site_transient( 'update_themes' ); +// if ( !empty( $last_update ) && property_exists( $last_update, 'last_checked' ) ) { +// $last_update->last_checked = $originalLastChecked; +// set_site_transient( 'update_themes', $last_update ); +// } + +// @wp_update_themes(); + if ( count( $premiumThemes ) > 0 ) { $mwp_premium_updates = apply_filters( 'mwp_premium_perform_update', array() ); $mwp_premium_updates_todo = array(); @@ -1618,7 +1715,7 @@ class MainWP_Child { //Already added - can't readd. Deactivate plugin.. if ( get_option( 'mainwp_child_pubkey' ) ) { - MainWP_Helper::error( __( 'Public key already set, reset the MainWP plugin on your site and try again.', 'mainwp-child' ) ); + MainWP_Helper::error( __( 'Public key already set, reset the MainWP Child plugin on your Child site and try again.', 'mainwp-child' ) ); } if ( '' != get_option( 'mainwp_child_uniqueId' ) ) { @@ -2283,9 +2380,11 @@ class MainWP_Child { if ( 'all' === $_POST['feature'] || 'versions' === $_POST['feature'] ) { $security['scripts_version'] = true; $security['styles_version'] = true; + $security['generator_version'] = true; MainWP_Security::remove_scripts_version( true ); MainWP_Security::remove_styles_version( true ); - $information['versions'] = ( ! MainWP_Security::remove_scripts_version_ok() || ! MainWP_Security::remove_styles_version_ok() ? 'N' : 'Y' ); + MainWP_Security::remove_generator_version( true ); + $information['versions'] = 'Y'; } if ( 'all' === $_POST['feature'] || 'admin' === $_POST['feature'] ) { @@ -2339,6 +2438,7 @@ class MainWP_Child { if ( 'all' === $_POST['feature'] || 'versions' === $_POST['feature'] ) { $security['scripts_version'] = false; $security['styles_version'] = false; + $security['generator_version'] = false; $information['versions'] = 'N'; } @@ -2369,7 +2469,7 @@ class MainWP_Child { // $information['file_perms'] = (!MainWP_Security::fix_file_permissions_ok() ? 'N' : 'Y'); $information['db_reporting'] = ( ! MainWP_Security::remove_database_reporting_ok() ? 'N' : 'Y' ); $information['php_reporting'] = ( ! MainWP_Security::remove_php_reporting_ok() ? 'N' : 'Y' ); - $information['versions'] = ( ! MainWP_Security::remove_scripts_version_ok() || ! MainWP_Security::remove_styles_version_ok() + $information['versions'] = ( ! MainWP_Security::remove_scripts_version_ok() || ! MainWP_Security::remove_styles_version_ok() || ! MainWP_Security::remove_generator_version_ok() ? 'N' : 'Y' ); $information['admin'] = ( ! MainWP_Security::admin_user_ok() ? 'N' : 'Y' ); $information['readme'] = ( MainWP_Security::remove_readme_ok() ? 'Y' : 'N' ); @@ -2396,6 +2496,7 @@ class MainWP_Child { $update_htaccess = true; } MainWP_Helper::update_option( 'heatMapEnabled', '0', 'yes' ); + MainWP_Helper::update_option( 'heatMapExtensionLoaded', '', 'yes' ); } } @@ -2561,7 +2662,19 @@ class MainWP_Child { $information['plugin_updates'][ $slug ] = $plugin_update; } + + // to fix bug + $fix_update_plugins = get_site_transient( 'tofix_update_plugins' ); + if ( count($fix_update_plugins) > 0 ) { + foreach( $fix_update_plugins as $slug => $plugin_update ) { + if ( !isset( $information['plugin_updates'][ $slug ] ) ) { + $information['plugin_updates'][ $slug ] = $plugin_update; + } + } + } + // end fix } + if ( null !== $this->filterFunction ) { remove_filter( 'pre_site_transient_update_plugins', $this->filterFunction, 99 ); } @@ -2586,6 +2699,34 @@ class MainWP_Child { if ( null !== $this->filterFunction ) { remove_filter( 'pre_site_transient_update_themes', $this->filterFunction, 99 ); } + + $translation_updates = wp_get_translation_updates(); + if ( !empty( $translation_updates ) ) { + $information['translation_updates'] = array(); + foreach ($translation_updates as $translation_update) + { + $new_translation_update = array('type' => $translation_update->type, + 'slug' => $translation_update->slug, + 'language' => $translation_update->language, + 'version' => $translation_update->version); + if ( 'plugin' === $translation_update->type ) { + $all_plugins = get_plugins(); + foreach ( $all_plugins as $file => $plugin ) { + if ( stristr( $file, $translation_update->slug ) ) { + $new_translation_update['name'] = $plugin['Name']; + break; + } + } + } else if ( 'theme' === $translation_update->type ) { + $theme = wp_get_theme($translation_update->slug); + $new_translation_update['name'] = $theme->name; + } else if ( ( 'core' === $translation_update->type ) && ( 'default' === $translation_update->slug ) ) { + $new_translation_update['name'] = 'Wordpress core'; + } + $information['translation_updates'][] = $new_translation_update; + } + } + $information['recent_comments'] = $this->get_recent_comments( array( 'approve', 'hold' ), 5 ); $information['recent_posts'] = $this->get_recent_posts( array( 'publish', 'draft', 'pending', 'trash' ), 5 ); $information['recent_pages'] = $this->get_recent_posts( array( @@ -2618,7 +2759,7 @@ class MainWP_Child { if ( ! MainWP_Security::remove_php_reporting_ok() ) { $securityIssuess ++; } - if ( ! MainWP_Security::remove_scripts_version_ok() || ! MainWP_Security::remove_styles_version_ok() ) { + if ( ! MainWP_Security::remove_scripts_version_ok() || ! MainWP_Security::remove_styles_version_ok() || ! MainWP_Security::remove_generator_version_ok() ) { $securityIssuess ++; } if ( ! MainWP_Security::admin_user_ok() ) { @@ -3640,6 +3781,35 @@ class MainWP_Child { function getTotalFileSize( $directory = WP_CONTENT_DIR ) { try { + function continueFileSize( $dir, $limit ) { + $dirs = array( $dir ); + $cnt = 0; + while ( isset( $dirs[0] ) ) { + $path = array_shift( $dirs ); + if ( stristr( $path, WP_CONTENT_DIR . '/uploads/mainwp' ) ) { + continue; + } + $uploadDir = MainWP_Helper::getMainWPDir(); + $uploadDir = $uploadDir[0]; + if ( stristr( $path, $uploadDir ) ) { + continue; + } + $res = @glob( $path . '/*' ); + if ( is_array( $res ) ) { + foreach ( $res as $next ) { + if ( is_dir( $next ) ) { + $dirs[] = $next; + } else { + if ($cnt++ > $limit) return false;; + } + } + } + } + return true; + } + + if ( !continueFilesize( $directory, 20000 ) ) return 0; + if ( MainWP_Helper::function_exists( 'popen' ) ) { $uploadDir = MainWP_Helper::getMainWPDir(); $uploadDir = $uploadDir[0]; @@ -3648,18 +3818,19 @@ class MainWP_Child { $size = @fread( $popenHandle, 1024 ); @pclose( $popenHandle ); $size = substr( $size, 0, strpos( $size, "\t" ) ); - if ( ctype_digit( $size ) ) { + if ( MainWP_Helper::ctype_digit( $size ) ) { return $size / 1024; } } } + if ( MainWP_Helper::function_exists( 'shell_exec' ) ) { $uploadDir = MainWP_Helper::getMainWPDir(); $uploadDir = $uploadDir[0]; - $size = @shell_exec( 'du -s ' . $directory . ' --exclude "' . str_replace( ABSPATH, '', $uploadDir ) . '"', 'r' ); + $size = @shell_exec( 'du -s ' . $directory . ' --exclude "' . str_replace( ABSPATH, '', $uploadDir ) . '"' ); if ( null !== $size ) { $size = substr( $size, 0, strpos( $size, "\t" ) ); - if ( ctype_digit( $size ) ) { + if ( MainWP_Helper::ctype_digit( $size ) ) { return $size / 1024; } } @@ -3673,7 +3844,7 @@ class MainWP_Child { $size = $ref->size; $obj = null; - if ( ctype_digit( $size ) ) { + if ( MainWP_Helper::ctype_digit( $size ) ) { return $size / 1024; } } @@ -3949,11 +4120,7 @@ class MainWP_Child { } $code = stripslashes( $_POST['code'] ); if ( 'run_snippet' === $action ) { - $return = $this->execute_snippet( $code ); - if ( is_array( $return ) && isset( $return['result'] ) && 'SUCCESS' === $return['result'] ) { - $information['status'] = 'SUCCESS'; - } - $information['result'] = isset( $return['output'] ) ? $return['output'] : ''; + $information = $this->execute_snippet( $code ); } else if ( 'save_snippet' === $action ) { $type = $_POST['type']; $slug = $_POST['slug']; @@ -4035,11 +4202,14 @@ class MainWP_Child { $result = eval( $code ); $output = ob_get_contents(); ob_end_clean(); - $return = array( 'output' => $output ); - if ( $result ) { - $return['result'] = 'SUCCESS'; + $return = array(); + if ( false === $result && ( $error = error_get_last() ) ) { + $return['status'] = 'FAIL'; + $return['result'] = $error['message']; + } else { + $return['status'] = 'SUCCESS'; + $return['result'] = $output; } - return $return; } diff --git a/class/class-mainwp-heatmap-tracker.php b/class/class-mainwp-heatmap-tracker.php index 554f184..1bc24c4 100644 --- a/class/class-mainwp-heatmap-tracker.php +++ b/class/class-mainwp-heatmap-tracker.php @@ -289,7 +289,7 @@ class MainWP_Heatmap_Tracker { */ public function trackerJsInline() { echo ''; +// $start = microtime(true); +// +// print_r(wp_get_translation_updates()); +// +// print_r($this->getSiteStats(array(), false)); +// - // phpinfo(); - // $_POST['type'] = 'full'; - // $_POST['ext'] = 'tar.gz'; - // $_POST['pid'] = time(); - // print_r($this->backup(false)); - - // $stop = microtime(true); - // die(($stop - $start) . 's'); +// $stop = microtime(true); +// die(($stop - $start) . 's