Refactoring

This commit is contained in:
thanghv 2020-05-07 01:03:56 +07:00
parent ae8f7446af
commit 033145bc47
28 changed files with 171 additions and 214 deletions

View file

@ -22,7 +22,7 @@ class MainWP_Backup {
public static function get() { public static function get() {
if ( null === self::$instance ) { if ( null === self::$instance ) {
self::$instance = new MainWP_Backup(); self::$instance = new self();
} }
return self::$instance; return self::$instance;

View file

@ -21,7 +21,7 @@ class MainWP_Child_Back_Up_Buddy {
public static function instance() { public static function instance() {
if ( null === self::$instance ) { if ( null === self::$instance ) {
self::$instance = new MainWP_Child_Back_Up_Buddy(); self::$instance = new self();
} }
return self::$instance; return self::$instance;
} }
@ -207,7 +207,7 @@ class MainWP_Child_Back_Up_Buddy {
} }
} }
} }
} catch ( Exception $e ) { } catch ( \Exception $e ) {
// ok! // ok!
} }
} }
@ -752,7 +752,7 @@ class MainWP_Child_Back_Up_Buddy {
if ( isset( $data['syncBackupBuddy'] ) && $data['syncBackupBuddy'] ) { if ( isset( $data['syncBackupBuddy'] ) && $data['syncBackupBuddy'] ) {
try { try {
$information['syncBackupBuddy'] = $this->get_sync_data(); $information['syncBackupBuddy'] = $this->get_sync_data();
} catch ( Exception $e ) { } catch ( \Exception $e ) {
// ok! // ok!
} }
} }
@ -796,7 +796,7 @@ class MainWP_Child_Back_Up_Buddy {
} }
return $data; return $data;
} catch ( Exception $e ) { } catch ( \Exception $e ) {
// not exit here! // not exit here!
} }

View file

@ -15,15 +15,14 @@
namespace MainWP\Child; namespace MainWP\Child;
class MainWP_Child_Back_Up_Wordpress { class MainWP_Child_Back_Up_WordPress{
public static $instance = null; public static $instance = null;
public $is_plugin_installed = false; public $is_plugin_installed = false;
public static function instance() { public static function instance() {
if ( null === self::$instance ) { if ( null === self::$instance ) {
self::$instance = new MainWP_Child_Back_Up_Wordpress(); self::$instance = new self();
} }
return self::$instance; return self::$instance;
} }
@ -154,7 +153,7 @@ class MainWP_Child_Back_Up_Wordpress {
if ( isset( $data['syncBackUpWordPress'] ) && $data['syncBackUpWordPress'] ) { if ( isset( $data['syncBackUpWordPress'] ) && $data['syncBackUpWordPress'] ) {
try { try {
$information['syncBackUpWordPress'] = $this->get_sync_data(); $information['syncBackUpWordPress'] = $this->get_sync_data();
} catch ( Exception $e ) { } catch ( \Exception $e ) {
// ok! // ok!
} }
} }
@ -233,7 +232,7 @@ class MainWP_Child_Back_Up_Wordpress {
} }
} }
} }
} catch ( Exception $e ) { } catch ( \Exception $e ) {
// ok! // ok!
} }
} }

View file

@ -58,7 +58,7 @@ class MainWP_Child_Back_WP_Up {
public static function instance() { public static function instance() {
if ( null == self::$instance ) { if ( null == self::$instance ) {
self::$instance = new MainWP_Child_Back_WP_Up(); self::$instance = new self();
} }
return self::$instance; return self::$instance;
@ -97,7 +97,7 @@ class MainWP_Child_Back_WP_Up {
add_action( 'admin_init', array( $this, 'init_download_backup' ) ); add_action( 'admin_init', array( $this, 'init_download_backup' ) );
add_filter( 'mainwp-site-sync-others-data', array( $this, 'sync_others_data' ), 10, 2 ); add_filter( 'mainwp-site-sync-others-data', array( $this, 'sync_others_data' ), 10, 2 );
} }
} catch ( Exception $e ) { } catch ( \Exception $e ) {
$this->is_backwpup_installed = false; $this->is_backwpup_installed = false;
} }
} }
@ -322,7 +322,7 @@ class MainWP_Child_Back_WP_Up {
MainWP_Helper::update_lasttime_backup( 'backwpup', $new_lasttime_logged ); // to support backup before update feature. MainWP_Helper::update_lasttime_backup( 'backwpup', $new_lasttime_logged ); // to support backup before update feature.
} }
} }
} catch ( Exception $ex ) { } catch ( \Exception $ex ) {
// ok! // ok!
} }
} }
@ -334,7 +334,7 @@ class MainWP_Child_Back_WP_Up {
$information['syncBackwpupData'] = array( $information['syncBackwpupData'] = array(
'lastbackup' => $lastbackup, 'lastbackup' => $lastbackup,
); );
} catch ( Exception $e ) { } catch ( \Exception $e ) {
// ok! // ok!
} }
} }
@ -1097,7 +1097,7 @@ class MainWP_Child_Back_WP_Up {
$message->setBody( __( 'If this message reaches your inbox, sending backup archives via email should work for you.', 'mainwp-child' ) ); $message->setBody( __( 'If this message reaches your inbox, sending backup archives via email should work for you.', 'mainwp-child' ) );
$result = $emailer->send( $message ); $result = $emailer->send( $message );
} catch ( Exception $e ) { } catch ( \Exception $e ) {
$message = 'Swift Mailer: ' . $e->getMessage(); $message = 'Swift Mailer: ' . $e->getMessage();
} }

View file

@ -10,7 +10,7 @@ class MainWP_Child_Branding {
public static function instance() { public static function instance() {
if ( null === self::$instance ) { if ( null === self::$instance ) {
self::$instance = new MainWP_Child_Branding(); self::$instance = new self();
} }
return self::$instance; return self::$instance;
} }
@ -259,7 +259,7 @@ class MainWP_Child_Branding {
} }
} }
} }
} catch ( Exception $e ) { } catch ( \Exception $e ) {
$information['error']['login_image'] = $e->getMessage(); $information['error']['login_image'] = $e->getMessage();
} }
} }
@ -285,7 +285,7 @@ class MainWP_Child_Branding {
} }
} }
} }
} catch ( Exception $e ) { } catch ( \Exception $e ) {
$information['error']['favico_image'] = $e->getMessage(); $information['error']['favico_image'] = $e->getMessage();
} }
} }
@ -321,7 +321,7 @@ class MainWP_Child_Branding {
remove_filter( 'http_request_args', array( $mainWPChild, 'http_request_reject_unsafe_urls' ), 99, 2 ); remove_filter( 'http_request_args', array( $mainWPChild, 'http_request_reject_unsafe_urls' ), 99, 2 );
if ( is_wp_error( $temporary_file ) ) { if ( is_wp_error( $temporary_file ) ) {
throw new Exception( $temporary_file->get_error_message() ); throw new \Exception( $temporary_file->get_error_message() );
} else { } else {
$upload_dir = wp_upload_dir(); $upload_dir = wp_upload_dir();
$local_img_path = $upload_dir['path'] . DIRECTORY_SEPARATOR . basename( $img_url ); $local_img_path = $upload_dir['path'] . DIRECTORY_SEPARATOR . basename( $img_url );

View file

@ -45,7 +45,7 @@ class MainWP_Child_IThemes_Security {
$information['syncIThemeData'] = array( $information['syncIThemeData'] = array(
'users_and_roles' => $this->get_available_admin_users_and_roles(), 'users_and_roles' => $this->get_available_admin_users_and_roles(),
); );
} catch ( Exception $e ) { } catch ( \Exception $e ) {
error_log( $e->getMessage() ); error_log( $e->getMessage() );
} }
} }

View file

@ -79,7 +79,7 @@ class MainWP_Child_Links_Checker {
} }
} }
MainWP_Helper::write( $information ); MainWP_Helper::write( $information );
} catch ( Exception $e ) { } catch ( \Exception $e ) {
MainWP_Helper::write( array( 'error' => $e->getMessage() ) ); MainWP_Helper::write( array( 'error' => $e->getMessage() ) );
} }
} }
@ -208,7 +208,7 @@ class MainWP_Child_Links_Checker {
if ( isset( $data['syncBrokenLinksCheckerData'] ) && $data['syncBrokenLinksCheckerData'] ) { if ( isset( $data['syncBrokenLinksCheckerData'] ) && $data['syncBrokenLinksCheckerData'] ) {
try { try {
$information['syncBrokenLinksCheckerData'] = $this->get_sync_data(); $information['syncBrokenLinksCheckerData'] = $this->get_sync_data();
} catch ( Exception $e ) { } catch ( \Exception $e ) {
// ok! // ok!
} }
} }
@ -548,7 +548,7 @@ class MainWP_Child_Links_Checker {
'errors' => array(), 'errors' => array(),
); );
foreach ( $rez['errors'] as $error ) { foreach ( $rez['errors'] as $error ) {
/** @var WP_Error $error */ /** @var \WP_Error $error */
array_push( $response['errors'], implode( ', ', $error->get_error_messages() ) ); array_push( $response['errors'], implode( ', ', $error->get_error_messages() ) );
} }

View file

