2015-10-15 22:52:37 +10:00
< ? php
2019-02-19 23:52:21 +07:00
/*
*
* Credits
*
* Plugin - Name : BackUpWordPress
* Plugin URI : http :// bwp . hmn . md /
* Author : Human Made Limited
* Author URI : http :// hmn . md /
* License : GPL - 2 +
* License URI : http :// www . gnu . org / licenses / gpl - 2.0 . txt
*
* The code is used for the MainWP BackUpWordPress Extension
* Extension URL : https :// mainwp . com / extension / backupwordpress /
*
*/
2015-10-15 22:52:37 +10:00
class MainWP_Child_Back_Up_Wordpress {
public static $instance = null ;
2017-08-24 20:41:12 +02:00
public $is_plugin_installed = false ;
2015-10-15 22:52:37 +10:00
static function Instance () {
2020-03-26 14:05:04 +00:00
if ( null === self :: $instance ) {
self :: $instance = new MainWP_Child_Back_Up_Wordpress ();
2015-10-15 22:52:37 +10:00
}
2020-03-26 14:05:04 +00:00
return self :: $instance ;
2015-10-15 22:52:37 +10:00
}
2018-09-27 19:52:32 +02:00
2017-02-22 21:39:22 +01:00
public function __construct () {
2020-03-26 14:11:33 +00:00
require_once ABSPATH . 'wp-admin/includes/plugin.php' ;
2016-10-24 20:33:37 +02:00
if ( is_plugin_active ( 'backupwordpress/backupwordpress.php' ) ) {
2018-09-27 19:52:32 +02:00
$this -> is_plugin_installed = true ;
2018-06-26 19:52:53 +02:00
if ( version_compare ( phpversion (), '5.3' , '>=' ) ) {
add_filter ( 'mainwp-site-sync-others-data' , array ( $this , 'syncOthersData' ), 10 , 2 );
}
2016-10-24 20:33:37 +02:00
}
2017-02-22 21:39:22 +01:00
}
2015-10-15 22:52:37 +10:00
public function init () {
2018-06-26 19:52:53 +02:00
if ( version_compare ( phpversion (), '5.3' , '<' ) ) {
return ;
}
2018-11-14 21:33:36 +07:00
2020-03-26 14:11:33 +00:00
if ( ! $this -> is_plugin_installed ) { return ;
}
2017-01-14 13:16:52 +01:00
add_action ( 'mainwp_child_site_stats' , array ( $this , 'do_site_stats' ) );
2015-10-15 22:52:37 +10:00
if ( get_option ( 'mainwp_backupwordpress_hide_plugin' ) === 'hide' ) {
add_filter ( 'all_plugins' , array ( $this , 'all_plugins' ) );
add_action ( 'admin_menu' , array ( $this , 'remove_menu' ) );
add_filter ( 'site_transient_update_plugins' , array ( & $this , 'remove_update_nag' ) );
2018-12-19 17:01:08 +07:00
add_filter ( 'mainwp_child_hide_update_notice' , array ( & $this , 'hide_update_notice' ) );
2015-10-15 22:52:37 +10:00
}
}
2018-12-19 17:01:08 +07:00
function hide_update_notice ( $slugs ) {
$slugs [] = 'backupwordpress/backupwordpress.php' ;
return $slugs ;
}
2015-10-15 22:52:37 +10:00
function remove_update_nag ( $value ) {
if ( isset ( $_POST [ 'mainwpsignature' ] ) ) {
return $value ;
}
2018-12-19 17:01:08 +07:00
if ( ! MainWP_Helper :: is_screen_with_update ()) {
return $value ;
}
2015-10-15 22:52:37 +10:00
if ( isset ( $value -> response [ 'backupwordpress/backupwordpress.php' ] ) ) {
unset ( $value -> response [ 'backupwordpress/backupwordpress.php' ] );
}
return $value ;
}
public function action () {
$information = array ();
if ( ! self :: isActivated () ) {
$information [ 'error' ] = 'NO_BACKUPWORDPRESS' ;
MainWP_Helper :: write ( $information );
}
2016-11-24 20:46:47 +01:00
2015-10-15 22:52:37 +10:00
if ( isset ( $_POST [ 'mwp_action' ] ) ) {
switch ( $_POST [ 'mwp_action' ] ) {
case 'set_showhide' :
$information = $this -> set_showhide ();
break ;
case 'delete_schedule' :
$information = $this -> delete_schedule ();
break ;
case 'cancel_schedule' :
$information = $this -> hmbkp_request_cancel_backup ();
break ;
case 'get_backup_status' :
$information = $this -> get_backup_status ();
break ;
case 'reload_backupslist' :
$information = $this -> reload_backups ();
break ;
case 'delete_backup' :
$information = $this -> hmbkp_request_delete_backup ();
break ;
case 'run_schedule' :
$information = $this -> run_schedule ();
break ;
2016-02-15 22:08:39 +01:00
case 'save_all_schedules' :
$information = $this -> save_all_schedules ();
break ;
2015-10-15 22:52:37 +10:00
case 'update_schedule' :
$information = $this -> update_schedule ();
break ;
case 'get_excluded' :
$information = $this -> get_excluded ();
break ;
case 'directory_browse' :
$information = $this -> directory_browse ();
break ;
case 'exclude_add_rule' :
$information = $this -> hmbkp_add_exclude_rule ();
break ;
case 'exclude_remove_rule' :
$information = $this -> hmbkp_remove_exclude_rule ();
break ;
2018-09-27 19:52:32 +02:00
case 'general_exclude_add_rule' :
$information = $this -> general_exclude_add_rule ();
break ;
2015-10-15 22:52:37 +10:00
}
}
MainWP_Helper :: write ( $information );
}
function check_schedule () {
$schedule_id = ( isset ( $_POST [ 'schedule_id' ] ) && ! empty ( $_POST [ 'schedule_id' ] ) ) ? $_POST [ 'schedule_id' ] : '' ;
if ( empty ( $schedule_id ) ) {
$information = array ( 'error' => 'Empty schedule id' );
MainWP_Helper :: write ( $information );
} else {
$schedule_id = sanitize_text_field ( urldecode ( $schedule_id ) );
HM\BackUpWordPress\Schedules :: get_instance () -> refresh_schedules ();
if ( ! HM\BackUpWordPress\Schedules :: get_instance () -> get_schedule ( $schedule_id ) ) {
$information = array ( 'result' => 'NOTFOUND' );
MainWP_Helper :: write ( $information );
}
}
return $schedule_id ;
}
2018-06-26 19:52:53 +02:00
// ok
public function syncOthersData ( $information , $data = array () ) {
2018-09-27 19:52:32 +02:00
if ( isset ( $data [ 'syncBackUpWordPress' ] ) && $data [ 'syncBackUpWordPress' ] ) {
2018-06-26 19:52:53 +02:00
try {
$information [ 'syncBackUpWordPress' ] = $this -> get_sync_data ();
} catch ( Exception $e ) {
2018-09-27 19:52:32 +02:00
2018-06-26 19:52:53 +02:00
}
2018-09-27 19:52:32 +02:00
}
2018-06-26 19:52:53 +02:00
return $information ;
2015-10-15 22:52:37 +10:00
}
2018-09-27 19:52:32 +02:00
2018-06-26 19:52:53 +02:00
// ok
2015-10-15 22:52:37 +10:00
private function get_sync_data () {
2018-06-26 19:52:53 +02:00
MainWP_Helper :: check_classes_exists ( 'HM\BackUpWordPress\Schedules' );
MainWP_Helper :: check_methods ( 'HM\BackUpWordPress\Schedules' , array ( 'get_instance' , 'refresh_schedules' , 'get_schedules' ) );
2018-09-27 19:52:32 +02:00
2015-10-15 22:52:37 +10:00
HM\BackUpWordPress\Schedules :: get_instance () -> refresh_schedules ();
$schedules = HM\BackUpWordPress\Schedules :: get_instance () -> get_schedules ();
$backups_time = array ();
2018-09-27 19:52:32 +02:00
2018-06-26 19:52:53 +02:00
if ( is_array ( $schedules ) && count ( $schedules )) {
$check = current ( $schedules );
MainWP_Helper :: check_methods ( $check , array ( 'get_backups' ) );
2018-09-27 19:52:32 +02:00
2018-06-26 19:52:53 +02:00
foreach ( $schedules as $sche ) {
$existing_backup = $sche -> get_backups ();
if ( ! empty ( $existing_backup ) ) {
$backups_time = array_merge ( $backups_time , array_keys ( $existing_backup ) );
}
}
}
2015-10-15 22:52:37 +10:00
$lasttime_backup = 0 ;
if ( ! empty ( $backups_time ) ) {
$lasttime_backup = max ( $backups_time );
}
$return = array ( 'lasttime_backup' => $lasttime_backup );
return $return ;
}
2018-09-27 19:52:32 +02:00
2017-01-14 13:16:52 +01:00
function do_site_stats () {
2017-02-22 21:39:22 +01:00
if ( has_action ( 'mainwp_child_reports_log' )) {
do_action ( 'mainwp_child_reports_log' , 'backupwordpress' );
} else {
$this -> do_reports_log ( 'backupwordpress' );
}
}
2018-09-27 19:52:32 +02:00
// ok
2020-03-26 14:05:04 +00:00
public function do_reports_log ( $ext = '' ) {
2020-03-26 14:11:33 +00:00
if ( $ext !== 'backupwordpress' ) { return ;
}
if ( ! $this -> is_plugin_installed ) { return ;
}
2018-09-27 19:52:32 +02:00
2018-06-26 19:52:53 +02:00
try {
2018-09-27 19:52:32 +02:00
MainWP_Helper :: check_classes_exists ( 'HM\BackUpWordPress\Schedules' );
2018-06-26 19:52:53 +02:00
MainWP_Helper :: check_methods ( 'HM\BackUpWordPress\Schedules' , array ( 'get_instance' , 'refresh_schedules' , 'get_schedules' ));
2018-09-27 19:52:32 +02:00
2018-06-26 19:52:53 +02:00
// Refresh the schedules from the database to make sure we have the latest changes
HM\BackUpWordPress\Schedules :: get_instance () -> refresh_schedules ();
$schedules = HM\BackUpWordPress\Schedules :: get_instance () -> get_schedules ();
if ( is_array ( $schedules ) && count ( $schedules ) > 0 ) {
$check = current ( $schedules );
MainWP_Helper :: check_methods ( $check , array ( 'get_backups' , 'get_type' ));
2018-09-27 19:52:32 +02:00
2018-06-26 19:52:53 +02:00
foreach ( $schedules as $schedule ) {
foreach ( $schedule -> get_backups () as $file ) {
$backup_type = $schedule -> get_type ();
2020-03-26 14:05:04 +00:00
$message = 'BackupWordpres backup ' . $backup_type . ' finished' ;
$destination = 'N/A' ;
2018-06-26 19:52:53 +02:00
if ( file_exists ( $file ) ) {
$date = @ filemtime ( $file );
if ( ! empty ( $date ) ) {
2020-03-26 14:05:04 +00:00
do_action ( 'mainwp_reports_backupwordpress_backup' , $destination , $message , 'finished' , $backup_type , $date );
2018-06-26 19:52:53 +02:00
MainWP_Helper :: update_lasttime_backup ( 'backupwordpress' , $date ); // to support backup before update feature
}
}
2017-01-14 13:16:52 +01:00
}
2016-10-24 20:33:37 +02:00
}
}
2018-06-26 19:52:53 +02:00
} catch ( Exception $e ) {
2018-09-27 19:52:32 +02:00
}
2017-01-14 13:16:52 +01:00
}
2018-09-27 19:52:32 +02:00
2015-10-15 22:52:37 +10:00
function set_showhide () {
$hide = isset ( $_POST [ 'showhide' ] ) && ( 'hide' === $_POST [ 'showhide' ] ) ? 'hide' : '' ;
MainWP_Helper :: update_option ( 'mainwp_backupwordpress_hide_plugin' , $hide );
$information [ 'result' ] = 'SUCCESS' ;
return $information ;
}
function delete_schedule () {
$schedule_id = $this -> check_schedule ();
$schedule = new HM\BackUpWordPress\Scheduled_Backup ( sanitize_text_field ( urldecode ( $schedule_id ) ) );
if ( $schedule ) {
$schedule -> cancel ( true );
$information [ 'result' ] = 'SUCCESS' ;
} else {
$information [ 'result' ] = 'NOTFOUND' ;
}
return $information ;
}
function hmbkp_request_cancel_backup () {
$schedule_id = $this -> check_schedule ();
$schedule = new HM\BackUpWordPress\Scheduled_Backup ( sanitize_text_field ( urldecode ( $schedule_id ) ) );
// Delete the running backup
2016-02-15 22:08:39 +01:00
if ( method_exists ( $schedule , 'get_running_backup_filename' )) {
if ( $schedule -> get_running_backup_filename () && file_exists ( trailingslashit ( hmbkp_path () ) . $schedule -> get_running_backup_filename () ) ) {
unlink ( trailingslashit ( hmbkp_path () ) . $schedule -> get_running_backup_filename () );
}
if ( $schedule -> get_schedule_running_path () && file_exists ( $schedule -> get_schedule_running_path () ) ) {
unlink ( $schedule -> get_schedule_running_path () );
}
} else {
$status = $schedule -> get_status ();
// Delete the running backup
if ( $status -> get_backup_filename () && file_exists ( trailingslashit ( HM\BackUpWordPress\Path :: get_path () ) . $status -> get_backup_filename () ) ) {
unlink ( trailingslashit ( HM\BackUpWordPress\Path :: get_path () ) . $status -> get_backup_filename () );
}
if ( file_exists ( $status -> get_status_filepath () ) ) {
unlink ( $status -> get_status_filepath () );
}
2015-10-15 22:52:37 +10:00
}
2016-02-15 22:08:39 +01:00
2015-10-15 22:52:37 +10:00
HM\BackUpWordPress\Path :: get_instance () -> cleanup ();
2016-02-15 22:08:39 +01:00
if ( $status === null ) {
$information [ 'scheduleStatus' ] = $schedule -> get_status ();
} else {
$information [ 'scheduleStatus' ] = $status -> get_status ();
}
2015-10-15 22:52:37 +10:00
$information [ 'result' ] = 'SUCCESS' ;
return $information ;
}
function get_backup_status () {
$schedule_id = $this -> check_schedule ();
$schedule = new HM\BackUpWordPress\Scheduled_Backup ( sanitize_text_field ( urldecode ( $schedule_id ) ) );
2016-02-15 22:08:39 +01:00
if ( method_exists ( $schedule , 'get_running_backup_filename' )) {
$information [ 'scheduleStatus' ] = $schedule -> get_status ();
} else {
$status = $schedule -> get_status ();
$information [ 'scheduleStatus' ] = $status -> get_status ();
}
2015-10-15 22:52:37 +10:00
$information [ 'result' ] = 'SUCCESS' ;
return $information ;
}
function run_schedule () {
$schedule_id = $this -> check_schedule ();
2016-02-15 22:08:39 +01:00
if ( function_exists ( 'hmbkp_run_schedule_async' )) {
hmbkp_run_schedule_async ( $schedule_id );
2020-03-26 14:11:33 +00:00
} elseif ( function_exists ( '\HM\BackUpWordPress\run_schedule_async' )) {
2016-03-03 20:28:07 +01:00
HM\BackUpWordPress\Path :: get_instance () -> cleanup ();
// Fixes an issue on servers which only allow a single session per client
session_write_close ();
2016-02-15 22:08:39 +01:00
$task = new \HM\Backdrop\Task ( '\HM\BackUpWordPress\run_schedule_async' , $schedule_id );
$task -> schedule ();
2020-03-26 14:11:33 +00:00
} else {
2016-10-24 20:33:37 +02:00
return array ( 'error' => __ ( 'Error while trying to trigger the schedule' , 'mainwp-child' ) );
2020-03-26 14:11:33 +00:00
}
2015-10-15 22:52:37 +10:00
return array ( 'result' => 'SUCCESS' );
}
function reload_backups () {
$scheduleIds = isset ( $_POST [ 'schedule_ids' ] ) ? $_POST [ 'schedule_ids' ] : array ();
HM\BackUpWordPress\Schedules :: get_instance () -> refresh_schedules ();
$all_schedules_ids = array ();
$schedules = HM\BackUpWordPress\Schedules :: get_instance () -> get_schedules ();
foreach ( $schedules as $sch ) {
$all_schedules_ids [] = $sch -> get_id ();
}
if ( empty ( $all_schedules_ids ) ) {
2016-10-24 20:33:37 +02:00
return array ( 'error' => 'Schedules could not be found.' );
2015-10-15 22:52:37 +10:00
}
foreach ( $all_schedules_ids as $schedule_id ) {
if ( ! HM\BackUpWordPress\Schedules :: get_instance () -> get_schedule ( $schedule_id ) ) {
continue ;
}
$schedule = new HM\BackUpWordPress\Scheduled_Backup ( sanitize_text_field ( urldecode ( $schedule_id ) ) );
2016-02-15 22:08:39 +01:00
$started_ago = method_exists ( $schedule , 'get_schedule_running_start_time' ) ? $schedule -> get_schedule_running_start_time () : $schedule -> get_schedule_start_time ();
2015-10-15 22:52:37 +10:00
$out = array (
'b' => $this -> get_backupslist_html ( $schedule ),
'count' => count ( $schedule -> get_backups () ),
'file_size_text' => $this -> hmbkp_get_site_size_text ( $schedule ),
2016-02-15 22:08:39 +01:00
'started_ago' => human_time_diff ( $started_ago ),
2015-10-15 22:52:37 +10:00
);
2016-02-15 22:08:39 +01:00
if ( method_exists ( $schedule , 'get_running_backup_filename' )) {
$out [ 'scheduleStatus' ] = $schedule -> get_status ();
} else {
$status = $schedule -> get_status ();
$out [ 'scheduleStatus' ] = $status -> get_status ();
}
2015-10-15 22:52:37 +10:00
$information [ 'backups' ][ $schedule_id ] = $out ;
}
$send_back_schedules = array ();
$schedules = HM\BackUpWordPress\Schedules :: get_instance () -> get_schedules ();
foreach ( $schedules as $schedule ) {
$sch_id = $schedule -> get_id ();
if ( ! in_array ( $sch_id , $scheduleIds ) ) {
$current_option = get_option ( 'hmbkp_schedule_' . $sch_id );
if ( is_array ( $current_option ) ) {
unset ( $current_option [ 'excludes' ] ); // not send this value
2016-02-15 22:08:39 +01:00
$started_ago = method_exists ( $schedule , 'get_schedule_running_start_time' ) ? $schedule -> get_schedule_running_start_time () : $schedule -> get_schedule_start_time ();
2015-10-15 22:52:37 +10:00
$send_back_schedules [ $sch_id ] = array (
'options' => $current_option ,
'b' => $this -> get_backupslist_html ( $schedule ),
'count' => count ( $schedule -> get_backups () ),
'file_size_text' => $this -> hmbkp_get_site_size_text ( $schedule ),
'scheduleStatus' => $schedule -> get_status (),
2016-02-15 22:08:39 +01:00
'started_ago' => human_time_diff ( $started_ago ),
2015-10-15 22:52:37 +10:00
);
2016-02-15 22:08:39 +01:00
if ( method_exists ( $schedule , 'get_running_backup_filename' )) {
$send_back_schedules [ 'scheduleStatus' ] = $schedule -> get_status ();
} else {
$status = $schedule -> get_status ();
$send_back_schedules [ 'scheduleStatus' ] = $status -> get_status ();
}
2015-10-15 22:52:37 +10:00
}
}
}
2020-03-26 14:11:33 +00:00
if ( function_exists ( 'HM\BackUpWordPress\Backup::get_home_path' )) {
2016-02-15 22:08:39 +01:00
$backups_path = str_replace ( HM\BackUpWordPress\Backup :: get_home_path (), '' , hmbkp_path () );
2020-03-26 14:11:33 +00:00
} else {
2016-02-15 22:08:39 +01:00
$backups_path = str_replace ( HM\BackUpWordPress\Path :: get_home_path (), '' , HM\BackUpWordPress\Path :: get_path () );
2020-03-26 14:11:33 +00:00
}
2016-02-15 22:08:39 +01:00
$information [ 'backups_path' ] = $backups_path ;
2015-10-15 22:52:37 +10:00
$information [ 'send_back_schedules' ] = $send_back_schedules ;
$information [ 'result' ] = 'SUCCESS' ;
return $information ;
}
function hmbkp_request_delete_backup () {
if ( ! isset ( $_POST [ 'hmbkp_backuparchive' ] ) || empty ( $_POST [ 'hmbkp_backuparchive' ] ) ) {
2018-06-26 19:52:53 +02:00
return array ( 'error' => __ ( 'Invalid data. Please check and try again.' , 'mainwp-child' ) );
2015-10-15 22:52:37 +10:00
}
$schedule_id = $this -> check_schedule ();
$schedule = new HM\BackUpWordPress\Scheduled_Backup ( sanitize_text_field ( urldecode ( $schedule_id ) ) );
2016-02-15 22:08:39 +01:00
$deleted = $schedule -> delete_backup ( base64_decode ( urldecode ( $_POST [ 'hmbkp_backuparchive' ] )));
2015-10-15 22:52:37 +10:00
if ( is_wp_error ( $deleted ) ) {
return array ( 'error' => $deleted -> get_error_message () );
}
2016-02-15 22:08:39 +01:00
$ret = array (
2015-10-15 22:52:37 +10:00
'result' => 'SUCCESS' ,
'b' => $this -> get_backupslist_html ( $schedule ),
'count' => count ( $schedule -> get_backups () ),
'file_size_text' => $this -> hmbkp_get_site_size_text ( $schedule ),
);
2016-02-15 22:08:39 +01:00
if ( method_exists ( $schedule , 'get_running_backup_filename' )) {
$ret [ 'scheduleStatus' ] = $schedule -> get_status ();
} else {
$status = $schedule -> get_status ();
$ret [ 'scheduleStatus' ] = $status -> get_status ();
}
return $ret ;
2015-10-15 22:52:37 +10:00
}
function get_backupslist_html ( $schedule ) {
ob_start ();
?>
< table class = " widefat " >
< thead >
< tr >
2020-03-26 14:05:04 +00:00
< th scope = " col " >< ? php function_exists ( 'hmbkp_backups_number' ) ? hmbkp_backups_number ( $schedule ) : ( function_exists ( 'backups_number' ) ? backups_number ( $schedule ) : '' ); ?> </th>
2015-10-15 22:52:37 +10:00
< 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>
</ tr >
</ thead >
< tbody >
2020-03-26 14:05:04 +00:00
< ? php
if ( $schedule -> get_backups () ) {
2015-10-15 22:52:37 +10:00
$schedule -> delete_old_backups ();
foreach ( $schedule -> get_backups () as $file ) {
if ( ! file_exists ( $file ) ) {
continue ;
}
$this -> hmbkp_get_backup_row ( $file , $schedule );
}
2020-03-26 14:05:04 +00:00
} else {
?>
2015-10-15 22:52:37 +10:00
< tr >
< td class = " hmbkp-no-backups "
colspan = " 4 " >< ? php esc_html_e ( 'This is where your backups will appear once you have some.' , 'mainwp-backupwordpress-extension' ); ?> </td>
</ tr >
< ? php } ?>
</ tbody >
</ table >
< ? php
$html = ob_get_clean ();
return $html ;
}
function hmbkp_get_site_size_text ( HM\BackUpWordPress\Scheduled_Backup $schedule ) {
2016-02-15 22:08:39 +01:00
if ( method_exists ( $schedule , 'is_site_size_cached' )) {
if ( ( 'database' === $schedule -> get_type () ) || $schedule -> is_site_size_cached () ) {
return sprintf ( '(<code title="' . __ ( 'Backups will be compressed and should be smaller than this.' , 'mainwp-backupwordpress-extension' ) . '">%s</code>)' , esc_attr ( $schedule -> get_formatted_site_size () ) );
}
2015-10-15 22:52:37 +10:00
} else {
2016-02-15 22:08:39 +01:00
$site_size = new HM\BackUpWordPress\Site_Size ( $schedule -> get_type (), $schedule -> get_excludes () );
if ( ( 'database' === $schedule -> get_type () ) || $site_size -> is_site_size_cached () ) {
return sprintf ( '(<code title="' . __ ( 'Backups will be compressed and should be smaller than this.' , 'backupwordpress' ) . '">%s</code>)' , esc_attr ( $site_size -> get_formatted_site_size () ) );
}
2015-10-15 22:52:37 +10:00
}
2016-02-15 22:08:39 +01:00
return sprintf ( '(<code class="calculating" title="' . __ ( 'this shouldn\'t take long…' , 'mainwp-backupwordpress-extension' ) . '">' . __ ( 'calculating the size of your backup…' , 'mainwp-backupwordpress-extension' ) . '</code>)' );
2015-10-15 22:52:37 +10:00
}
function hmbkp_get_backup_row ( $file , HM\BackUpWordPress\Scheduled_Backup $schedule ) {
$encoded_file = urlencode ( base64_encode ( $file ) );
$offset = get_option ( 'gmt_offset' ) * 3600 ;
?>
< tr class = " hmbkp_manage_backups_row " >
< th scope = " row " >
< ? php echo esc_html ( date_i18n ( get_option ( 'date_format' ) . ' - ' . get_option ( 'time_format' ), @ filemtime ( $file ) + $offset ) ); ?>
</ th >
< td class = " code " >
< ? php echo esc_html ( size_format ( @ filesize ( $file ) ) ); ?>
</ td >
2016-02-15 22:08:39 +01:00
< td >< ? php echo function_exists ( 'hmbkp_human_get_type' ) ? esc_html ( hmbkp_human_get_type ( $file , $schedule ) ) : esc_html ( HM\BackUpWordPress\human_get_type ( $file , $schedule )); ?> </td>
2015-10-15 22:52:37 +10:00
< td >
2020-03-26 14:05:04 +00:00
< ? php
if ( function_exists ( 'hmbkp_is_path_accessible' )) {
2016-02-15 22:08:39 +01:00
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> |
2020-03-26 14:05:04 +00:00
< ? php
};
2020-03-26 14:11:33 +00:00
} elseif ( function_exists ( 'HM\BackUpWordPress\is_path_accessible' ) ) {
2016-02-15 22:08:39 +01:00
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> |
2020-03-26 14:05:04 +00:00
< ? php
};
2016-02-15 22:08:39 +01:00
}
?>
2015-10-15 22:52:37 +10:00
< a href = " # "
2016-02-15 22:08:39 +01:00
onclick = " event.preventDefault(); mainwp_backupwp_delete_backup('<?php echo $encoded_file ; ?>', <?php echo esc_attr( $schedule->get_id () ); ?>, this); "
2015-10-15 22:52:37 +10:00
class = " delete-action " >< ? php esc_html_e ( 'Delete' , 'backupwordpress' ); ?> </a>
</ td >
</ tr >
2020-03-26 14:05:04 +00:00
< ? php
}
2015-10-15 22:52:37 +10:00
function get_excluded ( $browse_dir = null ) {
$schedule_id = $this -> check_schedule ();
$schedule = new HM\BackUpWordPress\Scheduled_Backup ( sanitize_text_field ( urldecode ( $schedule_id ) ) );
2016-03-03 20:28:07 +01:00
$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 ();
$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 ();
$is_size_calculated = HM\BackUpWordPress\Site_Size :: is_site_size_being_calculated ();
}
2015-10-15 22:52:37 +10:00
ob_start ();
?>
< div class = " hmbkp-exclude-settings " >
2016-03-03 20:28:07 +01:00
< ? php //if ( $schedule->get_excludes() ) : ?>
2015-10-15 22:52:37 +10:00
2016-03-03 20:28:07 +01:00
< h3 >
< ? php esc_html_e ( 'Currently Excluded' , 'backupwordpress' ); ?>
</ h3 >
2015-10-15 22:52:37 +10:00
2016-03-03 20:28:07 +01:00
< p >< ? php esc_html_e ( 'We automatically detect and ignore common <abbr title="Version Control Systems">VCS</abbr> folders and other backup plugin folders.' , 'backupwordpress' ); ?> </p>
2015-10-15 22:52:37 +10:00
2016-03-03 20:28:07 +01:00
< table class = " widefat " >
2015-10-15 22:52:37 +10:00
2016-03-03 20:28:07 +01:00
< tbody >
< ? php foreach ( $user_excludes as $key => $exclude ) : ?>
2015-10-15 22:52:37 +10:00
2016-03-03 20:28:07 +01:00
< ? php $exclude_path = new SplFileInfo ( trailingslashit ( $root_dir ) . ltrim ( str_ireplace ( $root_dir , '' , $exclude ), '/' ) ); ?>
2015-10-15 22:52:37 +10:00
2016-03-03 20:28:07 +01:00
< tr >
2015-10-15 22:52:37 +10:00
2016-03-03 20:28:07 +01:00
< th scope = " row " >
2015-10-15 22:52:37 +10:00
2016-03-03 20:28:07 +01:00
< ? php if ( $exclude_path -> isFile () ) { ?>
2015-10-15 22:52:37 +10:00
2016-03-03 20:28:07 +01:00
< div class = " dashicons dashicons-media-default " ></ div >
2015-10-15 22:52:37 +10:00
2016-03-03 20:28:07 +01:00
< ? php } elseif ( $exclude_path -> isDir () ) { ?>
2015-10-15 22:52:37 +10:00
2016-03-03 20:28:07 +01:00
< div class = " dashicons dashicons-portfolio " ></ div >
2015-10-15 22:52:37 +10:00
2016-03-03 20:28:07 +01:00
< ? php } ?>
2015-10-15 22:52:37 +10:00
2016-03-03 20:28:07 +01:00
</ th >
2015-10-15 22:52:37 +10:00
2016-03-03 20:28:07 +01:00
< td >
< code >
< ? php echo esc_html ( str_ireplace ( $root_dir , '' , $exclude ) ); ?>
</ code >
2015-10-15 22:52:37 +10:00
2016-03-03 20:28:07 +01:00
</ td >
2015-10-15 22:52:37 +10:00
2016-03-03 20:28:07 +01:00
< td >
< ? php
2020-03-26 14:11:33 +00:00
if ( $new_version ) {
2016-03-03 20:28:07 +01:00
$is_default_rule = ( in_array ( $exclude , $excludes -> get_default_excludes () ) ) || ( HM\BackUpWordPress\Path :: get_path () === trailingslashit ( HM\BackUpWordPress\Path :: get_root () ) . untrailingslashit ( $exclude ) );
2020-03-26 14:11:33 +00:00
} else {
2020-03-26 14:05:04 +00:00
$is_default_rule = ( in_array ( $exclude , $schedule -> backup -> default_excludes () ) ) || ( hmbkp_path () === untrailingslashit ( $exclude ) );
2020-03-26 14:11:33 +00:00
}
2015-10-15 22:52:37 +10:00
2020-03-26 14:05:04 +00:00
if ( $is_default_rule ) :
?>
2016-03-03 20:28:07 +01:00
< ? php esc_html_e ( 'Default rule' , 'backupwordpress' ); ?>
2015-10-15 22:52:37 +10:00
2016-03-03 20:28:07 +01:00
< ? php elseif ( defined ( 'HMBKP_EXCLUDE' ) && false !== strpos ( HMBKP_EXCLUDE , $exclude ) ) : ?>
2015-10-15 22:52:37 +10:00
2016-03-03 20:28:07 +01:00
< ? php esc_html_e ( 'Defined in wp-config.php' , 'backupwordpress' ); ?>
2015-10-15 22:52:37 +10:00
2016-03-03 20:28:07 +01:00
< ? php else : ?>
2015-10-15 22:52:37 +10:00
2016-03-03 20:28:07 +01:00
< a href = " # "
onclick = " event.preventDefault(); mainwp_backupwp_remove_exclude_rule('<?php esc_attr_e( $exclude ); ?>', this); "
class = " delete-action " >< ? php esc_html_e ( 'Stop excluding' , 'backupwordpress' ); ?> </a>
2015-10-15 22:52:37 +10:00
2016-03-03 20:28:07 +01:00
< ? php endif ; ?>
2015-10-15 22:52:37 +10:00
2016-03-03 20:28:07 +01:00
</ td >
2015-10-15 22:52:37 +10:00
2016-03-03 20:28:07 +01:00
</ tr >
2015-10-15 22:52:37 +10:00
2016-03-03 20:28:07 +01:00
< ? php endforeach ; ?>
2015-10-15 22:52:37 +10:00
2016-03-03 20:28:07 +01:00
</ tbody >
2015-10-15 22:52:37 +10:00
2016-03-03 20:28:07 +01:00
</ table >
2015-10-15 22:52:37 +10:00
2016-03-03 20:28:07 +01:00
< ? php //endif; ?>
2015-10-15 22:52:37 +10:00
2016-03-03 20:28:07 +01:00
< h3 id = " directory-listing " >< ? php esc_html_e ( 'Your Site' , 'backupwordpress' ); ?> </h3>
2015-10-15 22:52:37 +10:00
< p >< ? php esc_html_e ( 'Here\'s a directory listing of all files on your site, you can browse through and exclude files or folders that you don\'t want included in your backup.' , 'backupwordpress' ); ?> </p>
< ? php
2018-09-27 19:52:32 +02:00
// The directory to display
2016-03-03 20:28:07 +01:00
$directory = $root_dir ;
2015-10-15 22:52:37 +10:00
if ( isset ( $browse_dir ) ) {
$untrusted_directory = urldecode ( $browse_dir );
// Only allow real sub directories of the site root to be browsed
2016-03-03 20:28:07 +01:00
if ( false !== strpos ( $untrusted_directory , $root_dir ) && is_dir ( $untrusted_directory ) ) {
2015-10-15 22:52:37 +10:00
$directory = $untrusted_directory ;
}
}
// Kick off a recursive filesize scan
2016-03-03 20:28:07 +01:00
if ( $new_version ) {
2020-03-26 14:05:04 +00:00
$site_size = new HM\BackUpWordPress\Site_Size ();
2016-03-03 20:28:07 +01:00
$exclude_string = implode ( '|' , $excludes -> get_excludes_for_regex () );
2020-03-26 14:11:33 +00:00
if ( function_exists ( 'HM\BackUpWordPress\list_directory_by_total_filesize' )) {
2016-04-27 21:54:28 +02:00
$files = HM\BackUpWordPress\list_directory_by_total_filesize ( $directory , $excludes );
2020-03-26 14:11:33 +00:00
}
2016-03-03 20:28:07 +01:00
} else {
$files = $schedule -> list_directory_by_total_filesize ( $directory );
$exclude_string = $schedule -> backup -> exclude_string ( 'regex' );
}
2015-10-15 22:52:37 +10:00
2020-03-26 14:05:04 +00:00
if ( $files ) {
?>
2015-10-15 22:52:37 +10:00
< table class = " widefat " >
< thead >
< tr >
< th ></ th >
< th scope = " col " >< ? php esc_html_e ( 'Name' , 'backupwordpress' ); ?> </th>
< th scope = " col " class = " column-format " >< ? php esc_html_e ( 'Size' , 'backupwordpress' ); ?> </th>
< th scope = " col "
class = " column-format " >< ? php esc_html_e ( 'Permissions' , 'backupwordpress' ); ?> </th>
< th scope = " col " class = " column-format " >< ? php esc_html_e ( 'Type' , 'backupwordpress' ); ?> </th>
< th scope = " col " class = " column-format " >< ? php esc_html_e ( 'Status' , 'backupwordpress' ); ?> </th>
</ tr >
< tr >
< th scope = " row " >
< div class = " dashicons dashicons-admin-home " ></ div >
</ th >
< th scope = " col " >
2020-03-26 14:05:04 +00:00
< ? php
if ( $root_dir !== $directory ) {
2015-10-15 22:52:37 +10:00
// echo esc_url( remove_query_arg( 'hmbkp_directory_browse' ) );
?>
< a href = " # "
2016-03-03 20:28:07 +01:00
onclick = " event.preventDefault(); mainwp_backupwp_directory_browse('', this) " >< ? php echo esc_html ( $root_dir ); ?> </a>
2015-10-15 22:52:37 +10:00
< code >/</ code >
2020-03-26 14:05:04 +00:00
< ? php
$parents = array_filter ( explode ( '/' , str_replace ( trailingslashit ( $root_dir ), '' , trailingslashit ( dirname ( $directory ) ) ) ) );
2015-10-15 22:52:37 +10:00
2020-03-26 14:05:04 +00:00
foreach ( $parents as $directory_basename ) {
?>
2015-10-15 22:52:37 +10:00
< 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>
< code >/</ code >
< ? php } ?>
< ? php echo esc_html ( basename ( $directory ) ); ?>
< ? php } else { ?>
2016-03-03 20:28:07 +01:00
< ? php echo esc_html ( $root_dir ); ?>
2015-10-15 22:52:37 +10:00
< ? php } ?>
</ th >
< td class = " column-filesize " >
2016-03-03 20:28:07 +01:00
< ? php if ( $is_size_calculated ) : ?>
2015-10-15 22:52:37 +10:00
2016-03-03 20:28:07 +01:00
< span class = " spinner " ></ span >
2015-10-15 22:52:37 +10:00
< ? php
else :
2016-03-03 20:28:07 +01:00
$root = new SplFileInfo ( $root_dir );
2015-10-15 22:52:37 +10:00
2016-03-03 20:28:07 +01:00
if ( $new_version ) {
$size = $site_size -> filesize ( $root );
} else {
$size = $schedule -> filesize ( $root , true );
}
2015-10-15 22:52:37 +10:00
if ( false !== $size ) {
$size = size_format ( $size );
if ( ! $size ) {
$size = '0 B' ;
}
?>
< code >
< ? php echo esc_html ( $size ); ?>
< a class = " dashicons dashicons-update "
2016-03-03 20:28:07 +01:00
href = " <?php echo esc_attr( wp_nonce_url( add_query_arg( 'hmbkp_recalculate_directory_filesize', urlencode( $root_dir ) ), 'hmbkp-recalculate_directory_filesize' ) ); ?> " >< span >< ? php esc_html_e ( 'Refresh' , 'backupwordpress' ); ?> </span></a>
2015-10-15 22:52:37 +10:00
</ code >
< ? php } ?>
< ? php endif ; ?>
< td >
2016-03-03 20:28:07 +01:00
< ? php echo esc_html ( substr ( sprintf ( '%o' , fileperms ( $root_dir ) ), - 4 ) ); ?>
2015-10-15 22:52:37 +10:00
</ td >
< td >
< ? php
2016-03-03 20:28:07 +01:00
if ( is_link ( $root_dir ) ) {
2015-10-15 22:52:37 +10:00
esc_html_e ( 'Symlink' , 'backupwordpress' );
2016-03-03 20:28:07 +01:00
} elseif ( is_dir ( $root_dir ) ) {
2015-10-15 22:52:37 +10:00
esc_html_e ( 'Folder' , 'backupwordpress' );
}
?>
</ td >
< td ></ td >
</ tr >
</ thead >
< tbody >
2020-03-26 14:05:04 +00:00
< ? php
foreach ( $files as $size => $file ) {
2015-10-15 22:52:37 +10:00
$is_excluded = $is_unreadable = false ;
// Check if the file is excluded
2016-03-03 20:28:07 +01:00
if ( $new_version ) {
if ( $exclude_string && preg_match ( '(' . $exclude_string . ')' , str_ireplace ( trailingslashit ( $root_dir ), '' , wp_normalize_path ( $file -> getPathname () ) ) ) ) {
$is_excluded = true ;
}
} else {
if ( $exclude_string && preg_match ( '(' . $exclude_string . ')' , str_ireplace ( trailingslashit ( $root_dir ), '' , HM\BackUpWordPress\Backup :: conform_dir ( $file -> getPathname () ) ) ) ) {
$is_excluded = true ;
}
2015-10-15 22:52:37 +10:00
}
// Skip unreadable files
if ( ! @ realpath ( $file -> getPathname () ) || ! $file -> isReadable () ) {
$is_unreadable = true ;
2020-03-26 14:05:04 +00:00
}
?>
2015-10-15 22:52:37 +10:00
< tr >
< td >
< ? php if ( $is_unreadable ) { ?>
< div class = " dashicons dashicons-dismiss " ></ div >
< ? php } elseif ( $file -> isFile () ) { ?>
< div class = " dashicons dashicons-media-default " ></ div >
< ? php } elseif ( $file -> isDir () ) { ?>
< div class = " dashicons dashicons-portfolio " ></ div >
< ? php } ?>
</ td >
< td >
2016-03-03 20:28:07 +01:00
< ? php
if ( $new_version ) {
2020-03-26 14:05:04 +00:00
if ( $is_unreadable ) {
?>
2015-10-15 22:52:37 +10:00
2016-03-03 20:28:07 +01:00
< code class = " strikethrough "
title = " <?php echo esc_attr( wp_normalize_path( $file->getRealPath () ) ); ?> " >< ? php echo esc_html ( $file -> getBasename () ); ?> </code>
2015-10-15 22:52:37 +10:00
2016-03-03 20:28:07 +01:00
< ? php } elseif ( $file -> isFile () ) { ?>
2015-10-15 22:52:37 +10:00
2016-03-03 20:28:07 +01:00
< code
title = " <?php echo esc_attr( wp_normalize_path( $file->getRealPath () ) ); ?> " >< ? php echo esc_html ( $file -> getBasename () ); ?> </code>
2015-10-15 22:52:37 +10:00
2016-03-03 20:28:07 +01:00
< ? php } elseif ( $file -> isDir () ) { ?>
< code title = " <?php echo esc_attr( $file->getRealPath () ); ?> " >< a
href = " # "
onclick = " event.preventDefault(); mainwp_backupwp_directory_browse('<?php echo urlencode( wp_normalize_path( $file->getPathname ()) ); ?>', this) " >< ? php echo esc_html ( $file -> getBasename () ); ?> </a></code>
2015-10-15 22:52:37 +10:00
2020-03-26 14:05:04 +00:00
< ? php
}
2016-03-03 20:28:07 +01:00
} else {
2020-03-26 14:05:04 +00:00
if ( $is_unreadable ) {
?>
2016-03-03 20:28:07 +01:00
< code class = " strikethrough "
title = " <?php echo esc_attr( $file->getRealPath () ); ?> " >< ? php echo esc_html ( $file -> getBasename () ); ?> </code>
< ? php } elseif ( $file -> isFile () ) { ?>
< code
title = " <?php echo esc_attr( $file->getRealPath () ); ?> " >< ? php echo esc_html ( $file -> getBasename () ); ?> </code>
2020-03-26 14:05:04 +00:00
< ? php
} elseif ( $file -> isDir () ) {
2016-03-03 20:28:07 +01:00
//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>
2020-03-26 14:05:04 +00:00
< ? php
}
2016-03-03 20:28:07 +01:00
}
?>
2015-10-15 22:52:37 +10:00
</ td >
< td class = " column-format column-filesize " >
2016-03-03 20:28:07 +01:00
< ? php if ( $file -> isDir () && $is_size_calculated ) : ?>
2015-10-15 22:52:37 +10:00
< span class = " spinner " ></ span >
2016-02-15 22:08:39 +01:00
< ? php
2015-10-15 22:52:37 +10:00
else :
2016-03-03 20:28:07 +01:00
if ( $new_version ) {
$size = $site_size -> filesize ( $file );
} else {
$size = $schedule -> filesize ( $file );
}
2015-10-15 22:52:37 +10:00
if ( false !== $size ) {
$size = size_format ( $size );
if ( ! $size ) {
$size = '0 B' ;
2020-03-26 14:05:04 +00:00
}
?>
2015-10-15 22:52:37 +10:00
< code >
< ? php echo esc_html ( $size ); ?>
< ? php if ( $file -> isDir () ) { ?>
< a title = " <?php esc_attr_e( 'Recalculate the size of this directory', 'backupwordpress' ); ?> "
class = " dashicons dashicons-update "
2016-03-03 20:28:07 +01:00
href = " <?php echo esc_attr( wp_nonce_url( add_query_arg( 'hmbkp_recalculate_directory_filesize', urlencode( wp_normalize_path( $file->getPathname () ) ) ), 'hmbkp-recalculate_directory_filesize' ) ); ?> " >< span >< ? php esc_html_e ( 'Refresh' , 'backupwordpress' ); ?> </span></a>
2015-10-15 22:52:37 +10:00
< ? php } ?>
</ code >
< ? php } else { ?>
< code >--</ code >
2020-03-26 14:05:04 +00:00
< ? php
}
2015-10-15 22:52:37 +10:00
endif ;
?>
</ td >
< td >
< ? php echo esc_html ( substr ( sprintf ( '%o' , $file -> getPerms () ), - 4 ) ); ?>
</ td >
< td >
< ? php if ( $file -> isLink () ) : ?>
< span
2016-03-03 20:28:07 +01:00
title = " <?php echo esc_attr( wp_normalize_path( $file->GetRealPath () ) ); ?> " >< ? php esc_html_e ( 'Symlink' , 'backupwordpress' ); ?> </span>
2015-10-15 22:52:37 +10:00
2020-03-26 14:05:04 +00:00
< ? php
elseif ( $file -> isDir () ) :
2015-10-15 22:52:37 +10:00
esc_html_e ( 'Folder' , 'backupwordpress' );
else :
esc_html_e ( 'File' , 'backupwordpress' );
endif ;
?>
</ td >
< td class = " column-format " >
< ? php if ( $is_unreadable ) : ?>
< strong
title = " <?php esc_attr_e( 'Unreadable files won \ 't be backed up.', 'backupwordpress' ); ?> " >< ? php esc_html_e ( 'Unreadable' , 'backupwordpress' ); ?> </strong>
< ? php elseif ( $is_excluded ) : ?>
< strong >< ? php esc_html_e ( 'Excluded' , 'backupwordpress' ); ?> </strong>
2016-02-15 22:08:39 +01:00
< ? php
2015-10-15 22:52:37 +10:00
else :
$exclude_path = $file -> getPathname ();
// Excluded directories need to be trailingslashed
if ( $file -> isDir () ) {
2016-03-03 20:28:07 +01:00
$exclude_path = trailingslashit ( wp_normalize_path ( $file -> getPathname () ) );
2015-10-15 22:52:37 +10:00
}
?>
< a href = " # "
onclick = " event.preventDefault(); mainwp_backupwp_exclude_add_rule('<?php echo urlencode( $exclude_path ); ?>', this) "
class = " button-secondary " >< ? php esc_html_e ( 'Exclude →' , 'backupwordpress' ); ?> </a>
< ? php endif ; ?>
</ td >
</ tr >
< ? php } ?>
</ tbody >
</ table >
< ? php } ?>
< p class = " submit " >
< a href = " # " onclick = " event.preventDefault(); mainwp_backupwp_edit_exclude_done() "
class = " button-primary " >< ? php esc_html_e ( 'Done' , 'backupwordpress' ); ?> </a>
</ p >
</ div >
< ? php
$output = ob_get_clean ();
$information [ 'e' ] = $output ;
return $information ;
}
function directory_browse () {
$browse_dir = $_POST [ 'browse_dir' ];
$out = array ();
$return = $this -> get_excluded ( $browse_dir );
$out [ 'e' ] = $return [ 'e' ];
$out [ 'current_browse_dir' ] = $browse_dir ;
return $out ;
}
function hmbkp_add_exclude_rule () {
if ( ! isset ( $_POST [ 'exclude_pathname' ] ) || empty ( $_POST [ 'exclude_pathname' ] ) ) {
return array ( 'error' => __ ( 'Error: Empty exclude directory path.' ) );
}
$schedule_id = $this -> check_schedule ();
$schedule = new HM\BackUpWordPress\Scheduled_Backup ( sanitize_text_field ( $schedule_id ) );
$exclude_rule = urldecode ( $_POST [ 'exclude_pathname' ] );
$schedule -> set_excludes ( $exclude_rule , true );
$schedule -> save ();
$current_path = urldecode ( $_POST [ 'browse_dir' ] );
if ( empty ( $current_path ) ) {
$current_path = null ;
}
$return = $this -> get_excluded ( $current_path );
$out [ 'e' ] = $return [ 'e' ];
$out [ 'current_browse_dir' ] = $_POST [ 'browse_dir' ];
return $out ;
}
function hmbkp_remove_exclude_rule () {
if ( ! isset ( $_POST [ 'remove_rule' ] ) || empty ( $_POST [ 'remove_rule' ] ) ) {
return array ( 'error' => __ ( 'Error: Empty exclude directory path.' ) );
}
$schedule_id = $this -> check_schedule ();
$schedule = new HM\BackUpWordPress\Scheduled_Backup ( sanitize_text_field ( $schedule_id ) );
$excludes = $schedule -> get_excludes ();
2016-03-03 20:28:07 +01:00
$exclude_rule_to_remove = stripslashes ( sanitize_text_field ( $_POST [ 'remove_rule' ] ) );
2015-10-15 22:52:37 +10:00
2016-03-03 20:28:07 +01:00
if ( method_exists ( $excludes , 'get_user_excludes' )) {
$schedule -> set_excludes ( array_diff ( $excludes -> get_user_excludes (), ( array ) $exclude_rule_to_remove ) );
2020-03-26 14:11:33 +00:00
} else {
2016-03-03 20:28:07 +01:00
$schedule -> set_excludes ( array_diff ( $excludes , $exclude_rule_to_remove ) );
2020-03-26 14:11:33 +00:00
}
2015-10-15 22:52:37 +10:00
$schedule -> save ();
$current_path = urldecode ( $_POST [ 'browse_dir' ] );
if ( empty ( $current_path ) ) {
$current_path = null ;
}
$return = $this -> get_excluded ( $current_path );
$out [ 'e' ] = $return [ 'e' ];
$out [ 'current_browse_dir' ] = $_POST [ 'browse_dir' ];
return $out ;
}
2016-03-03 20:28:07 +01:00
2018-09-27 19:52:32 +02:00
function general_exclude_add_rule () {
2016-03-03 20:28:07 +01:00
2018-09-27 19:52:32 +02:00
$sch_id = $this -> check_schedule ();
$schedule = new HM\BackUpWordPress\Scheduled_Backup ( sanitize_text_field ( $sch_id ) );
2016-03-03 20:28:07 +01:00
2018-09-27 19:52:32 +02:00
$exclude_paths = urldecode ( $_POST [ 'exclude_paths' ] );
$exclude_paths = explode ( " \n " , $exclude_paths );
if ( is_array ( $exclude_paths ) && count ( $exclude_paths ) > 0 ) {
foreach ( $exclude_paths as $excl_rule ) {
$excl_rule = trim ( $excl_rule );
$excl_rule = trim ( $excl_rule , '/' );
2016-03-03 20:28:07 +01:00
2020-03-26 14:11:33 +00:00
if ( empty ( $excl_rule )) {
2018-09-27 19:52:32 +02:00
continue ;
2020-03-26 14:11:33 +00:00
}
2016-03-03 20:28:07 +01:00
2018-09-27 19:52:32 +02:00
$exclude_rule = ABSPATH . $excl_rule ;
$path = realpath ( $exclude_rule );
// If it exist
if ( $path !== false )
{
$schedule -> set_excludes ( $exclude_rule , true );
$schedule -> save ();
}
}
}
2016-03-03 20:28:07 +01:00
2018-09-27 19:52:32 +02:00
$un_exclude_paths = urldecode ( $_POST [ 'un_exclude_paths' ] );
$un_exclude_paths = explode ( " \n " , $un_exclude_paths );
2016-03-03 20:28:07 +01:00
2018-09-27 19:52:32 +02:00
if ( is_array ( $un_exclude_paths ) && count ( get_user_excludes ) > 0 ) {
foreach ( $un_exclude_paths as $exclude_rule_to_remove ) {
$exclude_rule_to_remove = trim ( $exclude_rule_to_remove );
$exclude_rule_to_remove = trim ( $exclude_rule_to_remove , '/' );
2020-03-26 14:11:33 +00:00
if ( empty ( $exclude_rule_to_remove )) {
2018-09-27 19:52:32 +02:00
continue ;
2020-03-26 14:11:33 +00:00
}
2018-09-27 19:52:32 +02:00
$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 ) );
}
$schedule -> save ();
}
}
return array ( 'result' => 'SUCCESS' );
}
2016-03-03 20:28:07 +01:00
2015-10-15 22:52:37 +10:00
function update_schedule () {
$sch_id = isset ( $_POST [ 'schedule_id' ] ) ? $_POST [ 'schedule_id' ] : 0 ;
$sch_id = sanitize_text_field ( urldecode ( $sch_id ) );
2015-12-05 17:38:52 +01:00
$options = isset ( $_POST [ 'options' ] ) ? maybe_unserialize ( base64_decode ( $_POST [ 'options' ] ) ) : false ;
2015-10-15 22:52:37 +10:00
if ( ! is_array ( $options ) || empty ( $options ) || empty ( $sch_id ) ) {
return array ( 'error' => 'Error: Schedule data' );
}
2016-02-15 22:08:39 +01:00
// $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'];
// }
2015-10-15 22:52:37 +10:00
$filter_opts = array (
'type' ,
'email' ,
'reoccurrence' ,
'max_backups' ,
'schedule_start_time' ,
);
$out = array ();
if ( is_array ( $options ) ) {
$old_options = get_option ( 'hmbkp_schedule_' . $sch_id );
if ( is_array ( $old_options ) ) {
foreach ( $old_options as $key => $val ) {
if ( ! in_array ( $key , $filter_opts ) ) {
$options [ $key ] = $old_options [ $key ];
}
}
}
update_option ( 'hmbkp_schedule_' . $sch_id , $options );
2018-09-27 19:52:32 +02:00
delete_transient ( 'hmbkp_schedules' );
2015-10-15 22:52:37 +10:00
$out [ 'result' ] = 'SUCCESS' ;
} else {
$out [ 'result' ] = 'NOTCHANGE' ;
}
2016-02-15 22:08:39 +01:00
$schedule = new HM\BackUpWordPress\Scheduled_Backup ( sanitize_text_field ( $sch_id ) );
2015-10-15 22:52:37 +10:00
if ( ! empty ( $options [ 'reoccurrence' ] ) && ! empty ( $options [ 'schedule_start_time' ] ) ) {
// Calculate the start time depending on the recurrence
$start_time = $options [ 'schedule_start_time' ];
if ( $start_time ) {
$schedule -> set_schedule_start_time ( $start_time );
}
}
if ( ! empty ( $options [ 'reoccurrence' ] ) ) {
$schedule -> set_reoccurrence ( $options [ 'reoccurrence' ] );
}
$out [ 'next_occurrence' ] = $schedule -> get_next_occurrence ( false );
return $out ;
}
2016-02-15 22:08:39 +01:00
public function save_all_schedules () {
$schedules = isset ( $_POST [ 'all_schedules' ] ) ? maybe_unserialize ( base64_decode ( $_POST [ 'all_schedules' ] ) ) : false ;
if ( ! is_array ( $schedules ) || empty ( $schedules ) ) {
return array ( 'error' => 'Error: Schedule data' );
}
$out = array ();
foreach ( $schedules as $sch_id => $sch ) {
2020-03-26 14:11:33 +00:00
if ( empty ( $sch_id ) || ! isset ( $sch [ 'options' ] ) || ! is_array ( $sch [ 'options' ] ) ) {
2016-02-15 22:08:39 +01:00
continue ;
2020-03-26 14:11:33 +00:00
}
2016-02-15 22:08:39 +01:00
$options = $sch [ 'options' ];
$filter_opts = array (
'type' ,
'email' ,
'reoccurrence' ,
'max_backups' ,
'schedule_start_time' ,
);
if ( is_array ( $options ) ) {
$old_options = get_option ( 'hmbkp_schedule_' . $sch_id );
if ( is_array ( $old_options ) ) {
foreach ( $old_options as $key => $val ) {
if ( ! in_array ( $key , $filter_opts ) ) {
$options [ $key ] = $old_options [ $key ];
}
}
}
update_option ( 'hmbkp_schedule_' . $sch_id , $options );
}
$schedule = new HM\BackUpWordPress\Scheduled_Backup ( sanitize_text_field ( $sch_id ) );
if ( ! empty ( $options [ 'reoccurrence' ] ) && ! empty ( $options [ 'schedule_start_time' ] ) ) {
// Calculate the start time depending on the recurrence
$start_time = $options [ 'schedule_start_time' ];
if ( $start_time ) {
$schedule -> set_schedule_start_time ( $start_time );
}
}
if ( ! empty ( $options [ 'reoccurrence' ] ) ) {
$schedule -> set_reoccurrence ( $options [ 'reoccurrence' ] );
}
$out [ 'result' ] = 'SUCCESS' ;
}
2016-10-24 20:33:37 +02:00
delete_transient ( 'hmbkp_schedules' );
2016-02-15 22:08:39 +01:00
return $out ;
}
2015-10-15 22:52:37 +10:00
public static function isActivated () {
if ( ! defined ( 'HMBKP_PLUGIN_PATH' ) || ! class_exists ( 'HM\BackUpWordPress\Plugin' ) ) {
return false ;
}
return true ;
}
public function all_plugins ( $plugins ) {
foreach ( $plugins as $key => $value ) {
$plugin_slug = basename ( $key , '.php' );
if ( 'backupwordpress' === $plugin_slug ) {
unset ( $plugins [ $key ] );
}
}
return $plugins ;
}
public function remove_menu () {
global $submenu ;
if ( isset ( $submenu [ 'tools.php' ] ) ) {
foreach ( $submenu [ 'tools.php' ] as $index => $item ) {
if ( 'backupwordpress' === $item [ 2 ] ) {
unset ( $submenu [ 'tools.php' ][ $index ] );
break ;
}
}
}
$pos = stripos ( $_SERVER [ 'REQUEST_URI' ], 'tools.php?page=backupwordpress' );
if ( false !== $pos ) {
wp_redirect ( get_option ( 'siteurl' ) . '/wp-admin/index.php' );
exit ();
}
}
}