@@ -263,7 +263,7 @@ discard block |
||
| 263 | 263 | if(isset($org_arr['name']) and $this->config['orgname']) |
| 264 | 264 | $orgname = trim($org_arr['name']); |
| 265 | 265 | |
| 266 | - if (isset($vcard_obj->fn[0])) |
|
| 266 | + if(isset($vcard_obj->fn[0])) |
|
| 267 | 267 | $formattedname = $vcard_obj->fn[0]; |
| 268 | 268 | |
| 269 | 269 | $firstname = trim($name_arr['firstname']); |
@@ -668,7 +668,7 @@ discard block |
||
| 668 | 668 | if(array_key_exists('output_file', $this->config)) |
| 669 | 669 | { |
| 670 | 670 | // build md5 hash of previous stored xml without <mod_time> Elements |
| 671 | - $oldphonebhash = md5(preg_replace("/<mod_time>(\\d{10})/","",file_get_contents($this->config['output_file'],'r'),-1,$debugoldtsreplace)); |
|
| 671 | + $oldphonebhash = md5(preg_replace("/<mod_time>(\\d{10})/", "", file_get_contents($this->config['output_file'], 'r'), -1, $debugoldtsreplace)); |
|
| 672 | 672 | $output = fopen($this->config['output_file'], 'w'); |
| 673 | 673 | if($output) |
| 674 | 674 | { |
@@ -676,13 +676,13 @@ discard block |
||
| 676 | 676 | fclose($output); |
| 677 | 677 | print " Saved to file " . $this->config['output_file'] . PHP_EOL; |
| 678 | 678 | } |
| 679 | - if (array_key_exists('output_and_upload', $this->config) and $this->config['output_and_upload']) |
|
| 679 | + if(array_key_exists('output_and_upload', $this->config) and $this->config['output_and_upload']) |
|
| 680 | 680 | { |
| 681 | - $newphonebhash = md5(preg_replace("/<mod_time>(\\d{10})/","",file_get_contents($this->config['output_file'],'r'),-1,$debugnewtsreplace)); |
|
| 681 | + $newphonebhash = md5(preg_replace("/<mod_time>(\\d{10})/", "", file_get_contents($this->config['output_file'], 'r'), -1, $debugnewtsreplace)); |
|
| 682 | 682 | print " INFO: Compare old and new phonebook file versions." . PHP_EOL . " INFO: old version: " . $oldphonebhash . PHP_EOL . " INFO: new version: " . $newphonebhash . PHP_EOL; |
| 683 | 683 | if($oldphonebhash === $newphonebhash) |
| 684 | 684 | { |
| 685 | - print " INFO: Same versions ==> No changes in phonebook or images" . PHP_EOL . " EXIT: No need to upload phonebook to the FRITZ!Box.". PHP_EOL; |
|
| 685 | + print " INFO: Same versions ==> No changes in phonebook or images" . PHP_EOL . " EXIT: No need to upload phonebook to the FRITZ!Box." . PHP_EOL; |
|
| 686 | 686 | return 0; |
| 687 | 687 | } |
| 688 | 688 | else |
@@ -38,9 +38,12 @@ discard block |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 | { |
@@ -209,7 +228,9 @@ discard block |
||
| 209 | 228 | // set the vcard extension in case the user |
| 210 | 229 | // defined it in the config |
| 211 | 230 | if(isset($conf['extension'])) |
| 212 | - $carddav->setVcardExtension($conf['extension']); |
|
| 231 | + { |
|
| 232 | + $carddav->setVcardExtension($conf['extension']); |
|
| 233 | + } |
|
| 213 | 234 | |
| 214 | 235 | // retrieve data from the CardDAV server now |
| 215 | 236 | $xmldata = $carddav->get(); |
@@ -218,7 +239,9 @@ discard block |
||
| 218 | 239 | // CardDAV server and if not reencode it since the FRITZ!Box |
| 219 | 240 | // requires UTF-8 encoded data |
| 220 | 241 | if(iconv('utf-8', 'utf-8//IGNORE', $xmldata) != $xmldata) |
| 221 | - $xmldata = utf8_encode($xmldata); |
|
| 242 | + { |
|
| 243 | + $xmldata = utf8_encode($xmldata); |
|
| 244 | + } |
|
| 222 | 245 | |
| 223 | 246 | // read raw_vcard data from xml response |
| 224 | 247 | $raw_vcards = array(); |
@@ -240,10 +263,14 @@ discard block |
||
| 240 | 263 | $vcard_obj = new vCard(false, $v); |
| 241 | 264 | $name_arr = null; |
| 242 | 265 | if(isset($vcard_obj->n[0])) |
| 243 | - $name_arr = $vcard_obj->n[0]; |
|
| 266 | + { |
|
| 267 | + $name_arr = $vcard_obj->n[0]; |
|
| 268 | + } |
|
| 244 | 269 | $org_arr = null; |
| 245 | 270 | if(isset($vcard_obj->org[0])) |
| 246 | - $org_arr = $vcard_obj->org[0]; |
|
| 271 | + { |
|
| 272 | + $org_arr = $vcard_obj->org[0]; |
|
| 273 | + } |
|
| 247 | 274 | $addnames = ''; |
| 248 | 275 | $prefix = ''; |
| 249 | 276 | $suffix = ''; |
@@ -252,19 +279,29 @@ discard block |
||
| 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 | if (isset($vcard_obj->fn[0])) |
| 267 | - $formattedname = $vcard_obj->fn[0]; |
|
| 302 | + { |
|
| 303 | + $formattedname = $vcard_obj->fn[0]; |
|
| 304 | + } |
|
| 268 | 305 | |
| 269 | 306 | $firstname = trim($name_arr['firstname']); |
| 270 | 307 | $lastname = trim($name_arr['lastname']); |
@@ -284,78 +321,106 @@ discard block |
||
| 284 | 321 | |
| 285 | 322 | // Prefix |
| 286 | 323 | if(!empty($prefix)) |
| 287 | - $name .= $prefix; |
|
| 324 | + { |
|
| 325 | + $name .= $prefix; |
|
| 326 | + } |
|
| 288 | 327 | |
| 289 | 328 | if($format == 0) |
| 290 | 329 | { |
| 291 | 330 | // Lastname |
| 292 | 331 | if(!empty($name) and !empty($lastname)) |
| 293 | - $name .= ' ' . $lastname; |
|
| 294 | - else |
|
| 295 | - $name .= $lastname; |
|
| 332 | + { |
|
| 333 | + $name .= ' ' . $lastname; |
|
| 334 | + } |
|
| 335 | + else { |
|
| 336 | + $name .= $lastname; |
|
| 337 | + } |
|
| 296 | 338 | } |
| 297 | 339 | else |
| 298 | 340 | { |
| 299 | 341 | // Firstname |
| 300 | 342 | if(!empty($name) and !empty($firstname)) |
| 301 | - $name .= ' ' . $firstname; |
|
| 302 | - else |
|
| 303 | - $name .= $firstname; |
|
| 343 | + { |
|
| 344 | + $name .= ' ' . $firstname; |
|
| 345 | + } |
|
| 346 | + else { |
|
| 347 | + $name .= $firstname; |
|
| 348 | + } |
|
| 304 | 349 | } |
| 305 | 350 | |
| 306 | 351 | if($format == 2) |
| 307 | 352 | { |
| 308 | 353 | // AdditionalNames |
| 309 | 354 | if(!empty($name) and !empty($addnames)) |
| 310 | - $name .= ' ' . $addnames; |
|
| 311 | - else |
|
| 312 | - $name .= $addnames; |
|
| 355 | + { |
|
| 356 | + $name .= ' ' . $addnames; |
|
| 357 | + } |
|
| 358 | + else { |
|
| 359 | + $name .= $addnames; |
|
| 360 | + } |
|
| 313 | 361 | } |
| 314 | 362 | |
| 315 | 363 | if($format == 0) |
| 316 | 364 | { |
| 317 | 365 | // Firstname |
| 318 | 366 | if(!empty($name) and !empty($firstname)) |
| 319 | - $name .= ', ' . $firstname; |
|
| 320 | - else |
|
| 321 | - $name .= $firstname; |
|
| 367 | + { |
|
| 368 | + $name .= ', ' . $firstname; |
|
| 369 | + } |
|
| 370 | + else { |
|
| 371 | + $name .= $firstname; |
|
| 372 | + } |
|
| 322 | 373 | } |
| 323 | 374 | else |
| 324 | 375 | { |
| 325 | 376 | // Lastname |
| 326 | 377 | if(!empty($name) and !empty($lastname)) |
| 327 | - $name .= ' ' . $lastname; |
|
| 328 | - else |
|
| 329 | - $name .= $lastname; |
|
| 378 | + { |
|
| 379 | + $name .= ' ' . $lastname; |
|
| 380 | + } |
|
| 381 | + else { |
|
| 382 | + $name .= $lastname; |
|
| 383 | + } |
|
| 330 | 384 | } |
| 331 | 385 | |
| 332 | 386 | if($format != 2) |
| 333 | 387 | { |
| 334 | 388 | // AdditionalNames |
| 335 | 389 | if(!empty($name) and !empty($addnames)) |
| 336 | - $name .= ' ' . $addnames; |
|
| 337 | - else |
|
| 338 | - $name .= $addnames; |
|
| 390 | + { |
|
| 391 | + $name .= ' ' . $addnames; |
|
| 392 | + } |
|
| 393 | + else { |
|
| 394 | + $name .= $addnames; |
|
| 395 | + } |
|
| 339 | 396 | } |
| 340 | 397 | |
| 341 | 398 | // Suffix |
| 342 | 399 | if(!empty($name) and !empty($suffix)) |
| 343 | - $name .= ' ' . $suffix; |
|
| 344 | - else |
|
| 345 | - $name .= $suffix; |
|
| 400 | + { |
|
| 401 | + $name .= ' ' . $suffix; |
|
| 402 | + } |
|
| 403 | + else { |
|
| 404 | + $name .= $suffix; |
|
| 405 | + } |
|
| 346 | 406 | |
| 347 | 407 | // OrgName |
| 348 | 408 | if(!empty($name) and !empty($orgname)) |
| 349 | - $name .= ' (' . $orgname . ')'; |
|
| 350 | - else |
|
| 351 | - $name .= $orgname; |
|
| 409 | + { |
|
| 410 | + $name .= ' (' . $orgname . ')'; |
|
| 411 | + } |
|
| 412 | + else { |
|
| 413 | + $name .= $orgname; |
|
| 414 | + } |
|
| 352 | 415 | |
| 353 | 416 | // make sure to trim whitespaces and double spaces |
| 354 | 417 | $name = trim(str_replace(' ', ' ', $name)); |
| 355 | 418 | |
| 356 | 419 | // perform a fallback to formatted name, if we don't have any name and formatted name is available |
| 357 | 420 | if(empty($name) and !empty($formattedname)) |
| 358 | - $name = $formattedname; |
|
| 421 | + { |
|
| 422 | + $name = $formattedname; |
|
| 423 | + } |
|
| 359 | 424 | |
| 360 | 425 | if(empty($name)) |
| 361 | 426 | { |
@@ -369,15 +434,19 @@ discard block |
||
| 369 | 434 | $photo = str_replace(array(',', '&', ' ', '/', 'ä', 'ö', 'ü', 'Ä', 'Ö', 'Ü', 'ß', 'á', 'à', 'ó', 'ò', 'ú', 'ù', 'í', 'ø'), |
| 370 | 435 | array('', '_', '_', '_', 'ae', 'oe', 'ue', 'Ae', 'Oe', 'Ue', 'ss', 'a', 'a', 'o', 'o', 'u', 'u', 'i', 'oe'), $name); |
| 371 | 436 | } |
| 372 | - else |
|
| 373 | - $photo = ''; |
|
| 437 | + else { |
|
| 438 | + $photo = ''; |
|
| 439 | + } |
|
| 374 | 440 | |
| 375 | 441 | // phone |
| 376 | 442 | $phone_no = array(); |
| 377 | 443 | if($vcard_obj->categories) |
| 378 | - $categories = $vcard_obj->categories[0]; |
|
| 379 | - else |
|
| 380 | - $categories = array(); |
|
| 444 | + { |
|
| 445 | + $categories = $vcard_obj->categories[0]; |
|
| 446 | + } |
|
| 447 | + else { |
|
| 448 | + $categories = array(); |
|
| 449 | + } |
|
| 381 | 450 | |
| 382 | 451 | // check for quickdial entry |
| 383 | 452 | if(isset($vcard_obj->note[0])) |
@@ -412,9 +481,10 @@ discard block |
||
| 412 | 481 | break; |
| 413 | 482 | } |
| 414 | 483 | } |
| 415 | - } |
|
| 416 | - else |
|
| 417 | - $add_entry = 1; |
|
| 484 | + } |
|
| 485 | + else { |
|
| 486 | + $add_entry = 1; |
|
| 487 | + } |
|
| 418 | 488 | |
| 419 | 489 | if($add_entry == 1) |
| 420 | 490 | { |
@@ -439,9 +509,13 @@ discard block |
||
| 439 | 509 | { |
| 440 | 510 | //Set quickdial |
| 441 | 511 | if($value == 1) |
| 442 | - print "\nWARNING: Quickdial value 1 (**701) is not possible but used! \n"; |
|
| 512 | + { |
|
| 513 | + print "\nWARNING: Quickdial value 1 (**701) is not possible but used! \n"; |
|
| 514 | + } |
|
| 443 | 515 | elseif($value >= 100) |
| 444 | - print "\nWARNING: Quickdial value bigger than 99 (**799) is not possible but used! \n"; |
|
| 516 | + { |
|
| 517 | + print "\nWARNING: Quickdial value bigger than 99 (**799) is not possible but used! \n"; |
|
| 518 | + } |
|
| 445 | 519 | |
| 446 | 520 | $quickdial = $value; |
| 447 | 521 | } |
@@ -451,23 +525,38 @@ discard block |
||
| 451 | 525 | |
| 452 | 526 | // find out priority |
| 453 | 527 | if(in_array("pref", $typearr_lower)) |
| 454 | - $prio = 1; |
|
| 528 | + { |
|
| 529 | + $prio = 1; |
|
| 530 | + } |
|
| 455 | 531 | |
| 456 | 532 | // set the proper type |
| 457 | 533 | if(in_array("cell", $typearr_lower)) |
| 458 | - $type = "mobile"; |
|
| 534 | + { |
|
| 535 | + $type = "mobile"; |
|
| 536 | + } |
|
| 459 | 537 | elseif(in_array("home", $typearr_lower)) |
| 460 | - $type = "home"; |
|
| 538 | + { |
|
| 539 | + $type = "home"; |
|
| 540 | + } |
|
| 461 | 541 | elseif(in_array("fax", $typearr_lower)) |
| 462 | - $type = "fax_work"; |
|
| 542 | + { |
|
| 543 | + $type = "fax_work"; |
|
| 544 | + } |
|
| 463 | 545 | elseif(in_array("work", $typearr_lower)) |
| 464 | - $type = "work"; |
|
| 546 | + { |
|
| 547 | + $type = "work"; |
|
| 548 | + } |
|
| 465 | 549 | elseif(in_array("other", $typearr_lower)) |
| 466 | - $type = "other"; |
|
| 550 | + { |
|
| 551 | + $type = "other"; |
|
| 552 | + } |
|
| 467 | 553 | elseif(in_array("dom", $typearr_lower)) |
| 468 | - $type = "other"; |
|
| 469 | - else |
|
| 470 | - continue; |
|
| 554 | + { |
|
| 555 | + $type = "other"; |
|
| 556 | + } |
|
| 557 | + else { |
|
| 558 | + continue; |
|
| 559 | + } |
|
| 471 | 560 | } |
| 472 | 561 | $phone_no[] = array("type"=>$type, "prio"=>$prio, "quickdial"=>$quickdial, "value" => $this->_clear_phone_number($phone_number)); |
| 473 | 562 | } |
@@ -487,13 +576,20 @@ discard block |
||
| 487 | 576 | $email = $e['value']; |
| 488 | 577 | $typearr_lower = unserialize(strtolower(serialize($e['type']))); |
| 489 | 578 | if(in_array("work", $typearr_lower)) |
| 490 | - $type_email = "work"; |
|
| 579 | + { |
|
| 580 | + $type_email = "work"; |
|
| 581 | + } |
|
| 491 | 582 | elseif(in_array("home", $typearr_lower)) |
| 492 | - $type_email = "home"; |
|
| 583 | + { |
|
| 584 | + $type_email = "home"; |
|
| 585 | + } |
|
| 493 | 586 | elseif(in_array("other", $typearr_lower)) |
| 494 | - $type_email = "other"; |
|
| 495 | - else |
|
| 496 | - continue; |
|
| 587 | + { |
|
| 588 | + $type_email = "other"; |
|
| 589 | + } |
|
| 590 | + else { |
|
| 591 | + continue; |
|
| 592 | + } |
|
| 497 | 593 | } |
| 498 | 594 | |
| 499 | 595 | // DEBUG: print out the email address on the console |
@@ -521,7 +617,9 @@ discard block |
||
| 521 | 617 | public function build_fb_xml() |
| 522 | 618 | { |
| 523 | 619 | if(empty($this->entries)) |
| 524 | - throw new Exception('No entries available! Call get_carddav_entries or set $this->entries manually!'); |
|
| 620 | + { |
|
| 621 | + throw new Exception('No entries available! Call get_carddav_entries or set $this->entries manually!'); |
|
| 622 | + } |
|
| 525 | 623 | |
| 526 | 624 | // create FB XML in utf-8 format |
| 527 | 625 | $root = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><phonebooks><phonebook></phonebook></phonebooks>'); |
@@ -560,7 +658,9 @@ discard block |
||
| 560 | 658 | |
| 561 | 659 | // output a warning if no telephone number was found |
| 562 | 660 | if($id == 0) |
| 563 | - print " WARNING: no phone entry found. VCard will be ignored." . PHP_EOL; |
|
| 661 | + { |
|
| 662 | + print " WARNING: no phone entry found. VCard will be ignored." . PHP_EOL; |
|
| 663 | + } |
|
| 564 | 664 | |
| 565 | 665 | // email: put the email addresses into the fritzbox xml file |
| 566 | 666 | $email = $contact->addChild("services"); |
@@ -610,8 +710,9 @@ discard block |
||
| 610 | 710 | |
| 611 | 711 | print " Added photo: " . basename($photo_file) . PHP_EOL; |
| 612 | 712 | } |
| 613 | - else |
|
| 614 | - print " WARNING: Only jpg contact photos are currently supported." . PHP_EOL; |
|
| 713 | + else { |
|
| 714 | + print " WARNING: Only jpg contact photos are currently supported." . PHP_EOL; |
|
| 715 | + } |
|
| 615 | 716 | } |
| 616 | 717 | elseif(substr($entry['photo_data'][0], 0, 4) == 'http') |
| 617 | 718 | { |
@@ -620,8 +721,9 @@ discard block |
||
| 620 | 721 | |
| 621 | 722 | print " Added photo: " . $entry['photo_data'][0] . PHP_EOL; |
| 622 | 723 | } |
| 623 | - else |
|
| 624 | - print " WARNING: Only VCard embedded photo data or a reference URL is currently supported." . PHP_EOL; |
|
| 724 | + else { |
|
| 725 | + print " WARNING: Only VCard embedded photo data or a reference URL is currently supported." . PHP_EOL; |
|
| 726 | + } |
|
| 625 | 727 | } |
| 626 | 728 | |
| 627 | 729 | $contact->addChild("services"); |
@@ -630,7 +732,9 @@ discard block |
||
| 630 | 732 | } |
| 631 | 733 | |
| 632 | 734 | if($root->asXML() !== false) |
| 633 | - $this->fbxml = $root->asXML(); |
|
| 735 | + { |
|
| 736 | + $this->fbxml = $root->asXML(); |
|
| 737 | + } |
|
| 634 | 738 | else |
| 635 | 739 | { |
| 636 | 740 | print " ERROR: created XML data isn't well-formed." . PHP_EOL; |
@@ -647,19 +751,27 @@ discard block |
||
| 647 | 751 | public function _concat($text1, $text2) |
| 648 | 752 | { |
| 649 | 753 | if($text1 == '') |
| 650 | - return $text2; |
|
| 754 | + { |
|
| 755 | + return $text2; |
|
| 756 | + } |
|
| 651 | 757 | elseif($text2 == '') |
| 652 | - return $text1; |
|
| 653 | - else |
|
| 654 | - return $text1 . ", " . $text2; |
|
| 758 | + { |
|
| 759 | + return $text1; |
|
| 760 | + } |
|
| 761 | + else { |
|
| 762 | + return $text1 . ", " . $text2; |
|
| 763 | + } |
|
| 655 | 764 | } |
| 656 | 765 | |
| 657 | 766 | public function _parse_fb_result($text) |
| 658 | 767 | { |
| 659 | 768 | if(preg_match("/\<h2\>([^\<]+)\<\/h2\>/", $text, $matches) == 1 && !empty($matches)) |
| 660 | - return $matches[1]; |
|
| 661 | - else |
|
| 662 | - return "Error while uploading xml to fritzbox"; |
|
| 769 | + { |
|
| 770 | + return $matches[1]; |
|
| 771 | + } |
|
| 772 | + else { |
|
| 773 | + return "Error while uploading xml to fritzbox"; |
|
| 774 | + } |
|
| 663 | 775 | } |
| 664 | 776 | |
| 665 | 777 | public function upload_to_fb() |
@@ -681,15 +793,17 @@ discard block |
||
| 681 | 793 | $newphonebhash = md5(preg_replace("/<mod_time>(\\d{10})/","",file_get_contents($this->config['output_file'],'r'),-1,$debugnewtsreplace)); |
| 682 | 794 | print " INFO: Compare old and new phonebook file versions." . PHP_EOL . " INFO: old version: " . $oldphonebhash . PHP_EOL . " INFO: new version: " . $newphonebhash . PHP_EOL; |
| 683 | 795 | if($oldphonebhash === $newphonebhash) |
| 684 | - { |
|
| 796 | + { |
|
| 685 | 797 | print " INFO: Same versions ==> No changes in phonebook or images" . PHP_EOL . " EXIT: No need to upload phonebook to the FRITZ!Box.". PHP_EOL; |
| 686 | 798 | return 0; |
| 687 | 799 | } |
| 688 | - else |
|
| 689 | - print " INFO: Different versions ==> Changes in phonebook." . PHP_EOL . " INFO: Changes dedected! Continue with upload." . PHP_EOL; |
|
| 800 | + else { |
|
| 801 | + print " INFO: Different versions ==> Changes in phonebook." . PHP_EOL . " INFO: Changes dedected! Continue with upload." . PHP_EOL; |
|
| 802 | + } |
|
| 690 | 803 | } |
| 691 | - else |
|
| 692 | - return 0; |
|
| 804 | + else { |
|
| 805 | + return 0; |
|
| 806 | + } |
|
| 693 | 807 | } |
| 694 | 808 | // now we upload the photo jpgs first being stored in the |
| 695 | 809 | // temp directory. |
@@ -759,12 +873,16 @@ discard block |
||
| 759 | 873 | |
| 760 | 874 | ftp_pasv($conn_id, true); |
| 761 | 875 | if(!ftp_put($conn_id, $remote_path . "/" . $file, $fileinfo->getPathname(), FTP_BINARY)) |
| 762 | - print " ERROR: while uploading file " . $fileinfo->getFilename() . PHP_EOL; |
|
| 763 | - else |
|
| 764 | - print " ok." . PHP_EOL; |
|
| 876 | + { |
|
| 877 | + print " ERROR: while uploading file " . $fileinfo->getFilename() . PHP_EOL; |
|
| 878 | + } |
|
| 879 | + else { |
|
| 880 | + print " ok." . PHP_EOL; |
|
| 881 | + } |
|
| 882 | + } |
|
| 883 | + else { |
|
| 884 | + print " ok." . PHP_EOL; |
|
| 765 | 885 | } |
| 766 | - else |
|
| 767 | - print " ok." . PHP_EOL; |
|
| 768 | 886 | |
| 769 | 887 | // cleanup old files |
| 770 | 888 | foreach($all_existing_files as $existing_file) |
@@ -776,20 +894,23 @@ discard block |
||
| 776 | 894 | } |
| 777 | 895 | } |
| 778 | 896 | } |
| 779 | - else |
|
| 780 | - print " already exists." . PHP_EOL; |
|
| 897 | + else { |
|
| 898 | + print " already exists." . PHP_EOL; |
|
| 899 | + } |
|
| 781 | 900 | } |
| 782 | 901 | } |
| 783 | 902 | } |
| 784 | 903 | } |
| 785 | - else |
|
| 786 | - print " ERROR: couldn't login to FTP-server '" . $ftp_server . "' with provided username/password settings." . PHP_EOL; |
|
| 904 | + else { |
|
| 905 | + print " ERROR: couldn't login to FTP-server '" . $ftp_server . "' with provided username/password settings." . PHP_EOL; |
|
| 906 | + } |
|
| 787 | 907 | |
| 788 | 908 | // close ftp connection |
| 789 | 909 | ftp_close($conn_id); |
| 790 | 910 | } |
| 791 | - else |
|
| 792 | - print " ERROR: couldn't connect to FTP server '" . $ftp_server . "'." . PHP_EOL; |
|
| 911 | + else { |
|
| 912 | + print " ERROR: couldn't connect to FTP server '" . $ftp_server . "'." . PHP_EOL; |
|
| 913 | + } |
|
| 793 | 914 | |
| 794 | 915 | // lets post the phonebook xml to the FRITZ!Box |
| 795 | 916 | print " Uploading Phonebook XML to " . $this->config['fritzbox_ip'] . PHP_EOL; |