@ -21,7 +21,7 @@ class MainWP_Child_Pagespeed {
public static function instance() { public static function instance() {
if ( null === self::$instance ) { if ( null === self::$instance ) {
self::$instance = new MainWP_Child_Pagespeed(); self::$instance = new self();
} }
return self::$instance; return self::$instance;
@ -279,7 +279,7 @@ class MainWP_Child_Pagespeed {
if ( isset( $data['syncPageSpeedData'] ) && $data['syncPageSpeedData'] ) { if ( isset( $data['syncPageSpeedData'] ) && $data['syncPageSpeedData'] ) {
try { try {
$information['syncPageSpeedData'] = $this->get_sync_data(); $information['syncPageSpeedData'] = $this->get_sync_data();
} catch ( Exception $e ) { } catch ( \Exception $e ) {
// ok! // ok!
} }
} }

View file

@ -23,7 +23,7 @@ class MainWP_Child_Plugins_Check {
public static function instance() { public static function instance() {
if ( null === self::$instance ) { if ( null === self::$instance ) {
self::$instance = new MainWP_Child_Plugins_Check(); self::$instance = new self();
} }
return self::$instance; return self::$instance;

View file

@ -552,7 +552,7 @@ class MainWP_Child_Server_Information {
<tr> <tr>
<td></td> <td></td>
<td><?php echo esc_html( stripslashes( $branding_title ) ) . ' ' . __( 'Version', 'mainwp-chil' ); ?></td> <td><?php echo esc_html( stripslashes( $branding_title ) ) . ' ' . __( 'Version', 'mainwp-chil' ); ?></td>
<td><?php echo esc_html( self::getMainWPVersion() ); ?></td> <td><?php echo esc_html( self::get_mainwp_version() ); ?></td>
<td><?php echo esc_html( self::get_current_version() ); ?></td> <td><?php echo esc_html( self::get_current_version() ); ?></td>
<td><?php echo esc_html( self::get_mainwp_version_check() ); ?></td> <td><?php echo esc_html( self::get_mainwp_version_check() ); ?></td>
</tr> </tr>
@ -949,7 +949,7 @@ class MainWP_Child_Server_Information {
try { try {
$dirs = MainWP_Helper::get_mainwp_dir( null, false ); $dirs = MainWP_Helper::get_mainwp_dir( null, false );
$path = $dirs[0]; $path = $dirs[0];
} catch ( Exception $e ) { } catch ( \Exception $e ) {
return self::render_directory_row( $branding_title, '', 'Writable', $e->getMessage(), false ); return self::render_directory_row( $branding_title, '', 'Writable', $e->getMessage(), false );
} }

View file

@ -8,7 +8,7 @@ class MainWP_Child_Skeleton_Key {
public static function instance() { public static function instance() {
if ( null === self::$instance ) { if ( null === self::$instance ) {
self::$instance = new MainWP_Child_Skeleton_Key(); self::$instance = new self();
} }
return self::$instance; return self::$instance;

View file

@ -21,7 +21,7 @@ class MainWP_Child_Staging {
public static function instance() { public static function instance() {
if ( null === self::$instance ) { if ( null === self::$instance ) {
self::$instance = new MainWP_Child_Staging(); self::$instance = new self();
} }
return self::$instance; return self::$instance;
} }
@ -63,7 +63,7 @@ class MainWP_Child_Staging {
if ( isset( $data['syncWPStaging'] ) && $data['syncWPStaging'] ) { if ( isset( $data['syncWPStaging'] ) && $data['syncWPStaging'] ) {
try { try {
$information['syncWPStaging'] = $this->get_sync_data(); $information['syncWPStaging'] = $this->get_sync_data();
} catch ( Exception $e ) { } catch ( \Exception $e ) {
// ok! // ok!
} }
} }

View file

@ -22,7 +22,7 @@ class MainWP_Child_Themes_Check {
public static function instance() { public static function instance() {
if ( null === self::$instance ) { if ( null === self::$instance ) {
self::$instance = new MainWP_Child_Themes_Check(); self::$instance = new self();
} }
return self::$instance; return self::$instance;

View file

@ -19,7 +19,7 @@ class MainWP_Child_Timecapsule {
public static function instance() { public static function instance() {
if ( null === self::$instance ) { if ( null === self::$instance ) {
self::$instance = new MainWP_Child_Timecapsule(); self::$instance = new self();
} }
return self::$instance; return self::$instance;
} }
@ -65,7 +65,7 @@ class MainWP_Child_Timecapsule {
try { try {
$this->require_files(); $this->require_files();
} catch ( Exception $e ) { } catch ( \Exception $e ) {
$error = $e->getMessage(); $error = $e->getMessage();
MainWP_Helper::write( array( 'error' => $error ) ); MainWP_Helper::write( array( 'error' => $error ) );
} }
@ -281,7 +281,7 @@ class MainWP_Child_Timecapsule {
'backups_count' => $backups_count, 'backups_count' => $backups_count,
); );
return $return; return $return;
} catch ( Exception $e ) { } catch ( \Exception $e ) {
// do not exit here! // do not exit here!
} }
return false; return false;
@ -727,7 +727,7 @@ class MainWP_Child_Timecapsule {
} }
} }
} }
} catch ( Exception $e ) { } catch ( \Exception $e ) {
// ok. // ok.
} }
} }

View file

@ -19,7 +19,7 @@ class MainWP_Child_Updraft_Plus_Backups {
public $is_plugin_installed = false; public $is_plugin_installed = false;
public static function instance() { public static function instance() {
if ( null === self::$instance ) { if ( null === self::$instance ) {
self::$instance = new MainWP_Child_Updraft_Plus_Backups(); self::$instance = new self();
} }
return self::$instance; return self::$instance;
@ -70,7 +70,7 @@ class MainWP_Child_Updraft_Plus_Backups {
$information['sync_Updraftvault_quota_text'] = $this->connected_html(); $information['sync_Updraftvault_quota_text'] = $this->connected_html();
} }
} }
} catch ( Exception $e ) { } catch ( \Exception $e ) {
// ok. // ok.
} }
@ -159,7 +159,7 @@ class MainWP_Child_Updraft_Plus_Backups {
$information = $this->vault_disconnect(); $information = $this->vault_disconnect();
break; break;
} }
} catch ( Exception $e ) { } catch ( \Exception $e ) {
$information = array( 'error' => $e->getMessage() ); $information = array( 'error' => $e->getMessage() );
} }
} }
@ -291,7 +291,7 @@ class MainWP_Child_Updraft_Plus_Backups {
} }
// Returns either true (in which case the Vault token will be stored), or false|WP_Error. // Returns either true (in which case the Vault token will be stored), or false|\WP_Error.
private function vault_connect( $email, $password ) { private function vault_connect( $email, $password ) {
global $updraftplus; global $updraftplus;
$vault_mothership = 'https://vault.updraftplus.com/plugin-info/'; $vault_mothership = 'https://vault.updraftplus.com/plugin-info/';
@ -318,9 +318,9 @@ class MainWP_Child_Updraft_Plus_Backups {
if ( ! is_array( $response ) || ! isset( $response['mothership'] ) || ! isset( $response['loggedin'] ) ) { if ( ! is_array( $response ) || ! isset( $response['mothership'] ) || ! isset( $response['loggedin'] ) ) {
if ( preg_match( '/has banned your IP address \(([\.:0-9a-f]+)\)/', $result['body'], $matches ) ) { if ( preg_match( '/has banned your IP address \(([\.:0-9a-f]+)\)/', $result['body'], $matches ) ) {
return new WP_Error( 'banned_ip', sprintf( __( "UpdraftPlus.com has responded with 'Access Denied'.", 'updraftplus' ) . '<br>' . __( "It appears that your web server's IP Address (%s) is blocked.", 'updraftplus' ) . ' ' . __( 'This most likely means that you share a webserver with a hacked website that has been used in previous attacks.', 'updraftplus' ) . '<br> <a href="https://updraftplus.com/unblock-ip-address/" target="_blank">' . __( 'To remove the block, please go here.', 'updraftplus' ) . '</a> ', $matches[1] ) ); return new \WP_Error( 'banned_ip', sprintf( __( "UpdraftPlus.com has responded with 'Access Denied'.", 'updraftplus' ) . '<br>' . __( "It appears that your web server's IP Address (%s) is blocked.", 'updraftplus' ) . ' ' . __( 'This most likely means that you share a webserver with a hacked website that has been used in previous attacks.', 'updraftplus' ) . '<br> <a href="https://updraftplus.com/unblock-ip-address/" target="_blank">' . __( 'To remove the block, please go here.', 'updraftplus' ) . '</a> ', $matches[1] ) );
} else { } else {
return new WP_Error( 'unknown_response', sprintf( __( 'UpdraftPlus.Com returned a response which we could not understand (data: %s)', 'updraftplus' ), $result['body'] ) ); return new \WP_Error( 'unknown_response', sprintf( __( 'UpdraftPlus.Com returned a response which we could not understand (data: %s)', 'updraftplus' ), $result['body'] ) );
} }
} }
@ -342,26 +342,26 @@ class MainWP_Child_Updraft_Plus_Backups {
} }
UpdraftPlus_Options::update_updraft_option( 'updraft_updraftvault', $vault_settings ); UpdraftPlus_Options::update_updraft_option( 'updraft_updraftvault', $vault_settings );
} elseif ( isset( $response['quota'] ) && ! $response['quota'] ) { } elseif ( isset( $response['quota'] ) && ! $response['quota'] ) {
return new WP_Error( 'no_quota', __( 'You do not currently have any UpdraftPlus Vault quota', 'updraftplus' ) ); return new \WP_Error( 'no_quota', __( 'You do not currently have any UpdraftPlus Vault quota', 'updraftplus' ) );
} else { } else {
return new WP_Error( 'unknown_response', __( 'UpdraftPlus.Com returned a response, but we could not understand it', 'updraftplus' ) ); return new \WP_Error( 'unknown_response', __( 'UpdraftPlus.Com returned a response, but we could not understand it', 'updraftplus' ) );
} }
break; break;
case 'authfailed': case 'authfailed':
if ( ! empty( $response['authproblem'] ) ) { if ( ! empty( $response['authproblem'] ) ) {
if ( 'invalidpassword' == $response['authproblem'] ) { if ( 'invalidpassword' == $response['authproblem'] ) {
$authfail_error = new WP_Error( 'authfailed', __( 'Your email address was valid, but your password was not recognised by UpdraftPlus.Com.', 'updraftplus' ) . ' <a href="https://updraftplus.com/my-account/lost-password/">' . __( 'If you have forgotten your password, then go here to change your password on updraftplus.com.', 'updraftplus' ) . '</a>' ); $authfail_error = new \WP_Error( 'authfailed', __( 'Your email address was valid, but your password was not recognised by UpdraftPlus.Com.', 'updraftplus' ) . ' <a href="https://updraftplus.com/my-account/lost-password/">' . __( 'If you have forgotten your password, then go here to change your password on updraftplus.com.', 'updraftplus' ) . '</a>' );
return $authfail_error; return $authfail_error;
} elseif ( 'invaliduser' == $response['authproblem'] ) { } elseif ( 'invaliduser' == $response['authproblem'] ) {
return new WP_Error( 'authfailed', __( 'You entered an email address that was not recognised by UpdraftPlus.Com', 'updraftplus' ) ); return new \WP_Error( 'authfailed', __( 'You entered an email address that was not recognised by UpdraftPlus.Com', 'updraftplus' ) );
} }
} }
$return = new WP_Error( 'authfailed', __( 'Your email address and password were not recognised by UpdraftPlus.Com', 'updraftplus' ) ); $return = new \WP_Error( 'authfailed', __( 'Your email address and password were not recognised by UpdraftPlus.Com', 'updraftplus' ) );
break; break;
default: default:
$return = new WP_Error( 'unknown_response', __( 'UpdraftPlus.Com returned a response, but we could not understand it', 'updraftplus' ) ); $return = new \WP_Error( 'unknown_response', __( 'UpdraftPlus.Com returned a response, but we could not understand it', 'updraftplus' ) );
break; break;
} }
@ -430,7 +430,7 @@ class MainWP_Child_Updraft_Plus_Backups {
if ( class_exists( 'UpdraftPlus_Options' ) ) { if ( class_exists( 'UpdraftPlus_Options' ) ) {
foreach ( $keys_filter as $key ) { foreach ( $keys_filter as $key ) {
if ( 'updraft_googledrive' === $key || 'updraft_googlecloud' === $key || 'updraft_onedrive' === $key ) { if ( 'updraft_googledrive' === $key || 'updraft_googlecloud' === $key || 'updraft_onedrive' === $key ) {
continue; // skip continue;
} }
if ( isset( $settings[ $key ] ) ) { if ( isset( $settings[ $key ] ) ) {
$settings_key = null; $settings_key = null;

View file

@ -23,7 +23,7 @@ class MainWP_Child_Vulnerability_Checker {
public static function instance() { public static function instance() {
if ( null === self::$instance ) { if ( null === self::$instance ) {
self::$instance = new MainWP_Child_Vulnerability_Checker(); self::$instance = new self();
} }
return self::$instance; return self::$instance;
} }

View file

@ -173,7 +173,7 @@ class MainWP_Child_Wordfence {
public static function instance() { public static function instance() {
if ( null === self::$instance ) { if ( null === self::$instance ) {
self::$instance = new MainWP_Child_Wordfence(); self::$instance = new self();
} }
return self::$instance; return self::$instance;
@ -1258,9 +1258,9 @@ SQL
$result['isPaid'] = 0; $result['isPaid'] = 0;
$reload = 'reload'; $reload = 'reload';
} else { } else {
throw new Exception( "The Wordfence server's response did not contain the expected elements." ); throw new \Exception( "The Wordfence server's response did not contain the expected elements." );
} }
} catch ( Exception $e ) { } catch ( \Exception $e ) {
$result['error'] = 'Your options have been saved, but you left your license key blank, so we tried to get you a free license key from the Wordfence servers. There was a problem fetching the free key: ' . wp_kses( $e->getMessage(), array() ); $result['error'] = 'Your options have been saved, but you left your license key blank, so we tried to get you a free license key from the Wordfence servers. There was a problem fetching the free key: ' . wp_kses( $e->getMessage(), array() );
return $result; return $result;
} }
@ -1287,9 +1287,9 @@ SQL
$ping = true; $ping = true;
$reload = 'reload'; $reload = 'reload';
} else { } else {
throw new Exception( 'We could not understand the Wordfence API server reply when updating your API key.' ); throw new \Exception( 'We could not understand the Wordfence API server reply when updating your API key.' );
} }
} catch ( Exception $e ) { } catch ( \Exception $e ) {
$result['error'] = 'Your options have been saved. However we noticed you changed your API key and we tried to verify it with the Wordfence servers and received an error: ' . htmlentities( $e->getMessage() ); $result['error'] = 'Your options have been saved. However we noticed you changed your API key and we tried to verify it with the Wordfence servers and received an error: ' . htmlentities( $e->getMessage() );
return $result; return $result;
} }
@ -1343,7 +1343,7 @@ SQL
$result['paidKeyMsg'] = true; $result['paidKeyMsg'] = true;
} }
} }
} catch ( Exception $e ) { } catch ( \Exception $e ) {
$result['error'] = 'Your options have been saved. However we tried to verify your license key with the Wordfence servers and received an error: ' . wp_kses( $e->getMessage(), array() ); $result['error'] = 'Your options have been saved. However we tried to verify your license key with the Wordfence servers and received an error: ' . wp_kses( $e->getMessage(), array() );
return $result; return $result;
} }
@ -1435,7 +1435,7 @@ SQL
} else { } else {
wfConfig::removeCodeExecutionProtectionForUploads(); wfConfig::removeCodeExecutionProtectionForUploads();
} }
} catch ( wfConfigException $e ) { } catch ( wfConfig\Exception $e ) {
return array( 'error' => $e->getMessage() ); return array( 'error' => $e->getMessage() );
} }
} }
@ -1475,9 +1475,9 @@ SQL
$result['isPaid'] = 0; $result['isPaid'] = 0;
$reload = 'reload'; $reload = 'reload';
} else { } else {
throw new Exception( "We could not understand the Wordfence server's response because it did not contain an 'ok' and 'apiKey' element." ); throw new \Exception( "We could not understand the Wordfence server's response because it did not contain an 'ok' and 'apiKey' element." );
} }
} catch ( Exception $e ) { } catch ( \Exception $e ) {
$result['error'] = 'Your options have been saved, but we encountered a problem. You left your API key blank, so we tried to get you a free API key from the Wordfence servers. However we encountered a problem fetching the free key: ' . htmlentities( $e->getMessage() ); $result['error'] = 'Your options have been saved, but we encountered a problem. You left your API key blank, so we tried to get you a free API key from the Wordfence servers. However we encountered a problem fetching the free key: ' . htmlentities( $e->getMessage() );
return $result; return $result;
@ -1496,9 +1496,9 @@ SQL
} }
$reload = 'reload'; $reload = 'reload';
} else { } else {
throw new Exception( 'We could not understand the Wordfence API server reply when updating your API key.' ); throw new \Exception( 'We could not understand the Wordfence API server reply when updating your API key.' );
} }
} catch ( Exception $e ) { } catch ( \Exception $e ) {
$result['error'] = 'Your options have been saved. However we noticed you changed your API key and we tried to verify it with the Wordfence servers and received an error: ' . htmlentities( $e->getMessage() ); $result['error'] = 'Your options have been saved. However we noticed you changed your API key and we tried to verify it with the Wordfence servers and received an error: ' . htmlentities( $e->getMessage() );
return $result; return $result;
@ -1507,7 +1507,7 @@ SQL
try { try {
$api = new wfAPI( $apiKey, wfUtils::getWPVersion() ); $api = new wfAPI( $apiKey, wfUtils::getWPVersion() );
$res = $api->call( 'ping_api_key', array(), array() ); $res = $api->call( 'ping_api_key', array(), array() );
} catch ( Exception $e ) { } catch ( \Exception $e ) {
$result['error'] = 'Your options have been saved. However we noticed you do not change your API key and we tried to verify it with the Wordfence servers and received an error: ' . htmlentities( $e->getMessage() ); $result['error'] = 'Your options have been saved. However we noticed you do not change your API key and we tried to verify it with the Wordfence servers and received an error: ' . htmlentities( $e->getMessage() );
return $result; return $result;
@ -1548,9 +1548,9 @@ SQL
} elseif ( $res['err'] ) { } elseif ( $res['err'] ) {
return array( 'errorExport' => __( 'An error occurred: ', 'wordfence' ) . $res['err'] ); return array( 'errorExport' => __( 'An error occurred: ', 'wordfence' ) . $res['err'] );
} else { } else {
throw new Exception( __( 'Invalid response: ', 'wordfence' ) . var_export( $res, true ) ); throw new \Exception( __( 'Invalid response: ', 'wordfence' ) . var_export( $res, true ) );
} }
} catch ( Exception $e ) { } catch ( \Exception $e ) {
return array( 'errorExport' => __( 'An error occurred: ', 'wordfence' ) . $e->getMessage() ); return array( 'errorExport' => __( 'An error occurred: ', 'wordfence' ) . $e->getMessage() );
} }
} }
@ -1611,9 +1611,9 @@ SQL
} elseif ( $res['err'] ) { } elseif ( $res['err'] ) {
return array( 'errorImport' => 'An error occurred: ' . $res['err'] ); return array( 'errorImport' => 'An error occurred: ' . $res['err'] );
} else { } else {
throw new Exception( 'Invalid response: ' . var_export( $res, true ) ); throw new \Exception( 'Invalid response: ' . var_export( $res, true ) );
} }
} catch ( Exception $e ) { } catch ( \Exception $e ) {
return array( 'errorImport' => 'An error occurred: ' . $e->getMessage() ); return array( 'errorImport' => 'An error occurred: ' . $e->getMessage() );
} }
} }
@ -1891,11 +1891,11 @@ SQL
wfConfig::save( $changes ); wfConfig::save( $changes );
return array( 'success' => true ); return array( 'success' => true );
} catch ( wfWAFStorageFileException $e ) { } catch ( wfWAFStorageFile\Exception $e ) {
return array( return array(
'error' => __( 'An error occurred while saving the configuration.', 'wordfence' ), 'error' => __( 'An error occurred while saving the configuration.', 'wordfence' ),
); );
} catch ( Exception $e ) { } catch ( \Exception $e ) {
return array( return array(
'error' => $e->getMessage(), 'error' => $e->getMessage(),
); );
@ -1991,9 +1991,9 @@ SQL
// When downgrading we must disable all two factor authentication because it can lock an admin out if we don't. // When downgrading we must disable all two factor authentication because it can lock an admin out if we don't.
wfConfig::set_ser( 'twoFactorUsers', array() ); wfConfig::set_ser( 'twoFactorUsers', array() );
} else { } else {
throw new Exception( 'Could not understand the response we received from the Wordfence servers when applying for a free API key.' ); throw new \Exception( 'Could not understand the response we received from the Wordfence servers when applying for a free API key.' );
} }
} catch ( Exception $e ) { } catch ( \Exception $e ) {
$return['errorMsg'] = 'Could not fetch free API key from Wordfence: ' . htmlentities( $e->getMessage() ); $return['errorMsg'] = 'Could not fetch free API key from Wordfence: ' . htmlentities( $e->getMessage() );
return $return; return $return;

View file

@ -20,7 +20,7 @@ class MainWP_Child_WP_Rocket {
public static function instance() { public static function instance() {
if ( null === self::$instance ) { if ( null === self::$instance ) {
self::$instance = new MainWP_Child_WP_Rocket(); self::$instance = new self();
} }
return self::$instance; return self::$instance;
@ -128,7 +128,7 @@ class MainWP_Child_WP_Rocket {
try { try {
$data = array( 'rocket_boxes' => get_user_meta( $GLOBALS['current_user']->ID, 'rocket_boxes', true ) ); $data = array( 'rocket_boxes' => get_user_meta( $GLOBALS['current_user']->ID, 'rocket_boxes', true ) );
$information['syncWPRocketData'] = $data; $information['syncWPRocketData'] = $data;
} catch ( Exception $e ) { } catch ( \Exception $e ) {
// ok! // ok!
} }
} }
@ -271,7 +271,7 @@ class MainWP_Child_WP_Rocket {
$information = $this->do_admin_post_rocket_purge_opcache(); $information = $this->do_admin_post_rocket_purge_opcache();
break; break;
} }
} catch ( Exception $e ) { } catch ( \Exception $e ) {
$information = array( 'error' => $e->getMessage() ); $information = array( 'error' => $e->getMessage() );
} }
} }

