From aa89db5f6cc3467c40a4a3eab98fbed9f2c9dc11 Mon Sep 17 00:00:00 2001 From: thanghv Date: Wed, 6 May 2020 20:22:11 +0700 Subject: [PATCH] Refactoring --- class/class-mainwp-backup.php | 200 ++------- class/class-mainwp-child-back-up-buddy.php | 2 +- .../class-mainwp-child-back-up-wordpress.php | 6 +- class/class-mainwp-child-back-wp-up.php | 2 +- class/class-mainwp-child-branding.php | 2 +- class/class-mainwp-child-ithemes-security.php | 2 +- class/class-mainwp-child-links-checker.php | 2 +- class/class-mainwp-child-pagespeed.php | 2 +- class/class-mainwp-child-plugins-check.php | 2 +- .../class-mainwp-child-server-information.php | 370 ++++++++--------- class/class-mainwp-child-skeleton-key.php | 2 +- class/class-mainwp-child-staging.php | 70 ++-- class/class-mainwp-child-themes-check.php | 2 +- class/class-mainwp-child-timecapsule.php | 8 +- ...lass-mainwp-child-updraft-plus-backups.php | 392 +----------------- ...ass-mainwp-child-vulnerability-checker.php | 2 +- .../class-mainwp-child-woocommerce-status.php | 2 +- class/class-mainwp-child-wordfence.php | 18 +- class/class-mainwp-child-wp-rocket.php | 4 +- ...ass-mainwp-child-wpvivid-backuprestore.php | 2 +- class/class-mainwp-child.php | 136 +++--- class/class-mainwp-client-report.php | 20 +- class/class-mainwp-clone-install.php | 111 ++--- class/class-mainwp-clone.php | 76 ++-- class/class-mainwp-custom-post-type.php | 2 +- class/class-mainwp-helper.php | 2 +- class/class-mainwp-keyword-links.php | 6 +- class/class-mainwp-security.php | 8 +- class/class-mainwp-wordpress-seo.php | 2 +- class/class-tar-archiver.php | 124 +++--- 30 files changed, 506 insertions(+), 1073 deletions(-) diff --git a/class/class-mainwp-backup.php b/class/class-mainwp-backup.php index fe08fac..b702784 100644 --- a/class/class-mainwp-backup.php +++ b/class/class-mainwp-backup.php @@ -31,7 +31,7 @@ class MainWP_Backup { /** * Create full backup */ - public function createFullBackup( $excludes, $filePrefix = '', $addConfig = false, $includeCoreFiles = false, $file_descriptors = 0, $fileSuffix = false, $excludezip = false, $excludenonwp = false, $loadFilesBeforeZip = true, $ext = 'zip', $pid = false, $append = false ) { + public function create_full_backup( $excludes, $filePrefix = '', $addConfig = false, $includeCoreFiles = false, $file_descriptors = 0, $fileSuffix = false, $excludezip = false, $excludenonwp = false, $loadFilesBeforeZip = true, $ext = 'zip', $pid = false, $append = false ) { $this->file_descriptors = $file_descriptors; $this->loadFilesBeforeZip = $loadFilesBeforeZip; @@ -67,7 +67,7 @@ class MainWP_Backup { $ext = '.zip'; } else { $this->archiver = new Tar_Archiver( $this, $ext, $pid ); - $ext = $this->archiver->getExtension(); + $ext = $this->archiver->get_extension(); } if ( ( false !== $fileSuffix ) && ! empty( $fileSuffix ) ) { @@ -95,13 +95,13 @@ class MainWP_Backup { // phpcs:enable if ( null !== $this->archiver ) { - $success = $this->archiver->createFullBackup( $filepath, $excludes, $addConfig, $includeCoreFiles, $excludezip, $excludenonwp, $append ); - } elseif ( $this->checkZipSupport() ) { - $success = $this->createZipFullBackup( $filepath, $excludes, $addConfig, $includeCoreFiles, $excludezip, $excludenonwp ); - } elseif ( $this->checkZipConsole() ) { - $success = $this->createZipConsoleFullBackup( $filepath, $excludes, $addConfig, $includeCoreFiles, $excludezip, $excludenonwp ); + $success = $this->archiver->create_full_backup( $filepath, $excludes, $addConfig, $includeCoreFiles, $excludezip, $excludenonwp, $append ); + } elseif ( $this->check_zip_support() ) { + $success = $this->create_zip_full_backup( $filepath, $excludes, $addConfig, $includeCoreFiles, $excludezip, $excludenonwp ); + } elseif ( $this->check_zip_console() ) { + $success = $this->create_zip_console_full_backup( $filepath, $excludes, $addConfig, $includeCoreFiles, $excludezip, $excludenonwp ); } else { - $success = $this->createZipPclFullBackup2( $filepath, $excludes, $addConfig, $includeCoreFiles, $excludezip, $excludenonwp ); + $success = $this->create_zip_pcl_full_backup2( $filepath, $excludes, $addConfig, $includeCoreFiles, $excludezip, $excludenonwp ); } return ( $success ) ? array( @@ -111,7 +111,7 @@ class MainWP_Backup { ) : false; } - public function zipFile( $files, $archive ) { + public function zip_file( $files, $archive ) { $this->timeout = 20 * 60 * 60; $mem = '512M'; // phpcs:disable @@ -125,19 +125,19 @@ class MainWP_Backup { } if ( null !== $this->archiver ) { - $success = $this->archiver->zipFile( $files, $archive ); - } elseif ( $this->checkZipSupport() ) { - $success = $this->_zipFile( $files, $archive ); - } elseif ( $this->checkZipConsole() ) { - $success = $this->_zipFileConsole( $files, $archive ); + $success = $this->archiver->zip_file( $files, $archive ); + } elseif ( $this->check_zip_support() ) { + $success = $this->m_zip_file( $files, $archive ); + } elseif ( $this->check_zip_console() ) { + $success = $this->m_zip_file_console( $files, $archive ); } else { - $success = $this->_zipFilePcl( $files, $archive ); + $success = $this->m_zip_file_pcl( $files, $archive ); } return $success; } - public function _zipFile( $files, $archive ) { + public function m_zip_file( $files, $archive ) { $this->zip = new ZipArchive(); $this->zipArchiveFileCount = 0; $this->zipArchiveSizeCount = 0; @@ -145,7 +145,7 @@ class MainWP_Backup { $zipRes = $this->zip->open( $archive, ZipArchive::CREATE ); if ( $zipRes ) { foreach ( $files as $file ) { - $this->addFileToZip( $file, basename( $file ) ); + $this->add_fileToZip( $file, basename( $file ) ); } return $this->zip->close(); @@ -154,11 +154,11 @@ class MainWP_Backup { return false; } - public function _zipFileConsole( $files, $archive ) { + public function m_zip_file_console( $files, $archive ) { return false; } - public function _zipFilePcl( $files, $archive ) { + public function m_zip_file_pcl( $files, $archive ) { // Zip this backup folder. require_once ABSPATH . 'wp-admin/includes/class-pclzip.php'; $this->zip = new PclZip( $archive ); @@ -179,7 +179,7 @@ class MainWP_Backup { * * @return bool */ - public function checkZipSupport() { + public function check_zip_support() { return class_exists( 'ZipArchive' ); } @@ -188,7 +188,7 @@ class MainWP_Backup { * * @return bool */ - public function checkZipConsole() { + public function check_zip_console() { return false; } @@ -199,7 +199,7 @@ class MainWP_Backup { * * @return bool */ - public function createZipFullBackup( $filepath, $excludes, $addConfig, $includeCoreFiles, $excludezip, $excludenonwp ) { + public function create_zip_full_backup( $filepath, $excludes, $addConfig, $includeCoreFiles, $excludezip, $excludenonwp ) { $this->excludeZip = $excludezip; $this->zip = new ZipArchive(); $this->zipArchiveFileCount = 0; @@ -248,13 +248,13 @@ class MainWP_Backup { unset( $coreFiles ); } - $db_files = $this->createBackupDB( dirname( $filepath ) . DIRECTORY_SEPARATOR . 'dbBackup' ); + $db_files = $this->create_backup_db( dirname( $filepath ) . DIRECTORY_SEPARATOR . 'dbBackup' ); foreach ( $db_files as $db_file ) { - $this->addFileToZip( $db_file, basename( WP_CONTENT_DIR ) . '/' . basename( $db_file ) ); + $this->add_file_to_zipp( $db_file, basename( WP_CONTENT_DIR ) . '/' . basename( $db_file ) ); } if ( file_exists( ABSPATH . '.htaccess' ) ) { - $this->addFileToZip( ABSPATH . '.htaccess', 'mainwp-htaccess' ); + $this->add_file_to_zipp( ABSPATH . '.htaccess', 'mainwp-htaccess' ); } foreach ( $nodes as $node ) { @@ -266,9 +266,9 @@ class MainWP_Backup { if ( ! MainWP_Helper::in_excludes( $excludes, str_replace( ABSPATH, '', $node ) ) ) { if ( is_dir( $node ) ) { - $this->zipAddDir( $node, $excludes ); + $this->zip_add_dir( $node, $excludes ); } elseif ( is_file( $node ) ) { - $this->addFileToZip( $node, str_replace( ABSPATH, '', $node ) ); + $this->add_file_to_zipp( $node, str_replace( ABSPATH, '', $node ) ); } } } @@ -321,7 +321,7 @@ class MainWP_Backup { ) ); - $this->addFileFromStringToZip( 'clone/config.txt', $string ); + $this->add_file_from_string_to_zip( 'clone/config.txt', $string ); } $return = $this->zip->close(); @@ -335,114 +335,6 @@ class MainWP_Backup { return false; } - /** - * Create full backup using pclZip library - * - * @param string $filepath File path to create - * - * @return bool - */ - public function createZipPclFullBackup( $filepath, $excludes, $addConfig, $includeCoreFiles ) { - require_once ABSPATH . 'wp-admin/includes/class-pclzip.php'; - $this->zip = new PclZip( $filepath ); - $nodes = glob( ABSPATH . '*' ); - if ( ! $includeCoreFiles ) { - $coreFiles = array( - 'favicon.ico', - 'index.php', - 'license.txt', - 'readme.html', - 'wp-activate.php', - 'wp-app.php', - 'wp-blog-header.php', - 'wp-comments-post.php', - 'wp-config.php', - 'wp-config-sample.php', - 'wp-cron.php', - 'wp-links-opml.php', - 'wp-load.php', - 'wp-login.php', - 'wp-mail.php', - 'wp-pass.php', - 'wp-register.php', - 'wp-settings.php', - 'wp-signup.php', - 'wp-trackback.php', - 'xmlrpc.php', - ); - foreach ( $nodes as $key => $node ) { - if ( MainWP_Helper::starts_with( $node, ABSPATH . WPINC ) ) { - unset( $nodes[ $key ] ); - } elseif ( MainWP_Helper::starts_with( $node, ABSPATH . basename( admin_url( '' ) ) ) ) { - unset( $nodes[ $key ] ); - } else { - foreach ( $coreFiles as $coreFile ) { - if ( ABSPATH . $coreFile === $node ) { - unset( $nodes[ $key ] ); - } - } - } - } - unset( $coreFiles ); - } - - $db_files = $this->createBackupDB( dirname( $filepath ) . DIRECTORY_SEPARATOR . 'dbBackup' ); - $error = false; - foreach ( $db_files as $db_file ) { - $rslt = $this->zip->add( $db_file, PCLZIP_OPT_REMOVE_PATH, dirname( $db_file ), PCLZIP_OPT_ADD_PATH, basename( WP_CONTENT_DIR ) ); - if ( 0 === $rslt ) { - $error = true; - } - } - - foreach ( $db_files as $db_file ) { - unlink( $db_file ); - } - if ( ! $error ) { - foreach ( $nodes as $node ) { - if ( null === $excludes || ! in_array( str_replace( ABSPATH, '', $node ), $excludes, true ) ) { - if ( is_dir( $node ) ) { - if ( ! $this->pclZipAddDir( $node, $excludes ) ) { - $error = true; - break; - } - } elseif ( is_file( $node ) ) { - $rslt = $this->zip->add( $node, PCLZIP_OPT_REMOVE_PATH, ABSPATH ); - if ( 0 === $rslt ) { - $error = true; - break; - } - } - } - } - } - - if ( $addConfig ) { - global $wpdb; - $string = base64_encode( // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for benign reasons. - serialize( - array( - 'siteurl' => get_option( 'siteurl' ), - 'home' => get_option( 'home' ), - 'abspath' => ABSPATH, - 'prefix' => $wpdb->prefix, - 'lang' => WPLANG, - ) - ) - ); - - $this->addFileFromStringToPCLZip( 'clone/config.txt', $string, $filepath ); - } - - if ( $error ) { - unlink( $filepath ); // phpcs:ignore - - return false; - } - - return true; - } - public function copy_dir( $nodes, $excludes, $backupfolder, $excludenonwp, $root ) { if ( ! is_array( $nodes ) ) { return; @@ -475,14 +367,14 @@ class MainWP_Backup { } } - public function createZipPclFullBackup2( $filepath, $excludes, $addConfig, $includeCoreFiles, $excludezip, $excludenonwp ) { + public function create_zip_pcl_full_backup2( $filepath, $excludes, $addConfig, $includeCoreFiles, $excludezip, $excludenonwp ) { // Create backup folder. $backupFolder = dirname( $filepath ) . DIRECTORY_SEPARATOR . 'backup' . DIRECTORY_SEPARATOR; mkdir( $backupFolder ); // phpcs:ignore // Create DB backup. - $db_files = $this->createBackupDB( $backupFolder . 'dbBackup' ); + $db_files = $this->create_backup_db( $backupFolder . 'dbBackup' ); // Copy installation to backup folder. $nodes = glob( ABSPATH . '*' ); @@ -552,7 +444,7 @@ class MainWP_Backup { ) ); - $this->addFileFromStringToPCLZip( 'clone/config.txt', $string, $filepath ); + $this->add_file_from_string_to_pcl_zip( 'clone/config.txt', $string, $filepath ); } // Remove backup folder. MainWP_Helper::delete_dir( $backupFolder ); @@ -563,11 +455,11 @@ class MainWP_Backup { /** * Recursive add directory for default PHP zip library */ - public function zipAddDir( $path, $excludes ) { - $this->zip->addEmptyDir( str_replace( ABSPATH, '', $path ) ); + public function zip_add_dir( $path, $excludes ) { + $this->zip->add_empty_dir( str_replace( ABSPATH, '', $path ) ); if ( file_exists( rtrim( $path, '/' ) . '/.htaccess' ) ) { - $this->addFileToZip( rtrim( $path, '/' ) . '/.htaccess', rtrim( str_replace( ABSPATH, '', $path ), '/' ) . '/mainwp-htaccess' ); + $this->add_file_to_zipp( rtrim( $path, '/' ) . '/.htaccess', rtrim( str_replace( ABSPATH, '', $path ), '/' ) . '/mainwp-htaccess' ); } $iterator = new RecursiveIteratorIterator( new RecursiveDirectoryIterator( $path ), RecursiveIteratorIterator::SELF_FIRST ); @@ -580,9 +472,9 @@ class MainWP_Backup { if ( ! MainWP_Helper::in_excludes( $excludes, str_replace( ABSPATH, '', $name ) ) ) { if ( $path->isDir() ) { - $this->zipAddDir( $name, $excludes ); + $this->zip_add_dir( $name, $excludes ); } else { - $this->addFileToZip( $name, str_replace( ABSPATH, '', $name ) ); + $this->add_file_to_zipp( $name, str_replace( ABSPATH, '', $name ) ); } } $name = null; @@ -593,7 +485,7 @@ class MainWP_Backup { unset( $iterator ); } - public function pclZipAddDir( $path, $excludes ) { + public function pcl_zip_add_dir( $path, $excludes ) { $error = false; $nodes = glob( rtrim( $path, '/' ) . '/*' ); if ( empty( $nodes ) ) { @@ -603,7 +495,7 @@ class MainWP_Backup { foreach ( $nodes as $node ) { if ( null === $excludes || ! in_array( str_replace( ABSPATH, '', $node ), $excludes, true ) ) { if ( is_dir( $node ) ) { - if ( ! $this->pclZipAddDir( $node, $excludes ) ) { + if ( ! $this->pcl_zip_add_dir( $node, $excludes ) ) { $error = true; break; } @@ -620,11 +512,11 @@ class MainWP_Backup { return ! $error; } - public function addFileFromStringToZip( $file, $string ) { + public function add_file_from_string_to_zip( $file, $string ) { return $this->zip->addFromString( $file, $string ); } - public function addFileFromStringToPCLZip( $file, $string, $filepath ) { + public function add_file_from_string_to_pcl_zip( $file, $string, $filepath ) { $file = preg_replace( '/(?:\.|\/)*(.*)/', '$1', $file ); $localpath = dirname( $file ); $tmpfilename = dirname( $filepath ) . '/' . basename( $file ); @@ -649,7 +541,7 @@ class MainWP_Backup { protected $gcCnt = 0; protected $testContent; - public function addFileToZip( $path, $zipEntryName ) { + public function add_file_to_zipp( $path, $zipEntryName ) { if ( time() - $this->lastRun > 20 ) { set_time_limit( $this->timeout ); // phpcs:ignore $this->lastRun = time(); @@ -664,7 +556,7 @@ class MainWP_Backup { if ( ! $this->loadFilesBeforeZip || ( filesize( $path ) > 5 * 1024 * 1024 ) ) { $this->zipArchiveFileCount ++; - $added = $this->zip->addFile( $path, $zipEntryName ); + $added = $this->zip->add_file( $path, $zipEntryName ); } else { $this->zipArchiveFileCount ++; @@ -704,11 +596,11 @@ class MainWP_Backup { return $added; } - public function createZipConsoleFullBackup( $filepath, $excludes, $addConfig, $includeCoreFiles, $excludezip, $excludenonwp ) { + public function create_zip_console_full_backup( $filepath, $excludes, $addConfig, $includeCoreFiles, $excludezip, $excludenonwp ) { return false; } - public function createBackupDB( $filepath_prefix, $archiveExt = false, &$archiver = null ) { + public function create_backup_db( $filepath_prefix, $archiveExt = false, &$archiver = null ) { $timeout = 20 * 60 * 60; set_time_limit( $timeout ); ini_set( 'max_execution_time', $timeout ); @@ -722,7 +614,7 @@ class MainWP_Backup { $tables_db = $wpdb->get_results( 'SHOW TABLES FROM `' . DB_NAME . '`', ARRAY_N ); foreach ( $tables_db as $curr_table ) { if ( null !== $archiver ) { - $archiver->updatePidFile(); + $archiver->update_pid_file(); } $table = $curr_table[0]; @@ -788,7 +680,7 @@ class MainWP_Backup { $this->archiver = new Tar_Archiver( $this, $archiveExt ); } - if ( $this->zipFile( $db_files, $archivefilePath ) && file_exists( $archivefilePath ) ) { + if ( $this->zip_file( $db_files, $archivefilePath ) && file_exists( $archivefilePath ) ) { foreach ( $db_files as $db_file ) { unlink( $db_file ); } diff --git a/class/class-mainwp-child-back-up-buddy.php b/class/class-mainwp-child-back-up-buddy.php index 6a05c31..2afe0dc 100644 --- a/class/class-mainwp-child-back-up-buddy.php +++ b/class/class-mainwp-child-back-up-buddy.php @@ -19,7 +19,7 @@ class MainWP_Child_Back_Up_Buddy { public $plugin_translate = 'mainwp-child'; public $is_backupbuddy_installed = false; - public static function Instance() { + public static function instance() { if ( null === self::$instance ) { self::$instance = new MainWP_Child_Back_Up_Buddy(); } diff --git a/class/class-mainwp-child-back-up-wordpress.php b/class/class-mainwp-child-back-up-wordpress.php index ccdfe90..eb4c7c7 100644 --- a/class/class-mainwp-child-back-up-wordpress.php +++ b/class/class-mainwp-child-back-up-wordpress.php @@ -19,7 +19,7 @@ class MainWP_Child_Back_Up_Wordpress { public static $instance = null; public $is_plugin_installed = false; - public static function Instance() { + public static function instance() { if ( null === self::$instance ) { self::$instance = new MainWP_Child_Back_Up_Wordpress(); } @@ -78,7 +78,7 @@ class MainWP_Child_Back_Up_Wordpress { public function action() { $information = array(); - if ( ! self::isActivated() ) { + if ( ! self::is_activated() ) { $information['error'] = 'NO_BACKUPWORDPRESS'; MainWP_Helper::write( $information ); } @@ -1043,7 +1043,7 @@ class MainWP_Child_Back_Up_Wordpress { return $out; } - public static function isActivated() { + public static function is_activated() { if ( ! defined( 'HMBKP_PLUGIN_PATH' ) || ! class_exists( 'HM\BackUpWordPress\Plugin' ) ) { return false; } diff --git a/class/class-mainwp-child-back-wp-up.php b/class/class-mainwp-child-back-wp-up.php index 17bed7b..014d13b 100644 --- a/class/class-mainwp-child-back-wp-up.php +++ b/class/class-mainwp-child-back-wp-up.php @@ -56,7 +56,7 @@ class MainWP_Child_Back_WP_Up { 'dest-GLACIER' => array( 'glaciersecretkey' ), ); - public static function Instance() { + public static function instance() { if ( null == self::$instance ) { self::$instance = new MainWP_Child_Back_WP_Up(); } diff --git a/class/class-mainwp-child-branding.php b/class/class-mainwp-child-branding.php index 2a7d762..8329cae 100644 --- a/class/class-mainwp-child-branding.php +++ b/class/class-mainwp-child-branding.php @@ -8,7 +8,7 @@ class MainWP_Child_Branding { public $child_plugin_dir; public $child_branding_options = null; - public static function Instance() { + public static function instance() { if ( null === self::$instance ) { self::$instance = new MainWP_Child_Branding(); } diff --git a/class/class-mainwp-child-ithemes-security.php b/class/class-mainwp-child-ithemes-security.php index aefc27b..8929c88 100644 --- a/class/class-mainwp-child-ithemes-security.php +++ b/class/class-mainwp-child-ithemes-security.php @@ -19,7 +19,7 @@ class MainWP_Child_IThemes_Security { public static $instance = null; public $is_plugin_installed = false; - public static function Instance() { + public static function instance() { if ( null === self::$instance ) { self::$instance = new self(); } diff --git a/class/class-mainwp-child-links-checker.php b/class/class-mainwp-child-links-checker.php index 750259d..3f8b5cd 100644 --- a/class/class-mainwp-child-links-checker.php +++ b/class/class-mainwp-child-links-checker.php @@ -16,7 +16,7 @@ class MainWP_Child_Links_Checker { public static $instance = null; public $is_plugin_installed = false; - public static function Instance() { + public static function instance() { if ( null === self::$instance ) { self::$instance = new MainWP_Child_Links_Checker(); } diff --git a/class/class-mainwp-child-pagespeed.php b/class/class-mainwp-child-pagespeed.php index 03f6144..842dbb9 100644 --- a/class/class-mainwp-child-pagespeed.php +++ b/class/class-mainwp-child-pagespeed.php @@ -19,7 +19,7 @@ class MainWP_Child_Pagespeed { public static $instance = null; public $is_plugin_installed = false; - public static function Instance() { + public static function instance() { if ( null === self::$instance ) { self::$instance = new MainWP_Child_Pagespeed(); } diff --git a/class/class-mainwp-child-plugins-check.php b/class/class-mainwp-child-plugins-check.php index 90b3035..f55bde7 100644 --- a/class/class-mainwp-child-plugins-check.php +++ b/class/class-mainwp-child-plugins-check.php @@ -21,7 +21,7 @@ class MainWP_Child_Plugins_Check { private $tran_name_plugins_to_batch = 'mainwp_child_tran_name_plugins_to_batch'; private $option_name_last_daily_run = 'mainwp_child_plugin_last_daily_run'; - public static function Instance() { + public static function instance() { if ( null === self::$instance ) { self::$instance = new MainWP_Child_Plugins_Check(); } diff --git a/class/class-mainwp-child-server-information.php b/class/class-mainwp-child-server-information.php index a7e4d4c..db8896a 100644 --- a/class/class-mainwp-child-server-information.php +++ b/class/class-mainwp-child-server-information.php @@ -5,11 +5,22 @@ class MainWP_Child_Server_Information { const WARNING = 1; const ERROR = 2; + /** + * Method get_class_name() + * + * Get Class Name. + * + * @return object + */ + public static function get_class_name() { + return __CLASS__; + } + public static function init() { add_action( 'wp_ajax_mainwp-child_dismiss_warnings', array( - 'MainWP_Child_Server_Information', + MainWP_Child_Server_Information::get_class_name(), 'dismiss_warnings', ) ); @@ -25,7 +36,7 @@ class MainWP_Child_Server_Information { if ( isset( $_POST['warnings'] ) ) { $warnings = intval( $_POST['warnings'] ); } else { - $warnings = self::getWarnings(); + $warnings = self::get_warnings(); } $dismissWarnings['warnings'] = $warnings; } @@ -33,12 +44,12 @@ class MainWP_Child_Server_Information { } } - public static function showWarnings() { + public static function show_warnings() { if ( stristr( $_SERVER['REQUEST_URI'], 'mainwp_child_tab' ) || stristr( $_SERVER['REQUEST_URI'], 'mainwp-reports-page' ) || stristr( $_SERVER['REQUEST_URI'], 'mainwp-reports-settings' ) ) { return; } - $warnings = self::getWarnings(); + $warnings = self::get_warnings(); $dismissWarnings = get_option( 'mainwp_child_dismiss_warnings' ); if ( ! is_array( $dismissWarnings ) ) { @@ -135,7 +146,7 @@ class MainWP_Child_Server_Information { isActivated() ) { + if ( MainWP_Child_WP_Rocket::instance()->is_activated() ) { if ( function_exists( 'get_rocket_option' ) ) { $wprocket_activated = true; foreach ( $wprocket_fields as $field ) { diff --git a/class/class-mainwp-keyword-links.php b/class/class-mainwp-keyword-links.php index 93bd0b8..a6d9e30 100644 --- a/class/class-mainwp-keyword-links.php +++ b/class/class-mainwp-keyword-links.php @@ -14,7 +14,7 @@ class MainWP_Keyword_Links { protected $link_exact_match = 1; protected $link_case_sensitive = 1; - static function Instance() { + static function instance() { if ( null === self::$instance ) { self::$instance = new MainWP_Keyword_Links(); } @@ -35,7 +35,7 @@ class MainWP_Keyword_Links { } // print_r($this->keyword_links); $this->siteurl = get_option( 'home' ); - add_action( 'permalink_structure_changed', array( &$this, 'permalinkChanged' ), 10, 2 ); + add_action( 'permalink_structure_changed', array( &$this, 'permalink_changed' ), 10, 2 ); } @@ -59,7 +59,7 @@ class MainWP_Keyword_Links { } - public function permalinkChanged( $old_struct, $new_struct ) { + public function permalink_changed( $old_struct, $new_struct ) { if ( '1' !== get_option( 'mainwpKeywordLinks' ) ) { if ( 'yes' === get_option( 'mainwp_keyword_links_htaccess_set' ) ) { $this->update_htaccess( false, true ); // force clear diff --git a/class/class-mainwp-security.php b/class/class-mainwp-security.php index 2764330..83cf263 100644 --- a/class/class-mainwp-security.php +++ b/class/class-mainwp-security.php @@ -15,7 +15,7 @@ class MainWP_Security { return __CLASS__; } - public static function fixAll() { + public static function fix_all() { self::remove_wp_version(); self::remove_rsd(); self::remove_wlw(); @@ -33,7 +33,7 @@ class MainWP_Security { // Prevent listing wp-content, wp-content/plugins, wp-content/themes, wp-content/uploads. private static $listingDirectories = null; - private static function init_listingDirectories() { + private static function init_listing_directories() { if ( null === self::$listingDirectories ) { $wp_upload_dir = wp_upload_dir(); self::$listingDirectories = array( @@ -46,7 +46,7 @@ class MainWP_Security { } public static function prevent_listing_ok() { - self::init_listingDirectories(); + self::init_listing_directories(); foreach ( self::$listingDirectories as $directory ) { $file = $directory . DIRECTORY_SEPARATOR . 'index.php'; if ( ! file_exists( $file ) ) { @@ -58,7 +58,7 @@ class MainWP_Security { } public static function prevent_listing() { - self::init_listingDirectories(); + self::init_listing_directories(); foreach ( self::$listingDirectories as $directory ) { $file = $directory . DIRECTORY_SEPARATOR . 'index.php'; if ( ! file_exists( $file ) ) { diff --git a/class/class-mainwp-wordpress-seo.php b/class/class-mainwp-wordpress-seo.php index c127744..f0dc387 100644 --- a/class/class-mainwp-wordpress-seo.php +++ b/class/class-mainwp-wordpress-seo.php @@ -17,7 +17,7 @@ namespace MainWP\Child; class MainWP_Wordpress_SEO { public static $instance = null; - public static function Instance() { + public static function instance() { if ( null === self::$instance ) { self::$instance = new MainWP_Wordpress_SEO(); } diff --git a/class/class-tar-archiver.php b/class/class-tar-archiver.php index 891e9c6..31ed7d3 100644 --- a/class/class-tar-archiver.php +++ b/class/class-tar-archiver.php @@ -49,7 +49,7 @@ class Tar_Archiver { } } - public function getExtension() { + public function get_extension() { if ( 'tar.bz2' == $this->type ) { return '.tar.bz2'; } @@ -60,14 +60,14 @@ class Tar_Archiver { return '.tar'; } - public function zipFile( $files, $archive ) { + public function zip_file( $files, $archive ) { $this->create( $archive ); if ( $this->archive ) { foreach ( $files as $filepath ) { - $this->addFile( $filepath, basename( $filepath ) ); + $this->add_file( $filepath, basename( $filepath ) ); } - $this->addData( pack( 'a1024', '' ) ); + $this->add_data( pack( 'a1024', '' ) ); $this->close(); return true; @@ -76,7 +76,7 @@ class Tar_Archiver { return false; } - private function createPidFile( $file ) { + private function create_pid_file( $file ) { if ( false === $this->pidFile ) { return false; } @@ -92,7 +92,7 @@ class Tar_Archiver { return true; } - public function updatePidFile() { + public function update_pid_file() { if ( false === $this->pidFile ) { return false; } @@ -109,7 +109,7 @@ class Tar_Archiver { return true; } - private function completePidFile() { + private function complete_pid_file() { if ( false === $this->pidFile ) { return false; } @@ -124,8 +124,8 @@ class Tar_Archiver { return true; } - public function createFullBackup( $filepath, $excludes, $addConfig, $includeCoreFiles, $excludezip, $excludenonwp, $append = false ) { - $this->createPidFile( $filepath ); + public function create_full_backup( $filepath, $excludes, $addConfig, $includeCoreFiles, $excludezip, $excludenonwp, $append = false ) { + $this->create_pid_file( $filepath ); $this->excludeZip = $excludezip; @@ -133,7 +133,7 @@ class Tar_Archiver { if ( $append && file_exists( $filepath ) ) { $this->mode = self::APPEND; - $this->prepareAppend( $filepath ); + $this->prepare_append( $filepath ); } else { $this->mode = self::CREATE; $this->create( $filepath ); @@ -181,14 +181,14 @@ class Tar_Archiver { unset( $coreFiles ); } - $db_files = $this->backup->createBackupDB( dirname( $filepath ) . DIRECTORY_SEPARATOR . 'dbBackup', false, $this ); + $db_files = $this->backup->create_backup_db( dirname( $filepath ) . DIRECTORY_SEPARATOR . 'dbBackup', false, $this ); foreach ( $db_files as $db_file ) { - $this->addFile( $db_file, basename( WP_CONTENT_DIR ) . '/' . basename( $db_file ) ); + $this->add_file( $db_file, basename( WP_CONTENT_DIR ) . '/' . basename( $db_file ) ); } if ( file_exists( ABSPATH . '.htaccess' ) ) { - $this->addFile( ABSPATH . '.htaccess', 'mainwp-htaccess' ); + $this->add_file( ABSPATH . '.htaccess', 'mainwp-htaccess' ); } foreach ( $nodes as $node ) { @@ -200,9 +200,9 @@ class Tar_Archiver { if ( ! MainWP_Helper::in_excludes( $excludes, str_replace( ABSPATH, '', $node ) ) ) { if ( is_dir( $node ) ) { - $this->addDir( $node, $excludes ); + $this->add_dir( $node, $excludes ); } elseif ( is_file( $node ) ) { - $this->addFile( $node, str_replace( ABSPATH, '', $node ) ); + $this->add_file( $node, str_replace( ABSPATH, '', $node ) ); } } } @@ -251,17 +251,17 @@ class Tar_Archiver { ) ); - $this->addEmptyDirectory( 'clone', 0, 0, 0, time() ); - $this->addFileFromString( 'clone/config.txt', $string ); + $this->add_empty_directory( 'clone', 0, 0, 0, time() ); + $this->add_file_from_string( 'clone/config.txt', $string ); } - $this->addData( pack( 'a1024', '' ) ); + $this->add_data( pack( 'a1024', '' ) ); $this->close(); foreach ( $db_files as $db_file ) { unlink( $db_file ); } - $this->completePidFile(); + $this->complete_pid_file(); return true; } @@ -269,15 +269,15 @@ class Tar_Archiver { return false; } - public function addDir( $path, $excludes ) { + public function add_dir( $path, $excludes ) { if ( ( '.' == basename( $path ) ) || ( '..' == basename( $path ) ) ) { return; } - $this->addEmptyDir( $path, str_replace( ABSPATH, '', $path ) ); + $this->add_empty_dir( $path, str_replace( ABSPATH, '', $path ) ); if ( file_exists( rtrim( $path, '/' ) . '/.htaccess' ) ) { - $this->addFile( rtrim( $path, '/' ) . '/.htaccess', rtrim( str_replace( ABSPATH, '', $path ), '/' ) . '/mainwp-htaccess' ); + $this->add_file( rtrim( $path, '/' ) . '/.htaccess', rtrim( str_replace( ABSPATH, '', $path ), '/' ) . '/mainwp-htaccess' ); } $iterator = new RecursiveIteratorIterator( new RecursiveDirectoryIterator( $path ), RecursiveIteratorIterator::SELF_FIRST, RecursiveIteratorIterator::CATCH_GET_CHILD ); @@ -295,9 +295,9 @@ class Tar_Archiver { if ( ! MainWP_Helper::in_excludes( $excludes, str_replace( ABSPATH, '', $name ) ) ) { if ( $path->isDir() ) { - $this->addEmptyDir( $name, str_replace( ABSPATH, '', $name ) ); + $this->add_empty_dir( $name, str_replace( ABSPATH, '', $name ) ); } else { - $this->addFile( $name, str_replace( ABSPATH, '', $name ) ); + $this->add_file( $name, str_replace( ABSPATH, '', $name ) ); } } $name = null; @@ -308,12 +308,12 @@ class Tar_Archiver { unset( $iterator ); } - private function addData( $data ) { + private function add_data( $data ) { if ( $this->debug ) { $this->chunk .= $data; if ( strlen( $this->chunk ) > $this->chunkSize ) { - $this->writeChunk(); + $this->write_chunk(); } return; @@ -335,7 +335,7 @@ class Tar_Archiver { } } - private function writeChunk() { + private function write_chunk() { $len = strlen( $this->chunk ); if ( 0 == $len ) { return; @@ -362,15 +362,15 @@ class Tar_Archiver { $this->chunk = ''; } - private function addEmptyDir( $path, $entryName ) { + private function add_empty_dir( $path, $entryName ) { $stat = stat( $path ); - $this->addEmptyDirectory( $entryName, $stat['mode'], $stat['uid'], $stat['gid'], $stat['mtime'] ); + $this->add_empty_directory( $entryName, $stat['mode'], $stat['uid'], $stat['gid'], $stat['mtime'] ); } - private function addEmptyDirectory( $entryName, $mode, $uid, $gid, $mtime ) { + private function add_empty_directory( $entryName, $mode, $uid, $gid, $mtime ) { if ( self::APPEND == $this->mode ) { - if ( true === $this->checkBeforeAppend( $entryName ) ) { + if ( true === $this->check_before_append( $entryName ) ) { return true; } } @@ -411,8 +411,8 @@ class Tar_Archiver { $checksum = pack( 'a8', sprintf( '%07o', $checksum ) ); $block = substr_replace( $block, $checksum, 148, 8 ); - $this->addData( $block ); - $this->addData( pack( 'a512', $entryName ) ); + $this->add_data( $block ); + $this->add_data( pack( 'a512', $entryName ) ); $entryName = substr( $entryName, 0, 100 ); } } @@ -445,7 +445,7 @@ class Tar_Archiver { $checksum = pack( 'a8', sprintf( '%07o', $checksum ) ); $block = substr_replace( $block, $checksum, 148, 8 ); - $this->addData( $block ); + $this->add_data( $block ); return true; } @@ -455,7 +455,7 @@ class Tar_Archiver { protected $gcCnt = 0; protected $cnt = 0; - private function addFile( $path, $entryName ) { + private function add_file( $path, $entryName ) { if ( ( '.' == basename( $path ) ) || ( '..' == basename( $path ) ) ) { return false; } @@ -468,11 +468,11 @@ class Tar_Archiver { $this->log( 'Adding ' . $path ); - $this->updatePidFile(); + $this->update_pid_file(); $rslt = false; if ( self::APPEND == $this->mode ) { - $rslt = $this->checkBeforeAppend( $entryName ); + $rslt = $this->check_before_append( $entryName ); if ( true === $rslt ) { return true; } @@ -537,10 +537,10 @@ class Tar_Archiver { $block = substr_replace( $block, $checksum, 148, 8 ); if ( ! isset( $rslt['bytesRead'] ) ) { - $this->addData( $block ); + $this->add_data( $block ); } if ( ! isset( $rslt['bytesRead'] ) ) { - $this->addData( pack( 'a512', $entryName ) ); + $this->add_data( pack( 'a512', $entryName ) ); } $entryName = substr( $entryName, 0, 100 ); } @@ -575,7 +575,7 @@ class Tar_Archiver { $this->block = substr_replace( $this->block, $checksum, 148, 8 ); if ( ! isset( $rslt['bytesRead'] ) ) { - $this->addData( $this->block ); + $this->add_data( $this->block ); } if ( isset( $rslt['bytesRead'] ) ) { @@ -586,12 +586,12 @@ class Tar_Archiver { if ( $toRead > 0 ) { $this->tempContent = fread( $fp, $toRead ); - $this->addData( $this->tempContent ); + $this->add_data( $this->tempContent ); $remainder = 512 - ( strlen( $this->tempContent ) + $alreadyRead ); $this->log( 'DEBUG-Added ' . strlen( $this->tempContent ) . '(before: ' . $alreadyRead . ') will pack: ' . $remainder . ' (packed: ' . strlen( pack( 'a' . $remainder, '' ) ) ); if ( $remainder > 0 ) { - $this->addData( pack( 'a' . $remainder ), '' ); + $this->add_data( pack( 'a' . $remainder ), '' ); } } } @@ -602,13 +602,13 @@ class Tar_Archiver { $read = strlen( $this->tempContent ); $divide = $read % 512; - $this->addData( substr( $this->tempContent, 0, $read - $divide ) ); + $this->add_data( substr( $this->tempContent, 0, $read - $divide ) ); if ( $divide > 0 ) { - $this->addData( pack( 'a512', substr( $this->tempContent, - 1 * $divide ) ) ); + $this->add_data( pack( 'a512', substr( $this->tempContent, - 1 * $divide ) ) ); } - $this->updatePidFile(); + $this->update_pid_file(); } fclose( $fp ); @@ -616,11 +616,11 @@ class Tar_Archiver { return true; } - private function addFileFromString( $entryName, $content ) { + private function add_file_from_string( $entryName, $content ) { $this->log( 'Add from string ' . $entryName ); if ( self::APPEND == $this->mode ) { - if ( true === $this->checkBeforeAppend( $entryName ) ) { + if ( true === $this->check_before_append( $entryName ) ) { return true; } } @@ -661,8 +661,8 @@ class Tar_Archiver { $checksum = pack( 'a8', sprintf( '%07o', $checksum ) ); $block = substr_replace( $block, $checksum, 148, 8 ); - $this->addData( $block ); - $this->addData( pack( 'a512', $entryName ) ); + $this->add_data( $block ); + $this->add_data( pack( 'a512', $entryName ) ); $entryName = substr( $entryName, 0, 100 ); } } @@ -695,17 +695,17 @@ class Tar_Archiver { $checksum = pack( 'a8', sprintf( '%07o', $checksum ) ); $block = substr_replace( $block, $checksum, 148, 8 ); - $this->addData( $block ); + $this->add_data( $block ); $i = 0; while ( ( $line = substr( $content, $i ++ * 512, 512 ) ) != '' ) { - $this->addData( pack( 'a512', $line ) ); + $this->add_data( pack( 'a512', $line ) ); } return true; } - private function checkBeforeAppend( $entryName ) { - $rslt = $this->isNextFile( $entryName ); + private function check_before_append( $entryName ) { + $rslt = $this->is_next_file( $entryName ); if ( true === $rslt ) { return true; @@ -753,7 +753,7 @@ class Tar_Archiver { * @return array|bool * @throws Exception */ - private function isNextFile( $entryName ) { + private function is_next_file( $entryName ) { $currentOffset = ftell( $this->archive ); $rslt = array( 'startOffset' => $currentOffset ); try { @@ -910,11 +910,11 @@ class Tar_Archiver { } } - public function isOpen() { + public function is_open() { return ! empty( $this->archive ); } - public function prepareAppend( $filepath ) { + public function prepare_append( $filepath ) { if ( $this->debug ) { if ( 'tar.gz' == substr( $filepath, - 6 ) ) { $text = chr( 31 ) . chr( 139 ) . chr( 8 ) . chr( 0 ) . chr( 0 ) . chr( 0 ) . chr( 0 ) . chr( 0 ) . chr( 0 ); @@ -929,7 +929,7 @@ class Tar_Archiver { echo ord( $read[ $i ] ) . "\n"; } - if ( ! $this->isValidBlock( substr( $read, 10, $pos - 10 ) ) ) { + if ( ! $this->is_valid_block( substr( $read, 10, $pos - 10 ) ) ) { throw new Exception( 'invalid!' ); } @@ -938,7 +938,7 @@ class Tar_Archiver { } } - if ( ! $this->isValidBlock( substr( $read, 10 ) ) ) { + if ( ! $this->is_valid_block( substr( $read, 10 ) ) ) { throw new Exception( 'invalid!' ); } @@ -980,7 +980,7 @@ class Tar_Archiver { } public function close( $closeLog = true ) { - $this->writeChunk(); + $this->write_chunk(); $this->log( 'Closing archive' ); if ( $closeLog && $this->logHandle ) { @@ -998,7 +998,7 @@ class Tar_Archiver { } } - public function getFromName( $entryName ) { + public function get_from_name( $entryName ) { if ( ! $this->archive ) { return false; } @@ -1125,7 +1125,7 @@ class Tar_Archiver { return false; } - public function extractTo( $to ) { + public function extract_to( $to ) { /** @var $wp_filesystem WP_Filesystem_Base */ global $wp_filesystem; @@ -1230,7 +1230,7 @@ class Tar_Archiver { return null; } - public function isValidBlock( $block ) { + public function is_valid_block( $block ) { $test = gzinflate( $block ); if ( false === $test ) { return false;