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.
Completed
Branch dev (953bb6)
by Liuta
01:57
created

Xcloner_Settings::get_xcloner_encryption_key()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 0
dl 0
loc 9
rs 9.9666
c 0
b 0
f 0
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 View Code Duplication
	public function get_xcloner_start_path() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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 View Code Duplication
	public function get_xcloner_store_path() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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
0 ignored issues
show
Documentation introduced by
The doc-type $str could not be parsed: Unknown type name "$str" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
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 );
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
97
				@chmod( $path, 0777 );
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
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
	public function get_xcloner_option( $option ) {
214
		$data = get_option( $option );
215
216
		return $data;
217
	}
218
219
	public function get_server_unique_hash( $strlen = 0 ) {
220
		$hash = md5( get_home_url() . __DIR__ );
221
222
		if ( $strlen ) {
223
			$hash = substr( $hash, 0, $strlen );
224
		}
225
226
		return $hash;
227
	}
228
229
	public function settings_init() {
230
		global $wpdb;
231
		$this->xcloner_sanitization = $this->get_xcloner_container()->get_xcloner_sanitization();
0 ignored issues
show
Bug introduced by
The method get_xcloner_sanitization() does not seem to exist on object<Xcloner>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
232
233
		//ADDING MISSING OPTIONS
234
		if ( false == get_option( 'xcloner_mysql_settings_page' ) ) {
235
			add_option( 'xcloner_mysql_settings_page' );
236
		} // end if
237
238
		if ( false == get_option( 'xcloner_cron_settings_page' ) ) {
239
			add_option( 'xcloner_cron_settings_page' );
240
		} // end if
241
242
		if ( false == get_option( 'xcloner_system_settings_page' ) ) {
243
			add_option( 'xcloner_system_settings_page' );
244
		} // end if
245
246
		if ( false == get_option( 'xcloner_cleanup_settings_page' ) ) {
247
			add_option( 'xcloner_cleanup_settings_page' );
248
		} // end if
249
250
251
		//ADDING SETTING SECTIONS
252
		//GENERAL section
253
		add_settings_section(
254
			'xcloner_general_settings_group',
255
			__( ' ' ),
256
			array( $this, 'xcloner_settings_section_cb' ),
257
			'xcloner_settings_page'
258
		);
259
		//MYSQL section
260
		add_settings_section(
261
			'xcloner_mysql_settings_group',
262
			__( ' ' ),
263
			array( $this, 'xcloner_settings_section_cb' ),
264
			'xcloner_mysql_settings_page'
265
		);
266
267
		//SYSTEM section
268
		add_settings_section(
269
			'xcloner_system_settings_group',
270
			__( 'These are advanced options recommended for developers!', 'xcloner-backup-and-restore' ),
271
			array( $this, 'xcloner_settings_section_cb' ),
272
			'xcloner_system_settings_page'
273
		);
274
275
		//CLEANUP section
276
		add_settings_section(
277
			'xcloner_cleanup_settings_group',
278
			__( ' ' ),
279
			array( $this, 'xcloner_settings_section_cb' ),
280
			'xcloner_cleanup_settings_page'
281
		);
282
283
284
		//CRON section
285
		add_settings_section(
286
			'xcloner_cron_settings_group',
287
			__( ' ' ),
288
			array( $this, 'xcloner_settings_section_cb' ),
289
			'xcloner_cron_settings_page'
290
		);
291
292
293
		//REGISTERING THE 'GENERAL SECTION' FIELDS
294
		register_setting( 'xcloner_general_settings_group', 'xcloner_backup_compression_level', array(
295
			$this->xcloner_sanitization,
296
			"sanitize_input_as_int"
297
		) );
298
		add_settings_field(
299
			'xcloner_backup_compression_level',
300
			__( 'Backup Compression Level', 'xcloner-backup-and-restore' ),
301
			array( $this, 'do_form_range_field' ),
302
			'xcloner_settings_page',
303
			'xcloner_general_settings_group',
304
			array(
305
				'xcloner_backup_compression_level',
306
				__( 'Options between [0-9]. Value 0 means no compression, while 9 is maximum compression affecting cpu load', 'xcloner-backup-and-restore' ),
307
				0,
308
				9
309
			)
310
		);
311
312
		register_setting( 'xcloner_general_settings_group', 'xcloner_start_path', array(
313
			$this->xcloner_sanitization,
314
			"sanitize_input_as_absolute_path"
315
		) );
316
		add_settings_field(
317
			'xcloner_start_path',
318
			__( 'Backup Start Location', 'xcloner-backup-and-restore' ),
319
			array( $this, 'do_form_text_field' ),
320
			'xcloner_settings_page',
321
			'xcloner_general_settings_group',
322
			array(
323
				'xcloner_start_path',
324
				__( 'Base path location from where XCloner can start the Backup.', 'xcloner-backup-and-restore' ),
325
				$this->get_xcloner_start_path(),
326
				//'disabled'
327
			)
328
		);
329
330
		register_setting( 'xcloner_general_settings_group', 'xcloner_store_path', array(
331
            $this->xcloner_sanitization,
332
            "sanitize_input_as_absolute_path"
333
        ) );
334
        add_settings_field(
335
            'xcloner_store_path',
336
            __( 'Backup Storage Location', 'xcloner-backup-and-restore' ),
337
            array( $this, 'do_form_text_field' ),
338
            'xcloner_settings_page',
339
            'xcloner_general_settings_group',
340
            array(
341
                'xcloner_store_path',
342
                __( 'Location where XCloner will store the Backup archives.', 'xcloner-backup-and-restore' ),
343
                $this->get_xcloner_store_path(),
344
                //'disabled'
345
            )
346
        );
347
348
        register_setting( 'xcloner_general_settings_group', 'xcloner_encryption_key', array(
349
            $this->xcloner_sanitization,
350
            "sanitize_input_as_string"
351
        ) );
352
        add_settings_field(
353
            'xcloner_encryption_key',
354
            __( 'Backup Encryption Key', 'xcloner-backup-and-restore' ),
355
            array( $this, 'do_form_text_field' ),
356
            'xcloner_settings_page',
357
            'xcloner_general_settings_group',
358
            array(
359
                'xcloner_encryption_key',
360
                __( 'Backup Encryption Key used to Encrypt/Decrypt backups, you might want to save this somewhere else as well.', 'xcloner-backup-and-restore' ),
361
                $this->get_xcloner_encryption_key(),
362
                //'disabled'
363
            )
364
        );
365
366
		register_setting( 'xcloner_general_settings_group', 'xcloner_enable_log', array(
367
			$this->xcloner_sanitization,
368
			"sanitize_input_as_int"
369
		) );
370
		add_settings_field(
371
			'xcloner_enable_log',
372
			__( 'Enable XCloner Backup Log', 'xcloner-backup-and-restore' ),
373
			array( $this, 'do_form_switch_field' ),
374
			'xcloner_settings_page',
375
			'xcloner_general_settings_group',
376
			array(
377
				'xcloner_enable_log',
378
				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() )
379
			)
380
		);