View file

@ -9,7 +9,7 @@ class MainWP_Child_WPvivid_BackupRestore {
public $public_intetface; public $public_intetface;
static function instance() { static function instance() {
if ( null === self::$instance ) { if ( null === self::$instance ) {
self::$instance = new MainWP_Child_WPvivid_BackupRestore(); self::$instance = new self();
} }
return self::$instance; return self::$instance;
@ -43,7 +43,7 @@ class MainWP_Child_WPvivid_BackupRestore {
$information['syncWPvividScheduleData'] = $data['schedule']; $information['syncWPvividScheduleData'] = $data['schedule'];
$information['syncWPvividSetting'] = $data; $information['syncWPvividSetting'] = $data;
} }
} catch ( Exception $e ) { } catch ( \Exception $e ) {
} }
@ -124,7 +124,7 @@ class MainWP_Child_WPvivid_BackupRestore {
$information = $this->post_mainwp_data($_POST); $information = $this->post_mainwp_data($_POST);
break; break;
} }
} catch ( Exception $e ) { } catch ( \Exception $e ) {
$information = array( 'error' => $e->getMessage() ); $information = array( 'error' => $e->getMessage() );
} }

View file

@ -653,6 +653,12 @@ class MainWP_Child {
} }
} }
if ( ! $hide_restore ) {
if ( '' === session_id() ) {
session_start();
}
}
self::render_header( $shownPage, false ); self::render_header( $shownPage, false );
?> ?>
<?php if ( ! $hide_settings ) { ?> <?php if ( ! $hide_settings ) { ?>
@ -664,10 +670,6 @@ class MainWP_Child {
<?php if ( ! $hide_restore ) { ?> <?php if ( ! $hide_restore ) { ?>
<div class="mainwp-child-setting-tab restore-clone" <?php echo ( 'restore-clone' !== $shownPage ) ? $hide_style : ''; ?>> <div class="mainwp-child-setting-tab restore-clone" <?php echo ( 'restore-clone' !== $shownPage ) ? $hide_style : ''; ?>>
<?php <?php
if ( '' === session_id() ) {
session_start();
}
if ( isset( $_SESSION['file'] ) ) { if ( isset( $_SESSION['file'] ) ) {
MainWP_Clone::render_restore(); MainWP_Clone::render_restore();
} else { } else {
@ -1390,7 +1392,7 @@ class MainWP_Child {
// Handle fatal errors for those init if needed. // Handle fatal errors for those init if needed.
MainWP_Child_IThemes_Security::instance()->ithemes_init(); MainWP_Child_IThemes_Security::instance()->ithemes_init();
MainWP_Child_Updraft_Plus_Backups::instance()->updraftplus_init(); MainWP_Child_Updraft_Plus_Backups::instance()->updraftplus_init();
MainWP_Child_Back_Up_Wordpress::instance()->init(); MainWP_Child_Back_Up_WordPress::instance()->init();
MainWP_Child_WP_Rocket::instance()->init(); MainWP_Child_WP_Rocket::instance()->init();
MainWP_Child_Back_WP_Up::instance()->init(); MainWP_Child_Back_WP_Up::instance()->init();
MainWP_Child_Back_Up_Buddy::instance(); MainWP_Child_Back_Up_Buddy::instance();
@ -2668,7 +2670,7 @@ class MainWP_Child {
$user->description = trim( $data['description'] ); $user->description = trim( $data['description'] );
} }
$errors = new WP_Error(); $errors = new \WP_Error();
// checking that username has been typed. // checking that username has been typed.
if ( '' == $user->user_login ) { if ( '' == $user->user_login ) {
@ -3755,7 +3757,7 @@ class MainWP_Child {
try { try {
do_action( 'mainwp_child_site_stats' ); do_action( 'mainwp_child_site_stats' );
} catch ( Exception $e ) { } catch ( \Exception $e ) {
// ok. // ok.
} }
@ -3774,7 +3776,7 @@ class MainWP_Child {
try { try {
$information = apply_filters( 'mainwp-site-sync-others-data', $information, $othersData ); $information = apply_filters( 'mainwp-site-sync-others-data', $information, $othersData );
} catch ( Exception $e ) { } catch ( \Exception $e ) {
// ok! // ok!
} }
} }
@ -4245,7 +4247,7 @@ class MainWP_Child {
} }
MainWP_Helper::write( $information ); MainWP_Helper::write( $information );
} catch ( Exception $e ) { } catch ( \Exception $e ) {
$information['error'] = $e->getMessage(); $information['error'] = $e->getMessage();
MainWP_Helper::write( $information ); MainWP_Helper::write( $information );
} }
@ -4945,7 +4947,7 @@ class MainWP_Child {
} }
} }
return 0; return 0;
} catch ( Exception $e ) { } catch ( \Exception $e ) {
return 0; return 0;
} }
} }
@ -5347,7 +5349,7 @@ class MainWP_Child {
if ( null !== $upload ) { if ( null !== $upload ) {
$information['success'] = true; $information['success'] = true;
} }
} catch ( Exception $e ) { } catch ( \Exception $e ) {
$information['error'] = $e->getMessage(); $information['error'] = $e->getMessage();
} }
MainWP_Helper::write( $information ); MainWP_Helper::write( $information );
@ -5395,7 +5397,7 @@ class MainWP_Child {
$error = sprintf( __( 'PHP Version %s is unsupported.', 'mainwp-child' ), phpversion() ); $error = sprintf( __( 'PHP Version %s is unsupported.', 'mainwp-child' ), phpversion() );
MainWP_Helper::write( array( 'error' => $error ) ); MainWP_Helper::write( array( 'error' => $error ) );
} }
MainWP_Child_Back_Up_Wordpress::instance()->action(); MainWP_Child_Back_Up_WordPress::instance()->action();
} }
public function wp_rocket() { public function wp_rocket() {

View file

@ -8,7 +8,7 @@ class MainWP_Client_Report {
public static function instance() { public static function instance() {
if ( null === self::$instance ) { if ( null === self::$instance ) {
self::$instance = new MainWP_Client_Report(); self::$instance = new self();
} }
return self::$instance; return self::$instance;
@ -50,7 +50,7 @@ class MainWP_Client_Report {
MainWP_Child_Back_Up_Buddy::instance()->do_reports_log( $ext ); MainWP_Child_Back_Up_Buddy::instance()->do_reports_log( $ext );
break; break;
case 'backupwordpress': case 'backupwordpress':
MainWP_Child_Back_Up_Wordpress::instance()->do_reports_log( $ext ); MainWP_Child_Back_Up_WordPress::instance()->do_reports_log( $ext );
break; break;
case 'backwpup': case 'backwpup':
MainWP_Child_Back_WP_Up::instance()->do_reports_log( $ext ); MainWP_Child_Back_WP_Up::instance()->do_reports_log( $ext );

View file

@ -87,13 +87,13 @@ class MainWP_Clone_Install {
public function test_download() { public function test_download() {
if ( ! $this->file_exists( 'wp-content/' ) ) { if ( ! $this->file_exists( 'wp-content/' ) ) {
throw new Exception( __( 'This is not a full backup.', 'mainwp-child' ) ); throw new \Exception( __( 'This is not a full backup.', 'mainwp-child' ) );
} }
if ( ! $this->file_exists( 'wp-admin/' ) ) { if ( ! $this->file_exists( 'wp-admin/' ) ) {
throw new Exception( __( 'This is not a full backup.', 'mainwp-child' ) ); throw new \Exception( __( 'This is not a full backup.', 'mainwp-child' ) );
} }
if ( ! $this->file_exists( 'wp-content/dbBackup.sql' ) ) { if ( ! $this->file_exists( 'wp-content/dbBackup.sql' ) ) {
throw new Exception( __( 'Database backup is missing.', 'mainwp-child' ) ); throw new \Exception( __( 'Database backup is missing.', 'mainwp-child' ) );
} }
} }
@ -135,7 +135,7 @@ class MainWP_Clone_Install {
public function read_configuration_file() { public function read_configuration_file() {
$configContents = $this->get_config_contents(); $configContents = $this->get_config_contents();
if ( false === $configContents ) { if ( false === $configContents ) {
throw new Exception( __( 'Cant read configuration file from the backup.', 'mainwp-child' ) ); throw new \Exception( __( 'Cant read configuration file from the backup.', 'mainwp-child' ) );
} }
$this->config = maybe_unserialize( base64_decode( $configContents ) ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for benign reasons. $this->config = maybe_unserialize( base64_decode( $configContents ) ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for benign reasons.
@ -169,7 +169,7 @@ class MainWP_Clone_Install {
unlink( $file ); unlink( $file );
} }
} }
} catch ( Exception $e ) { } catch ( \Exception $e ) {
// ok! // ok!
} }
} }
@ -241,7 +241,7 @@ class MainWP_Clone_Install {
} }
if ( ! feof( $handle ) ) { if ( ! feof( $handle ) ) {
throw new Exception( __( 'Error: unexpected end of file for database.', 'mainwp-child' ) ); throw new \Exception( __( 'Error: unexpected end of file for database.', 'mainwp-child' ) );
} }
fclose( $handle ); fclose( $handle );
} }
@ -438,7 +438,7 @@ class MainWP_Clone_Install {
return false; return false;
} }
if ( PCLZIP_ERR_NO_ERROR !== $zip->error_code ) { if ( PCLZIP_ERR_NO_ERROR !== $zip->error_code ) {
throw new Exception( $zip->errorInfo( true ) ); throw new \Exception( $zip->errorInfo( true ) );
} }
return true; return true;
@ -650,7 +650,7 @@ class MainWP_Clone_Install {
if ( $serialised ) { if ( $serialised ) {
return serialize( $data ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions. return serialize( $data ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.
} }
} catch ( Exception $error ) { } catch ( \Exception $error ) {
// ok! // ok!
} }

View file

@ -20,7 +20,7 @@ class MainWP_Clone {
public static function get() { public static function get() {
if ( null === self::$instance ) { if ( null === self::$instance ) {
self::$instance = new MainWP_Clone(); self::$instance = new self();
} }
return self::$instance; return self::$instance;
@ -1141,7 +1141,7 @@ class MainWP_Clone {
$this->secure_request( 'mainwp-child_clone_backupcreate' ); $this->secure_request( 'mainwp-child_clone_backupcreate' );
if ( ! isset( $_POST['siteId'] ) ) { if ( ! isset( $_POST['siteId'] ) ) {
throw new Exception( __( 'No site given', 'mainwp-child' ) ); throw new \Exception( __( 'No site given', 'mainwp-child' ) );
} }
$siteId = $_POST['siteId']; $siteId = $_POST['siteId'];
@ -1149,7 +1149,7 @@ class MainWP_Clone {
$sitesToClone = get_option( 'mainwp_child_clone_sites' ); $sitesToClone = get_option( 'mainwp_child_clone_sites' );
if ( ! is_array( $sitesToClone ) || ! isset( $sitesToClone[ $siteId ] ) ) { if ( ! is_array( $sitesToClone ) || ! isset( $sitesToClone[ $siteId ] ) ) {
throw new Exception( __( 'Site not found', 'mainwp-child' ) ); throw new \Exception( __( 'Site not found', 'mainwp-child' ) );
} }
$siteToClone = $sitesToClone[ $siteId ]; $siteToClone = $sitesToClone[ $siteId ];
@ -1173,7 +1173,7 @@ class MainWP_Clone {
); );
if ( ! $result['backup'] ) { if ( ! $result['backup'] ) {
throw new Exception( __( 'Could not create backupfile on child', 'mainwp-child' ) ); throw new \Exception( __( 'Could not create backupfile on child', 'mainwp-child' ) );
} }
session_start(); session_start();
@ -1184,7 +1184,7 @@ class MainWP_Clone {
'url' => $result['backup'], 'url' => $result['backup'],
'size' => round( $result['size'] / 1024, 0 ), 'size' => round( $result['size'] / 1024, 0 ),
); );
} catch ( Exception $e ) { } catch ( \Exception $e ) {
$output = array( 'error' => $e->getMessage() ); $output = array( 'error' => $e->getMessage() );
} }
@ -1196,14 +1196,14 @@ class MainWP_Clone {
$this->secure_request( 'mainwp-child_clone_backupcreatepoll' ); $this->secure_request( 'mainwp-child_clone_backupcreatepoll' );
if ( ! isset( $_POST['siteId'] ) ) { if ( ! isset( $_POST['siteId'] ) ) {
throw new Exception( __( 'No site given', 'mainwp-child' ) ); throw new \Exception( __( 'No site given', 'mainwp-child' ) );
} }
$siteId = $_POST['siteId']; $siteId = $_POST['siteId'];
$rand = $_POST['rand']; $rand = $_POST['rand'];
$sitesToClone = get_option( 'mainwp_child_clone_sites' ); $sitesToClone = get_option( 'mainwp_child_clone_sites' );
if ( ! is_array( $sitesToClone ) || ! isset( $sitesToClone[ $siteId ] ) ) { if ( ! is_array( $sitesToClone ) || ! isset( $sitesToClone[ $siteId ] ) ) {
throw new Exception( __( 'Site not found', 'mainwp-child' ) ); throw new \Exception( __( 'Site not found', 'mainwp-child' ) );
} }
$siteToClone = $sitesToClone[ $siteId ]; $siteToClone = $sitesToClone[ $siteId ];
@ -1224,11 +1224,11 @@ class MainWP_Clone {
); );
if ( ! isset( $result['size'] ) ) { if ( ! isset( $result['size'] ) ) {
throw new Exception( __( 'Invalid response', 'mainwp-child' ) ); throw new \Exception( __( 'Invalid response', 'mainwp-child' ) );
} }
$output = array( 'size' => round( $result['size'] / 1024, 0 ) ); $output = array( 'size' => round( $result['size'] / 1024, 0 ) );
} catch ( Exception $e ) { } catch ( \Exception $e ) {
$output = array( 'error' => $e->getMessage() ); $output = array( 'error' => $e->getMessage() );
} }
die( json_encode( $output ) ); die( json_encode( $output ) );
@ -1239,7 +1239,7 @@ class MainWP_Clone {
$this->secure_request( 'mainwp-child_clone_backupdownload' ); $this->secure_request( 'mainwp-child_clone_backupdownload' );
if ( ! isset( $_POST['file'] ) ) { if ( ! isset( $_POST['file'] ) ) {
throw new Exception( __( 'No download link given', 'mainwp-child' ) ); throw new \Exception( __( 'No download link given', 'mainwp-child' ) );
} }
$file = $_POST['file']; $file = $_POST['file'];
@ -1248,7 +1248,7 @@ class MainWP_Clone {
$sitesToClone = get_option( 'mainwp_child_clone_sites' ); $sitesToClone = get_option( 'mainwp_child_clone_sites' );
if ( ! is_array( $sitesToClone ) || ! isset( $sitesToClone[ $siteId ] ) ) { if ( ! is_array( $sitesToClone ) || ! isset( $sitesToClone[ $siteId ] ) ) {
throw new Exception( __( 'Site not found', 'mainwp-child' ) ); throw new \Exception( __( 'Site not found', 'mainwp-child' ) );
} }
$siteToClone = $sitesToClone[ $siteId ]; $siteToClone = $sitesToClone[ $siteId ];
@ -1297,7 +1297,7 @@ class MainWP_Clone {
if ( 200 !== (int) wp_remote_retrieve_response_code( $response ) ) { if ( 200 !== (int) wp_remote_retrieve_response_code( $response ) ) {
unlink( $filename ); unlink( $filename );
return new WP_Error( 'http_404', trim( wp_remote_retrieve_response_message( $response ) ) ); return new \WP_Error( 'http_404', trim( wp_remote_retrieve_response_message( $response ) ) );
} }
$output = array( 'done' => $filename ); $output = array( 'done' => $filename );
@ -1321,10 +1321,10 @@ class MainWP_Clone {
); );
} }
} }
} catch ( Exception $e ) { } catch ( \Exception $e ) {
throw $e; throw $e;
} }
} catch ( Exception $e ) { } catch ( \Exception $e ) {
$output = array( 'error' => $e->getMessage() ); $output = array( 'error' => $e->getMessage() );
} }
@ -1349,10 +1349,10 @@ class MainWP_Clone {
} }
} }
if ( false === $archiveFile ) { if ( false === $archiveFile ) {
throw new Exception( __( 'No download file found', 'mainwp-child' ) ); throw new \Exception( __( 'No download file found', 'mainwp-child' ) );
} }
$output = array( 'size' => filesize( $archiveFile ) / 1024 ); $output = array( 'size' => filesize( $archiveFile ) / 1024 );
} catch ( Exception $e ) { } catch ( \Exception $e ) {
$output = array( 'error' => $e->getMessage() ); $output = array( 'error' => $e->getMessage() );
} }
die( json_encode( $output ) ); die( json_encode( $output ) );
@ -1379,7 +1379,7 @@ class MainWP_Clone {
} }
} }
if ( false === $archiveFile ) { if ( false === $archiveFile ) {
throw new Exception( __( 'No download file found', 'mainwp-child' ) ); throw new \Exception( __( 'No download file found', 'mainwp-child' ) );
} }
$file = $archiveFile; $file = $archiveFile;
} elseif ( file_exists( $file ) ) { } elseif ( file_exists( $file ) ) {
@ -1387,7 +1387,7 @@ class MainWP_Clone {
} else { } else {
$file = ABSPATH . $file; $file = ABSPATH . $file;
if ( ! file_exists( $file ) ) { if ( ! file_exists( $file ) ) {
throw new Exception( __( 'Backup file not found', 'mainwp-child' ) ); throw new \Exception( __( 'Backup file not found', 'mainwp-child' ) );
} }
$testFull = true; $testFull = true;
} }
@ -1481,7 +1481,7 @@ class MainWP_Clone {
$output = array( 'result' => 'ok' ); $output = array( 'result' => 'ok' );
wp_logout(); wp_logout();
wp_set_current_user( 0 ); wp_set_current_user( 0 );
} catch ( Exception $e ) { } catch ( \Exception $e ) {
$output = array( 'error' => $e->getMessage() ); $output = array( 'error' => $e->getMessage() );
} }
die( json_encode( $output ) ); die( json_encode( $output ) );

