GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Branch dev (058cbe)
by Liuta
03:27
created

Xcloner_Settings::get_xcloner_tmp_path()   B

Complexity

Conditions 7
Paths 18

Size

Total Lines 25
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

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