GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Push — master ( 8b886b...4d21df )
by Jens
02:52
created
carddav2fb.php 1 patch
Braces   +205 added lines, -90 removed lines patch added patch discarded remove patch
@@ -38,9 +38,12 @@  discard block
 block discarded – undo
38 38
 require_once('lib/fritzbox_api_php/fritzbox_api.class.php');
39 39
 
40 40
 if($argc == 2)
41
+{
41 42
   $config_file_name = $argv[1];
42
-else
43
+}
44
+else {
43 45
   $config_file_name = __DIR__ . '/config.php';
46
+}
44 47
 
45 48
 // default/fallback config options
46 49
 $config['tmp_dir'] = sys_get_temp_dir();
@@ -60,7 +63,9 @@  discard block
 block discarded – undo
60 63
 $config['quickdial_keyword'] = 'Quickdial:';
61 64
 
62 65
 if(is_file($config_file_name))
66
+{
63 67
   require($config_file_name);
68
+}
64 69
 else
65 70
 {
66 71
   print 'ERROR: No ' . $config_file_name . ' found, please take a look at config.example.php and create a ' . $config_file_name . ' file!' . PHP_EOL;
@@ -122,7 +127,9 @@  discard block
 block discarded – undo
122 127
   public function mktemp($dir, $prefix = '', $mode = 0700)
123 128
   {
124 129
     if(substr($dir, -1) != '/')
125
-      $dir .= '/';
130
+    {
131
+          $dir .= '/';
132
+    }
126 133
 
127 134
     do
128 135
     {
@@ -143,7 +150,12 @@  discard block
 block discarded – undo
143 150
         if($object != "." && $object != "..")
144 151
         {
145 152
           if(filetype($dir . "/" . $object) == "dir")
146
-            rrmdir($dir . "/" . $object); else unlink($dir . "/" . $object);
153
+          {
154
+                      rrmdir($dir . "/" . $object);
155
+          }
156
+          else {
157
+              unlink($dir . "/" . $object);
158
+            }
147 159
         }
148 160
       }
149 161
       reset($objects);
@@ -157,18 +169,25 @@  discard block
 block discarded – undo
157 169
     {
158 170
       // Check if there are valid base64 characters
159 171
       if(!preg_match('/^[a-zA-Z0-9\/\r\n+]*={0,2}$/', $str))
160
-        return false;
172
+      {
173
+              return false;
174
+      }
161 175
 
162 176
       // Decode the string in strict mode and check the results
163 177
       $decoded = base64_decode($str, true);
164 178
       if($decoded === false)
165
-        return false;
179
+      {
180
+              return false;
181
+      }
166 182
 
167 183
       // Encode the string again
168 184
       if(base64_encode($decoded) === $str)
169
-        return true;
170
-      else
171
-        return false;
185
+      {
186
+              return true;
187
+      }
188
+      else {
189
+              return false;
190
+      }
172 191
     }
173 192
     catch(Exception $e)
174 193
     {
@@ -210,7 +229,9 @@  discard block
 block discarded – undo
210 229
         // set the vcard extension in case the user
211 230
         // defined it in the config
212 231
         if(isset($conf['extension']))
213
-          $carddav->setVcardExtension($conf['extension']);
232
+        {
233
+                  $carddav->setVcardExtension($conf['extension']);
234
+        }
214 235
 
215 236
         // retrieve data from the CardDAV server now
216 237
         $xmldata = $carddav->get();
@@ -219,7 +240,9 @@  discard block
 block discarded – undo
219 240
         // CardDAV server and if not reencode it since the FRITZ!Box
220 241
         // requires UTF-8 encoded data
221 242
         if(iconv('utf-8', 'utf-8//IGNORE', $xmldata) != $xmldata)
222
-          $xmldata = utf8_encode($xmldata);
243
+        {
244
+                  $xmldata = utf8_encode($xmldata);
245
+        }
223 246
 
224 247
         // read raw_vcard data from xml response
225 248
         $raw_vcards = array();
@@ -241,10 +264,14 @@  discard block
 block discarded – undo
241 264
           $vcard_obj = new vCard(false, $v);
242 265
           $name_arr = null;
243 266
           if(isset($vcard_obj->n[0]))
244
-            $name_arr = $vcard_obj->n[0];
267
+          {
268
+                      $name_arr = $vcard_obj->n[0];
269
+          }
245 270
           $org_arr = null;
246 271
           if(isset($vcard_obj->org[0]))
247
-            $org_arr = $vcard_obj->org[0];
272
+          {
273
+                      $org_arr = $vcard_obj->org[0];
274
+          }
248 275
           $addnames = '';
249 276
           $prefix = '';
250 277
           $suffix = '';
@@ -252,16 +279,24 @@  discard block
 block discarded – undo
252 279
 
253 280
           // Build name Parts if existing ans switch to true in config
254 281
           if(isset($name_arr['prefixes']) and $this->config['prefix'])
255
-            $prefix = trim($name_arr['prefixes']);
282
+          {
283
+                      $prefix = trim($name_arr['prefixes']);
284
+          }
256 285
 
257 286
           if(isset($name_arr['suffixes']) and $this->config['suffix'])
258
-            $suffix = trim($name_arr['suffixes']);
287
+          {
288
+                      $suffix = trim($name_arr['suffixes']);
289
+          }
259 290
 
260 291
           if(isset($name_arr['additionalnames']) and $this->config['addnames'])
261
-            $addnames = trim($name_arr['additionalnames']);
292
+          {
293
+                      $addnames = trim($name_arr['additionalnames']);
294
+          }
262 295
 
263 296
           if(isset($org_arr['name']) and $this->config['orgname'])
264
-            $orgname = trim($org_arr['name']);
297
+          {
298
+                      $orgname = trim($org_arr['name']);
299
+          }
265 300
 
266 301
           $firstname = trim($name_arr['firstname']);
267 302
           $lastname = trim($name_arr['lastname']);
@@ -281,71 +316,97 @@  discard block
 block discarded – undo
281 316
 
282 317
           // Prefix
283 318
           if(!empty($prefix))
284
-            $name .= $prefix;
319
+          {
320
+                      $name .= $prefix;
321
+          }
285 322
 
286 323
           if($format == 0)
287 324
           {
288 325
             // Lastname
289 326
             if(!empty($name) and !empty($lastname))
290
-              $name .= ' ' . $lastname;
291
-            else
292
-              $name .= $lastname;
327
+            {
328
+                          $name .= ' ' . $lastname;
329
+            }
330
+            else {
331
+                          $name .= $lastname;
332
+            }
293 333
           }
294 334
           else
295 335
           {
296 336
             // Firstname
297 337
             if(!empty($name) and !empty($firstname))
298
-              $name .= ' ' . $firstname;
299
-            else
300
-              $name .= $firstname;
338
+            {
339
+                          $name .= ' ' . $firstname;
340
+            }
341
+            else {
342
+                          $name .= $firstname;
343
+            }
301 344
           }
302 345
 
303 346
           if($format == 2)
304 347
           {
305 348
             // AdditionalNames
306 349
             if(!empty($name) and !empty($addnames))
307
-              $name .= ' ' . $addnames;
308
-            else
309
-              $name .= $addnames;
350
+            {
351
+                          $name .= ' ' . $addnames;
352
+            }
353
+            else {
354
+                          $name .= $addnames;
355
+            }
310 356
           }
311 357
 
312 358
           if($format == 0)
313 359
           {
314 360
             // Firstname
315 361
             if(!empty($name) and !empty($firstname))
316
-              $name .= ', ' . $firstname;
317
-            else
318
-              $name .= $firstname;
362
+            {
363
+                          $name .= ', ' . $firstname;
364
+            }
365
+            else {
366
+                          $name .= $firstname;
367
+            }
319 368
           }
320 369
           else
321 370
           {
322 371
             // Lastname
323 372
             if(!empty($name) and !empty($lastname))
324
-              $name .= ' ' . $lastname;
325
-            else
326
-              $name .= $lastname;
373
+            {
374
+                          $name .= ' ' . $lastname;
375
+            }
376
+            else {
377
+                          $name .= $lastname;
378
+            }
327 379
           }
328 380
 
329 381
           if($format != 2)
330 382
           {
331 383
             // AdditionalNames
332 384
             if(!empty($name) and !empty($addnames))
333
-              $name .= ' ' . $addnames;
334
-            else
335
-              $name .= $addnames;
385
+            {
386
+                          $name .= ' ' . $addnames;
387
+            }
388
+            else {
389
+                          $name .= $addnames;
390
+            }
336 391
           }
337 392
 
338 393
           // Suffix
339 394
           if(!empty($name) and !empty($suffix))
340
-            $name .= ' ' . $suffix;
341
-          else
342
-            $name .= $suffix;
395
+          {
396
+                      $name .= ' ' . $suffix;
397
+          }
398
+          else {
399
+                      $name .= $suffix;
400
+          }
343 401
 
344 402
           // OrgName
345 403
           if(!empty($name) and !empty($orgname))
346
-            $name .= ' (' . $orgname . ')';
347
-          else
348
-            $name .= $orgname;
404
+          {
405
+                      $name .= ' (' . $orgname . ')';
406
+          }
407
+          else {
408
+                      $name .= $orgname;
409
+          }
349 410
 
350 411
           // make sure to trim whitespaces and double spaces
351 412
           $name = trim(str_replace('  ', ' ', $name));
@@ -370,15 +431,19 @@  discard block
 block discarded – undo
370 431
               array('', '_', '_', '_', 'ae', 'oe', 'ue', 'Ae', 'Oe', 'Ue', 'ss', 'a', 'a', 'o', 'o', 'u', 'u', 'i', 'oe'), $name);
371 432
             }
372 433
           }