381
382
		register_setting( 'xcloner_general_settings_group', 'xcloner_enable_pre_update_backup', array(
383
			$this->xcloner_sanitization,
384
			"sanitize_input_as_int"
385
		) );
386
		add_settings_field(
387
			'xcloner_enable_pre_update_backup',
388
			__( 'Generate Backups before Automatic WP Upgrades', 'xcloner-backup-and-restore' ),
389
			array( $this, 'do_form_switch_field' ),
390
			'xcloner_settings_page',
391
			'xcloner_general_settings_group',
392
			array(
393
				'xcloner_enable_pre_update_backup',
394
				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() )
395
			)
396
		);
397
398
		register_setting( 'xcloner_general_settings_group', 'xcloner_regex_exclude', array(
399
			$this->xcloner_sanitization,
400
			"sanitize_input_as_raw"
401
		) );
402
		add_settings_field(
403
			'xcloner_regex_exclude',
404
			__( 'Regex Exclude Files', 'xcloner-backup-and-restore' ),
405
			array( $this, 'do_form_textarea_field' ),
406
			'xcloner_settings_page',
407
			'xcloner_general_settings_group',
408
			array(
409
				'xcloner_regex_exclude',
410
				__( 'Regular expression match to exclude files and folders, example patterns provided below, one pattern per line', 'xcloner-backup-and-restore' ),
411
				//$this->get_xcloner_store_path(), 
412
				//'disabled'
413
			)
414
		);
