update
This commit is contained in:
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,607 @@
|
||||
<?php
|
||||
|
||||
if (!defined('WPVIVID_PLUGIN_DIR'))
|
||||
{
|
||||
die;
|
||||
}
|
||||
|
||||
class WPvivid_Restore_DB_WPDB_Method_2
|
||||
{
|
||||
public $max_allow_packet;
|
||||
public $skip_query=0;
|
||||
public $last_error='';
|
||||
public $last_log='';
|
||||
|
||||
public function connect_db()
|
||||
{
|
||||
global $wpdb;
|
||||
$wpdb->get_results('SET NAMES utf8mb4', ARRAY_A);
|
||||
$ret['result']=WPVIVID_SUCCESS;
|
||||
return $ret;
|
||||
}
|
||||
|
||||
public function get_last_error()
|
||||
{
|
||||
return $this->last_error;
|
||||
}
|
||||
|
||||
public function get_last_log()
|
||||
{
|
||||
return $this->last_log;
|
||||
}
|
||||
|
||||
public function test_db()
|
||||
{
|
||||
global $wpdb;
|
||||
|
||||
$test_table_new=uniqid('wpvivid_test_tables_');
|
||||
$columns='(test_id int primary key)';
|
||||
$test_table = $wpdb->get_results("CREATE TABLE IF NOT EXISTS $test_table_new $columns",ARRAY_A);
|
||||
|
||||
if ($test_table!==false)
|
||||
{
|
||||
$this->last_log='The test to create table succeeds.';
|
||||
$test_table = $wpdb->get_results("INSERT INTO $test_table_new (`test_id`) VALUES ('123')",ARRAY_A);
|
||||
if($test_table!==false)
|
||||
{
|
||||
$this->last_log='The test to insert into table succeeds.';
|
||||
$test_table = $wpdb->get_results("DROP TABLE IF EXISTS $test_table_new",ARRAY_A);
|
||||
if($test_table!==false)
|
||||
{
|
||||
$this->last_log='The test to drop table succeeds.';
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->last_error='Unable to drop table. The reason is '.$wpdb->last_error;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->last_error='Unable to insert into table. The reason is '.$wpdb->last_error;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
$this->last_error='Unable to create table. The reason is '.$wpdb->last_error;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function check_max_allow_packet($log)
|
||||
{
|
||||
$restore_task=get_option('wpvivid_restore_task',array());
|
||||
$restore_detail_options=$restore_task['restore_detail_options'];
|
||||
$max_allowed_packet=$restore_detail_options['max_allowed_packet'];
|
||||
$set_max_allowed_packet=$max_allowed_packet*1024*1024;
|
||||
|
||||
global $wpdb;
|
||||
$max_allowed_packet =$wpdb->get_var("SELECT @@session.max_allowed_packet");
|
||||
|
||||
if($max_allowed_packet!==null)
|
||||
{
|
||||
if($max_allowed_packet<$set_max_allowed_packet)
|
||||
{
|
||||
$query='set global max_allowed_packet='.$set_max_allowed_packet;
|
||||
$test=$wpdb->get_results($query);
|
||||
var_dump($test);
|
||||
$wpdb->db_connect();
|
||||
$max_allowed_packet =$wpdb->get_var("SELECT @@session.max_allowed_packet");
|
||||
$this->max_allow_packet=$max_allowed_packet;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->max_allow_packet=$max_allowed_packet;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->last_log='get max_allowed_packet failed.';
|
||||
$this->max_allow_packet=1048576;
|
||||
}
|
||||
}
|
||||
|
||||
public function get_max_allow_packet()
|
||||
{
|
||||
return $this->max_allow_packet;
|
||||
}
|
||||
|
||||
public function init_sql_mode()
|
||||
{
|
||||
global $wpdb;
|
||||
$res = $wpdb->get_var('SELECT @@SESSION.sql_mode');
|
||||
if($res===null)
|
||||
{
|
||||
$this->last_error='get sql_mode failed';
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
$sql_mod = $res;
|
||||
$temp_sql_mode = str_replace('NO_ENGINE_SUBSTITUTION','',$sql_mod);
|
||||
$temp_sql_mode = 'ALLOW_INVALID_DATES,NO_AUTO_VALUE_ON_ZERO,'.$temp_sql_mode;
|
||||
$wpdb->get_results('SET SESSION sql_mode = "'.$temp_sql_mode.'"',ARRAY_A);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public function set_skip_query($count)
|
||||
{
|
||||
$this->skip_query=$count;
|
||||
}
|
||||
|
||||
public function execute_sql($query)
|
||||
{
|
||||
if(preg_match('#SET TIME_ZONE=@OLD_TIME_ZONE#', $query))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if(preg_match('#SET SQL_MODE=@OLD_SQL_MODE#', $query))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if(preg_match('#SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS#', $query))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if(preg_match('#SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS#', $query))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if(preg_match('#SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT#', $query))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if(preg_match('#SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS#', $query))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if(preg_match('#SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION#', $query))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if(preg_match('#SET SQL_NOTES=@OLD_SQL_NOTES#', $query))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
global $wpdb;
|
||||
if ($wpdb->get_results($query)===false)
|
||||
{
|
||||
$this->last_error=$wpdb->last_error;
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public function query($sql,$output)
|
||||
{
|
||||
global $wpdb;
|
||||
return $wpdb->get_results($sql,$output);
|
||||
}
|
||||
|
||||
public function errorInfo()
|
||||
{
|
||||
global $wpdb;
|
||||
return $wpdb->last_error;
|
||||
}
|
||||
}
|
||||
|
||||
class WPvivid_Restore_DB_PDO_Mysql_Method_2
|
||||
{
|
||||
private $db;
|
||||
public $max_allow_packet;
|
||||
public $skip_query=0;
|
||||
public $last_error='';
|
||||
public $last_log='';
|
||||
|
||||
public function get_last_error()
|
||||
{
|
||||
return $this->last_error;
|
||||
}
|
||||
|
||||
public function get_last_log()
|
||||
{
|
||||
return $this->last_log;
|
||||
}
|
||||
|
||||
public function connect_db()
|
||||
{
|
||||
try
|
||||
{
|
||||
$res = explode(':',DB_HOST);
|
||||
$db_host = $res[0];
|
||||
$db_port = empty($res[1])?'':$res[1];
|
||||
if(!empty($db_port)) {
|
||||
$dsn='mysql:host=' . $db_host . ';port=' . $db_port . ';dbname=' . DB_NAME;
|
||||
}
|
||||
else{
|
||||
$dsn='mysql:host=' . $db_host . ';dbname=' . DB_NAME;
|
||||
}
|
||||
$this->db = null;
|
||||
$this->db=new PDO($dsn, DB_USER, DB_PASSWORD);
|
||||
$this->db->exec('SET NAMES utf8mb4');
|
||||
if(empty($this->db) || !$this->db)
|
||||
{
|
||||
if(class_exists('PDO'))
|
||||
{
|
||||
$extensions=get_loaded_extensions();
|
||||
if(array_search('pdo_mysql',$extensions))
|
||||
{
|
||||
$ret['result']=WPVIVID_FAILED;
|
||||
$ret['error']='The error establishing a database connection. Please check wp-config.php file and make sure the information is correct.';
|
||||
}
|
||||
else{
|
||||
$ret['result']=WPVIVID_FAILED;
|
||||
$ret['error']='The pdo_mysql extension is not detected. Please install the extension first or choose wpdb option for Database connection method.';
|
||||
}
|
||||
}
|
||||
else{
|
||||
$ret['result']=WPVIVID_FAILED;
|
||||
$ret['error']='The pdo_mysql extension is not detected. Please install the extension first or choose wpdb option for Database connection method.';
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$ret['result']=WPVIVID_SUCCESS;
|
||||
}
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
if(empty($this->db) || !$this->db)
|
||||
{
|
||||
if(class_exists('PDO'))
|
||||
{
|
||||
$extensions=get_loaded_extensions();
|
||||
if(array_search('pdo_mysql',$extensions))
|
||||
{
|
||||
$ret['result']=WPVIVID_FAILED;
|
||||
$ret['error']='The error establishing a database connection. Please check wp-config.php file and make sure the information is correct.';
|
||||
}
|
||||
else{
|
||||
$ret['result']=WPVIVID_FAILED;
|
||||
$ret['error']='The pdo_mysql extension is not detected. Please install the extension first or choose wpdb option for Database connection method.';
|
||||
}
|
||||
}
|
||||
else{
|
||||
$ret['result']=WPVIVID_FAILED;
|
||||
$ret['error']='The pdo_mysql extension is not detected. Please install the extension first or choose wpdb option for Database connection method.';
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$ret['result']=WPVIVID_FAILED;
|
||||
$ret['error']=$e->getMessage();
|
||||
}
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
public function test_db()
|
||||
{
|
||||
$test_table_new=uniqid('wpvivid_test_tables_');
|
||||
$columns='(test_id int primary key)';
|
||||
$test_table = $this->db->exec("CREATE TABLE IF NOT EXISTS $test_table_new $columns");
|
||||
|
||||
if ($test_table!==false)
|
||||
{
|
||||
$this->last_log='The test to create table succeeds.';
|
||||
|
||||
$test_table = $this->db->exec("INSERT INTO $test_table_new (`test_id`) VALUES ('123')");
|
||||
if($test_table!==false)
|
||||
{
|
||||
$this->last_log='The test to insert into table succeeds.';
|
||||
$test_table = $this->db->exec("DROP TABLE IF EXISTS $test_table_new");
|
||||
if($test_table!==false)
|
||||
{
|
||||
$this->last_log='The test to drop table succeeds.';
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
$error=$this->db->errorInfo();
|
||||
|
||||
$this->last_error='Unable to drop table. The reason is '.$error[2];
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$error=$this->db->errorInfo();
|
||||
$this->last_error='Unable to insert into table. The reason is '.$error[2];
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
$error=$this->db->errorInfo();
|
||||
$this->last_error='Unable to create table. The reason is '.$error[2];
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function check_max_allow_packet($log)
|
||||
{
|
||||
$restore_task=get_option('wpvivid_restore_task',array());
|
||||
$restore_detail_options=$restore_task['restore_detail_options'];
|
||||
$max_allowed_packet=$restore_detail_options['max_allowed_packet'];
|
||||
$set_max_allowed_packet=$max_allowed_packet*1024*1024;
|
||||
|
||||
try{
|
||||
$max_allowed_packet = $this->db->query("SELECT @@session.max_allowed_packet;");
|
||||
if($max_allowed_packet)
|
||||
{
|
||||
$max_allowed_packet = $max_allowed_packet -> fetchAll();
|
||||
|
||||
if(is_array($max_allowed_packet)&&isset($max_allowed_packet[0])&&isset($max_allowed_packet[0][0]))
|
||||
{
|
||||
if($max_allowed_packet[0][0]<$set_max_allowed_packet)
|
||||
{
|
||||
$query='set global max_allowed_packet='.$set_max_allowed_packet;
|
||||
$this->db->exec($query);
|
||||
$this->connect_db();
|
||||
$max_allowed_packet = $this->db->query("SELECT @@session.max_allowed_packet;");
|
||||
$max_allowed_packet = $max_allowed_packet -> fetchAll();
|
||||
if(is_array($max_allowed_packet)&&isset($max_allowed_packet[0])&&isset($max_allowed_packet[0][0]))
|
||||
{
|
||||
$this->max_allow_packet=$max_allowed_packet[0][0];
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->max_allow_packet=1048576;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->max_allow_packet=$max_allowed_packet[0][0];
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->last_log='get max_allowed_packet failed.';
|
||||
$this->max_allow_packet=1048576;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->last_log='get max_allowed_packet failed.';
|
||||
$this->max_allow_packet=1048576;
|
||||
}
|
||||
}
|
||||
catch (Exception $error)
|
||||
{
|
||||
$message = 'An exception has occurred. class: '.get_class($error).';msg: '.$error->getMessage().';code: '.$error->getCode().';line: '.$error->getLine().';in_file: '.$error->getFile().';';
|
||||
$log->WriteLog($message, 'warning');
|
||||
}
|
||||
}
|
||||
|
||||
public function get_max_allow_packet()
|
||||
{
|
||||
return $this->max_allow_packet;
|
||||
}
|
||||
|
||||
public function init_sql_mode()
|
||||
{
|
||||
$res = $this->db->query('SELECT @@SESSION.sql_mode') -> fetchAll();
|
||||
$sql_mod = $res[0][0];
|
||||
|
||||
$modes = explode( ',', $sql_mod );
|
||||
$modes = array_change_key_case( $modes, CASE_UPPER );
|
||||
|
||||
$incompatible_modes = array(
|
||||
'NO_ZERO_DATE',
|
||||
'ONLY_FULL_GROUP_BY',
|
||||
'STRICT_TRANS_TABLES',
|
||||
'STRICT_ALL_TABLES',
|
||||
'TRADITIONAL',
|
||||
);
|
||||
|
||||
$incompatible_modes = (array) apply_filters( 'incompatible_sql_modes', $incompatible_modes );
|
||||
|
||||
foreach ( $modes as $i => $mode ) {
|
||||
if ( in_array( $mode, $incompatible_modes ) ) {
|
||||
unset( $modes[ $i ] );
|
||||
}
|
||||
}
|
||||
|
||||
$sql_mod = implode( ',', $modes );
|
||||
|
||||
//$temp_sql_mode = str_replace('NO_ENGINE_SUBSTITUTION','',$sql_mod);
|
||||
//$temp_sql_mode = 'NO_AUTO_VALUE_ON_ZERO,'.$temp_sql_mode;
|
||||
$this->db->query('SET SESSION sql_mode = "'.$sql_mod.'"');
|
||||
return true;
|
||||
}
|
||||
|
||||
public function set_skip_query($count)
|
||||
{
|
||||
$this->skip_query=$count;
|
||||
}
|
||||
|
||||
public function execute_sql($query)
|
||||
{
|
||||
if($this->skip_query>10)
|
||||
{
|
||||
if(strlen($query)>$this->max_allow_packet)
|
||||
{
|
||||
$this->last_log='skip query size:'.size_format(strlen($query));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if(preg_match('#SET TIME_ZONE=@OLD_TIME_ZONE#', $query))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if(preg_match('#SET SQL_MODE=@OLD_SQL_MODE#', $query))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if(preg_match('#SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS#', $query))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if(preg_match('#SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS#', $query))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if(preg_match('#SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT#', $query))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if(preg_match('#SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS#', $query))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if(preg_match('#SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION#', $query))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if(preg_match('#SET SQL_NOTES=@OLD_SQL_NOTES#', $query))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($this->db->exec($query)===false)
|
||||
{
|
||||
$info=$this->db->errorInfo();
|
||||
|
||||
if($info[1] == 2006)
|
||||
{
|
||||
if(strlen($query)>$this->max_allow_packet)
|
||||
{
|
||||
$this->skip_query++;
|
||||
$this->last_error='max_allow_packet too small:'.size_format($this->max_allow_packet).' query size:'.size_format(strlen($query));
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->last_error='execute sql failed. The reason is '.$info[2];
|
||||
}
|
||||
$ret=$this->connect_db();
|
||||
if($ret['result']==WPVIVID_FAILED)
|
||||
{
|
||||
$this->last_log='reconnect failed';
|
||||
|
||||
}
|
||||
else {
|
||||
$this->last_log='reconnect succeed';
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->last_error='execute sql failed. The reason is '.$info[2];
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public function query($sql,$output)
|
||||
{
|
||||
$ret=$this->db->query($sql);
|
||||
if($ret===false)
|
||||
{
|
||||
$error=$this->db->errorInfo();
|
||||
$this->last_error=$error[1].' - '.$error[2];
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return $ret -> fetchAll();
|
||||
}
|
||||
}
|
||||
|
||||
public function errorInfo()
|
||||
{
|
||||
return $this->db->errorInfo();
|
||||
}
|
||||
}
|
||||
|
||||
class WPvivid_Restore_DB_Method_2
|
||||
{
|
||||
private $db;
|
||||
private $type;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$restore_task=get_option('wpvivid_restore_task',array());
|
||||
$restore_detail_options=$restore_task['restore_detail_options'];
|
||||
$db_connect_method=$restore_detail_options['db_connect_method'];
|
||||
if($db_connect_method === 'wpdb')
|
||||
{
|
||||
$this->db =new WPvivid_Restore_DB_WPDB_Method_2();
|
||||
$this->type='wpdb';
|
||||
}
|
||||
else{
|
||||
$this->db =new WPvivid_Restore_DB_PDO_Mysql_Method_2();
|
||||
$this->type='pdo_mysql';
|
||||
}
|
||||
}
|
||||
|
||||
public function get_last_error()
|
||||
{
|
||||
return $this->db->last_error;
|
||||
}
|
||||
|
||||
public function get_last_log()
|
||||
{
|
||||
return $this->db->last_log;
|
||||
}
|
||||
|
||||
public function get_type()
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
public function connect_db()
|
||||
{
|
||||
return $this->db->connect_db();
|
||||
}
|
||||
|
||||
public function test_db()
|
||||
{
|
||||
return $this->db->test_db();
|
||||
}
|
||||
|
||||
public function check_max_allow_packet($log)
|
||||
{
|
||||
$this->db->check_max_allow_packet($log);
|
||||
}
|
||||
|
||||
public function get_max_allow_packet()
|
||||
{
|
||||
return $this->db->get_max_allow_packet();
|
||||
}
|
||||
|
||||
public function init_sql_mode()
|
||||
{
|
||||
$this->db->init_sql_mode();
|
||||
}
|
||||
|
||||
public function set_skip_query($count)
|
||||
{
|
||||
$this->db->set_skip_query($count);
|
||||
}
|
||||
|
||||
public function execute_sql($query)
|
||||
{
|
||||
return $this->db->execute_sql($query);
|
||||
}
|
||||
|
||||
public function query($sql,$output=ARRAY_A)
|
||||
{
|
||||
return $this->db->query($sql,$output);
|
||||
}
|
||||
|
||||
public function errorInfo()
|
||||
{
|
||||
return $this->db->errorInfo();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,768 @@
|
||||
<?php
|
||||
|
||||
if (!defined('WPVIVID_PLUGIN_DIR'))
|
||||
{
|
||||
die;
|
||||
}
|
||||
|
||||
class WPvivid_Restore_File_2
|
||||
{
|
||||
public $log;
|
||||
|
||||
public function __construct($log=false)
|
||||
{
|
||||
$this->log=$log;
|
||||
}
|
||||
|
||||
public function restore($sub_task,$backup_id)
|
||||
{
|
||||
if($sub_task['type']=='wp-core')
|
||||
{
|
||||
return $this->restore_core($sub_task,$backup_id);
|
||||
}
|
||||
|
||||
$files=$sub_task['unzip_file']['files'];
|
||||
$GLOBALS['wpvivid_restore_addon_type'] =$sub_task['type'];
|
||||
//restore_reset
|
||||
|
||||
foreach ($files as $index=>$file)
|
||||
{
|
||||
if($file['finished']==1)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$sub_task['unzip_file']['last_action']='Unzipping';
|
||||
$sub_task['unzip_file']['last_unzip_file']=$file['file_name'];
|
||||
$sub_task['last_msg']='<span><strong>Extracting file:</strong></span><span>'.$file['file_name'].'</span>';
|
||||
$this->update_sub_task($sub_task);
|
||||
|
||||
$backup = WPvivid_Backuplist::get_backup_by_id($backup_id);
|
||||
$backup_item = new WPvivid_Backup_Item($backup);
|
||||
|
||||
$extract_child_finished=isset($file['extract_child_finished'])?$file['extract_child_finished']:0;
|
||||
|
||||
if(isset($file['has_child'])&&$extract_child_finished==0)
|
||||
{
|
||||
$sub_task['unzip_file']['last_action']='Unzipping';
|
||||
$sub_task['unzip_file']['last_unzip_file']=$file['parent_file'];
|
||||
$sub_task['unzip_file']['last_unzip_file_index']=0;
|
||||
$sub_task['last_msg']='<span><strong>Extracting file:</strong></span><span>'.$file['parent_file'].'</span>';
|
||||
$this->update_sub_task($sub_task);
|
||||
|
||||
$root_path=$backup_item->get_local_path();
|
||||
|
||||
if(!file_exists($root_path))
|
||||
{
|
||||
@mkdir($root_path);
|
||||
}
|
||||
$this->log->WriteLog('Extracting file:'.$file['parent_file'],'notice');
|
||||
$extract_files[]=$file['file_name'];
|
||||
$ret=$this->extract_ex($root_path.$file['parent_file'],$extract_files,untrailingslashit($root_path),$sub_task['options']);
|
||||
if($ret['result']!='success')
|
||||
{
|
||||
return $ret;
|
||||
}
|
||||
$this->log->WriteLog('Extracting file:'.$file['parent_file'].' succeeded.','notice');
|
||||
$file_name=$root_path.$file['file_name'];
|
||||
$sub_task['unzip_file']['files'][$index]['extract_child_finished']=1;
|
||||
$sub_task['last_msg']='<span><strong>Extracting file:</strong></span><span>'.$file['parent_file'].' completed.</span>';
|
||||
$this->update_sub_task($sub_task);
|
||||
}
|
||||
else
|
||||
{
|
||||
$root_path=$backup_item->get_local_path();
|
||||
$file_name=$root_path.$file['file_name'];
|
||||
}
|
||||
|
||||
|
||||
$root_path = '';
|
||||
if (isset($file['options']['root']))
|
||||
{
|
||||
$root_path = $this->transfer_path(get_home_path() . $file['options']['root']);
|
||||
}
|
||||
else if (isset($file['options']['root_flag']))
|
||||
{
|
||||
if ($file['options']['root_flag'] == WPVIVID_BACKUP_ROOT_WP_CONTENT)
|
||||
{
|
||||
$root_path = $this->transfer_path(WP_CONTENT_DIR);
|
||||
}
|
||||
else if ($file['options']['root_flag'] == WPVIVID_BACKUP_ROOT_CUSTOM)
|
||||
{
|
||||
$root_path = $this->transfer_path(WP_CONTENT_DIR . DIRECTORY_SEPARATOR . WPvivid_Setting::get_backupdir());
|
||||
}
|
||||
else if ($file['options']['root_flag'] == WPVIVID_BACKUP_ROOT_WP_ROOT)
|
||||
{
|
||||
$root_path = $this->transfer_path(ABSPATH);
|
||||
}
|
||||
else if($file['options']['root_flag'] == WPVIVID_BACKUP_ROOT_WP_UPLOADS)
|
||||
{
|
||||
$upload_dir = wp_upload_dir();
|
||||
$upload_path = $upload_dir['basedir'];
|
||||
|
||||
$root_path = $this->transfer_path($upload_path);
|
||||
}
|
||||
}
|
||||
|
||||
if($sub_task['restore_reset'])
|
||||
{
|
||||
if($sub_task['restore_reset_finished']===false)
|
||||
{
|
||||
$sub_task['unzip_file']['last_action']='Unzipping';
|
||||
$sub_task['last_msg']='<span>Cleaning folder:</span><span>'.$sub_task['type'].'</span>';
|
||||
$this->update_sub_task($sub_task);
|
||||
$this->log->WriteLog('Cleaning folder:'.$sub_task['type'],'notice');
|
||||
$this->reset_restore($sub_task['type']);
|
||||
$sub_task['restore_reset_finished']=true;
|
||||
$sub_task['unzip_file']['last_action']='Unzipping';
|
||||
$sub_task['last_msg']='<span>Cleaning folder:</span><span>'.$sub_task['type'].' completed.</span>';
|
||||
$this->update_sub_task($sub_task);
|
||||
}
|
||||
}
|
||||
|
||||
$root_path = rtrim($root_path, '/');
|
||||
$root_path = rtrim($root_path, DIRECTORY_SEPARATOR);
|
||||
|
||||
$restore_task=get_option('wpvivid_restore_task',array());
|
||||
$restore_detail_options=$restore_task['restore_detail_options'];
|
||||
$unzip_files_pre_request=$restore_detail_options['unzip_files_pre_request'];
|
||||
$use_index=$restore_detail_options['use_index'];
|
||||
if($use_index==false)
|
||||
{
|
||||
$sub_task['last_msg']='<span><strong>Extracting file:</strong></span><span>'.$file['file_name'].'</span>';
|
||||
$sub_task['unzip_file']['last_action']='Unzipping';
|
||||
$sub_task['unzip_file']['last_unzip_file']=$file['file_name'];
|
||||
$sub_task['unzip_file']['last_unzip_file_index']=0;
|
||||
|
||||
$this->update_sub_task($sub_task);
|
||||
$this->log->WriteLog('Extracting file:'.$file_name,'notice');
|
||||
$ret=$this->extract($file_name,untrailingslashit($root_path),$sub_task['options']);
|
||||
if($ret['result']!='success')
|
||||
{
|
||||
return $ret;
|
||||
}
|
||||
$this->log->WriteLog('Extracting file:'.$file_name.' succeeded','notice');
|
||||
$sub_task['unzip_file']['files'][$index]['finished']=1;
|
||||
$sub_task['last_msg']='<span><strong>Extracting file:</strong></span><span>'.$file['file_name'].' completed.</span>';
|
||||
}
|
||||
else
|
||||
{
|
||||
$sum=$this->get_zip_file_count($file_name);
|
||||
|
||||
$start=$file['index'];
|
||||
$sub_task['last_msg']='<span><strong>Extracting file:</strong></span><span>'.$file['file_name'].' '.$start.'/'.$sum.'</span>';
|
||||
$sub_task['unzip_file']['sum']=$sum;
|
||||
$sub_task['unzip_file']['start']=$start;
|
||||
$sub_task['unzip_file']['last_action']='Unzipping';
|
||||
$sub_task['unzip_file']['last_unzip_file']=$file['file_name'];
|
||||
$sub_task['unzip_file']['last_unzip_file_index']=$start;
|
||||
$this->update_sub_task($sub_task);
|
||||
$this->log->WriteLog('Extracting file:'.basename($file_name).' index:'.$start,'notice');
|
||||
$ret=$this->extract_by_index($file_name,untrailingslashit($root_path),$start,$start+$unzip_files_pre_request,$sub_task['options']);
|
||||
if($ret['result']!='success')
|
||||
{
|
||||
return $ret;
|
||||
}
|
||||
$this->log->WriteLog('Extracting file:'.basename($file_name).' index:'.$start.' finished.','notice');
|
||||
$sub_task['unzip_file']['files'][$index]['index']=$start+$unzip_files_pre_request;
|
||||
$sub_task['unzip_file']['last_action']='Unzipping';
|
||||
if($start+$unzip_files_pre_request>=$sum)
|
||||
{
|
||||
$sub_task['unzip_file']['files'][$index]['finished']=1;
|
||||
$sub_task['unzip_file']['sum']=0;
|
||||
$sub_task['unzip_file']['start']=0;
|
||||
$sub_task['last_msg']='<span><strong>Extracting file:</strong></span><span>'.$file['file_name'].' completed.</span>';
|
||||
}
|
||||
else
|
||||
{
|
||||
$sub_task['last_msg']='<span><strong>Extracting file:</strong></span><span>'.$file['file_name'].' '.$sub_task['unzip_file']['files'][$index]['index'].'/'.$sum.'</span>';
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if($this->check_restore_finished($sub_task))
|
||||
{
|
||||
$sub_task['finished']=1;
|
||||
$sub_task['unzip_file']['unzip_finished']=1;
|
||||
$sub_task['unzip_file']['sum']=0;
|
||||
$sub_task['unzip_file']['start']=0;
|
||||
}
|
||||
|
||||
$ret['result']='success';
|
||||
$ret['sub_task']=$sub_task;
|
||||
return $ret;
|
||||
}
|
||||
|
||||
public function restore_core($sub_task,$backup_id)
|
||||
{
|
||||
$files=$sub_task['unzip_file']['files'];
|
||||
$GLOBALS['wpvivid_restore_addon_type'] =$sub_task['type'];
|
||||
//restore_reset
|
||||
foreach ($files as $index=>$file)
|
||||
{
|
||||
if($file['finished']==1)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$sub_task['unzip_file']['last_action']='Unzipping';
|
||||
$sub_task['unzip_file']['last_unzip_file']=$file['file_name'];
|
||||
$sub_task['last_msg']='<span><strong>Extracting file:</strong></span><span>'.$file['file_name'].'</span>';
|
||||
$this->update_sub_task($sub_task);
|
||||
|
||||
$backup = WPvivid_Backuplist::get_backup_by_id($backup_id);
|
||||
$backup_item = new WPvivid_Backup_Item($backup);
|
||||
$extract_child_finished=isset($file['extract_child_finished'])?$file['extract_child_finished']:0;
|
||||
if(isset($file['has_child'])&&$extract_child_finished==0)
|
||||
{
|
||||
$sub_task['unzip_file']['last_action']='Unzipping';
|
||||
$sub_task['last_msg']='<span><strong>Extracting file:</strong></span><span>'.$file['parent_file'].'</span>';
|
||||
$this->update_sub_task($sub_task);
|
||||
|
||||
$root_path=$backup_item->get_local_path();
|
||||
|
||||
if(!file_exists($root_path))
|
||||
{
|
||||
@mkdir($root_path);
|
||||
}
|
||||
$this->log->WriteLog('Extracting file:'.$file['parent_file'],'notice');
|
||||
|
||||
$extract_files[]=$file['file_name'];
|
||||
$ret=$this->extract_ex($root_path.$file['parent_file'],$extract_files,untrailingslashit($root_path),$sub_task['options']);
|
||||
if($ret['result']!='success')
|
||||
{
|
||||
return $ret;
|
||||
}
|
||||
$this->log->WriteLog('Extracting file:'.$file['parent_file'].' succeeded.','notice');
|
||||
$file_name=$root_path.$file['file_name'];
|
||||
$sub_task['unzip_file']['files'][$index]['extract_child_finished']=1;
|
||||
$sub_task['last_msg']='<span><strong>Extracting file:</strong></span><span>'.$file['parent_file'].' completed.</span>';
|
||||
$this->update_sub_task($sub_task);
|
||||
}
|
||||
else
|
||||
{
|
||||
$root_path=$backup_item->get_local_path();
|
||||
$file_name=$root_path.$file['file_name'];
|
||||
}
|
||||
|
||||
if($sub_task['restore_reset'])
|
||||
{
|
||||
if($sub_task['restore_reset_finished']===false)
|
||||
{
|
||||
$sub_task['unzip_file']['last_action']='Unzipping';
|
||||
$sub_task['last_msg']='<span>Cleaning folder:</span><span>'.$sub_task['type'].'</span>';
|
||||
$this->update_sub_task($sub_task);
|
||||
$this->log->WriteLog('Cleaning folder:'.$sub_task['type'],'notice');
|
||||
$this->reset_restore($sub_task['type']);
|
||||
|
||||
$sub_task['restore_reset_finished']=true;
|
||||
$sub_task['unzip_file']['last_action']='Unzipping';
|
||||
$sub_task['last_msg']='<span>Cleaning folder:</span><span>'.$sub_task['type'].' completed.</span>';
|
||||
$this->update_sub_task($sub_task);
|
||||
}
|
||||
}
|
||||
|
||||
$root_path = $this->transfer_path(ABSPATH);
|
||||
|
||||
$root_path = rtrim($root_path, '/');
|
||||
$root_path = rtrim($root_path, DIRECTORY_SEPARATOR);
|
||||
|
||||
$sub_task['last_msg']='<span><strong>Extracting Files:</strong></span><span>'.$file['file_name'].'</span>';
|
||||
$sub_task['unzip_file']['last_action']='Unzipping';
|
||||
$this->update_sub_task($sub_task);
|
||||
$this->log->WriteLog('Extracting file:'.basename($file_name),'notice');
|
||||
|
||||
$ret=$this->extract($file_name,untrailingslashit($root_path),$sub_task['options']);
|
||||
if($ret['result']!='success')
|
||||
{
|
||||
return $ret;
|
||||
}
|
||||
$this->log->WriteLog('Extracting file:'.basename($file_name).' succeeded.','notice');
|
||||
$sub_task['unzip_file']['files'][$index]['finished']=1;
|
||||
$sub_task['last_msg']='<span><strong>Extracting Files:</strong></span><span>'.$file['file_name'].' finished</span>';
|
||||
$this->update_sub_task($sub_task);
|
||||
}
|
||||
|
||||
if($this->check_restore_finished($sub_task))
|
||||
{
|
||||
$sub_task['finished']=1;
|
||||
$sub_task['unzip_file']['unzip_finished']=1;
|
||||
}
|
||||
|
||||
$ret['result']='success';
|
||||
$ret['sub_task']=$sub_task;
|
||||
return $ret;
|
||||
}
|
||||
|
||||
public function extract($file_name,$root_path,$option)
|
||||
{
|
||||
if (!class_exists('WPvivid_PclZip'))
|
||||
include_once WPVIVID_PLUGIN_DIR . '/includes/zip/class-wpvivid-pclzip.php';
|
||||
|
||||
if(!empty($option))
|
||||
{
|
||||
$GLOBALS['wpvivid_restore_option'] = $option;
|
||||
}
|
||||
|
||||
if(!defined('PCLZIP_TEMPORARY_DIR'))
|
||||
define(PCLZIP_TEMPORARY_DIR,dirname($root_path));
|
||||
|
||||
$archive = new WPvivid_PclZip($file_name);
|
||||
$zip_ret = $archive->extract(WPVIVID_PCLZIP_OPT_PATH, $root_path,WPVIVID_PCLZIP_OPT_REPLACE_NEWER,WPVIVID_PCLZIP_CB_PRE_EXTRACT,'wpvivid_function_pre_extract_callback_2',WPVIVID_PCLZIP_OPT_TEMP_FILE_THRESHOLD,16);
|
||||
if(!$zip_ret)
|
||||
{
|
||||
$ret['result']='failed';
|
||||
$ret['error'] = $archive->errorInfo(true);
|
||||
$this->log->WriteLog('Extracting failed. Error:'.$archive->errorInfo(true),'notice');
|
||||
}
|
||||
else
|
||||
{
|
||||
$ret['result']='success';
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
public function extract_ex($file_name,$extract_files,$root_path,$option)
|
||||
{
|
||||
if (!class_exists('WPvivid_PclZip'))
|
||||
include_once WPVIVID_PLUGIN_DIR . '/includes/zip/class-wpvivid-pclzip.php';
|
||||
|
||||
if(!empty($option))
|
||||
{
|
||||
$GLOBALS['wpvivid_restore_option'] = $option;
|
||||
}
|
||||
|
||||
if(!defined('PCLZIP_TEMPORARY_DIR'))
|
||||
define(PCLZIP_TEMPORARY_DIR,dirname($root_path));
|
||||
|
||||
$archive = new WPvivid_PclZip($file_name);
|
||||
$zip_ret = $archive->extract(WPVIVID_PCLZIP_OPT_BY_NAME,$extract_files,WPVIVID_PCLZIP_OPT_PATH, $root_path,WPVIVID_PCLZIP_OPT_REPLACE_NEWER,WPVIVID_PCLZIP_CB_PRE_EXTRACT,'wpvivid_function_pre_extract_callback_2',WPVIVID_PCLZIP_OPT_TEMP_FILE_THRESHOLD,16);
|
||||
if(!$zip_ret)
|
||||
{
|
||||
$ret['result']='failed';
|
||||
$ret['error'] = $archive->errorInfo(true);
|
||||
$this->log->WriteLog('Extracting failed. Error:'.$archive->errorInfo(true),'notice');
|
||||
}
|
||||
else
|
||||
{
|
||||
$ret['result']='success';
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
public function extract_by_index($file_name,$root_path,$start,$end,$option)
|
||||
{
|
||||
$index=$start.'-'.$end;
|
||||
|
||||
if (!class_exists('WPvivid_PclZip'))
|
||||
include_once WPVIVID_PLUGIN_DIR . '/includes/zip/class-wpvivid-pclzip.php';
|
||||
|
||||
if(!empty($option))
|
||||
{
|
||||
$GLOBALS['wpvivid_restore_option'] = $option;
|
||||
}
|
||||
|
||||
if(!defined('PCLZIP_TEMPORARY_DIR'))
|
||||
define(PCLZIP_TEMPORARY_DIR,dirname($root_path));
|
||||
|
||||
$archive = new WPvivid_PclZip($file_name);
|
||||
$zip_ret = $archive->extractByIndex($index,WPVIVID_PCLZIP_OPT_PATH, $root_path,WPVIVID_PCLZIP_OPT_REPLACE_NEWER,WPVIVID_PCLZIP_CB_PRE_EXTRACT,'wpvivid_function_pre_extract_callback_2',WPVIVID_PCLZIP_OPT_TEMP_FILE_THRESHOLD,16);
|
||||
if(!$zip_ret)
|
||||
{
|
||||
$ret['result']='failed';
|
||||
$ret['error'] = $archive->errorInfo(true);
|
||||
$this->log->WriteLog('Extracting failed. Error:'.$archive->errorInfo(true),'notice');
|
||||
}
|
||||
else
|
||||
{
|
||||
$ret['result']='success';
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
public function get_zip_file_count($file_name)
|
||||
{
|
||||
if (!class_exists('WPvivid_PclZip'))
|
||||
include_once WPVIVID_PLUGIN_DIR . '/includes/zip/class-wpvivid-pclzip.php';
|
||||
|
||||
$archive = new WPvivid_PclZip($file_name);
|
||||
$properties=$archive->properties();
|
||||
return $properties['nb'];
|
||||
}
|
||||
|
||||
public function check_restore_finished($sub_task)
|
||||
{
|
||||
$finished=true;
|
||||
|
||||
$files=$sub_task['unzip_file']['files'];
|
||||
|
||||
foreach ($files as $index=>$file)
|
||||
{
|
||||
if($file['finished']==1)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
$finished=false;
|
||||
}
|
||||
}
|
||||
|
||||
return $finished;
|
||||
}
|
||||
|
||||
private function transfer_path($path)
|
||||
{
|
||||
$path = str_replace('\\','/',$path);
|
||||
$values = explode('/',$path);
|
||||
return implode(DIRECTORY_SEPARATOR,$values);
|
||||
}
|
||||
|
||||
public function update_sub_task($sub_task=false)
|
||||
{
|
||||
$restore_task=get_option('wpvivid_restore_task',array());
|
||||
|
||||
if($restore_task['do_sub_task']!==false)
|
||||
{
|
||||
$key=$restore_task['do_sub_task'];
|
||||
$restore_task['update_time']=time();
|
||||
if($sub_task!==false)
|
||||
$restore_task['sub_tasks'][$key]=$sub_task;
|
||||
update_option('wpvivid_restore_task',$restore_task,'no');
|
||||
}
|
||||
}
|
||||
|
||||
public function reset_restore($type)
|
||||
{
|
||||
if($type=='themes')
|
||||
{
|
||||
return $this->delete_themes();
|
||||
}
|
||||
else if($type=='plugin')
|
||||
{
|
||||
return $this->delete_plugins();
|
||||
}
|
||||
else if($type=='upload')
|
||||
{
|
||||
return $this->delete_uploads();
|
||||
}
|
||||
else if($type=='wp-content')
|
||||
{
|
||||
return $this->delete_wp_content();
|
||||
}
|
||||
//else if($type=='mu_plugins')
|
||||
//{
|
||||
// return $this->delete_mu_plugins();
|
||||
//}
|
||||
else if($type=='wp-core')
|
||||
{
|
||||
return $this->delete_core();
|
||||
}
|
||||
$ret['result']='success';
|
||||
return $ret;
|
||||
}
|
||||
|
||||
public function delete_themes()
|
||||
{
|
||||
if (!function_exists('delete_theme'))
|
||||
{
|
||||
require_once ABSPATH . 'wp-admin/includes/theme.php';
|
||||
}
|
||||
|
||||
if (!function_exists('request_filesystem_credentials'))
|
||||
{
|
||||
require_once ABSPATH . 'wp-admin/includes/file.php';
|
||||
}
|
||||
|
||||
$all_themes = wp_get_themes(array('errors' => null));
|
||||
|
||||
foreach ($all_themes as $theme_slug => $theme_details)
|
||||
{
|
||||
delete_theme($theme_slug);
|
||||
}
|
||||
|
||||
update_option('template', '');
|
||||
update_option('stylesheet', '');
|
||||
update_option('current_theme', '');
|
||||
|
||||
$ret['result']=WPVIVID_SUCCESS;
|
||||
return $ret;
|
||||
}
|
||||
|
||||
public function delete_plugins()
|
||||
{
|
||||
if (!function_exists('get_plugins'))
|
||||
{
|
||||
require_once ABSPATH . 'wp-admin/includes/plugin.php';
|
||||
}
|
||||
if (!function_exists('request_filesystem_credentials'))
|
||||
{
|
||||
require_once ABSPATH . 'wp-admin/includes/file.php';
|
||||
}
|
||||
|
||||
$wpvivid_backup_pro='wpvivid-backup-pro/wpvivid-backup-pro.php';
|
||||
$wpvivid_backup='wpvivid-backuprestore/wpvivid-backuprestore.php';
|
||||
|
||||
$all_plugins = get_plugins();
|
||||
unset($all_plugins[$wpvivid_backup_pro]);
|
||||
unset($all_plugins[$wpvivid_backup]);
|
||||
|
||||
if (!empty($all_plugins))
|
||||
{
|
||||
$this->_delete_plugins(array_keys($all_plugins));
|
||||
}
|
||||
|
||||
$ret['result']=WPVIVID_SUCCESS;
|
||||
return $ret;
|
||||
}
|
||||
|
||||
public function _delete_plugins($plugins)
|
||||
{
|
||||
if ( empty( $plugins ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
$plugins_dir = trailingslashit( WP_PLUGIN_DIR );
|
||||
|
||||
foreach ( $plugins as $plugin_file )
|
||||
{
|
||||
$this_plugin_dir = trailingslashit( dirname( $plugins_dir . $plugin_file ) );
|
||||
|
||||
// If plugin is in its own directory, recursively delete the directory.
|
||||
if ( strpos( $plugin_file, '/' ) && $this_plugin_dir != $plugins_dir )
|
||||
{ //base check on if plugin includes directory separator AND that it's not the root plugin folder
|
||||
$this->delete_folder($this_plugin_dir,$plugins_dir);
|
||||
} else {
|
||||
@wp_delete_file($plugins_dir . $plugin_file);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function delete_uploads()
|
||||
{
|
||||
$upload_dir = wp_get_upload_dir();
|
||||
|
||||
$this->delete_folder($upload_dir['basedir'], $upload_dir['basedir']);
|
||||
|
||||
$ret['result']=WPVIVID_SUCCESS;
|
||||
return $ret;
|
||||
}
|
||||
|
||||
public function delete_folder($folder, $base_folder)
|
||||
{
|
||||
$files = array_diff(scandir($folder), array('.', '..'));
|
||||
|
||||
foreach ($files as $file)
|
||||
{
|
||||
if (is_dir($folder . DIRECTORY_SEPARATOR . $file))
|
||||
{
|
||||
$this->delete_folder($folder . DIRECTORY_SEPARATOR . $file, $base_folder);
|
||||
} else {
|
||||
@wp_delete_file($folder . DIRECTORY_SEPARATOR . $file);
|
||||
}
|
||||
} // foreach
|
||||
|
||||
if ($folder != $base_folder)
|
||||
{
|
||||
$tmp = @rmdir($folder);
|
||||
return $tmp;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public function delete_wp_content()
|
||||
{
|
||||
global $wpvivid_plugin;
|
||||
|
||||
$wp_content_dir = trailingslashit(WP_CONTENT_DIR);
|
||||
|
||||
$wpvivid_backup=WPvivid_Setting::get_backupdir();
|
||||
|
||||
$whitelisted_folders = array('mu-plugins', 'plugins', 'themes', 'uploads',$wpvivid_backup);
|
||||
|
||||
$dirs = glob($wp_content_dir . '*', GLOB_ONLYDIR);
|
||||
foreach ($dirs as $dir)
|
||||
{
|
||||
if (false == in_array(basename($dir), $whitelisted_folders))
|
||||
{
|
||||
$this->delete_folder($dir, $dir);
|
||||
@rmdir($dir);
|
||||
}
|
||||
}
|
||||
|
||||
$ret['result']=WPVIVID_SUCCESS;
|
||||
return $ret;
|
||||
}
|
||||
|
||||
public function delete_mu_plugins()
|
||||
{
|
||||
$ret['result']=WPVIVID_SUCCESS;
|
||||
|
||||
$mu_plugins = get_mu_plugins();
|
||||
|
||||
if(empty($mu_plugins))
|
||||
{
|
||||
return $ret;
|
||||
}
|
||||
|
||||
$this->delete_folder(WPMU_PLUGIN_DIR, WPMU_PLUGIN_DIR);
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
public function delete_core()
|
||||
{
|
||||
$ret['result']=WPVIVID_SUCCESS;
|
||||
|
||||
require_once( ABSPATH . 'wp-admin/includes/update-core.php' );
|
||||
|
||||
global $_old_files;
|
||||
|
||||
$wp_dir = ABSPATH;
|
||||
|
||||
foreach ( $_old_files as $old_file )
|
||||
{
|
||||
$old_file = $wp_dir . $old_file;
|
||||
if ( ! file_exists( $old_file ) )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// If the file isn't deleted, try writing an empty string to the file instead.
|
||||
@wp_delete_file($old_file);
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
}
|
||||
|
||||
function wpvivid_function_pre_extract_callback_2($p_event, &$p_header)
|
||||
{
|
||||
$plugins = substr(WP_PLUGIN_DIR, strpos(WP_PLUGIN_DIR, 'wp-content/'));
|
||||
|
||||
if ( isset( $GLOBALS['wpvivid_restore_option'] ) )
|
||||
{
|
||||
$option = $GLOBALS['wpvivid_restore_option'];
|
||||
$type=$GLOBALS['wpvivid_restore_addon_type'];
|
||||
if ($type == 'themes')
|
||||
{
|
||||
if (isset($option['remove_themes']))
|
||||
{
|
||||
foreach ($option['remove_themes'] as $slug => $themes)
|
||||
{
|
||||
if (empty($slug))
|
||||
continue;
|
||||
if(strpos($p_header['filename'],$plugins.DIRECTORY_SEPARATOR.$slug)!==false)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if ($type == 'plugin')
|
||||
{
|
||||
if (isset($option['remove_plugins']))
|
||||
{
|
||||
foreach ($option['remove_plugins'] as $slug => $plugin)
|
||||
{
|
||||
if (empty($slug))
|
||||
continue;
|
||||
if(strpos($p_header['filename'],$plugins.'/'.$slug)!==false)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$option=array();
|
||||
}
|
||||
|
||||
$path = str_replace('\\','/',WP_CONTENT_DIR);
|
||||
$content_path = $path.'/';
|
||||
if(strpos($p_header['filename'], $content_path.'advanced-cache.php')!==false)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(strpos($p_header['filename'], $content_path.'db.php')!==false)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(strpos($p_header['filename'], $content_path.'object-cache.php')!==false)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(strpos($p_header['filename'],$plugins.'/wpvivid-backuprestore')!==false)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(strpos($p_header['filename'],'wp-config.php')!==false)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(strpos($p_header['filename'],'wpvivid_package_info.json')!==false)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(isset($option['restore_htaccess'])&&$option['restore_htaccess'])
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
if(strpos($p_header['filename'],'.htaccess')!==false)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if(strpos($p_header['filename'],'.user.ini')!==false)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(strpos($p_header['filename'],'wordfence-waf.php')!==false)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(strpos($p_header['filename'], $content_path.'mu-plugins/endurance-browser-cache.php')!==false)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(strpos($p_header['filename'], $content_path.'mu-plugins/endurance-page-cache.php')!==false)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(strpos($p_header['filename'], $content_path.'mu-plugins/endurance-php-edge.php')!==false)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(strpos($p_header['filename'], $content_path.'mu-plugins/wp-stack-cache.php')!==false)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(strpos($p_header['filename'], '.DS_Store')!==false)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,352 @@
|
||||
<?php
|
||||
|
||||
if (!defined('WPVIVID_PLUGIN_DIR'))
|
||||
{
|
||||
die;
|
||||
}
|
||||
|
||||
class WPvivid_Zip
|
||||
{
|
||||
public $zip_object;
|
||||
|
||||
public function __construct($zip_method='')
|
||||
{
|
||||
$this->check_available_zip_object($zip_method);
|
||||
}
|
||||
|
||||
public function add_files($zip_file,$root_path,$files,$create=false,$json=false)
|
||||
{
|
||||
if($create)
|
||||
{
|
||||
if(file_exists($zip_file))
|
||||
@wp_delete_file($zip_file);
|
||||
}
|
||||
|
||||
if($json!==false)
|
||||
{
|
||||
$this->add_json_file($zip_file,$json,$create);
|
||||
}
|
||||
|
||||
if(file_exists($zip_file))
|
||||
{
|
||||
$this->zip_object->open($zip_file);
|
||||
clearstatcache();
|
||||
}
|
||||
else
|
||||
{
|
||||
$create_code = (version_compare(PHP_VERSION, '5.2.12', '>') && defined('ZIPARCHIVE::CREATE')) ? ZIPARCHIVE::CREATE : 1;
|
||||
$this->zip_object->open($zip_file, $create_code);
|
||||
}
|
||||
|
||||
if(is_a($this->zip_object,'WPvivid_PclZip_2'))
|
||||
$this->zip_object->set_replace_path($root_path);
|
||||
|
||||
foreach ($files as $file)
|
||||
{
|
||||
$new_file=str_replace($root_path,'',$file);
|
||||
if(file_exists($file))
|
||||
{
|
||||
$this->zip_object->addFile($file,$new_file);
|
||||
}
|
||||
}
|
||||
|
||||
if($this->zip_object->close()===false)
|
||||
{
|
||||
$ret['result']='failed';
|
||||
$ret['error']='Failed to add zip files.';
|
||||
if(is_a($this->zip_object,'WPvivid_PclZip_2'))
|
||||
{
|
||||
$ret['error'].=' last error:'.$this->zip_object->last_error;
|
||||
}
|
||||
else if(is_a($this->zip_object,'ZipArchive'))
|
||||
{
|
||||
$ret['error'].=' status string:'.$this->zip_object->getStatusString();
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
$ret['result']='success';
|
||||
return $ret;
|
||||
}
|
||||
|
||||
public function add_file($zip_file,$file,$add_as,$replace_path)
|
||||
{
|
||||
global $wpvivid_plugin;
|
||||
$wpvivid_plugin->wpvivid_log->WriteLog('Prepare to zip file. file: '.basename($file),'notice');
|
||||
|
||||
if(file_exists($zip_file))
|
||||
{
|
||||
$this->zip_object->open($zip_file);
|
||||
clearstatcache();
|
||||
}
|
||||
else
|
||||
{
|
||||
$create_code = (version_compare(PHP_VERSION, '5.2.12', '>') && defined('ZIPARCHIVE::CREATE')) ? ZIPARCHIVE::CREATE : 1;
|
||||
$this->zip_object->open($zip_file, $create_code);
|
||||
}
|
||||
|
||||
if(is_a($this->zip_object,'WPvivid_PclZip_2'))
|
||||
$this->zip_object->set_replace_path($replace_path);
|
||||
|
||||
if($this->zip_object->addFile($file,$add_as)===false)
|
||||
{
|
||||
$ret['result']='failed';
|
||||
$ret['error']='Failed to add zip file '.$file;
|
||||
if(is_a($this->zip_object,'WPvivid_PclZip_2'))
|
||||
{
|
||||
$ret['error'].=' last error:'.$this->zip_object->last_error;
|
||||
}
|
||||
else if(is_a($this->zip_object,'ZipArchive'))
|
||||
{
|
||||
$ret['error'].=' status string:'.$this->zip_object->getStatusString();
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
if($this->zip_object->close()===false)
|
||||
{
|
||||
$ret['result']='failed';
|
||||
$ret['error']='Failed to add zip files.';
|
||||
if(is_a($this->zip_object,'WPvivid_PclZip_2'))
|
||||
{
|
||||
$ret['error'].=' last error:'.$this->zip_object->last_error;
|
||||
}
|
||||
else if(is_a($this->zip_object,'ZipArchive'))
|
||||
{
|
||||
$ret['error'].=' status string:'.$this->zip_object->getStatusString();
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
$ret['result']='success';
|
||||
$wpvivid_plugin->wpvivid_log->WriteLog('Adding zip files completed.'.basename($zip_file).', filesize: '.size_format(filesize($zip_file),2),'notice');
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
public function add_json_file($zip_file,$json,$create=false)
|
||||
{
|
||||
if($create)
|
||||
{
|
||||
if(file_exists($zip_file))
|
||||
@wp_delete_file($zip_file);
|
||||
}
|
||||
$json['file']=basename($zip_file);
|
||||
$string=wp_json_encode($json);
|
||||
|
||||
if(file_exists($zip_file))
|
||||
{
|
||||
$this->zip_object->open($zip_file);
|
||||
clearstatcache();
|
||||
}
|
||||
else
|
||||
{
|
||||
$create_code = (version_compare(PHP_VERSION, '5.2.12', '>') && defined('ZIPARCHIVE::CREATE')) ? ZIPARCHIVE::CREATE : 1;
|
||||
$this->zip_object->open($zip_file, $create_code);
|
||||
}
|
||||
|
||||
if($this->zip_object->addFromString('wpvivid_package_info.json',$string)===false)
|
||||
{
|
||||
$ret['result']='failed';
|
||||
$ret['error']='Failed to add zip file';
|
||||
return $ret;
|
||||
}
|
||||
|
||||
if(is_a($this->zip_object,'WPvivid_PclZip_2'))
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
if($this->zip_object->close()===false)
|
||||
{
|
||||
$ret['result']='failed';
|
||||
$ret['error']='Failed to add zip file';
|
||||
return $ret;
|
||||
}
|
||||
}
|
||||
|
||||
$ret['result']='success';
|
||||
return $ret;
|
||||
}
|
||||
|
||||
public function check_available_zip_object($zip_method)
|
||||
{
|
||||
if($zip_method=='ziparchive'||empty($zip_method))
|
||||
{
|
||||
if($this->check_ziparchive_available())
|
||||
{
|
||||
$this->zip_object=new ZipArchive();
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->zip_object=new WPvivid_PclZip_2();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->zip_object=new WPvivid_PclZip_2();
|
||||
}
|
||||
}
|
||||
|
||||
public function check_ziparchive_available()
|
||||
{
|
||||
if(class_exists('ZipArchive'))
|
||||
{
|
||||
if(method_exists('ZipArchive', 'addFile'))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function addEmptyDir($zip_file,$folders)
|
||||
{
|
||||
$path=WP_CONTENT_DIR.DIRECTORY_SEPARATOR.WPvivid_Setting::get_backupdir().DIRECTORY_SEPARATOR;
|
||||
if(file_exists($path.$zip_file))
|
||||
{
|
||||
$this->zip_object->open($path.$zip_file);
|
||||
}
|
||||
else
|
||||
{
|
||||
$create_code = (version_compare(PHP_VERSION, '5.2.12', '>') && defined('ZIPARCHIVE::CREATE')) ? ZIPARCHIVE::CREATE : 1;
|
||||
$this->zip_object->open($path.$zip_file, $create_code);
|
||||
}
|
||||
|
||||
foreach ($folders as $folder)
|
||||
{
|
||||
$this->zip_object->addEmptyDir($folder);
|
||||
}
|
||||
|
||||
$this->zip_object->close();
|
||||
|
||||
$ret['result']='success';
|
||||
return $ret;
|
||||
}
|
||||
}
|
||||
|
||||
class WPvivid_PclZip_2
|
||||
{
|
||||
public $addfiles;
|
||||
|
||||
public $adddirs;
|
||||
|
||||
public $path;
|
||||
|
||||
public $pclzip;
|
||||
|
||||
public $last_error;
|
||||
|
||||
public $replace_path;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->addfiles = array();
|
||||
$this->adddirs = array();
|
||||
if(!defined('PCLZIP_TEMPORARY_DIR'))
|
||||
{
|
||||
$path=WP_CONTENT_DIR.DIRECTORY_SEPARATOR.WPvivid_Setting::get_backupdir().DIRECTORY_SEPARATOR;
|
||||
$temp_dir =$path.'wpvivid-pclzip-temp'.DIRECTORY_SEPARATOR;
|
||||
define(PCLZIP_TEMPORARY_DIR,$temp_dir);
|
||||
}
|
||||
|
||||
if (!class_exists('WPvivid_PclZip'))
|
||||
include_once WPVIVID_PLUGIN_DIR . '/includes/zip/class-wpvivid-pclzip.php';
|
||||
}
|
||||
|
||||
public function open($path, $flags = 0)
|
||||
{
|
||||
$ziparchive_create_match = (version_compare(PHP_VERSION, '5.2.12', '>') && defined('ZIPARCHIVE::CREATE')) ? ZIPARCHIVE::CREATE : 1;
|
||||
|
||||
if ($flags == $ziparchive_create_match && file_exists($path))
|
||||
@wp_delete_file($path);
|
||||
|
||||
$this->pclzip = new WPvivid_PclZip($path);
|
||||
|
||||
if (empty($this->pclzip))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->path = $path;
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
public function set_replace_path($replace_path)
|
||||
{
|
||||
$this->replace_path=$replace_path;
|
||||
}
|
||||
|
||||
public function addFile($file, $add_as)
|
||||
{
|
||||
$this->addfiles[] = $file;
|
||||
return true;
|
||||
}
|
||||
|
||||
public function addEmptyDir($dir)
|
||||
{
|
||||
$this->adddirs[] = $dir;
|
||||
}
|
||||
|
||||
public function close()
|
||||
{
|
||||
if (empty($this->pclzip))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
$path=WP_CONTENT_DIR.DIRECTORY_SEPARATOR.WPvivid_Setting::get_backupdir().DIRECTORY_SEPARATOR;
|
||||
|
||||
foreach ($this->adddirs as $dir)
|
||||
{
|
||||
$ret=$this->pclzip->add($path.'emptydir', WPVIVID_PCLZIP_OPT_REMOVE_PATH, $path.'emptydir', WPVIVID_PCLZIP_OPT_ADD_PATH, $dir);
|
||||
if (!$ret)
|
||||
{
|
||||
$this->last_error = $this->pclzip->errorInfo(true);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if(!class_exists('WPvivid_ZipClass'))
|
||||
include_once WPVIVID_PLUGIN_DIR . '/includes/class-wpvivid-zipclass.php';
|
||||
$ret = $this->pclzip -> add($this->addfiles,WPVIVID_PCLZIP_OPT_REMOVE_PATH,$this->replace_path,WPVIVID_PCLZIP_CB_PRE_ADD,'wpvivid_function_per_add_callback',WPVIVID_PCLZIP_OPT_NO_COMPRESSION,WPVIVID_PCLZIP_OPT_TEMP_FILE_THRESHOLD,16);
|
||||
|
||||
if (!$ret)
|
||||
{
|
||||
$this->last_error = $this->pclzip->errorInfo(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->pclzip = false;
|
||||
$this->addfiles = array();
|
||||
$this->adddirs = array();
|
||||
|
||||
clearstatcache();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function addFromString($file_name,$string)
|
||||
{
|
||||
$path=WP_CONTENT_DIR.DIRECTORY_SEPARATOR.WPvivid_Setting::get_backupdir().DIRECTORY_SEPARATOR;
|
||||
$temp_path = $path.$file_name;
|
||||
if(file_exists($temp_path))
|
||||
{
|
||||
@wp_delete_file($temp_path);
|
||||
}
|
||||
file_put_contents($temp_path,$string);
|
||||
$this->pclzip -> add($temp_path,WPVIVID_PCLZIP_OPT_REMOVE_PATH,dirname($temp_path));
|
||||
@wp_delete_file($temp_path);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user