373
-          else
374
-            $photo = '';
434
+          else {
435
+                      $photo = '';
436
+          }
375 437
 
376 438
           // phone
377 439
           $phone_no = array();
378 440
           if($vcard_obj->categories)
379
-            $categories = $vcard_obj->categories[0];
380
-          else
381
-            $categories = array();
441
+          {
442
+                      $categories = $vcard_obj->categories[0];
443
+          }
444
+          else {
445
+                      $categories = array();
446
+          }
382 447
 
383 448
           // check for quickdial entry
384 449
           if(isset($vcard_obj->note[0]))
@@ -413,9 +478,10 @@  discard block
 block discarded – undo
413 478
                 break;
414 479
               }
415 480
             }
416
-          } 
417
-          else
418
-            $add_entry = 1;
481
+          }
482
+          else {
483
+                      $add_entry = 1;
484
+          }
419 485
 
420 486
           if($add_entry == 1)
421 487
           {
@@ -440,9 +506,13 @@  discard block
 block discarded – undo
440 506
                   {
441 507
                     //Set quickdial
442 508
                     if($value == 1)
443
-                      print "\nWARNING: Quickdial value 1 (**701) is not possible but used! \n";
509
+                    {
510
+                                          print "\nWARNING: Quickdial value 1 (**701) is not possible but used! \n";
511
+                    }
444 512
                     elseif($value >= 100)
445
-                      print "\nWARNING: Quickdial value bigger than 99 (**799) is not possible but used! \n";
513
+                    {
514
+                                          print "\nWARNING: Quickdial value bigger than 99 (**799) is not possible but used! \n";
515
+                    }
446 516
 
447 517
                     $quickdial = $value;
448 518
                   }
@@ -452,23 +522,38 @@  discard block
 block discarded – undo
452 522
 
453 523
                 // find out priority
454 524
                 if(in_array("pref", $typearr_lower))
455
-                  $prio = 1;
525
+                {
526
+                                  $prio = 1;
527
+                }
456 528
 
457 529
                 // set the proper type
458 530
                 if(in_array("cell", $typearr_lower))
459
-                  $type = "mobile";
531
+                {
532
+                                  $type = "mobile";
533
+                }
460 534
                 elseif(in_array("home", $typearr_lower))
461
-                  $type = "home";
535
+                {
536
+                                  $type = "home";
537
+                }
462 538
                 elseif(in_array("fax", $typearr_lower))
463
-                  $type = "fax_work";
539
+                {
540
+                                  $type = "fax_work";
541
+                }
464 542
                 elseif(in_array("work", $typearr_lower))
465
-                  $type = "work";
543
+                {
544
+                                  $type = "work";
545
+                }
466 546
                 elseif(in_array("other", $typearr_lower))
467
-                  $type = "other";
547
+                {
548
+                                  $type = "other";
549
+                }
468 550
                 elseif(in_array("dom", $typearr_lower))
469
-                  $type = "other";
470
-                else
471
-                  continue;
551
+                {
552
+                                  $type = "other";
553
+                }
554
+                else {
555
+                                  continue;
556
+                }
472 557
               }