View file

@ -9,7 +9,7 @@ class MainWP_Custom_Post_Type {
public static function instance() { public static function instance() {
if ( null == self::$instance ) { if ( null == self::$instance ) {
self::$instance = new MainWP_Custom_Post_Type(); self::$instance = new self();
} }
return self::$instance; return self::$instance;
@ -124,7 +124,7 @@ class MainWP_Custom_Post_Type {
if ( 'http:' !== $lnkToReplace && 'https:' !== $lnkToReplace ) { if ( 'http:' !== $lnkToReplace && 'https:' !== $lnkToReplace ) {
$post_content = str_replace( $lnkToReplace, $linkToReplaceWith, $post_content ); $post_content = str_replace( $lnkToReplace, $linkToReplaceWith, $post_content );
} }
} catch ( Exception $e ) { } catch ( \Exception $e ) {
// ok! // ok!
} }
} }
@ -238,7 +238,7 @@ class MainWP_Custom_Post_Type {
} else { } else {
return array( 'error' => __( 'Cannot add product image', $this->plugin_translate ) ); return array( 'error' => __( 'Cannot add product image', $this->plugin_translate ) );
} }
} catch ( Exception $e ) { } catch ( \Exception $e ) {
continue; continue;
} }
} }
@ -259,7 +259,7 @@ class MainWP_Custom_Post_Type {
} else { } else {
return array( 'error' => __( 'Cannot add featured image', $this->plugin_translate ) ); return array( 'error' => __( 'Cannot add featured image', $this->plugin_translate ) );
} }
} catch ( Exception $e ) { } catch ( \Exception $e ) {
continue; continue;
} }
} else { } else {

View file

@ -213,7 +213,7 @@ class MainWP_Helper {
remove_filter( 'http_request_args', array( $mainWPChild, 'http_request_reject_unsafe_urls' ), 99, 2 ); remove_filter( 'http_request_args', array( $mainWPChild, 'http_request_reject_unsafe_urls' ), 99, 2 );
if ( is_wp_error( $temporary_file ) ) { if ( is_wp_error( $temporary_file ) ) {
throw new Exception( 'Error: ' . $temporary_file->get_error_message() ); throw new \Exception( 'Error: ' . $temporary_file->get_error_message() );
} else { } else {
$filename = basename( $img_url ); $filename = basename( $img_url );
$local_img_path = $upload_dir['path'] . DIRECTORY_SEPARATOR . $filename; $local_img_path = $upload_dir['path'] . DIRECTORY_SEPARATOR . $filename;
@ -337,12 +337,12 @@ class MainWP_Helper {
if ( is_wp_error( $response ) ) { if ( is_wp_error( $response ) ) {
unlink( $full_file_name ); unlink( $full_file_name );
throw new Exception( 'Error: ' . $response->get_error_message() ); throw new \Exception( 'Error: ' . $response->get_error_message() );
} }
if ( 200 !== (int) wp_remote_retrieve_response_code( $response ) ) { if ( 200 !== (int) wp_remote_retrieve_response_code( $response ) ) {
unlink( $full_file_name ); unlink( $full_file_name );
throw new Exception( 'Error 404: ' . trim( wp_remote_retrieve_response_message( $response ) ) ); throw new \Exception( 'Error 404: ' . trim( wp_remote_retrieve_response_message( $response ) ) );
} }
if ( '.phpfile.txt' === substr( $file_name, - 12 ) ) { if ( '.phpfile.txt' === substr( $file_name, - 12 ) ) {
$new_file_name = substr( $file_name, 0, - 12 ) . '.php'; $new_file_name = substr( $file_name, 0, - 12 ) . '.php';
@ -352,7 +352,7 @@ class MainWP_Helper {
return array( 'path' => $new_file_name ); return array( 'path' => $new_file_name );
} else { } else {
unlink( $full_file_name ); unlink( $full_file_name );
throw new Exception( 'Error: Copy file.' ); throw new \Exception( 'Error: Copy file.' );
} }
} }
@ -503,7 +503,7 @@ class MainWP_Helper {
if ( 'http:' !== $lnkToReplace && 'https:' !== $lnkToReplace ) { if ( 'http:' !== $lnkToReplace && 'https:' !== $lnkToReplace ) {
$new_post['post_content'] = str_replace( $lnkToReplace, $linkToReplaceWith, $new_post['post_content'] ); $new_post['post_content'] = str_replace( $lnkToReplace, $linkToReplaceWith, $new_post['post_content'] );
} }
} catch ( Exception $e ) { } catch ( \Exception $e ) {
error_log( $e->getMessage() ); error_log( $e->getMessage() );
} }
} }
@ -522,7 +522,7 @@ class MainWP_Helper {
if ( null !== $upload ) { if ( null !== $upload ) {
$replaceAttachedIds[ $gallery['id'] ] = $upload['id']; $replaceAttachedIds[ $gallery['id'] ] = $upload['id'];
} }
} catch ( Exception $e ) { } catch ( \Exception $e ) {
// ok! // ok!
} }
} }
@ -720,7 +720,7 @@ class MainWP_Helper {
if ( null !== $upload ) { if ( null !== $upload ) {
update_post_meta( $new_post_id, WPSEO_Meta::$meta_prefix . 'opengraph-image', $upload['url'] ); // Add the image to the post! update_post_meta( $new_post_id, WPSEO_Meta::$meta_prefix . 'opengraph-image', $upload['url'] ); // Add the image to the post!
} }
} catch ( Exception $e ) { } catch ( \Exception $e ) {
// ok! // ok!
} }
} }
@ -769,7 +769,7 @@ class MainWP_Helper {
); );
} }
} }
} catch ( Exception $e ) { } catch ( \Exception $e ) {
// ok! // ok!
} }
} }
@ -901,7 +901,7 @@ class MainWP_Helper {
if ( $dieOnError ) { if ( $dieOnError ) {
self::error( $error ); self::error( $error );
} else { } else {
throw new Exception( $error ); throw new \Exception( $error );
} }
} }
} }
@ -915,7 +915,7 @@ class MainWP_Helper {
global $wp_filesystem; global $wp_filesystem;
try { try {
self::check_dir( $dir, false ); self::check_dir( $dir, false );
} catch ( Exception $e ) { } catch ( \Exception $e ) {
// ok! // ok!
} }
if ( ! empty( $wp_filesystem ) ) { if ( ! empty( $wp_filesystem ) ) {
@ -1049,10 +1049,10 @@ class MainWP_Helper {
} }
return self::m_fetch_url( $tmpUrl . 'wp-admin/', $postdata ); return self::m_fetch_url( $tmpUrl . 'wp-admin/', $postdata );
} catch ( Exception $e ) { } catch ( \Exception $e ) {
try { try {
return self::m_fetch_url( $url, $postdata ); return self::m_fetch_url( $url, $postdata );
} catch ( Exception $ex ) { } catch ( \Exception $ex ) {
throw $e; throw $e;
} }
} }
@ -1080,7 +1080,7 @@ class MainWP_Helper {
curl_close( $ch ); curl_close( $ch );
if ( ( false === $data ) && ( 0 === $http_status ) ) { if ( ( false === $data ) && ( 0 === $http_status ) ) {
throw new Exception( 'Http Error: ' . $err ); throw new \Exception( 'Http Error: ' . $err );
} elseif ( preg_match( '/<mainwp>(.*)<\/mainwp>/', $data, $results ) > 0 ) { } elseif ( preg_match( '/<mainwp>(.*)<\/mainwp>/', $data, $results ) > 0 ) {
$result = $results[1]; $result = $results[1];
$result_base = base64_decode( $result ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for benign reasons. $result_base = base64_decode( $result ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for benign reasons.
@ -1089,9 +1089,9 @@ class MainWP_Helper {
return $information; return $information;
} elseif ( '' === $data ) { } elseif ( '' === $data ) {
throw new Exception( __( 'Something went wrong while contacting the child site. Please check if there is an error on the child site. This error could also be caused by trying to clone or restore a site to large for your server settings.', 'mainwp-child' ) ); throw new \Exception( __( 'Something went wrong while contacting the child site. Please check if there is an error on the child site. This error could also be caused by trying to clone or restore a site to large for your server settings.', 'mainwp-child' ) );
} else { } else {
throw new Exception( __( 'Child plugin is disabled or the security key is incorrect. Please resync with your main installation.', 'mainwp-child' ) ); throw new \Exception( __( 'Child plugin is disabled or the security key is incorrect. Please resync with your main installation.', 'mainwp-child' ) );
} }
} }
@ -1266,7 +1266,7 @@ class MainWP_Helper {
if ( $autoload != $wpdb->get_var( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name = %s", $option_name ) ) ) { if ( $autoload != $wpdb->get_var( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name = %s", $option_name ) ) ) {
$option_value = get_option( $option_name ); $option_value = get_option( $option_name );
delete_option( $option_name ); delete_option( $option_name );
add_option( $option_name, $option_value, null, $autoload ); add_option( $option_name, $option_value, '', $autoload );
} }
} }
@ -1472,7 +1472,7 @@ class MainWP_Helper {
// Remove anything which isn't a word, whitespace, number or any of the following caracters -_~,;:[](). // Remove anything which isn't a word, whitespace, number or any of the following caracters -_~,;:[]().
// If you don't need to handle multi-byte characters you can use preg_replace rather than mb_ereg_replace. // If you don't need to handle multi-byte characters you can use preg_replace rather than mb_ereg_replace.
// Thanks @Łukasz Rysiak! // Thanks @Å?ukasz Rysiak!
$filename = mb_ereg_replace( '([^\w\s\d\-_~,;:\[\]\(\).])', '', $filename ); $filename = mb_ereg_replace( '([^\w\s\d\-_~,;:\[\]\(\).])', '', $filename );
// Remove any runs of periods (thanks falstro!). // Remove any runs of periods (thanks falstro!).
$filename = mb_ereg_replace( '([\.]{2,})', '', $filename ); $filename = mb_ereg_replace( '([\.]{2,})', '', $filename );
@ -1583,7 +1583,7 @@ class MainWP_Helper {
if ( $return ) { if ( $return ) {
return $message; return $message;
} else { } else {
throw new Exception( $message ); throw new \Exception( $message );
} }
} }
return true; return true;
@ -1608,7 +1608,7 @@ class MainWP_Helper {
if ( $return ) { if ( $return ) {
return $message; return $message;
} else { } else {
throw new Exception( $message ); throw new \Exception( $message );
} }
} }
return true; return true;
@ -1634,7 +1634,7 @@ class MainWP_Helper {
if ( $return ) { if ( $return ) {
return $message; return $message;
} else { } else {
throw new Exception( $message ); throw new \Exception( $message );
} }
} }
@ -1660,7 +1660,7 @@ class MainWP_Helper {
if ( $return ) { if ( $return ) {
return $message; return $message;
} else { } else {
throw new Exception( $message ); throw new \Exception( $message );
} }
} }
@ -1686,7 +1686,7 @@ class MainWP_Helper {
if ( $return ) { if ( $return ) {
return $message; return $message;
} else { } else {
throw new Exception( $message ); throw new \Exception( $message );
} }
} }