415
416
		//REGISTERING THE 'MYSQL SECTION' FIELDS
417
		register_setting( 'xcloner_mysql_settings_group', 'xcloner_enable_mysql_backup', array(
418
			$this->xcloner_sanitization,
419
			"sanitize_input_as_int"
420
		) );
421
		add_settings_field(
422
			'xcloner_enable_mysql_backup',
423
			__( 'Enable Mysql Backup', 'xcloner-backup-and-restore' ),
424
			array( $this, 'do_form_switch_field' ),
425
			'xcloner_mysql_settings_page',
426
			'xcloner_mysql_settings_group',
427
			array(
428
				'xcloner_enable_mysql_backup',
429
				__( 'Enable Mysql Backup Option. If you don\'t want to backup the database, you can disable this.', 'xcloner-backup-and-restore' )
430
			)
431
		);
432
433
		register_setting( 'xcloner_mysql_settings_group', 'xcloner_backup_only_wp_tables' );
434
		add_settings_field(
435
			'xcloner_backup_only_wp_tables',
436
			__( 'Backup only WP tables', 'xcloner-backup-and-restore' ),
437
			array( $this, 'do_form_switch_field' ),
438
			'xcloner_mysql_settings_page',
439
			'xcloner_mysql_settings_group',
440
			array(
441
				'xcloner_backup_only_wp_tables',
442
				sprintf( __( 'Enable this if you only want to Backup only tables starting with \'%s\' prefix', 'xcloner-backup-and-restore' ), $this->get_table_prefix() )
443
			)
444
		);
445
446
		register_setting( 'xcloner_mysql_settings_group', 'xcloner_mysql_hostname', array(
447
			$this->xcloner_sanitization,
448
			"sanitize_input_as_raw"
449
		) );
450
		add_settings_field(
451
			'xcloner_mysql_hostname',
452
			__( 'Mysql Hostname', 'xcloner-backup-and-restore' ),
453
			array( $this, 'do_form_text_field' ),
454
			'xcloner_mysql_settings_page',
455
			'xcloner_mysql_settings_group',
456
			array(
457
				'xcloner_mysql_hostname',
458
				__( 'Wordpress mysql hostname', 'xcloner-backup-and-restore' ),
459
				$this->get_db_hostname(),
460
				'disabled'
461
			)
462
		);
463
464
		register_setting( 'xcloner_mysql_settings_group', 'xcloner_mysql_username', array(
465
			$this->xcloner_sanitization,
466
			"sanitize_input_as_raw"
467
		) );
468
		add_settings_field(
469
			'xcloner_mysql_username',
470
			__( 'Mysql Username', 'xcloner-backup-and-restore' ),
471
			array( $this, 'do_form_text_field' ),
472
			'xcloner_mysql_settings_page',
473
			'xcloner_mysql_settings_group',
474
			array(
475
				'xcloner_mysql_username',
476
				__( 'Wordpress mysql username', 'xcloner-backup-and-restore' ),
477
				$this->get_db_username(),
478
				'disabled'
479
			)
480
		);
481
482
		register_setting( 'xcloner_mysql_settings_group', 'xcloner_mysql_database', array(
483
			$this->xcloner_sanitization,
484
			"sanitize_input_as_raw"
485
		) );