473 558
               $phone_no[] = array("type"=>$type, "prio"=>$prio, "quickdial"=>$quickdial, "value" => $this->_clear_phone_number($phone_number));
474 559
             }
@@ -488,13 +573,20 @@  discard block
 block discarded – undo
488 573
                   $email = $e['value'];
489 574
                   $typearr_lower = unserialize(strtolower(serialize($e['type'])));
490 575
                   if(in_array("work", $typearr_lower))
491
-                    $type_email = "work";
576
+                  {
577
+                                      $type_email = "work";
578
+                  }
492 579
                   elseif(in_array("home", $typearr_lower))
493
-                    $type_email = "home";
580
+                  {
581
+                                      $type_email = "home";
582
+                  }
494 583
                   elseif(in_array("other", $typearr_lower))
495
-                    $type_email = "other";
496
-                  else
497
-                    continue;
584
+                  {
585
+                                      $type_email = "other";
586
+                  }
587
+                  else {
588
+                                      continue;
589
+                  }
498 590
                 }
499 591
 
500 592
                 // DEBUG: print out the email address on the console
@@ -522,7 +614,9 @@  discard block
 block discarded – undo
522 614
   public function build_fb_xml()
523 615
   {
524 616
     if(empty($this->entries))
525
-      throw new Exception('No entries available! Call get_carddav_entries or set $this->entries manually!');
617
+    {
618
+          throw new Exception('No entries available! Call get_carddav_entries or set $this->entries manually!');
619
+    }
526 620
 
527 621
     // create FB XML in utf-8 format
528 622
     $root = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><phonebooks><phonebook></phonebook></phonebooks>');
@@ -561,7 +655,9 @@  discard block
 block discarded – undo
561 655
 
562 656
       // output a warning if no telephone number was found
563 657
       if($id == 0)
564
-        print "  WARNING: no phone entry found. VCard will be ignored." . PHP_EOL;
658
+      {
659
+              print "  WARNING: no phone entry found. VCard will be ignored." . PHP_EOL;
660
+      }
565 661
 
566 662
       // email: put the email addresses into the fritzbox xml file
567 663
       $email = $contact->addChild("services");
@@ -611,8 +707,9 @@  discard block
 block discarded – undo
611 707
 
612 708
             print "  Added photo: " . basename($photo_file) . PHP_EOL;
613 709
           }
614
-          else
615
-           print "  WARNING: Only jpg contact photos are currently supported." . PHP_EOL;
710
+          else {
711
+                     print "  WARNING: Only jpg contact photos are currently supported." . PHP_EOL;
712
+          }
616 713
         }
617 714
         elseif(substr($entry['photo_data'][0], 0, 4) == 'http')
618 715
         {
@@ -621,8 +718,9 @@  discard block
 block discarded – undo
621 718
 
622 719
           print "  Added photo: " . $entry['photo_data'][0] . PHP_EOL;
623 720
         }
624
-        else
625
-          print "  WARNING: Only VCard embedded photo data or a reference URL is currently supported." . PHP_EOL;
721
+        else {
722
+                  print "  WARNING: Only VCard embedded photo data or a reference URL is currently supported." . PHP_EOL;
723
+        }
626 724
       }
627 725
 
628 726
       $contact->addChild("services");
@@ -642,20 +740,28 @@  discard block
 block discarded – undo
642 740
   public function _concat($text1, $text2)
643 741
   {
644 742
     if($text1 == '')
645
-      return $text2;
743
+    {
744
+          return $text2;
745
+    }
646 746
     elseif($text2 == '')
647
-      return $text1;
648
-    else
649
-      return $text1 . ", " . $text2;
747
+    {
748
+          return $text1;
749
+    }
750
+    else {
751
+          return $text1 . ", " . $text2;
752
+    }
650 753
   }
