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
Push — master ( 1a6a13...b32b6e )
by Liuta
03:37
created
includes/class-xcloner-api.php 1 patch
Braces   +111 added lines, -85 removed lines patch added patch discarded remove patch
@@ -27,8 +27,9 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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());
@@ -107,8 +109,9 @@  discard block
 block discarded – undo
107 109
 		$schedule = array();
108 110
 		$response = array();
109 111
 		
110
-		if(isset($_POST['data']))
111
-			$params = json_decode(stripslashes($_POST['data']));
112
+		if(isset($_POST['data'])) {
113
+					$params = json_decode(stripslashes($_POST['data']));
114
+		}
112 115
 		
113 116
 		$this->process_params($params);
114 117
 		
@@ -131,8 +134,9 @@  discard block
 block discarded – undo
131 134
 			{
132 135
 					$table = str_replace("\r","", $table);
133 136
 					$data = explode(".", $table);
134
-					if(isset($data[1]))
135
-						$return[$data[0]][] = $data[1];
137
+					if(isset($data[1])) {
138
+											$return[$data[0]][] = $data[1];
139
+					}
136 140
 			}
137 141
 			
138 142
 			$this->form_params['database'] = ($return);
@@ -143,27 +147,30 @@  discard block
 block discarded – undo
143 147
 			foreach($excluded_files as $file)
144 148
 			{
145 149
 				$file = str_replace("\r","", $file);
146
-				if($file)
147
-					$return[] = $file;
150
+				if($file) {
151
+									$return[] = $file;
152
+				}
148 153
 			}
149 154
 			
150 155
 			$this->form_params['excluded_files'] = ($return);
151 156
 			
152 157
 			$schedule['start_at'] = $this->form_params['backup_params']['start_at'] ;
153 158
 			
154
-			if(!isset($_POST['status']))
155
-				$schedule['status'] = 0;
156
-			else	
157
-				$schedule['status'] = $this->xcloner_sanitization->sanitize_input_as_int($_POST['status']);
158
-		}else{
159
+			if(!isset($_POST['status'])) {
160
+							$schedule['status'] = 0;
161
+			} else {
162
+							$schedule['status'] = $this->xcloner_sanitization->sanitize_input_as_int($_POST['status']);
163
+			}
164
+		} else{
159 165
 		
160 166
 			$schedule['status'] = 1;
161 167
 			$schedule['start_at'] = strtotime($this->form_params['backup_params']['schedule_start_date'] .
162 168
 								" ".$this->form_params['backup_params']['schedule_start_time']);
163 169
 		}
164 170
 		
165
-		if(!$schedule['start_at'])						
166
-			$schedule['start_at'] = time();
171
+		if(!$schedule['start_at']) {
172
+					$schedule['start_at'] = time();
173
+		}
167 174
 		
168 175
 		$schedule['start_at'] = date('Y-m-d H:i:s', $schedule['start_at']);	
169 176
 		
@@ -183,7 +190,7 @@  discard block
 block discarded – undo
183 190
 					'%s' 
184 191
 				) 
185 192
 			);
186
-		}else		{
193
+		} else		{
187 194
 			$wpdb->update( 
188 195
 				$wpdb->prefix.'xcloner_scheduler', 
189 196
 				$schedule, 
@@ -194,8 +201,9 @@  discard block
 block discarded – undo
194 201
 				) 
195 202
 			);
196 203
 		}
197
-		if(isset($_POST['id']))
198
-			$scheduler->update_cron_hook($_POST['id']);
204
+		if(isset($_POST['id'])) {
205
+					$scheduler->update_cron_hook($_POST['id']);
206
+		}
199 207
 			
200 208
 		if( $wpdb->last_error ) {
201 209
             $response['error'] = 1;
@@ -224,8 +232,9 @@  discard block
 block discarded – undo
224 232
 		
225 233
 		$init 	= (int)$_POST['init'];
226 234
 		
227
-		if($params === NULL)
228
-			 die( '{"status":false,"msg":"The post_data parameter must be valid JSON"}' );
235
+		if($params === NULL) {
236
+					 die( '{"status":false,"msg":"The post_data parameter must be valid JSON"}' );
237
+		}
229 238
 			 
230 239
 		$this->process_params($params);
231 240
 		
@@ -234,7 +243,7 @@  discard block
 block discarded – undo
234 243
 		//$return = $this->archive_system->start_incremental_backup($this->form_params['backup_params'], $this->form_params['extra'], $init);
235 244
 		try{
236 245
 			$return = $this->archive_system->start_incremental_backup($this->form_params['backup_params'], $this->form_params['extra'], $init);
237
-		}catch(Exception $e)
246
+		} catch(Exception $e)
238 247
 		{
239 248
 			$return = array();
240 249
 			$return['error'] = true;
@@ -246,8 +255,9 @@  discard block
 block discarded – undo
246 255
 		if($return['finished'])
247 256
 		{
248 257
 			$return['extra']['backup_parent'] = $this->archive_system->get_archive_name_with_extension();
249
-			if($this->xcloner_file_system->is_part($this->archive_system->get_archive_name_with_extension()))
250
-				$return['extra']['backup_parent'] = $this->archive_system->get_archive_name_multipart();
258
+			if($this->xcloner_file_system->is_part($this->archive_system->get_archive_name_with_extension())) {
259
+							$return['extra']['backup_parent'] = $this->archive_system->get_archive_name_multipart();
260
+			}
251 261
 		}
252 262
 		
253 263
 		$data = $return;
@@ -261,7 +271,7 @@  discard block
 block discarded – undo
261 271
 					$from = "";
262 272
 					$subject = "";
263 273
 					$this->archive_system->send_notification($to, $from, $subject, $return['extra']['backup_parent'], $this->form_params);
264
-				}catch(Exception $e)
274
+				} catch(Exception $e)
265 275
 				{
266 276
 					$this->logger->error($e->getMessage());
267 277
 				}
@@ -287,18 +297,20 @@  discard block
 block discarded – undo
287 297
 		
288 298
 		$init 	= (int)$_POST['init'];
289 299
 		
290
-		if($params === NULL)
291
-			 die( '{"status":false,"msg":"The post_data parameter must be valid JSON"}' );
300
+		if($params === NULL) {
301
+					 die( '{"status":false,"msg":"The post_data parameter must be valid JSON"}' );
302
+		}
292 303
 		
293 304
 		$this->process_params($params);
294 305
 			
295 306
 		//$xcloner_database = $this->init_db();	
296 307
 		$return = $this->xcloner_database->start_database_recursion($this->form_params['database'], $this->form_params['extra'], $init);
297 308
 		
298
-		if(isset($return['error']) and $return['error'])
299
-			$data['finished'] = 1;
300
-		else	
301
-			$data['finished'] = $return['finished'];
309
+		if(isset($return['error']) and $return['error']) {
310
+					$data['finished'] = 1;
311
+		} else {
312
+					$data['finished'] = $return['finished'];
313
+		}
302 314
 			
303 315
 		$data['extra'] = $return;
304 316
 		
@@ -319,8 +331,9 @@  discard block
 block discarded – undo
319 331
 		$params = json_decode(stripslashes($_POST['data']));
320 332
 		$init 	= (int)$_POST['init'];
321 333
 		
322
-		if($params === NULL)
323
-			 die( '{"status":false,"msg":"The post_data parameter must be valid JSON"}' );
334
+		if($params === NULL) {
335
+					 die( '{"status":false,"msg":"The post_data parameter must be valid JSON"}' );
336
+		}
324 337
 			 
325 338
 		$hash = $this->process_params($params);
326 339
 		
@@ -343,8 +356,9 @@  discard block
 block discarded – undo
343 356
 	 */ 
344 357
 	private function process_params($params)