486
		add_settings_field(
487
			'xcloner_mysql_database',
488
			__( 'Mysql Database', 'xcloner-backup-and-restore' ),
489
			array( $this, 'do_form_text_field' ),
490
			'xcloner_mysql_settings_page',
491
			'xcloner_mysql_settings_group',
492
			array(
493
				'xcloner_mysql_database',
494
				__( 'Wordpress mysql database', 'xcloner-backup-and-restore' ),
495
				$this->get_db_database(),
496
				'disabled'
497
			)
498
		);
499
500
		//REGISTERING THE 'SYSTEM SECTION' FIELDS
501
		register_setting( 'xcloner_system_settings_group', 'xcloner_size_limit_per_request', array(
502
			$this->xcloner_sanitization,
503
			"sanitize_input_as_int"
504
		) );
505
		add_settings_field(
506
			'xcloner_size_limit_per_request',
507
			__( 'Data Size Limit Per Request', 'xcloner-backup-and-restore' ),
508
			array( $this, 'do_form_range_field' ),
509
			'xcloner_system_settings_page',
510
			'xcloner_system_settings_group',
511
			array(
512
				'xcloner_size_limit_per_request',
513
				__( 'Use this option to set how much file data can XCloner backup in one AJAX request. Range 0-1024 MB', 'xcloner-backup-and-restore' ),
514
				0,
515
				1024
516
			)
517
		);
518
519
		register_setting( 'xcloner_system_settings_group', 'xcloner_files_to_process_per_request', array(
520
			$this->xcloner_sanitization,
521
			"sanitize_input_as_int"
522
		) );
523
		add_settings_field(
524
			'xcloner_files_to_process_per_request',
525
			__( 'Files To Process Per Request', 'xcloner-backup-and-restore' ),
526
			array( $this, 'do_form_range_field' ),
527
			'xcloner_system_settings_page',
528
			'xcloner_system_settings_group',
529
			array(
530
				'xcloner_files_to_process_per_request',
531
				__( 'Use this option to set how many files XCloner should process at one time before doing another AJAX call', 'xcloner-backup-and-restore' ),
532
				0,
533
				1000
534
			)
535
		);
536
537
		register_setting( 'xcloner_system_settings_group', 'xcloner_directories_to_scan_per_request', array(
538
			$this->xcloner_sanitization,
539
			"sanitize_input_as_int"
540
		) );
541
		add_settings_field(
542
			'xcloner_directories_to_scan_per_request',
543
			__( 'Directories To Scan Per Request', 'xcloner-backup-and-restore' ),
544
			array( $this, 'do_form_range_field' ),
545
			'xcloner_system_settings_page',
546
			'xcloner_system_settings_group',
547
			array(
548
				'xcloner_directories_to_scan_per_request',
549
				__( 'Use this option to set how many directories XCloner should scan at one time before doing another AJAX call', 'xcloner-backup-and-restore' ),
550
				0,
551
				1000
552
			)
553
		);
554
555
		register_setting( 'xcloner_system_settings_group', 'xcloner_database_records_per_request', array(
556
			$this->xcloner_sanitization,
557
			"sanitize_input_as_int"
558
		) );
559
		add_settings_field(
560
			'xcloner_database_records_per_request',
561
			__( 'Database Records Per Request', 'xcloner-backup-and-restore' ),
562
			array( $this, 'do_form_range_field' ),
563
			'xcloner_system_settings_page',
564
			'xcloner_system_settings_group',
565
			array(
566
				'xcloner_database_records_per_request',
567
				__( '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' ),
568
				0,
569
				100000
570
			)
571
		);
572
573
		/*register_setting('xcloner_system_settings_group', 'xcloner_diff_backup_recreate_period', array($this->xcloner_sanitization, "sanitize_input_as_int"));
574
	    add_settings_field(
575
	        'xcloner_diff_backup_recreate_period',
576
	       __('Differetial Backups Max Days','xcloner-backup-and-restore'),
577
	        array($this, 'do_form_number_field'),
578
	        'xcloner_system_settings_page',
579
	        'xcloner_system_settings_group',
580
	        array('xcloner_diff_backup_recreate_period',
581
	         __('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'), 
582
	         )
583
	    );*/