651 754
 
652 755
   public function _parse_fb_result($text)
653 756
   {
654 757
     preg_match("/\<h2\>([^\<]+)\<\/h2\>/", $text, $matches);
655 758
     if($matches)
656
-      return $matches[1];
657
-    else
658
-      return "Error while uploading xml to fritzbox";
759
+    {
760
+          return $matches[1];
761
+    }
762
+    else {
763
+          return "Error while uploading xml to fritzbox";
764
+    }
659 765
   }
660 766
 
661 767
   public function upload_to_fb()
@@ -741,12 +847,16 @@  discard block
 block discarded – undo
741 847
 
742 848
                   ftp_pasv($conn_id, true);
743 849
                   if(!ftp_put($conn_id, $remote_path . "/" . $file, $fileinfo->getPathname(), FTP_BINARY))
744
-                    print " ERROR: while uploading file " . $fileinfo->getFilename() . PHP_EOL;
745
-                  else
746
-                    print " ok." . PHP_EOL;
850
+                  {
851
+                                      print " ERROR: while uploading file " . $fileinfo->getFilename() . PHP_EOL;
852
+                  }
853
+                  else {
854
+                                      print " ok." . PHP_EOL;
855
+                  }
856
+                }
857
+                else {
858
+                                  print " ok." . PHP_EOL;
747 859
                 }
748
-                else
749
-                  print " ok." . PHP_EOL;
750 860
 
751 861
                 // cleanup old files
752 862
                 foreach($all_existing_files as $existing_file)
@@ -758,20 +868,23 @@  discard block
 block discarded – undo
758 868
                   }
759 869
                 }
760 870
               }
761
-              else
762
-                print " already exists." . PHP_EOL;
871
+              else {
872
+                              print " already exists." . PHP_EOL;
873
+              }
763 874
             }
764 875
           }
765 876
         }
766 877
       }
767
-      else
768
-        print " ERROR: couldn't login to FTP-server '" . $ftp_server . "' with provided username/password settings." . PHP_EOL;
878
+      else {
879
+              print " ERROR: couldn't login to FTP-server '" . $ftp_server . "' with provided username/password settings." . PHP_EOL;
880
+      }
769 881
 
770 882
       // close ftp connection
771 883
       ftp_close($conn_id);
772 884
     }
773
-    else
774
-      print " ERROR: couldn't connect to FTP server '" . $ftp_server . "'." . PHP_EOL;
885
+    else {
886
+          print " ERROR: couldn't connect to FTP server '" . $ftp_server . "'." . PHP_EOL;
887
+    }
775 888
 
776 889
     // in case numeric IP is given, try to resolve to hostname. Otherwise Fritzbox may decline login, because it is determine to be (prohibited) remote access
777 890
     $hostname = $this->config['fritzbox_ip'];
@@ -779,7 +892,9 @@  discard block
 block discarded – undo
779 892
     {
780 893
       $hostname = gethostbyaddr($hostname);
781 894
       if($hostname == $this->config['fritzbox_ip'])
782
-        print " WARNING: Unable to get hostname for IP address (" . $this->config['fritzbox_ip'] . ") <" . $hostname . "<" . PHP_EOL;
895
+      {
896
+              print " WARNING: Unable to get hostname for IP address (" . $this->config['fritzbox_ip'] . ") <" . $hostname . "<" . PHP_EOL;
897
+      }
783 898
       else
784 899
       {
785 900
         print " INFO: Given IP address (" . $this->config['fritzbox_ip'] . ") has hostname " . $hostname . "." . PHP_EOL;
Please login to merge, or discard this patch.