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