diff --git a/.gitattributes b/.gitattributes index a810b8d..8f35e6b 100644 --- a/.gitattributes +++ b/.gitattributes @@ -4,9 +4,8 @@ bin export-ignore composer.* export-ignore tests export-ignore .gitattributes export-ignore -.phpcs.xml.dist export-ignore +phpcs.xml export-ignore .travis.yml export-ignore LICENSE.md export-ignore LICENSE.txt export-ignore README.md export-ignore -phpunit.xml.dist export-ignore diff --git a/.phpcs.xml.dist b/.phpcs.xml.dist deleted file mode 100644 index 067d574..0000000 --- a/.phpcs.xml.dist +++ /dev/null @@ -1,49 +0,0 @@ - - - Generally-applicable sniffs for WordPress plugins. - - - . - /vendor/ - /node_modules/ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/.travis.yml b/.travis.yml index 84be180..769a300 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,5 @@ sudo: false -dist: trusty +dist: xenial language: php @@ -19,7 +19,7 @@ cache: matrix: include: - php: 7.4 - env: WP_VERSION=latest + env: WP_TRAVISCI=phpcs WP_VERSION=latest - php: 7.3 env: WP_VERSION=latest - php: 7.2 @@ -28,12 +28,7 @@ matrix: env: WP_VERSION=latest - php: 7.0 env: WP_VERSION=latest - - php: 5.6 - env: WP_VERSION=latest - - php: 5.6 - env: WP_VERSION=trunk - dist: precise - + before_script: - export PATH="$HOME/.composer/vendor/bin:$PATH" - | diff --git a/README.md b/README.md index 0d888d8..0a4094c 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,6 @@ Latest Stable Version WordPress Plugin Active Installs WordPress Plugin Rating - Build Status

