Merge remote-tracking branch 'remotes/origin/bogdan01' into thang

This commit is contained in:
thanghv 2020-03-27 19:56:41 +07:00
commit 8474ecc2a3
43 changed files with 6996 additions and 6465 deletions

3
.gitattributes vendored
View file

@ -4,9 +4,8 @@ bin export-ignore
composer.* export-ignore
tests export-ignore
.gitattributes export-ignore
.phpcs.xml.dist export-ignore
phpcs.xml export-ignore
.travis.yml export-ignore
LICENSE.md export-ignore
LICENSE.txt export-ignore
README.md export-ignore
phpunit.xml.dist export-ignore

View file

@ -1,49 +0,0 @@
<?xml version="1.0"?>
<ruleset name="WordPress Coding Standards based custom ruleset for your plugin">
<description>Generally-applicable sniffs for WordPress plugins.</description>
<!-- What to scan -->
<file>.</file>
<exclude-pattern>/vendor/</exclude-pattern>
<exclude-pattern>/node_modules/</exclude-pattern>
<!-- How to scan -->
<!-- Usage instructions: https://github.com/squizlabs/PHP_CodeSniffer/wiki/Usage -->
<!-- Annotated ruleset: https://github.com/squizlabs/PHP_CodeSniffer/wiki/Annotated-ruleset.xml -->
<arg value="sp"/> <!-- Show sniff and progress -->
<arg name="basepath" value="./"/><!-- Strip the file paths down to the relevant bit -->
<arg name="colors"/>
<arg name="extensions" value="php"/>
<arg name="parallel" value="8"/><!-- Enables parallel processing when available for faster results. -->
<!-- Rules: Check PHP version compatibility -->
<!-- https://github.com/PHPCompatibility/PHPCompatibility#sniffing-your-code-for-compatibility-with-specific-php-versions -->
<config name="testVersion" value="5.3-"/>
<!-- https://github.com/PHPCompatibility/PHPCompatibilityWP -->
<rule ref="PHPCompatibilityWP"/>
<!-- Rules: WordPress Coding Standards -->
<!-- https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards -->
<!-- https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/wiki/Customizable-sniff-properties -->
<config name="minimum_supported_wp_version" value="4.6"/>
<rule ref="WordPress">
<exclude name="WordPress.VIP"/>
</rule>
<rule ref="WordPress.NamingConventions.PrefixAllGlobals">
<properties>
<!-- Value: replace the function, class, and variable prefixes used. Separate multiple prefixes with a comma. -->
<property name="prefixes" type="array" value="my-plugin"/>
</properties>
</rule>
<rule ref="WordPress.WP.I18n">
<properties>
<!-- Value: replace the text domain used. -->
<property name="text_domain" type="array" value="my-plugin"/>
</properties>
</rule>
<rule ref="WordPress.WhiteSpace.ControlStructureSpacing">
<properties>
<property name="blank_line_check" value="true"/>
</properties>
</rule>
</ruleset>

View file

@ -1,5 +1,5 @@
sudo: false
dist: trusty
dist: xenial
language: php
@ -19,7 +19,7 @@ cache:
matrix:
include:
- php: 7.4
env: WP_VERSION=latest
env: WP_TRAVISCI=phpcs WP_VERSION=latest
- php: 7.3
env: WP_VERSION=latest
- php: 7.2
@ -28,12 +28,7 @@ matrix:
env: WP_VERSION=latest
- php: 7.0
env: WP_VERSION=latest
- php: 5.6
env: WP_VERSION=latest
- php: 5.6
env: WP_VERSION=trunk
dist: precise
before_script:
- export PATH="$HOME/.composer/vendor/bin:$PATH"
- |

View file

@ -6,7 +6,6 @@
<a href="https://packagist.org/packages/mainwp/mainwp-child"><img src="https://poser.pugx.org/mainwp/mainwp-child/v/stable" alt="Latest Stable Version"></a>
<img alt="WordPress Plugin Active Installs" src="https://img.shields.io/wordpress/plugin/installs/mainwp-child?label=MainWP%20Child%20Active%20Installs">
<img alt="WordPress Plugin Rating" src="https://img.shields.io/wordpress/plugin/stars/mainwp-child?label=WP.org%20Rating">
<a href="https://travis-ci.org/mainwp/mainwp-child"><img src="https://travis-ci.org/mainwp/mainwp-child.svg?branch=master" alt="Build Status"></a>
</p>
Welcome to the [MainWP](https://mainwp.com) Child plugin repository on GitHub. Here you can browse the source, look at open issues and keep track of development.

View file

@ -43,7 +43,7 @@ class MainWP_Backup {
$pid = trailingslashit( $backupdir ) . 'backup-' . $pid . '.pid';
}
//Verify if another backup is running, if so, return an error
// Verify if another backup is running, if so, return an error
$files = glob( $backupdir . '*.pid' );
foreach ( $files as $file ) {
if ( basename( $file ) == basename( $pid ) ) {
@ -68,38 +68,23 @@ class MainWP_Backup {
$ext = $this->archiver->getExtension();
}
// throw new Exception('Test 1 2 : ' . print_r($append,1));
if ( ( false !== $fileSuffix ) && ! empty( $fileSuffix ) ) {
$file = $fileSuffix . ( true === $append ? '' : $ext ); //Append already contains extension!
// Append already contains extension!
$file = $fileSuffix . ( true === $append ? '' : $ext );
} else {
$file = 'backup-' . $filePrefix . $timestamp . $ext;
}
$filepath = $backupdir . $file;
$fileurl = $file;
// if (!$append)
// {
// if ($dh = opendir($backupdir))
// {
// while (($file = readdir($dh)) !== false)
// {
// if ($file != '.' && $file != '..' && preg_match('/(.*).(zip|tar|tar.gz|tar.bz2|pid|done)$/', $file))
// {
// @unlink($backupdir . $file);
// }
// }
// closedir($dh);
// }
// }
if ( ! $addConfig ) {
if ( ! in_array( str_replace( ABSPATH, '', WP_CONTENT_DIR ), $excludes ) && ! in_array( 'wp-admin', $excludes ) && ! in_array( WPINC, $excludes ) ) {
if ( ! in_array( str_replace( ABSPATH, '', WP_CONTENT_DIR ), $excludes, true ) && ! in_array( 'wp-admin', $excludes, true ) && ! in_array( WPINC, $excludes, true ) ) {
$addConfig = true;
$includeCoreFiles = true;
}
}
$this->timeout = 20 * 60 * 60; /*20 minutes*/
$this->timeout = 20 * 60 * 60;
$mem = '512M';
// @codingStandardsIgnoreStart
@ini_set( 'memory_limit', $mem );
@ -109,9 +94,9 @@ class MainWP_Backup {
if ( null !== $this->archiver ) {
$success = $this->archiver->createFullBackup( $filepath, $excludes, $addConfig, $includeCoreFiles, $excludezip, $excludenonwp, $append );
} else if ( $this->checkZipSupport() ) {
} elseif ( $this->checkZipSupport() ) {
$success = $this->createZipFullBackup( $filepath, $excludes, $addConfig, $includeCoreFiles, $excludezip, $excludenonwp );
} else if ( $this->checkZipConsole() ) {
} elseif ( $this->checkZipConsole() ) {
$success = $this->createZipConsoleFullBackup( $filepath, $excludes, $addConfig, $includeCoreFiles, $excludezip, $excludenonwp );
} else {
$success = $this->createZipPclFullBackup2( $filepath, $excludes, $addConfig, $includeCoreFiles, $excludezip, $excludenonwp );
@ -125,7 +110,7 @@ class MainWP_Backup {
}
public function zipFile( $files, $archive ) {
$this->timeout = 20 * 60 * 60; /*20 minutes*/
$this->timeout = 20 * 60 * 60;
$mem = '512M';
// @codingStandardsIgnoreStart
@ini_set( 'memory_limit', $mem );
@ -133,15 +118,15 @@ class MainWP_Backup {
@ini_set( 'max_execution_time', $this->timeout );
// @codingStandardsIgnoreEnd
if ( !is_array( $files ) ) {
$files = array ($files );
if ( ! is_array( $files ) ) {
$files = array( $files );
}
if ( null !== $this->archiver ) {
$success = $this->archiver->zipFile( $files, $archive );
} else if ( $this->checkZipSupport() ) {
} elseif ( $this->checkZipSupport() ) {
$success = $this->_zipFile( $files, $archive );
} else if ( $this->checkZipConsole() ) {
} elseif ( $this->checkZipConsole() ) {
$success = $this->_zipFileConsole( $files, $archive );
} else {
$success = $this->_zipFilePcl( $files, $archive );
@ -172,8 +157,8 @@ class MainWP_Backup {
}
public function _zipFilePcl( $files, $archive ) {
//Zip this backup folder..
require_once( ABSPATH . 'wp-admin/includes/class-pclzip.php' );
// Zip this backup folder..
require_once ABSPATH . 'wp-admin/includes/class-pclzip.php';
$this->zip = new PclZip( $archive );
$error = false;
@ -183,7 +168,7 @@ class MainWP_Backup {
}
}
return !$error;
return ! $error;
}
/**
@ -202,7 +187,6 @@ class MainWP_Backup {
*/
public function checkZipConsole() {
return false;
// return function_exists('system');
}
/**
@ -248,7 +232,7 @@ class MainWP_Backup {
foreach ( $nodes as $key => $node ) {
if ( MainWP_Helper::startsWith( $node, ABSPATH . WPINC ) ) {
unset( $nodes[ $key ] );
} else if ( MainWP_Helper::startsWith( $node, ABSPATH . basename( admin_url( '' ) ) ) ) {
} elseif ( MainWP_Helper::startsWith( $node, ABSPATH . basename( admin_url( '' ) ) ) ) {
unset( $nodes[ $key ] );
} else {
foreach ( $coreFiles as $coreFile ) {
@ -280,7 +264,7 @@ class MainWP_Backup {
if ( ! MainWP_Helper::inExcludes( $excludes, str_replace( ABSPATH, '', $node ) ) ) {
if ( is_dir( $node ) ) {
$this->zipAddDir( $node, $excludes );
} else if ( is_file( $node ) ) {
} elseif ( is_file( $node ) ) {
$this->addFileToZip( $node, str_replace( ABSPATH, '', $node ) );
}
}
@ -352,7 +336,7 @@ class MainWP_Backup {
* @return bool
*/
public function createZipPclFullBackup( $filepath, $excludes, $addConfig, $includeCoreFiles ) {
require_once( ABSPATH . 'wp-admin/includes/class-pclzip.php' );
require_once ABSPATH . 'wp-admin/includes/class-pclzip.php';
$this->zip = new PclZip( $filepath );
$nodes = glob( ABSPATH . '*' );
if ( ! $includeCoreFiles ) {
@ -382,7 +366,7 @@ class MainWP_Backup {
foreach ( $nodes as $key => $node ) {
if ( MainWP_Helper::startsWith( $node, ABSPATH . WPINC ) ) {
unset( $nodes[ $key ] );
} else if ( MainWP_Helper::startsWith( $node, ABSPATH . basename( admin_url( '' ) ) ) ) {
} elseif ( MainWP_Helper::startsWith( $node, ABSPATH . basename( admin_url( '' ) ) ) ) {
unset( $nodes[ $key ] );
} else {
foreach ( $coreFiles as $coreFile ) {
@ -396,7 +380,7 @@ class MainWP_Backup {
}
$db_files = $this->createBackupDB( dirname( $filepath ) . DIRECTORY_SEPARATOR . 'dbBackup' );
$error = false;
$error = false;
foreach ( $db_files as $db_file ) {
if ( 0 === ( $rslt = $this->zip->add( $db_file, PCLZIP_OPT_REMOVE_PATH, dirname( $db_file ), PCLZIP_OPT_ADD_PATH, basename( WP_CONTENT_DIR ) ) ) ) {
$error = true;
@ -408,13 +392,13 @@ class MainWP_Backup {
}
if ( ! $error ) {
foreach ( $nodes as $node ) {
if ( null === $excludes || ! in_array( str_replace( ABSPATH, '', $node ), $excludes ) ) {
if ( null === $excludes || ! in_array( str_replace( ABSPATH, '', $node ), $excludes, true ) ) {
if ( is_dir( $node ) ) {
if ( ! $this->pclZipAddDir( $node, $excludes ) ) {
$error = true;
break;
}
} else if ( is_file( $node ) ) {
} elseif ( is_file( $node ) ) {
if ( 0 === ( $rslt = $this->zip->add( $node, PCLZIP_OPT_REMOVE_PATH, ABSPATH ) ) ) {
$error = true;
break;
@ -471,7 +455,7 @@ class MainWP_Backup {
$newnodes = glob( $node . DIRECTORY_SEPARATOR . '*' );
$this->copy_dir( $newnodes, $excludes, $backupfolder, $excludenonwp, false );
unset( $newnodes );
} else if ( is_file( $node ) ) {
} elseif ( is_file( $node ) ) {
if ( $this->excludeZip && MainWP_Helper::endsWith( $node, '.zip' ) ) {
continue;
}
@ -485,16 +469,16 @@ class MainWP_Backup {
}
public function createZipPclFullBackup2( $filepath, $excludes, $addConfig, $includeCoreFiles, $excludezip, $excludenonwp ) {
//Create backup folder
// Create backup folder
$backupFolder = dirname( $filepath ) . DIRECTORY_SEPARATOR . 'backup' . DIRECTORY_SEPARATOR;
// @codingStandardsIgnoreStart
@mkdir( $backupFolder );
// @codingStandardsIgnoreEnd
//Create DB backup
// Create DB backup
$db_files = $this->createBackupDB( $backupFolder . 'dbBackup' );
//Copy installation to backup folder
// Copy installation to backup folder
$nodes = glob( ABSPATH . '*' );
if ( ! $includeCoreFiles ) {
$coreFiles = array(
@ -523,7 +507,7 @@ class MainWP_Backup {
foreach ( $nodes as $key => $node ) {
if ( MainWP_Helper::startsWith( $node, ABSPATH . WPINC ) ) {
unset( $nodes[ $key ] );
} else if ( MainWP_Helper::startsWith( $node, ABSPATH . basename( admin_url( '' ) ) ) ) {
} elseif ( MainWP_Helper::startsWith( $node, ABSPATH . basename( admin_url( '' ) ) ) ) {
unset( $nodes[ $key ] );
} else {
foreach ( $coreFiles as $coreFile ) {
@ -546,8 +530,8 @@ class MainWP_Backup {
// @codingStandardsIgnoreEnd
unset( $nodes );
//Zip this backup folder..
require_once( ABSPATH . 'wp-admin/includes/class-pclzip.php' );
// Zip this backup folder..
require_once ABSPATH . 'wp-admin/includes/class-pclzip.php';
$this->zip = new PclZip( $filepath );
$this->zip->create( $backupFolder, PCLZIP_OPT_REMOVE_PATH, $backupFolder );
if ( $addConfig ) {
@ -562,7 +546,7 @@ class MainWP_Backup {
$this->addFileFromStringToPCLZip( 'clone/config.txt', $string, $filepath );
}
//Remove backup folder
// Remove backup folder
MainWP_Helper::delete_dir( $backupFolder );
return true;
@ -599,24 +583,6 @@ class MainWP_Backup {
$iterator = null;
unset( $iterator );
// $nodes = glob(rtrim($path, '/') . '/*');
// if (empty($nodes)) return true;
//
// foreach ($nodes as $node)
// {
// if (!MainWP_Helper::inExcludes($excludes, str_replace(ABSPATH, '', $node)))
// {
// if (is_dir($node))
// {
// $this->zipAddDir($node, $excludes);
// }
// else if (is_file($node))
// {
// $this->addFileToZip($node, str_replace(ABSPATH, '', $node));
// }
// }
// }
}
public function pclZipAddDir( $path, $excludes ) {
@ -627,13 +593,13 @@ class MainWP_Backup {
}
foreach ( $nodes as $node ) {
if ( null === $excludes || ! in_array( str_replace( ABSPATH, '', $node ), $excludes ) ) {
if ( null === $excludes || ! in_array( str_replace( ABSPATH, '', $node ), $excludes, true ) ) {
if ( is_dir( $node ) ) {
if ( ! $this->pclZipAddDir( $node, $excludes ) ) {
$error = true;
break;
}
} else if ( is_file( $node ) ) {
} elseif ( is_file( $node ) ) {
if ( 0 === ( $rslt = $this->zip->add( $node, PCLZIP_OPT_REMOVE_PATH, ABSPATH ) ) ) {
$error = true;
break;
@ -657,7 +623,8 @@ class MainWP_Backup {
$this->zip->delete( PCLZIP_OPT_BY_NAME, $file );
$add = $this->zip->add( $tmpfilename,
PCLZIP_OPT_REMOVE_PATH, dirname( $filepath ),
PCLZIP_OPT_ADD_PATH, $localpath );
PCLZIP_OPT_ADD_PATH, $localpath
);
unlink( $tmpfilename );
if ( ! empty( $add ) ) {
return true;
@ -693,7 +660,7 @@ class MainWP_Backup {
$this->zipArchiveSizeCount += filesize( $path );
$this->gcCnt ++;
//5 mb limit!
// 5 mb limit!
if ( ! $this->loadFilesBeforeZip || ( filesize( $path ) > 5 * 1024 * 1024 ) ) {
$this->zipArchiveFileCount ++;
$added = $this->zip->addFile( $path, $zipEntryName );
@ -719,7 +686,7 @@ class MainWP_Backup {
$this->gcCnt = 0;
}
//Over limits?
// Over limits?
if ( ( ( $this->file_descriptors > 0 ) && ( $this->zipArchiveFileCount > $this->file_descriptors ) ) ) { // || $this->zipArchiveSizeCount >= (31457280 * 2))
$this->zip->close();
$this->zip = null;
@ -742,13 +709,11 @@ class MainWP_Backup {
}
public function createZipConsoleFullBackup( $filepath, $excludes, $addConfig, $includeCoreFiles, $excludezip, $excludenonwp ) {
// @TODO to work with 'zip' from system if PHP Zip library not available
//system('zip');
return false;
}
public function createBackupDB( $filepath_prefix, $archiveExt = false, &$archiver = null ) {
$timeout = 20 * 60 * 60; //20minutes
$timeout = 20 * 60 * 60;
// @codingStandardsIgnoreStart
@set_time_limit( $timeout );
@ini_set( 'max_execution_time', $timeout );
@ -760,7 +725,7 @@ class MainWP_Backup {
global $wpdb;
$db_files = array();
//Get all the tables
// Get all the tables
$tables_db = $wpdb->get_results( 'SHOW TABLES FROM `' . DB_NAME . '`', ARRAY_N );
foreach ( $tables_db as $curr_table ) {
if ( null !== $archiver ) {
@ -770,15 +735,15 @@ class MainWP_Backup {
$table = $curr_table[0];
$currentfile = $filepath_prefix . '-' . MainWP_Helper::sanitize_filename( $table ) . '.sql';
$db_files[] = $currentfile;
$db_files[] = $currentfile;
if ( file_exists( $currentfile ) ) {
continue;
}
$fh = fopen( $currentfile . '.tmp', 'w' ); //or error;
$fh = fopen( $currentfile . '.tmp', 'w' ); // or error;
fwrite( $fh, "\n\n" . 'DROP TABLE IF EXISTS ' . $table . ';' );
//todo fix this
//$table_create = $wpdb->get_row( $wpdb->prepare( 'SHOW CREATE TABLE %s', $table ), ARRAY_N );
// todo fix this
// $table_create = $wpdb->get_row( $wpdb->prepare( 'SHOW CREATE TABLE %s', $table ), ARRAY_N );
$table_create = $wpdb->get_row( 'SHOW CREATE TABLE ' . $table, ARRAY_N );
fwrite( $fh, "\n" . $table_create[1] . ";\n\n" );
@ -839,11 +804,10 @@ class MainWP_Backup {
@unlink( $db_file );
}
} else {
//todo: throw exception!
// todo: throw exception!
}
}
return ( false !== $archiveExt ? array( 'filepath' => $archivefilePath ) : $db_files );
}
}

File diff suppressed because it is too large Load diff

View file

@ -18,25 +18,24 @@
*/
class MainWP_Child_Back_Up_Wordpress {
public static $instance = null;
public static $instance = null;
public $is_plugin_installed = false;
static function Instance() {
if ( null === MainWP_Child_Back_Up_Wordpress::$instance ) {
MainWP_Child_Back_Up_Wordpress::$instance = new MainWP_Child_Back_Up_Wordpress();
if ( null === self::$instance ) {
self::$instance = new MainWP_Child_Back_Up_Wordpress();
}
return MainWP_Child_Back_Up_Wordpress::$instance;
return self::$instance;
}
public function __construct() {
require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
require_once ABSPATH . 'wp-admin/includes/plugin.php';
if ( is_plugin_active( 'backupwordpress/backupwordpress.php' ) ) {
$this->is_plugin_installed = true;
if ( version_compare( phpversion(), '5.3', '>=' ) ) {
add_filter( 'mainwp-site-sync-others-data', array( $this, 'syncOthersData' ), 10, 2 );
}
}
}
public function init() {
@ -44,7 +43,9 @@ class MainWP_Child_Back_Up_Wordpress {
return;
}
if (!$this->is_plugin_installed) return;
if ( ! $this->is_plugin_installed) {
return;
}
add_action( 'mainwp_child_site_stats', array( $this, 'do_site_stats' ) );
@ -66,7 +67,7 @@ class MainWP_Child_Back_Up_Wordpress {
return $value;
}
if (! MainWP_Helper::is_screen_with_update()) {
if ( ! MainWP_Helper::is_screen_with_update()) {
return $value;
}
if ( isset( $value->response['backupwordpress/backupwordpress.php'] ) ) {
@ -154,7 +155,7 @@ class MainWP_Child_Back_Up_Wordpress {
if ( isset( $data['syncBackUpWordPress'] ) && $data['syncBackUpWordPress'] ) {
try {
$information['syncBackUpWordPress'] = $this->get_sync_data();
} catch(Exception $e) {
} catch (Exception $e) {
}
}
@ -201,9 +202,13 @@ class MainWP_Child_Back_Up_Wordpress {
}
// ok
public function do_reports_log($ext = '') {
if ( $ext !== 'backupwordpress' ) return;
if (!$this->is_plugin_installed) return;
public function do_reports_log( $ext = '') {
if ( $ext !== 'backupwordpress' ) {
return;
}
if ( ! $this->is_plugin_installed) {
return;
}
try {
MainWP_Helper::check_classes_exists('HM\BackUpWordPress\Schedules');
@ -216,22 +221,22 @@ class MainWP_Child_Back_Up_Wordpress {
$check = current($schedules);
MainWP_Helper::check_methods($check, array( 'get_backups', 'get_type' ));
foreach($schedules as $schedule) {
foreach ($schedules as $schedule) {
foreach ( $schedule->get_backups() as $file ) {
$backup_type = $schedule->get_type();
$message = "BackupWordpres backup " . $backup_type . ' finished';
$destination = "N/A";
$backup_type = $schedule->get_type();
$message = 'BackupWordpres backup ' . $backup_type . ' finished';
$destination = 'N/A';
if ( file_exists( $file ) ) {
$date = @filemtime( $file );
if ( !empty( $date ) ) {
do_action( "mainwp_reports_backupwordpress_backup", $destination, $message, 'finished', $backup_type, $date );
if ( ! empty( $date ) ) {
do_action( 'mainwp_reports_backupwordpress_backup', $destination, $message, 'finished', $backup_type, $date );
MainWP_Helper::update_lasttime_backup('backupwordpress', $date); // to support backup before update feature
}
}
}
}
}
} catch(Exception $e) {
} catch (Exception $e) {
}
}
@ -262,7 +267,6 @@ class MainWP_Child_Back_Up_Wordpress {
$schedule_id = $this->check_schedule();
$schedule = new HM\BackUpWordPress\Scheduled_Backup( sanitize_text_field( urldecode( $schedule_id ) ) );
// Delete the running backup
if (method_exists($schedule, 'get_running_backup_filename' )) {
if ( $schedule->get_running_backup_filename() && file_exists( trailingslashit( hmbkp_path() ) . $schedule->get_running_backup_filename() ) ) {
@ -291,7 +295,7 @@ class MainWP_Child_Back_Up_Wordpress {
$information['scheduleStatus'] = $status->get_status();
}
$information['result'] = 'SUCCESS';
$information['result'] = 'SUCCESS';
return $information;
}
@ -303,11 +307,11 @@ class MainWP_Child_Back_Up_Wordpress {
if (method_exists($schedule, 'get_running_backup_filename' )) {
$information['scheduleStatus'] = $schedule->get_status();
} else {
$status = $schedule->get_status();
$status = $schedule->get_status();
$information['scheduleStatus'] = $status->get_status();
}
$information['result'] = 'SUCCESS';
$information['result'] = 'SUCCESS';
return $information;
}
@ -316,14 +320,15 @@ class MainWP_Child_Back_Up_Wordpress {
$schedule_id = $this->check_schedule();
if (function_exists('hmbkp_run_schedule_async')) {
hmbkp_run_schedule_async($schedule_id);
} else if (function_exists('\HM\BackUpWordPress\run_schedule_async')) {
} elseif (function_exists('\HM\BackUpWordPress\run_schedule_async')) {
HM\BackUpWordPress\Path::get_instance()->cleanup();
// Fixes an issue on servers which only allow a single session per client
session_write_close();
$task = new \HM\Backdrop\Task( '\HM\BackUpWordPress\run_schedule_async', $schedule_id );
$task->schedule();
} else
} else {
return array( 'error' => __('Error while trying to trigger the schedule', 'mainwp-child') );
}
return array( 'result' => 'SUCCESS' );
}
@ -347,9 +352,9 @@ class MainWP_Child_Back_Up_Wordpress {
continue;
}
$schedule = new HM\BackUpWordPress\Scheduled_Backup( sanitize_text_field( urldecode( $schedule_id ) ) );
$started_ago = method_exists($schedule, 'get_schedule_running_start_time') ? $schedule->get_schedule_running_start_time() : $schedule->get_schedule_start_time();
$out = array(
$schedule = new HM\BackUpWordPress\Scheduled_Backup( sanitize_text_field( urldecode( $schedule_id ) ) );
$started_ago = method_exists($schedule, 'get_schedule_running_start_time') ? $schedule->get_schedule_running_start_time() : $schedule->get_schedule_start_time();
$out = array(
'b' => $this->get_backupslist_html( $schedule ),
'count' => count( $schedule->get_backups() ),
'file_size_text' => $this->hmbkp_get_site_size_text( $schedule ),
@ -359,7 +364,7 @@ class MainWP_Child_Back_Up_Wordpress {
if (method_exists($schedule, 'get_running_backup_filename' )) {
$out['scheduleStatus'] = $schedule->get_status();
} else {
$status = $schedule->get_status();
$status = $schedule->get_status();
$out['scheduleStatus'] = $status->get_status();
}
@ -375,7 +380,7 @@ class MainWP_Child_Back_Up_Wordpress {
$current_option = get_option( 'hmbkp_schedule_' . $sch_id );
if ( is_array( $current_option ) ) {
unset( $current_option['excludes'] ); // not send this value
$started_ago = method_exists($schedule, 'get_schedule_running_start_time') ? $schedule->get_schedule_running_start_time() : $schedule->get_schedule_start_time();
$started_ago = method_exists($schedule, 'get_schedule_running_start_time') ? $schedule->get_schedule_running_start_time() : $schedule->get_schedule_start_time();
$send_back_schedules[ $sch_id ] = array(
'options' => $current_option,
'b' => $this->get_backupslist_html( $schedule ),
@ -387,17 +392,18 @@ class MainWP_Child_Back_Up_Wordpress {
if (method_exists($schedule, 'get_running_backup_filename' )) {
$send_back_schedules['scheduleStatus'] = $schedule->get_status();
} else {
$status = $schedule->get_status();
$status = $schedule->get_status();
$send_back_schedules['scheduleStatus'] = $status->get_status();
}
}
}
}
if (function_exists('HM\BackUpWordPress\Backup::get_home_path'))
if (function_exists('HM\BackUpWordPress\Backup::get_home_path')) {
$backups_path = str_replace( HM\BackUpWordPress\Backup::get_home_path(), '', hmbkp_path() );
else
} else {
$backups_path = str_replace( HM\BackUpWordPress\Path::get_home_path(), '', HM\BackUpWordPress\Path::get_path() );
}
$information['backups_path'] = $backups_path;
$information['send_back_schedules'] = $send_back_schedules;
@ -421,7 +427,7 @@ class MainWP_Child_Back_Up_Wordpress {
return array( 'error' => $deleted->get_error_message() );
}
$ret = array(
$ret = array(
'result' => 'SUCCESS',
'b' => $this->get_backupslist_html( $schedule ),
'count' => count( $schedule->get_backups() ),
@ -430,7 +436,7 @@ class MainWP_Child_Back_Up_Wordpress {
if (method_exists($schedule, 'get_running_backup_filename' )) {
$ret['scheduleStatus'] = $schedule->get_status();
} else {
$status = $schedule->get_status();
$status = $schedule->get_status();
$ret['scheduleStatus'] = $status->get_status();
}
return $ret;
@ -445,7 +451,7 @@ class MainWP_Child_Back_Up_Wordpress {
<tr>
<th scope="col"><?php function_exists('hmbkp_backups_number') ? hmbkp_backups_number( $schedule ) : ( function_exists('backups_number') ? backups_number( $schedule ) : "" ) ; ?></th>
<th scope="col"><?php function_exists('hmbkp_backups_number') ? hmbkp_backups_number( $schedule ) : ( function_exists('backups_number') ? backups_number( $schedule ) : '' ); ?></th>
<th scope="col"><?php esc_html_e( 'Size', 'mainwp-backupwordpress-extension' ); ?></th>
<th scope="col"><?php esc_html_e( 'Type', 'mainwp-backupwordpress-extension' ); ?></th>
<th scope="col"><?php esc_html_e( 'Actions', 'mainwp-backupwordpress-extension' ); ?></th>
@ -456,7 +462,8 @@ class MainWP_Child_Back_Up_Wordpress {
<tbody>
<?php if ( $schedule->get_backups() ) {
<?php
if ( $schedule->get_backups() ) {
$schedule->delete_old_backups();
@ -469,7 +476,8 @@ class MainWP_Child_Back_Up_Wordpress {
$this->hmbkp_get_backup_row( $file, $schedule );
}
} else { ?>
} else {
?>
<tr>
<td class="hmbkp-no-backups"
@ -501,7 +509,6 @@ class MainWP_Child_Back_Up_Wordpress {
}
return sprintf( '(<code class="calculating" title="' . __( 'this shouldn\'t take long&hellip;', 'mainwp-backupwordpress-extension' ) . '">' . __( 'calculating the size of your backup&hellip;', 'mainwp-backupwordpress-extension' ) . '</code>)' );
}
function hmbkp_get_backup_row( $file, HM\BackUpWordPress\Scheduled_Backup $schedule ) {
@ -525,20 +532,23 @@ class MainWP_Child_Back_Up_Wordpress {
<td>
<?php if (function_exists('hmbkp_is_path_accessible')) {
<?php
if (function_exists('hmbkp_is_path_accessible')) {
if ( hmbkp_is_path_accessible( hmbkp_path() ) ) {
?>
<a href="#"
onclick="event.preventDefault(); mainwp_backupwp_download_backup('<?php echo $encoded_file; ?>', <?php echo esc_attr( $schedule->get_id() ); ?>, this);"
class="download-action"><?php esc_html_e( 'Download', 'backupwordpress' ); ?></a> |
<?php };
} else if (function_exists('HM\BackUpWordPress\is_path_accessible') ) {
<?php
};
} elseif (function_exists('HM\BackUpWordPress\is_path_accessible') ) {
if (HM\BackUpWordPress\is_path_accessible(HM\BackUpWordPress\Path::get_path())) {
?>
<a href="#"
onclick="event.preventDefault(); mainwp_backupwp_download_backup('<?php echo $encoded_file; ?>', <?php echo esc_attr( $schedule->get_id() ); ?>, this);"
class="download-action"><?php esc_html_e( 'Download', 'backupwordpress' ); ?></a> |
<?php };
<?php
};
}
?>
@ -550,7 +560,8 @@ class MainWP_Child_Back_Up_Wordpress {
</tr>
<?php }
<?php
}
function get_excluded( $browse_dir = null ) {
@ -559,14 +570,14 @@ class MainWP_Child_Back_Up_Wordpress {
$new_version = true;
if (method_exists($schedule, 'get_running_backup_filename' )) {
$new_version = false;
$user_excludes = array_diff( $schedule->get_excludes(), $schedule->backup->default_excludes() );
$root_dir = $schedule->backup->get_root();
$new_version = false;
$user_excludes = array_diff( $schedule->get_excludes(), $schedule->backup->default_excludes() );
$root_dir = $schedule->backup->get_root();
$is_size_calculated = $schedule->is_site_size_being_calculated();
} else {
$excludes = $schedule->get_excludes();
$user_excludes = $excludes->get_user_excludes();
$root_dir = HM\BackUpWordPress\Path::get_root();
$excludes = $schedule->get_excludes();
$user_excludes = $excludes->get_user_excludes();
$root_dir = HM\BackUpWordPress\Path::get_root();
$is_size_calculated = HM\BackUpWordPress\Site_Size::is_site_size_being_calculated();
}
@ -575,7 +586,7 @@ class MainWP_Child_Back_Up_Wordpress {
?>
<div class="hmbkp-exclude-settings">
<?php //if ( $schedule->get_excludes() ) : ?>
<?php // if ( $schedule->get_excludes() ) : ?>
<h3>
<?php esc_html_e( 'Currently Excluded', 'backupwordpress' ); ?>
@ -615,12 +626,14 @@ class MainWP_Child_Back_Up_Wordpress {
<td>
<?php
if ($new_version)
if ($new_version) {
$is_default_rule = ( in_array( $exclude, $excludes->get_default_excludes() ) ) || ( HM\BackUpWordPress\Path::get_path() === trailingslashit( HM\BackUpWordPress\Path::get_root() ) . untrailingslashit( $exclude ) );
else
$is_default_rule = ( in_array( $exclude, $schedule->backup->default_excludes() ) ) || ( hmbkp_path() === untrailingslashit( $exclude ) ) ;
} else {
$is_default_rule = ( in_array( $exclude, $schedule->backup->default_excludes() ) ) || ( hmbkp_path() === untrailingslashit( $exclude ) );
}
if ( $is_default_rule ) : ?>
if ( $is_default_rule ) :
?>
<?php esc_html_e( 'Default rule', 'backupwordpress' ); ?>
<?php elseif ( defined( 'HMBKP_EXCLUDE' ) && false !== strpos( HMBKP_EXCLUDE, $exclude ) ) : ?>
@ -645,7 +658,7 @@ class MainWP_Child_Back_Up_Wordpress {
</table>
<?php //endif; ?>
<?php // endif; ?>
<h3 id="directory-listing"><?php esc_html_e( 'Your Site', 'backupwordpress' ); ?></h3>
@ -668,19 +681,21 @@ class MainWP_Child_Back_Up_Wordpress {
// Kick off a recursive filesize scan
if ($new_version) {
$site_size = new HM\BackUpWordPress\Site_Size;
$site_size = new HM\BackUpWordPress\Site_Size();
$exclude_string = implode( '|', $excludes->get_excludes_for_regex() );
if (function_exists('HM\BackUpWordPress\list_directory_by_total_filesize'))
if (function_exists('HM\BackUpWordPress\list_directory_by_total_filesize')) {
$files = HM\BackUpWordPress\list_directory_by_total_filesize( $directory, $excludes );
}
} else {
$files = $schedule->list_directory_by_total_filesize( $directory );
$files = $schedule->list_directory_by_total_filesize( $directory );
$exclude_string = $schedule->backup->exclude_string( 'regex' );
}
if ( $files ) { ?>
if ( $files ) {
?>
<table class="widefat">
<thead>
@ -702,16 +717,19 @@ class MainWP_Child_Back_Up_Wordpress {
<th scope="col">
<?php if ( $root_dir !== $directory ) {
<?php
if ( $root_dir !== $directory ) {
// echo esc_url( remove_query_arg( 'hmbkp_directory_browse' ) );
?>
<a href="#"
onclick="event.preventDefault(); mainwp_backupwp_directory_browse('', this)"><?php echo esc_html( $root_dir ); ?></a>
<code>/</code>
<?php $parents = array_filter( explode( '/', str_replace( trailingslashit( $root_dir ), '', trailingslashit( dirname( $directory ) ) ) ) );
<?php
$parents = array_filter( explode( '/', str_replace( trailingslashit( $root_dir ), '', trailingslashit( dirname( $directory ) ) ) ) );
foreach ( $parents as $directory_basename ) { ?>
foreach ( $parents as $directory_basename ) {
?>
<a href="#"
onclick="event.preventDefault(); mainwp_backupwp_directory_browse('<?php echo urlencode( substr( $directory, 0, strpos( $directory, $directory_basename ) ) . $directory_basename ); ?>', this)"><?php echo esc_html( $directory_basename ); ?></a>
@ -793,7 +811,8 @@ class MainWP_Child_Back_Up_Wordpress {
<tbody>
<?php foreach ( $files as $size => $file ) {
<?php
foreach ( $files as $size => $file ) {
$is_excluded = $is_unreadable = false;
@ -811,7 +830,8 @@ class MainWP_Child_Back_Up_Wordpress {
// Skip unreadable files
if ( ! @realpath( $file->getPathname() ) || ! $file->isReadable() ) {
$is_unreadable = true;
} ?>
}
?>
<tr>
@ -836,7 +856,8 @@ class MainWP_Child_Back_Up_Wordpress {
<td>
<?php
if ($new_version) {
if ( $is_unreadable ) { ?>
if ( $is_unreadable ) {
?>
<code class="strikethrough"
title="<?php echo esc_attr( wp_normalize_path( $file->getRealPath() ) ); ?>"><?php echo esc_html( $file->getBasename() ); ?></code>
@ -852,9 +873,11 @@ class MainWP_Child_Back_Up_Wordpress {
onclick="event.preventDefault(); mainwp_backupwp_directory_browse('<?php echo urlencode( wp_normalize_path( $file->getPathname()) ); ?>', this)"><?php echo esc_html( $file->getBasename() ); ?></a></code>
<?php }
<?php
}
} else {
if ( $is_unreadable ) { ?>
if ( $is_unreadable ) {
?>
<code class="strikethrough"
title="<?php echo esc_attr( $file->getRealPath() ); ?>"><?php echo esc_html( $file->getBasename() ); ?></code>
@ -864,14 +887,16 @@ class MainWP_Child_Back_Up_Wordpress {
<code
title="<?php echo esc_attr( $file->getRealPath() ); ?>"><?php echo esc_html( $file->getBasename() ); ?></code>
<?php } elseif ( $file->isDir() ) {
//echo add_query_arg( 'hmbkp_directory_browse', urlencode( $file->getPathname() ) );
<?php
} elseif ( $file->isDir() ) {
// echo add_query_arg( 'hmbkp_directory_browse', urlencode( $file->getPathname() ) );
?>
<code title="<?php echo esc_attr( $file->getRealPath() ); ?>"><a
href="#"
onclick="event.preventDefault(); mainwp_backupwp_directory_browse('<?php echo urlencode( $file->getPathname() ); ?>', this)"><?php echo esc_html( $file->getBasename() ); ?></a></code>
<?php }
<?php
}
}
?>
@ -897,7 +922,8 @@ class MainWP_Child_Back_Up_Wordpress {
if ( ! $size ) {
$size = '0 B';
} ?>
}
?>
<code>
@ -918,7 +944,8 @@ class MainWP_Child_Back_Up_Wordpress {
<code>--</code>
<?php }
<?php
}
endif;
?>
@ -935,7 +962,8 @@ class MainWP_Child_Back_Up_Wordpress {
<span
title="<?php echo esc_attr( wp_normalize_path( $file->GetRealPath() ) ); ?>"><?php esc_html_e( 'Symlink', 'backupwordpress' ); ?></span>
<?php elseif ( $file->isDir() ) :
<?php
elseif ( $file->isDir() ) :
esc_html_e( 'Folder', 'backupwordpress' );
@ -999,7 +1027,6 @@ class MainWP_Child_Back_Up_Wordpress {
$information['e'] = $output;
return $information;
}
function directory_browse() {
@ -1038,7 +1065,6 @@ class MainWP_Child_Back_Up_Wordpress {
$out['current_browse_dir'] = $_POST['browse_dir'];
return $out;
}
function hmbkp_remove_exclude_rule() {
@ -1050,13 +1076,14 @@ class MainWP_Child_Back_Up_Wordpress {
$schedule_id = $this->check_schedule();
$schedule = new HM\BackUpWordPress\Scheduled_Backup( sanitize_text_field( $schedule_id ) );
$excludes = $schedule->get_excludes();
$excludes = $schedule->get_excludes();
$exclude_rule_to_remove = stripslashes( sanitize_text_field( $_POST['remove_rule'] ) );
if (method_exists($excludes, 'get_user_excludes')) {
$schedule->set_excludes( array_diff( $excludes->get_user_excludes(), (array) $exclude_rule_to_remove ) );
} else
} else {
$schedule->set_excludes( array_diff( $excludes, $exclude_rule_to_remove ) );
}
$schedule->save();
@ -1077,7 +1104,7 @@ class MainWP_Child_Back_Up_Wordpress {
function general_exclude_add_rule() {
$sch_id = $this->check_schedule();
$sch_id = $this->check_schedule();
$schedule = new HM\BackUpWordPress\Scheduled_Backup( sanitize_text_field( $sch_id ) );
$exclude_paths = urldecode( $_POST['exclude_paths'] );
@ -1087,21 +1114,20 @@ class MainWP_Child_Back_Up_Wordpress {
$excl_rule = trim($excl_rule);
$excl_rule = trim($excl_rule, '/');
if (empty($excl_rule))
if (empty($excl_rule)) {
continue;
}
$exclude_rule = ABSPATH . $excl_rule;
$path = realpath($exclude_rule);
$path = realpath($exclude_rule);
// If it exist
if($path !== false)
{
if ($path !== false) {
$schedule->set_excludes( $exclude_rule, true );
$schedule->save();
}
}
}
$un_exclude_paths = urldecode( $_POST['un_exclude_paths'] );
$un_exclude_paths = explode("\n", $un_exclude_paths);
@ -1110,20 +1136,21 @@ class MainWP_Child_Back_Up_Wordpress {
$exclude_rule_to_remove = trim($exclude_rule_to_remove);
$exclude_rule_to_remove = trim($exclude_rule_to_remove, '/');
if (empty($exclude_rule_to_remove))
continue;
if (empty($exclude_rule_to_remove)) {
continue;
}
$excludes = $schedule->get_excludes();
if (method_exists($excludes, 'get_user_excludes')) {
$schedule->set_excludes( array_diff( $excludes->get_user_excludes(), (array) $exclude_rule_to_remove ) );
} else {
$schedule->set_excludes( array_diff( $excludes, $exclude_rule_to_remove ) );
}
if (method_exists($excludes, 'get_user_excludes')) {
$schedule->set_excludes( array_diff( $excludes->get_user_excludes(), (array) $exclude_rule_to_remove ) );
} else {
$schedule->set_excludes( array_diff( $excludes, $exclude_rule_to_remove ) );
}
$schedule->save();
}
}
return array('result' => 'SUCCESS');
return array( 'result' => 'SUCCESS' );
}
@ -1136,11 +1163,11 @@ class MainWP_Child_Back_Up_Wordpress {
return array( 'error' => 'Error: Schedule data' );
}
// $current_value = get_option( 'hmbkp_schedule_' . $sch_id );
// if ( is_array( $current_value ) && isset( $current_value['excludes'] ) ) {
// // do not update 'excludes' value
// $options['excludes'] = $current_value['excludes'];
// }
// $current_value = get_option( 'hmbkp_schedule_' . $sch_id );
// if ( is_array( $current_value ) && isset( $current_value['excludes'] ) ) {
// do not update 'excludes' value
// $options['excludes'] = $current_value['excludes'];
// }
$filter_opts = array(
'type',
@ -1194,10 +1221,11 @@ class MainWP_Child_Back_Up_Wordpress {
}
$out = array();
foreach($schedules as $sch_id => $sch) {
if ( empty($sch_id) || !isset( $sch['options'] ) || ! is_array( $sch['options'] ) )
foreach ($schedules as $sch_id => $sch) {
if ( empty($sch_id) || ! isset( $sch['options'] ) || ! is_array( $sch['options'] ) ) {
continue;
$options = $sch['options'];
}
$options = $sch['options'];
$filter_opts = array(
'type',
'email',

View file

@ -22,11 +22,11 @@ if ( ! defined( 'MAINWP_BACKWPUP_DEVELOPMENT' ) ) {
class MainWP_Child_Back_WP_Up {
public $is_backwpup_installed = false;
public $is_backwpup_pro = false;
public $plugin_translate = 'mainwp-backwpup-extension';
public static $instance = null;
protected $software_version = '0.1';
public static $information = array();
public $is_backwpup_pro = false;
public $plugin_translate = 'mainwp-backwpup-extension';
public static $instance = null;
protected $software_version = '0.1';
public static $information = array();
protected $exclusions = array(
'cron' => array(
@ -58,36 +58,36 @@ class MainWP_Child_Back_WP_Up {
);
static function Instance() {
if ( MainWP_Child_Back_WP_Up::$instance == null ) {
MainWP_Child_Back_WP_Up::$instance = new MainWP_Child_Back_WP_Up();
if ( self::$instance == null ) {
self::$instance = new MainWP_Child_Back_WP_Up();
}
return MainWP_Child_Back_WP_Up::$instance;
return self::$instance;
}
public function __construct() {
require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
require_once ABSPATH . 'wp-admin/includes/plugin.php';
try {
if ( is_plugin_active( 'backwpup-pro/backwpup.php' ) && file_exists( plugin_dir_path( __FILE__ ) . '../../backwpup-pro/backwpup.php' ) ) {
$file_path1 = plugin_dir_path( __FILE__ ) . '../../backwpup-pro/backwpup.php';
$file_path2 = plugin_dir_path( __FILE__ ) . '../../backwpup-pro/inc/Pro/class-pro.php';
// to fix
if ( ! file_exists( $file_path2 ) ) {
$file_path2 = plugin_dir_path( __FILE__ ) . '../../backwpup-pro/inc/pro/class-pro.php';
}
MainWP_Helper::check_files_exists(array( $file_path1, $file_path2 ));
require_once( $file_path1 );
require_once( $file_path2 );
require_once $file_path1;
require_once $file_path2;
$this->is_backwpup_installed = true;
$this->is_backwpup_pro = true;
} else if ( is_plugin_active( 'backwpup/backwpup.php' ) && file_exists( plugin_dir_path( __FILE__ ) . '../../backwpup/backwpup.php' ) ) {
} elseif ( is_plugin_active( 'backwpup/backwpup.php' ) && file_exists( plugin_dir_path( __FILE__ ) . '../../backwpup/backwpup.php' ) ) {
$file_path = plugin_dir_path( __FILE__ ) . '../../backwpup/backwpup.php';
MainWP_Helper::check_files_exists(array( $file_path ));
require_once( $file_path );
require_once $file_path;
$this->is_backwpup_installed = true;
}
@ -96,8 +96,8 @@ class MainWP_Child_Back_WP_Up {
MainWP_Helper::check_methods('get_instance');
BackWPup::get_instance();
//add_action( 'wp_ajax_mainwp_backwpup_download_backup', array( $this, 'download_backup' ) );
add_action( 'admin_init', array( $this, 'init_download_backup' ) );
// add_action( 'wp_ajax_mainwp_backwpup_download_backup', array( $this, 'download_backup' ) );
add_action( 'admin_init', array( $this, 'init_download_backup' ) );
add_filter( 'mainwp-site-sync-others-data', array( $this, 'syncOthersData' ), 10, 2 );
}
} catch ( Exception $e) {
@ -116,11 +116,11 @@ class MainWP_Child_Back_WP_Up {
error_reporting( 0 );
function mainwp_backwpup_handle_fatal_error() {
$error = error_get_last();
$info = MainWP_Child_Back_WP_Up::$information;
$info = self::$information;
if ( isset( $error['type'] ) && E_ERROR === $error['type'] && isset( $error['message'] ) ) {
MainWP_Helper::write( array( 'error' => 'MainWP_Child fatal error : ' . $error['message'] . ' Line: ' . $error['line'] . ' File: ' . $error['file'] ) );
} else if ( ! empty( $info ) ) {
MainWP_Helper::write( MainWP_Child_Back_WP_Up::$information );
} elseif ( ! empty( $info ) ) {
MainWP_Helper::write( self::$information );
} else {
MainWP_Helper::write( array( 'error' => 'Missing information array inside fatal_error' ) );
}
@ -212,14 +212,15 @@ class MainWP_Child_Back_WP_Up {
}
}
MainWP_Child_Back_WP_Up::$information = $information;
self::$information = $information;
exit();
}
public function init() {
if (!$this->is_backwpup_installed)
if ( ! $this->is_backwpup_installed) {
return;
}
add_action( 'mainwp_child_site_stats', array( $this, 'do_site_stats' ) );
@ -237,14 +238,17 @@ class MainWP_Child_Back_WP_Up {
}
}
// ok
public function do_reports_log($ext = '') {
if ( $ext !== 'backwpup' ) return;
if (!$this->is_backwpup_installed)
public function do_reports_log( $ext = '') {
if ( $ext !== 'backwpup' ) {
return;
}
if ( ! $this->is_backwpup_installed) {
return;
}
try {
MainWP_Helper::check_classes_exists(array('BackWPup_File', 'BackWPup_Job'));
MainWP_Helper::check_classes_exists(array( 'BackWPup_File', 'BackWPup_Job' ));
MainWP_Helper::check_methods('BackWPup_File', array( 'get_absolute_path' ));
MainWP_Helper::check_methods('BackWPup_Job', array( 'read_logheader' ));
@ -254,12 +258,12 @@ class MainWP_Child_Back_WP_Up {
$log_folder = BackWPup_File::get_absolute_path( $log_folder );
$log_folder = untrailingslashit( $log_folder );
//load logs
// load logs
$logfiles = array();
if ( is_readable( $log_folder ) && $dir = opendir( $log_folder ) ) {
while ( ( $file = readdir( $dir ) ) !== FALSE ) {
while ( ( $file = readdir( $dir ) ) !== false ) {
$log_file = $log_folder . '/' . $file;
if ( is_file( $log_file ) && is_readable( $log_file ) && FALSE !== strpos( $file, 'backwpup_log_' ) && FALSE !== strpos( $file, '.html' ) ) {
if ( is_file( $log_file ) && is_readable( $log_file ) && false !== strpos( $file, 'backwpup_log_' ) && false !== strpos( $file, '.html' ) ) {
$logfiles[] = $file;
}
}
@ -269,39 +273,40 @@ class MainWP_Child_Back_WP_Up {
$log_items = array();
foreach ( $logfiles as $mtime => $logfile ) {
$meta = BackWPup_Job::read_logheader( $log_folder . '/' . $logfile );
if (!isset($meta['logtime']) || $meta['logtime'] < $lasttime_logged)
if ( ! isset($meta['logtime']) || $meta['logtime'] < $lasttime_logged) {
continue;
}
if (isset($meta['errors']) && !empty($meta['errors'])) {
if (isset($meta['errors']) && ! empty($meta['errors'])) {
continue; // do not logging backups have errors
}
$log_items[$mtime] = $meta;
$log_items[$mtime]['file'] = $logfile;
$log_items[ $mtime ] = $meta;
$log_items[ $mtime ]['file'] = $logfile;
}
if ( !empty( $log_items ) ) {
if ( ! empty( $log_items ) ) {
$job_types = array(
'DBDUMP' => __('Database backup', 'mainwp-child'),
'FILE' => __('File backup', 'mainwp-child'),
'WPEXP' => __('WordPress XML export', 'mainwp-child'),
'DBDUMP' => __('Database backup', 'mainwp-child'),
'FILE' => __('File backup', 'mainwp-child'),
'WPEXP' => __('WordPress XML export', 'mainwp-child'),
'WPPLUGIN' => __('Installed plugins list', 'mainwp-child'),
'DBCHECK' => __('Check database tables', 'mainwp-child')
'DBCHECK' => __('Check database tables', 'mainwp-child'),
);
$new_lasttime_logged = $lasttime_logged;
foreach ($log_items as $log) {
$backup_time = $log[ "logtime" ];
$backup_time = $log['logtime'];
if ($backup_time < $lasttime_logged) {
// small than last backup time then skip
continue;
}
$job_job_types = explode('+', $log['type']);
$backup_type = '';
foreach($job_job_types as $typeid) {
if (isset( $job_types[$typeid] )) {
$backup_type .= ' + ' . $job_types[$typeid];
$backup_type = '';
foreach ($job_job_types as $typeid) {
if (isset( $job_types[ $typeid ] )) {
$backup_type .= ' + ' . $job_types[ $typeid ];
}
}
@ -313,8 +318,9 @@ class MainWP_Child_Back_WP_Up {
$message = 'BackWPup backup finished (' . $backup_type . ')';
do_action( 'mainwp_reports_backwpup_backup', $message, $backup_type, $backup_time );
if ($new_lasttime_logged < $backup_time)
if ($new_lasttime_logged < $backup_time) {
$new_lasttime_logged = $backup_time;
}
}
if ($new_lasttime_logged > $lasttime_logged ) {
@ -328,13 +334,13 @@ class MainWP_Child_Back_WP_Up {
// ok
function syncOthersData( $information, $data = array() ) {
if ( isset( $data['syncBackwpupData'] ) && $data['syncBackwpupData'] ) {
try{
$lastbackup = MainWP_Helper::get_lasttime_backup('backwpup');
if ( isset( $data['syncBackwpupData'] ) && $data['syncBackwpupData'] ) {
try {
$lastbackup = MainWP_Helper::get_lasttime_backup('backwpup');
$information['syncBackwpupData'] = array(
'lastbackup' => $lastbackup
'lastbackup' => $lastbackup,
);
} catch(Exception $e) {
} catch (Exception $e) {
}
}
@ -342,7 +348,7 @@ class MainWP_Child_Back_WP_Up {
}
function get_destinations_list() {
MainWP_Helper::check_classes_exists(array('BackWPup', 'BackWPup_Option'));
MainWP_Helper::check_classes_exists(array( 'BackWPup', 'BackWPup_Option' ));
MainWP_Helper::check_methods('BackWPup', array( 'get_registered_destinations', 'get_destination' ));
MainWP_Helper::check_methods('BackWPup_Option', array( 'get_job_ids', 'get' ));
@ -355,7 +361,7 @@ class MainWP_Child_Back_WP_Up {
}
$dests = BackWPup_Option::get( $jobid, 'destinations' );
foreach ( $dests as $dest ) {
if ( ! $destinations[ $dest ][ 'class' ] ) {
if ( ! $destinations[ $dest ]['class'] ) {
continue;
}
@ -363,7 +369,7 @@ class MainWP_Child_Back_WP_Up {
if ($dest_class && method_exists($dest_class, 'file_get_list')) {
$can_do_dest = $dest_class->file_get_list( $jobid . '_' . $dest );
if ( ! empty( $can_do_dest ) ) {
$jobdest[ ] = $jobid . '_' . $dest;
$jobdest[] = $jobid . '_' . $dest;
}
}
}
@ -512,7 +518,7 @@ class MainWP_Child_Back_WP_Up {
echo '<tr title="WP_MEMORY_LIMIT"><td>' . __( 'WP memory limit', 'backwpup' ) . '</td><td>' . esc_html( WP_MEMORY_LIMIT ) . '</td></tr>';
echo '<tr title="WP_MAX_MEMORY_LIMIT"><td>' . __( 'WP maximum memory limit', 'backwpup' ) . '</td><td>' . esc_html( WP_MAX_MEMORY_LIMIT ) . '</td></tr>';
echo '<tr title=""><td>' . __( 'Memory in use', 'backwpup' ) . '</td><td>' . esc_html( size_format( @memory_get_usage( true ), 2 ) ) . '</td></tr>';
//disabled PHP functions
// disabled PHP functions
$disabled = ini_get( 'disable_functions' );
if ( ! empty( $disabled ) ) {
$disabledarry = explode( ',', $disabled );
@ -520,7 +526,7 @@ class MainWP_Child_Back_WP_Up {
echo esc_html( implode( ', ', $disabledarry ) );
echo '</td></tr>';
}
//Loaded PHP Extensions
// Loaded PHP Extensions
echo '<tr title=""><td>' . __( 'Loaded PHP Extensions:', 'backwpup' ) . '</td><td>';
$extensions = get_loaded_extensions();
sort( $extensions );
@ -532,7 +538,10 @@ class MainWP_Child_Back_WP_Up {
ob_end_clean();
return array( 'success' => 1, 'response' => $output );
return array(
'success' => 1,
'response' => $output,
);
}
protected function delete_log() {
@ -601,11 +610,17 @@ class MainWP_Child_Back_WP_Up {
if ( is_array( $file ) && $file['file'] == $backupfile ) {
$dest_class->file_delete( $dest, $backupfile );
return array( 'success' => 1, 'response' => 'DELETED' );
return array(
'success' => 1,
'response' => 'DELETED',
);
}
}
return array( 'success' => 1, 'response' => 'Not found' );
return array(
'success' => 1,
'response' => 'Not found',
);
}
protected function view_log() {
@ -615,7 +630,7 @@ class MainWP_Child_Back_WP_Up {
$log_folder = get_site_option( 'backwpup_cfg_logfolder' );
$log_folder = BackWPup_File::get_absolute_path( $log_folder );
$log_file = $log_folder . basename( $_POST['settings']['logfile'] );
$log_file = $log_folder . basename( $_POST['settings']['logfile'] );
if ( ! is_readable( $log_file ) && ! is_readable( $log_file . '.gz' ) && ! is_readable( $log_file . '.bz2' ) ) {
$output = __( 'Log file doesn\'t exists', $this->plugin_translate );
@ -635,7 +650,10 @@ class MainWP_Child_Back_WP_Up {
}
}
return array( 'success' => 1, 'response' => $output );
return array(
'success' => 1,
'response' => $output,
);
}
protected function tables() {
@ -661,7 +679,10 @@ class MainWP_Child_Back_WP_Up {
$log_folder = untrailingslashit( $log_folder );
if ( ! is_dir( $log_folder ) ) {
return array( 'success' => 1, 'response' => $array );
return array(
'success' => 1,
'response' => $array,
);
}
update_user_option( get_current_user_id(), 'backwpuplogs_per_page', 99999999 );
$output = new BackWPup_Page_Logs();
@ -687,13 +708,13 @@ class MainWP_Child_Back_WP_Up {
if ( is_null($dest_class) ) {
continue;
}
$items = $dest_class->file_get_list( $jobid . '_' . $dest );
$items = $dest_class->file_get_list( $jobid . '_' . $dest );
if ( ! empty( $items ) ) {
foreach ( $items as $item ) {
$temp_single_item = $item;
$temp_single_item['dest'] = $jobid . '_' . $dest;
$temp_single_item['timeloc'] = sprintf( __( '%1$s at %2$s', 'backwpup' ), date_i18n( get_option( 'date_format' ), $temp_single_item[ 'time' ], TRUE ), date_i18n( get_option( 'time_format' ), $temp_single_item[ 'time' ], TRUE ) );
$output->items[] = $temp_single_item;
$temp_single_item = $item;
$temp_single_item['dest'] = $jobid . '_' . $dest;
$temp_single_item['timeloc'] = sprintf( __( '%1$s at %2$s', 'backwpup' ), date_i18n( get_option( 'date_format' ), $temp_single_item['time'], true ), date_i18n( get_option( 'time_format' ), $temp_single_item['time'], true ) );
$output->items[] = $temp_single_item;
}
}
}
@ -744,7 +765,7 @@ class MainWP_Child_Back_WP_Up {
$temp_array['website_id'] = $website_id;
$array[] = $temp_array;
}
} else if ( $type == 'backups' ) {
} elseif ( $type == 'backups' ) {
$without_dupes = array();
foreach ( $output->items as $key ) {
$temp_array = $key;
@ -755,18 +776,18 @@ class MainWP_Child_Back_WP_Up {
'&',
admin_url( 'admin-ajax.php' ) . '?action=mainwp_backwpup_download_backup&type=',
), $temp_array['downloadurl'] . '&_wpnonce=' . $this->create_nonce_without_session( 'mainwp_download_backup' ) );
$temp_array['downloadurl_id'] = '/wp-admin/admin.php?page=backwpupbackups';
if ( preg_match( '/.*&jobid=([^&]+)&.*/is', $temp_array['downloadurl'], $matches )) {
if ( !empty( $matches[1] ) && is_numeric( $matches[1] ) ) {
$temp_array['downloadurl_id'] .= '&download_click_id=' . $matches[1];
}
error_log('did match' . print_r($matches, true));
if ( ! empty( $matches[1] ) && is_numeric( $matches[1] ) ) {
$temp_array['downloadurl_id'] .= '&download_click_id=' . $matches[1];
}
error_log('did match' . print_r($matches, true));
} else {
error_log('not match');
}
$temp_array['website_id'] = $website_id;
$temp_array['website_id'] = $website_id;
if ( ! isset( $without_dupes[ $temp_array['file'] ] ) ) {
$array[] = $temp_array;
@ -780,11 +801,14 @@ class MainWP_Child_Back_WP_Up {
}
}
return array( 'success' => 1, 'response' => $array );
return array(
'success' => 1,
'response' => $array,
);
}
public function init_download_backup() {
if ( ! isset( $_GET['page'] ) || $_GET['page'] !== 'backwpupbackups' || !isset( $_GET['download_click_id'] ) || empty( $_GET['download_click_id'] )) {
if ( ! isset( $_GET['page'] ) || $_GET['page'] !== 'backwpupbackups' || ! isset( $_GET['download_click_id'] ) || empty( $_GET['download_click_id'] )) {
return;
}
?>
@ -798,8 +822,8 @@ class MainWP_Child_Back_WP_Up {
</script>
<?php
}
public function download_backup() {
public function download_backup() {
if ( ! isset( $_GET['type'] ) || empty( $_GET['type'] ) || ! isset( $_GET['_wpnonce'] ) || empty( $_GET['_wpnonce'] ) ) {
die( '-1' );
}
@ -811,21 +835,21 @@ class MainWP_Child_Back_WP_Up {
if ( ! $this->verify_nonce_without_session( $_GET['_wpnonce'], 'mainwp_download_backup' ) ) {
die( '-3' );
}
$dest = strtoupper( str_replace( 'download', '', $_GET['type'] ) );
if ( ! empty( $dest ) && strstr( $_GET['type'], 'download' ) ) {
$dest_class = BackWPup::get_destination( $dest );
if ( is_null( $dest_class ) ) {
die( '-4' );
}
}
$dest_class->file_download( (int) $_GET['jobid'], $_GET['file'] );
} else {
die( '-5' );
}
}
die();
}
}
protected function create_nonce_without_session( $action = - 1 ) {
$user = wp_get_current_user();
@ -897,7 +921,10 @@ class MainWP_Child_Back_WP_Up {
ob_end_clean();
return array( 'success' => 1, 'response' => $output );
return array(
'success' => 1,
'response' => $output,
);
}
protected function backup_now() {
@ -933,7 +960,10 @@ class MainWP_Child_Back_WP_Up {
'logfile' => basename( $job_object->logfile ),
);
} else {
return array( 'success' => 1, 'response' => $output['message'] );
return array(
'success' => 1,
'response' => $output['message'],
);
}
}
}
@ -955,7 +985,10 @@ class MainWP_Child_Back_WP_Up {
if ( isset( $output['error'] ) ) {
return array( 'error' => 'Cannot abort: ' . $output['error'] );
} else {
return array( 'success' => 1, 'response' => $output['message'] );
return array(
'success' => 1,
'response' => $output['message'],
);
}
}
@ -969,12 +1002,11 @@ class MainWP_Child_Back_WP_Up {
if ( ! function_exists( 'add_screen_option' ) ) {
function add_screen_option( $option, $args = array() ) {
}
}
if ( ! class_exists( 'WP_List_Table' ) ) {
require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
}
}
@ -989,7 +1021,10 @@ class MainWP_Child_Back_WP_Up {
ob_end_clean();
return array( 'success' => 1, 'response' => $output );
return array(
'success' => 1,
'response' => $output,
);
} else {
return array( 'error' => 'Missing BackWPup_Pro_Wizard_SystemTest' );
}
@ -1014,7 +1049,7 @@ class MainWP_Child_Back_WP_Up {
// From BackWPup_Destination_Email::edit_ajax
if ( $emailmethod ) {
//do so if i'm the wp_mail to get the settings
// do so if i'm the wp_mail to get the settings
global $phpmailer;
// (Re)create it, if it's gone missing
if ( ! is_object( $phpmailer ) || ! $phpmailer instanceof PHPMailer ) {
@ -1022,10 +1057,10 @@ class MainWP_Child_Back_WP_Up {
require_once ABSPATH . WPINC . '/class-smtp.php';
$phpmailer = new PHPMailer( true );
}
//only if PHPMailer really used
// only if PHPMailer really used
if ( is_object( $phpmailer ) ) {
do_action_ref_array( 'phpmailer_init', array( &$phpmailer ) );
//get settings from PHPMailer
// get settings from PHPMailer
$emailmethod = $phpmailer->Mailer;
$emailsendmail = $phpmailer->Sendmail;
$emailhost = $phpmailer->Host;
@ -1036,7 +1071,7 @@ class MainWP_Child_Back_WP_Up {
}
}
//Generate mail with Swift Mailer
// Generate mail with Swift Mailer
if ( ! class_exists( 'Swift', false ) ) {
require BackWPup::get_plugin_data( 'plugindir' ) . '/vendor/SwiftMailer/swift_required.php';
}
@ -1088,7 +1123,10 @@ class MainWP_Child_Back_WP_Up {
}
}
return array( 'success' => 1, 'message' => $message );
return array(
'success' => 1,
'message' => $message,
);
}
protected function get_job_files() {
@ -1137,9 +1175,9 @@ class MainWP_Child_Back_WP_Up {
if ( $dir = @opendir( $main_folder_name ) ) {
while ( ( $file = readdir( $dir ) ) !== false ) {
if ( ! in_array( $file, array(
'.',
'..',
) ) && is_dir( $main_folder_name . '/' . $file ) && ! in_array( trailingslashit( $main_folder_name . '/' . $file ), mainwp_backwpup_get_exclude_dirs( $main_folder_name ) )
'.',
'..',
) ) && is_dir( $main_folder_name . '/' . $file ) && ! in_array( trailingslashit( $main_folder_name . '/' . $file ), mainwp_backwpup_get_exclude_dirs( $main_folder_name ) )
) {
$folder_size = ' (' . size_format( BackWPup_File::get_folder_size( $main_folder_name . '/' . $file ), 2 ) . ')';
@ -1154,11 +1192,18 @@ class MainWP_Child_Back_WP_Up {
@closedir( $dir );
}
$return[ $key ] = array( 'size' => $main_folder_size, 'name' => $folder, 'folders' => $return_temp );
$return[ $key ] = array(
'size' => $main_folder_size,
'name' => $folder,
'folders' => $return_temp,
);
}
}
return array( 'success' => 1, 'folders' => $return );
return array(
'success' => 1,
'folders' => $return,
);
}
protected function get_child_tables() {
@ -1213,7 +1258,10 @@ class MainWP_Child_Back_WP_Up {
if (isset($settings['job_id'])) {
$return['dbdumpexclude'] = BackWPup_Option::get( $settings['job_id'], 'dbdumpexclude' );
}
return array( 'success' => 1, 'return' => $return );
return array(
'success' => 1,
'return' => $return,
);
}
protected function insert_or_update_jobs_global() {
@ -1287,29 +1335,29 @@ class MainWP_Child_Back_WP_Up {
// From BackWPup_JobType_File::edit_form_post_save with some tweaks
public function edit_form_post_save( $post_data, $id ) {
// Parse and save files to exclude
$exclude_input = $post_data['fileexclude'];
$to_exclude_list = $exclude_input ? str_replace( array( "\r\n", "\r" ), ',', $exclude_input ) : array();
$exclude_input = $post_data['fileexclude'];
$to_exclude_list = $exclude_input ? str_replace( array( "\r\n", "\r" ), ',', $exclude_input ) : array();
$to_exclude_list and $to_exclude_list = sanitize_text_field( stripslashes( $to_exclude_list ) );
$to_exclude = $to_exclude_list ? explode( ',', $to_exclude_list ) : array();
$to_exclude_parsed = array();
$to_exclude = $to_exclude_list ? explode( ',', $to_exclude_list ) : array();
$to_exclude_parsed = array();
foreach ( $to_exclude as $key => $value ) {
$normalized = wp_normalize_path( trim( $value ) );
$normalized and $to_exclude_parsed[$key] = $normalized;
$normalized = wp_normalize_path( trim( $value ) );
$normalized and $to_exclude_parsed[ $key ] = $normalized;
}
sort( $to_exclude_parsed );
BackWPup_Option::update( $id, 'fileexclude', implode( ',', $to_exclude_parsed ) );
unset( $exclude_input, $to_exclude_list, $to_exclude, $to_exclude_parsed, $normalized );
// Parse and save folders to include
$include_input = $post_data['dirinclude'];
$include_list = $include_input ? str_replace( array( "\r\n", "\r" ), ',', $include_input ) : array();
$to_include = $include_list ? explode( ',', $include_list ) : array();
$include_input = $post_data['dirinclude'];
$include_list = $include_input ? str_replace( array( "\r\n", "\r" ), ',', $include_input ) : array();
$to_include = $include_list ? explode( ',', $include_list ) : array();
$to_include_parsed = array();
foreach ( $to_include as $key => $value ) {
$normalized = trailingslashit( wp_normalize_path( trim( $value ) ) );
$normalized and $normalized = filter_var( $normalized, FILTER_SANITIZE_URL );
$realpath = $normalized && $normalized !== '/' ? realpath( $normalized ) : false;
$realpath and $to_include_parsed[$key] = $realpath;
$normalized = trailingslashit( wp_normalize_path( trim( $value ) ) );
$normalized and $normalized = filter_var( $normalized, FILTER_SANITIZE_URL );
$realpath = $normalized && $normalized !== '/' ? realpath( $normalized ) : false;
$realpath and $to_include_parsed[ $key ] = $realpath;
}
sort( $to_include_parsed );
BackWPup_Option::update( $id, 'dirinclude', implode( ',', $to_include_parsed ) );
@ -1327,19 +1375,34 @@ class MainWP_Child_Back_WP_Up {
'backupuploads' => FILTER_VALIDATE_BOOLEAN,
);
foreach( $boolean_fields_def as $key => $value ) {
BackWPup_Option::update( $id, $key, ! empty( $post_data[$key] ) );
foreach ( $boolean_fields_def as $key => $value ) {
BackWPup_Option::update( $id, $key, ! empty( $post_data[ $key ] ) );
}
// Parse and save directories to exclude
$exclude_dirs_def = array(
'backuprootexcludedirs' => array( 'filter' => FILTER_SANITIZE_URL, 'flags' => FILTER_FORCE_ARRAY ),
'backuppluginsexcludedirs' => array( 'filter' => FILTER_SANITIZE_URL, 'flags' => FILTER_FORCE_ARRAY ),
'backupcontentexcludedirs' => array( 'filter' => FILTER_SANITIZE_URL, 'flags' => FILTER_FORCE_ARRAY ),
'backupthemesexcludedirs' => array( 'filter' => FILTER_SANITIZE_URL, 'flags' => FILTER_FORCE_ARRAY ),
'backupuploadsexcludedirs' => array( 'filter' => FILTER_SANITIZE_URL, 'flags' => FILTER_FORCE_ARRAY ),
'backuprootexcludedirs' => array(
'filter' => FILTER_SANITIZE_URL,
'flags' => FILTER_FORCE_ARRAY,
),
'backuppluginsexcludedirs' => array(
'filter' => FILTER_SANITIZE_URL,
'flags' => FILTER_FORCE_ARRAY,
),
'backupcontentexcludedirs' => array(
'filter' => FILTER_SANITIZE_URL,
'flags' => FILTER_FORCE_ARRAY,
),
'backupthemesexcludedirs' => array(
'filter' => FILTER_SANITIZE_URL,
'flags' => FILTER_FORCE_ARRAY,
),
'backupuploadsexcludedirs' => array(
'filter' => FILTER_SANITIZE_URL,
'flags' => FILTER_FORCE_ARRAY,
),
);
foreach( $exclude_dirs_def as $key => $filter ) {
$value = ! empty( $post_data[$key] ) && is_array( $post_data[$key] ) ? $post_data[$key] : array();
foreach ( $exclude_dirs_def as $key => $filter ) {
$value = ! empty( $post_data[ $key ] ) && is_array( $post_data[ $key ] ) ? $post_data[ $key ] : array();
BackWPup_Option::update( $id, $key, $value );
}
}
@ -1367,7 +1430,7 @@ class MainWP_Child_Back_WP_Up {
if ( $settings['job_id'] > 0 ) {
$job_id = intval( $settings['job_id'] );
} else {
//generate jobid if not exists
// generate jobid if not exists
$newjobid = BackWPup_Option::get_job_ids();
sort( $newjobid );
$job_id = end( $newjobid ) + 1;
@ -1376,8 +1439,8 @@ class MainWP_Child_Back_WP_Up {
update_site_option( 'backwpup_messages', array() );
if (isset($settings['value']['backupdir']) && empty($settings['value']['backupdir'])) {
$backupdir = BackWPup_Option::get( (int)$job_id, 'backupdir' );
if (!empty($backupdir)) {
$backupdir = BackWPup_Option::get( (int) $job_id, 'backupdir' );
if ( ! empty($backupdir)) {
$settings['value']['backupdir'] = $backupdir;
}
}
@ -1389,13 +1452,13 @@ class MainWP_Child_Back_WP_Up {
if ($settings['tab'] == 'jobtype-FILE') {
// to fix
$this->edit_form_post_save($settings['value'], $job_id);
//saved message
// saved message
$messages = BackWPup_Admin::get_messages();
if ( empty( $messages['error'] ) ) {
$url = BackWPup_Job::get_jobrun_url( 'runnowlink', $job_id );
BackWPup_Admin::message( sprintf( __( 'Changes for job <i>%s</i> saved.', 'backwpup' ), BackWPup_Option::get( $job_id, 'name' ) ) . ' <a href="' . network_admin_url( 'admin.php' ) . '?page=backwpupjobs">' . __( 'Jobs overview', 'backwpup' ) . '</a> | <a href="' . $url['url'] . '">' . __( 'Run now', 'backwpup' ) . '</a>' );
}
} else if ($settings['tab'] == 'dest-DROPBOX') {
} elseif ($settings['tab'] == 'dest-DROPBOX') {
unset($settings['value']); // do not save dropbox settings
BackWPup_Page_Editjob::save_post_form( $settings['tab'], $job_id );
} else {
@ -1437,7 +1500,7 @@ class MainWP_Child_Back_WP_Up {
if ( ! in_array( $key, $this->exclusions[ $settings['tab'] ] ) && strcmp( $temp_value, $val ) != 0 ) {
$changes_array[ $key ] = $temp_value;
}
} else if ( strcmp( $temp_value, $val ) != 0 ) {
} elseif ( strcmp( $temp_value, $val ) != 0 ) {
$changes_array[ $key ] = $temp_value;
}
}
@ -1473,7 +1536,7 @@ class MainWP_Child_Back_WP_Up {
update_site_option( 'backwpup_messages', array() );
$settings_views = array();
$settings_views = array();
$settings_updaters = array();
$backwpup = new BackWPup_Page_Settings($settings_views, $settings_updaters);
@ -1510,7 +1573,11 @@ class MainWP_Child_Back_WP_Up {
}
}
return array( 'success' => 1, 'changes' => $changes_array, 'message' => $return['message'] );
return array(
'success' => 1,
'changes' => $changes_array,
'message' => $return['message'],
);
}
protected function check_backwpup_messages() {
@ -1519,12 +1586,11 @@ class MainWP_Child_Back_WP_Up {
if ( isset( $message['error'] ) ) {
return array( 'error' => implode( ', ', $message['error'] ) );
} else if ( isset( $message['updated'] ) ) {
} elseif ( isset( $message['updated'] ) ) {
return array( 'message' => $message['updated'] );
} else {
return array( 'error' => 'Generic error' );
}
}
}

View file

@ -7,10 +7,10 @@ class MainWP_Child_Branding {
public $child_branding_options = null;
static function Instance() {
if ( null === MainWP_Child_Branding::$instance ) {
MainWP_Child_Branding::$instance = new MainWP_Child_Branding();
if ( null === self::$instance ) {
self::$instance = new MainWP_Child_Branding();
}
return MainWP_Child_Branding::$instance;
return self::$instance;
}
public function __construct() {
@ -20,11 +20,11 @@ class MainWP_Child_Branding {
$this->child_branding_options = $this->init_options();
}
function init_options(){
function init_options() {
$opts = get_option( 'mainwp_child_branding_settings' );
if ( !is_array( $opts ) ) {
if ( ! is_array( $opts ) ) {
// compatible with old code
$opts = array();
@ -33,20 +33,20 @@ class MainWP_Child_Branding {
$label = stripslashes( $label );
}
$opts['contact_label'] = $label;
$opts['extra_settings'] = get_option( 'mainwp_branding_extra_settings' );
$opts['contact_label'] = $label;
$opts['extra_settings'] = get_option( 'mainwp_branding_extra_settings' );
MainWP_Helper::update_option( 'mainwp_child_branding_settings', $opts );
}
if ( !isset($opts['contact_label']) || empty($opts['contact_label']) ) {
if ( ! isset($opts['contact_label']) || empty($opts['contact_label']) ) {
$opts['contact_label'] = 'Contact Support';
}
$disconnected = isset( $opts['branding_disconnected'] ) ? $opts['branding_disconnected'] : '';
$preserve_branding = isset( $opts['preserve_branding'] ) ? $opts['preserve_branding'] : '';
$disconnected = isset( $opts['branding_disconnected'] ) ? $opts['branding_disconnected'] : '';
$preserve_branding = isset( $opts['preserve_branding'] ) ? $opts['preserve_branding'] : '';
$cancelled_branding = ( $disconnected === 'yes' ) && ! $preserve_branding;
$opts['cancelled_branding'] = $cancelled_branding;
$opts['cancelled_branding'] = $cancelled_branding;
$opts['branding_preserve_title'] = '';
if ( ! $cancelled_branding ) {
@ -56,9 +56,9 @@ class MainWP_Child_Branding {
$opts['branding_preserve_title'] = stripslashes( $branding_header['name'] );
}
}
}
$opts = apply_filters( 'mainwp_child_branding_init_options', $opts );
}
$opts = apply_filters( 'mainwp_child_branding_init_options', $opts );
return $opts;
}
@ -66,8 +66,9 @@ class MainWP_Child_Branding {
$extra = array();
if (is_array($this->child_branding_options) && isset($this->child_branding_options['extra_settings'])) {
$extra = $this->child_branding_options['extra_settings'];
if (!is_array($extra))
if ( ! is_array($extra)) {
$extra = array();
}
}
return $extra;
@ -109,7 +110,7 @@ class MainWP_Child_Branding {
'mainwp_branding_remove_wp_tools',
'mainwp_branding_remove_wp_setting',
'mainwp_branding_remove_permalink',
//'mainwp_branding_plugin_header', // don't remove header
// 'mainwp_branding_plugin_header', // don't remove header
'mainwp_branding_button_contact_label',
'mainwp_branding_send_email_message',
'mainwp_branding_message_return_sender',
@ -135,7 +136,7 @@ class MainWP_Child_Branding {
'remove_wp_tools',
'remove_wp_setting',
'remove_permalink',
//'branding_header', // don't remove header
// 'branding_header', // don't remove header
'contact_label',
'email_message',
'message_return_sender',
@ -144,13 +145,12 @@ class MainWP_Child_Branding {
'branding_ext_enabled',
);
foreach($brandingOptions_empty as $opt) {
if (isset($this->child_branding_options[$opt])) {
$this->child_branding_options[$opt] = '';
foreach ($brandingOptions_empty as $opt) {
if (isset($this->child_branding_options[ $opt ])) {
$this->child_branding_options[ $opt ] = '';
}
}
MainWP_Helper::update_option( 'mainwp_child_branding_settings', $this->child_branding_options );
}
@ -171,10 +171,10 @@ class MainWP_Child_Branding {
return $information;
}
$current_settings = $this->child_branding_options;
$current_settings = $this->child_branding_options;
$current_extra_setting = $this->child_branding_options['extra_settings'];
//MainWP_Helper::update_option( 'mainwp_branding_ext_enabled', 'Y' );
// MainWP_Helper::update_option( 'mainwp_branding_ext_enabled', 'Y' );
$current_settings['branding_ext_enabled'] = 'Y';
$header = array(
@ -187,41 +187,41 @@ class MainWP_Child_Branding {
MainWP_Helper::update_option( 'mainwp_branding_preserve_branding', $settings['child_preserve_branding'], 'yes' ); // to compatible with old version of child report plugin
MainWP_Helper::update_option( 'mainwp_branding_plugin_header', $header, 'yes' ); // to compatible
// MainWP_Helper::update_option( 'mainwp_branding_support_email', $settings['child_support_email'] );
// MainWP_Helper::update_option( 'mainwp_branding_support_message', $settings['child_support_message'] );
// MainWP_Helper::update_option( 'mainwp_branding_remove_restore', $settings['child_remove_restore'] );
// MainWP_Helper::update_option( 'mainwp_branding_remove_setting', $settings['child_remove_setting'], 'yes' );
// MainWP_Helper::update_option( 'mainwp_branding_remove_server_info', $settings['child_remove_server_info'] );
// MainWP_Helper::update_option( 'mainwp_branding_remove_connection_detail', (isset($settings['child_remove_connection_detail']) ? $settings['child_remove_connection_detail'] : 0) );
// MainWP_Helper::update_option( 'mainwp_branding_remove_wp_tools', $settings['child_remove_wp_tools'], 'yes' );
// MainWP_Helper::update_option( 'mainwp_branding_remove_wp_setting', $settings['child_remove_wp_setting'], 'yes' );
// MainWP_Helper::update_option( 'mainwp_branding_remove_permalink', $settings['child_remove_permalink'], 'yes' );
// MainWP_Helper::update_option( 'mainwp_branding_button_contact_label', $settings['child_button_contact_label'], 'yes' );
// MainWP_Helper::update_option( 'mainwp_branding_send_email_message', $settings['child_send_email_message'] );
// MainWP_Helper::update_option( 'mainwp_branding_message_return_sender', $settings['child_message_return_sender'] );
// MainWP_Helper::update_option( 'mainwp_branding_submit_button_title', $settings['child_submit_button_title'] );
// if ( isset( $settings['child_disable_wp_branding'] ) && ( 'Y' === $settings['child_disable_wp_branding'] || 'N' === $settings['child_disable_wp_branding'] ) ) {
// MainWP_Helper::update_option( 'mainwp_branding_disable_wp_branding', $settings['child_disable_wp_branding'] );
// }
// MainWP_Helper::update_option( 'mainwp_branding_support_email', $settings['child_support_email'] );
// MainWP_Helper::update_option( 'mainwp_branding_support_message', $settings['child_support_message'] );
// MainWP_Helper::update_option( 'mainwp_branding_remove_restore', $settings['child_remove_restore'] );
// MainWP_Helper::update_option( 'mainwp_branding_remove_setting', $settings['child_remove_setting'], 'yes' );
// MainWP_Helper::update_option( 'mainwp_branding_remove_server_info', $settings['child_remove_server_info'] );
// MainWP_Helper::update_option( 'mainwp_branding_remove_connection_detail', (isset($settings['child_remove_connection_detail']) ? $settings['child_remove_connection_detail'] : 0) );
// MainWP_Helper::update_option( 'mainwp_branding_remove_wp_tools', $settings['child_remove_wp_tools'], 'yes' );
// MainWP_Helper::update_option( 'mainwp_branding_remove_wp_setting', $settings['child_remove_wp_setting'], 'yes' );
// MainWP_Helper::update_option( 'mainwp_branding_remove_permalink', $settings['child_remove_permalink'], 'yes' );
// MainWP_Helper::update_option( 'mainwp_branding_button_contact_label', $settings['child_button_contact_label'], 'yes' );
// MainWP_Helper::update_option( 'mainwp_branding_send_email_message', $settings['child_send_email_message'] );
// MainWP_Helper::update_option( 'mainwp_branding_message_return_sender', $settings['child_message_return_sender'] );
// MainWP_Helper::update_option( 'mainwp_branding_submit_button_title', $settings['child_submit_button_title'] );
// if ( isset( $settings['child_disable_wp_branding'] ) && ( 'Y' === $settings['child_disable_wp_branding'] || 'N' === $settings['child_disable_wp_branding'] ) ) {
// MainWP_Helper::update_option( 'mainwp_branding_disable_wp_branding', $settings['child_disable_wp_branding'] );
// }
$current_settings['preserve_branding'] = $settings['child_preserve_branding'];
$current_settings['branding_header'] = $header;
$current_settings['support_email'] = $settings['child_support_email'];
$current_settings['support_message'] = $settings['child_support_message'];
$current_settings['remove_restore'] = $settings['child_remove_restore'];
$current_settings['remove_setting'] = $settings['child_remove_setting'];
$current_settings['remove_server_info'] = $settings['child_remove_server_info'];
$current_settings['remove_connection_detail'] = isset($settings['child_remove_connection_detail']) ? $settings['child_remove_connection_detail'] : 0 ;
$current_settings['remove_wp_tools'] = $settings['child_remove_wp_tools'];
$current_settings['remove_wp_setting'] = $settings['child_remove_wp_setting'];
$current_settings['remove_permalink'] = $settings['child_remove_permalink'];
$current_settings['contact_label'] = $settings['child_button_contact_label'];
$current_settings['email_message'] = $settings['child_send_email_message'];
$current_settings['return_sender'] = $settings['child_message_return_sender'];
$current_settings['submit_button_title'] = $settings['child_submit_button_title'];
$current_settings['preserve_branding'] = $settings['child_preserve_branding'];
$current_settings['branding_header'] = $header;
$current_settings['support_email'] = $settings['child_support_email'];
$current_settings['support_message'] = $settings['child_support_message'];
$current_settings['remove_restore'] = $settings['child_remove_restore'];
$current_settings['remove_setting'] = $settings['child_remove_setting'];
$current_settings['remove_server_info'] = $settings['child_remove_server_info'];
$current_settings['remove_connection_detail'] = isset($settings['child_remove_connection_detail']) ? $settings['child_remove_connection_detail'] : 0;
$current_settings['remove_wp_tools'] = $settings['child_remove_wp_tools'];
$current_settings['remove_wp_setting'] = $settings['child_remove_wp_setting'];
$current_settings['remove_permalink'] = $settings['child_remove_permalink'];
$current_settings['contact_label'] = $settings['child_button_contact_label'];
$current_settings['email_message'] = $settings['child_send_email_message'];
$current_settings['return_sender'] = $settings['child_message_return_sender'];
$current_settings['submit_button_title'] = $settings['child_submit_button_title'];
if ( isset( $settings['child_disable_wp_branding'] ) && ( 'Y' === $settings['child_disable_wp_branding'] || 'N' === $settings['child_disable_wp_branding'] ) ) {
$current_settings['disable_wp_branding'] = $settings['child_disable_wp_branding'];
$current_settings['disable_wp_branding'] = $settings['child_disable_wp_branding'];
}
$extra_setting = array(
@ -233,8 +233,8 @@ class MainWP_Child_Branding {
'remove_widget_activity' => $settings['child_remove_widget_activity'],
'remove_widget_quick' => $settings['child_remove_widget_quick'],
'remove_widget_news' => $settings['child_remove_widget_news'],
'login_image_link' => $settings['child_login_image_link'],
'login_image_title' => $settings['child_login_image_title'],
'login_image_link' => $settings['child_login_image_link'],
'login_image_title' => $settings['child_login_image_title'],
'site_generator' => $settings['child_site_generator'],
'generator_link' => $settings['child_generator_link'],
'admin_css' => $settings['child_admin_css'],
@ -266,9 +266,12 @@ class MainWP_Child_Branding {
$extra_setting['login_image'] = array();
} else {
try {
$upload = $this->uploadImage( $settings['child_login_image_url'] ); //Upload image to WP
$upload = $this->uploadImage( $settings['child_login_image_url'] ); // Upload image to WP
if ( null !== $upload ) {
$extra_setting['login_image'] = array( 'path' => $upload['path'], 'url' => $upload['url'] );
$extra_setting['login_image'] = array(
'path' => $upload['path'],
'url' => $upload['url'],
);
if ( isset( $current_extra_setting['login_image']['path'] ) ) {
$old_file = $current_extra_setting['login_image']['path'];
if ( ! empty( $old_file ) && file_exists( $old_file ) ) {
@ -280,7 +283,7 @@ class MainWP_Child_Branding {
$information['error']['login_image'] = $e->getMessage();
}
}
} else if ( isset( $current_extra_setting['login_image'] ) ) {
} elseif ( isset( $current_extra_setting['login_image'] ) ) {
$extra_setting['login_image'] = $current_extra_setting['login_image'];
}
@ -289,9 +292,12 @@ class MainWP_Child_Branding {
$extra_setting['favico_image'] = array();
} else {
try {
$upload = $this->uploadImage( $settings['child_favico_image_url'] ); //Upload image to WP
$upload = $this->uploadImage( $settings['child_favico_image_url'] ); // Upload image to WP
if ( null !== $upload ) {
$extra_setting['favico_image'] = array( 'path' => $upload['path'], 'url' => $upload['url'] );
$extra_setting['favico_image'] = array(
'path' => $upload['path'],
'url' => $upload['url'],
);
if ( isset( $current_extra_setting['favico_image']['path'] ) ) {
$old_file = $current_extra_setting['favico_image']['path'];
if ( ! empty( $old_file ) && file_exists( $old_file ) ) {
@ -303,11 +309,11 @@ class MainWP_Child_Branding {
$information['error']['favico_image'] = $e->getMessage();
}
}
} else if ( isset( $current_extra_setting['favico_image'] ) ) {
} elseif ( isset( $current_extra_setting['favico_image'] ) ) {
$extra_setting['favico_image'] = $current_extra_setting['favico_image'];
}
//MainWP_Helper::update_option( 'mainwp_branding_extra_settings', $extra_setting, 'yes' );
// MainWP_Helper::update_option( 'mainwp_branding_extra_settings', $extra_setting, 'yes' );
$current_settings['extra_settings'] = $extra_setting;
// keep it to compatible with old version of child reports plugin
@ -316,28 +322,28 @@ class MainWP_Child_Branding {
} else {
MainWP_Helper::update_option( 'mainwp_branding_child_hide', '' );
}
//
// if ( $settings['child_show_support_button'] && ! empty( $settings['child_support_email'] ) ) {
// MainWP_Helper::update_option( 'mainwp_branding_show_support', 'T' );
// } else {
// MainWP_Helper::update_option( 'mainwp_branding_show_support', '' );
// }
//
// if ( $settings['child_show_support_button'] && ! empty( $settings['child_support_email'] ) ) {
// MainWP_Helper::update_option( 'mainwp_branding_show_support', 'T' );
// } else {
// MainWP_Helper::update_option( 'mainwp_branding_show_support', '' );
// }
// if ( $settings['child_disable_change'] ) {
// MainWP_Helper::update_option( 'mainwp_branding_disable_change', 'T' );
// } else {
// MainWP_Helper::update_option( 'mainwp_branding_disable_change', '' );
// }
// if ( $settings['child_disable_change'] ) {
// MainWP_Helper::update_option( 'mainwp_branding_disable_change', 'T' );
// } else {
// MainWP_Helper::update_option( 'mainwp_branding_disable_change', '' );
// }
// if ( $settings['child_disable_switching_theme'] ) {
// MainWP_Helper::update_option( 'mainwp_branding_disable_switching_theme', 'T' );
// } else {
// MainWP_Helper::update_option( 'mainwp_branding_disable_switching_theme', '' );
// }
// if ( $settings['child_disable_switching_theme'] ) {
// MainWP_Helper::update_option( 'mainwp_branding_disable_switching_theme', 'T' );
// } else {
// MainWP_Helper::update_option( 'mainwp_branding_disable_switching_theme', '' );
// }
$current_settings['hide'] = $settings['child_plugin_hide'] ? 'T' : '';
$current_settings['show_support'] = ( $settings['child_show_support_button'] && !empty($settings['child_support_email']) ) ? 'T' : '';
$current_settings['disable_change'] = $settings['child_disable_change'] ? 'T' : '';
$current_settings['hide'] = $settings['child_plugin_hide'] ? 'T' : '';
$current_settings['show_support'] = ( $settings['child_show_support_button'] && ! empty($settings['child_support_email']) ) ? 'T' : '';
$current_settings['disable_change'] = $settings['child_disable_change'] ? 'T' : '';
$current_settings['disable_switching_theme'] = $settings['child_disable_switching_theme'] ? 'T' : '';
MainWP_Helper::update_option( 'mainwp_child_branding_settings', $current_settings );
@ -348,10 +354,10 @@ class MainWP_Child_Branding {
}
static function uploadImage( $img_url ) {
include_once( ABSPATH . 'wp-admin/includes/file.php' ); //Contains download_url
include_once ABSPATH . 'wp-admin/includes/file.php'; // Contains download_url
global $mainWPChild;
add_filter( 'http_request_args', array( $mainWPChild, 'http_request_reject_unsafe_urls' ), 99, 2 );
//Download $img_url
// Download $img_url
$temporary_file = download_url( $img_url );
remove_filter( 'http_request_args', array( $mainWPChild, 'http_request_reject_unsafe_urls' ), 99, 2 );
@ -359,12 +365,15 @@ class MainWP_Child_Branding {
throw new Exception( 'Error: ' . $temporary_file->get_error_message() );
} else {
$upload_dir = wp_upload_dir();
$local_img_path = $upload_dir['path'] . DIRECTORY_SEPARATOR . basename( $img_url ); //Local name
$local_img_path = $upload_dir['path'] . DIRECTORY_SEPARATOR . basename( $img_url ); // Local name
$local_img_path = dirname( $local_img_path ) . '/' . wp_unique_filename( dirname( $local_img_path ), basename( $local_img_path ) );
$local_img_url = $upload_dir['url'] . '/' . basename( $local_img_path );
$moved = @rename( $temporary_file, $local_img_path );
if ( $moved ) {
return array( 'path' => $local_img_path, 'url' => $local_img_url );
return array(
'path' => $local_img_path,
'url' => $local_img_url,
);
}
}
if ( file_exists( $temporary_file ) ) {
@ -383,7 +392,7 @@ class MainWP_Child_Branding {
if (is_admin()) {
// back end
add_action( 'in_admin_footer', array( $this, 'in_admin_footer' ) );
} else if (is_user_logged_in()) {
} elseif (is_user_logged_in()) {
// front end
add_action( 'wp_after_admin_bar_render', array( $this, 'after_admin_bar_render' ));
}
@ -402,7 +411,7 @@ class MainWP_Child_Branding {
add_filter( 'mainwp_child_hide_update_notice', array( &$this, 'hide_update_notice' ) );
}
if ( !isset($opts['branding_ext_enabled']) || $opts['branding_ext_enabled'] !== 'Y' ) {
if ( ! isset($opts['branding_ext_enabled']) || $opts['branding_ext_enabled'] !== 'Y' ) {
return;
}
@ -410,29 +419,32 @@ class MainWP_Child_Branding {
if ( 'T' === $opts['disable_change']) {
// Disable the wordpress plugin update notifications
// Disable the WordPress plugin update notifications
remove_action('load-update-core.php', 'wp_update_plugins');
add_filter('pre_site_transient_update_plugins', '__return_null');
// Disable the wordpress theme update notifications
// Disable the WordPress theme update notifications
remove_action('load-update-core.php', 'wp_update_themes');
add_filter('pre_site_transient_update_themes', ( $func = function($a){ return null;} ));
add_filter('pre_site_transient_update_themes', ( $func = function( $a) {
return null;
} ));
// Disable the wordpress core update notifications
// Disable the WordPress core update notifications
add_action('after_setup_theme', 'remove_core_updates');
function remove_core_updates() {
add_action('init', ( $func = function($a){ remove_action( 'wp_version_check', 'wp_version_check' );} ), 2);
add_action('init', ( $func = function( $a) {
remove_action( 'wp_version_check', 'wp_version_check' );
} ), 2);
add_filter('pre_option_update_core', '__return_null');
add_filter('pre_site_transient_update_core', '__return_null');
}
add_action( 'admin_head', array( &$this, 'admin_head_hide_elements' ), 15 );
add_action( 'admin_menu', array($this, 'branding_redirect' ), 9);
add_action( 'admin_menu', array( $this, 'branding_redirect' ), 9);
}
// to fix
add_action( 'admin_menu', array( &$this, 'admin_menu' ) );//
if ( !isset($opts['disable_wp_branding']) || $opts['disable_wp_branding'] !== 'Y' ) {
add_action( 'admin_menu', array( &$this, 'admin_menu' ) ); if ( ! isset($opts['disable_wp_branding']) || $opts['disable_wp_branding'] !== 'Y' ) {
add_filter( 'wp_footer', array( &$this, 'branding_global_footer' ), 15 );
add_action( 'wp_dashboard_setup', array( &$this, 'custom_dashboard_widgets' ), 999 );
// branding site generator
@ -448,13 +460,13 @@ class MainWP_Child_Branding {
add_filter( 'login_headertext', array( &$this, 'custom_login_headertitle' ) );
add_action( 'wp_head', array( &$this, 'custom_favicon_frontend' ) );
if ( isset( $extra_setting['dashboard_footer'] ) && ! empty( $extra_setting['dashboard_footer'] ) ) {
//remove_filter( 'update_footer', 'core_update_footer' );
// remove_filter( 'update_footer', 'core_update_footer' );
add_filter( 'update_footer', array( &$this, 'core_update_footer' ), 14 );
add_filter( 'admin_footer_text', array( &$this, 'admin_footer_text' ), 14 );
}
if ( isset( $extra_setting['hide_nag'] ) && ! empty( $extra_setting['hide_nag'] ) ) {
add_action( 'admin_init', array($this, 'admin_init'));
add_action( 'admin_init', array( $this, 'admin_init' ));
}
add_action( 'admin_menu', array( &$this, 'remove_default_post_metaboxes' ) );
@ -470,9 +482,8 @@ class MainWP_Child_Branding {
// to fix conflict with other plugin
function admin_menu() {
$allow_contact = apply_filters('mainwp_branding_role_cap_enable_contact_form', false);
if ( $allow_contact ) {
; // ok
} else if ( !current_user_can( 'administrator' ) ) {
if ( $allow_contact ) {; // ok
} elseif ( ! current_user_can( 'administrator' ) ) {
return false;
}
@ -500,7 +511,6 @@ class MainWP_Child_Branding {
add_action( 'admin_bar_menu', array( $this, 'add_support_button_in_top_admin_bar' ), 100 );
}
}
}
function remove_default_post_metaboxes() {
@ -630,7 +640,8 @@ class MainWP_Child_Branding {
el.parentElement.innerHTML = '';
}
});
</script><?php
</script>
<?php
}
function core_update_footer() {
@ -795,24 +806,24 @@ class MainWP_Child_Branding {
public function send_support_mail() {
$email = $this->child_branding_options['support_email'];
$sub = wp_kses_post( nl2br( stripslashes( $_POST['mainwp_branding_contact_message_subject'] ) ) );
$from = trim($_POST['mainwp_branding_contact_send_from']);
$subject = !empty( $sub ) ? $sub : "MainWP - Support Contact";
$sub = wp_kses_post( nl2br( stripslashes( $_POST['mainwp_branding_contact_message_subject'] ) ) );
$from = trim($_POST['mainwp_branding_contact_send_from']);
$subject = ! empty( $sub ) ? $sub : 'MainWP - Support Contact';
$content = wp_kses_post( nl2br( stripslashes( $_POST['mainwp_branding_contact_message_content'] ) ) );
$mail = $headers = '';
$mail = $headers = '';
if ( ! empty( $_POST['mainwp_branding_contact_message_content'] ) && ! empty( $email ) ) {
global $current_user;
$headers .= "Content-Type: text/html;charset=utf-8\r\n";
if (!empty($from))
$headers .= "From: \"" . $from . "\" <" . $from . ">\r\n";
if ( ! empty($from)) {
$headers .= 'From: "' . $from . '" <' . $from . ">\r\n";
}
$mail .= "<p>Support Email from: <a href='" . site_url() . "'>" . site_url() . "</a></p>\r\n\r\n";
$mail .= "<p>Sent from WordPress page: " . ( ! empty( $_POST["mainwp_branding_send_from_page"] ) ? "<a href='" . esc_url( $_POST["mainwp_branding_send_from_page"] ) . "'>" . esc_url( $_POST["mainwp_branding_send_from_page"] ) . "</a></p>\r\n\r\n" : "" );
$mail .= "<p>Client Email: " . $current_user->user_email . " </p>\r\n\r\n";
$mail .= '<p>Sent from WordPress page: ' . ( ! empty( $_POST['mainwp_branding_send_from_page'] ) ? "<a href='" . esc_url( $_POST['mainwp_branding_send_from_page'] ) . "'>" . esc_url( $_POST['mainwp_branding_send_from_page'] ) . "</a></p>\r\n\r\n" : '' );
$mail .= '<p>Client Email: ' . $current_user->user_email . " </p>\r\n\r\n";
$mail .= "<p>Support Text:</p>\r\n\r\n";
$mail .= "<p>" . $content . "</p>\r\n\r\n";
$mail .= '<p>' . $content . "</p>\r\n\r\n";
if ( @wp_mail( $email, $subject, $mail, $headers ) ) {
;
if ( @wp_mail( $email, $subject, $mail, $headers ) ) {;
}
return true;
@ -860,7 +871,8 @@ class MainWP_Child_Branding {
}
?>
<div
class="mainwp_info-box-yellow"><?php echo esc_html( $send_email_message ) . "&nbsp;&nbsp" . $back_link; ?></div><?php
class="mainwp_info-box-yellow"><?php echo esc_html( $send_email_message ) . '&nbsp;&nbsp' . $back_link; ?></div>
<?php
} else {
$from_page = '';
if ( isset( $_GET['from_page'] ) ) {
@ -873,7 +885,7 @@ class MainWP_Child_Branding {
$support_message = $opts['support_message'];
$support_message = nl2br( stripslashes( $support_message ) );
$from_email = $current_user ? $current_user->user_email : '';
$from_email = $current_user ? $current_user->user_email : '';
?>
<form action="" method="post">
<div style="width: 99%;">
@ -890,12 +902,12 @@ class MainWP_Child_Branding {
<?php
remove_editor_styles(); // stop custom theme styling interfering with the editor
wp_editor( '', 'mainwp_branding_contact_message_content', array(
'textarea_name' => 'mainwp_branding_contact_message_content',
'textarea_rows' => 10,
'teeny' => true,
'wpautop' => true,
'media_buttons' => false,
)
'textarea_name' => 'mainwp_branding_contact_message_content',
'textarea_rows' => 10,
'teeny' => true,
'wpautop' => true,
'media_buttons' => false,
)
);
?>
</div>
@ -913,7 +925,8 @@ class MainWP_Child_Branding {
value="<?php echo esc_url( $from_page ); ?>"/>
<input type="hidden" name="_wpnonce" value="<?php echo esc_attr( wp_create_nonce( '_contactNonce' ) ); ?>"/>
</form>
<?php }
<?php
}
}
/**
@ -921,9 +934,8 @@ class MainWP_Child_Branding {
*/
public function add_support_button_in_top_admin_bar( $wp_admin_bar ) {
$allow_contact = apply_filters('mainwp_branding_role_cap_enable_contact_form', false);
if ( $allow_contact ) {
; // ok
} else if ( !current_user_can( 'administrator' ) ) {
if ( $allow_contact ) {; // ok
} elseif ( ! current_user_can( 'administrator' ) ) {
return false;
}
@ -951,13 +963,13 @@ class MainWP_Child_Branding {
public function is_branding() {
$opts = $this->child_branding_options;
if (!isset($opts['branding_ext_enabled']) || $opts['branding_ext_enabled'] !== 'Y') {
if ( ! isset($opts['branding_ext_enabled']) || $opts['branding_ext_enabled'] !== 'Y') {
return false;
}
$is_hide = isset( $opts['hide'] ) ? $opts['hide'] : '';
$is_hide = isset( $opts['hide'] ) ? $opts['hide'] : '';
$cancelled_branding = $opts['cancelled_branding'];
$branding_header = isset( $opts['branding_header'] ) ? $opts['branding_header'] : '';
$branding_header = isset( $opts['branding_header'] ) ? $opts['branding_header'] : '';
if ( $cancelled_branding ) {
return false;
@ -966,7 +978,7 @@ class MainWP_Child_Branding {
if ( 'T' === $is_hide ) {
return true;
}
if ( is_array( $branding_header ) && !empty( $branding_header['name'] ) ) {
if ( is_array( $branding_header ) && ! empty( $branding_header['name'] ) ) {
return true;
}
return false;
@ -985,30 +997,31 @@ class MainWP_Child_Branding {
}
public function save_branding_options( $name, $val ) {
$this->child_branding_options[$name] = $val;
$this->child_branding_options[ $name ] = $val;
MainWP_Helper::update_option( 'mainwp_child_branding_settings', $this->child_branding_options );
}
public function after_admin_bar_render() {
$hide_slugs = apply_filters('mainwp_child_hide_update_notice' , array());
$hide_slugs = apply_filters('mainwp_child_hide_update_notice', array());
if (!is_array($hide_slugs))
if ( ! is_array($hide_slugs)) {
$hide_slugs = array();
}
if (count($hide_slugs) == 0) {
return;
}
if (!function_exists('get_plugin_updates')) {
include_once( ABSPATH . '/wp-admin/includes/update.php' );
if ( ! function_exists('get_plugin_updates')) {
include_once ABSPATH . '/wp-admin/includes/update.php';
}
$count_hide = 0;
$updates = get_plugin_updates();
if (is_array($updates)) {
foreach($updates as $slug => $data) {
foreach ($updates as $slug => $data) {
if (in_array($slug, $hide_slugs)) {
$count_hide++;
}
@ -1037,22 +1050,23 @@ class MainWP_Child_Branding {
$adminBarUpdates.textContent = itemCount;
}
});
</script><?php
</script>
<?php
}
public function in_admin_footer() {
$hide_slugs = apply_filters('mainwp_child_hide_update_notice' , array());
$hide_slugs = apply_filters('mainwp_child_hide_update_notice', array());
if (!is_array($hide_slugs))
if ( ! is_array($hide_slugs)) {
$hide_slugs = array();
}
$count_hide = 0;
$updates = get_plugin_updates();
if (is_array($updates)) {
foreach($updates as $slug => $data) {
foreach ($updates as $slug => $data) {
if (in_array($slug, $hide_slugs)) {
$count_hide++;
}
@ -1115,7 +1129,8 @@ class MainWP_Child_Branding {
});
}
});
</script><?php
</script>
<?php
}
public function branding_map_meta_cap( $caps, $cap, $user_id, $args ) {
@ -1131,9 +1146,9 @@ class MainWP_Child_Branding {
public function modify_plugin_header( $plugins ) {
$opts = $this->child_branding_options;
if ( is_array($opts) ) {
$is_hide = isset( $opts['hide'] ) ? $opts['hide'] : '';
$is_hide = isset( $opts['hide'] ) ? $opts['hide'] : '';
$cancelled_branding = $opts['cancelled_branding'];
$branding_header = isset( $opts['branding_header'] ) ? $opts['branding_header'] : '';
$branding_header = isset( $opts['branding_header'] ) ? $opts['branding_header'] : '';
if ( $cancelled_branding ) {
return $plugins;
@ -1170,7 +1185,7 @@ class MainWP_Child_Branding {
return $value;
}
if (! MainWP_Helper::is_screen_with_update()) {
if ( ! MainWP_Helper::is_screen_with_update()) {
return $value;
}

View file

@ -1,7 +1,7 @@
<?php
class MainWP_Child_DB {
//Support old & new versions of wordpress (3.9+)
// Support old & new versions of WordPress (3.9+)
public static function use_mysqli() {
/** @var $wpdb wpdb */
if ( ! function_exists( 'mysqli_connect' ) ) {
@ -90,9 +90,9 @@ class MainWP_Child_DB {
/** @var $wpdb wpdb */
global $wpdb;
$rows = MainWP_Child_DB::_query( 'SHOW table STATUS', $wpdb->dbh );
$rows = self::_query( 'SHOW table STATUS', $wpdb->dbh );
$size = 0;
while ( $row = MainWP_Child_DB::fetch_array( $rows ) ) {
while ( $row = self::fetch_array( $rows ) ) {
$size += $row['Data_length'];
}

View file

@ -16,36 +16,37 @@
*/
class MainWP_Child_iThemes_Security {
public static $instance = null;
public static $instance = null;
public $is_plugin_installed = false;
static function Instance() {
if ( null === MainWP_Child_iThemes_Security::$instance ) {
MainWP_Child_iThemes_Security::$instance = new MainWP_Child_iThemes_Security();
if ( null === self::$instance ) {
self::$instance = new MainWP_Child_iThemes_Security();
}
return MainWP_Child_iThemes_Security::$instance;
return self::$instance;
}
public function __construct() {
require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
require_once ABSPATH . 'wp-admin/includes/plugin.php';
if ( is_plugin_active( 'better-wp-security/better-wp-security.php') || is_plugin_active( 'ithemes-security-pro/ithemes-security-pro.php' ) ) {
$this->is_plugin_installed = true;
}
if (!$this->is_plugin_installed)
if ( ! $this->is_plugin_installed) {
return;
}
add_filter( 'mainwp-site-sync-others-data', array( $this, 'syncOthersData' ), 10, 2 );
}
// ok
function syncOthersData( $information, $data = array() ) {
if ( is_array( $data ) && isset( $data['ithemeExtActivated'] ) && ( 'yes' === $data['ithemeExtActivated'] ) ) {
try{
try {
$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());
}
}
@ -54,7 +55,7 @@ class MainWP_Child_iThemes_Security {
public function action() {
$information = array();
if ( ! class_exists( 'ITSEC_Core' ) || !class_exists('ITSEC_Modules')) {
if ( ! class_exists( 'ITSEC_Core' ) || ! class_exists('ITSEC_Modules')) {
$information['error'] = 'NO_ITHEME';
MainWP_Helper::write( $information );
}
@ -63,7 +64,6 @@ class MainWP_Child_iThemes_Security {
$mainwp_itsec_modules_path = ITSEC_Core::get_core_dir() . '/modules/';
if ( isset( $_POST['mwp_action'] ) ) {
switch ( $_POST['mwp_action'] ) {
case 'set_showhide':
@ -131,15 +131,16 @@ class MainWP_Child_iThemes_Security {
}
public function ithemes_init() {
if (!$this->is_plugin_installed)
if ( ! $this->is_plugin_installed) {
return;
}
if ( get_option( 'mainwp_ithemes_hide_plugin' ) === 'hide' ) {
add_filter( 'all_plugins', array( $this, 'all_plugins' ) );
add_action( 'admin_menu', array( $this, 'remove_menu' ) );
add_action( 'admin_init', array( $this, 'admin_init' ) );
add_action( 'admin_head', array( &$this, 'custom_admin_css' ) );
if ( isset($_GET['page']) && ($_GET['page'] == 'itsec' || $_GET['page'] == 'itsec-security-check') ) {
if ( isset($_GET['page']) && ( $_GET['page'] == 'itsec' || $_GET['page'] == 'itsec-security-check' ) ) {
wp_redirect( get_option( 'siteurl' ) . '/wp-admin/index.php' );
exit();
}
@ -178,7 +179,7 @@ class MainWP_Child_iThemes_Security {
function save_settings() {
if ( ! class_exists( 'ITSEC_Lib' ) ) {
require( ITSEC_Core::get_core_dir() . '/core/class-itsec-lib.php' );
require ITSEC_Core::get_core_dir() . '/core/class-itsec-lib.php';
}
$_itsec_modules = array(
@ -193,73 +194,74 @@ class MainWP_Child_iThemes_Security {
'404-detection',
'network-brute-force',
'ssl',
//'strong-passwords',
// 'strong-passwords',
'password-requirements',
'system-tweaks',
'wordpress-tweaks',
'multisite-tweaks',
'notification-center',
//'salts',
//'content-directory',
// 'salts',
// 'content-directory',
);
$require_permalinks = false;
$updated = false;
$errors = array();
$nbf_settings = array();
$updated = false;
$errors = array();
$nbf_settings = array();
$update_settings = maybe_unserialize( base64_decode( $_POST['settings'] ) );
$update_settings = maybe_unserialize( base64_decode( $_POST['settings'] ) );
foreach($update_settings as $module => $settings) {
foreach ($update_settings as $module => $settings) {
$do_not_save = false;
if (in_array($module, $_itsec_modules)) {
if ($module == 'wordpress-salts') {
$settings['last_generated'] = ITSEC_Modules::get_setting( $module, 'last_generated' ); // not update
} else if ($module == 'global') {
$keep_olds = array( 'did_upgrade', 'log_info', 'show_new_dashboard_notice', 'show_security_check' , 'nginx_file' );
foreach($keep_olds as $key) {
$settings[$key] = ITSEC_Modules::get_setting( $module, $key ); // not update
} elseif ($module == 'global') {
$keep_olds = array( 'did_upgrade', 'log_info', 'show_new_dashboard_notice', 'show_security_check', 'nginx_file' );
foreach ($keep_olds as $key) {
$settings[ $key ] = ITSEC_Modules::get_setting( $module, $key ); // not update
}
if (!isset($settings['log_location']) || empty($settings['log_location']) ) {
if ( ! isset($settings['log_location']) || empty($settings['log_location']) ) {
$settings['log_location'] = ITSEC_Modules::get_setting( $module, 'log_location' );
} else {
$result = $this->validate_directory('log_location', $settings['log_location']);
if ($result !== true) {
$errors[] = $result;
$errors[] = $result;
$settings['log_location'] = ITSEC_Modules::get_setting( $module, 'log_location' ); // no change
}
}
} else if ($module == 'backup') {
if (!isset($settings['location']) || empty($settings['location']) ) {
} elseif ($module == 'backup') {
if ( ! isset($settings['location']) || empty($settings['location']) ) {
$settings['location'] = ITSEC_Modules::get_setting( $module, 'location' );
} else {
$result = $this->validate_directory('location', $settings['location']);
if ($result !== true) {
$errors[] = $result;
$errors[] = $result;
$settings['location'] = ITSEC_Modules::get_setting( $module, 'location' ); // no change
}
}
if (!isset($settings['exclude']) ) {
$settings['exclude'] = ITSEC_Modules::get_setting( $module, 'exclude' );;
if ( ! isset($settings['exclude']) ) {
$settings['exclude'] = ITSEC_Modules::get_setting( $module, 'exclude' );
}
} else if ($module == 'hide-backend') {
if (isset($settings['enabled']) && !empty($settings['enabled'])) {
} elseif ($module == 'hide-backend') {
if (isset($settings['enabled']) && ! empty($settings['enabled'])) {
$permalink_structure = get_option( 'permalink_structure', false );
if ( empty( $permalink_structure ) && ! is_multisite() ) {
$errors[] = __( 'You must change <strong>WordPress permalinks</strong> to a setting other than "Plain" in order to use "Hide Backend" feature.', 'better-wp-security' );
$errors[] = __( 'You must change <strong>WordPress permalinks</strong> to a setting other than "Plain" in order to use "Hide Backend" feature.', 'better-wp-security' );
$require_permalinks = true;
$do_not_save = true;
$do_not_save = true;
}
}
} else if ($module == 'network-brute-force') {
} elseif ($module == 'network-brute-force') {
if ( isset( $settings['email'] ) ) {
$result = $this->activate_api_key($settings);
if ($result === false) {
$nbf_settings = $settings;
$errors[] = 'Error: Active iThemes Network Brute Force Protection Api Key';
$errors[] = 'Error: Active iThemes Network Brute Force Protection Api Key';
} else {
$nbf_settings = $result;
}
@ -268,36 +270,36 @@ class MainWP_Child_iThemes_Security {
// update 'enable_ban' field only
if (isset($settings['enable_ban'])) {
$previous_settings['enable_ban'] = $settings['enable_ban'];
$nbf_settings = $previous_settings;
$nbf_settings = $previous_settings;
} else {
$do_not_save = true;
$do_not_save = true;
$nbf_settings = $previous_settings;
}
}
$settings = $nbf_settings;
} else if ($module == 'notification-center') {
} elseif ($module == 'notification-center') {
$current_settings = ITSEC_Modules::get_settings( $module );
if (isset($settings['notifications'])) {
$update_fields = array( 'schedule', 'enabled', 'subject');
$update_fields = array( 'schedule', 'enabled', 'subject' );
if (isset($_POST['is_individual']) && $_POST['is_individual']) {
$update_fields = array_merge($update_fields, array('user_list', 'email_list'));
$update_fields = array_merge($update_fields, array( 'user_list', 'email_list' ));
}
foreach ($settings['notifications'] as $key => $val) {
foreach ($update_fields as $field) {
if(isset($val[$field])) {
$current_settings['notifications'][$key][$field] = $val[$field];
if (isset($val[ $field ])) {
$current_settings['notifications'][ $key ][ $field ] = $val[ $field ];
}
}
}
$updated = true;
$updated = true;
ITSEC_Modules::set_settings( $module, $current_settings );
}
continue;
}
if ( !$do_not_save ) {
if ( ! $do_not_save ) {
ITSEC_Modules::set_settings( $module, $settings );
$updated = true;
$updated = true;
}
}
}
@ -305,33 +307,33 @@ class MainWP_Child_iThemes_Security {
if ( isset( $update_settings['itsec_active_modules'] ) ) {
$current_val = get_site_option( 'itsec_active_modules', array() );
foreach ($update_settings['itsec_active_modules'] as $mod => $val) {
$current_val[$mod] = $val;
$current_val[ $mod ] = $val;
}
update_site_option( 'itsec_active_modules', $current_val );
}
require_once( ITSEC_Core::get_core_dir() . '/lib/class-itsec-lib-config-file.php' );
require_once ITSEC_Core::get_core_dir() . '/lib/class-itsec-lib-config-file.php';
$values = array(
'permalink_structure' => get_option( 'permalink_structure' ),
'is_multisite' => is_multisite() ? 1 : 0,
'users_can_register' => get_site_option( 'users_can_register' ) ? 1 : 0,
'server_nginx' => ( ITSEC_Lib::get_server() === 'nginx' ) ? 1 : 0,
'has_ssl' => ITSEC_Lib::get_ssl_support_probability(),
'jquery_version' => ITSEC_Modules::get_setting( 'wordpress-tweaks', 'jquery_version' ),
'server_rules' => ITSEC_Lib_Config_File::get_server_config(),
'config_rules' => ITSEC_Lib_Config_File::get_wp_config(),
'has_ssl' => ITSEC_Lib::get_ssl_support_probability(),
'jquery_version' => ITSEC_Modules::get_setting( 'wordpress-tweaks', 'jquery_version' ),
'server_rules' => ITSEC_Lib_Config_File::get_server_config(),
'config_rules' => ITSEC_Lib_Config_File::get_wp_config(),
'lockouts_host' => $this->get_lockouts( 'host', true ),
'lockouts_user' => $this->get_lockouts( 'user', true ),
'lockouts_username' => $this->get_lockouts( 'username', true ),
'default_log_location' => ITSEC_Modules::get_default( 'global', 'log_location' ),
'default_location' => ITSEC_Modules::get_default( 'backup', 'location' ),
'excludable_tables' => $this->get_excludable_tables(),
'users_and_roles' => $this->get_available_admin_users_and_roles()
'default_log_location' => ITSEC_Modules::get_default( 'global', 'log_location' ),
'default_location' => ITSEC_Modules::get_default( 'backup', 'location' ),
'excludable_tables' => $this->get_excludable_tables(),
'users_and_roles' => $this->get_available_admin_users_and_roles(),
);
$return = array(
'site_status' => $values
'site_status' => $values,
);
if ($require_permalinks) {
@ -340,44 +342,45 @@ class MainWP_Child_iThemes_Security {
$return['nbf_settings'] = $nbf_settings;
if (!empty($errors)) {
if ( ! empty($errors)) {
$return['extra_message'] = $errors;
}
if ($updated)
if ($updated) {
$return['result'] = 'success';
else
} else {
$return['error'] = __('Not Updated', 'mainwp-child' );
}
return $return;
}
public static function activate_network_brute_force() {
$data = maybe_unserialize( base64_decode( $_POST['data'] ) );
$data = maybe_unserialize( base64_decode( $_POST['data'] ) );
$information = array();
if (is_array($data)) {
$settings = ITSEC_Modules::get_settings( 'network-brute-force' );
$settings['email'] = $data['email'];
$settings = ITSEC_Modules::get_settings( 'network-brute-force' );
$settings['email'] = $data['email'];
$settings['updates_optin'] = $data['updates_optin'];
$settings['api_nag'] = false;
$results = ITSEC_Modules::set_settings( 'network-brute-force', $settings );
$settings['api_nag'] = false;
$results = ITSEC_Modules::set_settings( 'network-brute-force', $settings );
if ( is_wp_error( $results ) ) {
$information['error'] = 'Error: Active iThemes Network Brute Force Protection Api Key';
} else if ( $results['saved'] ) {
} elseif ( $results['saved'] ) {
ITSEC_Modules::activate( 'network-brute-force' );
$nbf_settings = ITSEC_Modules::get_settings( 'network-brute-force' );
// ITSEC_Response::set_response( '<p>' . __( 'Your site is now using Network Brute Force Protection.', 'better-wp-security' ) . '</p>' );
// ITSEC_Response::set_response( '<p>' . __( 'Your site is now using Network Brute Force Protection.', 'better-wp-security' ) . '</p>' );
}
}
if ($nbf_settings !== null) {
$information['nbf_settings'] = $nbf_settings;
$information['result'] = 'success';
$information['result'] = 'success';
}
return $information;
}
private function validate_directory($name, $folder) {
require_once( ITSEC_Core::get_core_dir() . 'lib/class-itsec-lib-directory.php' );
private function validate_directory( $name, $folder) {
require_once ITSEC_Core::get_core_dir() . 'lib/class-itsec-lib-directory.php';
$error = null;
if ( ! ITSEC_Lib_Directory::is_dir( $folder ) ) {
$result = ITSEC_Lib_Directory::create( $folder );
@ -399,24 +402,24 @@ class MainWP_Child_iThemes_Security {
}
}
private function activate_api_key($settings) {
private function activate_api_key( $settings) {
global $mainwp_itsec_modules_path;
require_once ( $mainwp_itsec_modules_path . 'ipcheck/utilities.php' );
require_once $mainwp_itsec_modules_path . 'ipcheck/utilities.php';
$key = ITSEC_Network_Brute_Force_Utilities::get_api_key( $settings['email'], $settings['updates_optin'] );
if ( is_wp_error( $key ) ) {
return false;
// $this->set_can_save( false );
// $this->add_error( $key );
// $this->set_can_save( false );
// $this->add_error( $key );
} else {
$secret = ITSEC_Network_Brute_Force_Utilities::activate_api_key( $key );
if ( is_wp_error( $secret ) ) {
return false;
// $this->set_can_save( false );
// $this->add_error( $secret );
// $this->set_can_save( false );
// $this->add_error( $secret );
} else {
$settings['api_key'] = $key;
$settings['api_key'] = $key;
$settings['api_secret'] = $secret;
$settings['api_nag'] = false;
@ -483,7 +486,6 @@ class MainWP_Child_iThemes_Security {
return $response;
}
}
function whitelist_release() {
@ -496,15 +498,15 @@ class MainWP_Child_iThemes_Security {
global $itsec_backup, $mainwp_itsec_modules_path;
if ( ! isset( $itsec_backup ) ) {
require_once ( $mainwp_itsec_modules_path . 'backup/class-itsec-backup.php' );
require_once $mainwp_itsec_modules_path . 'backup/class-itsec-backup.php';
$itsec_backup = new ITSEC_Backup();
$itsec_backup->run();
}
$return = array();
$return = array();
$str_error = '';
$result = $itsec_backup->do_backup( true );
$result = $itsec_backup->do_backup( true );
if ( is_wp_error( $result ) ) {
$errors = ITSEC_Response::get_error_strings( $result );
@ -512,14 +514,14 @@ class MainWP_Child_iThemes_Security {
foreach ( $errors as $error ) {
$str_error .= $error . '<br />';
}
} else if ( is_string( $result ) ) {
$return['result'] = 'success';
} elseif ( is_string( $result ) ) {
$return['result'] = 'success';
$return['message'] = $result;
} else {
$str_error = sprintf( __( 'The backup request returned an unexpected response. It returned a response of type <code>%1$s</code>.', 'better-wp-security' ), gettype( $result ) ) ;
$str_error = sprintf( __( 'The backup request returned an unexpected response. It returned a response of type <code>%1$s</code>.', 'better-wp-security' ), gettype( $result ) );
}
if (!empty($str_error)) {
if ( ! empty($str_error)) {
$return['error'] = $str_error;
}
@ -530,9 +532,9 @@ class MainWP_Child_iThemes_Security {
private function wordpress_salts() {
global $mainwp_itsec_modules_path;
if ( ! class_exists( 'ITSEC_WordPress_Salts_Utilities' ) ) {
require( $mainwp_itsec_modules_path . 'salts/utilities.php' );
require $mainwp_itsec_modules_path . 'salts/utilities.php';
}
$result = ITSEC_WordPress_Salts_Utilities::generate_new_salts();
$result = ITSEC_WordPress_Salts_Utilities::generate_new_salts();
$str_error = '';
if ( is_wp_error( $result ) ) {
$errors = ITSEC_Response::get_error_strings( $result );
@ -541,19 +543,19 @@ class MainWP_Child_iThemes_Security {
$str_error .= $error . '<br />';
}
} else {
$return['result'] = 'success';
$return['message'] = __( 'The WordPress salts were successfully regenerated.', 'better-wp-security' ) ;
$last_generated = ITSEC_Core::get_current_time_gmt();
$return['result'] = 'success';
$return['message'] = __( 'The WordPress salts were successfully regenerated.', 'better-wp-security' );
$last_generated = ITSEC_Core::get_current_time_gmt();
ITSEC_Modules::set_setting( 'wordpress-salts', 'last_generated', $last_generated );
}
if (!empty($str_error)) {
if ( ! empty($str_error)) {
$return['error'] = $str_error;
}
return $return;
}
private function file_permissions() {
require_once( ITSEC_Core::get_core_dir() . '/lib/class-itsec-lib-config-file.php' );
require_once ITSEC_Core::get_core_dir() . '/lib/class-itsec-lib-config-file.php';
$wp_upload_dir = ITSEC_Core::get_wp_upload_dir();
@ -584,7 +586,7 @@ class MainWP_Child_iThemes_Security {
),
array(
WP_PLUGIN_DIR,
0755
0755,
),
array(
$wp_upload_dir['basedir'],
@ -600,7 +602,6 @@ class MainWP_Child_iThemes_Security {
),
);
$rows = array();
foreach ( $path_data as $path ) {
@ -619,7 +620,7 @@ class MainWP_Child_iThemes_Security {
$row[] = sprintf( '%o', $suggested_permissions );
$permissions = fileperms( $path ) & 0777;
$row[] = sprintf( '%o', $permissions );
$row[] = sprintf( '%o', $permissions );
if ( ! $permissions || $permissions != $suggested_permissions ) {
$row[] = __( 'WARNING', 'better-wp-security' );
@ -632,10 +633,9 @@ class MainWP_Child_iThemes_Security {
$rows[] = $row;
}
$class = 'entry-row';
ob_start();
?>
ob_start();
?>
<p><input type="button" id="itsec-file-permissions-reload_file_permissions" name="file-permissions[reload_file_permissions]" class="button-primary itsec-reload-module" value="<?php _e('Reload File Permissions Details', 'mainwp-child'); ?>"></p>
<table class="widefat">
<thead>
@ -668,19 +668,19 @@ class MainWP_Child_iThemes_Security {
</tbody>
</table>
<br />
<?php
<?php
$html = ob_get_clean();
return array('html' => $html);
return array( 'html' => $html );
}
public function file_change() {
global $mainwp_itsec_modules_path;
if ( ! class_exists( 'ITSEC_File_Change_Scanner' ) ) {
require_once( $mainwp_itsec_modules_path . 'file-change/scanner.php' );
require_once $mainwp_itsec_modules_path . 'file-change/scanner.php';
}
$result = ITSEC_File_Change_Scanner::run_scan( false );
if ($result === false || $result === true || $result === -1) {
$return['result'] = 'success';
$return['result'] = 'success';
$return['scan_result'] = $result;
}
return $return;
@ -690,17 +690,17 @@ class MainWP_Child_iThemes_Security {
$settings = $_POST['settings'];
if (!is_array($settings))
if ( ! is_array($settings)) {
$settings = array();
}
$new_username = isset( $settings['new_username'] ) ? $settings['new_username'] : '';
$change_id = isset( $settings['change_id'] ) && $settings['change_id'] ? true : false;
$new_username = isset( $settings['new_username'] ) ? $settings['new_username'] : '';
$change_id = isset( $settings['change_id'] ) && $settings['change_id'] ? true : false;
//load utility functions
// load utility functions
if ( ! class_exists( 'ITSEC_Lib' ) ) {
global $itsec_globals;
require( ITSEC_Core::get_core_dir() . '/core/class-itsec-lib.php' );
require ITSEC_Core::get_core_dir() . '/core/class-itsec-lib.php';
}
$username_exists = username_exists( 'admin' );
@ -710,13 +710,12 @@ class MainWP_Child_iThemes_Security {
global $current_user;
if ( ! $username_exists ) {
$msg = __( 'Admin user already changes.', 'mainwp-child' );
} else if ($current_user->user_login == 'admin') {
} elseif ($current_user->user_login == 'admin') {
$return['result'] = 'CHILD_ADMIN';
return $return;
}
}
if ( true === $change_id && ! $user_id_exists ) {
if ( ! empty( $msg ) ) {
$msg .= '<br/>';
@ -724,16 +723,16 @@ class MainWP_Child_iThemes_Security {
$msg .= __( 'Admin user ID already changes.', 'mainwp-child' );
}
// if ( $change_id ) {
// $user = get_user_by( 'login', $new_username );
// if ( $user && 1 === (int) $user->ID ) {
// $return['result'] = 'CHILD_ADMIN';
// return $return;
// }
// }
// if ( $change_id ) {
// $user = get_user_by( 'login', $new_username );
// if ( $user && 1 === (int) $user->ID ) {
// $return['result'] = 'CHILD_ADMIN';
// return $return;
// }
// }
$admin_success = true;
$return = array();
$return = array();
if ( strlen( $new_username ) >= 1 && $username_exists ) {
$admin_success = $this->change_admin_user( $new_username, $change_id );
@ -756,95 +755,94 @@ class MainWP_Child_iThemes_Security {
$itsec_files = ITSEC_Core::get_itsec_files();
// do not need to check this
//if ( $itsec_files->get_file_lock( 'admin_user' ) ) { //make sure it isn't already running
// if ( $itsec_files->get_file_lock( 'admin_user' ) ) { //make sure it isn't already running
//sanitize the username
// sanitize the username
$new_user = sanitize_text_field( $username );
//Get the full user object
// Get the full user object
$user_object = get_user_by( 'id', '1' );
if ( null !== $username && validate_username( $new_user ) && false === username_exists( $new_user ) ) { //there is a valid username to change
if ( null !== $username && validate_username( $new_user ) && false === username_exists( $new_user ) ) { // there is a valid username to change
if ( true === $id ) { //we're changing the id too so we'll set the username
if ( true === $id ) { // we're changing the id too so we'll set the username
$user_login = $new_user;
$user_login = $new_user;
} else { // we're only changing the username
} else { // we're only changing the username
//query main user table
$wpdb->query( "UPDATE `" . $wpdb->users . "` SET user_login = '" . esc_sql( $new_user ) . "' WHERE user_login='admin';" );
// query main user table
$wpdb->query( 'UPDATE `' . $wpdb->users . "` SET user_login = '" . esc_sql( $new_user ) . "' WHERE user_login='admin';" );
if ( is_multisite() ) { //process sitemeta if we're in a multi-site situation
$oldAdmins = $wpdb->get_var( 'SELECT meta_value FROM `' . $wpdb->sitemeta . "` WHERE meta_key = 'site_admins'" );
$newAdmins = str_replace( '5:"admin"', strlen( $new_user ) . ':"' . esc_sql( $new_user ) . '"', $oldAdmins );
$wpdb->query( $wpdb->prepare( 'UPDATE `' . $wpdb->sitemeta . "` SET meta_value = %s WHERE meta_key = 'site_admins'", $newAdmins ) );
}
wp_clear_auth_cookie();
$itsec_files->release_file_lock( 'admin_user' );
return true;
}
} elseif ( null !== $username ) { //username didn't validate
$itsec_files->release_file_lock( 'admin_user' );
return false;
} else { //only changing the id
$user_login = $user_object->user_login;
}
if ( true === $id ) { //change the user id
$wpdb->query( 'DELETE FROM `' . $wpdb->users . '` WHERE ID = 1;' );
$wpdb->insert( $wpdb->users, array(
'user_login' => $user_login,
'user_pass' => $user_object->user_pass,
'user_nicename' => $user_object->user_nicename,
'user_email' => $user_object->user_email,
'user_url' => $user_object->user_url,
'user_registered' => $user_object->user_registered,
'user_activation_key' => $user_object->user_activation_key,
'user_status' => $user_object->user_status,
'display_name' => $user_object->display_name,
) );
if ( is_multisite() && null !== $username && validate_username( $new_user ) ) { //process sitemeta if we're in a multi-site situation
if ( is_multisite() ) { // process sitemeta if we're in a multi-site situation
$oldAdmins = $wpdb->get_var( 'SELECT meta_value FROM `' . $wpdb->sitemeta . "` WHERE meta_key = 'site_admins'" );
$newAdmins = str_replace( '5:"admin"', strlen( $new_user ) . ':"' . esc_sql( $new_user ) . '"', $oldAdmins );
$wpdb->query( 'UPDATE `' . $wpdb->sitemeta . "` SET meta_value = '" . esc_sql( $newAdmins ) . "' WHERE meta_key = 'site_admins'" );
$wpdb->query( $wpdb->prepare( 'UPDATE `' . $wpdb->sitemeta . "` SET meta_value = %s WHERE meta_key = 'site_admins'", $newAdmins ) );
}
$new_user = $wpdb->insert_id;
$wpdb->query( $wpdb->prepare( 'UPDATE `' . $wpdb->posts . "` SET post_author = %s WHERE post_author = 1;", $new_user ) );
$wpdb->query( $wpdb->prepare( 'UPDATE `' . $wpdb->usermeta . "` SET user_id = %s WHERE user_id = 1;", $new_user ) );
$wpdb->query( $wpdb->prepare( 'UPDATE `' . $wpdb->comments . "` SET user_id = %s WHERE user_id = 1;", $new_user ) );
$wpdb->query( $wpdb->prepare( 'UPDATE `' . $wpdb->links . "` SET link_owner = %s WHERE link_owner = 1;", $new_user ) );
wp_clear_auth_cookie();
$itsec_files->release_file_lock( 'admin_user' );
return true;
}
//}
} elseif ( null !== $username ) { // username didn't validate
$itsec_files->release_file_lock( 'admin_user' );
return false;
} else { // only changing the id
$user_login = $user_object->user_login;
}
if ( true === $id ) { // change the user id
$wpdb->query( 'DELETE FROM `' . $wpdb->users . '` WHERE ID = 1;' );
$wpdb->insert( $wpdb->users, array(
'user_login' => $user_login,
'user_pass' => $user_object->user_pass,
'user_nicename' => $user_object->user_nicename,
'user_email' => $user_object->user_email,
'user_url' => $user_object->user_url,
'user_registered' => $user_object->user_registered,
'user_activation_key' => $user_object->user_activation_key,
'user_status' => $user_object->user_status,
'display_name' => $user_object->display_name,
) );
if ( is_multisite() && null !== $username && validate_username( $new_user ) ) { // process sitemeta if we're in a multi-site situation
$oldAdmins = $wpdb->get_var( 'SELECT meta_value FROM `' . $wpdb->sitemeta . "` WHERE meta_key = 'site_admins'" );
$newAdmins = str_replace( '5:"admin"', strlen( $new_user ) . ':"' . esc_sql( $new_user ) . '"', $oldAdmins );
$wpdb->query( 'UPDATE `' . $wpdb->sitemeta . "` SET meta_value = '" . esc_sql( $newAdmins ) . "' WHERE meta_key = 'site_admins'" );
}
$new_user = $wpdb->insert_id;
$wpdb->query( $wpdb->prepare( 'UPDATE `' . $wpdb->posts . '` SET post_author = %s WHERE post_author = 1;', $new_user ) );
$wpdb->query( $wpdb->prepare( 'UPDATE `' . $wpdb->usermeta . '` SET user_id = %s WHERE user_id = 1;', $new_user ) );
$wpdb->query( $wpdb->prepare( 'UPDATE `' . $wpdb->comments . '` SET user_id = %s WHERE user_id = 1;', $new_user ) );
$wpdb->query( $wpdb->prepare( 'UPDATE `' . $wpdb->links . '` SET link_owner = %s WHERE link_owner = 1;', $new_user ) );
wp_clear_auth_cookie();
$itsec_files->release_file_lock( 'admin_user' );
return true;
}
// }
return false;
}
public function build_wpconfig_rules( $rules_array, $input = null ) {
//Get the rules from the database if input wasn't sent
// Get the rules from the database if input wasn't sent
if ( null === $input ) {
return $rules_array;
}
@ -869,18 +867,21 @@ class MainWP_Child_iThemes_Security {
'rule' => "define( 'WP_CONTENT_DIR', '" . $new_dir . "' );",
);
$rules_array[] = array( 'type' => 'wpconfig', 'name' => 'Content Directory', 'rules' => $rules );
$rules_array[] = array(
'type' => 'wpconfig',
'name' => 'Content Directory',
'rules' => $rules,
);
return $rules_array;
}
public function change_database_prefix() {
global $mainwp_itsec_modules_path;
require_once( $mainwp_itsec_modules_path . 'database-prefix/utility.php' );
require_once $mainwp_itsec_modules_path . 'database-prefix/utility.php';
$str_error = '';
$return = array();
$return = array();
if ( isset( $_POST['change_prefix'] ) && 'yes' === $_POST['change_prefix'] ) {
$result = ITSEC_Database_Prefix_Utility::change_database_prefix();
@ -899,7 +900,7 @@ class MainWP_Child_iThemes_Security {
if ( false === $result['new_prefix'] ) {
$return['error'] = $str_error;
} else {
$return['result'] = 'success';
$return['result'] = 'success';
$return['message'] = sprintf( __( 'The database table prefix was successfully changed to <code>%1$s</code>.', 'better-wp-security' ), $result['new_prefix'] );
}
@ -913,7 +914,7 @@ class MainWP_Child_iThemes_Security {
$settings = array();
}
$settings['reset'] = true;
$return = array();
$return = array();
if ( update_site_option( 'itsec_ipcheck', $settings ) ) {
$return['result'] = 'success';
} else {
@ -926,7 +927,7 @@ class MainWP_Child_iThemes_Security {
public function reset_api_key() {
$defaults = ITSEC_Modules::get_defaults( 'network-brute-force' );
$results = ITSEC_Modules::set_settings( 'network-brute-force', $defaults );
$results = ITSEC_Modules::set_settings( 'network-brute-force', $defaults );
ITSEC_Response::set_response( $results['saved'] );
ITSEC_Response::add_errors( $results['errors'] );
@ -934,9 +935,9 @@ class MainWP_Child_iThemes_Security {
$information = array();
if ( $results['saved'] ) {
$information['result'] = 'success';
$information['result'] = 'success';
$information['nbf_settings'] = ITSEC_Modules::get_settings( 'network-brute-force');
} else if ( empty( $results['errors'] ) ) {
} elseif ( empty( $results['errors'] ) ) {
$information['error_reset_api'] = 1;
}
return $information;
@ -946,15 +947,15 @@ class MainWP_Child_iThemes_Security {
global $mainwp_itsec_modules_path;
if ( ! class_exists( 'ITSEC_Malware_Scanner' ) ) {
require_once( $mainwp_itsec_modules_path . 'malware/class-itsec-malware-scanner.php' );
require_once( $mainwp_itsec_modules_path . 'malware/class-itsec-malware-scan-results-template.php' );
require_once $mainwp_itsec_modules_path . 'malware/class-itsec-malware-scanner.php';
require_once $mainwp_itsec_modules_path . 'malware/class-itsec-malware-scan-results-template.php';
}
$response = array();
if ( ! ITSEC_Core::current_user_can_manage() ) {
$response['error'] = 'The currently logged in user does not have sufficient permissions to run this scan.';
} else {
$results = ITSEC_Malware_Scanner::scan();
$results = ITSEC_Malware_Scanner::scan();
$response['html'] = ITSEC_Malware_Scan_Results_Template::get_html( $results, true );
}
@ -965,11 +966,11 @@ class MainWP_Child_iThemes_Security {
global $mainwp_itsec_modules_path;
if ( ! class_exists( 'ITSEC_Malware_Scanner' ) ) {
require_once( $mainwp_itsec_modules_path . 'malware/class-itsec-malware-scanner.php' );
require_once( $mainwp_itsec_modules_path . 'malware/class-itsec-malware-scan-results-template.php' );
require_once $mainwp_itsec_modules_path . 'malware/class-itsec-malware-scanner.php';
require_once $mainwp_itsec_modules_path . 'malware/class-itsec-malware-scan-results-template.php';
}
$response = array();
$results= ITSEC_Malware_Scanner::scan();
$response = array();
$results = ITSEC_Malware_Scanner::scan();
$response['html'] = ITSEC_Malware_Scan_Results_Template::get_html( $results, true );
return $response;
}
@ -1068,7 +1069,7 @@ class MainWP_Child_iThemes_Security {
global $wpdb;
if ( ! class_exists( 'ITSEC_Lib' ) ) {
require( ITSEC_Core::get_core_dir() . '/core/class-itsec-lib.php' );
require ITSEC_Core::get_core_dir() . '/core/class-itsec-lib.php';
}
$lockout_ids = $_POST['lockout_ids'];
@ -1095,7 +1096,7 @@ class MainWP_Child_iThemes_Security {
if ( ! is_multisite() ) {
if ( ! function_exists( 'add_settings_error' ) ) {
require_once( ABSPATH . '/wp-admin/includes/template.php' );
require_once ABSPATH . '/wp-admin/includes/template.php';
}
add_settings_error( 'itsec', esc_attr( 'settings_updated' ), $message, $type );
@ -1110,30 +1111,30 @@ class MainWP_Child_iThemes_Security {
$active_modules = $_POST['active_modules'];
if (!is_array($active_modules))
if ( ! is_array($active_modules)) {
$active_modules = array();
}
$current_val = get_site_option( 'itsec_active_modules', array() );
foreach ($active_modules as $mod => $val) {
$current_val[$mod] = $val;
$current_val[ $mod ] = $val;
}
update_site_option( 'itsec_active_modules', $current_val );
return array('result' => 'success');
return array( 'result' => 'success' );
}
private function reload_backup_exclude( ) {
private function reload_backup_exclude() {
return array(
'exclude' => ITSEC_Modules::get_setting( 'backup', 'exclude' ),
'exclude' => ITSEC_Modules::get_setting( 'backup', 'exclude' ),
'excludable_tables' => $this->get_excludable_tables(),
'result' => 'success'
'result' => 'success',
);
}
private function get_excludable_tables( ) {
private function get_excludable_tables() {
global $wpdb;
$all_sites = ITSEC_Modules::get_setting( 'backup', 'all_sites' );
$all_sites = ITSEC_Modules::get_setting( 'backup', 'all_sites' );
$ignored_tables = array(
'commentmeta',
'comments',
@ -1154,7 +1155,7 @@ class MainWP_Child_iThemes_Security {
$query = $wpdb->prepare( 'SHOW TABLES LIKE %s', "{$wpdb->base_prefix}%" );
}
$tables = $wpdb->get_results( $query, ARRAY_N );
$tables = $wpdb->get_results( $query, ARRAY_N );
$excludes = array();
foreach ( $tables as $table ) {
@ -1164,21 +1165,24 @@ class MainWP_Child_iThemes_Security {
continue;
}
$excludes[$short_table] = $table[0];
$excludes[ $short_table ] = $table[0];
}
return $excludes ;
return $excludes;
}
private function security_site() {
global $mainwp_itsec_modules_path;
require_once( $mainwp_itsec_modules_path . 'security-check/scanner.php' );
require_once( $mainwp_itsec_modules_path . 'security-check/feedback-renderer.php' );
require_once $mainwp_itsec_modules_path . 'security-check/scanner.php';
require_once $mainwp_itsec_modules_path . 'security-check/feedback-renderer.php';
$results = ITSEC_Security_Check_Scanner::get_results();
ob_start();
ITSEC_Security_Check_Feedback_Renderer::render( $results );
$response = ob_get_clean();
return array('result' => 'success' , 'response' => $response);
return array(
'result' => 'success',
'response' => $response,
);
}
// source from itheme plugin
@ -1195,7 +1199,7 @@ class MainWP_Child_iThemes_Security {
foreach ( $roles->roles as $role => $details ) {
if ( isset( $details['capabilities']['manage_options'] ) && ( true === $details['capabilities']['manage_options'] ) ) {
$available_roles["role:$role"] = translate_user_role( $details['name'] );
$available_roles[ "role:$role" ] = translate_user_role( $details['name'] );
$users = get_users( array( 'role' => $role ) );

View file

@ -15,28 +15,28 @@
class MainWP_Child_Links_Checker {
public static $instance = null;
public static $instance = null;
public $is_plugin_installed = false;
static function Instance() {
if ( null === MainWP_Child_Links_Checker::$instance ) {
MainWP_Child_Links_Checker::$instance = new MainWP_Child_Links_Checker();
if ( null === self::$instance ) {
self::$instance = new MainWP_Child_Links_Checker();
}
return MainWP_Child_Links_Checker::$instance;
return self::$instance;
}
public function __construct() {
require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
require_once ABSPATH . 'wp-admin/includes/plugin.php';
if ( is_plugin_active( 'broken-link-checker/broken-link-checker.php' ) ) {
$this->is_plugin_installed = true;
}
if ( !$this->is_plugin_installed )
if ( ! $this->is_plugin_installed ) {
return;
}
add_filter( 'mainwp-site-sync-others-data', array( $this, 'syncOthersData' ), 10, 2 );
}
public function action() {
@ -82,8 +82,8 @@ class MainWP_Child_Links_Checker {
}
}
MainWP_Helper::write( $information );
} catch(Exception $e) {
MainWP_Helper::write( array('error' => $e->getMessage()) );
} catch (Exception $e) {
MainWP_Helper::write( array( 'error' => $e->getMessage() ) );
}
}
@ -114,8 +114,8 @@ class MainWP_Child_Links_Checker {
}
function save_settings() {
$information = array();
$check_threshold = intval( $_POST['check_threshold'] );
$information = array();
$check_threshold = intval( $_POST['check_threshold'] );
if ( $check_threshold > 0 ) {
$conf = blc_get_configuration();
$conf->options['check_threshold'] = $check_threshold;
@ -137,13 +137,13 @@ class MainWP_Child_Links_Checker {
global $wpdb;
/** @var wpdb $wpdb */
//Delete all discovered instances
// Delete all discovered instances
$wpdb->query( "TRUNCATE {$wpdb->prefix}blc_instances" );
//Delete all discovered links
// Delete all discovered links
$wpdb->query( "TRUNCATE {$wpdb->prefix}blc_links" );
//Mark all posts, custom fields and bookmarks for processing.
// Mark all posts, custom fields and bookmarks for processing.
blc_resynch( true );
}
@ -158,18 +158,18 @@ class MainWP_Child_Links_Checker {
}
blc_init();
//Get the container type matching the type of the deleted post
// Get the container type matching the type of the deleted post
$post = get_post( $post_id );
if ( ! $post ) {
return;
}
//Get the associated container object
// Get the associated container object
$post_container = blcContainerHelper::get_container( array( $post->post_type, intval( $post_id ) ) );
if ( $post_container ) {
//Delete it
// Delete it
$post_container->delete();
//Clean up any dangling links
// Clean up any dangling links
blc_cleanup_links();
}
}
@ -210,9 +210,9 @@ class MainWP_Child_Links_Checker {
// ok
public function syncOthersData( $information, $data = array() ) {
if ( isset( $data['syncBrokenLinksCheckerData'] ) && $data['syncBrokenLinksCheckerData'] ) {
try{
try {
$information['syncBrokenLinksCheckerData'] = $this->get_sync_data();
} catch(Exception $e) {
} catch (Exception $e) {
}
}
@ -223,14 +223,17 @@ class MainWP_Child_Links_Checker {
function get_sync_data( $strategy = '' ) {
$information = array();
$data = $this->get_count_links();
if (is_array($data))
if (is_array($data)) {
$information['data'] = $data;
}
return $information;
}
function get_links_data() {
if (!defined('BLC_DIRECTORY')) return;
if ( ! defined('BLC_DIRECTORY')) {
return;
}
$file_path1 = BLC_DIRECTORY . '/includes/link-query.php';
$file_path2 = BLC_DIRECTORY . '/includes/modules.php';
@ -242,20 +245,19 @@ class MainWP_Child_Links_Checker {
MainWP_Helper::check_classes_exists('blcLinkQuery');
MainWP_Helper::check_methods('blcLinkQuery', 'getInstance');
$blc_link_query = blcLinkQuery::getInstance();
$blc_link_query = blcLinkQuery::getInstance();
MainWP_Helper::check_methods($blc_link_query, 'get_filter_links');
$total = $blc_link_query->get_filter_links( 'all', array( 'count_only' => true ) );
$total = $blc_link_query->get_filter_links( 'all', array( 'count_only' => true ) );
$max_results = isset($_POST['max_results']) ? intval($_POST['max_results']) : 50;
$offset = isset($_POST['offset']) ? intval($_POST['offset']) : 0;
$offset = isset($_POST['offset']) ? intval($_POST['offset']) : 0;
$params = array(
array( 'load_instances' => true ),
'max_results' => $max_results
);
$params = array(
array( 'load_instances' => true ),
'max_results' => $max_results,
);
if (empty($offset)) {
$first_sync = true;
@ -266,12 +268,12 @@ class MainWP_Child_Links_Checker {
$link_data = $this->links_checker_data($params);
$total_sync = 0;
if ($offset){
if ($offset) {
$total_sync = $offset;
}
$total_sync += (is_array($link_data) ? count($link_data) : 0);
$total_sync += ( is_array($link_data) ? count($link_data) : 0 );
$information = array('links_data' => $link_data);
$information = array( 'links_data' => $link_data );
if ($first_sync) {
$information['data'] = $this->get_count_links();
@ -280,9 +282,9 @@ class MainWP_Child_Links_Checker {
if ($total > $offset + $max_results ) {
$information['sync_offset'] = $offset + $max_results;
} else {
$information['last_sync'] = 1;
$information['last_sync'] = 1;
$information['total_sync'] = $total_sync;
$information['data'] = $this->get_count_links();
$information['data'] = $this->get_count_links();
}
$information['result'] = 'success';
@ -290,7 +292,9 @@ class MainWP_Child_Links_Checker {
}
function get_count_links() {
if (!defined('BLC_DIRECTORY')) return;
if ( ! defined('BLC_DIRECTORY')) {
return;
}
$file_path1 = BLC_DIRECTORY . '/includes/link-query.php';
$file_path2 = BLC_DIRECTORY . '/includes/modules.php';
@ -303,25 +307,25 @@ class MainWP_Child_Links_Checker {
MainWP_Helper::check_classes_exists('blcLinkQuery');
MainWP_Helper::check_methods('blcLinkQuery', 'getInstance');
$data = array();
$blc_link_query = blcLinkQuery::getInstance();
$data = array();
$blc_link_query = blcLinkQuery::getInstance();
MainWP_Helper::check_methods($blc_link_query, 'get_filter_links');
$data['broken'] = $blc_link_query->get_filter_links( 'broken', array( 'count_only' => true ) );
$data['redirects'] = $blc_link_query->get_filter_links( 'redirects', array( 'count_only' => true ) );
$data['dismissed'] = $blc_link_query->get_filter_links( 'dismissed', array( 'count_only' => true ) );
$data['broken'] = $blc_link_query->get_filter_links( 'broken', array( 'count_only' => true ) );
$data['redirects'] = $blc_link_query->get_filter_links( 'redirects', array( 'count_only' => true ) );
$data['dismissed'] = $blc_link_query->get_filter_links( 'dismissed', array( 'count_only' => true ) );
$data['warning'] = $blc_link_query->get_filter_links( 'warning', array( 'count_only' => true ) );
$data['all'] = $blc_link_query->get_filter_links( 'all', array( 'count_only' => true ) );
$data['all'] = $blc_link_query->get_filter_links( 'all', array( 'count_only' => true ) );
return $data;
}
function links_checker_data($params) {
function links_checker_data( $params) {
MainWP_Helper::check_functions('blc_get_links');
MainWP_Helper::check_classes_exists('blcLink');
$links = blc_get_links( $params );
$links = blc_get_links( $params );
$filter_fields = array(
'link_id',
@ -341,13 +345,13 @@ class MainWP_Child_Links_Checker {
'last_success',
'may_recheck',
'false_positive',
//'result_hash',
// 'result_hash',
'dismissed',
'status_text',
'status_code',
'log'
'log',
);
$return = array();
$return = array();
$blc_option = get_option( 'wsblc_options' );
@ -370,7 +374,7 @@ class MainWP_Child_Links_Checker {
$days_broken = 0;
if ( $link->broken ) {
//Add a highlight to broken links that appear to be permanently broken
// Add a highlight to broken links that appear to be permanently broken
$days_broken = intval( ( time() - $link->first_failure ) / ( 3600 * 24 ) );
if ( $days_broken >= $blc_option['failure_duration_threshold'] ) {
$extra_info['permanently_broken'] = 1;
@ -380,7 +384,7 @@ class MainWP_Child_Links_Checker {
}
}
$extra_info['days_broken'] = $days_broken;
$instances = false;
$instances = false;
$get_link = new blcLink( intval( $link->link_id ) );
if ( $get_link->valid() ) {
@ -389,13 +393,13 @@ class MainWP_Child_Links_Checker {
}
if ( ! empty( $instances ) ) {
$first_instance = reset( $instances );
$first_instance = reset( $instances );
MainWP_Helper::check_methods($first_instance, array( 'ui_get_link_text', 'get_container', 'is_link_text_editable', 'is_url_editable') );
MainWP_Helper::check_methods($first_instance, array( 'ui_get_link_text', 'get_container', 'is_link_text_editable', 'is_url_editable' ) );
$new_link->link_text = $first_instance->ui_get_link_text();
$new_link->link_text = $first_instance->ui_get_link_text();
$extra_info['count_instance'] = count( $instances );
$container = $first_instance->get_container();
$container = $first_instance->get_container();
/** @var blcContainer $container */
@ -403,8 +407,8 @@ class MainWP_Child_Links_Checker {
if (true === MainWP_Helper::check_properties($first_instance, array( 'container_field' ), true )) {
if (true === MainWP_Helper::check_properties($container, array( 'container_type', 'container_id' ), true )) {
$extra_info['container_type'] = $container->container_type;
$extra_info['container_id'] = $container->container_id;
$extra_info['source_data'] = $this->ui_get_source( $container, $first_instance->container_field );
$extra_info['container_id'] = $container->container_id;
$extra_info['source_data'] = $this->ui_get_source( $container, $first_instance->container_field );
}
}
}
@ -429,27 +433,26 @@ class MainWP_Child_Links_Checker {
$link_texts = $can_edit_text ? $editable_link_texts : $non_editable_link_texts;
$data_link_text = '';
if ( count( $link_texts ) === 1 ) {
//All instances have the same text - use it.
// All instances have the same text - use it.
$link_text = key( $link_texts );
$data_link_text = esc_attr( $link_text );
}
$extra_info['data_link_text'] = $data_link_text;
$extra_info['can_edit_url'] = $can_edit_url;
$extra_info['can_edit_text'] = $can_edit_text;
$extra_info['can_edit_url'] = $can_edit_url;
$extra_info['can_edit_text'] = $can_edit_text;
} else {
$new_link->link_text = '';
$new_link->link_text = '';
$extra_info['count_instance'] = 0;
}
$new_link->extra_info = base64_encode(serialize($extra_info));
$new_link->synced = 1;
$return[] = $new_link;
$new_link->synced = 1;
$return[] = $new_link;
}
} else {
return array();
}
return $return;
}
function edit_link() {
@ -459,14 +462,14 @@ class MainWP_Child_Links_Checker {
return $information;
}
//Load the link
// Load the link
$link = new blcLink( intval( $_POST['link_id'] ) );
if ( ! $link->valid() ) {
$information['error'] = 'NOTFOUNDLINK'; // Oops, I can't find the link
return $information;
}
//Validate the new URL.
// Validate the new URL.
$new_url = stripslashes( $_POST['new_url'] );
$parsed = @parse_url( $new_url );
if ( ! $parsed ) {
@ -479,7 +482,7 @@ class MainWP_Child_Links_Checker {
$new_text = null;
}
if ( ! empty( $new_text ) && ! current_user_can( 'unfiltered_html' ) ) {
$new_text = stripslashes( wp_filter_post_kses( addslashes( $new_text ) ) ); //wp_filter_post_kses expects slashed data.
$new_text = stripslashes( wp_filter_post_kses( addslashes( $new_text ) ) ); // wp_filter_post_kses expects slashed data.
}
$rez = $link->edit( $new_url, $new_text );
@ -512,7 +515,7 @@ class MainWP_Child_Links_Checker {
'ui_link_text' => isset( $new_text ) ? $ui_link_text : null,
'errors' => array(),
);
//url, status text, status code, link text, editable link text
// url, status text, status code, link text, editable link text
foreach ( $rez['errors'] as $error ) {
/** @var $error WP_Error */
@ -532,7 +535,7 @@ class MainWP_Child_Links_Checker {
}
if ( isset( $_POST['link_id'] ) ) {
//Load the link
// Load the link
$link = new blcLink( intval( $_POST['link_id'] ) );
if ( ! $link->valid() ) {
@ -540,7 +543,7 @@ class MainWP_Child_Links_Checker {
return $information;
}
//Try and unlink it
// Try and unlink it
$rez = $link->unlink();
if ( false === $rez ) {
@ -577,7 +580,7 @@ class MainWP_Child_Links_Checker {
}
if ( isset( $_POST['link_id'] ) ) {
//Load the link
// Load the link
$link = new blcLink( intval( $_POST['link_id'] ) );
if ( ! $link->valid() ) {
@ -587,7 +590,7 @@ class MainWP_Child_Links_Checker {
$link->dismissed = $dismiss;
//Save the changes
// Save the changes
if ( $link->save() ) {
$information = 'OK';
} else {
@ -610,7 +613,7 @@ class MainWP_Child_Links_Checker {
return $information;
}
if ( isset( $_POST['link_id'] ) ) {
//Load the link
// Load the link
$link = new blcLink( intval( $_POST['link_id'] ) );
if ( ! $link->valid() ) {
@ -618,13 +621,13 @@ class MainWP_Child_Links_Checker {
return $information;
}
//Make it appear "not broken"
// Make it appear "not broken"
$link->broken = false;
$link->false_positive = true;
$link->last_check_attempt = time();
$link->log = __( 'This link was manually marked as working by the user.', 'mainwp-child' );
//Save the changes
// Save the changes
if ( $link->save() ) {
$information['status'] = 'OK';
$information['last_check_attempt'] = $link->last_check_attempt;
@ -641,7 +644,7 @@ class MainWP_Child_Links_Checker {
function ui_get_source( $container, $container_field = '' ) {
if ( 'comment' === $container->container_type ) {
return $this->ui_get_source_comment( $container, $container_field );
} else if ( $container instanceof blcAnyPostContainer ) {
} elseif ( $container instanceof blcAnyPostContainer ) {
return $this->ui_get_source_post( $container, $container_field );
}
@ -649,19 +652,20 @@ class MainWP_Child_Links_Checker {
}
function ui_get_source_comment( $container, $container_field = '' ) {
//Display a comment icon.
// Display a comment icon.
if ( 'comment_author_url' === $container_field ) {
$image = 'font-awesome/font-awesome-user.png';
} else {
$image = 'font-awesome/font-awesome-comment-alt.png';
}
if (true !== MainWP_Helper::check_methods($container, array( 'get_wrapped_object'), true ))
if (true !== MainWP_Helper::check_methods($container, array( 'get_wrapped_object' ), true )) {
return false;
}
$comment = $container->get_wrapped_object();
//Display a small text sample from the comment
// Display a small text sample from the comment
$text_sample = strip_tags( $comment->comment_content );
$text_sample = blcUtility::truncate( $text_sample, 65 );
@ -680,7 +684,7 @@ class MainWP_Child_Links_Checker {
function ui_get_source_post( $container, $container_field = '' ) {
return array(
'post_title' => get_the_title( $container->container_id ),
'post_status' => get_post_status($container->container_id),
'post_status' => get_post_status($container->container_id),
'container_anypost' => true,
);
}

View file

@ -17,25 +17,26 @@
class MainWP_Child_Pagespeed {
public static $instance = null;
public static $instance = null;
public $is_plugin_installed = false;
static function Instance() {
if ( null === MainWP_Child_Pagespeed::$instance ) {
MainWP_Child_Pagespeed::$instance = new MainWP_Child_Pagespeed();
if ( null === self::$instance ) {
self::$instance = new MainWP_Child_Pagespeed();
}
return MainWP_Child_Pagespeed::$instance;
return self::$instance;
}
public function __construct() {
require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
require_once ABSPATH . 'wp-admin/includes/plugin.php';
if ( is_plugin_active( 'google-pagespeed-insights/google-pagespeed-insights.php' ) ) {
$this->is_plugin_installed = true;
}
if (!$this->is_plugin_installed)
if ( ! $this->is_plugin_installed) {
return;
}
add_filter( 'mainwp-site-sync-others-data', array( $this, 'syncOthersData' ), 10, 2 );
@ -60,7 +61,7 @@ class MainWP_Child_Pagespeed {
case 'sync_data':
$information = $this->get_sync_data();
break;
case "check_pages":
case 'check_pages':
$information = $this->check_pages();
break;
}
@ -75,12 +76,13 @@ class MainWP_Child_Pagespeed {
}
public function init() {
if (!$this->is_plugin_installed)
if ( ! $this->is_plugin_installed) {
return;
}
if ( get_option( 'mainwp_pagespeed_hide_plugin' ) === 'hide' ) {
add_filter( 'all_plugins', array( $this, 'hide_plugin' ) );
add_action('admin_menu', array($this, 'hide_menu'), 999);
add_action('admin_menu', array( $this, 'hide_menu' ), 999);
}
$this->init_cron();
}
@ -126,9 +128,9 @@ class MainWP_Child_Pagespeed {
public function hide_menu() {
global $submenu;
if (isset($submenu['tools.php'])) {
foreach($submenu['tools.php'] as $key => $menu) {
foreach ($submenu['tools.php'] as $key => $menu) {
if ($menu[2] == 'google-pagespeed-insights') {
unset($submenu['tools.php'][$key]);
unset($submenu['tools.php'][ $key ]);
break;
}
}
@ -157,7 +159,7 @@ class MainWP_Child_Pagespeed {
function save_settings() {
$current_values = get_option( 'gpagespeedi_options' );
$checkstatus = apply_filters( 'gpi_check_status', false );
$checkstatus = apply_filters( 'gpi_check_status', false );
if ( $checkstatus ) {
return array( 'result' => 'RUNNING' );
}
@ -214,9 +216,9 @@ class MainWP_Child_Pagespeed {
if ( isset( $settings['check_report'] ) ) {
if ( is_array( $settings['check_report'] ) ) {
$current_values['check_pages'] = in_array( 'page', $settings['check_report'] ) ? true : false;
$current_values['check_posts'] = in_array( 'post', $settings['check_report'] ) ? true : false;
$current_values['check_categories'] = in_array( 'category', $settings['check_report'] ) ? true : false;
$current_values['check_pages'] = in_array( 'page', $settings['check_report'] ) ? true : false;
$current_values['check_posts'] = in_array( 'post', $settings['check_report'] ) ? true : false;
$current_values['check_categories'] = in_array( 'category', $settings['check_report'] ) ? true : false;
$current_values['check_custom_urls'] = in_array( 'custom_urls', $settings['check_report'] ) ? true : false;
} else {
$current_values['check_pages'] = $current_values['check_posts'] = $current_values['check_categories'] = $current_values['check_custom_urls'] = false;
@ -238,24 +240,24 @@ class MainWP_Child_Pagespeed {
$result = $this->get_sync_data( $strategy );
// if ( isset( $_POST['doaction'] ) && ( 'check_new_pages' === $_POST['doaction'] || 'recheck_all_pages' === $_POST['doaction'] ) ) {
// if ( 'recheck_all_pages' === $_POST['doaction'] ) {
// $recheck = true;
// } else {
// $recheck = false;
// }
//
//
// if ($this->do_check_pages($recheck))
// $information['checked_pages'] = 1;
// }
// if ( isset( $_POST['doaction'] ) && ( 'check_new_pages' === $_POST['doaction'] || 'recheck_all_pages' === $_POST['doaction'] ) ) {
// if ( 'recheck_all_pages' === $_POST['doaction'] ) {
// $recheck = true;
// } else {
// $recheck = false;
// }
//
//
// if ($this->do_check_pages($recheck))
// $information['checked_pages'] = 1;
// }
$information['data'] = $result['data'];
return $information;
}
function check_pages() {
if (isset($_POST['force_recheck']) && !empty($_POST['force_recheck'])) {
if (isset($_POST['force_recheck']) && ! empty($_POST['force_recheck'])) {
$recheck = true;
} else {
$recheck = false;
@ -267,14 +269,14 @@ class MainWP_Child_Pagespeed {
return $information;
}
function do_check_pages($forceRecheck = false) {
function do_check_pages( $forceRecheck = false) {
$information = array();
if ( defined( 'GPI_DIRECTORY' ) ) {
$checkstatus = apply_filters( 'gpi_check_status', false );
if ( $checkstatus ) {
$information['error'] = __( 'The API is busy checking other pages, please try again later.', 'gpagespeedi' );
} else {
//do_action( 'googlepagespeedinsightsworker', array(), $forceRecheck );
// do_action( 'googlepagespeedinsightsworker', array(), $forceRecheck );
do_action( 'run_gpi', $forceRecheck ); // to fix
$information['checked_pages'] = 1;
}
@ -284,9 +286,9 @@ class MainWP_Child_Pagespeed {
public function syncOthersData( $information, $data = array() ) {
if ( isset( $data['syncPageSpeedData'] ) && $data['syncPageSpeedData'] ) {
try{
try {
$information['syncPageSpeedData'] = $this->get_sync_data();
} catch(Exception $e) {
} catch (Exception $e) {
}
}
@ -299,7 +301,7 @@ class MainWP_Child_Pagespeed {
}
$current_values = get_option( 'gpagespeedi_options' );
$checkstatus = apply_filters( 'gpi_check_status', false );
$checkstatus = apply_filters( 'gpi_check_status', false );
if ( $checkstatus ) {
return array( 'result' => 'RUNNING' );
}
@ -309,16 +311,16 @@ class MainWP_Child_Pagespeed {
$data = array( 'bad_api_key' => $bad_key );
if ( 'both' === $strategy || 'desktop' === $strategy ) {
$result = self::cal_pagespeed_data( 'desktop' );
if ( !empty($result) && is_array($result) ) {
$result = self::cal_pagespeed_data( 'desktop' );
if ( ! empty($result) && is_array($result) ) {
$data['desktop_score'] = $result['average_score'];
$data['desktop_total_pages'] = $result['total_pages'];
$data['desktop_last_modified'] = $result['last_modified'];
}
}
if ( 'both' === $strategy || 'mobile' === $strategy ) {
$result = self::cal_pagespeed_data( 'mobile' );
if ( !empty($result) && is_array($result) ) {
$result = self::cal_pagespeed_data( 'mobile' );
if ( ! empty($result) && is_array($result) ) {
$data['mobile_score'] = $result['average_score'];
$data['mobile_total_pages'] = $result['total_pages'];
$data['mobile_last_modified'] = $result['last_modified'];
@ -340,9 +342,8 @@ class MainWP_Child_Pagespeed {
return false;
}
$score_column = $strategy . '_score';
//$page_stats_column = $strategy . '_page_stats';
$score_column = $strategy . '_score';
// $page_stats_column = $strategy . '_page_stats';
$data_typestocheck = self::get_filter_options( 'all' );
@ -399,9 +400,9 @@ class MainWP_Child_Pagespeed {
// Not Null check for Report List scores
switch ( $strategy ) {
// case 'both':
// $nullcheck = 'desktop_score IS NOT NULL AND mobile_score IS NOT NULL';
// break;
// case 'both':
// $nullcheck = 'desktop_score IS NOT NULL AND mobile_score IS NOT NULL';
// break;
case 'mobile':
$nullcheck = 'mobile_score IS NOT NULL';
@ -437,61 +438,59 @@ class MainWP_Child_Pagespeed {
);
}
static function get_filter_options($restrict_type = 'all') {
static function get_filter_options( $restrict_type = 'all') {
$types = array();
$gpi_options = get_option('gpagespeedi_options');
$types = array();
$gpi_options = get_option('gpagespeedi_options');
$typestocheck = array();
if($gpi_options['check_pages']) {
if($restrict_type == 'all' || $restrict_type == 'ignored' || $restrict_type == 'pages') {
if ($gpi_options['check_pages']) {
if ($restrict_type == 'all' || $restrict_type == 'ignored' || $restrict_type == 'pages') {
$typestocheck[] = 'type = %s';
$types[1][] = "page";
$types[1][] = 'page';
}
}
if($gpi_options['check_posts']) {
if($restrict_type == 'all' || $restrict_type == 'ignored' || $restrict_type == 'posts') {
if ($gpi_options['check_posts']) {
if ($restrict_type == 'all' || $restrict_type == 'ignored' || $restrict_type == 'posts') {
$typestocheck[] = 'type = %s';
$types[1][] = "post";
$types[1][] = 'post';
}
}
if($gpi_options['check_categories']) {
if($restrict_type == 'all' || $restrict_type == 'ignored' || $restrict_type == 'categories') {
if ($gpi_options['check_categories']) {
if ($restrict_type == 'all' || $restrict_type == 'ignored' || $restrict_type == 'categories') {
$typestocheck[] = 'type = %s';
$types[1][] = "category";
$types[1][] = 'category';
}
}
if($gpi_options['cpt_whitelist']) {
if($restrict_type == 'all' || $restrict_type == 'ignored' || stristr($restrict_type, 'gpi_custom_posts')) {
if ($gpi_options['cpt_whitelist']) {
if ($restrict_type == 'all' || $restrict_type == 'ignored' || stristr($restrict_type, 'gpi_custom_posts')) {
$cpt_whitelist_arr = false;
if(!empty($gpi_options['cpt_whitelist'])) {
if ( ! empty($gpi_options['cpt_whitelist'])) {
$cpt_whitelist_arr = unserialize($gpi_options['cpt_whitelist']);
}
$args=array(
$args = array(
'public' => true,
'_builtin' => false
'_builtin' => false,
);
$custom_post_types = get_post_types($args,'names','and');
if($restrict_type != 'gpi_custom_posts' && $restrict_type != 'all' && $restrict_type != 'ignored') {
$custom_post_types = get_post_types($args, 'names', 'and');
if ($restrict_type != 'gpi_custom_posts' && $restrict_type != 'all' && $restrict_type != 'ignored') {
$restrict_type = str_replace('gpi_custom_posts-', '', $restrict_type);
foreach($custom_post_types as $post_type)
{
if($cpt_whitelist_arr && in_array($post_type, $cpt_whitelist_arr)) {
if($post_type == $restrict_type) {
foreach ($custom_post_types as $post_type) {
if ($cpt_whitelist_arr && in_array($post_type, $cpt_whitelist_arr)) {
if ($post_type == $restrict_type) {
$typestocheck[] = 'type = %s';
$types[1][] = $custom_post_types[$post_type];
$types[1][] = $custom_post_types[ $post_type ];
}
}
}
} else {
foreach($custom_post_types as $post_type)
{
if($cpt_whitelist_arr && in_array($post_type, $cpt_whitelist_arr)) {
foreach ($custom_post_types as $post_type) {
if ($cpt_whitelist_arr && in_array($post_type, $cpt_whitelist_arr)) {
$typestocheck[] = 'type = %s';
$types[1][] = $custom_post_types[$post_type];
$types[1][] = $custom_post_types[ $post_type ];
}
}
}
@ -501,7 +500,7 @@ class MainWP_Child_Pagespeed {
if ( $gpi_options['check_custom_urls'] ) {
global $wpdb;
$gpi_custom_urls = $wpdb->prefix . 'gpi_custom_urls';
$gpi_custom_urls = $wpdb->prefix . 'gpi_custom_urls';
$custom_url_types = $wpdb->get_col(
"
SELECT DISTINCT type
@ -512,21 +511,19 @@ class MainWP_Child_Pagespeed {
if ( ! empty( $custom_url_types ) ) {
foreach ( $custom_url_types as $custom_url_type ) {
$typestocheck[] = 'type = %s';
$types[1][] = $custom_url_type;
$types[1][] = $custom_url_type;
}
}
}
if(!empty($typestocheck)) {
if ( ! empty($typestocheck)) {
$types[0] = '';
foreach($typestocheck as $type)
{
if(!is_array($type)) {
foreach ($typestocheck as $type) {
if ( ! is_array($type)) {
$types[0] .= $type . ' OR ';
} else {
foreach($type as $custom_post_type)
{
$types[0] .= 'type = %s OR ';
foreach ($type as $custom_post_type) {
$types[0] .= 'type = %s OR ';
$types[1][] = $custom_post_type;
}
}

View file

@ -29,11 +29,11 @@ class MainWP_Child_Plugins_Check {
private $option_name_last_daily_run = 'mainwp_child_plugin_last_daily_run';
public static function Instance() {
if ( null === MainWP_Child_Plugins_Check::$instance ) {
MainWP_Child_Plugins_Check::$instance = new MainWP_Child_Plugins_Check();
if ( null === self::$instance ) {
self::$instance = new MainWP_Child_Plugins_Check();
}
return MainWP_Child_Plugins_Check::$instance;
return self::$instance;
}
public function __construct() {
@ -45,7 +45,7 @@ class MainWP_Child_Plugins_Check {
add_action( $this->cron_name_watcher, array( $this, 'perform_watchdog' ) );
//add_filter( 'plugin_row_meta', array( $this, 'change_plugin_row_meta' ), 10, 4 );
// add_filter( 'plugin_row_meta', array( $this, 'change_plugin_row_meta' ), 10, 4 );
add_filter( 'plugins_api_args', array( $this, 'modify_plugin_api_search_query' ), 10, 2 );
@ -97,7 +97,7 @@ class MainWP_Child_Plugins_Check {
$last_run = new \DateTime( '@' . $last_run );
}
//Get now
// Get now
$now = new \DateTime();
if ( false === $last_run || (int) $now->diff( $last_run )->format( '%h' ) >= 24 ) {
@ -112,14 +112,13 @@ class MainWP_Child_Plugins_Check {
}
public function schedule_watchdog() {
//For testing
//$this->cleanup_deactivation();
// For testing
// $this->cleanup_deactivation();
//Schedule a global watching cron just in case both other crons get killed
// Schedule a global watching cron just in case both other crons get killed
if ( ! wp_next_scheduled( $this->cron_name_watcher ) ) {
wp_schedule_event( time(), 'hourly', $this->cron_name_watcher );
}
}
public function get_plugins_outdate_info() {
@ -143,44 +142,38 @@ class MainWP_Child_Plugins_Check {
}
return $plugins_outdate;
}
// for testing
public function change_plugin_row_meta( $plugin_meta, $plugin_file, $plugin_data, $status ) {
//Grab our previously stored array of known last modified dates
//Requires WP 2.8.0
// Grab our previously stored array of known last modified dates
// Requires WP 2.8.0
$plugin_info = get_transient( $this->tran_name_plugin_timestamps );
//Sanity check the response
if( false === $plugin_info || ! is_array( $plugin_info ) && 0 === count( $plugin_info ) )
{
// Sanity check the response
if ( false === $plugin_info || ! is_array( $plugin_info ) && 0 === count( $plugin_info ) ) {
return $plugin_meta;
}
//See if this specific plugin is in the known list
if( array_key_exists( $plugin_file, $plugin_info ) )
{
//Get now
$now = new \DateTime();
// See if this specific plugin is in the known list
if ( array_key_exists( $plugin_file, $plugin_info ) ) {
// Get now
$now = new \DateTime();
$last_updated = $plugin_info[ $plugin_file ]['last_updated'];
//Last updated is stored as timestamp, get a real date
// Last updated is stored as timestamp, get a real date
$plugin_last_updated_date = new \DateTime( '@' . $last_updated );
//Compute days between now and plugin last updated
// Compute days between now and plugin last updated
$diff_in_days = $now->diff( $plugin_last_updated_date )->format( '%a' );
//Customizable number of days for tolerance
// Customizable number of days for tolerance
$tolerance_in_days = get_option( 'mainwp_child_plugintheme_days_outdate', 365 );
//If we're outside the window for tolerance show a message
if( $diff_in_days > $tolerance_in_days )
{
// If we're outside the window for tolerance show a message
if ( $diff_in_days > $tolerance_in_days ) {
$plugin_meta[] = sprintf( '<strong style="color: #f00;">This plugin has not been updated by the author in %1$d days!</strong>', $diff_in_days );
}
else
{
} else {
$plugin_meta[] = sprintf( '<span style="color: #090;">This plugin was last updated by the author in %1$d days ago.</span>', $diff_in_days );
}
}
@ -193,17 +186,17 @@ class MainWP_Child_Plugins_Check {
require_once ABSPATH . '/wp-admin/includes/plugin.php';
}
//Get our previous results
// Get our previous results
$responses = get_transient( $this->tran_name_plugin_timestamps );
if ( false === $responses || ! is_array( $responses ) ) {
$responses = array();
}
//Get our previous cache of plugins for batching
// Get our previous cache of plugins for batching
$all_plugins = get_transient( $this->tran_name_plugins_to_batch );
//If there wasn't a previous cache
// If there wasn't a previous cache
if ( false === $all_plugins || ! is_array( $all_plugins ) ) {
$plugins = get_plugins();
if ( is_array( $plugins ) ) {
@ -222,29 +215,29 @@ class MainWP_Child_Plugins_Check {
}
$avoid_plugins = array( 'sitepress-multilingual-cms/sitepress.php' );
//Grab a small number of plugins to scan
$plugins_to_scan = array_splice( $all_plugins, 0, apply_filters( 'mainwp_child_plugin_health_check_max_plugins_to_batch', 10 ) );
// Grab a small number of plugins to scan
$plugins_to_scan = array_splice( $all_plugins, 0, apply_filters( 'mainwp_child_plugin_health_check_max_plugins_to_batch', 10 ) );
$tolerance_in_days = get_option( 'mainwp_child_plugintheme_days_outdate', 365 );
//Loop through each known plugin
// Loop through each known plugin
foreach ( $plugins_to_scan as $slug => $v ) {
if ( in_array( $slug, $avoid_plugins ) ) {
continue;
}
//Try to get the raw information for this plugin
// Try to get the raw information for this plugin
$body = $this->try_get_response_body( $slug, false );
//We couldn't get any information, skip this plugin
// We couldn't get any information, skip this plugin
if ( false === $body ) {
continue;
}
//Deserialize the response
// Deserialize the response
$obj = maybe_unserialize( $body );
$now = new \DateTime();
//Sanity check that deserialization worked and that our property exists
// Sanity check that deserialization worked and that our property exists
if ( false !== $obj && is_object( $obj ) && property_exists( $obj, 'last_updated' ) ) {
if ( version_compare( $v['Version'], $obj->version, '>' ) ) {
continue;
@ -266,7 +259,7 @@ class MainWP_Child_Plugins_Check {
define( 'DAY_IN_SECONDS', 24 * 60 * 60 );
}
//Store the master response for usage in the plugin table
// Store the master response for usage in the plugin table
set_transient( $this->tran_name_plugin_timestamps, $responses, DAY_IN_SECONDS );
if ( 0 === count( $all_plugins ) ) {
@ -278,26 +271,26 @@ class MainWP_Child_Plugins_Check {
}
private function try_get_response_body( $plugin, $second_pass ) {
//Some of this code is lifted from class-wp-upgrader
// Some of this code is lifted from class-wp-upgrader
//Get the WordPress current version to be polite in the API call
include( ABSPATH . WPINC . '/version.php' );
// Get the WordPress current version to be polite in the API call
include ABSPATH . WPINC . '/version.php';
global $wp_version;
//General options to be passed to wp_remote_get
// General options to be passed to wp_remote_get
$options = array(
'timeout' => 60 * 60, //HOUR_IN_SECONDS
'timeout' => 60 * 60, // HOUR_IN_SECONDS
'user-agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' ),
);
//The URL for the endpoint
// The URL for the endpoint
$url = $http_url = 'http://api.wordpress.org/plugins/info/1.0/';
//If we support SSL
//Requires WP 3.2.0
// If we support SSL
// Requires WP 3.2.0
if ( $ssl = wp_http_supports( array( 'ssl' ) ) ) {
//Requires WP 3.4.0
// Requires WP 3.4.0
$url = set_url_scheme( $url, 'https' );
}
@ -306,27 +299,27 @@ class MainWP_Child_Plugins_Check {
$plugin_dir = dirname( $plugin );
}
//Try to get the response (usually the SSL version)
//Requires WP 2.7.0
// Try to get the response (usually the SSL version)
// Requires WP 2.7.0
$raw_response = wp_remote_get( $url . $plugin_dir, $options );
//If we don't have an error and we received a valid response code
//Requires WP 2.7.0
// If we don't have an error and we received a valid response code
// Requires WP 2.7.0
if ( ! is_wp_error( $raw_response ) && 200 === (int) wp_remote_retrieve_response_code( $raw_response ) ) {
//Get the actual body
//Requires WP 2.7.0
// Get the actual body
// Requires WP 2.7.0
$body = wp_remote_retrieve_body( $raw_response );
//Make sure that it isn't empty and also not an empty serialized object
// Make sure that it isn't empty and also not an empty serialized object
if ( '' !== $body && 'N;' !== $body ) {
//If valid, return that
// If valid, return that
return $body;
}
}
//The above valid
//If we previously tried an SSL version try without SSL
//Code below same as above block
// The above valid
// If we previously tried an SSL version try without SSL
// Code below same as above block
if ( $ssl ) {
$raw_response = wp_remote_get( $http_url . $plugin, $options );
if ( ! is_wp_error( $raw_response ) && 200 === (int) wp_remote_retrieve_response_code( $raw_response ) ) {
@ -337,22 +330,22 @@ class MainWP_Child_Plugins_Check {
}
}
//The above failed
//If we're on a second pass already then there's nothing left to do but bail
// The above failed
// If we're on a second pass already then there's nothing left to do but bail
if ( true === $second_pass ) {
return false;
}
//We're still on the first pass, try to get just the name of the directory of the plugin
// We're still on the first pass, try to get just the name of the directory of the plugin
$parts = explode( '/', $plugin );
//Sanity check that we have two parts, a directory and a file name
// Sanity check that we have two parts, a directory and a file name
if ( 2 === count( $parts ) ) {
//Try this entire function using just the directory name
// Try this entire function using just the directory name
return $this->try_get_response_body( $parts[0], true );
}
//Everything above failed, bail
// Everything above failed, bail
return false;
}
}

View file

@ -4,11 +4,11 @@ class MainWP_Child_Robot {
public static $instance = null;
static function Instance() {
if ( null === MainWP_Child_Robot::$instance ) {
MainWP_Child_Robot::$instance = new MainWP_Child_Robot();
if ( null === self::$instance ) {
self::$instance = new MainWP_Child_Robot();
}
return MainWP_Child_Robot::$instance;
return self::$instance;
}
public function wpr_insertcomments( $postid, $comments ) {
@ -23,12 +23,12 @@ class MainWP_Child_Robot {
$comment_author = $comment['author'];
$comment_author_url = '';
$comment_content = '';
$comment_content .= $comment['content'];
$comment_type = '';
$user_ID = '';
$comment_approved = 1;
$commentdata = compact( 'comment_post_ID', 'comment_date', 'comment_date_gmt', 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_content', 'comment_type', 'user_ID', 'comment_approved' );
$comment_id = wp_insert_comment( $commentdata );
$comment_content .= $comment['content'];
$comment_type = '';
$user_ID = '';
$comment_approved = 1;
$commentdata = compact( 'comment_post_ID', 'comment_date', 'comment_date_gmt', 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_content', 'comment_type', 'user_ID', 'comment_approved' );
$comment_id = wp_insert_comment( $commentdata );
}
}
}

View file

@ -2,7 +2,7 @@
class MainWP_Child_Server_Information {
const WARNING = 1;
const ERROR = 2;
const ERROR = 2;
public static function init() {
add_action( 'wp_ajax_mainwp-child_dismiss_warnings', array(
@ -19,10 +19,11 @@ class MainWP_Child_Server_Information {
}
if ( $_POST['what'] == 'warning' ) {
if (isset($_POST['warnings']))
$warnings = intval($_POST['warnings']);
else
$warnings = self::getWarnings();
if (isset($_POST['warnings'])) {
$warnings = intval($_POST['warnings']);
} else {
$warnings = self::getWarnings();
}
$dismissWarnings['warnings'] = $warnings;
}
MainWP_Helper::update_option( 'mainwp_child_dismiss_warnings', $dismissWarnings );
@ -34,7 +35,7 @@ class MainWP_Child_Server_Information {
return;
}
$warnings = self::getWarnings();
$warnings = self::getWarnings();
$dismissWarnings = get_option( 'mainwp_child_dismiss_warnings' );
if ( ! is_array( $dismissWarnings ) ) {
@ -473,12 +474,17 @@ class MainWP_Child_Server_Information {
</div>
<br/>
<div class="mwp_server_info_box">
<h2><?php esc_html_e( 'Server Information' ); ?></h2><?php
MainWP_Child_Server_Information::render();
?><h2><?php esc_html_e( 'Cron Schedules' ); ?></h2><?php
MainWP_Child_Server_Information::renderCron();
?><h2><?php esc_html_e( 'Error Log' ); ?></h2><?php
MainWP_Child_Server_Information::renderErrorLogPage();
<h2><?php esc_html_e( 'Server Information' ); ?></h2>
<?php
self::render();
?>
<h2><?php esc_html_e( 'Cron Schedules' ); ?></h2>
<?php
self::renderCron();
?>
<h2><?php esc_html_e( 'Error Log' ); ?></h2>
<?php
self::renderErrorLogPage();
?>
</div>
</div>
@ -509,7 +515,7 @@ class MainWP_Child_Server_Information {
if ( ! self::check( '>=', '10000', 'getOutputBufferSize' ) ) {
$i ++;
}
// if (!self::check('=', true, 'getSSLSupport')) $i++;
// if (!self::check('=', true, 'getSSLSupport')) $i++;
if ( ! self::checkDirectoryMainWPDirectory( false ) ) {
$i ++;
@ -538,10 +544,10 @@ class MainWP_Child_Server_Information {
public static function render() {
$branding_title = MainWP_Child_Branding::Instance()->get_branding_title();
$isBranding = true;
$isBranding = true;
if ( $branding_title == '' ) {
$branding_title = 'MainWP Child';
$isBranding = false;
$isBranding = false;
}
?>
@ -573,7 +579,7 @@ class MainWP_Child_Server_Information {
</tr>
<?php
self::checkDirectoryMainWPDirectory();
$server = get_option( 'mainwp_child_server' );
$server = get_option( 'mainwp_child_server' );
?>
<tr>
<td></td>
@ -583,8 +589,9 @@ class MainWP_Child_Server_Information {
<td></td>
</tr>
<tr>
<td style="background: #333; color: #fff;" colspan="5"><?php esc_html_e( 'WORDPRESS', 'mainwp-child' ); ?></td>
</tr><?php
<td style="background: #333; color: #fff;" colspan="5"><?php esc_html_e( 'WordPress', 'mainwp-child' ); ?></td>
</tr>
<?php
self::renderRow( 'WordPress Version', '>=', '3.4', 'getWordpressVersion' );
self::renderRow( 'WordPress Memory Limit', '>=', '64M', 'getWordpressMemoryLimit' );
self::renderRow( 'MultiSite Disabled', '=', true, 'checkIfMultisite' );
@ -599,7 +606,8 @@ class MainWP_Child_Server_Information {
<tr>
<td style="background: #333; color: #fff;"
colspan="5"><?php esc_html_e( 'PHP SETTINGS', 'mainwp-child' ); ?></td>
</tr><?php
</tr>
<?php
self::renderRow( 'PHP Version', '>=', '5.6', 'getPHPVersion' );
?>
<tr>
@ -629,13 +637,15 @@ class MainWP_Child_Server_Information {
<tr>
<td style="background: #333; color: #fff;"
colspan="5"><?php esc_html_e( 'MySQL SETTINGS', 'mainwp-child' ); ?></td>
</tr><?php
</tr>
<?php
self::renderRow( 'MySQL Version', '>=', '5.0', 'getMySQLVersion' );
?>
<tr>
<td style="background: #333; color: #fff;"
colspan="5"><?php esc_html_e( 'BACKUP ARCHIVE INFORMATION', 'mainwp-child' ); ?></td>
</tr><?php
</tr>
<?php
self::renderRow( 'ZipArchive enabled in PHP', '=', true, 'getZipArchiveEnabled' );
self::renderRow( 'Tar GZip supported', '=', true, 'getGZipEnabled' );
self::renderRow( 'Tar BZip2 supported', '=', true, 'getBZipEnabled' );
@ -808,7 +818,7 @@ class MainWP_Child_Server_Information {
<td colspan="3"><?php echo esc_html( defined( 'DB_CHARSET' ) ? DB_CHARSET : '' ); ?></td>
</tr>
<tr>
<td style="background: #333; color: #fff;" colspan="5"><?php _e( 'WORDPRESS PLUGINS', 'mainwp-child' ); ?></td>
<td style="background: #333; color: #fff;" colspan="5"><?php _e( 'WordPress PLUGINS', 'mainwp-child' ); ?></td>
</tr>
<?php
$all_plugins = get_plugins();
@ -817,7 +827,7 @@ class MainWP_Child_Server_Information {
if ( $isBranding ) {
if ( $slug == 'mainwp-child/mainwp-child.php' ) {
$plugin['Name'] = esc_html( stripslashes( $branding_title ) );
} else if ($slug == 'mainwp-child-reports/mainwp-child-reports.php') {
} elseif ($slug == 'mainwp-child-reports/mainwp-child-reports.php') {
$plugin['Name'] = esc_html( stripslashes( $branding_title ) ) . ' reports';
}
}
@ -869,7 +879,7 @@ class MainWP_Child_Server_Information {
}
public static function mainwpRequiredFunctions() {
//error_reporting(E_ALL);
// error_reporting(E_ALL);
$disabled_functions = ini_get( 'disable_functions' );
if ( '' !== $disabled_functions ) {
$arr = explode( ',', $disabled_functions );
@ -896,7 +906,7 @@ class MainWP_Child_Server_Information {
}
protected static function getMainwpVersion() {
include_once( ABSPATH . '/wp-admin/includes/plugin-install.php' );
include_once ABSPATH . '/wp-admin/includes/plugin-install.php';
$api = plugins_api( 'plugin_information', array(
'slug' => 'mainwp-child',
'fields' => array( 'sections' => false ),
@ -957,8 +967,9 @@ class MainWP_Child_Server_Information {
protected static function checkDirectoryMainWPDirectory( $write = true ) {
$branding_title = MainWP_Child_Branding::Instance()->get_branding_title();
if ($branding_title == '')
if ($branding_title == '') {
$branding_title = 'MainWP';
}
$branding_title .= ' Upload Directory';
@ -1043,19 +1054,18 @@ class MainWP_Child_Server_Information {
<td><?php echo( $currentVersion === true ? 'true' : $currentVersion ); ?></td>
<?php if ( $whatType == 'filesize' ) { ?>
<td><?php echo( self::filesize_compare( $currentVersion, $pVersion, $pCompare ) ? '<span class="mainwp-pass"><i class="fa fa-check-circle"></i> Pass</span>' : self::getWarningHTML( $errorType ) ); ?></td>
<?php } else if ( $whatType == 'curlssl' ) { ?>
<?php } elseif ( $whatType == 'curlssl' ) { ?>
<td><?php echo( self::curlssl_compare( $pVersion, $pCompare ) ? '<span class="mainwp-pass"><i class="fa fa-check-circle"></i> Pass</span>' : self::getWarningHTML( $errorType ) ); ?></td>
<?php } else if (($pGetter == 'getMaxInputTime' || $pGetter == 'getMaxExecutionTime') && $currentVersion == -1) { ?>
<?php } elseif (( $pGetter == 'getMaxInputTime' || $pGetter == 'getMaxExecutionTime' ) && $currentVersion == -1) { ?>
<td><?php echo '<span class="mainwp-pass"><i class="fa fa-check-circle"></i> Pass</span>'; ?></td>
<?php } else { ?>
<td><?php echo (version_compare($currentVersion, $pVersion, $pCompare) || (($pExtraCompare != null) && version_compare($currentVersion, $pExtraVersion, $pExtraCompare)) ? '<span class="mainwp-pass"><i class="fa fa-check-circle"></i> Pass</span>' : self::getWarningHTML( $errorType )); ?></td>
<td><?php echo ( version_compare($currentVersion, $pVersion, $pCompare) || ( ( $pExtraCompare != null ) && version_compare($currentVersion, $pExtraVersion, $pExtraCompare) ) ? '<span class="mainwp-pass"><i class="fa fa-check-circle"></i> Pass</span>' : self::getWarningHTML( $errorType ) ); ?></td>
<?php } ?>
</tr>
<?php
}
private static function getWarningHTML($errorType = self::WARNING)
{
private static function getWarningHTML( $errorType = self::WARNING) {
if (self::WARNING == $errorType) {
return '<span class="mainwp-warning"><i class="fa fa-exclamation-circle"></i> Warning</span>';
}
@ -1124,9 +1134,9 @@ class MainWP_Child_Server_Information {
protected static function getSSLWarning() {
$conf = array( 'private_key_bits' => 2048 );
$str = '';
$str = '';
if ( function_exists( 'openssl_pkey_new' ) ) {
$res = @openssl_pkey_new( $conf );
$res = @openssl_pkey_new( $conf );
@openssl_pkey_export( $res, $privkey );
$str = openssl_error_string();
@ -1170,7 +1180,10 @@ class MainWP_Child_Server_Information {
}
protected static function getArchitecture() {
echo esc_html( PHP_INT_SIZE * 8 ) ?>&nbsp;bit <?php
echo esc_html( PHP_INT_SIZE * 8 )
?>
&nbsp;bit
<?php
}
protected static function memoryUsage() {
@ -1315,31 +1328,33 @@ class MainWP_Child_Server_Information {
}
protected static function serverSelfConnect() {
$url = site_url( 'wp-cron.php' );
$query_args = array('mainwp_child_run' => 'test');
$url = add_query_arg( $query_args, $url );
$args = array( 'blocking' => TRUE,
'sslverify' => apply_filters( 'https_local_ssl_verify', true ),
'timeout' => 15
$url = site_url( 'wp-cron.php' );
$query_args = array( 'mainwp_child_run' => 'test' );
$url = add_query_arg( $query_args, $url );
$args = array(
'blocking' => true,
'sslverify' => apply_filters( 'https_local_ssl_verify', true ),
'timeout' => 15,
);
$response = wp_remote_post( $url, $args );
$response = wp_remote_post( $url, $args );
$test_result = '';
if ( is_wp_error( $response ) ) {
$test_result .= sprintf( __( 'The HTTP response test get an error "%s"','mainwp-child' ), $response->get_error_message() );
$test_result .= sprintf( __( 'The HTTP response test get an error "%s"', 'mainwp-child' ), $response->get_error_message() );
}
$response_code = wp_remote_retrieve_response_code( $response );
if ( $response_code < 200 && $response_code > 204 ) {
$test_result .= sprintf( __( 'The HTTP response test get a false http status (%s)','mainwp-child' ), wp_remote_retrieve_response_code( $response ) );
if ( $response_code < 200 && $response_code > 204 ) {
$test_result .= sprintf( __( 'The HTTP response test get a false http status (%s)', 'mainwp-child' ), wp_remote_retrieve_response_code( $response ) );
} else {
$response_body = wp_remote_retrieve_body( $response );
if ( FALSE === strstr( $response_body, 'MainWP Test' ) ) {
$test_result .= sprintf( __( 'Not expected HTTP response body: %s','mainwp-child' ), esc_attr( strip_tags( $response_body ) ) );
if ( false === strstr( $response_body, 'MainWP Test' ) ) {
$test_result .= sprintf( __( 'Not expected HTTP response body: %s', 'mainwp-child' ), esc_attr( strip_tags( $response_body ) ) );
}
}
if ( empty( $test_result ) ) {
_e( 'Response Test O.K.', 'mainwp-child' );
} else
} else {
echo $test_result;
}
}
@ -1411,7 +1426,6 @@ class MainWP_Child_Server_Information {
}
return $bytes;
}
@ -1472,7 +1486,7 @@ class MainWP_Child_Server_Information {
$branding_title = 'MainWP';
}
$msg = esc_html( stripslashes( $branding_title ) ) . ' is unable to find your error logs, please contact your host for server error logs.';
echo '<tr><td colspan="2">' . $msg . '</td></tr>';
echo '<tr><td colspan="2">' . $msg . '</td></tr>';
return;
}
@ -1504,7 +1518,6 @@ class MainWP_Child_Server_Information {
echo wp_kses_post( "<tr><td>{$time}</td><td>{$error}</td></tr>" );
}
}
}
static function time_compare( $a, $b ) {
@ -1543,7 +1556,7 @@ class MainWP_Child_Server_Information {
// read them to $data and then move the file pointer
// back to where we were.
fseek( $fh, - $can_read, SEEK_CUR );
$data = fread( $fh, $can_read );
$data = fread( $fh, $can_read );
$data .= $leftover;
fseek( $fh, - $can_read, SEEK_CUR );
@ -1577,7 +1590,7 @@ class MainWP_Child_Server_Information {
if ( file_exists( ABSPATH . 'wp-config.php' ) ) {
@show_source( ABSPATH . 'wp-config.php' );
} else {
$files = @get_included_files();
$files = @get_included_files();
$configFound = false;
if ( is_array( $files ) ) {
foreach ( $files as $file ) {
@ -1589,7 +1602,7 @@ class MainWP_Child_Server_Information {
}
}
if ( !$configFound ) {
if ( ! $configFound ) {
_e( 'wp-config.php not found', 'mainwp' );
}
}
@ -1613,68 +1626,69 @@ class MainWP_Child_Server_Information {
<?php
}
public static function renderConnectionDetails() {
$branding_title = MainWP_Child_Branding::Instance()->get_branding_title();
if ($branding_title == '')
$branding_title = 'MainWP';
public static function renderConnectionDetails() {
$branding_title = MainWP_Child_Branding::Instance()->get_branding_title();
if ($branding_title == '') {
$branding_title = 'MainWP';
}
global $current_user;
$uniqueId = get_option('mainwp_child_uniqueId');
$details = array(
'siteurl' => array(
'title' => __('Site URL', 'mainwp-child'),
'value' => get_bloginfo( 'url' ),
'desc' => get_bloginfo( 'url' )
),
'adminuser' => array(
'title' => __('Administrator name', 'mainwp-child'),
'value' => $current_user->user_login,
'desc' => __('This is your Administrator username, however, you can use any existing Administrator username.', 'mainwp-child')
),
'friendly_name' => array(
'title' => __('Friendly site name', 'mainwp-child'),
'value' => get_bloginfo( 'name' ),
'desc' => __('For the friendly site name, you can use any name, this is just a suggestion.', 'mainwp-child')
),
'uniqueid' => array(
'title' => __('Child unique security id', 'mainwp-child'),
'value' => !empty($uniqueId) ? $uniqueId : __('Leave the field blank', 'mainwp-child'),
'desc' => sprintf(__('Child unique security id is not required, however, since you have enabled it, you need to add it to your %s dashboard.', 'mainwp-child') , stripslashes( $branding_title ) )
),
'verify_ssl' => array(
'title' => __('Verify certificate', 'mainwp-child'),
'value' => __('Yes', 'mainwp-child'),
'desc' => __('If there is an issue with SSL certificate on this site, try to set this option to No.', 'mainwp-child')
),
'ssl_version' => array(
'title' => __('SSL version', 'mainwp-child'),
'value' => __('Auto Detect', 'mainwp-child'),
'desc' => __('Auto Detect', 'mainwp-child'),
),
global $current_user;
$uniqueId = get_option('mainwp_child_uniqueId');
$details = array(
'siteurl' => array(
'title' => __('Site URL', 'mainwp-child'),
'value' => get_bloginfo( 'url' ),
'desc' => get_bloginfo( 'url' ),
),
'adminuser' => array(
'title' => __('Administrator name', 'mainwp-child'),
'value' => $current_user->user_login,
'desc' => __('This is your Administrator username, however, you can use any existing Administrator username.', 'mainwp-child'),
),
'friendly_name' => array(
'title' => __('Friendly site name', 'mainwp-child'),
'value' => get_bloginfo( 'name' ),
'desc' => __('For the friendly site name, you can use any name, this is just a suggestion.', 'mainwp-child'),
),
'uniqueid' => array(
'title' => __('Child unique security id', 'mainwp-child'),
'value' => ! empty($uniqueId) ? $uniqueId : __('Leave the field blank', 'mainwp-child'),
'desc' => sprintf(__('Child unique security id is not required, however, since you have enabled it, you need to add it to your %s dashboard.', 'mainwp-child'), stripslashes( $branding_title ) ),
),
'verify_ssl' => array(
'title' => __('Verify certificate', 'mainwp-child'),
'value' => __('Yes', 'mainwp-child'),
'desc' => __('If there is an issue with SSL certificate on this site, try to set this option to No.', 'mainwp-child'),
),
'ssl_version' => array(
'title' => __('SSL version', 'mainwp-child'),
'value' => __('Auto Detect', 'mainwp-child'),
'desc' => __('Auto Detect', 'mainwp-child'),
),
);
);
?>
<div class="postbox" id="connection_detail">
<h3 class="mainwp_box_title"><span><?php _e( 'Connection details', 'mainwp-child' ); ?></span></h3>
<div class="inside">
<div class="mainwp-postbox-actions-top mainwp-padding-5">
<?php
echo sprintf(__('If you are trying to connect this child site to your %s Dashboard, you can use following details to do that. Please note that these are only suggested values.', 'mainwp-child') , stripslashes( $branding_title ));
?>
<?php
echo sprintf(__('If you are trying to connect this child site to your %s Dashboard, you can use following details to do that. Please note that these are only suggested values.', 'mainwp-child'), stripslashes( $branding_title ));
?>
</div>
<table id="mainwp-table" class="wp-list-table widefat" cellspacing="0" style="border: 0">
<tbody>
<?php
foreach ($details as $row) {
?>
<?php
foreach ($details as $row) {
?>
<tr>
<th style="width: 20%"><strong><?php echo esc_html($row['title']); ?></strong></th>
<td style="width: 20%"><strong><?php echo esc_html($row['value']); ?></strong></td>
<td><?php echo esc_html($row['desc']); ?></td>
</tr>
<?php
}
?>
<?php
}
?>
</tbody>
</table>
</div>
@ -1682,4 +1696,4 @@ class MainWP_Child_Server_Information {
<?php
}
}
}

View file

@ -2,16 +2,16 @@
class MainWP_Child_Skeleton_Key {
public static $instance = null;
public static $instance = null;
public static $information = array();
public $plugin_translate = 'mainwp-child';
public $plugin_translate = 'mainwp-child';
static function Instance() {
if ( null === MainWP_Child_Skeleton_Key::$instance ) {
MainWP_Child_Skeleton_Key::$instance = new MainWP_Child_Skeleton_Key();
if ( null === self::$instance ) {
self::$instance = new MainWP_Child_Skeleton_Key();
}
return MainWP_Child_Skeleton_Key::$instance;
return self::$instance;
}
public function action() {
@ -19,13 +19,13 @@ class MainWP_Child_Skeleton_Key {
error_reporting( 0 );
function mainwp_skeleton_key_handle_fatal_error() {
$error = error_get_last();
if ( isset( $error['type'] ) && in_array($error['type'], array(1, 4, 16, 64, 256) ) && isset( $error['message'] ) ) {
if ( isset( $error['type'] ) && in_array($error['type'], array( 1, 4, 16, 64, 256 ) ) && isset( $error['message'] ) ) {
MainWP_Helper::write( array( 'error' => 'MainWP_Child fatal error : ' . $error['message'] . ' Line: ' . $error['line'] . ' File: ' . $error['file'] ) );
}
// to fix issue double <mainwp></mainwp> header in response
// else {
// MainWP_Helper::write( MainWP_Child_Skeleton_Key::$information );
// }
// else {
// MainWP_Helper::write( MainWP_Child_Skeleton_Key::$information );
// }
}
register_shutdown_function( 'mainwp_skeleton_key_handle_fatal_error' );
@ -42,7 +42,7 @@ class MainWP_Child_Skeleton_Key {
}
MainWP_Helper::write( $information );
//MainWP_Child_Skeleton_Key::$information = $information;
// MainWP_Child_Skeleton_Key::$information = $information;
exit();
}
@ -67,26 +67,31 @@ class MainWP_Child_Skeleton_Key {
$manager = WP_Session_Tokens::get_instance( $current_user->ID );
$token = $manager->create( $expiration );
$secure = is_ssl();
if ( $secure ) {
$auth_cookie_name = SECURE_AUTH_COOKIE;
$scheme = 'secure_auth';
$scheme = 'secure_auth';
} else {
$auth_cookie_name = AUTH_COOKIE;
$scheme = 'auth';
$scheme = 'auth';
}
$auth_cookie = wp_generate_auth_cookie( $current_user->ID, $expiration, $scheme, $token );
$logged_in_cookie = wp_generate_auth_cookie( $current_user->ID, $expiration, 'logged_in', $token );
$_COOKIE[ $auth_cookie_name ] = $auth_cookie;
$_COOKIE[ LOGGED_IN_COOKIE ] = $logged_in_cookie;
$post_args = array();
$post_args['body'] = array();
$post_args['redirection'] = 5;
$post_args['decompress'] = false; // For gzinflate() data error bug
$post_args['cookies'] = array(
new WP_Http_Cookie( array( 'name' => $auth_cookie_name, 'value' => $auth_cookie ) ),
new WP_Http_Cookie( array( 'name' => LOGGED_IN_COOKIE, 'value' => $logged_in_cookie ) ),
$auth_cookie = wp_generate_auth_cookie( $current_user->ID, $expiration, $scheme, $token );
$logged_in_cookie = wp_generate_auth_cookie( $current_user->ID, $expiration, 'logged_in', $token );
$_COOKIE[ $auth_cookie_name ] = $auth_cookie;
$_COOKIE[ LOGGED_IN_COOKIE ] = $logged_in_cookie;
$post_args = array();
$post_args['body'] = array();
$post_args['redirection'] = 5;
$post_args['decompress'] = false; // For gzinflate() data error bug
$post_args['cookies'] = array(
new WP_Http_Cookie( array(
'name' => $auth_cookie_name,
'value' => $auth_cookie,
) ),
new WP_Http_Cookie( array(
'name' => LOGGED_IN_COOKIE,
'value' => $logged_in_cookie,
) ),
);
if ( isset( $args['get'] ) ) {
@ -190,30 +195,33 @@ class MainWP_Child_Skeleton_Key {
public function save_settings() {
$settings = isset($_POST['settings']) ? $_POST['settings'] : array();
if (!is_array($settings) || empty($settings))
return array('error' => 'Invalid data. Please check and try again.');
if ( ! is_array($settings) || empty($settings)) {
return array( 'error' => 'Invalid data. Please check and try again.' );
}
$whitelist_options = array(
'general' => array( 'blogname', 'blogdescription', 'gmt_offset', 'date_format', 'time_format', 'start_of_week', 'timezone_string', 'WPLANG' ),
);
if ( !is_multisite() ) {
if ( !defined( 'WP_SITEURL' ) )
if ( ! is_multisite() ) {
if ( ! defined( 'WP_SITEURL' ) ) {
$whitelist_options['general'][] = 'siteurl';
if ( !defined( 'WP_HOME' ) )
}
if ( ! defined( 'WP_HOME' ) ) {
$whitelist_options['general'][] = 'home';
}
$whitelist_options['general'][] = 'admin_email';
$whitelist_options['general'][] = 'users_can_register';
$whitelist_options['general'][] = 'default_role';
}
//$whitelist_options = apply_filters( 'whitelist_options', $whitelist_options );
$whitelist_general = $whitelist_options[ 'general' ];
// $whitelist_options = apply_filters( 'whitelist_options', $whitelist_options );
$whitelist_general = $whitelist_options['general'];
// Handle translation install.
if ( ! empty( $settings['WPLANG'] ) ) {
require_once( ABSPATH . 'wp-admin/includes/translation-install.php' );
require_once ABSPATH . 'wp-admin/includes/translation-install.php';
if ( wp_can_install_language_pack() ) {
$language = wp_download_language_pack( $settings['WPLANG'] );
if ( $language ) {
@ -223,20 +231,22 @@ class MainWP_Child_Skeleton_Key {
}
$updated = false;
foreach($settings as $option => $value) {
foreach ($settings as $option => $value) {
if (in_array($option, $whitelist_general)) {
if ( ! is_array( $value ) )
if ( ! is_array( $value ) ) {
$value = trim( $value );
}
$value = wp_unslash( $value );
update_option($option, $value);
$updated = true;
}
}
if (!$updated)
if ( ! $updated) {
return false;
}
return array('result' => 'ok');
return array( 'result' => 'ok' );
}
}

View file

@ -18,37 +18,40 @@
class MainWP_Child_Staging {
public static $instance = null;
public static $instance = null;
public $is_plugin_installed = false;
static function Instance() {
if ( null === MainWP_Child_Staging::$instance ) {
MainWP_Child_Staging::$instance = new MainWP_Child_Staging();
if ( null === self::$instance ) {
self::$instance = new MainWP_Child_Staging();
}
return MainWP_Child_Staging::$instance;
return self::$instance;
}
public function __construct() {
require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
require_once ABSPATH . 'wp-admin/includes/plugin.php';
if ( is_plugin_active( 'wp-staging/wp-staging.php' ) && defined('WPSTG_PLUGIN_DIR')) {
$this->is_plugin_installed = true;
} else if ( is_plugin_active( 'wp-staging-pro/wp-staging-pro.php' ) ) {
} elseif ( is_plugin_active( 'wp-staging-pro/wp-staging-pro.php' ) ) {
$this->is_plugin_installed = true;
}
if (!$this->is_plugin_installed)
if ( ! $this->is_plugin_installed) {
return;
}
add_filter( 'mainwp-site-sync-others-data', array( $this, 'syncOthersData' ), 10, 2 );
}
public function init() {
if ( get_option( 'mainwp_wp_staging_ext_enabled' ) !== 'Y' )
if ( get_option( 'mainwp_wp_staging_ext_enabled' ) !== 'Y' ) {
return;
}
if (!$this->is_plugin_installed)
if ( ! $this->is_plugin_installed) {
return;
}
if ( get_option( 'mainwp_wp_staging_hide_plugin' ) === 'hide' ) {
add_filter( 'all_plugins', array( $this, 'all_plugins' ) );
@ -60,9 +63,9 @@ class MainWP_Child_Staging {
public function syncOthersData( $information, $data = array() ) {
if ( isset( $data['syncWPStaging'] ) && $data['syncWPStaging'] ) {
try{
try {
$information['syncWPStaging'] = $this->get_sync_data();
} catch(Exception $e) {
} catch (Exception $e) {
// do not exit
}
}
@ -74,75 +77,75 @@ class MainWP_Child_Staging {
}
public function action() {
if (!$this->is_plugin_installed) {
MainWP_Helper::write( array('error' => 'Please install WP Staging plugin on child website') );
}
if ( ! $this->is_plugin_installed) {
MainWP_Helper::write( array( 'error' => 'Please install WP Staging plugin on child website' ) );
}
if (!class_exists( 'WPStaging\WPStaging' )){
require_once WPSTG_PLUGIN_DIR . "apps/Core/WPStaging.php";
}
if ( ! class_exists( 'WPStaging\WPStaging' )) {
require_once WPSTG_PLUGIN_DIR . 'apps/Core/WPStaging.php';
}
\WPStaging\WPStaging::getInstance();
$information = array();
if (get_option( 'mainwp_wp_staging_ext_enabled' ) !== 'Y') {
MainWP_Helper::update_option( 'mainwp_wp_staging_ext_enabled', 'Y', 'yes' );
}
if (get_option( 'mainwp_wp_staging_ext_enabled' ) !== 'Y') {
MainWP_Helper::update_option( 'mainwp_wp_staging_ext_enabled', 'Y', 'yes' );
}
if ( isset( $_POST['mwp_action'] ) ) {
switch ( $_POST['mwp_action'] ) {
case 'set_showhide':
$information = $this->set_showhide();
break;
case 'save_settings':
$information = $this->save_settings();
break;
case 'get_overview':
$information = $this->get_overview();
break;
case 'get_scan':
$information = $this->get_scan();
break;
case 'check_disk_space':
$information = $this->ajaxCheckFreeSpace();
break;
case 'check_clone':
$information = $this->ajaxCheckCloneName();
break;
case 'start_clone':
$information = $this->ajaxStartClone();
break;
case 'clone_database':
$information = $this->ajaxCloneDatabase();
break;
case 'prepare_directories':
$information = $this->ajaxPrepareDirectories();
break;
case 'copy_files':
$information = $this->ajaxCopyFiles();
break;
case 'replace_data':
$information = $this->ajaxReplaceData();
break;
case 'clone_finish':
$information = $this->ajaxFinish();
break;
case 'delete_confirmation':
$information = $this->ajaxDeleteConfirmation();
break;
case 'delete_clone':
$information = $this->ajaxDeleteClone();
break;
case 'cancel_clone':
$information = $this->ajaxCancelClone();
break;
case 'staging_update':
$information = $this->ajaxUpdateProcess();
break;
case 'cancel_update':
$information = $this->ajaxCancelUpdate();
break;
}
}
if ( isset( $_POST['mwp_action'] ) ) {
switch ( $_POST['mwp_action'] ) {
case 'set_showhide':
$information = $this->set_showhide();
break;
case 'save_settings':
$information = $this->save_settings();
break;
case 'get_overview':
$information = $this->get_overview();
break;
case 'get_scan':
$information = $this->get_scan();
break;
case 'check_disk_space':
$information = $this->ajaxCheckFreeSpace();
break;
case 'check_clone':
$information = $this->ajaxCheckCloneName();
break;
case 'start_clone':
$information = $this->ajaxStartClone();
break;
case 'clone_database':
$information = $this->ajaxCloneDatabase();
break;
case 'prepare_directories':
$information = $this->ajaxPrepareDirectories();
break;
case 'copy_files':
$information = $this->ajaxCopyFiles();
break;
case 'replace_data':
$information = $this->ajaxReplaceData();
break;
case 'clone_finish':
$information = $this->ajaxFinish();
break;
case 'delete_confirmation':
$information = $this->ajaxDeleteConfirmation();
break;
case 'delete_clone':
$information = $this->ajaxDeleteClone();
break;
case 'cancel_clone':
$information = $this->ajaxCancelClone();
break;
case 'staging_update':
$information = $this->ajaxUpdateProcess();
break;
case 'cancel_update':
$information = $this->ajaxCancelUpdate();
break;
}
}
MainWP_Helper::write( $information );
}
@ -155,7 +158,7 @@ class MainWP_Child_Staging {
function save_settings() {
$settings = $_POST['settings'];
$filters = array(
$filters = array(
'queryLimit',
'fileLimit',
'batchSize',
@ -164,27 +167,27 @@ class MainWP_Child_Staging {
'disableAdminLogin',
'querySRLimit',
'maxFileSize',
//'wpSubDirectory', // removed
// 'wpSubDirectory', // removed
'debugMode',
'unInstallOnDelete',
'checkDirectorySize',
'optimizer',
//'loginSlug' // removed
// 'loginSlug' // removed
);
$save_fields = array();
foreach($filters as $field) {
if (isset($settings[$field])) {
$save_fields[$field] = $settings[$field];
foreach ($filters as $field) {
if (isset($settings[ $field ])) {
$save_fields[ $field ] = $settings[ $field ];
}
}
update_option('wpstg_settings', $save_fields );
return array('result' => 'success');
return array( 'result' => 'success' );
}
public function get_overview() {
$return = array(
'availableClones' => get_option( "wpstg_existing_clones_beta", array())
'availableClones' => get_option( 'wpstg_existing_clones_beta', array()),
);
return $return;
}
@ -198,198 +201,195 @@ class MainWP_Child_Staging {
$options = $scan->getOptions();
$return = array(
'options' => serialize($options),
'options' => serialize($options),
'directoryListing' => $scan->directoryListing(),
'prefix' => WPStaging\WPStaging::getTablePrefix()
'prefix' => WPStaging\WPStaging::getTablePrefix(),
);
return $return;
}
}
public function ajaxCheckCloneName() {
$cloneName = sanitize_key( $_POST["cloneID"] );
$cloneNameLength = strlen( $cloneName );
$clones = get_option( "wpstg_existing_clones_beta", array() );
$cloneName = sanitize_key( $_POST['cloneID'] );
$cloneNameLength = strlen( $cloneName );
$clones = get_option( 'wpstg_existing_clones_beta', array() );
// Check clone name length
if( $cloneNameLength < 1 || $cloneNameLength > 16 ) {
echo array(
"status" => "failed",
"message" => "Clone name must be between 1 - 16 characters"
);
} elseif( array_key_exists( $cloneName, $clones ) ) {
return array(
"status" => "failed",
"message" => "Clone name is already in use, please choose an another clone name"
);
}
// Check clone name length
if ( $cloneNameLength < 1 || $cloneNameLength > 16 ) {
echo array(
'status' => 'failed',
'message' => 'Clone name must be between 1 - 16 characters',
);
} elseif ( array_key_exists( $cloneName, $clones ) ) {
return array(
'status' => 'failed',
'message' => 'Clone name is already in use, please choose an another clone name',
);
}
return array("status" => "success");
}
return array( 'status' => 'success' );
}
public function ajaxStartClone() {
public function ajaxStartClone() {
$this->url = ''; // to fix warning
$cloning = new WPStaging\Backend\Modules\Jobs\Cloning();
$this->url = ''; // to fix warning
$cloning = new WPStaging\Backend\Modules\Jobs\Cloning();
if( !$cloning->save() ) {
return;
}
ob_start();
require_once WPSTG_PLUGIN_DIR . "apps/Backend/views/clone/ajax/start.php";
$result = ob_get_clean();
return $result;
}
public function ajaxCloneDatabase() {
$cloning = new WPStaging\Backend\Modules\Jobs\Cloning();
return $cloning->start();
}
/**
* Ajax Prepare Directories (get listing of files)
*/
public function ajaxPrepareDirectories() {
$cloning = new WPStaging\Backend\Modules\Jobs\Cloning();
return $cloning->start();
}
/**
* Ajax Clone Files
*/
public function ajaxCopyFiles() {
$cloning = new WPStaging\Backend\Modules\Jobs\Cloning();
return $cloning->start();
}
/**
* Ajax Replace Data
*/
public function ajaxReplaceData() {
$cloning = new WPStaging\Backend\Modules\Jobs\Cloning();
return $cloning->start();
}
/**
* Ajax Finish
*/
public function ajaxFinish() {
$cloning = new WPStaging\Backend\Modules\Jobs\Cloning();
$this->url = ''; // to fix warning
$return = $cloning->start();
$return->blogInfoName = get_bloginfo("name");
return $return;
}
/**
* Ajax Delete Confirmation
*/
public function ajaxDeleteConfirmation() {
$delete = new WPStaging\Backend\Modules\Jobs\Delete();
$delete->setData();
$clone = $delete->getClone();
$result = array(
'clone' => $clone,
'deleteTables' => $delete->getTables()
);
return $result;
}
/**
* Delete clone
*/
public function ajaxDeleteClone() {
$delete = new WPStaging\Backend\Modules\Jobs\Delete();
return $delete->start();
}
/**
* Delete clone
*/
public function ajaxCancelClone() {
$cancel = new WPStaging\Backend\Modules\Jobs\Cancel();
return $cancel->start();
}
public function ajaxCancelUpdate() {
$cancel = new WPStaging\Backend\Modules\Jobs\CancelUpdate();
return $cancel->start();
}
public function ajaxUpdateProcess() {
$cloning = new WPStaging\Backend\Modules\Jobs\Updating();
if( !$cloning->save() ) {
return;
if ( ! $cloning->save() ) {
return;
}
ob_start();
require_once WPSTG_PLUGIN_DIR . "apps/Backend/views/clone/ajax/update.php";
require_once WPSTG_PLUGIN_DIR . 'apps/Backend/views/clone/ajax/start.php';
$result = ob_get_clean();
return $result;
}
}
public function ajaxCloneDatabase() {
$cloning = new WPStaging\Backend\Modules\Jobs\Cloning();
return $cloning->start();
}
/**
* Ajax Prepare Directories (get listing of files)
*/
public function ajaxPrepareDirectories() {
$cloning = new WPStaging\Backend\Modules\Jobs\Cloning();
return $cloning->start();
}
/**
* Ajax Clone Files
*/
public function ajaxCopyFiles() {
$cloning = new WPStaging\Backend\Modules\Jobs\Cloning();
return $cloning->start();
}
/**
* Ajax Replace Data
*/
public function ajaxReplaceData() {
$cloning = new WPStaging\Backend\Modules\Jobs\Cloning();
return $cloning->start();
}
/**
* Ajax Finish
*/
public function ajaxFinish() {
$cloning = new WPStaging\Backend\Modules\Jobs\Cloning();
$this->url = ''; // to fix warning
$return = $cloning->start();
$return->blogInfoName = get_bloginfo('name');
return $return;
}
/**
* Ajax Delete Confirmation
*/
public function ajaxDeleteConfirmation() {
$delete = new WPStaging\Backend\Modules\Jobs\Delete();
$delete->setData();
$clone = $delete->getClone();
$result = array(
'clone' => $clone,
'deleteTables' => $delete->getTables(),
);
return $result;
}
/**
* Delete clone
*/
public function ajaxDeleteClone() {
$delete = new WPStaging\Backend\Modules\Jobs\Delete();
return $delete->start();
}
/**
* Delete clone
*/
public function ajaxCancelClone() {
$cancel = new WPStaging\Backend\Modules\Jobs\Cancel();
return $cancel->start();
}
public function ajaxCancelUpdate() {
$cancel = new WPStaging\Backend\Modules\Jobs\CancelUpdate();
return $cancel->start();
}
public function ajaxUpdateProcess() {
$cloning = new WPStaging\Backend\Modules\Jobs\Updating();
if ( ! $cloning->save() ) {
return;
}
ob_start();
require_once WPSTG_PLUGIN_DIR . 'apps/Backend/views/clone/ajax/update.php';
$result = ob_get_clean();
return $result;
}
public function ajaxCheckFreeSpace() {
return $this->hasFreeDiskSpace();
return $this->hasFreeDiskSpace();
}
// from wp-staging plugin
public function hasFreeDiskSpace() {
if( !function_exists( "disk_free_space" ) ) {
return null;
}
$freeSpace = @disk_free_space( ABSPATH );
if( false === $freeSpace ) {
$data = array(
'freespace' => false,
'usedspace' => $this->formatSize($this->getDirectorySizeInclSubdirs(ABSPATH))
);
return $data;
}
$data = array(
'freespace' => $this->formatSize($freeSpace),
'usedspace' => $this->formatSize($this->getDirectorySizeInclSubdirs(ABSPATH))
);
return $data;
}
if ( ! function_exists( 'disk_free_space' ) ) {
return null;
}
$freeSpace = @disk_free_space( ABSPATH );
if ( false === $freeSpace ) {
$data = array(
'freespace' => false,
'usedspace' => $this->formatSize($this->getDirectorySizeInclSubdirs(ABSPATH)),
);
return $data;
}
$data = array(
'freespace' => $this->formatSize($freeSpace),
'usedspace' => $this->formatSize($this->getDirectorySizeInclSubdirs(ABSPATH)),
);
return $data;
}
// from wp-staging plugin
function getDirectorySizeInclSubdirs( $dir ) {
$size = 0;
foreach ( glob( rtrim( $dir, '/' ) . '/*', GLOB_NOSORT ) as $each ) {
$size += is_file( $each ) ? filesize( $each ) : $this->getDirectorySizeInclSubdirs( $each );
}
return $size;
}
$size = 0;
foreach ( glob( rtrim( $dir, '/' ) . '/*', GLOB_NOSORT ) as $each ) {
$size += is_file( $each ) ? filesize( $each ) : $this->getDirectorySizeInclSubdirs( $each );
}
return $size;
}
// from wp-staging plugin
public function formatSize($bytes, $precision = 2)
{
if ((double) $bytes < 1)
{
public function formatSize( $bytes, $precision = 2) {
if ( (float) $bytes < 1) {
return '';
}
$units = array('B', "KB", "MB", "GB", "TB");
$units = array( 'B', 'KB', 'MB', 'GB', 'TB' );
$bytes = (double) $bytes;
$base = log($bytes) / log(1000); // 1024 would be for MiB KiB etc
$pow = pow(1000, $base - floor($base)); // Same rule for 1000
$bytes = (float) $bytes;
$base = log($bytes) / log(1000); // 1024 would be for MiB KiB etc
$pow = pow(1000, $base - floor($base)); // Same rule for 1000
return round($pow, $precision) . ' ' . $units[(int) floor($base)];
return round($pow, $precision) . ' ' . $units[ (int) floor($base) ];
}
@ -423,7 +423,7 @@ class MainWP_Child_Staging {
return $value;
}
if (! MainWP_Helper::is_screen_with_update()) {
if ( ! MainWP_Helper::is_screen_with_update()) {
return $value;
}

View file

@ -29,11 +29,11 @@ class MainWP_Child_Themes_Check {
private $option_name_last_daily_run = 'mainwp_child_theme_last_daily_run';
public static function Instance() {
if ( null === MainWP_Child_Themes_Check::$instance ) {
MainWP_Child_Themes_Check::$instance = new MainWP_Child_Themes_Check();
if ( null === self::$instance ) {
self::$instance = new MainWP_Child_Themes_Check();
}
return MainWP_Child_Themes_Check::$instance;
return self::$instance;
}
public function __construct() {
@ -49,7 +49,6 @@ class MainWP_Child_Themes_Check {
add_action( 'mainwp_child_deactivation', array( $this, 'cleanup_deactivation' ) );
}
}
private function cleanup_basic() {
@ -96,7 +95,7 @@ class MainWP_Child_Themes_Check {
$last_run = new \DateTime( '@' . $last_run );
}
//Get now
// Get now
$now = new \DateTime();
if ( false === $last_run || (int) $now->diff( $last_run )->format( '%h' ) >= 24 ) {
@ -111,14 +110,13 @@ class MainWP_Child_Themes_Check {
}
public function schedule_watchdog() {
//For testing
//$this->cleanup_deactivation();
// For testing
// $this->cleanup_deactivation();
//Schedule a global watching cron just in case both other crons get killed
// Schedule a global watching cron just in case both other crons get killed
if ( ! wp_next_scheduled( $this->cron_name_watcher ) ) {
wp_schedule_event( time(), 'hourly', $this->cron_name_watcher );
}
}
public function get_themes_outdate_info() {
@ -127,7 +125,7 @@ class MainWP_Child_Themes_Check {
$themes_outdate = array();
}
if ( ! function_exists( 'wp_get_themes' ) ) {
require_once( ABSPATH . '/wp-admin/includes/theme.php' );
require_once ABSPATH . '/wp-admin/includes/theme.php';
}
$themes = wp_get_themes();
$update = false;
@ -146,10 +144,10 @@ class MainWP_Child_Themes_Check {
public function run_check() {
if ( ! function_exists( 'wp_get_themes' ) ) {
require_once( ABSPATH . '/wp-admin/includes/theme.php' );
require_once ABSPATH . '/wp-admin/includes/theme.php';
}
//Get our previous results
// Get our previous results
$responses = get_transient( $this->tran_name_theme_timestamps );
if ( false === $responses || ! is_array( $responses ) ) {
@ -157,10 +155,10 @@ class MainWP_Child_Themes_Check {
}
$all_themes = get_transient( $this->tran_name_themes_to_batch );
//If there wasn't a previous cache
// If there wasn't a previous cache
if ( false === $all_themes || ! is_array( $all_themes ) ) {
$all_themes = array();
$themes = wp_get_themes();
$themes = wp_get_themes();
if ( is_array( $themes ) ) {
foreach ( $themes as $theme ) {
$slug = $theme->get_stylesheet();
@ -174,12 +172,14 @@ class MainWP_Child_Themes_Check {
$responses = array();
}
$avoid_themes = array( 'superstore' );
$themes_to_scan = array_splice( $all_themes, 0, apply_filters( 'mainwp_child_theme_health_check_max_themes_to_batch', 10 ) );
$avoid_themes = array( 'superstore' );
$themes_to_scan = array_splice( $all_themes, 0, apply_filters( 'mainwp_child_theme_health_check_max_themes_to_batch', 10 ) );
$tolerance_in_days = get_option( 'mainwp_child_plugintheme_days_outdate', 365 );
foreach ( $themes_to_scan as $slug => $v ) {
if ( in_array( $slug, $avoid_themes ) ) continue;
if ( in_array( $slug, $avoid_themes ) ) {
continue;
}
$body = $this->try_get_response_body( $slug, false );
@ -187,19 +187,18 @@ class MainWP_Child_Themes_Check {
continue;
}
//Deserialize the response
// Deserialize the response
$obj = maybe_unserialize( $body );
$now = new \DateTime();
//Sanity check that deserialization worked and that our property exists
// Sanity check that deserialization worked and that our property exists
if ( false !== $obj && is_object( $obj ) && property_exists( $obj, 'last_updated' ) ) {
$last_updated = strtotime( $obj->last_updated );
$theme_last_updated_date = new \DateTime( '@' . $last_updated );
$diff_in_days = $now->diff( $theme_last_updated_date )->format( '%a' );
if ( $diff_in_days < $tolerance_in_days ) {
continue;
}
@ -214,7 +213,7 @@ class MainWP_Child_Themes_Check {
define( 'DAY_IN_SECONDS', 24 * 60 * 60 );
}
//Store the master response for usage in the plugin table
// Store the master response for usage in the plugin table
set_transient( $this->tran_name_theme_timestamps, $responses, DAY_IN_SECONDS );
if ( 0 === count( $all_themes ) ) {
@ -228,15 +227,21 @@ class MainWP_Child_Themes_Check {
private function try_get_response_body( $theme ) {
//Get the WordPress current version to be polite in the API call
include( ABSPATH . WPINC . '/version.php' );
// Get the WordPress current version to be polite in the API call
include ABSPATH . WPINC . '/version.php';
$url = $http_url = 'http://api.wordpress.org/themes/info/1.0/';
if ( $ssl = wp_http_supports( array( 'ssl' ) ) ) {
$url = set_url_scheme( $url, 'https' );
}
$args = array( 'slug' => $theme, 'fields' => array( 'sections' => false, 'tags' => false ) );
$args = array(
'slug' => $theme,
'fields' => array(
'sections' => false,
'tags' => false,
),
);
$args = (object) $args;
$http_args = array(
@ -249,20 +254,20 @@ class MainWP_Child_Themes_Check {
$raw_response = wp_remote_post( $url, $http_args );
if ( ! is_wp_error( $raw_response ) && 200 === (int) wp_remote_retrieve_response_code( $raw_response ) ) {
//Get the actual body
//Requires WP 2.7.0
// Get the actual body
// Requires WP 2.7.0
$body = wp_remote_retrieve_body( $raw_response );
//Make sure that it isn't empty and also not an empty serialized object
// Make sure that it isn't empty and also not an empty serialized object
if ( '' !== $body && 'N;' !== $body ) {
//If valid, return that
// If valid, return that
return $body;
}
}
//The above valid
//If we previously tried an SSL version try without SSL
//Code below same as above block
// The above valid
// If we previously tried an SSL version try without SSL
// Code below same as above block
if ( $ssl ) {
$raw_response = wp_remote_post( $http_url, $http_args );
@ -274,7 +279,7 @@ class MainWP_Child_Themes_Check {
}
}
//Everything above failed, bail
// Everything above failed, bail
return false;
}
}

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -19,118 +19,121 @@
class MainWP_Child_Vulnerability_Checker {
public static $instance = null;
private $wpvulndb_api = 'https://wpvulndb.com/api/v3/';
private $wpvulndb_api = 'https://wpvulndb.com/api/v3/';
private $wpvulndb_token = false;
static function Instance() {
if ( null === MainWP_Child_Vulnerability_Checker::$instance ) {
MainWP_Child_Vulnerability_Checker::$instance = new MainWP_Child_Vulnerability_Checker();
}
return MainWP_Child_Vulnerability_Checker::$instance;
if ( null === self::$instance ) {
self::$instance = new MainWP_Child_Vulnerability_Checker();
}
return self::$instance;
}
public function __construct() {
$this->wpvulndb_token = get_option('mainwp_child_wpvulndb_token', '');
$this->wpvulndb_token = get_option('mainwp_child_wpvulndb_token', '');
}
public function action() {
$information = array();
if ( ! empty( $this->wpvulndb_token ) ) {
if ( isset( $_POST['mwp_action'] ) ) {
switch ( $_POST['mwp_action'] ) {
case 'vulner_recheck':
$information = $this->vulner_recheck();
break;
}
if ( ! empty( $this->wpvulndb_token ) ) {
if ( isset( $_POST['mwp_action'] ) ) {
switch ( $_POST['mwp_action'] ) {
case 'vulner_recheck':
$information = $this->vulner_recheck();
break;
}
}
}
MainWP_Helper::write( $information );
}
function vulner_recheck(){
$result = array();
$force = (isset($_POST['force']) && !empty($_POST['force'])) ? true : false;
function vulner_recheck() {
$result = array();
$force = ( isset($_POST['force']) && ! empty($_POST['force']) ) ? true : false;
$result['plugin'] = $this->check_plugins($force);
$result['wp'] = $this->check_wp($force);
$result['theme'] = $this->check_themes($force);
$information = array( 'result' => $result, 'ok' => 1);
$result['wp'] = $this->check_wp($force);
$result['theme'] = $this->check_themes($force);
$information = array(
'result' => $result,
'ok' => 1,
);
return $information;
}
function check_plugins($force = false){
$result = array();
function check_plugins( $force = false) {
$result = array();
$active_plugins = get_option('active_plugins');
if( !empty($active_plugins) ){
foreach($active_plugins as $plug){
if ( ! empty($active_plugins) ) {
foreach ($active_plugins as $plug) {
$plugin_file = WP_CONTENT_DIR . '/plugins/' . $plug;
$plugin_info = get_plugin_data($plugin_file);
$plugin_version = isset($plugin_info['Version']) ? $plugin_info['Version'] : '';
$string = explode('/',$plug);
$plug_vuln = get_transient('mainwp_vulnche_trans_plug_'.$string[0]);
if(false === $plug_vuln || $force) {
$plug_vuln = $this->vulnche_get_content( $this->wpvulndb_api . 'plugins/' . $string[0]);
set_transient('mainwp_vulnche_trans_plug_'.$string[0],$plug_vuln, 1 * DAY_IN_SECONDS);
}
if ($plug_vuln) {
$plug_vuln = json_decode($plug_vuln, true);
$plug_vuln_filter = $plug_vuln;
$plugin_file = WP_CONTENT_DIR . '/plugins/' . $plug;
$plugin_info = get_plugin_data($plugin_file);
$plugin_version = isset($plugin_info['Version']) ? $plugin_info['Version'] : '';
$string = explode('/', $plug);
$plug_vuln = get_transient('mainwp_vulnche_trans_plug_' . $string[0]);
if (false === $plug_vuln || $force) {
$plug_vuln = $this->vulnche_get_content( $this->wpvulndb_api . 'plugins/' . $string[0]);
set_transient('mainwp_vulnche_trans_plug_' . $string[0], $plug_vuln, 1 * DAY_IN_SECONDS);
}
if ($plug_vuln) {
$plug_vuln = json_decode($plug_vuln, true);
$plug_vuln_filter = $plug_vuln;
foreach ($plug_vuln as $slug => $pl_data) {
if (isset($pl_data['vulnerabilities']) && count($pl_data['vulnerabilities']) > 0) {
$plug_vulner_data = array();
foreach($pl_data['vulnerabilities'] as $vuln_data) {
if ( isset($vuln_data['fixed_in']) && version_compare( $plugin_version, $vuln_data['fixed_in'] ) >= 0 ) {
continue;
}
$plug_vulner_data[] = $vuln_data;
}
foreach ($plug_vuln as $slug => $pl_data) {
if (isset($pl_data['vulnerabilities']) && count($pl_data['vulnerabilities']) > 0) {
$plug_vulner_data = array();
foreach ($pl_data['vulnerabilities'] as $vuln_data) {
if ( isset($vuln_data['fixed_in']) && version_compare( $plugin_version, $vuln_data['fixed_in'] ) >= 0 ) {
continue;
}
$plug_vulner_data[] = $vuln_data;
}
if(count($plug_vulner_data) == 0) {
unset($plug_vuln_filter[$slug]);
} else {
$plug_vuln_filter[$slug]['vulnerabilities'] = $plug_vulner_data;
$plug_vuln_filter[$slug]['detected_version'] = $plugin_version;
$plug_vuln_filter[$slug]['plugin_slug'] = $plug;
}
if (count($plug_vulner_data) == 0) {
unset($plug_vuln_filter[ $slug ]);
} else {
$plug_vuln_filter[ $slug ]['vulnerabilities'] = $plug_vulner_data;
$plug_vuln_filter[ $slug ]['detected_version'] = $plugin_version;
$plug_vuln_filter[ $slug ]['plugin_slug'] = $plug;
}
} else {
unset($plug_vuln_filter[$slug]);
}
} else {
unset($plug_vuln_filter[ $slug ]);
}
}
}
if (count($plug_vuln_filter) == 0) {
continue;
}
$plug_vuln = json_encode($plug_vuln_filter);
if (count($plug_vuln_filter) == 0) {
continue;
}
$plug_vuln = json_encode($plug_vuln_filter);
} else {
continue;
}
$result[$plug] = $plug_vuln;
}
}
} else {
continue;
}
$result[ $plug ] = $plug_vuln;
}
}
return $result;
}
function check_wp($force = false){
$wp_vuln = get_transient('mainwp_vulnche_trans_wp_json');
function check_wp( $force = false) {
$wp_vuln = get_transient('mainwp_vulnche_trans_wp_json');
$wp_version = str_replace('.', '', get_bloginfo('version'));
if(false === $wp_vuln || $force) {
$wp_vuln = $this->vulnche_get_content( $this->wpvulndb_api . 'wordpresses/' . $wp_version);
set_transient('mainwp_vulnche_trans_wp_json', $wp_vuln, 1 * DAY_IN_SECONDS);
}
if (false === $wp_vuln || $force) {
$wp_vuln = $this->vulnche_get_content( $this->wpvulndb_api . 'wordpresses/' . $wp_version);
set_transient('mainwp_vulnche_trans_wp_json', $wp_vuln, 1 * DAY_IN_SECONDS);
}
return $wp_vuln;
}
function check_themes($force = false){
function check_themes( $force = false) {
require_once( ABSPATH . 'wp-admin/includes/misc.php' );
require_once( ABSPATH . 'wp-admin/includes/theme.php' );
require_once ABSPATH . 'wp-admin/includes/misc.php';
require_once ABSPATH . 'wp-admin/includes/theme.php';
if ( current_user_can( 'switch_themes' ) ) {
$themes = wp_prepare_themes_for_js();
@ -139,9 +142,9 @@ class MainWP_Child_Vulnerability_Checker {
}
wp_reset_vars( array( 'theme', 'search' ) );
$result = array();
if(!empty($themes)){
foreach($themes as $th){
if(empty($th['parent'])) {
if ( ! empty($themes)) {
foreach ($themes as $th) {
if (empty($th['parent'])) {
$th_vuln = get_transient('mainwp_vulnche_trans_theme_' . $th['id']);
if (false === $th_vuln || $force) {
$th_vuln = $this->vulnche_get_content( $this->wpvulndb_api . 'themes/' . $th['id']);
@ -149,15 +152,16 @@ class MainWP_Child_Vulnerability_Checker {
}
if ($th_vuln) {
$th_vuln = json_decode($th_vuln, true);
$th_vuln = json_decode($th_vuln, true);
$th_vuln_filter = $th_vuln;
foreach ($th_vuln as $slug => $th_data) {
if (isset($th_data['vulnerabilities']) && count($th_data['vulnerabilities']) > 0) {
$th_vulner_data = array();
foreach($th_data['vulnerabilities'] as $vuln_data) {
if (empty($vuln_data))
foreach ($th_data['vulnerabilities'] as $vuln_data) {
if (empty($vuln_data)) {
continue;
}
if ( isset($vuln_data['fixed_in']) && version_compare( $th['version'], $vuln_data['fixed_in'] ) >= 0 ) {
continue;
@ -166,13 +170,13 @@ class MainWP_Child_Vulnerability_Checker {
$th_vulner_data[] = $vuln_data;
}
if(count($th_vulner_data) == 0) {
unset($th_vuln_filter[$slug]);
if (count($th_vulner_data) == 0) {
unset($th_vuln_filter[ $slug ]);
} else {
$th_vuln_filter[$slug]['vulnerabilities'] = $th_vulner_data;
$th_vuln_filter[ $slug ]['vulnerabilities'] = $th_vulner_data;
}
} else {
unset($th_vuln_filter[$slug]);
unset($th_vuln_filter[ $slug ]);
}
}
@ -185,10 +189,10 @@ class MainWP_Child_Vulnerability_Checker {
continue;
}
$result[$th['id']]['vulner_data'] = $th_vuln;
$result[$th['id']]['name'] = $th['name'];
$result[$th['id']]['author'] = $th['author'];
$result[$th['id']]['detected_version'] = $th['version'];
$result[ $th['id'] ]['vulner_data'] = $th_vuln;
$result[ $th['id'] ]['name'] = $th['name'];
$result[ $th['id'] ]['author'] = $th['author'];
$result[ $th['id'] ]['detected_version'] = $th['version'];
}
}
}
@ -197,45 +201,45 @@ class MainWP_Child_Vulnerability_Checker {
function vulnche_get_content ( $url ) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Token token=' . $this->wpvulndb_token));
curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Authorization: Token token=' . $this->wpvulndb_token ));
curl_setopt($ch, CURLOPT_USERAGENT, $this->get_random_user_agent());
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec($ch);
$info = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$info = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($output === false || $info != 200) {
$output = null;
}
}
return $output;
}
function get_random_user_agent ( ) {
function get_random_user_agent () {
$someUA = array (
"Mozilla/5.0 (Windows; U; Windows NT 6.0; fr; rv:1.9.1b1) Gecko/20081007 Firefox/3.1b1",
"Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.1) Gecko/2008070208 Firefox/3.0.0",
"Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/525.19 (KHTML, like Gecko) Chrome/0.4.154.18 Safari/525.19",
"Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/525.13 (KHTML, like Gecko) Chrome/0.2.149.27 Safari/525.13",
"Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30)",
"Mozilla/4.0 (compatible; MSIE 7.0b; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.40607)",
"Mozilla/4.0 (compatible; MSIE 7.0b; Windows NT 5.1; .NET CLR 1.1.4322)",
"Mozilla/4.0 (compatible; MSIE 7.0b; Windows NT 5.1; .NET CLR 1.0.3705; Media Center PC 3.1; Alexa Toolbar; .NET CLR 1.1.4322; .NET CLR 2.0.50727)",
"Mozilla/45.0 (compatible; MSIE 6.0; Windows NT 5.1)",
"Mozilla/4.08 (compatible; MSIE 6.0; Windows NT 5.1)",
"Mozilla/4.01 (compatible; MSIE 6.0; Windows NT 5.1)"
$someUA = array(
'Mozilla/5.0 (Windows; U; Windows NT 6.0; fr; rv:1.9.1b1) Gecko/20081007 Firefox/3.1b1',
'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.1) Gecko/2008070208 Firefox/3.0.0',
'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/525.19 (KHTML, like Gecko) Chrome/0.4.154.18 Safari/525.19',
'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/525.13 (KHTML, like Gecko) Chrome/0.2.149.27 Safari/525.13',
'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30)',
'Mozilla/4.0 (compatible; MSIE 7.0b; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.40607)',
'Mozilla/4.0 (compatible; MSIE 7.0b; Windows NT 5.1; .NET CLR 1.1.4322)',
'Mozilla/4.0 (compatible; MSIE 7.0b; Windows NT 5.1; .NET CLR 1.0.3705; Media Center PC 3.1; Alexa Toolbar; .NET CLR 1.1.4322; .NET CLR 2.0.50727)',
'Mozilla/45.0 (compatible; MSIE 6.0; Windows NT 5.1)',
'Mozilla/4.08 (compatible; MSIE 6.0; Windows NT 5.1)',
'Mozilla/4.01 (compatible; MSIE 6.0; Windows NT 5.1)',
);
srand((double)microtime()*1000000);
srand( (float) microtime() * 1000000);
return $someUA[rand(0,count($someUA)-1)];
return $someUA[ rand(0, count($someUA) - 1) ];
}

View file

@ -18,25 +18,23 @@ class MainWP_Child_WooCommerce_Status {
public static $instance = null;
static function Instance() {
if ( null === MainWP_Child_WooCommerce_Status::$instance ) {
MainWP_Child_WooCommerce_Status::$instance = new MainWP_Child_WooCommerce_Status();
if ( null === self::$instance ) {
self::$instance = new MainWP_Child_WooCommerce_Status();
}
return MainWP_Child_WooCommerce_Status::$instance;
return self::$instance;
}
public function __construct() {
add_action( 'mainwp_child_deactivation', array( $this, 'child_deactivation' ) );
}
public function child_deactivation() {
}
public function action() {
$information = array();
if ( ! class_exists( 'WooCommerce' ) || !defined('WC_VERSION')) {
if ( ! class_exists( 'WooCommerce' ) || ! defined('WC_VERSION')) {
$information['error'] = 'NO_WOOCOMMERCE';
MainWP_Helper::write( $information );
}
@ -66,7 +64,7 @@ class MainWP_Child_WooCommerce_Status {
global $wpdb;
$file = WP_PLUGIN_DIR . '/woocommerce/includes/admin/reports/class-wc-admin-report.php';
if ( file_exists( $file ) ) {
include_once( $file );
include_once $file;
} else {
return false;
}
@ -83,17 +81,15 @@ class MainWP_Child_WooCommerce_Status {
AND posts.post_status = 'publish'
AND tax.taxonomy = 'shop_order_status'
AND term.slug IN ( '" . implode( "','", apply_filters( 'woocommerce_reports_order_statuses', array(
'completed',
'processing',
'on-hold',
) ) ) . "' )
'completed',
'processing',
'on-hold',
) ) ) . "' )
AND postmeta.meta_key = '_order_total'
AND posts.post_date >= %s
AND posts.post_date <= %s
", date( 'Y-m-01', $start_date ), date( 'Y-m-d H:i:s', $end_date ) ) );
// Get top seller
$top_seller = $wpdb->get_row( $wpdb->prepare( "SELECT SUM( order_item_meta.meta_value ) as qty, order_item_meta_2.meta_value as product_id
FROM {$wpdb->posts} as posts
@ -107,10 +103,10 @@ class MainWP_Child_WooCommerce_Status {
AND posts.post_status = 'publish'
AND tax.taxonomy = 'shop_order_status'
AND term.slug IN ( '" . implode( "','", apply_filters( 'woocommerce_reports_order_statuses', array(
'completed',
'processing',
'on-hold',
) ) ) . "' )
'completed',
'processing',
'on-hold',
) ) ) . "' )
AND order_item_meta.meta_key = '_qty'
AND order_item_meta_2.meta_key = '_product_id'
AND posts.post_date >= %s
@ -118,7 +114,7 @@ class MainWP_Child_WooCommerce_Status {
GROUP BY product_id
ORDER BY qty DESC
LIMIT 1
", date( 'Y-m-01', $start_date ), date( 'Y-m-d H:i:s', $end_date )) );
", date( 'Y-m-01', $start_date ), date( 'Y-m-d H:i:s', $end_date )) );
if ( ! empty( $top_seller ) ) {
$top_seller->name = get_the_title( $top_seller->product_id );
@ -184,7 +180,7 @@ class MainWP_Child_WooCommerce_Status {
global $wpdb;
$file = WP_PLUGIN_DIR . '/woocommerce/includes/admin/reports/class-wc-admin-report.php';
if ( file_exists( $file ) ) {
include_once( $file );
include_once $file;
} else {
return false;
}
@ -194,7 +190,7 @@ class MainWP_Child_WooCommerce_Status {
$end_date = $_POST['end_date'];
$start_date = date( 'Y-m-d H:i:s', $start_date );
$end_date = date( 'Y-m-d H:i:s', $end_date );
$end_date = date( 'Y-m-d H:i:s', $end_date );
// Get sales
$sales = $wpdb->get_var( "SELECT SUM( postmeta.meta_value ) FROM {$wpdb->posts} as posts
@ -206,18 +202,15 @@ class MainWP_Child_WooCommerce_Status {
AND posts.post_status = 'publish'
AND tax.taxonomy = 'shop_order_status'
AND term.slug IN ( '" . implode( "','", apply_filters( 'woocommerce_reports_order_statuses', array(
'completed',
'processing',
'on-hold',
) ) ) . "' )
'completed',
'processing',
'on-hold',
) ) ) . "' )
AND postmeta.meta_key = '_order_total'
AND posts.post_date >= STR_TO_DATE(" . $wpdb->prepare('%s', $start_date) . ", '%Y-%m-%d %H:%i:%s')
AND posts.post_date <= STR_TO_DATE(" . $wpdb->prepare('%s', $end_date) . ", '%Y-%m-%d %H:%i:%s')
" );
// Get top seller
$top_seller = $wpdb->get_row( "SELECT SUM( order_item_meta.meta_value ) as qty, order_item_meta_2.meta_value as product_id
FROM {$wpdb->posts} as posts
@ -231,10 +224,10 @@ class MainWP_Child_WooCommerce_Status {
AND posts.post_status = 'publish'
AND tax.taxonomy = 'shop_order_status'
AND term.slug IN ( '" . implode( "','", apply_filters( 'woocommerce_reports_order_statuses', array(
'completed',
'processing',
'on-hold',
) ) ) . "' )
'completed',
'processing',
'on-hold',
) ) ) . "' )
AND order_item_meta.meta_key = '_qty'
AND order_item_meta_2.meta_key = '_product_id'
AND posts.post_date >= STR_TO_DATE(" . $wpdb->prepare('%s', $start_date) . ", '%Y-%m-%d %H:%i:%s')
@ -307,10 +300,10 @@ class MainWP_Child_WooCommerce_Status {
function sync_data_two() {
// sync data for current month
$start_date = date( 'Y-m-01 00:00:00', time() );
$end_date = date( 'Y-m-d H:i:s', time() );
$end_date = date( 'Y-m-d H:i:s', time() );
$start_date = strtotime( $start_date );
$end_date = strtotime( $end_date );
$end_date = strtotime( $end_date );
return $this->get_woocom_data( $start_date, $end_date );
}
@ -333,13 +326,13 @@ class MainWP_Child_WooCommerce_Status {
global $wpdb;
$file = WP_PLUGIN_DIR . '/woocommerce/includes/admin/reports/class-wc-admin-report.php';
if ( file_exists( $file ) ) {
include_once( $file );
include_once $file;
} else {
return false;
}
$start_date = date( 'Y-m-d H:i:s', $start_date );
$end_date = date( 'Y-m-d H:i:s', $end_date );
$end_date = date( 'Y-m-d H:i:s', $end_date );
$reports = new WC_Admin_Report();
// Sales
@ -348,39 +341,38 @@ class MainWP_Child_WooCommerce_Status {
$query['join'] = "INNER JOIN {$wpdb->postmeta} AS postmeta ON posts.ID = postmeta.post_id ";
$query['where'] = "WHERE posts.post_type IN ( '" . implode( "','", wc_get_order_types( 'reports' ) ) . "' ) ";
$query['where'] .= "AND posts.post_status IN ( 'wc-" . implode( "','wc-", apply_filters( 'woocommerce_reports_order_statuses', array(
'completed',
'processing',
'on-hold',
) ) ) . "' ) ";
'completed',
'processing',
'on-hold',
) ) ) . "' ) ";
$query['where'] .= "AND postmeta.meta_key = '_order_total' ";
$query['where'] .= "AND posts.post_date >= STR_TO_DATE(" . $wpdb->prepare('%s', $start_date) . ", '%Y-%m-%d %H:%i:%s') ";
$query['where'] .= "AND posts.post_date <= STR_TO_DATE(" . $wpdb->prepare('%s', $end_date) . ", '%Y-%m-%d %H:%i:%s') ";
$query['where'] .= 'AND posts.post_date >= STR_TO_DATE(' . $wpdb->prepare('%s', $start_date) . ", '%Y-%m-%d %H:%i:%s') ";
$query['where'] .= 'AND posts.post_date <= STR_TO_DATE(' . $wpdb->prepare('%s', $end_date) . ", '%Y-%m-%d %H:%i:%s') ";
$sales = $wpdb->get_var( implode( ' ', apply_filters( 'woocommerce_dashboard_status_widget_sales_query', $query ) ) );
// Get top seller
$query = array();
$query['fields'] = "SELECT SUM( order_item_meta.meta_value ) as qty, order_item_meta_2.meta_value as product_id
$query = array();
$query['fields'] = "SELECT SUM( order_item_meta.meta_value ) as qty, order_item_meta_2.meta_value as product_id
FROM {$wpdb->posts} as posts";
$query['join'] = "INNER JOIN {$wpdb->prefix}woocommerce_order_items AS order_items ON posts.ID = order_id ";
$query['join'] .= "INNER JOIN {$wpdb->prefix}woocommerce_order_itemmeta AS order_item_meta ON order_items.order_item_id = order_item_meta.order_item_id ";
$query['join'] .= "INNER JOIN {$wpdb->prefix}woocommerce_order_itemmeta AS order_item_meta_2 ON order_items.order_item_id = order_item_meta_2.order_item_id ";
$query['where'] = "WHERE posts.post_type IN ( '" . implode( "','", wc_get_order_types( 'order-count' ) ) . "' ) ";
$query['where'] .= "AND posts.post_status IN ( 'wc-" . implode( "','wc-", apply_filters( 'woocommerce_reports_order_statuses', array(
'completed',
'processing',
'on-hold',
) ) ) . "' ) ";
$query['where'] .= "AND order_item_meta.meta_key = '_qty' ";
$query['where'] .= "AND order_item_meta_2.meta_key = '_product_id' ";
$query['where'] .= "AND posts.post_date >= STR_TO_DATE(" . $wpdb->prepare('%s', $start_date) . ", '%Y-%m-%d %H:%i:%s') ";
$query['where'] .= "AND posts.post_date <= STR_TO_DATE(" . $wpdb->prepare('%s', $end_date) . ", '%Y-%m-%d %H:%i:%s') ";
$query['join'] = "INNER JOIN {$wpdb->prefix}woocommerce_order_items AS order_items ON posts.ID = order_id ";
$query['join'] .= "INNER JOIN {$wpdb->prefix}woocommerce_order_itemmeta AS order_item_meta ON order_items.order_item_id = order_item_meta.order_item_id ";
$query['join'] .= "INNER JOIN {$wpdb->prefix}woocommerce_order_itemmeta AS order_item_meta_2 ON order_items.order_item_id = order_item_meta_2.order_item_id ";
$query['where'] = "WHERE posts.post_type IN ( '" . implode( "','", wc_get_order_types( 'order-count' ) ) . "' ) ";
$query['where'] .= "AND posts.post_status IN ( 'wc-" . implode( "','wc-", apply_filters( 'woocommerce_reports_order_statuses', array(
'completed',
'processing',
'on-hold',
) ) ) . "' ) ";
$query['where'] .= "AND order_item_meta.meta_key = '_qty' ";
$query['where'] .= "AND order_item_meta_2.meta_key = '_product_id' ";
$query['where'] .= 'AND posts.post_date >= STR_TO_DATE(' . $wpdb->prepare('%s', $start_date) . ", '%Y-%m-%d %H:%i:%s') ";
$query['where'] .= 'AND posts.post_date <= STR_TO_DATE(' . $wpdb->prepare('%s', $end_date) . ", '%Y-%m-%d %H:%i:%s') ";
$query['groupby'] = 'GROUP BY product_id';
$query['orderby'] = 'ORDER BY qty DESC';
$query['limits'] = 'LIMIT 1';
$top_seller = $wpdb->get_row( implode( ' ', $query ) );
$top_seller = $wpdb->get_row( implode( ' ', $query ) );
if ( ! empty( $top_seller ) ) {
$top_seller->name = get_the_title( $top_seller->product_id );
@ -391,8 +383,8 @@ class MainWP_Child_WooCommerce_Status {
$processing_count = 0;
foreach ( wc_get_order_types( 'order-count' ) as $type ) {
$counts = (array) wp_count_posts( $type );
$on_hold_count += isset( $counts['wc-on-hold'] ) ? $counts['wc-on-hold'] : 0;
$counts = (array) wp_count_posts( $type );
$on_hold_count += isset( $counts['wc-on-hold'] ) ? $counts['wc-on-hold'] : 0;
$processing_count += isset( $counts['wc-processing'] ) ? $counts['wc-processing'] : 0;
}
@ -432,7 +424,7 @@ class MainWP_Child_WooCommerce_Status {
$outofstock_count = absint( $wpdb->get_var( "SELECT COUNT( DISTINCT posts.ID ) {$query_from};" ) );
$data = array(
$data = array(
'sales' => $sales,
'formated_sales' => wc_price( $sales ),
'top_seller' => $top_seller,
@ -441,15 +433,15 @@ class MainWP_Child_WooCommerce_Status {
'stock' => $stock,
'nostock' => $nostock,
'lowstock' => $lowinstock_count,
'outstock' => $outofstock_count
'outstock' => $outofstock_count,
);
$information['data'] = $data;
$information['data'] = $data;
$information['need_db_update'] = $this->check_db_update();
return $information;
}
private static function update_wc_db() {
include_once( WC()->plugin_path() . '/includes/class-wc-background-updater.php' );
include_once WC()->plugin_path() . '/includes/class-wc-background-updater.php';
$background_updater = new WC_Background_Updater();
$current_db_version = get_option( 'woocommerce_db_version' );
@ -473,7 +465,7 @@ class MainWP_Child_WooCommerce_Status {
$background_updater->save()->dispatch();
}
return array('result' => 'success');
return array( 'result' => 'success' );
}
}

File diff suppressed because it is too large Load diff

View file

@ -16,15 +16,15 @@
*/
class MainWP_Child_WP_Rocket {
public static $instance = null;
public static $instance = null;
public $is_plugin_installed = false;
public static function Instance() {
if ( null === MainWP_Child_WP_Rocket::$instance ) {
MainWP_Child_WP_Rocket::$instance = new MainWP_Child_WP_Rocket();
if ( null === self::$instance ) {
self::$instance = new MainWP_Child_WP_Rocket();
}
return MainWP_Child_WP_Rocket::$instance;
return self::$instance;
}
public function __construct() {
@ -34,9 +34,9 @@ class MainWP_Child_WP_Rocket {
}
public function init() {
// if ( get_option( 'mainwp_wprocket_ext_enabled' ) !== 'Y' ) {
// return;
// }
// if ( get_option( 'mainwp_wprocket_ext_enabled' ) !== 'Y' ) {
// return;
// }
if ( ! $this->is_plugin_installed ) {
return;
@ -56,91 +56,91 @@ class MainWP_Child_WP_Rocket {
function get_rocket_default_options() {
return array(
'cache_mobile' => 1,
'do_caching_mobile_files' => 0,
'cache_logged_user' => 0,
'cache_ssl' => 0,
'emoji' => 0,
'embeds' => 1,
'control_heartbeat' => 0,
'heartbeat_site_behavior' => 'reduce_periodicity',
'heartbeat_admin_behavior' => 'reduce_periodicity',
'heartbeat_editor_behavior' => 'reduce_periodicity',
'varnish_auto_purge' => 0,
'manual_preload' => 0,
'automatic_preload' => 0,
'sitemap_preload' => 0,
'sitemap_preload_url_crawl' => 500000,
'sitemaps' => array(),
'database_revisions' => 0,
'database_auto_drafts' => 0,
'database_trashed_posts' => 0,
'database_spam_comments' => 0,
'database_trashed_comments' => 0,
'database_expired_transients' => 0,
'database_all_transients' => 0,
'database_optimize_tables' => 0,
'schedule_automatic_cleanup' => 0,
'automatic_cleanup_frequency' => '',
'cache_reject_uri' => array(),
'cache_reject_cookies' => array(),
'cache_reject_ua' => array(),
'cache_query_strings' => array(),
'cache_purge_pages' => array(),
'purge_cron_interval' => 10,
'purge_cron_unit' => 'HOUR_IN_SECONDS',
'exclude_css' => array(),
'exclude_js' => array(),
'exclude_inline_js' => array(),
'async_css' => 0,
'defer_all_js' => 0,
'defer_all_js_safe' => 1,
'critical_css' => '',
'deferred_js_files' => array(),
'lazyload' => 0,
'lazyload_iframes' => 0,
'lazyload_youtube' =>0,
'minify_css' => 0,
// 'minify_css_key' => $minify_css_key,
'minify_concatenate_css' => 0,
//'minify_css_combine_all' => 0,
'minify_css_legacy' => 0,
'minify_js' => 0,
// 'minify_js_key' => $minify_js_key,
'minify_js_in_footer' => array(),
'minify_concatenate_js' => 0,
'minify_js_combine_all' => 0,
//'minify_js_legacy' => 0,
'minify_google_fonts' => 0,
'minify_html' => 0,
'remove_query_strings' => 0,
'dns_prefetch' => 0,
'cdn' => 0,
'cdn_cnames' => array(),
'cdn_zone' => array(),
//'cdn_ssl' => 0,
'cdn_reject_files' => array(),
'do_cloudflare' => 0,
'cloudflare_email' => '',
'cloudflare_api_key' => '',
'cloudflare_domain' => '',
//'cloudflare_zone_id' => '',
'cloudflare_devmode' => 0,
'cloudflare_protocol_rewrite' => 0,
'cloudflare_auto_settings' => 0,
'cloudflare_old_settings' => 0,
'do_beta' => 0,
'analytics_enabled' => 1,
);
'cache_mobile' => 1,
'do_caching_mobile_files' => 0,
'cache_logged_user' => 0,
'cache_ssl' => 0,
'emoji' => 0,
'embeds' => 1,
'control_heartbeat' => 0,
'heartbeat_site_behavior' => 'reduce_periodicity',
'heartbeat_admin_behavior' => 'reduce_periodicity',
'heartbeat_editor_behavior' => 'reduce_periodicity',
'varnish_auto_purge' => 0,
'manual_preload' => 0,
'automatic_preload' => 0,
'sitemap_preload' => 0,
'sitemap_preload_url_crawl' => 500000,
'sitemaps' => array(),
'database_revisions' => 0,
'database_auto_drafts' => 0,
'database_trashed_posts' => 0,
'database_spam_comments' => 0,
'database_trashed_comments' => 0,
'database_expired_transients' => 0,
'database_all_transients' => 0,
'database_optimize_tables' => 0,
'schedule_automatic_cleanup' => 0,
'automatic_cleanup_frequency' => '',
'cache_reject_uri' => array(),
'cache_reject_cookies' => array(),
'cache_reject_ua' => array(),
'cache_query_strings' => array(),
'cache_purge_pages' => array(),
'purge_cron_interval' => 10,
'purge_cron_unit' => 'HOUR_IN_SECONDS',
'exclude_css' => array(),
'exclude_js' => array(),
'exclude_inline_js' => array(),
'async_css' => 0,
'defer_all_js' => 0,
'defer_all_js_safe' => 1,
'critical_css' => '',
'deferred_js_files' => array(),
'lazyload' => 0,
'lazyload_iframes' => 0,
'lazyload_youtube' => 0,
'minify_css' => 0,
// 'minify_css_key' => $minify_css_key,
'minify_concatenate_css' => 0,
// 'minify_css_combine_all' => 0,
'minify_css_legacy' => 0,
'minify_js' => 0,
// 'minify_js_key' => $minify_js_key,
'minify_js_in_footer' => array(),
'minify_concatenate_js' => 0,
'minify_js_combine_all' => 0,
// 'minify_js_legacy' => 0,
'minify_google_fonts' => 0,
'minify_html' => 0,
'remove_query_strings' => 0,
'dns_prefetch' => 0,
'cdn' => 0,
'cdn_cnames' => array(),
'cdn_zone' => array(),
// 'cdn_ssl' => 0,
'cdn_reject_files' => array(),
'do_cloudflare' => 0,
'cloudflare_email' => '',
'cloudflare_api_key' => '',
'cloudflare_domain' => '',
// 'cloudflare_zone_id' => '',
'cloudflare_devmode' => 0,
'cloudflare_protocol_rewrite' => 0,
'cloudflare_auto_settings' => 0,
'cloudflare_old_settings' => 0,
'do_beta' => 0,
'analytics_enabled' => 1,
);
}
// ok
public function syncOthersData( $information, $data = array() ) {
if ( isset( $data['syncWPRocketData'] ) && ( 'yes' === $data['syncWPRocketData'] ) ) {
try{
$data = array( 'rocket_boxes' => get_user_meta( $GLOBALS['current_user']->ID, 'rocket_boxes', true ));
try {
$data = array( 'rocket_boxes' => get_user_meta( $GLOBALS['current_user']->ID, 'rocket_boxes', true ) );
$information['syncWPRocketData'] = $data;
} catch(Exception $e) {
} catch (Exception $e) {
}
}
return $information;
@ -192,7 +192,7 @@ class MainWP_Child_WP_Rocket {
return $value;
}
if (! MainWP_Helper::is_screen_with_update()) {
if ( ! MainWP_Helper::is_screen_with_update()) {
return $value;
}
@ -207,9 +207,9 @@ class MainWP_Child_WP_Rocket {
if ( ! $this->is_plugin_installed ) {
return false;
}
// if ( ! defined( 'WP_ROCKET_VERSION' ) || ! defined( 'WP_ROCKET_SLUG' ) ) {
// return false;
// }
// if ( ! defined( 'WP_ROCKET_VERSION' ) || ! defined( 'WP_ROCKET_SLUG' ) ) {
// return false;
// }
return true;
}
@ -251,9 +251,8 @@ class MainWP_Child_WP_Rocket {
$information = array();
if ( isset( $_POST['mwp_action'] ) ) {
// MainWP_Helper::update_option( 'mainwp_wprocket_ext_enabled', 'Y' );
// MainWP_Helper::update_option( 'mainwp_wprocket_ext_enabled', 'Y' );
try {
switch ( $_POST['mwp_action'] ) {
case 'set_showhide':
@ -274,7 +273,7 @@ class MainWP_Child_WP_Rocket {
case 'save_settings':
$information = $this->save_settings();
break;
case "load_existing_settings":
case 'load_existing_settings':
$information = $this->load_existing_settings();
break;
case 'optimize_database':
@ -287,7 +286,7 @@ class MainWP_Child_WP_Rocket {
$information = $this->do_admin_post_rocket_purge_opcache();
break;
}
} catch(Exception $e) {
} catch (Exception $e) {
$information = array( 'error' => $e->getMessage() );
}
}
@ -306,9 +305,9 @@ class MainWP_Child_WP_Rocket {
if ( function_exists( 'opcache_reset' ) ) {
@opcache_reset();
} else {
return array('error' => 'The host do not support the function reset opcache.');
return array( 'error' => 'The host do not support the function reset opcache.' );
}
return array('result' => 'SUCCESS');
return array( 'result' => 'SUCCESS' );
}
function purge_cloudflare() {
@ -336,13 +335,13 @@ class MainWP_Child_WP_Rocket {
rocket_clean_cache_busting();
}
if ( !function_exists( 'rocket_dismiss_boxes' ) && defined('WP_ROCKET_ADMIN_PATH')) {
if ( ! function_exists( 'rocket_dismiss_boxes' ) && defined('WP_ROCKET_ADMIN_PATH')) {
require_once WP_ROCKET_ADMIN_PATH . 'admin.php';
}
// to fix
include_once( ABSPATH . '/wp-admin/includes/template.php' );
include_once ABSPATH . '/wp-admin/includes/template.php';
// Generate a new random key for minify cache file
$options = get_option( WP_ROCKET_SLUG );
$options['minify_css_key'] = create_rocket_uniqid();
@ -362,7 +361,7 @@ class MainWP_Child_WP_Rocket {
MainWP_Helper::check_classes_exists('WP_Rocket\Preload\Full_Process');
$preload_process = new WP_Rocket\Preload\Full_Process();
MainWP_Helper::check_methods($preload_process, array( 'is_process_running'));
MainWP_Helper::check_methods($preload_process, array( 'is_process_running' ));
if ( $preload_process->is_process_running() ) {
return array( 'result' => 'RUNNING' );
@ -375,16 +374,17 @@ class MainWP_Child_WP_Rocket {
}
function generate_critical_css() {
MainWP_Helper::check_classes_exists( array( 'WP_Rocket\Subscriber\Optimization\Critical_CSS_Subscriber',
'WP_Rocket\Optimization\CSS\Critical_CSS',
'WP_Rocket\Optimization\CSS\Critical_CSS_Generation',
'WP_Rocket\Admin\Options',
'WP_Rocket\Admin\Options_Data'
));
MainWP_Helper::check_classes_exists( array(
'WP_Rocket\Subscriber\Optimization\Critical_CSS_Subscriber',
'WP_Rocket\Optimization\CSS\Critical_CSS',
'WP_Rocket\Optimization\CSS\Critical_CSS_Generation',
'WP_Rocket\Admin\Options',
'WP_Rocket\Admin\Options_Data',
));
$critical_css = new WP_Rocket\Optimization\CSS\Critical_CSS( new WP_Rocket\Optimization\CSS\Critical_CSS_Generation() );
$options_api = new WP_Rocket\Admin\Options( 'wp_rocket_' );
$options = new WP_Rocket\Admin\Options_Data( $options_api->get( 'settings', array() ) );
$options_api = new WP_Rocket\Admin\Options( 'wp_rocket_' );
$options = new WP_Rocket\Admin\Options_Data( $options_api->get( 'settings', array() ) );
$sitemap_preload = new WP_Rocket\Subscriber\Optimization\Critical_CSS_Subscriber( $critical_css, $options );
@ -411,10 +411,9 @@ class MainWP_Child_WP_Rocket {
}
}
update_option( WP_ROCKET_SLUG, $options );
if (isset($_POST['do_database_optimization']) && !empty($_POST['do_database_optimization'])) {
if (isset($_POST['do_database_optimization']) && ! empty($_POST['do_database_optimization'])) {
$this->optimize_database();
}
@ -423,22 +422,23 @@ class MainWP_Child_WP_Rocket {
function optimize_database() {
MainWP_Helper::check_classes_exists( array( 'WP_Rocket\Admin\Database\Optimization',
'WP_Rocket\Admin\Database\Optimization_Process',
'WP_Rocket\Admin\Options',
'WP_Rocket\Admin\Options_Data'
));
MainWP_Helper::check_classes_exists( array(
'WP_Rocket\Admin\Database\Optimization',
'WP_Rocket\Admin\Database\Optimization_Process',
'WP_Rocket\Admin\Options',
'WP_Rocket\Admin\Options_Data',
));
$process = new WP_Rocket\Admin\Database\Optimization_Process();
$process = new WP_Rocket\Admin\Database\Optimization_Process();
$optimization = new WP_Rocket\Admin\Database\Optimization( $process );
MainWP_Helper::check_methods( $optimization, array( 'process_handler', 'get_options' ) );
$options_api = new WP_Rocket\Admin\Options( 'wp_rocket_' );
$options = new WP_Rocket\Admin\Options_Data( $options_api->get( 'settings', array() ) );
$items = array_filter( array_keys( $optimization->get_options() ), [ $options, 'get' ] );
$items = array_filter( array_keys( $optimization->get_options() ), array( $options, 'get' ) );
if ( !empty( $items ) ) {
if ( ! empty( $items ) ) {
$optimization->process_handler( $items );
}
@ -448,23 +448,24 @@ class MainWP_Child_WP_Rocket {
function get_optimize_info() {
MainWP_Helper::check_classes_exists( array( 'WP_Rocket\Admin\Database\Optimization',
'WP_Rocket\Admin\Database\Optimization_Process'
));
MainWP_Helper::check_classes_exists( array(
'WP_Rocket\Admin\Database\Optimization',
'WP_Rocket\Admin\Database\Optimization_Process',
));
$process = new WP_Rocket\Admin\Database\Optimization_Process();
$process = new WP_Rocket\Admin\Database\Optimization_Process();
$optimization = new WP_Rocket\Admin\Database\Optimization( $process );
MainWP_Helper::check_methods($optimization, 'count_cleanup_items');
$information['optimize_info'] = array(
'total_revisions' => $optimization->count_cleanup_items( 'database_revisions' ),
'total_revisions' => $optimization->count_cleanup_items( 'database_revisions' ),
'total_auto_draft' => $optimization->count_cleanup_items( 'database_auto_drafts' ),
'total_trashed_posts' => $optimization->count_cleanup_items( 'database_trashed_posts' ),
'total_spam_comments' => $optimization->count_cleanup_items( 'database_spam_comments' ),
'total_spam_comments' => $optimization->count_cleanup_items( 'database_spam_comments' ),
'total_trashed_comments' => $optimization->count_cleanup_items( 'database_trashed_comments' ),
'total_expired_transients' => $optimization->count_cleanup_items( 'database_expired_transients' ),
'total_all_transients' => $optimization->count_cleanup_items( 'database_all_transients' ),
'total_optimize_tables' => $optimization->count_cleanup_items( 'database_optimize_tables' )
'total_optimize_tables' => $optimization->count_cleanup_items( 'database_optimize_tables' ),
);
$information['result'] = 'SUCCESS';
@ -473,7 +474,10 @@ class MainWP_Child_WP_Rocket {
function load_existing_settings() {
$options = get_option( WP_ROCKET_SLUG );
return array('result' => 'SUCCESS', 'options' => $options);
return array(
'result' => 'SUCCESS',
'options' => $options,
);
}
}

View file

@ -1,72 +1,62 @@
<?php
class MainWP_Child_WPvivid_BackupRestore
{
public static $instance = null;
class MainWP_Child_WPvivid_BackupRestore {
public static $instance = null;
public $is_plugin_installed = false;
public $public_intetface;
static function Instance()
{
if ( null === MainWP_Child_WPvivid_BackupRestore::$instance )
{
MainWP_Child_WPvivid_BackupRestore::$instance = new MainWP_Child_WPvivid_BackupRestore();
static function Instance() {
if ( null === self::$instance ) {
self::$instance = new MainWP_Child_WPvivid_BackupRestore();
}
return MainWP_Child_WPvivid_BackupRestore::$instance;
return self::$instance;
}
public function __construct()
{
require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
if ( is_plugin_active( 'wpvivid-backuprestore/wpvivid-backuprestore.php' ) && defined('WPVIVID_PLUGIN_DIR'))
{
public function __construct() {
require_once ABSPATH . 'wp-admin/includes/plugin.php';
if ( is_plugin_active( 'wpvivid-backuprestore/wpvivid-backuprestore.php' ) && defined('WPVIVID_PLUGIN_DIR')) {
$this->is_plugin_installed = true;
}
if (!$this->is_plugin_installed)
if ( ! $this->is_plugin_installed) {
return;
}
add_filter( 'mainwp-site-sync-others-data', array( $this, 'syncOthersData' ), 10, 2 );
$this->public_intetface = new WPvivid_Public_Interface();
}
public function init()
{
public function init() {
}
function syncOthersData( $information, $data = array() )
{
try{
function syncOthersData( $information, $data = array() ) {
try {
if ( isset( $data['syncWPvividData'] ))
{
$information['syncWPvividData']=1;
$data = WPvivid_Setting::get_sync_data();
$information['syncWPvividSettingData']=$data['setting'];
$information['syncWPvividRemoteData']=$data['remote'];
$information['syncWPvividScheduleData']=$data['schedule'];
$information['syncWPvividSetting'] = $data;
if ( isset( $data['syncWPvividData'] )) {
$information['syncWPvividData'] = 1;
$data = WPvivid_Setting::get_sync_data();
$information['syncWPvividSettingData'] = $data['setting'];
$information['syncWPvividRemoteData'] = $data['remote'];
$information['syncWPvividScheduleData'] = $data['schedule'];
$information['syncWPvividSetting'] = $data;
}
} catch(Exception $e) {
} catch (Exception $e) {
}
return $information;
}
public function action()
{
public function action() {
$information = array();
if ( ! $this->is_plugin_installed )
{
if ( ! $this->is_plugin_installed ) {
$information['error'] = 'NO_WPVIVIDBACKUP';
MainWP_Helper::write( $information );
}
if ( isset( $_POST['mwp_action'] ) )
{
if ( isset( $_POST['mwp_action'] ) ) {
try {
switch ($_POST['mwp_action']) {
case 'prepare_backup':
@ -134,174 +124,154 @@ class MainWP_Child_WPvivid_BackupRestore
break;
}
} catch (Exception $e) {
$information = array('error' => $e->getMessage());
$information = array( 'error' => $e->getMessage() );
}
MainWP_Helper::write($information);
}
}
public function post_mainwp_data($data){
public function post_mainwp_data( $data) {
global $wpvivid_plugin;
$ret =$wpvivid_plugin->wpvivid_handle_mainwp_action($data);
$ret = $wpvivid_plugin->wpvivid_handle_mainwp_action($data);
return $ret;
}
public function prepare_backup()
{
public function prepare_backup() {
global $wpvivid_plugin;
$wpvivid_plugin->ajax_check_security();
$ret = $this->public_intetface->prepare_backup($_POST['backup']);
return $ret;
}
}
public function backup_now()
{
public function backup_now() {
global $wpvivid_plugin;
$wpvivid_plugin->ajax_check_security();
$ret = $this->public_intetface->backup_now($_POST['task_id']);
return $ret;
}
public function get_status()
{
public function get_status() {
global $wpvivid_plugin;
$wpvivid_plugin->ajax_check_security();
$ret = $this->public_intetface->get_status();
return $ret;
}
public function get_backup_schedule()
{
public function get_backup_schedule() {
global $wpvivid_plugin;
$wpvivid_plugin->ajax_check_security();
$ret = $this->public_intetface->get_backup_schedule();
return $ret;
}
}
public function get_backup_list()
{
public function get_backup_list() {
global $wpvivid_plugin;
$wpvivid_plugin->ajax_check_security();
$ret = $this->public_intetface->get_backup_list();
return $ret;
}
}
public function get_default_remote()
{
public function get_default_remote() {
global $wpvivid_plugin;
$wpvivid_plugin->ajax_check_security();
$ret = $this->public_intetface->get_default_remote();
return $ret;
}
}
public function delete_backup()
{
public function delete_backup() {
global $wpvivid_plugin;
$wpvivid_plugin->ajax_check_security();
$ret = $this->public_intetface->delete_backup($_POST['backup_id'], $_POST['force']);
return $ret;
}
}
public function delete_backup_array()
{
public function delete_backup_array() {
global $wpvivid_plugin;
$wpvivid_plugin->ajax_check_security();
$ret = $this->public_intetface->delete_backup_array($_POST['backup_id']);
return $ret;
}
}
public function set_security_lock()
{
public function set_security_lock() {
global $wpvivid_plugin;
$wpvivid_plugin->ajax_check_security();
$ret = $this->public_intetface->set_security_lock($_POST['backup_id'], $_POST['lock']);
return $ret;
}
}
public function view_log()
{
public function view_log() {
global $wpvivid_plugin;
$wpvivid_plugin->ajax_check_security();
$ret = $this->public_intetface->view_log($_POST['id']);
return $ret;
}
}
public function read_last_backup_log()
{
public function read_last_backup_log() {
global $wpvivid_plugin;
$wpvivid_plugin->ajax_check_security();
$ret = $this->public_intetface->read_last_backup_log($_POST['log_file_name']);
return $ret;
}
}
public function view_backup_task_log()
{
public function view_backup_task_log() {
global $wpvivid_plugin;
$wpvivid_plugin->ajax_check_security();
$ret = $this->public_intetface->view_backup_task_log($_POST['id']);
return $ret;
}
}
public function backup_cancel()
{
public function backup_cancel() {
global $wpvivid_plugin;
$wpvivid_plugin->ajax_check_security();
$ret = $this->public_intetface->backup_cancel($_POST['task_id']);
return $ret;
}
}
public function init_download_page()
{
public function init_download_page() {
global $wpvivid_plugin;
$wpvivid_plugin->ajax_check_security();
$ret = $this->public_intetface->init_download_page($_POST['backup_id']);
return $ret;
}
}
public function prepare_download_backup()
{
public function prepare_download_backup() {
global $wpvivid_plugin;
$wpvivid_plugin->ajax_check_security();
$ret = $this->public_intetface->prepare_download_backup($_POST['backup_id'], $_POST['file_name']);
return $ret;
}
}
public function get_download_task()
{
public function get_download_task() {
global $wpvivid_plugin;
$wpvivid_plugin->ajax_check_security();
$ret = $this->public_intetface->get_download_task($_POST['backup_id']);
return $ret;
}
}
public function download_backup()
{
public function download_backup() {
global $wpvivid_plugin;
$wpvivid_plugin->ajax_check_security();
$ret = $this->public_intetface->download_backup($_POST['backup_id'], $_POST['file_name']);
return $ret;
}
}
public function set_general_setting()
{
public function set_general_setting() {
global $wpvivid_plugin;
$wpvivid_plugin->ajax_check_security();
$ret = $this->public_intetface->set_general_setting($_POST['setting']);
return $ret;
}
}
public function set_schedule()
{
public function set_schedule() {
global $wpvivid_plugin;
$wpvivid_plugin->ajax_check_security();
$ret = $this->public_intetface->set_schedule($_POST['schedule']);
return $ret;
}
}
public function set_remote()
{
public function set_remote() {
global $wpvivid_plugin;
$wpvivid_plugin->ajax_check_security();
$ret = $this->public_intetface->set_remote($_POST['remote']);

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -12,16 +12,16 @@ class MainWP_Clone_Install {
* @param string $file The zip backup file path
*/
public function __construct( $file ) {
require_once( ABSPATH . 'wp-admin/includes/class-pclzip.php' );
require_once ABSPATH . 'wp-admin/includes/class-pclzip.php';
$this->file = $file;
if ( '.zip' === substr( $this->file, - 4 ) ) {
$this->archiver = null;
} else if ( '.tar.gz' === substr( $this->file, - 7 ) ) {
} elseif ( '.tar.gz' === substr( $this->file, - 7 ) ) {
$this->archiver = new Tar_Archiver( null, 'tar.gz' );
} else if ( '.tar.bz2' === substr( $this->file, - 8 ) ) {
} elseif ( '.tar.bz2' === substr( $this->file, - 8 ) ) {
$this->archiver = new Tar_Archiver( null, 'tar.bz2' );
} else if ( '.tar' === substr( $this->file, - 4 ) ) {
} elseif ( '.tar' === substr( $this->file, - 4 ) ) {
$this->archiver = new Tar_Archiver( null, 'tar' );
}
}
@ -41,8 +41,8 @@ class MainWP_Clone_Install {
* @return bool
*/
public function checkZipConsole() {
//todo: implement
// return function_exists('system');
// todo: implement
// return function_exists('system');
return false;
}
@ -58,9 +58,9 @@ class MainWP_Clone_Install {
if ( null !== $this->archiver ) {
} else if ( $this->checkZipConsole() ) {
//todo: implement
} else if ( $this->checkZipSupport() ) {
} elseif ( $this->checkZipConsole() ) {
// todo: implement
} elseif ( $this->checkZipSupport() ) {
$zip = new ZipArchive();
$zipRes = $zip->open( $this->file );
if ( $zipRes ) {
@ -73,7 +73,7 @@ class MainWP_Clone_Install {
return false;
} else {
//use pclzip
// use pclzip
$zip = new PclZip( $this->file );
$list = $zip->delete( PCLZIP_OPT_BY_NAME, 'wp-config.php' );
$list2 = $zip->delete( PCLZIP_OPT_BY_NAME, 'clone' );
@ -114,9 +114,9 @@ class MainWP_Clone_Install {
}
return $this->archiver->file_exists( $file );
} else if ( $this->checkZipConsole() ) {
//todo: implement
} else if ( $this->checkZipSupport() ) {
} elseif ( $this->checkZipConsole() ) {
// todo: implement
} elseif ( $this->checkZipSupport() ) {
$zip = new ZipArchive();
$zipRes = $zip->open( $this->file );
if ( $zipRes ) {
@ -236,7 +236,7 @@ class MainWP_Clone_Install {
$readline = '';
while ( ( $line = fgets( $handle, 81920 ) ) !== false ) {
if ( time() - $lastRun > 20 ) {
@set_time_limit( 0 ); //reset timer..
@set_time_limit( 0 ); // reset timer..
$lastRun = time();
}
@ -331,16 +331,16 @@ class MainWP_Clone_Install {
}
$token = $data[0];
switch ( $token ) {
case 's' :
case 's':
if ( '"' !== $data[ $length - 2 ] ) {
return false;
}
case 'a' :
case 'O' :
case 'a':
case 'O':
return (bool) preg_match( "/^{$token}:[0-9]+:/s", $data );
case 'b' :
case 'i' :
case 'd' :
case 'b':
case 'i':
case 'd':
return (bool) preg_match( "/^{$token}:[0-9.E-]+;\$/", $data );
}
@ -373,14 +373,14 @@ class MainWP_Clone_Install {
return $content;
} else {
if ( $this->checkZipConsole() ) {
//todo: implement
} else if ( $this->checkZipSupport() ) {
// todo: implement
} elseif ( $this->checkZipSupport() ) {
$zip = new ZipArchive();
$zipRes = $zip->open( $this->file );
if ( $zipRes ) {
$content = $zip->getFromName( 'clone/config.txt' );
// $zip->deleteName('clone/config.txt');
// $zip->deleteName('clone/');
// $zip->deleteName('clone/config.txt');
// $zip->deleteName('clone/');
$zip->close();
return $content;
@ -388,7 +388,7 @@ class MainWP_Clone_Install {
return false;
} else {
//use pclzip
// use pclzip
$zip = new PclZip( $this->file );
$content = $zip->extract( PCLZIP_OPT_BY_NAME, 'clone/config.txt',
PCLZIP_OPT_EXTRACT_AS_STRING );
@ -419,13 +419,13 @@ class MainWP_Clone_Install {
}
return $this->archiver->extractTo( ABSPATH );
} else if ( ( filesize( $this->file ) >= 50000000 ) && $this->checkWPZip() ) {
} elseif ( ( filesize( $this->file ) >= 50000000 ) && $this->checkWPZip() ) {
return $this->extractWPZipBackup();
} else if ( $this->checkZipConsole() ) {
} elseif ( $this->checkZipConsole() ) {
return $this->extractZipConsoleBackup();
} else if ( $this->checkZipSupport() ) {
} elseif ( $this->checkZipSupport() ) {
return $this->extractZipBackup();
} else if ( ( filesize( $this->file ) < 50000000 ) && $this->checkWPZip() ) {
} elseif ( ( filesize( $this->file ) < 50000000 ) && $this->checkWPZip() ) {
return $this->extractWPZipBackup();
} else {
return $this->extractZipPclBackup();
@ -484,8 +484,8 @@ class MainWP_Clone_Install {
* @return bool
*/
public function extractZipConsoleBackup() {
//todo implement
//system('zip');
// todo implement
// system('zip');
return false;
}
@ -536,10 +536,10 @@ class MainWP_Clone_Install {
* We split large tables into 50,000 row blocks when dealing with them to save
* on memmory consumption.
*
* @param mysql $connection The db connection object
* @param mysql $connection The db connection object
* @param string $search What we want to replace
* @param string $replace What we want to replace it with.
* @param array $tables The tables we want to look at.
* @param array $tables The tables we want to look at.
*
* @return array Collection of information gathered during the run.
*/
@ -647,14 +647,14 @@ class MainWP_Clone_Install {
*
* @return array The original array with all elements replaced as needed.
*/
/* Fixed serialize issue */
function recursive_unserialize_replace( $from = '', $to = '', $data = '', $serialised = false ) {
// some unseriliased data cannot be re-serialised eg. SimpleXMLElements
try {
if ( is_string( $data ) && is_serialized( $data ) && !is_serialized_string( $data ) && ( $unserialized = @unserialize( $data ) ) !== false ) {
if ( is_string( $data ) && is_serialized( $data ) && ! is_serialized_string( $data ) && ( $unserialized = @unserialize( $data ) ) !== false ) {
$data = $this->recursive_unserialize_replace( $from, $to, $unserialized, true );
} elseif ( is_array( $data ) ) {
$_tmp = array();
@ -665,7 +665,7 @@ class MainWP_Clone_Install {
$data = $_tmp;
unset( $_tmp );
} elseif ( is_object( $data ) ) {
$_tmp = $data;
$_tmp = $data;
$props = get_object_vars( $data );
foreach ( $props as $key => $value ) {
$_tmp->{$key} = $this->recursive_unserialize_replace( $from, $to, $value, false );
@ -673,9 +673,9 @@ class MainWP_Clone_Install {
$data = $_tmp;
unset( $_tmp );
} elseif (is_serialized_string($data) && is_serialized($data)) {
} elseif (is_serialized_string($data) && is_serialized($data)) {
// TODO: apply solution like phpmyadmin project have!
if ( ($data = @unserialize( $data )) !== false ) {
if ( ( $data = @unserialize( $data ) ) !== false ) {
$data = str_replace( $from, $to, $data );
$data = serialize( $data );
}

View file

@ -18,7 +18,7 @@ class MainWP_Clone {
}
if ( ! function_exists( 'wp_create_nonce' ) ) {
include_once( ABSPATH . WPINC . '/pluggable.php' );
include_once ABSPATH . WPINC . '/pluggable.php';
}
$this->security_nonces[ $action ] = wp_create_nonce( $action );
}
@ -50,7 +50,7 @@ class MainWP_Clone {
$ajaxPosts = array();
}
//If already processed, just quit!
// If already processed, just quit!
if ( isset( $ajaxPosts[ $action ] ) && ( $ajaxPosts[ $action ] == $_POST['dts'] ) ) {
die( json_encode( array( 'error' => __( 'Double request!', 'mainwp-child' ) ) ) );
}
@ -112,7 +112,7 @@ class MainWP_Clone {
if ( isset( $_REQUEST['upload'] ) && wp_verify_nonce( $_POST['_nonce'], 'cloneRestore' ) ) {
if ( isset( $_FILES['file'] ) ) {
if ( ! function_exists( 'wp_handle_upload' ) ) {
require_once( ABSPATH . 'wp-admin/includes/file.php' );
require_once ABSPATH . 'wp-admin/includes/file.php';
}
$uploadedfile = $_FILES['file'];
$upload_overrides = array( 'test_form' => false );
@ -153,13 +153,17 @@ class MainWP_Clone {
<?php
if ( $uploadFile ) {
esc_html_e( 'Upload successful.', 'mainwp-child' ); ?> <a href="#" id="mainwp-child_uploadclonebutton"
esc_html_e( 'Upload successful.', 'mainwp-child' );
?>
<a href="#" id="mainwp-child_uploadclonebutton"
class="button-primary"
file="<?php echo esc_attr( $uploadFile ); ?>"><?php esc_html_e( 'Clone/Restore website', 'mainwp-child' ); ?></a><?php
file="<?php echo esc_attr( $uploadFile ); ?>"><?php esc_html_e( 'Clone/Restore website', 'mainwp-child' ); ?></a>
<?php
} else {
if ( $uploadError ) {
?>
<div class="mainwp-child_info-box-red"><?php echo esc_html( $uploadError ); ?></div><?php
<div class="mainwp-child_info-box-red"><?php echo esc_html( $uploadError ); ?></div>
<?php
}
if ( empty( $sitesToClone ) ) {
@ -250,7 +254,7 @@ class MainWP_Clone {
if ( isset( $_REQUEST['upload'] ) && wp_verify_nonce( $_POST['_nonce'], 'cloneRestore' ) ) {
if ( isset( $_FILES['file'] ) ) {
if ( ! function_exists( 'wp_handle_upload' ) ) {
require_once( ABSPATH . 'wp-admin/includes/file.php' );
require_once ABSPATH . 'wp-admin/includes/file.php';
}
$uploadedfile = $_FILES['file'];
$upload_overrides = array( 'test_form' => false );
@ -277,27 +281,30 @@ class MainWP_Clone {
<?php
MainWP_Helper::getWPFilesystem();
global $wp_filesystem;
if ( ( ! empty( $wp_filesystem ) && ! $wp_filesystem->is_writable( WP_CONTENT_DIR ) ) || ( empty( $wp_filesystem ) && ! is_writable( WP_CONTENT_DIR ) ) ) {
echo '<div class="mainwp-child_info-box-red"><strong>' . esc_html__( 'Your content directory is not writable. Please set 0755 permission to ', 'mainwp-child' ) . esc_html( basename( WP_CONTENT_DIR ) ) . '. (' . esc_html( WP_CONTENT_DIR ) . ')</strong></div>';
$error = true;
}
if ( ( ! empty( $wp_filesystem ) && ! $wp_filesystem->is_writable( WP_CONTENT_DIR ) ) || ( empty( $wp_filesystem ) && ! is_writable( WP_CONTENT_DIR ) ) ) {
echo '<div class="mainwp-child_info-box-red"><strong>' . esc_html__( 'Your content directory is not writable. Please set 0755 permission to ', 'mainwp-child' ) . esc_html( basename( WP_CONTENT_DIR ) ) . '. (' . esc_html( WP_CONTENT_DIR ) . ')</strong></div>';
$error = true;
}
?>
<div class="mainwp-child_info-box-green" style="display: none;"><?php esc_html_e( 'Restore process completed successfully! You will now need to click ', 'mainwp-child' ); ?>
<a href="<?php echo esc_attr( admin_url( 'options-permalink.php' ) ); ?>"><?php esc_html_e( 'here', 'mainwp-child' ); ?></a><?php esc_html_e( ' to re-login to the admin and re-save permalinks.', 'mainwp-child' ); ?>
</div>
<?php
if ( $uploadFile ) {
esc_html_e( 'Upload successful.', 'mainwp-child' ); ?> <a href="#"
esc_html_e( 'Upload successful.', 'mainwp-child' );
?>
<a href="#"
id="mainwp-child_uploadclonebutton"
class="button-primary"
file="<?php echo esc_attr( $uploadFile ); ?>"><?php esc_html_e( 'Restore Website', 'mainwp-child' ); ?></a><?php
file="<?php echo esc_attr( $uploadFile ); ?>"><?php esc_html_e( 'Restore Website', 'mainwp-child' ); ?></a>
<?php
} else {
if ( $uploadError ) {
?>
if ( $uploadError ) {
?>
<div class="mainwp-child_info-box-red"><?php echo esc_html( $uploadError ); ?></div>
<?php
}
?>
<?php
}
?>
<p><?php esc_html_e( 'Upload backup in .zip format (Maximum filesize for your server settings: ', 'mainwp-child' ); ?><?php echo esc_html( $uploadSize ); ?>)</p>
<?php
$branding_title = MainWP_Child_Branding::Instance()->get_branding_title();
@ -307,7 +314,7 @@ class MainWP_Clone {
$branding_msg = esc_html__( 'If you have a FULL backup created by basic MainWP Backup system you may restore it by uploading here. Backups created by 3rd party plugins will not work.', 'mainwp-child' );
}
?>
<em> <?php echo $branding_msg ; ?> <br/>
<em> <?php echo $branding_msg; ?> <br/>
<?php esc_html_e( 'A database only backup will not work.', 'mainwp-child' ); ?></em><br/><br/>
<form action="<?php echo esc_attr( admin_url( 'options-general.php?page=mainwp_child_tab&tab=restore-clone&upload=yes' ) ); ?>"
method="post"
@ -326,8 +333,8 @@ class MainWP_Clone {
</div>
<?php
self::renderCloneFromServer();
self::renderJavaScript();
self::renderCloneFromServer();
self::renderJavaScript();
}
/*
@ -402,7 +409,7 @@ class MainWP_Clone {
$quick_links = array();
foreach ( $quick_dirs as $dir ) {
list( $text, $adir ) = $dir;
$adir = str_replace( '\\', '/', strtolower( $adir ) );
$adir = str_replace( '\\', '/', strtolower( $adir ) );
if ( strlen( $adir ) > 1 ) {
$adir = ltrim( $adir, '/' );
}
@ -448,7 +455,7 @@ class MainWP_Clone {
<div class="clonesite_select_site_item">
<div class="mainwp-child_name_label">
<a href="<?php echo esc_url( add_query_arg( array( 'dir' => rawurlencode( $parent ) ), $url ) ); ?>"
title="<?php echo esc_attr( dirname( $current_dir ) ) ?>"><?php esc_html_e( 'Parent Folder', 'mainwp-child' ) ?></a>
title="<?php echo esc_attr( dirname( $current_dir ) ); ?>"><?php esc_html_e( 'Parent Folder', 'mainwp-child' ); ?></a>
</div>
</div>
@ -459,7 +466,7 @@ class MainWP_Clone {
?>
<div class="clonesite_select_site_item">
<div class="mainwp-child_name_label">
<a href="<?php echo esc_attr( $folder_url ) ?>"><?php echo esc_html( rtrim( $filename, '/' ) . DIRECTORY_SEPARATOR ); ?></a>
<a href="<?php echo esc_attr( $folder_url ); ?>"><?php echo esc_html( rtrim( $filename, '/' ) . DIRECTORY_SEPARATOR ); ?></a>
</div>
</div>
<?php
@ -469,7 +476,7 @@ class MainWP_Clone {
?>
<div class="clonesite_select_site_item">
<div class="mainwp-child_name_label">
<span><?php echo esc_html( $file ) ?></span>
<span><?php echo esc_html( $file ); ?></span>
</div>
</div>
<?php
@ -479,7 +486,7 @@ class MainWP_Clone {
?>
<div class="mainwp_rejected_files">
<div class="mainwp-child_name_label">
<span><?php echo esc_html( $file ) ?></span>
<span><?php echo esc_html( $file ); ?></span>
</div>
</div>
<?php
@ -510,11 +517,10 @@ class MainWP_Clone {
<script language="javascript">
var child_security_nonces = [];
<?php
$security_nonces = MainWP_Clone::get()->getSecurityNonces();
foreach ($security_nonces as $k => $v)
{
echo 'child_security_nonces['."'" .$k . "'". '] = ' . "'" . $v . "';\n";
}
$security_nonces = self::get()->getSecurityNonces();
foreach ($security_nonces as $k => $v) {
echo 'child_security_nonces[' . "'" . $k . "'" . '] = ' . "'" . $v . "';\n";
}
?>
mainwpchild_secure_data = function(data, includeDts)
@ -585,8 +591,8 @@ class MainWP_Clone {
var translations = [];
translations['large_site'] = "<?php esc_html_e( 'This is a large site (%dMB), the restore process will more than likely fail.', 'mainwp-child' ); ?>";
translations['continue_anyway'] = "<?php esc_html_e( 'Continue Anyway?', 'mainwp-child' ); ?>";
translations['creating_backup'] = "<?php esc_html_e( 'Creating backup on %s expected size: %dMB (estimated time: %d seconds)', 'mainwp-child' ); ?>";
translations['backup_created'] = "<?php esc_html_e( 'Backup created on %s total size to download: %dMB', 'mainwp-child' ); ?>";
translations['creating_backup'] = "<?php esc_html_e( 'Creating backup on %1$s expected size: %2$dMB (estimated time: %3$d seconds)', 'mainwp-child' ); ?>";
translations['backup_created'] = "<?php esc_html_e( 'Backup created on %1$s total size to download: %2$dMB', 'mainwp-child' ); ?>";
translations['downloading_backup'] = "<?php esc_html_e( 'Downloading backup', 'mainwp-child' ); ?>";
translations['backup_downloaded'] = "<?php esc_html_e( 'Backup downloaded', 'mainwp-child' ); ?>";
translations['extracting_backup'] = "<?php esc_html_e( 'Extracting backup and updating your database, this might take a while. Please be patient.', 'mainwp-child' ); ?>";
@ -1199,16 +1205,16 @@ class MainWP_Clone {
$key = $siteToClone['extauth'];
MainWP_Helper::endSession();
//Send request to the childsite!
// Send request to the childsite!
global $wp_version;
$method = ( function_exists( 'gzopen' ) ? 'tar.gz' : 'zip' );
$result = MainWP_Helper::fetchUrl( $url, array(
'cloneFunc' => 'createCloneBackup',
'key' => $key,
'f' => $rand,
'wpversion' => $wp_version,
'zipmethod' => $method,
'json_result' => true
'cloneFunc' => 'createCloneBackup',
'key' => $key,
'f' => $rand,
'wpversion' => $wp_version,
'zipmethod' => $method,
'json_result' => true,
) );
if ( ! $result['backup'] ) {
@ -1219,7 +1225,10 @@ class MainWP_Clone {
MainWP_Helper::update_option( 'mainwp_temp_clone_plugins', $result['plugins'] );
MainWP_Helper::update_option( 'mainwp_temp_clone_themes', $result['themes'] );
$output = array( 'url' => $result['backup'], 'size' => round( $result['size'] / 1024, 0 ) );
$output = array(
'url' => $result['backup'],
'size' => round( $result['size'] / 1024, 0 ),
);
} catch ( Exception $e ) {
$output = array( 'error' => $e->getMessage() );
}
@ -1248,12 +1257,12 @@ class MainWP_Clone {
$key = $siteToClone['extauth'];
MainWP_Helper::endSession();
//Send request to the childsite!
// Send request to the childsite!
$result = MainWP_Helper::fetchUrl( $url, array(
'cloneFunc' => 'createCloneBackupPoll',
'key' => $key,
'f' => $rand,
'json_result' => true
'cloneFunc' => 'createCloneBackupPoll',
'key' => $key,
'f' => $rand,
'json_result' => true,
) );
if ( ! isset( $result['size'] ) ) {
@ -1264,7 +1273,7 @@ class MainWP_Clone {
} catch ( Exception $e ) {
$output = array( 'error' => $e->getMessage() );
}
//Return size in kb
// Return size in kb
die( json_encode( $output ) );
}
@ -1275,7 +1284,7 @@ class MainWP_Clone {
if ( ! isset( $_POST['file'] ) ) {
throw new Exception( __( 'No download link given', 'mainwp-child' ) );
}
// if (!isset($_POST['siteId'])) throw new Exception(__('No site given','mainwp-child'));
// if (!isset($_POST['siteId'])) throw new Exception(__('No site given','mainwp-child'));
$file = $_POST['file'];
if ( isset( $_POST['siteId'] ) ) {
@ -1295,7 +1304,7 @@ class MainWP_Clone {
$url = $file;
}
MainWP_Helper::endSession();
//Send request to the childsite!
// Send request to the childsite!
$split = explode( '=', $file );
$file = urldecode( $split[ count( $split ) - 1 ] );
$filename = 'download-' . basename( $file );
@ -1313,7 +1322,11 @@ class MainWP_Clone {
$filename = $backupdir . $filename;
$response = wp_remote_get( $url, array( 'timeout' => 300000, 'stream' => true, 'filename' => $filename ) );
$response = wp_remote_get( $url, array(
'timeout' => 300000,
'stream' => true,
'filename' => $filename,
) );
if ( is_wp_error( $response ) ) {
unlink( $filename );
@ -1329,7 +1342,7 @@ class MainWP_Clone {
$output = array( 'done' => $filename );
//Delete backup on child
// Delete backup on child
try {
if ( isset( $_POST['siteId'] ) ) {
$siteId = $_POST['siteId'];
@ -1338,10 +1351,10 @@ class MainWP_Clone {
$siteToClone = $sitesToClone[ $siteId ];
MainWP_Helper::fetchUrl( $siteToClone['url'], array(
'cloneFunc' => 'deleteCloneBackup',
'key' => $siteToClone['extauth'],
'f' => $_POST['file'],
'json_result' => true
'cloneFunc' => 'deleteCloneBackup',
'key' => $siteToClone['extauth'],
'f' => $_POST['file'],
'json_result' => true,
) );
}
}
@ -1379,7 +1392,7 @@ class MainWP_Clone {
} catch ( Exception $e ) {
$output = array( 'error' => $e->getMessage() );
}
//return size in kb
// return size in kb
die( json_encode( $output ) );
}
@ -1407,7 +1420,7 @@ class MainWP_Clone {
throw new Exception( __( 'No download file found', 'mainwp-child' ) );
}
$file = $archiveFile;
} else if ( file_exists( $file ) ) {
} elseif ( file_exists( $file ) ) {
$testFull = true;
} else {
$file = ABSPATH . $file;
@ -1416,10 +1429,10 @@ class MainWP_Clone {
}
$testFull = true;
}
//return size in kb
// return size in kb
$cloneInstall = new MainWP_Clone_Install( $file );
//todo: RS: refactor to get those plugins after install (after .18 release)
// todo: RS: refactor to get those plugins after install (after .18 release)
$cloneInstall->readConfigurationFile();
$plugins = get_option( 'mainwp_temp_clone_plugins' );
@ -1441,14 +1454,14 @@ class MainWP_Clone {
$cloneInstall->install();
// $cloneInstall->update_option('mainwp_child_pubkey', $pubkey);
// $cloneInstall->update_option('mainwp_child_uniqueId', $uniqueId);
// $cloneInstall->update_option('mainwp_child_server', $server);
// $cloneInstall->update_option('mainwp_child_nonce', $nonce);
// $cloneInstall->update_option('mainwp_child_nossl', $nossl);
// $cloneInstall->update_option('mainwp_child_nossl_key', $nossl_key);
// $cloneInstall->update_option('mainwp_child_clone_sites', $sitesToClone);
// $cloneInstall->update_option('mainwp_child_clone_permalink', true);
// $cloneInstall->update_option('mainwp_child_pubkey', $pubkey);
// $cloneInstall->update_option('mainwp_child_uniqueId', $uniqueId);
// $cloneInstall->update_option('mainwp_child_server', $server);
// $cloneInstall->update_option('mainwp_child_nonce', $nonce);
// $cloneInstall->update_option('mainwp_child_nossl', $nossl);
// $cloneInstall->update_option('mainwp_child_nossl_key', $nossl_key);
// $cloneInstall->update_option('mainwp_child_clone_sites', $sitesToClone);
// $cloneInstall->update_option('mainwp_child_clone_permalink', true);
// to fix update values
delete_option('mainwp_child_pubkey');
@ -1520,14 +1533,14 @@ class MainWP_Clone {
delete_option( 'mainwp_temp_clone_themes' );
}
$output = array( 'result' => 'ok' );
//todo: remove old tables if other prefix?
// todo: remove old tables if other prefix?
wp_logout();
wp_set_current_user( 0 );
} catch ( Exception $e ) {
$output = array( 'error' => $e->getMessage() );
}
//return size in kb
// return size in kb
die( json_encode( $output ) );
}
@ -1558,11 +1571,15 @@ class MainWP_Clone {
clear: both;
}
</style>
<div class="mainwp-child_info-box-green"><?php if ( get_option( 'mainwp_child_restore_permalink' ) ) {
<div class="mainwp-child_info-box-green">
<?php
if ( get_option( 'mainwp_child_restore_permalink' ) ) {
esc_html_e( 'Restore process completed successfully! Check and re-save permalinks ', 'mainwp-child' );
} else {
} else {
esc_html_e( 'Cloning process completed successfully! Check and re-save permalinks ', 'mainwp-child' );
} ?> <a
}
?>
<a
href="<?php echo esc_attr( admin_url( 'options-permalink.php' ) ); ?>"><?php esc_html_e( 'here', 'mainwp-child' ); ?></a>.
</div>
<?php

View file

@ -1,16 +1,16 @@
<?php
class MainWP_Custom_Post_Type {
public static $instance = null;
public static $instance = null;
public static $information = array();
public $plugin_translate = "mainwp-child";
public $plugin_translate = 'mainwp-child';
static function Instance() {
if ( MainWP_Custom_Post_Type::$instance == null ) {
MainWP_Custom_Post_Type::$instance = new MainWP_Custom_Post_Type();
if ( self::$instance == null ) {
self::$instance = new MainWP_Custom_Post_Type();
}
return MainWP_Custom_Post_Type::$instance;
return self::$instance;
}
public function action() {
@ -20,22 +20,22 @@ class MainWP_Custom_Post_Type {
$error = error_get_last();
if ( isset( $error['type'] ) && E_ERROR === $error['type'] && isset( $error['message'] ) ) {
$data = array( 'error' => 'MainWPChild fatal error : ' . $error['message'] . ' Line: ' . $error['line'] . ' File: ' . $error['file'] );
// die( '<mainwp>' . base64_encode( serialize( ) ) . '</mainwp>' );
// die( '<mainwp>' . base64_encode( serialize( ) ) . '</mainwp>' );
} else {
$data = MainWP_Custom_Post_Type::$information;
// die( '<mainwp>' . base64_encode( serialize( MainWP_Custom_Post_Type::$information ) ) . '</mainwp>' );
$data = self::$information;
// die( '<mainwp>' . base64_encode( serialize( MainWP_Custom_Post_Type::$information ) ) . '</mainwp>' );
}
if ( isset( $_REQUEST['json_result'] ) && $_REQUEST['json_result'] ) {
$data = json_encode( $data );
} else {
$data = serialize( $data );
}
die('<mainwp>' . base64_encode( $data ) . '</mainwp>');
}
register_shutdown_function( "mainwp_custom_post_type_handle_fatal_error" );
register_shutdown_function( 'mainwp_custom_post_type_handle_fatal_error' );
$information = array();
switch ( $_POST['action'] ) {
@ -48,7 +48,7 @@ class MainWP_Custom_Post_Type {
}
MainWP_Custom_Post_Type::$information = $information;
self::$information = $information;
exit();
}
@ -67,8 +67,8 @@ class MainWP_Custom_Post_Type {
if ( empty( $data ) || ! is_array( $data ) || ! isset( $data['post'] ) ) {
return array( 'error' => __( 'Cannot decode data', $this->plugin_translate ) );
}
$edit_id = (isset($_POST['post_id']) && !empty($_POST['post_id'])) ? $_POST['post_id'] : 0;
$return = $this->_insert_post($data, $edit_id, $parent_id = 0);
$edit_id = ( isset($_POST['post_id']) && ! empty($_POST['post_id']) ) ? $_POST['post_id'] : 0;
$return = $this->_insert_post($data, $edit_id, $parent_id = 0);
if (isset($return['success']) && $return['success'] == 1) {
if (isset($data['product_variation']) && is_array($data['product_variation'])) {
foreach ($data['product_variation'] as $product_variation) {
@ -104,7 +104,7 @@ class MainWP_Custom_Post_Type {
}
try {
$downloadfile = MainWP_Helper::uploadImage( $originalImgUrl , array(), $check_image );
$downloadfile = MainWP_Helper::uploadImage( $originalImgUrl, array(), $check_image );
$localUrl = $downloadfile['url'];
$linkToReplaceWith = dirname( $localUrl );
if ( '' !== $hrefLink ) {
@ -114,7 +114,7 @@ class MainWP_Custom_Post_Type {
$serverHref = 'href="' . $serverHost;
$replaceServerHref = 'href="' . parse_url( $localUrl, PHP_URL_SCHEME ) . '://' . parse_url( $localUrl, PHP_URL_HOST );
$post_content = str_replace( $serverHref, $replaceServerHref, $post_content );
} else if ( strpos( $hrefLink, 'http' ) !== false ) {
} elseif ( strpos( $hrefLink, 'http' ) !== false ) {
$lnkToReplace = dirname( $hrefLink );
if ( 'http:' !== $lnkToReplace && 'https:' !== $lnkToReplace ) {
$post_content = str_replace( $lnkToReplace, $linkToReplaceWith, $post_content );
@ -159,7 +159,7 @@ class MainWP_Custom_Post_Type {
'post_modified_gmt',
'post_content_filtered',
'menu_order',
'post_type'
'post_type',
);
foreach ( $data_keys as $key ) {
@ -174,23 +174,23 @@ class MainWP_Custom_Post_Type {
return array( 'error' => __( 'Please install', $this->plugin_translate ) . ' ' . $data_insert['post_type'] . ' ' . __( 'on child and try again', $this->plugin_translate ) );
}
//$data_insert['post_content'] = $this->_search_images( $data_insert['post_content'], $data['extras']['upload_dir'] );
// $data_insert['post_content'] = $this->_search_images( $data_insert['post_content'], $data['extras']['upload_dir'] );
$is_woocomerce = false;
if ( ($data_insert['post_type'] == 'product' || $data_insert['post_type'] == 'product_variation' )&& function_exists( 'wc_product_has_unique_sku' ) ) {
if ( ( $data_insert['post_type'] == 'product' || $data_insert['post_type'] == 'product_variation' ) && function_exists( 'wc_product_has_unique_sku' ) ) {
$is_woocomerce = true;
}
$check_image_existed = false;
// Support post_edit
if ( !empty( $edit_id ) ) {
if ( ! empty( $edit_id ) ) {
$old_post_id = (int) $edit_id;
$old_post = get_post( $old_post_id, ARRAY_A );
if ( is_null( $old_post ) ) {
return array(
'delete_connection' => 1,
'error' => __( 'Cannot get old post. Probably is deleted now. Please try again for create new post', $this->plugin_translate )
'error' => __( 'Cannot get old post. Probably is deleted now. Please try again for create new post', $this->plugin_translate ),
);
}
@ -215,7 +215,7 @@ class MainWP_Custom_Post_Type {
$data_insert['post_content'] = $this->_search_images( $data_insert['post_content'], $data['extras']['upload_dir'], $check_image_existed );
if (!empty($parent_id)) {
if ( ! empty($parent_id)) {
$data_insert['post_parent'] = $parent_id; // for product variation
}
$post_id = wp_insert_post( $data_insert, true );
@ -286,7 +286,7 @@ class MainWP_Custom_Post_Type {
// MainWP Categories
if ( ! empty( $data['categories'] ) && is_array( $data['categories'] ) ) {
// Contains wp_create_categories
include_once( ABSPATH . 'wp-admin/includes/taxonomy.php' );
include_once ABSPATH . 'wp-admin/includes/taxonomy.php';
$categories = $data['categories'];
if ( $data['post_only_existing'] == '0' ) {
$post_category = wp_create_categories( $categories, $post_id );
@ -303,7 +303,7 @@ class MainWP_Custom_Post_Type {
}
}
//Insert post terms except categories
// Insert post terms except categories
if ( ! empty( $data['terms'] ) && is_array( $data['terms'] ) ) {
foreach ( $data['terms'] as $key ) {
if ( ! taxonomy_exists( $key['taxonomy'] ) ) {
@ -313,7 +313,7 @@ class MainWP_Custom_Post_Type {
// @todo missing alias_of which means term_group
$term = wp_insert_term( $key['name'], $key['taxonomy'], array(
'description' => $key['description'],
'slug' => $key['slug']
'slug' => $key['slug'],
) );
$term_taxonomy_id = 0;
@ -337,6 +337,9 @@ class MainWP_Custom_Post_Type {
}
}
return array( 'success' => 1, 'post_id' => $post_id );
return array(
'success' => 1,
'post_id' => $post_id,
);
}
}

View file

@ -1,34 +1,33 @@
<?php
class MainWP_Debug {
/**
* @param $mainwpChild MainWP_Child
*/
public static function process(&$mainwpChild) {
if ( ! isset( $_GET['mainwpdebug'] ) || ! defined( 'MAINWP_DEBUG' ) || ( MAINWP_DEBUG !== true ) ) {
return;
}
echo '<pre>';
$start = microtime( true );
if ( 'fullbackup' == $_GET['mainwpdebug'] ) {
//Full backup
$_POST['type'] = 'full';
$_POST['excludebackup'] = '1';
$_POST['excludecache'] = '1';
$_POST['excludezip'] = '1';
$_POST['excludenonwp'] = '1';
$_POST['ext'] = 'tar.gz';
print_r( $mainwpChild->backup( false ) );
} else if ( 'test' == $_GET['mainwpdebug'] ) {
print_r( get_included_files() );
} else {
print_r( $mainwpChild->getSiteStats( array(), false ) );
}
$stop = microtime( true );
die( "\n\n\n" . 'duration: ' . ( $stop - $start ) . 's</pre>' );
}
}
<?php
class MainWP_Debug {
/**
* @param $mainwpChild MainWP_Child
*/
public static function process( &$mainwpChild) {
if ( ! isset( $_GET['mainwpdebug'] ) || ! defined( 'MAINWP_DEBUG' ) || ( MAINWP_DEBUG !== true ) ) {
return;
}
echo '<pre>';
$start = microtime( true );
if ( 'fullbackup' == $_GET['mainwpdebug'] ) {
// Full backup
$_POST['type'] = 'full';
$_POST['excludebackup'] = '1';
$_POST['excludecache'] = '1';
$_POST['excludezip'] = '1';
$_POST['excludenonwp'] = '1';
$_POST['ext'] = 'tar.gz';
print_r( $mainwpChild->backup( false ) );
} elseif ( 'test' == $_GET['mainwpdebug'] ) {
print_r( get_included_files() );
} else {
print_r( $mainwpChild->getSiteStats( array(), false ) );
}
$stop = microtime( true );
die( "\n\n\n" . 'duration: ' . ( $stop - $start ) . 's</pre>' );
}
}

File diff suppressed because it is too large Load diff

View file

@ -9,15 +9,15 @@ class MainWP_Keyword_Links {
protected $link_temp;
protected $link_count_temp;
protected $link_count_each_temp;
protected $link_exact_match = 1;
protected $link_exact_match = 1;
protected $link_case_sensitive = 1;
static function Instance() {
if ( null === MainWP_Keyword_Links::$instance ) {
MainWP_Keyword_Links::$instance = new MainWP_Keyword_Links();
if ( null === self::$instance ) {
self::$instance = new MainWP_Keyword_Links();
}
return MainWP_Keyword_Links::$instance;
return self::$instance;
}
public function __construct() {
@ -31,14 +31,14 @@ class MainWP_Keyword_Links {
if ( empty( $this->keyword_links ) ) {
$this->keyword_links = array();
}
//print_r($this->keyword_links);
// print_r($this->keyword_links);
$this->siteurl = get_option( 'home' );
add_action( 'permalink_structure_changed', array( &$this, 'permalinkChanged' ), 10, 2 );
}
public function keywordLinksJS() {
if ( ! is_admin() && get_option( 'mainwp_kwl_enable_statistic' ) && !empty($this->keyword_links) ) {
if ( ! is_admin() && get_option( 'mainwp_kwl_enable_statistic' ) && ! empty($this->keyword_links) ) {
wp_enqueue_script( 'jquery' );
wp_enqueue_script( 'keywordLinks', plugins_url( '/js/keywordlinks.js', dirname( __FILE__ ) ) );
add_action( 'wp_head', array( $this, 'head_loading' ), 1 );
@ -75,11 +75,11 @@ class MainWP_Keyword_Links {
$home_root = '/';
}
$rules = "<IfModule mod_rewrite.c>\n";
$rules = "<IfModule mod_rewrite.c>\n";
$rules .= "RewriteEngine On\n";
$rules .= "RewriteBase $home_root\n";
//add in the rules that don't redirect to WP's index.php (and thus shouldn't be handled by WP at all)
// add in the rules that don't redirect to WP's index.php (and thus shouldn't be handled by WP at all)
foreach ( $pRules as $match => $query ) {
// Apache 1.3 does not support the reluctant (non-greedy) modifier.
$match = str_replace( '.+?', '.+', $match );
@ -95,13 +95,13 @@ class MainWP_Keyword_Links {
function update_htaccess( $force_update = false, $force_clear = false ) {
if ( $force_clear ) {
$this->do_update_htaccess( true );
} else if ( $force_update ) {
} elseif ( $force_update ) {
return $this->do_update_htaccess();
} else {
if ( '' == get_option( 'permalink_structure' ) && 'yes' !== get_option( 'mainwp_keyword_links_htaccess_set' ) ) {
$this->do_update_htaccess();
} // need to update
else if ( '' != get_option( 'permalink_structure' ) && 'yes' === get_option( 'mainwp_keyword_links_htaccess_set' ) ) {
elseif ( '' != get_option( 'permalink_structure' ) && 'yes' === get_option( 'mainwp_keyword_links_htaccess_set' ) ) {
$this->do_update_htaccess();
} // need to update
}
@ -110,7 +110,7 @@ class MainWP_Keyword_Links {
}
public static function clear_htaccess() {
include_once( ABSPATH . '/wp-admin/includes/misc.php' );
include_once ABSPATH . '/wp-admin/includes/misc.php';
$home_path = ABSPATH;
$htaccess_file = $home_path . '.htaccess';
if ( function_exists( 'save_mod_rewrite_rules' ) ) {
@ -125,15 +125,15 @@ class MainWP_Keyword_Links {
self::clear_htaccess();
return true;
} else if ( '' === get_option( 'permalink_structure' ) ) {
include_once( ABSPATH . '/wp-admin/includes/misc.php' );
} elseif ( '' === get_option( 'permalink_structure' ) ) {
include_once ABSPATH . '/wp-admin/includes/misc.php';
$redirection_folder = $this->get_option( 'redirection_folder', '' );
if ( empty( $redirection_folder ) ) {
$rules = $this->get_cloak_rules();
$rules = $this->mod_rewrite_rules( $rules );
//self::clear_htaccess();
// self::clear_htaccess();
} else {
//Create rewrite ruler
// Create rewrite ruler
$rules = $this->mod_rewrite_rules( array( $redirection_folder . '/' => 'index.php' ) );
}
$home_path = ABSPATH;
@ -297,7 +297,7 @@ class MainWP_Keyword_Links {
if ( is_array( $specific_link ) && count( $specific_link ) > 0 ) {
$specific_link = current( $specific_link );
$specific_link->post_id = $post->ID;
//update_post_meta($post->ID, '_mainwp_kwl_specific_link_save', array($specific_link->id => $specific_link));
// update_post_meta($post->ID, '_mainwp_kwl_specific_link_save', array($specific_link->id => $specific_link));
update_post_meta( $post->ID, '_mainwp_kwl_specific_link_id', $specific_link->id );
if ( $this->set_link( $specific_link->id, $specific_link ) ) {
update_post_meta( $post->ID, '_mainwp_kwl_specific_link', '<saved>' );
@ -312,11 +312,11 @@ class MainWP_Keyword_Links {
}
// print_r($this->keyword_links);
// if ($post->ID == 751) {
// //print_r($links);
// $custom = get_post_custom($post->ID);
// print_r($custom);
// }
// if ($post->ID == 751) {
// print_r($links);
// $custom = get_post_custom($post->ID);
// print_r($custom);
// }
if ( empty( $links ) ) {
return $content;
@ -343,10 +343,10 @@ class MainWP_Keyword_Links {
$this->link_exact_match = $link->exact_match;
$this->link_case_sensitive = $link->case_sensitive;
$keywords = $this->explode_multi( $link->keyword );
//usort( $keywords, create_function( '$a,$b', 'return strlen($a)<strlen($b);' ) );
usort( $keywords, array($this, 'usort_callback_func') );
// usort( $keywords, create_function( '$a,$b', 'return strlen($a)<strlen($b);' ) );
usort( $keywords, array( $this, 'usort_callback_func' ) );
$replace_cs = $link->case_sensitive ? 's' : 'is';
//print_r($keywords);
// print_r($keywords);
foreach ( $keywords as $keyword ) {
$keyword = trim( $keyword );
if ( empty( $keyword ) ) {
@ -361,15 +361,15 @@ class MainWP_Keyword_Links {
$keyword = preg_replace( '/([$^\/?+.*\]\[)(}{])/is', '\\\\\1', $keyword );
if ( ( $link->case_sensitive && strpos( $content, $keyword ) !== false ) || ( ! $link->case_sensitive && stripos( $content, $keyword ) !== false ) ) {
//Replace keyword in H tag
// Replace keyword in H tag
if ( $this->get_option( 'replace_keyword_in_h_tag' ) ) {
//$content = preg_replace_callback('/(<a[^>]*>.*?'.$keyword.'.*?<\/a>|<[^>]*'.$keyword.'[^>]*>|\{[^}]*'.$keyword.'[^}]*\}|\w*('.$keyword.')\w*)/is', array(&$this, 'keyword_mark'), $content);
// $content = preg_replace_callback('/(<a[^>]*>.*?'.$keyword.'.*?<\/a>|<[^>]*'.$keyword.'[^>]*>|\{[^}]*'.$keyword.'[^}]*\}|\w*('.$keyword.')\w*)/is', array(&$this, 'keyword_mark'), $content);
$content = preg_replace_callback( '/(<a[^>]*>[^<]*?' . $keyword . '[^<]*?<\/a>|<[^>]*' . $keyword . '[^>]*>|\{[^\}]*' . $keyword . '[^\}]*\}|\w*(' . $keyword . ')\w*)/' . $replace_cs, array(
&$this,
'keyword_mark',
), $content );
} else {
//$content = preg_replace_callback('/(<h[123456][^>]*>.*?'.$keyword.'.*?<\/h[123456]>|<a[^>]*>.*?'.$keyword.'.*?<\/a>|<[^>]*'.$keyword.'[^>]*>|\{[^}]*'.$keyword.'[^}]*\}|\w*('.$keyword.')\w*)/is', array(&$this, 'keyword_mark'), $content);
// $content = preg_replace_callback('/(<h[123456][^>]*>.*?'.$keyword.'.*?<\/h[123456]>|<a[^>]*>.*?'.$keyword.'.*?<\/a>|<[^>]*'.$keyword.'[^>]*>|\{[^}]*'.$keyword.'[^}]*\}|\w*('.$keyword.')\w*)/is', array(&$this, 'keyword_mark'), $content);
$content = preg_replace_callback( '/(<h[123456][^>]*>[^<]*?' . $keyword . '[^<]*?<\/h[123456]>|<a[^>]*>[^<]*?' . $keyword . '[^<]*?<\/a>|<[^>]*' . $keyword . '[^>]*>|\{[^\}]*' . $keyword . '[^\}]*\}|\w*(' . $keyword . ')\w*)/' . $replace_cs, array(
&$this,
'keyword_mark',
@ -378,7 +378,7 @@ class MainWP_Keyword_Links {
}
}
}
//$content = preg_replace_callback('/\{MAINWP_LINK +HREF="(.*?)" +TARGET="(.*?)" +REL="(.*?)" +LINK-ID="(.*?)" +CLASS="(.*?)" +TEXT="(.*?)" *\}/is', array(&$this, 'keyword_replace'), $content);
// $content = preg_replace_callback('/\{MAINWP_LINK +HREF="(.*?)" +TARGET="(.*?)" +REL="(.*?)" +LINK-ID="(.*?)" +CLASS="(.*?)" +TEXT="(.*?)" *\}/is', array(&$this, 'keyword_replace'), $content);
$content = preg_replace_callback( '/\{MAINWP_LINK +HREF="(.*?)" +TARGET="(.*?)" +REL="(.*?)" +LINK-ID="(.*?)" +CLASS="(.*?)" +TEXT="(.*?)" +FULL_TEXT="(.*?)" *\}/is', array(
&$this,
'keyword_replace',
@ -387,8 +387,8 @@ class MainWP_Keyword_Links {
return $content;
}
private function usort_callback_func($a, $b) {
return strlen($a)<strlen($b);
private function usort_callback_func( $a, $b) {
return strlen($a) < strlen($b);
}
public function keyword_mark( $matches ) {
@ -415,19 +415,19 @@ class MainWP_Keyword_Links {
$this->link_count_each_temp --;
}
// if (isset($this->link_temp->type) && $this->link_temp->type == 'post_type') {
//// $post = get_post($this->link_temp->id);
//// if ($post) {
//// $disable_linking = $this->get_option('disable_linking_automatically', array());
//// if (in_array($post->post_name, $disable_linking[$post->post_type]))
//// return $matches[1]; // do not link to this post
//// }
// $link_target = get_post_meta($this->link_temp->id, '_mainwp_kl_link_newtab', true);
// $this->link_temp->link_target = ( $link_target != -1 && $link_target == 1 ? '_blank' : '' );
// $link_rel = get_post_meta($this->link_temp->id, '_mainwp_kl_link_nofollow', true);
// $this->link_temp->link_rel = ( $link_rel != -1 && $link_rel == 1 ? 'nofollow' : '' );
// $this->link_temp->link_class = get_post_meta($this->link_temp->id, '_mainwp_kl_link_class', true);
// }
// if (isset($this->link_temp->type) && $this->link_temp->type == 'post_type') {
// $post = get_post($this->link_temp->id);
// if ($post) {
// $disable_linking = $this->get_option('disable_linking_automatically', array());
// if (in_array($post->post_name, $disable_linking[$post->post_type]))
// return $matches[1]; // do not link to this post
// }
// $link_target = get_post_meta($this->link_temp->id, '_mainwp_kl_link_newtab', true);
// $this->link_temp->link_target = ( $link_target != -1 && $link_target == 1 ? '_blank' : '' );
// $link_rel = get_post_meta($this->link_temp->id, '_mainwp_kl_link_nofollow', true);
// $this->link_temp->link_rel = ( $link_rel != -1 && $link_rel == 1 ? 'nofollow' : '' );
// $this->link_temp->link_class = get_post_meta($this->link_temp->id, '_mainwp_kl_link_class', true);
// }
if ( '-1' !== $this->link_temp->link_target ) {
$target = $this->link_temp->link_target;
} else {
@ -453,15 +453,15 @@ class MainWP_Keyword_Links {
$regular_link = false;
if ( empty( $this->link_temp->cloak_path ) ) {
$regular_link = true;
$class .= ' kwl-regular-link';
$class .= ' kwl-regular-link';
}
//return '{MAINWP_LINK HREF="' . ( $this->link_temp->cloak_path ? $this->siteurl . $redirection_folder . '/' . $this->link_temp->cloak_path : $this->link_temp->destination_url) . '" TARGET="' . $target . '" REL="' . $rel . '" LINK-ID="' . (isset($this->link_temp->id) ? $this->link_temp->id : 0) . '" CLASS="' . $class . '" TEXT="' . $matches[1] . '"}';
// return '{MAINWP_LINK HREF="' . ( $this->link_temp->cloak_path ? $this->siteurl . $redirection_folder . '/' . $this->link_temp->cloak_path : $this->link_temp->destination_url) . '" TARGET="' . $target . '" REL="' . $rel . '" LINK-ID="' . (isset($this->link_temp->id) ? $this->link_temp->id : 0) . '" CLASS="' . $class . '" TEXT="' . $matches[1] . '"}';
return '{MAINWP_LINK HREF="' . ( $this->link_temp->cloak_path ? $this->siteurl . $redirection_folder . '/' . $this->link_temp->cloak_path : $this->link_temp->destination_url ) . '" TARGET="' . $target . '" REL="' . $rel . '" LINK-ID="' . ( isset( $this->link_temp->id ) ? $this->link_temp->id : 0 ) . '" CLASS="' . $class . '" TEXT="' . $matches[2] . '" FULL_TEXT="' . $matches[1] . '"}';
}
public function keyword_replace( $matches ) {
$a = '<a href="' . $matches[1] . '"';
$a = '<a href="' . $matches[1] . '"';
$a .= ( $matches[2] ) ? ' target="' . $matches[2] . '"' : '';
$a .= ( $matches[3] ) ? ' rel="' . $matches[3] . '"' : '';
$a .= ( $matches[4] ) ? ' link-id="' . $matches[4] . '"' : '';
@ -483,16 +483,16 @@ class MainWP_Keyword_Links {
$post = get_post( $post_id );
}
$links = array();
// $disable_add_links = $this->get_option('disable_add_links_automatically');
// // if disabled add links automatically in this post, avoid
// if (in_array($post->post_name, (array) $disable_add_links[$post->post_type])) {
// return $links;
// }
// $disable_add_links = $this->get_option('disable_add_links_automatically');
// if disabled add links automatically in this post, avoid
// if (in_array($post->post_name, (array) $disable_add_links[$post->post_type])) {
// return $links;
// }
// Check if this post was disabled with this function, come back
// $disable = get_post_meta($post->ID, '_mainwp_kl_disable', true);
// if ($disable == 1)
// return $links;
// $disable = get_post_meta($post->ID, '_mainwp_kl_disable', true);
// if ($disable == 1)
// return $links;
// count replace max and max keyword allowed.
$replace_max = intval( $this->get_option( 'replace_max' ) );
$replace_max_keyword = intval( $this->get_option( 'replace_max_keyword' ) );
@ -514,7 +514,7 @@ class MainWP_Keyword_Links {
} else {
$links_post_type = (array) $this->get_post_keywords( $post_type );
}
//print_r($links_post_type);
// print_r($links_post_type);
if ( count( $links_post_type ) > 0 ) {
$links = array_merge( $links, $links_post_type );
}
@ -534,7 +534,7 @@ class MainWP_Keyword_Links {
} else {
$links[] = $link;
}
} else if ( $spec_link_id && $spec_link_id === $link->id ) { // type 2 is specific link
} elseif ( $spec_link_id && $spec_link_id === $link->id ) { // type 2 is specific link
if ( $link->check_post_date ) {
if ( $post_timestamp < $link->check_post_date ) {
$links[] = $link;
@ -557,7 +557,7 @@ class MainWP_Keyword_Links {
$join = "JOIN $wpdb->term_relationships tr ON tr.object_id = p.ID";
$where = " AND (tr.term_taxonomy_id = '" . implode( "' OR tr.term_taxonomy_id = '", $cats ) . "')";
}
//$results = $wpdb->get_results(sprintf("SELECT * FROM $wpdb->posts as p LEFT JOIN $wpdb->postmeta as pm ON p.ID=pm.post_id $join WHERE p.post_status='publish' AND p.post_type='%s' AND pm.meta_key='_mainwp_kl_post_keyword' $where", $post_type));
// $results = $wpdb->get_results(sprintf("SELECT * FROM $wpdb->posts as p LEFT JOIN $wpdb->postmeta as pm ON p.ID=pm.post_id $join WHERE p.post_status='publish' AND p.post_type='%s' AND pm.meta_key='_mainwp_kl_post_keyword' $where", $post_type));
$results = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->posts as p $join WHERE p.post_status='publish' AND p.post_type= %s $where", $post_type ) );
$links = array();
if ( ! is_array( $results ) ) {
@ -571,14 +571,14 @@ class MainWP_Keyword_Links {
if ( in_array( $result->post_name, (array) $paths_blocked ) ) {
continue;
}
$link = new stdClass;
$link = new stdClass();
// This is on-fly link so have not ID
//$link->id = $result->ID;
// $link->id = $result->ID;
$link->name = $result->post_title;
//if ($result->post_type == 'page')
// $link->destination_url = get_permalink($result->ID);
//else
// $link->destination_url = $result->guid;
// if ($result->post_type == 'page')
// $link->destination_url = get_permalink($result->ID);
// else
// $link->destination_url = $result->guid;
$link->destination_url = get_permalink( $result->ID );
$link->cloak_path = '';
$link->keyword = ( 1 === (int) $this->get_option( 'post_match_title' ) ? $result->post_title : '' );
@ -616,7 +616,7 @@ class MainWP_Keyword_Links {
if ( ! preg_match( '|^[a-z0-9-~+_.?#=!&;,/:%@$\|*\'()\\x80-\\xff]+$|i', $request ) ) {
return;
}
// Check to see if Wordpress is installed in sub folder
// Check to see if WordPress is installed in sub folder
$siteurl = parse_url( $this->siteurl );
$sitepath = ( isset( $siteurl['path'] ) ) ? $siteurl['path'] : '';
$filter_request = preg_replace( '|^' . $sitepath . '/?|i', '', $request );
@ -625,7 +625,7 @@ class MainWP_Keyword_Links {
$redirection_folder = $this->get_option( 'redirection_folder', '' );
if ( ! empty( $redirection_folder ) ) {
//if the request doesn't' containt the redirection folder we will return immediately
// if the request doesn't' containt the redirection folder we will return immediately
if ( strpos( $filter_request, $redirection_folder . '/' ) === false ) {
return;
}
@ -677,21 +677,21 @@ class MainWP_Keyword_Links {
}
}
// public function get_statistic() {
// global $wpdb;
// $link_id = $_POST['link_id'];
// if ($link_id) {
// $stat_data = get_option('mainwp_kwl_statistic_data_' . $link_id, array());
// if ($stat_data) {
// $return['stat_data'] = $stat_data;
// //$wpdb->query("UPDATE {$wpdb->prefix}options SET option_name = 'mainwp_kwl_statistic_data_done_" . $link_id . "' WHERE option_name = 'mainwp_kwl_statistic_data_" . $link_id . "'");
// update_option('mainwp_kwl_statistic_data_' . $link_id, '');
// } else
// $return['stat_data'] = 'EMPTY';
// $return['status'] = 'SUCCESS';
// }
// return $return;
// }
// public function get_statistic() {
// global $wpdb;
// $link_id = $_POST['link_id'];
// if ($link_id) {
// $stat_data = get_option('mainwp_kwl_statistic_data_' . $link_id, array());
// if ($stat_data) {
// $return['stat_data'] = $stat_data;
// $wpdb->query("UPDATE {$wpdb->prefix}options SET option_name = 'mainwp_kwl_statistic_data_done_" . $link_id . "' WHERE option_name = 'mainwp_kwl_statistic_data_" . $link_id . "'");
// update_option('mainwp_kwl_statistic_data_' . $link_id, '');
// } else
// $return['stat_data'] = 'EMPTY';
// $return['status'] = 'SUCCESS';
// }
// return $return;
// }
public function action() {
$result = array();
@ -741,7 +741,7 @@ class MainWP_Keyword_Links {
if ( $remove_settings ) {
$this->clear_settings();
$return['status'] = 'SUCCESS';
} else if ( is_array( $remove_kws ) && is_array( $this->keyword_links ) ) {
} elseif ( is_array( $remove_kws ) && is_array( $this->keyword_links ) ) {
$new_keyword_links = array();
foreach ( $this->keyword_links as $link_id => $link ) {
$lnk_kws = $link->keyword;
@ -853,7 +853,7 @@ class MainWP_Keyword_Links {
if ( 3 === (int) $clear_link->type ) {
$clear_link->type = 2;
$cleared = $this->set_link( $clear_link->id, $clear_link );
} else if ( 1 === (int) $clear_link->type ) {
} elseif ( 1 === (int) $clear_link->type ) {
$cleared = $this->set_link( $clear_link->id, '' ); // delete link
}
$this->update_htaccess_for_change_cloak_links( $clear_link );
@ -885,7 +885,7 @@ class MainWP_Keyword_Links {
}
$old = $this->get_link( $link_id );
$link = new stdClass;
$link = new stdClass();
$link->id = intval( $link_id );
$link->name = sanitize_text_field( $_POST['name'] );
$link->destination_url = esc_url( $_POST['destination_url'] );
@ -901,7 +901,7 @@ class MainWP_Keyword_Links {
if ( 2 === (int) $link->type || 3 === (int) $link->type ) {
if ( intval( $_POST['post_id'] ) ) {
$link->post_id = intval( $_POST['post_id'] );
} else if ( $old && $old->post_id ) {
} elseif ( $old && $old->post_id ) {
$link->post_id = $old->post_id;
}
if ( $link->post_id ) {

View file

@ -2,16 +2,16 @@
class MainWP_Security {
public static function fixAll() {
MainWP_Security::remove_wp_version();
MainWP_Security::remove_rsd();
MainWP_Security::remove_wlw();
// MainWP_Security::remove_core_update();
// MainWP_Security::remove_plugin_update();
// MainWP_Security::remove_theme_update();
MainWP_Security::remove_php_reporting();
MainWP_Security::remove_registered_versions();
MainWP_Security::remove_generator_version();
MainWP_Security::remove_readme();
self::remove_wp_version();
self::remove_rsd();
self::remove_wlw();
// MainWP_Security::remove_core_update();
// MainWP_Security::remove_plugin_update();
// MainWP_Security::remove_theme_update();
self::remove_php_reporting();
self::remove_registered_versions();
self::remove_generator_version();
self::remove_readme();
add_filter( 'style_loader_src', array( 'MainWP_Security', 'remove_script_versions' ), PHP_INT_MAX );
add_filter( 'style_loader_src', array( 'MainWP_Security', 'remove_theme_versions' ), PHP_INT_MAX );
@ -19,13 +19,13 @@ class MainWP_Security {
add_filter( 'script_loader_src', array( 'MainWP_Security', 'remove_theme_versions' ), PHP_INT_MAX );
}
//Prevent listing wp-content, wp-content/plugins, wp-content/themes, wp-content/uploads
// Prevent listing wp-content, wp-content/plugins, wp-content/themes, wp-content/uploads
private static $listingDirectories = null;
private static function init_listingDirectories() {
if ( null === MainWP_Security::$listingDirectories ) {
$wp_upload_dir = wp_upload_dir();
MainWP_Security::$listingDirectories = array(
if ( null === self::$listingDirectories ) {
$wp_upload_dir = wp_upload_dir();
self::$listingDirectories = array(
WP_CONTENT_DIR,
WP_PLUGIN_DIR,
get_theme_root(),
@ -35,8 +35,8 @@ class MainWP_Security {
}
public static function prevent_listing_ok() {
MainWP_Security::init_listingDirectories();
foreach ( MainWP_Security::$listingDirectories as $directory ) {
self::init_listingDirectories();
foreach ( self::$listingDirectories as $directory ) {
$file = $directory . DIRECTORY_SEPARATOR . 'index.php';
if ( ! file_exists( $file ) ) {
return false;
@ -47,8 +47,8 @@ class MainWP_Security {
}
public static function prevent_listing() {
MainWP_Security::init_listingDirectories();
foreach ( MainWP_Security::$listingDirectories as $directory ) {
self::init_listingDirectories();
foreach ( self::$listingDirectories as $directory ) {
$file = $directory . DIRECTORY_SEPARATOR . 'index.php';
if ( ! file_exists( $file ) ) {
$h = fopen( $file, 'w' );
@ -66,7 +66,7 @@ class MainWP_Security {
return ! empty( $security ) && isset( $security[ $option ] ) && ( true === $security[ $option ] );
}
//Removed wp-version
// Removed wp-version
public static function remove_wp_version_ok() {
return ! ( has_action( 'wp_head', 'wp_generator' ) || has_filter( 'wp_head', 'wp_generator' ) );
}
@ -78,7 +78,7 @@ class MainWP_Security {
}
}
//Removed Really Simple Discovery meta tag
// Removed Really Simple Discovery meta tag
public static function remove_rsd_ok() {
return ( ! has_action( 'wp_head', 'rsd_link' ) );
}
@ -89,7 +89,7 @@ class MainWP_Security {
}
}
//Removed Windows Live Writer meta tag
// Removed Windows Live Writer meta tag
public static function remove_wlw_ok() {
return ( ! has_action( 'wp_head', 'wlwmanifest_link' ) );
}
@ -100,132 +100,132 @@ class MainWP_Security {
}
}
//Removed core update information for non-admins
// public static function remove_core_update_ok()
// {
// return self::get_security_option('core_updates');
// }
// Removed core update information for non-admins
// public static function remove_core_update_ok()
// {
// return self::get_security_option('core_updates');
// }
// public static function remove_core_update($force = false)
// {
// if ($force || self::get_security_option('core_updates'))
// {
// if (!current_user_can('update_plugins'))
// {
// add_action('admin_init', create_function('$a', "remove_action( 'admin_notices', 'maintenance_nag' );"));
// add_action('admin_init', create_function('$a', "remove_action( 'admin_notices', 'update_nag', 3 );"));
// add_action('admin_init', create_function('$a', "remove_action( 'admin_init', '_maybe_update_core' );"));
// add_action('init', create_function('$a', "remove_action( 'init', 'wp_version_check' );"));
// add_filter('pre_option_update_core', create_function('$a', "return null;"));
// remove_action('wp_version_check', 'wp_version_check');
// remove_action('admin_init', '_maybe_update_core');
// add_filter('pre_transient_update_core', create_function('$a', "return null;"));
// add_filter('pre_site_transient_update_core', create_function('$a', "return null;"));
// }
// }
// }
// public static function remove_core_update($force = false)
// {
// if ($force || self::get_security_option('core_updates'))
// {
// if (!current_user_can('update_plugins'))
// {
// add_action('admin_init', create_function('$a', "remove_action( 'admin_notices', 'maintenance_nag' );"));
// add_action('admin_init', create_function('$a', "remove_action( 'admin_notices', 'update_nag', 3 );"));
// add_action('admin_init', create_function('$a', "remove_action( 'admin_init', '_maybe_update_core' );"));
// add_action('init', create_function('$a', "remove_action( 'init', 'wp_version_check' );"));
// add_filter('pre_option_update_core', create_function('$a', "return null;"));
// remove_action('wp_version_check', 'wp_version_check');
// remove_action('admin_init', '_maybe_update_core');
// add_filter('pre_transient_update_core', create_function('$a', "return null;"));
// add_filter('pre_site_transient_update_core', create_function('$a', "return null;"));
// }
// }
// }
//Removed plugin-update information for non-admins
// public static function remove_plugin_update_ok()
// {
// return self:get_security_option('plugin_updates');
// }
// Removed plugin-update information for non-admins
// public static function remove_plugin_update_ok()
// {
// return self:get_security_option('plugin_updates');
// }
// public static function remove_plugin_update($force = false)
// {
// if ($force || self::get_security_option('plugin_updates'))
// {
// if (!current_user_can('update_plugins'))
// {
// add_action('admin_init', create_function('$a', "remove_action( 'admin_init', 'wp_plugin_update_rows' );"), 2);
// add_action('admin_init', create_function('$a', "remove_action( 'admin_init', '_maybe_update_plugins' );"), 2);
// add_action('admin_menu', create_function('$a', "remove_action( 'load-plugins.php', 'wp_update_plugins' );"));
// add_action('admin_init', create_function('$a', "remove_action( 'admin_init', 'wp_update_plugins' );"), 2);
// add_action('init', create_function('$a', "remove_action( 'init', 'wp_update_plugins' );"), 2);
// add_filter('pre_option_update_plugins', create_function('$a', "return null;"));
// remove_action('load-plugins.php', 'wp_update_plugins');
// remove_action('load-update.php', 'wp_update_plugins');
// remove_action('admin_init', '_maybe_update_plugins');
// remove_action('wp_update_plugins', 'wp_update_plugins');
// remove_action('load-update-core.php', 'wp_update_plugins');
// add_filter('pre_transient_update_plugins', create_function('$a', "return null;"));
// }
// }
// }
// public static function remove_plugin_update($force = false)
// {
// if ($force || self::get_security_option('plugin_updates'))
// {
// if (!current_user_can('update_plugins'))
// {
// add_action('admin_init', create_function('$a', "remove_action( 'admin_init', 'wp_plugin_update_rows' );"), 2);
// add_action('admin_init', create_function('$a', "remove_action( 'admin_init', '_maybe_update_plugins' );"), 2);
// add_action('admin_menu', create_function('$a', "remove_action( 'load-plugins.php', 'wp_update_plugins' );"));
// add_action('admin_init', create_function('$a', "remove_action( 'admin_init', 'wp_update_plugins' );"), 2);
// add_action('init', create_function('$a', "remove_action( 'init', 'wp_update_plugins' );"), 2);
// add_filter('pre_option_update_plugins', create_function('$a', "return null;"));
// remove_action('load-plugins.php', 'wp_update_plugins');
// remove_action('load-update.php', 'wp_update_plugins');
// remove_action('admin_init', '_maybe_update_plugins');
// remove_action('wp_update_plugins', 'wp_update_plugins');
// remove_action('load-update-core.php', 'wp_update_plugins');
// add_filter('pre_transient_update_plugins', create_function('$a', "return null;"));
// }
// }
// }
//Removed theme-update information for non-admins
// public static function remove_theme_update_ok()
// {
// return self::get_security_option('theme_updates');
// }
// Removed theme-update information for non-admins
// public static function remove_theme_update_ok()
// {
// return self::get_security_option('theme_updates');
// }
// public static function remove_theme_update($force = false)
// {
// if ($force || self::get_security_option('theme_updates'))
// {
// if (!current_user_can('edit_themes'))
// {
// remove_action('load-themes.php', 'wp_update_themes');
// remove_action('load-update.php', 'wp_update_themes');
// remove_action('admin_init', '_maybe_update_themes');
// remove_action('wp_update_themes', 'wp_update_themes');
// remove_action('load-update-core.php', 'wp_update_themes');
// add_filter('pre_transient_update_themes', create_function('$a', "return null;"));
// }
// }
// }
// public static function remove_theme_update($force = false)
// {
// if ($force || self::get_security_option('theme_updates'))
// {
// if (!current_user_can('edit_themes'))
// {
// remove_action('load-themes.php', 'wp_update_themes');
// remove_action('load-update.php', 'wp_update_themes');
// remove_action('admin_init', '_maybe_update_themes');
// remove_action('wp_update_themes', 'wp_update_themes');
// remove_action('load-update-core.php', 'wp_update_themes');
// add_filter('pre_transient_update_themes', create_function('$a', "return null;"));
// }
// }
// }
//File permissions not secure
// File permissions not secure
private static $permission_checks = null;
private static function init_permission_checks() {
if ( null === MainWP_Security::$permission_checks ) {
MainWP_Security::$permission_checks = array(
WP_CONTENT_DIR . DIRECTORY_SEPARATOR . '../' => '0755',
if ( null === self::$permission_checks ) {
self::$permission_checks = array(
WP_CONTENT_DIR . DIRECTORY_SEPARATOR . '../' => '0755',
WP_CONTENT_DIR . DIRECTORY_SEPARATOR . '../wp-includes' => '0755',
WP_CONTENT_DIR . DIRECTORY_SEPARATOR . '../.htaccess' => '0644',
WP_CONTENT_DIR . DIRECTORY_SEPARATOR . 'index.php' => '0644',
WP_CONTENT_DIR . DIRECTORY_SEPARATOR . 'js/' => '0755',
WP_CONTENT_DIR . DIRECTORY_SEPARATOR . 'themes' => '0755',
WP_CONTENT_DIR . DIRECTORY_SEPARATOR . 'plugins' => '0755',
WP_CONTENT_DIR . DIRECTORY_SEPARATOR . '../wp-admin' => '0755',
WP_CONTENT_DIR => '0755',
WP_CONTENT_DIR . DIRECTORY_SEPARATOR . '../.htaccess' => '0644',
WP_CONTENT_DIR . DIRECTORY_SEPARATOR . 'index.php' => '0644',
WP_CONTENT_DIR . DIRECTORY_SEPARATOR . 'js/' => '0755',
WP_CONTENT_DIR . DIRECTORY_SEPARATOR . 'themes' => '0755',
WP_CONTENT_DIR . DIRECTORY_SEPARATOR . 'plugins' => '0755',
WP_CONTENT_DIR . DIRECTORY_SEPARATOR . '../wp-admin' => '0755',
WP_CONTENT_DIR => '0755',
);
}
}
// public static function fix_file_permissions_ok()
// {
// MainWP_Security::init_permission_checks();
// public static function fix_file_permissions_ok()
// {
// MainWP_Security::init_permission_checks();
//
// $perms_issues = 0;
// $perms_issues = 0;
//
// foreach (MainWP_Security::$permission_checks as $dir => $needed_perms)
// {
// if (!file_exists($dir)) continue;
// foreach (MainWP_Security::$permission_checks as $dir => $needed_perms)
// {
// if (!file_exists($dir)) continue;
//
// $perms = substr(sprintf('%o', fileperms($dir)), -4);
// if ($perms != $needed_perms)
// {
// $perms_issues++;
// }
// }
// return ($perms_issues == 0);
// }
// $perms = substr(sprintf('%o', fileperms($dir)), -4);
// if ($perms != $needed_perms)
// {
// $perms_issues++;
// }
// }
// return ($perms_issues == 0);
// }
// public static function fix_file_permissions()
// {
// MainWP_Security::init_permission_checks();
// $success = true;
// foreach (MainWP_Security::$permission_checks as $dir => $needed_perms)
// {
// if (!file_exists($dir)) continue;
// $success == $success && chmod($dir, $needed_perms);
// }
// return $success;
// }
// public static function fix_file_permissions()
// {
// MainWP_Security::init_permission_checks();
// $success = true;
// foreach (MainWP_Security::$permission_checks as $dir => $needed_perms)
// {
// if (!file_exists($dir)) continue;
// $success == $success && chmod($dir, $needed_perms);
// }
// return $success;
// }
//Database error reporting turned on/off
// Database error reporting turned on/off
public static function remove_database_reporting_ok() {
global $wpdb;
@ -239,7 +239,7 @@ class MainWP_Security {
$wpdb->suppress_errors();
}
//PHP error reporting turned on/off
// PHP error reporting turned on/off
public static function remove_php_reporting_ok() {
return ! ( ( ( 0 != ini_get( 'display_errors' ) ) && ( 'off' != ini_get( 'display_errors' ) ) ) || ( ( 0 != ini_get( 'display_startup_errors' ) ) && ( 'off' != ini_get( 'display_startup_errors' ) ) ) );
}
@ -252,7 +252,7 @@ class MainWP_Security {
}
}
//Removed version information for scripts/stylesheets
// Removed version information for scripts/stylesheets
public static function remove_scripts_version_ok() {
return self::get_security_option( 'scripts_version' );
}
@ -275,7 +275,7 @@ class MainWP_Security {
public static function remove_registered_versions() {
if ( self::get_security_option( 'registered_versions' ) ) {
global $wp_styles;
if ( $wp_styles instanceof WP_Styles ) {
if ( $wp_styles instanceof WP_Styles ) {
foreach ( $wp_styles->registered as $handle => $style ) {
$wp_styles->registered[ $handle ]->ver = null;
}
@ -320,8 +320,9 @@ class MainWP_Security {
public static function remove_readme( $force = false ) {
// to prevent remove readme.html file on WPE hosts
if ( MainWP_Helper::is_wp_engine() )
if ( MainWP_Helper::is_wp_engine() ) {
return true;
}
if ( $force || self::get_security_option( 'readme' ) ) {
if ( @file_exists( ABSPATH . 'readme.html' ) ) {
@ -348,10 +349,12 @@ class MainWP_Security {
return self::get_security_option( 'styles_version' );
}
//Admin user name is not admin
// Admin user name is not admin
public static function admin_user_ok() {
$user = get_user_by( 'login', 'admin' );
if ( ! $user ) return true;
if ( ! $user ) {
return true;
}
if ( 10 !== $user->wp_user_level && ( ! isset( $user->user_level ) || 10 !== $user->user_level ) && ! user_can( $user, 'level_10' ) ) {
return true;
@ -362,8 +365,9 @@ class MainWP_Security {
public static function update_security_option( $key, $value ) {
$security = get_option( 'mainwp_security' );
if ( !empty($key) )
$security[$key] = $value;
if ( ! empty($key) ) {
$security[ $key ] = $value;
}
MainWP_Helper::update_option( 'mainwp_security', $security, 'yes' );
}
}

View file

@ -15,5 +15,5 @@ class MainWP_Tools {
$return['result'] = $output;
}
return $return;
}
}
}
}

View file

@ -19,11 +19,11 @@ class MainWP_Wordpress_SEO {
public static $instance = null;
static function Instance() {
if ( null === MainWP_Wordpress_SEO::$instance ) {
MainWP_Wordpress_SEO::$instance = new MainWP_Wordpress_SEO();
if ( null === self::$instance ) {
self::$instance = new MainWP_Wordpress_SEO();
}
return MainWP_Wordpress_SEO::$instance;
return self::$instance;
}
public function __construct() {
@ -58,7 +58,7 @@ class MainWP_Wordpress_SEO {
$file_url = base64_decode( $_POST['file_url'] );
$temporary_file = '';
try {
include_once( ABSPATH . 'wp-admin/includes/file.php' ); //Contains download_url
include_once ABSPATH . 'wp-admin/includes/file.php'; // Contains download_url
$temporary_file = download_url( $file_url );
if ( is_wp_error( $temporary_file ) ) {
@ -78,7 +78,7 @@ class MainWP_Wordpress_SEO {
unlink( $temporary_file );
}
} else if ( isset( $_POST['settings'] ) ) {
} elseif ( isset( $_POST['settings'] ) ) {
try {
$settings = base64_decode( $_POST['settings'] );
// @codingStandardsIgnoreLine
@ -86,24 +86,24 @@ class MainWP_Wordpress_SEO {
if ( is_array( $options ) && array() !== $options ) {
$old_wpseo_version = null;
if ( isset( $options['wpseo']['version'] ) && '' !== $options['wpseo']['version'] ) {
$old_wpseo_version = $options['wpseo']['version'];
}
foreach ( $options as $name => $optgroup ) {
if ( 'wpseo_taxonomy_meta' === $name ) {
$optgroup = json_decode( urldecode( $optgroup['wpseo_taxonomy_meta'] ), true );
}
// Make sure that the imported options are cleaned/converted on import
$option_instance = WPSEO_Options::get_option_instance( $name );
if ( is_object( $option_instance ) && method_exists( $option_instance, 'import' ) ) {
$optgroup = $option_instance->import( $optgroup, $old_wpseo_version, $options );
}
}
if ( isset( $options['wpseo']['version'] ) && '' !== $options['wpseo']['version'] ) {
$old_wpseo_version = $options['wpseo']['version'];
}
foreach ( $options as $name => $optgroup ) {
if ( 'wpseo_taxonomy_meta' === $name ) {
$optgroup = json_decode( urldecode( $optgroup['wpseo_taxonomy_meta'] ), true );
}
// Make sure that the imported options are cleaned/converted on import
$option_instance = WPSEO_Options::get_option_instance( $name );
if ( is_object( $option_instance ) && method_exists( $option_instance, 'import' ) ) {
$optgroup = $option_instance->import( $optgroup, $old_wpseo_version, $options );
}
}
$information['success'] = true;
} else {
throw new Exception( __( 'Settings could not be imported:', 'wordpress-seo' ) );
}
} else {
throw new Exception( __( 'Settings could not be imported:', 'wordpress-seo' ) );
}
} catch ( Exception $e ) {
$information['error'] = $e->getMessage();
}
@ -175,12 +175,10 @@ class MainWP_Wordpress_SEO {
$rank = new WPSEO_Rank( WPSEO_Rank::NO_INDEX );
$title = __( 'Post is set to noindex.', 'wordpress-seo' );
WPSEO_Meta::set_value( 'linkdex', 0, $post_id );
}
elseif ( '' === WPSEO_Meta::get_value( 'focuskw', $post_id ) ) {
} elseif ( '' === WPSEO_Meta::get_value( 'focuskw', $post_id ) ) {
$rank = new WPSEO_Rank( WPSEO_Rank::NO_FOCUS );
$title = __( 'Focus keyword not set.', 'wordpress-seo' );
}
else {
} else {
$score = (int) WPSEO_Meta::get_value( 'linkdex', $post_id );
$rank = WPSEO_Rank::from_numeric_score( $score );
$title = $rank->get_label();
@ -192,7 +190,7 @@ class MainWP_Wordpress_SEO {
// from wordpress-seo plugin
public function parse_column_score_readability( $post_id ) {
$score = (int) WPSEO_Meta::get_value( 'content_score', $post_id );
$rank = WPSEO_Rank::from_numeric_score( $score );
$rank = WPSEO_Rank::from_numeric_score( $score );
return $this->render_score_indicator( $rank );
}

View file

@ -1,9 +1,9 @@
<?php
//todo: BZ2; support fseek!
// todo: BZ2; support fseek!
class Tar_Archiver {
const IDLE = 0;
const IDLE = 0;
const APPEND = 1;
const CREATE = 2;
@ -16,16 +16,16 @@ class Tar_Archiver {
protected $debug;
protected $chunk = ''; //1024 * 1024 * 4
protected $chunkSize = 4194304; //1024 * 1024 * 4
protected $chunk = ''; // 1024 * 1024 * 4
protected $chunkSize = 4194304; // 1024 * 1024 * 4
/** @var $backup MainWP_Backup */
protected $backup;
protected $type;
protected $pidFile; //filepath of pid file
protected $pidContent; //content of pid file
protected $pidUpdated; //last updated pid file
protected $pidFile; // filepath of pid file
protected $pidContent; // content of pid file
protected $pidUpdated; // last updated pid file
protected $mode = self::IDLE;
@ -127,19 +127,19 @@ class Tar_Archiver {
}
public function createFullBackup( $filepath, $excludes, $addConfig, $includeCoreFiles, $excludezip, $excludenonwp, $append = false ) {
//$this->logHandle = fopen($filepath . ".log", "a+");
// $this->logHandle = fopen($filepath . ".log", "a+");
$this->createPidFile( $filepath );
$this->excludeZip = $excludezip;
$this->archivePath = $filepath;
// if (!file_exists($filepath))
// {
// $this->limit = true;
// }
// if (!file_exists($filepath))
// {
// $this->limit = true;
// }
if ( $append && @file_exists( $filepath ) ) { //todo: use wpFS
if ( $append && @file_exists( $filepath ) ) { // todo: use wpFS
$this->mode = self::APPEND;
$this->prepareAppend( $filepath );
} else {
@ -176,7 +176,7 @@ class Tar_Archiver {
foreach ( $nodes as $key => $node ) {
if ( MainWP_Helper::startsWith( $node, ABSPATH . WPINC ) ) {
unset( $nodes[ $key ] );
} else if ( MainWP_Helper::startsWith( $node, ABSPATH . basename( admin_url( '' ) ) ) ) {
} elseif ( MainWP_Helper::startsWith( $node, ABSPATH . basename( admin_url( '' ) ) ) ) {
unset( $nodes[ $key ] );
} else {
foreach ( $coreFiles as $coreFile ) {
@ -209,7 +209,7 @@ class Tar_Archiver {
if ( ! MainWP_Helper::inExcludes( $excludes, str_replace( ABSPATH, '', $node ) ) ) {
if ( is_dir( $node ) ) {
$this->addDir( $node, $excludes );
} else if ( is_file( $node ) ) {
} elseif ( is_file( $node ) ) {
$this->addFile( $node, str_replace( ABSPATH, '', $node ) );
}
}
@ -250,14 +250,14 @@ class Tar_Archiver {
'home' => get_option( 'home' ),
'abspath' => ABSPATH,
'prefix' => $wpdb->prefix,
'lang' => get_bloginfo("language"),
'lang' => get_bloginfo('language'),
'plugins' => $plugins,
'themes' => $themes,
) ) );
// $configFile = dirname($filepath) . DIRECTORY_SEPARATOR . time() . 'config.txt';
// $fh = fopen($filepath, 'w'); //or error;
// dirname($filepath) . DIRECTORY_SEPARATOR
// $configFile = dirname($filepath) . DIRECTORY_SEPARATOR . time() . 'config.txt';
// $fh = fopen($filepath, 'w'); //or error;
// dirname($filepath) . DIRECTORY_SEPARATOR
$this->addEmptyDirectory( 'clone', 0, 0, 0, time() );
$this->addFileFromString( 'clone/config.txt', $string );
}
@ -328,12 +328,12 @@ class Tar_Archiver {
}
if ( 'tar.gz' == $this->type ) {
//if (@fwrite($this->archive, $data, strlen($data)) === false)
// if (@fwrite($this->archive, $data, strlen($data)) === false)
if ( false === @gzwrite( $this->archive, $data, strlen( $data ) ) ) {
throw new Exception( 'Could not write to archive' );
}
//@fflush($this->archive);
} else if ( 'tar.bz2' == $this->type ) {
// @fflush($this->archive);
} elseif ( 'tar.bz2' == $this->type ) {
if ( false === @bzwrite( $this->archive, $data, strlen( $data ) ) ) {
throw new Exception( 'Could not write to archive' );
}
@ -351,12 +351,12 @@ class Tar_Archiver {
return;
}
// if ($this->cnt++ > 3)
// {
// $this->log('error?');
// $this->cnt = 0;
// throw new Exception('error!');
// }
// if ($this->cnt++ > 3)
// {
// $this->log('error?');
// $this->cnt = 0;
// throw new Exception('error!');
// }
if ( 'tar.gz' == $this->type ) {
$this->log( 'writing & flushing ' . $len );
@ -365,7 +365,7 @@ class Tar_Archiver {
throw new Exception( 'Could not write to archive' );
}
@fflush( $this->archive );
} else if ( 'tar.bz2' == $this->type ) {
} elseif ( 'tar.bz2' == $this->type ) {
if ( false === @bzwrite( $this->archive, $this->chunk, strlen( $len ) ) ) {
throw new Exception( 'Could not write to archive' );
}
@ -467,7 +467,7 @@ class Tar_Archiver {
protected $tempContent;
protected $gcCnt = 0;
// protected $limit;
// protected $limit;
protected $cnt = 0;
private function addFile( $path, $entryName ) {
@ -483,12 +483,12 @@ class Tar_Archiver {
$this->log( 'Adding ' . $path );
// if ($this->limit)
// {
// $this->cnt++;
// if ($this->limit)
// {
// $this->cnt++;
//
// if ($this->cnt > 250) throw new Exception('Some error..' . $this->archivePath);
// }
// if ($this->cnt > 250) throw new Exception('Some error..' . $this->archivePath);
// }
$this->updatePidFile();
@ -519,7 +519,7 @@ class Tar_Archiver {
$stat = @stat( $path );
$fp = @fopen( $path, 'rb' );
if ( ! $fp ) {
//todo: add some error feedback!
// todo: add some error feedback!
return;
}
@ -616,7 +616,7 @@ class Tar_Archiver {
}
while ( ! feof( $fp ) ) {
//0.1MB = 1024 000
// 0.1MB = 1024 000
$this->tempContent = fread( $fp, 1024000 * 5 );
$read = strlen( $this->tempContent );
@ -630,7 +630,7 @@ class Tar_Archiver {
$this->updatePidFile();
// if ($this->limit) throw new Exception('Some error..' . $entryName);
// if ($this->limit) throw new Exception('Some error..' . $entryName);
}
@fclose( $fp );
@ -725,14 +725,14 @@ class Tar_Archiver {
private function checkBeforeAppend( $entryName ) {
$rslt = $this->isNextFile( $entryName );
//Correct file
// Correct file
if ( true === $rslt ) {
return true;
}
$out = false;
//close, reopen with append & ftruncate
// close, reopen with append & ftruncate
$this->close( false );
$this->log( 'Reopen archive to append from here' );
$this->append( $this->archivePath );
@ -741,19 +741,19 @@ class Tar_Archiver {
$startOffset = $rslt['startOffset'];
@fseek( $this->archive, $startOffset );
@ftruncate( $this->archive, $startOffset );
} else if ( 'tar.gz' == $this->type ) {
} elseif ( 'tar.gz' == $this->type ) {
$readOffset = $rslt['readOffset'];
$bytesRead = $rslt['bytesRead'];
//@fseek($this->archive, $readOffset + $bytesRead);
// @fseek($this->archive, $readOffset + $bytesRead);
$out = array( 'bytesRead' => $bytesRead );
}
} else if ( false === $rslt ) {
} elseif ( false === $rslt ) {
if ( 'tar' == $this->type ) {
@fseek( $this->archive, 0, SEEK_END );
}
} else {
//todo: check for tar.gz & tar!
// todo: check for tar.gz & tar!
@fseek( $this->archive, $rslt );
@ftruncate( $this->archive, $rslt );
}
@ -790,7 +790,7 @@ class Tar_Archiver {
}
$temp = unpack( 'a100name/a8mode/a8uid/a8gid/a12size/a12mtime/a8checksum/a1type/a100symlink/a6magic/a2temp/a32temp/a32temp/a8temp/a8temp/a155prefix/a12temp', $block );
//Check for long file!!
// Check for long file!!
if ( 'L' == $temp['type'] ) {
$fname = trim( @fread( $this->archive, 512 ) );
$block = @fread( $this->archive, 512 );
@ -820,7 +820,7 @@ class Tar_Archiver {
} else {
throw new Exception( 'Unexpected directory [' . $file['name'] . ']' );
}
} else if ( 0 == $file['type'] ) {
} elseif ( 0 == $file['type'] ) {
if ( 0 == strcmp( trim( $file['name'] ), trim( $entryName ) ) ) {
$previousFtell = @ftell( $this->archive );
@ -843,14 +843,14 @@ class Tar_Archiver {
break;
}
$bytesRead += $bytesCurrentlyRead;
$bytesRead += $bytesCurrentlyRead;
$bytesToRead -= $bytesCurrentlyRead;
}
if ( 0 == $bytesToRead ) {
$toRead = ( 512 - $file['stat'][7] % 512 ) == 512 ? 0 : ( 512 - $file['stat'][7] % 512 );
if ( $toRead > 0 ) {
$read = strlen( fread( $this->archive, $toRead ) );
$read = strlen( fread( $this->archive, $toRead ) );
$bytesRead += $read;
}
}
@ -862,7 +862,7 @@ class Tar_Archiver {
return $rslt;
}
} else if ( ( 'tar' == $this->type ) && ( ( false === $ftell ) || ( -1 == $ftell ) ) ) {
} elseif ( ( 'tar' == $this->type ) && ( ( false === $ftell ) || ( -1 == $ftell ) ) ) {
$this->log( 'Will append this: ' . print_r( $rslt, 1 ) );
return $rslt;
@ -904,9 +904,9 @@ class Tar_Archiver {
}
if ( 'tar.gz' == $this->type ) {
//$this->archive = @fopen('compress.zlib://' . $filepath, 'ab');
// $this->archive = @fopen('compress.zlib://' . $filepath, 'ab');
$this->archive = @gzopen( $filepath, 'wb' );
} else if ( 'tar.bz2' == $this->type ) {
} elseif ( 'tar.bz2' == $this->type ) {
$this->archive = @bzopen( $filepath, 'w' );
} else {
$this->archive = @fopen( $filepath, 'wb+' );
@ -926,9 +926,9 @@ class Tar_Archiver {
}
if ( 'tar.gz' == $this->type ) {
//$this->archive = @fopen('compress.zlib://' . $filepath, 'ab');
// $this->archive = @fopen('compress.zlib://' . $filepath, 'ab');
$this->archive = @gzopen( $filepath, 'ab' );
} else if ( $this->type == 'tar.bz2' ) {
} elseif ( $this->type == 'tar.bz2' ) {
$this->archive = @bzopen( $filepath, 'a' );
} else {
$this->archive = @fopen( $filepath, 'ab+' );
@ -942,9 +942,9 @@ class Tar_Archiver {
function prepareAppend( $filepath ) {
if ( $this->debug ) {
if ( 'tar.gz' == substr( $filepath, - 6 ) ) {
$text = chr( 31 ) . chr( 139 ) . chr( 8 ) . chr( 0 ) . chr( 0 ) . chr( 0 ) . chr( 0 ) . chr( 0 ) . chr( 0 ); //magic header!!
$text = chr( 31 ) . chr( 139 ) . chr( 8 ) . chr( 0 ) . chr( 0 ) . chr( 0 ) . chr( 0 ) . chr( 0 ) . chr( 0 ); // magic header!!
//Check if valid, if not, crop to valid!
// Check if valid, if not, crop to valid!
$fh = @fopen( $filepath, 'rb' );
$read = '';
$lastCorrect = 0;
@ -961,7 +961,7 @@ class Tar_Archiver {
}
$lastCorrect += $pos;
$read = substr( $read, $pos );
$read = substr( $read, $pos );
}
}
@ -972,7 +972,7 @@ class Tar_Archiver {
@fclose( $fh );
} catch ( Exception $e ) {
@fclose( $fh );
//reopen & truncate
// reopen & truncate
$fh = @fopen( $filepath, 'ab+' );
@fseek( $fh, $lastCorrect );
@ftruncate( $fh, $lastCorrect );
@ -990,9 +990,9 @@ class Tar_Archiver {
if ( 'tar.gz' == substr( $filepath, - 6 ) ) {
$this->type = 'tar.gz';
// $this->archive = @fopen('compress.zlib://' . $filepath, 'rb');
// $this->archive = @fopen('compress.zlib://' . $filepath, 'rb');
$this->archive = @gzopen( $filepath, 'r' );
} else if ( 'tar.bz2' == substr( $filepath, - 7 ) ) {
} elseif ( 'tar.bz2' == substr( $filepath, - 7 ) ) {
$this->type = 'tar.bz2';
$this->archive = @bzopen( $filepath, 'r' );
} else {
@ -1009,7 +1009,7 @@ class Tar_Archiver {
}
function close( $closeLog = true ) {
//Write chunk if it's not empty..
// Write chunk if it's not empty..
$this->writeChunk();
$this->log( 'Closing archive' );
@ -1020,9 +1020,9 @@ class Tar_Archiver {
if ( $this->archive ) {
if ( 'tar.gz' == $this->type ) {
//@fclose($this->archive);
// @fclose($this->archive);
@gzclose( $this->archive );
} else if ( 'tar.bz2' == $this->type ) {
} elseif ( 'tar.bz2' == $this->type ) {
@bzclose( $this->archive );
} else {
@fclose( $this->archive );
@ -1041,7 +1041,7 @@ class Tar_Archiver {
@fseek( $this->archive, 0 );
while ( $block = @fread( $this->archive, 512 ) ) {
$temp = unpack( 'a100name/a8mode/a8uid/a8gid/a12size/a12mtime/a8checksum/a1type/a100symlink/a6magic/a2temp/a32temp/a32temp/a8temp/a8temp/a155prefix/a12temp', $block );
//Check for long file!!
// Check for long file!!
if ( 'L' == $temp['type'] ) {
$fname = trim( @fread( $this->archive, 512 ) );
$block = @fread( $this->archive, 512 );
@ -1065,8 +1065,8 @@ class Tar_Archiver {
if ( $file['checksum'] == 0x00000000 ) {
break;
} else if ( substr( $file['magic'], 0, 5 ) != 'ustar' ) {
// $this->error[] = "This script does not support extracting this type of tar file.";
} elseif ( substr( $file['magic'], 0, 5 ) != 'ustar' ) {
// $this->error[] = "This script does not support extracting this type of tar file.";
break;
}
@ -1075,8 +1075,8 @@ class Tar_Archiver {
for ( $i = 0; $i < 512; $i ++ ) {
$checksum += ord( substr( $block, $i, 1 ) );
}
// if ($file['checksum'] != $checksum)
// $this->error[] = "Could not extract from {$this->options['name']}, it is corrupt.";
// if ($file['checksum'] != $checksum)
// $this->error[] = "Could not extract from {$this->options['name']}, it is corrupt.";
if ( 0 == $file['type'] ) {
if ( 0 == strcmp( trim( $file['name'] ), trim( $entryName ) ) ) {
@ -1110,7 +1110,7 @@ class Tar_Archiver {
@fseek( $this->archive, 0 );
while ( $block = @fread( $this->archive, 512 ) ) {
$temp = unpack( 'a100name/a8mode/a8uid/a8gid/a12size/a12mtime/a8checksum/a1type/a100symlink/a6magic/a2temp/a32temp/a32temp/a8temp/a8temp/a155prefix/a12temp', $block );
//Check for long file!!
// Check for long file!!
if ( 'L' == $temp['type'] ) {
$fname = trim( @fread( $this->archive, 512 ) );
$block = @fread( $this->archive, 512 );
@ -1134,8 +1134,8 @@ class Tar_Archiver {
if ( $file['checksum'] == 0x00000000 ) {
break;
} else if ( 'ustar' != substr( $file['magic'], 0, 5 ) ) {
// $this->error[] = "This script does not support extracting this type of tar file.";
} elseif ( 'ustar' != substr( $file['magic'], 0, 5 ) ) {
// $this->error[] = "This script does not support extracting this type of tar file.";
break;
}
@ -1144,14 +1144,14 @@ class Tar_Archiver {
for ( $i = 0; $i < 512; $i ++ ) {
$checksum += ord( substr( $block, $i, 1 ) );
}
// if ($file['checksum'] != $checksum)
// $this->error[] = "Could not extract from {$this->options['name']}, it is corrupt.";
// if ($file['checksum'] != $checksum)
// $this->error[] = "Could not extract from {$this->options['name']}, it is corrupt.";
if ( 5 == $file['type'] ) {
if ( 0 == strcmp( trim( $file['name'] ), trim( $entryName ) ) ) {
return true;
}
} else if ( 0 == $file['type'] ) {
} elseif ( 0 == $file['type'] ) {
if ( 0 == strcmp( trim( $file['name'] ), trim( $entryName ) ) ) {
return true;
} else {
@ -1174,7 +1174,7 @@ class Tar_Archiver {
@fseek( $this->archive, 0 );
while ( $block = fread( $this->archive, 512 ) ) {
$temp = unpack( 'a100name/a8mode/a8uid/a8gid/a12size/a12mtime/a8checksum/a1type/a100symlink/a6magic/a2temp/a32temp/a32temp/a8temp/a8temp/a155prefix/a12temp', $block );
//Check for long file!!
// Check for long file!!
if ( 'L' == $temp['type'] ) {
$fname = trim( @fread( $this->archive, 512 ) );
$block = @fread( $this->archive, 512 );
@ -1198,8 +1198,8 @@ class Tar_Archiver {
if ( $file['checksum'] == 0x00000000 ) {
break;
} else if ( 'ustar' != substr( $file['magic'], 0, 5 ) ) {
// $this->error[] = "This script does not support extracting this type of tar file.";
} elseif ( 'ustar' != substr( $file['magic'], 0, 5 ) ) {
// $this->error[] = "This script does not support extracting this type of tar file.";
break;
}
$block = substr_replace( $block, ' ', 148, 8 );
@ -1207,8 +1207,8 @@ class Tar_Archiver {
for ( $i = 0; $i < 512; $i ++ ) {
$checksum += ord( substr( $block, $i, 1 ) );
}
// if ($file['checksum'] != $checksum)
// $this->error[] = "Could not extract from {$this->options['name']}, it is corrupt.";
// if ($file['checksum'] != $checksum)
// $this->error[] = "Could not extract from {$this->options['name']}, it is corrupt.";
if ( 5 == $file['type'] ) {
if ( ! is_dir( $to . $file['name'] ) ) {
if ( ! empty( $wp_filesystem ) ) {
@ -1217,7 +1217,7 @@ class Tar_Archiver {
mkdir( $to . $file['name'], 0777, true );
}
}
} else if ( 0 == $file['type'] ) {
} elseif ( 0 == $file['type'] ) {
if ( ! is_dir( dirname( $to . $file['name'] ) ) ) {
if ( ! empty( $wp_filesystem ) ) {
$wp_filesystem->mkdir( dirname( $to . $file['name'] ), FS_CHMOD_DIR );
@ -1230,8 +1230,8 @@ class Tar_Archiver {
$contents = '';
$bytesToRead = $file['stat'][7];
while ( $bytesToRead > 0 ) {
$readNow = $bytesToRead > 1024 ? 1024 : $bytesToRead;
$contents .= fread( $this->archive, $readNow );
$readNow = $bytesToRead > 1024 ? 1024 : $bytesToRead;
$contents .= fread( $this->archive, $readNow );
$bytesToRead -= $readNow;
}
@ -1302,20 +1302,20 @@ if ( class_exists( 'SplHeap' ) ) {
$dirnameA = ( is_file( $pathA ) ? dirname( $pathA ) : $pathA );
$dirnameB = ( is_file( $pathB ) ? dirname( $pathB ) : $pathB );
//if both are in the same folder, first show the files, then the directories
// if both are in the same folder, first show the files, then the directories
if ( dirname( $pathA ) == dirname( $pathB ) ) {
if ( is_file( $pathA ) && ! is_file( $pathB ) ) {
return - 1;
} else if ( ! is_file( $pathA ) && is_file( $pathB ) ) {
} elseif ( ! is_file( $pathA ) && is_file( $pathB ) ) {
return 1;
}
return strcmp( $pathA, $pathB );
} else if ( $dirnameA == $dirnameB ) {
} elseif ( $dirnameA == $dirnameB ) {
return strcmp( $pathA, $pathB );
} else if ( MainWP_Helper::startsWith( $dirnameA, $dirnameB ) ) {
} elseif ( MainWP_Helper::startsWith( $dirnameA, $dirnameB ) ) {
return 1;
} else if ( MainWP_Helper::startsWith( $dirnameB, $dirnameA ) ) {
} elseif ( MainWP_Helper::startsWith( $dirnameB, $dirnameA ) ) {
return - 1;
} else {
$cmp = strcmp( $dirnameA, $dirnameB );

View file

@ -16,16 +16,15 @@
"issues": "https://github.com/mainwp/mainwp-child/issues",
"source": "https://github.com/mainwp/mainwp"
},
"require": {
"require": {
"composer/installers": "^1.6",
"php": ">=5.6|>=7.0"
},
"require-dev": {
"dealerdirect/phpcodesniffer-composer-installer": "^0.5",
"phpcompatibility/php-compatibility": "^9.0",
"phpunit/phpunit": "^6.5",
"wp-cli/wp-cli": "^2.0",
"wp-coding-standards/wpcs": "^2.2.0"
"phpunit/phpunit": "^9.0",
"wp-cli/wp-cli": "^2.0"
},
"autoload-dev": {
"classmap": [
@ -54,7 +53,7 @@
"prefer-stable": true,
"config": {
"platform": {
"php": "7.3"
"php": "7.4"
},
"preferred-install": "dist",
"sort-packages": true

76
composer.lock generated
View file

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "a964220680db8aa4990a65c395fc0bd6",
"content-hash": "56eb205466c5010b883f6f55fe6017ad",
"packages": [
{
"name": "composer/installers",
@ -132,50 +132,6 @@
}
],
"packages-dev": [
{
"name": "cweagans/composer-patches",
"version": "1.6.7",
"source": {
"type": "git",
"url": "https://github.com/cweagans/composer-patches.git",
"reference": "2e6f72a2ad8d59cd7e2b729f218bf42adb14f590"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/cweagans/composer-patches/zipball/2e6f72a2ad8d59cd7e2b729f218bf42adb14f590",
"reference": "2e6f72a2ad8d59cd7e2b729f218bf42adb14f590",
"shasum": ""
},
"require": {
"composer-plugin-api": "^1.0",
"php": ">=5.3.0"
},
"require-dev": {
"composer/composer": "~1.0",
"phpunit/phpunit": "~4.6"
},
"type": "composer-plugin",
"extra": {
"class": "cweagans\\Composer\\Patches"
},
"autoload": {
"psr-4": {
"cweagans\\Composer\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Cameron Eagans",
"email": "me@cweagans.net"
}
],
"description": "Provides a way to patch Composer packages.",
"time": "2019-08-29T20:11:49+00:00"
},
{
"name": "dealerdirect/phpcodesniffer-composer-installer",
"version": "v0.5.0",
@ -1923,16 +1879,16 @@
},
{
"name": "symfony/finder",
"version": "v5.0.4",
"version": "v5.0.5",
"source": {
"type": "git",
"url": "https://github.com/symfony/finder.git",
"reference": "4176e7cb846fe08f32518b7e0ed8462e2db8d9bb"
"reference": "6251f201187ca9d66f6b099d3de65d279e971138"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/finder/zipball/4176e7cb846fe08f32518b7e0ed8462e2db8d9bb",
"reference": "4176e7cb846fe08f32518b7e0ed8462e2db8d9bb",
"url": "https://api.github.com/repos/symfony/finder/zipball/6251f201187ca9d66f6b099d3de65d279e971138",
"reference": "6251f201187ca9d66f6b099d3de65d279e971138",
"shasum": ""
},
"require": {
@ -1968,7 +1924,7 @@
],
"description": "Symfony Finder Component",
"homepage": "https://symfony.com",
"time": "2020-01-04T14:08:26+00:00"
"time": "2020-02-14T07:43:07+00:00"
},
{
"name": "symfony/polyfill-ctype",
@ -2289,22 +2245,21 @@
},
{
"name": "wp-cli/wp-cli",
"version": "v2.4.0",
"version": "v2.4.1",
"source": {
"type": "git",
"url": "https://github.com/wp-cli/wp-cli.git",
"reference": "74c949c74708e3a88ad0add70f3236c8675dfd85"
"reference": "ceb18598e79befa9b2a37a51efbb34910628988b"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/wp-cli/wp-cli/zipball/74c949c74708e3a88ad0add70f3236c8675dfd85",
"reference": "74c949c74708e3a88ad0add70f3236c8675dfd85",
"url": "https://api.github.com/repos/wp-cli/wp-cli/zipball/ceb18598e79befa9b2a37a51efbb34910628988b",
"reference": "ceb18598e79befa9b2a37a51efbb34910628988b",
"shasum": ""
},
"require": {
"cweagans/composer-patches": "^1.6",
"ext-curl": "*",
"mustache/mustache": "~2.4",
"mustache/mustache": "~2.13",
"php": "^5.4 || ^7.0",
"rmccue/requests": "~1.6",
"symfony/finder": ">2.7",
@ -2331,11 +2286,6 @@
"extra": {
"branch-alias": {
"dev-master": "2.4.x-dev"
},
"patches": {
"mustache/mustache": {
"Avoid notices on PHP 7.4+": "https://patch-diff.githubusercontent.com/raw/bobthecow/mustache.php/pull/349.patch"
}
}
},
"autoload": {
@ -2353,7 +2303,7 @@
"cli",
"wordpress"
],
"time": "2019-11-12T15:26:05+00:00"
"time": "2020-02-18T08:15:37+00:00"
},
{
"name": "wp-coding-standards/wpcs",
@ -2402,7 +2352,7 @@
}
],
"aliases": [],
"minimum-stability": "stable",
"minimum-stability": "dev",
"stability-flags": [],
"prefer-stable": true,
"prefer-lowest": false,

View file

@ -8,9 +8,9 @@
Text Domain: mainwp-child
Version: 4.0.7
*/
include_once( ABSPATH . 'wp-includes' . DIRECTORY_SEPARATOR . 'version.php' ); //Version information from wordpress
require_once ABSPATH . 'wp-includes' . DIRECTORY_SEPARATOR . 'version.php'; // Version information from WordPress
define( 'MAINWP_DEBUG', FALSE );
define( 'MAINWP_DEBUG', false );
if ( ! defined( 'MAINWP_CHILD_FILE' ) ) {
define( 'MAINWP_CHILD_FILE', __FILE__ );
@ -25,7 +25,7 @@ function mainwp_child_autoload( $class_name ) {
$autoload_path = sprintf( '%sclass-%s.php', $autoload_dir, strtolower( str_replace( '_', '-', $class_name ) ) );
if ( file_exists( $autoload_path ) ) {
require_once( $autoload_path );
require_once $autoload_path;
}
}

73
phpcs.xml Normal file
View file

@ -0,0 +1,73 @@
<?xml version="1.0"?>
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="WordPress Coding Standards" xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/squizlabs/PHP_CodeSniffer/master/phpcs.xsd">
<description>The Coding standard for the MainWP Child plugin.</description>
<file>.</file>
<arg value="sp"/>
<arg name="extensions" value="php"/>
<arg name="basepath" value="."/>
<arg name="parallel" value="8"/>
<exclude-pattern>*/vendor/*</exclude-pattern>
<exclude-pattern>*/bin/*</exclude-pattern>
<exclude-pattern>*/.github/*</exclude-pattern>
<exclude-pattern>*/tests/*</exclude-pattern>
<rule ref="WordPress">
<exclude name="WordPress.Files.FileName"/>
<exclude name="WordPress.NamingConventions.ValidVariableName"/>
<exclude name="WordPress.CodeAnalysis.AssignmentInCondition.FoundInWhileCondition"/>
<!-- Disable Nonce verification due to large number of false positives. -->
<exclude name="WordPress.Security.NonceVerification"/>
<!-- Disable Escaping output check due to large number of false positives. -->
<exclude name="WordPress.Security.EscapeOutput"/>
<!-- Disable Strict comparison check. Not applicable in the mojority of cases. -->
<exclude name="WordPress.PHP.StrictComparisons"/>
<!-- Disable Strict comparison in array check. Not applicable in the mojority of cases. -->
<exclude name="WordPress.PHP.StrictInArray"/>
<exclude name="Generic.WhiteSpace.DisallowSpaceIndent"/>
<exclude name="Squiz.ControlStructures.ControlSignature"/>
</rule>
<!-- Enforce PSR1 compatible namespaces. -->
<rule ref="PSR1.Classes.ClassDeclaration"/>
<rule ref="WordPress.Arrays.MultipleStatementAlignment">
<properties>
<property name="alignMultilineItems" value="!=100"/>
<property name="exact" value="false" phpcs-only="true"/>
</properties>
</rule>
<rule ref="PSR2.Methods.FunctionClosingBrace"/>
<!-- Check code for cross-version PHP compatibility. -->
<config name="testVersion" value="5.4-"/>
<rule ref="PHPCompatibility">
<!-- Exclude PHP constants back-filled by PHPCS. -->
<exclude name="PHPCompatibility.Constants.NewConstants.t_finallyFound"/>
<exclude name="PHPCompatibility.Constants.NewConstants.t_yieldFound"/>
<exclude name="PHPCompatibility.Constants.NewConstants.t_ellipsisFound"/>
<exclude name="PHPCompatibility.Constants.NewConstants.t_powFound"/>
<exclude name="PHPCompatibility.Constants.NewConstants.t_pow_equalFound"/>
<exclude name="PHPCompatibility.Constants.NewConstants.t_spaceshipFound"/>
<exclude name="PHPCompatibility.Constants.NewConstants.t_coalesceFound"/>
<exclude name="PHPCompatibility.Constants.NewConstants.t_coalesce_equalFound"/>
<exclude name="PHPCompatibility.Constants.NewConstants.t_yield_fromFound"/>
</rule>
<rule ref="WordPress.NamingConventions.PrefixAllGlobals.DeprecatedWhitelistCommentFound">
<!-- False positive for whitelist comment recognition, but no use fixing this now
as the WPCS native whitelist comments are deprecated anyhow. -->
<exclude-pattern>/WordPress/AbstractClassRestrictionsSniff\.php$</exclude-pattern>
</rule>
</ruleset>

View file

@ -1,16 +0,0 @@
<?xml version="1.0"?>
<phpunit
bootstrap="tests/bootstrap.php"
backupGlobals="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
>
<testsuites>
<testsuite>
<directory prefix="test-" suffix=".php">./tests/</directory>
<exclude>./tests/test-sample.php</exclude>
</testsuite>
</testsuites>
</phpunit>