584
585
		register_setting( 'xcloner_system_settings_group', 'xcloner_exclude_files_larger_than_mb', array(
586
			$this->xcloner_sanitization,
587
			"sanitize_input_as_int"
588
		) );
589
		add_settings_field(
590
			'xcloner_exclude_files_larger_than_mb',
591
			__( 'Exclude files larger than (MB)', 'xcloner-backup-and-restore' ),
592
			array( $this, 'do_form_number_field' ),
593
			'xcloner_system_settings_page',
594
			'xcloner_system_settings_group',
595
			array(
596
				'xcloner_exclude_files_larger_than_mb',
597
				__( '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' ),
598
			)
599
		);
600
601
		register_setting( 'xcloner_system_settings_group', 'xcloner_split_backup_limit', array(
602
			$this->xcloner_sanitization,
603
			"sanitize_input_as_int"
604
		) );
605
		add_settings_field(
606
			'xcloner_split_backup_limit',
607
			__( 'Split Backup Archive Limit (MB)', 'xcloner-backup-and-restore' ),
608
			array( $this, 'do_form_number_field' ),
609
			'xcloner_system_settings_page',
610
			'xcloner_system_settings_group',
611
			array(
612
				'xcloner_split_backup_limit',
613
				__( 'Use this option to automatically split the backup archive into smaller parts. Range  0-10000 MB', 'xcloner-backup-and-restore' ),
614
			)
615
		);
616
617
		register_setting( 'xcloner_system_settings_group', 'xcloner_force_tmp_path_site_root' );
618
		add_settings_field(
619
			'xcloner_force_tmp_path_site_root',
620
			__( 'Force Temporary Path Within XCloner Storage', 'xcloner-backup-and-restore' ),
621
			array( $this, 'do_form_switch_field' ),
622
			'xcloner_system_settings_page',
623
			'xcloner_system_settings_group',
624
			array(
625
				'xcloner_force_tmp_path_site_root',
626
				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() )
627
			)
628
		);
629
630
        register_setting( 'xcloner_system_settings_group', 'xcloner_disable_email_notification' );
631
        add_settings_field(
632
            'xcloner_disable_email_notification',
633
            __( 'Disable Email Notifications', 'xcloner-backup-and-restore' ),
634
            array( $this, 'do_form_switch_field' ),
635
            'xcloner_system_settings_page',
636
            'xcloner_system_settings_group',
637
            array(
638
                'xcloner_disable_email_notification',
639
                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() )
640
            )
641
        );
642
643
		//REGISTERING THE 'CLEANUP SECTION' FIELDS
644
		register_setting( 'xcloner_cleanup_settings_group', 'xcloner_cleanup_retention_limit_days', array(
645
			$this->xcloner_sanitization,
646
			"sanitize_input_as_int"
647
		) );
648
		add_settings_field(
649
			'xcloner_cleanup_retention_limit_days',
650
			__( 'Cleanup by Date(days)', 'xcloner-backup-and-restore' ),
651
			array( $this, 'do_form_number_field' ),
652
			'xcloner_cleanup_settings_page',
653
			'xcloner_cleanup_settings_group',
654
			array(
655
				'xcloner_cleanup_retention_limit_days',
656
				__( 'Specify the maximum number of days a backup archive can be kept on the server. 0 disables this option', 'xcloner-backup-and-restore' )
657
			)
658
		);
659
660
		register_setting( 'xcloner_cleanup_settings_group', 'xcloner_cleanup_retention_limit_archives', array(
661
			$this->xcloner_sanitization,
662
			"sanitize_input_as_int"
663
		) );
664
		add_settings_field(
665
			'xcloner_cleanup_retention_limit_archives',
666
			__( 'Cleanup by Quantity', 'xcloner-backup-and-restore' ),
667
			array( $this, 'do_form_number_field' ),
668
			'xcloner_cleanup_settings_page',
669
			'xcloner_cleanup_settings_group',
670
			array(
671
				'xcloner_cleanup_retention_limit_archives',
672
				__( 'Specify the maximum number of backup archives to keep on the server. 0 disables this option', 'xcloner-backup-and-restore' )
673
			)
674
		);
