mirror of
https://github.com/mainwp/mainwp-child.git
synced 2025-08-31 03:53:15 +08:00
Refactoring
This commit is contained in:
parent
fa9f53cea4
commit
e5fd37da9b
24 changed files with 1546 additions and 1551 deletions
|
@ -247,7 +247,7 @@ class MainWP_Backup {
|
|||
}
|
||||
|
||||
private function include_core_files( &$nodes ) {
|
||||
return array(
|
||||
$coreFiles = array(
|
||||
'favicon.ico',
|
||||
'index.php',
|
||||
'license.txt',
|
||||
|
|
|
@ -13,6 +13,8 @@
|
|||
*/
|
||||
|
||||
use MainWP\Child\MainWP_Helper;
|
||||
use MainWP\Child\MainWP_Utility;
|
||||
|
||||
// phpcs:disable -- third party credit.
|
||||
|
||||
class MainWP_Child_Back_Up_Buddy {
|
||||
|
@ -792,7 +794,7 @@ class MainWP_Child_Back_Up_Buddy {
|
|||
$time = $this->localize_time( $finish_time );
|
||||
$data['lastBackupStats'] = date( 'M j - g:i A', $time ); // phpcs:ignore -- local time.
|
||||
$data['lasttime_backup'] = $finish_time;
|
||||
MainWP_Helper::instance()->update_lasttime_backup( 'backupbuddy', $finish_time ); // support Require Backup Before Update feature.
|
||||
MainWP_Utility::update_lasttime_backup( 'backupbuddy', $finish_time ); // support Require Backup Before Update feature.
|
||||
} else {
|
||||
$data['lastBackupStats'] = 'Unknown';
|
||||
}
|
||||
|
@ -1265,7 +1267,7 @@ class MainWP_Child_Back_Up_Buddy {
|
|||
|
||||
// Calculate main row string.
|
||||
if ( 'default' == $type ) { // Default backup listing.
|
||||
$download_url = '/wp-admin/admin-ajax.php?action=mainwp_backupbuddy_download_archive&backupbuddy_backup=' . basename( $file ) . '&_wpnonce=' . MainWP_Helper::instance()->create_nonce_without_session( 'mainwp_download_backup' );
|
||||
$download_url = '/wp-admin/admin-ajax.php?action=mainwp_backupbuddy_download_archive&backupbuddy_backup=' . basename( $file ) . '&_wpnonce=' . MainWP_Utility::create_nonce_without_session( 'mainwp_download_backup' );
|
||||
$main_string = '<a href="#" download-url="' . $download_url . '"class="backupbuddyFileTitle mwp_bb_download_backup_lnk" title="' . basename( $file ) . '">' . $modified . ' (' . $time_ago . ')</a>';
|
||||
} elseif ( 'migrate' == $type ) { // Migration backup listing.
|
||||
$main_string = '<a class="pb_backupbuddy_hoveraction_migrate backupbuddyFileTitle" rel="' . basename( $file ) . '" href="' . pb_backupbuddy::page_url() . '&migrate=' . basename( $file ) . '&value=' . basename( $file ) . '" title="' . basename( $file ) . '">' . $modified . ' (' . $time_ago . ')</a>';
|
||||
|
@ -1761,7 +1763,7 @@ class MainWP_Child_Back_Up_Buddy {
|
|||
die( '-1' );
|
||||
}
|
||||
|
||||
if ( ! MainWP_Helper::instance()->verify_nonce_without_session( $_GET['_wpnonce'], 'mainwp_download_backup' ) ) {
|
||||
if ( ! MainWP_Utility::verify_nonce_without_session( $_GET['_wpnonce'], 'mainwp_download_backup' ) ) {
|
||||
die( '-2' );
|
||||
}
|
||||
|
||||
|
|
|
@ -14,8 +14,9 @@
|
|||
*/
|
||||
|
||||
use MainWP\Child\MainWP_Helper;
|
||||
use MainWP\Child\MainWP_Utility;
|
||||
|
||||
// phpcs:disable PSR1.Classes.ClassDeclaration, WordPress.WP.AlternativeFunctions -- root namespace to use external code.
|
||||
// phpcs:disable PSR1.Classes.ClassDeclaration, WordPress.WP.AlternativeFunctions -- to use external code.
|
||||
|
||||
class MainWP_Child_Back_Up_WordPress {
|
||||
public static $instance = null;
|
||||
|
@ -227,7 +228,7 @@ class MainWP_Child_Back_Up_WordPress {
|
|||
$date = filemtime( $file );
|
||||
if ( ! empty( $date ) ) {
|
||||
do_action( 'mainwp_reports_backupwordpress_backup', $destination, $message, 'finished', $backup_type, $date );
|
||||
MainWP_Helper::instance()->update_lasttime_backup( 'backupwordpress', $date ); // to support backup before update feature.
|
||||
MainWP_Utility::update_lasttime_backup( 'backupwordpress', $date ); // to support backup before update feature.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
// phpcs:disable -- third party credit.
|
||||
|
||||
use MainWP\Child\MainWP_Helper;
|
||||
use MainWP\Child\MainWP_Utility;
|
||||
|
||||
if ( ! defined( 'MAINWP_BACKWPUP_DEVELOPMENT' ) ) {
|
||||
define( 'MAINWP_BACKWPUP_DEVELOPMENT', false );
|
||||
|
@ -247,9 +248,7 @@ class MainWP_Child_Back_WP_Up {
|
|||
MainWP_Helper::instance()->check_classes_exists( array( '\BackWPup_File', '\BackWPup_Job' ) );
|
||||
MainWP_Helper::instance()->check_methods( '\BackWPup_File', array( 'get_absolute_path' ) );
|
||||
MainWP_Helper::instance()->check_methods( '\BackWPup_Job', array( 'read_logheader' ) );
|
||||
|
||||
$lasttime_logged = MainWP_Helper::instance()->get_lasttime_backup( 'backwpup' );
|
||||
|
||||
$lasttime_logged = MainWP_Utility::get_lasttime_backup( 'backwpup' );
|
||||
$log_folder = get_site_option( 'backwpup_cfg_logfolder' );
|
||||
$log_folder = \BackWPup_File::get_absolute_path( $log_folder );
|
||||
$log_folder = untrailingslashit( $log_folder );
|
||||
|
@ -319,7 +318,7 @@ class MainWP_Child_Back_WP_Up {
|
|||
}
|
||||
|
||||
if ( $new_lasttime_logged > $lasttime_logged ) {
|
||||
MainWP_Helper::instance()->update_lasttime_backup( 'backwpup', $new_lasttime_logged ); // to support backup before update feature.
|
||||
MainWP_Utility::update_lasttime_backup( 'backwpup', $new_lasttime_logged ); // to support backup before update feature.
|
||||
}
|
||||
}
|
||||
} catch ( \Exception $ex ) {
|
||||
|
@ -330,7 +329,7 @@ class MainWP_Child_Back_WP_Up {
|
|||
public function sync_others_data( $information, $data = array() ) {
|
||||
if ( isset( $data['syncBackwpupData'] ) && $data['syncBackwpupData'] ) {
|
||||
try {
|
||||
$lastbackup = MainWP_Helper::instance()->get_lasttime_backup( 'backwpup' );
|
||||
$lastbackup = MainWP_Utility::get_lasttime_backup( 'backwpup' );
|
||||
$information['syncBackwpupData'] = array(
|
||||
'lastbackup' => $lastbackup,
|
||||
);
|
||||
|
|
|
@ -656,17 +656,111 @@ class MainWP_Child_Branding {
|
|||
}
|
||||
|
||||
if ( ! empty( $header_css ) ) {
|
||||
echo '<style>' . MainWP_Helper::parse_css( $header_css ) . '</style>';
|
||||
echo '<style>' . self::parse_css( $header_css ) . '</style>';
|
||||
}
|
||||
}
|
||||
|
||||
public function custom_login_css() {
|
||||
$extra_setting = $this->get_extra_options();
|
||||
if ( isset( $extra_setting['login_css'] ) && ! empty( $extra_setting['login_css'] ) ) {
|
||||
echo '<style>' . MainWP_Helper::parse_css( $extra_setting['login_css'] ) . '</style>';
|
||||
echo '<style>' . self::parse_css( $extra_setting['login_css'] ) . '</style>';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* PARSE
|
||||
* Parses some CSS into an array
|
||||
* CSSPARSER
|
||||
* Copyright (C) 2009 Peter Kröner
|
||||
*/
|
||||
public static function parse_css( $css ) {
|
||||
|
||||
// Remove CSS-Comments.
|
||||
$css = preg_replace( '/\/\*.*?\*\//ms', '', $css );
|
||||
// Remove HTML-Comments.
|
||||
$css = preg_replace( '/([^\'"]+?)(\<!--|--\>)([^\'"]+?)/ms', '$1$3', $css );
|
||||
// Extract @media-blocks into $blocks.
|
||||
preg_match_all( '/@.+?\}[^\}]*?\}/ms', $css, $blocks );
|
||||
// Append the rest to $blocks.
|
||||
array_push( $blocks[0], preg_replace( '/@.+?\}[^\}]*?\}/ms', '', $css ) );
|
||||
$ordered = array();
|
||||
$count_blocks = count( $blocks[0] );
|
||||
for ( $i = 0; $i < $count_blocks; $i++ ) {
|
||||
// If @media-block, strip declaration and parenthesis.
|
||||
if ( '@media' === substr( $blocks[0][ $i ], 0, 6 ) ) {
|
||||
$ordered_key = preg_replace( '/^(@media[^\{]+)\{.*\}$/ms', '$1', $blocks[0][ $i ] );
|
||||
$ordered_value = preg_replace( '/^@media[^\{]+\{(.*)\}$/ms', '$1', $blocks[0][ $i ] );
|
||||
} elseif ( '@' === substr( $blocks[0][ $i ], 0, 1 ) ) {
|
||||
$ordered_key = $blocks[0][ $i ];
|
||||
$ordered_value = $blocks[0][ $i ];
|
||||
} else {
|
||||
$ordered_key = 'main';
|
||||
$ordered_value = $blocks[0][ $i ];
|
||||
}
|
||||
// Split by parenthesis, ignoring those inside content-quotes.
|
||||
$ordered[ $ordered_key ] = preg_split( '/([^\'"\{\}]*?[\'"].*?(?<!\\\)[\'"][^\'"\{\}]*?)[\{\}]|([^\'"\{\}]*?)[\{\}]/', trim( $ordered_value, " \r\n\t" ), -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE );
|
||||
}
|
||||
return self::parse_css_rebuild( $ordered );
|
||||
}
|
||||
|
||||
public static function parse_css_rebuild( $ordered ) {
|
||||
// Beginning to rebuild new slim CSS-Array.
|
||||
foreach ( $ordered as $key => $val ) {
|
||||
$new = array();
|
||||
$count_val = count( $val );
|
||||
for ( $i = 0; $i < $count_val; $i++ ) {
|
||||
// Split selectors and rules and split properties and values.
|
||||
$selector = trim( $val[ $i ], " \r\n\t" );
|
||||
|
||||
if ( ! empty( $selector ) ) {
|
||||
if ( ! isset( $new[ $selector ] ) ) {
|
||||
$new[ $selector ] = array();
|
||||
}
|
||||
$rules = explode( ';', $val[ ++$i ] );
|
||||
foreach ( $rules as $rule ) {
|
||||
$rule = trim( $rule, " \r\n\t" );
|
||||
if ( ! empty( $rule ) ) {
|
||||
$rule = array_reverse( explode( ':', $rule ) );
|
||||
$property = trim( array_pop( $rule ), " \r\n\t" );
|
||||
$value = implode( ':', array_reverse( $rule ) );
|
||||
|
||||
if ( ! isset( $new[ $selector ][ $property ] ) || ! preg_match( '/!important/', $new[ $selector ][ $property ] ) ) {
|
||||
$new[ $selector ][ $property ] = $value;
|
||||
} elseif ( preg_match( '/!important/', $new[ $selector ][ $property ] ) && preg_match( '/!important/', $value ) ) {
|
||||
$new[ $selector ][ $property ] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$ordered[ $key ] = $new;
|
||||
}
|
||||
$parsed = $ordered;
|
||||
|
||||
$output = '';
|
||||
foreach ( $parsed as $media => $content ) {
|
||||
if ( '@media' === substr( $media, 0, 6 ) ) {
|
||||
$output .= $media . " {\n";
|
||||
$prefix = "\t";
|
||||
} else {
|
||||
$prefix = '';
|
||||
}
|
||||
|
||||
foreach ( $content as $selector => $rules ) {
|
||||
$output .= $prefix . $selector . " {\n";
|
||||
foreach ( $rules as $property => $value ) {
|
||||
$output .= $prefix . "\t" . $property . ': ' . $value;
|
||||
$output .= ";\n";
|
||||
}
|
||||
$output .= $prefix . "}\n\n";
|
||||
}
|
||||
if ( '@media' === substr( $media, 0, 6 ) ) {
|
||||
$output .= "}\n\n";
|
||||
}
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
|
||||
public function custom_the_generator( $generator, $type = '' ) {
|
||||
$extra_setting = $this->get_extra_options();
|
||||
if ( isset( $extra_setting['site_generator'] ) ) {
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
namespace MainWP\Child;
|
||||
|
||||
// phpcs:disable WordPress.WP.AlternativeFunctions -- root namespace to use external code.
|
||||
// phpcs:disable WordPress.WP.AlternativeFunctions -- to use external code.
|
||||
|
||||
class MainWP_Child_Callable {
|
||||
|
||||
|
|
|
@ -19,11 +19,11 @@ class MainWP_Child_Install {
|
|||
protected static $instance = null;
|
||||
|
||||
|
||||
/**
|
||||
* Get Class Name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
/**
|
||||
* Get Class Name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get_class_name() {
|
||||
return __CLASS__;
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
|
||||
use MainWP\Child\MainWP_Helper;
|
||||
|
||||
// phpcs:disable PSR1.Classes.ClassDeclaration, WordPress.WP.AlternativeFunctions -- root namespace to use external code.
|
||||
// phpcs:disable PSR1.Classes.ClassDeclaration, WordPress.WP.AlternativeFunctions -- to use external code.
|
||||
|
||||
class MainWP_Child_Links_Checker {
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
use MainWP\Child\MainWP_Helper;
|
||||
|
||||
// phpcs:disable PSR1.Classes.ClassDeclaration, WordPress.WP.AlternativeFunctions -- root namespace to use external code.
|
||||
// phpcs:disable PSR1.Classes.ClassDeclaration, WordPress.WP.AlternativeFunctions -- to use external code.
|
||||
|
||||
class MainWP_Child_Pagespeed {
|
||||
|
||||
|
|
1118
class/class-mainwp-child-server-information-render.php
Normal file
1118
class/class-mainwp-child-server-information-render.php
Normal file
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
@ -15,7 +15,7 @@
|
|||
use MainWP\Child\MainWP_Child_Callable;
|
||||
use MainWP\Child\MainWP_Helper;
|
||||
|
||||
// phpcs:disable PSR1.Classes.ClassDeclaration, WordPress.WP.AlternativeFunctions -- root namespace to use external code.
|
||||
// phpcs:disable PSR1.Classes.ClassDeclaration, WordPress.WP.AlternativeFunctions -- to use external code.
|
||||
|
||||
class MainWP_Child_Staging {
|
||||
|
||||
|
@ -82,9 +82,13 @@ class MainWP_Child_Staging {
|
|||
MainWP_Helper::write( array( 'error' => __( 'Please install WP Staging plugin on child website', 'mainwp-child' ) ) );
|
||||
}
|
||||
|
||||
if ( ! class_exists( 'WPStaging\WPStaging' ) ) {
|
||||
require_once WPSTG_PLUGIN_DIR . 'apps/Core/WPStaging.php';
|
||||
}
|
||||
if (!class_exists( 'WPStaging\WPStaging' )){
|
||||
if ( file_exists( WPSTG_PLUGIN_DIR . 'app/Core/WPStaging.php' ) ) {
|
||||
require_once WPSTG_PLUGIN_DIR . 'app/Core/WPStaging.php';
|
||||
} else if ( file_exists( WPSTG_PLUGIN_DIR . "Core/WPStaging.php" ) ) {
|
||||
require_once WPSTG_PLUGIN_DIR . "Core/WPStaging.php";
|
||||
}
|
||||
}
|
||||
|
||||
\WPStaging\WPStaging::getInstance();
|
||||
$information = array();
|
||||
|
@ -237,7 +241,11 @@ class MainWP_Child_Staging {
|
|||
}
|
||||
|
||||
ob_start();
|
||||
require_once WPSTG_PLUGIN_DIR . 'apps/Backend/views/clone/ajax/start.php';
|
||||
if ( file_exists( WPSTG_PLUGIN_DIR . 'app/Backend/views/clone/ajax/start.php' ) ) {
|
||||
require_once WPSTG_PLUGIN_DIR . 'app/Backend/views/clone/ajax/start.php';
|
||||
} else if ( file_exists( WPSTG_PLUGIN_DIR . "Backend/views/clone/ajax/start.php" ) ) {
|
||||
require_once WPSTG_PLUGIN_DIR . "Backend/views/clone/ajax/start.php";
|
||||
}
|
||||
$result = ob_get_clean();
|
||||
return $result;
|
||||
}
|
||||
|
@ -333,7 +341,11 @@ class MainWP_Child_Staging {
|
|||
}
|
||||
|
||||
ob_start();
|
||||
require_once WPSTG_PLUGIN_DIR . 'apps/Backend/views/clone/ajax/update.php';
|
||||
if ( file_exists( WPSTG_PLUGIN_DIR . 'app/Backend/views/clone/ajax/update.php' ) ) {
|
||||
require_once WPSTG_PLUGIN_DIR . 'app/Backend/views/clone/ajax/update.php';
|
||||
} else if ( file_exists( WPSTG_PLUGIN_DIR . "Backend/views/clone/ajax/update.php" ) ) {
|
||||
require_once WPSTG_PLUGIN_DIR . "Backend/views/clone/ajax/update.php";
|
||||
}
|
||||
$result = ob_get_clean();
|
||||
return $result;
|
||||
}
|
||||
|
|
|
@ -141,7 +141,7 @@ class MainWP_Child_Stats {
|
|||
|
||||
if ( isset( $_POST['primaryBackup'] ) && ! empty( $_POST['primaryBackup'] ) ) {
|
||||
$primary_bk = $_POST['primaryBackup'];
|
||||
$information['primaryLasttimeBackup'] = MainWP_Helper::instance()->get_lasttime_backup( $primary_bk );
|
||||
$information['primaryLasttimeBackup'] = MainWP_Utility::get_lasttime_backup( $primary_bk );
|
||||
}
|
||||
|
||||
$last_post = wp_get_recent_posts( array( 'numberposts' => absint( '1' ) ) );
|
||||
|
@ -151,7 +151,7 @@ class MainWP_Child_Stats {
|
|||
if ( isset( $last_post ) && isset( $last_post['post_modified_gmt'] ) ) {
|
||||
$information['last_post_gmt'] = strtotime( $last_post['post_modified_gmt'] );
|
||||
}
|
||||
$information['mainwpdir'] = ( MainWP_Helper::validate_mainwp_dir() ? 1 : - 1 );
|
||||
$information['mainwpdir'] = ( MainWP_Utility::validate_mainwp_dir() ? 1 : - 1 );
|
||||
$information['uniqueId'] = get_option( 'mainwp_child_uniqueId', '' );
|
||||
$information['plugins_outdate_info'] = MainWP_Child_Plugins_Check::instance()->get_plugins_outdate_info();
|
||||
$information['themes_outdate_info'] = MainWP_Child_Themes_Check::instance()->get_themes_outdate_info();
|
||||
|
|
|
@ -12,9 +12,10 @@
|
|||
*/
|
||||
|
||||
use MainWP\Child\MainWP_Helper;
|
||||
use MainWP\Child\MainWP_Utility;
|
||||
use MainWP\Child\MainWP_Child_DB;
|
||||
|
||||
// phpcs:disable PSR1.Classes.ClassDeclaration, WordPress.WP.AlternativeFunctions -- root namespace to use external code.
|
||||
// phpcs:disable PSR1.Classes.ClassDeclaration, WordPress.WP.AlternativeFunctions, Generic.Metrics.CyclomaticComplexity -- to use external code.
|
||||
|
||||
class MainWP_Child_Timecapsule {
|
||||
public static $instance = null;
|
||||
|
@ -702,11 +703,11 @@ class MainWP_Child_Timecapsule {
|
|||
$backup_time = $config->get_option( 'last_backup_time' );
|
||||
|
||||
if ( ! empty( $backup_time ) ) {
|
||||
MainWP_Helper::instance()->update_lasttime_backup( 'wptimecapsule', $backup_time );
|
||||
MainWP_Utility::update_lasttime_backup( 'wptimecapsule', $backup_time );
|
||||
}
|
||||
|
||||
$last_time = time() - 24 * 7 * 2 * 60 * 60;
|
||||
$lasttime_logged = MainWP_Helper::instance()->get_lasttime_backup( 'wptimecapsule' );
|
||||
$lasttime_logged = MainWP_Utility::get_lasttime_backup( 'wptimecapsule' );
|
||||
if ( empty( $lasttime_logged ) ) {
|
||||
$last_time = time() - 24 * 7 * 8 * 60 * 60;
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
*/
|
||||
|
||||
use MainWP\Child\MainWP_Helper;
|
||||
use MainWP\Child\MainWP_Utility;
|
||||
|
||||
// phpcs:disable -- Third party credit.
|
||||
|
||||
|
@ -49,7 +50,7 @@ class MainWP_Child_Updraft_Plus_Backups {
|
|||
if ( isset( $last_backup['backup_time'] ) ) {
|
||||
$backup_time = $last_backup['backup_time'];
|
||||
if ( $last_backup['success'] ) {
|
||||
MainWP_Helper::instance()->update_lasttime_backup( 'updraftplus', $backup_time );
|
||||
MainWP_Utility::update_lasttime_backup( 'updraftplus', $backup_time );
|
||||
}
|
||||
}
|
||||
return $last_backup;
|
||||
|
@ -380,7 +381,7 @@ class MainWP_Child_Updraft_Plus_Backups {
|
|||
delete_transient( 'udvault_last_config' );
|
||||
delete_transient( 'updraftvault_quota_text' );
|
||||
|
||||
MainWP_Helper::close_connection(
|
||||
MainWP_Utility::close_connection(
|
||||
array(
|
||||
'disconnected' => 1,
|
||||
'html' => $this->connected_html(),
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
use MainWP\Child\MainWP_Helper;
|
||||
|
||||
|
||||
// phpcs:disable PSR1.Classes.ClassDeclaration, WordPress.WP.AlternativeFunctions -- root namespace to use external code.
|
||||
// phpcs:disable PSR1.Classes.ClassDeclaration, WordPress.WP.AlternativeFunctions -- to use external code.
|
||||
|
||||
class MainWP_Child_WooCommerce_Status {
|
||||
public static $instance = null;
|
||||
|
|
|
@ -12,9 +12,10 @@
|
|||
*/
|
||||
|
||||
use MainWP\Child\MainWP_Helper;
|
||||
use MainWP\Child\MainWP_Utility;
|
||||
use MainWP\Child\MainWP_Child_DB;
|
||||
|
||||
// phpcs:disable PSR1.Classes.ClassDeclaration, WordPress.WP.AlternativeFunctions -- root namespace to use external code.
|
||||
// phpcs:disable PSR1.Classes.ClassDeclaration, WordPress.WP.AlternativeFunctions -- to use external code.
|
||||
|
||||
class MainWP_Child_Wordfence {
|
||||
public static $instance = null;
|
||||
|
@ -2132,7 +2133,7 @@ SQL
|
|||
'code' => wfCache::getHtaccessCode(),
|
||||
);
|
||||
}
|
||||
$download_url = admin_url( 'admin-ajax.php' ) . '?action=mainwp_wordfence_download_htaccess&_wpnonce=' . MainWP_Helper::instance()->create_nonce_without_session( 'mainwp_download_htaccess' );
|
||||
$download_url = admin_url( 'admin-ajax.php' ) . '?action=mainwp_wordfence_download_htaccess&_wpnonce=' . MainWP_Utility::create_nonce_without_session( 'mainwp_download_htaccess' );
|
||||
return array(
|
||||
'ok' => 1,
|
||||
'download_url' => $download_url,
|
||||
|
@ -2160,7 +2161,7 @@ SQL
|
|||
die( '-1' );
|
||||
}
|
||||
|
||||
if ( ! MainWP_Helper::instance()->verify_nonce_without_session( $_GET['_wpnonce'], 'mainwp_download_htaccess' ) ) {
|
||||
if ( ! MainWP_Utility::verify_nonce_without_session( $_GET['_wpnonce'], 'mainwp_download_htaccess' ) ) {
|
||||
die( '-2' );
|
||||
}
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
use MainWP\Child\MainWP_Helper;
|
||||
|
||||
// phpcs:disable PSR1.Classes.ClassDeclaration, WordPress.WP.AlternativeFunctions -- root namespace to use external code.
|
||||
// phpcs:disable PSR1.Classes.ClassDeclaration, WordPress.WP.AlternativeFunctions -- to use external code.
|
||||
|
||||
class MainWP_Child_WP_Rocket {
|
||||
public static $instance = null;
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
use MainWP\Child\MainWP_Helper;
|
||||
|
||||
|
||||
// phpcs:disable PSR1.Classes.ClassDeclaration, WordPress.WP.AlternativeFunctions -- root namespace to use external code.
|
||||
// phpcs:disable PSR1.Classes.ClassDeclaration, WordPress.WP.AlternativeFunctions -- to use external code.
|
||||
|
||||
class MainWP_Child_WPvivid_BackupRestore {
|
||||
|
||||
|
|
|
@ -5,7 +5,16 @@ namespace MainWP\Child;
|
|||
class MainWP_Client_Report {
|
||||
|
||||
public static $instance = null;
|
||||
|
||||
|
||||
/**
|
||||
* Get Class Name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get_class_name() {
|
||||
return __CLASS__;
|
||||
}
|
||||
|
||||
public static function instance() {
|
||||
if ( null === self::$instance ) {
|
||||
self::$instance = new self();
|
||||
|
@ -20,7 +29,7 @@ class MainWP_Client_Report {
|
|||
|
||||
public function init() {
|
||||
add_filter( 'mainwp_site_sync_others_data', array( $this, 'sync_others_data' ), 10, 2 );
|
||||
add_action( 'mainwp_child_log', array( 'MainWP_Client_Report', 'do_reports_log' ) );
|
||||
add_action( 'mainwp_child_log', array( self::get_class_name(), 'do_reports_log' ) );
|
||||
}
|
||||
|
||||
public function current_agent( $agent ) {
|
||||
|
|
|
@ -36,29 +36,6 @@ class MainWP_Helper {
|
|||
die( '<mainwp>' . base64_encode( $output ) . '</mainwp>' ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- to compatible with http encoding.
|
||||
}
|
||||
|
||||
public static function close_connection( $val = null ) {
|
||||
|
||||
if ( isset( $_REQUEST['json_result'] ) && true == $_REQUEST['json_result'] ) :
|
||||
$output = wp_json_encode( $val );
|
||||
else :
|
||||
$output = serialize( $val ); // phpcs:ignore -- to compatible.
|
||||
endif;
|
||||
|
||||
$output = '<mainwp>' . base64_encode( $output ) . '</mainwp>'; // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for begin reasons.
|
||||
// Close browser connection so that it can resume AJAX polling.
|
||||
header( 'Content-Length: ' . strlen( $output ) );
|
||||
header( 'Connection: close' );
|
||||
header( 'Content-Encoding: none' );
|
||||
if ( session_id() ) {
|
||||
session_write_close();
|
||||
}
|
||||
echo $output;
|
||||
if ( ob_get_level() ) {
|
||||
ob_end_flush();
|
||||
}
|
||||
flush();
|
||||
}
|
||||
|
||||
public static function error( $error, $code = null ) {
|
||||
$information['error'] = $error;
|
||||
if ( null !== $code ) {
|
||||
|
@ -67,100 +44,6 @@ class MainWP_Helper {
|
|||
self::write( $information );
|
||||
}
|
||||
|
||||
/**
|
||||
* PARSE
|
||||
* Parses some CSS into an array
|
||||
* CSSPARSER
|
||||
* Copyright (C) 2009 Peter Kröner
|
||||
*/
|
||||
public static function parse_css( $css ) {
|
||||
|
||||
// Remove CSS-Comments.
|
||||
$css = preg_replace( '/\/\*.*?\*\//ms', '', $css );
|
||||
// Remove HTML-Comments.
|
||||
$css = preg_replace( '/([^\'"]+?)(\<!--|--\>)([^\'"]+?)/ms', '$1$3', $css );
|
||||
// Extract @media-blocks into $blocks.
|
||||
preg_match_all( '/@.+?\}[^\}]*?\}/ms', $css, $blocks );
|
||||
// Append the rest to $blocks.
|
||||
array_push( $blocks[0], preg_replace( '/@.+?\}[^\}]*?\}/ms', '', $css ) );
|
||||
$ordered = array();
|
||||
$count_blocks = count( $blocks[0] );
|
||||
for ( $i = 0; $i < $count_blocks; $i++ ) {
|
||||
// If @media-block, strip declaration and parenthesis.
|
||||
if ( '@media' === substr( $blocks[0][ $i ], 0, 6 ) ) {
|
||||
$ordered_key = preg_replace( '/^(@media[^\{]+)\{.*\}$/ms', '$1', $blocks[0][ $i ] );
|
||||
$ordered_value = preg_replace( '/^@media[^\{]+\{(.*)\}$/ms', '$1', $blocks[0][ $i ] );
|
||||
} elseif ( '@' === substr( $blocks[0][ $i ], 0, 1 ) ) {
|
||||
$ordered_key = $blocks[0][ $i ];
|
||||
$ordered_value = $blocks[0][ $i ];
|
||||
} else {
|
||||
$ordered_key = 'main';
|
||||
$ordered_value = $blocks[0][ $i ];
|
||||
}
|
||||
// Split by parenthesis, ignoring those inside content-quotes.
|
||||
$ordered[ $ordered_key ] = preg_split( '/([^\'"\{\}]*?[\'"].*?(?<!\\\)[\'"][^\'"\{\}]*?)[\{\}]|([^\'"\{\}]*?)[\{\}]/', trim( $ordered_value, " \r\n\t" ), -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE );
|
||||
}
|
||||
return self::parse_css_rebuild( $ordered );
|
||||
}
|
||||
|
||||
public static function parse_css_rebuild( $ordered ) {
|
||||
// Beginning to rebuild new slim CSS-Array.
|
||||
foreach ( $ordered as $key => $val ) {
|
||||
$new = array();
|
||||
$count_val = count( $val );
|
||||
for ( $i = 0; $i < $count_val; $i++ ) {
|
||||
// Split selectors and rules and split properties and values.
|
||||
$selector = trim( $val[ $i ], " \r\n\t" );
|
||||
|
||||
if ( ! empty( $selector ) ) {
|
||||
if ( ! isset( $new[ $selector ] ) ) {
|
||||
$new[ $selector ] = array();
|
||||
}
|
||||
$rules = explode( ';', $val[ ++$i ] );
|
||||
foreach ( $rules as $rule ) {
|
||||
$rule = trim( $rule, " \r\n\t" );
|
||||
if ( ! empty( $rule ) ) {
|
||||
$rule = array_reverse( explode( ':', $rule ) );
|
||||
$property = trim( array_pop( $rule ), " \r\n\t" );
|
||||
$value = implode( ':', array_reverse( $rule ) );
|
||||
|
||||
if ( ! isset( $new[ $selector ][ $property ] ) || ! preg_match( '/!important/', $new[ $selector ][ $property ] ) ) {
|
||||
$new[ $selector ][ $property ] = $value;
|
||||
} elseif ( preg_match( '/!important/', $new[ $selector ][ $property ] ) && preg_match( '/!important/', $value ) ) {
|
||||
$new[ $selector ][ $property ] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$ordered[ $key ] = $new;
|
||||
}
|
||||
$parsed = $ordered;
|
||||
|
||||
$output = '';
|
||||
foreach ( $parsed as $media => $content ) {
|
||||
if ( '@media' === substr( $media, 0, 6 ) ) {
|
||||
$output .= $media . " {\n";
|
||||
$prefix = "\t";
|
||||
} else {
|
||||
$prefix = '';
|
||||
}
|
||||
|
||||
foreach ( $content as $selector => $rules ) {
|
||||
$output .= $prefix . $selector . " {\n";
|
||||
foreach ( $rules as $property => $value ) {
|
||||
$output .= $prefix . "\t" . $property . ': ' . $value;
|
||||
$output .= ";\n";
|
||||
}
|
||||
$output .= $prefix . "}\n\n";
|
||||
}
|
||||
if ( '@media' === substr( $media, 0, 6 ) ) {
|
||||
$output .= "}\n\n";
|
||||
}
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
|
||||
public static function get_mainwp_dir( $what = null, $dieOnError = true ) {
|
||||
/** @var $wp_filesystem WP_Filesystem_Base */
|
||||
global $wp_filesystem;
|
||||
|
@ -222,38 +105,6 @@ class MainWP_Helper {
|
|||
}
|
||||
}
|
||||
|
||||
public static function validate_mainwp_dir() {
|
||||
$done = false;
|
||||
$dir = self::get_mainwp_dir();
|
||||
$dir = $dir[0];
|
||||
if ( self::get_wp_filesystem() ) {
|
||||
global $wp_filesystem;
|
||||
try {
|
||||
self::check_dir( $dir, false );
|
||||
} catch ( \Exception $e ) {
|
||||
// ok!
|
||||
}
|
||||
if ( ! empty( $wp_filesystem ) ) {
|
||||
if ( $wp_filesystem->is_writable( $dir ) ) {
|
||||
$done = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//phpcs:disable -- use system functions
|
||||
if ( ! $done ) {
|
||||
if ( ! file_exists( $dir ) ) {
|
||||
@mkdirs( $dir );
|
||||
}
|
||||
if ( is_writable( $dir ) ) {
|
||||
$done = true;
|
||||
}
|
||||
}
|
||||
//phpcs:enable
|
||||
|
||||
return $done;
|
||||
}
|
||||
|
||||
public static function search( $array, $key ) {
|
||||
if ( is_object( $array ) ) {
|
||||
$array = (array) $array;
|
||||
|
@ -490,104 +341,6 @@ class MainWP_Helper {
|
|||
return $success;
|
||||
}
|
||||
|
||||
public function update_lasttime_backup( $by, $time ) {
|
||||
$backup_by = array( 'backupbuddy', 'backupwordpress', 'backwpup', 'updraftplus', 'wptimecapsule' );
|
||||
if ( ! in_array( $by, $backup_by ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$lasttime = get_option( 'mainwp_lasttime_backup_' . $by );
|
||||
if ( $time > $lasttime ) {
|
||||
update_option( 'mainwp_lasttime_backup_' . $by, $time );
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function get_lasttime_backup( $by ) {
|
||||
|
||||
if ( 'backupwp' == $by ) {
|
||||
$by = 'backupwordpress';
|
||||
}
|
||||
|
||||
$activated = true;
|
||||
switch ( $by ) {
|
||||
case 'backupbuddy':
|
||||
if ( ! is_plugin_active( 'backupbuddy/backupbuddy.php' ) && ! is_plugin_active( 'Backupbuddy/backupbuddy.php' ) ) {
|
||||
$activated = false;
|
||||
}
|
||||
break;
|
||||
case 'backupwordpress':
|
||||
if ( ! is_plugin_active( 'backupwordpress/backupwordpress.php' ) ) {
|
||||
$activated = false;
|
||||
}
|
||||
break;
|
||||
case 'backwpup':
|
||||
if ( ! is_plugin_active( 'backwpup/backwpup.php' ) && ! is_plugin_active( 'backwpup-pro/backwpup.php' ) ) {
|
||||
$activated = false;
|
||||
}
|
||||
break;
|
||||
case 'updraftplus':
|
||||
if ( ! is_plugin_active( 'updraftplus/updraftplus.php' ) ) {
|
||||
$activated = false;
|
||||
}
|
||||
break;
|
||||
case 'wptimecapsule':
|
||||
if ( ! is_plugin_active( 'wp-time-capsule/wp-time-capsule.php' ) ) {
|
||||
$activated = false;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
$activated = false;
|
||||
break;
|
||||
}
|
||||
|
||||
if ( ! $activated ) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return get_option( 'mainwp_lasttime_backup_' . $by, 0 );
|
||||
}
|
||||
|
||||
public function create_nonce_without_session( $action = - 1 ) {
|
||||
$user = wp_get_current_user();
|
||||
$uid = (int) $user->ID;
|
||||
if ( ! $uid ) {
|
||||
$uid = apply_filters( 'nonce_user_logged_out', $uid, $action );
|
||||
}
|
||||
|
||||
$i = wp_nonce_tick();
|
||||
|
||||
return substr( wp_hash( $i . '|' . $action . '|' . $uid, 'nonce' ), - 12, 10 );
|
||||
}
|
||||
|
||||
public function verify_nonce_without_session( $nonce, $action = - 1 ) {
|
||||
$nonce = (string) $nonce;
|
||||
$user = wp_get_current_user();
|
||||
$uid = (int) $user->ID;
|
||||
if ( ! $uid ) {
|
||||
$uid = apply_filters( 'nonce_user_logged_out', $uid, $action );
|
||||
}
|
||||
|
||||
if ( empty( $nonce ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$i = wp_nonce_tick();
|
||||
|
||||
$expected = substr( wp_hash( $i . '|' . $action . '|' . $uid, 'nonce' ), - 12, 10 );
|
||||
if ( hash_equals( $expected, $nonce ) ) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
$expected = substr( wp_hash( ( $i - 1 ) . '|' . $action . '|' . $uid, 'nonce' ), - 12, 10 );
|
||||
if ( hash_equals( $expected, $nonce ) ) {
|
||||
return 2;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function get_revisions( $max_revisions ) {
|
||||
global $wpdb;
|
||||
return $wpdb->get_results( $wpdb->prepare( " SELECT `post_parent`, COUNT(*) cnt FROM $wpdb->posts WHERE `post_type` = 'revision' GROUP BY `post_parent` HAVING COUNT(*) > %d ", $max_revisions ) );
|
||||
|
|
|
@ -64,7 +64,7 @@ class MainWP_Pages {
|
|||
$msg .= '</div></div></div>';
|
||||
echo wp_kses_post( $msg );
|
||||
}
|
||||
MainWP_Child_Server_Information::show_warnings();
|
||||
MainWP_Child_Server_Information_Render::render_warnings();
|
||||
}
|
||||
|
||||
public function admin_menu() {
|
||||
|
@ -245,18 +245,15 @@ class MainWP_Pages {
|
|||
|
||||
<?php if ( ! $hide_server_info ) { ?>
|
||||
<div class="mainwp-child-setting-tab server-info" <?php echo ( 'server-info' !== $shownPage ) ? $hide_style : ''; ?>>
|
||||
<?php MainWP_Child_Server_Information::render_page(); ?>
|
||||
<?php MainWP_Child_Server_Information_Render::render_page(); ?>
|
||||
</div>
|
||||
<?php } ?>
|
||||
|
||||
<?php if ( ! $hide_connection_detail ) { ?>
|
||||
<div class="mainwp-child-setting-tab connection-detail" <?php echo ( 'connection-detail' !== $shownPage ) ? $hide_style : ''; ?>>
|
||||
<?php MainWP_Child_Server_Information::render_connection_details(); ?>
|
||||
<?php MainWP_Child_Server_Information_Render::render_connection_details(); ?>
|
||||
</div>
|
||||
<?php } ?>
|
||||
|
||||
|
||||
|
||||
<?php
|
||||
self::render_footer();
|
||||
}
|
||||
|
|
|
@ -506,5 +506,157 @@ class MainWP_Utility {
|
|||
}
|
||||
// phpcs:enable
|
||||
}
|
||||
|
||||
public static function validate_mainwp_dir() {
|
||||
$done = false;
|
||||
$dir = MainWP_Helper::get_mainwp_dir();
|
||||
$dir = $dir[0];
|
||||
if ( MainWP_Helper::get_wp_filesystem() ) {
|
||||
global $wp_filesystem;
|
||||
try {
|
||||
MainWP_Helper::check_dir( $dir, false );
|
||||
} catch ( \Exception $e ) {
|
||||
// ok!
|
||||
}
|
||||
if ( ! empty( $wp_filesystem ) ) {
|
||||
if ( $wp_filesystem->is_writable( $dir ) ) {
|
||||
$done = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//phpcs:disable -- use system functions
|
||||
if ( ! $done ) {
|
||||
if ( ! file_exists( $dir ) ) {
|
||||
@mkdirs( $dir );
|
||||
}
|
||||
if ( is_writable( $dir ) ) {
|
||||
$done = true;
|
||||
}
|
||||
}
|
||||
//phpcs:enable
|
||||
|
||||
return $done;
|
||||
}
|
||||
|
||||
public static function close_connection( $val = null ) {
|
||||
|
||||
if ( isset( $_REQUEST['json_result'] ) && true == $_REQUEST['json_result'] ) :
|
||||
$output = wp_json_encode( $val );
|
||||
else :
|
||||
$output = serialize( $val ); // phpcs:ignore -- to compatible.
|
||||
endif;
|
||||
|
||||
$output = '<mainwp>' . base64_encode( $output ) . '</mainwp>'; // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for begin reasons.
|
||||
// Close browser connection so that it can resume AJAX polling.
|
||||
header( 'Content-Length: ' . strlen( $output ) );
|
||||
header( 'Connection: close' );
|
||||
header( 'Content-Encoding: none' );
|
||||
if ( session_id() ) {
|
||||
session_write_close();
|
||||
}
|
||||
echo $output;
|
||||
if ( ob_get_level() ) {
|
||||
ob_end_flush();
|
||||
}
|
||||
flush();
|
||||
}
|
||||
|
||||
public static function create_nonce_without_session( $action = - 1 ) {
|
||||
$user = wp_get_current_user();
|
||||
$uid = (int) $user->ID;
|
||||
if ( ! $uid ) {
|
||||
$uid = apply_filters( 'nonce_user_logged_out', $uid, $action );
|
||||
}
|
||||
|
||||
$i = wp_nonce_tick();
|
||||
|
||||
return substr( wp_hash( $i . '|' . $action . '|' . $uid, 'nonce' ), - 12, 10 );
|
||||
}
|
||||
|
||||
public static function verify_nonce_without_session( $nonce, $action = - 1 ) {
|
||||
$nonce = (string) $nonce;
|
||||
$user = wp_get_current_user();
|
||||
$uid = (int) $user->ID;
|
||||
if ( ! $uid ) {
|
||||
$uid = apply_filters( 'nonce_user_logged_out', $uid, $action );
|
||||
}
|
||||
|
||||
if ( empty( $nonce ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$i = wp_nonce_tick();
|
||||
|
||||
$expected = substr( wp_hash( $i . '|' . $action . '|' . $uid, 'nonce' ), - 12, 10 );
|
||||
if ( hash_equals( $expected, $nonce ) ) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
$expected = substr( wp_hash( ( $i - 1 ) . '|' . $action . '|' . $uid, 'nonce' ), - 12, 10 );
|
||||
if ( hash_equals( $expected, $nonce ) ) {
|
||||
return 2;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function update_lasttime_backup( $by, $time ) {
|
||||
$backup_by = array( 'backupbuddy', 'backupwordpress', 'backwpup', 'updraftplus', 'wptimecapsule' );
|
||||
if ( ! in_array( $by, $backup_by ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$lasttime = get_option( 'mainwp_lasttime_backup_' . $by );
|
||||
if ( $time > $lasttime ) {
|
||||
update_option( 'mainwp_lasttime_backup_' . $by, $time );
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function get_lasttime_backup( $by ) {
|
||||
|
||||
if ( 'backupwp' == $by ) {
|
||||
$by = 'backupwordpress';
|
||||
}
|
||||
|
||||
$activated = true;
|
||||
switch ( $by ) {
|
||||
case 'backupbuddy':
|
||||
if ( ! is_plugin_active( 'backupbuddy/backupbuddy.php' ) && ! is_plugin_active( 'Backupbuddy/backupbuddy.php' ) ) {
|
||||
$activated = false;
|
||||
}
|
||||
break;
|
||||
case 'backupwordpress':
|
||||
if ( ! is_plugin_active( 'backupwordpress/backupwordpress.php' ) ) {
|
||||
$activated = false;
|
||||
}
|
||||
break;
|
||||
case 'backwpup':
|
||||
if ( ! is_plugin_active( 'backwpup/backwpup.php' ) && ! is_plugin_active( 'backwpup-pro/backwpup.php' ) ) {
|
||||
$activated = false;
|
||||
}
|
||||
break;
|
||||
case 'updraftplus':
|
||||
if ( ! is_plugin_active( 'updraftplus/updraftplus.php' ) ) {
|
||||
$activated = false;
|
||||
}
|
||||
break;
|
||||
case 'wptimecapsule':
|
||||
if ( ! is_plugin_active( 'wp-time-capsule/wp-time-capsule.php' ) ) {
|
||||
$activated = false;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
$activated = false;
|
||||
break;
|
||||
}
|
||||
|
||||
if ( ! $activated ) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return get_option( 'mainwp_lasttime_backup_' . $by, 0 );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
use MainWP\Child\MainWP_Helper;
|
||||
|
||||
// phpcs:disable PSR1.Classes.ClassDeclaration, WordPress.WP.AlternativeFunctions -- root namespace to use external code.
|
||||
// phpcs:disable PSR1.Classes.ClassDeclaration, WordPress.WP.AlternativeFunctions -- to use external code.
|
||||
|
||||
class MainWP_WordPress_SEO {
|
||||
public static $instance = null;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue