| @@ -1,12 +1,14 @@ | ||
| 1 | 1 | <?php | 
| 2 | 2 | |
| 3 | -if(!isset($argv)) | |
| 3 | +if(!isset($argv)) { | |
| 4 | 4 |  	die('Access denied from web.'); | 
| 5 | +} | |
| 5 | 6 | |
| 6 | 7 | $file = 'restore/vendor.phar'; | 
| 7 | 8 | |
| 8 | -if(file_exists($file)) | |
| 9 | +if(file_exists($file)) { | |
| 9 | 10 | unlink($file); | 
| 11 | +} | |
| 10 | 12 | $phar2 = new Phar($file, 0, 'vendor.phar'); | 
| 11 | 13 | |
| 12 | 14 | // add all files in the project, only include php files | 
| @@ -24,7 +24,7 @@ | ||
| 24 | 24 | |
| 25 | 25 |  		try{ | 
| 26 | 26 | $option = Util::normalizePath($path); | 
| 27 | -		}catch(Exception $e){ | |
| 27 | +		} catch(Exception $e){ | |
| 28 | 28 |  			add_settings_error('xcloner_error_message', '', __($e->getMessage()), 'error'); | 
| 29 | 29 | } | 
| 30 | 30 | |
| @@ -69,44 +69,57 @@ | ||
| 69 | 69 | update_option( "xcloner_db_version", $xcloner_db_version ); | 
| 70 | 70 | } | 
| 71 | 71 | |
| 72 | -		if(!get_option('xcloner_backup_compression_level')) | |
| 73 | -			update_option('xcloner_backup_compression_level', 0); | |
| 72 | +		if(!get_option('xcloner_backup_compression_level')) { | |
| 73 | +					update_option('xcloner_backup_compression_level', 0); | |
| 74 | + } | |
| 74 | 75 | |
| 75 | -		if(!get_option('xcloner_enable_log')) | |
| 76 | -			update_option('xcloner_enable_log', 1); | |
| 76 | +		if(!get_option('xcloner_enable_log')) { | |
| 77 | +					update_option('xcloner_enable_log', 1); | |
| 78 | + } | |
| 77 | 79 | |
| 78 | -		if(!get_option('xcloner_enable_mysql_backup')) | |
| 79 | -			update_option('xcloner_enable_mysql_backup', 1); | |
| 80 | +		if(!get_option('xcloner_enable_mysql_backup')) { | |
| 81 | +					update_option('xcloner_enable_mysql_backup', 1); | |
| 82 | + } | |
| 80 | 83 | |
| 81 | -		if(!get_option('xcloner_system_settings_page')) | |
| 82 | -			update_option('xcloner_system_settings_page', 100); | |
| 84 | +		if(!get_option('xcloner_system_settings_page')) { | |
| 85 | +					update_option('xcloner_system_settings_page', 100); | |
| 86 | + } | |
| 83 | 87 | |
| 84 | -		if(!get_option('xcloner_files_to_process_per_request')) | |
| 85 | -			update_option('xcloner_files_to_process_per_request', 250); | |
| 88 | +		if(!get_option('xcloner_files_to_process_per_request')) { | |
| 89 | +					update_option('xcloner_files_to_process_per_request', 250); | |
| 90 | + } | |
| 86 | 91 | |
| 87 | -		if(!get_option('xcloner_database_records_per_request')) | |
| 88 | -			update_option('xcloner_database_records_per_request', 10000); | |
| 92 | +		if(!get_option('xcloner_database_records_per_request')) { | |
| 93 | +					update_option('xcloner_database_records_per_request', 10000); | |
| 94 | + } | |
| 89 | 95 | |
| 90 | -		if(!get_option('xcloner_exclude_files_larger_than_mb')) | |
| 91 | -			update_option('xcloner_exclude_files_larger_than_mb', 0); | |
| 96 | +		if(!get_option('xcloner_exclude_files_larger_than_mb')) { | |
| 97 | +					update_option('xcloner_exclude_files_larger_than_mb', 0); | |
| 98 | + } | |
| 92 | 99 | |
| 93 | -		if(!get_option('xcloner_split_backup_limit')) | |
| 94 | -			update_option('xcloner_split_backup_limit', 2048); | |
| 100 | +		if(!get_option('xcloner_split_backup_limit')) { | |
| 101 | +					update_option('xcloner_split_backup_limit', 2048); | |
| 102 | + } | |
| 95 | 103 | |
| 96 | -		if(!get_option('xcloner_size_limit_per_request')) | |
| 97 | -			update_option('xcloner_size_limit_per_request', 50); | |
| 104 | +		if(!get_option('xcloner_size_limit_per_request')) { | |
| 105 | +					update_option('xcloner_size_limit_per_request', 50); | |
| 106 | + } | |
| 98 | 107 | |
| 99 | -		if(!get_option('xcloner_cleanup_retention_limit_days')) | |
| 100 | -			update_option('xcloner_cleanup_retention_limit_days', 60); | |
| 108 | +		if(!get_option('xcloner_cleanup_retention_limit_days')) { | |
| 109 | +					update_option('xcloner_cleanup_retention_limit_days', 60); | |
| 110 | + } | |
| 101 | 111 | |
| 102 | -		if(!get_option('xcloner_cleanup_retention_limit_archives')) | |
| 103 | -			update_option('xcloner_cleanup_retention_limit_archives', 100); | |
| 112 | +		if(!get_option('xcloner_cleanup_retention_limit_archives')) { | |
| 113 | +					update_option('xcloner_cleanup_retention_limit_archives', 100); | |
| 114 | + } | |
| 104 | 115 | |
| 105 | -		if(!get_option('xcloner_directories_to_scan_per_request')) | |
| 106 | -			update_option('xcloner_directories_to_scan_per_request', 25); | |
| 116 | +		if(!get_option('xcloner_directories_to_scan_per_request')) { | |
| 117 | +					update_option('xcloner_directories_to_scan_per_request', 25); | |
| 118 | + } | |
| 107 | 119 | |
| 108 | -		if(!get_option('xcloner_regex_exclude')) | |
| 109 | -			update_option('xcloner_regex_exclude', "(wp-content\/updraft|wp-content\/uploads\/wp_all_backup)(.*)$".PHP_EOL."(.*)\.(svn|git)(.*)$".PHP_EOL."wp-content\/cache(.*)$"); | |
| 120 | +		if(!get_option('xcloner_regex_exclude')) { | |
| 121 | +					update_option('xcloner_regex_exclude', "(wp-content\/updraft|wp-content\/uploads\/wp_all_backup)(.*)$".PHP_EOL."(.*)\.(svn|git)(.*)$".PHP_EOL."wp-content\/cache(.*)$"); | |
| 122 | + } | |
| 110 | 123 | |
| 111 | 124 | } | 
| 112 | 125 | |
| @@ -8,26 +8,29 @@ discard block | ||
| 8 | 8 | |
| 9 | 9 | public function __construct($hash = "") | 
| 10 | 10 |  	{ | 
| 11 | - if(isset($hash)) | |
| 12 | - $this->set_hash($hash); | |
| 11 | +		if(isset($hash)) { | |
| 12 | + $this->set_hash($hash); | |
| 13 | + } | |
| 13 | 14 | } | 
| 14 | 15 | |
| 15 | 16 | public function get_logger_filename($include_hash = 0) | 
| 16 | 17 |  	{ | 
| 17 | - if($include_hash) | |
| 18 | - $filename = sprintf($this->logger_file_hash, $this->get_hash()); | |
| 19 | - else | |
| 20 | - $filename = sprintf($this->logger_file, $this->get_server_unique_hash(5)); | |
| 18 | +		if($include_hash) { | |
| 19 | + $filename = sprintf($this->logger_file_hash, $this->get_hash()); | |
| 20 | +		} else { | |
| 21 | + $filename = sprintf($this->logger_file, $this->get_server_unique_hash(5)); | |
| 22 | + } | |
| 21 | 23 | |
| 22 | 24 | return $filename; | 
| 23 | 25 | } | 
| 24 | 26 | |
| 25 | 27 | public function get_xcloner_start_path() | 
| 26 | 28 |  	{ | 
| 27 | -		if(!get_option('xcloner_start_path') or !is_dir(get_option('xcloner_start_path'))) | |
| 28 | - $path = realpath(ABSPATH); | |
| 29 | - else | |
| 30 | -			$path = get_option('xcloner_start_path'); | |
| 29 | +		if(!get_option('xcloner_start_path') or !is_dir(get_option('xcloner_start_path'))) { | |
| 30 | + $path = realpath(ABSPATH); | |
| 31 | +		} else { | |
| 32 | +					$path = get_option('xcloner_start_path'); | |
| 33 | + } | |
| 31 | 34 | |
| 32 | 35 | return $path; | 
| 33 | 36 | } | 
| @@ -41,10 +44,11 @@ discard block | ||
| 41 | 44 | |
| 42 | 45 | public function get_xcloner_store_path() | 
| 43 | 46 |  	{ | 
| 44 | -		if(!get_option('xcloner_store_path')  or !is_dir(get_option('xcloner_store_path'))) | |
| 45 | - $path = realpath(XCLONER_STORAGE_PATH); | |
| 46 | - else | |
| 47 | -			$path = get_option('xcloner_store_path'); | |
| 47 | +		if(!get_option('xcloner_store_path')  or !is_dir(get_option('xcloner_store_path'))) { | |
| 48 | + $path = realpath(XCLONER_STORAGE_PATH); | |
| 49 | +		} else { | |
| 50 | +					$path = get_option('xcloner_store_path'); | |
| 51 | + } | |
| 48 | 52 | |
| 49 | 53 | return $path; | 
| 50 | 54 | } | 
| @@ -64,16 +68,18 @@ discard block | ||
| 64 | 68 | @chmod($path, 0777); | 
| 65 | 69 | } | 
| 66 | 70 | |
| 67 | -		if(!is_dir($path) or !is_writeable($path) or get_option('xcloner_force_tmp_path_site_root')) | |
| 68 | - $path = $this->get_xcloner_store_path().DS.".".$this->get_xcloner_tmp_path_suffix(); | |
| 71 | +		if(!is_dir($path) or !is_writeable($path) or get_option('xcloner_force_tmp_path_site_root')) { | |
| 72 | + $path = $this->get_xcloner_store_path().DS.".".$this->get_xcloner_tmp_path_suffix(); | |
| 73 | + } | |
| 69 | 74 | |
| 70 | 75 | return $path; | 
| 71 | 76 | } | 
| 72 | 77 | |
| 73 | 78 | public function get_enable_mysql_backup() | 
| 74 | 79 |  	{ | 
| 75 | -		if(get_option('xcloner_enable_mysql_backup')) | |
| 76 | - return true; | |
| 80 | +		if(get_option('xcloner_enable_mysql_backup')) { | |
| 81 | + return true; | |
| 82 | + } | |
| 77 | 83 | |
| 78 | 84 | return false; | 
| 79 | 85 | } | 
| @@ -82,10 +88,11 @@ discard block | ||
| 82 | 88 |  	{ | 
| 83 | 89 | if(!$ext) | 
| 84 | 90 |  		{ | 
| 85 | -			if(get_option('xcloner_backup_compression_level')) | |
| 86 | - $ext = ".tgz"; | |
| 87 | - else | |
| 88 | - $ext = ".tar"; | |
| 91 | +			if(get_option('xcloner_backup_compression_level')) { | |
| 92 | + $ext = ".tgz"; | |
| 93 | +			} else { | |
| 94 | + $ext = ".tar"; | |
| 95 | + } | |
| 89 | 96 | } | 
| 90 | 97 | return ($this->get_hash()).$ext; | 
| 91 | 98 | } | 
| @@ -111,8 +118,9 @@ discard block | ||
| 111 | 118 | |
| 112 | 119 | public function set_hash($hash = "") | 
| 113 | 120 |  	{ | 
| 114 | - if(substr($hash, 0, 1) != "-" and strlen($hash)) | |
| 115 | - $hash = "-".$hash; | |
| 121 | +		if(substr($hash, 0, 1) != "-" and strlen($hash)) { | |
| 122 | + $hash = "-".$hash; | |
| 123 | + } | |
| 116 | 124 | |
| 117 | 125 | $this->hash = substr( $hash, 0, 6); | 
| 118 | 126 | |
| @@ -132,8 +140,9 @@ discard block | ||
| 132 | 140 |  	{ | 
| 133 | 141 | global $wpdb; | 
| 134 | 142 | |
| 135 | -		if(!$data = get_option('xcloner_mysql_hostname')) | |
| 136 | - $data = $wpdb->dbhost; | |
| 143 | +		if(!$data = get_option('xcloner_mysql_hostname')) { | |
| 144 | + $data = $wpdb->dbhost; | |
| 145 | + } | |
| 137 | 146 | |
| 138 | 147 | return $data; | 
| 139 | 148 | } | 
| @@ -142,8 +151,9 @@ discard block | ||
| 142 | 151 |  	{ | 
| 143 | 152 | global $wpdb; | 
| 144 | 153 | |
| 145 | -		if(!$data = get_option('xcloner_mysql_username')) | |
| 146 | - $data = $wpdb->dbuser; | |
| 154 | +		if(!$data = get_option('xcloner_mysql_username')) { | |
| 155 | + $data = $wpdb->dbuser; | |
| 156 | + } | |
| 147 | 157 | |
| 148 | 158 | return $data; | 
| 149 | 159 | } | 
| @@ -152,8 +162,9 @@ discard block | ||
| 152 | 162 |  	{ | 
| 153 | 163 | global $wpdb; | 
| 154 | 164 | |
| 155 | -		if(!$data = get_option('xcloner_mysql_password')) | |
| 156 | - $data = $wpdb->dbpassword; | |
| 165 | +		if(!$data = get_option('xcloner_mysql_password')) { | |
| 166 | + $data = $wpdb->dbpassword; | |
| 167 | + } | |
| 157 | 168 | |
| 158 | 169 | return $data; | 
| 159 | 170 | } | 
| @@ -162,8 +173,9 @@ discard block | ||
| 162 | 173 |  	{ | 
| 163 | 174 | global $wpdb; | 
| 164 | 175 | |
| 165 | -		if(!$data = get_option('xcloner_mysql_database')) | |
| 166 | - $data = $wpdb->dbname; | |
| 176 | +		if(!$data = get_option('xcloner_mysql_database')) { | |
| 177 | + $data = $wpdb->dbname; | |
| 178 | + } | |
| 167 | 179 | |
| 168 | 180 | return $data; | 
| 169 | 181 | } | 
| @@ -186,8 +198,9 @@ discard block | ||
| 186 | 198 |  	{ | 
| 187 | 199 | $hash = md5(get_home_url().__DIR__); | 
| 188 | 200 | |
| 189 | - if($strlen) | |
| 190 | - $hash = substr($hash, 0, $strlen); | |
| 201 | +		if($strlen) { | |
| 202 | + $hash = substr($hash, 0, $strlen); | |
| 203 | + } | |
| 191 | 204 | |
| 192 | 205 | return $hash; | 
| 193 | 206 | } | 
| @@ -554,15 +567,18 @@ discard block | ||
| 554 | 567 | // text field content cb | 
| 555 | 568 | public function do_form_text_field($params) | 
| 556 | 569 |  	{ | 
| 557 | - if(!isset($params['3'])) | |
| 558 | - $params[3] = 0; | |
| 559 | - if(!isset($params['2'])) | |
| 560 | - $params[2] = 0; | |
| 570 | +		if(!isset($params['3'])) { | |
| 571 | + $params[3] = 0; | |
| 572 | + } | |
| 573 | +		if(!isset($params['2'])) { | |
| 574 | + $params[2] = 0; | |
| 575 | + } | |
| 561 | 576 | |
| 562 | 577 | list($fieldname, $label, $value, $disabled) = $params; | 
| 563 | 578 | |
| 564 | - if(!$value) | |
| 565 | - $value = get_option($fieldname); | |
| 579 | +		if(!$value) { | |
| 580 | + $value = get_option($fieldname); | |
| 581 | + } | |
| 566 | 582 | // output the field | 
| 567 | 583 | ?> | 
| 568 | 584 | <div class="row"> | 
| @@ -581,15 +597,18 @@ discard block | ||
| 581 | 597 | // textarea field content cb | 
| 582 | 598 | public function do_form_textarea_field($params) | 
| 583 | 599 |  	{ | 
| 584 | - if(!isset($params['3'])) | |
| 585 | - $params[3] = 0; | |
| 586 | - if(!isset($params['2'])) | |
| 587 | - $params[2] = 0; | |
| 600 | +		if(!isset($params['3'])) { | |
| 601 | + $params[3] = 0; | |
| 602 | + } | |
| 603 | +		if(!isset($params['2'])) { | |
| 604 | + $params[2] = 0; | |
| 605 | + } | |
| 588 | 606 | |
| 589 | 607 | list($fieldname, $label, $value, $disabled) = $params; | 
| 590 | 608 | |
| 591 | - if(!$value) | |
| 592 | - $value = get_option($fieldname); | |
| 609 | +		if(!$value) { | |
| 610 | + $value = get_option($fieldname); | |
| 611 | + } | |
| 593 | 612 | // output the field | 
| 594 | 613 | ?> | 
| 595 | 614 | <div class="row"> | 
| @@ -624,15 +643,18 @@ discard block | ||
| 624 | 643 | // number field content cb | 
| 625 | 644 | public function do_form_number_field($params) | 
| 626 | 645 |  	{ | 
| 627 | - if(!isset($params['3'])) | |
| 628 | - $params[3] = 0; | |
| 629 | - if(!isset($params['2'])) | |
| 630 | - $params[2] = 0; | |
| 646 | +		if(!isset($params['3'])) { | |
| 647 | + $params[3] = 0; | |
| 648 | + } | |
| 649 | +		if(!isset($params['2'])) { | |
| 650 | + $params[2] = 0; | |
| 651 | + } | |
| 631 | 652 | |
| 632 | 653 | list($fieldname, $label, $value, $disabled) = $params; | 
| 633 | 654 | |
| 634 | - if(!$value) | |
| 635 | - $value = get_option($fieldname); | |
| 655 | +		if(!$value) { | |
| 656 | + $value = get_option($fieldname); | |
| 657 | + } | |
| 636 | 658 | // output the field | 
| 637 | 659 | ?> | 
| 638 | 660 | <div class="row"> | 
| @@ -650,8 +672,9 @@ discard block | ||
| 650 | 672 | |
| 651 | 673 | public function do_form_range_field($params) | 
| 652 | 674 |  	{ | 
| 653 | - if(!isset($params['4'])) | |
| 654 | - $params[4] = 0; | |
| 675 | +		if(!isset($params['4'])) { | |
| 676 | + $params[4] = 0; | |
| 677 | + } | |
| 655 | 678 | |
| 656 | 679 | list($fieldname, $label, $range_start, $range_end, $disabled) = $params; | 
| 657 | 680 | $value = get_option($fieldname); | 
| @@ -672,8 +695,9 @@ discard block | ||
| 672 | 695 | |
| 673 | 696 | public function do_form_switch_field($params) | 
| 674 | 697 |  	{ | 
| 675 | - if(!isset($params['2'])) | |
| 676 | - $params[2] = 0; | |
| 698 | +		if(!isset($params['2'])) { | |
| 699 | + $params[2] = 0; | |
| 700 | + } | |
| 677 | 701 | list($fieldname, $label, $disabled) = $params; | 
| 678 | 702 | $value = get_option($fieldname); | 
| 679 | 703 | ?> | 
| @@ -27,8 +27,9 @@ discard block | ||
| 27 | 27 | global $wpdb; | 
| 28 | 28 | |
| 29 | 29 | error_reporting(0); | 
| 30 | - if( ob_get_length() ) | |
| 31 | - ob_end_clean(); | |
| 30 | +		if( ob_get_length() ) { | |
| 31 | + ob_end_clean(); | |
| 32 | + } | |
| 32 | 33 | ob_start(); | 
| 33 | 34 | |
| 34 | 35 | $wpdb->show_errors = false; | 
| @@ -38,10 +39,11 @@ discard block | ||
| 38 | 39 | //generating the hash suffix for tmp xcloner store folder | 
| 39 | 40 |  		if(isset($_POST['hash'])){ | 
| 40 | 41 | |
| 41 | - if($_POST['hash'] == "generate_hash") | |
| 42 | - $this->xcloner_settings->generate_new_hash(); | |
| 43 | - else | |
| 44 | - $this->xcloner_settings->set_hash($_POST['hash']); | |
| 42 | +			if($_POST['hash'] == "generate_hash") { | |
| 43 | + $this->xcloner_settings->generate_new_hash(); | |
| 44 | +			} else { | |
| 45 | + $this->xcloner_settings->set_hash($_POST['hash']); | |
| 46 | + } | |
| 45 | 47 | } | 
| 46 | 48 | |
| 47 | 49 |  		$this->logger 					= new XCloner_Logger("xcloner_api", $this->xcloner_settings->get_hash()); | 
| @@ -78,7 +80,7 @@ discard block | ||
| 78 | 80 | //$xcloner_db = new XCloner_Database($data['dbUsername'], $data['dbPassword'], $data['dbDatabase'], $data['dbHostname']); | 
| 79 | 81 | $this->xcloner_database->init($data); | 
| 80 | 82 | |
| 81 | - }catch(Exception $e) | |
| 83 | + } catch(Exception $e) | |
| 82 | 84 |  		{ | 
| 83 | 85 | $this->send_response($e->getMessage()); | 
| 84 | 86 | $this->logger->error($e->getMessage()); | 
| @@ -106,8 +108,9 @@ discard block | ||
| 106 | 108 | $params = array(); | 
| 107 | 109 | $schedule = array(); | 
| 108 | 110 | |
| 109 | - if(isset($_POST['data'])) | |
| 110 | - $params = json_decode(stripslashes($_POST['data'])); | |
| 111 | +		if(isset($_POST['data'])) { | |
| 112 | + $params = json_decode(stripslashes($_POST['data'])); | |
| 113 | + } | |
| 111 | 114 | |
| 112 | 115 | $this->process_params($params); | 
| 113 | 116 | |
| @@ -130,8 +133,9 @@ discard block | ||
| 130 | 133 |  			{ | 
| 131 | 134 |  					$table = str_replace("\r","", $table); | 
| 132 | 135 |  					$data = explode(".", $table); | 
| 133 | - if(isset($data[1])) | |
| 134 | - $return[$data[0]][] = $data[1]; | |
| 136 | +					if(isset($data[1])) { | |
| 137 | + $return[$data[0]][] = $data[1]; | |
| 138 | + } | |
| 135 | 139 | } | 
| 136 | 140 | |
| 137 | 141 | $this->form_params['database'] = ($return); | 
| @@ -142,8 +146,9 @@ discard block | ||
| 142 | 146 | foreach($excluded_files as $file) | 
| 143 | 147 |  			{ | 
| 144 | 148 |  				$file = str_replace("\r","", $file); | 
| 145 | - if($file) | |
| 146 | - $return[] = $file; | |
| 149 | +				if($file) { | |
| 150 | + $return[] = $file; | |
| 151 | + } | |
| 147 | 152 | } | 
| 148 | 153 | |
| 149 | 154 | $this->form_params['excluded_files'] = ($return); | 
| @@ -153,19 +158,21 @@ discard block | ||
| 153 | 158 | |
| 154 | 159 | $schedule['start_at'] = $this->form_params['backup_params']['start_at'] ; | 
| 155 | 160 | |
| 156 | - if(!isset($_POST['status'])) | |
| 157 | - $schedule['status'] = 0; | |
| 158 | - else | |
| 159 | - $schedule['status'] = $this->xcloner_sanitization->sanitize_input_as_int($_POST['status']); | |
| 160 | -		}else{ | |
| 161 | +			if(!isset($_POST['status'])) { | |
| 162 | + $schedule['status'] = 0; | |
| 163 | +			} else { | |
| 164 | + $schedule['status'] = $this->xcloner_sanitization->sanitize_input_as_int($_POST['status']); | |
| 165 | + } | |
| 166 | +		} else{ | |
| 161 | 167 | |
| 162 | 168 | $schedule['status'] = 1; | 
| 163 | 169 | $schedule['start_at'] = strtotime($this->form_params['backup_params']['schedule_start_date'] . | 
| 164 | 170 | " ".$this->form_params['backup_params']['schedule_start_time']); | 
| 165 | 171 | } | 
| 166 | 172 | |
| 167 | - if(!$schedule['start_at']) | |
| 168 | - $schedule['start_at'] = time(); | |
| 173 | +		if(!$schedule['start_at']) { | |
| 174 | + $schedule['start_at'] = time(); | |
| 175 | + } | |
| 169 | 176 | |
| 170 | 177 |  		$schedule['start_at'] = date('Y-m-d H:i:s', $schedule['start_at']);	 | 
| 171 | 178 | |
| @@ -185,7 +192,7 @@ discard block | ||
| 185 | 192 | '%s' | 
| 186 | 193 | ) | 
| 187 | 194 | ); | 
| 188 | -		}else		{ | |
| 195 | +		} else		{ | |
| 189 | 196 | $insert = $wpdb->update( | 
| 190 | 197 | $wpdb->prefix.'xcloner_scheduler', | 
| 191 | 198 | $schedule, | 
| @@ -196,8 +203,9 @@ discard block | ||
| 196 | 203 | ) | 
| 197 | 204 | ); | 
| 198 | 205 | } | 
| 199 | - if(isset($_POST['id'])) | |
| 200 | - $scheduler->update_cron_hook($_POST['id']); | |
| 206 | +		if(isset($_POST['id'])) { | |
| 207 | + $scheduler->update_cron_hook($_POST['id']); | |
| 208 | + } | |
| 201 | 209 | |
| 202 | 210 |  		if( $wpdb->last_error ) { | 
| 203 | 211 | $response['error'] = 1; | 
| @@ -226,8 +234,9 @@ discard block | ||
| 226 | 234 | |
| 227 | 235 | $init = (int)$_POST['init']; | 
| 228 | 236 | |
| 229 | - if($params === NULL) | |
| 230 | -			 die( '{"status":false,"msg":"The post_data parameter must be valid JSON"}' ); | |
| 237 | +		if($params === NULL) { | |
| 238 | +					 die( '{"status":false,"msg":"The post_data parameter must be valid JSON"}' ); | |
| 239 | + } | |
| 231 | 240 | |
| 232 | 241 | $this->process_params($params); | 
| 233 | 242 | |
| @@ -236,7 +245,7 @@ discard block | ||
| 236 | 245 | //$return = $this->archive_system->start_incremental_backup($this->form_params['backup_params'], $this->form_params['extra'], $init); | 
| 237 | 246 |  		try{ | 
| 238 | 247 | $return = $this->archive_system->start_incremental_backup($this->form_params['backup_params'], $this->form_params['extra'], $init); | 
| 239 | - }catch(Exception $e) | |
| 248 | + } catch(Exception $e) | |
| 240 | 249 |  		{ | 
| 241 | 250 | $return = array(); | 
| 242 | 251 | $return['error'] = true; | 
| @@ -248,8 +257,9 @@ discard block | ||
| 248 | 257 | if($return['finished']) | 
| 249 | 258 |  		{ | 
| 250 | 259 | $return['extra']['backup_parent'] = $this->archive_system->get_archive_name_with_extension(); | 
| 251 | - if($this->xcloner_file_system->is_part($this->archive_system->get_archive_name_with_extension())) | |
| 252 | - $return['extra']['backup_parent'] = $this->archive_system->get_archive_name_multipart(); | |
| 260 | +			if($this->xcloner_file_system->is_part($this->archive_system->get_archive_name_with_extension())) { | |
| 261 | + $return['extra']['backup_parent'] = $this->archive_system->get_archive_name_multipart(); | |
| 262 | + } | |
| 253 | 263 | } | 
| 254 | 264 | |
| 255 | 265 | $data = $return; | 
| @@ -263,7 +273,7 @@ discard block | ||
| 263 | 273 | $from = ""; | 
| 264 | 274 | $subject = ""; | 
| 265 | 275 | $this->archive_system->send_notification($to, $from, $subject, $return['extra']['backup_parent'], $this->form_params); | 
| 266 | - }catch(Exception $e) | |
| 276 | + } catch(Exception $e) | |
| 267 | 277 |  				{ | 
| 268 | 278 | $this->logger->error($e->getMessage()); | 
| 269 | 279 | } | 
| @@ -289,18 +299,20 @@ discard block | ||
| 289 | 299 | |
| 290 | 300 | $init = (int)$_POST['init']; | 
| 291 | 301 | |
| 292 | - if($params === NULL) | |
| 293 | -			 die( '{"status":false,"msg":"The post_data parameter must be valid JSON"}' ); | |
| 302 | +		if($params === NULL) { | |
| 303 | +					 die( '{"status":false,"msg":"The post_data parameter must be valid JSON"}' ); | |
| 304 | + } | |
| 294 | 305 | |
| 295 | 306 | $this->process_params($params); | 
| 296 | 307 | |
| 297 | 308 | //$xcloner_database = $this->init_db(); | 
| 298 | 309 | $return = $this->xcloner_database->start_database_recursion($this->form_params['database'], $this->form_params['extra'], $init); | 
| 299 | 310 | |
| 300 | - if(isset($return['error']) and $return['error']) | |
| 301 | - $data['finished'] = 1; | |
| 302 | - else | |
| 303 | - $data['finished'] = $return['finished']; | |
| 311 | +		if(isset($return['error']) and $return['error']) { | |
| 312 | + $data['finished'] = 1; | |
| 313 | +		} else { | |
| 314 | + $data['finished'] = $return['finished']; | |
| 315 | + } | |
| 304 | 316 | |
| 305 | 317 | $data['extra'] = $return; | 
| 306 | 318 | |
| @@ -321,8 +333,9 @@ discard block | ||
| 321 | 333 | $params = json_decode(stripslashes($_POST['data'])); | 
| 322 | 334 | $init = (int)$_POST['init']; | 
| 323 | 335 | |
| 324 | - if($params === NULL) | |
| 325 | -			 die( '{"status":false,"msg":"The post_data parameter must be valid JSON"}' ); | |
| 336 | +		if($params === NULL) { | |
| 337 | +					 die( '{"status":false,"msg":"The post_data parameter must be valid JSON"}' ); | |
| 338 | + } | |
| 326 | 339 | |
| 327 | 340 | $hash = $this->process_params($params); | 
| 328 | 341 | |
| @@ -345,8 +358,9 @@ discard block | ||
| 345 | 358 | */ | 
| 346 | 359 | private function process_params($params) | 
| 347 | 360 |  	{ | 
| 348 | - if(isset($params->hash)) | |
| 349 | - $this->xcloner_settings->set_hash($params->hash); | |
| 361 | +		if(isset($params->hash)) { | |
| 362 | + $this->xcloner_settings->set_hash($params->hash); | |
| 363 | + } | |
| 350 | 364 | |
| 351 | 365 | $this->form_params['extra'] = array(); | 
| 352 | 366 | $this->form_params['backup_params'] = array(); | 
| @@ -399,8 +413,9 @@ discard block | ||
| 399 | 413 | |
| 400 | 414 | if(isset($params->extra)) | 
| 401 | 415 |  		{ | 
| 402 | - foreach($params->extra as $key=>$value) | |
| 403 | - $this->form_params['extra'][$key] = $this->xcloner_sanitization->sanitize_input_as_raw($value); | |
| 416 | +			foreach($params->extra as $key=>$value) { | |
| 417 | + $this->form_params['extra'][$key] = $this->xcloner_sanitization->sanitize_input_as_raw($value); | |
| 418 | + } | |
| 404 | 419 | } | 
| 405 | 420 | |
| 406 | 421 | return $this->xcloner_settings->get_hash(); | 
| @@ -437,7 +452,7 @@ discard block | ||
| 437 | 452 | |
| 438 | 453 |  			try{ | 
| 439 | 454 | $files = $this->xcloner_file_system->list_directory($folder); | 
| 440 | -			}catch(Exception $e){ | |
| 455 | +			} catch(Exception $e){ | |
| 441 | 456 | |
| 442 | 457 | print $e->getMessage(); | 
| 443 | 458 | $this->logger->error($e->getMessage()); | 
| @@ -457,17 +472,19 @@ discard block | ||
| 457 | 472 | $children = false; | 
| 458 | 473 | $text = $file['basename']; | 
| 459 | 474 | |
| 460 | - if($file['type'] == "dir") | |
| 461 | - $children = true; | |
| 462 | - else | |
| 463 | -					 $text .= " (". $this->xcloner_requirements->file_format_size($file['size']).")"; | |
| 475 | +				if($file['type'] == "dir") { | |
| 476 | + $children = true; | |
| 477 | +				} else { | |
| 478 | +									 $text .= " (". $this->xcloner_requirements->file_format_size($file['size']).")"; | |
| 479 | + } | |
| 464 | 480 | |
| 465 | 481 | //if(in_array($file['path'], $this->xcloner_file_system->get_excluded_files())) | 
| 466 | 482 | //echo $file['path']."--".$this->xcloner_file_system->is_excluded($file); | 
| 467 | - if($excluded_pattern = $this->xcloner_file_system->is_excluded($file)) | |
| 468 | - $selected = true; | |
| 469 | - else | |
| 470 | - $selected = false; | |
| 483 | +				if($excluded_pattern = $this->xcloner_file_system->is_excluded($file)) { | |
| 484 | + $selected = true; | |
| 485 | +				} else { | |
| 486 | + $selected = false; | |
| 487 | + } | |
| 471 | 488 | |
| 472 | 489 | $data[] = array( | 
| 473 | 490 | 'id' => $file['path'], | 
| @@ -505,22 +522,24 @@ discard block | ||
| 505 | 522 |  		{ | 
| 506 | 523 |  			try{ | 
| 507 | 524 | $return = $this->xcloner_database->get_all_databases(); | 
| 508 | -			}catch(Exception $e){ | |
| 525 | +			} catch(Exception $e){ | |
| 509 | 526 | $this->logger->error($e->getMessage()); | 
| 510 | 527 | } | 
| 511 | 528 | |
| 512 | 529 | foreach($return as $database) | 
| 513 | 530 |  			{ | 
| 514 | - if($xcloner_backup_only_wp_tables and $database['name'] != $this->xcloner_settings->get_db_database()) | |
| 515 | - continue; | |
| 531 | +				if($xcloner_backup_only_wp_tables and $database['name'] != $this->xcloner_settings->get_db_database()) { | |
| 532 | + continue; | |
| 533 | + } | |
| 516 | 534 | |
| 517 | 535 | $state = array(); | 
| 518 | 536 | |
| 519 | 537 | if($database['name'] == $this->xcloner_settings->get_db_database()) | 
| 520 | 538 |  				{ | 
| 521 | 539 | $state['selected'] = true; | 
| 522 | - if($database['num_tables'] < 25) | |
| 523 | - $state['opened'] = false; | |
| 540 | +					if($database['num_tables'] < 25) { | |
| 541 | + $state['opened'] = false; | |
| 542 | + } | |
| 524 | 543 | } | 
| 525 | 544 | |
| 526 | 545 | $data[] = array( | 
| @@ -533,13 +552,11 @@ discard block | ||
| 533 | 552 | ); | 
| 534 | 553 | } | 
| 535 | 554 | |
| 536 | - } | |
| 537 | - | |
| 538 | -		else{ | |
| 555 | +		} else{ | |
| 539 | 556 | |
| 540 | 557 |  			try{ | 
| 541 | 558 | $return = $this->xcloner_database->list_tables($database, "", 1); | 
| 542 | -			}catch(Exception $e){ | |
| 559 | +			} catch(Exception $e){ | |
| 543 | 560 | $this->logger->error($e->getMessage()); | 
| 544 | 561 | } | 
| 545 | 562 | |
| @@ -547,11 +564,13 @@ discard block | ||
| 547 | 564 |  			{ | 
| 548 | 565 | $state = array(); | 
| 549 | 566 | |
| 550 | - if($xcloner_backup_only_wp_tables and !stristr($table['name'], $this->xcloner_settings->get_table_prefix())) | |
| 551 | - continue; | |
| 567 | +				if($xcloner_backup_only_wp_tables and !stristr($table['name'], $this->xcloner_settings->get_table_prefix())) { | |
| 568 | + continue; | |
| 569 | + } | |
| 552 | 570 | |
| 553 | - if(isset($database['name']) and $database['name'] == $this->xcloner_settings->get_db_database()) | |
| 554 | -					$state = array('selected' => true); | |
| 571 | +				if(isset($database['name']) and $database['name'] == $this->xcloner_settings->get_db_database()) { | |
| 572 | +									$state = array('selected' => true); | |
| 573 | + } | |
| 555 | 574 | |
| 556 | 575 | $data[] = array( | 
| 557 | 576 | 'id' => $table['name'], | 
| @@ -604,10 +623,11 @@ discard block | ||
| 604 | 623 |  		{ | 
| 605 | 624 | $action = "<a href=\"#".$res->id."\" class=\"edit\" title='Edit'> <i class=\"material-icons \">edit</i></a> | 
| 606 | 625 | <a href=\"#".$res->id."\" class=\"delete\" title='Delete'><i class=\"material-icons \">delete</i></a>"; | 
| 607 | - if($res->status) | |
| 608 | - $status = '<i class="material-icons active status">timer</i>'; | |
| 609 | - else | |
| 610 | - $status = '<i class="material-icons status inactive">timer_off</i>'; | |
| 626 | +			if($res->status) { | |
| 627 | + $status = '<i class="material-icons active status">timer</i>'; | |
| 628 | +			} else { | |
| 629 | + $status = '<i class="material-icons status inactive">timer_off</i>'; | |
| 630 | + } | |
| 611 | 631 | |
| 612 | 632 |  			$next_run_time = wp_next_scheduled('xcloner_scheduler_'.$res->id, array($res->id)); | 
| 613 | 633 | |
| @@ -615,17 +635,19 @@ discard block | ||
| 615 | 635 | |
| 616 | 636 | $remote_storage = $res->remote_storage; | 
| 617 | 637 | |
| 618 | - if(!$next_run_time >= time()) | |
| 619 | - $next_run = " "; | |
| 638 | +			if(!$next_run_time >= time()) { | |
| 639 | + $next_run = " "; | |
| 640 | + } | |
| 620 | 641 | |
| 621 | 642 | if(trim($next_run)) | 
| 622 | 643 |  			{ | 
| 623 | 644 | $date_text = $next_run; | 
| 624 | 645 | |
| 625 | - if($next_run_time >= time()) | |
| 626 | - $next_run = "in ".human_time_diff($next_run_time, time()); | |
| 627 | - else | |
| 628 | -					$next_run = __("executed", 'xcloner-backup-and-restore'); | |
| 646 | +				if($next_run_time >= time()) { | |
| 647 | + $next_run = "in ".human_time_diff($next_run_time, time()); | |
| 648 | +				} else { | |
| 649 | +									$next_run = __("executed", 'xcloner-backup-and-restore'); | |
| 650 | + } | |
| 629 | 651 | |
| 630 | 652 | $next_run = "<a href='#' title='".$date_text."'>".$next_run."</a>"; | 
| 631 | 653 | //$next_run .=" ($date_text)"; | 
| @@ -712,7 +734,7 @@ discard block | ||
| 712 | 734 | $tar->open($this->xcloner_settings->get_xcloner_store_path().DS.$backup_file, $start); | 
| 713 | 735 | |
| 714 | 736 |  			$data = $tar->contents(get_option('xcloner_files_to_process_per_request')); | 
| 715 | - }catch(Exception $e) | |
| 737 | + } catch(Exception $e) | |
| 716 | 738 |  		{ | 
| 717 | 739 | $return['error'] = true; | 
| 718 | 740 | $return['message'] = $e->getMessage(); | 
| @@ -740,15 +762,16 @@ discard block | ||
| 740 | 762 |  		{ | 
| 741 | 763 | $return['start'] = $data['start']; | 
| 742 | 764 | $return['finished'] = 0; | 
| 743 | -		}else{ | |
| 765 | +		} else{ | |
| 744 | 766 | if($this->xcloner_file_system->is_multipart($source_backup_file)) | 
| 745 | 767 |  			{ | 
| 746 | 768 | $return['start'] = 0; | 
| 747 | 769 | |
| 748 | 770 | ++$return['part']; | 
| 749 | 771 | |
| 750 | - if($return['part'] < sizeof($backup_parts)) | |
| 751 | - $return['finished'] = 0; | |
| 772 | +				if($return['part'] < sizeof($backup_parts)) { | |
| 773 | + $return['finished'] = 0; | |
| 774 | + } | |
| 752 | 775 | |
| 753 | 776 | } | 
| 754 | 777 | } | 
| @@ -780,7 +803,7 @@ discard block | ||
| 780 | 803 |  			{ | 
| 781 | 804 | $return = call_user_func_array(array($xcloner_remote_storage, "upload_backup_to_storage"), array($backup_file, $storage_type)); | 
| 782 | 805 | } | 
| 783 | -		}catch(Exception $e){ | |
| 806 | +		} catch(Exception $e){ | |
| 784 | 807 | |
| 785 | 808 | $return['error'] = 1; | 
| 786 | 809 | $return['message'] = $e->getMessage(); | 
| @@ -925,11 +948,13 @@ discard block | ||
| 925 | 948 | $file = $this->xcloner_sanitization->sanitize_input_as_string($_POST['file']); | 
| 926 | 949 | $hash = $this->xcloner_sanitization->sanitize_input_as_string($_POST['hash']); | 
| 927 | 950 | |
| 928 | - if(isset($_POST['part'])) | |
| 929 | - $return['part'] = $this->xcloner_sanitization->sanitize_input_as_int($_POST['part']); | |
| 951 | +		if(isset($_POST['part'])) { | |
| 952 | + $return['part'] = $this->xcloner_sanitization->sanitize_input_as_int($_POST['part']); | |
| 953 | + } | |
| 930 | 954 | |
| 931 | - if(isset($_POST['uploaded_size'])) | |
| 932 | - $return['uploaded_size'] = $this->xcloner_sanitization->sanitize_input_as_int($_POST['uploaded_size']); | |
| 955 | +		if(isset($_POST['uploaded_size'])) { | |
| 956 | + $return['uploaded_size'] = $this->xcloner_sanitization->sanitize_input_as_int($_POST['uploaded_size']); | |
| 957 | + } | |
| 933 | 958 | |
| 934 | 959 | $start = $this->xcloner_sanitization->sanitize_input_as_string($_POST['start']); | 
| 935 | 960 | $target_url = $this->xcloner_sanitization->sanitize_input_as_string($_POST['target_url']); | 
| @@ -956,7 +981,7 @@ discard block | ||
| 956 | 981 | $xcloner_file_transfer->set_target($target_url); | 
| 957 | 982 | $return['start'] = $xcloner_file_transfer->transfer_file($file, $start, $hash); | 
| 958 | 983 | |
| 959 | -		}catch(Exception $e){ | |
| 984 | +		} catch(Exception $e){ | |
| 960 | 985 | |
| 961 | 986 | $return = array(); | 
| 962 | 987 | $return['error'] = true; | 
| @@ -990,8 +1015,9 @@ discard block | ||
| 990 | 1015 | $data['hash'] = $this->xcloner_settings->get_hash(); | 
| 991 | 1016 | } | 
| 992 | 1017 | |
| 993 | - if( ob_get_length() ) | |
| 994 | - ob_clean(); | |
| 1018 | +		if( ob_get_length() ) { | |
| 1019 | + ob_clean(); | |
| 1020 | + } | |
| 995 | 1021 | wp_send_json($data); | 
| 996 | 1022 | |
| 997 | 1023 | die(); | 
| @@ -13,20 +13,25 @@ discard block | ||
| 13 | 13 | |
| 14 | 14 | public function check_backup_ready_status() | 
| 15 | 15 |  	{ | 
| 16 | - if(!$this->check_min_php_version(1)) | |
| 17 | - return false; | |
| 16 | +		if(!$this->check_min_php_version(1)) { | |
| 17 | + return false; | |
| 18 | + } | |
| 18 | 19 | |
| 19 | - if(!$this->check_safe_mode(1)) | |
| 20 | - return false; | |
| 20 | +		if(!$this->check_safe_mode(1)) { | |
| 21 | + return false; | |
| 22 | + } | |
| 21 | 23 | |
| 22 | - if(!$this->check_xcloner_start_path(1)) | |
| 23 | - return false; | |
| 24 | +		if(!$this->check_xcloner_start_path(1)) { | |
| 25 | + return false; | |
| 26 | + } | |
| 24 | 27 | |
| 25 | - if(!$this->check_xcloner_store_path(1)) | |
| 26 | - return false; | |
| 28 | +		if(!$this->check_xcloner_store_path(1)) { | |
| 29 | + return false; | |
| 30 | + } | |
| 27 | 31 | |
| 28 | - if(!$this->check_xcloner_tmp_path(1)) | |
| 29 | - return false; | |
| 32 | +		if(!$this->check_xcloner_tmp_path(1)) { | |
| 33 | + return false; | |
| 34 | + } | |
| 30 | 35 | |
| 31 | 36 | return true; | 
| 32 | 37 | } | 
| @@ -41,10 +46,11 @@ discard block | ||
| 41 | 46 | |
| 42 | 47 | if($return_bool == 1) | 
| 43 | 48 |  		{ | 
| 44 | - if(version_compare(phpversion(), $this->min_php_version, '<')) | |
| 45 | - return false; | |
| 46 | - else | |
| 47 | - return true; | |
| 49 | +			if(version_compare(phpversion(), $this->min_php_version, '<')) { | |
| 50 | + return false; | |
| 51 | +			} else { | |
| 52 | + return true; | |
| 53 | + } | |
| 48 | 54 | } | 
| 49 | 55 | |
| 50 | 56 | return phpversion(); | 
| @@ -56,14 +62,16 @@ discard block | ||
| 56 | 62 | |
| 57 | 63 | if($return_bool) | 
| 58 | 64 |  		{ | 
| 59 | -			if( ini_get('safe_mode') ) | |
| 60 | - return false; | |
| 61 | - else | |
| 62 | - return true; | |
| 65 | +			if( ini_get('safe_mode') ) { | |
| 66 | + return false; | |
| 67 | +			} else { | |
| 68 | + return true; | |
| 69 | + } | |
| 63 | 70 | } | 
| 64 | 71 | |
| 65 | -		if( ini_get('safe_mode') ) | |
| 66 | - $safe_mode = "On"; | |
| 72 | +		if( ini_get('safe_mode') ) { | |
| 73 | + $safe_mode = "On"; | |
| 74 | + } | |
| 67 | 75 | |
| 68 | 76 | return $safe_mode; | 
| 69 | 77 | } | 
| @@ -74,8 +82,9 @@ discard block | ||
| 74 | 82 | |
| 75 | 83 | if($return_bool) | 
| 76 | 84 |  		{ | 
| 77 | - if(!file_exists($path)) | |
| 78 | - return false; | |
| 85 | +			if(!file_exists($path)) { | |
| 86 | + return false; | |
| 87 | + } | |
| 79 | 88 | |
| 80 | 89 | return is_readable($path); | 
| 81 | 90 | } | 
| @@ -89,11 +98,13 @@ discard block | ||
| 89 | 98 | |
| 90 | 99 | if($return_bool) | 
| 91 | 100 |  		{ | 
| 92 | - if(!file_exists($path)) | |
| 93 | - return false; | |
| 101 | +			if(!file_exists($path)) { | |
| 102 | + return false; | |
| 103 | + } | |
| 94 | 104 | |
| 95 | - if(!is_writeable($path)) | |
| 96 | - @chmod($path, 0777); | |
| 105 | +			if(!is_writeable($path)) { | |
| 106 | + @chmod($path, 0777); | |
| 107 | + } | |
| 97 | 108 | |
| 98 | 109 | return is_writeable($path); | 
| 99 | 110 | } | 
| @@ -107,11 +118,13 @@ discard block | ||
| 107 | 118 | |
| 108 | 119 | if($return_bool) | 
| 109 | 120 |  		{ | 
| 110 | - if(!file_exists($path)) | |
| 111 | - return false; | |
| 121 | +			if(!file_exists($path)) { | |
| 122 | + return false; | |
| 123 | + } | |
| 112 | 124 | |
| 113 | - if(!is_writeable($path)) | |
| 114 | - @chmod($path, 0777); | |
| 125 | +			if(!is_writeable($path)) { | |
| 126 | + @chmod($path, 0777); | |
| 127 | + } | |
| 115 | 128 | |
| 116 | 129 | return is_writeable($path); | 
| 117 | 130 | } | 
| @@ -133,8 +146,9 @@ discard block | ||
| 133 | 146 |  	{ | 
| 134 | 147 |  		$open_basedir =  ini_get('open_basedir'); | 
| 135 | 148 | |
| 136 | - if(!$open_basedir) | |
| 137 | - $open_basedir = "none"; | |
| 149 | +		if(!$open_basedir) { | |
| 150 | + $open_basedir = "none"; | |
| 151 | + } | |
| 138 | 152 | return $open_basedir; | 
| 139 | 153 | } | 
| 140 | 154 | |
| @@ -153,8 +167,9 @@ discard block | ||
| 153 | 167 | $unit_count = count($unit_list); | 
| 154 | 168 |  	  for ($i = $unit_count - 1; $i >= 0; $i--) { | 
| 155 | 169 | $power = $i * 10; | 
| 156 | - if (($bytes >> $power) >= 1) | |
| 157 | - return round($bytes / (1 << $power), $decimals) . ' ' . $unit_list[$i]; | |
| 170 | +	    if (($bytes >> $power) >= 1) { | |
| 171 | + return round($bytes / (1 << $power), $decimals) . ' ' . $unit_list[$i]; | |
| 172 | + } | |
| 158 | 173 | } | 
| 159 | 174 | } | 
| 160 | 175 | } | 
| @@ -19,8 +19,9 @@ discard block | ||
| 19 | 19 | |
| 20 | 20 | public function transfer_file($file, $start = 0, $hash = "") | 
| 21 | 21 |  	{ | 
| 22 | - if(!$this->target_url) | |
| 23 | -			throw new Exception("Please setup a target url for upload"); | |
| 22 | +		if(!$this->target_url) { | |
| 23 | +					throw new Exception("Please setup a target url for upload"); | |
| 24 | + } | |
| 24 | 25 | |
| 25 | 26 | |
| 26 | 27 | $fp = $this->get_storage_filesystem()->readStream($file); | 
| @@ -68,8 +69,9 @@ discard block | ||
| 68 | 69 | |
| 69 | 70 | $result = json_decode($original_result); | 
| 70 | 71 | |
| 71 | - if(!$result) | |
| 72 | -			throw new Exception("We have received no valid response from the remote host, original message: ". $original_result); | |
| 72 | +		if(!$result) { | |
| 73 | +					throw new Exception("We have received no valid response from the remote host, original message: ". $original_result); | |
| 74 | + } | |
| 73 | 75 | |
| 74 | 76 | if($result->status != 200) | 
| 75 | 77 |  		{ | 
| @@ -94,7 +96,7 @@ discard block | ||
| 94 | 96 | . ($postname ?: basename($filename)) | 
| 95 | 97 | . ($mimetype ? ";type=$mimetype" : ''); | 
| 96 | 98 | |
| 97 | -		}else{ | |
| 99 | +		} else{ | |
| 98 | 100 | |
| 99 | 101 | return curl_file_create($filename, $mimetype, $postname); | 
| 100 | 102 | |
| @@ -97,8 +97,9 @@ discard block | ||
| 97 | 97 | foreach($this->storage_fields as $storage=>$data) | 
| 98 | 98 |  		{ | 
| 99 | 99 | $check_field = $this->storage_fields["option_prefix"].$storage."_enable"; | 
| 100 | - if(get_option($check_field)) | |
| 101 | - $return[$storage] = $data['text']; | |
| 100 | +			if(get_option($check_field)) { | |
| 101 | + $return[$storage] = $data['text']; | |
| 102 | + } | |
| 102 | 103 | } | 
| 103 | 104 | |
| 104 | 105 | return $return; | 
| @@ -116,11 +117,13 @@ discard block | ||
| 116 | 117 | $check_field = $this->storage_fields["option_prefix"].$field; | 
| 117 | 118 | $sanitize_method = "sanitize_input_as_".$validation; | 
| 118 | 119 | |
| 119 | - if(!isset($_POST[$check_field])) | |
| 120 | - $_POST[$check_field] = 0; | |
| 120 | +				if(!isset($_POST[$check_field])) { | |
| 121 | + $_POST[$check_field] = 0; | |
| 122 | + } | |
| 121 | 123 | |
| 122 | - if(!method_exists($this->xcloner_sanitization, $sanitize_method)) | |
| 123 | - $sanitize_method = "sanitize_input_as_string"; | |
| 124 | +				if(!method_exists($this->xcloner_sanitization, $sanitize_method)) { | |
| 125 | + $sanitize_method = "sanitize_input_as_string"; | |
| 126 | + } | |
| 124 | 127 | |
| 125 | 128 | $sanitized_value = $this->xcloner_sanitization->$sanitize_method($_POST[$check_field]); | 
| 126 | 129 | update_option($check_field, $sanitized_value); | 
| @@ -135,7 +138,7 @@ discard block | ||
| 135 | 138 | $this->verify_filesystem($action); | 
| 136 | 139 |  				$this->xcloner->trigger_message(__("%s connection is valid.", 'xcloner-backup-and-restore'), "success", ucfirst($action)); | 
| 137 | 140 |  				$this->logger->debug(sprintf("Connection to remote storage %s is valid", strtoupper($action)));	 | 
| 138 | -			}catch(Exception $e){ | |
| 141 | +			} catch(Exception $e){ | |
| 139 | 142 |  				$this->xcloner->trigger_message("%s connection error: ".$e->getMessage(), "error", ucfirst($action)); | 
| 140 | 143 | } | 
| 141 | 144 | } | 
| @@ -148,38 +151,44 @@ discard block | ||
| 148 | 151 | |
| 149 | 152 |  		$this->logger->info(sprintf("Checking validity of the remote storage %s filesystem", strtoupper($storage_type)));	 | 
| 150 | 153 | |
| 151 | - if(!method_exists($this, $method)) | |
| 152 | - return false; | |
| 154 | +		if(!method_exists($this, $method)) { | |
| 155 | + return false; | |
| 156 | + } | |
| 153 | 157 | |
| 154 | 158 | list($adapter, $filesystem) = $this->$method(); | 
| 155 | 159 | |
| 156 | 160 |  		$test_file = substr(".xcloner_".md5(time()), 0, 15); | 
| 157 | 161 | |
| 158 | 162 | //testing write access | 
| 159 | - if(!$filesystem->write($test_file, "data")) | |
| 160 | -			throw new Exception(__("Could not write data",'xcloner-backup-and-restore')); | |
| 163 | +		if(!$filesystem->write($test_file, "data")) { | |
| 164 | +					throw new Exception(__("Could not write data",'xcloner-backup-and-restore')); | |
| 165 | + } | |
| 161 | 166 |  		$this->logger->debug(sprintf("I can write data to remote storage %s", strtoupper($storage_type)));	 | 
| 162 | 167 | |
| 163 | 168 | //testing read access | 
| 164 | - if(!$filesystem->read($test_file)) | |
| 165 | -			throw new Exception(__("Could not read data",'xcloner-backup-and-restore')); | |
| 169 | +		if(!$filesystem->read($test_file)) { | |
| 170 | +					throw new Exception(__("Could not read data",'xcloner-backup-and-restore')); | |
| 171 | + } | |
| 166 | 172 |  		$this->logger->debug(sprintf("I can read data to remote storage %s", strtoupper($storage_type)));		 | 
| 167 | 173 | |
| 168 | 174 | //delete test file | 
| 169 | - if(!$filesystem->delete($test_file)) | |
| 170 | -			throw new Exception(__("Could not delete data",'xcloner-backup-and-restore')); | |
| 175 | +		if(!$filesystem->delete($test_file)) { | |
| 176 | +					throw new Exception(__("Could not delete data",'xcloner-backup-and-restore')); | |
| 177 | + } | |
| 171 | 178 |  		$this->logger->debug(sprintf("I can delete data to remote storage %s", strtoupper($storage_type)));		 | 
| 172 | 179 | } | 
| 173 | 180 | |
| 174 | 181 | public function upload_backup_to_storage($file, $storage) | 
| 175 | 182 |  	{ | 
| 176 | - if(!$this->xcloner_file_system->get_storage_filesystem()->has($file)) | |
| 177 | - return false; | |
| 183 | +		if(!$this->xcloner_file_system->get_storage_filesystem()->has($file)) { | |
| 184 | + return false; | |
| 185 | + } | |
| 178 | 186 | |
| 179 | 187 | $method = "get_".$storage."_filesystem"; | 
| 180 | 188 | |
| 181 | - if(!method_exists($this, $method)) | |
| 182 | - return false; | |
| 189 | +		if(!method_exists($this, $method)) { | |
| 190 | + return false; | |
| 191 | + } | |
| 183 | 192 | |
| 184 | 193 | list($remote_storage_adapter, $remote_storage_filesystem) = $this->$method(); | 
| 185 | 194 | |
| @@ -205,14 +214,16 @@ discard block | ||
| 205 | 214 | if($this->xcloner_file_system->is_multipart($file)) | 
| 206 | 215 |  		{ | 
| 207 | 216 | $parts = $this->xcloner_file_system->get_multipart_files($file); | 
| 208 | - if(is_array($parts)) | |
| 209 | - foreach($parts as $part_file) | |
| 217 | +			if(is_array($parts)) { | |
| 218 | + foreach($parts as $part_file) | |
| 210 | 219 |  				{ | 
| 211 | 220 |  					$this->logger->info(sprintf("Transferring backup %s to remote storage %s", $part_file, strtoupper($storage)), array("")); | 
| 221 | + } | |
| 212 | 222 | |
| 213 | 223 | $backup_file_stream = $this->xcloner_file_system->get_storage_filesystem()->readStream($part_file); | 
| 214 | - if(!$remote_storage_filesystem->updateStream($part_file, $backup_file_stream)) | |
| 215 | - return false; | |
| 224 | +					if(!$remote_storage_filesystem->updateStream($part_file, $backup_file_stream)) { | |
| 225 | + return false; | |
| 226 | + } | |
| 216 | 227 | } | 
| 217 | 228 | } | 
| 218 | 229 | |
| @@ -234,10 +245,11 @@ discard block | ||
| 234 | 245 | |
| 235 | 246 |  			$current_timestamp = strtotime("-".$expire_days." days"); | 
| 236 | 247 | |
| 237 | - if(is_array($files)) | |
| 238 | - foreach($files as $file) | |
| 248 | +			if(is_array($files)) { | |
| 249 | + foreach($files as $file) | |
| 239 | 250 |  			{ | 
| 240 | 251 | $file['timestamp'] = $remote_storage_filesystem->getTimestamp($file['path']); | 
| 252 | + } | |
| 241 | 253 | |
| 242 | 254 | if($current_timestamp >= $file['timestamp']) | 
| 243 | 255 |  				{ | 
| @@ -30,10 +30,11 @@ discard block | ||
| 30 | 30 |  		{ | 
| 31 | 31 | $new_list= array(); | 
| 32 | 32 | |
| 33 | - foreach($list as $res) | |
| 34 | - if($res->status) | |
| 33 | +			foreach($list as $res) { | |
| 34 | + if($res->status) | |
| 35 | 35 |  				{ | 
| 36 | 36 |  					$res->next_run_time = wp_next_scheduled('xcloner_scheduler_'.$res->id, array($res->id)); | 
| 37 | + } | |
| 37 | 38 | $new_list[] = $res; | 
| 38 | 39 | } | 
| 39 | 40 | $list = $new_list; | 
| @@ -59,8 +60,9 @@ discard block | ||
| 59 | 60 |  	{ | 
| 60 | 61 |  		$data = $this->db->get_row("SELECT * FROM ".$this->scheduler_table." WHERE id=".$id, ARRAY_A); | 
| 61 | 62 | |
| 62 | - if(!$data) | |
| 63 | - return false; | |
| 63 | +		if(!$data) { | |
| 64 | + return false; | |
| 65 | + } | |
| 64 | 66 | |
| 65 | 67 | $params = json_decode($data['params']); | 
| 66 | 68 | |
| @@ -110,12 +112,13 @@ discard block | ||
| 110 | 112 | |
| 111 | 113 |  			if ( ! wp_next_scheduled( $hook, array($schedule->id) ) and $schedule->status) { | 
| 112 | 114 | |
| 113 | - if($schedule->recurrence == "single") | |
| 114 | - wp_schedule_single_event( strtotime($schedule->start_at), $hook, array($schedule->id)); | |
| 115 | - else | |
| 116 | - wp_schedule_event( strtotime($schedule->start_at), $schedule->recurrence, $hook, array($schedule->id) ); | |
| 115 | +				if($schedule->recurrence == "single") { | |
| 116 | + wp_schedule_single_event( strtotime($schedule->start_at), $hook, array($schedule->id)); | |
| 117 | +				} else { | |
| 118 | + wp_schedule_event( strtotime($schedule->start_at), $schedule->recurrence, $hook, array($schedule->id) ); | |
| 119 | + } | |
| 117 | 120 | |
| 118 | - }elseif(!$schedule->status) | |
| 121 | + } elseif(!$schedule->status) | |
| 119 | 122 |  			{ | 
| 120 | 123 | $timestamp = wp_next_scheduled( $hook , array($schedule->id) ); | 
| 121 | 124 | wp_unschedule_event( $timestamp, $hook, array($schedule->id) ); | 
| @@ -134,9 +137,9 @@ discard block | ||
| 134 | 137 | |
| 135 | 138 |  		if ($schedule->status) { | 
| 136 | 139 | |
| 137 | - if($schedule->recurrence == "single") | |
| 138 | - wp_schedule_single_event( strtotime($schedule->start_at), $hook, array($schedule->id)); | |
| 139 | -			else{	 | |
| 140 | +			if($schedule->recurrence == "single") { | |
| 141 | + wp_schedule_single_event( strtotime($schedule->start_at), $hook, array($schedule->id)); | |
| 142 | +			} else{	 | |
| 140 | 143 | wp_schedule_event( strtotime($schedule->start_at), $schedule->recurrence, $hook, array($schedule->id) ); | 
| 141 | 144 | } | 
| 142 | 145 | |
| @@ -268,8 +271,9 @@ discard block | ||
| 268 | 271 | |
| 269 | 272 | //getting the last backup archive file | 
| 270 | 273 | $return['extra']['backup_parent'] = $this->archive_system->get_archive_name_with_extension(); | 
| 271 | - if($this->xcloner_file_system->is_part($this->archive_system->get_archive_name_with_extension())) | |
| 272 | - $return['extra']['backup_parent'] = $this->archive_system->get_archive_name_multipart(); | |
| 274 | +		if($this->xcloner_file_system->is_part($this->archive_system->get_archive_name_with_extension())) { | |
| 275 | + $return['extra']['backup_parent'] = $this->archive_system->get_archive_name_multipart(); | |
| 276 | + } | |
| 273 | 277 | |
| 274 | 278 | $this->update_last_backup($schedule['id'], $return['extra']['backup_parent']); | 
| 275 | 279 | |
| @@ -279,8 +283,9 @@ discard block | ||
| 279 | 283 | |
| 280 | 284 |  			$this->logger->info(sprintf("Transferring backup to remote storage %s", strtoupper($schedule['remote_storage'])), array("CRON")); | 
| 281 | 285 | |
| 282 | - if(method_exists($this->xcloner_remote_storage, "upload_backup_to_storage")) | |
| 283 | - $return_storage = call_user_func_array(array($this->xcloner_remote_storage, "upload_backup_to_storage"), array($backup_file, $schedule['remote_storage'])); | |
| 286 | +			if(method_exists($this->xcloner_remote_storage, "upload_backup_to_storage")) { | |
| 287 | + $return_storage = call_user_func_array(array($this->xcloner_remote_storage, "upload_backup_to_storage"), array($backup_file, $schedule['remote_storage'])); | |
| 288 | + } | |
| 284 | 289 | } | 
| 285 | 290 | |
| 286 | 291 | |
| @@ -289,7 +294,7 @@ discard block | ||
| 289 | 294 |  			try{ | 
| 290 | 295 | $from = "XCloner Schedule - ".$schedule['name']; | 
| 291 | 296 | $this->archive_system->send_notification($to, $from, "", $return['extra']['backup_parent'], $schedule); | 
| 292 | - }catch(Exception $e) | |
| 297 | + } catch(Exception $e) | |
| 293 | 298 |  			{ | 
| 294 | 299 | $this->logger->error($e->getMessage()); | 
| 295 | 300 | } | 
| @@ -308,7 +313,7 @@ discard block | ||
| 308 | 313 | |
| 309 | 314 | $this->__xcloner_scheduler_callback($id, $schedule); | 
| 310 | 315 | |
| 311 | -		}catch(Exception $e){ | |
| 316 | +		} catch(Exception $e){ | |
| 312 | 317 | |
| 313 | 318 | if(isset($schedule['backup_params']->email_notification) and $to=$schedule['backup_params']->email_notification) | 
| 314 | 319 |  			{ |