675
676
		register_setting( 'xcloner_cleanup_settings_group', 'xcloner_cleanup_capacity_limit', array(
677
			$this->xcloner_sanitization,
678
			"sanitize_input_as_int"
679
		) );
680
		add_settings_field(
681
			'xcloner_cleanup_capacity_limit',
682
			__( 'Cleanup by Capacity(MB)', 'xcloner-backup-and-restore' ),
683
			array( $this, 'do_form_number_field' ),
684
			'xcloner_cleanup_settings_page',
685
			'xcloner_cleanup_settings_group',
686
			array(
687
				'xcloner_cleanup_capacity_limit',
688
				__( 'Remove oldest backups if all created backups exceed the configured limit in Megabytes. 0 disables this option', 'xcloner-backup-and-restore' )
689
			)
690
		);
691
692
		register_setting( 'xcloner_cleanup_settings_group', 'xcloner_cleanup_delete_after_remote_transfer', array(
693
			$this->xcloner_sanitization,
694
			"sanitize_input_as_int"
695
		) );
696
		add_settings_field(
697
			'xcloner_cleanup_delete_after_remote_transfer',
698
			__( 'Delete Backup After Remote Storage Transfer', 'xcloner-backup-and-restore' ),
699
			array( $this, 'do_form_switch_field' ),
700
			'xcloner_cleanup_settings_page',
701
			'xcloner_cleanup_settings_group',
702
			array(
703
				'xcloner_cleanup_delete_after_remote_transfer',
704
				__( 'Remove backup created automatically from local storage after sending the backup to Remote Storage', 'xcloner-backup-and-restore' )
705
			)
706
		);
707
708
		//REGISTERING THE 'CRON SECTION' FIELDS
709
		register_setting( 'xcloner_cron_settings_group', 'xcloner_cron_frequency' );
710
		add_settings_field(
711
			'xcloner_cron_frequency',
712
			__( 'Cron frequency', 'xcloner-backup-and-restore' ),
713
			array( $this, 'do_form_text_field' ),
714
			'xcloner_cron_settings_page',
715
			'xcloner_cron_settings_group',
716
			array(
717
				'xcloner_cron_frequency',
718
				__( 'Cron frequency' )
719
			)
720
		);
721
	}
722
723
724
725
726
	/**
727
	 * callback functions
728
	 */
729
730
	// section content cb
731
	public function xcloner_settings_section_cb() {
732
		//echo '<p>WPOrg Section Introduction.</p>';
733
	}
734
735
	// text field content cb
736 View Code Duplication
	public function do_form_text_field( $params ) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
737
		if ( ! isset( $params['3'] ) ) {
738
			$params[3] = 0;
739
		}
740
		if ( ! isset( $params['2'] ) ) {
741
			$params[2] = 0;
742
		}
743
744
		list( $fieldname, $label, $value, $disabled ) = $params;
745
746
		if ( ! $value ) {
747
			$value = get_option( $fieldname );
748
		}
749
		// output the field
750
		?>
751
        <div class="row">
752
            <div class="input-field col s10 m10 l8">
753
                <input class="validate" <?php echo ( $disabled ) ? "disabled" : "" ?> name="<?php echo $fieldname ?>"
754
                       id="<?php echo $fieldname ?>" type="text" class="validate"
755
                       value="<?php echo isset( $value ) ? esc_attr( $value ) : ''; ?>">
756
            </div>
757
            <div class="col s2 m2 ">
758
                <a class="btn-floating tooltipped btn-small" data-position="left" data-delay="50"
759
                   data-tooltip="<?php echo $label ?>" data-tooltip-id=""><i class="material-icons">help_outline</i></a>
760
            </div>
761
        </div>
762
763
764
		<?php
765
	}
