wpvivid-backuprestore
Last commit date
admin
1 week ago
includes
2 days ago
languages
4 years ago
vendor
1 year ago
index.php
7 years ago
readme.txt
2 days ago
uninstall.php
1 year ago
wpvivid-backuprestore.php
2 days ago
wpvivid-backuprestore.php
351 lines
| 1 | <?php |
| 2 | /** |
| 3 | * @link https://wpvivid.com |
| 4 | * @since 0.9.1 |
| 5 | * @package wpvivid |
| 6 | * |
| 7 | * @wordpress-plugin |
| 8 | * Plugin Name: WPvivid Backup Plugin |
| 9 | * Description: Clone or copy WP sites then move or migrate them to new host (new domain), schedule backups, transfer backups to leading remote storage. All in one. |
| 10 | * Version: 0.9.129 |
| 11 | * Author: WPvivid Backup & Migration |
| 12 | * Author URI: https://wpvivid.com |
| 13 | * License: GPL-3.0+ |
| 14 | * License URI: http://www.gnu.org/copyleft/gpl.html |
| 15 | * Text Domain: wpvivid-backuprestore |
| 16 | * Domain Path: /languages |
| 17 | */ |
| 18 | |
| 19 | // If this file is called directly, abort. |
| 20 | if ( ! defined( 'WPINC' ) ) { |
| 21 | die; |
| 22 | } |
| 23 | |
| 24 | define( 'WPVIVID_PLUGIN_VERSION', '0.9.129' ); |
| 25 | // |
| 26 | define('WPVIVID_RESTORE_INIT','init'); |
| 27 | define('WPVIVID_RESTORE_READY','ready'); |
| 28 | define('WPVIVID_RESTORE_COMPLETED','completed'); |
| 29 | define('WPVIVID_RESTORE_RUNNING','running'); |
| 30 | define('WPVIVID_RESTORE_ERROR','error'); |
| 31 | define('WPVIVID_RESTORE_WAIT','wait'); |
| 32 | define('WPVIVID_RESTORE_TIMEOUT',180); |
| 33 | |
| 34 | define('WPVIVID_PLUGIN_SLUG','WPvivid'); |
| 35 | define('WPVIVID_PLUGIN_NAME',plugin_basename(__FILE__)); |
| 36 | define('WPVIVID_PLUGIN_URL',plugins_url('',__FILE__)); |
| 37 | define('WPVIVID_PLUGIN_DIR',dirname(__FILE__)); |
| 38 | define('WPVIVID_PLUGIN_DIR_URL',plugin_dir_url(__FILE__).'admin/'); |
| 39 | define('WPVIVID_PLUGIN_IMAGES_URL',WPVIVID_PLUGIN_URL.'/admin/partials/images/'); |
| 40 | //We set a long enough default execution time (10 min) to ensure that the backup process can be completed. |
| 41 | define('WPVIVID_MAX_EXECUTION_TIME',300); |
| 42 | define('WPVIVID_RESTORE_MAX_EXECUTION_TIME', 300); |
| 43 | define('WPVIVID_MEMORY_LIMIT','512M'); |
| 44 | define('WPVIVID_RESTORE_MEMORY_LIMIT','512M'); |
| 45 | define('WPVIVID_MIGRATE_SIZE', '2048'); |
| 46 | //If the server uses fastcgi then default execution time should be set to 2 min for more efficient. |
| 47 | define('WPVIVID_MAX_EXECUTION_TIME_FCGI',180); |
| 48 | //Default number of reserved backups |
| 49 | define('WPVIVID_MAX_BACKUP_COUNT',7); |
| 50 | define('WPVIVID_DEFAULT_BACKUP_COUNT',3); |
| 51 | define('WPVIVID_DEFAULT_COMPRESS_TYPE','zip'); |
| 52 | //Max zip file size. |
| 53 | define('WPVIVID_DEFAULT_MAX_FILE_SIZE',200); |
| 54 | //Instruct PclZip to use all the time temporary files to create the zip archive or not.The default value is 1. |
| 55 | define('WPVIVID_DEFAULT_USE_TEMP',1); |
| 56 | //Instruct PclZip to use temporary files for files with size greater than.The default value is 16M. |
| 57 | define('WPVIVID_DEFAULT_USE_TEMP_SIZE',16); |
| 58 | //Exclude the files which is larger than.The default value is 0 means unlimited. |
| 59 | define('WPVIVID_DEFAULT_EXCLUDE_FILE_SIZE',0); |
| 60 | //Add a file in an archive without compressing the file.The default value is 200. |
| 61 | define('WPVIVID_DEFAULT_NO_COMPRESS',true); |
| 62 | //Backup save folder under WP_CONTENT_DIR |
| 63 | define('WPVIVID_DEFAULT_BACKUP_DIR','wpvividbackups'); |
| 64 | //Log save folder under WP_CONTENT_DIR |
| 65 | define('WPVIVID_DEFAULT_LOG_DIR','wpvividbackups'.DIRECTORY_SEPARATOR.'wpvivid_log'); |
| 66 | //Old files folder under WPVIVID_DEFAULT_BACKUP_DIR |
| 67 | define('WPVIVID_DEFAULT_ROLLBACK_DIR','wpvivid-old-files'); |
| 68 | // |
| 69 | define('WPVIVID_DEFAULT_ADMIN_BAR', true); |
| 70 | define('WPVIVID_DEFAULT_TAB_MENU', true); |
| 71 | define('WPVIVID_DEFAULT_DOMAIN_INCLUDE', true); |
| 72 | // |
| 73 | define('WPVIVID_DEFAULT_ESTIMATE_BACKUP', true); |
| 74 | //Specify the folder and database to be backed up |
| 75 | define('WPVIVID_DEFAULT_SUBPACKAGE_PLUGIN_UPLOAD', false); |
| 76 | |
| 77 | //define schedule hooks |
| 78 | define('WPVIVID_MAIN_SCHEDULE_EVENT','wpvivid_main_schedule_event'); |
| 79 | define('WPVIVID_RESUME_SCHEDULE_EVENT','wpvivid_resume_schedule_event'); |
| 80 | define('WPVIVID_CLEAN_BACKING_UP_DATA_EVENT','wpvivid_clean_backing_up_data_event'); |
| 81 | define('WPVIVID_TASK_MONITOR_EVENT','wpvivid_task_monitor_event'); |
| 82 | define('WPVIVID_CLEAN_BACKUP_RECORD_EVENT','wpvivid_clean_backup_record_event'); |
| 83 | //backup resume retry times |
| 84 | define('WPVIVID_RESUME_RETRY_TIMES',6); |
| 85 | define('WPVIVID_RESUME_INTERVAL',60); |
| 86 | |
| 87 | define('WPVIVID_REMOTE_CONNECT_RETRY_TIMES','3'); |
| 88 | define('WPVIVID_REMOTE_CONNECT_RETRY_INTERVAL','3'); |
| 89 | |
| 90 | define('WPVIVID_PACK_SIZE',1 << 20); |
| 91 | |
| 92 | define('WPVIVID_SUCCESS','success'); |
| 93 | define('WPVIVID_FAILED','failed'); |
| 94 | /** |
| 95 | * The core plugin class that is used to define internationalization, |
| 96 | * admin-specific hooks, and public-facing site hooks. |
| 97 | */ |
| 98 | //when active plugin redirect plugin page. |
| 99 | |
| 100 | |
| 101 | function wpvivid_plugin_activate() |
| 102 | { |
| 103 | $dir=get_option('wpvivid_local_setting'); |
| 104 | |
| 105 | if(!isset($dir['path'])) |
| 106 | { |
| 107 | $backup_dir=WPVIVID_DEFAULT_BACKUP_DIR; |
| 108 | $backup_log_dir=WPVIVID_DEFAULT_LOG_DIR; |
| 109 | } |
| 110 | else |
| 111 | { |
| 112 | $backup_dir=$dir['path']; |
| 113 | $backup_log_dir=$dir['path'].DIRECTORY_SEPARATOR.'wpvivid_log'; |
| 114 | } |
| 115 | |
| 116 | if(!is_dir(WP_CONTENT_DIR.DIRECTORY_SEPARATOR.$backup_dir)) |
| 117 | { |
| 118 | @mkdir(WP_CONTENT_DIR.DIRECTORY_SEPARATOR.$backup_dir,0777,true); |
| 119 | @fopen(WP_CONTENT_DIR.DIRECTORY_SEPARATOR.$backup_dir.DIRECTORY_SEPARATOR.'index.html', 'x'); |
| 120 | $tempfile=@fopen(WP_CONTENT_DIR.DIRECTORY_SEPARATOR.$backup_dir.DIRECTORY_SEPARATOR.'.htaccess', 'x'); |
| 121 | if($tempfile) |
| 122 | { |
| 123 | $text="<IfModule mod_rewrite.c>\r\nRewriteEngine On\r\nRewriteRule .* - [F,L]\r\n</IfModule>"; |
| 124 | fwrite($tempfile,$text ); |
| 125 | fclose($tempfile); |
| 126 | } |
| 127 | } |
| 128 | if(!is_dir(WP_CONTENT_DIR.DIRECTORY_SEPARATOR.$backup_log_dir)) |
| 129 | { |
| 130 | @mkdir(WP_CONTENT_DIR.DIRECTORY_SEPARATOR.$backup_log_dir,0777,true); |
| 131 | @fopen(WP_CONTENT_DIR.DIRECTORY_SEPARATOR.$backup_log_dir.DIRECTORY_SEPARATOR.'index.html', 'x'); |
| 132 | $tempfile=@fopen(WP_CONTENT_DIR.DIRECTORY_SEPARATOR.$backup_log_dir.DIRECTORY_SEPARATOR.'.htaccess', 'x'); |
| 133 | if($tempfile) |
| 134 | { |
| 135 | $text="<IfModule mod_rewrite.c>\r\nRewriteEngine On\r\nRewriteRule .* - [F,L]\r\n</IfModule>"; |
| 136 | fwrite($tempfile,$text ); |
| 137 | fclose($tempfile); |
| 138 | } |
| 139 | } |
| 140 | if(!is_dir(WP_CONTENT_DIR.DIRECTORY_SEPARATOR.$backup_log_dir.DIRECTORY_SEPARATOR.'error')) |
| 141 | { |
| 142 | @mkdir(WP_CONTENT_DIR.DIRECTORY_SEPARATOR.$backup_log_dir.DIRECTORY_SEPARATOR.'error',0777,true); |
| 143 | @fopen(WP_CONTENT_DIR.DIRECTORY_SEPARATOR.$backup_log_dir.DIRECTORY_SEPARATOR.'error'.DIRECTORY_SEPARATOR.'index.html', 'x'); |
| 144 | $tempfile=@fopen(WP_CONTENT_DIR.DIRECTORY_SEPARATOR.$backup_log_dir.DIRECTORY_SEPARATOR.'error'.DIRECTORY_SEPARATOR.'.htaccess', 'x'); |
| 145 | if($tempfile) |
| 146 | { |
| 147 | $text="<IfModule mod_rewrite.c>\r\nRewriteEngine On\r\nRewriteRule .* - [F,L]\r\n</IfModule>"; |
| 148 | fwrite($tempfile,$text ); |
| 149 | fclose($tempfile); |
| 150 | } |
| 151 | } |
| 152 | |
| 153 | //A flag to determine whether plugin had been initialized |
| 154 | $init=get_option('wpvivid_init', 'not init'); |
| 155 | if($init=='not init') |
| 156 | { |
| 157 | include_once WPVIVID_PLUGIN_DIR . '/includes/class-wpvivid-setting.php'; |
| 158 | //Initialization settings |
| 159 | WPvivid_Setting::init_option(); |
| 160 | update_option('wpvivid_init','init','no'); |
| 161 | } |
| 162 | |
| 163 | $wpvivid_remote_init=get_option('wpvivid_remote_init', 'not init'); |
| 164 | if($wpvivid_remote_init=='not init') |
| 165 | { |
| 166 | include_once WPVIVID_PLUGIN_DIR . '/includes/class-wpvivid-setting.php'; |
| 167 | wpvivid_init_remote_option(); |
| 168 | update_option('wpvivid_remote_init','init','no'); |
| 169 | } |
| 170 | |
| 171 | add_option('wpvivid_do_activation_redirect', true); |
| 172 | } |
| 173 | |
| 174 | function wpvivid_init_plugin_redirect() |
| 175 | { |
| 176 | if (get_option('wpvivid_do_activation_redirect', false)) |
| 177 | { |
| 178 | delete_option('wpvivid_do_activation_redirect'); |
| 179 | |
| 180 | $active_plugins = get_option('active_plugins'); |
| 181 | if(!function_exists('get_plugins')) |
| 182 | require_once(ABSPATH . 'wp-admin/includes/plugin.php'); |
| 183 | $plugins=get_plugins(); |
| 184 | $pro_wpvivid_slug='wpvivid-backup-pro/wpvivid-backup-pro.php'; |
| 185 | $b_redirect_pro=false; |
| 186 | if(!empty($plugins)) |
| 187 | { |
| 188 | if(isset($plugins[$pro_wpvivid_slug])) |
| 189 | { |
| 190 | if(in_array($pro_wpvivid_slug, $active_plugins)) |
| 191 | { |
| 192 | $b_redirect_pro=true; |
| 193 | } |
| 194 | } |
| 195 | } |
| 196 | |
| 197 | if($b_redirect_pro) |
| 198 | { |
| 199 | $url=apply_filters('wpvivid_backup_activate_redirect_url','admin.php?page=wpvivid-dashboard'); |
| 200 | if (is_multisite()) |
| 201 | { |
| 202 | wp_redirect(network_admin_url().$url); |
| 203 | } |
| 204 | else |
| 205 | { |
| 206 | wp_redirect(admin_url().$url); |
| 207 | } |
| 208 | } |
| 209 | else |
| 210 | { |
| 211 | $url=apply_filters('wpvivid_backup_activate_redirect_url','admin.php?page=WPvivid'); |
| 212 | if (is_multisite()) |
| 213 | { |
| 214 | wp_redirect(network_admin_url().$url); |
| 215 | } |
| 216 | else |
| 217 | { |
| 218 | wp_redirect(admin_url().$url); |
| 219 | } |
| 220 | } |
| 221 | } |
| 222 | } |
| 223 | |
| 224 | function wpvivid_init_remote_option() |
| 225 | { |
| 226 | $remoteslist=WPvivid_Setting::get_all_remote_options(); |
| 227 | foreach ($remoteslist as $key=>$value) |
| 228 | { |
| 229 | if(!array_key_exists('options',$value)) |
| 230 | { |
| 231 | continue; |
| 232 | } |
| 233 | $remote = array(); |
| 234 | if($value['type'] === 'ftp') |
| 235 | { |
| 236 | $remote['host']=$value['options']['host']; |
| 237 | $remote['username']=$value['options']['username']; |
| 238 | $remote['password']=$value['options']['password']; |
| 239 | $remote['path']=$value['options']['path']; |
| 240 | $remote['name']=$value['options']['name']; |
| 241 | $remote['passive']=$value['options']['passive']; |
| 242 | $value['type'] = strtolower($value['type']); |
| 243 | $remote['type']=$value['type']; |
| 244 | $remoteslist[$key]=$remote; |
| 245 | } |
| 246 | elseif ($value['type'] === 'sftp') |
| 247 | { |
| 248 | $remote['host']=$value['options']['host']; |
| 249 | $remote['username']=$value['options']['username']; |
| 250 | $remote['password']=$value['options']['password']; |
| 251 | $remote['path']=$value['options']['path']; |
| 252 | $remote['name']=$value['options']['name']; |
| 253 | $remote['port']=$value['options']['port']; |
| 254 | $value['type'] = strtolower($value['type']); |
| 255 | $remote['type']=$value['type']; |
| 256 | $remoteslist[$key]=$remote; |
| 257 | } |
| 258 | elseif ($value['type'] === 'amazonS3') |
| 259 | { |
| 260 | $remote['classMode']='0'; |
| 261 | $remote['sse']='0'; |
| 262 | $remote['name']=$value['options']['name']; |
| 263 | $remote['access']=$value['options']['access']; |
| 264 | $remote['secret']=$value['options']['secret']; |
| 265 | $remote['s3Path']=$value['options']['s3Path']; |
| 266 | $value['type'] = strtolower($value['type']); |
| 267 | $remote['type']=$value['type']; |
| 268 | $remoteslist[$key]=$remote; |
| 269 | } |
| 270 | } |
| 271 | WPvivid_Setting::update_option('wpvivid_upload_setting',$remoteslist); |
| 272 | |
| 273 | include_once WPVIVID_PLUGIN_DIR . '/includes/class-wpvivid-backuplist.php'; |
| 274 | |
| 275 | $backuplist=WPvivid_Backuplist::get_backuplist(); |
| 276 | foreach ($backuplist as $key=>$value) |
| 277 | { |
| 278 | if(is_array($value['remote'])) |
| 279 | { |
| 280 | foreach ($value['remote'] as $remote_key=>$storage_type) |
| 281 | { |
| 282 | if(!array_key_exists('options',$storage_type)) |
| 283 | { |
| 284 | continue; |
| 285 | } |
| 286 | $remote = array(); |
| 287 | if($storage_type['type'] === 'ftp') |
| 288 | { |
| 289 | $remote['host']=$storage_type['options']['host']; |
| 290 | $remote['username']=$storage_type['options']['username']; |
| 291 | $remote['password']=$storage_type['options']['password']; |
| 292 | $remote['path']=$storage_type['options']['path']; |
| 293 | $remote['name']=$storage_type['options']['name']; |
| 294 | $remote['passive']=$storage_type['options']['passive']; |
| 295 | $storage_type['type'] = strtolower($storage_type['type']); |
| 296 | $remote['type']=$storage_type['type']; |
| 297 | } |
| 298 | elseif ($storage_type['type'] === 'sftp') |
| 299 | { |
| 300 | $remote['host']=$storage_type['options']['host']; |
| 301 | $remote['username']=$storage_type['options']['username']; |
| 302 | $remote['password']=$storage_type['options']['password']; |
| 303 | $remote['path']=$storage_type['options']['path']; |
| 304 | $remote['name']=$storage_type['options']['name']; |
| 305 | $remote['port']=$storage_type['options']['port']; |
| 306 | $storage_type['type'] = strtolower($storage_type['type']); |
| 307 | $remote['type']=$storage_type['type']; |
| 308 | } |
| 309 | elseif ($storage_type['type'] === 'amazonS3') |
| 310 | { |
| 311 | $remote['classMode']='0'; |
| 312 | $remote['sse']='0'; |
| 313 | $remote['name']=$storage_type['options']['name']; |
| 314 | $remote['access']=$storage_type['options']['access']; |
| 315 | $remote['secret']=$storage_type['options']['secret']; |
| 316 | $remote['s3Path']=$storage_type['options']['s3Path']; |
| 317 | $storage_type['type'] = strtolower($storage_type['type']); |
| 318 | $remote['type']=$storage_type['type']; |
| 319 | } |
| 320 | $backuplist[$key]['remote'][$remote_key]=$remote; |
| 321 | } |
| 322 | } |
| 323 | } |
| 324 | WPvivid_Setting::update_option('wpvivid_backup_list',$backuplist); |
| 325 | } |
| 326 | |
| 327 | register_activation_hook(__FILE__, 'wpvivid_plugin_activate'); |
| 328 | add_action('admin_init', 'wpvivid_init_plugin_redirect'); |
| 329 | |
| 330 | /** |
| 331 | * Begins execution of the plugin. |
| 332 | * |
| 333 | * Since everything within the plugin is registered via hooks, |
| 334 | * then kicking off the plugin from this point in the file does |
| 335 | * not affect the page life cycle. |
| 336 | * |
| 337 | * @since 0.9.1 |
| 338 | */ |
| 339 | if(isset($wpvivid_plugin)&&is_a($wpvivid_plugin,'WPvivid')) |
| 340 | { |
| 341 | return ; |
| 342 | } |
| 343 | |
| 344 | require plugin_dir_path( __FILE__ ) . 'includes/class-wpvivid.php'; |
| 345 | |
| 346 | function run_wpvivid() |
| 347 | { |
| 348 | $wpvivid_plugin = new WPvivid(); |
| 349 | $GLOBALS['wpvivid_plugin'] = $wpvivid_plugin; |
| 350 | } |
| 351 | run_wpvivid(); |