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 ( 6a121b...8b886b )
by Jens
02:50
created
carddav2fb.php 1 patch
Spacing   +129 added lines, -129 removed lines patch added patch discarded remove patch
@@ -27,9 +27,9 @@  discard block
 block discarded – undo
27 27
 
28 28
 // check for the minimum php version
29 29
 $php_min_version = '5.3.6';
30
-if(version_compare(PHP_VERSION, $php_min_version) < 0)
30
+if (version_compare(PHP_VERSION, $php_min_version) < 0)
31 31
 {
32
-  print 'ERROR: PHP version '.$php_min_version.' is required. Found version: ' . PHP_VERSION . PHP_EOL;
32
+  print 'ERROR: PHP version ' . $php_min_version . ' is required. Found version: ' . PHP_VERSION . PHP_EOL;
33 33
   exit(1);
34 34
 }
35 35
 
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
 require_once('lib/vCard-parser/vCard.php');
38 38
 require_once('lib/fritzbox_api_php/fritzbox_api.class.php');
39 39
 
40
-if($argc == 2)
40
+if ($argc == 2)
41 41
   $config_file_name = $argv[1];
42 42
 else
43 43
   $config_file_name = __DIR__ . '/config.php';
@@ -59,11 +59,11 @@  discard block
 block discarded – undo
59 59
 $config['build_photos'] = true;
60 60
 $config['quickdial_keyword'] = 'Quickdial:';
61 61
 
62
-if(is_file($config_file_name))
62
+if (is_file($config_file_name))
63 63
   require($config_file_name);
64 64
 else
65 65
 {
66
-  print 'ERROR: No '.$config_file_name.' found, please take a look at config.example.php and create a '.$config_file_name.' file!'.PHP_EOL;
66
+  print 'ERROR: No ' . $config_file_name . ' found, please take a look at config.example.php and create a ' . $config_file_name . ' file!' . PHP_EOL;
67 67
   exit(1);
68 68
 }
69 69
 
@@ -119,14 +119,14 @@  discard block
 block discarded – undo
119 119
   }
120 120
 
121 121
   // Source: https://php.net/manual/de/function.tempnam.php#61436