766
767
	// textarea field content cb
768
	public function do_form_textarea_field( $params ) {
769
		if ( ! isset( $params['3'] ) ) {
770
			$params[3] = 0;
771
		}
772
		if ( ! isset( $params['2'] ) ) {
773
			$params[2] = 0;
774
		}
775
776
		list( $fieldname, $label, $value, $disabled ) = $params;
777
778
		if ( ! $value ) {
779
			$value = get_option( $fieldname );
780
		}
781
		// output the field
782
		?>
783
        <div class="row">
784
            <div class="input-field col s10 m10 l8">
785
                <textarea class="validate" <?php echo ( $disabled ) ? "disabled" : "" ?> name="<?php echo $fieldname ?>"
786
                          id="<?php echo $fieldname ?>" type="text" class="validate"
787
                          value=""><?php echo isset( $value ) ? esc_attr( $value ) : ''; ?></textarea>
788
            </div>
789
            <div class="col s2 m2 ">
790
                <a class="btn-floating tooltipped btn-small" data-position="center" data-html="true" data-delay="50"
791
                   data-tooltip="<?php echo $label ?>" data-tooltip-id=""><i class="material-icons">help_outline</i></a>
792
            </div>
793
            <div class="col s12">
794
                <ul class="xcloner_regex_exclude_limit">
795
                    <li>Exclude all except .php file: <span
796
                                class="regex_pattern"><?php echo htmlentities( '(.*)\.(.+)$(?<!(php))' ) ?></span></li>
797
                    <li>Exclude all except .php and .txt: <span
798
                                class="regex_pattern"> <?php echo htmlentities( '(.*)\.(.+)$(?<!(php|txt))' ) ?></span>
799
                    </li>
800
                    <li>Exclude all .avi files: <span
801
                                class="regex_pattern"> <?php echo htmlentities( '(.*)\.(.+)$(?<=(avi))' ) ?></span></li>
802
                    <li>Exclude all .jpg,.gif and .png files: <span
803
                                class="regex_pattern"> <?php echo htmlentities( '(.*)\.(.+)$(?<=(gif|png|jpg))' ) ?></span>
804
                    </li>
805
                    <li>Exclude all .svn and .git: <span
806
                                class="regex_pattern"> <?php echo htmlentities( '(.*)\.(svn|git)(.*)$' ) ?></span></li>
807
                    <li>Exclude root directory /test: <span
808
                                class="regex_pattern"> <?php echo htmlentities( '\/test(.*)$' ) ?></span> or <span
809
                                class="regex_pattern"> <?php echo htmlentities( 'test(.*)$' ) ?></span></li>
810
                    <li>Exclude the wp-admin folder: <span
811
                                class="regex_pattern"> <?php echo htmlentities( '(\/wp-admin)(.*)$' ) ?></span></li>
812
                    <li>Exclude the wp-content/uploads folder: <span
813
                                class="regex_pattern"> <?php echo htmlentities( '(\/wp-content\/uploads)(.*)$' ) ?></span>
814
                    </li>
815
                    <li>Exclude the wp-admin, wp-includes and wp-config.php: <span
816
                                class="regex_pattern"> <?php echo htmlentities( '\/(wp-admin|wp-includes|wp-config.php)(.*)$' ) ?></span>
817
                    </li>
818
                    <li>Exclude wp-content/updraft and wp/content/uploads/wp_all_backup folder :<span
819
                                class="regex_pattern">\/(wp-content\/updraft|\/wp-content\/uploads\/wp_all_backup)(.*)$</span>
820
                    </li>
821
                    <li>Exclude all cache folders from wp-content/ and it's subdirectories: <span
822
                                class="regex_pattern"> <?php echo htmlentities( '\/wp-content(.*)\/cache($|\/)(.*)' ) ?></span>
823
                    </li>
824
                    <li>Exclude wp-content/cache/ folder: <span
825
                                class="regex_pattern"> <?php echo htmlentities( '\/wp-content\/cache(.*)' ) ?></span>
826
                    </li>
827
                    <li>Exclude all error_log files: <span
828
                                class="regex_pattern"> <?php echo htmlentities( '(.*)error_log$' ) ?></span></li>
829
                </ul>
830
            </div>
831
        </div>
832
833
834
		<?php
835
	}