345 358
 	{
346
-		if(isset($params->hash))
347
-			$this->xcloner_settings->set_hash($params->hash);
359
+		if(isset($params->hash)) {
360
+					$this->xcloner_settings->set_hash($params->hash);
361
+		}
348 362
 			
349 363
 		$this->form_params['extra'] = array();
350 364
 		$this->form_params['backup_params'] = array();
@@ -397,8 +411,9 @@  discard block
 block discarded – undo
397 411
 		
398 412
 		if(isset($params->extra))
399 413
 		{
400
-			foreach($params->extra as $key=>$value)
401
-				$this->form_params['extra'][$key] = $this->xcloner_sanitization->sanitize_input_as_raw($value);
414
+			foreach($params->extra as $key=>$value) {
415
+							$this->form_params['extra'][$key] = $this->xcloner_sanitization->sanitize_input_as_raw($value);
416
+			}
402 417
 		}
403 418
 			
404 419
 		return $this->xcloner_settings->get_hash();
@@ -435,7 +450,7 @@  discard block
 block discarded – undo
435 450
 			
436 451
 			try{
437 452
 				$files = $this->xcloner_file_system->list_directory($folder);
438
-			}catch(Exception $e){
453
+			} catch(Exception $e){
439 454
 				
440 455
 				print $e->getMessage();
441 456
 				$this->logger->error($e->getMessage());
@@ -455,17 +470,19 @@  discard block
 block discarded – undo
455 470
 				$children = false;
456 471
 				$text = $file['basename'];
457 472
 				
458
-				if($file['type'] == "dir")
459
-					$children = true;
460
-				else
461
-					 $text .= " (". $this->xcloner_requirements->file_format_size($file['size']).")";
473
+				if($file['type'] == "dir") {
474
+									$children = true;
475
+				} else {
476
+									 $text .= " (". $this->xcloner_requirements->file_format_size($file['size']).")";
477
+				}
462 478
 				
463 479
 				//if(in_array($file['path'], $this->xcloner_file_system->get_excluded_files()))
464 480
 				//echo $file['path']."--".$this->xcloner_file_system->is_excluded($file);
465
-				if($this->xcloner_file_system->is_excluded($file))
466
-					$selected = true;
467
-				else
468
-					$selected = false;
481
+				if($this->xcloner_file_system->is_excluded($file)) {
482
+									$selected = true;
483
+				} else {
484
+									$selected = false;
485
+				}
469 486
 					
470 487
 				$data[] = array(
471 488
 							'id' => $file['path'],
@@ -503,22 +520,24 @@  discard block
 block discarded – undo
503 520
 		{
504 521
 			try{
505 522
 				$return = $this->xcloner_database->get_all_databases();
506
-			}catch(Exception $e){
523
+			} catch(Exception $e){
507 524
 				$this->logger->error($e->getMessage());
508 525
 			}
509 526
 			
510 527
 			foreach($return as $database)
511 528
 			{
512
-				if($xcloner_backup_only_wp_tables and $database['name'] != $this->xcloner_settings->get_db_database())
513
-					continue;
529
+				if($xcloner_backup_only_wp_tables and $database['name'] != $this->xcloner_settings->get_db_database()) {
530
+									continue;
531
+				}
514 532
 					
515 533
 				$state = array();
516 534
 				
517 535
 				if($database['name'] == $this->xcloner_settings->get_db_database())
518 536
 				{
519 537
 					$state['selected'] = true;
520
-					if($database['num_tables'] < 25)
521
-						$state['opened'] = false;
538
+					if($database['num_tables'] < 25) {
539
+											$state['opened'] = false;
540
+					}
522 541
 				}
523 542
 					
524 543
 				$data[] = array(
@@ -531,13 +550,11 @@  discard block
 block discarded – undo
531 550
 						);
532 551
 			}
533 552
 			
534
-		}
535
-		
536
-		else{
553
+		} else{
537 554
 			
538 555
 			try{
539 556
 				$return = $this->xcloner_database->list_tables($database, "", 1);
540
-			}catch(Exception $e){
557
+			} catch(Exception $e){
541 558
 				$this->logger->error($e->getMessage());
542 559
 			}
543 560
 			
@@ -545,11 +562,13 @@  discard block
 block discarded – undo
545 562
 			{
546 563
 				$state = array();
547 564
 				
548
-				if($xcloner_backup_only_wp_tables and !stristr($table['name'], $this->xcloner_settings->get_table_prefix()))
549
-					continue;
565
+				if($xcloner_backup_only_wp_tables and !stristr($table['name'], $this->xcloner_settings->get_table_prefix())) {
566
+									continue;
567
+				}
550 568
 				
551
-				if(isset($database['name']) and $database['name'] == $this->xcloner_settings->get_db_database())
552
-					$state = array('selected' => true);
569
+				if(isset($database['name']) and $database['name'] == $this->xcloner_settings->get_db_database()) {
570
+									$state = array('selected' => true);
571
+				}
553 572
 					
554 573
 				$data[] = array(
555 574
 						'id' => $table['name'],
@@ -602,10 +621,11 @@  discard block
 block discarded – undo
602 621
 		{
603 622
 			$action = "<a href=\"#".$res->id."\" class=\"edit\" title='Edit'> <i class=\"material-icons \">edit</i></a> 
604 623
 					<a href=\"#".$res->id."\" class=\"delete\" title='Delete'><i class=\"material-icons  \">delete</i></a>";
605
-			if($res->status)
606
-				$status = '<i class="material-icons active status">timer</i>';
607
-			else
608
-				$status = '<i class="material-icons status inactive">timer_off</i>';
624
+			if($res->status) {
625
+							$status = '<i class="material-icons active status">timer</i>';
626
+			} else {
627
+							$status = '<i class="material-icons status inactive">timer_off</i>';
628
+			}
609 629
 				
610 630
 			$next_run_time = wp_next_scheduled('xcloner_scheduler_'.$res->id, array($res->id));
611 631
 				
@@ -613,17 +633,19 @@  discard block
 block discarded – undo
613 633
 			
614 634
 			$remote_storage = $res->remote_storage;
615 635
 			
616
-			if(!$next_run_time >= time())
617
-				$next_run = " ";
636
+			if(!$next_run_time >= time()) {
637
+							$next_run = " ";
638
+			}
618 639
 			
619 640
 			if(trim($next_run))
620 641
 			{
621 642
 				$date_text = $next_run;
622 643
 				
623
-				if($next_run_time >= time())
624
-					$next_run = "in ".human_time_diff($next_run_time, time());
625
-				else
626
-					$next_run = __("executed", 'xcloner-backup-and-restore');
644
+				if($next_run_time >= time()) {
645
+									$next_run = "in ".human_time_diff($next_run_time, time());
646
+				} else {
647
+									$next_run = __("executed", 'xcloner-backup-and-restore');
648
+				}
627 649
 				
628 650
 				$next_run = "<a href='#' title='".$date_text."'>".$next_run."</a>";
629 651
 				//$next_run .=" ($date_text)";	
@@ -712,7 +734,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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();
Please login to merge, or discard this patch.