Welcome to the [MainWP](https://mainwp.com) Child plugin repository on GitHub. Here you can browse the source, look at open issues and keep track of development. diff --git a/class/class-mainwp-backup.php b/class/class-mainwp-backup.php index 0f49c5f..20e21d2 100644 --- a/class/class-mainwp-backup.php +++ b/class/class-mainwp-backup.php @@ -43,7 +43,7 @@ class MainWP_Backup { $pid = trailingslashit( $backupdir ) . 'backup-' . $pid . '.pid'; } - //Verify if another backup is running, if so, return an error + // Verify if another backup is running, if so, return an error $files = glob( $backupdir . '*.pid' ); foreach ( $files as $file ) { if ( basename( $file ) == basename( $pid ) ) { @@ -68,38 +68,23 @@ class MainWP_Backup { $ext = $this->archiver->getExtension(); } - // throw new Exception('Test 1 2 : ' . print_r($append,1)); if ( ( false !== $fileSuffix ) && ! empty( $fileSuffix ) ) { - $file = $fileSuffix . ( true === $append ? '' : $ext ); //Append already contains extension! + // Append already contains extension! + $file = $fileSuffix . ( true === $append ? '' : $ext ); } else { $file = 'backup-' . $filePrefix . $timestamp . $ext; } $filepath = $backupdir . $file; $fileurl = $file; - // if (!$append) - // { - // if ($dh = opendir($backupdir)) - // { - // while (($file = readdir($dh)) !== false) - // { - // if ($file != '.' && $file != '..' && preg_match('/(.*).(zip|tar|tar.gz|tar.bz2|pid|done)$/', $file)) - // { - // @unlink($backupdir . $file); - // } - // } - // closedir($dh); - // } - // } - if ( ! $addConfig ) { - if ( ! in_array( str_replace( ABSPATH, '', WP_CONTENT_DIR ), $excludes ) && ! in_array( 'wp-admin', $excludes ) && ! in_array( WPINC, $excludes ) ) { + if ( ! in_array( str_replace( ABSPATH, '', WP_CONTENT_DIR ), $excludes, true ) && ! in_array( 'wp-admin', $excludes, true ) && ! in_array( WPINC, $excludes, true ) ) { $addConfig = true; $includeCoreFiles = true; } } - $this->timeout = 20 * 60 * 60; /*20 minutes*/ + $this->timeout = 20 * 60 * 60; $mem = '512M'; // @codingStandardsIgnoreStart @ini_set( 'memory_limit', $mem ); @@ -109,9 +94,9 @@ class MainWP_Backup { if ( null !== $this->archiver ) { $success = $this->archiver->createFullBackup( $filepath, $excludes, $addConfig, $includeCoreFiles, $excludezip, $excludenonwp, $append ); - } else if ( $this->checkZipSupport() ) { + } elseif ( $this->checkZipSupport() ) { $success = $this->createZipFullBackup( $filepath, $excludes, $addConfig, $includeCoreFiles, $excludezip, $excludenonwp ); - } else if ( $this->checkZipConsole() ) { + } elseif ( $this->checkZipConsole() ) { $success = $this->createZipConsoleFullBackup( $filepath, $excludes, $addConfig, $includeCoreFiles, $excludezip, $excludenonwp ); } else { $success = $this->createZipPclFullBackup2( $filepath, $excludes, $addConfig, $includeCoreFiles, $excludezip, $excludenonwp ); @@ -125,7 +110,7 @@ class MainWP_Backup { } public function zipFile( $files, $archive ) { - $this->timeout = 20 * 60 * 60; /*20 minutes*/ + $this->timeout = 20 * 60 * 60; $mem = '512M'; // @codingStandardsIgnoreStart @ini_set( 'memory_limit', $mem ); @@ -133,15 +118,15 @@ class MainWP_Backup { @ini_set( 'max_execution_time', $this->timeout ); // @codingStandardsIgnoreEnd - if ( !is_array( $files ) ) { - $files = array ($files ); + if ( ! is_array( $files ) ) { + $files = array( $files ); } if ( null !== $this->archiver ) { $success = $this->archiver->zipFile( $files, $archive ); - } else if ( $this->checkZipSupport() ) { + } elseif ( $this->checkZipSupport() ) { $success = $this->_zipFile( $files, $archive ); - } else if ( $this->checkZipConsole() ) { + } elseif ( $this->checkZipConsole() ) { $success = $this->_zipFileConsole( $files, $archive ); } else { $success = $this->_zipFilePcl( $files, $archive ); @@ -172,8 +157,8 @@ class MainWP_Backup { } public function _zipFilePcl( $files, $archive ) { - //Zip this backup folder.. - require_once( ABSPATH . 'wp-admin/includes/class-pclzip.php' ); + // Zip this backup folder.. + require_once ABSPATH . 'wp-admin/includes/class-pclzip.php'; $this->zip = new PclZip( $archive ); $error = false; @@ -183,7 +168,7 @@ class MainWP_Backup { } } - return !$error; + return ! $error; } /** @@ -202,7 +187,6 @@ class MainWP_Backup { */ public function checkZipConsole() { return false; - // return function_exists('system'); } /** @@ -248,7 +232,7 @@ class MainWP_Backup { foreach ( $nodes as $key => $node ) { if ( MainWP_Helper::startsWith( $node, ABSPATH . WPINC ) ) { unset( $nodes[ $key ] ); - } else if ( MainWP_Helper::startsWith( $node, ABSPATH . basename( admin_url( '' ) ) ) ) { + } elseif ( MainWP_Helper::startsWith( $node, ABSPATH . basename( admin_url( '' ) ) ) ) { unset( $nodes[ $key ] ); } else { foreach ( $coreFiles as $coreFile ) { @@ -280,7 +264,7 @@ class MainWP_Backup { if ( ! MainWP_Helper::inExcludes( $excludes, str_replace( ABSPATH, '', $node ) ) ) { if ( is_dir( $node ) ) { $this->zipAddDir( $node, $excludes ); - } else if ( is_file( $node ) ) { + } elseif ( is_file( $node ) ) { $this->addFileToZip( $node, str_replace( ABSPATH, '', $node ) ); } } @@ -352,7 +336,7 @@ class MainWP_Backup { * @return bool */ public function createZipPclFullBackup( $filepath, $excludes, $addConfig, $includeCoreFiles ) { - require_once( ABSPATH . 'wp-admin/includes/class-pclzip.php' ); + require_once ABSPATH . 'wp-admin/includes/class-pclzip.php'; $this->zip = new PclZip( $filepath ); $nodes = glob( ABSPATH . '*' ); if ( ! $includeCoreFiles ) { @@ -382,7 +366,7 @@ class MainWP_Backup { foreach ( $nodes as $key => $node ) { if ( MainWP_Helper::startsWith( $node, ABSPATH . WPINC ) ) { unset( $nodes[ $key ] ); - } else if ( MainWP_Helper::startsWith( $node, ABSPATH . basename( admin_url( '' ) ) ) ) { + } elseif ( MainWP_Helper::startsWith( $node, ABSPATH . basename( admin_url( '' ) ) ) ) { unset( $nodes[ $key ] ); } else { foreach ( $coreFiles as $coreFile ) { @@ -396,7 +380,7 @@ class MainWP_Backup { } $db_files = $this->createBackupDB( dirname( $filepath ) . DIRECTORY_SEPARATOR . 'dbBackup' ); - $error = false; + $error = false; foreach ( $db_files as $db_file ) { if ( 0 === ( $rslt = $this->zip->add( $db_file, PCLZIP_OPT_REMOVE_PATH, dirname( $db_file ), PCLZIP_OPT_ADD_PATH, basename( WP_CONTENT_DIR ) ) ) ) { $error = true; @@ -408,13 +392,13 @@ class MainWP_Backup { } if ( ! $error ) { foreach ( $nodes as $node ) { - if ( null === $excludes || ! in_array( str_replace( ABSPATH, '', $node ), $excludes ) ) { + if ( null === $excludes || ! in_array( str_replace( ABSPATH, '', $node ), $excludes, true ) ) { if ( is_dir( $node ) ) { if ( ! $this->pclZipAddDir( $node, $excludes ) ) { $error = true; break; } - } else if ( is_file( $node ) ) { + } elseif ( is_file( $node ) ) { if ( 0 === ( $rslt = $this->zip->add( $node, PCLZIP_OPT_REMOVE_PATH, ABSPATH ) ) ) { $error = true; break; @@ -471,7 +455,7 @@ class MainWP_Backup { $newnodes = glob( $node . DIRECTORY_SEPARATOR . '*' ); $this->copy_dir( $newnodes, $excludes, $backupfolder, $excludenonwp, false ); unset( $newnodes ); - } else if ( is_file( $node ) ) { + } elseif ( is_file( $node ) ) { if ( $this->excludeZip && MainWP_Helper::endsWith( $node, '.zip' ) ) { continue; } @@ -485,16 +469,16 @@ class MainWP_Backup { } public function createZipPclFullBackup2( $filepath, $excludes, $addConfig, $includeCoreFiles, $excludezip, $excludenonwp ) { - //Create backup folder + // Create backup folder $backupFolder = dirname( $filepath ) . DIRECTORY_SEPARATOR . 'backup' . DIRECTORY_SEPARATOR; // @codingStandardsIgnoreStart @mkdir( $backupFolder ); // @codingStandardsIgnoreEnd - //Create DB backup + // Create DB backup $db_files = $this->createBackupDB( $backupFolder . 'dbBackup' ); - //Copy installation to backup folder + // Copy installation to backup folder $nodes = glob( ABSPATH . '*' ); if ( ! $includeCoreFiles ) { $coreFiles = array( @@ -523,7 +507,7 @@ class MainWP_Backup { foreach ( $nodes as $key => $node ) { if ( MainWP_Helper::startsWith( $node, ABSPATH . WPINC ) ) { unset( $nodes[ $key ] ); - } else if ( MainWP_Helper::startsWith( $node, ABSPATH . basename( admin_url( '' ) ) ) ) { + } elseif ( MainWP_Helper::startsWith( $node, ABSPATH . basename( admin_url( '' ) ) ) ) { unset( $nodes[ $key ] ); } else { foreach ( $coreFiles as $coreFile ) { @@ -546,8 +530,8 @@ class MainWP_Backup { // @codingStandardsIgnoreEnd unset( $nodes ); - //Zip this backup folder.. - require_once( ABSPATH . 'wp-admin/includes/class-pclzip.php' ); + // Zip this backup folder.. + require_once ABSPATH . 'wp-admin/includes/class-pclzip.php'; $this->zip = new PclZip( $filepath ); $this->zip->create( $backupFolder, PCLZIP_OPT_REMOVE_PATH, $backupFolder ); if ( $addConfig ) { @@ -562,7 +546,7 @@ class MainWP_Backup { $this->addFileFromStringToPCLZip( 'clone/config.txt', $string, $filepath ); } - //Remove backup folder + // Remove backup folder MainWP_Helper::delete_dir( $backupFolder ); return true; @@ -599,24 +583,6 @@ class MainWP_Backup { $iterator = null; unset( $iterator ); - - // $nodes = glob(rtrim($path, '/') . '/*'); - // if (empty($nodes)) return true; - // - // foreach ($nodes as $node) - // { - // if (!MainWP_Helper::inExcludes($excludes, str_replace(ABSPATH, '', $node))) - // { - // if (is_dir($node)) - // { - // $this->zipAddDir($node, $excludes); - // } - // else if (is_file($node)) - // { - // $this->addFileToZip($node, str_replace(ABSPATH, '', $node)); - // } - // } - // } } public function pclZipAddDir( $path, $excludes ) { @@ -627,13 +593,13 @@ class MainWP_Backup { } foreach ( $nodes as $node ) { - if ( null === $excludes || ! in_array( str_replace( ABSPATH, '', $node ), $excludes ) ) { + if ( null === $excludes || ! in_array( str_replace( ABSPATH, '', $node ), $excludes, true ) ) { if ( is_dir( $node ) ) { if ( ! $this->pclZipAddDir( $node, $excludes ) ) { $error = true; break; } - } else if ( is_file( $node ) ) { + } elseif ( is_file( $node ) ) { if ( 0 === ( $rslt = $this->zip->add( $node, PCLZIP_OPT_REMOVE_PATH, ABSPATH ) ) ) { $error = true; break; @@ -657,7 +623,8 @@ class MainWP_Backup { $this->zip->delete( PCLZIP_OPT_BY_NAME, $file ); $add = $this->zip->add( $tmpfilename, PCLZIP_OPT_REMOVE_PATH, dirname( $filepath ), - PCLZIP_OPT_ADD_PATH, $localpath ); + PCLZIP_OPT_ADD_PATH, $localpath + ); unlink( $tmpfilename ); if ( ! empty( $add ) ) { return true; @@ -693,7 +660,7 @@ class MainWP_Backup { $this->zipArchiveSizeCount += filesize( $path ); $this->gcCnt ++; - //5 mb limit! + // 5 mb limit! if ( ! $this->loadFilesBeforeZip || ( filesize( $path ) > 5 * 1024 * 1024 ) ) { $this->zipArchiveFileCount ++; $added = $this->zip->addFile( $path, $zipEntryName ); @@ -719,7 +686,7 @@ class MainWP_Backup { $this->gcCnt = 0; } - //Over limits? + // Over limits? if ( ( ( $this->file_descriptors > 0 ) && ( $this->zipArchiveFileCount > $this->file_descriptors ) ) ) { // || $this->zipArchiveSizeCount >= (31457280 * 2)) $this->zip->close(); $this->zip = null; @@ -742,13 +709,11 @@ class MainWP_Backup { } public function createZipConsoleFullBackup( $filepath, $excludes, $addConfig, $includeCoreFiles, $excludezip, $excludenonwp ) { - // @TODO to work with 'zip' from system if PHP Zip library not available - //system('zip'); return false; } public function createBackupDB( $filepath_prefix, $archiveExt = false, &$archiver = null ) { - $timeout = 20 * 60 * 60; //20minutes + $timeout = 20 * 60 * 60; // @codingStandardsIgnoreStart @set_time_limit( $timeout ); @ini_set( 'max_execution_time', $timeout ); @@ -760,7 +725,7 @@ class MainWP_Backup { global $wpdb; $db_files = array(); - //Get all the tables + // Get all the tables $tables_db = $wpdb->get_results( 'SHOW TABLES FROM `' . DB_NAME . '`', ARRAY_N ); foreach ( $tables_db as $curr_table ) { if ( null !== $archiver ) { @@ -770,15 +735,15 @@ class MainWP_Backup { $table = $curr_table[0]; $currentfile = $filepath_prefix . '-' . MainWP_Helper::sanitize_filename( $table ) . '.sql'; - $db_files[] = $currentfile; + $db_files[] = $currentfile; if ( file_exists( $currentfile ) ) { continue; } - $fh = fopen( $currentfile . '.tmp', 'w' ); //or error; + $fh = fopen( $currentfile . '.tmp', 'w' ); // or error; fwrite( $fh, "\n\n" . 'DROP TABLE IF EXISTS ' . $table . ';' ); - //todo fix this - //$table_create = $wpdb->get_row( $wpdb->prepare( 'SHOW CREATE TABLE %s', $table ), ARRAY_N ); + // todo fix this + // $table_create = $wpdb->get_row( $wpdb->prepare( 'SHOW CREATE TABLE %s', $table ), ARRAY_N ); $table_create = $wpdb->get_row( 'SHOW CREATE TABLE ' . $table, ARRAY_N ); fwrite( $fh, "\n" . $table_create[1] . ";\n\n" ); @@ -839,11 +804,10 @@ class MainWP_Backup { @unlink( $db_file ); } } else { - //todo: throw exception! + // todo: throw exception! } } - return ( false !== $archiveExt ? array( 'filepath' => $archivefilePath ) : $db_files ); } } diff --git a/class/class-mainwp-child-back-up-buddy.php b/class/class-mainwp-child-back-up-buddy.php index 3b2e065..d4e12e4 100644 --- a/class/class-mainwp-child-back-up-buddy.php +++ b/class/class-mainwp-child-back-up-buddy.php @@ -16,25 +16,25 @@ */ class MainWP_Child_Back_Up_Buddy { - public static $instance = null; - public $plugin_translate = 'mainwp-child'; + public static $instance = null; + public $plugin_translate = 'mainwp-child'; public $is_backupbuddy_installed = false; static function Instance() { - if ( null === MainWP_Child_Back_Up_Buddy::$instance ) { - MainWP_Child_Back_Up_Buddy::$instance = new MainWP_Child_Back_Up_Buddy(); + if ( null === self::$instance ) { + self::$instance = new MainWP_Child_Back_Up_Buddy(); } - return MainWP_Child_Back_Up_Buddy::$instance; + return self::$instance; } public function __construct() { // To fix bug run dashboard on local machine - //if ( is_plugin_active( 'backupbuddy/backupbuddy.php' )) { + // if ( is_plugin_active( 'backupbuddy/backupbuddy.php' )) { if ( class_exists('pb_backupbuddy')) { $this->is_backupbuddy_installed = true; } - if (!$this->is_backupbuddy_installed) { + if ( ! $this->is_backupbuddy_installed) { return; } @@ -61,7 +61,7 @@ class MainWP_Child_Back_Up_Buddy { return $value; } - if (! MainWP_Helper::is_screen_with_update()) { + if ( ! MainWP_Helper::is_screen_with_update()) { return $value; } @@ -104,11 +104,12 @@ class MainWP_Child_Back_Up_Buddy { } } // ok - function do_reports_log($ext = '') { - if ($ext !== 'backupbuddy') + function do_reports_log( $ext = '') { + if ($ext !== 'backupbuddy') { return; + } - if (!$this->is_backupbuddy_installed) { + if ( ! $this->is_backupbuddy_installed) { return; } @@ -117,96 +118,97 @@ class MainWP_Child_Back_Up_Buddy { MainWP_Helper::check_methods( 'pb_backupbuddy', array( 'plugin_path' )); if ( ! class_exists( 'backupbuddy_core' ) ) { - if ( file_exists(pb_backupbuddy::plugin_path() . '/classes/core.php') ) - require_once( pb_backupbuddy::plugin_path() . '/classes/core.php' ); + if ( file_exists(pb_backupbuddy::plugin_path() . '/classes/core.php') ) { + require_once pb_backupbuddy::plugin_path() . '/classes/core.php'; + } } - if (file_exists(pb_backupbuddy::plugin_path() . '/classes/fileoptions.php')) - require_once( pb_backupbuddy::plugin_path() . '/classes/fileoptions.php' ); + if (file_exists(pb_backupbuddy::plugin_path() . '/classes/fileoptions.php')) { + require_once pb_backupbuddy::plugin_path() . '/classes/fileoptions.php'; + } MainWP_Helper::check_classes_exists(array( 'backupbuddy_core', 'pb_backupbuddy_fileoptions' )); MainWP_Helper::check_methods('backupbuddy_core', 'getLogDirectory'); // Backup type. $pretty_type = array( - 'full' => 'Full', - 'db' => 'Database', - 'files' => 'Files', + 'full' => 'Full', + 'db' => 'Database', + 'files' => 'Files', ); $recentBackups_list = glob( backupbuddy_core::getLogDirectory() . 'fileoptions/*.txt' ); + foreach ( $recentBackups_list as $backup_fileoptions ) { - foreach( $recentBackups_list as $backup_fileoptions ) { + $backup = new pb_backupbuddy_fileoptions( $backup_fileoptions, $read_only = true ); + if ( method_exists($backup, 'is_ok') && true !== ( $result = $backup->is_ok() ) ) { + continue; + } - $backup = new pb_backupbuddy_fileoptions( $backup_fileoptions, $read_only = true ); - if ( method_exists($backup, 'is_ok') && true !== ( $result = $backup->is_ok() ) ) { - continue; - } + $backup = &$backup->options; - $backup = &$backup->options; + if ( ! isset( $backup['serial'] ) || ( $backup['serial'] == '' ) ) { + continue; + } - if ( !isset( $backup['serial'] ) || ( $backup['serial'] == '' ) ) { - continue; - } + if ( ( $backup['finish_time'] >= $backup['start_time'] ) && ( 0 != $backup['start_time'] ) ) { + // it is ok + } else { + continue; + } - if ( ( $backup['finish_time'] >= $backup['start_time'] ) && ( 0 != $backup['start_time'] ) ) { - // it is ok - } else { - continue; - } + $backupType = ''; + if ( isset( $backup['profile'] ) && isset( $backup['profile']['type'] ) ) { + if (true === MainWP_Helper::check_properties('pb_backupbuddy', 'format', true)) { + if (true === MainWP_Helper::check_methods(pb_backupbuddy::$format, array( 'prettify' ), true)) { + $backupType = pb_backupbuddy::$format->prettify( $backup['profile']['type'], $pretty_type ); + } + } + } else { + if (true === MainWP_Helper::check_methods('backupbuddy_core', array( 'pretty_backup_type', 'getBackupTypeFromFile' ), true)) { + $backupType = backupbuddy_core::pretty_backup_type( backupbuddy_core::getBackupTypeFromFile( $backup['archive_file'] ) ); + } + } - $backupType = ''; - if ( isset( $backup['profile'] ) && isset( $backup['profile']['type'] ) ) { - if (true === MainWP_Helper::check_properties('pb_backupbuddy', 'format', true)) { - if (true === MainWP_Helper::check_methods(pb_backupbuddy::$format, array( 'prettify' ), true)) { - $backupType = pb_backupbuddy::$format->prettify( $backup['profile']['type'], $pretty_type ); - } - } - } else { - if (true === MainWP_Helper::check_methods('backupbuddy_core', array( 'pretty_backup_type', 'getBackupTypeFromFile' ), true)) { - $backupType = backupbuddy_core::pretty_backup_type( backupbuddy_core::getBackupTypeFromFile( $backup['archive_file'] ) ); - } - } + if ( '' == $backupType ) { + $backupType = 'Unknown'; + } - if ( '' == $backupType ) { - $backupType = 'Unknown'; - } + $finish_time = $backup['finish_time']; + $message = 'BackupBuddy ' . $backupType . ' finished'; + if ( ! empty($finish_time)) { + do_action( 'mainwp_reports_backupbuddy_backup', $message, $backupType, $finish_time); + } + } - $finish_time = $backup['finish_time']; - $message = 'BackupBuddy ' . $backupType . ' finished'; - if (!empty($finish_time)) { - do_action( 'mainwp_reports_backupbuddy_backup', $message, $backupType, $finish_time); - } - } + if ( file_exists(pb_backupbuddy::plugin_path() . '/destinations/live/live_periodic.php') ) { + require_once pb_backupbuddy::plugin_path() . '/destinations/live/live_periodic.php'; - if ( file_exists(pb_backupbuddy::plugin_path() . '/destinations/live/live_periodic.php') ) { - require_once( pb_backupbuddy::plugin_path() . '/destinations/live/live_periodic.php' ); + MainWP_Helper::check_classes_exists(array( 'backupbuddy_live_periodic' )); + MainWP_Helper::check_methods('backupbuddy_live_periodic', 'get_stats'); - MainWP_Helper::check_classes_exists(array( 'backupbuddy_live_periodic' )); - MainWP_Helper::check_methods('backupbuddy_live_periodic', 'get_stats'); + $state = backupbuddy_live_periodic::get_stats(); + if (is_array($state) && isset($state['stats'])) { - $state = backupbuddy_live_periodic::get_stats(); - if (is_array($state) && isset($state['stats'])) { + if ( is_array($state['stats'] ) && isset( $state['stats']['last_remote_snapshot'] )) { + if (isset( $state['stats']['last_remote_snapshot_response'] )) { + $resp = $state['stats']['last_remote_snapshot_response']; + if ( isset( $resp['success'] ) && $resp['success']) { + $finish_time = $state['stats']['last_remote_snapshot']; + $backupType = 'Live Backup to cloud'; + $message = 'BackupBuddy ' . $backupType . ' finished'; + if ( ! empty($finish_time)) { + do_action( 'mainwp_reports_backupbuddy_backup', $message, $backupType, $finish_time); + } - if ( is_array($state['stats'] ) && isset( $state['stats']['last_remote_snapshot'] )) { - if (isset( $state['stats']['last_remote_snapshot_response'] )) { - $resp = $state['stats']['last_remote_snapshot_response']; - if ( isset( $resp['success'] ) && $resp['success']) { - $finish_time = $state['stats']['last_remote_snapshot']; - $backupType = 'Live Backup to cloud'; - $message = 'BackupBuddy ' . $backupType . ' finished'; - if (!empty($finish_time)) { - do_action( 'mainwp_reports_backupbuddy_backup', $message, $backupType, $finish_time); - } + } + } + } - } - } - } - - } - } - } catch( Exception $e ) { + } + } + } catch ( Exception $e ) { } } @@ -218,10 +220,10 @@ class MainWP_Child_Back_Up_Buddy { } if ( ! class_exists( 'backupbuddy_core' ) ) { - require_once( pb_backupbuddy::plugin_path() . '/classes/core.php' ); + require_once pb_backupbuddy::plugin_path() . '/classes/core.php'; } - if ( !isset( pb_backupbuddy::$options ) ) { + if ( ! isset( pb_backupbuddy::$options ) ) { pb_backupbuddy::load(); } @@ -383,7 +385,7 @@ class MainWP_Child_Back_Up_Buddy { $type = isset($_POST['type']) ? $_POST['type'] : ''; if ($type !== 'general_settings' && $type !== 'advanced_settings' && $type !== 'all' ) { - return array('error' => __('Invalid data. Please check and try again.') ); + return array( 'error' => __('Invalid data. Please check and try again.') ); } $filter_advanced_settings = array( @@ -439,7 +441,6 @@ class MainWP_Child_Back_Up_Buddy { 'ignore_zip_symlinks', ); - $filter_general_settings = array( 'importbuddy_pass_hash', 'importbuddy_pass_length', @@ -470,7 +471,7 @@ class MainWP_Child_Back_Up_Buddy { 'email_notify_error', 'email_notify_error_subject', 'email_notify_error_body', - 'email_return' + 'email_return', ); $filter_profile0_values = array( @@ -479,7 +480,7 @@ class MainWP_Child_Back_Up_Buddy { 'excludes', 'integrity_check', 'skip_database_dump', - 'backup_nonwp_tables' + 'backup_nonwp_tables', ); $settings = unserialize(base64_decode($_POST['options'])); @@ -488,35 +489,35 @@ class MainWP_Child_Back_Up_Buddy { if (is_array($settings)) { if ($type === 'all' || 'general_settings' === $type) { - foreach($filter_general_settings as $field) { - if(isset($settings[$field])) { - $save_settings[$field] = $settings[$field]; + foreach ($filter_general_settings as $field) { + if (isset($settings[ $field ])) { + $save_settings[ $field ] = $settings[ $field ]; } } } if ($type === 'all' || 'advanced_settings' === $type) { - foreach($filter_advanced_settings as $field) { - if(isset($settings[$field])) { - $save_settings[$field] = $settings[$field]; + foreach ($filter_advanced_settings as $field) { + if (isset($settings[ $field ])) { + $save_settings[ $field ] = $settings[ $field ]; } } } } - if (!empty($save_settings)) { + if ( ! empty($save_settings)) { $newOptions = pb_backupbuddy::$options; - foreach($newOptions as $key => $val) { - if (isset($save_settings[$key])) { - $newOptions[$key] = $save_settings[$key]; + foreach ($newOptions as $key => $val) { + if (isset($save_settings[ $key ])) { + $newOptions[ $key ] = $save_settings[ $key ]; } } if (isset($newOptions['profiles']) && isset($newOptions['profiles'][0])) { foreach ($filter_profile0_values as $field) { - if (isset($settings[$field])) { - $newOptions['profiles'][0][$field] = $settings[$field]; + if (isset($settings[ $field ])) { + $newOptions['profiles'][0][ $field ] = $settings[ $field ]; } } } @@ -526,7 +527,7 @@ class MainWP_Child_Back_Up_Buddy { } global $wpdb; - $option = 'pb_' . pb_backupbuddy::settings( 'slug' ); + $option = 'pb_' . pb_backupbuddy::settings( 'slug' ); $newOptions = sanitize_option( $option, $newOptions ); $newOptions = maybe_serialize( $newOptions ); @@ -534,7 +535,7 @@ class MainWP_Child_Back_Up_Buddy { $wpdb->update( $wpdb->options, array( 'option_value' => $newOptions ), array( 'option_name' => $option ) ); $information['backupDirectoryDefault'] = backupbuddy_core::_getBackupDirectoryDefault(); - $information['result'] = 'SUCCESS'; + $information['result'] = 'SUCCESS'; } return $information; @@ -544,12 +545,12 @@ class MainWP_Child_Back_Up_Buddy { // Keep log serial. $old_log_serial = pb_backupbuddy::$options['log_serial']; - $keepDestNote = ''; - $remote_destinations = pb_backupbuddy::$options['remote_destinations']; + $keepDestNote = ''; + $remote_destinations = pb_backupbuddy::$options['remote_destinations']; pb_backupbuddy::$options = pb_backupbuddy::settings( 'default_options' ); if ( '1' == $_POST['keep_destinations'] ) { pb_backupbuddy::$options['remote_destinations'] = $remote_destinations; - $keepDestNote = ' ' . __( 'Remote destination settings were not reset.', 'mainwp-child' ); + $keepDestNote = ' ' . __( 'Remote destination settings were not reset.', 'mainwp-child' ); } // Replace log serial. @@ -562,12 +563,15 @@ class MainWP_Child_Back_Up_Buddy { backupbuddy_core::addNotification( 'settings_reset', 'Plugin settings reset', $resetNote . $keepDestNote ); $information['message'] = $resetNote . $keepDestNote; - $information['result'] = 'SUCCESS'; + $information['result'] = 'SUCCESS'; return $information; } function get_notifications() { - return array('result' => 'SUCCESS', 'notifications' => backupbuddy_core::getNotifications() ); + return array( + 'result' => 'SUCCESS', + 'notifications' => backupbuddy_core::getNotifications(), + ); } function get_schedules_run_time() { @@ -587,7 +591,7 @@ class MainWP_Child_Back_Up_Buddy { } // Determine next run. - $next_run = wp_next_scheduled( 'backupbuddy_cron', array( 'run_scheduled_backup', array( (int)$schedule_id ) ) ); + $next_run = wp_next_scheduled( 'backupbuddy_cron', array( 'run_scheduled_backup', array( (int) $schedule_id ) ) ); if ( false === $next_run ) { $next_run = 'Error: Cron event not found'; } else { @@ -598,7 +602,7 @@ class MainWP_Child_Back_Up_Buddy { 'Last run: ' . $last_run . '
' . 'Next run: ' . $next_run; - $schedules_run_time[$schedule_id] = $run_time; + $schedules_run_time[ $schedule_id ] = $run_time; } @@ -606,10 +610,10 @@ class MainWP_Child_Back_Up_Buddy { } function schedules_list() { - $information = array(); - $information['schedules'] = pb_backupbuddy::$options['schedules']; + $information = array(); + $information['schedules'] = pb_backupbuddy::$options['schedules']; $information['next_schedule_index'] = pb_backupbuddy::$options['next_schedule_index']; - $information['schedules_run_time'] = $this->get_schedules_run_time(); + $information['schedules_run_time'] = $this->get_schedules_run_time(); // to fix missing destination notice if (isset(pb_backupbuddy::$options['remote_destinations'])) { // update @@ -623,16 +627,16 @@ class MainWP_Child_Back_Up_Buddy { function run_scheduled_backup() { if ( ! is_main_site() ) { // Only run for main site or standalone. Multisite subsites do not allow schedules. - return array('error' => __('Only run for main site or standalone. Multisite subsites do not allow schedules', 'mainwp-child') ); + return array( 'error' => __('Only run for main site or standalone. Multisite subsites do not allow schedules', 'mainwp-child') ); } $schedule_id = (int) $_POST['schedule_id']; - if ( !isset( pb_backupbuddy::$options['schedules'][$schedule_id] ) || ! is_array( pb_backupbuddy::$options['schedules'][$schedule_id] ) ) { - return array('error' => __( 'Error: not found the backup schedule or invalid data', 'mainwp-child' )); + if ( ! isset( pb_backupbuddy::$options['schedules'][ $schedule_id ] ) || ! is_array( pb_backupbuddy::$options['schedules'][ $schedule_id ] ) ) { + return array( 'error' => __( 'Error: not found the backup schedule or invalid data', 'mainwp-child' ) ); } - pb_backupbuddy::alert( 'Manually running scheduled backup "' . pb_backupbuddy::$options['schedules'][$schedule_id]['title'] . '" in the background.' . '
' . + pb_backupbuddy::alert( 'Manually running scheduled backup "' . pb_backupbuddy::$options['schedules'][ $schedule_id ]['title'] . '" in the background.' . '
' . __( 'Note: If there is no site activity there may be delays between steps in the backup. Access the site or use a 3rd party service, such as a free pinging service, to generate site activity.', 'it-l10n-backupbuddy' ) ); pb_backupbuddy_cron::_run_scheduled_backup( $schedule_id ); @@ -644,46 +648,46 @@ class MainWP_Child_Back_Up_Buddy { function save_scheduled_backup() { $schedule_id = intval($_POST['schedule_id']); - $schedule = unserialize(base64_decode($_POST['data'])); + $schedule = unserialize(base64_decode($_POST['data'])); - if (!is_array($schedule)) { - return array('error' => __( 'Invalid schedule data', 'mainwp-child' )); + if ( ! is_array($schedule)) { + return array( 'error' => __( 'Invalid schedule data', 'mainwp-child' ) ); } $information = array(); // add new - if (!isset(pb_backupbuddy::$options['schedules'][$schedule_id])) { + if ( ! isset(pb_backupbuddy::$options['schedules'][ $schedule_id ])) { $next_index = pb_backupbuddy::$options['next_schedule_index']; pb_backupbuddy::$options['next_schedule_index']++; // This change will be saved in savesettings function below. - pb_backupbuddy::$options['schedules'][$schedule_id] = $schedule; + pb_backupbuddy::$options['schedules'][ $schedule_id ] = $schedule; $result = backupbuddy_core::schedule_event( $schedule['first_run'], $schedule['interval'], 'run_scheduled_backup', array( $schedule_id ) ); if ( $result === false ) { - return array('error' => 'Error scheduling event with WordPress. Your schedule may not work properly. Please try again. Error #3488439b. Check your BackupBuddy error log for details.'); + return array( 'error' => 'Error scheduling event with WordPress. Your schedule may not work properly. Please try again. Error #3488439b. Check your BackupBuddy error log for details.' ); } } else { - $first_run = $schedule['first_run']; - $next_scheduled_time = wp_next_scheduled( 'backupbuddy_cron', array( 'run_scheduled_backup', array( (int)$schedule_id ) ) ); - backupbuddy_core::unschedule_event( $next_scheduled_time, 'backupbuddy_cron', array( 'run_scheduled_backup', array( (int)$schedule_id ) ) ); - backupbuddy_core::schedule_event( $first_run, $schedule['interval'], 'run_scheduled_backup', array( (int)$schedule_id ) ); // Add new schedule. - pb_backupbuddy::$options['schedules'][$schedule_id] = $schedule; + $first_run = $schedule['first_run']; + $next_scheduled_time = wp_next_scheduled( 'backupbuddy_cron', array( 'run_scheduled_backup', array( (int) $schedule_id ) ) ); + backupbuddy_core::unschedule_event( $next_scheduled_time, 'backupbuddy_cron', array( 'run_scheduled_backup', array( (int) $schedule_id ) ) ); + backupbuddy_core::schedule_event( $first_run, $schedule['interval'], 'run_scheduled_backup', array( (int) $schedule_id ) ); // Add new schedule. + pb_backupbuddy::$options['schedules'][ $schedule_id ] = $schedule; } pb_backupbuddy::save(); - $information['result'] = 'SUCCESS'; - $information['schedules'] = pb_backupbuddy::$options['schedules']; + $information['result'] = 'SUCCESS'; + $information['schedules'] = pb_backupbuddy::$options['schedules']; $information['next_schedule_index'] = pb_backupbuddy::$options['next_schedule_index']; - $information['schedules_run_time'] = $this->get_schedules_run_time(); + $information['schedules_run_time'] = $this->get_schedules_run_time(); return $information; } function save_profile() { $profile_id = $_POST['profile_id']; - $profile = unserialize(base64_decode($_POST['data'])); + $profile = unserialize(base64_decode($_POST['data'])); - if (!is_array($profile)) { - return array('error' => __( 'Invalid profile data', 'mainwp-child' )); + if ( ! is_array($profile)) { + return array( 'error' => __( 'Invalid profile data', 'mainwp-child' ) ); } - pb_backupbuddy::$options['profiles'][$profile_id] = $profile; + pb_backupbuddy::$options['profiles'][ $profile_id ] = $profile; pb_backupbuddy::save(); $information['result'] = 'SUCCESS'; @@ -694,8 +698,9 @@ class MainWP_Child_Back_Up_Buddy { function delete_profile() { $profile_id = $_POST['profile_id']; - if (isset(pb_backupbuddy::$options['profiles'][$profile_id])) - unset(pb_backupbuddy::$options['profiles'][$profile_id]); + if (isset(pb_backupbuddy::$options['profiles'][ $profile_id ])) { + unset(pb_backupbuddy::$options['profiles'][ $profile_id ]); + } pb_backupbuddy::save(); $information['result'] = 'SUCCESS'; @@ -703,13 +708,13 @@ class MainWP_Child_Back_Up_Buddy { } function delete_backup( $type = 'default', $subsite_mode = false ) { - $item_ids = $_POST['item_ids']; - $item_ids = explode(',', $item_ids); + $item_ids = $_POST['item_ids']; + $item_ids = explode(',', $item_ids); $information = array(); if ( is_array( $item_ids ) && count( $item_ids ) > 0 ) { - $needs_save = false; + $needs_save = false; $deleted_files = array(); - foreach( $item_ids as $item ) { + foreach ( $item_ids as $item ) { if ( file_exists( backupbuddy_core::getBackupDirectory() . $item ) ) { if ( @unlink( backupbuddy_core::getBackupDirectory() . $item ) === true ) { $deleted_files[] = $item; @@ -722,7 +727,7 @@ class MainWP_Child_Back_Up_Buddy { $backup_files = array(); } if ( count( $backup_files ) > 5 ) { // Keep a minimum number of backups in array for stats. - $this_serial = backupbuddy_core::get_serial_from_file( $item ); + $this_serial = backupbuddy_core::get_serial_from_file( $item ); $fileoptions_file = backupbuddy_core::getLogDirectory() . 'fileoptions/' . $this_serial . '.txt'; if ( file_exists( $fileoptions_file ) ) { @unlink( $fileoptions_file ); @@ -750,7 +755,7 @@ class MainWP_Child_Back_Up_Buddy { if ( isset( $data['syncBackupBuddy'] ) && $data['syncBackupBuddy'] ) { try { $information['syncBackupBuddy'] = $this->get_sync_data(); - } catch(Exception $e) { + } catch (Exception $e) { } } @@ -766,30 +771,29 @@ class MainWP_Child_Back_Up_Buddy { MainWP_Helper::check_methods('pb_backupbuddy', array( 'plugin_path' ) ); $plugin_path = pb_backupbuddy::plugin_path(); - if (file_exists($plugin_path . '/classes/core.php')) - require_once( $plugin_path . '/classes/core.php' ); + if (file_exists($plugin_path . '/classes/core.php')) { + require_once $plugin_path . '/classes/core.php'; + } } MainWP_Helper::check_classes_exists(array( 'backupbuddy_core', 'backupbuddy_api' )); - MainWP_Helper::check_methods('backupbuddy_core', array( 'get_plugins_root', 'get_themes_root', 'get_media_root' ) ); + MainWP_Helper::check_methods('backupbuddy_core', array( 'get_plugins_root', 'get_themes_root', 'get_media_root' ) ); MainWP_Helper::check_methods('backupbuddy_api', array( 'getOverview' ) ); - - - $data = array(); - $data['plugins_root'] = backupbuddy_core::get_plugins_root(); - $data['themes_root'] = backupbuddy_core::get_themes_root(); - $data['media_root'] = backupbuddy_core::get_media_root(); + $data = array(); + $data['plugins_root'] = backupbuddy_core::get_plugins_root(); + $data['themes_root'] = backupbuddy_core::get_themes_root(); + $data['media_root'] = backupbuddy_core::get_media_root(); $data['additional_tables'] = $this->pb_additional_tables(); - $data['abspath'] = ABSPATH; + $data['abspath'] = ABSPATH; - $getOverview = backupbuddy_api::getOverview(); - $data['editsSinceLastBackup'] = $getOverview['editsSinceLastBackup'] ; + $getOverview = backupbuddy_api::getOverview(); + $data['editsSinceLastBackup'] = $getOverview['editsSinceLastBackup']; if ( isset( $getOverview['lastBackupStats']['finish'] ) ) { - $finish_time = $getOverview['lastBackupStats']['finish'] ; - $time = $this->localize_time( $finish_time ); - $data['lastBackupStats'] = date("M j - g:i A", $time); + $finish_time = $getOverview['lastBackupStats']['finish']; + $time = $this->localize_time( $finish_time ); + $data['lastBackupStats'] = date('M j - g:i A', $time); $data['lasttime_backup'] = $finish_time; MainWP_Helper::update_lasttime_backup('backupbuddy', $finish_time); // to support Require Backup Before Update feature } else { @@ -797,8 +801,8 @@ class MainWP_Child_Back_Up_Buddy { } return $data; - } catch(Exception $e) { - // not exit here + } catch (Exception $e) { + // not exit here } return false; @@ -814,37 +818,36 @@ class MainWP_Child_Back_Up_Buddy { } function backup_list() { - require_once( pb_backupbuddy::plugin_path() . '/destinations/bootstrap.php' ); - $information = array(); - $information['backup_list'] = $this->get_backup_list(); + require_once pb_backupbuddy::plugin_path() . '/destinations/bootstrap.php'; + $information = array(); + $information['backup_list'] = $this->get_backup_list(); $information['recent_backup_list'] = $this->get_recent_backup_list(); - //$information['destinations_list'] = pb_backupbuddy_destinations::get_destinations_list(); - $backup_directory = backupbuddy_core::getBackupDirectory(); - $backup_directory = str_replace( '\\', '/', $backup_directory ); - $backup_directory = rtrim( $backup_directory, '/\\' ) . '/'; - $information['backupDirectoryWithinSiteRoot'] = (FALSE !== stristr( $backup_directory, ABSPATH )) ? 'yes' : 'no'; - $information['result'] = 'SUCCESS'; + // $information['destinations_list'] = pb_backupbuddy_destinations::get_destinations_list(); + $backup_directory = backupbuddy_core::getBackupDirectory(); + $backup_directory = str_replace( '\\', '/', $backup_directory ); + $backup_directory = rtrim( $backup_directory, '/\\' ) . '/'; + $information['backupDirectoryWithinSiteRoot'] = ( false !== stristr( $backup_directory, ABSPATH ) ) ? 'yes' : 'no'; + $information['result'] = 'SUCCESS'; return $information; } function save_note() { - if ( !isset( pb_backupbuddy::$classes['zipbuddy'] ) ) { - require_once( pb_backupbuddy::plugin_path() . '/lib/zipbuddy/zipbuddy.php' ); + if ( ! isset( pb_backupbuddy::$classes['zipbuddy'] ) ) { + require_once pb_backupbuddy::plugin_path() . '/lib/zipbuddy/zipbuddy.php'; pb_backupbuddy::$classes['zipbuddy'] = new pluginbuddy_zipbuddy( backupbuddy_core::getBackupDirectory() ); } $backup_file = $_POST['backup_file']; - $note = $_POST['note']; - $note = preg_replace( "/[[:space:]]+/", ' ', $note ); - $note = preg_replace( "/[^[:print:]]/", '', $note ); - $note = substr( $note, 0, 200 ); - + $note = $_POST['note']; + $note = preg_replace( '/[[:space:]]+/', ' ', $note ); + $note = preg_replace( '/[^[:print:]]/', '', $note ); + $note = substr( $note, 0, 200 ); // Returns true on success, else the error message. - $old_comment = pb_backupbuddy::$classes['zipbuddy']->get_comment( $backup_file ); - $comment = backupbuddy_core::normalize_comment_data( $old_comment ); + $old_comment = pb_backupbuddy::$classes['zipbuddy']->get_comment( $backup_file ); + $comment = backupbuddy_core::normalize_comment_data( $old_comment ); $comment['note'] = $note; - //$new_comment = base64_encode( serialize( $comment ) ); + // $new_comment = base64_encode( serialize( $comment ) ); $comment_result = pb_backupbuddy::$classes['zipbuddy']->set_comment( $backup_file, $comment ); @@ -856,7 +859,7 @@ class MainWP_Child_Back_Up_Buddy { // Even if we cannot save the note into the archive file, store it in internal settings. $serial = backupbuddy_core::get_serial_from_file( $backup_file ); - require_once( pb_backupbuddy::plugin_path() . '/classes/fileoptions.php' ); + require_once pb_backupbuddy::plugin_path() . '/classes/fileoptions.php'; pb_backupbuddy::status( 'details', 'Fileoptions instance #24.' ); $backup_options = new pb_backupbuddy_fileoptions( backupbuddy_core::getLogDirectory() . 'fileoptions/' . $serial . '.txt' ); if ( true === ( $result = $backup_options->is_ok() ) ) { @@ -868,11 +871,15 @@ class MainWP_Child_Back_Up_Buddy { function get_hash() { $callback_data = $_POST['callback_data']; - $file = backupbuddy_core::getBackupDirectory() . $callback_data; - if (file_exists($file)) - return array( 'result' =>'SUCCESS', 'hash' => md5_file( $file ) ); - else - return array( 'error' =>'Not found the file' ); + $file = backupbuddy_core::getBackupDirectory() . $callback_data; + if (file_exists($file)) { + return array( + 'result' => 'SUCCESS', + 'hash' => md5_file( $file ), + ); + } else { + return array( 'error' => 'Not found the file' ); + } } function zip_viewer() { @@ -881,33 +888,33 @@ class MainWP_Child_Back_Up_Buddy { $max_cache_time = 86400; // This is the root directory we want the listing for - $root = $_POST[ 'dir' ]; + $root = $_POST['dir']; $root_len = strlen( $root ); // This will identify the backup zip file we want to list - $serial = $_POST[ 'serial' ]; + $serial = $_POST['serial']; $alerts = array(); // The fileoptions file that contains the file tree information - require_once( pb_backupbuddy::plugin_path() . '/classes/fileoptions.php' ); + require_once pb_backupbuddy::plugin_path() . '/classes/fileoptions.php'; $fileoptions_file = backupbuddy_core::getLogDirectory() . 'fileoptions/' . $serial . '-filetree.txt'; // Purge cache if too old. if ( file_exists( $fileoptions_file ) && ( ( time() - filemtime( $fileoptions_file ) ) > $max_cache_time ) ) { if ( false === unlink( $fileoptions_file ) ) { - $alerts[] = 'Error #456765545. Unable to wipe cached fileoptions file `' . $fileoptions_file . '`.' ; + $alerts[] = 'Error #456765545. Unable to wipe cached fileoptions file `' . $fileoptions_file . '`.'; } } pb_backupbuddy::status( 'details', 'Fileoptions instance #28.' ); $fileoptions = new pb_backupbuddy_fileoptions( $fileoptions_file ); - $zip_viewer = $_POST[ 'zip_viewer' ]; + $zip_viewer = $_POST['zip_viewer']; // Either we are getting cached file tree information or we need to create afresh if ( true !== ( $result = $fileoptions->is_ok() ) ) { // Get file listing. - require_once( pb_backupbuddy::plugin_path() . '/lib/zipbuddy/zipbuddy.php' ); + require_once pb_backupbuddy::plugin_path() . '/lib/zipbuddy/zipbuddy.php'; pb_backupbuddy::$classes['zipbuddy'] = new pluginbuddy_zipbuddy( ABSPATH, array(), 'unzip' ); - $files = pb_backupbuddy::$classes['zipbuddy']->get_file_list( backupbuddy_core::getBackupDirectory() . str_replace( '\\/', '', $zip_viewer ) ); - $fileoptions->options = $files; + $files = pb_backupbuddy::$classes['zipbuddy']->get_file_list( backupbuddy_core::getBackupDirectory() . str_replace( '\\/', '', $zip_viewer ) ); + $fileoptions->options = $files; $fileoptions->save(); } else { $files = &$fileoptions->options; @@ -922,12 +929,12 @@ class MainWP_Child_Back_Up_Buddy { $subdirs = array(); // Strip out any files/subdirs that are not actually directly under the given root - foreach( $files as $key => $file ) { + foreach ( $files as $key => $file ) { // If shorter than root length then certainly is not within this (root) directory. // It's a quick test that is more effective the longer the root (the deeper you go // into the tree) - if ( strlen( $file[ 0 ] ) < $root_len ) { + if ( strlen( $file[0] ) < $root_len ) { unset( $files[ $key ] ); continue; @@ -938,7 +945,7 @@ class MainWP_Child_Back_Up_Buddy { // e.g., with root=this/dir/path/ // these will fail: file=this/dir/file; file=this/dir/otherpath/; file=that/dir/path/file // and these would succeed: file=this/dir/path/; file=this/dir/path/file; file=this/dir/path/otherpath/ - if ( substr( $file[ 0 ], 0, $root_len ) != $root ) { + if ( substr( $file[0], 0, $root_len ) != $root ) { unset( $files[ $key ] ); continue; @@ -948,7 +955,7 @@ class MainWP_Child_Back_Up_Buddy { // If the file _is_ the root then we don't want to list it // Don't want to do this on _every_ file as very specific so do it here after we have // weeded out files for more common reasons - if ( 0 == strcmp( $file[ 0 ], $root ) ) { + if ( 0 == strcmp( $file[0], $root ) ) { unset( $files[ $key ] ); continue; @@ -957,7 +964,7 @@ class MainWP_Child_Back_Up_Buddy { // Interesting file, get the path with the root prefix removed // Note: root may be empty in which case the result will be the original filename - $unrooted_file = substr( $file[ 0 ], $root_len ); + $unrooted_file = substr( $file[0], $root_len ); // We must ensure that we list the subdir/ even if subdir/ does not appear // as a distinct entry in the list but only subdir/file or subdir/subsubdir/ or @@ -969,14 +976,14 @@ class MainWP_Child_Back_Up_Buddy { $subdir = substr( $unrooted_file, 0, ( $pos + 1 ) ); // Have we already seen it - if ( !in_array( $subdir, $subdirs ) ) { + if ( ! in_array( $subdir, $subdirs ) ) { // Not already seen so record we have seen it and modify this entry to be // specific for the subdir/ $subdirs[] = $subdir; // Replace the original (rooted) file name - $files[ $key ][ 0 ] = $subdir; + $files[ $key ][0] = $subdir; } else { @@ -990,31 +997,34 @@ class MainWP_Child_Back_Up_Buddy { // This is just like file within the root // Replace the original (rooted) file name - $files[ $key ][ 0 ] = $unrooted_file; + $files[ $key ][0] = $unrooted_file; } } - return array('result' => 'SUCCESS', 'files' => $files, 'message' => implode('
', $alerts)); - + return array( + 'result' => 'SUCCESS', + 'files' => $files, + 'message' => implode('
', $alerts), + ); } function exclude_tree() { $root = substr( ABSPATH, 0, strlen( ABSPATH ) - 1 ) . '/' . ltrim( urldecode( $_POST['dir'] ), '/\\' ); - if( file_exists( $root ) ) { + if ( file_exists( $root ) ) { $files = scandir( $root ); natcasesort( $files ); // Sort with directories first. - $sorted_files = array(); // Temporary holder for sorting files. + $sorted_files = array(); // Temporary holder for sorting files. $sorted_directories = array(); // Temporary holder for sorting directories. - foreach( $files as $file ) { + foreach ( $files as $file ) { if ( ( $file == '.' ) || ( $file == '..' ) ) { continue; } - if( is_file( str_replace( '//', '/', $root . $file ) ) ) { + if ( is_file( str_replace( '//', '/', $root . $file ) ) ) { array_push( $sorted_files, $file ); } else { array_unshift( $sorted_directories, $file ); @@ -1027,13 +1037,13 @@ class MainWP_Child_Back_Up_Buddy { ob_start(); - if( count( $files ) > 0 ) { // Files found. + if ( count( $files ) > 0 ) { // Files found. echo '