| Total Complexity | 81 |
| Total Lines | 921 |
| Duplicated Lines | 0 % |
| Changes | 5 | ||
| Bugs | 2 | Features | 0 |
Complex classes like Xcloner_Settings often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Xcloner_Settings, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 3 | class Xcloner_Settings { |
||
| 4 | private $logger_file = "xcloner_main_%s.log"; |
||
| 5 | private $logger_file_hash = "xcloner%s.log"; |
||
| 6 | private $hash; |
||
| 7 | private $xcloner_sanitization; |
||
| 8 | private $xcloner_container; |
||
| 9 | |||
| 10 | public function __construct(Xcloner $xcloner_container, $hash = "") { |
||
| 11 | $this->xcloner_container = $xcloner_container; |
||
| 12 | if (isset($hash)) { |
||
| 13 | $this->set_hash($hash); |
||
| 14 | } |
||
| 15 | } |
||
| 16 | |||
| 17 | private function get_xcloner_container() { |
||
| 18 | return $this->xcloner_container; |
||
| 19 | } |
||
| 20 | |||
| 21 | public function get_logger_filename($include_hash = 0) { |
||
| 22 | if ($include_hash) { |
||
| 23 | $filename = sprintf($this->logger_file_hash, $this->get_hash()); |
||
| 24 | } else { |
||
| 25 | $filename = sprintf($this->logger_file, $this->get_server_unique_hash(5)); |
||
| 26 | } |
||
| 27 | |||
| 28 | return $filename; |
||
| 29 | } |
||
| 30 | |||
| 31 | public function get_xcloner_start_path() { |
||
| 32 | if (!get_option('xcloner_start_path') or !is_dir(get_option('xcloner_start_path'))) { |
||
|
|
|||
| 33 | $path = realpath(ABSPATH); |
||
| 34 | } else { |
||
| 35 | $path = get_option('xcloner_start_path'); |
||
| 36 | } |
||
| 37 | |||
| 38 | return $path; |
||
| 39 | } |
||
| 40 | |||
| 41 | public function get_xcloner_dir_path($dir) { |
||
| 42 | $path = self::get_xcloner_start_path().DS.$dir; |
||
| 43 | |||
| 44 | return $path; |
||
| 45 | } |
||
| 46 | |||
| 47 | public function get_xcloner_store_path() { |
||
| 48 | if (!get_option('xcloner_store_path') or !is_dir(get_option('xcloner_store_path'))) { |
||
| 49 | $path = realpath(XCLONER_STORAGE_PATH); |
||
| 50 | } else { |
||
| 51 | $path = get_option('xcloner_store_path'); |
||
| 52 | } |
||
| 53 | |||
| 54 | return $path; |
||
| 55 | } |
||
| 56 | |||
| 57 | public function get_xcloner_encryption_key() { |
||
| 58 | |||
| 59 | if(!get_option('xcloner_encryption_key') ) |
||
| 60 | { |
||
| 61 | return $this->randomString(35); |
||
| 62 | } |
||
| 63 | |||
| 64 | return get_option('xcloner_encryption_key'); |
||
| 65 | } |
||
| 66 | |||
| 67 | /** |
||
| 68 | * Create a random string |
||
| 69 | * @author XEWeb <> |
||
| 70 | * @param $length the length of the string to create |
||
| 71 | * @return $str the string |
||
| 72 | */ |
||
| 73 | private function randomString($length = 6) { |
||
| 74 | $str = ""; |
||
| 75 | $characters = array_merge(range('A','Z'), range('a','z'), range('0','9')); |
||
| 76 | $max = count($characters) - 1; |
||
| 77 | for ($i = 0; $i < $length; $i++) { |
||
| 78 | $rand = mt_rand(0, $max); |
||
| 79 | $str .= $characters[$rand]; |
||
| 80 | } |
||
| 81 | return $str; |
||
| 82 | } |
||
| 83 | |||
| 84 | public function get_xcloner_tmp_path_suffix() { |
||
| 85 | return "xcloner".$this->get_hash(); |
||
| 86 | } |
||
| 87 | |||
| 88 | |||
| 89 | public function get_xcloner_tmp_path($suffix = true) { |
||
| 90 | if (get_option('xcloner_force_tmp_path_site_root')) { |
||
| 91 | $path = $this->get_xcloner_store_path(); |
||
| 92 | } else { |
||
| 93 | |||
| 94 | $path = sys_get_temp_dir(); |
||
| 95 | if (!is_dir($path)) { |
||
| 96 | @mkdir($path); |
||
| 97 | @chmod($path, 0777); |
||
| 98 | } |
||
| 99 | |||
| 100 | if (!is_dir($path) or !is_writeable($path)) { |
||
| 101 | $path = $this->get_xcloner_store_path(); |
||
| 102 | } |
||
| 103 | } |
||
| 104 | |||
| 105 | if ($suffix) { |
||
| 106 | $path = $path.DS.".".$this->get_xcloner_tmp_path_suffix(); |
||
| 107 | } |
||
| 108 | |||
| 109 | return $path; |
||
| 110 | } |
||
| 111 | |||
| 112 | public function get_enable_mysql_backup() { |
||
| 113 | if (get_option('xcloner_enable_mysql_backup')) { |
||
| 114 | return true; |
||
| 115 | } |
||
| 116 | |||
| 117 | return false; |
||
| 118 | } |
||
| 119 | |||
| 120 | public function get_backup_extension_name($ext = "") { |
||
| 121 | if (!$ext) { |
||
| 122 | if (get_option('xcloner_backup_compression_level')) { |
||
| 123 | $ext = ".tgz"; |
||
| 124 | } else { |
||
| 125 | $ext = ".tar"; |
||
| 126 | } |
||
| 127 | } |
||
| 128 | |||
| 129 | return ($this->get_hash()).$ext; |
||
| 130 | } |
||
| 131 | |||
| 132 | public function get_hash() { |
||
| 133 | if (!$this->hash) { |
||
| 134 | $this->set_hash("-".$this->get_server_unique_hash(5)); |
||
| 135 | } |
||
| 136 | |||
| 137 | //echo $this->hash; |
||
| 138 | return $this->hash; |
||
| 139 | } |
||
| 140 | |||
| 141 | public function generate_new_hash() { |
||
| 142 | $hash = "-".md5(rand()); |
||
| 143 | |||
| 144 | $this->set_hash(substr($hash, 0, 6)); |
||
| 145 | |||
| 146 | return $hash; |
||
| 147 | } |
||
| 148 | |||
| 149 | public function set_hash($hash = "") { |
||
| 150 | if (substr($hash, 0, 1) != "-" and strlen($hash)) { |
||
| 151 | $hash = "-".$hash; |
||
| 152 | } |
||
| 153 | |||
| 154 | $this->hash = substr($hash, 0, 6); |
||
| 155 | |||
| 156 | return $this; |
||
| 157 | } |
||
| 158 | |||
| 159 | public function get_default_backup_name() { |
||
| 160 | $data = parse_url(get_site_url()); |
||
| 161 | |||
| 162 | $backup_name = "backup_[domain]".(isset($data['port']) ? "_".$data['port'] : "")."-[time]-".($this->get_enable_mysql_backup() ? "sql" : "nosql"); |
||
| 163 | |||
| 164 | return $backup_name; |
||
| 165 | } |
||
| 166 | |||
| 167 | public function get_db_hostname() { |
||
| 168 | global $wpdb; |
||
| 169 | |||
| 170 | if (!$data = get_option('xcloner_mysql_hostname')) { |
||
| 171 | $data = $wpdb->dbhost; |
||
| 172 | } |
||
| 173 | |||
| 174 | return $data; |
||
| 175 | } |
||
| 176 | |||
| 177 | public function get_db_username() { |
||
| 178 | global $wpdb; |
||
| 179 | |||
| 180 | if (!$data = get_option('xcloner_mysql_username')) { |
||
| 181 | $data = $wpdb->dbuser; |
||
| 182 | } |
||
| 183 | |||
| 184 | return $data; |
||
| 185 | } |
||
| 186 | |||
| 187 | public function get_db_password() { |
||
| 188 | global $wpdb; |
||
| 189 | |||
| 190 | if (!$data = get_option('xcloner_mysql_password')) { |
||
| 191 | $data = $wpdb->dbpassword; |
||
| 192 | } |
||
| 193 | |||
| 194 | return $data; |
||
| 195 | } |
||
| 196 | |||
| 197 | public function get_db_database() { |
||
| 198 | global $wpdb; |
||
| 199 | |||
| 200 | if (!$data = get_option('xcloner_mysql_database')) { |
||
| 201 | $data = $wpdb->dbname; |
||
| 202 | } |
||
| 203 | |||
| 204 | return $data; |
||
| 205 | } |
||
| 206 | |||
| 207 | public function get_table_prefix() { |
||
| 208 | global $wpdb; |
||
| 209 | |||
| 210 | return $wpdb->prefix; |
||
| 211 | } |
||
| 212 | |||
| 213 | /** |
||
| 214 | * @param string $option |
||
| 215 | */ |
||
| 216 | public function get_xcloner_option( $option ) { |
||
| 217 | $data = get_option( $option ); |
||
| 218 | |||
| 219 | return $data; |
||
| 220 | } |
||
| 221 | |||
| 222 | public function get_server_unique_hash( $strlen = 0 ) { |
||
| 223 | $hash = md5( get_home_url() . __DIR__ ); |
||
| 224 | |||
| 225 | if ( $strlen ) { |
||
| 226 | $hash = substr( $hash, 0, $strlen ); |
||
| 227 | } |
||
| 228 | |||
| 229 | return $hash; |
||
| 230 | } |
||
| 231 | |||
| 232 | public function settings_init() { |
||
| 233 | global $wpdb; |
||
| 234 | $this->xcloner_sanitization = $this->get_xcloner_container()->get_xcloner_sanitization(); |
||
| 235 | |||
| 236 | //ADDING MISSING OPTIONS |
||
| 237 | if (false == get_option('xcloner_mysql_settings_page')) { |
||
| 238 | add_option('xcloner_mysql_settings_page'); |
||
| 239 | } // end if |
||
| 240 | |||
| 241 | if (false == get_option('xcloner_cron_settings_page')) { |
||
| 242 | add_option('xcloner_cron_settings_page'); |
||
| 243 | } // end if |
||
| 244 | |||
| 245 | if (false == get_option('xcloner_system_settings_page')) { |
||
| 246 | add_option('xcloner_system_settings_page'); |
||
| 247 | } // end if |
||
| 248 | |||
| 249 | if (false == get_option('xcloner_cleanup_settings_page')) { |
||
| 250 | add_option('xcloner_cleanup_settings_page'); |
||
| 251 | } // end if |
||
| 252 | |||
| 253 | |||
| 254 | //ADDING SETTING SECTIONS |
||
| 255 | //GENERAL section |
||
| 256 | add_settings_section( |
||
| 257 | 'xcloner_general_settings_group', |
||
| 258 | __(' '), |
||
| 259 | array($this, 'xcloner_settings_section_cb'), |
||
| 260 | 'xcloner_settings_page' |
||
| 261 | ); |
||
| 262 | //MYSQL section |
||
| 263 | add_settings_section( |
||
| 264 | 'xcloner_mysql_settings_group', |
||
| 265 | __(' '), |
||
| 266 | array($this, 'xcloner_settings_section_cb'), |
||
| 267 | 'xcloner_mysql_settings_page' |
||
| 268 | ); |
||
| 269 | |||
| 270 | //SYSTEM section |
||
| 271 | add_settings_section( |
||
| 272 | 'xcloner_system_settings_group', |
||
| 273 | __('These are advanced options recommended for developers!', 'xcloner-backup-and-restore'), |
||
| 274 | array($this, 'xcloner_settings_section_cb'), |
||
| 275 | 'xcloner_system_settings_page' |
||
| 276 | ); |
||
| 277 | |||
| 278 | //CLEANUP section |
||
| 279 | add_settings_section( |
||
| 280 | 'xcloner_cleanup_settings_group', |
||
| 281 | __(' '), |
||
| 282 | array($this, 'xcloner_settings_section_cb'), |
||
| 283 | 'xcloner_cleanup_settings_page' |
||
| 284 | ); |
||
| 285 | |||
| 286 | |||
| 287 | //CRON section |
||
| 288 | add_settings_section( |
||
| 289 | 'xcloner_cron_settings_group', |
||
| 290 | __( ' ' ), |
||
| 291 | array( $this, 'xcloner_settings_section_cb' ), |
||
| 292 | 'xcloner_cron_settings_page' |
||
| 293 | ); |
||
| 294 | |||
| 295 | |||
| 296 | //REGISTERING THE 'GENERAL SECTION' FIELDS |
||
| 297 | register_setting( 'xcloner_general_settings_group', 'xcloner_backup_compression_level', array( |
||
| 298 | $this->xcloner_sanitization, |
||
| 299 | "sanitize_input_as_int" |
||
| 300 | ) ); |
||
| 301 | add_settings_field( |
||
| 302 | 'xcloner_backup_compression_level', |
||
| 303 | __( 'Backup Compression Level', 'xcloner-backup-and-restore' ), |
||
| 304 | array( $this, 'do_form_range_field' ), |
||
| 305 | 'xcloner_settings_page', |
||
| 306 | 'xcloner_general_settings_group', |
||
| 307 | array( |
||
| 308 | 'xcloner_backup_compression_level', |
||
| 309 | __( 'Options between [0-9]. Value 0 means no compression, while 9 is maximum compression affecting cpu load', 'xcloner-backup-and-restore' ), |
||
| 310 | 0, |
||
| 311 | 9 |
||
| 312 | ) |
||
| 313 | ); |
||
| 314 | |||
| 315 | register_setting( 'xcloner_general_settings_group', 'xcloner_start_path', array( |
||
| 316 | $this->xcloner_sanitization, |
||
| 317 | "sanitize_input_as_absolute_path" |
||
| 318 | ) ); |
||
| 319 | add_settings_field( |
||
| 320 | 'xcloner_start_path', |
||
| 321 | __( 'Backup Start Location', 'xcloner-backup-and-restore' ), |
||
| 322 | array( $this, 'do_form_text_field' ), |
||
| 323 | 'xcloner_settings_page', |
||
| 324 | 'xcloner_general_settings_group', |
||
| 325 | array( |
||
| 326 | 'xcloner_start_path', |
||
| 327 | __( 'Base path location from where XCloner can start the Backup.', 'xcloner-backup-and-restore' ), |
||
| 328 | $this->get_xcloner_start_path(), |
||
| 329 | //'disabled' |
||
| 330 | ) |
||
| 331 | ); |
||
| 332 | |||
| 333 | register_setting( 'xcloner_general_settings_group', 'xcloner_store_path', array( |
||
| 334 | $this->xcloner_sanitization, |
||
| 335 | "sanitize_input_as_absolute_path" |
||
| 336 | ) ); |
||
| 337 | add_settings_field( |
||
| 338 | 'xcloner_store_path', |
||
| 339 | __( 'Backup Storage Location', 'xcloner-backup-and-restore' ), |
||
| 340 | array( $this, 'do_form_text_field' ), |
||
| 341 | 'xcloner_settings_page', |
||
| 342 | 'xcloner_general_settings_group', |
||
| 343 | array( |
||
| 344 | 'xcloner_store_path', |
||
| 345 | __( 'Location where XCloner will store the Backup archives.', 'xcloner-backup-and-restore' ), |
||
| 346 | $this->get_xcloner_store_path(), |
||
| 347 | //'disabled' |
||
| 348 | ) |
||
| 349 | ); |
||
| 350 | |||
| 351 | register_setting( 'xcloner_general_settings_group', 'xcloner_encryption_key', array( |
||
| 352 | $this->xcloner_sanitization, |
||
| 353 | "sanitize_input_as_string" |
||
| 354 | ) ); |
||
| 355 | add_settings_field( |
||
| 356 | 'xcloner_encryption_key', |
||
| 357 | __( 'Backup Encryption Key', 'xcloner-backup-and-restore' ), |
||
| 358 | array( $this, 'do_form_text_field' ), |
||
| 359 | 'xcloner_settings_page', |
||
| 360 | 'xcloner_general_settings_group', |
||
| 361 | array( |
||
| 362 | 'xcloner_encryption_key', |
||
| 363 | __( 'Backup Encryption Key used to Encrypt/Decrypt backups, you might want to save this somewhere else as well.', 'xcloner-backup-and-restore' ), |
||
| 364 | $this->get_xcloner_encryption_key(), |
||
| 365 | //'disabled' |
||
| 366 | ) |
||
| 367 | ); |
||
| 368 | |||
| 369 | register_setting( 'xcloner_general_settings_group', 'xcloner_enable_log', array( |
||
| 370 | $this->xcloner_sanitization, |
||
| 371 | "sanitize_input_as_int" |
||
| 372 | ) ); |
||
| 373 | add_settings_field( |
||
| 374 | 'xcloner_enable_log', |
||
| 375 | __( 'Enable XCloner Backup Log', 'xcloner-backup-and-restore' ), |
||
| 376 | array( $this, 'do_form_switch_field' ), |
||
| 377 | 'xcloner_settings_page', |
||
| 378 | 'xcloner_general_settings_group', |
||
| 379 | array( |
||
| 380 | 'xcloner_enable_log', |
||
| 381 | sprintf( __( 'Enable the XCloner Backup log. You will find it stored unde the Backup Storage Location, file %s', 'xcloner-backup-and-restore' ), $this->get_logger_filename() ) |
||
| 382 | ) |
||
| 383 | ); |
||
| 384 | |||
| 385 | register_setting( 'xcloner_general_settings_group', 'xcloner_enable_pre_update_backup', array( |
||
| 386 | $this->xcloner_sanitization, |
||
| 387 | "sanitize_input_as_int" |
||
| 388 | ) ); |
||
| 389 | add_settings_field( |
||
| 390 | 'xcloner_enable_pre_update_backup', |
||
| 391 | __( 'Generate Backups before Automatic WP Upgrades', 'xcloner-backup-and-restore' ), |
||
| 392 | array( $this, 'do_form_switch_field' ), |
||
| 393 | 'xcloner_settings_page', |
||
| 394 | 'xcloner_general_settings_group', |
||
| 395 | array( |
||
| 396 | 'xcloner_enable_pre_update_backup', |
||
| 397 | sprintf( __( 'Attempt to generate a core, plugins, themes or languages files backup before the automatic update of Wordpress core, plugins, themes or languages files.', 'xcloner-backup-and-restore' ), $this->get_logger_filename() ) |
||
| 398 | ) |
||
| 399 | ); |
||
| 400 | |||
| 401 | register_setting( 'xcloner_general_settings_group', 'xcloner_regex_exclude', array( |
||
| 402 | $this->xcloner_sanitization, |
||
| 403 | "sanitize_input_as_raw" |
||
| 404 | ) ); |
||
| 405 | add_settings_field( |
||
| 406 | 'xcloner_regex_exclude', |
||
| 407 | __( 'Regex Exclude Files', 'xcloner-backup-and-restore' ), |
||
| 408 | array( $this, 'do_form_textarea_field' ), |
||
| 409 | 'xcloner_settings_page', |
||
| 410 | 'xcloner_general_settings_group', |
||
| 411 | array( |
||
| 412 | 'xcloner_regex_exclude', |
||
| 413 | __( 'Regular expression match to exclude files and folders, example patterns provided below, one pattern per line', 'xcloner-backup-and-restore' ), |
||
| 414 | //$this->get_xcloner_store_path(), |
||
| 415 | //'disabled' |
||
| 416 | ) |
||
| 417 | ); |
||
| 418 | |||
| 419 | //REGISTERING THE 'MYSQL SECTION' FIELDS |
||
| 420 | register_setting( 'xcloner_mysql_settings_group', 'xcloner_enable_mysql_backup', array( |
||
| 421 | $this->xcloner_sanitization, |
||
| 422 | "sanitize_input_as_int" |
||
| 423 | ) ); |
||
| 424 | add_settings_field( |
||
| 425 | 'xcloner_enable_mysql_backup', |
||
| 426 | __( 'Enable Mysql Backup', 'xcloner-backup-and-restore' ), |
||
| 427 | array( $this, 'do_form_switch_field' ), |
||
| 428 | 'xcloner_mysql_settings_page', |
||
| 429 | 'xcloner_mysql_settings_group', |
||
| 430 | array( |
||
| 431 | 'xcloner_enable_mysql_backup', |
||
| 432 | __( 'Enable Mysql Backup Option. If you don\'t want to backup the database, you can disable this.', 'xcloner-backup-and-restore' ) |
||
| 433 | ) |
||
| 434 | ); |
||
| 435 | |||
| 436 | register_setting( 'xcloner_mysql_settings_group', 'xcloner_backup_only_wp_tables' ); |
||
| 437 | add_settings_field( |
||
| 438 | 'xcloner_backup_only_wp_tables', |
||
| 439 | __( 'Backup only WP tables', 'xcloner-backup-and-restore' ), |
||
| 440 | array( $this, 'do_form_switch_field' ), |
||
| 441 | 'xcloner_mysql_settings_page', |
||
| 442 | 'xcloner_mysql_settings_group', |
||
| 443 | array( |
||
| 444 | 'xcloner_backup_only_wp_tables', |
||
| 445 | sprintf( __( 'Enable this if you only want to Backup only tables starting with \'%s\' prefix', 'xcloner-backup-and-restore' ), $this->get_table_prefix() ) |
||
| 446 | ) |
||
| 447 | ); |
||
| 448 | |||
| 449 | register_setting( 'xcloner_mysql_settings_group', 'xcloner_mysql_hostname', array( |
||
| 450 | $this->xcloner_sanitization, |
||
| 451 | "sanitize_input_as_raw" |
||
| 452 | ) ); |
||
| 453 | add_settings_field( |
||
| 454 | 'xcloner_mysql_hostname', |
||
| 455 | __( 'Mysql Hostname', 'xcloner-backup-and-restore' ), |
||
| 456 | array( $this, 'do_form_text_field' ), |
||
| 457 | 'xcloner_mysql_settings_page', |
||
| 458 | 'xcloner_mysql_settings_group', |
||
| 459 | array( |
||
| 460 | 'xcloner_mysql_hostname', |
||
| 461 | __( 'Wordpress mysql hostname', 'xcloner-backup-and-restore' ), |
||
| 462 | $this->get_db_hostname(), |
||
| 463 | 'disabled' |
||
| 464 | ) |
||
| 465 | ); |
||
| 466 | |||
| 467 | register_setting( 'xcloner_mysql_settings_group', 'xcloner_mysql_username', array( |
||
| 468 | $this->xcloner_sanitization, |
||
| 469 | "sanitize_input_as_raw" |
||
| 470 | ) ); |
||
| 471 | add_settings_field( |
||
| 472 | 'xcloner_mysql_username', |
||
| 473 | __( 'Mysql Username', 'xcloner-backup-and-restore' ), |
||
| 474 | array( $this, 'do_form_text_field' ), |
||
| 475 | 'xcloner_mysql_settings_page', |
||
| 476 | 'xcloner_mysql_settings_group', |
||
| 477 | array( |
||
| 478 | 'xcloner_mysql_username', |
||
| 479 | __( 'Wordpress mysql username', 'xcloner-backup-and-restore' ), |
||
| 480 | $this->get_db_username(), |
||
| 481 | 'disabled' |
||
| 482 | ) |
||
| 483 | ); |
||
| 484 | |||
| 485 | register_setting( 'xcloner_mysql_settings_group', 'xcloner_mysql_database', array( |
||
| 486 | $this->xcloner_sanitization, |
||
| 487 | "sanitize_input_as_raw" |
||
| 488 | ) ); |
||
| 489 | add_settings_field( |
||
| 490 | 'xcloner_mysql_database', |
||
| 491 | __( 'Mysql Database', 'xcloner-backup-and-restore' ), |
||
| 492 | array( $this, 'do_form_text_field' ), |
||
| 493 | 'xcloner_mysql_settings_page', |
||
| 494 | 'xcloner_mysql_settings_group', |
||
| 495 | array( |
||
| 496 | 'xcloner_mysql_database', |
||
| 497 | __( 'Wordpress mysql database', 'xcloner-backup-and-restore' ), |
||
| 498 | $this->get_db_database(), |
||
| 499 | 'disabled' |
||
| 500 | ) |
||
| 501 | ); |
||
| 502 | |||
| 503 | //REGISTERING THE 'SYSTEM SECTION' FIELDS |
||
| 504 | register_setting( 'xcloner_system_settings_group', 'xcloner_size_limit_per_request', array( |
||
| 505 | $this->xcloner_sanitization, |
||
| 506 | "sanitize_input_as_int" |
||
| 507 | ) ); |
||
| 508 | add_settings_field( |
||
| 509 | 'xcloner_size_limit_per_request', |
||
| 510 | __( 'Data Size Limit Per Request', 'xcloner-backup-and-restore' ), |
||
| 511 | array( $this, 'do_form_range_field' ), |
||
| 512 | 'xcloner_system_settings_page', |
||
| 513 | 'xcloner_system_settings_group', |
||
| 514 | array( |
||
| 515 | 'xcloner_size_limit_per_request', |
||
| 516 | __( 'Use this option to set how much file data can XCloner backup in one AJAX request. Range 0-1024 MB', 'xcloner-backup-and-restore' ), |
||
| 517 | 0, |
||
| 518 | 1024 |
||
| 519 | ) |
||
| 520 | ); |
||
| 521 | |||
| 522 | register_setting( 'xcloner_system_settings_group', 'xcloner_files_to_process_per_request', array( |
||
| 523 | $this->xcloner_sanitization, |
||
| 524 | "sanitize_input_as_int" |
||
| 525 | ) ); |
||
| 526 | add_settings_field( |
||
| 527 | 'xcloner_files_to_process_per_request', |
||
| 528 | __( 'Files To Process Per Request', 'xcloner-backup-and-restore' ), |
||
| 529 | array( $this, 'do_form_range_field' ), |
||
| 530 | 'xcloner_system_settings_page', |
||
| 531 | 'xcloner_system_settings_group', |
||
| 532 | array( |
||
| 533 | 'xcloner_files_to_process_per_request', |
||
| 534 | __( 'Use this option to set how many files XCloner should process at one time before doing another AJAX call', 'xcloner-backup-and-restore' ), |
||
| 535 | 0, |
||
| 536 | 1000 |
||
| 537 | ) |
||
| 538 | ); |
||
| 539 | |||
| 540 | register_setting( 'xcloner_system_settings_group', 'xcloner_directories_to_scan_per_request', array( |
||
| 541 | $this->xcloner_sanitization, |
||
| 542 | "sanitize_input_as_int" |
||
| 543 | ) ); |
||
| 544 | add_settings_field( |
||
| 545 | 'xcloner_directories_to_scan_per_request', |
||
| 546 | __( 'Directories To Scan Per Request', 'xcloner-backup-and-restore' ), |
||
| 547 | array( $this, 'do_form_range_field' ), |
||
| 548 | 'xcloner_system_settings_page', |
||
| 549 | 'xcloner_system_settings_group', |
||
| 550 | array( |
||
| 551 | 'xcloner_directories_to_scan_per_request', |
||
| 552 | __( 'Use this option to set how many directories XCloner should scan at one time before doing another AJAX call', 'xcloner-backup-and-restore' ), |
||
| 553 | 0, |
||
| 554 | 1000 |
||
| 555 | ) |
||
| 556 | ); |
||
| 557 | |||
| 558 | register_setting( 'xcloner_system_settings_group', 'xcloner_database_records_per_request', array( |
||
| 559 | $this->xcloner_sanitization, |
||
| 560 | "sanitize_input_as_int" |
||
| 561 | ) ); |
||
| 562 | add_settings_field( |
||
| 563 | 'xcloner_database_records_per_request', |
||
| 564 | __( 'Database Records Per Request', 'xcloner-backup-and-restore' ), |
||
| 565 | array( $this, 'do_form_range_field' ), |
||
| 566 | 'xcloner_system_settings_page', |
||
| 567 | 'xcloner_system_settings_group', |
||
| 568 | array( |
||
| 569 | 'xcloner_database_records_per_request', |
||
| 570 | __( 'Use this option to set how many database table records should be fetched per AJAX request, or set to 0 to fetch all. Range 0-100000 records', 'xcloner-backup-and-restore' ), |
||
| 571 | 0, |
||
| 572 | 100000 |
||
| 573 | ) |
||
| 574 | ); |
||
| 575 | |||
| 576 | /*register_setting('xcloner_system_settings_group', 'xcloner_diff_backup_recreate_period', array($this->xcloner_sanitization, "sanitize_input_as_int")); |
||
| 577 | add_settings_field( |
||
| 578 | 'xcloner_diff_backup_recreate_period', |
||
| 579 | __('Differetial Backups Max Days','xcloner-backup-and-restore'), |
||
| 580 | array($this, 'do_form_number_field'), |
||
| 581 | 'xcloner_system_settings_page', |
||
| 582 | 'xcloner_system_settings_group', |
||
| 583 | array('xcloner_diff_backup_recreate_period', |
||
| 584 | __('Use this option to set when a full backup should be recreated if the scheduled backup type is set to \'Full Backup+Differential Backups\' ','xcloner-backup-and-restore'), |
||
| 585 | ) |
||
| 586 | );*/ |
||
| 587 | |||
| 588 | register_setting( 'xcloner_system_settings_group', 'xcloner_exclude_files_larger_than_mb', array( |
||
| 589 | $this->xcloner_sanitization, |
||
| 590 | "sanitize_input_as_int" |
||
| 591 | ) ); |
||
| 592 | add_settings_field( |
||
| 593 | 'xcloner_exclude_files_larger_than_mb', |
||
| 594 | __( 'Exclude files larger than (MB)', 'xcloner-backup-and-restore' ), |
||
| 595 | array( $this, 'do_form_number_field' ), |
||
| 596 | 'xcloner_system_settings_page', |
||
| 597 | 'xcloner_system_settings_group', |
||
| 598 | array( |
||
| 599 | 'xcloner_exclude_files_larger_than_mb', |
||
| 600 | __( 'Use this option to automatically exclude files larger than a certain size in MB, or set to 0 to include all. Range 0-1000 MB', 'xcloner-backup-and-restore' ), |
||
| 601 | ) |
||
| 602 | ); |
||
| 603 | |||
| 604 | register_setting( 'xcloner_system_settings_group', 'xcloner_split_backup_limit', array( |
||
| 605 | $this->xcloner_sanitization, |
||
| 606 | "sanitize_input_as_int" |
||
| 607 | ) ); |
||
| 608 | add_settings_field( |
||
| 609 | 'xcloner_split_backup_limit', |
||
| 610 | __( 'Split Backup Archive Limit (MB)', 'xcloner-backup-and-restore' ), |
||
| 611 | array( $this, 'do_form_number_field' ), |
||
| 612 | 'xcloner_system_settings_page', |
||
| 613 | 'xcloner_system_settings_group', |
||
| 614 | array( |
||
| 615 | 'xcloner_split_backup_limit', |
||
| 616 | __( 'Use this option to automatically split the backup archive into smaller parts. Range 0-10000 MB', 'xcloner-backup-and-restore' ), |
||
| 617 | ) |
||
| 618 | ); |
||
| 619 | |||
| 620 | register_setting( 'xcloner_system_settings_group', 'xcloner_force_tmp_path_site_root' ); |
||
| 621 | add_settings_field( |
||
| 622 | 'xcloner_force_tmp_path_site_root', |
||
| 623 | __( 'Force Temporary Path Within XCloner Storage', 'xcloner-backup-and-restore' ), |
||
| 624 | array( $this, 'do_form_switch_field' ), |
||
| 625 | 'xcloner_system_settings_page', |
||
| 626 | 'xcloner_system_settings_group', |
||
| 627 | array( |
||
| 628 | 'xcloner_force_tmp_path_site_root', |
||
| 629 | sprintf( __( 'Enable this option if you want the XCloner Temporary Path to be within your XCloner Storage Location', 'xcloner-backup-and-restore' ), $this->get_table_prefix() ) |
||
| 630 | ) |
||
| 631 | ); |
||
| 632 | |||
| 633 | register_setting( 'xcloner_system_settings_group', 'xcloner_disable_email_notification' ); |
||
| 634 | add_settings_field( |
||
| 635 | 'xcloner_disable_email_notification', |
||
| 636 | __( 'Disable Email Notifications', 'xcloner-backup-and-restore' ), |
||
| 637 | array( $this, 'do_form_switch_field' ), |
||
| 638 | 'xcloner_system_settings_page', |
||
| 639 | 'xcloner_system_settings_group', |
||
| 640 | array( |
||
| 641 | 'xcloner_disable_email_notification', |
||
| 642 | sprintf( __( 'Enable this option if you want the XCloner to NOT send email notifications on successful backups', 'xcloner-backup-and-restore' ), $this->get_table_prefix() ) |
||
| 643 | ) |
||
| 644 | ); |
||
| 645 | |||
| 646 | //REGISTERING THE 'CLEANUP SECTION' FIELDS |
||
| 647 | register_setting( 'xcloner_cleanup_settings_group', 'xcloner_cleanup_retention_limit_days', array( |
||
| 648 | $this->xcloner_sanitization, |
||
| 649 | "sanitize_input_as_int" |
||
| 650 | ) ); |
||
| 651 | add_settings_field( |
||
| 652 | 'xcloner_cleanup_retention_limit_days', |
||
| 653 | __( 'Cleanup by Date(days)', 'xcloner-backup-and-restore' ), |
||
| 654 | array( $this, 'do_form_number_field' ), |
||
| 655 | 'xcloner_cleanup_settings_page', |
||
| 656 | 'xcloner_cleanup_settings_group', |
||
| 657 | array( |
||
| 658 | 'xcloner_cleanup_retention_limit_days', |
||
| 659 | __( 'Specify the maximum number of days a backup archive can be kept on the server. 0 disables this option', 'xcloner-backup-and-restore' ) |
||
| 660 | ) |
||
| 661 | ); |
||
| 662 | |||
| 663 | register_setting( 'xcloner_cleanup_settings_group', 'xcloner_cleanup_retention_limit_archives', array( |
||
| 664 | $this->xcloner_sanitization, |
||
| 665 | "sanitize_input_as_int" |
||
| 666 | ) ); |
||
| 667 | add_settings_field( |
||
| 668 | 'xcloner_cleanup_retention_limit_archives', |
||
| 669 | __( 'Cleanup by Quantity', 'xcloner-backup-and-restore' ), |
||
| 670 | array( $this, 'do_form_number_field' ), |
||
| 671 | 'xcloner_cleanup_settings_page', |
||
| 672 | 'xcloner_cleanup_settings_group', |
||
| 673 | array( |
||
| 674 | 'xcloner_cleanup_retention_limit_archives', |
||
| 675 | __( 'Specify the maximum number of backup archives to keep on the server. 0 disables this option', 'xcloner-backup-and-restore' ) |
||
| 676 | ) |
||
| 677 | ); |
||
| 678 | |||
| 679 | register_setting( 'xcloner_cleanup_settings_group', 'xcloner_cleanup_capacity_limit', array( |
||
| 680 | $this->xcloner_sanitization, |
||
| 681 | "sanitize_input_as_int" |
||
| 682 | ) ); |
||
| 683 | add_settings_field( |
||
| 684 | 'xcloner_cleanup_capacity_limit', |
||
| 685 | __( 'Cleanup by Capacity(MB)', 'xcloner-backup-and-restore' ), |
||
| 686 | array( $this, 'do_form_number_field' ), |
||
| 687 | 'xcloner_cleanup_settings_page', |
||
| 688 | 'xcloner_cleanup_settings_group', |
||
| 689 | array( |
||
| 690 | 'xcloner_cleanup_capacity_limit', |
||
| 691 | __( 'Remove oldest backups if all created backups exceed the configured limit in Megabytes. 0 disables this option', 'xcloner-backup-and-restore' ) |
||
| 692 | ) |
||
| 693 | ); |
||
| 694 | |||
| 695 | register_setting( 'xcloner_cleanup_settings_group', 'xcloner_cleanup_delete_after_remote_transfer', array( |
||
| 696 | $this->xcloner_sanitization, |
||
| 697 | "sanitize_input_as_int" |
||
| 698 | ) ); |
||
| 699 | add_settings_field( |
||
| 700 | 'xcloner_cleanup_delete_after_remote_transfer', |
||
| 701 | __( 'Delete Backup After Remote Storage Transfer', 'xcloner-backup-and-restore' ), |
||
| 702 | array( $this, 'do_form_switch_field' ), |
||
| 703 | 'xcloner_cleanup_settings_page', |
||
| 704 | 'xcloner_cleanup_settings_group', |
||
| 705 | array( |
||
| 706 | 'xcloner_cleanup_delete_after_remote_transfer', |
||
| 707 | __( 'Remove backup created automatically from local storage after sending the backup to Remote Storage', 'xcloner-backup-and-restore' ) |
||
| 708 | ) |
||
| 709 | ); |
||
| 710 | |||
| 711 | //REGISTERING THE 'CRON SECTION' FIELDS |
||
| 712 | register_setting( 'xcloner_cron_settings_group', 'xcloner_cron_frequency' ); |
||
| 713 | add_settings_field( |
||
| 714 | 'xcloner_cron_frequency', |
||
| 715 | __( 'Cron frequency', 'xcloner-backup-and-restore' ), |
||
| 716 | array( $this, 'do_form_text_field' ), |
||
| 717 | 'xcloner_cron_settings_page', |
||
| 718 | 'xcloner_cron_settings_group', |
||
| 719 | array( |
||
| 720 | 'xcloner_cron_frequency', |
||
| 721 | __( 'Cron frequency' ) |
||
| 722 | ) |
||
| 723 | ); |
||
| 724 | } |
||
| 725 | |||
| 726 | |||
| 727 | |||
| 728 | |||
| 729 | /** |
||
| 730 | * callback functions |
||
| 731 | */ |
||
| 732 | |||
| 733 | // section content cb |
||
| 734 | public function xcloner_settings_section_cb() { |
||
| 735 | //echo '<p>WPOrg Section Introduction.</p>'; |
||
| 736 | } |
||
| 737 | |||
| 738 | // text field content cb |
||
| 739 | public function do_form_text_field($params) { |
||
| 740 | if (!isset($params['3'])) { |
||
| 741 | $params[3] = 0; |
||
| 742 | } |
||
| 743 | if (!isset($params['2'])) { |
||
| 744 | $params[2] = 0; |
||
| 745 | } |
||
| 746 | |||
| 747 | list($fieldname, $label, $value, $disabled) = $params; |
||
| 748 | |||
| 749 | if (!$value) { |
||
| 750 | $value = get_option($fieldname); |
||
| 751 | } |
||
| 752 | // output the field |
||
| 753 | ?> |
||
| 754 | <div class="row"> |
||
| 755 | <div class="input-field col s10 m10 l8"> |
||
| 756 | <input class="validate" <?php echo ($disabled) ? "disabled" : "" ?> name="<?php echo $fieldname ?>" |
||
| 757 | id="<?php echo $fieldname ?>" type="text" class="validate" |
||
| 758 | value="<?php echo isset($value) ? esc_attr($value) : ''; ?>"> |
||
| 759 | </div> |
||
| 760 | <div class="col s2 m2 "> |
||
| 761 | <a class="btn-floating tooltipped btn-small" data-position="left" data-delay="50" |
||
| 762 | data-tooltip="<?php echo $label ?>" data-tooltip-id=""><i class="material-icons">help_outline</i></a> |
||
| 763 | </div> |
||
| 764 | </div> |
||
| 765 | |||
| 766 | |||
| 767 | <?php |
||
| 768 | } |
||
| 769 | |||
| 770 | // textarea field content cb |
||
| 771 | public function do_form_textarea_field($params) { |
||
| 772 | if (!isset($params['3'])) { |
||
| 773 | $params[3] = 0; |
||
| 774 | } |
||
| 775 | if (!isset($params['2'])) { |
||
| 776 | $params[2] = 0; |
||
| 777 | } |
||
| 778 | |||
| 779 | list($fieldname, $label, $value, $disabled) = $params; |
||
| 780 | |||
| 781 | if (!$value) { |
||
| 782 | $value = get_option($fieldname); |
||
| 783 | } |
||
| 784 | // output the field |
||
| 785 | ?> |
||
| 786 | <div class="row"> |
||
| 787 | <div class="input-field col s10 m10 l8"> |
||
| 788 | <textarea class="validate" <?php echo ($disabled) ? "disabled" : "" ?> name="<?php echo $fieldname ?>" |
||
| 789 | id="<?php echo $fieldname ?>" type="text" class="validate" |
||
| 790 | value=""><?php echo isset($value) ? esc_attr($value) : ''; ?></textarea> |
||
| 791 | </div> |
||
| 792 | <div class="col s2 m2 "> |
||
| 793 | <a class="btn-floating tooltipped btn-small" data-position="center" data-html="true" data-delay="50" |
||
| 794 | data-tooltip="<?php echo $label ?>" data-tooltip-id=""><i class="material-icons">help_outline</i></a> |
||
| 795 | </div> |
||
| 796 | <div class="col s12"> |
||
| 797 | <ul class="xcloner_regex_exclude_limit"> |
||
| 798 | <li>Exclude all except .php file: <span |
||
| 799 | class="regex_pattern"><?php echo htmlentities('(.*)\.(.+)$(?<!(php))') ?></span></li> |
||
| 800 | <li>Exclude all except .php and .txt: <span |
||
| 801 | class="regex_pattern"> <?php echo htmlentities('(.*)\.(.+)$(?<!(php|txt))') ?></span> |
||
| 802 | </li> |
||
| 803 | <li>Exclude all .avi files: <span |
||
| 804 | class="regex_pattern"> <?php echo htmlentities('(.*)\.(.+)$(?<=(avi))') ?></span></li> |
||
| 805 | <li>Exclude all .jpg,.gif and .png files: <span |
||
| 806 | class="regex_pattern"> <?php echo htmlentities('(.*)\.(.+)$(?<=(gif|png|jpg))') ?></span> |
||
| 807 | </li> |
||
| 808 | <li>Exclude all .svn and .git: <span |
||
| 809 | class="regex_pattern"> <?php echo htmlentities('(.*)\.(svn|git)(.*)$') ?></span></li> |
||
| 810 | <li>Exclude root directory /test: <span |
||
| 811 | class="regex_pattern"> <?php echo htmlentities('\/test(.*)$') ?></span> or <span |
||
| 812 | class="regex_pattern"> <?php echo htmlentities('test(.*)$') ?></span></li> |
||
| 813 | <li>Exclude the wp-admin folder: <span |
||
| 814 | class="regex_pattern"> <?php echo htmlentities('(\/wp-admin)(.*)$') ?></span></li> |
||
| 815 | <li>Exclude the wp-content/uploads folder: <span |
||
| 816 | class="regex_pattern"> <?php echo htmlentities('(\/wp-content\/uploads)(.*)$') ?></span> |
||
| 817 | </li> |
||
| 818 | <li>Exclude the wp-admin, wp-includes and wp-config.php: <span |
||
| 819 | class="regex_pattern"> <?php echo htmlentities('\/(wp-admin|wp-includes|wp-config.php)(.*)$') ?></span> |
||
| 820 | </li> |
||
| 821 | <li>Exclude wp-content/updraft and wp/content/uploads/wp_all_backup folder :<span |
||
| 822 | class="regex_pattern">\/(wp-content\/updraft|\/wp-content\/uploads\/wp_all_backup)(.*)$</span> |
||
| 823 | </li> |
||
| 824 | <li>Exclude all cache folders from wp-content/ and it's subdirectories: <span |
||
| 825 | class="regex_pattern"> <?php echo htmlentities('\/wp-content(.*)\/cache($|\/)(.*)') ?></span> |
||
| 826 | </li> |
||
| 827 | <li>Exclude wp-content/cache/ folder: <span |
||
| 828 | class="regex_pattern"> <?php echo htmlentities('\/wp-content\/cache(.*)') ?></span> |
||
| 829 | </li> |
||
| 830 | <li>Exclude all error_log files: <span |
||
| 831 | class="regex_pattern"> <?php echo htmlentities('(.*)error_log$') ?></span></li> |
||
| 832 | </ul> |
||
| 833 | </div> |
||
| 834 | </div> |
||
| 835 | |||
| 836 | |||
| 837 | <?php |
||
| 838 | } |
||
| 839 | |||
| 840 | // number field content cb |
||
| 841 | public function do_form_number_field($params) { |
||
| 842 | if (!isset($params['3'])) { |
||
| 843 | $params[3] = 0; |
||
| 844 | } |
||
| 845 | if (!isset($params['2'])) { |
||
| 846 | $params[2] = 0; |
||
| 847 | } |
||
| 848 | |||
| 849 | list($fieldname, $label, $value, $disabled) = $params; |
||
| 850 | |||
| 851 | if (!$value) { |
||
| 852 | $value = get_option($fieldname); |
||
| 853 | } |
||
| 854 | // output the field |
||
| 855 | ?> |
||
| 856 | <div class="row"> |
||
| 857 | <div class="input-field col s10 m5 l3"> |
||
| 858 | <input class="validate" <?php echo ($disabled) ? "disabled" : "" ?> name="<?php echo $fieldname ?>" |
||
| 859 | id="<?php echo $fieldname ?>" type="number" class="validate" |
||
| 860 | value="<?php echo isset($value) ? esc_attr($value) : ''; ?>"> |
||
| 861 | </div> |
||
| 862 | <div class="col s2 m2 "> |
||
| 863 | <a class="btn-floating tooltipped btn-small" data-html="true" data-position="center" data-delay="50" |
||
| 864 | data-tooltip="<?php echo $label ?>" data-tooltip-id=""><i class="material-icons">help_outline</i></a> |
||
| 865 | </div> |
||
| 866 | </div> |
||
| 867 | |||
| 868 | |||
| 869 | <?php |
||
| 870 | } |
||
| 871 | |||
| 872 | public function do_form_range_field($params) { |
||
| 873 | if (!isset($params['4'])) { |
||
| 874 | $params[4] = 0; |
||
| 875 | } |
||
| 876 | |||
| 877 | list($fieldname, $label, $range_start, $range_end, $disabled) = $params; |
||
| 878 | $value = get_option($fieldname); |
||
| 879 | ?> |
||
| 880 | <div class="row"> |
||
| 881 | <div class="input-field col s10 m10 l8"> |
||
| 882 | <p class="range-field"> |
||
| 883 | <input <?php echo ($disabled) ? "disabled" : "" ?> type="range" name="<?php echo $fieldname ?>" |
||
| 884 | id="<?php echo $fieldname ?>" |
||
| 885 | min="<?php echo $range_start ?>" |
||
| 886 | max="<?php echo $range_end ?>" |
||
| 887 | value="<?php echo isset($value) ? esc_attr($value) : ''; ?>"/> |
||
| 888 | </p> |
||
| 889 | </div> |
||
| 890 | <div class="col s2 m2 "> |
||
| 891 | <a class="btn-floating tooltipped btn-small" data-html="true" data-position="center" data-delay="50" |
||
| 892 | data-tooltip="<?php echo $label ?>" data-tooltip-id=""><i class="material-icons">help_outline</i></a> |
||
| 893 | </div> |
||
| 894 | </div> |
||
| 895 | <?php |
||
| 896 | } |
||
| 897 | |||
| 898 | |||
| 899 | public function do_form_switch_field($params) { |
||
| 924 | </div> |
||
| 925 | </div> |
||
| 926 | <?php |
||
| 927 | } |
||
| 928 | } |
||
| 929 |