Файловый менеджер - Редактировать - /home/infrafs/INFRABIKEIT/wp-content/plugins/wpvivid-backup-mainwp.tar
Назад
wpvivid-backup-mainwp-option.php 0000644 00000117633 15133715745 0013035 0 ustar 00 <?php class Mainwp_WPvivid_Extension_Option { private static $instance = null; private $table_prefix; static function get_instance() { if ( null == Mainwp_WPvivid_Extension_Option::$instance ) { Mainwp_WPvivid_Extension_Option::$instance = new Mainwp_WPvivid_Extension_Option(); } return Mainwp_WPvivid_Extension_Option::$instance; } function __construct() { global $wpdb; $this->table_prefix = $wpdb->prefix . 'mainwp_'; } function get_table_name( $suffix ) { return $this->table_prefix . $suffix; } function init_options() { global $wpdb; $charset_collate = $wpdb->get_charset_collate(); if(!class_exists('dbDelta')) require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); $query='CREATE TABLE `'.$this->get_table_name('wpvivid').'` ( `site_id` int(11) NOT NULL, `individual` int NOT NULL DEFAULT 0, `is_pro` int NOT NULL DEFAULT 0, `is_install` int NOT NULL DEFAULT 0, `is_login` int NOT NULL DEFAULT 0, `latest_version` longtext NOT NULL DEFAULT "", `time_zone` int NOT NULL DEFAULT 0, `need_update` int NOT NULL DEFAULT 0, `current_version` longtext NOT NULL DEFAULT "", `backup_custom_setting` longtext NOT NULL DEFAULT "", `schedule` longtext NOT NULL DEFAULT "", `schedule_addon` longtext NOT NULL DEFAULT "", `remote` longtext NOT NULL DEFAULT "", `remote_addon` longtext NOT NULL DEFAULT "", `settings_addon` longtext NOT NULL DEFAULT "", `report_addon` longtext NOT NULL DEFAULT "", `sync_remote_setting` longtext NOT NULL DEFAULT "", `sync_error` longtext NOT NULL DEFAULT "", `settings` longtext NOT NULL DEFAULT "", PRIMARY KEY (`site_id`) ) ' . $charset_collate; dbDelta( $query ); $query='CREATE TABLE `'.$this->get_table_name('wpvivid_global').'` ( `global` int(11) NOT NULL, `select_pro` longtext NOT NULL DEFAULT "", `sync_init_addon_first` longtext NOT NULL DEFAULT "", `switch_pro_setting_page` longtext NOT NULL DEFAULT "", `backup_custom_setting` longtext NOT NULL DEFAULT "", `remote` longtext NOT NULL DEFAULT "", `remote_addon` longtext NOT NULL DEFAULT "", `schedule` longtext NOT NULL DEFAULT "", `schedule_addon` longtext NOT NULL DEFAULT "", `settings_addon` longtext NOT NULL DEFAULT "", `login_addon` longtext NOT NULL DEFAULT "", `settings` longtext NOT NULL DEFAULT "", PRIMARY KEY (`global`) ) ' . $charset_collate; dbDelta( $query ); } function wpvivid_update_single_option($site_id, $option, $value){ global $wpdb; $data[$option] = $value; if($this->is_set_options( $site_id,$option )===false) { $data['site_id']=$site_id; $wpdb->insert( $this->get_table_name( 'wpvivid' ), $data ); } else { $wpdb->update($this->get_table_name('wpvivid'),$data,array( 'site_id' => intval( $site_id ))); } } function wpvivid_get_single_option($site_id, $option, $default = false){ global $wpdb; $sql = $wpdb->prepare( 'SELECT * FROM ' . $this->get_table_name( 'wpvivid' ) . ' WHERE `site_id` = %d ', $site_id ); $options = $wpdb->get_results( $sql,ARRAY_A ); if(isset($options[0][$option])){ $value = $options[0][$option]; } else{ $value = $default; } $value = maybe_unserialize( $value ); return $value; } function sync_options($site_id,$data) { global $wpdb; $sql = $wpdb->prepare( 'SELECT * FROM ' . $this->get_table_name( 'wpvivid' ) . ' WHERE `site_id` = %d ', $site_id ); $options = $wpdb->get_results( $sql ,ARRAY_A); if(isset($options[0])==false) { $data['site_id']=$site_id; $wpdb->insert( $this->get_table_name( 'wpvivid' ), $data ); } else { $wpdb->update($this->get_table_name('wpvivid'),$data,array( 'site_id' => intval( $site_id ))); } } function set_global_options($data) { global $wpdb; $sql = 'SELECT * FROM ' . $this->get_table_name( 'wpvivid_global' ) . ' WHERE `global` = 1 '; $options = $wpdb->get_results( $sql ,ARRAY_A); if(isset($options[0])==false) { $data['global']=1; $wpdb->insert( $this->get_table_name( 'wpvivid_global' ), $data ); } else { $wpdb->update($this->get_table_name('wpvivid_global'),$data,array( 'global' => intval( 1 ))); } return true; } function is_vaild_child_site($site_id) { global $wpdb; $sql = $wpdb->prepare( 'SELECT * FROM ' . $this->get_table_name( 'wp' ) . ' WHERE `id` = %d', $site_id ); $options = $wpdb->get_results($sql, ARRAY_A); if(isset($options[0])){ return true; } else{ return false; } } function is_set_options($site_id,$option_name) { global $wpdb; $sql = $wpdb->prepare( 'SELECT '.$option_name.' FROM ' . $this->get_table_name( 'wpvivid' ) . ' WHERE `site_id` = %d ', $site_id ); $options = $wpdb->get_results( $sql ,ARRAY_A); if(isset($options[0])==false) { return false; } else { if(empty($options[0])) return false; else return true; } } function delete_site($site_id) { global $wpdb; $sql = $wpdb->prepare( 'DELETE FROM ' . $this->get_table_name( 'wpvivid' ) . ' WHERE `site_id`=%d ', $site_id ); $wpdb->query( $sql ); } function get_options($site_id) { global $wpdb; $sql = $wpdb->prepare( 'SELECT * FROM ' . $this->get_table_name( 'wpvivid' ) . ' WHERE `site_id` = %d ', $site_id ); $options = $wpdb->get_results( $sql,ARRAY_A ); if(isset($options[0])){ //$options = @unserialize($options[0]); return $options[0]; } else return false; return $options; }// function get_individual($site_id) { global $wpdb; $sql = $wpdb->prepare( 'SELECT * FROM ' . $this->get_table_name( 'wpvivid' ) . ' WHERE `site_id` = %d ', $site_id ); $options = $wpdb->get_results( $sql,ARRAY_A ); if(isset($options[0]['individual'])) return $options[0]['individual']; else return false; }// function set_individual($site_id,$value) { global $wpdb; $data['individual']=intval($value); if($this->is_set_options( $site_id,'individual' )===false) { $data['site_id']=$site_id; $wpdb->insert( $this->get_table_name( 'wpvivid' ), $data ); } else { $wpdb->update($this->get_table_name('wpvivid'),$data,array( 'site_id' => intval( $site_id ))); } }// function get_is_pro($site_id) { global $wpdb; $sql = $wpdb->prepare( 'SELECT * FROM ' . $this->get_table_name( 'wpvivid' ) . ' WHERE `site_id` = %d ', $site_id ); $options = $wpdb->get_results( $sql,ARRAY_A ); if(isset($options[0]['is_pro'])) return $options[0]['is_pro']; else return false; }// function get_is_install($site_id) { global $wpdb; $sql = $wpdb->prepare( 'SELECT * FROM ' . $this->get_table_name( 'wpvivid' ) . ' WHERE `site_id` = %d ', $site_id ); $options = $wpdb->get_results( $sql,ARRAY_A ); if(isset($options[0]['is_install'])) return $options[0]['is_install']; else return false; }// function set_install($site_id,$value) { global $wpdb; $data['is_install']=intval($value); if($this->is_set_options( $site_id,'is_install' )===false) { $data['site_id']=$site_id; $wpdb->insert( $this->get_table_name( 'wpvivid' ), $data ); } else { $wpdb->update($this->get_table_name('wpvivid'),$data,array( 'site_id' => intval( $site_id ))); } }// function get_is_login($site_id) { global $wpdb; $sql = $wpdb->prepare( 'SELECT * FROM ' . $this->get_table_name( 'wpvivid' ) . ' WHERE `site_id` = %d ', $site_id ); $options = $wpdb->get_results( $sql,ARRAY_A ); if(isset($options[0]['is_login'])) return $options[0]['is_login']; else return false; }// function set_login($site_id,$value) { global $wpdb; $data['is_login']=intval($value); if($this->is_set_options( $site_id,'is_login' )===false) { $data['site_id']=$site_id; $wpdb->insert( $this->get_table_name( 'wpvivid' ), $data ); } else { $wpdb->update($this->get_table_name('wpvivid'),$data,array( 'site_id' => intval( $site_id ))); } }// function get_latest_version($site_id){ global $wpdb; $sql = $wpdb->prepare( 'SELECT * FROM ' . $this->get_table_name( 'wpvivid' ) . ' WHERE `site_id` = %d ', $site_id ); $options = $wpdb->get_results( $sql,ARRAY_A ); if(isset($options[0]['latest_version'])) return $options[0]['latest_version']; else return false; }// function set_latest_version($site_id, $version){ global $wpdb; $data['latest_version']=$version; if($this->is_set_options( $site_id,'latest_version' )===false) { $data['site_id']=$site_id; $wpdb->insert( $this->get_table_name( 'wpvivid' ), $data ); } else { $wpdb->update($this->get_table_name('wpvivid'),$data,array( 'site_id' => intval( $site_id ))); } }// function time_zone($site_id) { global $wpdb; $sql = $wpdb->prepare( 'SELECT * FROM ' . $this->get_table_name( 'wpvivid' ) . ' WHERE `site_id` = %d ', $site_id ); $options = $wpdb->get_results( $sql,ARRAY_A ); if(isset($options[0]['time_zone'])) return $options[0]['time_zone']; else return false; }// function get_need_update($site_id){ global $wpdb; $sql = $wpdb->prepare( 'SELECT * FROM ' . $this->get_table_name( 'wpvivid' ) . ' WHERE `site_id` = %d ', $site_id ); $options = $wpdb->get_results( $sql,ARRAY_A ); if(isset($options[0]['need_update'])) return $options[0]['need_update']; else return false; }// function set_need_update($site_id,$value){ global $wpdb; $data['need_update']=intval($value); if($this->is_set_options( $site_id,'need_update' )===false) { $data['site_id']=$site_id; $wpdb->insert( $this->get_table_name( 'wpvivid' ), $data ); } else { $wpdb->update($this->get_table_name('wpvivid'),$data,array( 'site_id' => intval( $site_id ))); } }// function set_sync_error($site_id, $value){ global $wpdb; $data['sync_error']=intval($value); if($this->is_set_options( $site_id,'sync_error' )===false) { $data['site_id']=$site_id; $wpdb->insert( $this->get_table_name( 'wpvivid' ), $data ); } else { $wpdb->update($this->get_table_name('wpvivid'),$data,array( 'site_id' => intval( $site_id ))); } }// function get_current_version($site_id){ global $wpdb; $sql = $wpdb->prepare( 'SELECT * FROM ' . $this->get_table_name( 'wpvivid' ) . ' WHERE `site_id` = %d ', $site_id ); $options = $wpdb->get_results( $sql,ARRAY_A ); if(isset($options[0]['current_version'])) return $options[0]['current_version']; else return false; }// function set_current_version($site_id,$version){ global $wpdb; $data['current_version']=$version; if($this->is_set_options( $site_id,'current_version' )===false) { $data['site_id']=$site_id; $wpdb->insert( $this->get_table_name( 'wpvivid' ), $data ); } else { $wpdb->update($this->get_table_name('wpvivid'),$data,array( 'site_id' => intval( $site_id ))); } }// function get_setting($site_id) { global $wpdb; $sql = $wpdb->prepare( 'SELECT * FROM ' . $this->get_table_name( 'wpvivid' ) . ' WHERE `site_id` = %d ', $site_id ); $options = $wpdb->get_results( $sql,ARRAY_A ); if(isset($options[0]['settings'])) $options = @unserialize($options[0]['settings']); else return false; return $options; }// function update_setting($site_id,$options) { global $wpdb; $data['settings']=serialize($options); if($this->is_set_options( $site_id,'settings' )===false) { $data['site_id']=$site_id; $wpdb->insert( $this->get_table_name( 'wpvivid' ), $data ); } else { $wpdb->update($this->get_table_name('wpvivid'),$data,array( 'site_id' => intval( $site_id ))); } }// function get_setting_addon($site_id) { global $wpdb; $sql = $wpdb->prepare( 'SELECT * FROM ' . $this->get_table_name( 'wpvivid' ) . ' WHERE `site_id` = %d ', $site_id ); $options = $wpdb->get_results( $sql,ARRAY_A ); if(isset($options[0]['settings_addon'])) $options = @unserialize($options[0]['settings_addon']); else return false; return $options; }// function update_setting_addon($site_id,$options) { global $wpdb; $data['settings_addon']=serialize($options); if($this->is_set_options( $site_id,'settings_addon' )===false) { $data['site_id']=$site_id; $wpdb->insert( $this->get_table_name( 'wpvivid' ), $data ); } else { $wpdb->update($this->get_table_name('wpvivid'),$data,array( 'site_id' => intval( $site_id ))); } }// function get_schedule($site_id) { global $wpdb; $sql = $wpdb->prepare( 'SELECT * FROM ' . $this->get_table_name( 'wpvivid' ) . ' WHERE `site_id` = %d ', $site_id ); $options = $wpdb->get_results( $sql,ARRAY_A ); if(isset($options[0]['schedule'])) $options = @unserialize($options[0]['schedule']); else return false; return $options; }// function update_schedule($site_id,$options) { global $wpdb; $data['schedule']=serialize($options); if($this->is_set_options( $site_id,'schedule' )===false) { $data['site_id']=$site_id; $wpdb->insert( $this->get_table_name( 'wpvivid' ), $data ); } else { $wpdb->update($this->get_table_name('wpvivid'),$data,array( 'site_id' => intval( $site_id ))); } }// function get_schedule_addon($site_id) { global $wpdb; $sql = $wpdb->prepare( 'SELECT * FROM ' . $this->get_table_name( 'wpvivid' ) . ' WHERE `site_id` = %d ', $site_id ); $options = $wpdb->get_results( $sql,ARRAY_A ); if(isset($options[0]['schedule_addon'])) $options = @unserialize($options[0]['schedule_addon']); else return false; return $options; }// function get_remote($site_id) { global $wpdb; $sql = $wpdb->prepare( 'SELECT * FROM ' . $this->get_table_name( 'wpvivid' ) . ' WHERE `site_id` = %d ', $site_id ); $options = $wpdb->get_results( $sql,ARRAY_A ); if(isset($options[0]['remote'])) $options = @unserialize($options[0]['remote']); else return false; return $options; }// public static function get_oldest_backup_id($report_list) { $oldest_id='not set'; $oldest=0; foreach ($report_list as $key=>$value) { if ($oldest == 0) { $oldest = $value['backup_time']; $oldest_id = $key; } else { if ($oldest > $value['backup_time']) { $oldest_id = $key; } } } return $oldest_id; }// function clean_out_of_date_report($report_list, $max_report_count) { $size=sizeof($report_list); while($size>$max_report_count) { $oldest_id=self::get_oldest_backup_id($report_list); if($oldest_id!='not set') { unset($report_list[$oldest_id]); } $new_size=sizeof($report_list); if($new_size==$size) { break; } else { $size=$new_size; } } return $report_list; }// function set_report_addon($site_id, $report_option) { global $wpdb; $sql = $wpdb->prepare( 'SELECT * FROM ' . $this->get_table_name( 'wpvivid' ) . ' WHERE `site_id` = %d ', $site_id ); $options = $wpdb->get_results( $sql,ARRAY_A ); if(isset($options[0]['report_addon'])) { $options = @unserialize($options[0]['report_addon']); foreach ($report_option as $key => $value){ $options[$key] = $value; $options = $this->clean_out_of_date_report($options, 10); $data['report_addon']=serialize($options); $wpdb->update($this->get_table_name('wpvivid'),$data,array( 'site_id' => intval( $site_id ))); } } else{ $data['site_id']=$site_id; foreach ($report_option as $key => $value){ $options[$key] = $value; $options = $this->clean_out_of_date_report($options, 10); $data['report_addon']=serialize($options); $wpdb->insert( $this->get_table_name( 'wpvivid' ), $data ); } } }// function get_report_addon($site_id) { global $wpdb; $sql = $wpdb->prepare( 'SELECT * FROM ' . $this->get_table_name( 'wpvivid' ) . ' WHERE `site_id` = %d ', $site_id ); $options = $wpdb->get_results( $sql,ARRAY_A ); if(isset($options[0]['report_addon'])) $options = @unserialize($options[0]['report_addon']); else return false; return $options; }// function set_sync_remote_setting($site_id, $remote_id, $remote_option){ global $wpdb; $sql = $wpdb->prepare( 'SELECT * FROM ' . $this->get_table_name( 'wpvivid' ) . ' WHERE `site_id` = %d ', $site_id ); $options = $wpdb->get_results( $sql,ARRAY_A ); if(isset($options[0]['sync_remote_setting'])) { $options = @unserialize($options[0]['sync_remote_setting']); $options[$remote_id] = $remote_option; $data['sync_remote_setting']=serialize($options); $wpdb->update($this->get_table_name('wpvivid'),$data,array( 'site_id' => intval( $site_id ))); } else{ $data['site_id']=$site_id; $options[$remote_id] = $remote_option; $data['sync_remote_setting']=serialize($options); $wpdb->insert( $this->get_table_name( 'wpvivid' ), $data ); } }// function get_sync_remote_setting($site_id){ global $wpdb; $sql = $wpdb->prepare( 'SELECT * FROM ' . $this->get_table_name( 'wpvivid' ) . ' WHERE `site_id` = %d ', $site_id ); $options = $wpdb->get_results( $sql,ARRAY_A ); if(isset($options[0]['sync_remote_setting'])) $options = @unserialize($options[0]['sync_remote_setting']); else return false; return $options; }// function set_backup_custom_setting($site_id, $options){ global $wpdb; $data['backup_custom_setting']=serialize($options); if($this->is_set_options( $site_id,'backup_custom_setting' )===false) { $data['site_id']=$site_id; $wpdb->insert( $this->get_table_name( 'wpvivid' ), $data ); } else { $wpdb->update($this->get_table_name('wpvivid'),$data,array( 'site_id' => intval( $site_id ))); } }// function get_backup_custom_setting($site_id) { global $wpdb; $sql = $wpdb->prepare( 'SELECT * FROM ' . $this->get_table_name( 'wpvivid' ) . ' WHERE `site_id` = %d ', $site_id ); $options = $wpdb->get_results( $sql,ARRAY_A ); if(isset($options[0]['backup_custom_setting'])) $options = @unserialize($options[0]['backup_custom_setting']); else return false; return $options; }// function is_set_global_options() { global $wpdb; $sql = 'SELECT * FROM ' . $this->get_table_name( 'wpvivid_global' ) . ' WHERE `global` = 1 '; $options = $wpdb->get_results( $sql ,ARRAY_A); if(isset($options[0])==false) { return false; } else { if(empty($options[0])) return false; else return true; } } function get_global_setting() { global $wpdb; $sql = 'SELECT * FROM ' . $this->get_table_name( 'wpvivid_global' ) . ' WHERE `global` = 1 '; $options = $wpdb->get_results( $sql,ARRAY_A ); if(isset($options[0]['settings'])) $options = @unserialize($options[0]['settings']); else return false; return $options; }// function get_global_setting_addon() { global $wpdb; $sql = 'SELECT * FROM ' . $this->get_table_name( 'wpvivid_global' ) . ' WHERE `global` = 1 '; $options = $wpdb->get_results( $sql,ARRAY_A ); if(isset($options[0]['settings_addon'])) $options = @unserialize($options[0]['settings_addon']); else return false; return $options; }// function update_global_setting($options) { global $wpdb; $data['settings']=serialize($options); if($this->is_set_global_options()===false) { $data['global']=1; $wpdb->insert( $this->get_table_name( 'wpvivid_global' ), $data ); } else { $wpdb->update($this->get_table_name('wpvivid_global'),$data,array( 'global' => intval( 1 ))); } }// function update_global_setting_addon($options) { global $wpdb; $data['settings_addon']=serialize($options); if($this->is_set_global_options()===false) { $data['global']=1; $wpdb->insert( $this->get_table_name( 'wpvivid_global' ), $data ); } else { $wpdb->update($this->get_table_name('wpvivid_global'),$data,array( 'global' => intval( 1 ))); } }// function get_global_schedule() { global $wpdb; $sql = 'SELECT * FROM ' . $this->get_table_name( 'wpvivid_global' ) . ' WHERE `global` = 1 '; $options = $wpdb->get_results( $sql,ARRAY_A ); if(isset($options[0]['schedule'])) $options = @unserialize($options[0]['schedule']); else return false; return $options; }// function get_global_schedule_addon() { global $wpdb; $sql = 'SELECT * FROM ' . $this->get_table_name( 'wpvivid_global' ) . ' WHERE `global` = 1 '; $options = $wpdb->get_results( $sql,ARRAY_A ); if(isset($options[0]['schedule_addon'])) $options = @unserialize($options[0]['schedule_addon']); else return false; return $options; }// function update_global_schedule($options) { global $wpdb; $data['schedule']=serialize($options); if($this->is_set_global_options()===false) { $data['global']=1; $wpdb->insert( $this->get_table_name( 'wpvivid_global' ), $data ); } else { $wpdb->update($this->get_table_name('wpvivid_global'),$data,array( 'global' => intval( 1 ))); } }// function update_global_schedule_addon($options) { global $wpdb; $data['schedule_addon']=serialize($options); if($this->is_set_global_options()===false) { $data['global']=1; $wpdb->insert( $this->get_table_name( 'wpvivid_global' ), $data ); } else { $wpdb->update($this->get_table_name('wpvivid_global'),$data,array( 'global' => intval( 1 ))); } }// function get_global_remote() { global $wpdb; $sql = 'SELECT * FROM ' . $this->get_table_name( 'wpvivid_global' ) . ' WHERE `global` = 1 '; $options = $wpdb->get_results( $sql,ARRAY_A ); if(isset($options[0]['remote'])) $options = @unserialize($options[0]['remote']); else return false; return $options; }// function get_global_remote_addon() { global $wpdb; $sql = 'SELECT * FROM ' . $this->get_table_name( 'wpvivid_global' ) . ' WHERE `global` = 1 '; $options = $wpdb->get_results( $sql,ARRAY_A ); if(isset($options[0]['remote_addon'])) $options = @unserialize($options[0]['remote_addon']); else return false; return $options; }// function add_global_remote_addon($remote_option,$default=0) { global $wpdb; $sql = 'SELECT * FROM ' . $this->get_table_name( 'wpvivid_global' ) . ' WHERE `global` = 1 '; $options = $wpdb->get_results( $sql,ARRAY_A ); if(isset($options[0]['remote_addon'])) { $options = @unserialize($options[0]['remote_addon']); $id=uniqid('wpvivid-remote-'); $options['upload'][$id]=$remote_option; if($default) { $remote_ids[]=$id; $options['history']['remote_selected']=$remote_ids; } $data['remote_addon']=serialize($options); $wpdb->update($this->get_table_name('wpvivid_global'),$data,array( 'global' => intval( 1 ))); } else { $options=array(); $id=uniqid('wpvivid-remote-'); $options['upload'][$id]=$remote_option; if($default) { $remote_ids[]=$id; $options['history']['remote_selected']=$remote_ids; } $data['remote_addon']=serialize($options); $data['global']=1; $wpdb->insert( $this->get_table_name( 'wpvivid_global' ), $data ); } return $id; }// function delete_global_remote_addon($remote_id){ global $wpdb; $sql = 'SELECT * FROM ' . $this->get_table_name( 'wpvivid_global' ) . ' WHERE `global` = 1 '; $options = $wpdb->get_results( $sql,ARRAY_A ); if(isset($options[0]['remote_addon'])) { $options = @unserialize($options[0]['remote_addon']); if(isset($options['upload'][$remote_id])) { unset($options['upload'][$remote_id]); } $data['remote_addon']=serialize($options); $wpdb->update($this->get_table_name('wpvivid_global'),$data,array( 'global' => intval( 1 ))); } }// function update_global_remote_addon($remote_id, $remote_option, $default){ global $wpdb; $sql = 'SELECT * FROM ' . $this->get_table_name( 'wpvivid_global' ) . ' WHERE `global` = 1 '; $options = $wpdb->get_results( $sql,ARRAY_A ); if(isset($options[0]['remote_addon'])) { $options = @unserialize($options[0]['remote_addon']); if(isset($options['upload'][$remote_id])){ $options['upload'][$remote_id] = $remote_option; } $data['remote_addon']=serialize($options); $wpdb->update($this->get_table_name('wpvivid_global'),$data,array( 'global' => intval( 1 ))); } }// function set_global_backup_custom_setting($options){ global $wpdb; $data['backup_custom_setting']=serialize($options); if($this->is_set_global_options()===false) { $data['global']=1; $wpdb->insert( $this->get_table_name( 'wpvivid_global' ), $data ); } else { $wpdb->update($this->get_table_name('wpvivid_global'),$data,array( 'global' => intval( 1 ))); } }// function get_global_backup_custom_setting(){ global $wpdb; $sql = 'SELECT * FROM ' . $this->get_table_name( 'wpvivid_global' ) . ' WHERE `global` = 1 '; $options = $wpdb->get_results( $sql,ARRAY_A ); if(isset($options[0]['backup_custom_setting'])) $options = @unserialize($options[0]['backup_custom_setting']); else return false; return $options; }// function add_global_remote($remote_option,$default=0) { global $wpdb; $sql = 'SELECT * FROM ' . $this->get_table_name( 'wpvivid_global' ) . ' WHERE `global` = 1 '; $options = $wpdb->get_results( $sql,ARRAY_A ); if(isset($options[0]['remote'])) { $options = @unserialize($options[0]['remote']); $id=uniqid('wpvivid-remote-'); $options['upload'][$id]=$remote_option; if($default) { $remote_ids[]=$id; $options['history']['remote_selected']=$remote_ids; } $data['remote']=serialize($options); $wpdb->update($this->get_table_name('wpvivid_global'),$data,array( 'global' => intval( 1 ))); } else { $options=array(); $id=uniqid('wpvivid-remote-'); $options['upload'][$id]=$remote_option; if($default) { $remote_ids[]=$id; $options['history']['remote_selected']=$remote_ids; } $data['remote']=serialize($options); $data['global']=1; $wpdb->insert( $this->get_table_name( 'wpvivid_global' ), $data ); } }//? function delete_global_remote($remote_id) { global $wpdb; $sql = 'SELECT * FROM ' . $this->get_table_name( 'wpvivid_global' ) . ' WHERE `global` = 1 '; $options = $wpdb->get_results( $sql,ARRAY_A ); if(isset($options[0]['remote'])) { $options = @unserialize($options[0]['remote']); if(isset($options['upload'][$remote_id])) { unset($options['upload'][$remote_id]); } if(in_array($remote_id, $options['history']['remote_selected'])) { $options['history']['remote_selected']=array(); } $data['remote']=serialize($options); $wpdb->update($this->get_table_name('wpvivid_global'),$data,array( 'global' => intval( 1 ))); } }//? function update_global_remote_default($remote_id) { global $wpdb; $sql = 'SELECT * FROM ' . $this->get_table_name( 'wpvivid_global' ) . ' WHERE `global` = 1 '; $options = $wpdb->get_results( $sql,ARRAY_A ); if(isset($options[0]['remote'])) { $options = @unserialize($options[0]['remote']); $remote_ids[]=$remote_id; $options['history']['remote_selected']=$remote_ids; $data['remote']=serialize($options); $wpdb->update($this->get_table_name('wpvivid_global'),$data,array( 'global' => intval( 1 ))); } }//? function set_global_select_pro($value){ global $wpdb; $data['select_pro']=$value; if($this->is_set_global_options()===false) { $data['global']=1; $wpdb->insert( $this->get_table_name( 'wpvivid_global' ), $data ); } else { $wpdb->update($this->get_table_name('wpvivid_global'),$data,array( 'global' => intval( 1 ))); } }// function get_global_select_pro(){ global $wpdb; $sql = 'SELECT * FROM ' . $this->get_table_name( 'wpvivid_global' ) . ' WHERE `global` = 1 '; $options = $wpdb->get_results( $sql,ARRAY_A ); if(isset($options[0]['select_pro'])) return $options[0]['select_pro']; else return false; }// function set_switch_pro_setting_page($value){ global $wpdb; $data['switch_pro_setting_page']=$value; if($this->is_set_global_options()===false) { $data['global']=1; $wpdb->insert( $this->get_table_name( 'wpvivid_global' ), $data ); } else { $wpdb->update($this->get_table_name('wpvivid_global'),$data,array( 'global' => intval( 1 ))); } }// function get_switch_pro_setting_page(){ global $wpdb; $sql = 'SELECT * FROM ' . $this->get_table_name( 'wpvivid_global' ) . ' WHERE `global` = 1 '; $options = $wpdb->get_results( $sql,ARRAY_A ); if(isset($options[0]['switch_pro_setting_page'])) return $options[0]['switch_pro_setting_page']; else return false; }// function set_sync_init_addon_first($value){ global $wpdb; $data['sync_init_addon_first']=$value; if($this->is_set_global_options()===false) { $data['global']=1; $wpdb->insert( $this->get_table_name( 'wpvivid_global' ), $data ); } else { $wpdb->update($this->get_table_name('wpvivid_global'),$data,array( 'global' => intval( 1 ))); } }// function get_sync_init_addon_first(){ global $wpdb; $sql = 'SELECT * FROM ' . $this->get_table_name( 'wpvivid_global' ) . ' WHERE `global` = 1 '; $options = $wpdb->get_results( $sql,ARRAY_A ); if(isset($options[0]['sync_init_addon_first'])) return $options[0]['sync_init_addon_first']; else return false; }// function update_login_addon($options) { global $wpdb; $data['login_addon']=serialize($options); if($this->is_set_global_options()===false) { $data['global']=1; $wpdb->insert( $this->get_table_name( 'wpvivid_global' ), $data ); } else { $wpdb->update($this->get_table_name('wpvivid_global'),$data,array( 'global' => intval( 1 ))); } }// function get_login_addon() { global $wpdb; $sql = 'SELECT * FROM ' . $this->get_table_name( 'wpvivid_global' ) . ' WHERE `global` = 1 '; $options = $wpdb->get_results( $sql,ARRAY_A ); if(isset($options[0]['login_addon'])) $options = @unserialize($options[0]['login_addon']); else return false; return $options; }// function get_wpvivid_option($site_id, $option, $default = null) { global $wpdb; $sql = $wpdb->prepare( 'SELECT * FROM ' . $this->get_table_name( 'wpvivid' ) . ' WHERE `site_id` = %d ', $site_id ); $options = $wpdb->get_results( $sql,ARRAY_A ); if(isset($options[0]['wpvivid_setting']) && !empty($options[0]['wpvivid_setting'])){ $wpvivid_settings = unserialize(base64_decode($options[0]['wpvivid_setting'])); $value = (isset($wpvivid_settings[$option]) && !empty($wpvivid_settings[$option])) ? $wpvivid_settings[$option] : $default; } else{ $value = $default; } return $value; }// function update_wpvivid_option($site_id, $option, $value){ global $wpdb; $wpvivid_option = $this->is_set_wpvivid_setting($site_id); if($wpvivid_option===false) { $wpvivid_setting[$option] = serialize($value); $wpvivid_setting['site_id']=$site_id; $data = base64_encode(serialize($wpvivid_setting)); $wpdb->insert( $this->get_table_name( 'wpvivid' ), $data ); } else { $wpvivid_setting = unserialize(base64_decode($wpvivid_option['wpvivid_setting'])); $wpvivid_setting[$option] = ($value); $data['wpvivid_setting'] = base64_encode(serialize($wpvivid_setting)); $wpdb->update($this->get_table_name('wpvivid'),$data,array( 'site_id' => intval( $site_id ))); } }// function is_set_wpvivid_setting($site_id) { global $wpdb; $option_name = 'wpvivid_setting'; $sql = $wpdb->prepare( 'SELECT '.$option_name.' FROM ' . $this->get_table_name( 'wpvivid' ) . ' WHERE `site_id` = %d ', $site_id ); $options = $wpdb->get_results( $sql ,ARRAY_A); if(isset($options[0])==false) { return false; } else { if(empty($options[0])) return false; else return $options[0]; } }// function get_global_wpvivid_option($option, $default = null){ global $wpdb; $sql = 'SELECT * FROM ' . $this->get_table_name( 'wpvivid_global' ) . ' WHERE `global` = 1 '; $options = $wpdb->get_results( $sql,ARRAY_A ); if(isset($options[0]['wpvivid_setting']) && !empty($options[0]['wpvivid_setting'])){ $wpvivid_settings = unserialize(base64_decode($options[0]['wpvivid_setting'])); $value = (isset($wpvivid_settings[$option]) && !empty($wpvivid_settings[$option])) ? $wpvivid_settings[$option] : $default; } else{ $value = $default; } return $value; }// function update_global_wpvivid_option($option, $value){ global $wpdb; $wpvivid_option = $this->is_set_global_wpvivid_setting(); if($wpvivid_option===false) { $wpvivid_setting[$option] = serialize($value); $wpvivid_setting['global']=1; $data = base64_encode(serialize($wpvivid_setting)); $wpdb->insert( $this->get_table_name( 'wpvivid_global' ), $data ); } else { $wpvivid_setting = unserialize(base64_decode($wpvivid_option['wpvivid_setting'])); $wpvivid_setting[$option] = ($value); $data['wpvivid_setting'] = base64_encode(serialize($wpvivid_setting)); $wpdb->update($this->get_table_name('wpvivid_global'),$data,array( 'global' => intval( 1 ))); } }// function is_set_global_wpvivid_setting() { global $wpdb; $option_name = 'wpvivid_setting'; $sql = 'SELECT '.$option_name.' FROM ' . $this->get_table_name( 'wpvivid_global' ) . ' WHERE `global` = 1 '; $options = $wpdb->get_results( $sql ,ARRAY_A); if(isset($options[0])==false) { return false; } else { if(empty($options[0])) return false; else return $options[0]; } }// } includes/class-wpvivid-crypt.php 0000644 00000004326 15133715745 0013035 0 ustar 00 <?php if (!defined('MAINWP_WPVIVID_EXTENSION_PLUGIN_DIR')){ die; } class Mainwp_WPvivid_crypt { private $public_key; private $sym_key; private $rij; private $rsa; public function __construct($public_key) { $this->public_key=$public_key; include_once MAINWP_WPVIVID_EXTENSION_PLUGIN_DIR . '/vendor/autoload.php'; $this->rij= new Crypt_Rijndael(); $this->rsa= new Crypt_RSA(); } public function generate_key() { $this->sym_key = crypt_random_string(32); $this->rij->setKey($this->sym_key); } public function encrypt_message($message) { $this->generate_key(); $key=$this->encrypt_key(); $len=str_pad(dechex(strlen($key)),3,'0', STR_PAD_LEFT); $message=$this->rij->encrypt($message); if($message===false) return false; $message_len = str_pad(dechex(strlen($message)), 16, '0', STR_PAD_LEFT); return $len.$key.$message_len.$message; } public function encrypt_key() { $this->rsa->loadKey($this->public_key); return $this->rsa->encrypt($this->sym_key); } public function decrypt_message($message) { $len = substr($message, 0, 3); $len = hexdec($len); $key = substr($message, 3, $len); $cipherlen = substr($message, ($len + 3), 16); $cipherlen = hexdec($cipherlen); $data = substr($message, ($len + 19), $cipherlen); $rsa = new Crypt_RSA(); $rsa->loadKey($this->public_key); $key=$rsa->decrypt($key); $rij = new Crypt_Rijndael(); $rij->setKey($key); return $rij->decrypt($data); } public function encrypt_user_info($email,$pw) { $user_info['user']=$email; $user_info['pw']=$pw; $info=wp_json_encode($user_info); $this->rsa->loadKey($this->public_key); return $this->rsa->encrypt($info); } public function encrypt_user_token($token) { $user_info['token']=$token; $info=wp_json_encode($user_info); $this->rsa->loadKey($this->public_key); return $this->rsa->encrypt($info); } } includes/customclass/class-wpvivid-sftpclass.php 0000644 00000065714 15133715745 0016246 0 ustar 00 <?php if (!defined('MAINWP_WPVIVID_EXTENSION_PLUGIN_DIR')){ die; } define('MAINWP_WPVIVID_REMOTE_SFTP','sftp'); require_once MAINWP_WPVIVID_EXTENSION_PLUGIN_DIR .'/includes/customclass/class-wpvivid-remote.php'; class Mainwp_WPvivid_SFTPClass extends Mainwp_WPvivid_Remote { private $timeout = 20; private $error_str=false; private $options=array(); public function __construct($options=array()) { if(empty($options)) { add_action('mwp_wpvivid_add_storage_tab',array($this,'mwp_wpvivid_add_storage_tab_sftp'), 10); add_action('mwp_wpvivid_add_storage_page',array($this,'mwp_wpvivid_add_storage_page_sftp'), 10); add_action('mwp_wpvivid_add_storage_tab_addon', array($this, 'mwp_wpvivid_add_storage_tab_sftp_addon'), 10); add_action('mwp_wpvivid_add_storage_page_addon', array($this, 'mwp_wpvivid_add_storage_page_sftp_addon'), 10); add_action('mwp_wpvivid_add_storage_page_sftp_addon', array($this, 'mwp_wpvivid_add_storage_page_sftp_addon')); add_action('mwp_wpvivid_edit_storage_page_addon', array($this, 'mwp_wpvivid_edit_storage_page_sftp_addon'), 10); add_filter('mwp_wpvivid_remote_pic',array($this,'mwp_wpvivid_remote_pic_sftp'),10); add_filter('mwp_wpvivid_storage_provider_tran',array($this,'mwp_wpvivid_storage_provider_sftp'),10); } else { $this->options=$options; } } public function mwp_wpvivid_add_storage_tab_sftp() { ?> <div class="mwp-storage-providers" remote_type="sftp" onclick="select_remote_storage(event, 'mwp_wpvivid_storage_account_sftp');"> <img src="<?php echo esc_url(MAINWP_WPVIVID_EXTENSION_PLUGIN_URL.'/admin/images/storage-sftp.png'); ?>" style="vertical-align:middle;"/><?php esc_html_e('SFTP', 'mainwp-wpvivid-extension'); ?> </div> <?php } public function mwp_wpvivid_add_storage_page_sftp() { ?> <div class="storage-account-page" id="mwp_wpvivid_storage_account_sftp" style="display:none;"> <div class="mwp-wpvivid-block-bottom-space"><strong>Enter Your SFTP Account</strong></div> <table class="wp-list-table widefat plugins" style="width:100%;"> <tbody> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input type="text" class="regular-text" autocomplete="off" option="sftp" name="name" placeholder="Enter a unique alias: e.g. SFTP-001" onkeyup="value=value.replace(/[^a-zA-Z0-9\-_]/g,'')" style="height: 27px;" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>A name to help you identify the storage if you have multiple remote storage connected.</i> </div> </td> </tr> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input type="text" class="regular-text" autocomplete="off" option="sftp" name="host" placeholder="Server Address" style="height: 27px;" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>Enter the server address.</i> </div> </td> </tr> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input type="text" class="regular-text" autocomplete="off" option="sftp" name="username" placeholder="User Name" style="height: 27px;" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>Enter the user name.</i> </div> </td> </tr> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input type="password" class="regular-text" autocomplete="new-password" option="sftp" name="password" placeholder="User Password" style="height: 27px;" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>Enter the user password.</i> </div> </td> </tr> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input type="text" class="regular-text" autocomplete="off" option="sftp" name="port" placeholder="Port" onkeyup="value=value.replace(/\D/g,'')" style="height: 27px;" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>Enter the server port.</i> </div> </td> </tr> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input type="text" class="regular-text" autocomplete="off" option="sftp" name="path" placeholder="Absolute path must exist(e.g. /var)" style="height: 27px;" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>Enter an absolute path and a custom subdirectory (optional) for holding the backups of current website. For example, /var/customfolder/</i> </div> </td> </tr> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-select"> <label> <input type="checkbox" option="sftp" name="default" checked />Set as the default remote storage. </label> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>Once checked, all this sites backups sent to a remote storage destination will be uploaded to this storage by default.</i> </div> </td> </tr> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input class="ui green mini button" option="add-remote" type="button" value="Test and Add" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>Click the button to connect to SFTP server and add it to the storage list below.</i> </div> </td> </tr> </tbody> </table> </div> <?php } public function mwp_wpvivid_add_storage_tab_sftp_addon(){ ?> <div class="mwp-storage-providers-addon" remote_type="sftp" onclick="select_remote_storage_addon(event, 'mwp_wpvivid_storage_account_sftp_addon');"> <img src="<?php echo esc_url(MAINWP_WPVIVID_EXTENSION_PLUGIN_URL.'/admin/images/storage-sftp.png'); ?>" style="vertical-align:middle;"/><?php esc_html_e('SFTP', 'mainwp-wpvivid-extension'); ?> </div> <?php } public function mwp_wpvivid_add_storage_page_sftp_addon(){ ?> <div class="storage-account-page-addon" id="mwp_wpvivid_storage_account_sftp_addon"> <div class="mwp-wpvivid-block-bottom-space"><strong>Enter Your SFTP Account</strong></div> <table class="wp-list-table widefat plugins" style="width:100%;"> <tbody> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input type="text" class="regular-text" autocomplete="off" option="sftp-addon" name="name" placeholder="Enter a unique alias: e.g. SFTP-001" onkeyup="value=value.replace(/[^a-zA-Z0-9\-_]/g,'')" style="height: 27px;" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>A name to help you identify the storage if you have multiple remote storage connected.</i> </div> </td> </tr> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input type="text" class="regular-text" autocomplete="off" option="sftp-addon" name="host" placeholder="Server Address" style="height: 27px;" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>Enter the server address.</i> </div> </td> </tr> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input type="text" class="regular-text" autocomplete="off" option="sftp-addon" name="username" placeholder="User Name" style="height: 27px;" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>Enter the user name.</i> </div> </td> </tr> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input type="password" class="regular-text" autocomplete="new-password" option="sftp-addon" name="password" placeholder="User Password" style="height: 27px;" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>Enter the user password.</i> </div> </td> </tr> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input type="text" class="regular-text" autocomplete="off" option="sftp-addon" name="port" placeholder="Port" onkeyup="value=value.replace(/\D/g,'')" style="height: 27px;" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>Enter the server port.</i> </div> </td> </tr> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input type="text" class="regular-text" autocomplete="off" option="sftp-addon" name="path" placeholder="Absolute path must exist(e.g. /var)" style="height: 27px;" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>Enter an absolute path and a custom subdirectory (optional) for holding the backups of current website. For example, /var/customfolder/</i> </div> </td> </tr> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input type="text" class="regular-text" autocomplete="off" option="sftp-addon" name="root_path" value="<?php echo esc_attr(apply_filters('wpvivid_white_label_remote_root_path', 'wpvividbackuppro')); ?>" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i><?php /* translators: %s: Folder name. */ echo sprintf(esc_html('Customize a parent folder under the absolute path for holding %s folders.', 'wpvivid'), esc_html(apply_filters('wpvivid_white_label_display', 'WPvivid backup'))); ?></i> </div> </td> </tr> <?php do_action('mwp_wpvivid_remote_storage_backup_retention', 'sftp-addon', 'add'); ?> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input class="ui green mini button" option="add-remote-addon-global" type="button" value="Save and Sync" remote_type="sftp" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>Click the button to connect to SFTP server and add it to the storage list below.</i> </div> </td> </tr> </tbody> </table> </div> <?php } public function mwp_wpvivid_edit_storage_page_sftp_addon(){ ?> <div class="mwp-wpvivid-remote-storage-edit" id="mwp_wpvivid_storage_account_sftp_edit" style="display: none;"> <div class="mwp-wpvivid-block-bottom-space" style="margin-top: 10px;"><strong>Enter Your SFTP Account</strong></div> <table class="wp-list-table widefat plugins" style="width:100%;"> <tbody> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input type="text" class="regular-text" autocomplete="off" option="edit-sftp-addon" name="name" placeholder="Enter a unique alias: e.g. SFTP-001" onkeyup="value=value.replace(/[^a-zA-Z0-9\-_]/g,'')" style="height: 27px;" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>A name to help you identify the storage if you have multiple remote storage connected.</i> </div> </td> </tr> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input type="text" class="regular-text" autocomplete="off" option="edit-sftp-addon" name="host" placeholder="Server Address" style="height: 27px;" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>Enter the server address.</i> </div> </td> </tr> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input type="text" class="regular-text" autocomplete="off" option="edit-sftp-addon" name="username" placeholder="User Name" style="height: 27px;" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>Enter the user name.</i> </div> </td> </tr> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input type="password" class="regular-text" autocomplete="new-password" option="edit-sftp-addon" name="password" placeholder="User Password" style="height: 27px;" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>Enter the user password.</i> </div> </td> </tr> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input type="text" class="regular-text" autocomplete="off" option="edit-sftp-addon" name="port" placeholder="Port" onkeyup="value=value.replace(/\D/g,'')" style="height: 27px;" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>Enter the server port.</i> </div> </td> </tr> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input type="text" class="regular-text" autocomplete="off" option="edit-sftp-addon" name="path" placeholder="Absolute path must exist(e.g. /var)" style="height: 27px;" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>Enter an absolute path and a custom subdirectory (optional) for holding the backups of current website. For example, /var/customfolder/</i> </div> </td> </tr> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input type="text" class="regular-text" autocomplete="off" option="edit-sftp-addon" name="root_path" value="<?php echo esc_attr(apply_filters('wpvivid_white_label_remote_root_path', 'wpvividbackuppro')); ?>" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i><?php /* translators: %s: Folder name. */ echo sprintf(esc_html('Customize a parent folder under the absolute path for holding %s folders.', 'wpvivid'), esc_html(apply_filters('wpvivid_white_label_display', 'WPvivid backup'))); ?></i> </div> </td> </tr> <?php do_action('mwp_wpvivid_remote_storage_backup_retention', 'sftp-addon', 'edit'); ?> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input class="ui green mini button" option="edit-remote-addon-global" type="button" value="Save Changes" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>Click the button to connect to SFTP server and add it to the storage list below.</i> </div> </td> </tr> </tbody> </table> </div> <?php } public function mwp_wpvivid_remote_pic_sftp($remote) { $remote['sftp']['default_pic'] = '/admin/images/storage-sftp(gray).png'; $remote['sftp']['selected_pic'] = '/admin/images/storage-sftp.png'; $remote['sftp']['title'] = 'SFTP'; return $remote; } public function test_connect($is_pro) { $host = $this->options['host']; $username = $this->options['username']; $password = $this->options['password']; $path = $this->options['path']; $port = empty($this->options['port'])?22:$this->options['port']; $conn = $this->do_connect($host,$username,$password,$port); if(!is_subclass_of($conn,'Net_SSH2')) { return $conn; } $str = $this->do_chdir($conn,$path); if($str['result'] == 'success') { if($conn->put(trailingslashit($path) . 'testfile', 'test data', NET_SFTP_STRING)) { $this -> _delete($conn ,trailingslashit($path) . 'testfile'); return array('result'=>'success'); } return array('result'=>'failed','error'=>'Failed to create a test file. Please try again later.'); }else{ return $str; } } public function sanitize_options($skip_name='') { $ret['result']='failed'; if(!isset($this->options['name'])) { $ret['error']="Warning: An alias for remote storage is required."; return $ret; } $this->options['name']=sanitize_text_field($this->options['name']); if(empty($this->options['name'])) { $ret['error']="Warning: An alias for remote storage is required."; return $ret; } $remoteslist=Mainwp_WPvivid_Extension_DB_Option::get_instance()->wpvivid_get_global_option('remote_addon', array()); if(isset($remoteslist) && !empty($remoteslist)) { foreach ($remoteslist['upload'] as $key => $value) { if (isset($value['name']) && $value['name'] == $this->options['name'] && $skip_name != $value['name']) { $ret['error'] = "Warning: The alias already exists in storage list."; return $ret; } } } if(!isset($this->options['host'])) { $ret['error']="Warning: The IP Address is required."; return $ret; } $this->options['host']=sanitize_text_field($this->options['host']); if(empty($this->options['host'])) { $ret['error']="Warning: The IP Address is required."; return $ret; } if(!isset($this->options['username'])) { $ret['error']="Warning: The username is required."; return $ret; } $this->options['username']=sanitize_text_field($this->options['username']); if(empty($this->options['username'])) { $ret['error']="Warning: The username is required."; return $ret; } if(!isset($this->options['password'])||empty($this->options['password'])) { $ret['error']="Warning: The password is required."; return $ret; } $this->options['password']=sanitize_text_field($this->options['password']); if(empty($this->options['password'])) { $ret['error']="Warning: The password is required."; return $ret; } $this->options['password'] = base64_encode($this->options['password']); $this->options['is_encrypt'] = 1; if(!isset($this->options['port'])) { $ret['error']="Warning: The port number is required."; return $ret; } $this->options['port']=sanitize_text_field($this->options['port']); if(empty($this->options['port'])) { $ret['error']="Warning: The port number is required."; return $ret; } if(!isset($this->options['path'])||empty($this->options['path'])) { $ret['error']="Warning: The storage path is required."; return $ret; } $this->options['path']=sanitize_text_field($this->options['path']); if(empty($this->options['path'])) { $ret['error']="Warning: The storage path is required."; return $ret; } $ret['result']='success'; $ret['options']=$this->options; return $ret; } function do_connect($host,$username,$password,$port) { include_once MAINWP_WPVIVID_EXTENSION_PLUGIN_DIR . '/includes/customclass/class-wpvivid-extend-sftp.php'; $conn = new WPvivid_Net_SFTP($host,$port,$this -> timeout); $conn -> setTimeout($this->timeout); $ret = $conn->login($username,$password); if(!$ret) { return array('result'=>'failed','error'=>'Login failed. You have entered the incorrect credential(s). Please try again.'); } return $conn; } function do_chdir($conn,$path) { @$conn->mkdir($path); // See if the directory now exists if (!$conn->chdir($path)) { @$conn->disconnect(); return array('result'=>'failed','error'=>'Failed to create a backup. Make sure you have sufficient privileges to perform the operation.'); } return array('result'=>'success'); } public function get_last_error() { if($this->error_str===false) { $this->error_str='connection time out.'; } return $this->error_str; } function _delete($conn , $file) { $result = $conn ->delete($file , true); return $result; } public function mwp_wpvivid_storage_provider_sftp($storage_type) { if ($storage_type == MAINWP_WPVIVID_REMOTE_SFTP) { $storage_type = 'SFTP'; } return $storage_type; } } includes/customclass/class-wpvivid-webdav.php 0000644 00000045230 15133715745 0015503 0 ustar 00 <?php if (!defined('MAINWP_WPVIVID_EXTENSION_PLUGIN_DIR')){ die; } define('MAINWP_WPVIVID_REMOTE_WEBDAV','webdav'); require_once MAINWP_WPVIVID_EXTENSION_PLUGIN_DIR . '/includes/customclass/class-wpvivid-remote.php'; class Mainwp_WPvivid_WebDavClass extends Mainwp_WPvivid_Remote { public $options; public function __construct($options=array()) { if(empty($options)) { if(!defined('MAINWP_WPVIVID_INIT_STORAGE_TAB_WEBDAV')) { add_action('mwp_wpvivid_add_storage_page_webdav_addon', array($this, 'mwp_wpvivid_add_storage_page_webdav_addon')); add_action('mwp_wpvivid_edit_storage_page_addon', array($this, 'mwp_wpvivid_edit_storage_page_webdav_addon'), 11); add_filter('mwp_wpvivid_storage_provider_tran', array($this, 'mwp_wpvivid_storage_provider_webdav'), 10); define('MAINWP_WPVIVID_INIT_STORAGE_TAB_WEBDAV',1); } } else { $this->options=$options; } } public function mwp_wpvivid_add_storage_page_webdav_addon() { ?> <div class="storage-account-page-addon" id="mwp_wpvivid_storage_account_webdav_addon"> <div style="padding: 0 10px 10px 0;"><strong>Enter Your WebDav Account</strong></div> <table class="wp-list-table widefat plugins" style="width:100%;"> <tbody> <form> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input type="text" class="regular-text" autocomplete="off" option="webdav-addon" name="name" placeholder="Enter a unique alias: e.g. WEBDAV-001" onkeyup="value=value.replace(/[^a-zA-Z0-9\-_]/g,'')" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>A name to help you identify the storage if you have multiple remote storage connected.</i> </div> </td> </tr> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input type="text" class="regular-text" autocomplete="off" option="webdav-addon" name="host" placeholder="Host" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>Enter the storage hostname.</i> </div> </td> </tr> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input type="text" class="regular-text" autocomplete="off" option="webdav-addon" name="port" placeholder="Port" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>Enter the storage port.</i> </div> </td> </tr> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input type="text" class="regular-text" autocomplete="off" option="webdav-addon" name="username" placeholder="Username" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>Enter the username.</i> </div> </td> </tr> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input type="password" class="regular-text" autocomplete="off" option="webdav-addon" name="password" placeholder="Password" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>Enter the password.</i> </div> </td> </tr> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input type="text" class="regular-text" autocomplete="off" option="webdav-addon" name="root_path" value="<?php echo esc_attr(apply_filters('wpvivid_white_label_remote_root_path', 'wpvividbackuppro')); ?>" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i><span><?php echo sprintf(esc_html('Customize a root directory in the storage for holding WPvivid backup directories.', 'wpvivid'), esc_html(apply_filters('wpvivid_white_label_display', 'WPvivid backup'))); ?></span></i> </div> </td> </tr> <?php do_action('mwp_wpvivid_remote_storage_backup_retention', 'webdav-addon', 'add'); ?> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-select"> <label> <input type="checkbox" option="webdav-addon" name="ssl" />WebDAV (HTTPS) </label> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>Check the option to connect the storage server over HTTPS. Make sure HTTPS is enabled on the storage server.</i> </div> </td> </tr> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input style="width: 50px" type="text" class="regular-text" autocomplete="off" option="webdav-addon" name="chunk_size" placeholder="Chunk size" value="3" onkeyup="value=value.replace(/\D/g,'')" />MB </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>The block size of uploads and downloads. Reduce it if you encounter a timeout when transferring files.</i> </div> </td> </tr> </form> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input class="ui green mini button" option="add-remote-addon-global" type="button" value="Save and Sync" remote_type="webdav" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>Click the button to connect to B2 storage and add it to the storage list below</i> </div> </td> </tr> </tbody> </table> </div> <?php } public function mwp_wpvivid_edit_storage_page_webdav_addon() { ?> <div class="mwp-wpvivid-remote-storage-edit" id="mwp_wpvivid_storage_account_webdav_edit" style="display:none;"> <div class="mwp-wpvivid-block-bottom-space" style="margin-top: 10px;"><strong>Enter Your WebDav Account</strong></div> <table class="wp-list-table widefat plugins" style="width:100%;"> <tbody> <form> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input type="text" class="regular-text" autocomplete="off" option="edit-webdav-addon" name="name" placeholder="Enter a unique alias: e.g. WEBDAV-001" onkeyup="value=value.replace(/[^a-zA-Z0-9\-_]/g,'')" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>A name to help you identify the storage if you have multiple remote storage connected.</i> </div> </td> </tr> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input type="text" class="regular-text" autocomplete="off" option="edit-webdav-addon" name="host" placeholder="Host" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>Enter the storage hostname.</i> </div> </td> </tr> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input type="text" class="regular-text" autocomplete="off" option="edit-webdav-addon" name="port" placeholder="Port" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>Enter the storage port.</i> </div> </td> </tr> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input type="text" class="regular-text" autocomplete="off" option="edit-webdav-addon" name="username" placeholder="Username" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>Enter the username.</i> </div> </td> </tr> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input type="password" class="regular-text" autocomplete="off" option="edit-webdav-addon" name="password" placeholder="Password" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>Enter the password.</i> </div> </td> </tr> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input type="text" class="regular-text" autocomplete="off" option="edit-webdav-addon" name="root_path" value="<?php echo esc_attr(apply_filters('wpvivid_white_label_remote_root_path', 'wpvividbackuppro')); ?>" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i><span><?php echo sprintf(esc_html('Customize a root directory in the storage for holding WPvivid backup directories.', 'wpvivid'), esc_html(apply_filters('wpvivid_white_label_display', 'WPvivid backup'))); ?></span></i> </div> </td> </tr> <?php do_action('mwp_wpvivid_remote_storage_backup_retention', 'webdav-addon', 'edit'); ?> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-select"> <label> <input type="checkbox" option="edit-webdav-addon" name="ssl" />WebDAV (HTTPS) </label> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>Check the option to connect the storage server over HTTPS. Make sure HTTPS is enabled on the storage server.</i> </div> </td> </tr> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input style="width: 50px" type="text" class="regular-text" autocomplete="off" option="edit-webdav-addon" name="chunk_size" placeholder="Chunk size" value="3" onkeyup="value=value.replace(/\D/g,'')" />MB </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>The block size of uploads and downloads. Reduce it if you encounter a timeout when transferring files.</i> </div> </td> </tr> </form> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input class="ui green mini button" option="edit-remote-addon-global" type="button" value="Save Changes" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>Click the button to connect to B2 storage and add it to the storage list below</i> </div> </td> </tr> </tbody> </table> </div> <?php } public function mwp_wpvivid_storage_provider_webdav($storage_type) { if($storage_type == MAINWP_WPVIVID_REMOTE_WEBDAV) { $storage_type = 'Webdav'; } return $storage_type; } public function sanitize_options($skip_name='') { $ret['result']='failed'; if(!isset($this->options['name'])) { $ret['error']="Warning: An alias for remote storage is required."; return $ret; } $this->options['name']=sanitize_text_field($this->options['name']); if(empty($this->options['name'])) { $ret['error']="Warning: An alias for remote storage is required."; return $ret; } $remoteslist=Mainwp_WPvivid_Extension_DB_Option::get_instance()->wpvivid_get_global_option('remote_addon', array()); if(isset($remoteslist) && !empty($remoteslist)) { foreach ($remoteslist['upload'] as $key => $value) { if (isset($value['name']) && $value['name'] == $this->options['name'] && $skip_name != $value['name']) { $ret['error'] = "Warning: The alias already exists in storage list."; return $ret; } } } if(!isset($this->options['host'])) { $ret['error']="Warning: The hostname for WebDav is required."; return $ret; } $this->options['host']=sanitize_text_field($this->options['host']); if(empty($this->options['host'])) { $ret['error']="Warning: The hostname for WebDav is required."; return $ret; } if(!isset($this->options['username'])) { $ret['error']="Warning: The username for WebDav is required."; return $ret; } $this->options['username']=sanitize_text_field($this->options['username']); if(empty($this->options['username'])) { $ret['error']="Warning: The username for WebDav is required."; return $ret; } if(!isset($this->options['password']) || empty($this->options['password'])) { $ret['error']="Warning: The password is required."; return $ret; } if(isset($this->options['port'])) { $this->options['port']=sanitize_text_field($this->options['port']); } if(!isset($this->options['root_path'])) { $ret['error']="Warning: The root path is required."; return $ret; } $this->options['root_path']=sanitize_text_field($this->options['root_path']); if(empty($this->options['root_path'])) { $ret['error']="Warning: The root path is required."; return $ret; } $ret['result']='success'; $ret['options']=$this->options; return $ret; } public function test_connect($is_pro) { return array('result' => 'success'); } } includes/customclass/class-wpvivid-google-drive.php 0000644 00000013721 15133715745 0016616 0 ustar 00 <?php if (!defined('MAINWP_WPVIVID_EXTENSION_PLUGIN_DIR')){ die; } require_once MAINWP_WPVIVID_EXTENSION_PLUGIN_DIR . '/includes/customclass/class-wpvivid-remote.php'; define('MAINWP_WPVIVID_REMOTE_GOOGLEDRIVE','googledrive'); define('MAINWP_WPVIVID_GOOGLEDRIVE_DEFAULT_FOLDER','wpvivid_backup'); define('MAINWP_WPVIVID_GOOGLEDRIVE_SECRETS',MAINWP_WPVIVID_EXTENSION_PLUGIN_DIR.'/includes/customclass/client_secrets.json'); define('MAINWP_WPVIVID_GOOGLEDRIVE_UPLOAD_SIZE',1024*1024*2); define('MAINWP_WPVIVID_GOOGLE_NEED_PHP_VERSION','5.5'); class Mainwp_Wpvivid_Google_drive extends Mainwp_WPvivid_Remote { public $options; public $google_drive_secrets; public function __construct($options=array()) { if(empty($options)) { if(!defined('MAINWP_WPVIVID_INIT_STORAGE_TAB_GOOGLE_DRIVE')) { add_action('mwp_wpvivid_add_storage_tab',array($this,'mwp_wpvivid_add_storage_tab_google_drive'), 10); add_action('mwp_wpvivid_add_storage_page',array($this,'mwp_wpvivid_add_storage_page_google_drive'), 10); add_action('mwp_wpvivid_add_storage_tab_addon', array($this, 'mwp_wpvivid_add_storage_tab_google_drive_addon'), 10); add_action('mwp_wpvivid_add_storage_page_addon', array($this, 'mwp_wpvivid_add_storage_page_google_drive_addon'), 9); add_action('mwp_wpvivid_add_storage_page_google_drive_addon', array($this, 'mwp_wpvivid_add_storage_page_google_drive_addon')); add_filter('mwp_wpvivid_remote_pic',array($this,'mwp_wpvivid_remote_pic_google_drive'),10); add_filter('mwp_wpvivid_storage_provider_tran',array($this,'mwp_wpvivid_storage_provider_google_drive'),10); define('MAINWP_WPVIVID_INIT_STORAGE_TAB_GOOGLE_DRIVE',1); } } else { $this->options=$options; } $this->google_drive_secrets = array("web"=>array( "client_id"=>"134809148507-32crusepgace4h6g47ota99jjrvf4j1u.apps.googleusercontent.com", "project_id"=>"wpvivid-auth", "auth_uri"=>"https://accounts.google.com/o/oauth2/auth", "token_uri"=>"https://oauth2.googleapis.com/token", "auth_provider_x509_cert_url"=>"https://www.googleapis.com/oauth2/v1/certs", "client_secret"=>"GmD5Kmg_1fTcf0ciNEomposy", "redirect_uris"=>array("https://auth.wpvivid.com/google_drive") )); } public function mwp_wpvivid_add_storage_tab_google_drive() { ?> <div class="mwp-storage-providers" remote_type="googledrive" onclick="select_remote_storage(event, 'storage_account_google_drive');"> <img src="<?php echo esc_url(MAINWP_WPVIVID_EXTENSION_PLUGIN_URL.'/admin/images/stroage-google-drive.png'); ?>" style="vertical-align:middle;"/><?php esc_html_e('Google Drive', 'mainwp-wpvivid-extension'); ?> </div> <?php } public function mwp_wpvivid_add_storage_page_google_drive() { ?> <div id="storage_account_google_drive" class="storage-account-page" style="display:none;"> <p>Global configuration is not available for GoogleDrive due to authorization mechanism (tokens will be expired). Please get authorization in child-sites</p> </div> <?php } public function mwp_wpvivid_add_storage_tab_google_drive_addon(){ ?> <div class="mwp-storage-providers-addon" remote_type="googledrive" onclick="select_remote_storage_addon(event, 'mwp_wpvivid_storage_account_google_drive_addon');"> <img src="<?php echo esc_url(MAINWP_WPVIVID_EXTENSION_PLUGIN_URL.'/admin/images/stroage-google-drive.png'); ?>" style="vertical-align:middle;"/><?php esc_html_e('Google Drive', 'mainwp-wpvivid-extension'); ?> </div> <?php } public function mwp_wpvivid_add_storage_page_google_drive_addon(){ ?> <div id="mwp_wpvivid_storage_account_google_drive_addon" class="storage-account-page-addon"> <p>Global configuration is not available for GoogleDrive due to authorization mechanism (tokens will be expired). Please get authorization in child-sites</p> </div> <?php } public function mwp_wpvivid_remote_pic_google_drive($remote) { $remote['googledrive']['default_pic'] = '/admin/images/stroage-google-drive(gray).png'; $remote['googledrive']['selected_pic'] = '/admin/images/stroage-google-drive.png'; $remote['googledrive']['title'] = 'Google Drive'; return $remote; } public function sanitize_options($skip_name='') { $ret['result']='success'; if(!isset($this->options['name'])) { $ret['error']="Warning: An alias for remote storage is required."; return $ret; } $this->options['name']=sanitize_text_field($this->options['name']); if(empty($this->options['name'])) { $ret['error']="Warning: An alias for remote storage is required."; return $ret; } $remoteslist=Mainwp_WPvivid_Extension_DB_Option::get_instance()->wpvivid_get_global_option('remote_addon', array()); foreach ($remoteslist['upload'] as $key=>$value) { if(isset($value['name'])&&$value['name'] == $this->options['name']&&$skip_name!=$value['name']) { $ret['error']="Warning: The alias already exists in storage list."; return $ret; } } $ret['options']=$this->options; return $ret; } public function test_connect($is_pro) { return array('result' => 'success'); } public function mwp_wpvivid_storage_provider_google_drive($storage_type) { if($storage_type == MAINWP_WPVIVID_REMOTE_GOOGLEDRIVE){ $storage_type = 'Google Drive'; } return $storage_type; } } includes/customclass/class-wpvivid-s3.php 0000644 00000236172 15133715745 0014567 0 ustar 00 <?php if (!defined('MAINWP_WPVIVID_EXTENSION_PLUGIN_DIR')){ die; } /** * $Id$ * * Copyright (c) 2013, Donovan Schönknecht. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * - Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * - Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * * Amazon S3 is a trademark of Amazon.com, Inc. or its affiliates. */ /** * Amazon S3 PHP class * * @link http://undesigned.org.za/2007/10/22/amazon-s3-php-class * @version 0.5.1 */ class Mainwp_WPvivid_S3 { // ACL flags const ACL_PRIVATE = 'private'; const ACL_PUBLIC_READ = 'public-read'; const ACL_PUBLIC_READ_WRITE = 'public-read-write'; const ACL_AUTHENTICATED_READ = 'authenticated-read'; const STORAGE_CLASS_STANDARD = 'STANDARD'; const STORAGE_CLASS_RRS = 'REDUCED_REDUNDANCY'; const STORAGE_CLASS_STANDARD_IA = 'STANDARD_IA'; const SSE_NONE = ''; const SSE_AES256 = 'AES256'; /** * The AWS Access key * * @var string * @access private * @static */ private $__accessKey = null; /** * AWS Secret Key * * @var string * @access private * @static */ private $__secretKey = null; /** * SSL Client key * * @var string * @access private * @static */ private $__sslKey = null; /** * Default delimiter to be used, for example while getBucket(). * @var string * @access public * @ */ public $defDelimiter = null; /** * AWS URI * * @var string * @acess public * @static */ public $endpoint = 's3.amazonaws.com'; /** * Proxy information * * @var null|array * @access public * @static */ public $proxy = null; /** * Connect using SSL? * * @var bool * @access public * @static */ public $useSSL = false; /** * Use SSL validation? * * @var bool * @access public * @static */ public $useSSLValidation = true; /** * Use SSL version * * @var const * @access public * @static */ public $useSSLVersion = CURL_SSLVERSION_TLSv1; /** * Use PHP exceptions? * * @var bool * @access public * @static */ public $useExceptions = false; /** * Time offset applied to time() * @access private * @static */ private $__timeOffset = 0; /** * SSL client key * * @var bool * @access public * @static */ public $sslKey = null; /** * SSL client certfificate * * @var string * @acess public * @static */ public $sslCert = null; /** * SSL CA cert (only required if you are having problems with your system CA cert) * * @var string * @access public * @static */ public $sslCACert = null; /** * AWS Key Pair ID * * @var string * @access private * @static */ private $__signingKeyPairId = null; /** * Key resource, freeSigningKey() must be called to clear it from memory * * @var bool * @access private * @ */ private $__signingKeyResource = false; var $_serverSideEncryption = self::SSE_NONE; var $_storageClass = self::STORAGE_CLASS_STANDARD; /** * Constructor - if you're not using the class statically * * @param string $accessKey Access key * @param string $secretKey Secret key * @param boolean $useSSL Enable SSL * @param string $endpoint Amazon URI * @return void */ var $region; public function __construct($accessKey = null, $secretKey = null, $useSSL = false, $endpoint = 's3.amazonaws.com') { if ($accessKey !== null && $secretKey !== null) $this -> setAuth($accessKey, $secretKey); $this -> useSSL = $useSSL; $this -> endpoint = $endpoint; $this->region = 'us-east-1'; } /** * Set the service endpoint * * @param string $host Hostname * @return void */ public function setEndpoint($host) { $this -> endpoint = $host; } /** * Set the service region * * @param string $region Region * @return void */ public function setRegion($region) { $this->region = $region; } /** * Get the service region * Note: Region calculation will be done in methods/s3.php file * * @return string Region */ public function getRegion() { return $this->region; } /** * Set AWS access key and secret key * * @param string $accessKey Access key * @param string $secretKey Secret key * @return void */ public function setAuth($accessKey, $secretKey) { $this -> __accessKey = $accessKey; $this -> __secretKey = $secretKey; } /** * Check if AWS keys have been set * * @return boolean */ public function hasAuth() { return ($this -> __accessKey !== null && $this -> __secretKey !== null); } /** * Set SSL on or off * * @param boolean $enabled SSL enabled * @param boolean $validate SSL certificate validation * @return void */ public function setSSL($enabled, $validate = true) { $this -> useSSL = $enabled; $this -> useSSLValidation = $validate; } /** * Set SSL client certificates (experimental) * * @param string $sslCert SSL client certificate * @param string $sslKey SSL client key * @param string $sslCACert SSL CA cert (only required if you are having problems with your system CA cert) * @return void */ public function setSSLAuth($sslCert = null, $sslKey = null, $sslCACert = null) { $this -> sslCert = $sslCert; $this -> sslKey = $sslKey; $this -> sslCACert = $sslCACert; } /** * Set proxy information * * @param string $host Proxy hostname and port (localhost:1234) * @param string $user Proxy username * @param string $pass Proxy password * @param constant $type CURL proxy type * @return void */ public function setProxy($host, $user = null, $pass = null, $type = CURLPROXY_SOCKS5) { $this -> proxy = array('host' => $host, 'type' => $type, 'user' => $user, 'pass' => $pass); } /** * Set the error mode to exceptions * * @param boolean $enabled Enable exceptions * @return void */ public function setExceptions($enabled = true) { $this -> useExceptions = $enabled; } /** * Set AWS time correction offset (use carefully) * * This can be used when an inaccurate system time is generating * invalid request signatures. It should only be used as a last * resort when the system time cannot be changed. * * @param string $offset Time offset (set to zero to use AWS server time) * @return void */ public function setTimeCorrectionOffset($offset = 0) { if ($offset == 0) { $rest = new MainWP_WPvivid_S3Request('HEAD','','',$this -> endpoint,$this); $rest = $rest->getResponse(); $awstime = $rest->headers['date']; $systime = time(); $offset = $systime > $awstime ? -($systime - $awstime) : ($awstime - $systime); } $this -> __timeOffset = $offset; } /** * Set signing key * * @param string $keyPairId AWS Key Pair ID * @param string $signingKey Private Key * @param boolean $isFile Load private key from file, set to false to load string * @return boolean */ public function setSigningKey($keyPairId, $signingKey, $isFile = true) { $this -> __signingKeyPairId = $keyPairId; if (($this -> __signingKeyResource = openssl_pkey_get_private($isFile ? file_get_contents($signingKey) : $signingKey)) !== false) return true; $this -> __triggerError('S3::setSigningKey(): Unable to open load private key: '.$signingKey, __FILE__, __LINE__); return false; } /** * Free signing key from memory, MUST be called if you are using setSigningKey() * * @return void */ public function freeSigningKey() { if ($this -> __signingKeyResource !== false) openssl_free_key($this -> __signingKeyResource); } /** * Internal error handler * * @internal Internal error handler * @param string $message Error message * @param string $file Filename * @param integer $line Line number * @param integer $code Error code * @return void */ function __triggerError($message, $file, $line, $code = 0) { if ($this -> useExceptions) throw new Mainwp_WPvivid_S3Exception(esc_html($message), esc_attr($file), esc_attr($line), esc_attr($code)); else trigger_error(esc_html($message), E_USER_WARNING); } /** * Get a list of buckets * * @param boolean $detailed Returns detailed bucket list when true * @return array | false */ public function listBuckets($detailed = false) { $rest = new MainWP_WPvivid_S3Request('GET', '', '', $this -> endpoint,$this); $rest = $rest->getResponse(); if ($rest->error === false && $rest->code !== 200) $rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status'); if ($rest->error !== false) { $this -> __triggerError(sprintf("S3::listBuckets(): [%s] %s", $rest->error['code'], $rest->error['message']), __FILE__, __LINE__); return false; } $results = array(); if (!isset($rest->body->Buckets)) return $results; if ($detailed) { if (isset($rest->body->Owner, $rest->body->Owner->ID, $rest->body->Owner->DisplayName)) $results['owner'] = array( 'id' => (string)$rest->body->Owner->ID, 'name' => (string)$rest->body->Owner->DisplayName ); $results['buckets'] = array(); foreach ($rest->body->Buckets->Bucket as $b) $results['buckets'][] = array( 'name' => (string)$b->Name, 'time' => strtotime((string)$b->CreationDate) ); } else foreach ($rest->body->Buckets->Bucket as $b) $results[] = (string)$b->Name; return $results; } /** * Get contents for a bucket * * If maxKeys is null this method will loop through truncated result sets * * @param string $bucket Bucket name * @param string $prefix Prefix * @param string $marker Marker (last file listed) * @param string $maxKeys Max keys (maximum number of keys to return) * @param string $delimiter Delimiter * @param boolean $returnCommonPrefixes Set to true to return CommonPrefixes * @return array | false */ public function getBucket($bucket, $prefix = null, $marker = null, $maxKeys = null, $delimiter = null, $returnCommonPrefixes = false) { $rest = new MainWP_WPvivid_S3Request('GET', $bucket, '', $this -> endpoint,$this); if ($maxKeys == 0) $maxKeys = null; if ($prefix !== null && $prefix !== '') $rest->setParameter('prefix', $prefix); if ($marker !== null && $marker !== '') $rest->setParameter('marker', $marker); if ($maxKeys !== null && $maxKeys !== '') $rest->setParameter('max-keys', $maxKeys); if ($delimiter !== null && $delimiter !== '') $rest->setParameter('delimiter', $delimiter); else if (!empty($this -> defDelimiter)) $rest->setParameter('delimiter', $this -> defDelimiter); $response = $rest->getResponse(); if ($response->error === false && $response->code !== 200) $response->error = array('code' => $response->code, 'message' => 'Unexpected HTTP status'); if ($response->error !== false) { $this -> __triggerError(sprintf("S3::getBucket(): [%s] %s", $response->error['code'], $response->error['message']), __FILE__, __LINE__); return false; } $results = array(); $nextMarker = null; if (isset($response->body, $response->body->Contents)) foreach ($response->body->Contents as $c) { $results[(string)$c->Key] = array( 'name' => (string)$c->Key, 'time' => strtotime((string)$c->LastModified), 'size' => (int)$c->Size, 'hash' => substr((string)$c->ETag, 1, -1) ); $nextMarker = (string)$c->Key; } if ($returnCommonPrefixes && isset($response->body, $response->body->CommonPrefixes)) foreach ($response->body->CommonPrefixes as $c) $results[(string)$c->Prefix] = array('prefix' => (string)$c->Prefix); if (isset($response->body, $response->body->IsTruncated) && (string)$response->body->IsTruncated == 'false') return $results; if (isset($response->body, $response->body->NextMarker)) $nextMarker = (string)$response->body->NextMarker; // Loop through truncated results if maxKeys isn't specified if ($maxKeys == null && $nextMarker !== null && (string)$response->body->IsTruncated == 'true') do { $rest = new MainWP_WPvivid_S3Request('GET', $bucket, '', $this -> endpoint,$this); if ($prefix !== null && $prefix !== '') $rest->setParameter('prefix', $prefix); $rest->setParameter('marker', $nextMarker); if ($delimiter !== null && $delimiter !== '') $rest->setParameter('delimiter', $delimiter); if (($response = $rest->getResponse()) == false || $response->code !== 200) break; if (isset($response->body, $response->body->Contents)) foreach ($response->body->Contents as $c) { $results[(string)$c->Key] = array( 'name' => (string)$c->Key, 'time' => strtotime((string)$c->LastModified), 'size' => (int)$c->Size, 'hash' => substr((string)$c->ETag, 1, -1) ); $nextMarker = (string)$c->Key; } if ($returnCommonPrefixes && isset($response->body, $response->body->CommonPrefixes)) foreach ($response->body->CommonPrefixes as $c) $results[(string)$c->Prefix] = array('prefix' => (string)$c->Prefix); if (isset($response->body, $response->body->NextMarker)) $nextMarker = (string)$response->body->NextMarker; } while ($response !== false && (string)$response->body->IsTruncated == 'true'); return $results; } /** * Put a bucket * * @param string $bucket Bucket name * @param constant $acl ACL flag * @param string $location Set as "EU" to create buckets hosted in Europe * @return boolean */ public function putBucket($bucket, $acl = self::ACL_PRIVATE, $location = false) { $rest = new MainWP_WPvivid_S3Request('PUT', $bucket, '', $this -> endpoint,$this); $rest->setAmzHeader('x-amz-acl', $acl); if ($location !== false) { $dom = new DOMDocument; $createBucketConfiguration = $dom->createElement('CreateBucketConfiguration'); $locationConstraint = $dom->createElement('LocationConstraint', $location); $createBucketConfiguration->appendChild($locationConstraint); $dom->appendChild($createBucketConfiguration); $rest->data = $dom->saveXML(); $rest->size = strlen($rest->data); $rest->setHeader('Content-Type', 'application/xml'); } $rest = $rest->getResponse(); if ($rest->error === false && $rest->code !== 200) $rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status'); if ($rest->error !== false) { $this -> __triggerError(sprintf("S3::putBucket({$bucket}, {$acl}, {$location}): [%s] %s", $rest->error['code'], $rest->error['message']), __FILE__, __LINE__); return false; } return true; } /** * Delete an empty bucket * * @param string $bucket Bucket name * @return boolean */ public function deleteBucket($bucket) { $rest = new MainWP_WPvivid_S3Request('DELETE', $bucket, '', $this -> endpoint,$this); $rest = $rest->getResponse(); if ($rest->error === false && $rest->code !== 204) $rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status'); if ($rest->error !== false) { $this -> __triggerError(sprintf("S3::deleteBucket({$bucket}): [%s] %s", $rest->error['code'], $rest->error['message']), __FILE__, __LINE__); return false; } return true; } /** * Create input info array for putObject() * * @param string $file Input file * @param mixed $md5sum Use MD5 hash (supply a string if you want to use your own) * @return array | false */ public function inputFile($file, $md5sum = true) { if (!file_exists($file) || !is_file($file) || !is_readable($file)) { $this -> __triggerError('S3::inputFile(): Unable to open input file: '.$file, __FILE__, __LINE__); return false; } clearstatcache(false, $file); return array('file' => $file, 'size' => filesize($file), 'md5sum' => $md5sum !== false ? (is_string($md5sum) ? $md5sum : base64_encode(md5_file($file, true))) : ''); } /** * Create input array info for putObject() with a resource * * @param string $resource Input resource to read from * @param integer $bufferSize Input byte size * @param string $md5sum MD5 hash to send (optional) * @return array | false */ public function inputResource(&$resource, $bufferSize = false, $md5sum = '') { if (!is_resource($resource) || (int)$bufferSize < 0) { $this -> __triggerError('S3::inputResource(): Invalid resource or buffer size', __FILE__, __LINE__); return false; } // Try to figure out the bytesize if ($bufferSize === false) { if (fseek($resource, 0, SEEK_END) < 0 || ($bufferSize = ftell($resource)) === false) { $this -> __triggerError('S3::inputResource(): Unable to obtain resource size', __FILE__, __LINE__); return false; } fseek($resource, 0); } $input = array('size' => $bufferSize, 'md5sum' => $md5sum); $input['fp'] =& $resource; return $input; } /** * Put an object * * @param mixed $input Input data * @param string $bucket Bucket name * @param string $uri Object URI * @param constant $acl ACL constant * @param array $metaHeaders Array of x-amz-meta-* headers * @param array $requestHeaders Array of request headers or content type as a string * @param constant $storageClass Storage class constant * @param constant $serverSideEncryption Server-side encryption * @return boolean */ public function putObject($input, $bucket, $uri, $acl = self::ACL_PRIVATE, $metaHeaders = array(), $requestHeaders = array(), $storageClass = self::STORAGE_CLASS_STANDARD, $serverSideEncryption = self::SSE_NONE) { if ($input === false) return false; $rest = new MainWP_WPvivid_S3Request('PUT', $bucket, $uri, $this -> endpoint,$this); if (!is_array($input)) $input = array( 'data' => $input, 'size' => strlen($input), 'md5sum' => base64_encode(md5($input, true)) ); // Data if (isset($input['fp'])) $rest->fp =& $input['fp']; elseif (isset($input['file'])) $rest->fp = @fopen($input['file'], 'rb'); elseif (isset($input['data'])) $rest->data = $input['data']; // Content-Length (required) if (isset($input['size']) && $input['size'] >= 0) $rest->size = $input['size']; else { if (isset($input['file'])) { clearstatcache(false, $input['file']); $rest->size = filesize($input['file']); } elseif (isset($input['data'])) $rest->size = strlen($input['data']); } // Custom request headers (Content-Type, Content-Disposition, Content-Encoding) if (is_array($requestHeaders)) foreach ($requestHeaders as $h => $v) strpos($h, 'x-amz-') === 0 ? $rest->setAmzHeader($h, $v) : $rest->setHeader($h, $v); elseif (is_string($requestHeaders)) // Support for legacy contentType parameter $input['type'] = $requestHeaders; // Content-Type if (!isset($input['type'])) { if (isset($requestHeaders['Content-Type'])) $input['type'] =& $requestHeaders['Content-Type']; elseif (isset($input['file'])) $input['type'] = $this -> __getMIMEType($input['file']); else $input['type'] = 'application/octet-stream'; } if ($this -> _storageClass !== self::STORAGE_CLASS_STANDARD) // Storage class $rest->setAmzHeader('x-amz-storage-class', $this -> _storageClass); if ($this -> _serverSideEncryption !== self::SSE_NONE) // Server-side encryption $rest->setAmzHeader('x-amz-server-side-encryption', $this -> _serverSideEncryption); // We need to post with Content-Length and Content-Type, MD5 is optional if ($rest->size >= 0 && ($rest->fp !== false || $rest->data !== false)) { $rest->setHeader('Content-Type', $input['type']); if (isset($input['md5sum'])) $rest->setHeader('Content-MD5', $input['md5sum']); $rest->setAmzHeader('x-amz-acl', $acl); foreach ($metaHeaders as $h => $v) $rest->setAmzHeader('x-amz-meta-'.$h, $v); $rest->getResponse(); } else $rest->response->error = array('code' => 0, 'message' => 'Missing input parameters'); if ($rest->response->error === false && $rest->response->code !== 200) $rest->response->error = array('code' => $rest->response->code, 'message' => 'Unexpected HTTP status'); if ($rest->response->error !== false) { $this -> __triggerError(sprintf("S3::putObject(): [%s] %s", $rest->response->error['code'], $rest->response->error['message']), __FILE__, __LINE__); return false; } return true; } /** * Put an object from a file (legacy function) * * @param string $file Input file path * @param string $bucket Bucket name * @param string $uri Object URI * @param constant $acl ACL constant * @param array $metaHeaders Array of x-amz-meta-* headers * @param string $contentType Content type * @return boolean */ public function putObjectFile($file, $bucket, $uri, $acl = self::ACL_PRIVATE, $metaHeaders = array(), $contentType = null) { return $this -> putObject($this -> inputFile($file), $bucket, $uri, $acl, $metaHeaders, $contentType); } /** * Put an object from a string (legacy function) * * @param string $string Input data * @param string $bucket Bucket name * @param string $uri Object URI * @param constant $acl ACL constant * @param array $metaHeaders Array of x-amz-meta-* headers * @param string $contentType Content type * @return boolean */ public function putObjectString($string, $bucket, $uri, $acl = self::ACL_PRIVATE, $metaHeaders = array(), $contentType = 'text/plain') { return $this -> putObject($string, $bucket, $uri, $acl, $metaHeaders, $contentType); } /** * Get an object * * @param string $bucket Bucket name * @param string $uri Object URI * @param mixed $saveTo Filename or resource to write to * @return mixed */ public function getObject($bucket, $uri, $saveTo = false) { $rest = new MainWP_WPvivid_S3Request('GET', $bucket, $uri, $this -> endpoint,$this); if ($saveTo !== false) { if (is_resource($saveTo)) $rest->fp =& $saveTo; else if (($rest->fp = @fopen($saveTo, 'wb')) !== false) $rest->file = realpath($saveTo); else $rest->response->error = array('code' => 0, 'message' => 'Unable to open save file for writing: '.$saveTo); } if ($rest->response->error === false) $rest->getResponse(); if ($rest->response->error === false && $rest->response->code !== 200) $rest->response->error = array('code' => $rest->response->code, 'message' => 'Unexpected HTTP status'); if ($rest->response->error !== false) { $this -> __triggerError(sprintf("S3::getObject({$bucket}, {$uri}): [%s] %s", $rest->response->error['code'], $rest->response->error['message']), __FILE__, __LINE__); return false; } return $rest->response; } /** * Get object information * * @param string $bucket Bucket name * @param string $uri Object URI * @param boolean $returnInfo Return response information * @return mixed | false */ public function getObjectInfo($bucket, $uri, $returnInfo = true) { $rest = new MainWP_WPvivid_S3Request('HEAD', $bucket, $uri, $this -> endpoint,$this); $rest = $rest->getResponse(); if ($rest->error === false && ($rest->code !== 200 && $rest->code !== 404)) $rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status'); if ($rest->error !== false) { $this -> __triggerError(sprintf("S3::getObjectInfo({$bucket}, {$uri}): [%s] %s", $rest->error['code'], $rest->error['message']), __FILE__, __LINE__); return false; } return $rest->code == 200 ? $returnInfo ? $rest->headers : true : false; } /** * Copy an object * * @param string $srcBucket Source bucket name * @param string $srcUri Source object URI * @param string $bucket Destination bucket name * @param string $uri Destination object URI * @param constant $acl ACL constant * @param array $metaHeaders Optional array of x-amz-meta-* headers * @param array $requestHeaders Optional array of request headers (content type, disposition, etc.) * @param constant $storageClass Storage class constant * @return mixed | false */ public function copyObject($srcBucket, $srcUri, $bucket, $uri, $acl = self::ACL_PRIVATE, $metaHeaders = array(), $requestHeaders = array(), $storageClass = self::STORAGE_CLASS_STANDARD) { $rest = new MainWP_WPvivid_S3Request('PUT', $bucket, $uri, $this -> endpoint,$this); $rest->setHeader('Content-Length', 0); foreach ($requestHeaders as $h => $v) strpos($h, 'x-amz-') === 0 ? $rest->setAmzHeader($h, $v) : $rest->setHeader($h, $v); foreach ($metaHeaders as $h => $v) $rest->setAmzHeader('x-amz-meta-'.$h, $v); if ($storageClass !== self::STORAGE_CLASS_STANDARD) // Storage class $rest->setAmzHeader('x-amz-storage-class', $storageClass); $rest->setAmzHeader('x-amz-acl', $acl); $rest->setAmzHeader('x-amz-copy-source', sprintf('/%s/%s', $srcBucket, rawurlencode($srcUri))); if (sizeof($requestHeaders) > 0 || sizeof($metaHeaders) > 0) $rest->setAmzHeader('x-amz-metadata-directive', 'REPLACE'); $rest = $rest->getResponse(); if ($rest->error === false && $rest->code !== 200) $rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status'); if ($rest->error !== false) { $this -> __triggerError(sprintf("S3::copyObject({$srcBucket}, {$srcUri}, {$bucket}, {$uri}): [%s] %s", $rest->error['code'], $rest->error['message']), __FILE__, __LINE__); return false; } return isset($rest->body->LastModified, $rest->body->ETag) ? array( 'time' => strtotime((string)$rest->body->LastModified), 'hash' => substr((string)$rest->body->ETag, 1, -1) ) : false; } /** * Set up a bucket redirection * * @param string $bucket Bucket name * @param string $location Target host name * @return boolean */ public function setBucketRedirect($bucket = NULL, $location = NULL) { $rest = new MainWP_WPvivid_S3Request('PUT', $bucket, '', $this -> endpoint,$this); if( empty($bucket) || empty($location) ) { $this -> __triggerError("S3::setBucketRedirect({$bucket}, {$location}): Empty parameter.", __FILE__, __LINE__); return false; } $dom = new DOMDocument; $websiteConfiguration = $dom->createElement('WebsiteConfiguration'); $redirectAllRequestsTo = $dom->createElement('RedirectAllRequestsTo'); $hostName = $dom->createElement('HostName', $location); $redirectAllRequestsTo->appendChild($hostName); $websiteConfiguration->appendChild($redirectAllRequestsTo); $dom->appendChild($websiteConfiguration); $rest->setParameter('website', null); $rest->data = $dom->saveXML(); $rest->size = strlen($rest->data); $rest->setHeader('Content-Type', 'application/xml'); $rest = $rest->getResponse(); if ($rest->error === false && $rest->code !== 200) $rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status'); if ($rest->error !== false) { $this -> __triggerError(sprintf("S3::setBucketRedirect({$bucket}, {$location}): [%s] %s", $rest->error['code'], $rest->error['message']), __FILE__, __LINE__); return false; } return true; } /** * Set logging for a bucket * * @param string $bucket Bucket name * @param string $targetBucket Target bucket (where logs are stored) * @param string $targetPrefix Log prefix (e,g; domain.com-) * @return boolean */ public function setBucketLogging($bucket, $targetBucket, $targetPrefix = null) { // The S3 log delivery group has to be added to the target bucket's ACP if ($targetBucket !== null && ($acp = $this -> getAccessControlPolicy($targetBucket, '')) !== false) { // Only add permissions to the target bucket when they do not exist $aclWriteSet = false; $aclReadSet = false; foreach ($acp['acl'] as $acl) if ($acl['type'] == 'Group' && $acl['uri'] == 'http://acs.amazonaws.com/groups/s3/LogDelivery') { if ($acl['permission'] == 'WRITE') $aclWriteSet = true; elseif ($acl['permission'] == 'READ_ACP') $aclReadSet = true; } if (!$aclWriteSet) $acp['acl'][] = array( 'type' => 'Group', 'uri' => 'http://acs.amazonaws.com/groups/s3/LogDelivery', 'permission' => 'WRITE' ); if (!$aclReadSet) $acp['acl'][] = array( 'type' => 'Group', 'uri' => 'http://acs.amazonaws.com/groups/s3/LogDelivery', 'permission' => 'READ_ACP' ); if (!$aclReadSet || !$aclWriteSet) $this -> setAccessControlPolicy($targetBucket, '', $acp); } $dom = new DOMDocument; $bucketLoggingStatus = $dom->createElement('BucketLoggingStatus'); $bucketLoggingStatus->setAttribute('xmlns', 'http://s3.amazonaws.com/doc/2006-03-01/'); if ($targetBucket !== null) { if ($targetPrefix == null) $targetPrefix = $bucket . '-'; $loggingEnabled = $dom->createElement('LoggingEnabled'); $loggingEnabled->appendChild($dom->createElement('TargetBucket', $targetBucket)); $loggingEnabled->appendChild($dom->createElement('TargetPrefix', $targetPrefix)); // TODO: Add TargetGrants? $bucketLoggingStatus->appendChild($loggingEnabled); } $dom->appendChild($bucketLoggingStatus); $rest = new MainWP_WPvivid_S3Request('PUT', $bucket, '', $this -> endpoint,$this); $rest->setParameter('logging', null); $rest->data = $dom->saveXML(); $rest->size = strlen($rest->data); $rest->setHeader('Content-Type', 'application/xml'); $rest = $rest->getResponse(); if ($rest->error === false && $rest->code !== 200) $rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status'); if ($rest->error !== false) { $this -> __triggerError(sprintf("S3::setBucketLogging({$bucket}, {$targetBucket}): [%s] %s", $rest->error['code'], $rest->error['message']), __FILE__, __LINE__); return false; } return true; } /** * Get logging status for a bucket * * This will return false if logging is not enabled. * Note: To enable logging, you also need to grant write access to the log group * * @param string $bucket Bucket name * @return array | false */ public function getBucketLogging($bucket) { $rest = new MainWP_WPvivid_S3Request('GET', $bucket, '', $this -> endpoint,$this); $rest->setParameter('logging', null); $rest = $rest->getResponse(); if ($rest->error === false && $rest->code !== 200) $rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status'); if ($rest->error !== false) { $this -> __triggerError(sprintf("S3::getBucketLogging({$bucket}): [%s] %s", $rest->error['code'], $rest->error['message']), __FILE__, __LINE__); return false; } if (!isset($rest->body->LoggingEnabled)) return false; // No logging return array( 'targetBucket' => (string)$rest->body->LoggingEnabled->TargetBucket, 'targetPrefix' => (string)$rest->body->LoggingEnabled->TargetPrefix, ); } /** * Disable bucket logging * * @param string $bucket Bucket name * @return boolean */ public function disableBucketLogging($bucket) { return $this -> setBucketLogging($bucket, null); } /** * Get a bucket's location * * @param string $bucket Bucket name * @return string | false */ public function getBucketLocation($bucket) { $rest = new MainWP_WPvivid_S3Request('GET', $bucket, '', $this -> endpoint,$this); $rest->setParameter('location', null); $rest = $rest->getResponse(); if ($rest->error === false && $rest->code !== 200) $rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status'); if ($rest->error !== false) { $this -> __triggerError(sprintf("S3::getBucketLocation({$bucket}): [%s] %s", $rest->error['code'], $rest->error['message']), __FILE__, __LINE__); return false; } return (isset($rest->body[0]) && (string)$rest->body[0] !== '') ? (string)$rest->body[0] : 'us-east-1'; } /** * Set object or bucket Access Control Policy * * @param string $bucket Bucket name * @param string $uri Object URI * @param array $acp Access Control Policy Data (same as the data returned from getAccessControlPolicy) * @return boolean */ public function setAccessControlPolicy($bucket, $uri = '', $acp = array()) { $dom = new DOMDocument; $dom->formatOutput = true; $accessControlPolicy = $dom->createElement('AccessControlPolicy'); $accessControlList = $dom->createElement('AccessControlList'); // It seems the owner has to be passed along too $owner = $dom->createElement('Owner'); $owner->appendChild($dom->createElement('ID', $acp['owner']['id'])); $owner->appendChild($dom->createElement('DisplayName', $acp['owner']['name'])); $accessControlPolicy->appendChild($owner); foreach ($acp['acl'] as $g) { $grant = $dom->createElement('Grant'); $grantee = $dom->createElement('Grantee'); $grantee->setAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance'); if (isset($g['id'])) { // CanonicalUser (DisplayName is omitted) $grantee->setAttribute('xsi:type', 'CanonicalUser'); $grantee->appendChild($dom->createElement('ID', $g['id'])); } elseif (isset($g['email'])) { // AmazonCustomerByEmail $grantee->setAttribute('xsi:type', 'AmazonCustomerByEmail'); $grantee->appendChild($dom->createElement('EmailAddress', $g['email'])); } elseif ($g['type'] == 'Group') { // Group $grantee->setAttribute('xsi:type', 'Group'); $grantee->appendChild($dom->createElement('URI', $g['uri'])); } $grant->appendChild($grantee); $grant->appendChild($dom->createElement('Permission', $g['permission'])); $accessControlList->appendChild($grant); } $accessControlPolicy->appendChild($accessControlList); $dom->appendChild($accessControlPolicy); $rest = new MainWP_WPvivid_S3Request('PUT', $bucket, $uri, $this -> endpoint,$this); $rest->setParameter('acl', null); $rest->data = $dom->saveXML(); $rest->size = strlen($rest->data); $rest->setHeader('Content-Type', 'application/xml'); $rest = $rest->getResponse(); if ($rest->error === false && $rest->code !== 200) $rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status'); if ($rest->error !== false) { $this -> __triggerError(sprintf("S3::setAccessControlPolicy({$bucket}, {$uri}): [%s] %s", $rest->error['code'], $rest->error['message']), __FILE__, __LINE__); return false; } return true; } /** * Get object or bucket Access Control Policy * * @param string $bucket Bucket name * @param string $uri Object URI * @return mixed | false */ public function getAccessControlPolicy($bucket, $uri = '') { $rest = new MainWP_WPvivid_S3Request('GET', $bucket, $uri, $this -> endpoint,$this); $rest->setParameter('acl', null); $rest = $rest->getResponse(); if ($rest->error === false && $rest->code !== 200) $rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status'); if ($rest->error !== false) { $this -> __triggerError(sprintf("S3::getAccessControlPolicy({$bucket}, {$uri}): [%s] %s", $rest->error['code'], $rest->error['message']), __FILE__, __LINE__); return false; } $acp = array(); if (isset($rest->body->Owner, $rest->body->Owner->ID, $rest->body->Owner->DisplayName)) $acp['owner'] = array( 'id' => (string)$rest->body->Owner->ID, 'name' => (string)$rest->body->Owner->DisplayName ); if (isset($rest->body->AccessControlList)) { $acp['acl'] = array(); foreach ($rest->body->AccessControlList->Grant as $grant) { foreach ($grant->Grantee as $grantee) { if (isset($grantee->ID, $grantee->DisplayName)) // CanonicalUser $acp['acl'][] = array( 'type' => 'CanonicalUser', 'id' => (string)$grantee->ID, 'name' => (string)$grantee->DisplayName, 'permission' => (string)$grant->Permission ); elseif (isset($grantee->EmailAddress)) // AmazonCustomerByEmail $acp['acl'][] = array( 'type' => 'AmazonCustomerByEmail', 'email' => (string)$grantee->EmailAddress, 'permission' => (string)$grant->Permission ); elseif (isset($grantee->URI)) // Group $acp['acl'][] = array( 'type' => 'Group', 'uri' => (string)$grantee->URI, 'permission' => (string)$grant->Permission ); else continue; } } } return $acp; } /** * Delete an object * * @param string $bucket Bucket name * @param string $uri Object URI * @return boolean */ public function deleteObject($bucket, $uri) { $rest = new MainWP_WPvivid_S3Request('DELETE', $bucket, $uri, $this -> endpoint,$this); $rest = $rest->getResponse(); if ($rest->error === false && $rest->code !== 204) $rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status'); if ($rest->error !== false) { $this -> __triggerError(sprintf("S3::deleteObject(): [%s] %s", $rest->error['code'], $rest->error['message']), __FILE__, __LINE__); return false; } return true; } /** * Get a query string authenticated URL * * @param string $bucket Bucket name * @param string $uri Object URI * @param integer $lifetime Lifetime in seconds * @param boolean $hostBucket Use the bucket name as the hostname * @param boolean $https Use HTTPS ($hostBucket should be false for SSL verification) * @return string */ public function getAuthenticatedURL($bucket, $uri, $lifetime, $hostBucket = false, $https = false) { $expires = $this -> __getTime() + $lifetime; $uri = str_replace(array('%2F', '%2B'), array('/', '+'), rawurlencode($uri)); return sprintf(($https ? 'https' : 'http').'://%s/%s?AWSAccessKeyId=%s&Expires=%u&Signature=%s', // $hostBucket ? $bucket : $bucket.'.s3.amazonaws.com', $uri, self::$__accessKey, $expires, $hostBucket ? $bucket : $this -> endpoint.'/'.$bucket, $uri, $this -> __accessKey, $expires, urlencode($this -> __getHash("GET\n\n\n{$expires}\n/{$bucket}/{$uri}"))); } /** * Get a CloudFront signed policy URL * * @param array $policy Policy * @return string */ public function getSignedPolicyURL($policy) { $data = wp_json_encode($policy); $signature = ''; if (!openssl_sign($data, $signature, $this -> __signingKeyResource)) return false; $encoded = str_replace(array('+', '='), array('-', '_', '~'), base64_encode($data)); $signature = str_replace(array('+', '='), array('-', '_', '~'), base64_encode($signature)); $url = $policy['Statement'][0]['Resource'] . '?'; foreach (array('Policy' => $encoded, 'Signature' => $signature, 'Key-Pair-Id' => $this -> __signingKeyPairId) as $k => $v) $url .= $k.'='.str_replace('%2F', '/', rawurlencode($v)).'&'; return substr($url, 0, -1); } /** * Get a CloudFront canned policy URL * * @param string $url URL to sign * @param integer $lifetime URL lifetime * @return string */ public function getSignedCannedURL($url, $lifetime) { return $this -> getSignedPolicyURL(array( 'Statement' => array( array('Resource' => $url, 'Condition' => array( 'DateLessThan' => array('AWS:EpochTime' => $this -> __getTime() + $lifetime) )) ) )); } /** * Get upload POST parameters for form uploads * * @param string $bucket Bucket name * @param string $uriPrefix Object URI prefix * @param constant $acl ACL constant * @param integer $lifetime Lifetime in seconds * @param integer $maxFileSize Maximum filesize in bytes (default 5MB) * @param string $successRedirect Redirect URL or 200 / 201 status code * @param array $amzHeaders Array of x-amz-meta-* headers * @param array $headers Array of request headers or content type as a string * @param boolean $flashVars Includes additional "Filename" variable posted by Flash * @return object */ public function getHttpUploadPostParams($bucket, $uriPrefix = '', $acl = self::ACL_PRIVATE, $lifetime = 3600, $maxFileSize = 5242880, $successRedirect = "201", $amzHeaders = array(), $headers = array(), $flashVars = false) { // Create policy object $policy = new stdClass; $policy->expiration = gmdate('Y-m-d\TH:i:s\Z', ($this -> __getTime() + $lifetime)); $policy->conditions = array(); $obj = new stdClass; $obj->bucket = $bucket; array_push($policy->conditions, $obj); $obj = new stdClass; $obj->acl = $acl; array_push($policy->conditions, $obj); $obj = new stdClass; // 200 for non-redirect uploads if (is_numeric($successRedirect) && in_array((int)$successRedirect, array(200, 201))) $obj->success_action_status = (string)$successRedirect; else // URL $obj->success_action_redirect = $successRedirect; array_push($policy->conditions, $obj); if ($acl !== self::ACL_PUBLIC_READ) array_push($policy->conditions, array('eq', '$acl', $acl)); array_push($policy->conditions, array('starts-with', '$key', $uriPrefix)); if ($flashVars) array_push($policy->conditions, array('starts-with', '$Filename', '')); foreach (array_keys($headers) as $headerKey) array_push($policy->conditions, array('starts-with', '$'.$headerKey, '')); foreach ($amzHeaders as $headerKey => $headerVal) { $obj = new stdClass; $obj->{$headerKey} = (string)$headerVal; array_push($policy->conditions, $obj); } array_push($policy->conditions, array('content-length-range', 0, $maxFileSize)); $policy = base64_encode(str_replace('\/', '/', wp_json_encode($policy))); // Create parameters $params = new stdClass; $params->AWSAccessKeyId = $this -> __accessKey; $params->key = $uriPrefix.'${filename}'; $params->acl = $acl; $params->policy = $policy; unset($policy); $params->signature = $this -> __getHash($params->policy); if (is_numeric($successRedirect) && in_array((int)$successRedirect, array(200, 201))) $params->success_action_status = (string)$successRedirect; else $params->success_action_redirect = $successRedirect; foreach ($headers as $headerKey => $headerVal) $params->{$headerKey} = (string)$headerVal; foreach ($amzHeaders as $headerKey => $headerVal) $params->{$headerKey} = (string)$headerVal; return $params; } /** * Create a CloudFront distribution * * @param string $bucket Bucket name * @param boolean $enabled Enabled (true/false) * @param array $cnames Array containing CNAME aliases * @param string $comment Use the bucket name as the hostname * @param string $defaultRootObject Default root object * @param string $originAccessIdentity Origin access identity * @param array $trustedSigners Array of trusted signers * @return array | false */ public function createDistribution($bucket, $enabled = true, $cnames = array(), $comment = null, $defaultRootObject = null, $originAccessIdentity = null, $trustedSigners = array()) { if (!extension_loaded('openssl')) { $this -> __triggerError(sprintf("S3::createDistribution({$bucket}, ".(int)$enabled.", [], '$comment'): %s", "CloudFront functionality requires SSL"), __FILE__, __LINE__); return false; } $useSSL = $this -> useSSL; $this -> useSSL = true; // CloudFront requires SSL $rest = new MainWP_WPvivid_S3Request('POST', '', '2010-11-01/distribution', 'cloudfront.amazonaws.com',$this); $rest->data = $this -> __getCloudFrontDistributionConfigXML( $bucket.'.s3.amazonaws.com', $enabled, (string)$comment, (string)microtime(true), $cnames, $defaultRootObject, $originAccessIdentity, $trustedSigners ); $rest->size = strlen($rest->data); $rest->setHeader('Content-Type', 'application/xml'); $rest = $this -> __getCloudFrontResponse($rest); $this -> useSSL = $useSSL; if ($rest->error === false && $rest->code !== 201) $rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status'); if ($rest->error !== false) { $this -> __triggerError(sprintf("S3::createDistribution({$bucket}, ".(int)$enabled.", [], '$comment'): [%s] %s", $rest->error['code'], $rest->error['message']), __FILE__, __LINE__); return false; } elseif ($rest->body instanceof SimpleXMLElement) return $this -> __parseCloudFrontDistributionConfig($rest->body); return false; } /** * Get CloudFront distribution info * * @param string $distributionId Distribution ID from listDistributions() * @return array | false */ public function getDistribution($distributionId) { if (!extension_loaded('openssl')) { $this -> __triggerError(sprintf("S3::getDistribution($distributionId): %s", "CloudFront functionality requires SSL"), __FILE__, __LINE__); return false; } $useSSL = $this -> useSSL; $this -> useSSL = true; // CloudFront requires SSL $rest = new MainWP_WPvivid_S3Request('GET', '', '2010-11-01/distribution/'.$distributionId, 'cloudfront.amazonaws.com',$this); $rest = $this -> __getCloudFrontResponse($rest); $this -> useSSL = $useSSL; if ($rest->error === false && $rest->code !== 200) $rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status'); if ($rest->error !== false) { $this -> __triggerError(sprintf("S3::getDistribution($distributionId): [%s] %s", $rest->error['code'], $rest->error['message']), __FILE__, __LINE__); return false; } elseif ($rest->body instanceof SimpleXMLElement) { $dist = $this -> __parseCloudFrontDistributionConfig($rest->body); $dist['hash'] = $rest->headers['hash']; $dist['id'] = $distributionId; return $dist; } return false; } /** * Update a CloudFront distribution * * @param array $dist Distribution array info identical to output of getDistribution() * @return array | false */ public function updateDistribution($dist) { if (!extension_loaded('openssl')) { $this -> __triggerError(sprintf("S3::updateDistribution({$dist['id']}): %s", "CloudFront functionality requires SSL"), __FILE__, __LINE__); return false; } $useSSL = $this -> useSSL; $this -> useSSL = true; // CloudFront requires SSL $rest = new MainWP_WPvivid_S3Request('PUT', '', '2010-11-01/distribution/'.$dist['id'].'/config', 'cloudfront.amazonaws.com',$this); $rest->data = $this -> __getCloudFrontDistributionConfigXML( $dist['origin'], $dist['enabled'], $dist['comment'], $dist['callerReference'], $dist['cnames'], $dist['defaultRootObject'], $dist['originAccessIdentity'], $dist['trustedSigners'] ); $rest->size = strlen($rest->data); $rest->setHeader('If-Match', $dist['hash']); $rest = $this -> __getCloudFrontResponse($rest); $this -> useSSL = $useSSL; if ($rest->error === false && $rest->code !== 200) $rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status'); if ($rest->error !== false) { $this -> __triggerError(sprintf("S3::updateDistribution({$dist['id']}): [%s] %s", $rest->error['code'], $rest->error['message']), __FILE__, __LINE__); return false; } else { $dist = $this -> __parseCloudFrontDistributionConfig($rest->body); $dist['hash'] = $rest->headers['hash']; return $dist; } return false; } /** * Delete a CloudFront distribution * * @param array $dist Distribution array info identical to output of getDistribution() * @return boolean */ public function deleteDistribution($dist) { if (!extension_loaded('openssl')) { $this -> __triggerError(sprintf("S3::deleteDistribution({$dist['id']}): %s", "CloudFront functionality requires SSL"), __FILE__, __LINE__); return false; } $useSSL = $this -> useSSL; $this -> useSSL = true; // CloudFront requires SSL $rest = new MainWP_WPvivid_S3Request('DELETE', '', '2008-06-30/distribution/'.$dist['id'], 'cloudfront.amazonaws.com',$this); $rest->setHeader('If-Match', $dist['hash']); $rest = $this -> __getCloudFrontResponse($rest); $this -> useSSL = $useSSL; if ($rest->error === false && $rest->code !== 204) $rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status'); if ($rest->error !== false) { $this -> __triggerError(sprintf("S3::deleteDistribution({$dist['id']}): [%s] %s", $rest->error['code'], $rest->error['message']), __FILE__, __LINE__); return false; } return true; } /** * Get a list of CloudFront distributions * * @return array */ public function listDistributions() { if (!extension_loaded('openssl')) { $this -> __triggerError(sprintf("S3::listDistributions(): [%s] %s", "CloudFront functionality requires SSL"), __FILE__, __LINE__); return false; } $useSSL =$this -> useSSL; $this -> useSSL = true; // CloudFront requires SSL $rest = new MainWP_WPvivid_S3Request('GET', '', '2010-11-01/distribution', 'cloudfront.amazonaws.com',$this); $rest = self::__getCloudFrontResponse($rest); $this -> useSSL = $useSSL; if ($rest->error === false && $rest->code !== 200) $rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status'); if ($rest->error !== false) { $this -> __triggerError(sprintf("S3::listDistributions(): [%s] %s", $rest->error['code'], $rest->error['message']), __FILE__, __LINE__); return false; } elseif ($rest->body instanceof SimpleXMLElement && isset($rest->body->DistributionSummary)) { $list = array(); if (isset($rest->body->Marker, $rest->body->MaxItems, $rest->body->IsTruncated)) { //$info['marker'] = (string)$rest->body->Marker; //$info['maxItems'] = (int)$rest->body->MaxItems; //$info['isTruncated'] = (string)$rest->body->IsTruncated == 'true' ? true : false; } foreach ($rest->body->DistributionSummary as $summary) $list[(string)$summary->Id] = self::__parseCloudFrontDistributionConfig($summary); return $list; } return array(); } /** * List CloudFront Origin Access Identities * * @return array */ public function listOriginAccessIdentities() { if (!extension_loaded('openssl')) { $this -> __triggerError(sprintf("S3::listOriginAccessIdentities(): [%s] %s", "CloudFront functionality requires SSL"), __FILE__, __LINE__); return false; } $this -> useSSL = true; // CloudFront requires SSL $rest = new MainWP_WPvivid_S3Request('GET', '', '2010-11-01/origin-access-identity/cloudfront', 'cloudfront.amazonaws.com',$this); $rest = self::__getCloudFrontResponse($rest); $useSSL = $this -> useSSL; if ($rest->error === false && $rest->code !== 200) $rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status'); if ($rest->error !== false) { trigger_error(sprintf("S3::listOriginAccessIdentities(): [%s] %s", esc_html($rest->error['code']), esc_html($rest->error['message'])), E_USER_WARNING); return false; } if (isset($rest->body->CloudFrontOriginAccessIdentitySummary)) { $identities = array(); foreach ($rest->body->CloudFrontOriginAccessIdentitySummary as $identity) if (isset($identity->S3CanonicalUserId)) $identities[(string)$identity->Id] = array('id' => (string)$identity->Id, 's3CanonicalUserId' => (string)$identity->S3CanonicalUserId); return $identities; } return false; } /** * Invalidate objects in a CloudFront distribution * * Thanks to Martin Lindkvist for S3::invalidateDistribution() * * @param string $distributionId Distribution ID from listDistributions() * @param array $paths Array of object paths to invalidate * @return boolean */ public function invalidateDistribution($distributionId, $paths) { if (!extension_loaded('openssl')) { $this -> __triggerError(sprintf("S3::invalidateDistribution(): [%s] %s", "CloudFront functionality requires SSL"), __FILE__, __LINE__); return false; } $useSSL = $this -> useSSL; $this -> useSSL = true; // CloudFront requires SSL $rest = new MainWP_WPvivid_S3Request('POST', '', '2010-08-01/distribution/'.$distributionId.'/invalidation', 'cloudfront.amazonaws.com',$this); $rest->data = self::__getCloudFrontInvalidationBatchXML($paths, (string)microtime(true)); $rest->size = strlen($rest->data); $rest = self::__getCloudFrontResponse($rest); $this -> useSSL = $useSSL; if ($rest->error === false && $rest->code !== 201) $rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status'); if ($rest->error !== false) { trigger_error(esc_html(sprintf("S3::invalidate('{$distributionId}',{$paths}): [%s] %s", $rest->error['code'], $rest->error['message'])), E_USER_WARNING); return false; } return true; } /** * Get a InvalidationBatch DOMDocument * * @internal Used to create XML in invalidateDistribution() * @param array $paths Paths to objects to invalidateDistribution * @param int $callerReference * @return string */ private function __getCloudFrontInvalidationBatchXML($paths, $callerReference = '0') { $dom = new DOMDocument('1.0', 'UTF-8'); $dom->formatOutput = true; $invalidationBatch = $dom->createElement('InvalidationBatch'); foreach ($paths as $path) $invalidationBatch->appendChild($dom->createElement('Path', $path)); $invalidationBatch->appendChild($dom->createElement('CallerReference', $callerReference)); $dom->appendChild($invalidationBatch); return $dom->saveXML(); } /** * List your invalidation batches for invalidateDistribution() in a CloudFront distribution * * http://docs.amazonwebservices.com/AmazonCloudFront/latest/APIReference/ListInvalidation.html * returned array looks like this: * Array * ( * [I31TWB0CN9V6XD] => InProgress * [IT3TFE31M0IHZ] => Completed * [I12HK7MPO1UQDA] => Completed * [I1IA7R6JKTC3L2] => Completed * ) * * @param string $distributionId Distribution ID from listDistributions() * @return array */ public function getDistributionInvalidationList($distributionId) { if (!extension_loaded('openssl')) { $this -> __triggerError(sprintf("S3::getDistributionInvalidationList(): [%s] %s", "CloudFront functionality requires SSL"), __FILE__, __LINE__); return false; } $useSSL = $this -> useSSL; $this -> useSSL = true; // CloudFront requires SSL $rest = new MainWP_WPvivid_S3Request('GET', '', '2010-11-01/distribution/'.$distributionId.'/invalidation', 'cloudfront.amazonaws.com',$this); $rest = $this -> __getCloudFrontResponse($rest); $this -> useSSL = $useSSL; if ($rest->error === false && $rest->code !== 200) $rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status'); if ($rest->error !== false) { trigger_error(esc_html(sprintf("S3::getDistributionInvalidationList('{$distributionId}'): [%s]", $rest->error['code'], $rest->error['message'])), E_USER_WARNING); return false; } elseif ($rest->body instanceof SimpleXMLElement && isset($rest->body->InvalidationSummary)) { $list = array(); foreach ($rest->body->InvalidationSummary as $summary) $list[(string)$summary->Id] = (string)$summary->Status; return $list; } return array(); } /** * Get a DistributionConfig DOMDocument * * http://docs.amazonwebservices.com/AmazonCloudFront/latest/APIReference/index.html?PutConfig.html * * @internal Used to create XML in createDistribution() and updateDistribution() * @param string $bucket S3 Origin bucket * @param boolean $enabled Enabled (true/false) * @param string $comment Comment to append * @param string $callerReference Caller reference * @param array $cnames Array of CNAME aliases * @param string $defaultRootObject Default root object * @param string $originAccessIdentity Origin access identity * @param array $trustedSigners Array of trusted signers * @return string */ private function __getCloudFrontDistributionConfigXML($bucket, $enabled, $comment, $callerReference = '0', $cnames = array(), $defaultRootObject = null, $originAccessIdentity = null, $trustedSigners = array()) { $dom = new DOMDocument('1.0', 'UTF-8'); $dom->formatOutput = true; $distributionConfig = $dom->createElement('DistributionConfig'); $distributionConfig->setAttribute('xmlns', 'http://cloudfront.amazonaws.com/doc/2010-11-01/'); $origin = $dom->createElement('S3Origin'); $origin->appendChild($dom->createElement('DNSName', $bucket)); if ($originAccessIdentity !== null) $origin->appendChild($dom->createElement('OriginAccessIdentity', $originAccessIdentity)); $distributionConfig->appendChild($origin); if ($defaultRootObject !== null) $distributionConfig->appendChild($dom->createElement('DefaultRootObject', $defaultRootObject)); $distributionConfig->appendChild($dom->createElement('CallerReference', $callerReference)); foreach ($cnames as $cname) $distributionConfig->appendChild($dom->createElement('CNAME', $cname)); if ($comment !== '') $distributionConfig->appendChild($dom->createElement('Comment', $comment)); $distributionConfig->appendChild($dom->createElement('Enabled', $enabled ? 'true' : 'false')); $trusted = $dom->createElement('TrustedSigners'); foreach ($trustedSigners as $id => $type) $trusted->appendChild($id !== '' ? $dom->createElement($type, $id) : $dom->createElement($type)); $distributionConfig->appendChild($trusted); $dom->appendChild($distributionConfig); //var_dump($dom->saveXML()); return $dom->saveXML(); } /** * Parse a CloudFront distribution config * * See http://docs.amazonwebservices.com/AmazonCloudFront/latest/APIReference/index.html?GetDistribution.html * * @internal Used to parse the CloudFront DistributionConfig node to an array * @param object &$node DOMNode * @return array */ private function __parseCloudFrontDistributionConfig(&$node) { if (isset($node->DistributionConfig)) return $this -> __parseCloudFrontDistributionConfig($node->DistributionConfig); $dist = array(); if (isset($node->Id, $node->Status, $node->LastModifiedTime, $node->DomainName)) { $dist['id'] = (string)$node->Id; $dist['status'] = (string)$node->Status; $dist['time'] = strtotime((string)$node->LastModifiedTime); $dist['domain'] = (string)$node->DomainName; } if (isset($node->CallerReference)) $dist['callerReference'] = (string)$node->CallerReference; if (isset($node->Enabled)) $dist['enabled'] = (string)$node->Enabled == 'true' ? true : false; if (isset($node->S3Origin)) { if (isset($node->S3Origin->DNSName)) $dist['origin'] = (string)$node->S3Origin->DNSName; $dist['originAccessIdentity'] = isset($node->S3Origin->OriginAccessIdentity) ? (string)$node->S3Origin->OriginAccessIdentity : null; } $dist['defaultRootObject'] = isset($node->DefaultRootObject) ? (string)$node->DefaultRootObject : null; $dist['cnames'] = array(); if (isset($node->CNAME)) foreach ($node->CNAME as $cname) $dist['cnames'][(string)$cname] = (string)$cname; $dist['trustedSigners'] = array(); if (isset($node->TrustedSigners)) foreach ($node->TrustedSigners as $signer) { if (isset($signer->Self)) $dist['trustedSigners'][''] = 'Self'; elseif (isset($signer->KeyPairId)) $dist['trustedSigners'][(string)$signer->KeyPairId] = 'KeyPairId'; elseif (isset($signer->AwsAccountNumber)) $dist['trustedSigners'][(string)$signer->AwsAccountNumber] = 'AwsAccountNumber'; } $dist['comment'] = isset($node->Comment) ? (string)$node->Comment : null; return $dist; } /** * Grab CloudFront response * * @internal Used to parse the CloudFront MainWP_WPvivid_S3Request::getResponse() output * @param object &$rest MainWP_WPvivid_S3Request instance * @return object */ private function __getCloudFrontResponse(&$rest) { $rest->getResponse(); if ($rest->response->error === false && isset($rest->response->body) && is_string($rest->response->body) && substr($rest->response->body, 0, 5) == '<?xml') { $rest->response->body = simplexml_load_string($rest->response->body); // Grab CloudFront errors if (isset($rest->response->body->Error, $rest->response->body->Error->Code, $rest->response->body->Error->Message)) { $rest->response->error = array( 'code' => (string)$rest->response->body->Error->Code, 'message' => (string)$rest->response->body->Error->Message ); unset($rest->response->body); } } return $rest->response; } /** * Get MIME type for file * * To override the putObject() Content-Type, add it to $requestHeaders * * To use fileinfo, ensure the MAGIC environment variable is set * * @internal Used to get mime types * @param string &$file File path * @return string */ private function __getMIMEType(&$file) { $exts = array( 'jpg' => 'image/jpeg', 'jpeg' => 'image/jpeg', 'gif' => 'image/gif', 'png' => 'image/png', 'ico' => 'image/x-icon', 'pdf' => 'application/pdf', 'tif' => 'image/tiff', 'tiff' => 'image/tiff', 'svg' => 'image/svg+xml', 'svgz' => 'image/svg+xml', 'swf' => 'application/x-shockwave-flash', 'zip' => 'application/zip', 'gz' => 'application/x-gzip', 'tar' => 'application/x-tar', 'bz' => 'application/x-bzip', 'bz2' => 'application/x-bzip2', 'rar' => 'application/x-rar-compressed', 'exe' => 'application/x-msdownload', 'msi' => 'application/x-msdownload', 'cab' => 'application/vnd.ms-cab-compressed', 'txt' => 'text/plain', 'asc' => 'text/plain', 'htm' => 'text/html', 'html' => 'text/html', 'css' => 'text/css', 'js' => 'text/javascript', 'xml' => 'text/xml', 'xsl' => 'application/xsl+xml', 'ogg' => 'application/ogg', 'mp3' => 'audio/mpeg', 'wav' => 'audio/x-wav', 'avi' => 'video/x-msvideo', 'mpg' => 'video/mpeg', 'mpeg' => 'video/mpeg', 'mov' => 'video/quicktime', 'flv' => 'video/x-flv', 'php' => 'text/x-php' ); $ext = strtolower(pathinfo($file, PATHINFO_EXTENSION)); if (isset($exts[$ext])) return $exts[$ext]; // Use fileinfo if available if (extension_loaded('fileinfo') && isset($_ENV['MAGIC']) && ($finfo = finfo_open(FILEINFO_MIME, $_ENV['MAGIC'])) !== false) { if (($type = finfo_file($finfo, $file)) !== false) { // Remove the charset and grab the last content-type $type = explode(' ', str_replace('; charset=', ';charset=', $type)); $type = array_pop($type); $type = explode(';', $type); $type = trim(array_shift($type)); } finfo_close($finfo); if ($type !== false && strlen($type) > 0) return $type; } return 'application/octet-stream'; } /** * Get the current time * * @internal Used to apply offsets to sytem time * @return integer */ public function __getTime() { return time() + $this -> __timeOffset; } /** * Generate the auth string: "AWS AccessKey:Signature" * * @internal Used by MainWP_WPvivid_S3Request::getResponse() * @param string $string String to sign * @return string */ public function __getSignature($string) { return 'AWS '.$this -> __accessKey.':'.$this -> __getHash($string); } /** * Creates a HMAC-SHA1 hash * * This uses the hash extension if loaded * * @internal Used by __getSignature() * @param string $string String to sign * @return string */ private function __getHash($string) { return base64_encode(extension_loaded('hash') ? hash_hmac('sha1', $string, $this -> __secretKey, true) : pack('H*', sha1( (str_pad($this -> __secretKey, 64, chr(0x00)) ^ (str_repeat(chr(0x5c), 64))) . pack('H*', sha1((str_pad($this -> __secretKey, 64, chr(0x00)) ^ (str_repeat(chr(0x36), 64))) . $string))))); } /** * Generate the headers for AWS Signature V4 * * @internal Used by UpdraftPlus_S3Request::getResponse() * @param array $aHeaders amzHeaders * @param array $headers * @param string $method * @param string $uri * @param string $data * * @return array $headers */ public function __getSignatureV4($aHeaders, $headers, $method = 'GET', $uri = '', $data = '') {// phpcs:ignore PHPCompatibility.FunctionNameRestrictions.ReservedFunctionNames.MethodDoubleUnderscore -- Method name "UpdraftPlus_S3Request::__responseHeaderCallback" is discouraged; PHP has reserved all method names with a double underscore prefix for future use. $service = 's3'; $region = $this->getRegion(); $algorithm = 'AWS4-HMAC-SHA256'; $amzHeaders = array(); $amzRequests = array(); $amzDate = gmdate('Ymd\THis\Z'); $amzDateStamp = gmdate('Ymd'); // amz-date ISO8601 format? for aws request $amzHeaders['x-amz-date'] = $amzDate; // CanonicalHeaders foreach ($headers as $k => $v) { $amzHeaders[strtolower($k)] = trim($v); } foreach ($aHeaders as $k => $v) { $amzHeaders[strtolower($k)] = trim($v); } uksort($amzHeaders, 'strcmp'); // payload $payloadHash = isset($amzHeaders['x-amz-content-sha256']) ? $amzHeaders['x-amz-content-sha256'] : hash('sha256', $data); // parameters $parameters = array(); if (strpos($uri, '?')) { list($uri, $query_str) = @explode('?', $uri); parse_str($query_str, $parameters); } // Canonical Requests $amzRequests[] = $method; $uriQmPos = strpos($uri, '?'); $amzRequests[] = (false === $uriQmPos ? $uri : substr($uri, 0, $uriQmPos)); $amzRequests[] = http_build_query($parameters); // add headers as string to requests foreach ($amzHeaders as $k => $v) { $amzRequests[] = $k . ':' . $v; } // add a blank entry so we end up with an extra line break $amzRequests[] = ''; // SignedHeaders $amzRequests[] = implode(';', array_keys($amzHeaders)); // payload hash $amzRequests[] = $payloadHash; // request as string $amzRequestStr = implode("\n", $amzRequests); // CredentialScope $credentialScope = array(); $credentialScope[] = $amzDateStamp; $credentialScope[] = $region; $credentialScope[] = $service; $credentialScope[] = 'aws4_request'; // stringToSign $stringToSign = array(); $stringToSign[] = $algorithm; $stringToSign[] = $amzDate; $stringToSign[] = implode('/', $credentialScope); $stringToSign[] = hash('sha256', $amzRequestStr); // as string $stringToSignStr = implode("\n", $stringToSign); // Make Signature $kSecret = 'AWS4' . $this->__secretKey; $kDate = hash_hmac('sha256', $amzDateStamp, $kSecret, true); $kRegion = hash_hmac('sha256', $region, $kDate, true); $kService = hash_hmac('sha256', $service, $kRegion, true); $kSigning = hash_hmac('sha256', 'aws4_request', $kService, true); $signature = hash_hmac('sha256', $stringToSignStr, $kSigning); $authorization = array( 'Credential=' . $this->__accessKey . '/' . implode('/', $credentialScope), 'SignedHeaders=' . implode(';', array_keys($amzHeaders)), 'Signature=' . $signature, ); $authorizationStr = $algorithm . ' ' . implode(',', $authorization); $resultHeaders = array( 'X-AMZ-DATE' => $amzDate, 'Authorization' => $authorizationStr ); if (!isset($aHeaders['x-amz-content-sha256'])) { $resultHeaders['x-amz-content-sha256'] = $payloadHash; } return $resultHeaders; } } /** * S3 Request class * * @link http://undesigned.org.za/2007/10/22/amazon-s3-php-class * @version 0.5.0-dev */ final class MainWP_WPvivid_S3Request { /** * AWS URI * * @var string * @access private */ private $endpoint; /** * Verb * * @var string * @access private */ private $verb; /** * S3 bucket name * * @var string * @access private */ private $bucket; /** * Object URI * * @var string * @access private */ private $uri; /** * Final object URI * * @var string * @access private */ private $resource = ''; /** * Additional request parameters * * @var array * @access private */ private $parameters = array(); /** * Amazon specific request headers * * @var array * @access private */ private $amzHeaders = array(); /** * HTTP request headers * * @var array * @access private */ private $headers = array( 'Host' => '', 'Date' => '', 'Content-MD5' => '', 'Content-Type' => '' ); /** * Use HTTP PUT? * * @var bool * @access public */ public $fp = false; /** * PUT file size * * @var int * @access public */ public $size = 0; /** * PUT post fields * * @var array * @access public */ public $data = false; /** * S3 request respone * * @var object * @access public */ public $response; private $s3; /** * Constructor * * @param string $verb Verb * @param string $bucket Bucket name * @param string $uri Object URI * @param string $endpoint AWS endpoint URI * @return mixed */ function __construct($verb, $bucket = '', $uri = '', $endpoint = 's3.amazonaws.com', $s3 = null) { $this->endpoint = $endpoint; $this->verb = $verb; $this->bucket = $bucket; $this->uri = $uri !== '' ? '/'.str_replace('%2F', '/', rawurlencode($uri)) : '/'; $this -> s3 = $s3; if ($this->bucket !== '') { $this->headers['Host'] = $this->endpoint; $this->uri = $this->uri; if ($this->bucket !== '') $this->uri = '/'.$this->bucket.$this->uri; $this->bucket = ''; $this->resource = $this->uri; } else { $this->headers['Host'] = $this->endpoint; $this->resource = $this->uri; } $this->headers['Date'] = gmdate('D, d M Y H:i:s T'); $this->response = new STDClass; $this->response->error = false; $this->response->body = null; $this->response->headers = array(); } /** * Set request parameter * * @param string $key Key * @param string $value Value * @return void */ public function setParameter($key, $value) { $this->parameters[$key] = $value; } /** * Set request header * * @param string $key Key * @param string $value Value * @return void */ public function setHeader($key, $value) { $this->headers[$key] = $value; } /** * Set x-amz-meta-* header * * @param string $key Key * @param string $value Value * @return void */ public function setAmzHeader($key, $value) { $this->amzHeaders[$key] = $value; } /** * Get the S3 response * * @return object | false */ public function getResponse() { $query = ''; if (sizeof($this->parameters) > 0) { $query = ('?' !== substr($this->uri, -1)) ? '?' : '&'; foreach ($this->parameters as $var => $value) if (null == $value || '' == $value) $query .= $var.'&'; else $query .= $var.'='.rawurlencode($value).'&'; $query = substr($query, 0, -1); $this->uri .= $query; if (array_key_exists('acl', $this->parameters) || array_key_exists('location', $this->parameters) || array_key_exists('torrent', $this->parameters) || array_key_exists('logging', $this->parameters) || array_key_exists('partNumber', $this->parameters) || array_key_exists('uploads', $this->parameters) || array_key_exists('uploadId', $this->parameters)) $this->resource .= $query; } $url = ($this->s3->useSSL ? 'https://' : 'http://') . ('' !== $this->headers['Host'] ? $this->headers['Host'] : $this->endpoint) . $this->uri; //var_dump('bucket: ' . $this->bucket, 'uri: ' . $this->uri, 'resource: ' . $this->resource, 'url: ' . $url); $curl = curl_init(); curl_setopt($curl, CURLOPT_USERAGENT, 'S3/php'); if ($this->s3->useSSL) { // SSL Validation can now be optional for those with broken OpenSSL installations curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, $this->s3->useSSLValidation ? 2 : 0); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, $this->s3->useSSLValidation ? 1 : 0); if (null !== $this->s3->sslKey) curl_setopt($curl, CURLOPT_SSLKEY, $this->s3->sslKey); if (null !== $this->s3->sslCert) curl_setopt($curl, CURLOPT_SSLCERT, $this->s3->sslCert); if (null !== $this->s3->sslCACert) curl_setopt($curl, CURLOPT_CAINFO, $this->s3->sslCACert); } curl_setopt($curl, CURLOPT_URL, $url); // Headers $headers = array(); $amz = array(); foreach ($this->amzHeaders as $header => $value) if (strlen($value) > 0) $headers[] = $header.': '.$value; foreach ($this->headers as $header => $value) if (strlen($value) > 0) $headers[] = $header . ': ' . $value; // Collect AMZ headers for signature foreach ($this->amzHeaders as $header => $value) if (strlen($value) > 0) $amz[] = strtolower($header).':'.$value; // AMZ headers must be sorted if (sizeof($amz) > 0) { //sort($amz); usort($amz, array(&$this, '__sortMetaHeadersCmp')); $amz = "\n".implode("\n", $amz); } else { $amz = ''; } if ($this->s3->hasAuth()) { // Authorization string (CloudFront stringToSign should only contain a date) if ('cloudfront.amazonaws.com' == $this->headers['Host']) { $headers[] = 'Authorization: ' . $this->s3->__getSignature($this->headers['Date']); } else { if ('v2' === $this->s3->signVer) { $headers[] = 'Authorization: ' . $this->s3->__getSignature( $this->verb."\n". $this->headers['Content-MD5']."\n". $this->headers['Content-Type']."\n". $this->headers['Date'].$amz."\n". $this->resource ); } else { $amzHeaders = $this->s3->__getSignatureV4( $this->amzHeaders, $this->headers, $this->verb, $this->uri, $this->data ); foreach ($amzHeaders as $k => $v) { $headers[] = $k . ': ' . $v; } } } } // if (false !== $this->s3->port) curl_setopt($curl, CURLOPT_PORT, $this->s3->port); curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); curl_setopt($curl, CURLOPT_HEADER, false); curl_setopt($curl, CURLOPT_RETURNTRANSFER, false); curl_setopt($curl, CURLOPT_WRITEFUNCTION, array(&$this, '__responseWriteCallback')); curl_setopt($curl, CURLOPT_HEADERFUNCTION, array(&$this, '__responseHeaderCallback')); @curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); // Request types switch ($this->verb) { case 'GET': break; case 'PUT': case 'POST': if (false !== $this->fp) { curl_setopt($curl, CURLOPT_PUT, true); curl_setopt($curl, CURLOPT_INFILE, $this->fp); if ($this->size >= 0) { curl_setopt($curl, CURLOPT_INFILESIZE, $this->size); } } elseif (false !== $this->data) { curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $this->verb); curl_setopt($curl, CURLOPT_POSTFIELDS, $this->data); curl_setopt($curl, CURLOPT_INFILESIZE, strlen($this->data)); } else { curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $this->verb); } break; case 'HEAD': curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'HEAD'); curl_setopt($curl, CURLOPT_NOBODY, true); break; case 'DELETE': curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'DELETE'); break; default: break; } // Execute, grab errors if (curl_exec($curl)) $this->response->code = curl_getinfo($curl, CURLINFO_HTTP_CODE); else $this->response->error = array( 'code' => curl_errno($curl), 'message' => curl_error($curl), 'resource' => $this->resource ); @curl_close($curl); // Parse body into XML // The case in which there is not application/xml content-type header is to support a DreamObjects case seen, April 2018 if (false === $this->response->error && isset($this->response->body) && ((isset($this->response->headers['type']) && 'application/xml' == $this->response->headers['type']) || (!isset($this->response->headers['type']) && 0 === strpos($this->response->body, '<?xml')))) { $this->response->body = simplexml_load_string($this->response->body); // Grab S3 errors if (!in_array($this->response->code, array(200, 204, 206)) && isset($this->response->body->Code)) { $this->response->error = array( 'code' => (string)$this->response->body->Code, ); $this->response->error['message'] = isset($this->response->body->Message) ? $this->response->body->Message : ''; if (isset($this->response->body->Resource)) $this->response->error['resource'] = (string)$this->response->body->Resource; unset($this->response->body); } } // Clean up file resources // if (false !== $this->fp && is_resource($this->fp)) fclose($this->fp); return $this->response; } /** * Sort compare for meta headers * * @internal Used to sort x-amz meta headers * @param string $a String A * @param string $b String B * @return integer */ private function __sortMetaHeadersCmp($a, $b) { $lenA = strpos($a, ':'); $lenB = strpos($b, ':'); $minLen = min($lenA, $lenB); $ncmp = strncmp($a, $b, $minLen); if ($lenA == $lenB) return $ncmp; if (0 == $ncmp) return $lenA < $lenB ? -1 : 1; return $ncmp; } /** * CURL write callback * * @param resource &$curl CURL resource * @param string &$data Data * @return integer */ private function __responseWriteCallback(&$curl, &$data) { if (in_array($this->response->code, array(200, 206)) && $this->fp !== false) return fwrite($this->fp, $data); else $this->response->body .= $data; return strlen($data); } // /** // * Check DNS conformity // * // * @param string $bucket Bucket name // * @return boolean // */ // private function __dnsBucketName($bucket) // { // if (strlen($bucket) > 63 || preg_match("/[^a-z0-9\.-]/", $bucket)) return false; // if ($this -> s3 -> useSSL && strstr($bucket, '.') !== false) return false; // if (strstr($bucket, '-.') !== false) return false; // if (strstr($bucket, '..') !== false) return false; // if (!preg_match("/^[0-9a-z]/", $bucket)) return false; // if (!preg_match("/[0-9a-z]$/", $bucket)) return false; // return true; // } /** * CURL header callback * * @param resource $curl CURL resource * @param string $data Data * @return integer */ private function __responseHeaderCallback($curl, $data) { if (($strlen = strlen($data)) <= 2) return $strlen; if (substr($data, 0, 4) == 'HTTP') $this->response->code = (int)substr($data, 9, 3); else { $data = trim($data); if (strpos($data, ': ') === false) return $strlen; list($header, $value) = explode(': ', $data, 2); if ($header == 'Last-Modified') $this->response->headers['time'] = strtotime($value); elseif ($header == 'Date') $this->response->headers['date'] = strtotime($value); elseif ($header == 'Content-Length') $this->response->headers['size'] = (int)$value; elseif ($header == 'Content-Type') $this->response->headers['type'] = $value; elseif ($header == 'ETag') $this->response->headers['hash'] = $value[0] == '"' ? substr($value, 1, -1) : $value; elseif (preg_match('/^x-amz-meta-.*$/', $header)) $this->response->headers[$header] = $value; } return $strlen; } } /** * S3 exception class * * @link http://undesigned.org.za/2007/10/22/amazon-s3-php-class * @version 0.5.0-dev */ class Mainwp_WPvivid_S3Exception extends Exception { /** * Class constructor * * @param string $message Exception message * @param string $file File in which exception was created * @param string $line Line number on which exception was created * @param int $code Exception code */ function __construct($message, $file, $line, $code = 0) { parent::__construct($message, $code); $this->file = $file; $this->line = $line; } } includes/customclass/class-wpvivid-extend-sftp.php 0000644 00000010744 15133715745 0016476 0 ustar 00 <?php if (!defined('MAINWP_WPVIVID_EXTENSION_PLUGIN_DIR')){ die; } include_once MAINWP_WPVIVID_EXTENSION_PLUGIN_DIR.'/vendor/autoload.php'; class WPvivid_Net_SFTP extends Net_SFTP { function get($remote_file, $local_file = false, $offset = 0, $length = -1, $callback = null) { if (!($this->bitmap & NET_SSH2_MASK_LOGIN)) { return false; } $remote_file = $this->_realpath($remote_file); if ($remote_file === false) { return false; } $packet = pack('Na*N2', strlen($remote_file), $remote_file, NET_SFTP_OPEN_READ, 0); if (!$this->_send_sftp_packet(NET_SFTP_OPEN, $packet)) { return false; } $response = $this->_get_sftp_packet(); switch ($this->packet_type) { case NET_SFTP_HANDLE: $handle = substr($response, 4); break; case NET_SFTP_STATUS: $this->_logError($response); return false; default: user_error('Expected SSH_FXP_HANDLE or SSH_FXP_STATUS'); return false; } if (is_resource($local_file)) { $fp = $local_file; $stat = fstat($fp); $res_offset = $stat['size']; } else { $res_offset = 0; if ($local_file !== false) { $fp = fopen($local_file, 'wb'); if (!$fp) { return false; } } else { $content = ''; } } $fclose_check = $local_file !== false && !is_resource($local_file); $start = $offset; $read = 0; while (true) { $i = 0; while ($i < NET_SFTP_QUEUE_SIZE && ($length < 0 || $read < $length)) { $tempoffset = $start + $read; $packet_size = $length > 0 ? min($this->max_sftp_packet, $length - $read) : $this->max_sftp_packet; $packet = pack('Na*N3', strlen($handle), $handle, $tempoffset / 4294967296, $tempoffset, $packet_size); if (!$this->_send_sftp_packet(NET_SFTP_READ, $packet)) { if ($fclose_check) { fclose($fp); } return false; } $packet = null; $read+= $packet_size; $i++; } if (!$i) { break; } $clear_responses = false; while ($i > 0) { $i--; if ($clear_responses) { $this->_get_sftp_packet(); continue; } else { $response = $this->_get_sftp_packet(); } switch ($this->packet_type) { case NET_SFTP_DATA: $temp = substr($response, 4); $offset+= strlen($temp); if ($local_file === false) { $content.= $temp; } else { fputs($fp, $temp); } if( is_callable($callback)){ call_user_func_array($callback,array($offset)); } $temp = null; break; case NET_SFTP_STATUS: $this->_logError($response); $clear_responses = true; break; default: if ($fclose_check) { fclose($fp); } user_error('Expected SSH_FX_DATA or SSH_FXP_STATUS'); } $response = null; } if ($clear_responses) { break; } } if ($length > 0 && $length <= $offset - $start) { if ($local_file === false) { $content = substr($content, 0, $length); } else { ftruncate($fp, $length + $res_offset); } } if ($fclose_check) { fclose($fp); } if (!$this->_close_handle($handle)) { return false; } return isset($content) ? $content : true; } } includes/customclass/class-wpvivid-remote.php 0000644 00000000530 15133715745 0015520 0 ustar 00 <?php if (!defined('MAINWP_WPVIVID_EXTENSION_PLUGIN_DIR')){ die; } abstract class Mainwp_WPvivid_Remote{ public $current_file_name = ''; public $current_file_size = ''; public $last_time = 0; public $last_size = 0; public $object; public $remote; abstract public function test_connect($is_pro); } includes/customclass/class-wpvivid-b2.php 0000644 00000037665 15133715745 0014553 0 ustar 00 <?php if (!defined('MAINWP_WPVIVID_EXTENSION_PLUGIN_DIR')){ die; } define('MAINWP_WPVIVID_REMOTE_B2','b2'); require_once MAINWP_WPVIVID_EXTENSION_PLUGIN_DIR . '/includes/customclass/class-wpvivid-remote.php'; class Mainwp_WPvivid_B2Class extends Mainwp_WPvivid_Remote { public $options; public function __construct($options=array()) { if(empty($options)) { if(!defined('MAINWP_WPVIVID_INIT_STORAGE_TAB_B2')) { add_action('mwp_wpvivid_add_storage_page_b2_addon', array($this, 'mwp_wpvivid_add_storage_page_b2_addon')); add_action('mwp_wpvivid_edit_storage_page_addon', array($this, 'mwp_wpvivid_edit_storage_page_b2_addon'), 11); add_filter('mwp_wpvivid_storage_provider_tran', array($this, 'mwp_wpvivid_storage_provider_b2'), 10); define('MAINWP_WPVIVID_INIT_STORAGE_TAB_B2',1); } } else { $this->options=$options; } } public function mwp_wpvivid_add_storage_page_b2_addon(){ ?> <div class="storage-account-page-addon" id="mwp_wpvivid_storage_account_b2_addon"> <div style="padding: 0 10px 10px 0;"><strong>Enter Your Backblaze Storage Account</strong></div> <table class="wp-list-table widefat plugins" style="width:100%;"> <tbody> <form> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input type="text" class="regular-text" autocomplete="off" option="b2-addon" name="name" placeholder="Enter a unique alias: e.g. B2-001" onkeyup="value=value.replace(/[^a-zA-Z0-9\-_]/g,'')" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>A name to help you identify the storage if you have multiple remote storage connected.</i> </div> </td> </tr> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input type="text" class="regular-text" autocomplete="off" option="b2-addon" name="appkeyid" placeholder="Application key id" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>Enter your Application Key ID.</i> </div> </td> </tr> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input type="text" class="regular-text" autocomplete="off" option="b2-addon" name="appkey" placeholder="Application key" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>Enter your Application Key.</i> </div> </td> </tr> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input type="text" class="regular-text" autocomplete="off" option="b2-addon" name="bucket" placeholder="Backblaze Bucket Name(e.g. test)" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i><span><?php /* translators: %s: Folder name. */ echo sprintf(esc_html('Enter an existing Bucket in which you want to create a parent folder for holding %s folders.', 'wpvivid'), esc_html(apply_filters('wpvivid_white_label_display', 'WPvivid backup'))); ?></span></i> </div> </td> </tr> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input type="text" class="regular-text" autocomplete="off" option="b2-addon" name="root_path" value="<?php echo esc_attr(apply_filters('wpvivid_white_label_remote_root_path', 'wpvividbackuppro')); ?>" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i><span><?php /* translators: %s: Folder name. */ echo sprintf(esc_html('Customize a parent folder in the Bucket for holding %s folders.', 'wpvivid'), esc_html(apply_filters('wpvivid_white_label_display', 'WPvivid backup'))); ?></span></i> </div> </td> </tr> <?php do_action('mwp_wpvivid_remote_storage_backup_retention', 'b2-addon', 'add'); ?> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input style="width: 50px" type="text" class="regular-text" autocomplete="off" option="b2-addon" name="chunk_size" placeholder="Chunk size" value="3" onkeyup="value=value.replace(/\D/g,'')" />MB </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>The block size of uploads and downloads. Reduce it if you encounter a timeout when transferring files.</i> </div> </td> </tr> </form> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input class="ui green mini button" option="add-remote-addon-global" type="button" value="Save and Sync" remote_type="b2" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>Click the button to connect to B2 storage and add it to the storage list below</i> </div> </td> </tr> </tbody> </table> </div> <?php } public function mwp_wpvivid_edit_storage_page_b2_addon() { ?> <div class="mwp-wpvivid-remote-storage-edit" id="mwp_wpvivid_storage_account_b2_edit" style="display:none;"> <div class="mwp-wpvivid-block-bottom-space" style="margin-top: 10px;"><strong>Enter Your Backblaze Storage Account</strong></div> <table class="wp-list-table widefat plugins" style="width:100%;"> <tbody> <form> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input type="text" class="regular-text" autocomplete="off" option="edit-b2-addon" name="name" placeholder="Enter a unique alias: e.g. B2-001" onkeyup="value=value.replace(/[^a-zA-Z0-9\-_]/g,'')" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>A name to help you identify the storage if you have multiple remote storage connected.</i> </div> </td> </tr> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input type="text" class="regular-text" autocomplete="off" option="edit-b2-addon" name="appkeyid" placeholder="Application key id" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>Enter your Application Key ID.</i> </div> </td> </tr> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input type="text" class="regular-text" autocomplete="off" option="edit-b2-addon" name="appkey" placeholder="Application key" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>Enter your Application Key.</i> </div> </td> </tr> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input type="text" class="regular-text" autocomplete="off" option="edit-b2-addon" name="bucket" placeholder="Backblaze Bucket Name(e.g. test)" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i><span><?php /* translators: %s: Folder name. */ echo sprintf(esc_html('Enter an existing Bucket in which you want to create a parent folder for holding %s folders.', 'wpvivid'), esc_html(apply_filters('wpvivid_white_label_display', 'WPvivid backup'))); ?></span></i> </div> </td> </tr> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input type="text" class="regular-text" autocomplete="off" option="edit-b2-addon" name="root_path" value="<?php echo esc_attr(apply_filters('wpvivid_white_label_remote_root_path', 'wpvividbackuppro')); ?>" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i><span><?php /* translators: %s: Folder name. */ echo sprintf(esc_html('Customize a parent folder in the Bucket for holding %s folders.', 'wpvivid'), esc_html(apply_filters('wpvivid_white_label_display', 'WPvivid backup'))); ?></span></i> </div> </td> </tr> <?php do_action('mwp_wpvivid_remote_storage_backup_retention', 'b2-addon', 'edit'); ?> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input style="width: 50px" type="text" class="regular-text" autocomplete="off" option="edit-b2-addon" name="chunk_size" placeholder="Chunk size" value="3" onkeyup="value=value.replace(/\D/g,'')" />MB </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>The block size of uploads and downloads. Reduce it if you encounter a timeout when transferring files.</i> </div> </td> </tr> </form> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input class="ui green mini button" option="edit-remote-addon-global" type="button" value="Save Changes" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>Click the button to connect to B2 storage and add it to the storage list below</i> </div> </td> </tr> </tbody> </table> </div> <?php } public function mwp_wpvivid_storage_provider_b2($storage_type){ if($storage_type == MAINWP_WPVIVID_REMOTE_B2){ $storage_type = 'Backblaze'; } return $storage_type; } public function sanitize_options($skip_name=''){ $ret['result']='failed'; if(!isset($this->options['name'])) { $ret['error']="Warning: An alias for remote storage is required."; return $ret; } $this->options['name']=sanitize_text_field($this->options['name']); if(empty($this->options['name'])) { $ret['error']="Warning: An alias for remote storage is required."; return $ret; } $remoteslist=Mainwp_WPvivid_Extension_DB_Option::get_instance()->wpvivid_get_global_option('remote_addon', array()); if(isset($remoteslist) && !empty($remoteslist)) { foreach ($remoteslist['upload'] as $key => $value) { if (isset($value['name']) && $value['name'] == $this->options['name'] && $skip_name != $value['name']) { $ret['error'] = "Warning: The alias already exists in storage list."; return $ret; } } } if(!isset($this->options['appkeyid'])) { $ret['error']="Warning: The app key id for Backblaze is required."; return $ret; } $this->options['appkeyid']=sanitize_text_field($this->options['appkeyid']); if(empty($this->options['appkeyid'])) { $ret['error']="Warning: The app key id for Backblaze is required."; return $ret; } if(!isset($this->options['appkey'])) { $ret['error']="Warning: The storage app key is required."; return $ret; } $this->options['appkey']=sanitize_text_field($this->options['appkey']); if(empty($this->options['appkey'])) { $ret['error']="Warning: The storage app key is required."; return $ret; } if(!isset($this->options['bucket'])) { $ret['error']="Warning: A Bucket name is required."; return $ret; } $this->options['bucket']=sanitize_text_field($this->options['bucket']); if(empty($this->options['bucket'])) { $ret['error']="Warning: A Bucket name is required."; return $ret; } $ret['result']='success'; $ret['options']=$this->options; return $ret; } public function test_connect($is_pro){ return array('result' => 'success'); } } includes/customclass/client_secrets.json 0000644 00000000625 15133715745 0014631 0 ustar 00 {"web":{"client_id":"134809148507-32crusepgace4h6g47ota99jjrvf4j1u.apps.googleusercontent.com","project_id":"wpvivid-auth","auth_uri":"https://accounts.google.com/o/oauth2/auth","token_uri":"https://oauth2.googleapis.com/token","auth_provider_x509_cert_url":"https://www.googleapis.com/oauth2/v1/certs","client_secret":"GmD5Kmg_1fTcf0ciNEomposy","redirect_uris":["https://auth.wpvivid.com/google_drive"]}} includes/customclass/class-wpvivid-base-s3.php 0000644 00000021466 15133715745 0015475 0 ustar 00 <?php if (!defined('MAINWP_WPVIVID_EXTENSION_PLUGIN_DIR')){ die; } include_once 'class-wpvivid-s3.php'; class MainWP_WPvivid_Base_S3 extends Mainwp_Wpvivid_S3{ var $signVer = 'v2'; /** * Set Signature Version * * @param string $version * @return void */ public function setSignatureVersion($version = 'v2') { $this->signVer = $version; } public function setServerSideEncryption($value = self::SSE_AES256) { $this->_serverSideEncryption = $value; } public function setStorageClass($value = self::STORAGE_CLASS_STANDARD_IA){ $this -> _storageClass = $value; } public function initiateMultipartUpload ($bucket, $uri, $acl = self::ACL_PRIVATE, $metaHeaders = array(), $requestHeaders = array(), $storageClass = self::STORAGE_CLASS_STANDARD) { $rest = new MainWP_WPvivid_S3Request('POST', $bucket, $uri, $this->endpoint, $this); $rest->setParameter('uploads',''); if (is_array($requestHeaders) && !empty($requestHeaders)) foreach ($requestHeaders as $h => $v) $rest->setHeader($h, $v); if(is_array($metaHeaders) && !empty($metaHeaders)) foreach ($metaHeaders as $h => $v) $rest->setAmzHeader('x-amz-meta-'.$h, $v); if ($this -> _storageClass !== self::STORAGE_CLASS_STANDARD) // Storage class $rest->setAmzHeader('x-amz-storage-class', $this -> _storageClass); if ($this -> _serverSideEncryption !== self::SSE_NONE) // Server-side encryption $rest->setAmzHeader('x-amz-server-side-encryption', $this -> _serverSideEncryption); $rest->setAmzHeader('x-amz-acl', $acl); $rest->getResponse(); if (false === $rest->response->error && 200 !== $rest->response->code) { $rest->response->error = array('code' => $rest->response->code, 'message' => 'Unexpected HTTP status'); } if (false !== $rest->response->error) { $this->__triggerError(sprintf("Mainwp_WPvivid_S3::initiateMultipartUpload(): [%s] %s", $rest->response->error['code'], $rest->response->error['message']), __FILE__, __LINE__); return false; } elseif (isset($rest->response->body)) { if (is_a($rest->response->body, 'SimpleXMLElement')) { $body = $rest->response->body; } else { $body = new SimpleXMLElement($rest->response->body); } return (string) $body->UploadId; } return false; } public function uploadPart ($bucket, $uri, $uploadId, $filePath, $partNumber, $partSize = 5242880) { $rest = new MainWP_WPvivid_S3Request('PUT', $bucket, $uri, $this->endpoint, $this); $rest->setParameter('partNumber', $partNumber); $rest->setParameter('uploadId', $uploadId); $fileOffset = ($partNumber - 1 ) * $partSize; $fileBytes = min(filesize($filePath) - $fileOffset, $partSize); if ($fileBytes < 0) $fileBytes = 0; $rest->setHeader('Content-Type', 'application/octet-stream'); $rest->data = ""; if ($handle = fopen($filePath, "rb")) { if ($fileOffset >0) fseek($handle, $fileOffset); $bytes_read = 0; while ($fileBytes>0 && $read = fread($handle, max($fileBytes, 131072))) { //128kb $fileBytes = $fileBytes - strlen($read); $bytes_read += strlen($read); $rest->data = $rest->data . $read; } fclose($handle); } else { return false; } $rest->setHeader('Content-MD5', base64_encode(md5($rest->data, true))); $rest->size = $bytes_read; $rest = $rest->getResponse(); if (false === $rest->error && 200 !== $rest->code) { $rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status'); } if (false !== $rest->error) { $this->__triggerError(sprintf("S3::uploadPart(): [%s] %s", $rest->error['code'], $rest->error['message']), __FILE__, __LINE__); return false; } return $rest->headers['hash']; } public function completeMultipartUpload ($bucket, $uri, $uploadId, $parts) { $rest = new MainWP_WPvivid_S3Request('POST', $bucket, $uri, $this->endpoint, $this); $rest->setParameter('uploadId', $uploadId); $xml = "<CompleteMultipartUpload>\n"; $partno = 1; foreach ($parts as $etag) { $xml .= "<Part><PartNumber>$partno</PartNumber><ETag>$etag</ETag></Part>\n"; $partno++; } $xml .= "</CompleteMultipartUpload>"; $rest->data = $xml; $rest->size = strlen($rest->data); $rest->setHeader('Content-Type', 'application/xml'); $rest = $rest->getResponse(); if (false === $rest->error && 200 !== $rest->code) { $rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status'); } if (false !== $rest->error) { if ('InternalError' == $rest->error['code'] && 'This multipart completion is already in progress' == $rest->error['message']) { return true; } $this->__triggerError(sprintf("S3::completeMultipartUpload(): [%s] %s", $rest->error['code'], $rest->error['message']), __FILE__, __LINE__); return false; } return true; } public function abortMultipartUpload ($bucket, $uri, $uploadId) { $rest = new MainWP_WPvivid_S3Request('DELETE', $bucket, $uri, $this->endpoint, $this); $rest->setParameter('uploadId', $uploadId); $rest = $rest->getResponse(); if (false === $rest->error && 204 !== $rest->code) { $rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status'); } if (false !== $rest->error) { $this->__triggerError(sprintf("S3::abortMultipartUpload(): [%s] %s", $rest->error['code'], $rest->error['message']), __FILE__, __LINE__); return false; } return true; } public function getObject($bucket, $uri, $saveTo = false, $resume = false) { $rest = new MainWP_WPvivid_S3Request('GET', $bucket, $uri, $this->endpoint, $this); if (false !== $saveTo) { if (is_resource($saveTo)) { $rest->fp = $saveTo; if (!is_bool($resume)) $rest->setHeader('Range', $resume); } else { if ($resume && file_exists($saveTo)) { if (false !== ($rest->fp = @fopen($saveTo, 'ab'))) { $rest->setHeader('Range', "bytes=".filesize($saveTo).'-'); $rest->file = realpath($saveTo); } else { $rest->response->error = array('code' => 0, 'message' => 'Unable to open save file for writing: '.$saveTo); } } else { if (false !== ($rest->fp = @fopen($saveTo, 'wb'))) $rest->file = realpath($saveTo); else $rest->response->error = array('code' => 0, 'message' => 'Unable to open save file for writing: '.$saveTo); } } } if (false === $rest->response->error) $rest->getResponse(); if (false === $rest->response->error && ( !$resume && 200 != $rest->response->code) || ( $resume && 206 != $rest->response->code && 200 != $rest->response->code)) $rest->response->error = array('code' => $rest->response->code, 'message' => 'Unexpected HTTP status'); if (false !== $rest->response->error) { $this->__triggerError(sprintf("Mainwp_WPvivid_S3::getObject({$bucket}, {$uri}): [%s] %s", $rest->response->error['code'], $rest->response->error['message']), __FILE__, __LINE__); return false; } return $rest->response; } public function listObject($bucket, $path) { $rest = new MainWP_WPvivid_S3Request('GET', $bucket, '', $this->endpoint, $this); $rest->setParameter('prefix', $path); //$rest->setParameter('delimiter', $path); $response = $rest->getResponse(); if ($response->error === false && $response->code !== 200) { //$response->error = array('code' => $response->code, 'message' => 'Unexpected HTTP status'); $ret['result']='failed'; $ret['error']=$response['message'].' '.$response->code; return $ret; } if ($response->error !== false) { $ret['result']='failed'; $ret['error']=sprintf("S3::getBucket(): [%s] %s", $response->error['code'], $response->error['message']); return $ret; } $results = array(); if (isset($response->body, $response->body->Contents)) { foreach ($response->body->Contents as $c) { $results[] = array( 'name' => (string)$c->Key, 'size' => (int)$c->Size, ); } } $ret['result']='success'; $ret['data']=$results; return $ret; } } includes/customclass/class-wpvivid-s3compat.php 0000644 00000077570 15133715745 0016000 0 ustar 00 <?php if (!defined('MAINWP_WPVIVID_EXTENSION_PLUGIN_DIR')){ die; } if(!defined('MAINWP_WPVIVID_REMOTE_S3COMPAT')){ define('MAINWP_WPVIVID_REMOTE_S3COMPAT','s3compat'); } define('MAINWP_WPVIVID_S3COMPAT_DEFAULT_FOLDER','/wpvivid_backup'); define('MAINWP_WPVIVID_S3COMPAT_NEED_PHP_VERSION','5.3.9'); require_once MAINWP_WPVIVID_EXTENSION_PLUGIN_DIR . '/includes/customclass/class-wpvivid-remote.php'; class Mainwp_Wpvivid_S3Compat extends Mainwp_WPvivid_Remote{ private $options; private $bucket; private $region; public function __construct($options = array()) { if(empty($options)){ add_action('mwp_wpvivid_add_storage_tab',array($this,'mwp_wpvivid_add_storage_tab_s3compat'), 11); add_action('mwp_wpvivid_add_storage_page',array($this,'mwp_wpvivid_add_storage_page_s3compat'), 11); add_action('mwp_wpvivid_add_storage_tab_addon', array($this, 'mwp_wpvivid_add_storage_tab_s3compat_addon'), 11); add_action('mwp_wpvivid_add_storage_page_addon', array($this, 'mwp_wpvivid_add_storage_page_s3compat_addon'), 11); add_action('mwp_wpvivid_add_storage_page_s3compat_addon', array($this, 'mwp_wpvivid_add_storage_page_s3compat_addon')); add_action('mwp_wpvivid_edit_storage_page_addon', array($this, 'mwp_wpvivid_edit_storage_page_s3compat_addon'), 11); add_filter('mwp_wpvivid_remote_pic',array($this,'mwp_wpvivid_remote_pic_s3compat'),11); add_filter('mwp_wpvivid_storage_provider_tran',array($this,'mwp_wpvivid_storage_provider_s3compat'),10); }else{ $this -> options = $options; } } public function mwp_wpvivid_add_storage_tab_s3compat_addon(){ ?> <div class="mwp-storage-providers-addon" remote_type="s3compat" onclick="select_remote_storage_addon(event, 'mwp_wpvivid_storage_account_s3compat_addon');"> <img src="<?php echo esc_url(MAINWP_WPVIVID_EXTENSION_PLUGIN_URL.'/admin/images/storage-digitalocean.png'); ?>" style="vertical-align:middle;"/><?php esc_html_e('DigitalOcean Spaces', 'mainwp-wpvivid-extension'); ?> </div> <?php } public function mwp_wpvivid_add_storage_page_s3compat_addon(){ ?> <div class="storage-account-page-addon" id="mwp_wpvivid_storage_account_s3compat_addon"> <div class="mwp-wpvivid-block-bottom-space"><strong>Enter Your DigitalOcean Spaces Account</strong></div> <table class="wp-list-table widefat plugins" style="width:100%;"> <tbody> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input type="text" class="regular-text" autocomplete="off" option="s3compat-addon" name="name" placeholder="Enter a unique alias: e.g. DOS-001" onkeyup="value=value.replace(/[^a-zA-Z0-9\-_]/g,'')" style="height: 27px;" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>A name to help you identify the storage if you have multiple remote storage connected.</i> </div> </td> </tr> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input type="text" class="regular-text" autocomplete="off" option="s3compat-addon" name="access" placeholder="S3 access key" style="height: 27px;" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>Enter your S3 access key</i> </div> </td> </tr> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input type="password" class="regular-text" autocomplete="new-password" option="s3compat-addon" name="secret" placeholder="S3 secret key" style="height: 27px;" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>Enter your S3 secret key</i> </div> </td> </tr> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input type="text" class="regular-text" autocomplete="off" option="s3compat-addon" name="bucket" placeholder="Bucket Name(e.g. test)" style="height: 27px;" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i><span><?php /* translators: %s: Folder name. */ echo sprintf(esc_html('Enter an existing Bucket in which you want to create a parent folder for holding %s folders.', 'wpvivid'), esc_html(apply_filters('wpvivid_white_label_display', 'WPvivid backup'))); ?></span></i> </div> </td> </tr> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input type="text" class="regular-text" autocomplete="off" option="s3compat-addon" name="root_path" value="<?php echo esc_attr(apply_filters('wpvivid_white_label_remote_root_path', 'wpvividbackuppro')); ?>" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i><span><?php /* translators: %s: Folder name. */ echo sprintf(esc_html('Customize a parent folder in the Bucket for holding %s folders.', 'wpvivid'), esc_html(apply_filters('wpvivid_white_label_display', 'WPvivid backup'))); ?></span></i> </div> </td> </tr> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input type="text" class="regular-text" autocomplete="off" option="s3compat-addon" name="endpoint" placeholder="region.digitaloceanspaces.com" style="height: 27px;" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>Enter the service Endpoint for the storage</i> </div> </td> </tr> <tr> <td colspan=2> <label><input class="s3compat-addon" type="checkbox" option="s3compat-addon" name="use_region" onclick="mwp_wpvivid_check_special_region(this);">Enter the bucket region(if any) </td> </tr> <tr class="mwp-wpvivid-region-tr-s3compat-addon" style="display: none;"> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input type="text" class="regular-text" autocomplete="off" option="s3compat-addon" name="region" placeholder="region, e,g., ru-1" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>Enter the region of the s3 bucket.</i> </div> </td> </tr> <?php do_action('mwp_wpvivid_remote_storage_backup_retention', 's3compat-addon', 'add'); ?> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-select"> <label> <input type="checkbox" option="s3compat-addon" name="use_path_style_endpoint" />Use path-style access. </label> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>Use path-style to indicate to an S3-compatible storage. <a href="https://docs.wpvivid.com/path-style-access-to-s3-compatible-storage.html" target='_blank'>learn more...</a></i> </div> </td> </tr> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input class="ui green mini button" option="add-remote-addon-global" type="button" value="Save and Sync" remote_type="s3compat" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>Click the button to connect to DigitalOcean Spaces storage and add it to the storage list below.</i> </div> </td> </tr> </tbody> </table> </div> <script> function mwp_wpvivid_check_special_region(obj) { var class_name = jQuery(obj).attr('class'); if(jQuery(obj).prop('checked')) { jQuery('.mwp-wpvivid-region-tr-'+class_name).show(); } else { jQuery('.mwp-wpvivid-region-tr-'+class_name).hide(); } } </script> <?php } public function mwp_wpvivid_edit_storage_page_s3compat_addon(){ ?> <div class="mwp-wpvivid-remote-storage-edit" id="mwp_wpvivid_storage_account_s3compat_edit" style="display: none;"> <div class="mwp-wpvivid-block-bottom-space" style="margin-top: 10px;"><strong>Enter Your DigitalOcean Spaces Account</strong></div> <table class="wp-list-table widefat plugins" style="width:100%;"> <tbody> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input type="text" class="regular-text" autocomplete="off" option="edit-s3compat-addon" name="name" placeholder="Enter a unique alias: e.g. DOS-001" onkeyup="value=value.replace(/[^a-zA-Z0-9\-_]/g,'')" style="height: 27px;" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>A name to help you identify the storage if you have multiple remote storage connected.</i> </div> </td> </tr> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input type="text" class="regular-text" autocomplete="off" option="edit-s3compat-addon" name="access" placeholder="S3 access key" style="height: 27px;" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>Enter your S3 access key</i> </div> </td> </tr> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input type="password" class="regular-text" autocomplete="new-password" option="edit-s3compat-addon" name="secret" placeholder="S3 secret key" style="height: 27px;" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>Enter your S3 secret key</i> </div> </td> </tr> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input type="text" class="regular-text" autocomplete="off" option="edit-s3compat-addon" name="bucket" placeholder="Bucket Name(e.g. test)" style="height: 27px;" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i><span><?php echo /* translators: %s: Folder name. */ sprintf(esc_html('Enter an existing Bucket in which you want to create a parent folder for holding %s folders.', 'wpvivid'), esc_html(apply_filters('wpvivid_white_label_display', 'WPvivid backup'))); ?></span></i> </div> </td> </tr> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input type="text" class="regular-text" autocomplete="off" option="edit-s3compat-addon" name="root_path" value="<?php echo esc_attr(apply_filters('wpvivid_white_label_remote_root_path', 'wpvividbackuppro')); ?>" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i><span><?php /* translators: %s: Folder name. */ echo sprintf(esc_html('Customize a parent folder in the Bucket for holding %s folders.', 'wpvivid'), esc_html(apply_filters('wpvivid_white_label_display', 'WPvivid backup'))); ?></span></i> </div> </td> </tr> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input type="text" class="regular-text" autocomplete="off" option="edit-s3compat-addon" name="endpoint" placeholder="region.digitaloceanspaces.com" style="height: 27px;" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>Enter the service Endpoint for the storage</i> </div> </td> </tr> <tr> <td colspan=2> <label><input class="edit-s3compat-addon" type="checkbox" option="edit-s3compat-addon" name="use_region" onclick="mwp_wpvivid_check_special_edit_region(this);">Enter the bucket region(if any) </td> </tr> <tr class="mwp-wpvivid-region-tr-edit-s3compat-addon" style="display: none;"> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input type="text" class="regular-text" autocomplete="off" option="edit-s3compat-addon" name="region" placeholder="region, e,g., ru-1" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>Enter the region of the s3 bucket.</i> </div> </td> </tr> <?php do_action('mwp_wpvivid_remote_storage_backup_retention', 's3compat-addon', 'edit'); ?> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-select"> <label> <input type="checkbox" option="edit-s3compat-addon" name="use_path_style_endpoint" />Use path-style access. </label> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>Use path-style to indicate to an S3-compatible storage. <a href="https://docs.wpvivid.com/path-style-access-to-s3-compatible-storage.html" target='_blank'>learn more...</a></i> </div> </td> </tr> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input class="ui green mini button" option="edit-remote-addon-global" type="button" value="Save Changes" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>Click the button to connect to DigitalOcean Spaces storage and add it to the storage list below.</i> </div> </td> </tr> </tbody> </table> </div> <script> function mwp_wpvivid_check_special_edit_region(obj) { var class_name = jQuery(obj).attr('class'); if(jQuery(obj).prop('checked')) { jQuery('.mwp-wpvivid-region-tr-'+class_name).show(); } else { jQuery('.mwp-wpvivid-region-tr-'+class_name).hide(); } } </script> <?php } public function getClient(){ $res = $this -> compare_php_version(); if($res['result'] == 'failed') return $res; if(isset($this->options['s3directory'])) { $path_temp = str_replace('s3generic://','',$this->options['s3directory'].$this -> options['path']); if (preg_match("#^/*([^/]+)/(.*)$#", $path_temp, $bmatches)) { $this->bucket = $bmatches[1]; } else { $this->bucket = $path_temp; } $this->options['path']=ltrim($this -> options['path'],'/'); $endpoint_temp = str_replace('https://','',$this->options['endpoint']); $explodes = explode('.',$endpoint_temp); $this -> region = $explodes[0]; $this -> options['endpoint'] = 'https://'.trailingslashit($endpoint_temp); } else { $endpoint_temp = str_replace('https://','',$this->options['endpoint']); $explodes = explode('.',$endpoint_temp); $this -> region = $explodes[0]; $this -> options['endpoint'] = 'https://'.trailingslashit($endpoint_temp); $this -> bucket=$this->options['bucket']; } include_once WPVIVID_PLUGIN_DIR.'/vendor/autoload.php'; $s3compat = S3Client::factory( array( 'credentials' => array( 'key' => $this -> options['access'], 'secret' => $this -> options['secret'], ), 'version' => 'latest', 'region' => $this -> region, 'endpoint' => $this -> options['endpoint'], ) ); return $s3compat; } public function test_connect($is_pro) { $s3compat = $this -> getClient(); if(is_array($s3compat) && $s3compat['result'] == 'failed') { return $s3compat; } $temp_file = md5(wp_rand()); try { $result = $s3compat->putObject( array( 'Bucket'=>$this->bucket, 'Key' => $this->options['path'].'/'.$temp_file, 'Body' => $temp_file, ) ); $etag = $result->get('ETag'); if(!isset($etag)) { return array('result'=>'failed','error'=>'We successfully accessed the bucket, but create test file failed.'); } $result = $s3compat->deleteObject(array( 'Bucket' => $this -> bucket, 'Key' => $this -> options['path'].'/'.$temp_file, )); if(empty($result)) { return array('result'=>'failed','error'=>'We successfully accessed the bucket, and create test file succeed, but delete test file failed.'); } } catch(S3Exception $e) { return array('result' => 'failed','error' => $e -> getAwsErrorCode().$e -> getMessage()); } catch(Exception $e) { return array('result' => 'failed','error' => $e -> getMessage()); } return array('result' => 'success'); } public function mwp_wpvivid_add_storage_tab_s3compat(){ ?> <div class="mwp-storage-providers" remote_type="s3compat" onclick="select_remote_storage(event, 'storage_account_s3compat');"> <img src="<?php echo esc_url(MAINWP_WPVIVID_EXTENSION_PLUGIN_URL.'/admin/images/storage-digitalocean.png'); ?>" style="vertical-align:middle;"/><?php esc_html_e('DigitalOcean Spaces', 'mainwp-wpvivid-extension'); ?> </div> <?php } public function mwp_wpvivid_add_storage_page_s3compat(){ ?> <div id="storage_account_s3compat" class="storage-account-page" style="display:none;"> <div class="mwp-wpvivid-block-bottom-space"><strong>Enter Your DigitalOcean Spaces Account</strong></div> <table class="wp-list-table widefat plugins" style="width:100%;"> <tbody> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input type="text" class="regular-text" autocomplete="off" option="s3compat" name="name" placeholder="Enter a unique alias: e.g. DOS-001" onkeyup="value=value.replace(/[^a-zA-Z0-9\-_]/g,'')" style="height: 27px;" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>A name to help you identify the storage if you have multiple remote storage connected.</i> </div> </td> </tr> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input type="text" class="regular-text" autocomplete="off" option="s3compat" name="access" placeholder="DigitalOcean Spaces access key" style="height: 27px;" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>Enter your DigitalOcean Spaces access key</i> </div> </td> </tr> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input type="password" class="regular-text" autocomplete="new-password" option="s3compat" name="secret" placeholder="DigitalOcean Spaces secret key" style="height: 27px;" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>Enter your DigitalOcean Spaces secret key</i> </div> </td> </tr> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input type="text" class="regular-text" autocomplete="off" option="s3compat" name="bucket" placeholder="Space Name(e.g. test)" style="height: 27px;" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i><span>Enter an existed Space to create a custom backup storage directory.</span></i> </div> </td> </tr> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input type="text" class="regular-text" autocomplete="off" option="s3compat" name="path" placeholder="Custom Path" style="height: 27px;" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i><span>Customize the directory where you want to store backups within the Space.</span></i> </div> </td> </tr> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input type="text" class="regular-text" autocomplete="off" option="s3compat" name="endpoint" placeholder="region.digitaloceanspaces.com" style="height: 27px;" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>Enter the DigitalOcean Endpoint for the storage</i> </div> </td> </tr> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-select"> <label> <input type="checkbox" option="s3compat" name="default" checked />Set as the default remote storage. </label> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>Once checked, all this sites backups sent to a remote storage destination will be uploaded to this storage by default.</i> </div> </td> </tr> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input class="ui green mini button" option="add-remote" type="button" value="Test and Add" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>Click the button to connect to DigitalOcean Spaces storage and add it to the storage list below.</i> </div> </td> </tr> </tbody> </table> </div> <?php } public function mwp_wpvivid_remote_pic_s3compat($remote){ $remote['s3compat']['default_pic'] = '/admin/images/storage-digitalocean(gray).png'; $remote['s3compat']['selected_pic'] = '/admin/images/storage-digitalocean.png'; $remote['s3compat']['title'] = 'DigitalOcean Spaces'; return $remote; } public function sanitize_options($skip_name='') { $ret['result']='failed'; if(!isset($this->options['name'])) { $ret['error']="Warning: An alias for remote storage is required."; return $ret; } $this->options['name']=sanitize_text_field($this->options['name']); if(empty($this->options['name'])) { $ret['error']="Warning: An alias for remote storage is required."; return $ret; } $remoteslist=Mainwp_WPvivid_Extension_DB_Option::get_instance()->wpvivid_get_global_option('remote_addon', array()); if(isset($remoteslist) && !empty($remoteslist)) { foreach ($remoteslist['upload'] as $key => $value) { if (isset($value['name']) && $value['name'] == $this->options['name'] && $skip_name != $value['name']) { $ret['error'] = "Warning: The alias already exists in storage list."; return $ret; } } } if(!isset($this->options['access'])) { $ret['error']="Warning: The access key for S3-Compatible is required."; return $ret; } $this->options['access']=sanitize_text_field($this->options['access']); if(empty($this->options['access'])) { $ret['error']="Warning: The access key for S3-Compatible is required."; return $ret; } if(!isset($this->options['secret'])) { $ret['error']="Warning: The storage secret key is required."; return $ret; } $this->options['secret']=sanitize_text_field($this->options['secret']); if(empty($this->options['secret'])) { $ret['error']="Warning: The storage secret key is required."; return $ret; } $this->options['secret'] = base64_encode($this->options['secret']); $this->options['is_encrypt'] = 1; if(empty($this->options['bucket'])) { $ret['error']="Warning: A Digital Space is required."; return $ret; } if(!isset($this->options['endpoint'])) { $ret['error']="Warning: The end-point is required."; return $ret; } $this->options['endpoint']=sanitize_text_field($this->options['endpoint']); if(empty($this->options['endpoint'])) { $ret['error']="Warning: The end-point is required."; return $ret; } $ret['result']='success'; $ret['options']=$this->options; return $ret; } private function compare_php_version() { if(version_compare(MAINWP_WPVIVID_S3COMPAT_NEED_PHP_VERSION,phpversion()) > 0){ return array('result' => 'failed','error' => 'The required PHP version is higher than '.MAINWP_WPVIVID_S3COMPAT_NEED_PHP_VERSION.'. After updating your PHP version, please try again.'); } return array('result' => 'success'); } public function mwp_wpvivid_storage_provider_s3compat($storage_type) { if($storage_type == MAINWP_WPVIVID_REMOTE_S3COMPAT){ $storage_type = 'DigitalOcean Spaces'; } return $storage_type; } } includes/customclass/class-wpvivid-wasabi.php 0000644 00000052705 15133715745 0015506 0 ustar 00 <?php if (!defined('MAINWP_WPVIVID_EXTENSION_PLUGIN_DIR')){ die; } define('MAINWP_WPVIVID_REMOTE_WASABI','wasabi'); require_once MAINWP_WPVIVID_EXTENSION_PLUGIN_DIR . '/includes/customclass/class-wpvivid-remote.php'; class Mainwp_Wpvivid_WasabiS3 extends Mainwp_WPvivid_Remote{ public $options; public function __construct($options=array()){ if(empty($options)) { if(!defined('MAINWP_WPVIVID_INIT_STORAGE_TAB_WASABI')) { add_action('mwp_wpvivid_add_storage_tab_addon', array($this, 'mwp_wpvivid_add_storage_tab_wasabi_addon'), 11); add_action('mwp_wpvivid_add_storage_page_addon', array($this, 'mwp_wpvivid_add_storage_page_wasabi_addon'), 11); add_action('mwp_wpvivid_add_storage_page_wasabi_addon', array($this, 'mwp_wpvivid_add_storage_page_wasabi_addon')); add_action('mwp_wpvivid_edit_storage_page_addon', array($this, 'mwp_wpvivid_edit_storage_page_wasabi_addon'), 11); add_filter('mwp_wpvivid_remote_pic', array($this, 'mwp_wpvivid_remote_pic_wasabi'), 11); add_filter('mwp_wpvivid_storage_provider_tran', array($this, 'mwp_wpvivid_storage_provider_wasabi'), 10); define('MAINWP_WPVIVID_INIT_STORAGE_TAB_WASABI',1); } } else { $this->options=$options; } } public function mwp_wpvivid_add_storage_tab_wasabi_addon(){ ?> <div class="mwp-storage-providers-addon" remote_type="wasabi" onclick="select_remote_storage_addon(event, 'mwp_wpvivid_storage_account_wasabi_addon');"> <img src="<?php echo esc_url(MAINWP_WPVIVID_EXTENSION_PLUGIN_URL.'/admin/images/storage-wasabi.png'); ?>" style="vertical-align:middle;"/><?php esc_html_e('Wasabi', 'mainwp-wpvivid-extension'); ?> </div> <?php } public function mwp_wpvivid_add_storage_page_wasabi_addon(){ ?> <div class="storage-account-page-addon" id="mwp_wpvivid_storage_account_wasabi_addon"> <div style="padding: 0 10px 10px 0;"><strong>Enter Your Wasabi Account</strong></div> <table class="wp-list-table widefat plugins" style="width:100%;"> <tbody> <form> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input type="text" class="regular-text" autocomplete="off" option="wasabi-addon" name="name" placeholder="Enter a unique alias: e.g. Wasabi-001" onkeyup="value=value.replace(/[^a-zA-Z0-9\-_]/g,'')" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>A name to help you identify the storage if you have multiple remote storage connected.</i> </div> </td> </tr> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input type="text" class="regular-text" autocomplete="off" option="wasabi-addon" name="access" placeholder="Wasabi access key" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>Enter your Wasabi access key</i> </div> </td> </tr> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input type="password" class="regular-text" autocomplete="new-password" option="wasabi-addon" name="secret" placeholder="Wasabi secret key" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>Enter your Wasabi secret key</i> </div> </td> </tr> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input type="text" class="regular-text" autocomplete="off" option="wasabi-addon" name="bucket" placeholder="Bucket Name(e.g. test)" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i><span>Enter an existed Space in which you want to create a parent folder</span></i> </div> </td> </tr> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input type="text" class="regular-text" autocomplete="off" option="wasabi-addon" name="root_path" value="<?php echo esc_attr(apply_filters('wpvivid_white_label_remote_root_path', 'wpvividbackuppro')); ?>" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i><span><?php /* translators: %s: Folder name. */ echo sprintf(esc_html('Customize a parent folder in the Bucket for holding %s folders.', 'wpvivid'), esc_html(apply_filters('wpvivid_white_label_display', 'WPvivid backup'))); ?></span></i> </div> </td> </tr> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <select id="mwp_wpvivid_wasabi_endpoint_select" style="margin-bottom:5px;"> <option value="us_east1">US East 1</option> <option value="us_east2">US East 2</option> <option value="us_west1">US West 1</option> <option value="us_central1">EU Central 1</option> <option value="custom">Custom</option> </select> <input id="mwp_wpvivid_wasabi_endpoint" style="width:205px" type="text" class="regular-text" autocomplete="off" option="wasabi-addon" name="endpoint" value="s3.wasabisys.com" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>Enter the Wasabi Endpoint for the storage</i> </div> </td> </tr> <?php do_action('mwp_wpvivid_remote_storage_backup_retention', 'wasabi-addon', 'add'); ?> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-select"> <label> <input type="checkbox" option="wasabi-addon" name="uncheckdelete" />Do not check DeleteObject. </label> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <div style="float: left; padding-right: 5px;"> <i>Tick this option so WPvivid won't check s3:DeleteObject permission of the user in the authentication.</i> </div> <span class="dashicons dashicons-editor-help mwp-wpvivid-dashicons-editor-help mwp-wpvivid-tooltip-ex"> <div class="mwp-wpvivid-bottom"> <p>s3:DeleteObject is a permission for deleting objects from Wasabi. Without it, you are not able to delete backups on S3 from WPvivid.</p> <i></i> </div> </span> <div style="clear: both;"></div> </div> </td> </tr> </form> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input class="ui green mini button" option="add-remote-addon-global" type="button" value="Save and Sync" remote_type="wasabi" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>Click the button to connect to Wasabi storage and add it to the storage list below.</i> </div> </td> </tr> </tbody> </table> </div> <script> jQuery('#mwp_wpvivid_wasabi_endpoint_select').change(function() { if('us_east1'==jQuery(this).val()) { jQuery('#mwp_wpvivid_wasabi_endpoint').val('s3.wasabisys.com'); } else if('us_east2'==jQuery(this).val()) { jQuery('#mwp_wpvivid_wasabi_endpoint').val('s3.us-east-2.wasabisys.com'); } else if('us_west1'==jQuery(this).val()) { jQuery('#mwp_wpvivid_wasabi_endpoint').val('s3.us-west-1.wasabisys.com'); } else if('us_central1'==jQuery(this).val()) { jQuery('#mwp_wpvivid_wasabi_endpoint').val('s3.eu-central-1.wasabisys.com'); } else if('custom'==jQuery(this).val()) { jQuery('#mwp_wpvivid_wasabi_endpoint').val(''); } }); </script> <?php } public function mwp_wpvivid_edit_storage_page_wasabi_addon(){ ?> <div class="mwp-wpvivid-remote-storage-edit" id="mwp_wpvivid_storage_account_wasabi_edit" style="display:none;"> <div class="mwp-wpvivid-block-bottom-space" style="margin-top: 10px;"><strong>Enter Your Wasabi Account</strong></div> <table class="wp-list-table widefat plugins" style="width:100%;"> <tbody> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input type="text" class="regular-text" autocomplete="off" option="edit-wasabi-addon" name="name" placeholder="Enter a unique alias: e.g. Wasabi-001" onkeyup="value=value.replace(/[^a-zA-Z0-9\-_]/g,'')" style="height: 27px;" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>A name to help you identify the storage if you have multiple remote storage connected.</i> </div> </td> </tr> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input type="text" class="regular-text" autocomplete="off" option="edit-wasabi-addon" name="access" placeholder="Wasabi access key" style="height: 27px;" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>Enter your Wasabi access key.</i> </div> </td> </tr> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input type="password" class="regular-text" autocomplete="new-password" option="edit-wasabi-addon" name="secret" placeholder="Wasabi secret key" style="height: 27px;" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>Enter your Wasabi secret key.</i> </div> </td> </tr> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input type="text" class="regular-text" autocomplete="off" option="edit-wasabi-addon" name="bucket" placeholder="Bucket Name(e.g. test)" style="height: 27px;" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i><span>Enter an existed Bucket to create a custom backup storage directory.</span></i> </div> </td> </tr> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input type="text" class="regular-text" autocomplete="off" option="edit-wasabi-addon" name="root_path" value="<?php echo esc_attr(apply_filters('wpvivid_white_label_remote_root_path', 'wpvividbackuppro')); ?>" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i><span><?php /* translators: %s: Folder name. */ echo sprintf(esc_html('Customize a parent folder in the Bucket for holding %s folders.', 'wpvivid'), esc_html(apply_filters('wpvivid_white_label_display', 'WPvivid backup'))); ?></span></i> </div> </td> </tr> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <select id="mwp_wpvivid_wasabi_endpoint_select_edit" style="margin-bottom:5px;"> <option value="us_east1">US East 1</option> <option value="us_east2">US East 2</option> <option value="us_west1">US West 1</option> <option value="us_central1">EU Central 1</option> <option value="custom">Custom</option> </select> <input id="mwp_wpvivid_wasabi_endpoint_edit" style="width:205px" type="text" class="regular-text" autocomplete="off" option="edit-wasabi-addon" name="endpoint" value="s3.wasabisys.com" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>Enter the Wasabi Endpoint for the storage</i> </div> </td> </tr> <?php do_action('mwp_wpvivid_remote_storage_backup_retention', 'wasabi-addon', 'edit'); ?> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input class="ui green mini button" option="edit-remote-addon-global" type="button" value="Save Changes" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>Click the button to connect to Amazon S3 storage and add it to the storage list below.</i> </div> </td> </tr> </tbody> </table> </div> <script> jQuery('#mwp_wpvivid_wasabi_endpoint_select_edit').change(function() { if('us_east1'==jQuery(this).val()) { jQuery('#mwp_wpvivid_wasabi_endpoint_edit').val('s3.wasabisys.com'); } else if('us_east2'==jQuery(this).val()) { jQuery('#mwp_wpvivid_wasabi_endpoint_edit').val('s3.us-east-2.wasabisys.com'); } else if('us_west1'==jQuery(this).val()) { jQuery('#mwp_wpvivid_wasabi_endpoint_edit').val('s3.us-west-1.wasabisys.com'); } else if('us_central1'==jQuery(this).val()) { jQuery('#mwp_wpvivid_wasabi_endpoint_edit').val('s3.eu-central-1.wasabisys.com'); } else if('custom'==jQuery(this).val()) { jQuery('#mwp_wpvivid_wasabi_endpoint').val(''); } }); </script> <?php } public function mwp_wpvivid_remote_pic_wasabi($remote){ $remote['wasabi']['default_pic'] = '/admin/images/storage-wasabi(gray).png'; $remote['wasabi']['selected_pic'] = '/admin/images/storage-wasabi.png'; $remote['wasabi']['title'] = 'Wasabi'; return $remote; } public function mwp_wpvivid_storage_provider_wasabi($storage_type){ if($storage_type == MAINWP_WPVIVID_REMOTE_WASABI){ $storage_type = 'Wasabi'; } return $storage_type; } public function sanitize_options($skip_name=''){ $ret['result']='failed'; if(!isset($this->options['name'])) { $ret['error']="Warning: An alias for remote storage is required."; return $ret; } $this->options['name']=sanitize_text_field($this->options['name']); if(empty($this->options['name'])) { $ret['error']="Warning: An alias for remote storage is required."; return $ret; } $remoteslist=Mainwp_WPvivid_Extension_DB_Option::get_instance()->wpvivid_get_global_option('remote_addon', array()); if(isset($remoteslist) && !empty($remoteslist)) { foreach ($remoteslist['upload'] as $key => $value) { if (isset($value['name']) && $value['name'] == $this->options['name'] && $skip_name != $value['name']) { $ret['error'] = "Warning: The alias already exists in storage list."; return $ret; } } } if(!isset($this->options['access'])) { $ret['error']="Warning: The access key for Amazon S3 is required."; return $ret; } $this->options['access']=sanitize_text_field($this->options['access']); if(empty($this->options['access'])) { $ret['error']="Warning: The access key for Amazon S3 is required."; return $ret; } if(!isset($this->options['secret'])) { $ret['error']="Warning: The storage secret key is required."; return $ret; } $this->options['secret']=sanitize_text_field($this->options['secret']); if(empty($this->options['secret'])) { $ret['error']="Warning: The storage secret key is required."; return $ret; } $this->options['secret'] = base64_encode($this->options['secret']); $this->options['is_encrypt'] = 1; if(!isset($this->options['bucket'])) { $ret['error']="Warning: A Bucket name is required."; return $ret; } $this->options['bucket']=sanitize_text_field($this->options['bucket']); if(empty($this->options['bucket'])) { $ret['error']="Warning: A Bucket name is required."; return $ret; } if(!isset($this->options['endpoint'])) { $ret['error']="Warning: The end-point is required."; return $ret; } $this->options['endpoint']=sanitize_text_field($this->options['endpoint']); if(empty($this->options['endpoint'])) { $ret['error']="Warning: The end-point is required."; return $ret; } $ret['result']='success'; $ret['options']=$this->options; return $ret; } public function test_connect($is_pro){ return array('result' => 'success'); } } includes/customclass/class-wpvivid-dropbox.php 0000644 00000012717 15133715745 0015714 0 ustar 00 <?php if (!defined('MAINWP_WPVIVID_EXTENSION_PLUGIN_DIR')){ die; } if(!defined('MAINWP_WPVIVID_REMOTE_DROPBOX')){ define('MAINWP_WPVIVID_REMOTE_DROPBOX','dropbox'); } define('MAINWP_WPVIVID_DROPBOX_DEFAULT_FOLDER','/'); require_once MAINWP_WPVIVID_EXTENSION_PLUGIN_DIR . '/includes/customclass/class-wpvivid-base-dropbox.php'; require_once MAINWP_WPVIVID_EXTENSION_PLUGIN_DIR . '/includes/customclass/class-wpvivid-remote.php'; class Mainwp_WPvivid_Dropbox extends Mainwp_WPvivid_Remote { private $options; private $redirect_url = 'https://auth.wpvivid.com/dropbox'; public function __construct($options = array()) { if(empty($options)){ if(!defined('MAINWP_WPVIVID_INIT_STORAGE_TAB_DROPBOX')) { add_action('mwp_wpvivid_add_storage_tab',array($this,'mwp_wpvivid_add_storage_tab_dropbox'), 10); add_action('mwp_wpvivid_add_storage_page',array($this,'mwp_wpvivid_add_storage_page_dropbox'), 10); add_action('mwp_wpvivid_add_storage_tab_addon', array($this, 'mwp_wpvivid_add_storage_tab_dropbox_addon'), 10); add_action('mwp_wpvivid_add_storage_page_addon', array($this, 'mwp_wpvivid_add_storage_page_dropbox_addon'), 10); add_action('mwp_wpvivid_add_storage_page_dropbox_addon', array($this, 'mwp_wpvivid_add_storage_page_dropbox_addon')); add_filter('mwp_wpvivid_remote_pic',array($this,'mwp_wpvivid_remote_pic_dropbox'),10); add_filter('mwp_wpvivid_storage_provider_tran',array($this,'mwp_wpvivid_storage_provider_dropbox'),10); define('MAINWP_WPVIVID_INIT_STORAGE_TAB_DROPBOX',1); } }else{ $this -> options = $options; } } public function test_connect($is_pro) { return array('result' => 'success'); } public function sanitize_options($skip_name='') { $ret['result']='success'; if(!isset($this->options['name'])) { $ret['error']="Warning: An alias for remote storage is required."; return $ret; } $this->options['name']=sanitize_text_field($this->options['name']); if(empty($this->options['name'])) { $ret['error']="Warning: An alias for remote storage is required."; return $ret; } $remoteslist=Mainwp_WPvivid_Extension_DB_Option::get_instance()->wpvivid_get_global_option('remote_addon', array()); foreach ($remoteslist['upload'] as $key=>$value) { if(isset($value['name'])&&$value['name'] == $this->options['name']&&$skip_name!=$value['name']) { $ret['error']="Warning: The alias already exists in storage list."; return $ret; } } $ret['options']=$this->options; return $ret; } public function mwp_wpvivid_add_storage_tab_dropbox(){ ?> <div class="mwp-storage-providers" remote_type="dropbox" onclick="select_remote_storage(event, 'storage_account_dropbox');"> <img src="<?php echo esc_url(MAINWP_WPVIVID_EXTENSION_PLUGIN_URL.'/admin/images/storage-dropbox.png'); ?>" style="vertical-align:middle;"/><?php esc_html_e('Dropbox', 'mainwp-wpvivid-extension'); ?> </div> <?php } public function mwp_wpvivid_add_storage_page_dropbox(){ ?> <div id="storage_account_dropbox" class="storage-account-page" style="display:none;"> <p>Global configuration is not available for Dropbox due to authorization mechanism (tokens will be expired). Please get authorization in child-sites</p> </div> <?php } public function mwp_wpvivid_add_storage_tab_dropbox_addon(){ ?> <div class="mwp-storage-providers-addon" remote_type="dropbox" onclick="select_remote_storage_addon(event, 'mwp_wpvivid_storage_account_dropbox_addon');"> <img src="<?php echo esc_url(MAINWP_WPVIVID_EXTENSION_PLUGIN_URL.'/admin/images/storage-dropbox.png'); ?>" style="vertical-align:middle;"/><?php esc_html_e('Dropbox', 'mainwp-wpvivid-extension'); ?> </div> <?php } public function mwp_wpvivid_add_storage_page_dropbox_addon(){ ?> <div id="mwp_wpvivid_storage_account_dropbox_addon" class="storage-account-page-addon"> <p>Global configuration is not available for Dropbox due to authorization mechanism (tokens will be expired). Please get authorization in child-sites</p> </div> <?php } public function mwp_wpvivid_remote_pic_dropbox($remote) { $remote['dropbox']['default_pic'] = '/admin/images/storage-dropbox(gray).png'; $remote['dropbox']['selected_pic'] = '/admin/images/storage-dropbox.png'; $remote['dropbox']['title'] = 'Dropbox'; return $remote; } public function mwp_wpvivid_get_out_of_date_dropbox($out_of_date_remote, $remote) { if($remote['type'] == MAINWP_WPVIVID_REMOTE_DROPBOX){ $root_path=apply_filters('wpvivid_get_root_path', $remote['type']); $out_of_date_remote = $root_path.$remote['path']; } return $out_of_date_remote; } public function mwp_wpvivid_storage_provider_dropbox($storage_type) { if($storage_type == MAINWP_WPVIVID_REMOTE_DROPBOX){ $storage_type = 'Dropbox'; } return $storage_type; } } includes/customclass/class-wpvivid-ftpclass.php 0000644 00000076310 15133715745 0016055 0 ustar 00 <?php if (!defined('MAINWP_WPVIVID_EXTENSION_PLUGIN_DIR')){ die; } define('MAINWP_WPVIVID_REMOTE_FTP','ftp'); require_once MAINWP_WPVIVID_EXTENSION_PLUGIN_DIR .'/includes/customclass/class-wpvivid-remote.php'; class Mainwp_WPvivid_FTPClass extends Mainwp_WPvivid_Remote { private $time_out = 20; private $options=array(); public function __construct($options=array()) { if(empty($options)) { add_action('mwp_wpvivid_add_storage_tab',array($this,'mwp_wpvivid_add_storage_tab_ftp'), 9); add_action('mwp_wpvivid_add_storage_page',array($this,'mwp_wpvivid_add_storage_page_ftp'), 9); add_action('mwp_wpvivid_add_storage_tab_addon', array($this, 'mwp_wpvivid_add_storage_tab_ftp_addon'), 9); add_action('mwp_wpvivid_add_storage_page_addon', array($this, 'mwp_wpvivid_add_storage_page_ftp_addon'), 9); add_action('mwp_wpvivid_add_storage_page_ftp_addon', array($this, 'mwp_wpvivid_add_storage_page_ftp_addon')); add_action('mwp_wpvivid_edit_storage_page_addon', array($this, 'mwp_wpvivid_edit_storage_page_ftp_addon'), 9); add_filter('mwp_wpvivid_remote_pic',array($this,'mwp_wpvivid_remote_pic_ftp'),9); add_filter('mwp_wpvivid_storage_provider_tran',array($this,'mwp_wpvivid_storage_provider_ftp'),10); }else{ $this->options = $options; } } public function mwp_wpvivid_add_storage_tab_ftp() { ?> <div class="mwp-storage-providers mwp-storage-providers-active" remote_type="ftp" onclick="select_remote_storage(event, 'mwp_wpvivid_storage_account_ftp');"> <img src="<?php echo esc_url(MAINWP_WPVIVID_EXTENSION_PLUGIN_URL.'/admin/images/storage-ftp.png'); ?>" style="vertical-align:middle;"/><?php esc_html_e('FTP', 'mainwp-wpvivid-extension'); ?> </div> <?php } public function mwp_wpvivid_add_storage_page_ftp() { ?> <div class="storage-account-page" id="mwp_wpvivid_storage_account_ftp"> <div class="mwp-wpvivid-block-bottom-space"><strong>Enter Your FTP Account</strong></div> <table class="wp-list-table widefat plugins" style="width:100%;"> <tbody> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input type="text" autocomplete="off" option="ftp" name="name" placeholder="Enter an unique alias: e.g. FTP-001" class="regular-text" onkeyup="value=value.replace(/[^a-zA-Z0-9\-_]/g,'')" style="height: 27px;" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>A name to help you identify the storage if you have multiple remote storage connected.</i> </div> </td> </tr> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input type="text" autocomplete="off" option="ftp" name="server" placeholder="FTP server (server's port 21)" class="regular-text" style="height: 27px;" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i style="margin-right: 10px;">Enter the FTP server.</i> </div> </td> </tr> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input type="text" class="regular-text" autocomplete="off" option="ftp" name="username" placeholder="FTP login" style="height: 27px;" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>Enter your FTP server user name.</i> </div> </td> </tr> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input type="password" class="regular-text" autocomplete="new-password" option="ftp" name="password" placeholder="FTP password" style="height: 27px;" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>Enter the FTP server password.</i> </div> </td> </tr> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input type="text" autocomplete="off" option="ftp" name="path" placeholder="Absolute path must exist(e.g. /home/username)" class="regular-text" style="height: 27px;" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>Enter an absolute path and a custom subdirectory (optional) for holding the backups of current website. For example, /home/username/customfolder</i> </div> </td> </tr> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-select"> <label> <input type="checkbox" option="ftp" name="default" checked />Set as the default remote storage. </label> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>Once checked, all this sites backups sent to a remote storage destination will be uploaded to this storage by default.</i> </div> </td> </tr> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-select"> <label> <input type="checkbox" option="ftp" name="passive" checked />Uncheck this to enable FTP active mode. </label> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>Uncheck the option to use FTP active mode when transferring files. Make sure the FTP server you are configuring supports the active FTP mode.</i> </div> </td> </tr> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input class="ui green mini button" type="button" option="add-remote" value="Test and Add"> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>Click the button to connect to FTP server and add it to the storage list below.</i> </div> </td> </tr> </tbody> </table> </div> <?php } public function mwp_wpvivid_add_storage_tab_ftp_addon(){ ?> <div class="mwp-storage-providers-addon mwp-storage-providers-addon-active" remote_type="ftp" onclick="select_remote_storage_addon(event, 'mwp_wpvivid_storage_account_ftp_addon');"> <img src="<?php echo esc_url(MAINWP_WPVIVID_EXTENSION_PLUGIN_URL.'/admin/images/storage-ftp.png'); ?>" style="vertical-align:middle;"/><?php esc_html_e('FTP', 'mainwp-wpvivid-extension'); ?> </div> <?php } public function mwp_wpvivid_add_storage_page_ftp_addon(){ ?> <div class="storage-account-page-addon" id="mwp_wpvivid_storage_account_ftp_addon"> <div class="mwp-wpvivid-block-bottom-space"><strong>Enter Your FTP Account</strong></div> <table class="wp-list-table widefat plugins" style="width:100%;"> <tbody> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input type="text" autocomplete="off" option="ftp-addon" name="name" placeholder="Enter an unique alias: e.g. FTP-001" class="regular-text" onkeyup="value=value.replace(/[^a-zA-Z0-9\-_]/g,'')" style="height: 27px;" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>A name to help you identify the storage if you have multiple remote storage connected.</i> </div> </td> </tr> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input type="text" autocomplete="off" option="ftp-addon" name="server" placeholder="Server Address" class="regular-text" style="height: 27px;" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i style="margin-right: 10px;">Enter the server address.</i> </div> </td> </tr> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input type="text" autocomplete="off" option="ftp-addon" name="port" value="21" placeholder="FTP server port" class="regular-text" style="height: 27px;" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i style="margin-right: 10px;">Enter the custom server port.</i> </div> </td> </tr> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input type="text" class="regular-text" autocomplete="off" option="ftp-addon" name="username" placeholder="FTP login" style="height: 27px;" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>Enter your FTP server user name.</i> </div> </td> </tr> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input type="password" class="regular-text" autocomplete="new-password" option="ftp-addon" name="password" placeholder="FTP password" style="height: 27px;" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>Enter the FTP server password.</i> </div> </td> </tr> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input type="text" autocomplete="off" option="ftp-addon" name="path" placeholder="Absolute path must exist(e.g. /home/username)" class="regular-text" style="height: 27px;" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>The root directory created by WPvivid backup plugin for holding the backups is </i><i id="mwp_wpvivid_ftp_root_path">/the_absolute_path</i><i>/wpvividbackuppro/</i> </div> </td> </tr> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input type="text" class="regular-text" autocomplete="off" option="ftp-addon" name="root_path" value="wpvividbackuppro" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i><?php /* translators: %s: Folder name. */ echo sprintf(esc_html('Customize a parent folder under the absolute path for holding %s folders.', 'wpvivid'), esc_html(apply_filters('wpvivid_white_label_display', 'WPvivid backup'))); ?></i> </div> </td> </tr> <?php do_action('mwp_wpvivid_remote_storage_backup_retention', 'ftp-addon', 'add'); ?> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-select"> <label> <input type="checkbox" option="ftp-addon" name="use_ftps" />Check this option to enable FTP-SSL connection. </label> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>Check this option to enable FTP-SSL connection while transferring files. Make sure the FTP server you are configuring supports FTPS connections.</i> </div> </td> </tr> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-select"> <label> <input type="checkbox" option="ftp-addon" name="passive" checked />Uncheck this to enable FTP active mode. </label> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>Uncheck the option to use FTP active mode when transferring files. Make sure the FTP server you are configuring supports the active FTP mode.</i> </div> </td> </tr> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input class="ui green mini button" type="button" option="add-remote-addon-global" value="Save and Sync" remote_type="ftp"> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>Click the button to connect to FTP server and add it to the storage list below.</i> </div> </td> </tr> </tbody> </table> </div> <?php } public function mwp_wpvivid_edit_storage_page_ftp_addon(){ ?> <div class="mwp-wpvivid-remote-storage-edit" id="mwp_wpvivid_storage_account_ftp_edit" style="display: none;"> <div class="mwp-wpvivid-block-bottom-space" style="margin-top: 10px;"><strong>Enter Your FTP Account</strong></div> <table class="wp-list-table widefat plugins" style="width:100%;"> <tbody> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input type="text" autocomplete="off" option="edit-ftp-addon" name="name" placeholder="Enter an unique alias: e.g. FTP-001" class="regular-text" onkeyup="value=value.replace(/[^a-zA-Z0-9\-_]/g,'')" style="height: 27px;" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>A name to help you identify the storage if you have multiple remote storage connected.</i> </div> </td> </tr> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input type="text" autocomplete="off" option="edit-ftp-addon" name="server" placeholder="Server Address" class="regular-text" style="height: 27px;" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i style="margin-right: 10px;">Enter the server address.</i> </div> </td> </tr> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input type="text" autocomplete="off" option="edit-ftp-addon" name="port" value="21" placeholder="FTP server port" class="regular-text" style="height: 27px;" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i style="margin-right: 10px;">Enter the custom server port.</i> </div> </td> </tr> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input type="text" class="regular-text" autocomplete="off" option="edit-ftp-addon" name="username" placeholder="FTP login" style="height: 27px;" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>Enter your FTP server user name.</i> </div> </td> </tr> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input type="password" class="regular-text" autocomplete="new-password" option="edit-ftp-addon" name="password" placeholder="FTP password" style="height: 27px;" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>Enter the FTP server password.</i> </div> </td> </tr> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input type="text" autocomplete="off" option="edit-ftp-addon" name="path" placeholder="Absolute path must exist(e.g. /home/username)" class="regular-text" style="height: 27px;" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>The root directory created by WPvivid backup plugin for holding the backups is </i><i id="mwp_wpvivid_ftp_root_path">/the_absolute_path</i><i>/wpvividbackuppro/</i> </div> </td> </tr> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input type="text" class="regular-text" autocomplete="off" option="edit-ftp-addon" name="root_path" value="wpvividbackuppro" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i><?php /* translators: %s: Folder name. */ echo sprintf(esc_html('Customize a parent folder under the absolute path for holding %s folders.', 'wpvivid'), esc_html(apply_filters('wpvivid_white_label_display', 'WPvivid backup'))); ?></i> </div> </td> </tr> <?php do_action('mwp_wpvivid_remote_storage_backup_retention', 'ftp-addon', 'edit'); ?> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-select"> <label> <input type="checkbox" option="edit-ftp-addon" name="use_ftps" />Check this option to enable FTP-SSL connection. </label> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>Check this option to enable FTP-SSL connection while transferring files. Make sure the FTP server you are configuring supports FTPS connections.</i> </div> </td> </tr> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-select"> <label> <input type="checkbox" option="edit-ftp-addon" name="passive" checked />Uncheck this to enable FTP active mode. </label> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>Uncheck the option to use FTP active mode when transferring files. Make sure the FTP server you are configuring supports the active FTP mode.</i> </div> </td> </tr> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input class="ui green mini button" type="button" option="edit-remote-addon-global" value="Save Changes"> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>Click the button to connect to FTP server and add it to the storage list below.</i> </div> </td> </tr> </tbody> </table> </div> <?php } public function mwp_wpvivid_remote_pic_ftp($remote){ $remote['ftp']['default_pic'] = '/admin/images/storage-ftp(gray).png'; $remote['ftp']['selected_pic'] = '/admin/images/storage-ftp.png'; $remote['ftp']['title'] = 'FTP'; return $remote; } public function test_connect($is_pro) { $passive =$this->options['passive']; $host = $this->options['host']; $username = $this->options['username']; $password = $this->options['password']; $path = $this->options['path']; $port = empty($this->options['port'])?21:$this->options['port']; $conn = $this -> do_connect($host,$username,$password,$port); if(is_array($conn) && array_key_exists('result',$conn)) return $conn; ftp_pasv($conn,$passive); if($is_pro){ $ret= $this->do_chdir($conn,$path); if($ret['result']=='success') { $path=$this->options['path'].'wpvividbackuppro/'; $ret= $this->do_chdir($conn,$path); if($ret['result']=='success') { $custom_path = 'localhost_child-site'; $path= $this->options['path'].'wpvividbackuppro/'.$custom_path; $this->do_chdir($conn,$path); $path= $this->options['path'].'wpvividbackuppro/'.$custom_path.'/rollback'; return $this->do_chdir($conn,$path); } else { return $ret; } } else { return $ret; } } else { return $this->do_chdir($conn, $path); } } public function sanitize_options($skip_name='') { $ret['result']='failed'; if(!isset($this->options['name'])) { $ret['error']=__('Warning: An alias for remote storage is required.','mainwp-wpvivid-extension'); return $ret; } $this->options['name']=sanitize_text_field($this->options['name']); if(empty($this->options['name'])) { $ret['error']=__('Warning: An alias for remote storage is required.','mainwp-wpvivid-extension'); return $ret; } $remoteslist=Mainwp_WPvivid_Extension_DB_Option::get_instance()->wpvivid_get_global_option('remote_addon', array()); if(isset($remoteslist) && !empty($remoteslist)) { foreach ($remoteslist['upload'] as $key => $value) { if (isset($value['name']) && $value['name'] == $this->options['name'] && $skip_name != $value['name']) { $ret['error'] = "Warning: The alias already exists in storage list."; return $ret; } } } $this->options['server']=sanitize_text_field($this->options['server']); if(empty($this->options['server'])) { $ret['error']="Warning: The FTP server is required."; return $ret; } $res = explode(':',$this -> options['server']); if(sizeof($res) > 1){ $this ->options['host'] = $res[0]; if($res[1] != 21){ $ret['error']='Currently, only port 21 is supported.'; return $ret; } }else{ $this -> options['host'] = $res[0]; } if(!isset($this->options['port'])){ $ret['error']="Warning: The servers port is required."; return $ret; } if(empty($this->options['port'])){ $ret['error']="Warning: The servers port is required."; return $ret; } if(!isset($this->options['username'])) { $ret['error']="Warning: The FTP login is required."; return $ret; } $this->options['username']=sanitize_text_field($this->options['username']); if(empty($this->options['username'])) { $ret['error']="Warning: The FTP login is required."; return $ret; } if(!isset($this->options['password'])||empty($this->options['password'])) { $ret['error']="Warning: The FTP password is required."; return $ret; } $this->options['password']=sanitize_text_field($this->options['password']); if(empty($this->options['password'])) { $ret['error']="Warning: The FTP password is required."; return $ret; } $this->options['password'] = base64_encode($this->options['password']); $this->options['is_encrypt'] = 1; if(!isset($this->options['path'])||empty($this->options['path'])) { $ret['error']="Warning: The storage path is required."; return $ret; } $this->options['path']=sanitize_text_field($this->options['path']); $this->options['path']=trailingslashit($this->options['path']); if(empty($this->options['path'])) { $ret['error']="Warning: The storage path is required."; return $ret; } $ret['result']='success'; $ret['options']=$this->options; return $ret; } public function do_connect($server,$username,$password,$port = 21) { $conn = ftp_connect( $server, $port, $this ->time_out ); if($conn) { if(ftp_login($conn,$username,$password)) { return $conn; } else { return array('result'=>'failed','error'=>'Login failed. You have entered the incorrect credential(s). Please try again.'); } } else{ return array('result'=>'failed','error'=>'Login failed. The connection has timed out. Please try again later.'); } } public function do_chdir($conn,$path){ if(!@ftp_chdir($conn,$path)) { if ( ! ftp_mkdir( $conn, $path ) ) { return array('result'=>'failed','error'=>'Failed to create a backup. Make sure you have sufficient privileges to perform the operation.'); } if (!@ftp_chdir($conn,$path)){ return array('result'=>'failed','error'=>'Failed to create a backup. Make sure you have sufficient privileges to perform the operation.'); } } return array('result'=>'success'); } public function mwp_wpvivid_get_out_of_date_ftp($out_of_date_remote, $remote) { if($remote['type'] == MAINWP_WPVIVID_REMOTE_FTP){ $out_of_date_remote = $remote['path']; } return $out_of_date_remote; } public function mwp_wpvivid_storage_provider_ftp($storage_type) { if($storage_type == MAINWP_WPVIVID_REMOTE_FTP){ $storage_type = 'FTP'; } return $storage_type; } } includes/customclass/class-wpvivid-pcloud.php 0000644 00000005315 15133715745 0015521 0 ustar 00 <?php if (!defined('MAINWP_WPVIVID_EXTENSION_PLUGIN_DIR')){ die; } define('MAINWP_WPVIVID_REMOTE_PCLOUD','pCloud'); require_once MAINWP_WPVIVID_EXTENSION_PLUGIN_DIR . '/includes/customclass/class-wpvivid-remote.php'; class Mainwp_WPvivid_pCloud extends Mainwp_WPvivid_Remote{ public $options; public function __construct($options=array()){ if(empty($options)) { if(!defined('MAINWP_WPVIVID_INIT_STORAGE_TAB_PCLOUD')) { add_action('mwp_wpvivid_add_storage_tab_addon', array($this, 'mwp_wpvivid_add_storage_tab_pcloud_addon'), 10); add_action('mwp_wpvivid_add_storage_page_addon', array($this, 'mwp_wpvivid_add_storage_page_pcloud_addon'), 10); add_action('mwp_wpvivid_add_storage_page_pcloud_addon', array($this, 'mwp_wpvivid_add_storage_page_pcloud_addon')); add_filter('mwp_wpvivid_remote_pic', array($this, 'mwp_wpvivid_remote_pic_pcloud'), 11); add_filter('mwp_wpvivid_storage_provider_tran', array($this, 'mwp_wpvivid_storage_provider_pcloud'), 10); define('MAINWP_WPVIVID_INIT_STORAGE_TAB_PCLOUD',1); } } else { $this->options=$options; } } public function mwp_wpvivid_add_storage_tab_pcloud_addon(){ ?> <div class="mwp-storage-providers-addon" remote_type="pcloud" onclick="select_remote_storage_addon(event, 'mwp_wpvivid_storage_account_pcloud_addon');"> <img src="<?php echo esc_url(MAINWP_WPVIVID_EXTENSION_PLUGIN_URL.'/admin/images/storage-pcloud.png'); ?>" style="vertical-align:middle;"/><?php esc_html_e('pCloud', 'mainwp-wpvivid-extension'); ?> </div> <?php } public function mwp_wpvivid_add_storage_page_pcloud_addon(){ ?> <div id="mwp_wpvivid_storage_account_pcloud_addon" class="storage-account-page-addon"> <p>Global configuration is not available for pCloud due to authorization mechanism (tokens will be expired). Please get authorization in child-sites</p> </div> <?php } public function mwp_wpvivid_remote_pic_pcloud($remote){ $remote['pCloud']['default_pic'] = '/admin/images/storage-pcloud(gray).png'; $remote['pCloud']['selected_pic'] = '/admin/images/storage-pcloud.png'; $remote['pCloud']['title'] = 'pCloud'; return $remote; } public function mwp_wpvivid_storage_provider_pcloud($storage_type){ if($storage_type == MAINWP_WPVIVID_REMOTE_PCLOUD){ $storage_type = 'pCloud'; } return $storage_type; } public function test_connect($is_pro){ return array('result' => 'success'); } } includes/customclass/class-wpvivid-one-drive.php 0000644 00000011020 15133715745 0016111 0 ustar 00 <?php /** * Created by PhpStorm. * User: alienware`x * Date: 2019/2/14 * Time: 16:06 */ if (!defined('MAINWP_WPVIVID_EXTENSION_PLUGIN_DIR')){ die; } require_once MAINWP_WPVIVID_EXTENSION_PLUGIN_DIR . '/includes/customclass/class-wpvivid-remote.php'; define('MAINWP_WPVIVID_REMOTE_ONEDRIVE','onedrive'); define('MAINWP_WPVIVID_ONEDRIVE_DEFAULT_FOLDER','wpvivid_backup'); define('MAINWP_WPVIVID_ONEDRIVE_RETRY_TIMES','3'); class Mainwp_WPvivid_one_drive extends Mainwp_WPvivid_Remote { public $options; public function __construct($options=array()) { if(empty($options)) { if(!defined('MAINWP_WPVIVID_INIT_STORAGE_TAB_ONE_DRIVE')) { add_action('mwp_wpvivid_add_storage_tab',array($this,'mwp_wpvivid_add_storage_tab_one_drive'), 10); add_action('mwp_wpvivid_add_storage_page',array($this,'mwp_wpvivid_add_storage_page_one_drive'), 10); add_action('mwp_wpvivid_add_storage_tab_addon', array($this, 'mwp_wpvivid_add_storage_tab_one_drive_addon'), 10); add_action('mwp_wpvivid_add_storage_page_addon', array($this, 'mwp_wpvivid_add_storage_page_one_drive_addon'), 10); add_action('mwp_wpvivid_add_storage_page_one_drive_addon', array($this, 'mwp_wpvivid_add_storage_page_one_drive_addon')); add_filter('mwp_wpvivid_remote_pic',array($this,'mwp_wpvivid_remote_pic_one_drive'),10); add_filter('mwp_wpvivid_storage_provider_tran',array($this,'mwp_wpvivid_storage_provider_one_drive'),10); define('MAINWP_WPVIVID_INIT_STORAGE_TAB_ONE_DRIVE',1); } } else { $this->options=$options; } } public function mwp_wpvivid_add_storage_tab_one_drive() { ?> <div class="mwp-storage-providers" remote_type="one_drive" onclick="select_remote_storage(event, 'storage_account_one_drive');"> <img src="<?php echo esc_url(MAINWP_WPVIVID_EXTENSION_PLUGIN_URL.'/admin/images/storage-microsoft-onedrive.png'); ?>" style="vertical-align:middle;"/><?php esc_html_e('Microsoft OneDrive', 'mainwp-wpvivid-extension'); ?> </div> <?php } public function mwp_wpvivid_add_storage_page_one_drive() { ?> <div id="storage_account_one_drive" class="storage-account-page" style="display:none;"> <p>Global configuration is not available for OneDrive due to authorization mechanism (tokens will be expired). Please get authorization in child-sites</p> </div> <?php } public function mwp_wpvivid_add_storage_tab_one_drive_addon(){ ?> <div class="mwp-storage-providers-addon" remote_type="one_drive" onclick="select_remote_storage_addon(event, 'mwp_wpvivid_storage_account_one_drive_addon');"> <img src="<?php echo esc_url(MAINWP_WPVIVID_EXTENSION_PLUGIN_URL.'/admin/images/storage-microsoft-onedrive.png'); ?>" style="vertical-align:middle;"/><?php esc_html_e('Microsoft OneDrive', 'mainwp-wpvivid-extension'); ?> </div> <?php } public function mwp_wpvivid_add_storage_page_one_drive_addon(){ ?> <div id="mwp_wpvivid_storage_account_one_drive_addon" class="storage-account-page-addon"> <p>Global configuration is not available for OneDrive due to authorization mechanism (tokens will be expired). Please get authorization in child-sites</p> </div> <?php } public function sanitize_options($skip_name='') { $ret['result']='success'; if(!isset($this->options['name'])) { $ret['error']="Warning: An alias for remote storage is required."; return $ret; } $ret['options']=$this->options; return $ret; } public function test_connect($is_pro) { return array('result' => 'success'); } public function mwp_wpvivid_remote_pic_one_drive($remote) { $remote['onedrive']['default_pic'] = '/admin/images/storage-microsoft-onedrive(gray).png'; $remote['onedrive']['selected_pic'] = '/admin/images/storage-microsoft-onedrive.png'; $remote['onedrive']['title'] = 'Microsoft OneDrive'; return $remote; } public function mwp_wpvivid_storage_provider_one_drive($storage_type) { if($storage_type == MAINWP_WPVIVID_REMOTE_ONEDRIVE){ $storage_type = 'Microsoft OneDrive'; } return $storage_type; } } includes/customclass/class-wpvivid-nextcloud.php 0000644 00000040110 15133715745 0016230 0 ustar 00 <?php if (!defined('MAINWP_WPVIVID_EXTENSION_PLUGIN_DIR')){ die; } define('MAINWP_WPVIVID_REMOTE_NEXTCLOUD','nextcloud'); require_once MAINWP_WPVIVID_EXTENSION_PLUGIN_DIR . '/includes/customclass/class-wpvivid-remote.php'; class Mainwp_WPvivid_NextcloudClass extends Mainwp_WPvivid_Remote { public $options; public function __construct($options=array()) { if(empty($options)) { if(!defined('MAINWP_WPVIVID_INIT_STORAGE_TAB_NEXTCLOUD')) { add_action('mwp_wpvivid_add_storage_page_nextcloud_addon', array($this, 'mwp_wpvivid_add_storage_page_nextcloud_addon')); add_action('mwp_wpvivid_edit_storage_page_addon', array($this, 'mwp_wpvivid_edit_storage_page_nextcloud_addon'), 11); add_filter('mwp_wpvivid_storage_provider_tran', array($this, 'mwp_wpvivid_storage_provider_nextcloud'), 10); define('MAINWP_WPVIVID_INIT_STORAGE_TAB_NEXTCLOUD',1); } } else { $this->options=$options; } } public function mwp_wpvivid_add_storage_page_nextcloud_addon() { ?> <div class="storage-account-page-addon" id="mwp_wpvivid_storage_account_nextcloud_addon"> <div style="padding: 0 10px 10px 0;"><strong>Enter Your Nextcloud Account</strong></div> <table class="wp-list-table widefat plugins" style="width:100%;"> <tbody> <form> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input type="text" class="regular-text" autocomplete="off" option="nextcloud-addon" name="name" placeholder="Enter a unique alias: e.g. NEXTCLOUD-001" onkeyup="value=value.replace(/[^a-zA-Z0-9\-_]/g,'')" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>A name to help you identify the storage if you have multiple remote storage connected.</i> </div> </td> </tr> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input type="text" autocomplete="off" option="nextcloud-addon" name="host" placeholder="Host" style="width:220px;" /> <span style="width:10px;">/</span> <input type="text" value="remote.php/dav" style="width:120px;" readonly="readonly" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>Enter the storage hostname.</i> </div> </td> </tr> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input type="text" class="regular-text" autocomplete="off" option="nextcloud-addon" name="username" placeholder="Username" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>Enter the username.</i> </div> </td> </tr> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input type="password" class="regular-text" autocomplete="off" option="nextcloud-addon" name="password" placeholder="Password" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>Enter the password.</i> </div> </td> </tr> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input type="text" class="regular-text" autocomplete="off" option="nextcloud-addon" name="root_path" value="<?php echo esc_attr(apply_filters('wpvivid_white_label_remote_root_path', 'wpvividbackuppro')); ?>" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i><span><?php echo sprintf(esc_html('Customize a root directory in the storage for holding WPvivid backup directories.', 'wpvivid'), esc_html(apply_filters('wpvivid_white_label_display', 'WPvivid backup'))); ?></span></i> </div> </td> </tr> <?php do_action('mwp_wpvivid_remote_storage_backup_retention', 'nextcloud-addon', 'add'); ?> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input style="width: 50px" type="text" class="regular-text" autocomplete="off" option="nextcloud-addon" name="chunk_size" placeholder="Chunk size" value="3" onkeyup="value=value.replace(/\D/g,'')" />MB </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>The block size of uploads and downloads. Reduce it if you encounter a timeout when transferring files.</i> </div> </td> </tr> </form> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input class="ui green mini button" option="add-remote-addon-global" type="button" value="Save and Sync" remote_type="nextcloud" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>Click the button to connect to B2 storage and add it to the storage list below</i> </div> </td> </tr> </tbody> </table> </div> <?php } public function mwp_wpvivid_edit_storage_page_nextcloud_addon() { ?> <div class="mwp-wpvivid-remote-storage-edit" id="mwp_wpvivid_storage_account_nextcloud_edit" style="display:none;"> <div class="mwp-wpvivid-block-bottom-space" style="margin-top: 10px;"><strong>Enter Your Nextcloud Account</strong></div> <table class="wp-list-table widefat plugins" style="width:100%;"> <tbody> <form> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input type="text" class="regular-text" autocomplete="off" option="edit-nextcloud-addon" name="name" placeholder="Enter a unique alias: e.g. NEXTCLOUD-001" onkeyup="value=value.replace(/[^a-zA-Z0-9\-_]/g,'')" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>A name to help you identify the storage if you have multiple remote storage connected.</i> </div> </td> </tr> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input type="text" autocomplete="off" option="edit-nextcloud-addon" name="host" placeholder="Host" style="width:220px;" /> <span style="width:10px;">/</span> <input type="text" value="remote.php/dav" style="width:120px;" readonly="readonly" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>Enter the storage hostname.</i> </div> </td> </tr> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input type="text" class="regular-text" autocomplete="off" option="edit-nextcloud-addon" name="username" placeholder="Username" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>Enter the username.</i> </div> </td> </tr> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input type="password" class="regular-text" autocomplete="off" option="edit-nextcloud-addon" name="password" placeholder="Password" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>Enter the password.</i> </div> </td> </tr> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input type="text" class="regular-text" autocomplete="off" option="edit-nextcloud-addon" name="root_path" value="<?php echo esc_attr(apply_filters('wpvivid_white_label_remote_root_path', 'wpvividbackuppro')); ?>" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i><span><?php echo sprintf(esc_html('Customize a root directory in the storage for holding WPvivid backup directories.', 'wpvivid'), esc_html(apply_filters('wpvivid_white_label_display', 'WPvivid backup'))); ?></span></i> </div> </td> </tr> <?php do_action('mwp_wpvivid_remote_storage_backup_retention', 'nextcloud-addon', 'edit'); ?> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input style="width: 50px" type="text" class="regular-text" autocomplete="off" option="edit-nextcloud-addon" name="chunk_size" placeholder="Chunk size" value="3" onkeyup="value=value.replace(/\D/g,'')" />MB </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>The block size of uploads and downloads. Reduce it if you encounter a timeout when transferring files.</i> </div> </td> </tr> </form> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input class="ui green mini button" option="edit-remote-addon-global" type="button" value="Save Changes" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>Click the button to connect to B2 storage and add it to the storage list below</i> </div> </td> </tr> </tbody> </table> </div> <?php } public function mwp_wpvivid_storage_provider_nextcloud($storage_type) { if($storage_type == MAINWP_WPVIVID_REMOTE_NEXTCLOUD) { $storage_type = 'NextCloud'; } return $storage_type; } public function sanitize_options($skip_name='') { $ret['result']='failed'; if(!isset($this->options['name'])) { $ret['error']="Warning: An alias for remote storage is required."; return $ret; } $this->options['name']=sanitize_text_field($this->options['name']); if(empty($this->options['name'])) { $ret['error']="Warning: An alias for remote storage is required."; return $ret; } $remoteslist=Mainwp_WPvivid_Extension_DB_Option::get_instance()->wpvivid_get_global_option('remote_addon', array()); if(isset($remoteslist) && !empty($remoteslist)) { foreach ($remoteslist['upload'] as $key => $value) { if (isset($value['name']) && $value['name'] == $this->options['name'] && $skip_name != $value['name']) { $ret['error'] = "Warning: The alias already exists in storage list."; return $ret; } } } if(!isset($this->options['host'])) { $ret['error']="Warning: The hostname for Nextcloud is required."; return $ret; } $this->options['host']=sanitize_text_field($this->options['host']); if(empty($this->options['host'])) { $ret['error']="Warning: The hostname for Nextcloud is required."; return $ret; } if(!isset($this->options['username'])) { $ret['error']="Warning: The username for Nextcloud is required."; return $ret; } $this->options['username']=sanitize_text_field($this->options['username']); if(empty($this->options['username'])) { $ret['error']="Warning: The username for Nextcloud is required."; return $ret; } if(!isset($this->options['password'])) { $ret['error']="Warning: The password is required."; return $ret; } if(!isset($this->options['root_path'])) { $ret['error']="Warning: The root path is required."; return $ret; } $this->options['root_path']=sanitize_text_field($this->options['root_path']); if(empty($this->options['root_path'])) { $ret['error']="Warning: The root path is required."; return $ret; } $ret['result']='success'; $ret['options']=$this->options; return $ret; } public function test_connect($is_pro) { return array('result' => 'success'); } } includes/customclass/class-wpvivid-remote-default.php 0000644 00000001455 15133715745 0017151 0 ustar 00 <?php if (!defined('WPVIVID_PLUGIN_DIR')){ die; } require_once WPVIVID_PLUGIN_DIR .'/includes/customclass/class-wpvivid-remote.php'; class WPvivid_Remote_Defult extends WPvivid_Remote{ public function test_connect($is_pro) { return array('result' => MAINWP_WPVIVID_FAILED,'error'=> 'Type incorrect.'); } public function upload($task_id, $files, $callback = '') { return array('result' => MAINWP_WPVIVID_FAILED,'error'=> 'Type incorrect.'); } public function download( $file, $local_path, $callback = '') { return array('result' => MAINWP_WPVIVID_FAILED,'error'=> 'Type incorrect.'); } public function cleanup($files) { return array('result' => MAINWP_WPVIVID_FAILED,'error'=> 'Type incorrect.'); } } includes/customclass/class-wpvivid-amazons3-plus.php 0000644 00000102267 15133715745 0016753 0 ustar 00 <?php if (!defined('MAINWP_WPVIVID_EXTENSION_PLUGIN_DIR')){ die; } define('MAINWP_WPVIVID_REMOTE_AMAZONS3','amazons3'); define('MAINWP_WPVIVID_AMAZONS3_DEFAULT_FOLDER','/wpvivid_backup'); require_once MAINWP_WPVIVID_EXTENSION_PLUGIN_DIR . '/includes/customclass/class-wpvivid-remote.php'; require_once MAINWP_WPVIVID_EXTENSION_PLUGIN_DIR . '/includes/customclass/class-wpvivid-base-s3.php'; class Mainwp_WPvivid_AMAZONS3Class extends Mainwp_WPvivid_Remote{ public $options; public $bucket=''; public function __construct($options=array()) { if(empty($options)) { add_action('mwp_wpvivid_add_storage_tab',array($this,'mwp_wpvivid_add_storage_tab_amazons3'), 11); add_action('mwp_wpvivid_add_storage_page',array($this,'mwp_wpvivid_add_storage_page_amazons3'), 11); add_action('mwp_wpvivid_add_storage_tab_addon', array($this, 'mwp_wpvivid_add_storage_tab_amazons3_addon'), 11); add_action('mwp_wpvivid_add_storage_page_addon', array($this, 'mwp_wpvivid_add_storage_page_amazons3_addon'), 11); add_action('mwp_wpvivid_add_storage_page_amazons3_addon', array($this, 'mwp_wpvivid_add_storage_page_amazons3_addon')); add_action('mwp_wpvivid_edit_storage_page_addon', array($this, 'mwp_wpvivid_edit_storage_page_amazons3_addon'), 11); add_filter('mwp_wpvivid_remote_pic',array($this,'mwp_wpvivid_remote_pic_amazons3'),11); add_filter('mwp_wpvivid_storage_provider_tran',array($this,'mwp_wpvivid_storage_provider_amazons3'),10); } else { $this->options=$options; } } public function mwp_wpvivid_add_storage_tab_amazons3() { ?> <div class="mwp-storage-providers" remote_type="amazons3" onclick="select_remote_storage(event, 'mwp_wpvivid_storage_account_amazons3');"> <img src="<?php echo esc_url(MAINWP_WPVIVID_EXTENSION_PLUGIN_URL.'/admin/images/storage-amazon-s3.png'); ?>" style="vertical-align:middle;"/><?php esc_html_e('Amazon S3', 'mainwp-wpvivid-extension'); ?> </div> <?php } public function mwp_wpvivid_add_storage_page_amazons3() { ?> <div id="mwp_wpvivid_storage_account_amazons3" class="storage-account-page" style="display:none;"> <div class="mwp-wpvivid-block-bottom-space"><strong>Enter Your Amazon S3 Account</strong></div> <table class="wp-list-table widefat plugins" style="width:100%;"> <tbody> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input type="text" class="regular-text" autocomplete="off" option="amazons3" name="name" placeholder="Enter a unique alias: e.g. Amazon S3-001" onkeyup="value=value.replace(/[^a-zA-Z0-9\-_]/g,'')" style="height: 27px;" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>A name to help you identify the storage if you have multiple remote storage connected.</i> </div> </td> </tr> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input type="text" class="regular-text" autocomplete="off" option="amazons3" name="access" placeholder="Amazon S3 access key" style="height: 27px;" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>Enter your Amazon S3 access key.</i> </div> </td> </tr> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input type="password" class="regular-text" autocomplete="new-password" option="amazons3" name="secret" placeholder="Amazon S3 secret key" style="height: 27px;" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>Enter your Amazon S3 secret key.</i> </div> </td> </tr> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input type="text" class="regular-text" autocomplete="off" option="amazons3" name="bucket" placeholder="Amazon S3 Bucket Name(e.g. test)" style="height: 27px;" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i><span>Enter an existed Bucket to create a custom backup storage directory.</span></i> </div> </td> </tr> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input type="text" class="regular-text" autocomplete="off" option="amazons3" name="path" placeholder="Custom Path" style="height: 27px;" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i><span>Customize the directory where you want to store backups within the Bucket.</span></i> </div> </td> </tr> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-select"> <label> <input type="checkbox" option="amazons3" name="default" checked />Set as the default remote storage. </label> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>Once checked, all this sites backups sent to a remote storage destination will be uploaded to this storage by default.</i> </div> </td> </tr> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-select"> <label> <input type="checkbox" option="amazons3" name="classMode" checked />Storage class: Standard (infrequent access). </label> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>Check the option to use Amazon S3 Standard-Infrequent Access (S3 Standard-IA) storage class for data transfer.</i> </div> </td> </tr> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-select"> <label> <input type="checkbox" option="amazons3" name="sse" checked />Server-side encryption. </label> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>Check the option to use Amazon S3 server-side encryption to protect data.</i> </div> </td> </tr> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input class="ui green mini button" option="add-remote" type="button" value="Test and Add" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>Click the button to connect to Amazon S3 storage and add it to the storage list below.</i> </div> </td> </tr> </tbody> </table> </div> <?php } public function mwp_wpvivid_add_storage_tab_amazons3_addon(){ ?> <div class="mwp-storage-providers-addon" remote_type="amazons3" onclick="select_remote_storage_addon(event, 'mwp_wpvivid_storage_account_amazons3_addon');"> <img src="<?php echo esc_url(MAINWP_WPVIVID_EXTENSION_PLUGIN_URL.'/admin/images/storage-amazon-s3.png'); ?>" style="vertical-align:middle;"/><?php esc_html_e('Amazon S3', 'mainwp-wpvivid-extension'); ?> </div> <?php } public function mwp_wpvivid_add_storage_page_amazons3_addon(){ ?> <div class="storage-account-page-addon" id="mwp_wpvivid_storage_account_amazons3_addon"> <div class="mwp-wpvivid-block-bottom-space"><strong>Enter Your Amazon S3 Account</strong></div> <table class="wp-list-table widefat plugins" style="width:100%;"> <tbody> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input type="text" class="regular-text" autocomplete="off" option="amazons3-addon" name="name" placeholder="Enter a unique alias: e.g. Amazon S3-001" onkeyup="value=value.replace(/[^a-zA-Z0-9\-_]/g,'')" style="height: 27px;" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>A name to help you identify the storage if you have multiple remote storage connected.</i> </div> </td> </tr> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input type="text" class="regular-text" autocomplete="off" option="amazons3-addon" name="access" placeholder="Amazon S3 access key" style="height: 27px;" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>Enter your Amazon S3 access key.</i> </div> </td> </tr> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input type="password" class="regular-text" autocomplete="new-password" option="amazons3-addon" name="secret" placeholder="Amazon S3 secret key" style="height: 27px;" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>Enter your Amazon S3 secret key.</i> </div> </td> </tr> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input type="text" class="regular-text" autocomplete="off" option="amazons3-addon" name="bucket" placeholder="Amazon S3 Bucket Name(e.g. test)" style="height: 27px;" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i><span>Enter an existed Bucket to create a custom backup storage directory.</span></i> </div> </td> </tr> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input type="text" class="regular-text" autocomplete="off" option="amazons3-addon" name="root_path" value="<?php echo esc_attr(apply_filters('wpvivid_white_label_remote_root_path', 'wpvividbackuppro')); ?>" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i><span><?php /* translators: %s: Folder name. */ echo sprintf(esc_html('Customize a parent folder in the Bucket for holding %s folders.', 'wpvivid'), esc_html(apply_filters('wpvivid_white_label_display', 'WPvivid backup'))); ?></span></i> </div> </td> </tr> <?php do_action('mwp_wpvivid_remote_storage_backup_retention', 'amazons3-addon', 'add'); ?> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input style="width: 50px" type="text" class="regular-text" autocomplete="off" option="amazons3-addon" name="chunk_size" placeholder="Chunk size" value="5" onkeyup="value=value.replace(/\D/g,'')" />MB </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>The block size of uploads and downloads. Reduce it if you encounter a timeout when transferring files.</i> </div> </td> </tr> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-select"> <label> <input type="checkbox" option="amazons3-addon" name="classMode" checked />Storage class: Standard (infrequent access). </label> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>Check the option to use Amazon S3 Standard-Infrequent Access (S3 Standard-IA) storage class for data transfer.</i> </div> </td> </tr> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-select"> <label> <input type="checkbox" option="amazons3-addon" name="sse" checked />Server-side encryption. </label> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>Check the option to use Amazon S3 server-side encryption to protect data.</i> </div> </td> </tr> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-select"> <label> <input type="checkbox" option="amazons3-addon" name="uncheckdelete" />Do not check DeleteObject. </label> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <div style="float: left; padding-right: 5px;"> <i>Tick this option so WPvivid won't check s3:DeleteObject permission of the user in the authentication.</i> </div> <span class="dashicons dashicons-editor-help mwp-wpvivid-dashicons-editor-help mwp-wpvivid-tooltip-ex"> <div class="mwp-wpvivid-bottom"> <p>s3:DeleteObject is a permission for deleting objects from Amazon S3. Without it, you are not able to delete backups on S3 from WPvivid.</p> <i></i> </div> </span> <div style="clear: both;"></div> </div> </td> </tr> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input class="ui green mini button" option="add-remote-addon-global" type="button" value="Save and Sync" remote_type="amazons3" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>Click the button to connect to Amazon S3 storage and add it to the storage list below.</i> </div> </td> </tr> </tbody> </table> </div> <?php } public function mwp_wpvivid_edit_storage_page_amazons3_addon(){ ?> <div class="mwp-wpvivid-remote-storage-edit" id="mwp_wpvivid_storage_account_amazons3_edit" style="display:none;"> <div class="mwp-wpvivid-block-bottom-space" style="margin-top: 10px;"><strong>Enter Your Amazon S3 Account</strong></div> <table class="wp-list-table widefat plugins" style="width:100%;"> <tbody> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input type="text" class="regular-text" autocomplete="off" option="edit-amazons3-addon" name="name" placeholder="Enter a unique alias: e.g. Amazon S3-001" onkeyup="value=value.replace(/[^a-zA-Z0-9\-_]/g,'')" style="height: 27px;" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>A name to help you identify the storage if you have multiple remote storage connected.</i> </div> </td> </tr> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input type="text" class="regular-text" autocomplete="off" option="edit-amazons3-addon" name="access" placeholder="Amazon S3 access key" style="height: 27px;" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>Enter your Amazon S3 access key.</i> </div> </td> </tr> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input type="password" class="regular-text" autocomplete="new-password" option="edit-amazons3-addon" name="secret" placeholder="Amazon S3 secret key" style="height: 27px;" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>Enter your Amazon S3 secret key.</i> </div> </td> </tr> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input type="text" class="regular-text" autocomplete="off" option="edit-amazons3-addon" name="bucket" placeholder="Amazon S3 Bucket Name(e.g. test)" style="height: 27px;" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i><span>Enter an existed Bucket to create a custom backup storage directory.</span></i> </div> </td> </tr> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input type="text" class="regular-text" autocomplete="off" option="edit-amazons3-addon" name="root_path" value="<?php echo esc_attr(apply_filters('wpvivid_white_label_remote_root_path', 'wpvividbackuppro')); ?>" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i><span><?php /* translators: %s: Folder name. */ echo sprintf(esc_html('Customize a parent folder in the Bucket for holding %s folders.', 'wpvivid'), esc_html(apply_filters('wpvivid_white_label_display', 'WPvivid backup'))); ?></span></i> </div> </td> </tr> <?php do_action('mwp_wpvivid_remote_storage_backup_retention', 'amazons3-addon', 'edit'); ?> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input style="width: 50px" type="text" class="regular-text" autocomplete="off" option="edit-amazons3-addon" name="chunk_size" placeholder="Chunk size" value="5" onkeyup="value=value.replace(/\D/g,'')" />MB </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>The block size of uploads and downloads. Reduce it if you encounter a timeout when transferring files.</i> </div> </td> </tr> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-select"> <label> <input type="checkbox" option="edit-amazons3-addon" name="classMode" checked />Storage class: Standard (infrequent access). </label> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>Check the option to use Amazon S3 Standard-Infrequent Access (S3 Standard-IA) storage class for data transfer.</i> </div> </td> </tr> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-select"> <label> <input type="checkbox" option="edit-amazons3-addon" name="sse" checked />Server-side encryption. </label> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>Check the option to use Amazon S3 server-side encryption to protect data.</i> </div> </td> </tr> <tr> <td class="plugin-title column-primary"> <div class="mwp-wpvivid-storage-form"> <input class="ui green mini button" option="edit-remote-addon-global" type="button" value="Save Changes" /> </div> </td> <td class="column-description desc"> <div class="mwp-wpvivid-storage-form-desc"> <i>Click the button to connect to Amazon S3 storage and add it to the storage list below.</i> </div> </td> </tr> </tbody> </table> </div> <?php } public function mwp_wpvivid_remote_pic_amazons3($remote){ $remote['amazons3']['default_pic'] = '/admin/images/storage-amazon-s3(gray).png'; $remote['amazons3']['selected_pic'] = '/admin/images/storage-amazon-s3.png'; $remote['amazons3']['title'] = 'Amazon S3'; return $remote; } public function test_connect($is_pro) { $amazons3 = $this -> getS3(); if(is_array($amazons3) && $amazons3['result'] === 'failed') return $amazons3; $temp_file = md5(wp_rand()); try { if(isset($this->options['s3Path'])) { $url=$this->options['s3Path'].$temp_file; } else { $url=$this->options['path'].'/'.$temp_file; } if(!$amazons3 -> putObjectString($temp_file,$this -> bucket,$url)) { return array('result'=>'failed','error'=>'We successfully accessed the bucket, but create test file failed.'); } if(!$amazons3 -> deleteObject($this -> bucket,$url)) { return array('result'=>'failed','error'=>'We successfully accessed the bucket, and create test file succeed, but delete test file failed.'); } }catch(Exception $e){ return array('result'=>'failed','error'=>$e -> getMessage()); } return array('result'=>'success'); } public function sanitize_options($skip_name='') { $ret['result']='failed'; if(!isset($this->options['name'])) { $ret['error']="Warning: An alias for remote storage is required."; return $ret; } $this->options['name']=sanitize_text_field($this->options['name']); if(empty($this->options['name'])) { $ret['error']="Warning: An alias for remote storage is required."; return $ret; } $remoteslist=Mainwp_WPvivid_Extension_DB_Option::get_instance()->wpvivid_get_global_option('remote_addon', array()); if(isset($remoteslist) && !empty($remoteslist)) { foreach ($remoteslist['upload'] as $key => $value) { if (isset($value['name']) && $value['name'] == $this->options['name'] && $skip_name != $value['name']) { $ret['error'] = "Warning: The alias already exists in storage list."; return $ret; } } } if(!isset($this->options['access'])) { $ret['error']="Warning: The access key for Amazon S3 is required."; return $ret; } $this->options['access']=sanitize_text_field($this->options['access']); if(empty($this->options['access'])) { $ret['error']="Warning: The access key for Amazon S3 is required."; return $ret; } if(!isset($this->options['secret'])) { $ret['error']="Warning: The storage secret key is required."; return $ret; } $this->options['secret']=sanitize_text_field($this->options['secret']); if(empty($this->options['secret'])) { $ret['error']="Warning: The storage secret key is required."; return $ret; } $this->options['secret'] = base64_encode($this->options['secret']); $this->options['is_encrypt'] = 1; if(!isset($this->options['bucket'])) { $ret['error']="Warning: A Bucket name is required."; return $ret; } $this->options['bucket']=sanitize_text_field($this->options['bucket']); if(empty($this->options['bucket'])) { $ret['error']="Warning: A Bucket name is required."; return $ret; } $ret['result']='success'; $ret['options']=$this->options; return $ret; } private function getS3() { if(isset($this->options['s3Path'])) { $path_temp = str_replace('s3://','',$this->options['s3Path']); if (preg_match("#^/*([^/]+)/(.*)$#", $path_temp, $bmatches)) { $this->bucket = $bmatches[1]; if(empty($bmatches[2])){ $this->options['s3Path'] = ''; }else{ $this->options['s3Path'] = trailingslashit($bmatches[2]); } } else { $this->bucket = $path_temp; $this->options['s3Path'] = ''; } $amazons3 = new MainWP_WPvivid_Base_S3($this->options['access'],$this->options['secret']); $amazons3 -> setExceptions(); if($this->options['classMode']) $amazons3 -> setStorageClass(); if($this->options['sse']) $amazons3 -> setServerSideEncryption(); try{ $region = $amazons3 -> getBucketLocation($this->bucket); }catch(Exception $e){ return array('result' => 'failed','error' => $e -> getMessage()); } $endpoint = $this -> getEndpoint($region); if(!empty($endpoint)) $amazons3 -> setEndpoint($endpoint); return $amazons3; } else { $this->bucket= $this->options['bucket']; $amazons3 = new MainWP_WPvivid_Base_S3($this->options['access'],$this->options['secret']); $amazons3 -> setExceptions(); if($this->options['classMode']) $amazons3 -> setStorageClass(); if($this->options['sse']) $amazons3 -> setServerSideEncryption(); try{ $region = $amazons3 -> getBucketLocation($this->bucket); }catch(Exception $e){ return array('result' => 'failed','error' => $e -> getMessage()); } $amazons3->setSignatureVersion('v4'); $amazons3->setRegion($region); $endpoint = $this -> getEndpoint($region); if(!empty($endpoint)) $amazons3 -> setEndpoint($endpoint); return $amazons3; } } private function getEndpoint($region){ switch ($region) { case 'EU': case 'eu-west-1': $endpoint = 's3-eu-west-1.amazonaws.com'; break; case 'US': case 'us-east-1': $endpoint = 's3.amazonaws.com'; break; case 'us-west-1': case 'us-east-2': case 'us-west-2': case 'eu-west-2': case 'eu-west-3': case 'ap-southeast-1': case 'ap-southeast-2': case 'ap-northeast-2': case 'sa-east-1': case 'ca-central-1': case 'us-gov-west-1': case 'eu-north-1': case 'eu-central-1': $endpoint = 's3-'.$region.'.amazonaws.com'; break; case 'ap-northeast-1': $endpoint = 's3.'.$region.'.amazonaws.com'; break; case 'ap-south-1': $endpoint = 's3.'.$region.'.amazonaws.com'; break; case 'cn-north-1': $endpoint = 's3.'.$region.'.amazonaws.com.cn'; break; default: $endpoint = 's3.amazonaws.com'; break; } return $endpoint; } public function mwp_wpvivid_storage_provider_amazons3($storage_type) { if($storage_type == MAINWP_WPVIVID_REMOTE_AMAZONS3){ $storage_type = 'Amazon S3'; } return $storage_type; } } includes/customclass/class-wpvivid-base-dropbox.php 0000644 00000012764 15133715745 0016626 0 ustar 00 <?php if (!defined('MAINWP_WPVIVID_EXTENSION_PLUGIN_DIR')){ die; } class MainWP_Dropbox_Base{ const API_URL_V2 = 'https://api.dropboxapi.com/'; const CONTENT_URL_V2 = 'https://content.dropboxapi.com/2/'; const API_ID = 'cwn4z5jg8wy7b4u'; private $access_token; private $option; public function __construct($option){ $this -> option = $option; $this -> access_token = $option['token']; } public function upload($target_path, $file_data, $mode = "add") { $endpoint = self::CONTENT_URL_V2."files/upload"; $headers = array( "Content-Type: application/octet-stream", "Dropbox-API-Arg: {\"path\": \"$target_path\", \"mode\": \"$mode\"}" ); if (file_exists($file_data)) $postdata = file_get_contents($file_data); else $postdata = $file_data; $returnData = $this ->postRequest($endpoint, $headers, $postdata); return $returnData; } public function upload_session_start() { $endpoint = self::CONTENT_URL_V2."files/upload_session/start"; $headers = array( "Content-Type: application/octet-stream", "Dropbox-API-Arg: {\"close\": false}" ); $returnData = $this ->postRequest($endpoint, $headers,null); return $returnData; } public function upload_session_append_v2($session_id, $offset, $postdata) { $endpoint = self::CONTENT_URL_V2."files/upload_session/append_v2"; $headers = array( "Content-Type: application/octet-stream", "Dropbox-API-Arg: {\"cursor\": {\"session_id\": \"$session_id\",\"offset\": $offset},\"close\": false}" ); $returnData = $this ->postRequest($endpoint, $headers, $postdata); return $returnData; } public function upload_session_finish($session_id, $filesize, $path, $mode = 'add') { $endpoint = self::CONTENT_URL_V2."files/upload_session/finish"; $entry = array( 'cursor' => array( 'session_id' => $session_id, 'offset' => $filesize, ), 'commit' => array( 'path' => $path, 'mode' => $mode, ), ); $headers = array( "Content-Type: application/octet-stream", "Dropbox-API-Arg: " . wp_json_encode($entry), ); $returnData = $this ->postRequest($endpoint, $headers,null); return $returnData; } public function download($path,$header = array()) { $endpoint = "https://content.dropboxapi.com/2/files/download"; $headers = array( "Content-Type: text/plain; charset=utf-8", "Dropbox-API-Arg: {\"path\": \"$path\"}" ); $headers = array_merge ($headers,$header); $data = $this ->postRequest($endpoint, $headers,null,false); return $data; } public function delete($path) { $endpoint = self::API_URL_V2."2/files/delete"; $headers = array( "Content-Type: application/json" ); $postdata = wp_json_encode(array( "path" => $path )); $returnData = $this -> postRequest($endpoint, $headers, $postdata); return $returnData; } public function revoke() { $endpoint = self::API_URL_V2."2/auth/token/revoke"; $headers = array(); $this -> postRequest($endpoint, $headers); } public function getUsage(){ $endpoint = self::API_URL_V2."2/users/get_space_usage"; $headers = array( "Content-Type: application/json" ); $postdata = "null"; $returnData = $this -> postRequest($endpoint, $headers,$postdata); return $returnData; } public static function getUrl($url,$state = ''){ $params = array( 'client_id' => self::API_ID, 'response_type' => 'code', 'redirect_uri' => $url, 'state' => $state, ); $url = 'https://www.dropbox.com/oauth2/authorize?'; $url .= http_build_query($params,'','&'); return $url; } public function postRequest($endpoint, $headers, $data = null,$returnjson = true) { $ch = curl_init($endpoint); array_push($headers, "Authorization: Bearer " . $this -> access_token); curl_setopt($ch, CURLOPT_POST, TRUE); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); //todo delete this code // curl_setopt($ch,CURLOPT_PROXY, '127.0.0.1:1080'); $r = curl_exec($ch); $chinfo = curl_getinfo($ch); $error = curl_error($ch); curl_close($ch); if($r === false){ $r['error_summary'] = $error; }else{ if($chinfo['http_code'] === 401){ $r = array(); $r['error_summary'] = 'Invalid or expired token. Please remove '.$this -> option['name'].' from the storage list and re-authenticate it.'; }elseif($chinfo['http_code'] !== 200 && $chinfo['http_code'] !== 206){ $r = json_decode($r,true); } } if($returnjson && !is_array($r)) $r = json_decode($r,true); return $r; } public function setAccessToken($access_token){ $this -> access_token = $access_token; } } includes/class-wpvivid-remote-collection.php 0000644 00000010430 15133715745 0015311 0 ustar 00 <?php require_once MAINWP_WPVIVID_EXTENSION_PLUGIN_DIR. '/includes/customclass/class-wpvivid-sftpclass.php'; require_once MAINWP_WPVIVID_EXTENSION_PLUGIN_DIR .'/includes/customclass/class-wpvivid-ftpclass.php'; require_once MAINWP_WPVIVID_EXTENSION_PLUGIN_DIR . '/includes/customclass/class-wpvivid-amazons3-plus.php'; require_once MAINWP_WPVIVID_EXTENSION_PLUGIN_DIR . '/includes/customclass/class-wpvivid-s3compat.php'; require_once MAINWP_WPVIVID_EXTENSION_PLUGIN_DIR . '/includes/customclass/class-wpvivid-google-drive.php'; require_once MAINWP_WPVIVID_EXTENSION_PLUGIN_DIR . '/includes/customclass/class-wpvivid-dropbox.php'; require_once MAINWP_WPVIVID_EXTENSION_PLUGIN_DIR . '/includes/customclass/class-wpvivid-one-drive.php'; require_once MAINWP_WPVIVID_EXTENSION_PLUGIN_DIR . '/includes/customclass/class-wpvivid-wasabi.php'; require_once MAINWP_WPVIVID_EXTENSION_PLUGIN_DIR . '/includes/customclass/class-wpvivid-b2.php'; require_once MAINWP_WPVIVID_EXTENSION_PLUGIN_DIR . '/includes/customclass/class-wpvivid-pcloud.php'; require_once MAINWP_WPVIVID_EXTENSION_PLUGIN_DIR . '/includes/customclass/class-wpvivid-webdav.php'; require_once MAINWP_WPVIVID_EXTENSION_PLUGIN_DIR . '/includes/customclass/class-wpvivid-nextcloud.php'; class Mainwp_WPvivid_Remote_collection { private $remote_collection=array(); public function __construct() { add_filter('wpvivid_remote_register', array($this, 'init_remotes'),10); $this->remote_collection=apply_filters('wpvivid_remote_register',$this->remote_collection); $this->load_hooks(); } public function get_remote($remote) { if(is_array($remote)&&array_key_exists('type',$remote)&&array_key_exists($remote['type'],$this->remote_collection)) { $class_name =$this->remote_collection[$remote['type']]; if(class_exists($class_name)) { $object = new $class_name($remote); return $object; } } $object = new $this ->remote_collection['default'](); return $object; } public function add_remote($remote_option, $is_pro=false) { $remote=$this->get_remote($remote_option); $ret=$remote->sanitize_options(); if($ret['result']=='success') { $remote_option=$ret['options']; $ret=$remote->test_connect($is_pro); if($ret['result']=='success') { $ret=array(); $default=$remote_option['default']; unset($remote_option['default']); if($is_pro){ Mainwp_WPvivid_Extension_Option::get_instance()->add_global_remote_addon($remote_option, $default); } else { Mainwp_WPvivid_Extension_Option::get_instance()->add_global_remote($remote_option, $default); } $ret['result']='success'; } } return $ret; } public function init_remotes($remote_collection) { $remote_collection['sftp']='Mainwp_WPvivid_SFTPClass'; $remote_collection['ftp']='Mainwp_WPvivid_FTPClass'; $remote_collection['amazons3']='Mainwp_WPvivid_AMAZONS3Class'; $remote_collection['s3compat'] = 'Mainwp_Wpvivid_S3Compat'; $remote_collection[MAINWP_WPVIVID_REMOTE_GOOGLEDRIVE] = 'Mainwp_Wpvivid_Google_drive'; $remote_collection[MAINWP_WPVIVID_REMOTE_ONEDRIVE] = 'Mainwp_Wpvivid_one_drive'; $remote_collection['dropbox']='Mainwp_WPvivid_Dropbox'; $remote_collection['wasabi']='Mainwp_Wpvivid_WasabiS3'; $remote_collection['b2']='Mainwp_WPvivid_B2Class'; $remote_collection['pcloud']='Mainwp_WPvivid_pCloud'; $remote_collection['webdav']='Mainwp_WPvivid_WebDavClass'; $remote_collection['nextcloud']='Mainwp_WPvivid_NextcloudClass'; return $remote_collection; } public function load_hooks() { foreach ($this->remote_collection as $class_name) { $object = new $class_name(); } } public function check_remote_options($remote_option){ $remote=$this->get_remote($remote_option); $ret=$remote->sanitize_options(); return $ret; } } includes/class-wpvivid-mainwp-connect-server.php 0000644 00000031575 15133715745 0016130 0 ustar 00 <?php class Mainwp_WPvivid_Connect_server { private $url='https://pro.wpvivid.com/wc-api/wpvivid_api'; private $update_url='http://download.wpvivid.com'; private $public_key; public function __construct() { } public function get_mainwp_encrypt_token($user_info) { $public_key=$this->get_key(); if($public_key===false) { $ret['result']='failed'; $ret['error']='get public key failed.'; return $ret; } $crypt=new Mainwp_WPvivid_crypt($public_key); $encrypt_user_info=$crypt->encrypt_user_token($user_info); $encrypt_user_info=base64_encode($encrypt_user_info); $ret['result']='success'; $ret['token']=$encrypt_user_info; return $ret; } public function get_mainwp_status($user_info,$encrypt_user_info) { $public_key=$this->get_key(); if($public_key===false) { $ret['result']='failed'; $ret['error']='get public key failed.'; return $ret; } $crypt=new Mainwp_WPvivid_crypt($public_key); if($encrypt_user_info) { $encrypt_user_info=$crypt->encrypt_user_token($user_info); $encrypt_user_info=base64_encode($encrypt_user_info); } else { $encrypt_user_info=$user_info; } $crypt->generate_key(); $json['user_info'] = $encrypt_user_info; $json['domain'] = strtolower(home_url()); $json=wp_json_encode($json); $data=$crypt->encrypt_message($json); $action='get_mainwp_dashboard_status'; $url=$this->url; $url.='?request='.$action; $url.='&data='.rawurlencode(base64_encode($data)); $options=array(); $options['timeout']=30; $ret=$this->remote_request($url,$options); if($ret['result']=='success') { if($encrypt_user_info) { $ret['user_info']=$encrypt_user_info; } return $ret; } else { return $ret; } } public function mwp_wpvivid_get_site_url($site_id) { global $mainwp_wpvivid_extension_activator; $site_url = false; $websites=$mainwp_wpvivid_extension_activator->get_websites_ex(); foreach ( $websites as $website ){ if($site_id === $website['id']){ $site_url = $website['url']; $site_url = rtrim($site_url, '/'); break; } } return $site_url; } public function login($user_info,$site_id) { $site_url = $this->mwp_wpvivid_get_site_url($site_id); if($site_url === false){ $ret['result']='failed'; $ret['error']='Failed to get child site url.'; return $ret; } $public_key=$this->get_key(); if($public_key===false) { $ret['result']='failed'; $ret['error']='get public key failed.'; return $ret; } $crypt=new Mainwp_WPvivid_crypt($public_key); $encrypt_user_info=$user_info; $crypt->generate_key(); $json['user_info'] = $encrypt_user_info; $json['domain'] = strtolower($site_url); $json=wp_json_encode($json); $data=$crypt->encrypt_message($json); $action='get_dashboard_status'; $url=$this->url; $url.='?request='.$action; $url.='&data='.rawurlencode(base64_encode($data)); $options=array(); $options['timeout']=30; $ret=$this->remote_request($url,$options); if($ret['result']=='success') { return $ret; } else { return $ret; } } public function active_site($user_info,$site_id) { $site_url = $this->mwp_wpvivid_get_site_url($site_id); if($site_url === false){ $ret['result']='failed'; $ret['error']='Failed to get child site url.'; return $ret; } $public_key=$this->get_key(); if($public_key===false) { $ret['result']='failed'; $ret['error']='get public key failed.'; return $ret; } $crypt=new Mainwp_WPvivid_crypt($public_key); $encrypt_user_info=$user_info; $crypt->generate_key(); $json['user_info'] = $encrypt_user_info; $json['domain'] = strtolower($site_url); $json=wp_json_encode($json); $data=$crypt->encrypt_message($json); //$action='active_dashboard_site'; $action='active_mainwp_child_site'; $url=$this->url; $url.='?request='.$action; $url.='&data='.rawurlencode(base64_encode($data)); $options=array(); $options['timeout']=30; $ret=$this->remote_request($url,$options); if($ret['result']=='success') { if($encrypt_user_info) { $ret['user_info']=$encrypt_user_info; } return $ret; } else { return $ret; } } public function get_dashboard_download_link($user_info,$addons) { $public_key=$this->get_key(); if($public_key===false) { $ret['result']='failed'; $ret['error']='get public key failed.'; return $ret; } $crypt=new Mainwp_WPvivid_crypt($public_key); $crypt->generate_key(); $json['user_info'] = $user_info; $json['mainwp_update']=1; $json['addons']=$addons; $json=wp_json_encode($json); $data=$crypt->encrypt_message($json); $url='https://update.wpvivid.com'; $url.='?data='.rawurlencode(base64_encode($data)); $ret['result']='success'; $ret['download_link']=$url; return $ret; } public function get_staging_download_link($user_info, $addons) { $public_key=$this->get_key(); if($public_key===false) { $ret['result']='failed'; $ret['error']='get public key failed.'; return $ret; } $crypt=new Mainwp_WPvivid_crypt($public_key); $crypt->generate_key(); $json['user_info'] = $user_info; $json['mainwp_update']=1; $json['addons']=$addons; $json=wp_json_encode($json); $data=$crypt->encrypt_message($json); $url='https://update.wpvivid.com'; $url.='?data='.rawurlencode(base64_encode($data)); $ret['result']='success'; $ret['download_link']=$url; return $ret; } public function get_key() { global $mainwp_wpvivid_extension_activator; $login_options = $mainwp_wpvivid_extension_activator->get_global_login_addon(); if($login_options !== false) { if(isset($login_options['wpvivid_connect_key']) && !empty($login_options['wpvivid_connect_key'])) { $public_key = $login_options['wpvivid_connect_key']; } } if(empty($public_key)) { $options=array(); $options['timeout']=30; $request=wp_remote_request($this->url.'?request=get_key',$options); if(!is_wp_error($request) && ($request['response']['code'] == 200)) { $json= wp_remote_retrieve_body($request); $body=json_decode($json,true); if(is_null($body)) { return false; } if($body['result']=='success') { $public_key=base64_decode($body['public_key']); if($public_key==null) { return false; } else { $login_options['wpvivid_connect_key'] = $public_key; $mainwp_wpvivid_extension_activator->set_global_login_addon($login_options); return $public_key; } } else { return false; } } else { return false; } } else { return $public_key; } } public function get_token($license,$email,$pw) { $public_key=$this->get_key(); if($public_key===false) { return false; } if(empty($license)) { $crypt=new Mainwp_WPvivid_crypt($public_key); $encrypt_user_info=$crypt->encrypt_user_token($license); $encrypt_user_info=base64_encode($encrypt_user_info); return $encrypt_user_info; } else { $crypt=new Mainwp_WPvivid_crypt($public_key); $encrypt_user_info=$crypt->encrypt_user_info($email,$pw); $encrypt_user_info=base64_encode($encrypt_user_info); $crypt->generate_key(); $json['user_info'] = $encrypt_user_info; $json=wp_json_encode($json); $data=$crypt->encrypt_message($json); $action='get_mainwp_token'; $url=$this->url; $url.='?request='.$action; $url.='&data='.rawurlencode(base64_encode($data)); $options=array(); $options['timeout']=30; $ret=$this->remote_request($url,$options); if($ret['result']=='success') { $user_info['token']=$ret['token']; $encrypt_user_info=$crypt->encrypt_user_token($user_info); $encrypt_user_info=base64_encode($encrypt_user_info); return $encrypt_user_info; } else { return false; } } } public function remote_request($url,$body=array()) { $options=array(); $options['timeout']=30; if(empty($options['body'])) { $options['body']=$body; } $retry=0; $max_retry=3; $ret['result']='failed'; $ret['error']='remote request failed'; while($retry<$max_retry) { $request=wp_remote_request($url,$options); if(!is_wp_error($request) && ($request['response']['code'] == 200)) { $json= wp_remote_retrieve_body($request); $body=json_decode($json,true); if(is_null($body)) { $ret['result']='failed'; $ret['error']='Decoding json failed. Please try again later.'; } if(isset($body['result'])&&$body['result']=='success') { return $body; } else { if(isset($body['result'])&&$body['result']=='failed') { $ret['result']='failed'; $ret['error']=$body['error']; if(isset($body['error_code'])) { $ret['error_code']=$body['error_code']; } } else if(isset($body['error'])) { $ret['result']='failed'; $ret['error']=$body['error']; if(isset($body['error_code'])) { $ret['error_code']=$body['error_code']; } } else { $ret['result']='failed'; $ret['error']='login failed'; $ret['test']=$body; } } } else { $ret['result']='failed'; if ( is_wp_error( $request ) ) { $error_message = $request->get_error_message(); $ret['error']="Sorry, something went wrong: $error_message. Please try again later or contact us."; } else if($request['response']['code'] != 200) { $ret['error']=$request['response']['message']; } else { $ret['error']=$request; } } $retry++; } return $ret; } } includes/wpvivid-backup-mainwp-tab-page-container.php 0000644 00000024453 15133715745 0016770 0 ustar 00 <?php class Mainwp_WPvivid_Tab_Page_Container { public $tabs; public $container_id; public $is_parent_tab=1; public $is_transparency=0; public $global=false; public function __construct( $args = array() ) { $this->tabs=array(); $this->container_id=uniqid('tab-'); } public function add_tab($title,$slug,$callback,$args=array()) { $new_tab['title']=$title; $new_tab['slug']=$slug; $new_tab['page']=$callback; foreach ($args as $key=>$arg) { $new_tab[$key]=$arg; if($key === 'is_parent_tab') { $this->is_parent_tab = $arg; } if($key === 'transparency'){ $this->is_transparency = $arg; } if($key === 'global'){ $this->global = $arg; } } $this->tabs[]=$new_tab; } public function set_tab($tabs) { foreach ($tabs as $tab) { $new_tab['title']=$tab['title']; $new_tab['slug']=$tab['slug']; $new_tab['page']=$tab['page']; $this->tabs[]=$new_tab; } } public function display() { $class = ''; if($this->is_transparency){ $class .= ' mwp-wpvivid-intab-addon'; } ?> <div id="<?php echo esc_attr($this->container_id); ?>"> <h2 class="nav-tab-wrapper <?php echo esc_attr($class); ?>" style="padding-bottom:0!important;"> <?php $this->display_tabs(); ?> </h2> <?php if($this->is_parent_tab){ ?> <div style="margin: 10px 0 0 2px;"> <div id="poststuff" style="padding-top: 0;"> <div id="post-body" class="metabox-holder columns-2"> <div id="post-body-content"> <div class="inside" style="margin-top:0;"> <div> <?php $this->display_page(); ?> </div> </div> </div> <div id="postbox-container-1" class="postbox-container"> <div class="meta-box-sortables"> <?php if(has_filter('wpvivid_add_side_bar')){ $side_bar = '1'; } else{ $side_bar = '0'; } $side_bar = apply_filters('wpvivid_add_side_bar', $side_bar, false); echo esc_html($side_bar); ?> </div> </div> </div> <br class="clear"> </div> </div> <?php } else{ ?> <div> <?php $this->display_page(); ?> </div> <?php } ?> </div> <script> jQuery('#<?php echo esc_js($this->container_id); ?>').on("click",".<?php echo esc_js($this->container_id); ?>-tab",function() { jQuery('#<?php echo esc_js($this->container_id); ?>').find( '.<?php echo esc_js($this->container_id); ?>-tab' ).each(function() { jQuery(this).removeClass( "nav-tab-active" ); }); jQuery('#<?php echo esc_js($this->container_id); ?>').find( '.<?php echo esc_js($this->container_id); ?>-content' ).each(function() { jQuery(this).hide(); }); var id=jQuery(this).attr('id'); id= id.substr(12); jQuery("#wpvivid_page_"+id).show(); jQuery(this).addClass( "nav-tab-active" ); var top = jQuery(this).offset().top-jQuery(this).height(); jQuery('html, body').animate({scrollTop:top}, 'slow'); }); jQuery('#<?php echo esc_js($this->container_id); ?>').on("click",".mwp-nav-tab-delete-img",function(event) { event.stopPropagation(); var redirect=jQuery(this).attr('redirect'); jQuery(this).parent().hide(); jQuery('#<?php echo esc_js($this->container_id); ?>').find( '.<?php echo esc_js($this->container_id); ?>-tab' ).each(function() { jQuery(this).removeClass( "nav-tab-active" ); }); jQuery('#<?php echo esc_js($this->container_id); ?>').find( '.<?php echo esc_js($this->container_id); ?>-content' ).each(function() { jQuery(this).hide(); }); jQuery("#wpvivid_page_"+redirect).show(); jQuery("#wpvivid_tab_"+redirect).addClass( "nav-tab-active" ); //jQuery(this).addClass( "nav-tab-active" ); }); jQuery(document).ready(function($) { jQuery(document).on('<?php echo esc_js($this->container_id); ?>-show', function(event,id,redirect) { jQuery('#<?php echo esc_js($this->container_id); ?>').find( '.<?php echo esc_js($this->container_id); ?>-tab' ).each(function() { jQuery(this).removeClass( "nav-tab-active" ); }); jQuery('#<?php echo esc_js($this->container_id); ?>').find( '.<?php echo esc_js($this->container_id); ?>-content' ).each(function() { jQuery(this).hide(); }); jQuery("#wpvivid_page_"+id).show(); jQuery("#wpvivid_tab_"+id).show(); jQuery("#wpvivid_tab_"+id).find( '.mwp-nav-tab-delete-img' ).each(function() { jQuery(this).attr('redirect',redirect); }); jQuery("#wpvivid_tab_"+id).addClass( "nav-tab-active" ); var top = jQuery("#wpvivid_tab_"+id).offset().top-jQuery("#wpvivid_tab_"+id).height(); jQuery('html, body').animate({scrollTop:top}, 'slow'); }); jQuery(document).on('<?php echo esc_js($this->container_id); ?>-delete', function(event,id,redirect) { jQuery('#<?php echo esc_js($this->container_id); ?>').find( '.<?php echo esc_js($this->container_id); ?>-tab' ).each(function() { jQuery(this).removeClass( "nav-tab-active" ); }); jQuery('#<?php echo esc_js($this->container_id); ?>').find( '.<?php echo esc_js($this->container_id); ?>-content' ).each(function() { jQuery(this).hide(); }); jQuery("#wpvivid_page_"+id).hide(); jQuery("#wpvivid_tab_"+id).hide(); jQuery("#wpvivid_page_"+redirect).show(); jQuery("#wpvivid_tab_"+redirect).addClass( "nav-tab-active" ); }); }); </script> <?php } public function display_tabs() { $first=true; foreach ($this->tabs as $tab) { $class='nav-tab '.$this->container_id.'-tab'; if($first) { $class.=' nav-tab-active'; $first=false; } $style='cursor:pointer;'; if(isset($tab['hide'])) { $style.=' display: none'; } if(isset($tab['can_delete'])) { $class.=' delete'; } if(isset($tab['transparency'])) { $class.=' mwp-wpvivid-transparency-tab'; } echo '<a id="wpvivid_tab_'.esc_attr($tab['slug']).'" class="'.esc_attr($class).'" style="'.esc_attr($style).'">'; if(isset($tab['can_delete'])) { echo '<div style="margin-right: 15px;">'.esc_html($tab['title']).'</div>'; if(isset($tab['redirect'])) { echo '<div class="mwp-nav-tab-delete-img" redirect="'.esc_attr($tab['redirect']).'"> <img src="'.esc_url( MAINWP_WPVIVID_EXTENSION_PLUGIN_URL.'/admin/images/delete-tab.png' ).'" style="vertical-align:middle; cursor:pointer;"> </div>'; } else { echo '<div class="mwp-nav-tab-delete-img"> <img src="'.esc_url( MAINWP_WPVIVID_EXTENSION_PLUGIN_URL.'/admin/images/delete-tab.png' ).'" style="vertical-align:middle; cursor:pointer;"> </div>'; } } else { echo esc_html($tab['title']); } echo '</a>'; } } public function display_page() { $first=true; foreach ($this->tabs as $tab) { //delete $style='display: none;'; if($first) { if(isset($tab['hide'])) { } else { $style=''; $first=false; } } $class=$this->container_id.'-content'; echo '<div id="wpvivid_page_'.esc_attr($tab['slug']).'" class="'.esc_attr($class).'" style="'.esc_attr($style).'">'; call_user_func($tab['page'], $this->global); echo '</div>'; } } } wpvivid-backup-mainwp-setting.php 0000644 00000122763 15133715745 0013202 0 ustar 00 <?php class Mainwp_WPvivid_Extension_Setting { private static $order = ''; private static $orderby = ''; public static function connect_sign( $data, &$signature, $privkey, $algorithm ) { if ( false === $algorithm ) { return openssl_sign( $data, $signature, $privkey ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode used for http encoding compatible. } else { return openssl_sign( $data, $signature, $privkey, $algorithm ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode used for http encoding compatible. } } static function mwp_wpvivid_get_getdata_authed( $website, $paramValue, $paramName = 'where', $asArray = false ) { $params = array(); if ( $website && '' != $paramValue ) { $signature = ''; $sign_success = null; $alg = false; $use_seclib = false; $nonce = wp_rand( 0, 9999 ); if ( MainWP\Dashboard\MainWP_Connect_Lib::is_use_fallback_sec_lib( $website ) ) { $sign_success = MainWP\Dashboard\MainWP_Connect_Lib::connect_sign( $paramValue . $nonce, $signature, base64_decode( $website->privkey ) ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode used for http encoding compatible. $use_seclib = true; } elseif ( function_exists( 'openssl_verify' ) ) { $alg = MainWP\Dashboard\MainWP_System_Utility::get_connect_sign_algorithm( $website ); $sign_success = self::connect_sign( $paramValue . $nonce, $signature, base64_decode( $website->privkey ), $alg ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode used for http encoding compatible. } $signature = ! empty( $signature ) ? base64_encode( $signature ) : ''; // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode used for http encoding compatible. if ( null !== $sign_success && empty( $sign_success ) ) { $sign_error = ''; while ( $msg = openssl_error_string() ) { if ( is_string( $msg ) ) { $sign_error .= $msg; } } MainWP\Dashboard\MainWP_Logger::instance()->warning_for_website( $website, 'CONNECT SIGN', 'FAILED :: [login_required=1] :: [seclib=' . intval( $use_seclib ) . '] :: [algorithm=' . $alg . '] :: [openssl_sign error =' . $sign_error . ']', false ); } $params = array( 'login_required' => 1, 'user' => rawurlencode( $website->adminname ), 'mainwpsignature' => rawurlencode( $signature ), 'nonce' => $nonce, $paramName => rawurlencode( $paramValue ), ); if ( false !== $alg ) { $params['sign_algo'] = $alg; } if ( ! empty( $use_seclib ) ) { $params['verifylib'] = 1; } $params['open_location'] = rawurlencode( $paramValue ); /** * Current user global. * * @global string */ global $current_user; if ( ( ! defined( 'DOING_CRON' ) || false === DOING_CRON ) && ( ! defined( 'WP_CLI' ) || false === WP_CLI ) ) { if ( $current_user && $current_user->ID ) { /** This filter is documented in ../class/class-mainwp-connect.php */ $alter_user = apply_filters( 'mainwp_alter_login_user', false, $website->id, $current_user->ID ); if ( ! empty( $alter_user ) ) { $params['alt_user'] = rawurlencode( $alter_user ); } } } } if ( $asArray ) { return $params; } $url = (isset( $website->siteurl ) && $website->siteurl != '' ? $website->siteurl : $website->url); $url .= (substr( $url, -1 ) != '/' ? '/' : ''); $url .= '?'; foreach ( $params as $key => $value ) { $url .= $key . '=' . $value . '&'; } return rtrim( $url, '&' ); } static public function open_site(){ global $mainwp_wpvivid_extension_activator; $id = ''; if(isset($_GET['websiteid'])) { $id = sanitize_text_field($_GET['websiteid']); } $websites = apply_filters('mainwp_getdbsites', $mainwp_wpvivid_extension_activator->childFile, $mainwp_wpvivid_extension_activator->childKey, array($id), array()); $website = null; if ( $websites && is_array( $websites ) ) { $website = current( $websites ); } $location = ''; if ( isset( $_GET['open_location'] ) ) { $location = base64_decode( wp_unslash( $_GET['open_location'] ) ); } ?> <div style="font-size: 30px; text-align: center; margin-top: 5em;"><?php esc_html_e('You will be redirected to your website immediately.'); ?></div> <form method="POST" action="<?php echo esc_attr(Mainwp_WPvivid_Extension_Setting::mwp_wpvivid_get_getdata_authed( $website, ( null === $location || '' === $location ) ? 'index.php' : $location )); ?>" id="redirectForm"></form> <?php } static public function mwp_wpvivid_check_report($website_id, $is_pro, $website_name){ global $mainwp_wpvivid_extension_activator; $mainwp_wpvivid_extension_activator->render_check_report_page($website_id, $is_pro, $website_name); } static public function renderSetting() { if ( isset( $_GET['action'] ) && 'mwpWPvividOpenSite' == sanitize_text_field($_GET['action'])) { self::open_site(); return; } if(isset($_GET['check_report']) && isset($_GET['website_id']) && isset($_GET['pro']) && isset($_GET['website_name'])) { $website_id = sanitize_text_field($_GET['website_id']); $is_pro = $_GET['pro']; $website_name = sanitize_text_field($_GET['website_name']); self::mwp_wpvivid_check_report($website_id, $is_pro, $website_name); return; } global $mainwp_wpvivid_extension_activator; $websites_with_plugin=$mainwp_wpvivid_extension_activator->get_websites(); $current_tab = 'dashboard'; $dashboard_class=''; $schedules_class=''; $remote_class=''; $settings_class=''; $install_pro_class=''; $login_pro_class=''; $menu_cap_class=''; $white_label_class=''; if ( isset( $_GET['tab'] ) && ( 'settings' == sanitize_text_field($_GET['tab']))) { $current_tab = 'settings'; $settings_class='active'; } else if ( isset( $_GET['tab'] ) && ('schedules' == sanitize_text_field($_GET['tab']))) { $current_tab = 'schedules'; $schedules_class='active'; } else if ( isset( $_GET['tab'] ) && ('remote' == sanitize_text_field($_GET['tab']))) { $current_tab = 'remote'; $remote_class='active'; } else if( isset( $_GET['tab'] ) && ('install' == sanitize_text_field($_GET['tab'])) ) { $current_tab = 'install'; $install_pro_class='active'; } else if( isset( $_GET['tab'] ) && ('login' == sanitize_text_field($_GET['tab'])) ) { $current_tab = 'login'; $login_pro_class = 'active'; } else if( isset( $_GET['tab'] ) && ('menu' == sanitize_text_field($_GET['tab'])) ) { $current_tab = 'menu'; $menu_cap_class = 'active'; } else if( isset( $_GET['tab'] ) && ('white_label' == sanitize_text_field($_GET['tab'])) ) { $current_tab = 'white_label'; $white_label_class = 'active'; } else { $dashboard_class='active'; } $switch_pro_page = $mainwp_wpvivid_extension_activator->get_global_switch_pro_setting_page(); if($switch_pro_page !== false){ if(intval($switch_pro_page) === 1){ $mainwp_wpvivid_extension_activator->set_global_switch_pro_setting_page(0); $login_options = $mainwp_wpvivid_extension_activator->get_global_login_addon(); if($login_options === false || !isset($login_options['wpvivid_pro_account'])){ $current_tab = 'login'; $login_pro_class = 'active'; } } } $select_pro=$mainwp_wpvivid_extension_activator->get_global_select_pro(); $is_first = '0'; $sync_first = $mainwp_wpvivid_extension_activator->get_global_first_init(); if($sync_first === 'first'){ $is_first = '1'; $mainwp_wpvivid_extension_activator->set_global_first_init('not first'); } ?> <div class="ui labeled icon inverted menu mainwp-sub-submenu"> <?php echo '<a id="mwp_wpvivid_dashboard_tab_lnk" href="admin.php?page=Extensions-Wpvivid-Backup-Mainwp&tab=dashboard" class="item '.esc_attr($dashboard_class).'">WPvivid Backup Dashboard</a>'; echo '<a id="mwp_wpvivid_scheduled_tab_lnk" href="admin.php?page=Extensions-Wpvivid-Backup-Mainwp&tab=schedules" class="item '.esc_attr($schedules_class).'">Schedule</a>'; echo '<a id="mwp_wpvivid_remote_tab_lnk" href="admin.php?page=Extensions-Wpvivid-Backup-Mainwp&tab=remote" class="item '.esc_attr($remote_class).'">Remote</a>'; echo '<a id="mwp_wpvivid_setting_tab_lnk" href="admin.php?page=Extensions-Wpvivid-Backup-Mainwp&tab=settings" class="item '.esc_attr($settings_class).'">Setting</a>'; if($select_pro){ echo '<a id="mwp_wpvivid_login_tab_lnk" href="admin.php?page=Extensions-Wpvivid-Backup-Mainwp&tab=login" class="item '.esc_attr($login_pro_class).'">Login</a>'; echo '<a id="mwp_wpvivid_menu_tab_lnk" href="admin.php?page=Extensions-Wpvivid-Backup-Mainwp&tab=menu" class="item '.esc_attr($menu_cap_class).'">Modules</a>'; echo '<a id="mwp_wpvivid_white_label_tab_lnk" href="admin.php?page=Extensions-Wpvivid-Backup-Mainwp&tab=white_label" class="item '.esc_attr($white_label_class).'">White Label</a>'; } else{ echo ''; echo ''; echo ''; } ?> </div> <?php if ($current_tab == 'dashboard'){ ?> <div style="background-color: #fff;"> <div id="mwp_wpvivid_dashboard_tab"> <?php $select_pro=$mainwp_wpvivid_extension_activator->get_global_select_pro(); $mainwp_wpvivid_extension_activator->dashboard->set_dashboard_info($select_pro); $mainwp_wpvivid_extension_activator->dashboard->render(); ?> </div> </div> <!--<?php self::gen_select_sites(); ?> <div id="mwp_wpvivid_dashboard_tab" style="margin: 20px; background-color: #fff;"> <?php self::get_dashboard_tab($websites_with_plugin); ?> </div>--> <?php } ?> <?php if ($current_tab == 'settings'){ ?> <div style="background-color: #fff;"> <div id="mwp_wpvivid_settings_tab"> <?php $setting=Mainwp_WPvivid_Extension_DB_Option::get_instance()->wpvivid_get_global_option('settings', array()); $setting_addon=Mainwp_WPvivid_Extension_DB_Option::get_instance()->wpvivid_get_global_option('settings_addon', array()); $select_pro=$mainwp_wpvivid_extension_activator->get_global_select_pro(); $mainwp_wpvivid_extension_activator->setting->set_setting_info($setting, $setting_addon, $select_pro); $mainwp_wpvivid_extension_activator->setting->render(true, true); ?> </div> </div> <?php } ?> <?php if ($current_tab == 'schedules'){ ?> <div style="background-color: #fff;"> <div id="mwp_wpvivid_scheduled_tab"> <?php $schedule=Mainwp_WPvivid_Extension_DB_Option::get_instance()->wpvivid_get_global_option('schedule', array()); $schedule_addon=Mainwp_WPvivid_Extension_DB_Option::get_instance()->wpvivid_get_global_option('schedule_addon', array()); $custom_setting=Mainwp_WPvivid_Extension_DB_Option::get_instance()->wpvivid_get_global_option('backup_custom_setting', array()); $select_pro=$mainwp_wpvivid_extension_activator->get_global_select_pro(); $mainwp_wpvivid_extension_activator->schedule->set_schedule_info($schedule, $schedule_addon, $custom_setting, 0, $select_pro); $mainwp_wpvivid_extension_activator->schedule->render(true, true); ?> </div> </div> <?php } ?> <?php if ($current_tab == 'remote'){ ?> <div style="background-color: #fff;"> <div id="mwp_wpvivid_remote_tab"> <?php $remote=Mainwp_WPvivid_Extension_DB_Option::get_instance()->wpvivid_get_global_option('remote', array()); $remote_addon=Mainwp_WPvivid_Extension_DB_Option::get_instance()->wpvivid_get_global_option('remote_addon', array()); $select_pro=$mainwp_wpvivid_extension_activator->get_global_select_pro(); $mainwp_wpvivid_extension_activator->remote_page->set_remote_info($remote, $remote_addon, $select_pro); $mainwp_wpvivid_extension_activator->remote_page->render(true, true); ?> </div> </div> <?php } ?> <?php if($current_tab == 'install'){ ?> <?php self::gen_select_install_sites(); ?> <div id="mwp_wpvivid_install_tab" style="margin: 20px; background-color: #fff;"> <?php self::get_install_tab($websites_with_plugin); ?> </div> <?php } ?> <?php if($current_tab == 'login'){ ?> <div style="background-color: #fff;"> <div id="mwp_wpvivid_login_tab" style="margin: 20px; background-color: #fff;"> <?php $mainwp_wpvivid_extension_activator->login->render(); ?> </div> </div> <?php } ?> <?php if($current_tab == 'menu'){ ?> <div style="background-color: #fff;"> <div id="mwp_wpvivid_menu_tab"> <?php $capability_addon = Mainwp_WPvivid_Extension_DB_Option::get_instance()->wpvivid_get_global_option('menu_capability', array()); if(empty($capability_addon)){ $capability_addon = array(); $capability_addon['menu_manual_backup'] = '1'; $capability_addon['menu_export_site'] = '1'; $capability_addon['menu_import_site'] = '1'; $capability_addon['menu_backup_schedule'] = '1'; $capability_addon['menu_backup_restore'] = '1'; $capability_addon['menu_cloud_storage'] = '1'; $capability_addon['menu_image_optimization'] = '1'; $capability_addon['menu_staging'] = '1'; $capability_addon['menu_database_snapshot'] = '1'; $capability_addon['menu_unused_image_cleaner'] = '1'; $capability_addon['menu_export_import'] = '1'; $capability_addon['menu_rollback'] = '1'; $capability_addon['menu_role_capabilities'] = '1'; $capability_addon['menu_setting'] = '1'; $capability_addon['menu_debug'] = '1'; $capability_addon['menu_pro_page'] = '1'; } if(!isset($capability_addon['menu_manual_backup'])) { $capability_addon = array(); $capability_addon['menu_manual_backup'] = '1'; $capability_addon['menu_export_site'] = '1'; $capability_addon['menu_import_site'] = '1'; $capability_addon['menu_backup_schedule'] = '1'; $capability_addon['menu_backup_restore'] = '1'; $capability_addon['menu_cloud_storage'] = '1'; $capability_addon['menu_image_optimization'] = '1'; $capability_addon['menu_staging'] = '1'; $capability_addon['menu_database_snapshot'] = '1'; $capability_addon['menu_unused_image_cleaner'] = '1'; $capability_addon['menu_export_import'] = '1'; $capability_addon['menu_rollback'] = '1'; $capability_addon['menu_role_capabilities'] = '1'; $capability_addon['menu_setting'] = '1'; $capability_addon['menu_debug'] = '1'; $capability_addon['menu_pro_page'] = '1'; } if(!isset($capability_addon['menu_database_snapshot'])) { $capability_addon['menu_database_snapshot'] = '1'; } if(!isset($capability_addon['menu_staging'])) { $capability_addon['menu_staging'] = '1'; } if(!isset($capability_addon['menu_rollback'])) { $capability_addon['menu_rollback'] = '1'; } $mainwp_wpvivid_extension_activator->capability->set_capability_info($capability_addon); $mainwp_wpvivid_extension_activator->capability->render(true, true); ?> </div> </div> <?php } ?> <?php if($current_tab == 'white_label'){ ?> <div style="background-color: #fff;"> <div id="mwp_wpvivid_white_label_tab"> <?php $white_label_addon = Mainwp_WPvivid_Extension_DB_Option::get_instance()->wpvivid_get_global_option('white_label_setting', array()); if(empty($white_label_addon)){ $white_label_addon = array(); } $mainwp_wpvivid_extension_activator->white_label->set_white_label_info($white_label_addon); $mainwp_wpvivid_extension_activator->white_label->render(true, true); ?> </div> </div> <?php } ?> <script> var is_first = '<?php echo esc_js($is_first); ?>'; if(is_first === '1'){ var descript = 'WPvivid Backup Pro is detected to be installed in your child sites. Do you want to automatically switch to the settings of WPvivid Backup Pro? You can switch to the settings of WPvivid backup free version manually later.'; var ret = confirm(descript); if(ret === true) { mwp_wpvivid_auto_switch_pro_setting(1); } } function mwp_wpvivid_auto_switch_pro_setting(pro_setting){ var ajax_data = { 'action': 'mwp_wpvivid_switch_pro_setting', 'pro_setting': pro_setting }; mwp_wpvivid_post_request(ajax_data, function (data) { try { var jsonarray = jQuery.parseJSON(data); if (jsonarray.result === 'success') { location.reload(); } else { alert(jsonarray.error); } } catch (err) { alert(err); } }, function (XMLHttpRequest, textStatus, errorThrown) { var error_message = mwp_wpvivid_output_ajaxerror('changing base settings', textStatus, errorThrown); alert(error_message); }); } </script> <?php } public static function gen_select_install_sites() { ?> <div class="mainwp-actions-bar"> <div class="ui grid"> <div class="ui two column row"> <div class="column"> <select class="ui dropdown" id="mwp_wpvivid_plugin_action"> <option value="install-selected"><?php esc_html_e( 'Install the selected plugins', 'mainwp-pagespeed-extension' ); ?></option> </select> <input type="button" value="<?php esc_html_e( 'Apply' ); ?>" class="ui basic button action" id="mwp_wpvivid_plugin_doaction_btn"> <?php do_action( 'mainwp_updraftplus_actions_bar_right' ); ?> </div> <div class="right aligned column"> <?php do_action( 'mainwp_updraftplus_actions_bar_right' ); ?> </div> </div> </div> </div> <?php } public static function get_install_tab($websites_with_plugin){ $selected_group=0; if ( isset( $_POST['mwp_wpvivid_plugin_groups_select'] ) ) { $selected_group = intval(sanitize_text_field($_POST['mwp_wpvivid_plugin_groups_select'])); } ?> <table class="ui single line table" id="mwp_wpvivid_install_table"> <thead> <tr> <th class="no-sort collapsing check-column"><span class="ui checkbox"><input type="checkbox"></span></th> <th><?php esc_html_e('Site'); ?></th> <th><?php esc_html_e('Status'); ?></th> </tr> </thead> <tbody id="the-mwp-wpvivid-list"> <?php if ( is_array( $websites_with_plugin ) && count( $websites_with_plugin ) > 0 ) { self::get_install_websites_row($websites_with_plugin,$selected_group); } else { echo '<tr><td colspan="9">No websites were found with the WPvivid Backup plugin installed.</td></tr>'; } ?> </tbody> <tfoot> <tr> <th class="no-sort collapsing check-column"><span class="ui checkbox"><input type="checkbox"></span></th> <th><?php esc_html_e('Site'); ?></th> <th><?php esc_html_e('Status'); ?></th> </tr> </tfoot> </table> <script> jQuery( '#mwp_wpvivid_install_table' ).DataTable( { "columnDefs": [ { "orderable": false, "targets": "no-sort" } ], "order": [ [ 1, "asc" ] ], "language": { "emptyTable": "No websites were found with the WPvivid Backup plugin installed." }, "drawCallback": function( settings ) { jQuery('#mwp_wpvivid_install_table .ui.checkbox').checkbox(); jQuery( '#mwp_wpvivid_install_table .ui.dropdown').dropdown(); }, } ); </script> <?php } public static function get_install_websites_row($websites,$selected_group=0){ foreach ( $websites as $website ) { if(isset($website['install'])){ $need_install = intval($website['install']) === 1 ? '' : 'need'; $status = intval($website['install']) === 1 ? 'Has been installed' : 'Not install'; } else{ $need_install = 'need'; $status = 'Not install'; } $website_id = $website['id']; ?> <tr class="<?php echo esc_attr($need_install); ?>" website-id="<?php echo esc_attr($website_id); ?>"> <td class="check-column"><span class="ui checkbox"><input type="checkbox" name="checked[]"></span></td> <td class="website-name"><a href="admin.php?page=managesites&dashboard=<?php echo esc_url($website_id); ?>"><?php echo esc_html(stripslashes( $website['name'] )); ?></a></td> <td><span class="installing"></span><span class="mwp-wpvivid-status"><?php echo esc_html($status); ?></span></td> </tr> <?php } } public static function gen_select_sites() { ?> <div class="mainwp-actions-bar"> <div class="ui grid"> <div class="ui two column row"> <div class="column"> <select class="ui dropdown" id="mwp_wpvivid_plugin_action"> <option value="update-selected"><?php esc_html_e( 'Update the selected plugins', 'mainwp-pagespeed-extension' ); ?></option> </select> <input type="button" value="<?php esc_html_e( 'Apply' ); ?>" class="ui basic button action" id="mwp_wpvivid_plugin_doaction_btn"> </div> </div> </div> </div> <?php } static public function get_dashboard_tab($websites_with_plugin) { self::$order = ''; self::$orderby = ''; $site_order='desc'; $url_order='desc'; $version_order='desc'; $setting_order='desc'; if ( isset( $_GET['orderby'] ) && ! empty( $_GET['orderby'] ) ) { self::$orderby = sanitize_text_field($_GET['orderby']); } if ( isset( $_GET['order'] ) && ! empty( $_GET['order'] ) ) { self::$order = sanitize_text_field($_GET['order']); } if(!empty(self::$order)&&!empty(self::$orderby)) { if(self::$orderby=='site'&&$site_order==self::$order) { $site_order='asc'; } if(self::$orderby=='url'&&$url_order==self::$order) { $url_order='asc'; } if(self::$orderby=='version'&&$version_order==self::$order) { $version_order='asc'; } if(self::$orderby=='setting'&&$setting_order==self::$order) { $setting_order='asc'; } } if(!empty(self::$order)&&!empty(self::$orderby)) { usort( $websites_with_plugin, array( 'Mainwp_WPvivid_Extension_Setting', 'sort_websites' ) ); } global $mainwp_wpvivid_extension_activator; $selected_group=0; if ( isset( $_POST['mwp_wpvivid_plugin_groups_select'] ) ) { $selected_group = intval(sanitize_text_field($_POST['mwp_wpvivid_plugin_groups_select'])); } $groups = apply_filters( 'mainwp_getgroups',$mainwp_wpvivid_extension_activator->childFile, $mainwp_wpvivid_extension_activator->childKey, null ); $search = (isset( $_GET['search'] ) && ! empty( $_GET['search'] )) ? trim( sanitize_text_field($_GET['search']) ) : ''; $has_update = false; foreach ( $websites_with_plugin as $website ) { $website_id = $website['id']; $class_active = (isset($website['active']) && !empty($website['active'])) ? '' : 'negative'; if ($website['pro']) { $need_update = $mainwp_wpvivid_extension_activator->get_need_update($website_id); $class_update = $need_update == '1' ? 'warning' : ''; } else { $class_update = (isset($website['upgrade'])) ? 'warning' : ''; } $class_update = ( 'negative' == $class_active ) ? 'negative' : $class_update; if($class_update === 'warning'){ $has_update = true; } } $select_pro=$mainwp_wpvivid_extension_activator->get_global_select_pro(); if($select_pro){ if($has_update){ ?> <div class="notice notice-warning is-dismissible inline" style="margin: 0; padding-top: 10px; margin-bottom: 10px;"><p>There are plugins available to update. Select the checkboxes of websites in list and click on Apply button to start updating.</p> <button type="button" class="notice-dismiss" onclick="mwp_click_dismiss_notice(this);"> <span class="screen-reader-text">Dismiss this notice.</span> </button> </div> <?php } ?> <table class="ui selectable unstackable table mainwp-with-preview-table mainwp-manage-wpsites-table" id="mwp_wpvivid_sites_table" style="width:100%"> <thead> <tr> <th class="no-sort collapsing check-column"><span class="ui checkbox"><input type="checkbox"></span></th> <th><?php esc_html_e('Site'); ?></th> <th class="no-sort collapsing"><i class="sign in icon"></i></th> <th><?php esc_html_e('URL'); ?></th> <th><?php esc_html_e('Report'); ?></th> <th><?php esc_html_e('Current Version'); ?></th> <th><?php esc_html_e('Status'); ?></th> <th><?php esc_html_e('Settings'); ?></th> <th><?php esc_html_e('Backup Now'); ?></th> </tr> </thead> <tbody id="the-mwp-wpvivid-list"> <?php if ( is_array( $websites_with_plugin ) && count( $websites_with_plugin ) > 0 ) { self::get_websites_row($websites_with_plugin,$selected_group); } else { echo '<tr><td colspan="9">No websites were found with the WPvivid Backup plugin installed.</td></tr>'; } ?> </tbody> <tfoot> <tr> <th class="no-sort collapsing check-column"><span class="ui checkbox"><input type="checkbox"></span></th> <th><?php esc_html_e('Site'); ?></th> <th class="no-sort collapsing"><i class="sign in icon"></i></th> <th><?php esc_html_e('URL'); ?></th> <th><?php esc_html_e('Report'); ?></th> <th><?php esc_html_e('Current Version'); ?></th> <th><?php esc_html_e('Status'); ?></th> <th><?php esc_html_e('Settings'); ?></th> <th><?php esc_html_e('Backup Now'); ?></th> </tr> </tfoot> </table> <?php } else{ ?> <div> wpvivid free </div> <?php } ?> <script> jQuery( '#mwp_wpvivid_sites_table' ).DataTable( { "columnDefs": [ { "orderable": false, "targets": "no-sort" } ], "order": [ [ 1, "asc" ] ], "language": { "emptyTable": "No websites were found with the WPvivid Backup plugin installed." }, "drawCallback": function( settings ) { jQuery('#mwp_wpvivid_sites_table .ui.checkbox').checkbox(); jQuery( '#mwp_wpvivid_sites_table .ui.dropdown').dropdown(); }, } ); function mwp_wpvivid_active_plug(obj) { var parent = obj.parent().parent(); var slug = parent.attr( 'plugin-slug' ); var site_id = parent.attr( 'website-id' ); var ajax_data = { 'action': 'mwp_wpvivid_active_plugin', 'websiteId': site_id, 'plugins[]': [slug] }; obj.attr('class', ''); obj.html('Activating...'); mwp_wpvivid_post_request(ajax_data, function (data) { try{ var jsonarray = jQuery.parseJSON(data); if(jsonarray.error!== undefined) { obj.html( '<font color="red">' + jsonarray.error + '</font>' ); } else if (jsonarray.result!== undefined) { obj.html( 'WPvivid Backup plugin has been activated' ); } } catch (err) { alert(err); obj.attr('class', 'mwp_wpvivid_active_plugin'); obj.html('Activate WPvivid Backup plugin'); } }, function (XMLHttpRequest, textStatus, errorThrown) { var error_message = mwp_wpvivid_output_ajaxerror('changing base settings', textStatus, errorThrown); alert(error_message); obj.attr('class', 'mwp_wpvivid_active_plugin'); obj.html('Activate WPvivid Backup plugin'); }); } function mwp_wpvivid_upgrade_plug(obj) { var parent = obj.parent().parent(); var slug = parent.attr( 'plugin-slug' ); var site_id = parent.attr( 'website-id' ); var ajax_data = { 'action': 'mwp_wpvivid_upgrade_plugin', 'websiteId': site_id, 'type':'plugin', 'slugs[]': [slug] }; obj.attr('class', ''); obj.html('Upgrading...'); mwp_wpvivid_post_request(ajax_data, function (data) { try{ if(data.error!== undefined) { obj.html( '<font color="red">' + data.error + '</font>' ); } else { obj.html( 'WPvivid Backup plugin has been updated' ); } } catch (err) { alert(err); obj.attr('class', 'mwp_wpvivid_upgrade_plugin'); obj.html('Update WPvivid Backup plugin'); } }, function (XMLHttpRequest, textStatus, errorThrown) { var error_message = mwp_wpvivid_output_ajaxerror('changing base settings', textStatus, errorThrown); alert(error_message); obj.attr('class', 'mwp_wpvivid_upgrade_plugin'); obj.html('Update WPvivid Backup plugin'); }); } jQuery( '.mwp_wpvivid_active_plugin' ).on('click', function () { if(jQuery( this ).attr('class')==='mwp_wpvivid_active_plugin') mwp_wpvivid_active_plug( jQuery( this ), false ); return false; }); jQuery( '.mwp_wpvivid_upgrade_plugin' ).on('click', function () { if(jQuery( this ).attr('class')==='mwp_wpvivid_upgrade_plugin') mwp_wpvivid_upgrade_plug( jQuery( this ), false ); return false; }); </script> <?php } static public function get_websites_row($websites,$selected_group=0) { global $mainwp_wpvivid_extension_activator; $plugin_name = 'WPvivid Backup'; foreach ( $websites as $website ) { $website_id = $website['id']; if($website['individual']) { $individual='Individual'; } else { $individual='General'; } $class_active = ( isset( $website['active'] ) && ! empty( $website['active'] ) ) ? '' : 'negative'; if($website['pro']){ $need_update = $mainwp_wpvivid_extension_activator->get_need_update($website_id); $class_update = $need_update == '1' ? 'warning' : ''; $latest_version = $mainwp_wpvivid_extension_activator->get_latest_version($website_id); if($latest_version == ''){ $latest_version = $mainwp_wpvivid_extension_activator->get_current_version($website_id); } } else { $class_update = (isset($website['upgrade'])) ? 'warning' : ''; $latest_version = (isset($website['upgrade']['new_version'])) ? $website['upgrade']['new_version'] : $website['version']; } $class_update = ( 'negative' == $class_active ) ? 'negative' : $class_update; $plugin_slug = ( isset( $website['slug'] ) ) ? $website['slug'] : ''; ?> <tr class="<?php echo esc_attr($class_active.' '.$class_update); ?>" website-id="<?php echo esc_attr($website_id); ?>" plugin-name="<?php echo esc_attr($plugin_name); ?>" plugin-slug="<?php echo esc_attr($plugin_slug); ?>" is-pro="<?php echo esc_attr($website['pro']); ?>" version="<?php echo esc_attr(isset($website['version']) ? $website['version'] : ''); ?>" latest-version="<?php echo esc_attr($latest_version); ?>"> <td class="check-column"><span class="ui checkbox"><input type="checkbox" name="checked[]"></span></td> <td class="website-name"><a href="admin.php?page=managesites&dashboard=<?php echo esc_html($website_id); ?>"><?php echo esc_html(stripslashes( $website['name'] )); ?></a></td> <td><a href="admin.php?page=SiteOpen&newWindow=yes&websiteid=<?php echo esc_html($website_id); ?>&_opennonce=<?php echo esc_html(wp_create_nonce( 'mainwp-admin-nonce' )); ?>" target="_blank"><i class="sign in icon"></i></a></td> <td><a href="<?php echo esc_url($website['url']); ?>" target="_blank"><?php echo esc_html($website['url']); ?></a></td> <td><a onclick="mwp_wpvivid_check_report('<?php echo esc_js($website['id']); ?>', '<?php echo esc_js($website['pro']); ?>', '<?php echo esc_js($website['name']); ?>');" style="cursor: pointer;">Report</a></td> <td><span class="updating"></span><span class="mwp-wpvivid-current-version"> <?php if($website['pro']){ $version = $mainwp_wpvivid_extension_activator->get_current_version($website_id); echo esc_html($version).' (WPvivid Backup Pro)'; } else{ $version = isset($website['version']) ? $website['version'] : ''; echo esc_html($version).' (WPvivid Backup)'; } ?> </span> </td> <td> <span class="mwp-wpvivid-status"> <?php if($website['pro']){ $need_update = $mainwp_wpvivid_extension_activator->get_need_update($website_id); echo $need_update == '1' ? 'New version available' : 'Latest version'; } else{ echo isset($website['upgrade']) ? 'New version available' : 'Latest version'; } ?> </span> </td> <td><span><?php echo esc_html($individual); ?></span></td> <td><span><a href="admin.php?page=ManageSitesWPvivid&id=<?php echo esc_url($website_id); ?>"><i class="fa fa-hdd-o"></i> <?php esc_html_e( 'Backup Now', 'mainwp-wpvivid-extension' ); ?></a></span></td> </tr> <?php } ?> <script> function mwp_wpvivid_check_report(website_id, is_pro, website_name){ window.location.href = window.location.href + "&check_report=1&website_id="+website_id+"&pro="+is_pro+"&website_name="+website_name; } </script> <?php } static public function sort_websites($a, $b) { if ( 'version' == self::$orderby ) { $a = $a['version']; $b = $b['version']; $cmp = version_compare( $a, $b ); } else if ( 'url' == self::$orderby ) { $a = $a['url']; $b = $b['url']; $cmp = strcmp( $a, $b ); } else if ( 'setting' == self::$orderby ) { $a = $a['individual']; $b = $b['individual']; $cmp = $a - $b; } else { $a = $a['name']; $b = $b['name']; $cmp = strcmp( $a, $b ); } if ( 0 == $cmp ) { return 0; } if ( 'desc' == self::$order ) { return ($cmp > 0) ? -1 : 1; } else { return ($cmp > 0) ? 1 : -1; } } } wpvivid-backup-mainwp.php 0000644 00000333354 15133715745 0011527 0 ustar 00 <?php /** * Plugin Name: WPvivid Backup MainWP * Plugin URI: https://mainwp.com/ * Description: WPvivid Backup for MainWP enables you to create and download backups of a specific child site, set backup schedules, connect with your remote storage and set settings for all of your child sites directly from your MainWP dashboard. * Version: 0.9.39 * Author: WPvivid Team * Author URI: https://wpvivid.com * License: GPL-3.0+ * License URI: http://www.gnu.org/copyleft/gpl.html * Documentation URI: https://docs.wpvivid.com/wpvivid-backup-for-mainwp.html */ define('MAINWP_WPVIVID_EXTENSION_PLUGIN_DIR',dirname(__FILE__)); define('MAINWP_WPVIVID_EXTENSION_PLUGIN_URL',plugins_url('',__FILE__)); define('MAINWP_WPVIVID_SUCCESS','success'); define('MAINWP_WPVIVID_FAILED','failed'); use MainWP\Dashboard; class Mainwp_WPvivid_Extension_Activator { protected $plugin_handle = 'wpvivid-backup-mainwp'; protected $product_id = 'WPvivid Backup MainWP'; protected $version = '0.9.39'; protected $childEnabled; public $childKey; public $childFile; protected $mainwpMainActivated; public $remote; public $login; public $setting; public $dashboard; public $schedule; public $incremental_schedule; public $white_label; public $remote_page; public $capability; public $backup_page; public $backup_restore_page; private $mainwp_wpvivid_backups_db_version = '1.0'; public function __construct() { $this->load_dependencies(); $this->remote=new Mainwp_WPvivid_Remote_collection(); $this->childFile = __FILE__; add_filter( 'mainwp_getextensions', array( &$this, 'get_this_extension' ) ); add_action( 'admin_init', array( &$this, 'admin_init' ) ); $primary_backup = get_option( 'mainwp_primaryBackup', null ); if ( 'wpvivid' == $primary_backup ) { add_filter( 'mainwp_managesites_getbackuplink', array( $this, 'managesites_backup_link' ), 10, 2 ); } $this->mainwpMainActivated = apply_filters( 'mainwp_activated_check', false ); if ( $this->mainwpMainActivated !== false ) { $this->activate_this_plugin(); } else { add_action( 'mainwp_activated', array( &$this, 'activate_this_plugin' ) ); } $this->init_database(); $this->load_ajax_hook(); add_filter( 'mainwp_getsubpages_sites', array( &$this, 'managesites_subpage' ), 10, 1 ); add_filter( 'mainwp_sync_others_data', array( $this, 'sync_others_data' ), 10, 2 ); add_action( 'mainwp_site_synced', array( $this, 'synced_site' ), 10, 2 ); //add_filter( 'mainwp-sync-extensions-options', array( &$this, 'mainwp_sync_extensions_options' ), 10, 1 ); add_action( 'mainwp_delete_site', array( &$this, 'delete_site_data' ), 10, 1 ); add_filter( 'mainwp_getprimarybackup_methods', array( $this, 'primary_backups_method' ), 10, 1 ); add_filter('mwp_wpvivid_set_schedule_notice', array($this, 'set_schedule_notice'), 10, 2); add_filter('mwp_wpvivid_add_remote_storage_list', array( $this, 'add_remote_storage_list' ), 10); add_filter( 'mainwp_plugins_install_checks', array( $this, 'wpvivid_mainwp_plugins_install_checks' ), 10, 1 ); if(!defined( 'DOING_CRON' )) { if(wp_get_schedule('mwp_wpvivid_check_version_event')===false) { wp_schedule_event(time()+10, 'hourly', 'mwp_wpvivid_check_version_event'); } if(wp_get_schedule('mwp_wpvivid_refresh_latest_pro_version_event')===false) { wp_schedule_event(time()+10, 'daily', 'mwp_wpvivid_refresh_latest_pro_version_event'); } } } public function wpvivid_mainwp_plugins_install_checks($plugins) { global $mainwp_wpvivid_extension_activator; $select_pro=$mainwp_wpvivid_extension_activator->get_global_select_pro(); if($select_pro) { } else { $plugins[] = array( 'page' => 'Extensions-Wpvivid-Backup-Mainwp', 'slug' => 'wpvivid-backuprestore/wpvivid-backuprestore.php', 'name' => 'WPvivid Backup Plugin', ); } return $plugins; } public function managesites_backup_link( $input, $site_id ) { if ( $site_id ) { $last_backup = 'Never'; $report = Mainwp_WPvivid_Extension_DB_Option::get_instance()->wpvivid_get_option($site_id, 'report_addon', array()); if(isset($report) && !empty($report)){ usort($report, function($a, $b){ if($a['backup_time'] === $b['backup_time']){ return 0; } else if($a['backup_time'] > $b['backup_time']){ return -1; } else{ return 1; } }); $time_zone=Mainwp_WPvivid_Extension_Option::get_instance()->wpvivid_get_single_option($site_id, 'time_zone', ''); if(empty($time_zone)){ $time_zone = 0; } foreach ($report as $task_id => $report_option) { if($report_option['status'] === 'Succeeded') { //$last_backup = date("H:i:s - m/d/Y", $report_option['backup_time']); $last_backup = date("F d, Y H:i", $report_option['backup_time'] + $time_zone * 60 * 60); break; } } $output = $last_backup . '<br />'; } else{ $last_backup = 'Never'; $output = '<span class="mainwp-red">Never</span><br/>'; } if ( mainwp_current_user_can( 'dashboard', 'execute_backups' ) ) { $output .= sprintf( '<a href="admin.php?page=ManageSitesWPvivid&id=%s">' . __( 'Backup Now', 'mainwp' ) . '</a>', $site_id ); } return $output; } else { return $input; } } public function wpvivid_cron_schedules($schedules) { if(!isset($schedules["hourly"])){ $schedules["hourly"] = array( 'interval' => 3600, 'display' => __('Once Hourly')); } return $schedules; } public function load_dependencies() { include_once dirname(__FILE__) .DIRECTORY_SEPARATOR. 'wpvivid-backup-mainwp-setting.php'; include_once dirname(__FILE__) .DIRECTORY_SEPARATOR. 'wpvivid-backup-mainwp-subpage.php'; include_once dirname(__FILE__) .DIRECTORY_SEPARATOR. 'wpvivid-backup-mainwp-option.php'; include_once dirname(__FILE__) .DIRECTORY_SEPARATOR. 'wpvivid-backup-mainwp-db-option.php'; include_once dirname(__FILE__) .DIRECTORY_SEPARATOR. '/admin/wpvivid-backup-mainwp-backupmanager.php'; include_once dirname(__FILE__) .DIRECTORY_SEPARATOR. '/admin/wpvivid-backup-mainwp-backuprestorepage.php'; include_once dirname(__FILE__) .DIRECTORY_SEPARATOR. '/includes/class-wpvivid-mainwp-connect-server.php'; include_once dirname(__FILE__) .DIRECTORY_SEPARATOR. '/includes/class-wpvivid-crypt.php'; include_once dirname(__FILE__) .DIRECTORY_SEPARATOR. '/includes/class-wpvivid-remote-collection.php'; include_once dirname(__FILE__) .DIRECTORY_SEPARATOR. '/admin/wpvivid-backup-mainwp-loginpage.php'; include_once dirname(__FILE__) .DIRECTORY_SEPARATOR. '/admin/wpvivid-backup-mainwp-settingpage.php'; include_once dirname(__FILE__) .DIRECTORY_SEPARATOR. '/admin/wpvivid-backup-mainwp-dashboardpage.php'; include_once dirname(__FILE__) .DIRECTORY_SEPARATOR. '/admin/wpvivid-backup-mainwp-schedulepage.php'; include_once dirname(__FILE__) .DIRECTORY_SEPARATOR. '/admin/wpvivid-backup-mainwp-incremental-backup.php'; include_once dirname(__FILE__) .DIRECTORY_SEPARATOR. '/admin/wpvivid-backup-mainwp-white-label.php'; include_once dirname(__FILE__) .DIRECTORY_SEPARATOR. '/admin/wpvivid-backup-mainwp-remotepage.php'; include_once dirname(__FILE__) .DIRECTORY_SEPARATOR. '/admin/wpvivid-backup-mainwp-capabilitypage.php'; include_once dirname(__FILE__) .DIRECTORY_SEPARATOR. '/admin/wpvivid-backup-mainwp-backuppage.php'; $this->login=new Mainwp_WPvivid_Extension_LoginPage(); $this->setting=new Mainwp_WPvivid_Extension_SettingPage(); $this->dashboard=new Mainwp_WPvivid_Extension_DashboardPage(); $this->schedule=new Mainwp_WPvivid_Extension_SchedulePage(); $this->incremental_schedule=new Mainwp_WPvivid_Extension_Incremental_Backup(); $this->white_label=new Mainwp_WPvivid_Extension_White_Label(); $this->remote_page=new Mainwp_WPvivid_Extension_RemotePage(); $this->capability=new Mainwp_WPvivid_Extension_Capability(); $this->backup_page=new Mainwp_WPvivid_Extension_BackupPage(); $this->backup_restore_page=new Mainwp_WPvivid_Extension_BackupRestorePage(); } public function load_ajax_hook() { add_action('wp_ajax_mwp_wpvivid_switch_pro_setting', array($this, 'switch_pro_setting')); add_action('wp_ajax_mwp_wpvivid_set_individual', array( $this, 'set_individual')); //check pro need update add_action('mwp_wpvivid_check_version_event',array( $this,'mwp_wpvivid_check_version_event')); add_action('mwp_wpvivid_refresh_latest_pro_version_event',array($this, 'mwp_wpvivid_refresh_latest_pro_version_event')); add_filter('mwp_wpvivid_custom_backup_data_transfer', array($this, 'mwp_wpvivid_custom_backup_data_transfer'), 10, 3); } public function init_database() { Mainwp_WPvivid_Extension_DB_Option::get_instance()->import_settings(); Mainwp_WPvivid_Extension_DB_Option::get_instance()->import_global_settings(); $currentVersion = get_site_option( 'mainwp_wpvivid_backups_db_version' ); $query_wpvividmeta = $this->query("SHOW TABLES LIKE '" . Mainwp_WPvivid_Extension_DB_Option::get_instance()->get_table_name('wpvividmeta') . "'"); if ( @self::num_rows( $query_wpvividmeta ) == 0 ) { $currentVersion = false; } $query_wpvivid_global_options = $this->query("SHOW TABLES LIKE '" . Mainwp_WPvivid_Extension_DB_Option::get_instance()->get_table_name('wpvivid_global_options') . "'"); if ( @self::num_rows( $query_wpvivid_global_options ) == 0 ) { $currentVersion = false; } $query_wpvivid = $this->query("SHOW TABLES LIKE '" . Mainwp_WPvivid_Extension_Option::get_instance()->get_table_name('wpvivid') . "'"); if ( @self::num_rows( $query_wpvivid ) == 0 ) { $currentVersion = false; } $query_wpvivid_global = $this->query("SHOW TABLES LIKE '" . Mainwp_WPvivid_Extension_Option::get_instance()->get_table_name('wpvivid_global') . "'"); if ( @self::num_rows( $query_wpvivid_global ) == 0 ) { $currentVersion = false; } if ( $currentVersion == $this->mainwp_wpvivid_backups_db_version ) { return; } Mainwp_WPvivid_Extension_Option::get_instance()->init_options(); Mainwp_WPvivid_Extension_DB_Option::get_instance()->init_db_options(); update_option('mainwp_wpvivid_backups_db_version', $this->mainwp_wpvivid_backups_db_version); } public static function use_mysqli() { /** @var $wpdb wpdb */ if ( ! function_exists( 'mysqli_connect' ) ) { return false; } global $wpdb; return ( $wpdb->dbh instanceof mysqli ); } public static function num_rows( $result ) { if ( $result === false ) { return 0; } if ( self::use_mysqli() ) { return mysqli_num_rows( $result ); } else { return mysql_num_rows( $result ); } } public function query( $sql ) { if ( null == $sql ) { return false; } /** @var $wpdb wpdb */ global $wpdb; $result = @self::_query( $sql, $wpdb->dbh ); if ( ! $result || ( @self::num_rows( $result ) == 0 ) ) { return false; } return $result; } public static function _query( $query, $link ) { if ( self::use_mysqli() ) { return mysqli_query( $link, $query ); } else { return mysql_query( $query, $link ); } } public function sync_others_data( $data, $pWebsite = null ) { if ( ! is_array( $data ) ) { $data = array(); } $data['syncWPvividData'] = 1; return $data; } public function handle_custom_tree_data($options){ if(isset($options['uploads_option']['exclude_uploads_list']) && !empty($options['uploads_option']['exclude_uploads_list'])){ foreach ($options['uploads_option']['exclude_uploads_list'] as $key => $value){ if($value['type'] === 'wpvivid-custom-li-folder-icon'){ $value['type'] = 'mwp-wpvivid-custom-li-folder-icon'; } else if($value['type'] === 'wpvivid-custom-li-file-icon'){ $value['type'] = 'mwp-wpvivid-custom-li-file-icon'; } $options['uploads_option']['exclude_uploads_list'][$key] = $value; } } if(isset($options['content_option']['exclude_content_list']) && !empty($options['content_option']['exclude_content_list'])){ foreach ($options['content_option']['exclude_content_list'] as $key => $value){ if($value['type'] === 'wpvivid-custom-li-folder-icon'){ $value['type'] = 'mwp-wpvivid-custom-li-folder-icon'; } else if($value['type'] === 'wpvivid-custom-li-file-icon'){ $value['type'] = 'mwp-wpvivid-custom-li-file-icon'; } $options['content_option']['exclude_content_list'][$key] = $value; } } if(isset($options['other_option']['include_other_list']) && !empty($options['other_option']['include_other_list'])){ foreach ($options['other_option']['include_other_list'] as $key => $value){ if($value['type'] === 'wpvivid-custom-li-folder-icon'){ $value['type'] = 'mwp-wpvivid-custom-li-folder-icon'; } else if($value['type'] === 'wpvivid-custom-li-file-icon'){ $value['type'] = 'mwp-wpvivid-custom-li-file-icon'; } $options['other_option']['include_other_list'][$key] = $value; } } return $options; } public function synced_site( $pWebsite, $information = array() ) { if ( is_array( $information ) ) { if ( isset( $information['syncWPvividData'] ) ) { if(isset($information['syncWPvividSetting'])){ $data['settings'] = isset($information['syncWPvividSetting']['setting']) ? serialize($information['syncWPvividSetting']['setting']) : ''; $data_meta['settings'] = isset($information['syncWPvividSetting']['setting']) ? ($information['syncWPvividSetting']['setting']) : '';// $data['settings_addon'] = isset($information['syncWPvividSetting']['setting_addon']) ? serialize($information['syncWPvividSetting']['setting_addon']) : ''; $data_meta['settings_addon'] = isset($information['syncWPvividSetting']['setting_addon']) ? ($information['syncWPvividSetting']['setting_addon']) : '';// $data['schedule'] = isset($information['syncWPvividSetting']['schedule']) ? serialize($information['syncWPvividSetting']['schedule']) : ''; $data_meta['schedule'] = isset($information['syncWPvividSetting']['schedule']) ? ($information['syncWPvividSetting']['schedule']) : '';// $data['schedule_addon'] = isset($information['syncWPvividSetting']['schedule_addon']) ? serialize($information['syncWPvividSetting']['schedule_addon']) : ''; $data_meta['schedule_addon'] = isset($information['syncWPvividSetting']['schedule_addon']) ? ($information['syncWPvividSetting']['schedule_addon']) : '';// $data['remote'] = isset($information['syncWPvividSetting']['remote']) ? serialize($information['syncWPvividSetting']['remote']) : ''; $data_meta['remote'] = isset($information['syncWPvividSetting']['remote']) ? ($information['syncWPvividSetting']['remote']) : '';// if(isset($information['syncWPvividSetting']['backup_custom_setting_ex'])) { $information['syncWPvividSetting']['backup_custom_setting_ex'] = $this->handle_custom_tree_data($information['syncWPvividSetting']['backup_custom_setting_ex']); $data['backup_custom_setting_ex'] = serialize($information['syncWPvividSetting']['backup_custom_setting_ex']); $data_meta['backup_custom_setting_ex'] = ($information['syncWPvividSetting']['backup_custom_setting_ex']); } else{ $data['backup_custom_setting_ex'] = ''; $data_meta['backup_custom_setting_ex'] = ''; } $data_meta['menu_capability'] = isset($information['syncWPvividSetting']['menu_capability']) ? $information['syncWPvividSetting']['menu_capability'] : ''; $data_meta['white_label_setting'] = isset($information['syncWPvividSetting']['white_label_setting']) ? $information['syncWPvividSetting']['white_label_setting'] : ''; $data_meta['incremental_backup_setting'] = isset($information['syncWPvividSetting']['incremental_backup_setting']) ? $information['syncWPvividSetting']['incremental_backup_setting'] : array(); $data_meta['dashboard_version'] = isset($information['syncWPvividSetting']['dashboard_version']) ? $information['syncWPvividSetting']['dashboard_version'] : ''; $data_meta['addons_info'] = isset($information['syncWPvividSetting']['addons_info']) ? $information['syncWPvividSetting']['addons_info'] : array(); if(isset($information['syncWPvividSetting']['is_mu'])){ $data_meta['is_mu'] = $information['syncWPvividSetting']['is_mu'] === true ? 1 : 0; } else{ $data_meta['is_mu'] = 0; } Mainwp_WPvivid_Extension_DB_Option::get_instance()->wpvivid_sync_options($pWebsite->id, $data_meta); $data['need_update'] = isset($information['syncWPvividSetting']['need_update']) ? $information['syncWPvividSetting']['need_update'] : ''; $data['current_version'] = isset($information['syncWPvividSetting']['current_version']) ? $information['syncWPvividSetting']['current_version'] : ''; if(isset($information['syncWPvividSetting']['is_pro'])) { $data['is_pro'] = $information['syncWPvividSetting']['is_pro'] === true ? 1 : 0; if($data['is_pro'] === 1){ $sync_first = $this->get_global_first_init(); if(!$sync_first){ $this->set_global_first_init('first'); } } } else{ $data['is_pro'] = 0; } if(isset($information['syncWPvividSetting']['is_install'])){ $data['is_install'] = $information['syncWPvividSetting']['is_install'] === true ? 1 : 0; } else{ $data['is_install'] = 0; } if(isset($information['syncWPvividSetting']['is_login'])){ $data['is_login'] = $information['syncWPvividSetting']['is_login'] === true ? 1 : 0; } else{ $data['is_login'] = 0; } $data['latest_version'] = isset($information['syncWPvividSetting']['latest_version']) ? $information['syncWPvividSetting']['latest_version'] : ''; $data['time_zone'] = isset($information['syncWPvividSetting']['time_zone']) ? $information['syncWPvividSetting']['time_zone'] : 0; $last_backup_report = isset($information['syncWPvividSetting']['last_backup_report']) ? $information['syncWPvividSetting']['last_backup_report'] : array(); $this->set_backup_report($pWebsite->id, $last_backup_report); //$data['report_addon'] = isset($information['syncWPvividSetting']['report_addon']) ? base64_encode(serialize($information['syncWPvividSetting']['report_addon'])) : ''; $login_options = $this->get_global_login_addon(); $tmp_version = 0; if(isset($login_options['wpvivid_pro_login_cache']['pro']['version'])){ $tmp_version = $login_options['wpvivid_pro_login_cache']['pro']['version']; } else if(isset($login_options['wpvivid_pro_login_cache']['dashboard']['version'])){ $tmp_version = $login_options['wpvivid_pro_login_cache']['dashboard']['version']; } if(isset($login_options['wpvivid_pro_login_cache'])) { if (isset($data['current_version'])) { if(version_compare($tmp_version, $data['current_version'],'>')) { $data['need_update']=1; $data['latest_version']=$tmp_version; } else{ $data['need_update']=0; } } else{ $data['need_update']=1; $data['latest_version']=$tmp_version; } } unset($data['backup_custom_setting_ex']); Mainwp_WPvivid_Extension_Option::get_instance()->sync_options($pWebsite->id,$data); unset($data['wpvivid_setting']); unset($data['need_update']); unset($data['current_version']); unset($data['is_pro']); unset($data['is_install']); unset($data['is_login']); unset($data['latest_version']); unset($data['time_zone']); //unset($data['report_addon']); if(!Mainwp_WPvivid_Extension_Option::get_instance()->is_set_global_options()) { Mainwp_WPvivid_Extension_Option::get_instance()->set_global_options($data); } unset( $information['syncWPvividSetting'] ); unset( $information['syncWPvividData'] ); } else{ $this->set_sync_error($pWebsite->id, 2); } } else{ $this->set_sync_error($pWebsite->id, 1); } } } public function delete_site_data($website) { if ( $website ) { Mainwp_WPvivid_Extension_Option::get_instance()->delete_site($website->id ); } } /*public function mainwp_sync_extensions_options($values = array()) { $values['wpvivid-backup-mainwp'] = array( 'plugin_name' => 'WPvivid Backup Plugin', 'plugin_slug' => 'wpvivid-backuprestore/wpvivid-backuprestore.php' ); return $values; }*/ public function primary_backups_method( $methods ) { $methods[] = array( 'value' => 'wpvivid', 'title' => 'WPvivid Backup for MainWP' ); return $methods; } public function set_schedule_notice($notice_type, $message) { $html = ''; if($notice_type) { $html .= '<div class="notice notice-success is-dismissible inline" style="margin: 0; padding-top: 10px; margin-bottom: 10px; margin-left: 0px !important;"><p>'.esc_html($message).'</p> <button type="button" class="notice-dismiss" onclick="mwp_click_dismiss_notice(this);"> <span class="screen-reader-text">Dismiss this notice.</span> </button> </div>'; } else{ $html .= '<div class="notice notice-error inline" style="margin: 0; padding: 10px; margin-bottom: 10px; margin-left: 0px !important;"><p>' . esc_html($message) . '</p></div>'; } return $html; } public function check_site_id_secure($site_id) { if(Mainwp_WPvivid_Extension_Option::get_instance()->is_vaild_child_site($site_id)){ return true; } else{ return false; } } public function admin_init() { wp_enqueue_style('Mainwp Wpvivid Extension', plugin_dir_url(__FILE__) . 'admin/css/wpvivid-backup-mainwp-admin.css', array(), $this->version, 'all'); wp_enqueue_style('Mainwp Wpvivid Extension'.'jstree', plugin_dir_url(__FILE__) . 'admin/js/jstree/dist/themes/default/style.min.css', array(), $this->version, 'all'); wp_enqueue_script('Mainwp Wpvivid Extension', plugin_dir_url(__FILE__) . 'admin/js/wpvivid-backup-mainwp-admin.js', array('jquery'), $this->version, false); wp_enqueue_script('Mainwp Wpvivid Extension'.'jstree', plugin_dir_url(__FILE__) . 'admin/js/jstree/dist/jstree.min.js', array('jquery'), $this->version, false); wp_localize_script('Mainwp Wpvivid Extension', 'ajax_object', array('ajax_url' => admin_url('admin-ajax.php'), 'ajax_nonce'=>wp_create_nonce('wpvivid_mainwp_ajax'))); if(isset($_GET['id']) && !empty($_GET['id'])) { $site_id=sanitize_key($_GET['id']); wp_add_inline_script( 'Mainwp Wpvivid Extension', 'site_id='.$site_id); } } public function managesites_subpage( $subPage ) { $subPage[] = array( 'title' => __( 'WPvivid Backups', 'mainwp' ), 'slug' => 'WPvivid', 'sitetab' => true, 'menu_hidden' => true, 'callback' => array( $this, 'render' ), ); return $subPage; } function render() { do_action( "mainwp_pageheader_sites", "WPvivid" ); Mainwp_WPvivid_Extension_Subpage::renderSubpage(); do_action( "mainwp_pagefooter_sites", "WPvivid" ); } function get_this_extension( $pArray ) { $extension['plugin']=__FILE__; $extension['mainwp']=false; $extension['callback']=array(&$this, 'settings'); $extension['icon']=MAINWP_WPVIVID_EXTENSION_PLUGIN_URL.'/admin/images/logo.png'; $pArray[] = $extension; return $pArray; } function activate_this_plugin() { $this->mainwpMainActivated = apply_filters( 'mainwp_activated_check', $this->mainwpMainActivated ); $this->childEnabled = apply_filters( 'mainwp_extension_enabled_check', __FILE__ ); $this->childKey = $this->childEnabled['key']; } function settings() { do_action( 'mainwp_pageheader_extensions', $this->childFile ); Mainwp_WPvivid_Extension_Setting::renderSetting(); do_action( 'mainwp_pagefooter_extensions', $this->childFile ); } public function switch_pro_setting() { $this->mwp_ajax_check_security(); try{ if(isset($_POST['pro_setting']) && is_string($_POST['pro_setting'])){ $pro_setting = sanitize_text_field($_POST['pro_setting']); if($pro_setting == '1'){ $this->set_global_switch_pro_setting_page(1); } else{ $this->set_global_switch_pro_setting_page(0); } $this->set_global_select_pro($pro_setting); $ret['result'] = 'success'; echo wp_json_encode($ret); } } 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().';'; error_log($message); echo wp_json_encode(array('result'=>'failed','error'=>$message)); } die(); } public function set_individual() { $this->mwp_ajax_check_security(); try { if(isset($_POST['site_id']) && !empty($_POST['site_id']) && is_string($_POST['site_id']) && isset($_POST['individual']) && is_string($_POST['individual'])) { $site_id = sanitize_key($_POST['site_id']); $individual = sanitize_text_field($_POST['individual']); $individual = intval($individual); Mainwp_WPvivid_Extension_Option::get_instance()->wpvivid_update_single_option($site_id, 'individual', $individual); $ret['result'] = 'success'; echo wp_json_encode($ret); } die(); } 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().';'; error_log($message); echo wp_json_encode(array('result'=>'failed','error'=>$message)); die(); } } public function mwp_wpvivid_get_website_plugins_list($site_id) { $plugins = array(); $dbwebsites = $this->mwp_get_child_websites(); foreach ($dbwebsites as $website) { if ($website) { if ($website->id === $site_id) { $plugins = json_decode($website->plugins, 1); } } } return $plugins; } public function get_is_login($site_id) { $is_login_pro = Mainwp_WPvivid_Extension_Option::get_instance()->wpvivid_get_single_option($site_id, 'is_login', false); if(empty($is_login_pro)){ $is_login_pro = false; } return $is_login_pro; } public function set_is_login($site_id, $is_login) { Mainwp_WPvivid_Extension_Option::get_instance()->wpvivid_update_single_option($site_id, 'is_login', $is_login); } public function get_latest_version($site_id) { $latest_version = Mainwp_WPvivid_Extension_Option::get_instance()->wpvivid_get_single_option($site_id, 'latest_version', ''); if(empty($latest_version)){ $latest_version = ''; } return $latest_version; } public function set_latest_version($site_id, $version) { Mainwp_WPvivid_Extension_Option::get_instance()->wpvivid_update_single_option($site_id, 'latest_version', $version); } public function get_current_version($site_id) { $current_version = Mainwp_WPvivid_Extension_Option::get_instance()->wpvivid_get_single_option($site_id, 'current_version', ''); return $current_version; } public function set_current_version($site_id, $version) { Mainwp_WPvivid_Extension_Option::get_instance()->wpvivid_update_single_option($site_id, 'current_version', $version); } public function get_need_update($site_id) { $need_update = Mainwp_WPvivid_Extension_Option::get_instance()->wpvivid_get_single_option($site_id, 'need_update', ''); return $need_update; } public function set_need_update($site_id, $need_update) { Mainwp_WPvivid_Extension_Option::get_instance()->wpvivid_update_single_option($site_id, 'need_update', $need_update); } public function set_sync_error($site_id, $sync_error) { Mainwp_WPvivid_Extension_Option::get_instance()->wpvivid_update_single_option($site_id, 'sync_error', $sync_error); } public function set_backup_report($site_id, $option) { $reports = Mainwp_WPvivid_Extension_DB_Option::get_instance()->wpvivid_get_option($site_id, 'report_addon', array()); if(!empty($reports)){ foreach ($option as $key => $value){ $reports[$key] = $value; $reports = $this->clean_out_of_date_report($reports, 10); Mainwp_WPvivid_Extension_DB_Option::get_instance()->wpvivid_update_option($site_id, 'report_addon', $reports); } } else{ Mainwp_WPvivid_Extension_DB_Option::get_instance()->wpvivid_update_option($site_id, 'report_addon', $option); } } public static function get_oldest_backup_id($report_list) { $oldest_id='not set'; $oldest=0; foreach ($report_list as $key=>$value) { if ($oldest == 0) { $oldest = $value['backup_time']; $oldest_id = $key; } else { if ($oldest > $value['backup_time']) { $oldest_id = $key; } } } return $oldest_id; } function clean_out_of_date_report($report_list, $max_report_count) { $size=sizeof($report_list); while($size>$max_report_count) { $oldest_id=self::get_oldest_backup_id($report_list); if($oldest_id!='not set') { unset($report_list[$oldest_id]); } $new_size=sizeof($report_list); if($new_size==$size) { break; } else { $size=$new_size; } } return $report_list; } public function get_global_first_init() { $sync_init_addon_first=Mainwp_WPvivid_Extension_DB_Option::get_instance()->wpvivid_get_global_option('sync_init_addon_first', ''); return $sync_init_addon_first; } public function set_global_first_init($first) { Mainwp_WPvivid_Extension_DB_Option::get_instance()->wpvivid_update_global_option('sync_init_addon_first', $first); } public function get_global_switch_pro_setting_page() { $switch_pro_setting_page=Mainwp_WPvivid_Extension_DB_Option::get_instance()->wpvivid_get_global_option('switch_pro_setting_page', ''); return $switch_pro_setting_page; } public function set_global_switch_pro_setting_page($pro_setting_page) { Mainwp_WPvivid_Extension_DB_Option::get_instance()->wpvivid_update_global_option('switch_pro_setting_page', $pro_setting_page); } public function get_global_select_pro() { $select_pro=Mainwp_WPvivid_Extension_DB_Option::get_instance()->wpvivid_get_global_option('select_pro', ''); return $select_pro; } public function set_global_select_pro($select_pro) { Mainwp_WPvivid_Extension_DB_Option::get_instance()->wpvivid_update_global_option('select_pro', $select_pro); } public function get_global_login_addon() { $login_addon=Mainwp_WPvivid_Extension_DB_Option::get_instance()->wpvivid_get_global_option('login_addon', array()); if ( !is_array($login_addon) || empty($login_addon) ) { $login_addon = array(); } return $login_addon; } public function set_global_login_addon($login_addon) { Mainwp_WPvivid_Extension_DB_Option::get_instance()->wpvivid_update_global_option('login_addon', $login_addon); } public function add_remote_storage_list($html) { $html = ''; $options=Mainwp_WPvivid_Extension_DB_Option::get_instance()->wpvivid_get_global_option('remote', array()); $remoteslist=$options['upload']; $history=$options['history']; $default_remote_storage=''; if(isset($history['remote_selected'])) { foreach ($history['remote_selected'] as $value) { $default_remote_storage = $value; } } $i=1; foreach ($remoteslist as $key=>$value) { if($key === 'remote_selected') { continue; } if ($key === $default_remote_storage) { $check_status = 'checked'; } else { $check_status=''; } $storage_type = $value['type']; $storage_type=apply_filters('wpvivid_storage_provider_tran', $storage_type); $html .= '<tr> <td>'.esc_html($i++).'</td> <td><input type="checkbox" name="remote_storage" value="'.esc_attr($key).'" '.esc_attr($check_status).' /></td> <td>'.esc_html($storage_type).'</td> <td class="row-title"><label for="tablecell">'.esc_html($value['name']).'</label></td> <td> <div><img src="'.esc_url(MAINWP_WPVIVID_EXTENSION_PLUGIN_URL.'/admin/images/Delete.png').'" onclick="mwp_wpvivid_delete_remote_storage(\''.esc_js($key).'\');" style="vertical-align:middle; cursor:pointer;" title="Remove the remote storage"/></div> </td> </tr>'; } return $html; } public function mwp_wpvivid_check_version_event(){ $websites=$this->get_websites_ex(); foreach ( $websites as $website ){ $site_id = $website['id']; if($website['slug'] === 'wpvivid-backup-pro/wpvivid-backup-pro.php'){ $post_data['mwp_action'] = 'wpvivid_get_wpvivid_info_addon_mainwp'; $information = apply_filters('mainwp_fetchurlauthed', $this->childFile, $this->childKey, $site_id, 'wpvivid_backuprestore', $post_data); if (isset($information['error'])) { $ret['result'] = 'failed'; $ret['error'] = $information['error']; } else { $ret['result'] = 'success'; if(isset($information['need_update'])){ if($information['need_update']){ $need_update = 1; } else{ $need_update = 0; } } else{ $need_update = 0; } $login_options = $this->get_global_login_addon(); if(isset($login_options['wpvivid_pro_login_cache'])){ $tmp_version = 0; if(isset($login_options['wpvivid_pro_login_cache']['pro']['version'])){ $tmp_version = $login_options['wpvivid_pro_login_cache']['pro']['version']; } else if(isset($login_options['wpvivid_pro_login_cache']['dashboard']['version'])){ $tmp_version = $login_options['wpvivid_pro_login_cache']['dashboard']['version']; } if (isset($information['current_version'])) { if(version_compare($tmp_version, $information['current_version'],'>')){ $this->set_need_update($site_id, 1); $this->set_current_version($site_id, $information['current_version']); $this->set_latest_version($site_id, $tmp_version); } else{ $this->set_need_update($site_id, 0); $this->set_current_version($site_id, $information['current_version']); } } else{ $this->set_need_update($site_id, 1); $this->set_latest_version($site_id, $tmp_version); } } else { $this->set_need_update($site_id, $need_update); if (isset($information['current_version'])) { $current_version = $information['current_version']; $this->set_current_version($site_id, $current_version); } } if(isset($information['last_backup_report'])){ $last_backup_report = $information['last_backup_report']; $this->set_backup_report($site_id, $last_backup_report); } } } } } public function mwp_wpvivid_refresh_latest_pro_version_event(){ $login_options = $this->get_global_login_addon(); if($login_options !== false && isset($login_options['wpvivid_pro_account'])) { if(!isset($login_options['wpvivid_pro_account']['user_info'])) { $ret['result'] = 'failed'; $ret['error'] = 'Failed to get previously entered login information, please login again.'; echo wp_json_encode($ret); die(); } $user_info=$login_options['wpvivid_pro_account']['user_info']; $server=new Mainwp_WPvivid_Connect_server(); $ret=$server->get_mainwp_status($user_info,false); if($ret['result']=='success') { $login_options = $this->get_global_login_addon(); $login_options['wpvivid_pro_login_cache'] = $ret['status']; $this->set_global_login_addon($login_options); $need_update = false; if($login_options === false || !isset($login_options['wpvivid_pro_account'])){ $login_options = array(); $need_update = true; } else{ if(isset($login_options['wpvivid_pro_login_cache'])){ $tmp_version = 0; if(isset($login_options['wpvivid_pro_login_cache']['pro']['version'])){ $tmp_version = $login_options['wpvivid_pro_login_cache']['pro']['version']; } else if(isset($login_options['wpvivid_pro_login_cache']['dashboard']['version'])){ $tmp_version = $login_options['wpvivid_pro_login_cache']['dashboard']['version']; } if(version_compare($ret['status']['dashboard']['version'], $tmp_version,'>')){ $need_update = true; } else{ $need_update = false; } } else{ $need_update = true; } } if($need_update) { $this->check_child_site_need_update($ret['status']['dashboard']['version']); } } } } public function check_child_site_need_update($new_version) { $dbwebsites = $this->mwp_get_child_websites(); foreach ($dbwebsites as $website) { if ($website) { $old_version = $this->get_latest_version($website->id); if(version_compare($new_version, $old_version,'>')){ $this->set_need_update($website->id, 1); $this->set_latest_version($website->id, $new_version); } } } } public function mwp_wpvivid_update_backup_exclude_extension_rule($site_id, $type, $value){ $history = Mainwp_WPvivid_Extension_DB_Option::get_instance()->wpvivid_get_option($site_id, 'backup_custom_setting_ex', array()); if(!$history){ $history = array(); } if($type === 'uploads'){ $history['uploads_option']['uploads_extension_list'] = array(); $str_tmp = explode(',', $value); for($index=0; $index<count($str_tmp); $index++){ if(!empty($str_tmp[$index])) { $history['uploads_option']['uploads_extension_list'][] = $str_tmp[$index]; } } } if($type === 'content'){ $history['content_option']['content_extension_list'] = array(); $str_tmp = explode(',', $value); for($index=0; $index<count($str_tmp); $index++){ if(!empty($str_tmp[$index])) { $history['content_option']['content_extension_list'][] = $str_tmp[$index]; } } } if($type === 'additional_folder'){ $history['other_option']['other_extension_list'] = array(); $str_tmp = explode(',', $value); for($index=0; $index<count($str_tmp); $index++){ if(!empty($str_tmp[$index])) { $history['other_option']['other_extension_list'][] = $str_tmp[$index]; } } } Mainwp_WPvivid_Extension_DB_Option::get_instance()->wpvivid_update_option($site_id, 'backup_custom_setting_ex', $history); } public function mwp_wpvivid_update_global_backup_exclude_extension_rule($type, $value){ $history = Mainwp_WPvivid_Extension_DB_Option::get_instance()->wpvivid_get_global_option('backup_custom_setting', array()); if(!$history){ $history = array(); } if($type === 'uploads'){ $history['uploads_option']['uploads_extension_list'] = array(); $str_tmp = explode(',', $value); for($index=0; $index<count($str_tmp); $index++){ if(!empty($str_tmp[$index])) { $history['uploads_option']['uploads_extension_list'][] = $str_tmp[$index]; } } } if($type === 'content'){ $history['content_option']['content_extension_list'] = array(); $str_tmp = explode(',', $value); for($index=0; $index<count($str_tmp); $index++){ if(!empty($str_tmp[$index])) { $history['content_option']['content_extension_list'][] = $str_tmp[$index]; } } } if($type === 'additional_folder'){ $history['other_option']['other_extension_list'] = array(); $str_tmp = explode(',', $value); for($index=0; $index<count($str_tmp); $index++){ if(!empty($str_tmp[$index])) { $history['other_option']['other_extension_list'][] = $str_tmp[$index]; } } } Mainwp_WPvivid_Extension_DB_Option::get_instance()->wpvivid_update_global_option('backup_custom_setting', $history); } public function mwp_wpvivid_update_backup_custom_setting($site_id, $options){ $custom_option = Mainwp_WPvivid_Extension_DB_Option::get_instance()->wpvivid_get_option($site_id, 'backup_custom_setting_ex', array()); $custom_option['exclude_files'] = $options['exclude_files']; $custom_option['custom_dirs'] = $options['custom_dirs']; $custom_option['exclude_file_type'] = $options['exclude_file_type']; Mainwp_WPvivid_Extension_DB_Option::get_instance()->wpvivid_update_option($site_id, 'backup_custom_setting_ex', $custom_option); } public function mwp_wpvivid_update_global_backup_custom_setting($options){ $history = Mainwp_WPvivid_Extension_DB_Option::get_instance()->wpvivid_get_global_option('backup_custom_setting', array()); $custom_option['database_option']['database_check'] = $options['database_check']; $custom_option['themes_option']['themes_check'] = $options['themes_check']; $custom_option['plugins_option']['plugins_check'] = $options['plugins_check']; $custom_option['uploads_option']['uploads_check'] = $options['uploads_check']; $custom_option['uploads_option']['uploads_extension_list'] = array(); if(isset($options['upload_extension'])){ $str_tmp = explode(',', $options['upload_extension']); for($index=0; $index<count($str_tmp); $index++){ if(!empty($str_tmp[$index])) { $custom_option['uploads_option']['uploads_extension_list'][] = $str_tmp[$index]; } } } $custom_option['content_option']['content_check'] = $options['content_check']; $custom_option['content_option']['content_extension_list'] = array(); if(isset($options['content_extension'])){ $str_tmp = explode(',', $options['content_extension']); for($index=0; $index<count($str_tmp); $index++){ if(!empty($str_tmp[$index])) { $custom_option['content_option']['content_extension_list'][] = $str_tmp[$index]; } } } $custom_option['core_option']['core_check'] = $options['core_check']; Mainwp_WPvivid_Extension_DB_Option::get_instance()->wpvivid_update_global_option('backup_custom_setting', $custom_option); } public function set_incremental_file_settings($site_id, $options) { $incremental_backup_setting = Mainwp_WPvivid_Extension_DB_Option::get_instance()->wpvivid_get_option($site_id, 'incremental_backup_setting', array()); if(empty($incremental_backup_setting)){ $incremental_backup_setting = array(); $history = array(); } else{ $history = isset($incremental_backup_setting['incremental_history']) ? $incremental_backup_setting['incremental_history'] : array(); if(empty($history)){ $history = array(); } } $custom_option['database_option']['database_check'] = isset($options['database_check']) ? $options['database_check'] : 0; $custom_option['database_option']['exclude_table_list'] = isset($options['database_list']) ? $options['database_list'] : array(); $custom_option['themes_option']['themes_check'] = isset($options['themes_check']) ? $options['themes_check'] : 0; $custom_option['themes_option']['exclude_themes_list'] = isset($options['themes_list']) ? $options['themes_list'] : array(); $custom_option['plugins_option']['plugins_check'] = isset($options['plugins_check']) ? $options['plugins_check'] : 0; $custom_option['plugins_option']['exclude_plugins_list'] = isset($options['plugins_list']) ? $options['plugins_list'] : array(); $custom_option['uploads_option']['uploads_check'] = isset($options['uploads_check']) ? $options['uploads_check'] : 0; $custom_option['uploads_option']['exclude_uploads_list'] = isset($options['uploads_list']) ? $options['uploads_list'] : array(); $custom_option['uploads_option']['uploads_extension_list'] = isset($options['upload_extension']) ? $options['upload_extension'] : array(); $custom_option['content_option']['content_check'] = isset($options['content_check']) ? $options['content_check'] : 0; $custom_option['content_option']['exclude_content_list'] = isset($options['content_list']) ? $options['content_list'] : array(); $custom_option['content_option']['content_extension_list'] = isset($options['content_extension']) ? $options['content_extension'] : array(); $custom_option['core_option']['core_check'] = isset($options['core_check']) ? $options['core_check'] : 0; $custom_option['other_option']['other_check'] = isset($options['other_check']) ? $options['other_check'] : 0; $custom_option['other_option']['include_other_list'] = isset($options['other_list']) ? $options['other_list'] : array(); $custom_option['other_option']['other_extension_list'] = isset($options['other_extension']) ? $options['other_extension'] : array(); $custom_option['additional_database_option']['additional_database_check'] = isset($options['additional_database_check']) ? $options['additional_database_check'] : 0; if(isset($history['incremental_file']['additional_database_option'])) { $custom_option['additional_database_option'] = $history['incremental_file']['additional_database_option']; } $incremental_backup_setting['incremental_history']['incremental_file'] = $custom_option; Mainwp_WPvivid_Extension_DB_Option::get_instance()->wpvivid_update_option($site_id, 'incremental_backup_setting', $incremental_backup_setting); } public function set_incremental_db_setting($site_id, $options){ $incremental_backup_setting = Mainwp_WPvivid_Extension_DB_Option::get_instance()->wpvivid_get_option($site_id, 'incremental_backup_setting', array()); if(empty($incremental_backup_setting)){ $incremental_backup_setting = array(); $history = array(); } else{ $history = isset($incremental_backup_setting['incremental_history']) ? $incremental_backup_setting['incremental_history'] : array(); if(empty($history)){ $history = array(); } } $custom_option['database_option']['database_check'] = isset($options['database_check']) ? $options['database_check'] : 0; $custom_option['database_option']['exclude_table_list'] = isset($options['database_list']) ? $options['database_list'] : array(); $custom_option['themes_option']['themes_check'] = isset($options['themes_check']) ? $options['themes_check'] : 0; $custom_option['themes_option']['exclude_themes_list'] = isset($options['themes_list']) ? $options['themes_list'] : array(); $custom_option['plugins_option']['plugins_check'] = isset($options['plugins_check']) ? $options['plugins_check'] : 0; $custom_option['plugins_option']['exclude_plugins_list'] = isset($options['plugins_list']) ? $options['plugins_list'] : array(); $custom_option['uploads_option']['uploads_check'] = isset($options['uploads_check']) ? $options['uploads_check'] : 0; $custom_option['uploads_option']['exclude_uploads_list'] = isset($options['uploads_list']) ? $options['uploads_list'] : array(); $custom_option['uploads_option']['uploads_extension_list'] = isset($options['upload_extension']) ? $options['upload_extension'] : array(); $custom_option['content_option']['content_check'] = isset($options['content_check']) ? $options['content_check'] : 0; $custom_option['content_option']['exclude_content_list'] = isset($options['content_list']) ? $options['content_list'] : array(); $custom_option['content_option']['content_extension_list'] = isset($options['content_extension']) ? $options['content_extension'] : array(); $custom_option['core_option']['core_check'] = isset($options['core_check']) ? $options['core_check'] : 0; $custom_option['other_option']['other_check'] = isset($options['other_check']) ? $options['other_check'] : 0; $custom_option['other_option']['include_other_list'] = isset($options['other_list']) ? $options['other_list'] : array(); $custom_option['other_option']['other_extension_list'] = isset($options['other_extension']) ? $options['other_extension'] : array(); if(isset($history['incremental_db']['additional_database_option'])) { $custom_option['additional_database_option'] = $history['incremental_db']['additional_database_option']; } $custom_option['additional_database_option']['additional_database_check'] = isset($options['additional_database_check']) ? $options['additional_database_check'] : 0; $incremental_backup_setting['incremental_history']['incremental_db'] = $custom_option; Mainwp_WPvivid_Extension_DB_Option::get_instance()->wpvivid_update_option($site_id, 'incremental_backup_setting', $incremental_backup_setting); } public function set_incremental_remote_retain_count($site_id, $count){ $incremental_backup_setting = Mainwp_WPvivid_Extension_DB_Option::get_instance()->wpvivid_get_option($site_id, 'incremental_backup_setting', array()); if(empty($incremental_backup_setting)){ $incremental_backup_setting = array(); } $incremental_backup_setting['incremental_remote_backup_count'] = $count; Mainwp_WPvivid_Extension_DB_Option::get_instance()->wpvivid_update_option($site_id, 'incremental_backup_setting', $incremental_backup_setting); } public function set_incremental_enable($site_id, $status){ $incremental_backup_setting = Mainwp_WPvivid_Extension_DB_Option::get_instance()->wpvivid_get_option($site_id, 'incremental_backup_setting', array()); if(empty($incremental_backup_setting)){ $incremental_backup_setting = array(); } $incremental_backup_setting['enable_incremental_schedules'] = $status; Mainwp_WPvivid_Extension_DB_Option::get_instance()->wpvivid_update_option($site_id, 'incremental_backup_setting', $incremental_backup_setting); } public function set_incremental_schedules($site_id, $schedules){ $incremental_backup_setting = Mainwp_WPvivid_Extension_DB_Option::get_instance()->wpvivid_get_option($site_id, 'incremental_backup_setting', array()); if(empty($incremental_backup_setting)){ $incremental_backup_setting = array(); } $incremental_backup_setting['incremental_schedules'] = $schedules; Mainwp_WPvivid_Extension_DB_Option::get_instance()->wpvivid_update_option($site_id, 'incremental_backup_setting', $incremental_backup_setting); } public function set_incremental_backup_data($site_id, $data){ $incremental_backup_setting = Mainwp_WPvivid_Extension_DB_Option::get_instance()->wpvivid_get_option($site_id, 'incremental_backup_setting', array()); if(empty($incremental_backup_setting)){ $incremental_backup_setting = array(); } $incremental_backup_setting['incremental_backup_data'] = $data; Mainwp_WPvivid_Extension_DB_Option::get_instance()->wpvivid_update_option($site_id, 'incremental_backup_setting', $incremental_backup_setting); } public function set_incremental_output_msg($site_id, $msg){ $incremental_backup_setting = Mainwp_WPvivid_Extension_DB_Option::get_instance()->wpvivid_get_option($site_id, 'incremental_backup_setting', array()); if(empty($incremental_backup_setting)){ $incremental_backup_setting = array(); } $incremental_backup_setting['incremental_output_msg'] = $msg; Mainwp_WPvivid_Extension_DB_Option::get_instance()->wpvivid_update_option($site_id, 'incremental_backup_setting', $incremental_backup_setting); } public function mwp_wpvivid_custom_backup_data_transfer($options, $data, $type) { if(!isset($data['database_check'])){ $data['database_check'] = 0; } $options['backup_select']['db'] = intval($data['database_check']); if(!isset($data['database_list'])){ $data['database_list'] = array(); } $options['exclude_tables'] = $data['database_list']; if(!isset($data['themes_check'])){ $data['themes_check'] = 0; } $options['backup_select']['themes'] = intval($data['themes_check']); if(!isset($data['themes_list'])){ $data['themes_list'] = array(); } $options['exclude_themes'] = $data['themes_list']; if(!isset($data['plugins_check'])){ $data['plugins_check'] = 0; } $options['backup_select']['plugin'] = intval($data['plugins_check']); if(!isset($data['plugins_list'])){ $data['plugins_list'] = array(); } $options['exclude_plugins'] = $data['plugins_list']; if(!isset($data['uploads_check'])){ $data['uploads_check'] = 0; } $options['backup_select']['uploads'] = intval($data['uploads_check']); $upload_exclude_list = array(); if(isset($data['uploads_list'])) { foreach ($data['uploads_list'] as $key => $value){ $upload_exclude_list[] = $key; } } else{ $data['uploads_list'] = array(); } $options['exclude_uploads'] = $upload_exclude_list; $upload_exclude_file_list=array(); $upload_extension_tmp = array(); if(isset($data['upload_extension']) && !empty($data['upload_extension'])) { $str_tmp = explode(',', $data['upload_extension']); for($index=0; $index<count($str_tmp); $index++){ if(!empty($str_tmp[$index])) { $upload_exclude_file_list[] = '.*\.'.$str_tmp[$index].'$'; $upload_extension_tmp[] = $str_tmp[$index]; } } $data['upload_extension'] = $upload_extension_tmp; } else{ $data['upload_extension'] = array(); } $options['exclude_uploads_files'] = $upload_exclude_file_list; if(!isset($data['content_check'])){ $data['content_check'] = 0; } $options['backup_select']['content'] = intval($data['content_check']); $content_exclude_list=array(); if(isset($data['content_list'])) { foreach ($data['content_list'] as $key => $value){ $content_exclude_list[] = $key; } } else{ $data['content_list'] = array(); } $options['exclude_content'] = $content_exclude_list; $content_exclude_file_list=array(); $content_extension_tmp = array(); if(isset($data['content_extension']) && !empty($data['content_extension'])) { $str_tmp = explode(',', $data['content_extension']); for($index=0; $index<count($str_tmp); $index++){ if(!empty($str_tmp[$index])) { $content_exclude_file_list[] = '.*\.'.$str_tmp[$index].'$'; $content_extension_tmp[] = $str_tmp[$index]; } } $data['content_extension'] = $content_extension_tmp; } else{ $data['content_extension'] = array(); } $options['exclude_content_files'] = $content_exclude_file_list; if(!isset($data['core_check'])){ $data['core_check'] = 0; } $options['backup_select']['core'] = intval($data['core_check']); if(!isset($data['other_check'])){ $data['other_check'] = 0; } $options['backup_select']['other'] = intval($data['other_check']); $other_include_list=array(); if(isset($data['other_list'])) { foreach ($data['other_list'] as $key => $value){ $other_include_list[] = $key; } } else{ $data['other_list'] = array(); } $options['custom_other_root'] = $other_include_list; $other_exclude_file_list=array(); $other_extension_tmp = array(); if(isset($data['other_extension']) && !empty($data['other_extension'])) { $str_tmp = explode(',', $data['other_extension']); for($index=0; $index<count($str_tmp); $index++){ if(!empty($str_tmp[$index])) { $other_exclude_file_list[] = '.*\.'.$str_tmp[$index].'$'; $other_extension_tmp[] = $str_tmp[$index]; } } $data['other_extension'] = $other_extension_tmp; } else{ $data['other_extension'] = array(); } $options['exclude_custom_other_files'] = $other_exclude_file_list; $options['exclude_custom_other']=array(); if(!isset($data['additional_database_check'])){ $data['additional_database_check'] = 0; } $options['backup_select']['additional_db'] = intval($data['additional_database_check']); if($options['backup_select']['additional_db'] === 1){ if(isset($history['additional_database_option']['additional_database_list']) && !empty($history['additional_database_option']['additional_database_list'])) { $options['additional_database_list'] = $history['additional_database_option']['additional_database_list']; } else{ $options['additional_database_list'] = array(); } } return $options; } public function check_incremental_schedule_option($data){ //$ret['schedule']['file_start_time_zone'] = $data['file_start_time_zone']; //$ret['schedule']['db_start_time_zone'] = $data['db_start_time_zone']; $ret['schedule']['incremental_recurrence'] =$data['recurrence']; $ret['schedule']['incremental_recurrence_week'] =$data['recurrence_week']; $ret['schedule']['incremental_recurrence_day'] =$data['recurrence_day']; $ret['schedule']['incremental_files_recurrence'] =$data['incremental_files_recurrence']; $ret['schedule']['incremental_db_recurrence'] =$data['incremental_db_recurrence']; $ret['schedule']['incremental_db_recurrence_week'] = $data['incremental_db_recurrence_week']; $ret['schedule']['incremental_db_recurrence_day'] = $data['incremental_db_recurrence_day']; $ret['schedule']['incremental_backup_status'] = $data['incremental_backup_status']; $ret['schedule']['incremental_files_start_backup'] = $data['incremental_files_start_backup']; /*if(isset($data['custom']['files'])){ $ret['schedule']['backup_files']=array(); $ret['schedule']['backup_files'] = apply_filters('mwp_wpvivid_custom_backup_data_transfer', $ret['schedule']['backup_files'], $data['custom']['files'], 'incremental_backup_file'); } if(isset($data['custom']['db'])){ $ret['schedule']['backup_db']=array(); $ret['schedule']['backup_db'] = apply_filters('mwp_wpvivid_custom_backup_data_transfer', $ret['schedule']['backup_db'], $data['custom']['db'], 'incremental_backup_db'); }*/ $data['save_local_remote']=sanitize_text_field($data['save_local_remote']); if(!empty($data['save_local_remote'])) { if($data['save_local_remote'] == 'remote') { $ret['schedule']['backup']['remote']=1; $ret['schedule']['backup']['local']=0; } else { $ret['schedule']['backup']['remote']=0; $ret['schedule']['backup']['local']=1; } } if(isset($data['backup_prefix']) && !empty($data['backup_prefix'])) { $ret['schedule']['backup']['backup_prefix'] = $data['backup_prefix']; } if(isset($data['db_current_day'])) { $ret['schedule']['db_current_day'] = $data['db_current_day']; } if(isset($data['files_current_day'])) { $ret['schedule']['files_current_day'] = $data['files_current_day']; } $ret['schedule']['files_current_day_hour'] = $data['files_current_day_hour']; $ret['schedule']['files_current_day_minute'] = $data['files_current_day_minute']; $ret['schedule']['db_current_day_hour'] = $data['db_current_day_hour']; $ret['schedule']['db_current_day_minute'] = $data['db_current_day_minute']; $ret['schedule']['backup_db'] = $data['backup_db']; $ret['schedule']['backup_files'] = $data['backup_files']; $ret['schedule']['exclude_files'] = $data['exclude_files']; $ret['schedule']['exclude_file_type'] = $data['exclude_file_type']; return $ret; } public function mwp_add_incremental_schedule($schedule){ $schedule_data=array(); $schedule_data['id']=uniqid('wpvivid_incremental_schedule'); $schedule_data['files_schedule_id']=uniqid('wpvivid_incremental_files_schedule_event'); $schedule_data['db_schedule_id']=uniqid('wpvivid_incremental_db_schedule_event'); $schedule['backup']['ismerge']=1; $schedule['backup']['lock']=0; $schedule_data= $this->mwp_set_incremental_schedule_data($schedule_data,$schedule); $schedules=array(); $schedules[$schedule_data['id']]=$schedule_data; return $schedules; } public function mwp_set_incremental_schedule_data($schedule_data,$schedule){ //$schedule_data['file_start_time_zone'] = $schedule['file_start_time_zone']; //$schedule_data['db_start_time_zone'] = $schedule['db_start_time_zone']; $schedule_data['incremental_recurrence']=$schedule['incremental_recurrence']; $schedule_data['incremental_recurrence_week']=$schedule['incremental_recurrence_week']; $schedule_data['incremental_recurrence_day']=$schedule['incremental_recurrence_day'] ; $schedule_data['incremental_files_recurrence']=$schedule['incremental_files_recurrence']; $schedule_data['incremental_db_recurrence']=$schedule['incremental_db_recurrence']; $schedule_data['incremental_db_recurrence_week']=$schedule['incremental_db_recurrence_week']; $schedule_data['incremental_db_recurrence_day']=$schedule['incremental_db_recurrence_day']; $schedule_data['db_current_day']=$schedule['db_current_day']; $schedule_data['files_current_day']=$schedule['files_current_day']; $schedule_data['incremental_backup_status'] = $schedule['incremental_backup_status']; $schedule_data['incremental_files_start_backup']=$schedule['incremental_files_start_backup']; $schedule_data['files_current_day_hour'] = $schedule['files_current_day_hour']; $schedule_data['files_current_day_minute'] = $schedule['files_current_day_minute']; $schedule_data['db_current_day_hour'] = $schedule['db_current_day_hour']; $schedule_data['db_current_day_minute'] = $schedule['db_current_day_minute']; $schedule_data['backup_files'] = $schedule['backup_files']; $schedule_data['backup_db'] = $schedule['backup_db']; $schedule_data['exclude_files'] = $schedule['exclude_files']; $schedule_data['exclude_file_type'] = $schedule['exclude_file_type']; $schedule_data['backup']=$schedule['backup']; return $schedule_data; } public function set_global_incremental_file_settings($incremental_schedule_mould_name, $options){ $incremental_backup_setting = Mainwp_WPvivid_Extension_DB_Option::get_instance()->wpvivid_get_global_option('incremental_backup_setting', array()); if(empty($incremental_backup_setting)){ $incremental_backup_setting = array(); $history = array(); } else{ $history = isset($incremental_backup_setting['incremental_history']) ? $incremental_backup_setting['incremental_history'] : array(); if(empty($history)){ $history = array(); } } $custom_option['database_option']['database_check'] = isset($options['database_check']) ? $options['database_check'] : 0; $custom_option['themes_option']['themes_check'] = isset($options['themes_check']) ? $options['themes_check'] : 0; $custom_option['plugins_option']['plugins_check'] = isset($options['plugins_check']) ? $options['plugins_check'] : 0; $custom_option['uploads_option']['uploads_check'] = isset($options['uploads_check']) ? $options['uploads_check'] : 0; $upload_extension_tmp = array(); if(isset($options['upload_extension']) && !empty($options['upload_extension'])) { $str_tmp = explode(',', $options['upload_extension']); for($index=0; $index<count($str_tmp); $index++){ if(!empty($str_tmp[$index])) { $upload_extension_tmp[] = $str_tmp[$index]; } } $custom_option['uploads_option']['uploads_extension_list'] = $upload_extension_tmp; } else{ $custom_option['uploads_option']['uploads_extension_list'] = array(); } //$custom_option['uploads_option']['uploads_extension_list'] = isset($options['upload_extension']) ? $options['upload_extension'] : array(); $custom_option['content_option']['content_check'] = isset($options['content_check']) ? $options['content_check'] : 0; $content_extension_tmp = array(); if(isset($options['content_extension']) && !empty($options['content_extension'])) { $str_tmp = explode(',', $options['content_extension']); for($index=0; $index<count($str_tmp); $index++){ if(!empty($str_tmp[$index])) { $content_extension_tmp[] = $str_tmp[$index]; } } $custom_option['content_option']['content_extension_list'] = $content_extension_tmp; } else{ $custom_option['content_option']['content_extension_list'] = array(); } //$custom_option['content_option']['content_extension_list'] = isset($options['content_extension']) ? $options['content_extension'] : array(); $custom_option['core_option']['core_check'] = isset($options['core_check']) ? $options['core_check'] : 0; $incremental_backup_setting[$incremental_schedule_mould_name]['incremental_history']['incremental_file'] = $custom_option; Mainwp_WPvivid_Extension_DB_Option::get_instance()->wpvivid_update_global_option('incremental_backup_setting', $incremental_backup_setting); } public function set_global_incremental_db_settings($incremental_schedule_mould_name, $options){ $incremental_backup_setting = Mainwp_WPvivid_Extension_DB_Option::get_instance()->wpvivid_get_global_option('incremental_backup_setting', array()); if(empty($incremental_backup_setting)){ $incremental_backup_setting = array(); $history = array(); } else{ $history = isset($incremental_backup_setting['incremental_history']) ? $incremental_backup_setting['incremental_history'] : array(); if(empty($history)){ $history = array(); } } $custom_option['database_option']['database_check'] = isset($options['database_check']) ? $options['database_check'] : 0; $custom_option['themes_option']['themes_check'] = isset($options['themes_check']) ? $options['themes_check'] : 0; $custom_option['plugins_option']['plugins_check'] = isset($options['plugins_check']) ? $options['plugins_check'] : 0; $custom_option['uploads_option']['uploads_check'] = isset($options['uploads_check']) ? $options['uploads_check'] : 0; $custom_option['uploads_option']['uploads_extension_list'] = isset($options['upload_extension']) ? $options['upload_extension'] : array(); $custom_option['content_option']['content_check'] = isset($options['content_check']) ? $options['content_check'] : 0; $custom_option['content_option']['content_extension_list'] = isset($options['content_extension']) ? $options['content_extension'] : array(); $custom_option['core_option']['core_check'] = isset($options['core_check']) ? $options['core_check'] : 0; $incremental_backup_setting[$incremental_schedule_mould_name]['incremental_history']['incremental_db'] = $custom_option; Mainwp_WPvivid_Extension_DB_Option::get_instance()->wpvivid_update_global_option('incremental_backup_setting', $incremental_backup_setting); } public function set_global_incremental_remote_retain_count($incremental_schedule_mould_name, $count){ $incremental_backup_setting = Mainwp_WPvivid_Extension_DB_Option::get_instance()->wpvivid_get_global_option('incremental_backup_setting', array()); if(empty($incremental_backup_setting)){ $incremental_backup_setting = array(); } $incremental_backup_setting[$incremental_schedule_mould_name]['incremental_remote_backup_count'] = $count; Mainwp_WPvivid_Extension_DB_Option::get_instance()->wpvivid_update_global_option('incremental_backup_setting', $incremental_backup_setting); } public function set_global_incremental_schedules($incremental_schedule_mould_name, $schedule){ $incremental_backup_setting = Mainwp_WPvivid_Extension_DB_Option::get_instance()->wpvivid_get_global_option('incremental_backup_setting', array()); if(empty($incremental_backup_setting)){ $incremental_backup_setting = array(); } $ret = $this->check_incremental_schedule_option($schedule); $schedules = $this->mwp_add_incremental_schedule($ret['schedule']); $incremental_backup_setting[$incremental_schedule_mould_name]['incremental_schedules'] = $schedules; Mainwp_WPvivid_Extension_DB_Option::get_instance()->wpvivid_update_global_option('incremental_backup_setting', $incremental_backup_setting); } public function mwp_check_white_label_option($data) { $ret['result']='failed'; if(!isset($data['white_label_display'])) { $ret['error']=__('The white label is required.', 'wpvivid'); return $ret; } $data['white_label_display']=sanitize_text_field($data['white_label_display']); if(empty($data['white_label_display'])) { $ret['error']=__('The white label is required.', 'wpvivid'); return $ret; } if(!isset($data['white_label_slug'])) { $ret['error']=__('The slug is required.', 'wpvivid'); return $ret; } $data['white_label_slug']=sanitize_text_field($data['white_label_slug']); if(empty($data['white_label_slug'])) { $ret['error']=__('The slug is required.', 'wpvivid'); return $ret; } if(!isset($data['white_label_support_email'])) { $ret['error']=__('The support email is required.', 'wpvivid'); return $ret; } $data['white_label_support_email']=sanitize_text_field($data['white_label_support_email']); if(empty($data['white_label_support_email'])) { $ret['error']=__('The support email is required.', 'wpvivid'); return $ret; } if(!isset($data['white_label_website'])) { $ret['error']=__('The website is required.', 'wpvivid'); return $ret; } $data['white_label_website']=sanitize_text_field($data['white_label_website']); if(empty($data['white_label_website'])) { $ret['error']=__('The website is required.', 'wpvivid'); return $ret; } $ret['result']='success'; return $ret; } public function mwp_ajax_check_security($role='administrator') { check_ajax_referer( 'wpvivid_mainwp_ajax', 'nonce' ); if(!is_admin()||!current_user_can($role)) die(); } public function mwp_check_wpvivid_pro($plugins, $website_id){ $check_pro = false; $is_pro=Mainwp_WPvivid_Extension_Option::get_instance()->wpvivid_get_single_option($website_id, 'is_pro', false); if($is_pro){ $check_pro = true; } return $check_pro; } public function get_websites() { $websites = apply_filters( 'mainwp_getsites', $this->childFile, $this->childKey, null ); $sites_ids = array(); if ( is_array( $websites ) ) { foreach ( $websites as $site ) { $sites_ids[] = $site['id']; } unset( $websites ); } $option = array( 'plugin_upgrades' => true, 'plugins' => true ); $selected_group=array(); if ( isset( $_POST['mwp_wpvivid_plugin_groups_select'] ) && $_POST['mwp_wpvivid_plugin_groups_select']!=0) { $selected_group[] = intval(sanitize_text_field($_POST['mwp_wpvivid_plugin_groups_select'])); } if(!empty($selected_group)) { $sites_ids=array(); } $dbwebsites = apply_filters( 'mainwp_getdbsites', $this->childFile, $this->childKey, $sites_ids, $selected_group, $option ); $websites_with_plugin=array(); foreach ( $dbwebsites as $website ) { if ( $website ) { $plugins = json_decode( $website->plugins, 1 ); if ( is_array( $plugins ) && count( $plugins ) != 0 ) { $site = array('id' => $website->id, 'name' => $website->name, 'url' => $website->url); $check_pro = $this->mwp_check_wpvivid_pro($plugins, $website->id); if(!$check_pro) { $site['pro'] = 0; $site['install'] = 0; $site['active'] = 0; $site['login'] = 0; $site['version'] = 'N/A'; $site['slug'] = 'wpvivid-backuprestore'; //wpvivid-backup-pro $site['individual'] = 0; $site['status'] = 'Not Install'; $site['class'] = 'need-install'; foreach ($plugins as $plugin) { $reg_string = 'wpvivid-backuprestore/wpvivid-backuprestore.php'; if ((strcmp($plugin['slug'], $reg_string) === 0)) { $site['pro'] = 0; $site['install'] = 1; $site['slug'] = $plugin['slug']; $site['version'] = esc_html($plugin['version']).' (WPvivid Backup)'; $individual = Mainwp_WPvivid_Extension_Option::get_instance()->wpvivid_get_single_option($site['id'], 'individual', false); if ($individual) { $site['individual'] = 1; } else { $site['individual'] = 0; } if ($plugin['active']) { $site['active'] = 1; $plugin_upgrades = json_decode($website->plugin_upgrades, 1); if (is_array($plugin_upgrades) && count($plugin_upgrades) > 0) { if (isset($plugin_upgrades['wpvivid-backuprestore/wpvivid-backuprestore.php'])) { $upgrade = $plugin_upgrades['wpvivid-backuprestore/wpvivid-backuprestore.php']; if (isset($upgrade['update'])) { $site['upgrade'] = $upgrade['update']; $site['status'] = 'New version available'; $site['class'] = 'need-update'; } else{ $site['status'] = 'Latest version'; $site['class'] = ''; } } else{ $site['status'] = 'Latest version'; $site['class'] = ''; } } else{ $site['status'] = 'Latest version'; $site['class'] = ''; } } else { $site['active'] = 0; $site['status'] = 'Not Actived'; $site['class'] = 'need-active'; } //$site['report'] = Mainwp_WPvivid_Extension_Option::get_instance()->get_report_addon($site['id']); //$site['sync_remote_setting'] = Mainwp_WPvivid_Extension_Option::get_instance()->get_sync_remote_setting($site['id']); break; } } if (isset($_GET['search']) && !empty($_GET['search'])) { $find = trim(sanitize_text_field($_GET['search'])); if (stripos($site['name'], $find) !== false || stripos($site['url'], $find) !== false) { $websites_with_plugin[$site['id']] = $site; } } else { $websites_with_plugin[$site['id']] = $site; } } } } } return $websites_with_plugin; } public function mwp_get_child_websites(){ $websites = apply_filters( 'mainwp_getsites', $this->childFile, $this->childKey, null ); $sites_ids = array(); if ( is_array( $websites ) ) { foreach ( $websites as $site ) { $sites_ids[] = $site['id']; } unset( $websites ); } $option = array( 'plugin_upgrades' => true, 'plugins' => true ); $selected_group=array(); if ( isset( $_POST['mwp_wpvivid_plugin_groups_select'] ) && $_POST['mwp_wpvivid_plugin_groups_select']!=0) { $selected_group[] = intval(sanitize_text_field($_POST['mwp_wpvivid_plugin_groups_select'])); } if(!empty($selected_group)) { $sites_ids=array(); } $dbwebsites = apply_filters( 'mainwp_getdbsites', $this->childFile, $this->childKey, $sites_ids, $selected_group, $option ); return $dbwebsites; } public function get_websites_ex() { $websites = apply_filters( 'mainwp_getsites', $this->childFile, $this->childKey, null ); $sites_ids = array(); if ( is_array( $websites ) ) { foreach ( $websites as $site ) { $sites_ids[] = $site['id']; } unset( $websites ); } $option = array( 'plugin_upgrades' => true, 'plugins' => true ); $selected_group=array(); if ( isset( $_POST['mwp_wpvivid_plugin_groups_select'] ) && $_POST['mwp_wpvivid_plugin_groups_select']!=0) { $selected_group[] = intval(sanitize_text_field($_POST['mwp_wpvivid_plugin_groups_select'])); } if(!empty($selected_group)) { $sites_ids=array(); } $login_options = $this->get_global_login_addon(); if($login_options !== false && isset($login_options['wpvivid_pro_login_cache'])){ $addons_cache = $login_options['wpvivid_pro_login_cache']; if(isset($addons_cache['pro']['version'])){ $latest_version = $addons_cache['pro']['version']; } else if(isset($addons_cache['dashboard']['version'])){ $latest_version = $addons_cache['dashboard']['version']; } else{ $latest_version = false; } } else{ $latest_version = false; } $dbwebsites = apply_filters( 'mainwp_getdbsites', $this->childFile, $this->childKey, $sites_ids, $selected_group, $option ); $websites_with_plugin=array(); foreach ( $dbwebsites as $website ){ if ( $website ) { $plugins = json_decode( $website->plugins, 1 ); if ( is_array( $plugins ) && count( $plugins ) != 0 ) { $site = array('id' => $website->id, 'name' => $website->name, 'url' => $website->url); $check_pro = $this->mwp_check_wpvivid_pro($plugins, $website->id); $site['pro'] = 1; $site['slug'] = 'wpvivid-backup-pro'; $site['version'] = 'N/A'; $site['individual'] = 0; $site['install-wpvivid'] = 0; $site['active-wpvivid'] = 0; $site['install-wpvivid-pro'] = 0; $site['active-wpvivid-pro'] = 0; $site['login'] = 0; $site['check-status'] = 0; $site['status'] = 'WPvivid Backup Pro not claimed'; $site['class'] = 'need-install-wpvivid'; $site['class-update'] = ''; $wpvivid_need_update = false; /*$wpvivid_status = false; foreach ($plugins as $plugin){ $reg_string = 'wpvivid-backuprestore/wpvivid-backuprestore.php'; if ((strcmp($plugin['slug'], $reg_string) === 0)) { $site['install-wpvivid'] = 1; if ($plugin['active']) { $site['active-wpvivid'] = 1; $plugin_upgrades = json_decode($website->plugin_upgrades, 1); if (is_array($plugin_upgrades) && count($plugin_upgrades) > 0) { if (isset($plugin_upgrades['wpvivid-backuprestore/wpvivid-backuprestore.php'])) { $upgrade = $plugin_upgrades['wpvivid-backuprestore/wpvivid-backuprestore.php']; if (isset($upgrade['update'])) { $site['status'] = 'New version available'; $site['class-update'] = 'need-update-wpvivid'; $wpvivid_need_update = true; } } } $wpvivid_status = true; } else { $site['active-wpvivid'] = 0; $site['status'] = 'WPvivid Backup Pro not claimed'; $site['class'] = 'need-active-wpvivid'; } break; } }*/ //if($wpvivid_status) //{ $site['status'] = 'WPvivid Backup Pro not claimed'; $site['class'] = 'need-install-wpvivid-pro'; foreach ($plugins as $plugin) { $reg_string = 'wpvivid-backup-pro/wpvivid-backup-pro.php'; if ((strcmp($plugin['slug'], $reg_string) === 0)) { $site['install-wpvivid-pro'] = 1; $site['slug'] = $plugin['slug']; $individual = Mainwp_WPvivid_Extension_Option::get_instance()->wpvivid_get_single_option($site['id'], 'individual', false); if ($individual) { $site['individual'] = 1; } else { $site['individual'] = 0; } if ($plugin['active']) { $site['active-wpvivid-pro'] = 1; $wpvivid_pro_need_update_pro = false; if($latest_version !== false){ if(version_compare($latest_version, $plugin['version'],'>')){ $is_login_pro = $this->get_is_login($site['id']); if($is_login_pro !== false){ if(intval($is_login_pro) !== 1){ $wpvivid_pro_need_update_pro = true; $site['status'] = 'WPvivid Backup Pro not claimed'; $site['class'] = 'need-install-wpvivid-pro'; } } else{ $wpvivid_pro_need_update_pro = true; $site['status'] = 'WPvivid Backup Pro not claimed'; $site['class'] = 'need-install-wpvivid-pro'; } } } if(!$wpvivid_pro_need_update_pro){ $is_login_pro = $this->get_is_login($site['id']); if($is_login_pro !== false){ if(intval($is_login_pro) === 1){ $site['login'] = 1; $need_update = $this->get_need_update($site['id']); if($need_update == '1'){ $site['status'] = 'New version available'; $site['class-update'] = 'need-update-wpvivid-pro'; $site['class'] = ''; } else{ if(!$wpvivid_need_update) { $site['status'] = 'Latest version'; $site['class'] = ''; $site['check-status'] = 1; } else{ $site['status'] = 'New version available'; $site['class'] = ''; $site['class-update'] = 'need-update-wpvivid'; } } $site['version'] = $this->get_current_version($site['id']); $site['version'] = $site['version'].' (WPvivid Backup Pro)'; } else{ $site['login'] = 0; $site['status'] = 'WPvivid Backup Pro not claimed'; $site['class'] = 'need-login'; } } else{ $site['status'] = 'WPvivid Backup Pro not claimed'; $site['class'] = 'need-login'; } } } else { $site['active-wpvivid-pro'] = 0; $site['status'] = 'WPvivid Backup Pro not claimed'; $site['class'] = 'need-active-wpvivid-pro'; } break; } } //} if (isset($_GET['search']) && !empty($_GET['search'])) { $find = trim(sanitize_text_field($_GET['search'])); if (stripos($site['name'], $find) !== false || stripos($site['url'], $find) !== false) { $websites_with_plugin[$site['id']] = $site; } } else { $websites_with_plugin[$site['id']] = $site; } } } } return $websites_with_plugin; } public function render_sync_websites_page($submit_id, $check_addon = false, $schedule_mould_name = '') { global $mainwp_wpvivid_extension_activator; if(intval($check_addon) === 1){ $websites_with_plugin=$mainwp_wpvivid_extension_activator->get_websites_ex(); } else{ $websites_with_plugin=$mainwp_wpvivid_extension_activator->get_websites(); } ?> <div style="padding: 10px;"> <h2 style="margin-top: 10px;">Saving settings to child sites ...</h2><br> <?php if($submit_id === 'mwp_wpvivid_sync_schedule' && intval($check_addon) === 1){ ?> <div class="mwp-wpvivid-block-bottom-space"> <span>Schedule Name:</span><span class="mwp_wpvivid_schedule_mould_name"><?php echo esc_html($schedule_mould_name); ?></span> </div> <div class="mwp-wpvivid-block-bottom-space"> <div> <label> <input type="radio" name="mwp_wpvivid_default_schedule" value="default_only" checked /> <span>Set as the only active schedule (This will disable and replace existing schedules on the child sites)</span> </label> </div> <div> <label> <input type="radio" name="mwp_wpvivid_default_schedule" value="default_append" /> <span>Set as an additional active schedule (This will add the new schedule to the child sites and will not disable existing schedules)</span> </label> </div> </div> <?php } else if($submit_id === 'mwp_wpvivid_sync_incremental_schedule' && intval($check_addon) === 1){ ?> <div class="mwp-wpvivid-block-bottom-space"> <span>Schedule Name:</span><span class="mwp_wpvivid_schedule_mould_name"><?php echo esc_html($schedule_mould_name); ?></span> </div> <div class="mwp-wpvivid-block-bottom-space"> <span>This will disable all existing schedules on the child sites.</span> </div> <?php } ?> <table class="ui selectable unstackable table mainwp-with-preview-table mainwp-manage-wpsites-table"> <thead> <tr> <th class="no-sort collapsing check-column"><span class="ui checkbox"><input type="checkbox" checked /></span></th> <th><?php esc_html_e( 'Site' ); ?></th> <th><?php esc_html_e( 'URL' ); ?></th> <th><?php esc_html_e( 'Status' ); ?></th> </tr> </thead> <tbody class="list:sites"> <?php if ( is_array( $websites_with_plugin ) && count( $websites_with_plugin ) > 0 ) { foreach ( $websites_with_plugin as $website ) { $website_id = $website['id']; if(intval($check_addon) !== intval($website['pro'])) { continue; } if(intval($check_addon) === 1) { if(!$website['check-status']) { continue; } } else { if(!$website['install']) { continue; } if(!$website['active']) { continue; } } if($website['individual']) { continue; } ?> <tr class="mwp-wpvivid-sync-row"> <td class="check-column" website-id="<?php echo esc_attr($website_id); ?>"><span class="ui checkbox"><input type="checkbox" name="checked[]" checked /></span></td> <td> <a href="admin.php?page=managesites&dashboard=<?php echo esc_html($website_id); ?>"><?php echo esc_html(stripslashes($website['name'])); ?></a><br/> </td> <td> <a href="<?php echo esc_attr($website['url']); ?>" target="_blank"><?php echo esc_html($website['url']); ?></a><br/> </td> <td class="mwp-wpvivid-progress" website-id="<?php echo esc_attr($website_id); ?>"> <span>Ready to update</span> </td> </tr> <?php } } else { echo '<tr><td colspan="9">No websites were found with the WPvivid Backup plugin installed.</td></tr>'; } ?> </tbody> </table> <input class="ui green mini button" id="<?php echo esc_attr($submit_id) ?>" type="button" value="<?php esc_attr_e('Start Syncing Changes', 'mainwp-wpvivid-extension'); ?>"/> </div> <?php } public function render_sync_websites_remote_page($submit_id, $check_addon = false){ global $mainwp_wpvivid_extension_activator; $websites_with_plugin=$mainwp_wpvivid_extension_activator->get_websites_ex(); ?> <div style="padding: 10px;"> <h2 style="margin-top: 10px;">Saving settings to child sites ...</h2><br> <table class="ui single line table"> <thead> <tr> <th class="no-sort collapsing check-column"><span class="ui checkbox"><input type="checkbox" checked /></span></th> <th><?php esc_html_e( 'Site' ); ?></th> <th><?php esc_html_e( 'URL' ); ?></th> <th><?php esc_html_e(' Custom Path' ); ?></th> <th><?php esc_html_e( 'Status' ); ?></th> </tr> </thead> <tbody class="list:sites" id="mwp_wpvivid_sync_remote_list"> <?php if ( is_array( $websites_with_plugin ) && count( $websites_with_plugin ) > 0 ) { foreach ( $websites_with_plugin as $website ) { $website_id = $website['id']; if(!$website['install']) { continue; } if(!$website['active']) { continue; } if(intval($check_addon) !== intval($website['pro'])) { continue; } if(intval($check_addon) === 1) { if(!$website['login']) { continue; } } if($website['individual']) { continue; } ?> <tr class="mwp-wpvivid-sync-row"> <td class="check-column" website-id="<?php echo esc_attr($website_id); ?>"><span class="ui checkbox"><input type="checkbox" name="checked[]" checked /></span></td> <td> <a href="admin.php?page=managesites&dashboard=<?php echo esc_url($website_id); ?>"><?php echo esc_html(stripslashes($website['name'])); ?></a><br/> </td> <td> <a href="<?php echo esc_url($website['url']); ?>" target="_blank"><?php echo esc_html($website['url']); ?></a><br/> </td> <td> <span>Domain</span> <input class="ui green mini button remote-path-edit" type="button" value="<?php esc_attr_e('Edit', 'mainwp-wpvivid-extension'); ?>" /> </td> <td class="mwp-wpvivid-progress" website-id="<?php echo esc_attr($website_id); ?>"> <span>Ready to update</span> </td> </tr> <?php } } else { echo '<tr><td colspan="9">No websites were found with the WPvivid Backup plugin installed.</td></tr>'; } ?> </tbody> <tfoot> <tr> <th class="row-title" colspan="5"><input class="ui green mini button" id="<?php echo esc_attr($submit_id) ?>" type="button" value="<?php esc_attr_e('Start Syncing Changes', 'mainwp-wpvivid-extension'); ?>"/></th> </tr> </tfoot> </table> </div> <?php } public function render_check_report_page($website_id, $pro, $website_name){ $report = Mainwp_WPvivid_Extension_DB_Option::get_instance()->wpvivid_get_option($website_id, 'report_addon', array()); ?> <div style="padding: 10px;"> <div class="mwp-wpvivid-block-bottom-space">Note: The list below includes the last 10 backup information.</div> <div class="mwp-wpvivid-block-bottom-space"><span>Site Title: </span><span><?php echo esc_html($website_name); ?></span></div> <table class="widefat mwp-wpvivid-block-bottom-space"> <thead> <th>Backup Time</th> <th>Status</th> </thead> <tbody> <?php if(isset($report) && !empty($report)) { usort($report, function($a, $b){ if($a['backup_time'] === $b['backup_time']){ return 0; } else if($a['backup_time'] > $b['backup_time']){ return -1; } else{ return 1; } }); $time_zone=Mainwp_WPvivid_Extension_Option::get_instance()->wpvivid_get_single_option($website_id, 'time_zone', ''); if(empty($time_zone)){ $time_zone = 0; } foreach ($report as $task_id => $report_option) { if(isset($report_option['task_id']) && !empty($report_option['task_id'])) { ?> <tr> <td><?php echo esc_html(date("H:i:s - m/d/Y", $report_option['backup_time'] + $time_zone * 60 * 60)); ?></td> <td><?php echo esc_html($report_option['status']); ?></td> </tr> <?php } } } ?> </tbody> </table> <div> <a href="admin.php?page=Extensions-Wpvivid-Backup-Mainwp&tab=dashboard" class="ui green mini button">Return to WPvivid Backup Dashboard</a> </div> </div> <?php } } global $mainwp_wpvivid_extension_activator; $mainwp_wpvivid_extension_activator = new Mainwp_WPvivid_Extension_Activator(); wpvivid-backup-mainwp-db-option.php 0000644 00000017346 15133715745 0013420 0 ustar 00 <?php class Mainwp_WPvivid_Extension_DB_Option { private static $instance = null; private $table_prefix; static function get_instance() { if ( null == Mainwp_WPvivid_Extension_DB_Option::$instance ) { Mainwp_WPvivid_Extension_DB_Option::$instance = new Mainwp_WPvivid_Extension_DB_Option(); } return Mainwp_WPvivid_Extension_DB_Option::$instance; } function __construct() { global $wpdb; $this->table_prefix = $wpdb->prefix . 'mainwp_'; } function get_table_name( $suffix ) { return $this->table_prefix . $suffix; } function init_db_options() { global $wpdb; $charset_collate = $wpdb->get_charset_collate(); if(!class_exists('dbDelta')) require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); $query='CREATE TABLE `'.$this->get_table_name('wpvividmeta').'` ( `meta_id` bigint(20) unsigned NOT NULL auto_increment, `site_id` int(11) NOT NULL, `option_name` longtext NOT NULL DEFAULT "", `option_value` longtext NOT NULL DEFAULT "", PRIMARY KEY (`meta_id`) ) ' . $charset_collate; dbDelta( $query ); $query='CREATE TABLE `'.$this->get_table_name('wpvivid_global_options').'` ( `option_id` bigint(20) unsigned NOT NULL auto_increment, `option_name` longtext NOT NULL DEFAULT "", `option_value` longtext NOT NULL DEFAULT "", PRIMARY KEY (`option_id`) ) ' . $charset_collate; dbDelta( $query ); } function import_settings() { global $wpdb; $sql_site_id = 'SELECT site_id FROM ' . $this->get_table_name( 'wpvivid' ) . ' GROUP BY site_id'; $option_site_id = $wpdb->get_results( $sql_site_id,ARRAY_A ); if(isset($option_site_id) && !empty($option_site_id)){ foreach ($option_site_id as $key => $value){ $site_id = $value['site_id']; $is_imported = $this->wpvivid_get_option($site_id, 'is_imported', false); if(!$is_imported) { $need_import_key = array('backup_custom_setting', 'schedule', 'schedule_addon', 'remote', 'remote_addon', 'settings', 'settings_addon', 'report_addon', 'sync_remote_setting'); $sql = 'SELECT * FROM ' . $this->get_table_name('wpvivid') . ' WHERE `site_id` = ' . $site_id; $options = $wpdb->get_results($sql, ARRAY_A); if (isset($options[0]) && !empty($options[0])) { foreach ($need_import_key as $option_name) { if (isset($options[0][$option_name])) { $this->wpvivid_update_option($site_id, $option_name, maybe_unserialize($options[0][$option_name])); } } } $this->wpvivid_update_option($site_id, 'is_imported', 1); } } } } function wpvivid_update_option($site_id, $option, $value) { $value = maybe_serialize($value); global $wpdb; $table_name = $this->get_table_name('wpvividmeta'); $row = $wpdb->get_row( $wpdb->prepare( "SELECT option_value FROM $table_name WHERE site_id = %d AND option_name = %s LIMIT 1", $site_id, $option ) ); if ( is_object( $row ) ) { $data['option_value'] = $value; $wpdb->update($this->get_table_name('wpvividmeta'), $data, array( 'site_id' => $site_id, 'option_name' => $option )); } else{ $data['site_id'] = $site_id; $data['option_name'] = $option; $data['option_value'] = $value; $wpdb->insert( $this->get_table_name( 'wpvividmeta' ), $data ); } } function wpvivid_get_option($site_id, $option, $default = false) { global $wpdb; $table_name = $this->get_table_name('wpvividmeta'); $row = $wpdb->get_row( $wpdb->prepare( "SELECT option_value FROM $table_name WHERE site_id = %d AND option_name = %s LIMIT 1", $site_id, $option ) ); if ( is_object( $row ) ) { $value = $row->option_value; } else{ $value = $default; } $value = maybe_unserialize( $value ); return $value; } function wpvivid_sync_options($site_id, $options) { $is_imported = $this->wpvivid_get_option($site_id, 'is_imported', false); if($is_imported) { foreach ($options as $key => $value) { $this->wpvivid_update_option($site_id, $key, $value); } } } function import_global_settings() { $is_imported = $this->wpvivid_get_global_option('is_imported', false); if(!$is_imported){ $need_import_key = array('global', 'select_pro', 'sync_init_addon_first', 'switch_pro_setting_page', 'backup_custom_setting', 'remote', 'remote_addon', 'schedule', 'schedule_addon', 'settings_addon', 'login_addon', 'settings'); global $wpdb; $sql = 'SELECT * FROM ' . $this->get_table_name( 'wpvivid_global' ) . ' WHERE `global` = 1 '; $options = $wpdb->get_results( $sql,ARRAY_A ); if(isset($options[0]) && !empty($options[0])){ foreach ($need_import_key as $option_name) { if (isset($options[0][$option_name])) { $this->wpvivid_update_global_option($option_name, maybe_unserialize($options[0][$option_name])); } } } $this->wpvivid_update_global_option('is_imported', 1); } } function wpvivid_update_global_option($option, $value) { $value = maybe_serialize($value); global $wpdb; $table_name = $this->get_table_name('wpvivid_global_options'); $row = $wpdb->get_row( $wpdb->prepare( "SELECT option_value FROM $table_name WHERE option_name = %s LIMIT 1", $option ) ); if ( is_object( $row ) ) { $data['option_value'] = $value; $wpdb->update($this->get_table_name('wpvivid_global_options'), $data, array( 'option_name' => $option )); } else{ $data['option_name'] = $option; $data['option_value'] = $value; $wpdb->insert( $this->get_table_name( 'wpvivid_global_options' ), $data ); } } function wpvivid_get_global_option($option, $default = false) { global $wpdb; $table_name = $this->get_table_name('wpvivid_global_options'); $row = $wpdb->get_row( $wpdb->prepare( "SELECT option_value FROM $table_name WHERE option_name = %s LIMIT 1", $option ) ); if ( is_object( $row ) ) { $value = $row->option_value; } else{ $value = $default; } $value = maybe_unserialize( $value ); return $value; } function wpvivid_first_init_schedule_to_module() { $first_init_mould = $this->wpvivid_get_global_option('init_schedule_mould_first', false); if(empty($first_init_mould)){ $global_schedules = $this->wpvivid_get_global_option('schedule_addon', array()); if(!empty($global_schedules)){ $schedule_mould = array(); $schedule_mould_name = 'schedule-mould-1'; $schedule_mould[$schedule_mould_name] = $global_schedules; $this->wpvivid_update_global_option('schedule_mould_addon', $schedule_mould); } $this->wpvivid_update_global_option('init_schedule_mould_first', 1); } } } wpvivid-backup-mainwp-subpage.php 0000644 00000245462 15133715745 0013155 0 ustar 00 <?php class Mainwp_WPvivid_Extension_Subpage { static public function renderSubpage() { global $mainwp_wpvivid_extension_activator; if (isset($_GET['id']) && !empty($_GET['id'])) { $sites_ids[] = sanitize_text_field($_GET['id']); if($mainwp_wpvivid_extension_activator->check_site_id_secure(sanitize_text_field($_GET['id']))) { $option = array('plugin_upgrades' => true, 'plugins' => true); global $mainwp_wpvivid_extension_activator; $dbwebsites = apply_filters('mainwp_getdbsites', $mainwp_wpvivid_extension_activator->childFile, $mainwp_wpvivid_extension_activator->childKey, $sites_ids, array(), $option); $activated = false; foreach ($dbwebsites as $website) { $plugins = json_decode($website->plugins, 1); if (is_array($plugins) && count($plugins) != 0) { $check_pro = $mainwp_wpvivid_extension_activator->mwp_check_wpvivid_pro($plugins, $website->id); foreach ($plugins as $plugin) { if ((strcmp($plugin['slug'], "wpvivid-backuprestore/wpvivid-backuprestore.php") === 0)) { if ($plugin['active']) { $activated = true; } break; } } } break; } if(!$activated){ ?> <div class="ui yellow message">WPvivid backup plugin is not installed or activated on the site.</div> <?php return; } } ?> <script> function mwp_wpvivid_save_override(site_id) { var individual = 0; if (document.getElementById('mwp_wpvivid_override_settings').checked) { individual = 1; } else { individual = 0; } var ajax_data = { 'action': 'mwp_wpvivid_set_individual', 'individual': individual, 'site_id': site_id }; mwp_wpvivid_post_request(ajax_data, function (data) { try { var jsonarray = jQuery.parseJSON(data); if (jsonarray.result === 'success') { location.reload(); } else { alert(jsonarray.error); } } catch (err) { alert(err); } }, function (XMLHttpRequest, textStatus, errorThrown) { var error_message = mwp_wpvivid_output_ajaxerror('changing base settings', textStatus, errorThrown); alert(error_message); }); } function mwp_wpvivid_click_remote_page() { <?php if($check_pro) { $white_label_setting = Mainwp_WPvivid_Extension_DB_Option::get_instance()->wpvivid_get_option(sanitize_text_field($_GET['id']), 'white_label_setting', array()); $is_mu = Mainwp_WPvivid_Extension_DB_Option::get_instance()->wpvivid_get_option(sanitize_text_field($_GET['id']), 'is_mu', array()); if(!$white_label_setting){ if($is_mu) { $location = 'network/admin.php?page=wpvivid-remote'; } else { $location = 'admin.php?page=wpvivid-remote'; } } else{ $slug = strtolower($white_label_setting['white_label_slug']); $slug_page = strtolower($white_label_setting['white_label_slug']); if($is_mu) { $location = 'network/admin.php?page='.$slug.'-remote'; } else { $location = 'admin.php?page='.$slug.'-remote'; } } } else { $location = 'admin.php?page=WPvivid'; } ?> var location = "admin.php?page=SiteOpen&newWindow=yes&websiteid=<?php echo esc_attr($_GET['id']); ?>&location=<?php echo esc_attr(base64_encode($location)); ?>&_opennonce=<?php echo esc_attr(wp_create_nonce( 'mainwp-admin-nonce' )); ?>"; window.open(location, '_blank'); } </script> <?php $override = ''; $individual = Mainwp_WPvivid_Extension_Option::get_instance()->wpvivid_get_single_option(sanitize_text_field($_GET['id']), 'individual', false); if(empty($individual)){ $individual = false; } if ($individual) { $override = 'checked'; } ?> <div class="ui labeled icon inverted menu mainwp-sub-submenu" id="mainwp-wpvivid-menu"> <?php self::mainwp_wpvivid_add_tab_backup(); if($check_pro){ self::mainwp_wpvivid_add_tab_backup_restore(); } self::mainwp_wpvivid_add_tab_schedule(); self::mainwp_wpvivid_add_tab_setting(); if($check_pro){ self::mainwp_wpvivid_add_tab_capability(); self::mainwp_wpvivid_add_tab_white_label(); } self::mainwp_wpvivid_add_tab_remote(); ?> </div> <div> <div style="background: #fff; margin: 10px 10px 0 10px;"> <div class="postbox" style="padding: 10px; margin-bottom: 0;"> <div style="float: left; margin-top: 7px; margin-right: 25px;"><?php esc_html_e('Override Settings'); ?></div> <div class="ui toggle checkbox" style="float: left; margin-top:4px; margin-right: 10px;"> <input type="checkbox" id="mwp_wpvivid_override_settings" <?php echo esc_attr($override); ?> /> <label for="mwp_wpvivid_override_settings"></label> </div> <div style="float: left;"><input class="ui green mini button" type="button" value="Save" onclick="mwp_wpvivid_save_override(<?php echo esc_js(sanitize_key($_GET['id'])); ?>)" /></div> <div style="clear: both;"></div> </div> </div> <div style="clear: both;"></div> <?php self::mainwp_wpvivid_add_page_backup($check_pro); if($check_pro){ self::mainwp_wpvivid_add_page_backup_restore($check_pro); } self::mainwp_wpvivid_add_page_schedule($check_pro); self::mainwp_wpvivid_add_page_setting($check_pro); if($check_pro){ self::mainwp_wpvivid_add_page_capability($check_pro); self::mainwp_wpvivid_add_page_white_label($check_pro); } ?> </div> <?php } else{ ?> <div style="padding: 10px; background: #fff;">Not a valid website.</div> <?php } } static function mainwp_wpvivid_add_tab_backup(){ ?> <a href="#" id="mwp_wpvivid_tab_backup" class="item active" onclick="mwp_switch_wpvivid_tab('backup');"><?php esc_html_e('Backup'); ?></a> <?php } static function mainwp_wpvivid_add_tab_backup_restore(){ ?> <a href="#" id="mwp_wpvivid_tab_backup_restore" class="item" onclick="mwp_switch_wpvivid_tab('backup_restore');"><?php esc_html_e('Backup & Restore'); ?></a> <?php } static function mainwp_wpvivid_add_tab_schedule() { ?> <a href="#" id="mwp_wpvivid_tab_schedule" class="item" onclick="mwp_switch_wpvivid_tab('schedule');"><?php esc_html_e('Schedule'); ?></a> <?php } static function mainwp_wpvivid_add_tab_remote() { ?> <a href="#" id="mwp_wpvivid_tab_remote" class="item" onclick="mwp_wpvivid_click_remote_page();"><?php esc_html_e('Remote Storage'); ?></a> <?php } static function mainwp_wpvivid_add_tab_setting(){ ?> <a href="#" id="mwp_wpvivid_tab_setting" class="item" onclick="mwp_switch_wpvivid_tab('setting');"><?php esc_html_e('Settings'); ?></a> <?php } static function mainwp_wpvivid_add_tab_capability(){ ?> <a href="#" id="mwp_wpvivid_tab_capability" class="item" onclick="mwp_switch_wpvivid_tab('capability');"><?php esc_html_e('Modules'); ?></a> <?php } static function mainwp_wpvivid_add_tab_white_label(){ ?> <a href="#" id="mwp_wpvivid_tab_white_label" class="item" onclick="mwp_switch_wpvivid_tab('white_label');"><?php esc_html_e('White Label'); ?></a> <?php } static function mainwp_wpvivid_add_page_backup($check_pro){ ?> <div id="mwp_wpvivid_page_backup" style="width:100%; background: #fff;"> <?php self::renderSubBackuppage($check_pro); ?> </div> <?php } static function mainwp_wpvivid_add_page_backup_restore($check_pro){ ?> <div id="mwp_wpvivid_page_backup_restore" style="display: none; background: #fff;"> <?php self::renderSubBackupRestorepage($check_pro); ?> </div> <?php } static function mainwp_wpvivid_add_page_schedule($check_pro) { ?> <div id="mwp_wpvivid_page_schedule" style="display: none; background: #fff;"> <?php self::renderSubSchedulepage($check_pro); ?> </div> <?php } static function mainwp_wpvivid_add_page_setting($check_pro){ ?> <div id="mwp_wpvivid_page_setting" style="display: none; background: #fff;"> <?php self::renderSubSettingpage($check_pro); ?> </div> <?php } static function mainwp_wpvivid_add_page_capability($check_pro){ ?> <div id="mwp_wpvivid_page_capability" style="display: none; background: #fff;"> <?php self::renderSubCapabilitypage($check_pro); ?> </div> <?php } static function mainwp_wpvivid_add_page_white_label($check_pro){ ?> <div id="mwp_wpvivid_page_white_label" style="display: none; background: #fff;"> <?php self::renderSubWhiteLabelpage($check_pro); ?> </div> <?php } static function renderSubBackuppage($check_pro) { global $mainwp_wpvivid_extension_activator; $setting=Mainwp_WPvivid_Extension_DB_Option::get_instance()->wpvivid_get_option(sanitize_text_field($_GET['id']), 'settings', array()); $setting_addon=Mainwp_WPvivid_Extension_DB_Option::get_instance()->wpvivid_get_option(sanitize_text_field($_GET['id']), 'settings_addon', array()); $backup_custom_setting=Mainwp_WPvivid_Extension_DB_Option::get_instance()->wpvivid_get_option(sanitize_text_field($_GET['id']), 'backup_custom_setting_ex', array()); $mainwp_wpvivid_extension_activator->backup_page->set_site_id(sanitize_text_field($_GET['id'])); $mainwp_wpvivid_extension_activator->backup_page->set_backup_info($setting, $setting_addon, $backup_custom_setting); $mainwp_wpvivid_extension_activator->backup_page->render($check_pro); } static function renderSubBackupRestorepage($check_pro) { global $mainwp_wpvivid_extension_activator; $setting=Mainwp_WPvivid_Extension_DB_Option::get_instance()->wpvivid_get_option(sanitize_text_field($_GET['id']), 'settings', array()); $setting_addon=Mainwp_WPvivid_Extension_DB_Option::get_instance()->wpvivid_get_option(sanitize_text_field($_GET['id']), 'settings_addon', array()); $remote=Mainwp_WPvivid_Extension_DB_Option::get_instance()->wpvivid_get_option(sanitize_text_field($_GET['id']), 'remote', array()); $mainwp_wpvivid_extension_activator->backup_restore_page->set_site_id(sanitize_text_field($_GET['id'])); $mainwp_wpvivid_extension_activator->backup_restore_page->set_backup_restore_info($setting, $setting_addon, $remote); $mainwp_wpvivid_extension_activator->backup_restore_page->render($check_pro); } static function renderSubSchedulepage($check_pro) { global $mainwp_wpvivid_extension_activator; $schedule=Mainwp_WPvivid_Extension_DB_Option::get_instance()->wpvivid_get_option(sanitize_text_field($_GET['id']), 'schedule', array()); $schedule_addon=Mainwp_WPvivid_Extension_DB_Option::get_instance()->wpvivid_get_option(sanitize_text_field($_GET['id']), 'schedule_addon', array()); $time_zone=Mainwp_WPvivid_Extension_Option::get_instance()->wpvivid_get_single_option(sanitize_text_field($_GET['id']), 'time_zone', ''); if(empty($time_zone)){ $time_zone = 0; } $mainwp_wpvivid_extension_activator->schedule->set_schedule_info($schedule, $schedule_addon, array(), $time_zone); $mainwp_wpvivid_extension_activator->schedule->set_site_id(sanitize_text_field($_GET['id'])); $mainwp_wpvivid_extension_activator->schedule->render($check_pro); } static function renderSubSettingpage($check_pro) { global $mainwp_wpvivid_extension_activator; $setting=Mainwp_WPvivid_Extension_DB_Option::get_instance()->wpvivid_get_option(sanitize_text_field($_GET['id']), 'settings', array()); $setting_addon=Mainwp_WPvivid_Extension_DB_Option::get_instance()->wpvivid_get_option(sanitize_text_field($_GET['id']), 'settings_addon', array()); $mainwp_wpvivid_extension_activator->setting->set_site_id(sanitize_text_field($_GET['id'])); $mainwp_wpvivid_extension_activator->setting->set_setting_info($setting, $setting_addon); $mainwp_wpvivid_extension_activator->setting->render($check_pro); } static function renderSubCapabilitypage($check_pro) { global $mainwp_wpvivid_extension_activator; $capability_addon = Mainwp_WPvivid_Extension_DB_Option::get_instance()->wpvivid_get_option(sanitize_text_field($_GET['id']), 'menu_capability', array()); if(empty($capability_addon)){ $capability_addon = array(); $capability_addon['menu_manual_backup'] = '1'; $capability_addon['menu_export_site'] = '1'; $capability_addon['menu_import_site'] = '1'; $capability_addon['menu_backup_schedule'] = '1'; $capability_addon['menu_backup_restore'] = '1'; $capability_addon['menu_cloud_storage'] = '1'; $capability_addon['menu_image_optimization'] = '1'; $capability_addon['menu_staging'] = '1'; $capability_addon['menu_database_snapshot'] = '1'; $capability_addon['menu_unused_image_cleaner'] = '1'; $capability_addon['menu_export_import'] = '1'; $capability_addon['menu_rollback'] = '1'; $capability_addon['menu_role_capabilities'] = '1'; $capability_addon['menu_setting'] = '1'; $capability_addon['menu_debug'] = '1'; $capability_addon['menu_pro_page'] = '1'; } if(!isset($capability_addon['menu_manual_backup'])) { $capability_addon = array(); $capability_addon['menu_manual_backup'] = '1'; $capability_addon['menu_export_site'] = '1'; $capability_addon['menu_import_site'] = '1'; $capability_addon['menu_backup_schedule'] = '1'; $capability_addon['menu_backup_restore'] = '1'; $capability_addon['menu_cloud_storage'] = '1'; $capability_addon['menu_image_optimization'] = '1'; $capability_addon['menu_staging'] = '1'; $capability_addon['menu_database_snapshot'] = '1'; $capability_addon['menu_unused_image_cleaner'] = '1'; $capability_addon['menu_export_import'] = '1'; $capability_addon['menu_rollback'] = '1'; $capability_addon['menu_role_capabilities'] = '1'; $capability_addon['menu_setting'] = '1'; $capability_addon['menu_debug'] = '1'; $capability_addon['menu_pro_page'] = '1'; } if(!isset($capability_addon['menu_database_snapshot'])) { $capability_addon['menu_database_snapshot'] = '1'; } if(!isset($capability_addon['menu_staging'])) { $capability_addon['menu_staging'] = '1'; } if(!isset($capability_addon['menu_rollback'])) { $capability_addon['menu_rollback'] = '1'; } $mainwp_wpvivid_extension_activator->capability->set_site_id(sanitize_text_field($_GET['id'])); $mainwp_wpvivid_extension_activator->capability->set_capability_info($capability_addon); $mainwp_wpvivid_extension_activator->capability->render($check_pro); } static function renderSubWhiteLabelpage($check_pro) { global $mainwp_wpvivid_extension_activator; $white_label_addon = Mainwp_WPvivid_Extension_DB_Option::get_instance()->wpvivid_get_option(sanitize_text_field($_GET['id']), 'white_label_setting', array()); if(empty($white_label_addon)){ $white_label_addon = array(); } $mainwp_wpvivid_extension_activator->white_label->set_site_id(sanitize_text_field($_GET['id'])); $mainwp_wpvivid_extension_activator->white_label->set_white_label_info($white_label_addon); $mainwp_wpvivid_extension_activator->white_label->render($check_pro); } static public function output_backup_status($site_id, $tasks,$backup_list,$schedule) { global $mainwp_wpvivid_extension_activator; $html=''; foreach ($tasks as $task_id => $task) { if($task['status']['str']=='running') { $html='<div class="mwp-action-progress-bar"> <div class="mwp-action-progress-bar-percent" style="height:24px;width:'.esc_attr($task['task_info']['backup_percent']).'"></div> </div> <div style="float: left; '.esc_attr($task['task_info']['display_estimate_backup']).'"> <div class="mwp-backup-basic-info"><span class="mwp-wpvivid-span">'.__('Database Size:', 'mainwp-wpvivid-extension').'</span><span class="mwp-wpvivid-span">'.esc_html($task['task_info']['db_size']).'</span></div> <div class="mwp-backup-basic-info"><span class="mwp-wpvivid-span">'.__('File Size:', 'mainwp-wpvivid-extension').'</span><span class="mwp-wpvivid-span">'.esc_html($task['task_info']['file_size']).'</span></div> </div> <div style="float: left;"> <div class="mwp-backup-basic-info"><span class="mwp-wpvivid-span">'.__('Total Size:', 'mainwp-wpvivid-extension').'</span><span class="mwp-wpvivid-span">'.esc_html($task['task_info']['total']).'</span></div> <div class="mwp-backup-basic-info"><span class="mwp-wpvivid-span">'.__('Uploaded:', 'mainwp-wpvivid-extension').'</span><span class="mwp-wpvivid-span">'.esc_html($task['task_info']['upload']).'</span></div> <div class="mwp-backup-basic-info"><span class="mwp-wpvivid-span">'.__('Speed:', 'mainwp-wpvivid-extension').'</span><span class="mwp-wpvivid-span">'.esc_html($task['task_info']['speed']).'</span></div> </div> <div style="float: left;"> <div class="mwp-backup-basic-info"><span class="mwp-wpvivid-span">'.__('Network Connection:', 'mainwp-wpvivid-extension').'</span><span class="mwp-wpvivid-span">'.esc_html($task['task_info']['network_connection']).'</span></div> </div> <div style="clear:both;"></div> <div style="padding:10px; float: left; width:100%;"><p id="mwp_wpvivid_current_doing">'.esc_html($task['task_info']['descript'], 'mainwp-wpvivid-extension').'</p></div> <div style="clear: both;"></div> <div> <div class="mwp-backup-log-btn" style="float: left;"><input class="ui green mini button" id="mwp_wpvivid_backup_cancel_btn" type="button" value="'.esc_attr( 'Cancel' ).'" onclick="mwp_wpvivid_cancel_backup();" style="'.esc_attr($task['task_info']['css_btn_cancel']).'" /></div> <div class="mwp-backup-log-btn" style="float: left;"><input class="ui green mini button" type="button" value="'.esc_attr( 'Log' ).'" onclick="mwp_wpvivid_read_log(\'mwp_wpvivid_view_backup_task_log\');" /></div> <div style="clear: both;"></div> </div> <div style="clear: both;"></div>'; break; } else if($task['status']['str'] === 'completed'){ $options[$task_id]['task_id'] = $task_id; $options[$task_id]['backup_time'] = $task['status']['start_time']; $options[$task_id]['status'] = 'Succeeded'; $mainwp_wpvivid_extension_activator->set_backup_report($site_id, $options); } else if($task['status']['str'] === 'error'){ $options[$task_id]['task_id'] = $task_id; $options[$task_id]['backup_time'] = $task['status']['start_time']; $options[$task_id]['status'] = 'Failed, '.$task['status']['error']; $mainwp_wpvivid_extension_activator->set_backup_report($site_id, $options); } } return $html; } static public function output_backup_status_addon_ex($site_id, $information){ global $mainwp_wpvivid_extension_activator; $tasks = $information['tasks']; $ret['result']='success'; $ret['progress_html']=false; $ret['success_notice_html'] =false; $ret['error_notice_html'] =false; $ret['need_update']=false; $ret['last_msg_html']=false; $ret['running_backup_taskid']=''; $ret['wait_resume']=false; $ret['next_resume_time']=false; $ret['need_refresh_remote']=false; $ret['backup_finish_info']=false; $ret['task_no_response']=false; foreach ($tasks as $task_id => $task) { if(!isset($task['id'])) { continue; } $ret['task_id']=$task['id']; $ret['need_update']=true; if ($task['status']['str'] === 'ready' || $task['status']['str'] === 'running' || $task['status']['str'] === 'wait_resume' || $task['status']['str'] === 'no_responds') { $ret['running_backup_taskid']=$task_id; if($task['status']['str']==='wait_resume') { $ret['wait_resume']=true; $ret['next_resume_time']=$task['data']['next_resume_time']; } $ret['progress_html'] = '<div class="mwp-action-progress-bar"> <div class="mwp-action-progress-bar-percent" style="height:24px;width:' . esc_attr($task['task_info']['backup_percent']) . '"></div> </div> <div style="float: left;"> <div class="mwp-backup-basic-info"><span class="mwp-wpvivid-span">' . __('Total Size:', 'mainwp-wpvivid-extension') . '</span><span class="mwp-wpvivid-span">' . esc_html($task['task_info']['total']) . '</span></div> <div class="mwp-backup-basic-info"><span class="mwp-wpvivid-span">' . __('Uploaded:', 'mainwp-wpvivid-extension') . '</span><span class="mwp-wpvivid-span">' . esc_html($task['task_info']['upload']) . '</span></div> <div class="mwp-backup-basic-info"><span class="mwp-wpvivid-span">' . __('Speed:', 'mainwp-wpvivid-extension') . '</span><span class="mwp-wpvivid-span">' . esc_html($task['task_info']['speed']) . '</span></div> </div> <div style="float: left;"> <div class="mwp-backup-basic-info"><span class="mwp-wpvivid-span">' . __('Network Connection:', 'mainwp-wpvivid-extension') . '</span><span class="mwp-wpvivid-span">' . esc_html($task['task_info']['network_connection']) . '</span></div> </div> <div style="clear:both;"></div> <div style="padding:10px; float: left; width:100%;"><p id="mwp_wpvivid_current_doing">' . esc_html($task['task_info']['descript'], 'mainwp-wpvivid-extension') . '</p></div> <div style="clear: both;"></div> <div> <div class="mwp-backup-log-btn" style="float: left;"><input class="ui green mini button" id="mwp_wpvivid_backup_cancel_btn_addon" type="button" value="' . esc_attr('Cancel') . '" style="' . esc_attr($task['task_info']['css_btn_cancel']) . '" /></div> <div style="clear: both;"></div> </div> <div style="clear: both;"></div>'; } else if($task['status']['str'] === 'completed'){ $options[$task_id]['task_id'] = $task_id; $options[$task_id]['backup_time'] = $task['status']['start_time']; $options[$task_id]['status'] = 'Succeeded'; $mainwp_wpvivid_extension_activator->set_backup_report($site_id, $options); } else if($task['status']['str'] === 'error'){ $options[$task_id]['task_id'] = $task_id; $options[$task_id]['backup_time'] = $task['status']['start_time']; $options[$task_id]['status'] = 'Failed, '.$task['status']['error']; $mainwp_wpvivid_extension_activator->set_backup_report($site_id, $options); } } if($information['success_notice_html'] !== false){ $ret['success_notice_html'] = __('<div class="notice notice-success is-dismissible inline" style="margin: 0; padding-top: 10px; margin-left: 0px !important;"><p>Backup task have been completed.</p> <button type="button" class="notice-dismiss" onclick="mwp_click_dismiss_notice(this);"> <span class="screen-reader-text">Dismiss this notice.</span> </button> </div>'); } if($information['error_notice_html'] !== false){ $ret['error_notice_html'] = '<div class="notice notice-error inline" style="margin: 0; padding: 10px; margin-left: 0px !important;"><p>'.esc_html($information['error_notice_html']).'</p></div>'; } $ret['need_refresh_remote'] = $information['need_refresh_remote']; return $ret; } static public function output_backup_status_addon($site_id, $information){ global $mainwp_wpvivid_extension_activator; $tasks = $information['tasks']; $ret['result']='success'; $ret['need_update']=false; $ret['running_backup_taskid']=''; $ret['progress_html']=false; $ret['success_notice_html']=false; $ret['error_notice_html']=false; $ret['need_refresh_remote']=false; $ret['wait_resume']=false; $ret['next_resume_time']=false; foreach ($tasks as $task_id => $task) { $ret['need_update']=true; if ($task['status']['str'] === 'ready' || $task['status']['str'] === 'running' || $task['status']['str'] === 'wait_resume' || $task['status']['str'] === 'no_responds') { $ret['running_backup_taskid']=$task_id; if($task['status']['str']==='wait_resume') { $ret['wait_resume']=true; $ret['next_resume_time']=$task['data']['next_resume_time']; } $ret['progress_html'] = '<div class="mwp-action-progress-bar"> <div class="mwp-action-progress-bar-percent" style="height:24px;width:' . esc_attr($task['task_info']['backup_percent']) . '"></div> </div> <div style="float: left; ' . esc_attr($task['task_info']['display_estimate_backup']) . '"> <div class="mwp-backup-basic-info"><span class="mwp-wpvivid-span">' . __('Database Size:', 'mainwp-wpvivid-extension') . '</span><span class="mwp-wpvivid-span">' . esc_html($task['task_info']['db_size']) . '</span></div> <div class="mwp-backup-basic-info"><span class="mwp-wpvivid-span">' . __('File Size:', 'mainwp-wpvivid-extension') . '</span><span class="mwp-wpvivid-span">' . esc_html($task['task_info']['file_size']) . '</span></div> </div> <div style="float: left;"> <div class="mwp-backup-basic-info"><span class="mwp-wpvivid-span">' . __('Total Size:', 'mainwp-wpvivid-extension') . '</span><span class="mwp-wpvivid-span">' . esc_html($task['task_info']['total']) . '</span></div> <div class="mwp-backup-basic-info"><span class="mwp-wpvivid-span">' . __('Uploaded:', 'mainwp-wpvivid-extension') . '</span><span class="mwp-wpvivid-span">' . esc_html($task['task_info']['upload']) . '</span></div> <div class="mwp-backup-basic-info"><span class="mwp-wpvivid-span">' . __('Speed:', 'mainwp-wpvivid-extension') . '</span><span class="mwp-wpvivid-span">' . esc_html($task['task_info']['speed']) . '</span></div> </div> <div style="float: left;"> <div class="mwp-backup-basic-info"><span class="mwp-wpvivid-span">' . __('Network Connection:', 'mainwp-wpvivid-extension') . '</span><span class="mwp-wpvivid-span">' . esc_html($task['task_info']['network_connection']) . '</span></div> </div> <div style="clear:both;"></div> <div style="padding:10px; float: left; width:100%;"><p id="mwp_wpvivid_current_doing">' . esc_html($task['task_info']['descript'], 'mainwp-wpvivid-extension') . '</p></div> <div style="clear: both;"></div> <div> <div class="mwp-backup-log-btn" style="float: left;"><input class="ui green mini button" id="mwp_wpvivid_backup_cancel_btn_addon" type="button" value="' . esc_attr('Cancel') . '" style="' . esc_attr($task['task_info']['css_btn_cancel']) . '" /></div> <div style="clear: both;"></div> </div> <div style="clear: both;"></div>'; } else if($task['status']['str'] === 'completed'){ $options[$task_id]['task_id'] = $task_id; $options[$task_id]['backup_time'] = $task['status']['start_time']; $options[$task_id]['status'] = 'Succeeded'; $mainwp_wpvivid_extension_activator->set_backup_report($site_id, $options); } else if($task['status']['str'] === 'error'){ $options[$task_id]['task_id'] = $task_id; $options[$task_id]['backup_time'] = $task['status']['start_time']; $options[$task_id]['status'] = 'Failed, '.$task['status']['error']; $mainwp_wpvivid_extension_activator->set_backup_report($site_id, $options); } } if($information['success_notice_html'] !== false){ $ret['success_notice_html'] = __('<div class="notice notice-success is-dismissible inline" style="margin: 0; padding-top: 10px; margin-left: 0px !important;"><p>Backup task have been completed.</p> <button type="button" class="notice-dismiss" onclick="mwp_click_dismiss_notice(this);"> <span class="screen-reader-text">Dismiss this notice.</span> </button> </div>'); } if($information['error_notice_html'] !== false){ $ret['error_notice_html'] = '<div class="notice notice-error inline" style="margin: 0; padding: 10px; margin-left: 0px !important;"><p>'.esc_html($information['error_notice_html']).'</p></div>'; } $ret['need_refresh_remote'] = $information['need_refresh_remote']; return $ret; } static public function output_schedule_backup($schedule){ $html = ''; if($schedule['enable']){ $schedule_status='Enabled'; $next_backup_time=date("l, F d, Y H:i", $schedule['next_start']); } else{ $schedule_status='Disabled'; $next_backup_time='N/A'; } $message = $schedule['last_message']; if(empty($message)){ $last_message=__('The last backup message not found.', 'mainwp-wpvivid-extension'); } else{ $action_type = 'mwp_wpvivid_read_last_backup_log'; $log_html = '<a onclick="mwp_wpvivid_read_log(\''.esc_js($action_type).'\', \''.esc_js($message['log_file_name']).'\');" style="cursor:pointer;"> Log</a>'; if($message['status']['str'] == 'completed'){ $backup_status='Succeeded'; $last_message=$backup_status.', '.$message['status']['start_time'].$log_html; } elseif($message['status']['str'] == 'error'){ $backup_status='Failed'; $last_message=$backup_status.', '.$message['status']['start_time'].$log_html; } elseif($message['status']['str'] == 'cancel'){ $backup_status='Failed'; $last_message=$backup_status.', '.$message['status']['start_time'].$log_html; } else{ $last_message=__('The last backup message not found.', 'mainwp-wpvivid-extension'); } } $html.='<p><strong>Schedule Status:</strong>'.$schedule_status.'</p>'; $html.='<p><strong>Server Time: </strong>'.date("l, F d, Y H:i",time()).'</p>'; $html.='<p><strong>Last Backup: </strong>'.$last_message.'</p>'; $html.='<p><strong>Next Backup:</strong>'.$next_backup_time.'</p>'; $html.='<div style="clear:both;"></div>'; return $html; } static public function output_backup_list($backup_list){ $html=''; foreach ($backup_list as $key=>$backup){ $row_style = ''; if($backup['type'] == 'Migration' || $backup['type'] == 'Upload') { if($backup['type'] == 'Migration') { $upload_title = 'Received Backup: '; } else if($backup['type'] == 'Upload') { $upload_title = 'Uploaded Backup: '; } else { $upload_title='undefined'; } $row_style = 'border: 2px solid #006799; box-sizing:border-box; -moz-box-sizing:border-box; -webkit-box-sizing:border-box;'; } else if($backup['type'] == 'Manual' || $backup['type'] == 'Cron') { $row_style = ''; $upload_title=''; } else { $row_style = ''; $upload_title='undefined'; } if(empty($backup['lock'])){ $backup_lock='/admin/images/unlocked.png'; $lock_status='unlock'; } else{ if($backup['lock'] == 0){ $backup_lock='/admin/images/unlocked.png'; $lock_status='unlock'; } else{ $backup_lock='/admin/images/locked.png'; $lock_status='lock'; } } $remote=array(); $remote=apply_filters('mwp_wpvivid_remote_pic', $remote); $remote_pic_html=''; $save_local_pic_y = '/admin/images/storage-local.png'; $save_local_pic_n = '/admin/images/storage-local(gray).png'; $local_title = 'Localhost'; if($backup['save_local'] == 1 || $backup['type'] == 'Migration'){ $remote_pic_html .= '<img src="' . esc_url(MAINWP_WPVIVID_EXTENSION_PLUGIN_URL . $save_local_pic_y) . '" style="vertical-align:middle; " title="' . esc_attr($local_title) . '"/>'; } else{ $remote_pic_html .= '<img src="' . esc_url(MAINWP_WPVIVID_EXTENSION_PLUGIN_URL . $save_local_pic_n) . '" style="vertical-align:middle; " title="' . esc_attr($local_title) . '"/>'; } $b_has_remote=false; if(is_array($remote)) { foreach ($remote as $key1 => $value1) { foreach ($backup['remote'] as $storage_type) { $b_has_remote=true; if ($key1 === $storage_type['type']) { $pic = $value1['selected_pic']; } else { $pic = $value1['default_pic']; } } if(!$b_has_remote){ $pic = $value1['default_pic']; } $title = $value1['title']; $remote_pic_html .= '<img src="' . esc_url(MAINWP_WPVIVID_EXTENSION_PLUGIN_URL . $pic) . '" style="vertical-align:middle; " title="' . esc_attr($title) . '"/>'; } } $html .= '<tr style="'.$row_style.'"> <th class="check-column"><input name="check_backup" type="checkbox" id="'.$key.'" value="'.$key.'" onclick="mwp_wpvivid_click_check_backup(\''.$key.'\');" /></th> <td class="tablelistcolumn"> <div style="float:left;padding:0 10px 10px 0;"> <div class="backuptime"><strong>'.$upload_title.'</strong>'.date('M d, Y H:i',$backup['create_time']).'</div> <div class="common-table"> <span class="mwp-wpvivid-span" title="To lock the backup, the backup can only be deleted manually" id="wpvivid_lock_'.$key.'"> <img src="'.MAINWP_WPVIVID_EXTENSION_PLUGIN_URL.$backup_lock.'" name="'.$lock_status.'" onclick="mwp_wpvivid_set_backup_lock(\''.$key.'\', \''.$lock_status.'\');" style="vertical-align:middle; cursor:pointer;"/> </span> <span>|</span> <span class="mwp-wpvivid-span">'.__('Type: ', 'mainwp-wpvivid-extension').'</span><span class="mwp-wpvivid-span">'.$backup['type'].'</span> <span>|</span> <span class="mwp-wpvivid-span" title="Backup log"><a href="#" onclick="mwp_wpvivid_read_log(\'mwp_wpvivid_view_log\', \''.$key.'\');"><img src="'.MAINWP_WPVIVID_EXTENSION_PLUGIN_URL.'/admin/images/Log.png'.'" style="vertical-align:middle;cursor:pointer;"/><span>'.__('Log', 'mainwp-wpvivid-extension').'</span></a></span> </div> </div> </td> <td class="tablelistcolumn"> <div style="float:left;padding:10px 10px 10px 0;">'.$remote_pic_html.'</div> </td> <td class="tablelistcolumn" style="min-width:100px;"> <div id="wpvivid_file_part_'.esc_attr($key).'" style="float:left;padding:10px 10px 10px 0;"> <div style="cursor:pointer;" onclick="mwp_wpvivid_initialize_download(\''.$key.'\');" title="Prepare to download the backup"> <img id="wpvivid_download_btn_'.$key.'" src="'.MAINWP_WPVIVID_EXTENSION_PLUGIN_URL.'/admin/images/download.png'.'" style="vertical-align:middle;" /><span>'.__('Download', 'mainwp-wpvivid-extension').'</span> <div class="spinner" id="wpvivid_download_loading_'.$key.'" style="float:right;width:auto;height:auto;padding:10px 180px 10px 0;background-position:0 0;"></div> </div> </div> </td> <td class="tablelistcolumn" style="min-width:100px;"> <div style="cursor:pointer;padding:10px 0 10px 0;" onclick="mwp_wpvivid_initialize_restore(\''.$key.'\',\''.date('M d, Y H:i',$backup['create_time']).'\',\''.$backup['type'].'\');" title="You will be redirected to child-site when clicking the button" style="float:left;padding:10px 10px 10px 0;"> <img src="'.MAINWP_WPVIVID_EXTENSION_PLUGIN_URL. '/admin/images/Restore.png'.'" style="vertical-align:middle;" /><span>'.__('Restore', 'mainwp-wpvivid-extension').'</span> </div> </td> <td class="tablelistcolumn"> <div class="backuplist-delete-backup" style="padding:10px 0 10px 0;"> <img src="'.MAINWP_WPVIVID_EXTENSION_PLUGIN_URL.'/admin/images/Delete.png'.'" style="vertical-align:middle; cursor:pointer;" title="Delete the backup" onclick="mwp_wpvivid_delete_backup(\''.$key.'\');"/> </div> </td> </tr>'; } return $html; } static public function output_init_download_page($backup_id, $information){ $html = ''; $file_count=0; $file_part_num=1; foreach($information['files'] as $file_name => $value){ if($file_part_num < 10){ $format_part=sprintf("%02d", $file_part_num); } else{ $format_part=$file_part_num; } if($value['status'] == 'need_download'){ $information['files'][$file_name]['html']='<div style="float:left;margin:10px 10px 10px 0;text-align:center; width:180px;"> <span>Part'.esc_html($format_part).'</span></br> <span id=\''.esc_attr($backup_id).'-text-part-'.esc_attr($file_part_num).'\'><a onclick="mwp_wpvivid_prepare_download(\''.esc_js($file_part_num).'\', \''.esc_js($backup_id).'\', \''.esc_js($file_name).'\');" style="cursor: pointer;">Prepare to Download</a></span></br> <div style="width:100%;height:5px; background-color:#dcdcdc;"> <div id=\''.esc_attr($backup_id).'-progress-part-'.esc_attr($file_part_num).'\' style="background-color:#7fb100; float:left;width:0;height:5px;"></div> </div> <span>size:</span><span>'.esc_html($value['size']).'</span> </div>'; } else if($value['status'] == 'running'){ $information['files'][$file_name]['html']='<div style="float:left;margin:10px 10px 10px 0;text-align:center; width:180px;"> <span>Part'.esc_html($format_part).'</span></br> <span id=\''.esc_attr($backup_id).'-text-part-'.esc_attr($file_part_num).'\'><a >Retriving(remote storage to web server)</a></span></br> <div style="width:100%;height:5px; background-color:#dcdcdc;"> <div id=\''.esc_attr($backup_id).'-progress-part-'.esc_attr($file_part_num).'\' style="background-color:#7fb100; float:left;width:'.esc_attr($value['progress_text']).'%;height:5px;"></div> </div> <span>size:</span><span>'.esc_html($value['size']).'</span> </div>'; } else if($value['status'] == 'timeout'){ $information['files'][$file_name]['html']='<div style="float:left;margin:10px 10px 10px 0;text-align:center; width:180px;"> <span>Part'.esc_html($format_part).'</span></br> <span id=\''.esc_attr($backup_id).'-text-part-'.esc_attr($file_part_num).'\'><a onclick="mwp_wpvivid_prepare_download(\''.esc_js($file_part_num).'\', \''.esc_js($backup_id).'\', \''.esc_js($file_name).'\');" style="cursor: pointer;">Prepare to Download</a></span></br> <div style="width:100%;height:5px; background-color:#dcdcdc;"> <div id=\''.esc_attr($backup_id).'-progress-part-'.esc_attr($file_part_num).'\' style="background-color:#7fb100; float:left;width:'.esc_attr($value['progress_text']).'%;height:5px;"></div> </div> <span>size:</span><span>'.esc_html($value['size']).'</span> </div>'; } else if($value['status'] == 'completed'){ $information['files'][$file_name]['html']='<div style="float:left;margin:10px 10px 10px 0;text-align:center; width:180px;"> <span>Part'.esc_html($format_part).'</span></br> <span id=\''.esc_attr($backup_id).'-text-part-'.esc_attr($file_part_num).'\'><a onclick="mwp_wpvivid_download(\''.esc_js($backup_id).'\', \''.esc_js($file_name).'\');" style="cursor: pointer;">Download</a></span></br> <div style="width:100%;height:5px; background-color:#dcdcdc;"> <div id=\''.esc_attr($backup_id).'-progress-part-'.esc_attr($file_part_num).'\' style="background-color:#7fb100; float:left;width:100%;height:5px;"></div> </div> <span>size:</span><span>'.esc_html($value['size']).'</span> </div>'; } else if($value['status'] == 'error'){ $information['files'][$file_name]['html']='<div style="float:left;margin:10px 10px 10px 0;text-align:center; width:180px;"> <span>Part'.esc_html($format_part).'</span></br> <span id=\''.esc_attr($backup_id).'-text-part-'.esc_attr($file_part_num).'\'><a onclick="mwp_wpvivid_prepare_download(\''.esc_js($file_part_num).'\', \''.esc_js($backup_id).'\', \''.esc_js($file_name).'\');" style="cursor: pointer;">Prepare to Download</a></span></br> <div style="width:100%;height:5px; background-color:#dcdcdc;"> <div id=\''.esc_attr($backup_id).'-progress-part-'.esc_attr($file_part_num).'\' style="background-color:#7fb100; float:left;width:0;height:5px;"></div> </div> <span>size:</span><span>'.esc_html($value['size']).'</span> </div>'; } $file_count++; $file_part_num++; } if ($file_count % 2 != 0) { $file_count++; if($file_count < 10){ $format_part=sprintf("%02d", $file_count); } else{ $format_part=$file_count; } $information['files']['place_html']='<div style="float:left;margin:10px 10px 10px 0;text-align:center; width:180px; color:#cccccc;"> <span>Part'.esc_html($format_part).'</span></br> <span>Download</span></br> <div style="width:100%;height:5px; background-color:#dcdcdc;"> <div style="background-color:#7fb100; float:left;width:0;height:5px;"></div> </div> <span>size:</span><span>0</span> </div>'; } else{ $information['files']['place_html']=''; } return $information; } static public function output_default_remote($remote_storage_type){ $html=''; $remote=array(); $remote=apply_filters('mwp_wpvivid_remote_pic', $remote); if(is_array($remote)) { foreach ($remote as $key => $value) { $title = $value['title']; if ($key === $remote_storage_type) { $pic = $value['selected_pic']; } else { $pic = $value['default_pic']; } $html .= '<img src="' . esc_url(MAINWP_WPVIVID_EXTENSION_PLUGIN_URL . $pic) . '" style="vertical-align:middle; " title="' . esc_attr($title) . '"/>'; } } return $html; } static public function output_database_table($base_tables, $other_tables){ $html = ''; $base_table_html = ''; $base_tables_html = ''; $has_base_table = false; $base_table_all_check = true; foreach ($base_tables as $base_table){ if($base_table["table_check"] !== 'checked'){ $base_table_all_check = false; } $has_base_table = true; $base_table_html .= '<div class="wpvivid-text-line"> <input type="checkbox" option="mwp_base_db" name="Database" value="'.esc_html($base_table["table_name"]).'" '.esc_html($base_table["table_check"]).' /> <span class="wpvivid-text-line">'.esc_html($base_table["table_name"]).'|Rows:'.$base_table["table_row"].'|Size:'.$base_table["table_size"].'</span> </div>'; } $other_table_html = ''; $other_tables_html = ''; $has_other_table = false; $other_table_all_check = true; foreach ($other_tables as $other_table){ if($other_table['table_check'] !== 'checked'){ $other_table_all_check = false; } $has_other_table = true; $other_table_html .= '<div class="wpvivid-text-line"> <input type="checkbox" option="mwp_other_db" name="Database" value="'.esc_html($other_table["table_name"]).'" '.esc_html($other_table["table_check"]).' /> <span class="wpvivid-text-line">'.esc_html($other_table["table_name"]).'|Rows:'.$other_table["table_row"].'|Size:'.$other_table["table_size"].'</span> </div>'; } if($base_table_all_check){ $base_table_all_check = 'checked'; } else{ $base_table_all_check = ''; } if($other_table_all_check){ $other_table_all_check = 'checked'; } else{ $other_table_all_check = ''; } //$base_table_html .= '<div style="clear:both;"></div>'; //$other_table_html .= '<div style="clear:both;"></div>'; $ret['database_html'] = '<div style="padding-left:2em;margin-top:1em;"> <div style="border-bottom:1px solid rgb(204, 204, 204);"></div> </div>'; if($has_base_table) { $base_all_check = ''; if($base_table_all_check){ $base_all_check = 'checked'; } $base_tables_html .= '<div style="width:30%;float:left;box-sizing:border-box;padding-left:2em;padding-right:0.5em;"> <div style="margin-top: 10px; margin-bottom: 10px;"> <p> <span class="dashicons dashicons-list-view mwp-wpvivid-dashicons-blue"></span> <label title="Check/Uncheck all"> <span><input type="checkbox" class="mwp-wpvivid-database-table-check mwp-wpvivid-database-base-table-check" '.esc_attr($base_all_check).'></span> <span><strong>Wordpress default tables</strong></span> </label> </p> </div> <div style="padding-bottom:0.5em;"><span><input type="text" class="mwp-wpvivid-select-base-table-text" placeholder="Filter Tables"> <input type="button" value="Filter" class="button mwp-wpvivid-select-base-table-button" style="position: relative; z-index: 1;"></span> </div> <div class="mwp-wpvivid-database-base-list" style="height:250px;border:1px solid rgb(204, 204, 204);padding:0.2em 0.5em;overflow:auto;"> '.$base_table_html.' </div> <div style="clear:both;"></div> </div>'; } if($has_other_table) { $other_all_check = ''; if($other_table_all_check){ $other_all_check = 'checked'; } $other_tables_html .= '<div style="width:70%;float:left;box-sizing:border-box;padding-left:0.5em;"> <div style="margin-top: 10px; margin-bottom: 10px;"> <p> <span class="dashicons dashicons-list-view mwp-wpvivid-dashicons-green"></span> <label title="Check/Uncheck all"> <span><input type="checkbox" class="mwp-wpvivid-database-table-check mwp-wpvivid-database-other-table-check" '.esc_attr($other_all_check).'></span> <span><strong>Tables created by plugins or themes</strong></span> </label> </p> </div> <div style="padding-bottom:0.5em;"><span><input type="text" class="mwp-wpvivid-select-other-table-text" placeholder="Filter Tables"> <input type="button" value="Filter" class="button mwp-wpvivid-select-other-table-button" style="position: relative; z-index: 1;"></span> </div> <div class="mwp-wpvivid-database-other-list" style="height:250px;border:1px solid rgb(204, 204, 204);padding:0.2em 0.5em;overflow:auto;"> '.$other_table_html.' </div> </div>'; } $div = '<div style="clear:both;"></div>'; $div .= '<div style="margin-bottom: 10px;"></div>'; $database_table_html = $ret['database_html'] . $base_tables_html . $other_tables_html; $html = $database_table_html; return $html; } static public function output_filter_database_table($table_type, $table_arr){ $base_table_html = ''; $option = 'mwp_base_db'; if($table_type === 'base_table') { $option = 'mwp_base_db'; } else if($table_type === 'other_table') { $option = 'mwp_other_db'; } foreach ($table_arr as $table_info) { $base_table_html .= '<div class="wpvivid-text-line"> <input type="checkbox" option="'.esc_html($option).'" name="Database" value="'.esc_html($table_info["table_name"]).'" '.esc_html($table_info["table_check"]).' /> <span class="wpvivid-text-line">'.esc_html($table_info["table_name"]).'|Rows:'.$table_info["table_row"].'|Size:'.$table_info["table_size"].'</span> </div>'; } return $base_table_html; } static public function output_edit_schedule_database_table($base_tables, $other_tables, $global, $site_id='', $schedule_id=''){ $exclude_tables = array(); if($global) { } else { $schedule_addon=Mainwp_WPvivid_Extension_DB_Option::get_instance()->wpvivid_get_option($site_id, 'schedule_addon', array()); if(isset($schedule_addon[$schedule_id])) { $schedule_info = $schedule_addon[$schedule_id]; if(isset($schedule_info['backup']['custom_dirs']['exclude-tables'])){ $exclude_tables = $schedule_info['backup']['custom_dirs']['exclude-tables']; } } } $html = ''; $base_table_html = ''; $base_tables_html = ''; $has_base_table = false; $base_table_all_check = true; foreach ($base_tables as $base_table){ $checked = 'checked'; if (in_array($base_table["table_name"], $exclude_tables)) { $checked = ''; $base_table_all_check = false; } $has_base_table = true; $base_table_html .= '<div class="wpvivid-text-line"> <input type="checkbox" option="mwp_base_db" name="Database" value="'.esc_html($base_table["table_name"]).'" '.esc_html($checked).' /> <span class="wpvivid-text-line">'.esc_html($base_table["table_name"]).'|Rows:'.$base_table["table_row"].'|Size:'.$base_table["table_size"].'</span> </div>'; } $other_table_html = ''; $other_tables_html = ''; $has_other_table = false; $other_table_all_check = true; foreach ($other_tables as $other_table){ $checked = 'checked'; if (in_array($other_table["table_name"], $exclude_tables)) { $checked = ''; $other_table_all_check = false; } $has_other_table = true; $other_table_html .= '<div class="wpvivid-text-line"> <input type="checkbox" option="mwp_other_db" name="Database" value="'.esc_html($other_table["table_name"]).'" '.esc_html($checked).' /> <span class="wpvivid-text-line">'.esc_html($other_table["table_name"]).'|Rows:'.$other_table["table_row"].'|Size:'.$other_table["table_size"].'</span> </div>'; } if($base_table_all_check){ $base_table_all_check = 'checked'; } else{ $base_table_all_check = ''; } if($other_table_all_check){ $other_table_all_check = 'checked'; } else{ $other_table_all_check = ''; } $ret['database_html'] = '<div style="padding-left:2em;margin-top:1em;"> <div style="border-bottom:1px solid rgb(204, 204, 204);"></div> </div>'; if($has_base_table) { $base_all_check = ''; if($base_table_all_check){ $base_all_check = 'checked'; } $base_tables_html .= '<div style="width:30%;float:left;box-sizing:border-box;padding-left:2em;padding-right:0.5em;"> <div> <p> <span class="dashicons dashicons-list-view mwp-wpvivid-dashicons-blue"></span> <label title="Check/Uncheck all"> <span><input type="checkbox" class="mwp-wpvivid-database-table-check mwp-wpvivid-database-base-table-check" '.esc_attr($base_all_check).'></span> <span><strong>Wordpress default tables</strong></span> </label> </p> </div> <div style="padding-bottom:0.5em;"><span><input type="text" class="mwp-wpvivid-select-base-table-text" placeholder="Filter Tables"> <input type="button" value="Filter" class="button mwp-wpvivid-select-base-table-button" style="position: relative; z-index: 1;"></span> </div> <div class="mwp-wpvivid-database-base-list" style="height:250px;border:1px solid rgb(204, 204, 204);padding:0.2em 0.5em;overflow:auto;"> '.$base_table_html.' </div> <div style="clear:both;"></div> </div>'; } if($has_other_table) { $other_all_check = ''; if($other_table_all_check){ $other_all_check = 'checked'; } $other_tables_html .= '<div style="width:70%;float:left;box-sizing:border-box;padding-left:0.5em;"> <div> <p> <span class="dashicons dashicons-list-view mwp-wpvivid-dashicons-green"></span> <label title="Check/Uncheck all"> <span><input type="checkbox" class="mwp-wpvivid-database-table-check mwp-wpvivid-database-other-table-check" '.esc_attr($other_all_check).'></span> <span><strong>Tables created by plugins or themes</strong></span> </label> </p> </div> <div style="padding-bottom:0.5em;"><span><input type="text" class="mwp-wpvivid-select-other-table-text" placeholder="Filter Tables"> <input type="button" value="Filter" class="button mwp-wpvivid-select-other-table-button" style="position: relative; z-index: 1;"></span> </div> <div class="mwp-wpvivid-database-other-list" style="height:250px;border:1px solid rgb(204, 204, 204);padding:0.2em 0.5em;overflow:auto;"> '.$other_table_html.' </div> </div>'; } $div = '<div style="clear:both;"></div>'; $div .= '<div style="margin-bottom: 10px;"></div>'; $database_table_html = $base_tables_html . $other_tables_html; $html = $database_table_html; return $html; } static public function output_themes_plugins_table($themes, $plugins){ $html = ''; $theme_html = ''; $themes_html = ''; $themes_all_check = true; foreach ($themes as $theme){ if($theme["theme_check"] !== 'checked'){ $themes_all_check = false; } $theme_html .= '<div class="mwp-wpvivid-custom-database-table-column"> <label style="width:100%;overflow: hidden;text-overflow: ellipsis;white-space: nowrap; padding-top: 3px;" title="'.esc_html($theme['theme_name']).'|Size:'.$theme["theme_size"].'"> <input type="checkbox" option="mwp_themes" name="Themes" value="'.esc_attr($theme['theme_name']).'" '.esc_html($theme['theme_check']).' /> '.esc_html($theme['theme_name']).'|Size:'.$theme["theme_size"].' </label> </div>'; } $plugin_html = ''; $plugins_html = ''; $plugins_all_check = true; foreach ($plugins as $plugin){ if($plugin["plugin_check"] !== 'checked'){ $plugins_all_check = false; } $plugin_html .= '<div class="mwp-wpvivid-custom-database-table-column"> <label style="width:100%;overflow: hidden;text-overflow: ellipsis;white-space: nowrap; padding-top: 3px;" title="'.esc_html($plugin['plugin_display_name']).'|Size:'.$plugin["plugin_size"].'"> <input type="checkbox" option="mwp_plugins" name="Plugins" value="'.esc_attr($plugin['plugin_slug_name']).'" '.esc_html($plugin['plugin_check']).' /> '.esc_html($plugin['plugin_display_name']).'|Size:'.$plugin["plugin_size"].'</label> </div>'; } if($themes_all_check){ $themes_all_check = 'checked'; } else{ $themes_all_check = ''; } if($plugins_all_check){ $plugins_all_check = 'checked'; } else{ $plugins_all_check = ''; } $theme_html .= '<div style="clear:both;"></div>'; $plugin_html .= '<div style="clear:both;"></div>'; $themes_html .= '<div class="mwp-wpvivid-custom-database-wp-table-header" style="border:1px solid #e5e5e5;"> <label><input type="checkbox" class="mwp-wpvivid-themes-plugins-table-check mwp-wpvivid-themes-all-check" '.esc_attr($themes_all_check).' />Themes</label> </div> <div class="mwp-wpvivid-database-table-addon" style="border:1px solid #e5e5e5; border-top: none; padding: 0 4px 4px 4px; max-height: 300px; overflow-y: auto; overflow-x: hidden;"> '.$theme_html.' </div>'; $plugins_html .= '<div class="mwp-wpvivid-custom-database-other-table-header" style="border:1px solid #e5e5e5;"> <label><input type="checkbox" class="mwp-wpvivid-themes-plugins-table-check mwp-wpvivid-plugins-all-check" '.esc_attr($plugins_all_check).' />Plugins</label> </div> <div class="mwp-wpvivid-database-table-addon" style="border:1px solid #e5e5e5; border-top: none; padding: 0 4px 4px 4px; max-height: 300px; overflow-y: auto; overflow-x: hidden;"> '.$plugin_html.' </div>'; $div = '<div style="clear:both;"></div>'; $div .= '<div style="margin-bottom: 10px;"></div>'; $themes_plugins_html = $themes_html . $div . $plugins_html; $html = $themes_plugins_html; return $html; } static public function output_additional_database_table($database_array){ $database_html = ''; foreach ($database_array as $database) { $database_html .= '<div class="wpvivid-text-line"><span class="dashicons dashicons-plus-alt wpvivid-icon-16px mwp-wpvivid-add-additional-db" option="mwp_additional_db" name="'.$database.'"></span><span class="wpvivid-text-line">'.esc_html($database).'</span></div>'; } return $database_html; } static public function output_additional_database_list($data){ $html = ''; foreach ($data as $database => $db_info) { $html .= '<div class="wpvivid-text-line" database-name="'.$database.'" database-host="'.$db_info['db_host'].'" database-user="'.$db_info['db_user'].'" database-pass="'.$db_info['db_pass'].'"><span class="dashicons dashicons-trash wpvivid-icon-16px mwp-wpvivid-additional-database-remove" database-name="'.$database.'"></span><span class="dashicons dashicons-admin-site-alt3 wpvivid-dashicons-blue wpvivid-icon-16px-nopointer"></span><span class="wpvivid-text-line" option="additional_db_custom" name="'.$database.'">'.$database.'@'.$db_info['db_host'].'</span></div>'; } return $html; } static public function output_init_download_page_addon($files, $backup_id, $page=1){ $files_list=new Mainwp_WPvivid_Files_List(); $files_list->set_files_list($files, $backup_id, $page); $files_list->prepare_items(); ob_start(); $files_list->display(); $html = ob_get_clean(); return $html; } static public function output_download_progress_addon($backup_files){ $ret=array(); foreach ($backup_files as $file => $data){ if($data['status'] === 'need_download'){ $ret[$file]['status']='need_download'; $ret[$file]['html']='<div class="mwp-wpvivid-block-bottom-space"> <span class="mwp-wpvivid-block-right-space">Retriving (remote storage to web server)</span><span class="mwp-wpvivid-block-right-space">|</span><span>File Size: </span><span class="mwp-wpvivid-block-right-space">'.$data['file_size'].'</span><span class="mwp-wpvivid-block-right-space">|</span><span>Downloaded Size: </span><span>0</span> </div> <div style="width:100%;height:10px; background-color:#dcdcdc;"> <div style="background-color:#0085ba; float:left;width:0%;height:10px;"></div> </div>'; } else if($data['status'] === 'running'){ $ret[$file]['status']='running'; $ret[$file]['html']='<div class="mwp-wpvivid-block-bottom-space"> <span class="mwp-wpvivid-block-right-space">Retriving (remote storage to web server)</span><span class="mwp-wpvivid-block-right-space">|</span><span>File Size: </span><span class="mwp-wpvivid-block-right-space">'.$data['file_size'].'</span><span class="mwp-wpvivid-block-right-space">|</span><span>Downloaded Size: </span><span>'.$data['downloaded_size'].'</span> </div> <div style="width:100%;height:10px; background-color:#dcdcdc;"> <div style="background-color:#0085ba; float:left;width:'.$data['progress_text'].'%;height:10px;"></div> </div>'; } else if($data['status'] === 'timeout') { $ret[$file]['status']='completed'; $ret[$file]['html']='<div class="mwp-wpvivid-block-bottom-space"> <span>Download timeout, please retry.</span> </div> <div> <span>' . __('File Size: ', 'wpvivid') . '</span><span class="mwp-wpvivid-block-right-space">' . $data['file_size'] . '</span><span class="mwp-wpvivid-block-right-space">|</span><span class="mwp-wpvivid-block-right-space"><a class="mwp-wpvivid-prepare-download" style="cursor: pointer;">Prepare to Download</a></span> </div>'; } else if($data['status'] === 'completed'){ $ret[$file]['status']='completed'; $ret[$file]['html']='<span>'.__('File Size: ', 'wpvivid').'</span><span class="mwp-wpvivid-block-right-space">'.$data['file_size'].'</span><span class="mwp-wpvivid-block-right-space">|</span><span class="mwp-wpvivid-block-right-space mwp-wpvivid-ready-download"><a style="cursor: pointer;">Download</a></span>'; } else if($data['status'] === 'error'){ $ret[$file]['status']='error'; $ret[$file]['html']='<div class="mwp-wpvivid-block-bottom-space"> <span>'.$data['error'].'</span> </div> <div> <span>'.__('File Size: ', 'wpvivid').'</span><span class="mwp-wpvivid-block-right-space">'.$data['file_size'].'</span><span class="mwp-wpvivid-block-right-space">|</span><span class="mwp-wpvivid-block-right-space"><a class="mwp-wpvivid-prepare-download" style="cursor: pointer;">Prepare to Download</a></span> </div>'; } } return $ret; } static public function output_remote_backup_page_addon($remote_list, $select_remote_id){ $has_remote = false; foreach ($remote_list as $key => $value) { if ($key === 'remote_selected') { continue; } else { $has_remote = true; } } if($select_remote_id === '') { $first_remote_path = 'Common'; foreach ($remote_list as $key => $value) { if ($key === 'remote_selected') { continue; } else { if(isset($value['custom_path'])) { if(isset($value['root_path'])) { $path = $value['path'].untrailingslashit($value['root_path']).'/'.$value['custom_path']; } else { $path = $value['path'].'wpvividbackuppro/'.$value['custom_path']; } } else { $path = $value['path']; } if($first_remote_path === 'Common'){ $first_remote_path = $path; } } } $path = $first_remote_path; } else{ if (isset($remote_list[$select_remote_id])) { if(isset($remote_list[$select_remote_id]['custom_path'])) { if(isset($remote_list[$select_remote_id]['root_path'])) { $path = $remote_list[$select_remote_id]['path'].untrailingslashit($remote_list[$select_remote_id]['root_path']).'/'.$remote_list[$select_remote_id]['custom_path']; } else { $path = $remote_list[$select_remote_id]['path'].'wpvividbackuppro/'. $remote_list[$select_remote_id]['custom_path']; } } else { $path = $remote_list[$select_remote_id]['path']; } } else { $path='Common'; } } $remote_storage_option = ''; foreach ($remote_list as $key=>$value) { if($key === 'remote_selected') { continue; } $check_status = ''; if($key === $select_remote_id){ $check_status = 'selected'; } $value['type'] = apply_filters('mwp_wpvivid_storage_provider_tran', $value['type']); $remote_storage_option .= '<option value="' . $key . '" '.$check_status.'>' . $value['type'] . ' -> ' . $value['name'] . '</option>'; } if($has_remote){ $html = '<div class="mwp-quickstart-storage-setting"> <div style="padding: 10px 0;"> <div class="mwp-wpvivid-font-right-space" style="float: left;">Current Folder Path:</div> <div id="mwp_wpvivid_remote_folder" style="float: left;">'.$path.'</div> <div style="clear: both;"></div> </div> <div style="clear: both;"></div> </div> <div style="clear: both;"></div> <div class="mwp-wpvivid-block-bottom-space"> <div style="float: left;"> <div>Display all backups stored in account <select id="mwp_wpvivid_select_remote_storage" onchange="mwp_wpvivid_select_remote_storage_folder();">'.$remote_storage_option.'</select> under <select id="mwp_wpvivid_select_remote_folder" onchange="mwp_wpvivid_select_remote_storage_folder();"> <option value="Common">'.$path.'</option> <option value="Migrate">Migration</option> <option value="Rollback">Rollback</option> <option value="Incremental">Incremental</option> </select> folder. </div> </div> <div style="float: left; margin-left: 5px; height: 30px; line-height: 30px;"> <a onclick="mwp_wpvivid_explanation_folders();" style="cursor: pointer;">Explanation about these folders.</a> </div> <div style="clear: both;"></div> </div> <div class="mwp-wpvivid-click-popup mwp-wpvivid-block-bottom-space" id="mwp_wpvivid_explanation_folders" style="display: none; padding: 0 0 0 10px;"> <ul> <li><i id="mwp_wpvivid_explanation_backup_folder">'.$path.'</i> Folder is where the manual backups and scheduled backups are stored on your cloud storage. <a href="https://wpvivid.com/wpvivid-backup-pro-custom-backup-folder" target="_blank">Learn more</a></li> <li><i>Migrate</i> Folder is where the backups for migration are stored on your cloud storage. <a href="https://wpvivid.com/wpvivid-backup-pro-migration-folder" target="_blank">Learn more</a></li> <li><i id="mwp_wpvivid_explanation_rollback_folder">'.$path.'/rollback</i> Folder is where the backups created before updating are stored. You can disable this feature in Settings. <a href="https://wpvivid.com/wpvivid-backup-pro-rollback-folder" target="_blank">Learn more</a></li> </ul> </div> <div style="clear: both;"></div> <div style="margin-bottom: 10px;"> <input class="ui green mini button" id="mwp_wpvivid_sync_remote_folder" type="button" value="Scan The Folder" onclick="mwp_wpvivid_select_remote_folder();" style="float: left;"/> <div class="spinner" id="mwp_wpvivid_scanning_remote_folder" style="float: left;"></div> <div style="clear: both;"></div> </div> <div class="mwp-wpvivid-remote-sync-error" style="display: none;"></div> <div style="clear: both;"></div>'; } else{ $html = '<div class="mwp-quickstart-storage-setting mwp-wpvivid-block-bottom-space"> <div style="padding: 10px 0;"> <span style="margin-right: 0;">There is no remote storage available, please set it up first and sync.</span> </div> </div>'; } return $html; } static public function output_remote_list_addon($remote_list) { $remote_list_html='<option value="all_backup" selected="selected">--</option>'; foreach ($remote_list as $key => $value) { if($key === 'remote_selected') { continue; } $remote_list_html.='<option value="'.$value['id'].'">'.$value['name'].'</option>'; } return $remote_list_html; } static public function output_rollback_remote_list_addon($site_id, $remote_list) { $remote_list_html = ''; $setting_addon=Mainwp_WPvivid_Extension_DB_Option::get_instance()->wpvivid_get_option($site_id, 'settings_addon', array()); $rollback_remote = isset($setting_addon['wpvivid_rollback_remote']) ? $setting_addon['wpvivid_rollback_remote'] : 0; $remote_id = isset($setting_addon['wpvivid_rollback_remote_id']) ? $setting_addon['wpvivid_rollback_remote_id'] : 0; if($rollback_remote) { $remote_list_html .= '<option value="-1">Choose cloud storage</option>'; } else { $remote_list_html .= '<option value="-1" selected="selected" >Choose cloud storage</option>'; } foreach ($remote_list as $key => $value) { if($key === 'remote_selected') { continue; } if(!isset($remote_option['id'])) { $remote_option['id'] = $key; } if($remote_id==$key&&$rollback_remote) { $remote_list_html .= '<option value="'.$value['id'].'" selected="selected">'.$value['name'].'</option>'; } else { $remote_list_html .= '<option value="'.$value['id'].'">'.$value['name'].'</option>'; } } return $remote_list_html; } } admin/wpvivid-backup-mainwp-schedulepage.php 0000644 00001031224 15133715745 0015236 0 ustar 00 <?php if ( ! class_exists( 'WP_List_Table' ) ) { require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' ); } class Mainwp_WPvivid_Schedule_List extends WP_List_Table { public $page_num; public $schedule_list; public function __construct( $args = array() ) { parent::__construct( array( 'plural' => 'schedule', 'screen' => 'schedule', ) ); } public function print_column_headers( $with_id = true ) { list( $columns, $hidden, $sortable, $primary ) = $this->get_column_info(); if (!empty($columns['cb'])) { static $cb_counter = 1; $columns['cb'] = '<label class="screen-reader-text" for="cb-select-all-' . $cb_counter . '">' . __('Select All') . '</label>' . '<input id="cb-select-all-' . $cb_counter . '" type="checkbox"/>'; $cb_counter++; } foreach ( $columns as $column_key => $column_display_name ) { $class = array( 'manage-column', "column-$column_key" ); if ( in_array( $column_key, $hidden ) ) { $class[] = 'hidden'; } if ( $column_key === $primary ) { $class[] = 'column-primary'; } if ( $column_key === 'cb' ) { $class[] = 'check-column'; } $tag = ( 'cb' === $column_key ) ? 'td' : 'th'; $scope = ( 'th' === $tag ) ? 'scope="col"' : ''; $id = $with_id ? "id='$column_key'" : ''; if ( ! empty( $class ) ) { $class = "class='" . join( ' ', $class ) . "'"; } echo "<$tag $scope $id $class>$column_display_name</$tag>"; } } public function get_columns() { $columns = array(); $columns['wpvivid_backup_type'] = __( 'Backup Type', 'wpvivid' ); $columns['wpvivid_backup_cycles'] = __( 'Backup Cycles', 'wpvivid' ); $columns['wpvivid_last_backup'] = __( 'Last Backup', 'wpvivid' ); $columns['wpvivid_next_backup'] = __( 'Next Backup', 'wpvivid' ); $columns['wpvivid_storage'] = __( 'Storage', 'wpvivid' ); $columns['wpvivid_on_off_control'] = __( 'On/off', 'wpvivid' ); $columns['wpvivid_actions'] = __( 'Actions', 'wpvivid' ); return $columns; } public function set_schedule_list($schedule_list,$page_num=1) { $this->schedule_list=$schedule_list; $this->page_num=$page_num; } public function get_pagenum() { if($this->page_num=='first') { $this->page_num=1; } else if($this->page_num=='last') { $this->page_num=$this->_pagination_args['total_pages']; } $pagenum = $this->page_num ? $this->page_num : 0; if ( isset( $this->_pagination_args['total_pages'] ) && $pagenum > $this->_pagination_args['total_pages'] ) { $pagenum = $this->_pagination_args['total_pages']; } return max( 1, $pagenum ); } public function prepare_items() { $columns = $this->get_columns(); $hidden = array(); $sortable = array(); $this->_column_headers = array($columns, $hidden, $sortable); $total_items =sizeof($this->schedule_list); $this->set_pagination_args( array( 'total_items' => $total_items, 'per_page' => 10, ) ); } public function has_items() { return !empty($this->schedule_list); } public function column_cb( $schedule ) { if ($schedule['status'] == 'Active') { echo '<input type="checkbox" checked/>'; } else { echo '<input type="checkbox"/>'; } } public function _column_wpvivid_backup_type( $schedule ) { if (isset($schedule['backup']['backup_files'])) { $backup_type = $schedule['backup']['backup_files']; if ($backup_type === 'files+db') { $backup_type = 'Database + Files (WordPress Files)'; } else if ($backup_type === 'files') { $backup_type = 'WordPress Files (Exclude Database)'; } else if ($backup_type === 'db') { $backup_type = 'Only Database'; } } else { $backup_type = 'Custom'; } echo '<td>'.esc_html($backup_type).'</td>'; } public function _column_wpvivid_backup_cycles( $schedule ) { if (!isset($schedule['week'])) { $schedule['week'] = 'N/A'; } $schedule_type = $schedule['schedule_cycles']; echo '<td class="'.esc_attr($schedule['type']).'">'.esc_html($schedule_type).'</td>'; } public function _column_wpvivid_last_backup( $schedule ) { $last_backup_time = $schedule['last_backup_time']; echo '<td>'.esc_html($last_backup_time).'</td>'; } public function _column_wpvivid_next_backup( $schedule ) { $next_start = $schedule['next_start_time']; echo '<td>'.esc_html($next_start).'</td>'; } public function _column_wpvivid_storage( $schedule ) { if (isset($schedule['backup']['local'])) { if ($schedule['backup']['local'] == '1') { $backup_to = 'Localhost'; } else { $backup_to = 'Remote'; } } else { $backup_to = 'Localhost'; } echo '<td>'.esc_html($backup_to).'</td>'; } public function _column_wpvivid_on_off_control( $schedule ) { if($schedule['status'] === 'Active') { $style = 'checked'; } else { $style = ''; } echo '<td> <label class="mwp-wpvivid-switch" title="Enable/Disable the job"> <input class="mwp-wpvivid-schedule-on-off-control" type="checkbox" '.esc_attr($style).'> <span class="mwp-wpvivid-slider mwp-wpvivid-round"></span> </label> </td>'; } public function _column_wpvivid_actions( $schedule ) { echo '<td> <div> <img class="mwp-wpvivid-schedule-edit" src="' . esc_url(MAINWP_WPVIVID_EXTENSION_PLUGIN_URL . '/admin/images/Edit.png') . '" style="vertical-align:middle; cursor:pointer;" title="Edit the schedule" name="'.esc_attr(wp_json_encode($schedule)).'" /> <img class="mwp-wpvivid-schedule-delete" src="' . esc_url(MAINWP_WPVIVID_EXTENSION_PLUGIN_URL . '/admin/images/Delete.png') . '" style="vertical-align:middle; cursor:pointer;" title="Delete the schedule" /> </div> </td>'; } public function _column_wpvivid_status( $schedule ) { echo '<td class="mwp-wpvivid-schedule-status">'.esc_html($schedule['status']).'</td>'; } public function display_rows() { $this->_display_rows( $this->schedule_list ); } private function _display_rows($schedule_list) { $page=$this->get_pagenum(); $page_schedule_list=array(); $count=0; while ( $count<$page ) { $page_schedule_list = array_splice( $schedule_list, 0, 10); $count++; } foreach ( $page_schedule_list as $schedule) { $this->single_row($schedule); } } public function single_row($schedule) { $class='schedule-item'; ?> <tr class="<?php echo esc_attr($class);?>" slug="<?php echo esc_attr($schedule['id']);?>"> <?php $this->single_row_columns( $schedule ); ?> </tr> <?php } protected function pagination( $which ) { if ( empty( $this->_pagination_args ) ) { return; } $total_items = $this->_pagination_args['total_items']; $total_pages = $this->_pagination_args['total_pages']; $infinite_scroll = false; if ( isset( $this->_pagination_args['infinite_scroll'] ) ) { $infinite_scroll = $this->_pagination_args['infinite_scroll']; } if ( 'top' === $which && $total_pages > 1 ) { $this->screen->render_screen_reader_content( 'heading_pagination' ); } /* translators: %s: Number of comments. */ $output = '<span class="displaying-num">' . sprintf( _n( '%s item', '%s items', $total_items ), number_format_i18n( $total_items ) ) . '</span>'; $current = $this->get_pagenum(); $page_links = array(); $total_pages_before = '<span class="paging-input">'; $total_pages_after = '</span></span>'; $disable_first = $disable_last = $disable_prev = $disable_next = false; if ( $current == 1 ) { $disable_first = true; $disable_prev = true; } if ( $current == 2 ) { $disable_first = true; } if ( $current == $total_pages ) { $disable_last = true; $disable_next = true; } if ( $current == $total_pages - 1 ) { $disable_last = true; } if ( $disable_first ) { $page_links[] = '<span class="tablenav-pages-navspan button disabled" aria-hidden="true">«</span>'; } else { $page_links[] = sprintf( "<div class='first-page button'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></div>", __( 'First page' ), '«' ); } if ( $disable_prev ) { $page_links[] = '<span class="tablenav-pages-navspan button disabled" aria-hidden="true">‹</span>'; } else { $page_links[] = sprintf( "<div class='prev-page button' value='%s'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></div>", $current, __( 'Previous page' ), '‹' ); } if ( 'bottom' === $which ) { $html_current_page = $current; $total_pages_before = '<span class="screen-reader-text">' . __( 'Current Page' ) . '</span><span id="table-paging" class="paging-input"><span class="tablenav-paging-text">'; } else { $html_current_page = sprintf( "%s<input class='current-page' id='current-page-selector-schedule' type='text' name='paged' value='%s' size='%d' aria-describedby='table-paging' /><span class='tablenav-paging-text'>", '<label for="current-page-selector-schedule" class="screen-reader-text">' . __( 'Current Page' ) . '</label>', $current, strlen( $total_pages ) ); } $html_total_pages = sprintf( "<span class='total-pages'>%s</span>", number_format_i18n( $total_pages ) ); /* translators: 1: Current page, 2: Total pages. */ $page_links[] = $total_pages_before . sprintf( _x( '%1$s of %2$s', 'paging' ), $html_current_page, $html_total_pages ) . $total_pages_after; if ( $disable_next ) { $page_links[] = '<span class="tablenav-pages-navspan button disabled" aria-hidden="true">›</span>'; } else { $page_links[] = sprintf( "<div class='next-page button' value='%s'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></div>", $current, __( 'Next page' ), '›' ); } if ( $disable_last ) { $page_links[] = '<span class="tablenav-pages-navspan button disabled" aria-hidden="true">»</span>'; } else { $page_links[] = sprintf( "<div class='last-page button'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></div>", __( 'Last page' ), '»' ); } $pagination_links_class = 'pagination-links'; if ( ! empty( $infinite_scroll ) ) { $pagination_links_class .= ' hide-if-js'; } $output .= "\n<span class='$pagination_links_class'>" . join( "\n", $page_links ) . '</span>'; if ( $total_pages ) { $page_class = $total_pages < 2 ? ' one-page' : ''; } else { $page_class = ' no-pages'; } $this->_pagination = "<div class='tablenav-pages{$page_class}'>$output</div>"; echo $this->_pagination; } protected function display_tablenav( $which ) { $css_type = ''; if ( 'top' === $which ) { wp_nonce_field( 'bulk-' . $this->_args['plural'] ); $css_type = 'margin: 0 0 10px 0'; } else if( 'bottom' === $which ) { $css_type = 'margin: 10px 0 0 0'; } $total_pages = $this->_pagination_args['total_pages']; if ( $total_pages >1) { ?> <div class="tablenav <?php echo esc_attr($which); ?>" style="<?php echo esc_attr($css_type); ?>"> <?php $this->extra_tablenav($which); $this->pagination($which); ?> <br class="clear"/> </div> <?php } } protected function get_table_classes() { return array( 'widefat plugin-install' ); } } class Mainwp_WPvivid_Schedule_Global_List extends WP_List_Table { public $page_num; public $schedule_list; public function __construct( $args = array() ) { parent::__construct( array( 'plural' => 'schedule', 'screen' => 'schedule', ) ); } public function print_column_headers( $with_id = true ) { list( $columns, $hidden, $sortable, $primary ) = $this->get_column_info(); if (!empty($columns['cb'])) { static $cb_counter = 1; $columns['cb'] = '<label class="screen-reader-text" for="cb-select-all-' . $cb_counter . '">' . __('Select All') . '</label>' . '<input id="cb-select-all-' . $cb_counter . '" type="checkbox"/>'; $cb_counter++; } foreach ( $columns as $column_key => $column_display_name ) { $class = array( 'manage-column', "column-$column_key" ); if ( in_array( $column_key, $hidden ) ) { $class[] = 'hidden'; } if ( $column_key === $primary ) { $class[] = 'column-primary'; } if ( $column_key === 'cb' ) { $class[] = 'check-column'; } $tag = ( 'cb' === $column_key ) ? 'td' : 'th'; $scope = ( 'th' === $tag ) ? 'scope="col"' : ''; $id = $with_id ? "id='$column_key'" : ''; if ( ! empty( $class ) ) { $class = "class='" . join( ' ', $class ) . "'"; } echo "<$tag $scope $id $class>$column_display_name</$tag>"; } } public function get_columns() { $columns['wpvivid_backup_type'] = __( 'Backup Type', 'wpvivid' ); $columns['wpvivid_backup_cycles'] = __( 'Backup Cycles', 'wpvivid' ); $columns['wpvivid_start_time'] = __( 'Start Time', 'wpvivid' ); $columns['wpvivid_storage'] = __( 'Storage', 'wpvivid' ); $columns['wpvivid_on_off_control'] = __( 'On/off', 'wpvivid' ); $columns['wpvivid_actions'] = __( 'Actions', 'wpvivid' ); return $columns; } public function set_schedule_list($schedule_list,$page_num=1) { $this->schedule_list=$schedule_list; $this->page_num=$page_num; } public function get_pagenum() { if($this->page_num=='first') { $this->page_num=1; } else if($this->page_num=='last') { $this->page_num=$this->_pagination_args['total_pages']; } $pagenum = $this->page_num ? $this->page_num : 0; if ( isset( $this->_pagination_args['total_pages'] ) && $pagenum > $this->_pagination_args['total_pages'] ) { $pagenum = $this->_pagination_args['total_pages']; } return max( 1, $pagenum ); } public function prepare_items() { $columns = $this->get_columns(); $hidden = array(); $sortable = array(); $this->_column_headers = array($columns, $hidden, $sortable); $total_items =sizeof($this->schedule_list); $this->set_pagination_args( array( 'total_items' => $total_items, 'per_page' => 10, ) ); } public function has_items() { return !empty($this->schedule_list); } public function column_cb( $schedule ) { if ($schedule['status'] == 'Active') { echo '<input type="checkbox" checked/>'; } else { echo '<input type="checkbox"/>'; } } public function _column_wpvivid_status( $schedule ) { echo '<td class="mwp-wpvivid-schedule-status">'.esc_html($schedule['status']).'</td>'; } public function _column_wpvivid_backup_cycles( $schedule ) { if (!isset($schedule['week'])) { $schedule['week'] = 'N/A'; } //$schedule_type = $schedule['schedule_cycles']; $schedule_type = $schedule['type']; switch ($schedule_type){ case 'wpvivid_hourly': $schedule_type = 'Every hour'; break; case 'wpvivid_2hours': $schedule_type = 'Every 2 hours'; break; case 'wpvivid_4hours': $schedule_type = 'Every 4 hours'; break; case 'wpvivid_8hours': $schedule_type = 'Every 8 hours'; break; case 'wpvivid_12hours': $schedule_type = 'Every 12 hours'; break; case 'wpvivid_daily': $schedule_type = 'Daily'; break; case 'wpvivid_weekly': $schedule_type = 'Weekly'; break; case 'wpvivid_fortnightly': $schedule_type = 'Fortnightly'; break; case 'wpvivid_monthly': $schedule_type = 'Monthly'; break; default: $schedule_type = 'not found'; break; } if ($schedule_type === 'Weekly') { if (isset($schedule['week'])) { if ($schedule['week'] === 'sun') { $schedule_type = $schedule_type . '-Sunday'; } else if ($schedule['week'] === 'mon') { $schedule_type = $schedule_type . '-Monday'; } else if ($schedule['week'] === 'tue') { $schedule_type = $schedule_type . '-Tuesday'; } else if ($schedule['week'] === 'wed') { $schedule_type = $schedule_type . '-Wednesday'; } else if ($schedule['week'] === 'thu') { $schedule_type = $schedule_type . '-Thursday'; } else if ($schedule['week'] === 'fri') { $schedule_type = $schedule_type . '-Friday'; } else if ($schedule['week'] === 'sat') { $schedule_type = $schedule_type . '-Saturday'; } } } echo '<td class="'.esc_attr($schedule['type']).'">'.esc_html($schedule_type).'</td>'; } public function _column_wpvivid_start_time( $schedule ){ echo '<td>'.esc_html($schedule['current_day']).'</td>'; } public function _column_wpvivid_start_local_utc( $schedule ){ if(isset($schedule['start_time_local_utc'])){ $start_time_local_utc = $schedule['start_time_local_utc']; if($start_time_local_utc === 'local'){ $start_time_local_utc = 'Local Time'; } else{ $start_time_local_utc = 'UTC Time'; } } else{ $start_time_local_utc = 'UTC Time'; } echo '<td>'.esc_html($start_time_local_utc).'</td>'; } public function _column_wpvivid_last_backup( $schedule ) { if (isset($schedule['last_backup_time'])) { $offset=get_option('gmt_offset'); $localtime = $schedule['last_backup_time'] + $offset * 60 * 60; $last_backup_time = date("H:i:s - m/d/Y ", $schedule['last_backup_time']); } else { $last_backup_time = 'N/A'; } //$last_backup_time = $schedule['last_backup_time']; echo '<td>'.esc_html($last_backup_time).'</td>'; } public function _column_wpvivid_backup_type( $schedule ) { if (isset($schedule['backup']['backup_files'])) { $backup_type = $schedule['backup']['backup_files']; if ($backup_type === 'files+db') { $backup_type = 'Database + Files (WordPress Files)'; } else if ($backup_type === 'files') { $backup_type = 'WordPress Files (Exclude Database)'; } else if ($backup_type === 'db') { $backup_type = 'Only Database'; } } else { $backup_type = 'Custom'; } echo '<td>'.esc_html($backup_type).'</td>'; } public function _column_wpvivid_storage( $schedule ) { if (isset($schedule['backup']['local'])) { if ($schedule['backup']['local'] == '1') { $backup_to = 'Localhost'; } else { $backup_to = 'Remote'; } } else { $backup_to = 'Localhost'; } echo '<td>'.esc_html($backup_to).'</td>'; } public function _column_wpvivid_on_off_control( $schedule ) { if($schedule['status'] === 'Active') { $style = 'checked'; } else { $style = ''; } echo '<td> <label class="mwp-wpvivid-switch" title="Enable/Disable the job"> <input class="mwp-wpvivid-schedule-on-off-control" type="checkbox" '.esc_attr($style).'> <span class="mwp-wpvivid-slider mwp-wpvivid-round"></span> </label> </td>'; } public function _column_wpvivid_actions( $schedule ) { echo '<td> <div> <img class="mwp-wpvivid-schedule-edit" src="' . esc_url(MAINWP_WPVIVID_EXTENSION_PLUGIN_URL . '/admin/images/Edit.png') . '" style="vertical-align:middle; cursor:pointer;" title="Edit the schedule" /> <img class="mwp-wpvivid-schedule-delete" src="' . esc_url(MAINWP_WPVIVID_EXTENSION_PLUGIN_URL . '/admin/images/Delete.png') . '" style="vertical-align:middle; cursor:pointer;" title="Delete the schedule" /> </div> </td>'; } public function display_rows() { $this->_display_rows( $this->schedule_list ); } private function _display_rows($schedule_list) { $page=$this->get_pagenum(); $page_schedule_list=array(); $count=0; while ( $count<$page ) { $page_schedule_list = array_splice( $schedule_list, 0, 10); $count++; } foreach ( $page_schedule_list as $schedule) { $this->single_row($schedule); } } public function single_row($schedule) { $class='schedule-item'; ?> <tr class="<?php echo esc_attr($class);?>" slug="<?php echo esc_attr($schedule['id']);?>"> <?php $this->single_row_columns( $schedule ); ?> </tr> <?php } protected function pagination( $which ) { if ( empty( $this->_pagination_args ) ) { return; } $total_items = $this->_pagination_args['total_items']; $total_pages = $this->_pagination_args['total_pages']; $infinite_scroll = false; if ( isset( $this->_pagination_args['infinite_scroll'] ) ) { $infinite_scroll = $this->_pagination_args['infinite_scroll']; } if ( 'top' === $which && $total_pages > 1 ) { $this->screen->render_screen_reader_content( 'heading_pagination' ); } /* translators: %s: Number of comments. */ $output = '<span class="displaying-num">' . sprintf( _n( '%s item', '%s items', $total_items ), number_format_i18n( $total_items ) ) . '</span>'; $current = $this->get_pagenum(); $page_links = array(); $total_pages_before = '<span class="paging-input">'; $total_pages_after = '</span></span>'; $disable_first = $disable_last = $disable_prev = $disable_next = false; if ( $current == 1 ) { $disable_first = true; $disable_prev = true; } if ( $current == 2 ) { $disable_first = true; } if ( $current == $total_pages ) { $disable_last = true; $disable_next = true; } if ( $current == $total_pages - 1 ) { $disable_last = true; } if ( $disable_first ) { $page_links[] = '<span class="tablenav-pages-navspan button disabled" aria-hidden="true">«</span>'; } else { $page_links[] = sprintf( "<div class='first-page button'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></div>", __( 'First page' ), '«' ); } if ( $disable_prev ) { $page_links[] = '<span class="tablenav-pages-navspan button disabled" aria-hidden="true">‹</span>'; } else { $page_links[] = sprintf( "<div class='prev-page button' value='%s'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></div>", $current, __( 'Previous page' ), '‹' ); } if ( 'bottom' === $which ) { $html_current_page = $current; $total_pages_before = '<span class="screen-reader-text">' . __( 'Current Page' ) . '</span><span id="table-paging" class="paging-input"><span class="tablenav-paging-text">'; } else { $html_current_page = sprintf( "%s<input class='current-page' id='current-page-selector-schedule' type='text' name='paged' value='%s' size='%d' aria-describedby='table-paging' /><span class='tablenav-paging-text'>", '<label for="current-page-selector-schedule" class="screen-reader-text">' . __( 'Current Page' ) . '</label>', $current, strlen( $total_pages ) ); } $html_total_pages = sprintf( "<span class='total-pages'>%s</span>", number_format_i18n( $total_pages ) ); /* translators: 1: Current page, 2: Total pages. */ $page_links[] = $total_pages_before . sprintf( _x( '%1$s of %2$s', 'paging' ), $html_current_page, $html_total_pages ) . $total_pages_after; if ( $disable_next ) { $page_links[] = '<span class="tablenav-pages-navspan button disabled" aria-hidden="true">›</span>'; } else { $page_links[] = sprintf( "<div class='next-page button' value='%s'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></div>", $current, __( 'Next page' ), '›' ); } if ( $disable_last ) { $page_links[] = '<span class="tablenav-pages-navspan button disabled" aria-hidden="true">»</span>'; } else { $page_links[] = sprintf( "<div class='last-page button'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></div>", __( 'Last page' ), '»' ); } $pagination_links_class = 'pagination-links'; if ( ! empty( $infinite_scroll ) ) { $pagination_links_class .= ' hide-if-js'; } $output .= "\n<span class='$pagination_links_class'>" . join( "\n", $page_links ) . '</span>'; if ( $total_pages ) { $page_class = $total_pages < 2 ? ' one-page' : ''; } else { $page_class = ' no-pages'; } $this->_pagination = "<div class='tablenav-pages{$page_class}'>$output</div>"; echo $this->_pagination; } protected function display_tablenav( $which ) { $css_type = ''; if ( 'top' === $which ) { wp_nonce_field( 'bulk-' . $this->_args['plural'] ); $css_type = 'margin: 0 0 10px 0'; } else if( 'bottom' === $which ) { $css_type = 'margin: 10px 0 0 0'; } $total_pages = $this->_pagination_args['total_pages']; if ( $total_pages >1) { ?> <div class="tablenav <?php echo esc_attr($which); ?>" style="<?php echo esc_attr($css_type); ?>"> <?php $this->extra_tablenav($which); $this->pagination($which); ?> <br class="clear"/> </div> <?php } } protected function get_table_classes() { return array( 'widefat plugin-install' ); } } class Mainwp_WPvivid_Schedule_Mould_List extends WP_List_Table { public $page_num; public $schedule_mould_list; public function __construct( $args = array() ) { parent::__construct( array( 'plural' => 'schedule_mould', 'screen' => 'schedule_mould', ) ); } public function print_column_headers( $with_id = true ) { list( $columns, $hidden, $sortable, $primary ) = $this->get_column_info(); if (!empty($columns['cb'])) { static $cb_counter = 1; $columns['cb'] = '<label class="screen-reader-text" for="cb-select-all-' . $cb_counter . '">' . __('Select All') . '</label>' . '<input id="cb-select-all-' . $cb_counter . '" type="checkbox"/>'; $cb_counter++; } foreach ( $columns as $column_key => $column_display_name ) { $class = array( 'manage-column', "column-$column_key" ); if ( in_array( $column_key, $hidden ) ) { $class[] = 'hidden'; } if ( $column_key === $primary ) { $class[] = 'column-primary'; } if ( $column_key === 'cb' ) { $class[] = 'check-column'; } $tag = ( 'cb' === $column_key ) ? 'td' : 'th'; $scope = ( 'th' === $tag ) ? 'scope="col"' : ''; $id = $with_id ? "id='$column_key'" : ''; if ( ! empty( $class ) ) { $class = "class='" . join( ' ', $class ) . "'"; } echo "<$tag $scope $id $class>$column_display_name</$tag>"; } } public function get_columns() { $columns = array(); $columns['wpvivid_mould_name'] = __( 'Mould Name', 'wpvivid' ); $columns['wpvivid_sync_mould'] = __( 'Sync Mould', 'wpvivid' ); $columns['wpvivid_actions'] = __( 'Actions', 'wpvivid' ); return $columns; } public function set_schedule_mould_list($schedule_mould_list,$page_num=1) { $this->schedule_mould_list=$schedule_mould_list; $this->page_num=$page_num; } public function get_pagenum() { if($this->page_num=='first') { $this->page_num=1; } else if($this->page_num=='last') { $this->page_num=$this->_pagination_args['total_pages']; } $pagenum = $this->page_num ? $this->page_num : 0; if ( isset( $this->_pagination_args['total_pages'] ) && $pagenum > $this->_pagination_args['total_pages'] ) { $pagenum = $this->_pagination_args['total_pages']; } return max( 1, $pagenum ); } public function prepare_items() { $columns = $this->get_columns(); $hidden = array(); $sortable = array(); $this->_column_headers = array($columns, $hidden, $sortable); $total_items =sizeof($this->schedule_mould_list); $this->set_pagination_args( array( 'total_items' => $total_items, 'per_page' => 10, ) ); } public function has_items() { return !empty($this->schedule_mould_list); } public function _column_wpvivid_mould_name( $schedule_mould ) { echo '<td><div>'.esc_html($schedule_mould['mould_name']).'</div></td>'; } public function _column_wpvivid_sync_mould( $schedule_mould ) { echo '<td><input class="ui green mini button mwp-wpvivid-sync-schedule-mould" type="button" value="Sync" /></td>'; } public function _column_wpvivid_actions( $schedule_mould ) { echo '<td> <div> <img class="mwp-wpvivid-schedule-mould-edit" src="' . esc_url(MAINWP_WPVIVID_EXTENSION_PLUGIN_URL . '/admin/images/Edit.png') . '" style="vertical-align:middle; cursor:pointer;" title="Edit the schedule" /> <img class="mwp-wpvivid-schedule-mould-delete" src="' . esc_url(MAINWP_WPVIVID_EXTENSION_PLUGIN_URL . '/admin/images/Delete.png') . '" style="vertical-align:middle; cursor:pointer;" title="Delete the schedule" /> </div> </td>'; } public function display_rows() { $this->_display_rows( $this->schedule_mould_list ); } private function _display_rows($schedule_mould_list) { foreach ($schedule_mould_list as $mould_name => $schedule_mould) { foreach ($schedule_mould_list[$mould_name] as $schedule_id => $schedule_value) { $schedule_mould_list[$mould_name][$schedule_id]['mould_name'] = $mould_name; } } $page=$this->get_pagenum(); $page_schedule_mould_list=array(); $count=0; while ( $count<$page ) { $page_schedule_mould_list = array_splice( $schedule_mould_list, 0, 10); $count++; } foreach ( $page_schedule_mould_list as $mould_name => $schedule_mould) { foreach ($schedule_mould as $schedule_id => $schedule_value) { $mould_name = $schedule_value['mould_name']; } $schedule_mould['mould_name'] = $mould_name; $this->single_row($schedule_mould); } } public function single_row($schedule_mould) { ?> <tr slug="<?php echo esc_attr($schedule_mould['mould_name']);?>"> <?php $this->single_row_columns( $schedule_mould ); ?> </tr> <?php } protected function pagination( $which ) { if ( empty( $this->_pagination_args ) ) { return; } $total_items = $this->_pagination_args['total_items']; $total_pages = $this->_pagination_args['total_pages']; $infinite_scroll = false; if ( isset( $this->_pagination_args['infinite_scroll'] ) ) { $infinite_scroll = $this->_pagination_args['infinite_scroll']; } if ( 'top' === $which && $total_pages > 1 ) { $this->screen->render_screen_reader_content( 'heading_pagination' ); } /* translators: %s: Number of comments. */ $output = '<span class="displaying-num">' . sprintf( _n( '%s item', '%s items', $total_items ), number_format_i18n( $total_items ) ) . '</span>'; $current = $this->get_pagenum(); $page_links = array(); $total_pages_before = '<span class="paging-input">'; $total_pages_after = '</span></span>'; $disable_first = $disable_last = $disable_prev = $disable_next = false; if ( $current == 1 ) { $disable_first = true; $disable_prev = true; } if ( $current == 2 ) { $disable_first = true; } if ( $current == $total_pages ) { $disable_last = true; $disable_next = true; } if ( $current == $total_pages - 1 ) { $disable_last = true; } if ( $disable_first ) { $page_links[] = '<span class="tablenav-pages-navspan button disabled" aria-hidden="true">«</span>'; } else { $page_links[] = sprintf( "<div class='first-page button'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></div>", __( 'First page' ), '«' ); } if ( $disable_prev ) { $page_links[] = '<span class="tablenav-pages-navspan button disabled" aria-hidden="true">‹</span>'; } else { $page_links[] = sprintf( "<div class='prev-page button' value='%s'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></div>", $current, __( 'Previous page' ), '‹' ); } if ( 'bottom' === $which ) { $html_current_page = $current; $total_pages_before = '<span class="screen-reader-text">' . __( 'Current Page' ) . '</span><span id="table-paging" class="paging-input"><span class="tablenav-paging-text">'; } else { $html_current_page = sprintf( "%s<input class='current-page' id='current-page-selector-schedule' type='text' name='paged' value='%s' size='%d' aria-describedby='table-paging' /><span class='tablenav-paging-text'>", '<label for="current-page-selector-schedule" class="screen-reader-text">' . __( 'Current Page' ) . '</label>', $current, strlen( $total_pages ) ); } $html_total_pages = sprintf( "<span class='total-pages'>%s</span>", number_format_i18n( $total_pages ) ); /* translators: 1: Current page, 2: Total pages. */ $page_links[] = $total_pages_before . sprintf( _x( '%1$s of %2$s', 'paging' ), $html_current_page, $html_total_pages ) . $total_pages_after; if ( $disable_next ) { $page_links[] = '<span class="tablenav-pages-navspan button disabled" aria-hidden="true">›</span>'; } else { $page_links[] = sprintf( "<div class='next-page button' value='%s'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></div>", $current, __( 'Next page' ), '›' ); } if ( $disable_last ) { $page_links[] = '<span class="tablenav-pages-navspan button disabled" aria-hidden="true">»</span>'; } else { $page_links[] = sprintf( "<div class='last-page button'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></div>", __( 'Last page' ), '»' ); } $pagination_links_class = 'pagination-links'; if ( ! empty( $infinite_scroll ) ) { $pagination_links_class .= ' hide-if-js'; } $output .= "\n<span class='$pagination_links_class'>" . join( "\n", $page_links ) . '</span>'; if ( $total_pages ) { $page_class = $total_pages < 2 ? ' one-page' : ''; } else { $page_class = ' no-pages'; } $this->_pagination = "<div class='tablenav-pages{$page_class}'>$output</div>"; echo $this->_pagination; } protected function display_tablenav( $which ) { $css_type = ''; if ( 'top' === $which ) { wp_nonce_field( 'bulk-' . $this->_args['plural'] ); $css_type = 'margin: 0 0 10px 0'; } else if( 'bottom' === $which ) { $css_type = 'margin: 10px 0 0 0'; } $total_pages = $this->_pagination_args['total_pages']; if ( $total_pages >1) { ?> <div class="tablenav <?php echo esc_attr($which); ?>" style="<?php echo esc_attr($css_type); ?>"> <?php $this->extra_tablenav($which); $this->pagination($which); ?> <br class="clear"/> </div> <?php } } protected function get_table_classes() { return array( 'widefat plugin-install' ); } } class Mainwp_WPvivid_Extension_SchedulePage { private $setting; private $setting_addon; private $global_custom_setting; private $time_zone; private $select_pro; private $site_id; public $main_tab; public function __construct() { add_action('wp_ajax_mwp_wpvivid_sync_schedule', array($this, 'sync_schedule')); add_action('wp_ajax_mwp_wpvivid_set_schedule', array($this, 'set_schedule')); add_action('wp_ajax_mwp_wpvivid_set_global_schedule', array($this, 'set_global_schedule')); add_action('wp_ajax_mwp_wpvivid_get_schedules_addon', array($this, 'get_schedules_addon')); add_action('wp_ajax_mwp_wpvivid_create_schedule_addon', array($this, 'create_schedule_addon')); add_action('wp_ajax_mwp_wpvivid_update_schedule_addon', array($this, 'update_schedule_addon')); add_action('wp_ajax_mwp_wpvivid_delete_schedule_addon', array($this, 'delete_schedule_addon')); add_action('wp_ajax_mwp_wpvivid_edit_schedule_addon', array($this, 'edit_schedule_addon')); add_action('wp_ajax_mwp_wpvivid_save_schedule_status_addon', array($this, 'save_schedule_status_addon')); add_action('wp_ajax_mwp_wpvivid_global_create_schedule_addon', array($this, 'global_create_schedule_addon')); add_action('wp_ajax_mwp_wpvivid_edit_global_schedule_addon', array($this, 'edit_global_schedule_addon')); add_action('wp_ajax_mwp_wpvivid_global_update_schedule_addon', array($this, 'global_update_schedule_addon')); add_action('wp_ajax_mwp_wpvivid_global_delete_schedule_addon', array($this, 'global_delete_schedule_addon')); add_action('wp_ajax_mwp_wpvivid_global_save_schedule_status_addon', array($this, 'global_save_schedule_status_addon')); add_action('wp_ajax_mwp_wpvivid_edit_global_schedule_mould_addon', array($this, 'edit_global_schedule_mould_addon')); add_action('wp_ajax_mwp_wpvivid_delete_global_schedule_mould_addon', array($this, 'delete_global_schedule_mould_addon')); add_action('wp_ajax_mwp_wpvivid_get_schedule_mould_list', array($this, 'get_schedule_mould_list')); add_action('wp_ajax_mwp_wpvivid_update_global_schedule_backup_exclude_extension_addon', array($this, 'update_global_schedule_backup_exclude_extension_addon')); add_action('wp_ajax_mwp_wpvivid_edit_global_schedule_mould_name_addon', array($this, 'edit_global_schedule_mould_name_addon')); } public function set_site_id($site_id) { $this->site_id=$site_id; } public function set_schedule_info($setting, $setting_addon=array(), $global_custom_setting=array(), $time_zone=0, $select_pro=0) { $this->setting=$setting; $this->setting_addon=$setting_addon; $this->global_custom_setting=$global_custom_setting; $this->select_pro=$select_pro; $this->time_zone=$time_zone; } public function sync_schedule() { global $mainwp_wpvivid_extension_activator; $mainwp_wpvivid_extension_activator->mwp_ajax_check_security(); try { if(isset($_POST['id']) && !empty($_POST['id']) && is_string($_POST['id'])) { $site_id = sanitize_key($_POST['id']); $check_addon = '0'; if(isset($_POST['addon']) && !empty($_POST['addon']) && is_string($_POST['addon'])) { $check_addon = sanitize_text_field($_POST['addon']); } if($check_addon == '1'){ $schedule_mould_name = ''; if(isset($_POST['schedule_mould_name']) && !empty($_POST['schedule_mould_name'])){ $schedule_mould_name = sanitize_text_field($_POST['schedule_mould_name']); } $post_data['mwp_action'] = 'wpvivid_sync_schedule_addon_mainwp'; $schedule_mould = Mainwp_WPvivid_Extension_DB_Option::get_instance()->wpvivid_get_global_option('schedule_mould_addon', array()); $schedules = $schedule_mould[$schedule_mould_name]; if(isset($_POST['default_setting'])){ $default_setting = sanitize_text_field($_POST['default_setting']); } else{ $default_setting = 'default_only'; } $post_data['schedule'] = $schedules; $post_data['default_setting'] = $default_setting; } else { $post_data['mwp_action'] = 'wpvivid_set_schedule_mainwp'; $schedule = Mainwp_WPvivid_Extension_DB_Option::get_instance()->wpvivid_get_global_option('schedule', array()); Mainwp_WPvivid_Extension_DB_Option::get_instance()->wpvivid_update_option($site_id, 'schedule', $schedule); if ($schedule['enable'] == 1) { $schedule_data['enable'] = $schedule['enable']; $schedule_data['recurrence'] = $schedule['type']; $schedule_data['event'] = $schedule['event']; $schedule_data['backup_type'] = $schedule['backup']['backup_files']; if ($schedule['backup']['remote'] == 1) { $schedule_data['save_local_remote'] = 'remote'; } else { $schedule_data['save_local_remote'] = 'local'; } $schedule_data['lock'] = 0; } else { $schedule_data['enable'] = $schedule['enable']; } $post_data['schedule'] = wp_json_encode($schedule_data); } $information = apply_filters('mainwp_fetchurlauthed', $mainwp_wpvivid_extension_activator->childFile, $mainwp_wpvivid_extension_activator->childKey, $site_id, 'wpvivid_backuprestore', $post_data); if (isset($information['error'])) { $ret['result'] = 'failed'; $ret['error'] = $information['error']; } else { $ret['result'] = 'success'; } echo wp_json_encode($ret); } die(); } 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().';'; error_log($message); echo wp_json_encode(array('result'=>'failed','error'=>$message)); die(); } } public function set_schedule() { global $mainwp_wpvivid_extension_activator; $mainwp_wpvivid_extension_activator->mwp_ajax_check_security(); try { if(isset($_POST['site_id']) && !empty($_POST['site_id']) && is_string($_POST['site_id']) && isset($_POST['schedule']) && !empty($_POST['schedule']) && is_string($_POST['schedule'])) { $schedule = array(); $site_id = sanitize_key($_POST['site_id']); $json = stripslashes(sanitize_text_field($_POST['schedule'])); $schedule = json_decode($json, true); $options = Mainwp_WPvivid_Extension_DB_Option::get_instance()->wpvivid_get_option($site_id, 'schedule', array()); if ($schedule['mwp_enable'] == 1) { $options['enable'] = $schedule['mwp_enable']; $options['type'] = $schedule['mwp_recurrence']; if (!defined('WPVIVID_MAIN_SCHEDULE_EVENT')) define('WPVIVID_MAIN_SCHEDULE_EVENT', 'wpvivid_main_schedule_event'); $options['event'] = WPVIVID_MAIN_SCHEDULE_EVENT; $options['start_time'] = 0; $options['backup']['backup_files'] = $schedule['mwp_backup_type']; if ($schedule['mwp_save_local_remote'] == 'remote') { $options['backup']['local'] = 0; $options['backup']['remote'] = 1; } else { $options['backup']['local'] = 1; $options['backup']['remote'] = 0; } $options['backup']['ismerge'] = 1; $options['backup']['lock'] = $schedule['mwp_lock']; } else { $options['enable'] = $schedule['mwp_enable']; } Mainwp_WPvivid_Extension_DB_Option::get_instance()->wpvivid_update_option($site_id, 'schedule', $options); $new_schedule = Mainwp_WPvivid_Extension_DB_Option::get_instance()->wpvivid_get_option($site_id, 'schedule', array()); if ($new_schedule['enable'] == 1) { $schedule_data['enable'] = $new_schedule['enable']; $schedule_data['recurrence'] = $new_schedule['type']; $schedule_data['event'] = $new_schedule['event']; $schedule_data['backup_type'] = $new_schedule['backup']['backup_files']; if ($new_schedule['backup']['remote'] == 1) { $schedule_data['save_local_remote'] = 'remote'; } else { $schedule_data['save_local_remote'] = 'local'; } $schedule_data['lock'] = 0; } else { $schedule_data['enable'] = $new_schedule['enable']; } $post_data['mwp_action'] = 'wpvivid_set_schedule_mainwp'; $post_data['schedule'] = wp_json_encode($schedule_data); $information = apply_filters('mainwp_fetchurlauthed', $mainwp_wpvivid_extension_activator->childFile, $mainwp_wpvivid_extension_activator->childKey, $site_id, 'wpvivid_backuprestore', $post_data); if (isset($information['error'])) { $ret['result'] = 'failed'; $ret['error'] = $information['error']; } else { $ret['result'] = 'success'; } echo wp_json_encode($ret); } die(); } 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().';'; error_log($message); echo wp_json_encode(array('result'=>'failed','error'=>$message)); die(); } } public function set_global_schedule() { global $mainwp_wpvivid_extension_activator; $mainwp_wpvivid_extension_activator->mwp_ajax_check_security(); try { $schedule = array(); if (isset($_POST['schedule']) && !empty($_POST['schedule']) && is_string($_POST['schedule'])) { $json = stripslashes(sanitize_text_field($_POST['schedule'])); $schedule = json_decode($json, true); $options = Mainwp_WPvivid_Extension_DB_Option::get_instance()->wpvivid_get_global_option('schedule', array()); if(empty($options)){ $options = array(); } if ($schedule['mwp_enable'] == 1) { $options['enable'] = $schedule['mwp_enable']; $options['type'] = $schedule['mwp_recurrence']; if (!defined('WPVIVID_MAIN_SCHEDULE_EVENT')) define('WPVIVID_MAIN_SCHEDULE_EVENT', 'wpvivid_main_schedule_event'); $options['event'] = WPVIVID_MAIN_SCHEDULE_EVENT; $options['start_time'] = 0; $options['backup']['backup_files'] = $schedule['mwp_backup_type']; if ($schedule['mwp_save_local_remote'] == 'remote') { $options['backup']['local'] = 0; $options['backup']['remote'] = 1; } else { $options['backup']['local'] = 1; $options['backup']['remote'] = 0; } $options['backup']['ismerge'] = 1; $options['backup']['lock'] = $schedule['mwp_lock']; } else { $options['enable'] = $schedule['mwp_enable']; } Mainwp_WPvivid_Extension_DB_Option::get_instance()->wpvivid_update_global_option('schedule', $options); $ret['result'] = 'success'; echo wp_json_encode($ret); } die(); } 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().';'; error_log($message); echo wp_json_encode(array('result'=>'failed','error'=>$message)); die(); } } public function get_schedules_addon() { global $mainwp_wpvivid_extension_activator; $mainwp_wpvivid_extension_activator->mwp_ajax_check_security(); try{ if(isset($_POST['site_id']) && !empty($_POST['site_id']) && is_string($_POST['site_id'])) { $site_id = sanitize_key($_POST['site_id']); $post_data['mwp_action'] = 'wpvivid_get_schedules_addon_mainwp'; $information = apply_filters('mainwp_fetchurlauthed', $mainwp_wpvivid_extension_activator->childFile, $mainwp_wpvivid_extension_activator->childKey, $site_id, 'wpvivid_backuprestore', $post_data); if (isset($information['error'])) { $ret['result'] = 'failed'; $ret['error'] = $information['error']; } else { $ret['result'] = 'success'; $table=new Mainwp_WPvivid_Schedule_List(); $table->set_schedule_list($information['schedule_info']); $table->prepare_items(); ob_start(); $table->display(); $html = ob_get_clean(); $ret['html'] = $html; } echo wp_json_encode($ret); } die(); } 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().';'; error_log($message); echo wp_json_encode(array('result'=>'failed','error'=>$message)); die(); } } public function create_schedule_addon() { global $mainwp_wpvivid_extension_activator; $mainwp_wpvivid_extension_activator->mwp_ajax_check_security(); try { if(isset($_POST['site_id']) && !empty($_POST['site_id']) && is_string($_POST['site_id']) && isset($_POST['schedule']) && !empty($_POST['schedule']) && is_string($_POST['schedule'])) { $site_id = sanitize_key($_POST['site_id']); $json = stripslashes(sanitize_text_field($_POST['schedule'])); $post_data['mwp_action'] = 'wpvivid_create_schedule_addon_mainwp'; $json = json_decode($json, true); if(isset($json['custom_dirs'])){ $mainwp_wpvivid_extension_activator->mwp_wpvivid_update_backup_custom_setting($site_id, $json); } $json = wp_json_encode($json); $post_data['schedule'] = $json; $information = apply_filters('mainwp_fetchurlauthed', $mainwp_wpvivid_extension_activator->childFile, $mainwp_wpvivid_extension_activator->childKey, $site_id, 'wpvivid_backuprestore', $post_data); if (isset($information['error'])) { $ret['result'] = 'failed'; $ret['error'] = $information['error']; $ret['notice'] = apply_filters('mwp_wpvivid_set_schedule_notice', false, $information['error']); } else { $ret['result'] = 'success'; $table=new Mainwp_WPvivid_Schedule_List(); $table->set_schedule_list($information['schedule_info']); $table->prepare_items(); ob_start(); $table->display(); $html = ob_get_clean(); $ret['html'] = $html; $success_msg = 'You have successfully added a schedule.'; $ret['notice'] = apply_filters('mwp_wpvivid_set_schedule_notice', true, $success_msg); if(isset($information['enable_incremental_schedules'])){ if(empty($information['enable_incremental_schedules'])) $information['enable_incremental_schedules'] = 0; $mainwp_wpvivid_extension_activator->set_incremental_enable($site_id, $information['enable_incremental_schedules']); } if(isset($information['incremental_schedules'])){ $mainwp_wpvivid_extension_activator->set_incremental_schedules($site_id, $information['incremental_schedules']); } if(isset($information['incremental_backup_data'])){ $mainwp_wpvivid_extension_activator->set_incremental_backup_data($site_id, $information['incremental_backup_data']); } if(isset($information['incremental_output_msg'])){ $mainwp_wpvivid_extension_activator->set_incremental_output_msg($site_id, $information['incremental_output_msg']); } } echo wp_json_encode($ret); } } 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().';'; error_log($message); echo wp_json_encode(array('result'=>'failed','error'=>$message)); } die(); } public function update_schedule_addon() { global $mainwp_wpvivid_extension_activator; $mainwp_wpvivid_extension_activator->mwp_ajax_check_security(); try { if(isset($_POST['site_id']) && !empty($_POST['site_id']) && is_string($_POST['site_id']) && isset($_POST['schedule']) && !empty($_POST['schedule']) && is_string($_POST['schedule'])) { $site_id = sanitize_key($_POST['site_id']); $json = stripslashes(sanitize_text_field($_POST['schedule'])); $post_data['mwp_action'] = 'wpvivid_update_schedule_addon_mainwp'; $json = json_decode($json, true); if(isset($json['custom_dirs'])){ $mainwp_wpvivid_extension_activator->mwp_wpvivid_update_backup_custom_setting($site_id, $json); } $json = wp_json_encode($json); $post_data['schedule'] = $json; $information = apply_filters('mainwp_fetchurlauthed', $mainwp_wpvivid_extension_activator->childFile, $mainwp_wpvivid_extension_activator->childKey, $site_id, 'wpvivid_backuprestore', $post_data); if (isset($information['error'])) { $ret['result'] = 'failed'; $ret['error'] = $information['error']; $ret['notice'] = apply_filters('mwp_wpvivid_set_schedule_notice', false, $information['error']); } else { $ret['result'] = 'success'; $table=new Mainwp_WPvivid_Schedule_List(); $table->set_schedule_list($information['schedule_info']); $table->prepare_items(); ob_start(); $table->display(); $html = ob_get_clean(); $ret['html'] = $html; $success_msg = 'You have successfully updated the schedule.'; $ret['notice'] = apply_filters('mwp_wpvivid_set_schedule_notice', true, $success_msg); } echo wp_json_encode($ret); } die(); } 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().';'; error_log($message); echo wp_json_encode(array('result'=>'failed','error'=>$message)); die(); } } public function delete_schedule_addon() { global $mainwp_wpvivid_extension_activator; $mainwp_wpvivid_extension_activator->mwp_ajax_check_security(); try{ if(isset($_POST['site_id']) && !empty($_POST['site_id']) && is_string($_POST['site_id']) && isset($_POST['schedule_id']) && !empty($_POST['schedule_id']) && is_string($_POST['schedule_id'])) { $site_id = sanitize_key($_POST['site_id']); $post_data['mwp_action'] = 'wpvivid_delete_schedule_addon_mainwp'; $post_data['schedule_id'] = sanitize_key($_POST['schedule_id']); $information = apply_filters('mainwp_fetchurlauthed', $mainwp_wpvivid_extension_activator->childFile, $mainwp_wpvivid_extension_activator->childKey, $site_id, 'wpvivid_backuprestore', $post_data); if (isset($information['error'])) { $ret['result'] = 'failed'; $ret['error'] = $information['error']; $ret['notice'] = apply_filters('mwp_wpvivid_set_schedule_notice', false, $information['error']); } else { $ret['result'] = 'success'; $table=new Mainwp_WPvivid_Schedule_List(); $table->set_schedule_list($information['schedule_info']); $table->prepare_items(); ob_start(); $table->display(); $html = ob_get_clean(); $ret['html'] = $html; $success_msg = 'The schedule has been deleted successfully.'; $ret['notice'] = apply_filters('mwp_wpvivid_set_schedule_notice', true, $success_msg); } echo wp_json_encode($ret); } die(); } 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().';'; error_log($message); echo wp_json_encode(array('result'=>'failed','error'=>$message)); die(); } } public function edit_schedule_addon() { global $mainwp_wpvivid_extension_activator; $mainwp_wpvivid_extension_activator->mwp_ajax_check_security(); try{ if(isset($_POST['site_id']) && !empty($_POST['site_id']) && is_string($_POST['site_id']) && isset($_POST['schedule_id']) && !empty($_POST['schedule_id']) && is_string($_POST['schedule_id'])){ $site_id = sanitize_key($_POST['site_id']); $schedule_id = sanitize_key($_POST['schedule_id']); $post_data['mwp_action'] = 'wpvivid_get_database_tables_addon_mainwp'; $information = apply_filters('mainwp_fetchurlauthed', $mainwp_wpvivid_extension_activator->childFile, $mainwp_wpvivid_extension_activator->childKey, $site_id, 'wpvivid_backuprestore', $post_data); if (isset($information['error'])) { $ret['result'] = 'failed'; $ret['error'] = $information['error']; } else { $ret['result'] = 'success'; $ret['database_tables'] = Mainwp_WPvivid_Extension_Subpage::output_edit_schedule_database_table($information['base_tables'], $information['other_tables'], false, $site_id, $schedule_id); } echo wp_json_encode($ret); } die(); } 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().';'; error_log($message); echo wp_json_encode(array('result'=>'failed','error'=>$message)); die(); } } public function save_schedule_status_addon() { global $mainwp_wpvivid_extension_activator; $mainwp_wpvivid_extension_activator->mwp_ajax_check_security(); try{ if(isset($_POST['site_id']) && !empty($_POST['site_id']) && is_string($_POST['site_id']) && isset($_POST['schedule_data']) && !empty($_POST['schedule_data']) && is_string($_POST['schedule_data'])) { $site_id = sanitize_key($_POST['site_id']); $post_data['mwp_action'] = 'wpvivid_save_schedule_status_addon_mainwp'; $post_data['schedule_data'] = stripslashes(sanitize_text_field($_POST['schedule_data'])); $information = apply_filters('mainwp_fetchurlauthed', $mainwp_wpvivid_extension_activator->childFile, $mainwp_wpvivid_extension_activator->childKey, $site_id, 'wpvivid_backuprestore', $post_data); if (isset($information['error'])) { $ret['result'] = 'failed'; $ret['error'] = $information['error']; $ret['notice'] = apply_filters('mwp_wpvivid_set_schedule_notice', false, $information['error']); } else { $ret['result'] = 'success'; $table=new Mainwp_WPvivid_Schedule_List(); $table->set_schedule_list($information['schedule_info']); $table->prepare_items(); ob_start(); $table->display(); $html = ob_get_clean(); $ret['html'] = $html; $success_msg = 'You have successfully saved the changes.'; $ret['notice'] = apply_filters('mwp_wpvivid_set_schedule_notice', true, $success_msg); if(isset($information['enable_incremental_schedules'])){ if(empty($information['enable_incremental_schedules'])) $information['enable_incremental_schedules'] = 0; $mainwp_wpvivid_extension_activator->set_incremental_enable($site_id, $information['enable_incremental_schedules']); } if(isset($information['incremental_schedules'])){ $mainwp_wpvivid_extension_activator->set_incremental_schedules($site_id, $information['incremental_schedules']); } if(isset($information['incremental_backup_data'])){ $mainwp_wpvivid_extension_activator->set_incremental_backup_data($site_id, $information['incremental_backup_data']); } if(isset($information['incremental_output_msg'])){ $mainwp_wpvivid_extension_activator->set_incremental_output_msg($site_id, $information['incremental_output_msg']); } } echo wp_json_encode($ret); } die(); } 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().';'; error_log($message); echo wp_json_encode(array('result'=>'failed','error'=>$message)); die(); } } public function global_create_schedule_addon() { global $mainwp_wpvivid_extension_activator; $mainwp_wpvivid_extension_activator->mwp_ajax_check_security(); try { if(isset($_POST['schedule']) && !empty($_POST['schedule']) && is_string($_POST['schedule'])) { $json = stripslashes(sanitize_text_field($_POST['schedule'])); $schedule = json_decode($json, true); if(isset($_POST['schedule_mould_name']) && !empty($_POST['schedule_mould_name'])){ $schedule_mould_name = sanitize_text_field($_POST['schedule_mould_name']); if (isset($schedule['custom_dirs'])) { $mainwp_wpvivid_extension_activator->mwp_wpvivid_update_global_backup_custom_setting($schedule['custom_dirs']); } if(isset($_POST['first_create'])){ if(sanitize_text_field($_POST['first_create']) == '1'){ $need_check_exist = true; } else{ $need_check_exist = false; } } else{ $need_check_exist = true; } $schedule_mould_name_array = array(); $schedule_mould = Mainwp_WPvivid_Extension_DB_Option::get_instance()->wpvivid_get_global_option('schedule_mould_addon', array()); if(empty($schedule_mould)){ $schedule_mould = array(); } else{ foreach ($schedule_mould as $schedule_name => $value){ $schedule_mould_name_array[] = $schedule_name; } } if(!in_array($schedule_mould_name, $schedule_mould_name_array) || !$need_check_exist){ if(!$need_check_exist){ $schedules = $schedule_mould[$schedule_mould_name]; } else{ $schedules = array(); } $schedule_data = array(); $schedule_data['id'] = uniqid('wpvivid_schedule_event'); $schedule_data['status'] = $schedule['status']; $schedule_data['type'] = $schedule['recurrence']; $schedule_data['week'] = isset($schedule['week']) ? $schedule['week'] : 'sun'; $schedule_data['day'] = isset($schedule['day']) ? $schedule['day'] : '01'; $schedule['current_day_hour'] = isset($schedule['current_day_hour']) ? $schedule['current_day_hour'] : '00'; $schedule['current_day_minute'] = isset($schedule['current_day_minute']) ? $schedule['current_day_minute'] : '00'; $schedule_data['current_day'] = $schedule['current_day_hour'] . ':' . $schedule['current_day_minute']; $schedule_data['start_time_local_utc'] = isset($schedule['start_time_zone']) ? $schedule['start_time_zone'] : 'utc'; if (isset($schedule['mwp_schedule_add_backup_type']) && !empty($schedule['mwp_schedule_add_backup_type'])) { $schedule_data['backup']['backup_files'] = $schedule['mwp_schedule_add_backup_type']; if ($schedule['mwp_schedule_add_backup_type'] === 'custom') { $schedule_data['backup']['custom_dirs'] = $schedule['custom_dirs']; } } $schedule_data['backup']['exclude_files'] = $schedule['exclude_files']; $schedule_data['backup']['exclude_file_type'] = $schedule['exclude_file_type']; $schedule_data['backup']['local'] = 1; $schedule_data['backup']['remote'] = 0; if ($schedule['save_local_remote'] == 'remote') { $schedule_data['backup']['local'] = 0; $schedule_data['backup']['remote'] = 1; } $schedule_data['backup']['lock'] = 0; $schedule_data['backup']['backup_prefix'] = $schedule['backup_prefix']; $schedules[$schedule_data['id']] = $schedule_data; $schedule_mould[$schedule_mould_name] = $schedules; Mainwp_WPvivid_Extension_DB_Option::get_instance()->wpvivid_update_global_option('schedule_mould_addon', $schedule_mould); $table = new Mainwp_WPvivid_Schedule_Global_List(); $table->set_schedule_list($schedules); $table->prepare_items(); ob_start(); $table->display(); $html = ob_get_clean(); $success_msg = 'You have successfully added a schedule.'; $ret['notice'] = apply_filters('mwp_wpvivid_set_schedule_notice', true, $success_msg); $ret['html'] = $html; $ret['result'] = 'success'; } else { $ret['result'] = 'failed'; $error_msg = 'The schedule mould name already existed.'; $ret['notice'] = apply_filters('mwp_wpvivid_set_schedule_notice', false, $error_msg); } } else{ $ret['result'] = 'failed'; $error_msg = 'A schedule mould name is required.'; $ret['notice'] = apply_filters('mwp_wpvivid_set_schedule_notice', false, $error_msg); } echo wp_json_encode($ret); } die(); } 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().';'; error_log($message); echo wp_json_encode(array('result'=>'failed','error'=>$message)); die(); } } public function edit_global_schedule_addon() { global $mainwp_wpvivid_extension_activator; $mainwp_wpvivid_extension_activator->mwp_ajax_check_security(); try{ if(isset($_POST['schedule_id']) && !empty($_POST['schedule_id']) && is_string($_POST['schedule_id']) && isset($_POST['mould_name']) && !empty($_POST['mould_name']) && is_string($_POST['mould_name'])) { $schedule_id = sanitize_key($_POST['schedule_id']); $schedule_mould_name = sanitize_text_field($_POST['mould_name']); $schedule_mould = Mainwp_WPvivid_Extension_DB_Option::get_instance()->wpvivid_get_global_option('schedule_mould_addon', array()); $schedules = $schedule_mould[$schedule_mould_name]; $ret['result'] = 'success'; $ret['schedule_info'] = $schedules[$schedule_id]; if(!isset($schedules[$schedule_id]['start_time_local_utc'])){ $ret['schedule_info']['start_time_local_utc'] = 'utc'; } if(isset($ret['schedule_info']['current_day'])) { $dt = DateTime::createFromFormat("H:i", $ret['schedule_info']['current_day']); $offset=get_option('gmt_offset'); $hours=$dt->format('H'); $minutes=$dt->format('i'); $hour=(float)$hours+$offset; $whole = floor($hour); $fraction = $hour - $whole; $minute=(float)(60*($fraction))+(int)$minutes; $hour=(int)$hour; $minute=(int)$minute; if($minute>=60) { $hour=(int)$hour+1; $minute=(int)$minute-60; } if($hour>=24) { $hour=$hour-24; } else if($hour<0) { $hour=24-abs ($hour); } if($hour<10) { $hour='0'.(int)$hour; } else { $hour=(string)$hour; } if($minute<10) { $minute='0'.(int)$minute; } else { $minute=(string)$minute; } $ret['schedule_info']['hours']=$hour; $ret['schedule_info']['minute']=$minute; } else { $ret['schedule_info']['hours']='00'; $ret['schedule_info']['minute']='00'; } echo wp_json_encode($ret); die(); } } 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().';'; error_log($message); echo wp_json_encode(array('result'=>'failed','error'=>$message)); } die(); } public function global_update_schedule_addon() { global $mainwp_wpvivid_extension_activator; $mainwp_wpvivid_extension_activator->mwp_ajax_check_security(); try { if(isset($_POST['schedule']) && !empty($_POST['schedule']) && is_string($_POST['schedule']) && isset($_POST['mould_name']) && !empty($_POST['mould_name']) && is_string($_POST['mould_name'])) { $json = stripslashes(sanitize_text_field($_POST['schedule'])); $schedule_data = json_decode($json, true); $schedule_mould_name = sanitize_text_field($_POST['mould_name']); $schedule_mould = Mainwp_WPvivid_Extension_DB_Option::get_instance()->wpvivid_get_global_option('schedule_mould_addon', array()); $schedules = $schedule_mould[$schedule_mould_name]; $schedule_tmp = array(); $schedule_tmp['id'] = $schedule_data['schedule_id']; $schedule_tmp['status'] = $schedule_data['status']; $schedule_tmp['type'] = $schedule_data['recurrence']; $schedule_tmp['week'] = $schedule_data['week']; $schedule_tmp['day'] = $schedule_data['day']; $schedule_tmp['current_day'] = $schedule_data['current_day_hour'].':'.$schedule_data['current_day_minute']; $schedule_tmp['start_time_local_utc'] = isset($schedule_data['start_time_zone']) ? $schedule_data['start_time_zone'] : 'utc'; if(isset($schedule_data['mwp_schedule_update_backup_type']) && !empty($schedule_data['mwp_schedule_update_backup_type'])){ $schedule_tmp['backup']['backup_files'] = $schedule_data['mwp_schedule_update_backup_type']; if($schedule_data['mwp_schedule_update_backup_type'] === 'custom'){ $schedule_tmp['backup']['custom_dirs'] = $schedule_data['custom_dirs']; } } $schedule_tmp['backup']['exclude_files'] = $schedule_data['exclude_files']; $schedule_tmp['backup']['exclude_file_type'] = $schedule_data['exclude_file_type']; $schedule_tmp['backup']['local'] = $schedule_data['save_local_remote']==='local' ? 1 : 0; $schedule_tmp['backup']['remote'] = $schedule_data['save_local_remote']==='local' ? 0 : 1; $schedule_tmp['backup']['lock'] = intval($schedule_data['lock']); $schedule_tmp['backup']['backup_prefix'] = $schedule_data['backup_prefix']; $schedules[$schedule_data['schedule_id']] = $schedule_tmp; $schedule_mould[$schedule_mould_name] = $schedules; Mainwp_WPvivid_Extension_DB_Option::get_instance()->wpvivid_update_global_option('schedule_mould_addon', $schedule_mould); $table=new Mainwp_WPvivid_Schedule_Global_List(); $table->set_schedule_list($schedules); $table->prepare_items(); ob_start(); $table->display(); $html = ob_get_clean(); $success_msg = 'You have successfully updated the schedule. Please click on Save Changes and Sync button to synchronize the settings to child sites.'; $ret['notice'] = apply_filters('mwp_wpvivid_set_schedule_notice', true, $success_msg); $ret['html'] = $html; $ret['result'] = 'success'; echo wp_json_encode($ret); } die(); } 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().';'; error_log($message); echo wp_json_encode(array('result'=>'failed','error'=>$message)); die(); } } public function global_delete_schedule_addon() { global $mainwp_wpvivid_extension_activator; $mainwp_wpvivid_extension_activator->mwp_ajax_check_security(); try{ if(isset($_POST['schedule_id']) && !empty($_POST['schedule_id']) && is_string($_POST['schedule_id']) && isset($_POST['mould_name']) && !empty($_POST['mould_name']) && is_string($_POST['mould_name'])) { $schedule_id = sanitize_key($_POST['schedule_id']); $schedule_mould_name = sanitize_text_field($_POST['mould_name']); $schedule_mould = Mainwp_WPvivid_Extension_DB_Option::get_instance()->wpvivid_get_global_option('schedule_mould_addon', array()); $schedules = $schedule_mould[$schedule_mould_name]; if(isset($schedules[$schedule_id])) { unset($schedules[$schedule_id]); } $schedule_mould[$schedule_mould_name] = $schedules; Mainwp_WPvivid_Extension_DB_Option::get_instance()->wpvivid_update_global_option('schedule_mould_addon', $schedule_mould); $table=new Mainwp_WPvivid_Schedule_Global_List(); $table->set_schedule_list($schedules); $table->prepare_items(); ob_start(); $table->display(); $html = ob_get_clean(); $success_msg = 'The schedule has been deleted successfully. Please click on Save Changes and Sync button to synchronize the settings to child sites.'; $ret['notice'] = apply_filters('mwp_wpvivid_set_schedule_notice', true, $success_msg); $ret['html'] = $html; $ret['result'] = 'success'; echo wp_json_encode($ret); } die(); } 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().';'; error_log($message); echo wp_json_encode(array('result'=>'failed','error'=>$message)); die(); } } public function global_save_schedule_status_addon() { global $mainwp_wpvivid_extension_activator; $mainwp_wpvivid_extension_activator->mwp_ajax_check_security(); try{ if(isset($_POST['schedule_data']) && !empty($_POST['schedule_data']) && is_string($_POST['schedule_data']) && isset($_POST['mould_name']) && !empty($_POST['mould_name']) && is_string($_POST['mould_name'])) { $json = stripslashes(sanitize_text_field($_POST['schedule_data'])); $schedule_data = json_decode($json, true); $schedule_mould_name = sanitize_text_field($_POST['mould_name']); $schedule_mould = Mainwp_WPvivid_Extension_DB_Option::get_instance()->wpvivid_get_global_option('schedule_mould_addon', array()); $schedules = $schedule_mould[$schedule_mould_name]; foreach ($schedule_data as $schedule_id => $schedule_status){ $schedules[$schedule_id]['status'] = $schedule_status; } $schedule_mould[$schedule_mould_name] = $schedules; Mainwp_WPvivid_Extension_DB_Option::get_instance()->wpvivid_update_global_option('schedule_mould_addon', $schedule_mould); $table=new Mainwp_WPvivid_Schedule_Global_List(); $table->set_schedule_list($schedules); $table->prepare_items(); ob_start(); $table->display(); $html = ob_get_clean(); $success_msg = 'You have successfully saved the changes.'; $ret['notice'] = apply_filters('mwp_wpvivid_set_schedule_notice', true, $success_msg); $ret['html'] = $html; $ret['result'] = 'success'; echo wp_json_encode($ret); } die(); } 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().';'; error_log($message); echo wp_json_encode(array('result'=>'failed','error'=>$message)); die(); } } public function edit_global_schedule_mould_addon() { global $mainwp_wpvivid_extension_activator; $mainwp_wpvivid_extension_activator->mwp_ajax_check_security(); try{ if(isset($_POST['mould_name']) && !empty($_POST['mould_name']) && is_string($_POST['mould_name'])){ $mould_name = sanitize_text_field($_POST['mould_name']); $schedule_mould = Mainwp_WPvivid_Extension_DB_Option::get_instance()->wpvivid_get_global_option('schedule_mould_addon', array()); $schedules = $schedule_mould[$mould_name]; $table = new Mainwp_WPvivid_Schedule_Global_List(); $table->set_schedule_list($schedules); $table->prepare_items(); ob_start(); $table->display(); $html = ob_get_clean(); $ret['html'] = $html; $ret['result'] = 'success'; echo wp_json_encode($ret); } } 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().';'; error_log($message); echo wp_json_encode(array('result'=>'failed','error'=>$message)); } die(); } public function delete_global_schedule_mould_addon() { global $mainwp_wpvivid_extension_activator; $mainwp_wpvivid_extension_activator->mwp_ajax_check_security(); try{ if(isset($_POST['mould_name']) && !empty($_POST['mould_name']) && is_string($_POST['mould_name'])){ $mould_name = sanitize_text_field($_POST['mould_name']); $schedule_mould = Mainwp_WPvivid_Extension_DB_Option::get_instance()->wpvivid_get_global_option('schedule_mould_addon', array()); if(isset($schedule_mould[$mould_name])){ unset($schedule_mould[$mould_name]); } Mainwp_WPvivid_Extension_DB_Option::get_instance()->wpvivid_update_global_option('schedule_mould_addon', $schedule_mould); $table = new Mainwp_WPvivid_Schedule_Mould_List(); $table->set_schedule_mould_list($schedule_mould); $table->prepare_items(); ob_start(); $table->display(); $html = ob_get_clean(); $ret['html'] = $html; $ret['result'] = 'success'; echo wp_json_encode($ret); } } 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().';'; error_log($message); echo wp_json_encode(array('result'=>'failed','error'=>$message)); } die(); } public function get_schedule_mould_list() { global $mainwp_wpvivid_extension_activator; $mainwp_wpvivid_extension_activator->mwp_ajax_check_security(); try{ if(isset($_POST['page'])){ $page = sanitize_text_field($_POST['page']); $schedule_mould_list = Mainwp_WPvivid_Extension_DB_Option::get_instance()->wpvivid_get_global_option('schedule_mould_addon', array()); $table = new Mainwp_WPvivid_Schedule_Mould_List(); $table->set_schedule_mould_list($schedule_mould_list, $page); $table->prepare_items(); ob_start(); $table->display(); $html = ob_get_clean(); $ret['schedule_mould_list'] = $html; $ret['result'] = 'success'; echo wp_json_encode($ret); } } 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().';'; error_log($message); echo wp_json_encode(array('result'=>'failed','error'=>$message)); } die(); } public function update_global_schedule_backup_exclude_extension_addon() { global $mainwp_wpvivid_extension_activator; $mainwp_wpvivid_extension_activator->mwp_ajax_check_security(); try{ if(isset($_POST['type']) && !empty($_POST['type']) && is_string($_POST['type']) && isset($_POST['exclude_content']) && !empty($_POST['exclude_content']) && is_string($_POST['exclude_content'])){ $type = sanitize_text_field($_POST['type']); $exclude_content = sanitize_text_field($_POST['exclude_content']); $mainwp_wpvivid_extension_activator->mwp_wpvivid_update_global_backup_exclude_extension_rule($type, $exclude_content); $ret['result'] = 'success'; echo wp_json_encode($ret); } } 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().';'; error_log($message); echo wp_json_encode(array('result'=>'failed','error'=>$message)); } die(); } public function edit_global_schedule_mould_name_addon() { global $mainwp_wpvivid_extension_activator; $mainwp_wpvivid_extension_activator->mwp_ajax_check_security(); try{ if(isset($_POST['schedule_mould_name']) && !empty($_POST['schedule_mould_name']) && isset($_POST['schedule_mould_old_name']) && !empty($_POST['schedule_mould_old_name'])){ $schedule_mould_name = sanitize_text_field($_POST['schedule_mould_name']); $schedule_mould_old_name = sanitize_text_field($_POST['schedule_mould_old_name']); if($schedule_mould_name === $schedule_mould_old_name) { $ret['result'] = 'success'; } else { $schedule_mould_name_array = array(); $schedule_mould = Mainwp_WPvivid_Extension_DB_Option::get_instance()->wpvivid_get_global_option('schedule_mould_addon', array()); if(empty($schedule_mould)) { $schedule_mould = array(); } else { foreach ($schedule_mould as $schedule_name => $value) { $schedule_mould_name_array[] = $schedule_name; } } if(!in_array($schedule_mould_name, $schedule_mould_name_array)) { if(isset($schedule_mould[$schedule_mould_old_name])) { $schedule_mould[$schedule_mould_name] = $schedule_mould[$schedule_mould_old_name]; unset($schedule_mould[$schedule_mould_old_name]); } Mainwp_WPvivid_Extension_DB_Option::get_instance()->wpvivid_update_global_option('schedule_mould_addon', $schedule_mould); $ret['result'] = 'success'; } else { $ret['result'] = 'failed'; $error_msg = 'The schedule mould name already existed.'; $ret['notice'] = apply_filters('mwp_wpvivid_set_schedule_notice', false, $error_msg); } } echo wp_json_encode($ret); } } 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().';'; error_log($message); echo wp_json_encode(array('result'=>'failed','error'=>$message)); } die(); } public function render($check_pro, $global=false) { if(isset($_GET['synchronize']) && isset($_GET['addon'])) { $check_addon = sanitize_text_field($_GET['addon']); if(isset($_GET['mould_name'])){ $mould_name = sanitize_text_field($_GET['mould_name']); } else{ $mould_name = ''; } if(isset($_GET['is_incremental']) && $_GET['is_incremental'] == 1){ $is_incremental = 1; } else{ $is_incremental = 0; } $this->mwp_wpvivid_synchronize_setting($check_addon, $mould_name, $is_incremental); } else { ?> <div style="padding: 10px;"> <?php if($global){ if($this->select_pro){ $select_pro_check = 'checked'; } else{ $select_pro_check = ''; } ?> <div class="mwp-wpvivid-block-bottom-space" style="background: #fff;"> <div class="postbox" style="padding: 10px; margin-bottom: 0;"> <div style="float: left; margin-top: 7px; margin-right: 25px;"><?php esc_html_e('Switch to WPvivid Backup Pro'); ?></div> <div class="ui toggle checkbox mwp-wpvivid-pro-swtich" style="float: left; margin-top:4px; margin-right: 10px;"> <input type="checkbox" <?php echo esc_attr($select_pro_check); ?> /> <label for=""></label> </div> <div style="float: left;"><input class="ui green mini button" type="button" value="Save" onclick="mwp_wpvivid_switch_pro_setting();" /></div> <div style="clear: both;"></div> </div> </div> <div style="clear: both;"></div> <?php if($this->select_pro){ Mainwp_WPvivid_Extension_DB_Option::get_instance()->wpvivid_first_init_schedule_to_module(); $this->mwp_wpvivid_schedule_page_addon($global); } else{ $this->mwp_wpvivid_schedule_page($global); } ?> <?php } else { if ($check_pro) { $this->mwp_wpvivid_schedule_page_addon($global); } else { $this->mwp_wpvivid_schedule_page($global); } } ?> </div> <script> function mwp_wpvivid_switch_pro_setting(){ if(jQuery('.mwp-wpvivid-pro-swtich').find('input:checkbox').prop('checked')){ var pro_setting = 1; } else{ var pro_setting = 0; } var ajax_data = { 'action': 'mwp_wpvivid_switch_pro_setting', 'pro_setting': pro_setting }; mwp_wpvivid_post_request(ajax_data, function (data) { try { var jsonarray = jQuery.parseJSON(data); if (jsonarray.result === 'success') { location.reload(); } else { alert(jsonarray.error); } } catch (err) { alert(err); } }, function (XMLHttpRequest, textStatus, errorThrown) { var error_message = mwp_wpvivid_output_ajaxerror('changing base settings', textStatus, errorThrown); alert(error_message); }); } function mwp_wpvivid_swtich_global_schedule_tab(evt, contentName){ var i, tabcontent, tablinks; tabcontent = document.getElementsByClassName("mwp-global-schedule-tab-content"); for (i = 0; i < tabcontent.length; i++) { tabcontent[i].style.display = "none"; } tablinks = document.getElementsByClassName("mwp-global-schedule-nav-tab"); for (i = 0; i < tablinks.length; i++) { tablinks[i].className = tablinks[i].className.replace(" nav-tab-active", ""); } document.getElementById(contentName).style.display = "block"; evt.currentTarget.className += " nav-tab-active"; } </script> <?php } } public function mwp_wpvivid_schedule_page_addon($global){ global $mainwp_wpvivid_extension_activator; if(!$global){ $mainwp_wpvivid_extension_activator->incremental_schedule->set_site_id($this->site_id); $incremental_backup_data=Mainwp_WPvivid_Extension_DB_Option::get_instance()->wpvivid_get_option($this->site_id, 'incremental_backup_setting', array()); $mainwp_wpvivid_extension_activator->incremental_schedule->set_incremental_backup_data($incremental_backup_data); } else{ $incremental_backup_data=Mainwp_WPvivid_Extension_DB_Option::get_instance()->wpvivid_get_global_option('incremental_backup_setting', array()); $mainwp_wpvivid_extension_activator->incremental_schedule->set_incremental_backup_data($incremental_backup_data); } $schedules = Mainwp_WPvivid_Extension_DB_Option::get_instance()->wpvivid_get_global_option('schedule_addon', array()); add_filter('mwp_wpvivid_schedule_local_remote_addon', array($this, 'mwp_wpvivid_schedule_local_remote_addon'), 10, 2); ?> <div class="mwp-wpvivid-welcome-bar mwp-wpvivid-clear-float"> <div class="mwp-wpvivid-welcome-bar-left"> <p><span class="dashicons dashicons-calendar-alt mwp-wpvivid-dashicons-large mwp-wpvivid-dashicons-green"></span><span class="mwp-wpvivid-page-title">Backup Schedule</span></p> <span class="about-description">The page allows you to create backup/unused images clean/image optimiztion schedules</span> </div> <div class="mwp-wpvivid-welcome-bar-right"></div> <div class="mwp-wpvivid-nav-bar mwp-wpvivid-clear-float"> <span class="dashicons dashicons-lightbulb wpvivid-dashicons-orange"></span> <span> In order to ensure that the scheduled tasks can be performed as expected, it is best to complete a manual backup first to ensure that your server has sufficient resources.</span> </div> </div> <?php if(!class_exists('Mainwp_WPvivid_Tab_Page_Container')) include_once MAINWP_WPVIVID_EXTENSION_PLUGIN_DIR . '/includes/wpvivid-backup-mainwp-tab-page-container.php'; $this->main_tab=new Mainwp_WPvivid_Tab_Page_Container(); $args['is_parent_tab']=0; $args['transparency']=1; $tabs['schedules']['title'] = 'Schedules'; $tabs['schedules']['slug'] = 'schedules'; $tabs['schedules']['callback'] = array($this, 'output_schedules_page'); $tabs['schedules']['args'] = $args; $args['can_delete']=1; $args['hide']=1; $args['global']=$global; $tabs['schedules_edit']['title'] = 'Schedule Edit'; $tabs['schedules_edit']['slug'] = 'schedules_edit'; $tabs['schedules_edit']['callback'] = array($this, 'output_schedules_edit_page'); $tabs['schedules_edit']['args'] = $args; $tabs=apply_filters('mwp_wpvivid_schedule_tabs',$tabs); foreach ($tabs as $key=>$tab) { $this->main_tab->add_tab($tab['title'],$tab['slug'],$tab['callback'], $tab['args']); } $this->main_tab->display(); ?> <script> var is_global = '<?php echo esc_js($global); ?>'; if(!is_global){ mwp_wpvivid_get_schedules_addon(); } function mwp_wpvivid_get_schedules_addon(){ var ajax_data={ 'action': 'mwp_wpvivid_get_schedules_addon', 'site_id':'<?php echo esc_html($this->site_id); ?>' }; mwp_wpvivid_post_request(ajax_data, function (data) { try { var jsonarray = jQuery.parseJSON(data); if (jsonarray.result === 'success') { jQuery('#mwp_wpvivid_schedule_list_addon').html(jsonarray.html); } else { alert(jsonarray.error); } } catch(err) { alert(err); } }, function (XMLHttpRequest, textStatus, errorThrown) { setTimeout(function () { mwp_wpvivid_get_schedules_addon(); }, 3000); }); } var mwp_wpvivid_edit_schedule_id = ''; function mwp_wpvivid_display_edit_schedule_database_table(schedule_id) { var ajax_data = { 'action': 'mwp_wpvivid_edit_schedule_addon', 'site_id': '<?php echo esc_html($this->site_id); ?>', 'schedule_id': schedule_id }; jQuery('#mwp_wpvivid_schedule_update_notice').html(''); mwp_wpvivid_post_request(ajax_data, function (data) { try { var jsonarray = jQuery.parseJSON(data); if (jsonarray.result === 'success') { jQuery('#mwp_wpvivid_schedule_update_notice').html(jsonarray.notice); jQuery('#wpvivid_custom_update_schedule_backup').find('.mwp-wpvivid-custom-database-info').html(jsonarray.database_tables); } else { jQuery('#mwp_wpvivid_schedule_update_notice').html(jsonarray.notice); } } catch (err) { alert(err); } }, function (XMLHttpRequest, textStatus, errorThrown) { var error_message = mwp_wpvivid_output_ajaxerror('changing base settings', textStatus, errorThrown); alert(error_message); }); } function mwp_wpvivid_display_schedule_setting(backupinfo){ var database_check = true; var additional_database = true; var core_check = true; var content_check = true; var themes_check = true; var plugins_check = true; var uploads_check = true; var other_check = true; if(backupinfo.custom_dirs.database_check != 1){ database_check = false; } if(backupinfo.custom_dirs.additional_database_check != 1){ additional_database = false; } if(backupinfo.custom_dirs.core_check != 1){ core_check = false; } if(backupinfo.custom_dirs.content_check != 1){ content_check = false; } if(backupinfo.custom_dirs.themes_check != 1){ themes_check = false; } if(backupinfo.custom_dirs.plugins_check != 1){ plugins_check = false; } if(backupinfo.custom_dirs.uploads_check != 1){ uploads_check = false; } if(backupinfo.custom_dirs.other_check != 1){ other_check = false; } jQuery('#wpvivid_custom_update_schedule_backup').find('.mwp-wpvivid-custom-database-check').prop('checked', database_check); jQuery('#wpvivid_custom_update_schedule_backup').find('.mwp-wpvivid-custom-additional-database-check').prop('checked', additional_database); jQuery('#wpvivid_custom_update_schedule_backup').find('.mwp-wpvivid-custom-core-check').prop('checked', core_check); jQuery('#wpvivid_custom_update_schedule_backup').find('.mwp-wpvivid-custom-content-check').prop('checked', content_check); jQuery('#wpvivid_custom_update_schedule_backup').find('.mwp-wpvivid-custom-themes-check').prop('checked', themes_check); jQuery('#wpvivid_custom_update_schedule_backup').find('.mwp-wpvivid-custom-plugins-check').prop('checked', plugins_check); jQuery('#wpvivid_custom_update_schedule_backup').find('.mwp-wpvivid-custom-uploads-check').prop('checked', uploads_check); jQuery('#wpvivid_custom_update_schedule_backup').find('.mwp-wpvivid-custom-additional-folder-check').prop('checked', other_check); var include_other = ''; jQuery('#wpvivid_custom_update_schedule_backup').find('.mwp-wpvivid-custom-include-additional-folder-list').html(''); jQuery.each(backupinfo.custom_dirs.other_list, function(index ,value){ var type = 'folder'; var class_span = 'dashicons dashicons-category wpvivid-dashicons-orange wpvivid-icon-16px-nopointer'; include_other += "<div class='wpvivid-text-line' type='"+type+"'>" + "<span class='dashicons dashicons-trash wpvivid-icon-16px mwp-wpvivid-remove-custom-exlcude-tree'></span>" + "<span class='"+class_span+"'></span>" + "<span class='wpvivid-text-line'>" + value + "</span>" + "</div>"; }); jQuery('#wpvivid_custom_update_schedule_backup').find('.mwp-wpvivid-custom-include-additional-folder-list').append(include_other); } function mwp_wpvivid_edit_schedule_ex(schedule_id, data){ console.log(data); var jsonarray = jQuery.parseJSON(data); mwp_wpvivid_edit_schedule_id = jsonarray.id; jQuery( document ).trigger( '<?php echo esc_js($this->main_tab->container_id); ?>-show',[ 'schedules_edit', 'schedules' ]); var cycles = jsonarray.type; jQuery("#mwp_wpvivid_schedule_update_cycles_select").val(cycles); jQuery('#mwp_wpvivid_schedule_update_week').hide(); jQuery('#mwp_wpvivid_schedule_update_day').hide(); if(cycles === 'wpvivid_weekly' || cycles === 'wpvivid_fortnightly') { jQuery('#mwp_wpvivid_schedule_update_week').show(); jQuery('#mwp_wpvivid_schedule_update_week_select').val(jsonarray.week); } else if(cycles === 'wpvivid_monthly'){ jQuery('#mwp_wpvivid_schedule_update_day').show(); jQuery('#mwp_wpvivid_schedule_update_day_select').val(jsonarray.day); } jQuery('select[option=mwp_schedule_update][name=current_day_hour]').each(function() { jQuery(this).val(jsonarray.hours); }); jQuery('select[option=mwp_schedule_update][name=current_day_minute]').each(function(){ jQuery(this).val(jsonarray.minute); }); jQuery('#mwp_wpvivid_schedule_update_utc_time').html(jsonarray.current_day); jQuery('#mwp_wpvivid_schedule_update_start_local_time').html(jsonarray.hours+':'+jsonarray.minute); jQuery('#mwp_wpvivid_schedule_update_start_utc_time').html(jsonarray.current_day); jQuery('#mwp_wpvivid_schedule_update_start_cycles').html(jsonarray.schedule_cycles); if(typeof jsonarray.backup.backup_files !== 'undefined') { if (jsonarray.backup.backup_files === 'files+db') { jQuery('input[option=mwp_schedule_update][name=mwp_schedule_update_backup_type][value=\'files+db\']').prop('checked', true); } else if(jsonarray.backup.backup_files === 'custom'){ jQuery('input[option=mwp_schedule_update][name=mwp_schedule_update_backup_type][value=custom]').prop('checked', true); jQuery('#wpvivid_custom_update_schedule_backup').show(); mwp_wpvivid_display_schedule_setting(jsonarray.backup); mwp_wpvivid_display_edit_schedule_database_table(schedule_id); } else { jQuery('input[option=mwp_schedule_update][name=mwp_schedule_update_backup_type][value=' + jsonarray.backup.backup_files + ']').prop('checked', true); } } else{ jQuery('input[option=mwp_schedule_update][name=mwp_schedule_update_backup_type][value=custom]').prop('checked', true); jQuery('#wpvivid_custom_update_schedule_backup').show(); mwp_wpvivid_display_schedule_setting(jsonarray.backup); mwp_wpvivid_display_edit_schedule_database_table(schedule_id); } //var backup_to = jsonarray.backup.local === 1 ? 'local' : 'remote'; //jQuery('input:radio[option=mwp_schedule_update][name=mwp_schedule_update_save_local_remote][value='+backup_to+']').prop('checked', true); if(jsonarray.backup.local == 1){ jQuery('input[option=mwp_update_schedule_backup][name=update_schedule_save_local_remote][value=local]').prop('checked', true); jQuery('#mwp_wpvivid_update_schedule_backup_remote_selector_part').hide(); } else{ jQuery('input[option=mwp_update_schedule_backup][name=update_schedule_save_local_remote][value=remote]').prop('checked', true); jQuery('#mwp_wpvivid_update_schedule_backup_remote_selector_part').show(); if(typeof jsonarray.backup.remote_options !== 'undefined'){ jQuery.each(jsonarray.backup.remote_options, function(remote_id, remote_option){ jQuery('#mwp_wpvivid_update_schedule_backup_remote_selector').val(remote_id); }); } else { jQuery('#mwp_wpvivid_update_schedule_backup_remote_selector').val('all'); } } if(typeof jsonarray.backup.exclude_files !== 'undefined') { var exclude_list = ''; jQuery('#wpvivid_custom_update_schedule_advanced_option').find('.mwp-wpvivid-custom-exclude-list').html(''); jQuery.each(jsonarray.backup.exclude_files, function(index, value) { if(value.type === 'folder') { var class_span = 'dashicons dashicons-category wpvivid-dashicons-orange wpvivid-icon-16px-nopointer'; } else { var class_span = 'dashicons dashicons-media-default wpvivid-dashicons-grey wpvivid-icon-16px-nopointer'; } exclude_list += "<div class='wpvivid-text-line' type='"+value.type+"'>" + "<span class='dashicons dashicons-trash wpvivid-icon-16px mwp-wpvivid-remove-custom-exlcude-tree'></span>" + "<span class='"+class_span+"'></span>" + "<span class='wpvivid-text-line'>" + value.path + "</span>" + "</div>"; }); jQuery('#wpvivid_custom_update_schedule_advanced_option').find('.mwp-wpvivid-custom-exclude-list').append(exclude_list); } jQuery('#wpvivid_custom_update_schedule_advanced_option').find('.mwp-wpvivid-custom-exclude-extension').val(''); if(typeof jsonarray.backup.exclude_file_type !== 'undefined') { jQuery('#wpvivid_custom_update_schedule_advanced_option').find('.mwp-wpvivid-custom-exclude-extension').val(jsonarray.backup.exclude_file_type); } if(typeof jsonarray.backup.backup_prefix !== 'undefined') { jQuery('input:text[option=mwp_update_schedule_backup][name=backup_prefix]').val(jsonarray.backup.backup_prefix); } } function mwp_wpvivid_delete_schedule(schedule_id){ var ajax_data = { 'action': 'mwp_wpvivid_delete_schedule_addon', 'site_id': '<?php echo esc_html($this->site_id); ?>', 'schedule_id': schedule_id }; jQuery('#mwp_wpvivid_schedule_update_notice').html(''); mwp_wpvivid_post_request(ajax_data, function (data) { try { var jsonarray = jQuery.parseJSON(data); if (jsonarray.result === 'success') { jQuery('#mwp_wpvivid_schedule_update_notice').html(jsonarray.notice); jQuery('#mwp_wpvivid_schedule_list_addon').html(jsonarray.html); } else { jQuery('#mwp_wpvivid_schedule_update_notice').html(jsonarray.notice); } } catch (err) { alert(err); } }, function (XMLHttpRequest, textStatus, errorThrown) { var error_message = mwp_wpvivid_output_ajaxerror('changing base settings', textStatus, errorThrown); alert(error_message); }); } jQuery('#mwp_wpvivid_schedule_list_addon').on('click', '.mwp-wpvivid-schedule-on-off-control', function(){ var Obj=jQuery(this); var json = {}; var schedule_id = ''; var schedule_status = ''; schedule_id = Obj.closest('tr').attr('slug'); if(jQuery(this).prop('checked')) { schedule_status = 'Active'; } else { schedule_status = 'InActive'; } json[schedule_id] = schedule_status; schedule_status = JSON.stringify(json); var ajax_data= { 'action': 'mwp_wpvivid_save_schedule_status_addon', 'site_id': '<?php echo esc_html($this->site_id); ?>', 'schedule_data': schedule_status, }; jQuery('#mwp_wpvivid_schedule_update_notice').html(''); mwp_wpvivid_post_request(ajax_data, function(data) { location.href=window.location.href; }, function(XMLHttpRequest, textStatus, errorThrown) { var error_message = wpvivid_output_ajaxerror('setting up a lock for the backup', textStatus, errorThrown); alert(error_message); }); }); jQuery('#mwp_wpvivid_schedule_list_addon').on('click', '.mwp-wpvivid-schedule-edit', function(){ var Obj = jQuery(this); var id = Obj.closest('tr').attr('slug'); var name = jQuery(this).attr('name'); mwp_wpvivid_edit_schedule_ex(id, name); }); jQuery('#mwp_wpvivid_schedule_list_addon').on('click', '.mwp-wpvivid-schedule-delete', function(){ var descript = 'Are you sure to remove this schedule?'; var ret = confirm(descript); if(ret === true) { var Obj = jQuery(this); var id = Obj.closest('tr').attr('slug'); mwp_wpvivid_delete_schedule(id); } }); jQuery('#mwp_wpvivid_schedule_list_addon').on('change', '.schedule-item > .check-column > input', function(){ if( jQuery(this).is(':checked') ) { var Obj=jQuery(this).closest('tr'); Obj.addClass('mwp-wpvivid-schedule-active'); Obj.find('.mwp-wpvivid-schedule-status').html('Active'); } else { var Obj=jQuery(this).closest('tr'); Obj.removeClass('mwp-wpvivid-schedule-active'); Obj.find('.mwp-wpvivid-schedule-status').html('InActive'); } }); jQuery('#mwp_wpvivid_schedule_list_addon').on('change' ,'thead .check-column input',function() { if( jQuery(this).is(':checked') ) { jQuery('#mwp_wpvivid_schedule_list_addon').find('.schedule-item > .check-column > input').each(function() { var Obj=jQuery(this).closest('tr'); Obj.addClass('mwp-wpvivid-schedule-active'); Obj.find('.mwp-wpvivid-schedule-status').html('Active'); }); } else { jQuery('#mwp_wpvivid_schedule_list_addon').find('.schedule-item > .check-column > input').each(function() { var Obj=jQuery(this).closest('tr'); Obj.removeClass('mwp-wpvivid-schedule-active'); Obj.find('.mwp-wpvivid-schedule-status').html('InActive'); }); } }); jQuery('#mwp_wpvivid_schedule_list_addon').on('change' ,'tfoot .check-column input',function() { if( jQuery(this).is(':checked') ) { jQuery('#mwp_wpvivid_schedule_list_addon').find('.schedule-item > .check-column > input').each(function() { var Obj=jQuery(this).closest('tr'); Obj.addClass('mwp-wpvivid-schedule-active'); Obj.find('.mwp-wpvivid-schedule-status').html('Active'); }); } else { jQuery('#mwp_wpvivid_schedule_list_addon').find('.schedule-item > .check-column > input').each(function() { var Obj=jQuery(this).closest('tr'); Obj.removeClass('mwp-wpvivid-schedule-active'); Obj.find('.mwp-wpvivid-schedule-status').html('InActive'); }); } }); var mwp_wpvivid_global_edit_schedule_id = ''; var mwp_wpvivid_global_edit_schedule_mould_name = ''; function mwp_wpvivid_display_global_schedule_setting(backupinfo) { var database_check = true; var core_check = true; var content_check = true; var themes_check = true; var plugins_check = true; var uploads_check = true; if(backupinfo.backup_select.db != 1){ database_check = false; } if(backupinfo.backup_select.core != 1){ core_check = false; } if(backupinfo.backup_select.content != 1){ content_check = false; } if(backupinfo.backup_select.themes != 1){ themes_check = false; } if(backupinfo.backup_select.plugin != 1){ plugins_check = false; } if(backupinfo.backup_select.uploads != 1){ uploads_check = false; } jQuery('#wpvivid_global_custom_update_schedule_backup').find('.mwp-wpvivid-custom-database-check').prop('checked', database_check); jQuery('#wpvivid_global_custom_update_schedule_backup').find('.mwp-wpvivid-custom-core-check').prop('checked', core_check); jQuery('#wpvivid_global_custom_update_schedule_backup').find('.mwp-wpvivid-custom-content-check').prop('checked', content_check); jQuery('#wpvivid_global_custom_update_schedule_backup').find('.mwp-wpvivid-custom-themes-check').prop('checked', themes_check); jQuery('#wpvivid_global_custom_update_schedule_backup').find('.mwp-wpvivid-custom-plugins-check').prop('checked', plugins_check); jQuery('#wpvivid_global_custom_update_schedule_backup').find('.mwp-wpvivid-custom-uploads-check').prop('checked', uploads_check); /*var include_other = ''; jQuery('#wpvivid_custom_update_schedule_backup').find('.mwp-wpvivid-custom-include-additional-folder-list').html(''); jQuery.each(backupinfo.custom_dirs.other_list, function(index ,value){ var type = 'folder'; var class_span = 'dashicons dashicons-category wpvivid-dashicons-orange wpvivid-icon-16px-nopointer'; include_other += "<div class='wpvivid-text-line' type='"+type+"'>" + "<span class='dashicons dashicons-trash wpvivid-icon-16px mwp-wpvivid-remove-custom-exlcude-tree'></span>" + "<span class='"+class_span+"'></span>" + "<span class='wpvivid-text-line'>" + value + "</span>" + "</div>"; }); jQuery('#wpvivid_custom_update_schedule_backup').find('.mwp-wpvivid-custom-include-additional-folder-list').append(include_other);*/ } function mwp_wpvivid_global_edit_schedule(schedule_id){ var mould_name = jQuery('#mwp_wpvivid_schedule_mould_name').val(); mwp_wpvivid_global_edit_schedule_id = schedule_id; mwp_wpvivid_global_edit_schedule_mould_name = mould_name; var ajax_data = { 'action': 'mwp_wpvivid_edit_global_schedule_addon', 'schedule_id': schedule_id, 'mould_name': mould_name }; mwp_wpvivid_post_request(ajax_data, function (data) { try { var jsonarray = jQuery.parseJSON(data); if (jsonarray.result === 'success') { jQuery('#mwp_wpvivid_tab_schedule_edit').show(); jQuery( document ).trigger( '<?php echo esc_js($this->main_tab->container_id); ?>-show',[ 'schedules_edit', 'schedules' ]); var arr = new Array(); arr = jsonarray.schedule_info.current_day.split(':'); jQuery('select[option=mwp_schedule_update][name=current_day_hour]').each(function() { jQuery(this).val(arr[0]); }); jQuery('select[option=mwp_schedule_update][name=current_day_minute]').each(function(){ jQuery(this).val(arr[1]); }); if(jsonarray.schedule_info.start_time_local_utc === 'local') { jQuery('#mwp_wpvivid_schedule_update_start_timezone').val('local'); } else{ jQuery('#mwp_wpvivid_schedule_update_start_timezone').val('utc'); } if(jsonarray.schedule_info.type === 'wpvivid_daily') { jQuery('#mwp_wpvivid_schedule_update_cycles_select').val('wpvivid_daily'); } else if(jsonarray.schedule_info.type === 'wpvivid_weekly') { jQuery('#mwp_wpvivid_schedule_update_week').show(); jQuery('#mwp_wpvivid_schedule_update_cycles_select').val('wpvivid_weekly'); jQuery('#mwp_wpvivid_schedule_update_week_select').val(jsonarray.schedule_info.week); } else if(jsonarray.schedule_info.type === 'wpvivid_fortnightly') { jQuery('#mwp_wpvivid_schedule_update_week').show(); jQuery('#mwp_wpvivid_schedule_update_cycles_select').val('wpvivid_fortnightly'); jQuery('#mwp_wpvivid_schedule_update_week_select').val(jsonarray.schedule_info.week); } else if(jsonarray.schedule_info.type === 'wpvivid_monthly') { jQuery('#mwp_wpvivid_schedule_update_day').show(); jQuery('#mwp_wpvivid_schedule_update_cycles_select').val('wpvivid_monthly'); jQuery('#mwp_wpvivid_schedule_update_day_select').val(jsonarray.schedule_info.day); } else{ jQuery('#mwp_wpvivid_schedule_update_cycles_select').val(jsonarray.schedule_info.type); } jQuery('#mwp_wpvivid_schedule_update_week').hide(); jQuery('#mwp_wpvivid_schedule_update_day').hide(); var select_value = jQuery('#mwp_wpvivid_schedule_update_cycles_select').val(); if(select_value === 'wpvivid_weekly' || select_value === 'wpvivid_fortnightly') { jQuery('#mwp_wpvivid_schedule_update_week').show(); } else if(select_value === 'wpvivid_monthly'){ jQuery('#mwp_wpvivid_schedule_update_day').show(); } jQuery('#mwp_wpvivid_schedule_update_start_local_time').html(jsonarray.schedule_info.current_day); jQuery('#mwp_wpvivid_schedule_update_start_utc_time').html(jsonarray.schedule_info.current_day); var backup_cycles = jQuery("#mwp_wpvivid_schedule_update_cycles_select option:selected").text(); jQuery('#mwp_wpvivid_schedule_update_start_cycles').html(backup_cycles); if(typeof jsonarray.schedule_info.backup.backup_files !== 'undefined') { if (jsonarray.schedule_info.backup.backup_files == 'files+db') { jQuery('input[option=mwp_schedule_update][name=mwp_schedule_update_backup_type][value=\'files+db\']').prop('checked', true); } else { jQuery('input[option=mwp_schedule_update][name=mwp_schedule_update_backup_type][value=' + jsonarray.schedule_info.backup.backup_files + ']').prop('checked', true); } jQuery('#wpvivid_global_custom_update_schedule_backup').hide(); //jQuery('#mwp_wpvivid_schedule_update_custom_module_part').hide(); //mwp_wpvivid_popup_schedule_tour_addon('hide', 'schedule_update'); } else{ jQuery('input[option=mwp_schedule_update][name=mwp_schedule_update_backup_type][value=custom]').prop('checked', true); jQuery('#wpvivid_global_custom_update_schedule_backup').show(); mwp_wpvivid_display_global_schedule_setting(jsonarray.schedule_info.backup); //mwp_wpvivid_display_edit_schedule_database_table(schedule_id) //jQuery('#mwp_wpvivid_schedule_update_custom_module_part').show(); //mwp_wpvivid_popup_schedule_tour_addon('show', 'schedule_update'); //mwp_wpvivid_display_schedule_setting(jsonarray.schedule_info.backup); } var backup_to = jsonarray.schedule_info.backup.local === 1 ? 'local' : 'remote'; jQuery('input:radio[option=mwp_update_schedule_backup][name=update_schedule_save_local_remote][value='+backup_to+']').prop('checked', true); jQuery('#mwp_wpvivid_schedule_update_utc_time').html(jsonarray.schedule_info.current_day); jQuery('#wpvivid_global_custom_update_schedule_advanced_option').find('.mwp-wpvivid-exclude-path').val(jsonarray.schedule_info.backup.exclude_files); jQuery('#wpvivid_global_custom_update_schedule_advanced_option').find('.mwp-wpvivid-custom-exclude-extension').val(jsonarray.schedule_info.backup.exclude_file_type); if(typeof jsonarray.schedule_info.backup.backup_prefix !== 'undefined') { jQuery('input:text[option=mwp_update_schedule_backup][name=backup_prefix]').val(jsonarray.schedule_info.backup.backup_prefix); } } else { alert(jsonarray.error); } } catch (err) { alert(err); } }, function (XMLHttpRequest, textStatus, errorThrown) { var error_message = mwp_wpvivid_output_ajaxerror('editing schedule', textStatus, errorThrown); alert(error_message); }); } function mwp_wpvivid_global_delete_schedule(schedule_id){ var mould_name = jQuery('#mwp_wpvivid_schedule_mould_name').val(); var ajax_data = { 'action': 'mwp_wpvivid_global_delete_schedule_addon', 'schedule_id': schedule_id, 'mould_name': mould_name }; jQuery('#mwp_wpvivid_schedule_update_notice').html(''); mwp_wpvivid_post_request(ajax_data, function (data) { try { var jsonarray = jQuery.parseJSON(data); if (jsonarray.result === 'success') { jQuery('#mwp_wpvivid_schedule_update_notice').html(jsonarray.notice); jQuery('#mwp_wpvivid_global_schedule_list_addon').html(jsonarray.html); } else { jQuery('#mwp_wpvivid_schedule_update_notice').html(jsonarray.notice); } } catch (err) { alert(err); } }, function (XMLHttpRequest, textStatus, errorThrown) { var error_message = mwp_wpvivid_output_ajaxerror('changing base settings', textStatus, errorThrown); alert(error_message); }); } jQuery('#mwp_wpvivid_global_schedule_list_addon').on('click', '.mwp-wpvivid-schedule-on-off-control', function(){ var mould_name = jQuery('#mwp_wpvivid_schedule_mould_name').val(); var Obj=jQuery(this); var json = {}; var schedule_id = ''; var schedule_status = ''; schedule_id = Obj.closest('tr').attr('slug'); if(jQuery(this).prop('checked')) { schedule_status = 'Active'; } else { schedule_status = 'InActive'; } json[schedule_id] = schedule_status; schedule_status = JSON.stringify(json); var ajax_data= { 'action': 'mwp_wpvivid_global_save_schedule_status_addon', 'schedule_data': schedule_status, 'mould_name': mould_name }; jQuery('#mwp_wpvivid_schedule_update_notice').html(''); mwp_wpvivid_post_request(ajax_data, function(data) { try { var jsonarray = jQuery.parseJSON(data); if (jsonarray.result === 'success') { jQuery('#mwp_wpvivid_schedule_update_notice').html(jsonarray.notice); jQuery('#mwp_wpvivid_global_schedule_list_addon').html(jsonarray.html); } else { jQuery('#mwp_wpvivid_schedule_update_notice').html(jsonarray.notice); } } catch (err) { alert(err); } }, function(XMLHttpRequest, textStatus, errorThrown) { var error_message = mwp_wpvivid_output_ajaxerror('setting up a lock for the backup', textStatus, errorThrown); alert(error_message); }); }); jQuery('#mwp_wpvivid_global_schedule_list_addon').on('click', '.mwp-wpvivid-schedule-edit', function(){ var Obj=jQuery(this); var id=Obj.closest('tr').attr('slug'); mwp_wpvivid_global_edit_schedule(id); }); jQuery('#mwp_wpvivid_global_schedule_list_addon').on('click', '.mwp-wpvivid-schedule-delete', function(){ var descript = 'Are you sure to remove this schedule?'; var ret = confirm(descript); if(ret === true) { var Obj = jQuery(this); var id = Obj.closest('tr').attr('slug'); mwp_wpvivid_global_delete_schedule(id); } }); jQuery('#mwp_wpvivid_global_schedule_list_addon').on('change', '.schedule-item > .check-column > input', function(){ if( jQuery(this).is(':checked') ) { var Obj=jQuery(this).closest('tr'); Obj.addClass('mwp-wpvivid-schedule-active'); Obj.find('.mwp-wpvivid-schedule-status').html('Active'); } else { var Obj=jQuery(this).closest('tr'); Obj.removeClass('mwp-wpvivid-schedule-active'); Obj.find('.mwp-wpvivid-schedule-status').html('InActive'); } }); jQuery('#mwp_wpvivid_global_schedule_list_addon').on('change', 'thead .check-column input', function(){ if( jQuery(this).is(':checked') ) { jQuery('#mwp_wpvivid_global_schedule_list_addon').find('.schedule-item > .check-column > input').each(function() { var Obj=jQuery(this).closest('tr'); Obj.addClass('mwp-wpvivid-schedule-active'); Obj.find('.mwp-wpvivid-schedule-status').html('Active'); }); } else { jQuery('#mwp_wpvivid_global_schedule_list_addon').find('.schedule-item > .check-column > input').each(function() { var Obj=jQuery(this).closest('tr'); Obj.removeClass('mwp-wpvivid-schedule-active'); Obj.find('.mwp-wpvivid-schedule-status').html('InActive'); }); } }); jQuery('#mwp_wpvivid_global_schedule_list_addon').on('change' ,'tfoot .check-column input',function() { if( jQuery(this).is(':checked') ) { jQuery('#mwp_wpvivid_global_schedule_list_addon').find('.schedule-item > .check-column > input').each(function() { var Obj=jQuery(this).closest('tr'); Obj.addClass('mwp-wpvivid-schedule-active'); Obj.find('.mwp-wpvivid-schedule-status').html('Active'); }); } else { jQuery('#mwp_wpvivid_global_schedule_list_addon').find('.schedule-item > .check-column > input').each(function() { var Obj=jQuery(this).closest('tr'); Obj.removeClass('mwp-wpvivid-schedule-active'); Obj.find('.mwp-wpvivid-schedule-status').html('InActive'); }); } }); jQuery('#mwp_wpvivid_global_schedule_save_addon').click(function(){ mwp_wpvivid_global_schedule_save_addon(); }); jQuery('#mwp_wpvivid_schedule_save_addon').click(function(){ mwp_wpvivid_schedule_save_addon(); }); function mwp_wpvivid_global_schedule_save_addon() { var json={}; var schedule_id = ''; var schedule_status = ''; var need_update = false; jQuery('#mwp_wpvivid_global_schedule_list_addon tbody').find('tr').each(function(){ if(!jQuery(this).hasClass('no-items')) { need_update = true; schedule_id = jQuery(this).attr('slug'); if (jQuery(this).children().children().prop('checked')) { schedule_status = 'Active'; } else { schedule_status = 'InActive'; } json[schedule_id] = schedule_status; } }); schedule_status = JSON.stringify(json); var ajax_data= { 'action': 'mwp_wpvivid_global_save_schedule_status_addon', 'schedule_data': schedule_status }; jQuery('#mwp_wpvivid_schedule_update_notice').html(''); mwp_wpvivid_post_request(ajax_data, function(data) { try { var jsonarray = jQuery.parseJSON(data); if (jsonarray.result === 'success') { window.location.href = window.location.href + "&synchronize=1&addon=1"; } else { jQuery('#mwp_wpvivid_schedule_update_notice').html(jsonarray.notice); } } catch (err) { alert(err); } }, function(XMLHttpRequest, textStatus, errorThrown) { var error_message = mwp_wpvivid_output_ajaxerror('setting up a lock for the backup', textStatus, errorThrown); alert(error_message); }); } function mwp_wpvivid_schedule_save_addon() { var json={}; var schedule_id = ''; var schedule_status = ''; var need_update = false; jQuery('#mwp_wpvivid_schedule_list_addon tbody').find('tr').each(function(){ if(!jQuery(this).hasClass('no-items')) { need_update = true; schedule_id = jQuery(this).attr('slug'); if (jQuery(this).children().children().prop('checked')) { schedule_status = 'Active'; } else { schedule_status = 'InActive'; } json[schedule_id] = schedule_status; } }); schedule_status = JSON.stringify(json); if(need_update === true){ var ajax_data= { 'action': 'mwp_wpvivid_save_schedule_status_addon', 'schedule_data': schedule_status, 'site_id': '<?php echo esc_html($this->site_id); ?>' }; jQuery('#mwp_wpvivid_schedule_update_notice').html(''); mwp_wpvivid_post_request(ajax_data, function(data) { try { var jsonarray = jQuery.parseJSON(data); if (jsonarray.result === 'success') { jQuery('#mwp_wpvivid_schedule_update_notice').html(jsonarray.notice); jQuery('#mwp_wpvivid_schedule_list_addon').html(jsonarray.html); } else { jQuery('#mwp_wpvivid_schedule_update_notice').html(jsonarray.notice); } } catch (err) { alert(err); } }, function(XMLHttpRequest, textStatus, errorThrown) { var error_message = mwp_wpvivid_output_ajaxerror('setting up a lock for the backup', textStatus, errorThrown); alert(error_message); }); } } function mwp_wpvivid_start_sync_schedule(){ mwp_wpvivid_global_schedule_save_addon(); } </script> <?php } public function output_schedules_page($global){ ?> <div style="margin-top: 10px;"> <?php if($global){ ?> <div class="mwp-wpvivid-block-bottom-space" id="mwp_wpvivid_schedule_mould_part_1"> <div class="mwp-wpvivid-block-bottom-space" id="mwp_wpvivid_schedule_mould_list_addon"> <?php $schedule_mould_list = Mainwp_WPvivid_Extension_DB_Option::get_instance()->wpvivid_get_global_option('schedule_mould_addon', array()); if(empty($schedule_mould_list)){ $schedule_mould_list = array(); } $table = new Mainwp_WPvivid_Schedule_Mould_List(); $table->set_schedule_mould_list($schedule_mould_list); $table->prepare_items(); $table->display(); ?> </div> <div> <input class="ui green mini button" type="button" value="<?php esc_attr_e('Create New Schedule Mould'); ?>" onclick="mwp_wpvivid_create_new_schedule_mould();" /> </div> </div> <div id="mwp_wpvivid_schedule_mould_part_2" style="display: none;"> <div class="mwp-wpvivid-block-bottom-space"> <span>Name the schedule template:</span> <input id="mwp_wpvivid_schedule_mould_name" /> <input class="ui green mini button" id="mwp_wpvivid_schedule_mould_name_edit" type="button" value="Edit" style="display: none;" /> <input class="ui green mini button" id="mwp_wpvivid_schedule_mould_name_save" type="button" value="Save" style="display: none;" /> </div> <div class="mwp-wpvivid-one-coloum" style="padding: 0em;"> <div id="mwp_wpvivid_schedule_create_notice"></div> <div id="mwp_wpvivid_schedule_save_notice"></div> </div> <div class="mwp-wpvivid-block-bottom-space" id="mwp_wpvivid_global_schedule_list_addon"> <?php $schedules = $this->setting_addon; $schedules_list = array(); $table=new Mainwp_WPvivid_Schedule_Global_List(); $table->set_schedule_list($schedules_list); $table->prepare_items(); $table->display(); ?> </div> <div class="mwp-wpvivid-block-bottom-space"> <input class="ui green mini button" onclick="mwp_wpvivid_back_schedule_mould();" type="button" value="<?php esc_attr_e('Back to Mould List'); ?>" /> </div> <?php $type='mwp_schedule_add'; $utc_time=date( 'H:i:s - m/d/Y ', time() ); $offset = get_option('gmt_offset'); $local_time=date( 'H:i:s - m/d/Y ', current_time( 'timestamp', 0 ) ); $mwp_wpvivid_cycles = $type==='mwp_schedule_add' ? 'mwp_wpvivid_schedule_add_cycles' : 'mwp_wpvivid_schedule_update_cycles'; $mwp_wpvivid_cycles_select = $type==='mwp_schedule_add' ? 'mwp_wpvivid_schedule_add_cycles_select' : 'mwp_wpvivid_schedule_update_cycles_select'; $mwp_wpvivid_week = $type==='mwp_schedule_add' ? 'mwp_wpvivid_schedule_add_week' : 'mwp_wpvivid_schedule_update_week'; $mwp_wpvivid_week_select = $type==='mwp_schedule_add' ? 'mwp_wpvivid_schedule_add_week_select' : 'mwp_wpvivid_schedule_update_week_select'; $mwp_wpvivid_day = $type==='mwp_schedule_add' ? 'mwp_wpvivid_schedule_add_day' : 'mwp_wpvivid_schedule_update_day'; $mwp_wpvivid_day_select = $type==='mwp_schedule_add' ? 'mwp_wpvivid_schedule_add_day_select' : 'mwp_wpvivid_schedule_update_day_select'; $mwp_wpvivid_hour_select = $type==='mwp_schedule_add' ? 'mwp_wpvivid_schedule_add_hour_select' : 'mwp_wpvivid_schedule_update_hour_select'; $mwp_wpvivid_minute_select = $type==='mwp_schedule_add' ? 'mwp_wpvivid_schedule_add_minute_select' : 'mwp_wpvivid_schedule_update_minute_select'; $mwp_wpvivid_utc_time = $type==='mwp_schedule_add' ? 'mwp_wpvivid_schedule_add_utc_time' : 'mwp_wpvivid_schedule_update_utc_time'; $mwp_wpvivid_start_local_time = $type==='mwp_schedule_add' ? 'mwp_wpvivid_schedule_add_start_local_time' : 'mwp_wpvivid_schedule_update_start_local_time'; $mwp_wpvivid_start_utc_time = $type==='mwp_schedule_add' ? 'mwp_wpvivid_schedule_add_start_utc_time' : 'mwp_wpvivid_schedule_update_start_utc_time'; $mwp_wpvivid_start_cycles = $type==='mwp_schedule_add' ? 'mwp_wpvivid_schedule_add_start_cycles' : 'mwp_wpvivid_schedule_update_start_cycles'; $mwp_wpvivid_start_timezone = $type==='mwp_schedule_add' ? 'mwp_wpvivid_schedule_add_start_timezone' : 'mwp_wpvivid_schedule_update_start_timezone'; $location = 'options-general.php'; $mwp_wpvivid_timezone = $global === true ? admin_url().'options-general.php' : 'admin.php?page=SiteOpen&newWindow=yes&websiteid='.$this->site_id.'&location='.base64_encode($location).'&_opennonce='.wp_create_nonce( 'mainwp-admin-nonce' ); ?> <div style="width:100%; border:1px solid #e5e5e5; float:left; box-sizing: border-box;margin-bottom:10px;"> <div class="mwp-wpvivid-block-bottom-space" style="margin: 1px 1px 10px 1px; background-color: #f7f7f7; box-sizing: border-box; padding: 10px;">Set backup cycle and start time:</div> <div class="mwp-wpvivid-block-bottom-space" style="margin-left: 10px; margin-right: 10px;"> <div style="padding: 4px 10px 0 0; float: left;">The backup will run</div> <div id="<?php echo esc_attr($mwp_wpvivid_cycles); ?>" style="padding: 0 10px 0 0; float: left;"> <select id="<?php echo esc_attr($mwp_wpvivid_cycles_select); ?>" option="<?php echo esc_attr($type); ?>" name="recurrence" onchange="mwp_wpvivid_set_schedule('<?php echo esc_attr($type); ?>');"> <option value="wpvivid_hourly">Every hour</option> <option value="wpvivid_2hours">Every 2 hours</option> <option value="wpvivid_4hours">Every 4 hours</option> <option value="wpvivid_8hours">Every 8 hours</option> <option value="wpvivid_12hours">Every 12 hours</option> <option value="wpvivid_daily" selected>Daily</option> <option value="wpvivid_weekly">Weekly</option> <option value="wpvivid_fortnightly">Fortnightly</option> <option value="wpvivid_monthly">30 Days</option> </select> </div> <div style="padding: 4px 10px 0 0; float: left;">at</div> <div id="<?php echo esc_attr($mwp_wpvivid_week); ?>" style="padding: 0 10px 0 0; float: left; display: none;"> <select id="<?php echo esc_attr($mwp_wpvivid_week_select); ?>" option="<?php echo esc_attr($type); ?>" name="week"> <option value="sun" selected>Sunday</option> <option value="mon">Monday</option> <option value="tue">Tuesday</option> <option value="wed">Wednesday</option> <option value="thu">Thursday</option> <option value="fri">Friday</option> <option value="sat">Saturday</option> </select> </div> <div id="<?php echo esc_attr($mwp_wpvivid_day); ?>" style="padding: 0 10px 0 0; float: left; display: none;"> <select id="<?php echo esc_attr($mwp_wpvivid_day_select); ?>" option="<?php echo esc_attr($type); ?>" name="day"> <?php for ($i = 1; $i < 31; $i++) { echo '<option value="' . esc_attr($i) . '">' . esc_html($i) . '</option>'; } ?> </select> </div> <div style="padding: 0 10px 0 0; float: left;"> <select id="<?php echo esc_attr($mwp_wpvivid_hour_select); ?>" option="<?php echo esc_attr($type); ?>" name="current_day_hour" style="margin-bottom: 4px;" onchange="mwp_wpvivid_set_schedule('<?php echo esc_attr($type); ?>');"> <?php for ($hour = 0; $hour < 24; $hour++) { $format_hour = sprintf("%02d", $hour); echo '<option value="' . esc_attr($format_hour) . '">' . esc_html($format_hour) . '</option>'; } ?> </select> <span>:</span> <select id="<?php echo esc_attr($mwp_wpvivid_minute_select); ?>" option="<?php echo esc_attr($type); ?>" name="current_day_minute" style="margin-bottom: 4px;" onchange="mwp_wpvivid_set_schedule('<?php echo esc_attr($type); ?>');"> <?php for ($minute = 0; $minute < 60; $minute++) { $format_minute = sprintf("%02d", $minute); echo '<option value="' . esc_attr($format_minute) . '">' . esc_html($format_minute) . '</option>'; } ?> </select> </div> <div style="clear: both;"></div> </div> </div> <div class="mwp-wpvivid-one-coloum mwp-wpvivid-workflow mwp-wpvivid-clear-float" style="margin-top:0.5em; margin-bottom: 0.5em;"> <div> <p><span class="dashicons dashicons-backup mwp-wpvivid-dashicons-blue"></span><span><strong>Backup Location</strong></span></p> <div style="padding-left:2em;"> <label class=""> <input type="radio" option="mwp_schedule_backup" name="schedule_save_local_remote" value="local" checked="checked" />Backup to localhost </label> <span style="padding: 0 1em;"></span> <label class=""> <input type="radio" option="mwp_schedule_backup" name="schedule_save_local_remote" value="remote" />Backup to remote storage </label> <span style="padding: 0 0.2em;"></span> <?php if(!$global) { ?> <span id="mwp_wpvivid_create_schedule_backup_remote_selector_part" style="display: none;"> <select id="mwp_wpvivid_create_schedule_backup_remote_selector"> <?php $remoteslist=array();//WPvivid_Setting::get_all_remote_options(); foreach ($remoteslist as $key=>$remote_option) { if($key=='remote_selected') { continue; } if(!isset($remote_option['id'])) { $remote_option['id'] = $key; } ?> <option value="<?php echo esc_attr($remote_option['id']); ?>" selected="selected"><?php echo esc_html($remote_option['name']); ?></option> <?php } ?> <option value="all">All activated remote storage</option> </select> </span> <?php } ?> </div> </div> <div style="clear: both;"></div> <p></p> <div> <p><span class="dashicons dashicons-screenoptions mwp-wpvivid-dashicons-blue"></span><span><strong>Backup Content</strong></span></p> <div style="padding:0.5em;margin-bottom:0.5em;background:#eaf1fe;border-radius:8px;"> <?php ?> <fieldset> <?php $this->mwp_wpvivid_schedule_backup_type_addon($type, $global); ?> </fieldset> <?php ?> </div> </div> <div style="clear: both;"></div> <p></p> <div id="wpvivid_global_custom_schedule_backup" style="display: none;"> <div style="border-left: 4px solid #eaf1fe; border-right: 4px solid #eaf1fe;box-sizing: border-box; padding-left:0.5em;"> <?php $custom_backup_manager = new Mainwp_WPvivid_Custom_Backup_Manager(); $custom_backup_manager->set_parent_id('wpvivid_global_custom_schedule_backup','schedule_backup','0','1'); $custom_backup_manager->output_custom_backup_db_table(); $custom_backup_manager->output_custom_backup_file_table(); ?> </div> </div> <p></p> <!--Advanced Option (Exclude)--> <div id="wpvivid_global_custom_schedule_advanced_option"> <?php $custom_backup_manager->wpvivid_set_advanced_id('wpvivid_global_custom_schedule_advanced_option'); $custom_backup_manager->output_advanced_option_table(); $custom_backup_manager->load_js(); ?> </div> <p></p> <div> <p> <span class="dashicons dashicons-welcome-write-blog mwp-wpvivid-dashicons-green" style="margin-top:0.2em;"></span> <span><strong>Comment the backup</strong>(optional): </span><input type="text" option="mwp_schedule_backup" name="backup_prefix" id="wpvivid_set_schedule_prefix" value="" onkeyup="value=value.replace(/[^a-zA-Z0-9._]/g,'')" onpaste="value=value.replace(/[^\a-\z\A-\Z0-9]/g,'')" placeholder=""> </p> </div> </div> <div style="clear: both;"></div> <div class="mwp-wpvivid-block-bottom-space"> <div id="mwp_wpvivid_schedule_create_notice"></div> <?php if($type === 'mwp_schedule_add'){ ?> <input class="ui green mini button" type="button" id="mwp_wpvivid_create_schedule_btn" value="Create new schedule" onclick="mwp_wpvivid_create_schedule_addon('<?php echo esc_js($type); ?>', '<?php echo esc_js($global); ?>');" /> <?php } else{ ?> <input class="ui green mini button" type="button" value="Update Schedule" onclick="mwp_wpvivid_edit_schedule_addon('<?php echo esc_js($type); ?>', '<?php echo esc_js($global); ?>');" /> <?php } ?> </div> <script> var first_create = '1'; var time_offset=<?php echo esc_js($offset); ?>; jQuery('input:radio[option=<?php echo esc_attr($type); ?>][name=mwp_schedule_add_backup_type]').click(function() { if(this.value === 'custom') { jQuery('#wpvivid_custom_schedule_backup').show(); jQuery('#wpvivid_global_custom_schedule_backup').show(); //jQuery( document ).trigger( 'wpvivid_refresh_schedule_backup_tables', 'schedule_backup' ); } else { jQuery('#wpvivid_custom_schedule_backup').hide(); jQuery('#wpvivid_global_custom_schedule_backup').hide(); } }); </script> </div> <?php } else{ $type='mwp_schedule_add'; $utc_time=date( 'H:i:s - m/d/Y ', time() ); $offset = $this->time_zone; $local_time = time() + $offset * 60 * 60; $local_time = date("H:i:s - m/d/Y ", $local_time); $mwp_wpvivid_cycles = $type==='mwp_schedule_add' ? 'mwp_wpvivid_schedule_add_cycles' : 'mwp_wpvivid_schedule_update_cycles'; $mwp_wpvivid_cycles_select = $type==='mwp_schedule_add' ? 'mwp_wpvivid_schedule_add_cycles_select' : 'mwp_wpvivid_schedule_update_cycles_select'; $mwp_wpvivid_week = $type==='mwp_schedule_add' ? 'mwp_wpvivid_schedule_add_week' : 'mwp_wpvivid_schedule_update_week'; $mwp_wpvivid_week_select = $type==='mwp_schedule_add' ? 'mwp_wpvivid_schedule_add_week_select' : 'mwp_wpvivid_schedule_update_week_select'; $mwp_wpvivid_day = $type==='mwp_schedule_add' ? 'mwp_wpvivid_schedule_add_day' : 'mwp_wpvivid_schedule_update_day'; $mwp_wpvivid_day_select = $type==='mwp_schedule_add' ? 'mwp_wpvivid_schedule_add_day_select' : 'mwp_wpvivid_schedule_update_day_select'; $mwp_wpvivid_hour_select = $type==='mwp_schedule_add' ? 'mwp_wpvivid_schedule_add_hour_select' : 'mwp_wpvivid_schedule_update_hour_select'; $mwp_wpvivid_minute_select = $type==='mwp_schedule_add' ? 'mwp_wpvivid_schedule_add_minute_select' : 'mwp_wpvivid_schedule_update_minute_select'; $mwp_wpvivid_utc_time = $type==='mwp_schedule_add' ? 'mwp_wpvivid_schedule_add_utc_time' : 'mwp_wpvivid_schedule_update_utc_time'; $mwp_wpvivid_start_local_time = $type==='mwp_schedule_add' ? 'mwp_wpvivid_schedule_add_start_local_time' : 'mwp_wpvivid_schedule_update_start_local_time'; $mwp_wpvivid_start_utc_time = $type==='mwp_schedule_add' ? 'mwp_wpvivid_schedule_add_start_utc_time' : 'mwp_wpvivid_schedule_update_start_utc_time'; $mwp_wpvivid_start_cycles = $type==='mwp_schedule_add' ? 'mwp_wpvivid_schedule_add_start_cycles' : 'mwp_wpvivid_schedule_update_start_cycles'; $mwp_wpvivid_start_timezone = $type==='mwp_schedule_add' ? 'mwp_wpvivid_schedule_add_start_timezone' : 'mwp_wpvivid_schedule_update_start_timezone'; $location = 'options-general.php'; $mwp_wpvivid_timezone = $global === true ? admin_url().'options-general.php' : 'admin.php?page=SiteOpen&newWindow=yes&websiteid='.$this->site_id.'&location='.base64_encode($location).'&_opennonce='.wp_create_nonce( 'mainwp-admin-nonce' ); $prefix = ''; $prefix = apply_filters('mwp_wpvivid_get_backup_prefix', $prefix); ?> <div id="mwp_wpvivid_schedule_update_notice"></div> <div style="width: 100%; border: 1px solid #e5e5e5; float: left; box-sizing: border-box; margin-bottom: 10px; padding: 10px;"> <div class="mwp-wpvivid-block-bottom-space"><strong>Tips: </strong>Selected schedules will be executed sequentially. When there is a conflict of starting times for scheduled tasks, only one will be executed properly.</div> <div id="mwp_wpvivid_schedule_list_addon"></div> <?php if($global===false){ ?> <div style="margin-top: 10px; float: left;"> <?php if($global===false) { $save_change_id= 'mwp_wpvivid_schedule_save_addon'; ?> <!--<input class="ui green mini button" id="<?php echo esc_attr($save_change_id); ?>" type="button" value="Save Changes" />--> <?php } else { $save_change_id= 'mwp_wpvivid_global_schedule_save_addon'; } ?> </div> <?php } ?> <div style="clear: both;"></div> </div> <div class="mwp-wpvivid-block-bottom-space"> <input class="ui green mini button" type="button" value="Create a job" onclick="mwp_wpvivid_create_schedule_job();"> </div> <div id="mwp_wpvivid_schedule_backup_deploy" style="display: none;"> <div class="mwp-wpvivid-block-bottom-space" > <table class="wp-list-table widefat plugin"> <thead> <tr> <th></th> <th class="manage-column column-name column-primary"><strong>Local Time </strong><a href="<?php echo esc_url($mwp_wpvivid_timezone); ?>">(Timezone Setting)</a></th> <th class="manage-column column-name column-primary"><strong>Universal Time (UTC)</strong></th> </tr> </thead> <tbody> <tr> <th><strong>Current Time</strong></th> <td> <div> <div style="float: left; margin-right: 10px;"><?php echo esc_html($local_time); ?></div> <small> <div class="mwp-wpvivid-tooltip" style="float: left; margin-top:3px; line-height: 100%;">? <div class="mwp-wpvivid-tooltiptext">Current time in the city or the UTC timezone offset you have chosen in WordPress Timezone Settings. </div> </div> </small> <div style="clear: both;"></div> </div> </td> <td> <div> <div style="float: left; margin-right: 10px;"><?php echo esc_html($utc_time); ?></div> <small> <div class="mwp-wpvivid-tooltip" style="float: left; margin-top:3px; line-height: 100%;">? <div class="mwp-wpvivid-tooltiptext">Current local time in UTC.</div> </div> </small> <div style="clear: both;"></div> </div> </td> </tr> <tr> <th><strong>Schedule Start Time</strong></th> <td> <span> <div id="<?php echo esc_attr($mwp_wpvivid_cycles); ?>" style="padding: 0 10px 0 0; float: left;"> <select id="<?php echo esc_attr($mwp_wpvivid_cycles_select); ?>" option="<?php echo esc_attr($type); ?>" name="recurrence" onchange="mwp_wpvivid_set_schedule('<?php echo esc_attr($type); ?>');"> <option value="wpvivid_hourly">Every hour</option> <option value="wpvivid_2hours">Every 2 hours</option> <option value="wpvivid_4hours">Every 4 hours</option> <option value="wpvivid_8hours">Every 8 hours</option> <option value="wpvivid_12hours">Every 12 hours</option> <option value="wpvivid_daily" selected>Daily</option> <option value="wpvivid_weekly">Weekly</option> <option value="wpvivid_fortnightly">Fortnightly</option> <option value="wpvivid_monthly">30 Days</option> </select> </div> </span> <span> <div id="<?php echo esc_attr($mwp_wpvivid_week); ?>" style="padding: 0 10px 0 0; float: left; display: none;"> <select id="<?php echo esc_attr($mwp_wpvivid_week_select); ?>" option="<?php echo esc_attr($type); ?>" name="week"> <option value="sun" selected>Sunday</option> <option value="mon">Monday</option> <option value="tue">Tuesday</option> <option value="wed">Wednesday</option> <option value="thu">Thursday</option> <option value="fri">Friday</option> <option value="sat">Saturday</option> </select> </div> </span> <span> <div id="<?php echo esc_attr($mwp_wpvivid_day); ?>" style="padding: 0 10px 0 0; float: left; display: none;"> <div class="mwp-wpvivid-schedule-font-fix mwp-wpvivid-font-right-space" style="float: left;">Start at:</div> <select id="<?php echo esc_attr($mwp_wpvivid_day_select); ?>" option="<?php echo esc_attr($type); ?>" name="day"> <?php for ($i = 1; $i < 31; $i++) { echo '<option value="' . esc_attr($i) . '">' . esc_html($i) . '</option>'; } ?> </select> </div> </span> <span> <div style="padding: 0 10px 0 0;"> <select id="<?php echo esc_attr($mwp_wpvivid_hour_select); ?>" option="<?php echo esc_attr($type); ?>" name="current_day_hour" style="margin-bottom: 4px;" onchange="mwp_wpvivid_set_schedule('<?php echo esc_attr($type); ?>');"> <?php for ($hour = 0; $hour < 24; $hour++) { $format_hour = sprintf("%02d", $hour); echo '<option value="' . esc_attr($format_hour) . '">' . esc_html($format_hour) . '</option>'; } ?> </select> <span>:</span> <select id="<?php echo esc_attr($mwp_wpvivid_minute_select); ?>" option="<?php echo esc_attr($type); ?>" name="current_day_minute" style="margin-bottom: 4px;" onchange="mwp_wpvivid_set_schedule('<?php echo esc_attr($type); ?>');"> <?php for ($minute = 0; $minute < 60; $minute++) { $format_minute = sprintf("%02d", $minute); echo '<option value="' . esc_attr($format_minute) . '">' . esc_html($format_minute) . '</option>'; } ?> </select> </div> </span> </td> <td style="vertical-align: middle;"> <div> <div id="<?php echo esc_attr($mwp_wpvivid_utc_time); ?>" style="float: left; margin-right: 10px;">00:00 </div> <small> <div class="mwp-wpvivid-tooltip" style="float: left; margin-top:3px; line-height: 100%;">? <div class="mwp-wpvivid-tooltiptext">The schedule start time in UTC.</div> </div> </small> <div style="clear: both;"></div> </div> </td> </tr> </tbody> <tfoot> <tr> <th colspan="3"> <i> <span>The schedule will be performed at [(local time)</span> <span id="<?php echo esc_attr($mwp_wpvivid_start_local_time); ?>" style="margin-right: 0;">00:00</span> <span>] [UTC</span> <span id="<?php echo esc_attr($mwp_wpvivid_start_utc_time); ?>" style="margin-right: 0;">00:00</span> <span>] [Schedule Cycles:</span> <span id="<?php echo esc_attr($mwp_wpvivid_start_cycles); ?>" style="margin-right: 0;">Daily</span>] </i> </th> <tr> </tfoot> </table> </div> <div class="mwp-wpvivid-one-coloum mwp-wpvivid-workflow mwp-wpvivid-clear-float" style="margin-top:0.5em; margin-bottom: 0.5em;"> <div> <p><span class="dashicons dashicons-backup mwp-wpvivid-dashicons-blue"></span><span><strong>Backup Location</strong></span></p> <div style="padding-left:2em;"> <label class=""> <input type="radio" option="mwp_schedule_backup" name="schedule_save_local_remote" value="local" checked="checked" />Backup to localhost </label> <span style="padding: 0 1em;"></span> <label class=""> <input type="radio" option="mwp_schedule_backup" name="schedule_save_local_remote" value="remote" />Backup to remote storage </label> <span style="padding: 0 0.2em;"></span> <span id="mwp_wpvivid_create_schedule_backup_remote_selector_part" style="display: none;"> <select id="mwp_wpvivid_create_schedule_backup_remote_selector"> <?php $remoteslist=array();//WPvivid_Setting::get_all_remote_options(); foreach ($remoteslist as $key=>$remote_option) { if($key=='remote_selected') { continue; } if(!isset($remote_option['id'])) { $remote_option['id'] = $key; } ?> <option value="<?php echo esc_attr($remote_option['id']); ?>" selected="selected"><?php echo esc_html($remote_option['name']); ?></option> <?php } ?> <option value="all">All activated remote storage</option> </select> </span> </div> </div> <div style="clear: both;"></div> <p></p> <div> <p><span class="dashicons dashicons-screenoptions mwp-wpvivid-dashicons-blue"></span><span><strong>Backup Content</strong></span></p> <div style="padding:1em;margin-bottom:1em;background:#eaf1fe;border-radius:8px;"> <?php $fieldset_style = ''; ?> <fieldset style="<?php echo esc_attr($fieldset_style); ?>"> <?php $this->mwp_wpvivid_schedule_backup_type_addon($type, $global); ?> </fieldset> <?php ?> </div> </div> <div id="wpvivid_custom_schedule_backup" style="display: none;"> <div style="border-left: 4px solid #eaf1fe; border-right: 4px solid #eaf1fe;box-sizing: border-box; padding-left:0.5em;"> <?php $custom_backup_manager = new Mainwp_WPvivid_Custom_Backup_Manager(); $custom_backup_manager->set_site_id($this->site_id); $custom_backup_manager->set_parent_id('wpvivid_custom_schedule_backup','schedule_backup','0','0'); $custom_backup_manager->output_custom_backup_db_table(); $custom_backup_manager->output_custom_backup_file_table(); ?> </div> </div> <!--Advanced Option (Exclude)--> <div id="wpvivid_custom_schedule_advanced_option"> <?php $custom_backup_manager->wpvivid_set_advanced_id('wpvivid_custom_schedule_advanced_option'); $custom_backup_manager->output_advanced_option_table(); $custom_backup_manager->load_js(); ?> </div> <div> <p> <span class="dashicons dashicons-welcome-write-blog mwp-wpvivid-dashicons-green" style="margin-top:0.2em;"></span> <span><strong>Comment the backup</strong>(optional): </span><input type="text" option="mwp_schedule_backup" name="backup_prefix" id="wpvivid_set_schedule_prefix" value="<?php echo esc_attr($prefix); ?>" onkeyup="value=value.replace(/[^a-zA-Z0-9._]/g,'')" onpaste="value=value.replace(/[^\a-\z\A-\Z0-9]/g,'')" placeholder="<?php echo esc_attr($prefix); ?>"> </p> </div> </div> <div style="clear: both;"></div> <div class="mwp-wpvivid-block-bottom-space"> <div id="mwp_wpvivid_schedule_create_notice"></div> <?php if($type === 'mwp_schedule_add'){ ?> <input class="ui green mini button" type="button" id="mwp_wpvivid_create_schedule_btn" value="Create new schedule" onclick="mwp_wpvivid_create_schedule_addon('<?php echo esc_js($type); ?>', '<?php echo esc_js($global); ?>');" /> <?php } else{ ?> <input class="ui green mini button" type="button" value="Update Schedule" onclick="mwp_wpvivid_edit_schedule_addon('<?php echo esc_js($type); ?>', '<?php echo esc_js($global); ?>');" /> <?php } ?> </div> </div> <script> var first_create = '1'; var time_offset=<?php echo esc_js($offset); ?>; jQuery('input:radio[option=<?php echo esc_attr($type); ?>][name=mwp_schedule_add_backup_type]').click(function() { if(this.value === 'custom') { jQuery('#wpvivid_custom_schedule_backup').show(); jQuery('#wpvivid_global_custom_schedule_backup').show(); //jQuery( document ).trigger( 'wpvivid_refresh_schedule_backup_tables', 'schedule_backup' ); } else { jQuery('#wpvivid_custom_schedule_backup').hide(); jQuery('#wpvivid_global_custom_schedule_backup').hide(); } }); function mwp_wpvivid_create_schedule_job() { jQuery('#mwp_wpvivid_schedule_backup_deploy').show(); } </script> <?php } ?> </div> <script> var mwp_edit_global_schedule_mould_name = ''; function mwp_wpvivid_create_new_schedule_mould() { jQuery('#mwp_wpvivid_schedule_mould_part_1').hide(); jQuery('#mwp_wpvivid_schedule_mould_part_2').show(); } function mwp_wpvivid_back_schedule_mould() { window.location.href = window.location.href; } jQuery('#mwp_wpvivid_schedule_mould_name_edit').click(function(){ jQuery('#mwp_wpvivid_schedule_mould_name').attr('disabled', false); jQuery('#mwp_wpvivid_create_schedule_btn').attr('disabled', true); jQuery('#mwp_wpvivid_schedule_mould_name_edit').hide(); jQuery('#mwp_wpvivid_schedule_mould_name_save').show(); }); jQuery('#mwp_wpvivid_schedule_mould_name_save').click(function(){ jQuery('#mwp_wpvivid_schedule_create_notice').html(''); var schedule_mould_name = jQuery('#mwp_wpvivid_schedule_mould_name').val(); if(schedule_mould_name == ''){ alert('A schedule mould name is required.'); return; } if(mwp_edit_global_schedule_mould_name === schedule_mould_name) { jQuery('#mwp_wpvivid_schedule_mould_name').attr('disabled', true); jQuery('#mwp_wpvivid_create_schedule_btn').attr('disabled', false); jQuery('#mwp_wpvivid_schedule_mould_name_edit').show(); jQuery('#mwp_wpvivid_schedule_mould_name_save').hide(); } else { var ajax_data = { 'action': 'mwp_wpvivid_edit_global_schedule_mould_name_addon', 'schedule_mould_name': schedule_mould_name, 'schedule_mould_old_name': mwp_edit_global_schedule_mould_name }; mwp_wpvivid_post_request(ajax_data, function (data) { try { var jsonarray = jQuery.parseJSON(data); if (jsonarray.result === 'success') { jQuery('#mwp_wpvivid_schedule_mould_name').attr('disabled', true); jQuery('#mwp_wpvivid_create_schedule_btn').attr('disabled', false); jQuery('#mwp_wpvivid_schedule_mould_name_edit').show(); jQuery('#mwp_wpvivid_schedule_mould_name_save').hide(); } else { jQuery('#mwp_wpvivid_schedule_create_notice').html(jsonarray.notice); } } catch (err) { alert(err); } }, function (XMLHttpRequest, textStatus, errorThrown) { var error_message = mwp_wpvivid_output_ajaxerror('editing schedule mould name', textStatus, errorThrown); alert(error_message); }); } }); jQuery('#mwp_wpvivid_schedule_mould_list_addon').on('click', '.mwp-wpvivid-sync-schedule-mould', function(){ var Obj=jQuery(this); var mould_name=Obj.closest('tr').attr('slug'); window.location.href = window.location.href + "&synchronize=1&addon=1&mould_name=" + mould_name; }); jQuery('#mwp_wpvivid_schedule_mould_list_addon').on('click', '.mwp-wpvivid-schedule-mould-edit', function(){ jQuery('#mwp_wpvivid_schedule_mould_part_1').hide(); jQuery('#mwp_wpvivid_schedule_mould_part_2').show(); var Obj=jQuery(this); var mould_name=Obj.closest('tr').attr('slug'); mwp_wpvivid_edit_schedule_mould(mould_name); }); jQuery('#mwp_wpvivid_schedule_mould_list_addon').on('click', '.mwp-wpvivid-schedule-mould-delete', function(){ var descript = 'Are you sure to remove this schedule mould?'; var ret = confirm(descript); if(ret === true) { var Obj = jQuery(this); var mould_name = Obj.closest('tr').attr('slug'); mwp_wpvivid_delete_schedule_mould(mould_name); } }); function mwp_wpvivid_edit_schedule_mould(mould_name) { mwp_edit_global_schedule_mould_name = mould_name; jQuery('#mwp_wpvivid_schedule_mould_name').val(mould_name); jQuery('#mwp_wpvivid_schedule_mould_name').attr('disabled', 'disabled'); jQuery('#mwp_wpvivid_schedule_mould_name_edit').show(); first_create = '0'; var ajax_data = { 'action': 'mwp_wpvivid_edit_global_schedule_mould_addon', 'mould_name': mould_name }; mwp_wpvivid_post_request(ajax_data, function (data) { try { var jsonarray = jQuery.parseJSON(data); if (jsonarray.result === 'success') { jQuery('#mwp_wpvivid_global_schedule_list_addon').html(jsonarray.html); } else { alert(jsonarray.error); } } catch (err) { alert(err); } }, function (XMLHttpRequest, textStatus, errorThrown) { var error_message = mwp_wpvivid_output_ajaxerror('editing schedule', textStatus, errorThrown); alert(error_message); }); } function mwp_wpvivid_delete_schedule_mould(mould_name) { var ajax_data = { 'action': 'mwp_wpvivid_delete_global_schedule_mould_addon', 'mould_name': mould_name }; mwp_wpvivid_post_request(ajax_data, function (data) { try { var jsonarray = jQuery.parseJSON(data); if (jsonarray.result === 'success') { jQuery('#mwp_wpvivid_schedule_mould_list_addon').html(jsonarray.html); } else { alert(jsonarray.error); } } catch (err) { alert(err); } }, function (XMLHttpRequest, textStatus, errorThrown) { var error_message = mwp_wpvivid_output_ajaxerror('editing schedule', textStatus, errorThrown); alert(error_message); }); } jQuery('#mwp_wpvivid_schedule_mould_list_addon').on("click",'.first-page',function() { mwp_wpvivid_get_schedule_mould_list('first'); }); jQuery('#mwp_wpvivid_schedule_mould_list_addon').on("click",'.prev-page',function() { var page=parseInt(jQuery(this).attr('value')); mwp_wpvivid_get_schedule_mould_list(page-1); }); jQuery('#mwp_wpvivid_schedule_mould_list_addon').on("click",'.next-page',function() { var page=parseInt(jQuery(this).attr('value')); mwp_wpvivid_get_schedule_mould_list(page+1); }); jQuery('#mwp_wpvivid_schedule_mould_list_addon').on("click",'.last-page',function() { mwp_wpvivid_get_schedule_mould_list('last'); }); jQuery('#mwp_wpvivid_schedule_mould_list_addon').on("keypress", '.current-page', function(){ if(event.keyCode === 13){ var page = jQuery(this).val(); mwp_wpvivid_get_schedule_mould_list(page); } }); function mwp_wpvivid_get_schedule_mould_list(page=0) { if(page === 0){ var current_page = jQuery('#mwp_wpvivid_schedule_mould_list_addon').find('.current-page').val(); if(typeof current_page !== 'undefined') { page = jQuery('#mwp_wpvivid_schedule_mould_list_addon').find('.current-page').val(); } } var ajax_data = { 'action': 'mwp_wpvivid_get_schedule_mould_list', 'page':page }; mwp_wpvivid_post_request(ajax_data, function (data) { jQuery('#mwp_wpvivid_schedule_mould_list_addon').html(''); try { var jsonarray = jQuery.parseJSON(data); if (jsonarray.result === 'success') { jQuery('#mwp_wpvivid_schedule_mould_list_addon').html(jsonarray.schedule_mould_list); } else { alert(jsonarray.error); } } catch (err) { alert(err); } }, function (XMLHttpRequest, textStatus, errorThrown) { setTimeout(function () { mwp_wpvivid_get_schedule_mould_list(); }, 3000); }); } </script> <?php } public function output_schedules_edit_page($global){ ?> <div style="margin-top: 10px;"> <?php $type='mwp_schedule_update'; ?> <?php $utc_time=date( 'H:i:s - m/d/Y ', time() ); if($global) { $offset = get_option('gmt_offset'); $local_time=date( 'H:i:s - m/d/Y ', current_time( 'timestamp', 0 ) ); } else{ $offset = $this->time_zone; $local_time = time() + $offset * 60 * 60; $local_time = date("H:i:s - m/d/Y ", $local_time); } $mwp_wpvivid_cycles = $type==='mwp_schedule_add' ? 'mwp_wpvivid_schedule_add_cycles' : 'mwp_wpvivid_schedule_update_cycles'; $mwp_wpvivid_cycles_select = $type==='mwp_schedule_add' ? 'mwp_wpvivid_schedule_add_cycles_select' : 'mwp_wpvivid_schedule_update_cycles_select'; $mwp_wpvivid_week = $type==='mwp_schedule_add' ? 'mwp_wpvivid_schedule_add_week' : 'mwp_wpvivid_schedule_update_week'; $mwp_wpvivid_week_select = $type==='mwp_schedule_add' ? 'mwp_wpvivid_schedule_add_week_select' : 'mwp_wpvivid_schedule_update_week_select'; $mwp_wpvivid_day = $type==='mwp_schedule_add' ? 'mwp_wpvivid_schedule_add_day' : 'mwp_wpvivid_schedule_update_day'; $mwp_wpvivid_day_select = $type==='mwp_schedule_add' ? 'mwp_wpvivid_schedule_add_day_select' : 'mwp_wpvivid_schedule_update_day_select'; $mwp_wpvivid_hour_select = $type==='mwp_schedule_add' ? 'mwp_wpvivid_schedule_add_hour_select' : 'mwp_wpvivid_schedule_update_hour_select'; $mwp_wpvivid_minute_select = $type==='mwp_schedule_add' ? 'mwp_wpvivid_schedule_add_minute_select' : 'mwp_wpvivid_schedule_update_minute_select'; $mwp_wpvivid_utc_time = $type==='mwp_schedule_add' ? 'mwp_wpvivid_schedule_add_utc_time' : 'mwp_wpvivid_schedule_update_utc_time'; $mwp_wpvivid_start_local_time = $type==='mwp_schedule_add' ? 'mwp_wpvivid_schedule_add_start_local_time' : 'mwp_wpvivid_schedule_update_start_local_time'; $mwp_wpvivid_start_utc_time = $type==='mwp_schedule_add' ? 'mwp_wpvivid_schedule_add_start_utc_time' : 'mwp_wpvivid_schedule_update_start_utc_time'; $mwp_wpvivid_start_cycles = $type==='mwp_schedule_add' ? 'mwp_wpvivid_schedule_add_start_cycles' : 'mwp_wpvivid_schedule_update_start_cycles'; $mwp_wpvivid_start_timezone = $type==='mwp_schedule_add' ? 'mwp_wpvivid_schedule_add_start_timezone' : 'mwp_wpvivid_schedule_update_start_timezone'; $location = 'options-general.php'; $mwp_wpvivid_timezone = $global === true ? admin_url().'options-general.php' : 'admin.php?page=SiteOpen&newWindow=yes&websiteid='.$this->site_id.'&location='.base64_encode($location).'&_opennonce='.wp_create_nonce( 'mainwp-admin-nonce' ); ?> <?php if(!$global) { ?> <div class="mwp-wpvivid-block-bottom-space"> <table class="wp-list-table widefat plugin"> <thead> <tr> <th></th> <th class="manage-column column-name column-primary"><strong>Local Time </strong><a href="<?php echo esc_url($mwp_wpvivid_timezone); ?>">(Timezone Setting)</a></th> <th class="manage-column column-name column-primary"><strong>Universal Time (UTC)</strong></th> </tr> </thead> <tbody> <tr> <th><strong>Current Time</strong></th> <td> <div> <div style="float: left; margin-right: 10px;"><?php echo esc_html($local_time); ?></div> <small> <div class="mwp-wpvivid-tooltip" style="float: left; margin-top:3px; line-height: 100%;">? <div class="mwp-wpvivid-tooltiptext">Current time in the city or the UTC timezone offset you have chosen in WordPress Timezone Settings. </div> </div> </small> <div style="clear: both;"></div> </div> </td> <td> <div> <div style="float: left; margin-right: 10px;"><?php echo esc_html($utc_time); ?></div> <small> <div class="mwp-wpvivid-tooltip" style="float: left; margin-top:3px; line-height: 100%;">? <div class="mwp-wpvivid-tooltiptext">Current local time in UTC.</div> </div> </small> <div style="clear: both;"></div> </div> </td> </tr> <tr> <th><strong>Schedule Start Time</strong></th> <td> <span> <div id="<?php echo esc_attr($mwp_wpvivid_cycles); ?>" style="padding: 0 10px 0 0; float: left;"> <select id="<?php echo esc_attr($mwp_wpvivid_cycles_select); ?>" option="<?php echo esc_attr($type); ?>" name="recurrence" onchange="mwp_wpvivid_set_schedule('<?php echo esc_attr($type); ?>');"> <option value="wpvivid_hourly">Every hour</option> <option value="wpvivid_2hours">Every 2 hours</option> <option value="wpvivid_4hours">Every 4 hours</option> <option value="wpvivid_8hours">Every 8 hours</option> <option value="wpvivid_12hours">Every 12 hours</option> <option value="wpvivid_daily" selected>Daily</option> <option value="wpvivid_weekly">Weekly</option> <option value="wpvivid_fortnightly">Fortnightly</option> <option value="wpvivid_monthly">30 Days</option> </select> </div> </span> <span> <div id="<?php echo esc_attr($mwp_wpvivid_week); ?>" style="padding: 0 10px 0 0; float: left; display: none;"> <select id="<?php echo esc_attr($mwp_wpvivid_week_select); ?>" option="<?php echo esc_attr($type); ?>" name="week"> <option value="sun" selected>Sunday</option> <option value="mon">Monday</option> <option value="tue">Tuesday</option> <option value="wed">Wednesday</option> <option value="thu">Thursday</option> <option value="fri">Friday</option> <option value="sat">Saturday</option> </select> </div> </span> <span> <div id="<?php echo esc_attr($mwp_wpvivid_day); ?>" style="padding: 0 10px 0 0; float: left; display: none;"> <div class="mwp-wpvivid-schedule-font-fix mwp-wpvivid-font-right-space" style="float: left;">Start at:</div> <select id="<?php echo esc_attr($mwp_wpvivid_day_select); ?>" option="<?php echo esc_attr($type); ?>" name="day"> <?php for ($i = 1; $i < 31; $i++) { echo '<option value="' . esc_attr($i) . '">' . esc_html($i) . '</option>'; } ?> </select> </div> </span> <span> <div style="padding: 0 10px 0 0;"> <select id="<?php echo esc_attr($mwp_wpvivid_hour_select); ?>" option="<?php echo esc_attr($type); ?>" name="current_day_hour" style="margin-bottom: 4px;" onchange="mwp_wpvivid_set_schedule('<?php echo esc_attr($type); ?>');"> <?php for ($hour = 0; $hour < 24; $hour++) { $format_hour = sprintf("%02d", $hour); echo '<option value="' . esc_attr($format_hour) . '">' . esc_html($format_hour) . '</option>'; } ?> </select> <span>:</span> <select id="<?php echo esc_attr($mwp_wpvivid_minute_select); ?>" option="<?php echo esc_attr($type); ?>" name="current_day_minute" style="margin-bottom: 4px;" onchange="mwp_wpvivid_set_schedule('<?php echo esc_attr($type); ?>');"> <?php for ($minute = 0; $minute < 60; $minute++) { $format_minute = sprintf("%02d", $minute); echo '<option value="' . esc_attr($format_minute) . '">' . esc_html($format_minute) . '</option>'; } ?> </select> </div> </span> </td> <td style="vertical-align: middle;"> <div> <div id="<?php echo esc_attr($mwp_wpvivid_utc_time); ?>" style="float: left; margin-right: 10px;">00:00 </div> <small> <div class="mwp-wpvivid-tooltip" style="float: left; margin-top:3px; line-height: 100%;">? <div class="mwp-wpvivid-tooltiptext">The schedule start time in UTC.</div> </div> </small> <div style="clear: both;"></div> </div> </td> </tr> </tbody> <tfoot> <tr> <th colspan="3"> <i> <span>The schedule will be performed at [(local time)</span> <span id="<?php echo esc_attr($mwp_wpvivid_start_local_time); ?>" style="margin-right: 0;">00:00</span> <span>] [UTC</span> <span id="<?php echo esc_attr($mwp_wpvivid_start_utc_time); ?>" style="margin-right: 0;">00:00</span> <span>] [Schedule Cycles:</span> <span id="<?php echo esc_attr($mwp_wpvivid_start_cycles); ?>" style="margin-right: 0;">Daily</span>] </i> </th> <tr> </tfoot> </table> </div> <?php } else{ ?> <div style="width:100%; border:1px solid #e5e5e5; float:left; box-sizing: border-box;margin-bottom:10px;"> <div class="mwp-wpvivid-block-bottom-space" style="margin: 1px 1px 10px 1px; background-color: #f7f7f7; box-sizing: border-box; padding: 10px;">Set backup cycle and start time:</div> <div class="mwp-wpvivid-block-bottom-space" style="margin-left: 10px; margin-right: 10px;"> <div style="padding: 4px 10px 0 0; float: left;">The backup will run</div> <div id="<?php echo esc_attr($mwp_wpvivid_cycles); ?>" style="padding: 0 10px 0 0; float: left;"> <select id="<?php echo esc_attr($mwp_wpvivid_cycles_select); ?>" option="<?php echo esc_attr($type); ?>" name="recurrence" onchange="mwp_wpvivid_set_schedule('<?php echo esc_attr($type); ?>');"> <option value="wpvivid_hourly">Every hour</option> <option value="wpvivid_2hours">Every 2 hours</option> <option value="wpvivid_4hours">Every 4 hours</option> <option value="wpvivid_8hours">Every 8 hours</option> <option value="wpvivid_12hours">Every 12 hours</option> <option value="wpvivid_daily" selected>Daily</option> <option value="wpvivid_weekly">Weekly</option> <option value="wpvivid_fortnightly">Fortnightly</option> <option value="wpvivid_monthly">30 Days</option> </select> </div> <div style="padding: 4px 10px 0 0; float: left;">at</div> <div id="<?php echo esc_attr($mwp_wpvivid_week); ?>" style="padding: 0 10px 0 0; float: left; display: none;"> <select id="<?php echo esc_attr($mwp_wpvivid_week_select); ?>" option="<?php echo esc_attr($type); ?>" name="week"> <option value="sun" selected>Sunday</option> <option value="mon">Monday</option> <option value="tue">Tuesday</option> <option value="wed">Wednesday</option> <option value="thu">Thursday</option> <option value="fri">Friday</option> <option value="sat">Saturday</option> </select> </div> <div id="<?php echo esc_attr($mwp_wpvivid_day); ?>" style="padding: 0 10px 0 0; float: left; display: none;"> <select id="<?php echo esc_attr($mwp_wpvivid_day_select); ?>" option="<?php echo esc_attr($type); ?>" name="day"> <?php for ($i = 1; $i < 31; $i++) { echo '<option value="' . esc_attr($i) . '">' . esc_html($i) . '</option>'; } ?> </select> </div> <div style="padding: 0 10px 0 0; float: left;"> <select id="<?php echo esc_attr($mwp_wpvivid_hour_select); ?>" option="<?php echo esc_attr($type); ?>" name="current_day_hour" style="margin-bottom: 4px;" onchange="mwp_wpvivid_set_schedule('<?php echo esc_attr($type); ?>');"> <?php for ($hour = 0; $hour < 24; $hour++) { $format_hour = sprintf("%02d", $hour); echo '<option value="' . esc_attr($format_hour) . '">' . esc_html($format_hour) . '</option>'; } ?> </select> <span>:</span> <select id="<?php echo esc_attr($mwp_wpvivid_minute_select); ?>" option="<?php echo esc_attr($type); ?>" name="current_day_minute" style="margin-bottom: 4px;" onchange="mwp_wpvivid_set_schedule('<?php echo esc_attr($type); ?>');"> <?php for ($minute = 0; $minute < 60; $minute++) { $format_minute = sprintf("%02d", $minute); echo '<option value="' . esc_attr($format_minute) . '">' . esc_html($format_minute) . '</option>'; } ?> </select> </div> <div style="clear: both;"></div> </div> </div> <?php } ?> <div class="mwp-wpvivid-one-coloum mwp-wpvivid-workflow mwp-wpvivid-clear-float" style="margin-top:0.5em;"> <div> <p><span class="dashicons dashicons-backup mwp-wpvivid-dashicons-blue"></span><span><strong>Backup Location</strong></span></p> <div style="padding-left:2em;"> <?php if($global) { ?> <label class=""> <input type="radio" option="mwp_update_schedule_backup" name="update_schedule_save_local_remote" value="local" checked="checked" />Backup to localhost </label> <span style="padding: 0 1em;"></span> <label class=""> <input type="radio" option="mwp_update_schedule_backup" name="update_schedule_save_local_remote" value="remote" />Backup to remote storage </label> <span style="padding: 0 0.2em;"></span> <?php } else { ?> <label class=""> <input type="radio" option="mwp_update_schedule_backup" name="update_schedule_save_local_remote" value="local" checked="checked" />Backup to localhost </label> <span style="padding: 0 1em;"></span> <label class=""> <input type="radio" option="mwp_update_schedule_backup" name="update_schedule_save_local_remote" value="remote" />Backup to remote storage </label> <span style="padding: 0 0.2em;"></span> <?php } ?> <?php if(!$global) { ?> <span id="mwp_wpvivid_update_schedule_backup_remote_selector_part" style="display: none;"> <select id="mwp_wpvivid_update_schedule_backup_remote_selector"> <?php $remoteslist=array();//WPvivid_Setting::get_all_remote_options(); foreach ($remoteslist as $key=>$remote_option) { if($key=='remote_selected') { continue; } if(!isset($remote_option['id'])) { $remote_option['id'] = $key; } ?> <option value="<?php echo esc_attr($remote_option['id']); ?>" selected="selected"><?php echo esc_html($remote_option['name']); ?></option> <?php } ?> <option value="all">All activated remote storage</option> </select> </span> <?php } ?> </div> </div> <div style="clear: both;"></div> <p></p> <div> <p><span class="dashicons dashicons-screenoptions mwp-wpvivid-dashicons-blue"></span><span><strong>Backup Content</strong></span></p> <div style="padding:0.5em;margin-bottom:0.5em;background:#eaf1fe;border-radius:8px;"> <?php ?> <fieldset> <?php $this->mwp_wpvivid_schedule_backup_type_addon($type, $global); ?> </fieldset> <?php ?> </div> </div> <p></p> <?php if(!$global) { $prefix = ''; $prefix = apply_filters('mwp_wpvivid_get_backup_prefix', $prefix); ?> <div id="wpvivid_custom_update_schedule_backup" style="display: none;"> <div style="border-left: 4px solid #eaf1fe; border-right: 4px solid #eaf1fe;box-sizing: border-box; padding-left:0.5em;"> <?php $custom_backup_manager = new Mainwp_WPvivid_Custom_Backup_Manager(); $custom_backup_manager->set_site_id($this->site_id); $custom_backup_manager->set_parent_id('wpvivid_custom_update_schedule_backup','schedule_backup','0','0'); $custom_backup_manager->output_custom_backup_db_table(); $custom_backup_manager->output_custom_backup_file_table(); ?> </div> </div> <!--Advanced Option (Exclude)--> <div id="wpvivid_custom_update_schedule_advanced_option"> <?php $custom_backup_manager->wpvivid_set_advanced_id('wpvivid_custom_update_schedule_advanced_option'); $custom_backup_manager->output_advanced_option_table(); $custom_backup_manager->load_js(); ?> </div> <p></p> <div> <p> <span class="dashicons dashicons-welcome-write-blog mwp-wpvivid-dashicons-green" style="margin-top:0.2em;"></span> <span><strong>Comment the backup</strong>(optional): </span><input type="text" option="mwp_update_schedule_backup" name="backup_prefix" id="wpvivid_set_schedule_prefix" value="<?php echo esc_attr($prefix); ?>" onkeyup="value=value.replace(/[^a-zA-Z0-9._]/g,'')" onpaste="value=value.replace(/[^\a-\z\A-\Z0-9]/g,'')" placeholder="<?php echo esc_attr($prefix); ?>"> </p> </div> <?php } else { ?> <div id="wpvivid_global_custom_update_schedule_backup" style="display: none;"> <div style="border-left: 4px solid #eaf1fe; border-right: 4px solid #eaf1fe;box-sizing: border-box; padding-left:0.5em;"> <?php $custom_backup_manager = new Mainwp_WPvivid_Custom_Backup_Manager(); $custom_backup_manager->set_parent_id('wpvivid_global_custom_update_schedule_backup','schedule_backup','0','1'); $custom_backup_manager->output_custom_backup_db_table(); $custom_backup_manager->output_custom_backup_file_table(); ?> </div> </div> <!--Advanced Option (Exclude)--> <div id="wpvivid_global_custom_update_schedule_advanced_option"> <?php $custom_backup_manager->wpvivid_set_advanced_id('wpvivid_global_custom_update_schedule_advanced_option'); $custom_backup_manager->output_advanced_option_table(); $custom_backup_manager->load_js(); ?> </div> <p></p> <div> <p> <span class="dashicons dashicons-welcome-write-blog mwp-wpvivid-dashicons-green" style="margin-top:0.2em;"></span> <span><strong>Comment the backup</strong>(optional): </span><input type="text" option="mwp_update_schedule_backup" name="backup_prefix" id="wpvivid_set_schedule_prefix" value="" onkeyup="value=value.replace(/[^a-zA-Z0-9._]/g,'')" onpaste="value=value.replace(/[^\a-\z\A-\Z0-9]/g,'')" placeholder=""> </p> </div> <?php } ?> </div> <div style="clear: both;"></div> <p></p> <div class="mwp-wpvivid-block-bottom-space"> <div id="mwp_wpvivid_schedule_create_notice"></div> <?php if($type === 'mwp_schedule_add'){ ?> <input class="ui green mini button" type="button" id="mwp_wpvivid_create_schedule_btn" value="Create new schedule" onclick="mwp_wpvivid_create_schedule_addon('<?php echo esc_js($type); ?>', '<?php echo esc_js($global); ?>');" /> <?php } else{ ?> <input class="ui green mini button" type="button" value="Update Schedule" onclick="mwp_wpvivid_edit_schedule_addon('<?php echo esc_js($type); ?>', '<?php echo esc_js($global); ?>');" /> <?php } ?> </div> <script> var first_create = '1'; function mwp_wpvivid_create_schedule_addon(type, global){ var mwp_wpvivid_utc_time = type==='mwp_schedule_add' ? 'mwp_wpvivid_schedule_add_utc_time' : 'mwp_wpvivid_schedule_update_utc_time'; var schedule_data = ''; schedule_data = mwp_wpvivid_ajax_data_transfer('mwp_schedule_add'); schedule_data = JSON.parse(schedule_data); if(global){ var exclude_dirs = mwp_wpvivid_get_global_exclude_json('wpvivid_global_custom_schedule_advanced_option'); } else { var exclude_dirs = mwp_wpvivid_get_exclude_json('wpvivid_custom_schedule_advanced_option'); } var custom_option = { 'exclude_files': exclude_dirs }; jQuery.extend(schedule_data, custom_option); if(global){ var exclude_file_type = mwp_wpvivid_get_exclude_file_type('wpvivid_global_custom_schedule_advanced_option'); } else { var exclude_file_type = mwp_wpvivid_get_exclude_file_type('wpvivid_custom_schedule_advanced_option'); } var exclude_file_type_option = { 'exclude_file_type': exclude_file_type }; jQuery.extend(schedule_data, exclude_file_type_option); schedule_data = JSON.stringify(schedule_data); jQuery('input:radio[option=mwp_schedule_add][name=mwp_schedule_add_backup_type]').each(function () { if (jQuery(this).prop('checked')) { var value = jQuery(this).prop('value'); if (value === 'custom') { schedule_data = JSON.parse(schedule_data); if(global){ var custom_dirs = mwp_wpvivid_get_custom_setting_json_ex('wpvivid_global_custom_schedule_backup'); } else { var custom_dirs = mwp_wpvivid_get_custom_setting_json_ex('wpvivid_custom_schedule_backup'); } var custom_option = { 'custom_dirs': custom_dirs }; jQuery.extend(schedule_data, custom_option); schedule_data = JSON.stringify(schedule_data); } } }); jQuery('input:radio[option=mwp_schedule_backup][name=schedule_save_local_remote]').each(function () { if (jQuery(this).prop('checked')) { schedule_data = JSON.parse(schedule_data); if (this.value === 'remote') { if(global) { var local_remote_option = { 'save_local_remote': this.value }; } else { var remote_id_select = jQuery('#mwp_wpvivid_create_schedule_backup_remote_selector').val(); var local_remote_option = { 'save_local_remote': this.value, 'remote_id_select': remote_id_select }; } } else { var local_remote_option = { 'save_local_remote': this.value }; } jQuery.extend(schedule_data, local_remote_option); schedule_data = JSON.stringify(schedule_data); } }); schedule_data = JSON.parse(schedule_data); var backup_prefix = jQuery('input:text[option=mwp_schedule_backup][name=backup_prefix]').val(); var backup_prefix_option = { 'backup_prefix': backup_prefix }; jQuery.extend(schedule_data, backup_prefix_option); schedule_data = JSON.stringify(schedule_data); if(global){ schedule_data = JSON.parse(schedule_data); schedule_data['save_local_remote'] = schedule_data['save_local_remote']; schedule_data['schedule_backup_backup_type'] = schedule_data['mwp_schedule_add_backup_type']; schedule_data['status'] = 'Active'; schedule_data = JSON.stringify(schedule_data); var schedule_mould_name = jQuery('#mwp_wpvivid_schedule_mould_name').val(); if(schedule_mould_name == ''){ alert('A schedule mould name is required.'); return; } var ajax_data = { 'action': 'mwp_wpvivid_global_create_schedule_addon', 'schedule': schedule_data, 'schedule_mould_name': schedule_mould_name, 'first_create': first_create }; } else { //var utc_time = jQuery('#'+mwp_wpvivid_utc_time).html(); //var arr = new Array(); //arr = utc_time.split(':'); schedule_data = JSON.parse(schedule_data); schedule_data['save_local_remote'] = schedule_data['save_local_remote']; schedule_data['schedule_backup_backup_type'] = schedule_data['mwp_schedule_add_backup_type']; //schedule_data['current_day_hour'] = arr[0]; //schedule_data['current_day_minute'] = arr[1]; schedule_data['status'] = 'Active'; schedule_data = JSON.stringify(schedule_data); var ajax_data = { 'action': 'mwp_wpvivid_create_schedule_addon', 'schedule': schedule_data, 'site_id': '<?php echo esc_html($this->site_id); ?>' }; } jQuery('#mwp_wpvivid_schedule_create_notice').html(''); mwp_wpvivid_post_request(ajax_data, function (data) { try { var jsonarray = jQuery.parseJSON(data); if (jsonarray.result === 'success') { if(global) { first_create = '0'; jQuery('#mwp_wpvivid_schedule_create_notice').html(jsonarray.notice); jQuery('#mwp_wpvivid_global_schedule_list_addon').html(jsonarray.html); } else{ jQuery('#mwp_wpvivid_schedule_create_notice').html(jsonarray.notice); jQuery('#mwp_wpvivid_schedule_list_addon').html(jsonarray.html); jQuery('#mwp_wpvivid_schedule_backup_deploy').hide(); } } else { jQuery('#mwp_wpvivid_schedule_create_notice').html(jsonarray.notice); } } catch (err) { alert(err); } }, function (XMLHttpRequest, textStatus, errorThrown) { var error_message = mwp_wpvivid_output_ajaxerror('changing base settings', textStatus, errorThrown); alert(error_message); }); } function mwp_wpvivid_edit_schedule_addon(type, global){ var mwp_wpvivid_utc_time = type==='mwp_schedule_add' ? 'mwp_wpvivid_schedule_add_utc_time' : 'mwp_wpvivid_schedule_update_utc_time'; var schedule_data = ''; schedule_data = mwp_wpvivid_ajax_data_transfer('mwp_schedule_update'); schedule_data = JSON.parse(schedule_data); if(global){ var exclude_dirs = mwp_wpvivid_get_global_exclude_json('wpvivid_global_custom_update_schedule_advanced_option'); } else { var exclude_dirs = mwp_wpvivid_get_exclude_json('wpvivid_custom_update_schedule_advanced_option'); } var custom_option = { 'exclude_files': exclude_dirs }; jQuery.extend(schedule_data, custom_option); if(global){ var exclude_file_type = mwp_wpvivid_get_exclude_file_type('wpvivid_global_custom_update_schedule_advanced_option'); } else { var exclude_file_type = mwp_wpvivid_get_exclude_file_type('wpvivid_custom_update_schedule_advanced_option'); } var exclude_file_type_option = { 'exclude_file_type': exclude_file_type }; jQuery.extend(schedule_data, exclude_file_type_option); schedule_data = JSON.stringify(schedule_data); jQuery('input:radio[option=mwp_schedule_update][name=mwp_schedule_update_backup_type]').each(function () { if (jQuery(this).prop('checked')) { var value = jQuery(this).prop('value'); if (value === 'custom') { schedule_data = JSON.parse(schedule_data); if(global){ var custom_dirs = mwp_wpvivid_get_custom_setting_json_ex('wpvivid_global_custom_update_schedule_backup'); } else { var custom_dirs = mwp_wpvivid_get_custom_setting_json_ex('wpvivid_custom_update_schedule_backup'); } var custom_option = { 'custom_dirs': custom_dirs }; jQuery.extend(schedule_data, custom_option); schedule_data = JSON.stringify(schedule_data); } } }); jQuery('input:radio[option=mwp_update_schedule_backup][name=update_schedule_save_local_remote]').each(function () { if (jQuery(this).prop('checked')) { schedule_data = JSON.parse(schedule_data); if (this.value === 'remote') { var remote_id_select = jQuery('#mwp_wpvivid_update_schedule_backup_remote_selector').val(); var local_remote_option = { 'save_local_remote': this.value, 'remote_id_select': remote_id_select }; } else { var local_remote_option = { 'save_local_remote': this.value }; } jQuery.extend(schedule_data, local_remote_option); schedule_data = JSON.stringify(schedule_data); } }); schedule_data = JSON.parse(schedule_data); var backup_prefix = jQuery('input:text[option=mwp_update_schedule_backup][name=backup_prefix]').val(); var backup_prefix_option = { 'backup_prefix': backup_prefix }; jQuery.extend(schedule_data, backup_prefix_option); schedule_data = JSON.stringify(schedule_data); if(global){ var schedule_mould_name = mwp_wpvivid_global_edit_schedule_mould_name; schedule_data = JSON.parse(schedule_data); schedule_data['update_schedule_backup_save_local_remote'] = schedule_data['mwp_schedule_update_save_local_remote']; schedule_data['update_schedule_backup_backup_type'] = schedule_data['mwp_schedule_update_backup_type']; schedule_data['status'] = 'Active'; schedule_data['schedule_id'] = mwp_wpvivid_global_edit_schedule_id; schedule_data = JSON.stringify(schedule_data); var ajax_data = { 'action': 'mwp_wpvivid_global_update_schedule_addon', 'schedule': schedule_data, 'mould_name': schedule_mould_name }; } else { //var utc_time = jQuery('#'+mwp_wpvivid_utc_time).html(); //var arr = new Array(); //arr = utc_time.split(':'); schedule_data = JSON.parse(schedule_data); schedule_data['update_schedule_backup_save_local_remote'] = schedule_data['mwp_schedule_update_save_local_remote']; schedule_data['update_schedule_backup_backup_type'] = schedule_data['mwp_schedule_update_backup_type']; //schedule_data['current_day_hour'] = arr[0]; //schedule_data['current_day_minute'] = arr[1]; schedule_data['status'] = 'Active'; schedule_data['schedule_id'] = mwp_wpvivid_edit_schedule_id; schedule_data = JSON.stringify(schedule_data); var ajax_data = { 'action': 'mwp_wpvivid_update_schedule_addon', 'schedule': schedule_data, 'site_id': '<?php echo esc_html($this->site_id); ?>' }; } jQuery('#mwp_wpvivid_schedule_update_notice').html(''); mwp_wpvivid_post_request(ajax_data, function (data) { try { var jsonarray = jQuery.parseJSON(data); if (jsonarray.result === 'success') { if(global) { jQuery('#mwp_wpvivid_schedule_update_notice').html(jsonarray.notice); jQuery('#mwp_wpvivid_global_schedule_list_addon').html(jsonarray.html); jQuery( document ).trigger( '<?php echo esc_js($this->main_tab->container_id); ?>-delete',[ 'schedules_edit', 'schedules' ]); } else{ jQuery('#mwp_wpvivid_schedule_update_notice').html(jsonarray.notice); jQuery('#mwp_wpvivid_schedule_list_addon').html(jsonarray.html); jQuery( document ).trigger( '<?php echo esc_js($this->main_tab->container_id); ?>-delete',[ 'schedules_edit', 'schedules' ]); } } else { jQuery('#mwp_wpvivid_schedule_update_notice').html(jsonarray.notice); } } catch (err) { alert(err); } }, function (XMLHttpRequest, textStatus, errorThrown) { var error_message = mwp_wpvivid_output_ajaxerror('changing base settings', textStatus, errorThrown); alert(error_message); }); } var time_offset=<?php echo esc_js($offset); ?>; function mwp_wpvivid_set_schedule(type){ var mwp_wpvivid_week_id = type === 'mwp_schedule_add' ? 'mwp_wpvivid_schedule_add_week' : 'mwp_wpvivid_schedule_update_week'; var mwp_wpvivid_day_id = type === 'mwp_schedule_add' ? 'mwp_wpvivid_schedule_add_day' : 'mwp_wpvivid_schedule_update_day'; var mwp_wpvivid_cycles_select = type === 'mwp_schedule_add' ? 'mwp_wpvivid_schedule_add_cycles_select' : 'mwp_wpvivid_schedule_update_cycles_select'; var mwp_wpvivid_utc_time = type==='mwp_schedule_add' ? 'mwp_wpvivid_schedule_add_utc_time' : 'mwp_wpvivid_schedule_update_utc_time'; var mwp_wpvivid_start_local_time = type==='mwp_schedule_add' ? 'mwp_wpvivid_schedule_add_start_local_time' : 'mwp_wpvivid_schedule_update_start_local_time'; var mwp_wpvivid_start_utc_time = type==='mwp_schedule_add' ? 'mwp_wpvivid_schedule_add_start_utc_time' : 'mwp_wpvivid_schedule_update_start_utc_time'; var mwp_wpvivid_start_cycles = type==='mwp_schedule_add' ? 'mwp_wpvivid_schedule_add_start_cycles' : 'mwp_wpvivid_schedule_update_start_cycles'; jQuery('#'+mwp_wpvivid_week_id).hide(); jQuery('#'+mwp_wpvivid_day_id).hide(); var cycles_value = jQuery('#'+mwp_wpvivid_cycles_select).val(); if(cycles_value === 'wpvivid_weekly' || cycles_value === 'wpvivid_fortnightly') { jQuery('#'+mwp_wpvivid_week_id).show(); } else if(cycles_value === 'wpvivid_monthly'){ jQuery('#'+mwp_wpvivid_day_id).show(); } var cycles_display = jQuery('#'+mwp_wpvivid_cycles_select+' option:checked').text(); jQuery('#'+mwp_wpvivid_start_cycles).html(cycles_display); var hour='00'; var minute='00'; jQuery('select[option='+type+'][name=current_day_hour]').each(function() { hour=jQuery(this).val(); }); jQuery('select[option='+type+'][name=current_day_minute]').each(function(){ minute=jQuery(this).val(); }); var time=hour+":"+minute; jQuery('#'+mwp_wpvivid_start_local_time).html(time); hour=Number(hour)-Number(time_offset); var Hours=Math.floor(hour); var Minutes=Math.floor(60*(hour-Hours)); Minutes=Number(minute)+Minutes; if(Minutes>=60) { Hours=Hours+1; Minutes=Minutes-60; } if(Hours>=24) { Hours=Hours-24; } else if(Hours<0) { Hours=24-Math.abs(Hours); } if(Hours<10) { Hours='0'+Hours; } if(Minutes<10) { Minutes='0'+Minutes; } time=Hours+":"+Minutes; jQuery('#'+mwp_wpvivid_utc_time).html(time); jQuery('#'+mwp_wpvivid_start_utc_time).html(time); } jQuery('input:radio[option=<?php echo esc_attr($type); ?>][name=mwp_schedule_update_backup_type]').click(function() { if(this.value === 'custom') { jQuery('#wpvivid_custom_update_schedule_backup').show(); jQuery('#wpvivid_global_custom_update_schedule_backup').show(); //jQuery( document ).trigger( 'wpvivid_refresh_schedule_backup_tables', 'schedule_backup' ); } else { jQuery('#wpvivid_custom_update_schedule_backup').hide(); jQuery('#wpvivid_global_custom_update_schedule_backup').hide(); } }); jQuery('input:radio[option=mwp_schedule_backup][name=schedule_save_local_remote]').click(function(){ var value = jQuery(this).prop('value'); if(value === 'remote'){ if(!mwp_wpvivid_has_remote){ alert('There is no default remote storage configured. Please set it up first.'); jQuery('input:radio[option=mwp_schedule_backup][name=schedule_save_local_remote][value=local]').prop('checked', true); } else{ jQuery('#mwp_wpvivid_create_schedule_backup_remote_selector_part').show(); } } else { jQuery('#mwp_wpvivid_create_schedule_backup_remote_selector_part').hide(); } }); jQuery('input:radio[option=mwp_update_schedule_backup][name=update_schedule_save_local_remote]').click(function(){ var value = jQuery(this).prop('value'); if(value === 'remote'){ if(!mwp_wpvivid_has_remote){ alert('There is no default remote storage configured. Please set it up first.'); jQuery('input:radio[option=mwp_update_schedule_backup][name=update_schedule_save_local_remote][value=local]').prop('checked', true); } else{ jQuery('#mwp_wpvivid_update_schedule_backup_remote_selector_part').show(); } } else { jQuery('#mwp_wpvivid_update_schedule_backup_remote_selector_part').hide(); } }); jQuery(document).ready(function () { mwp_wpvivid_set_schedule('mwp_schedule_add'); }); </script> </div> <?php } public function mwp_wpvivid_schedule_page($global){ ?> <table class="widefat"> <tbody> <?php add_action('mwp_wpvivid_schedule_do_js',array( $this, 'mwp_wpvivid_schedule_do_js' ),10); $this->mwp_wpvivid_schedule_settings(); ?> <tfoot> <tr> <?php if($global===false) { $save_change_id= 'mwp_wpvivid_schedule_save'; } else { $save_change_id= 'mwp_wpvivid_global_schedule_save'; } ?> <th class="row-title"><input class="ui green mini button" id="<?php echo esc_attr($save_change_id); ?>" type="button" value="Save Changes" /></th> <th></th> </tr> </tfoot> </tbody> </table> <script> function mwp_wpvivid_global_schedule_save() { var setting_data = mwp_wpvivid_ajax_data_transfer('mwp-schedule'); var ajax_data = { 'action': 'mwp_wpvivid_set_global_schedule', 'schedule': setting_data, }; jQuery('#mwp_wpvivid_global_schedule_save').css({'pointer-events': 'none', 'opacity': '0.4'}); mwp_wpvivid_post_request(ajax_data, function (data) { try { var jsonarray = jQuery.parseJSON(data); jQuery('#mwp_wpvivid_global_schedule_save').css({'pointer-events': 'auto', 'opacity': '1'}); if (jsonarray.result === 'success') { window.location.href = window.location.href + "&synchronize=1&addon=0"; } else { alert(jsonarray.error); } } catch (err) { alert(err); jQuery('#mwp_wpvivid_global_schedule_save').css({'pointer-events': 'auto', 'opacity': '1'}); } }, function (XMLHttpRequest, textStatus, errorThrown) { jQuery('#mwp_wpvivid_global_schedule_save').css({'pointer-events': 'auto', 'opacity': '1'}); var error_message = mwp_wpvivid_output_ajaxerror('changing base settings', textStatus, errorThrown); alert(error_message); }); } function mwp_wpvivid_schedule_save() { var setting_data = mwp_wpvivid_ajax_data_transfer('mwp-schedule'); var ajax_data = { 'action': 'mwp_wpvivid_set_schedule', 'schedule': setting_data, 'site_id': '<?php echo esc_html($this->site_id); ?>' }; jQuery('#mwp_wpvivid_schedule_save').css({'pointer-events': 'none', 'opacity': '0.4'}); mwp_wpvivid_post_request(ajax_data, function (data) { try { var jsonarray = jQuery.parseJSON(data); jQuery('#mwp_wpvivid_schedule_save').css({'pointer-events': 'auto', 'opacity': '1'}); if (jsonarray.result === 'success') { location.reload(); } else { alert(jsonarray.error); } } catch (err) { alert(err); jQuery('#mwp_wpvivid_schedule_save').css({'pointer-events': 'auto', 'opacity': '1'}); } }, function (XMLHttpRequest, textStatus, errorThrown) { jQuery('#mwp_wpvivid_schedule_save').css({'pointer-events': 'auto', 'opacity': '1'}); var error_message = mwp_wpvivid_output_ajaxerror('changing base settings', textStatus, errorThrown); alert(error_message); }); } jQuery('#mwp_wpvivid_global_schedule_save').click(function(){ mwp_wpvivid_global_schedule_save(); }); jQuery('#mwp_wpvivid_schedule_save').click(function(){ mwp_wpvivid_schedule_save(); }); </script> <?php } public function mwp_wpvivid_schedule_backup_type_addon($type, $global){ if(!$global){ ?> <label style="padding-right:2em;"> <input type="radio" option="<?php echo esc_attr($type); ?>" name="<?php echo esc_attr($type); ?>_backup_type" value="files+db" checked /> <span>Wordpress Files + Database</span> </label> <label style="padding-right:2em;"> <input type="radio" option="<?php echo esc_attr($type); ?>" name="<?php echo esc_attr($type); ?>_backup_type" value="db" /> <span>Database</span> </label> <label style="padding-right:2em;"> <input type="radio" option="<?php echo esc_attr($type); ?>" name="<?php echo esc_attr($type); ?>_backup_type" value="files" /> <span>Wordpress Files</span> </label> <label style="padding-right:2em;"> <input type="radio" option="<?php echo esc_attr($type); ?>" name="<?php echo esc_attr($type); ?>_backup_type" value="custom" /> <span>Custom content</span> </label> <?php } else{ ?> <label style="padding-right:2em;"> <input type="radio" option="<?php echo esc_attr($type); ?>" name="<?php echo esc_attr($type); ?>_backup_type" value="files+db" checked /> <span>Wordpress Files + Database</span> </label> <label style="padding-right:2em;"> <input type="radio" option="<?php echo esc_attr($type); ?>" name="<?php echo esc_attr($type); ?>_backup_type" value="db" /> <span>Database</span> </label> <label style="padding-right:2em;"> <input type="radio" option="<?php echo esc_attr($type); ?>" name="<?php echo esc_attr($type); ?>_backup_type" value="files" /> <span>Wordpress Files</span> </label> <label style="padding-right:2em;"> <input type="radio" option="<?php echo esc_attr($type); ?>" name="<?php echo esc_attr($type); ?>_backup_type" value="custom" /> <span>Custom content</span> </label> <?php } } public function mwp_wpvivid_schedule_local_remote_addon($html, $type){ $html .= ' <div class="mwp-wpvivid-block-bottom-space"> <label> <input type="radio" option="'.$type.'" name="'.$type.'_save_local_remote" value="local" checked /> <span>Save backups on localhost (web server)</span> </label> </div> <div> <label> <input type="radio" option="'.$type.'" name="'.$type.'_save_local_remote" value="remote" /> <span>Send backups to remote storage (Backups will be deleted from localhost after they are completely uploaded to remote storage)</span> </label> </div> <input type="checkbox" option="'.$type.'" name="lock" value="0" style="display: none;" />'; return $html; } public function mwp_wpvivid_schedule_settings() { ?> <tr> <td class="row-title tablelistcolumn"><label for="tablecell">Schedule Settings</label></td> <td class="tablelistcolumn"> <div> <div class="postbox mwp-wpvivid-schedule-block" style="margin-bottom: 10px;"> <div class="mwp-wpvivid-block-bottom-space"> <label for="mwp_wpvivid_schedule_enable"> <input option="mwp-schedule" name="mwp_enable" type="checkbox" id="mwp_wpvivid_schedule_enable" /> <span>Enable backup schedule</span> </label><br> </div> <div class="mwp-wpvivid-block-bottom-space"> <?php $this->mwp_wpvivid_schedule_notice(); ?> </div> </div> <div class="postbox mwp-wpvivid-schedule-block" style="margin-bottom: 10px;"> <div class="mwp-wpvivid-block-bottom-space"> <label> <input type="radio" option="mwp-schedule" name="mwp_recurrence" value="wpvivid_12hours" /> <span>12Hours</span> </label> </div> <div class="mwp-wpvivid-block-bottom-space"> <label> <input type="radio" option="mwp-schedule" name="mwp_recurrence" value="wpvivid_daily" /> <span>Daily</span> </label> </div> <div class="mwp-wpvivid-block-bottom-space"> <label> <input type="radio" option="mwp-schedule" name="mwp_recurrence" value="wpvivid_weekly" /> <span>Weekly</span> </label> </div> <div class="mwp-wpvivid-block-bottom-space"> <label> <input type="radio" option="mwp-schedule" name="mwp_recurrence" value="wpvivid_fortnightly" /> <span>Fortnightly</span> </label> </div> <div class="mwp-wpvivid-block-bottom-space"> <label> <input type="radio" option="mwp-schedule" name="mwp_recurrence" value="wpvivid_monthly" /> <span>Monthly</span> </label> </div> </div> <div class="postbox mwp-wpvivid-schedule-block" id="mwp_wpvivid_schedule_backup_type" style="margin-bottom: 10px;"> <?php $this->mwp_wpvivid_schedule_backup_type(); ?> </div> <div class="postbox mwp-wpvivid-schedule-block" id="mwp_wpvivid_schedule_remote_storage" style="margin-bottom: 10px;"> <?php $this->mwp_wpvivid_schedule_local_remote(); ?> </div> </div> </td> </tr> <script> <?php do_action('mwp_wpvivid_schedule_do_js'); ?> </script> <?php } public function mwp_wpvivid_schedule_backup_type() { ?> <div class="mwp-wpvivid-block-bottom-space"> <label> <input type="radio" option="mwp-schedule" name="mwp_backup_type" value="files+db"/> <span>Database + Files (Entire website)</span> </label> </div> <div class="mwp-wpvivid-block-bottom-space"> <label> <input type="radio" option="mwp-schedule" name="mwp_backup_type" value="files"/> <span>All Files (Exclude Database)</span> </label> </div> <div class="mwp-wpvivid-block-bottom-space"> <label> <input type="radio" option="mwp-schedule" name="mwp_backup_type" value="db"/> <span>Only Database</span> </label> </div> <?php } public function mwp_wpvivid_schedule_notice() { ?> <div class="mwp-wpvivid-block-bottom-space">1) Scheduled job will start at web server time: </div> <div class="mwp-wpvivid-block-bottom-space">2) Being subjected to mechanisms of PHP, a scheduled backup task for your site will be triggered only when the site receives at least a visit at any page.</div> <?php } public function mwp_wpvivid_schedule_local_remote() { $html = ''; $schedule=$this->setting; $backup_local = 'checked'; $backup_remote = ''; if(isset($schedule['enable'])) { if ($schedule['enable'] == true) { if ($schedule['backup']['remote'] === 1) { $backup_local = ''; $backup_remote = 'checked'; } else { $backup_local = 'checked'; $backup_remote = ''; } } } ?> <div class="mwp-wpvivid-block-bottom-space"> <label> <input type="radio" option="mwp-schedule" name="mwp_save_local_remote" value="local" <?php echo esc_attr($backup_local); ?> /> <span>Save backups on localhost of child-site (web server)</span> </label> </div> <div class="mwp-wpvivid-block-bottom-space"> <label> <input type="radio" option="mwp-schedule" name="mwp_save_local_remote" value="remote" <?php echo esc_attr($backup_remote); ?> /> <span>Send backups to remote storage (choose this option, the local backup will be deleted after uploading to remote storage completely)</span> </label> </div> <div class="mwp-wpvivid-block-bottom-space" id="mwp_wpvivid_schedule_upload_storage" style="cursor:pointer;" title="Highlighted icon illuminates that you have choosed a remote storage to store backups"></div> <label style="display: none;"> <input type="checkbox" option="mwp-schedule" name="mwp_lock" value="0" /> </label> <?php } public function mwp_wpvivid_schedule_do_js() { $schedule=$this->setting; if(isset($schedule['enable'])) { if ($schedule['enable'] == true) { ?> jQuery("#mwp_wpvivid_schedule_enable").prop('checked', true); <?php if ($schedule['backup']['remote'] === 1) { $schedule_remote = 'remote'; } else { $schedule_remote = 'local'; } } else { $schedule['type'] = 'wpvivid_daily'; $schedule['backup']['backup_files'] = 'files+db'; $schedule_remote = 'local'; } } else{ $schedule = array(); $schedule['type'] = 'wpvivid_daily'; $schedule['backup']['backup_files'] = 'files+db'; $schedule_remote = 'local'; } ?> jQuery("input:radio[value='<?php echo esc_attr($schedule['type']); ?>']").prop('checked', true); jQuery("input:radio[value='<?php echo esc_attr($schedule['backup']['backup_files']); ?>']").prop('checked', true); jQuery("input:radio[name='mwp_save_local_remote'][value='remote']").click(function(){ if(!mwp_wpvivid_has_remote){ alert('There is no default remote storage configured. Please set it up first.'); jQuery('input:radio[name=mwp_save_local_remote][value=local]').prop('checked', true); } }); <?php } public function mwp_wpvivid_synchronize_setting($check_addon, $mould_name = '', $is_incremental = 0) { global $mainwp_wpvivid_extension_activator; if(intval($check_addon) === 1) { if (intval($is_incremental) === 1) { $submit_id = 'mwp_wpvivid_sync_incremental_schedule'; } else { $submit_id = 'mwp_wpvivid_sync_schedule'; } } else{ $submit_id = 'mwp_wpvivid_sync_schedule'; } $mainwp_wpvivid_extension_activator->render_sync_websites_page($submit_id, $check_addon, $mould_name); ?> <script> var sync_btn_id = '<?php echo esc_js($submit_id); ?>'; jQuery('#'+sync_btn_id).click(function(){ mwp_wpvivid_sync_schedule(); }); function mwp_wpvivid_sync_schedule() { var website_ids= []; mwp_wpvivid_sync_index=0; jQuery('.mwp-wpvivid-sync-row').each(function() { jQuery(this).children('td:first').each(function(){ if (jQuery(this).children().children().prop('checked')) { var id = jQuery(this).attr('website-id'); website_ids.push(id); } }); }); if(website_ids.length>0) { jQuery('#'+sync_btn_id).css({'pointer-events': 'none', 'opacity': '0.4'}); var check_addon = '<?php echo esc_js($check_addon); ?>'; if(check_addon){ var schedule_mould_name = jQuery('.mwp_wpvivid_schedule_mould_name').html(); mwp_wpvivid_sync_schedule_mould(website_ids, schedule_mould_name, check_addon, sync_btn_id, 'Extensions-Wpvivid-Backup-Mainwp&tab=schedules', 'mwp_wpvivid_scheduled_tab'); } else { mwp_wpvivid_sync_site(website_ids, check_addon, sync_btn_id, 'Extensions-Wpvivid-Backup-Mainwp&tab=schedules', 'mwp_wpvivid_scheduled_tab'); } } } </script> <?php } public function get_websites_row($websites) { foreach ( $websites as $website ) { $website_id = $website['id']; if(!$website['active']) { continue; } ?> <tr class="mwp-wpvivid-sync-row""> <th class="check-column" website-id="<?php echo esc_attr($website_id); ?>"> <input type="checkbox" name="checked[]" > </th> <td> <a href="admin.php?page=managesites&dashboard=<?php echo esc_url($website_id); ?>"><?php echo esc_html(stripslashes($website['name'])); ?></a><br/> </td> <td> <a href="<?php echo esc_url($website['url']); ?>" target="_blank"><?php echo esc_html($website['url']); ?></a><br/> </td> <td class="mwp-wpvivid-progress" website-id="<?php echo esc_attr($website_id); ?>"> <span>Ready to update</span> </td> </tr> <?php } } } admin/wpvivid-backup-mainwp-white-label.php 0000644 00000056572 15133715745 0015016 0 ustar 00 <?php class Mainwp_WPvivid_Extension_White_Label { private $white_label_addon; private $site_id; public function __construct() { $this->load_white_label_ajax(); } public function set_site_id($site_id) { $this->site_id=$site_id; } public function set_white_label_info($white_label_addon = array()) { $this->white_label_addon=$white_label_addon; } public function load_white_label_ajax() { add_action('wp_ajax_mwp_wpvivid_sync_white_label', array($this, 'sync_white_label')); add_action('wp_ajax_mwp_wpvivid_global_set_white_label_setting', array($this, 'global_set_white_label_setting')); add_action('wp_ajax_mwp_wpvivid_set_white_label_setting', array($this, 'set_white_label_setting')); } public function sync_white_label() { global $mainwp_wpvivid_extension_activator; $mainwp_wpvivid_extension_activator->mwp_ajax_check_security(); try{ if(isset($_POST['id']) && !empty($_POST['id']) && is_string($_POST['id'])) { $site_id = sanitize_key($_POST['id']); $white_label = Mainwp_WPvivid_Extension_DB_Option::get_instance()->wpvivid_get_global_option('white_label_setting', array()); if(empty($white_label)){ $white_label = array(); } Mainwp_WPvivid_Extension_DB_Option::get_instance()->wpvivid_update_option($site_id, 'white_label_setting', $white_label); $post_data['mwp_action'] = 'wpvivid_set_white_label_setting_addon_mainwp'; $post_data['setting'] = wp_json_encode($white_label); $information = apply_filters('mainwp_fetchurlauthed', $mainwp_wpvivid_extension_activator->childFile, $mainwp_wpvivid_extension_activator->childKey, $site_id, 'wpvivid_backuprestore', $post_data); if (isset($information['error'])) { $ret['result'] = 'failed'; $ret['error'] = $information['error']; } else { $ret['result'] = 'success'; } echo wp_json_encode($ret); } } 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().';'; error_log($message); echo wp_json_encode(array('result'=>'failed','error'=>$message)); } die(); } public function global_set_white_label_setting() { global $mainwp_wpvivid_extension_activator; $mainwp_wpvivid_extension_activator->mwp_ajax_check_security(); try{ if(isset($_POST['setting']) && !empty($_POST['setting']) && is_string($_POST['setting'])) { $json_setting = stripslashes(sanitize_text_field($_POST['setting'])); $setting = json_decode($json_setting, true); if (is_null($setting)) { echo 'json decode failed'; die(); } $ret = $mainwp_wpvivid_extension_activator->mwp_check_white_label_option($setting); if($ret['result']!='success') { echo wp_json_encode($ret); die(); } Mainwp_WPvivid_Extension_DB_Option::get_instance()->wpvivid_update_global_option('white_label_setting', $setting); $ret['result'] = 'success'; echo wp_json_encode($ret); } } 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().';'; error_log($message); echo wp_json_encode(array('result'=>'failed','error'=>$message)); } die(); } public function set_white_label_setting() { global $mainwp_wpvivid_extension_activator; $mainwp_wpvivid_extension_activator->mwp_ajax_check_security(); try{ if(isset($_POST['site_id']) && !empty($_POST['site_id']) && is_string($_POST['site_id']) && isset($_POST['setting']) && !empty($_POST['setting']) && is_string($_POST['setting'])) { $site_id = sanitize_key($_POST['site_id']); $json_setting = stripslashes(sanitize_text_field($_POST['setting'])); $setting = json_decode($json_setting, true); if (is_null($setting)) { echo 'json decode failed'; die(); } $ret = $mainwp_wpvivid_extension_activator->mwp_check_white_label_option($setting); if($ret['result']!='success') { echo wp_json_encode($ret); die(); } Mainwp_WPvivid_Extension_DB_Option::get_instance()->wpvivid_update_option($site_id, 'white_label_setting', $setting); $post_data['mwp_action'] = 'wpvivid_set_white_label_setting_addon_mainwp'; $post_data['setting'] = wp_json_encode($setting); $information = apply_filters('mainwp_fetchurlauthed', $mainwp_wpvivid_extension_activator->childFile, $mainwp_wpvivid_extension_activator->childKey, $site_id, 'wpvivid_backuprestore', $post_data); if (isset($information['error'])) { $ret['result'] = 'failed'; $ret['error'] = $information['error']; } else { $ret['result'] = 'success'; } echo wp_json_encode($ret); } } 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().';'; error_log($message); echo wp_json_encode(array('result'=>'failed','error'=>$message)); } die(); } public function render($check_pro, $global=false) { if(isset($_GET['synchronize']) && isset($_GET['addon'])) { $check_addon = sanitize_text_field($_GET['addon']); $this->mwp_wpvivid_synchronize_white_label($check_addon); } else{ $white_label_setting = $this->white_label_addon; $white_label_display = empty($white_label_setting['white_label_display']) ? 'WPvivid Backup' : $white_label_setting['white_label_display']; $white_label_slug = empty($white_label_setting['white_label_slug']) ? 'WPvivid' : $white_label_setting['white_label_slug']; $white_label_support_email = empty($white_label_setting['white_label_support_email']) ? 'pro.support@wpvivid.com' : $white_label_setting['white_label_support_email']; $white_label_website_protocol = empty($white_label_setting['white_label_website_protocol']) ? 'https' : $white_label_setting['white_label_website_protocol']; $white_label_website = empty($white_label_setting['white_label_website']) ? 'wpvivid.com' : $white_label_setting['white_label_website']; $white_label_author = empty($white_label_setting['white_label_author']) ? 'wpvivid.com' : $white_label_setting['white_label_author']; $wpvivid_access_white_label_slug= empty($white_label_setting['access_white_label_page_slug']) ? 'wpvivid_white_label' : $white_label_setting['access_white_label_page_slug']; $show_sidebar= empty($white_label_setting['show_sidebar']) ? 'show' : $white_label_setting['show_sidebar']; if($show_sidebar=='show') { $show_sidebar_link='checked'; $hide_sidebar_link=''; } else { $show_sidebar_link=''; $hide_sidebar_link='checked'; } $show_submit_ticket=empty($white_label_setting['show_submit_ticket']) ? 'show' : $white_label_setting['show_submit_ticket']; if($show_submit_ticket=='show') { $show_submit_ticket_link='checked'; $hide_submit_ticket_link=''; } else { $show_submit_ticket_link=''; $hide_submit_ticket_link='checked'; } ?> <div style="margin: 10px;"> <div class="mwp-wpvivid-welcome-bar mwp-wpvivid-clear-float"> <div class="mwp-wpvivid-welcome-bar-left"> <p><span class="dashicons dashicons-admin-generic mwp-wpvivid-dashicons-large mwp-wpvivid-dashicons-blue"></span><span class="mwp-wpvivid-page-title">White Label</span></p> <span class="about-description">This tab allows you to configure WPvivid Backup Pro white label settings.</span> </div> <div class="mwp-wpvivid-welcome-bar-right"></div> <div class="mwp-wpvivid-nav-bar mwp-wpvivid-clear-float"> <span class="dashicons dashicons-lightbulb wpvivid-dashicons-orange"></span> <span> To restore backups of a white-labeled website, the current website needs to be white labeled with the same brand name.</span> </div> </div> <div class="postbox"> <div class="mwp-wpvivid-setting-block mwp-wpvivid-block-bottom-space"> <div class="mwp-wpvivid-block-bottom-space"><strong><?php esc_html_e('Plugin Name', 'wpvivid'); ?></strong></div> <div class="mwp-wpvivid-block-bottom-space"> <input type="text" placeholder="WPvivid" option="mwp_white_label_setting" name="white_label_display" class="all-options" value="<?php echo esc_attr($white_label_display); ?>" onkeyup="value=value.replace(/[^a-zA-Z0-9_ ]/g,'')" onpaste="value=value.replace(/[^\a-\z\A-\Z0-9]/g,'')" /> </div> <div class="mwp-wpvivid-block-bottom-space"><?php /* translators: %s: Plugin name. */ echo sprintf(esc_html('Enter your preferred plugin name to replace %s on the plugin UI and WP dashboard.', 'wpvivid'), esc_html($white_label_display)); ?></div> <div class="mwp-wpvivid-block-bottom-space"><strong><?php esc_html_e('Slug', 'wpvivid'); ?></strong></div> <div class="mwp-wpvivid-block-bottom-space"> <input type="text" placeholder="WPvivid" option="mwp_white_label_setting" name="white_label_slug" class="all-options" value="<?php echo esc_attr($white_label_slug); ?>" onkeyup="value=value.replace(/[^a-zA-Z0-9]/g,'')" onpaste="value=value.replace(/[^\a-\z\A-\Z0-9]/g,'')" /> </div> <div class="mwp-wpvivid-block-bottom-space"><?php /* translators: %s: Plugin slug. */ echo sprintf(esc_html('Enter your preferred slug to replace %s in all slugs, default storage directory paths, backup file names, default staging database names and table prefixes.', 'wpvivid'), esc_html($white_label_slug)); ?></div> <div class="mwp-wpvivid-block-bottom-space"><strong><?php esc_html_e('Support Email', 'wpvivid'); ?></strong></div> <div class="mwp-wpvivid-block-bottom-space"> <input type="text" placeholder="pro.support@wpvivid.com" option="mwp_white_label_setting" name="white_label_support_email" class="all-options" value="<?php echo esc_attr($white_label_support_email); ?>" /> </div> <div class="mwp-wpvivid-block-bottom-space"><?php /* translators: %s: Email. */ echo sprintf(esc_html('Enter your support email to replace %s in the plugin\'s Debug tab.', 'wpvivid'), esc_html($white_label_support_email)); ?></div> <div class="mwp-wpvivid-block-bottom-space"><strong><?php esc_html_e('Author', 'wpvivid'); ?></strong></div> <div class="mwp-wpvivid-block-bottom-space"> <input type="text" placeholder="wpvivid.com" option="mwp_white_label_setting" name="white_label_author" class="all-options" value="<?php echo esc_attr($white_label_author); ?>" /> </div> <div class="mwp-wpvivid-block-bottom-space"><?php /* translators: %s: Author. */ echo sprintf(esc_html('Enter your preferred author name of the plugin to replace %s.', 'wpvivid'), esc_html($white_label_author)); ?></div> <div class="mwp-wpvivid-block-bottom-space"><strong><?php esc_html_e('Author URL', 'wpvivid'); ?></strong></div> <div class="mwp-wpvivid-block-bottom-space"> <select option="mwp_white_label_setting" name="white_label_website_protocol" style="margin-bottom: 3px;"> <?php if($white_label_website_protocol === 'http'){ $http_protocol = 'selected'; $https_protocol = ''; } else{ $http_protocol = ''; $https_protocol = 'selected'; } ?> <option value="https" <?php echo esc_attr($https_protocol); ?>>https://</option> <option value="http" <?php echo esc_attr($http_protocol); ?>>http://</option> </select> <input type="text" placeholder="pro.wpvivid.com" option="mwp_white_label_setting" name="white_label_website" class="all-options" value="<?php echo esc_attr($white_label_website); ?>" /> </div> <div class="mwp-wpvivid-block-bottom-space"><?php /* translators: 1: Website protocol, 2: Website domain. */ echo sprintf(esc_html('Enter your service URL to replace %1$s://%2$s in the plugin UI.'), esc_html($white_label_website_protocol), esc_html($white_label_website)); ?></div> <div class="mwp-wpvivid-block-bottom-space"><strong><?php esc_html_e('Documentation Links', 'wpvivid'); ?></strong></div> <div class="mwp-wpvivid-block-bottom-space"> <label class="wpvivid-radio" style="padding-right:1em;"> <input type="radio" option="mwp_white_label_setting" name="show_sidebar" value="show" <?php echo esc_attr($show_sidebar_link); ?> />Show links </label> <label class="wpvivid-radio" style="padding-right:1em;"> <input type="radio" option="mwp_white_label_setting" name="show_sidebar" value="hide" <?php echo esc_attr($hide_sidebar_link); ?> />Hide Links </label> </div> <div class="mwp-wpvivid-block-bottom-space"><?php esc_html_e('Show or hide links to WPvivid documentation and support in the sidebar.'); ?></div> <div class="mwp-wpvivid-block-bottom-space"><strong><?php esc_html_e('Submit A Ticket Link', 'wpvivid'); ?></strong></div> <div class="mwp-wpvivid-block-bottom-space"> <label class="wpvivid-radio" style="padding-right:1em;"> <input type="radio" option="mwp_white_label_setting" name="show_submit_ticket" value="show" <?php echo esc_attr($show_submit_ticket_link); ?> />Show the link </label> <label class="wpvivid-radio" style="padding-right:1em;"> <input type="radio" option="mwp_white_label_setting" name="show_submit_ticket" value="hide" <?php echo esc_attr($hide_submit_ticket_link); ?> />Hide the link </label> </div> <div class="mwp-wpvivid-block-bottom-space"><?php esc_html_e('Show or hide the Submit A Ticket link in the sidebar.', 'wpvivid'); ?></div> <div class="mwp-wpvivid-block-bottom-space"><strong><?php esc_html_e('White Label Settings Access URL', 'wpvivid'); ?></strong></div> <div class="mwp-wpvivid-block-bottom-space"> <label> <input type="text" placeholder="wpvivid_white_label" option="mwp_white_label_setting" name="access_white_label_page_slug" class="all-options" value="<?php echo esc_attr($wpvivid_access_white_label_slug); ?>" onkeyup="value=value.replace(/[^a-zA-Z0-9_]/g,'')" onpaste="value=value.replace(/[^\a-\z\A-\Z0-9]/g,'')" /> <span></span> </label> </div> <div class="mwp-wpvivid-block-bottom-space"><?php esc_html_e('Enter a slug and add it at the end of the url of your WPvivid plugin page to access the white label settings.'); ?></div> <div class="mwp-wpvivid-block-bottom-space"><?php echo 'Current access url is: http(s)://child-site/wp-admin/admin.php?page='.esc_html($white_label_slug).'-dashboard&'.esc_html($wpvivid_access_white_label_slug).'=1'; ?></div> </div> </div> <div> <?php if($global){ ?> <input class="ui green mini button" id="mwp_wpvivid_global_white_label_save" type="button" value="<?php esc_attr_e( 'Save Changes and Sync', 'wpvivid' ); ?>" /> <?php } else{ ?> <input class="ui green mini button" id="mwp_wpvivid_white_label_save" type="button" value="<?php esc_attr_e( 'Save Changes', 'wpvivid' ); ?>" /> <?php } ?> </div> </div> <script> jQuery('#mwp_wpvivid_global_white_label_save').on('click', function(){ var setting_data = mwp_wpvivid_ajax_data_transfer('mwp_white_label_setting'); var ajax_data = { 'action': 'mwp_wpvivid_global_set_white_label_setting', 'setting': setting_data }; jQuery('#mwp_wpvivid_global_white_label_save').css({'pointer-events': 'none', 'opacity': '0.4'}); mwp_wpvivid_post_request(ajax_data, function (data) { try { var jsonarray = jQuery.parseJSON(data); jQuery('#mwp_wpvivid_global_white_label_save').css({'pointer-events': 'auto', 'opacity': '1'}); if (jsonarray.result === 'success') { window.location.href = window.location.href + "&synchronize=1&addon=1"; } else { alert(jsonarray.error); } } catch (err) { alert(err); jQuery('#mwp_wpvivid_global_white_label_save').css({'pointer-events': 'auto', 'opacity': '1'}); } }, function (XMLHttpRequest, textStatus, errorThrown) { jQuery('#mwp_wpvivid_global_white_label_save').css({'pointer-events': 'auto', 'opacity': '1'}); var error_message = mwp_wpvivid_output_ajaxerror('changing base settings', textStatus, errorThrown); alert(error_message); }); }); jQuery('#mwp_wpvivid_white_label_save').on('click', function(){ var setting_data = mwp_wpvivid_ajax_data_transfer('mwp_white_label_setting'); var ajax_data = { 'action': 'mwp_wpvivid_set_white_label_setting', 'setting': setting_data, 'site_id': '<?php echo esc_html($this->site_id); ?>' }; jQuery('#mwp_wpvivid_white_label_save').css({'pointer-events': 'none', 'opacity': '0.4'}); mwp_wpvivid_post_request(ajax_data, function (data) { try { var jsonarray = jQuery.parseJSON(data); jQuery('#mwp_wpvivid_white_label_save').css({'pointer-events': 'auto', 'opacity': '1'}); if (jsonarray.result === 'success') { location.reload(); } else { alert(jsonarray.error); } } catch (err) { alert(err); jQuery('#mwp_wpvivid_white_label_save').css({'pointer-events': 'auto', 'opacity': '1'}); } }, function (XMLHttpRequest, textStatus, errorThrown) { jQuery('#mwp_wpvivid_white_label_save').css({'pointer-events': 'auto', 'opacity': '1'}); var error_message = mwp_wpvivid_output_ajaxerror('changing base settings', textStatus, errorThrown); alert(error_message); }); }); </script> <?php } } public function mwp_wpvivid_synchronize_white_label($check_addon){ global $mainwp_wpvivid_extension_activator; $mainwp_wpvivid_extension_activator->render_sync_websites_page('mwp_wpvivid_sync_white_label', $check_addon); ?> <script> jQuery('#mwp_wpvivid_sync_white_label').click(function(){ mwp_wpvivid_sync_white_label(); }); function mwp_wpvivid_sync_white_label(){ var website_ids= []; mwp_wpvivid_sync_index=0; jQuery('.mwp-wpvivid-sync-row').each(function() { jQuery(this).children('td:first').each(function(){ if (jQuery(this).children().children().prop('checked')) { var id = jQuery(this).attr('website-id'); website_ids.push(id); } }); }); if(website_ids.length>0) { jQuery('#mwp_wpvivid_sync_white_label').css({'pointer-events': 'none', 'opacity': '0.4'}); var check_addon = '<?php echo esc_js($check_addon); ?>'; mwp_wpvivid_sync_site(website_ids,check_addon,'mwp_wpvivid_sync_white_label','Extensions-Wpvivid-Backup-Mainwp&tab=white_label','mwp_wpvivid_white_label_tab'); } } </script> <?php } } admin/images/Delete.png 0000644 00000002271 15133715745 0011026 0 ustar 00 �PNG IHDR v�� tEXtSoftware Adobe ImageReadyq�e<