View file

@ -16,7 +16,7 @@ class MainWP_Keyword_Links {
static function instance() { static function instance() {
if ( null === self::$instance ) { if ( null === self::$instance ) {
self::$instance = new MainWP_Keyword_Links(); self::$instance = new self();
} }
return self::$instance; return self::$instance;

View file

@ -19,7 +19,7 @@ class MainWP_Wordpress_SEO {
public static function instance() { public static function instance() {
if ( null === self::$instance ) { if ( null === self::$instance ) {
self::$instance = new MainWP_Wordpress_SEO(); self::$instance = new self();
} }
return self::$instance; return self::$instance;
@ -62,15 +62,15 @@ class MainWP_Wordpress_SEO {
$temporary_file = download_url( $file_url ); $temporary_file = download_url( $file_url );
remove_filter( 'http_request_args', array( $mainWPChild, 'http_request_reject_unsafe_urls' ), 99, 2 ); remove_filter( 'http_request_args', array( $mainWPChild, 'http_request_reject_unsafe_urls' ), 99, 2 );
if ( is_wp_error( $temporary_file ) ) { if ( is_wp_error( $temporary_file ) ) {
throw new Exception( 'Error: ' . $temporary_file->get_error_message() ); throw new \Exception( 'Error: ' . $temporary_file->get_error_message() );
} else { } else {
if ( $this->import_seo_settings( $temporary_file ) ) { if ( $this->import_seo_settings( $temporary_file ) ) {
$information['success'] = true; $information['success'] = true;
} else { } else {
throw new Exception( __( 'Settings could not be imported.', 'mainwp-child' ) ); throw new \Exception( __( 'Settings could not be imported.', 'mainwp-child' ) );
} }
} }
} catch ( Exception $e ) { } catch ( \Exception $e ) {
$information['error'] = $e->getMessage(); $information['error'] = $e->getMessage();
} }
@ -99,9 +99,9 @@ class MainWP_Wordpress_SEO {
$information['success'] = true; $information['success'] = true;
} else { } else {
throw new Exception( __( 'Settings could not be imported:', 'mainwp-child' ) ); throw new \Exception( __( 'Settings could not be imported:', 'mainwp-child' ) );
} }
} catch ( Exception $e ) { } catch ( \Exception $e ) {
$information['error'] = $e->getMessage(); $information['error'] = $e->getMessage();
} }
} }
@ -145,21 +145,21 @@ class MainWP_Wordpress_SEO {
return true; return true;
} else { } else {
throw new Exception( __( 'Settings could not be imported:', 'mainwp-child' ) ); throw new \Exception( __( 'Settings could not be imported:', 'mainwp-child' ) );
} }
unset( $options, $name, $optgroup ); unset( $options, $name, $optgroup );
} else { } else {
throw new Exception( __( 'Settings could not be imported:', 'mainwp-child' ) ); throw new \Exception( __( 'Settings could not be imported:', 'mainwp-child' ) );
} }
unlink( $filename ); unlink( $filename );
unlink( $p_path ); unlink( $p_path );
} else { } else {
throw new Exception( __( 'Settings could not be imported:', 'mainwp-child' ) . ' ' . sprintf( __( 'Unzipping failed with error "%s".', 'mainwp-child' ), $unzipped->get_error_message() ) ); throw new \Exception( __( 'Settings could not be imported:', 'mainwp-child' ) . ' ' . sprintf( __( 'Unzipping failed with error "%s".', 'mainwp-child' ), $unzipped->get_error_message() ) );
} }
unset( $zip, $unzipped ); unset( $zip, $unzipped );
unlink( $file ); unlink( $file );
} else { } else {
throw new Exception( __( 'Settings could not be imported:', 'mainwp-child' ) . ' ' . __( 'Upload failed.', 'mainwp-child' ) ); throw new \Exception( __( 'Settings could not be imported:', 'mainwp-child' ) . ' ' . __( 'Upload failed.', 'mainwp-child' ) );
} }
return false; return false;