122
-  public function mktemp($dir, $prefix='', $mode=0700)
122
+  public function mktemp($dir, $prefix = '', $mode = 0700)
123 123
   {
124
-    if(substr($dir, -1) != '/')
124
+    if (substr($dir, -1) != '/')
125 125
       $dir .= '/';
126 126
 
127 127
     do
128 128
     {
129
-      $path = $dir.$prefix.mt_rand(0, 9999999);
129
+      $path = $dir . $prefix . mt_rand(0, 9999999);
130 130
     }
131 131
     while (!mkdir($path, $mode));
132 132
 
@@ -135,15 +135,15 @@  discard block
 block discarded – undo
135 135
 
136 136
   public function rmtemp($dir)
137 137
   {
138
-    if(is_dir($dir))
138
+    if (is_dir($dir))
139 139
     {
140 140
       $objects = scandir($dir);
141
-      foreach($objects as $object)
141
+      foreach ($objects as $object)
142 142
       {
143
-        if($object != "." && $object != "..")
143
+        if ($object != "." && $object != "..")
144 144
         {
145
-          if(filetype($dir."/".$object) == "dir")
146
-            rrmdir($dir."/".$object); else unlink($dir."/".$object);
145
+          if (filetype($dir . "/" . $object) == "dir")
146
+            rrmdir($dir . "/" . $object); else unlink($dir . "/" . $object);
147 147
         }
148 148
       }
149 149
       reset($objects);
@@ -156,21 +156,21 @@  discard block
 block discarded – undo
156 156
     try
157 157
     {
158 158
       // Check if there are valid base64 characters
159
-      if(!preg_match('/^[a-zA-Z0-9\/\r\n+]*={0,2}$/', $str))
159
+      if (!preg_match('/^[a-zA-Z0-9\/\r\n+]*={0,2}$/', $str))
160 160
         return false;
161 161
 
162 162
       // Decode the string in strict mode and check the results
163 163
       $decoded = base64_decode($str, true);
164
-      if($decoded === false)
164
+      if ($decoded === false)
165 165
         return false;
166 166
 
167 167
       // Encode the string again
168
-      if(base64_encode($decoded) === $str)
168
+      if (base64_encode($decoded) === $str)
169 169
         return true;
170 170
       else
171 171
         return false;
172 172
     }
173
-    catch(Exception $e)
173
+    catch (Exception $e)
174 174
     {
175 175
       // If exception is caught, then it is not a base64 encoded string
176 176
       return false;
@@ -199,9 +199,9 @@  discard block
 block discarded – undo
199 199
     $imgseqfname = 1;
200 200
     $snum = 0;
201 201
 
202
-    if(is_array($this->config['carddav']))
202
+    if (is_array($this->config['carddav']))
203 203
     {
204
-      foreach($this->config['carddav'] as $conf)
204
+      foreach ($this->config['carddav'] as $conf)
205 205
       {
206 206
         print " [" . $snum . "]: " . $conf['url'] . " ";
207 207
         $carddav = new CardDavPHP\CardDavBackend($conf['url']);
@@ -209,23 +209,23 @@  discard block
 block discarded – undo
209 209
 
210 210
         // set the vcard extension in case the user
211 211
         // defined it in the config
212
-        if(isset($conf['extension']))
212
+        if (isset($conf['extension']))
213 213
           $carddav->setVcardExtension($conf['extension']);
214 214
 
215 215
         // retrieve data from the CardDAV server now
216
-        $xmldata =  $carddav->get();
216
+        $xmldata = $carddav->get();
217 217
 
218 218
         // identify if we received UTF-8 encoded data from the
219 219
         // CardDAV server and if not reencode it since the FRITZ!Box
220 220
         // requires UTF-8 encoded data
221
-        if(iconv('utf-8', 'utf-8//IGNORE', $xmldata) != $xmldata)
221
+        if (iconv('utf-8', 'utf-8//IGNORE', $xmldata) != $xmldata)
222 222
           $xmldata = utf8_encode($xmldata);
223 223
 
224 224
         // read raw_vcard data from xml response
225 225
         $raw_vcards = array();
226 226
         $xmlvcard = new SimpleXMLElement($xmldata);
227 227
 
228
-        foreach($xmlvcard->element as $vcard_element)
228
+        foreach ($xmlvcard->element as $vcard_element)
229 229
         {
230 230
           $id = $vcard_element->id->__toString();
231 231
           $value = (string)$vcard_element->vcard->__toString();
@@ -236,14 +236,14 @@  discard block
 block discarded – undo
236 236
 
237 237
         // parse raw_vcards
238 238
         $quick_dial_arr = array();
239
-        foreach($raw_vcards as $v)
239
+        foreach ($raw_vcards as $v)
240 240
         {
241 241
           $vcard_obj = new vCard(false, $v);
242 242
           $name_arr = null;
243
-          if(isset($vcard_obj->n[0]))
243
+          if (isset($vcard_obj->n[0]))
244 244
             $name_arr = $vcard_obj->n[0];
245 245
           $org_arr = null;
246
-          if(isset($vcard_obj->org[0]))
246
+          if (isset($vcard_obj->org[0]))
247 247
             $org_arr = $vcard_obj->org[0];
248 248
           $addnames = '';
249 249
           $prefix = '';
@@ -251,16 +251,16 @@  discard block
 block discarded – undo
251 251
           $orgname = '';
252 252
 
253 253
           // Build name Parts if existing ans switch to true in config
254
-          if(isset($name_arr['prefixes']) AND $this->config['prefix'])
254
+          if (isset($name_arr['prefixes']) AND $this->config['prefix'])
255 255
             $prefix = trim($name_arr['prefixes']);
256 256
 
257
-          if(isset($name_arr['suffixes']) AND $this->config['suffix'])
257
+          if (isset($name_arr['suffixes']) AND $this->config['suffix'])
258 258
             $suffix = trim($name_arr['suffixes']);
259 259
 
260
-          if(isset($name_arr['additionalnames']) AND $this->config['addnames'])
260
+          if (isset($name_arr['additionalnames']) AND $this->config['addnames'])
261 261
             $addnames = trim($name_arr['additionalnames']);
262 262
 
263
-          if(isset($org_arr['name']) AND $this->config['orgname'])
263
+          if (isset($org_arr['name']) AND $this->config['orgname'])
264 264
             $orgname = trim($org_arr['name']);
265 265
 
266 266
           $firstname = trim($name_arr['firstname']);
@@ -280,13 +280,13 @@  discard block
 block discarded – undo
280 280
           $format = $this->config['fullname_format'];
281 281
 
282 282
           // Prefix
283
-          if(!empty($prefix))
283
+          if (!empty($prefix))
284 284
             $name .= $prefix;
285 285
 
286
-          if($format == 0)
286
+          if ($format == 0)
287 287
           {
288 288
             // Lastname
289
-            if(!empty($name) AND !empty($lastname))
289
+            if (!empty($name) AND !empty($lastname))
290 290
               $name .= ' ' . $lastname;
291 291
             else
292 292
               $name .= $lastname;
@@ -294,25 +294,25 @@  discard block
 block discarded – undo
294 294
           else
295 295
           {
296 296
             // Firstname
297
-            if(!empty($name) AND !empty($firstname))
297
+            if (!empty($name) AND !empty($firstname))
298 298
               $name .= ' ' . $firstname;
299 299
             else
300 300
               $name .= $firstname;
301 301
           }
302 302
 
303
-          if($format == 2)
303
+          if ($format == 2)
304 304
           {
305 305
             // AdditionalNames
306
-            if(!empty($name) AND !empty($addnames))
306
+            if (!empty($name) AND !empty($addnames))
307 307
               $name .= ' ' . $addnames;
308 308
             else
309 309
               $name .= $addnames;
310 310
           }
311 311
 
312
-          if($format == 0)
312
+          if ($format == 0)
313 313
           {
314 314
             // Firstname
315
-            if(!empty($name) AND !empty($firstname))
315
+            if (!empty($name) AND !empty($firstname))
316 316
               $name .= ', ' . $firstname;
317 317
             else
318 318
               $name .= $firstname;
@@ -320,29 +320,29 @@  discard block
 block discarded – undo
320 320
           else
321 321
           {
322 322
             // Lastname
323
-            if(!empty($name) AND !empty($lastname))
323
+            if (!empty($name) AND !empty($lastname))
324 324
               $name .= ' ' . $lastname;
325 325
             else
326 326
               $name .= $lastname;
327 327
           }
328 328
 
329
-          if($format != 2)
329
+          if ($format != 2)
330 330
           {
331 331
             // AdditionalNames
332
-            if(!empty($name) AND !empty($addnames))
332
+            if (!empty($name) AND !empty($addnames))
333 333
               $name .= ' ' . $addnames;
334 334
             else
335 335
               $name .= $addnames;
336 336
           }
337 337
 
338 338
           // Suffix
339
-          if(!empty($name) AND !empty($suffix))
339
+          if (!empty($name) AND !empty($suffix))
340 340
             $name .= ' ' . $suffix;
341 341
           else
342 342
             $name .= $suffix;
343 343
 
344 344
           // OrgName
345
-          if(!empty($name) AND !empty($orgname))
345
+          if (!empty($name) AND !empty($orgname))
346 346
             $name .= ' (' . $orgname . ')';
347 347
           else
348 348
             $name .= $orgname;
@@ -350,24 +350,24 @@  discard block
 block discarded – undo
350 350
           // make sure to trim whitespaces and double spaces
351 351
           $name = trim(str_replace('  ', ' ', $name));
352 352
 
353
-          if(empty($name))
353
+          if (empty($name))
354 354
           {
355 355
             print '  WARNING: No fullname, lastname or orgname found!';
356 356
             $name = 'UNKNOWN';
357 357
           }
358 358
 
359 359
           // format filename of contact photo; remove special letters, added config option for sequential filnames default is false
360
-          if($vcard_obj->photo)
360
+          if ($vcard_obj->photo)
361 361
           {
362
-            if(isset($this->config['seq_photo_name']) AND $this->config['seq_photo_name'] == true)
362
+            if (isset($this->config['seq_photo_name']) AND $this->config['seq_photo_name'] == true)
363 363
             {
364 364
               $photo = $imgseqfname;
365 365
               $imgseqfname++;
366 366
             }
367 367
             else
368 368
             {
369
-              $photo = str_replace(array(',','&',' ','/','ä','ö','ü','Ä','Ö','Ü','ß','á','à','ó','ò','ú','ù','í','ø'),
370
-              array('','_','_','_','ae','oe','ue','Ae','Oe','Ue','ss','a','a','o','o','u','u','i','oe'),$name);
369
+              $photo = str_replace(array(',', '&', ' ', '/', 'ä', 'ö', 'ü', 'Ä', 'Ö', 'Ü', 'ß', 'á', 'à', 'ó', 'ò', 'ú', 'ù', 'í', 'ø'),
370
+              array('', '_', '_', '_', 'ae', 'oe', 'ue', 'Ae', 'Oe', 'Ue', 'ss', 'a', 'a', 'o', 'o', 'u', 'u', 'i', 'oe'), $name);
371 371
             }
372 372
           }
373 373
           else
@@ -375,25 +375,25 @@  discard block
 block discarded – undo
375 375
 
376 376
           // phone
377 377
           $phone_no = array();
378
-          if($vcard_obj->categories)
378
+          if ($vcard_obj->categories)
379 379
             $categories = $vcard_obj->categories[0];
380 380
           else
381 381
             $categories = array();
382 382
 
383 383
           // check for quickdial entry
384
-          if(isset($vcard_obj->note[0]))
384
+          if (isset($vcard_obj->note[0]))
385 385
           {
386 386
             $note = $vcard_obj->note[0];
387 387
             $notes = explode($this->config['quickdial_keyword'], $note);
388
-            foreach($notes as $linenr => $linecontent)
388
+            foreach ($notes as $linenr => $linecontent)
389 389
             {
390
-              $found = strrpos($linecontent , ":**7");
391
-              if($found > 0)
390
+              $found = strrpos($linecontent, ":**7");
391
+              if ($found > 0)
392 392
               {
393
-                $pos_qd_start = strrpos($linecontent , ":**7" );
394
-                $quick_dial_for_nr = preg_replace("/[^0-9+]/", "",substr($linecontent , 0, $pos_qd_start));
395
-                $quick_dial_nr = intval(substr($linecontent , $pos_qd_start+4, 3));
396
-                $quick_dial_arr[$quick_dial_for_nr]=$quick_dial_nr;
393
+                $pos_qd_start = strrpos($linecontent, ":**7");
394
+                $quick_dial_for_nr = preg_replace("/[^0-9+]/", "", substr($linecontent, 0, $pos_qd_start));
395
+                $quick_dial_nr = intval(substr($linecontent, $pos_qd_start + 4, 3));
396
+                $quick_dial_arr[$quick_dial_for_nr] = $quick_dial_nr;
397 397
               }
398 398
             }
399 399
           }
@@ -402,12 +402,12 @@  discard block
 block discarded – undo
402 402
           $email_add = array();
403 403
           $vip = isset($this->config['group_vip']) && in_array((string)$this->config['group_vip'], $categories);
404 404
 
405
-          if(array_key_exists('group_filter',$this->config) && is_array($this->config['group_filter']))
405
+          if (array_key_exists('group_filter', $this->config) && is_array($this->config['group_filter']))
406 406
           {
407 407
             $add_entry = 0;
408
-            foreach($this->config['group_filter'] as $group_filter)
408
+            foreach ($this->config['group_filter'] as $group_filter)
409 409
             {
410
-              if(in_array($group_filter,$categories))
410
+              if (in_array($group_filter, $categories))
411 411
               {
412 412
                 $add_entry = 1;
413 413
                 break;
@@ -417,14 +417,14 @@  discard block
 block discarded – undo
417 417
           else
418 418
             $add_entry = 1;
419 419
 
420
-          if($add_entry == 1)
420
+          if ($add_entry == 1)
421 421
           {
422
-            foreach($vcard_obj->tel as $t)
422
+            foreach ($vcard_obj->tel as $t)
423 423
             {
424 424
               $prio = 0;
425
-              $quickdial =null;
425
+              $quickdial = null;
426 426
               
427
-              if(!is_array($t) || empty($t['type']))
427
+              if (!is_array($t) || empty($t['type']))
428 428
               {
429 429
                 $type = "mobile";
430 430
                 $phone_number = $t;
@@ -433,15 +433,15 @@  discard block
 block discarded – undo
433 433
               {
434 434
                 $phone_number = $t['value'];
435 435
                 
436
-                $phone_number_clean = preg_replace("/[^0-9+]/", "",$phone_number);
437
-                foreach($quick_dial_arr as $qd_phone_nr => $value)
436
+                $phone_number_clean = preg_replace("/[^0-9+]/", "", $phone_number);
437
+                foreach ($quick_dial_arr as $qd_phone_nr => $value)
438 438
                 {
439
-                  if($qd_phone_nr == $phone_number_clean)
439
+                  if ($qd_phone_nr == $phone_number_clean)
440 440
                   {
441 441
                     //Set quickdial
442
-                    if($value == 1)
442
+                    if ($value == 1)
443 443
                       print "\nWARNING: Quickdial value 1 (**701) is not possible but used! \n";
444
-                    elseif($value >= 100)
444
+                    elseif ($value >= 100)
445 445
                       print "\nWARNING: Quickdial value bigger than 99 (**799) is not possible but used! \n";
446 446
 
447 447
                     $quickdial = $value;
@@ -451,34 +451,34 @@  discard block
 block discarded – undo
451 451
                 $typearr_lower = unserialize(strtolower(serialize($t['type'])));
452 452
 
453 453
                 // find out priority
454
-                if(in_array("pref", $typearr_lower))
454
+                if (in_array("pref", $typearr_lower))
455 455
                   $prio = 1;
456 456
 
457 457
                 // set the proper type
458
-                if(in_array("cell", $typearr_lower))
458
+                if (in_array("cell", $typearr_lower))
459 459
                   $type = "mobile";
460
-                elseif(in_array("home", $typearr_lower))
460
+                elseif (in_array("home", $typearr_lower))
461 461
                   $type = "home";
462
-                elseif(in_array("fax", $typearr_lower))
462
+                elseif (in_array("fax", $typearr_lower))
463 463
                   $type = "fax_work";
464
-                elseif(in_array("work", $typearr_lower))
464
+                elseif (in_array("work", $typearr_lower))
465 465
                   $type = "work";
466
-                elseif(in_array("other", $typearr_lower))
466
+                elseif (in_array("other", $typearr_lower))
467 467
                   $type = "other";
468
-                elseif(in_array("dom", $typearr_lower))
468
+                elseif (in_array("dom", $typearr_lower))
469 469
                   $type = "other";
470 470
                 else
471 471
                   continue;
472 472
               }
473
-              $phone_no[] =  array("type"=>$type, "prio"=>$prio, "quickdial"=>$quickdial, "value" => $this->_clear_phone_number($phone_number));
473
+              $phone_no[] = array("type"=>$type, "prio"=>$prio, "quickdial"=>$quickdial, "value" => $this->_clear_phone_number($phone_number));
474 474
             }
475 475
 
476 476
             // request email address and type
477
-            if($vcard_obj->email)
477
+            if ($vcard_obj->email)
478 478
             {
479
-              foreach($vcard_obj->email as $e)
479
+              foreach ($vcard_obj->email as $e)
480 480
               {
481
-                if(empty($e['type']))
481
+                if (empty($e['type']))
482 482
                 {
483 483
                   $type_email = "work";
484 484
                   $email = $e;
@@ -487,11 +487,11 @@  discard block
 block discarded – undo
487 487
                 {
488 488
                   $email = $e['value'];
489 489
                   $typearr_lower = unserialize(strtolower(serialize($e['type'])));
490
-                  if(in_array("work", $typearr_lower))
490
+                  if (in_array("work", $typearr_lower))
491 491
                     $type_email = "work";
492
-                  elseif(in_array("home", $typearr_lower))
492
+                  elseif (in_array("home", $typearr_lower))
493 493
                     $type_email = "home";
494
-                  elseif(in_array("other", $typearr_lower))
494
+                  elseif (in_array("other", $typearr_lower))
495 495
                     $type_email = "other";
496 496
                   else
497 497
                     continue;
@@ -521,15 +521,15 @@  discard block
 block discarded – undo
521 521
 
522 522
   public function build_fb_xml()
523 523
   {
524
-    if(empty($this->entries))
524
+    if (empty($this->entries))
525 525
       throw new Exception('No entries available! Call get_carddav_entries or set $this->entries manually!');
526 526
 
527 527
     // create FB XML in utf-8 format
528 528
     $root = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><phonebooks><phonebook></phonebook></phonebooks>');
529 529
     $pb = $root->phonebook;
530
-    $pb->addAttribute("name",$this->config['phonebook_name']);
530
+    $pb->addAttribute("name", $this->config['phonebook_name']);
531 531
 
532
-    foreach($this->entries as $entry)
532
+    foreach ($this->entries as $entry)
533 533
     {
534 534
       $contact = $pb->addChild("contact");
535 535
       $contact->addChild("category", $entry['vip']);
@@ -541,17 +541,17 @@  discard block
 block discarded – undo
541 541
       // telephone: put the phonenumbers into the fritzbox xml file
542 542
       $telephony = $contact->addChild("telephony");
543 543
       $id = 0;
544
-      foreach($entry['telephony'] as $tel)
544
+      foreach ($entry['telephony'] as $tel)
545 545
       {
546 546
         $num = $telephony->addChild("number", $tel['value']);
547 547
         $num->addAttribute("type", $tel['type']);
548
-        $num->addAttribute("vanity","");
548
+        $num->addAttribute("vanity", "");
549 549
         $num->addAttribute("prio", $tel['prio']);
550 550
         $num->addAttribute("id", $id);
551 551
 
552
-        if(isset($tel['quickdial']))
552
+        if (isset($tel['quickdial']))
553 553
         {
554
-          $num->addAttribute("quickdial",$tel['quickdial']);
554
+          $num->addAttribute("quickdial", $tel['quickdial']);
555 555
           print "  Added quickdial: " . $tel['quickdial'] . " for: " . $tel['value'] . " (" . $tel['type'] . ")" . PHP_EOL;
556 556
         }
557 557
 
@@ -560,13 +560,13 @@  discard block
 block discarded – undo
560 560
       }
561 561
 
562 562
       // output a warning if no telephone number was found
563
-      if($id == 0)
563
+      if ($id == 0)
564 564
         print "  WARNING: no phone entry found. VCard will be ignored." . PHP_EOL;
565 565
 
566 566
       // email: put the email addresses into the fritzbox xml file
567 567
       $email = $contact->addChild("services");
568 568
       $id = 0;
569
-      foreach($entry['email'] as $mail)
569
+      foreach ($entry['email'] as $mail)
570 570
       {
571 571
         $mail_adr = $email->addChild("email", $mail['value']);
572 572
         $mail_adr->addAttribute("classifier", $mail['type']);
@@ -577,14 +577,14 @@  discard block
 block discarded – undo
577 577
       }
578 578
 
579 579
       // check for a photo being part of the VCard
580
-      if(($entry['photo']) and ($entry['photo_data']) and (is_array($entry['photo_data'])) and ($entry['photo_data'][0]))
580
+      if (($entry['photo']) and ($entry['photo_data']) and (is_array($entry['photo_data'])) and ($entry['photo_data'][0]))
581 581
       {
582 582
         // check if 'photo_data'[0] is an array as well because then
583 583
         // we have to extract ['value'] and friends.
584
-        if(is_array($entry['photo_data'][0]) and (array_key_exists('value', $entry['photo_data'][0])))
584
+        if (is_array($entry['photo_data'][0]) and (array_key_exists('value', $entry['photo_data'][0])))
585 585
         {
586 586
           // check if photo_data really contains JPEG data
587
-          if((array_key_exists('type', $entry['photo_data'][0])) and (is_array($entry['photo_data'][0]['type'])) and
587
+          if ((array_key_exists('type', $entry['photo_data'][0])) and (is_array($entry['photo_data'][0]['type'])) and
588 588
              ($entry['photo_data'][0]['type'][0] == 'jpeg' or $entry['photo_data'][0]['type'][0] == 'jpg'))
589 589
           {
590 590
             // get photo, rename, base64 convert and save as jpg
@@ -594,7 +594,7 @@  discard block
 block discarded – undo
594 594
 
595 595
             // check for base64 encoding of the photo data and convert it
596 596
             // accordingly.
597
-            if(((array_key_exists('encoding', $entry['photo_data'][0])) and ($entry['photo_data'][0]['encoding'] == 'b')) or $this->is_base64($photo_data))
597
+            if (((array_key_exists('encoding', $entry['photo_data'][0])) and ($entry['photo_data'][0]['encoding'] == 'b')) or $this->is_base64($photo_data))
598 598
             {
599 599
               file_put_contents($photo_file . ".b64", $photo_data);
600 600
               $this->base64_to_jpeg($photo_file . ".b64", $photo_file);
@@ -607,14 +607,14 @@  discard block
 block discarded – undo
607 607
             }
608 608
 
609 609
             // add contact photo to xml
610
-            $person->addChild("imageURL", $this->config['fritzbox_path'].$this->config['usb_disk']."FRITZ/fonpix/".basename($photo_file));
610
+            $person->addChild("imageURL", $this->config['fritzbox_path'] . $this->config['usb_disk'] . "FRITZ/fonpix/" . basename($photo_file));
611 611
 
612 612
             print "  Added photo: " . basename($photo_file) . PHP_EOL;
613 613
           }
614 614
           else
615 615
            print "  WARNING: Only jpg contact photos are currently supported." . PHP_EOL;
616 616
         }
617
-        elseif(substr($entry['photo_data'][0], 0, 4) == 'http')
617
+        elseif (substr($entry['photo_data'][0], 0, 4) == 'http')
618 618
         {
619 619
           // add contact photo to xml
620 620
           $person->addChild("imageURL", $entry['photo_data'][0]);
@@ -639,20 +639,20 @@  discard block
 block discarded – undo
639 639
     return $text;
640 640
   }
641 641
 
642
-  public function _concat ($text1,$text2)
642
+  public function _concat($text1, $text2)
643 643
   {
644
-    if($text1 == '')
644
+    if ($text1 == '')
645 645
       return $text2;
646
-    elseif($text2 == '')
646
+    elseif ($text2 == '')
647 647
       return $text1;
648 648
     else
649
-      return $text1.", ".$text2;
649
+      return $text1 . ", " . $text2;
650 650
   }
651 651
 
652 652
   public function _parse_fb_result($text)
653 653
   {
654 654
     preg_match("/\<h2\>([^\<]+)\<\/h2\>/", $text, $matches);
655
-    if($matches)
655
+    if ($matches)
656 656
       return $matches[1];
657 657
     else
658 658
       return "Error while uploading xml to fritzbox";
@@ -661,10 +661,10 @@  discard block
 block discarded – undo
661 661
   public function upload_to_fb()
662 662
   {
663 663
     // if the user wants to save the xml to a separate file, we do so now
664
-    if(array_key_exists('output_file',$this->config))
664
+    if (array_key_exists('output_file', $this->config))
665 665
     {
666 666
       $output = fopen($this->config['output_file'], 'w');
667
-      if($output)
667
+      if ($output)
668 668
       {
669 669
         fwrite($output, $this->fbxml);
670 670
         fclose($output);
@@ -679,24 +679,24 @@  discard block
 block discarded – undo
679 679
     // perform an ftps-connection to copy over the photos to a specified directory
680 680
     $ftp_server = $this->config['fritzbox_ip_ftp'];
681 681
     $conn_id = ftp_ssl_connect($ftp_server);
682
-    if($conn_id == false)
682
+    if ($conn_id == false)
683 683
     {
684 684
       print " WARNING: Secure connection to FTP-server '" . $ftp_server . "' failed, retrying without SSL." . PHP_EOL;
685 685
       $conn_id = ftp_connect($ftp_server);
686 686
     }
687 687
 
688
-    if($conn_id != false)
688
+    if ($conn_id != false)
689 689
     {
690 690
       ftp_set_option($conn_id, FTP_TIMEOUT_SEC, 60);
691 691
       $login_result = ftp_login($conn_id, $this->config['fritzbox_user'], $this->config['fritzbox_pw']);
692
-      if($login_result === true)
692
+      if ($login_result === true)
693 693
       {
694 694
         ftp_pasv($conn_id, true);
695 695
 
696 696
         // create remote photo path on FRITZ!Box if it doesn't exist
697
-        $remote_path = $this->config['usb_disk']."/FRITZ/fonpix";
697
+        $remote_path = $this->config['usb_disk'] . "/FRITZ/fonpix";
698 698
         $all_existing_files = ftp_nlist($conn_id, $remote_path);
699
-        if($all_existing_files == false)
699
+        if ($all_existing_files == false)
700 700
         {
701 701
           ftp_mkdir($conn_id, $remote_path);
702 702
           $all_existing_files = array();
@@ -704,43 +704,43 @@  discard block
 block discarded – undo
704 704
 
705 705
         // now iterate through all jpg files in tempdir and upload them if necessary
706 706
         $dir = new DirectoryIterator($this->tmpdir);
707
-        foreach($dir as $fileinfo)
707
+        foreach ($dir as $fileinfo)
708 708
         {
709
-          if(!$fileinfo->isDot())
709
+          if (!$fileinfo->isDot())
710 710
           {
711
-            if($fileinfo->getExtension() == "jpg")
711
+            if ($fileinfo->getExtension() == "jpg")
712 712
             {
713 713
               $file = $fileinfo->getFilename();
714 714
 
715 715
               print " FTP-Upload '" . $file . "'...";
716
-              if(!in_array($remote_path . "/" . $file, $all_existing_files))
716
+              if (!in_array($remote_path . "/" . $file, $all_existing_files))
717 717
               {
718
-                if(!ftp_put($conn_id, $remote_path . "/" . $file, $fileinfo->getPathname(), FTP_BINARY))
718
+                if (!ftp_put($conn_id, $remote_path . "/" . $file, $fileinfo->getPathname(), FTP_BINARY))
719 719
                 {
720 720
                   // retry when a fault occurs.
721 721
                   print " retrying... ";
722 722
                   $conn_id = ftp_ssl_connect($ftp_server);
723
-                  if($conn_id == false)
723
+                  if ($conn_id == false)
724 724
                   {
725 725
                     print " WARNING: Secure re-connection to FTP-server '" . $ftp_server . "' failed, retrying without SSL." . PHP_EOL;
726 726
                     $conn_id = ftp_connect($ftp_server);
727 727
                   }
728 728
 
729
-                  if($conn_id == false)
729
+                  if ($conn_id == false)
730 730
                   {
731 731
                     print " ERROR: couldn't re-connect to FTP server '" . $ftp_server . "', abortіng." . PHP_EOL;
732 732
                     break;
733 733
                   }
734 734
 
735 735
                   $login_result = ftp_login($conn_id, $this->config['fritzbox_user'], $this->config['fritzbox_pw']);
736
-                  if($login_result === false)
736
+                  if ($login_result === false)
737 737
                   {
738 738
                     print " ERROR: couldn't re-login to FTP-server '" . $ftp_server . "' with provided username/password settings." . PHP_EOL;
739 739
                     break;
740 740
                   }
741 741
 
742 742
                   ftp_pasv($conn_id, true);
743
-                  if(!ftp_put($conn_id, $remote_path . "/" . $file, $fileinfo->getPathname(), FTP_BINARY))
743
+                  if (!ftp_put($conn_id, $remote_path . "/" . $file, $fileinfo->getPathname(), FTP_BINARY))
744 744
                     print " ERROR: while uploading file " . $fileinfo->getFilename() . PHP_EOL;
745 745
                   else
746 746
                     print " ok." . PHP_EOL;
@@ -749,9 +749,9 @@  discard block
 block discarded – undo
749 749
                   print " ok." . PHP_EOL;
750 750
 
751 751
                 // cleanup old files
752
-                foreach($all_existing_files as $existing_file)
752
+                foreach ($all_existing_files as $existing_file)
753 753
                 {
754
-                  if(strpos($existing_file, $remote_path."/".substr($file, 0, -10)) !== false)
754
+                  if (strpos($existing_file, $remote_path . "/" . substr($file, 0, -10)) !== false)
755 755
                   {
756 756
                     print " FTP-Delete: " . $existing_file . PHP_EOL;
757 757
                     ftp_delete($conn_id, $remote_path . "/" . basename($existing_file));
@@ -775,14 +775,14 @@  discard block
 block discarded – undo
775 775
 
776 776
     // 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 777
     $hostname = $this->config['fritzbox_ip'];
778
-    if(filter_var($hostname, FILTER_VALIDATE_IP))
778
+    if (filter_var($hostname, FILTER_VALIDATE_IP))
779 779
     {
780 780
       $hostname = gethostbyaddr($hostname);
781
-      if($hostname ==  $this->config['fritzbox_ip'])
782
-        print " WARNING: Unable to get hostname for IP address (". $this->config['fritzbox_ip'] .") <" . $hostname . "<" . PHP_EOL;
781
+      if ($hostname == $this->config['fritzbox_ip'])
782
+        print " WARNING: Unable to get hostname for IP address (" . $this->config['fritzbox_ip'] . ") <" . $hostname . "<" . PHP_EOL;
783 783
       else
784 784
       {
785
-        print " INFO: Given IP address (". $this->config['fritzbox_ip'] .") has hostname ". $hostname . "." . PHP_EOL;
785
+        print " INFO: Given IP address (" . $this->config['fritzbox_ip'] . ") has hostname " . $hostname . "." . PHP_EOL;
786 786
         $this->config['fritzbox_ip'] = $hostname;
787 787
       }
788 788
     }
@@ -807,15 +807,15 @@  discard block
 block discarded – undo
807 807
        )
808 808
       );
809 809
 
810
-      $raw_result =  $fritz->doPostFile($formfields, $filefileds);   // send the command
810
+      $raw_result = $fritz->doPostFile($formfields, $filefileds); // send the command
811 811
       $msg = $this->_parse_fb_result($raw_result);
812
-      unset($fritz);  // destroy the object to log out
812
+      unset($fritz); // destroy the object to log out
813 813
 
814 814
       print "  FRITZ!Box returned message: '" . $msg . "'" . PHP_EOL;
815 815
     }
816
-    catch(Exception $e)
816
+    catch (Exception $e)
817 817
     {
818
-      print "  ERROR: " . $e->getMessage() . PHP_EOL;     // show the error message in anything failed
818
+      print "  ERROR: " . $e->getMessage() . PHP_EOL; // show the error message in anything failed
819 819
     }
820 820
   }
821 821
 }
Please login to merge, or discard this patch.