836
837
	// number field content cb
838 View Code Duplication
	public function do_form_number_field( $params ) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
839
		if ( ! isset( $params['3'] ) ) {
840
			$params[3] = 0;
841
		}
842
		if ( ! isset( $params['2'] ) ) {
843
			$params[2] = 0;
844
		}
845
846
		list( $fieldname, $label, $value, $disabled ) = $params;
847
848
		if ( ! $value ) {
849
			$value = get_option( $fieldname );
850
		}
851
		// output the field
852
		?>
853
        <div class="row">
854
            <div class="input-field col s10 m5 l3">
855
                <input class="validate" <?php echo ( $disabled ) ? "disabled" : "" ?> name="<?php echo $fieldname ?>"
856
                       id="<?php echo $fieldname ?>" type="number" class="validate"
857
                       value="<?php echo isset( $value ) ? esc_attr( $value ) : ''; ?>">
858
            </div>
859
            <div class="col s2 m2 ">
860
                <a class="btn-floating tooltipped btn-small" data-html="true" data-position="center" data-delay="50"
861
                   data-tooltip="<?php echo $label ?>" data-tooltip-id=""><i class="material-icons">help_outline</i></a>
862
            </div>
863
        </div>
864
865
866
		<?php
867
	}
868
869
	public function do_form_range_field( $params ) {
870
		if ( ! isset( $params['4'] ) ) {
871
			$params[4] = 0;
872
		}
873
874
		list( $fieldname, $label, $range_start, $range_end, $disabled ) = $params;
875
		$value = get_option( $fieldname );
876
		?>
877
        <div class="row">
878
            <div class="input-field col s10 m10 l8">
879
                <p class="range-field">
880
                    <input <?php echo ( $disabled ) ? "disabled" : "" ?> type="range" name="<?php echo $fieldname ?>"
881
                                                                         id="<?php echo $fieldname ?>"
882
                                                                         min="<?php echo $range_start ?>"
883
                                                                         max="<?php echo $range_end ?>"
884
                                                                         value="<?php echo isset( $value ) ? esc_attr( $value ) : ''; ?>"/>
885
                </p>
886
            </div>
887
            <div class="col s2 m2 ">
888
                <a class="btn-floating tooltipped btn-small" data-html="true" data-position="center" data-delay="50"
889
                   data-tooltip="<?php echo $label ?>" data-tooltip-id=""><i class="material-icons">help_outline</i></a>
890
            </div>
891
        </div>
892
		<?php
893
	}
894
895
896
	public function do_form_switch_field( $params ) {
897
		if ( ! isset( $params['2'] ) ) {
898
			$params[2] = 0;
899
		}
900
		list( $fieldname, $label, $disabled ) = $params;
901
		$value = get_option( $fieldname );
902
		?>
903
        <div class="row">
904
            <div class="input-field col s10 m5 l3">
905
                <div class="switch">
906
                    <label>
907
                        Off
908
                        <input <?php echo ( $disabled ) ? "disabled" : "" ?> type="checkbox"
909
                                                                             name="<?php echo $fieldname ?>"
910
                                                                             id="<?php echo $fieldname ?>"
911
                                                                             value="1" <?php echo ( $value ) ? 'checked="checked"' : ''; ?>
912
                        ">
913
                        <span class="lever"></span>
914
                        On
915
                    </label>
916
                </div>
917
            </div>
918
            <div class="col s2 m2">
919
                <a class="btn-floating tooltipped btn-small" data-position="center" data-delay="50"
920
                   data-tooltip="<?php echo $label ?>" data-tooltip-id=""><i class="material-icons">help_outline</i></a>
921
            </div>
922
        </div>
923
		<?php
924
	}
925
}
926