View file

@ -282,10 +282,6 @@ class Tar_Archiver {
$iterator = new RecursiveIteratorIterator( new RecursiveDirectoryIterator( $path ), RecursiveIteratorIterator::SELF_FIRST, RecursiveIteratorIterator::CATCH_GET_CHILD ); $iterator = new RecursiveIteratorIterator( new RecursiveDirectoryIterator( $path ), RecursiveIteratorIterator::SELF_FIRST, RecursiveIteratorIterator::CATCH_GET_CHILD );
if ( class_exists( 'ExampleSortedIterator' ) ) {
$iterator = new ExampleSortedIterator( $iterator );
}
/** @var $path DirectoryIterator */ /** @var $path DirectoryIterator */
foreach ( $iterator as $path ) { foreach ( $iterator as $path ) {
$name = $path->__toString(); $name = $path->__toString();
@ -321,15 +317,15 @@ class Tar_Archiver {
if ( 'tar.gz' == $this->type ) { if ( 'tar.gz' == $this->type ) {
if ( false === gzwrite( $this->archive, $data, strlen( $data ) ) ) { if ( false === gzwrite( $this->archive, $data, strlen( $data ) ) ) {
throw new Exception( 'Could not write to archive' ); throw new \Exception( 'Could not write to archive' );
} }
} elseif ( 'tar.bz2' == $this->type ) { } elseif ( 'tar.bz2' == $this->type ) {
if ( false === bzwrite( $this->archive, $data, strlen( $data ) ) ) { if ( false === bzwrite( $this->archive, $data, strlen( $data ) ) ) {
throw new Exception( 'Could not write to archive' ); throw new \Exception( 'Could not write to archive' );
} }
} else { } else {
if ( false === fwrite( $this->archive, $data, strlen( $data ) ) ) { if ( false === fwrite( $this->archive, $data, strlen( $data ) ) ) {
throw new Exception( 'Could not write to archive' ); throw new \Exception( 'Could not write to archive' );
} }
fflush( $this->archive ); fflush( $this->archive );
} }
@ -345,16 +341,16 @@ class Tar_Archiver {
$this->log( 'writing & flushing ' . $len ); $this->log( 'writing & flushing ' . $len );
$this->chunk = gzencode( $this->chunk ); $this->chunk = gzencode( $this->chunk );
if ( false === fwrite( $this->archive, $this->chunk, strlen( $this->chunk ) ) ) { if ( false === fwrite( $this->archive, $this->chunk, strlen( $this->chunk ) ) ) {
throw new Exception( 'Could not write to archive' ); throw new \Exception( 'Could not write to archive' );
} }
fflush( $this->archive ); fflush( $this->archive );
} elseif ( 'tar.bz2' == $this->type ) { } elseif ( 'tar.bz2' == $this->type ) {
if ( false === bzwrite( $this->archive, $this->chunk, strlen( $len ) ) ) { if ( false === bzwrite( $this->archive, $this->chunk, strlen( $len ) ) ) {
throw new Exception( 'Could not write to archive' ); throw new \Exception( 'Could not write to archive' );
} }
} else { } else {
if ( false === fwrite( $this->archive, $len, strlen( $len ) ) ) { if ( false === fwrite( $this->archive, $len, strlen( $len ) ) ) {
throw new Exception( 'Could not write to archive' ); throw new \Exception( 'Could not write to archive' );
} }
fflush( $this->archive ); fflush( $this->archive );
} }
@ -751,7 +747,7 @@ class Tar_Archiver {
* @param $entryName * @param $entryName
* *
* @return array|bool * @return array|bool
* @throws Exception * @throws \Exception
*/ */
private function is_next_file( $entryName ) { private function is_next_file( $entryName ) {
$currentOffset = ftell( $this->archive ); $currentOffset = ftell( $this->archive );
@ -764,7 +760,7 @@ class Tar_Archiver {
} }
if ( 512 != strlen( $block ) ) { if ( 512 != strlen( $block ) ) {
throw new Exception( 'Invalid block found' ); throw new \Exception( 'Invalid block found' );
} }
$temp = unpack( 'a100name/a8mode/a8uid/a8gid/a12size/a12mtime/a8checksum/a1type/a100symlink/a6magic/a2temp/a32temp/a32temp/a8temp/a8temp/a155prefix/a12temp', $block ); $temp = unpack( 'a100name/a8mode/a8uid/a8gid/a12size/a12mtime/a8checksum/a1type/a100symlink/a6magic/a2temp/a32temp/a32temp/a8temp/a8temp/a155prefix/a12temp', $block );
@ -795,7 +791,7 @@ class Tar_Archiver {
return true; return true;
} else { } else {
throw new Exception( 'Unexpected directory [' . $file['name'] . ']' ); throw new \Exception( 'Unexpected directory [' . $file['name'] . ']' );
} }
} elseif ( 0 == $file['type'] ) { } elseif ( 0 == $file['type'] ) {
if ( 0 == strcmp( trim( $file['name'] ), trim( $entryName ) ) ) { if ( 0 == strcmp( trim( $file['name'] ), trim( $entryName ) ) ) {
@ -850,13 +846,13 @@ class Tar_Archiver {
return true; return true;
} else { } else {
$this->log( 'Unexpected file [' . $file['name'] . ']' ); $this->log( 'Unexpected file [' . $file['name'] . ']' );
throw new Exception( 'Unexpected file' ); throw new \Exception( 'Unexpected file' );
} }
} }
$this->log( 'ERROR' ); $this->log( 'ERROR' );
throw new Exception( 'Should never get here?' ); throw new \Exception( 'Should never get here?' );
} catch ( Exception $e ) { } catch ( \Exception $e ) {
$this->log( $e->getMessage() ); $this->log( $e->getMessage() );
throw $e; throw $e;
} }
@ -930,7 +926,7 @@ class Tar_Archiver {
} }
if ( ! $this->is_valid_block( substr( $read, 10, $pos - 10 ) ) ) { if ( ! $this->is_valid_block( substr( $read, 10, $pos - 10 ) ) ) {
throw new Exception( 'invalid!' ); throw new \Exception( 'invalid!' );
} }
$lastCorrect += $pos; $lastCorrect += $pos;
@ -939,11 +935,11 @@ class Tar_Archiver {
} }
if ( ! $this->is_valid_block( substr( $read, 10 ) ) ) { if ( ! $this->is_valid_block( substr( $read, 10 ) ) ) {
throw new Exception( 'invalid!' ); throw new \Exception( 'invalid!' );
} }
fclose( $fh ); fclose( $fh );
} catch ( Exception $e ) { } catch ( \Exception $e ) {
fclose( $fh ); fclose( $fh );
$fh = fopen( $filepath, 'ab+' ); $fh = fopen( $filepath, 'ab+' );
fseek( $fh, $lastCorrect ); fseek( $fh, $lastCorrect );
@ -1242,43 +1238,3 @@ class Tar_Archiver {
return $crcFound == $crc; return $crcFound == $crc;
} }
} }
if ( class_exists( 'SplHeap' ) ) {
class ExampleSortedIterator extends SplHeap {
public function __construct( Iterator $iterator ) {
foreach ( $iterator as $item ) {
$this->insert( $item );
}
}
public function compare( $b, $a ) {
$pathA = $a->__toString();
$pathB = $b->__toString();
$dirnameA = ( is_file( $pathA ) ? dirname( $pathA ) : $pathA );
$dirnameB = ( is_file( $pathB ) ? dirname( $pathB ) : $pathB );
if ( dirname( $pathA ) == dirname( $pathB ) ) {
if ( is_file( $pathA ) && ! is_file( $pathB ) ) {
return - 1;
} elseif ( ! is_file( $pathA ) && is_file( $pathB ) ) {
return 1;
}
return strcmp( $pathA, $pathB );
} elseif ( $dirnameA == $dirnameB ) {
return strcmp( $pathA, $pathB );
} elseif ( MainWP_Helper::starts_with( $dirnameA, $dirnameB ) ) {
return 1;
} elseif ( MainWP_Helper::starts_with( $dirnameB, $dirnameA ) ) {
return - 1;
} else {
$cmp = strcmp( $dirnameA, $dirnameB );
if ( 0 == $cmp ) {
return strcmp( $pathA, $pathB );
}
return $cmp;
}
}
}
}