@@ -105,15 +105,19 @@ discard block |
||
| 105 | 105 | // special treatment for litmus compliance test |
| 106 | 106 | // reply on its identifier header |
| 107 | 107 | // not needed for the test itself but eases debugging |
| 108 | - if (isset($this->_SERVER['HTTP_X_LITMUS'])) { |
|
| 108 | + if (isset($this->_SERVER['HTTP_X_LITMUS'])) |
|
| 109 | + { |
|
| 109 | 110 | error_log("Litmus test ".$this->_SERVER['HTTP_X_LITMUS']); |
| 110 | 111 | header("X-Litmus-reply: ".$this->_SERVER['HTTP_X_LITMUS']); |
| 111 | 112 | } |
| 112 | 113 | |
| 113 | 114 | // set root directory, defaults to webserver document root if not set |
| 114 | - if ($base) { |
|
| 115 | + if ($base) |
|
| 116 | + { |
|
| 115 | 117 | $this->base = realpath($base); // TODO throw if not a directory |
| 116 | - } else if (!$this->base) { |
|
| 118 | + } |
|
| 119 | + else if (!$this->base) |
|
| 120 | + { |
|
| 117 | 121 | $this->base = $this->_SERVER['DOCUMENT_ROOT']; |
| 118 | 122 | } |
| 119 | 123 | |
@@ -154,7 +158,8 @@ discard block |
||
| 154 | 158 | $fspath = $this->base . $options["path"]; |
| 155 | 159 | |
| 156 | 160 | // sanity check |
| 157 | - if (!file_exists($fspath)) { |
|
| 161 | + if (!file_exists($fspath)) |
|
| 162 | + { |
|
| 158 | 163 | return false; |
| 159 | 164 | } |
| 160 | 165 | |
@@ -165,7 +170,8 @@ discard block |
||
| 165 | 170 | $files["files"][] = $this->fileinfo($options["path"]); |
| 166 | 171 | |
| 167 | 172 | // information for contained resources requested? |
| 168 | - if (!empty($options["depth"]) && is_dir($fspath) && $this->_is_readable($fspath)) { |
|
| 173 | + if (!empty($options["depth"]) && is_dir($fspath) && $this->_is_readable($fspath)) |
|
| 174 | + { |
|
| 169 | 175 | |
| 170 | 176 | // make sure path ends with '/' |
| 171 | 177 | $options["path"] = $this->_slashify($options["path"]); |
@@ -173,10 +179,13 @@ discard block |
||
| 173 | 179 | // try to open directory |
| 174 | 180 | $handle = opendir($fspath); |
| 175 | 181 | |
| 176 | - if ($handle) { |
|
| 182 | + if ($handle) |
|
| 183 | + { |
|
| 177 | 184 | // ok, now get all its contents |
| 178 | - while ($filename = readdir($handle)) { |
|
| 179 | - if ($filename != "." && $filename != "..") { |
|
| 185 | + while ($filename = readdir($handle)) |
|
| 186 | + { |
|
| 187 | + if ($filename != "." && $filename != "..") |
|
| 188 | + { |
|
| 180 | 189 | $files["files"][] = $this->fileinfo($options["path"].$filename); |
| 181 | 190 | } |
| 182 | 191 | } |
@@ -218,16 +227,22 @@ discard block |
||
| 218 | 227 | $info["props"][] = $this->mkprop("ishidden", ('.' === substr(basename($fspath), 0, 1))); |
| 219 | 228 | |
| 220 | 229 | // type and size (caller already made sure that path exists) |
| 221 | - if (is_dir($fspath)) { |
|
| 230 | + if (is_dir($fspath)) |
|
| 231 | + { |
|
| 222 | 232 | // directory (WebDAV collection) |
| 223 | 233 | $info["props"][] = $this->mkprop("resourcetype", "collection"); |
| 224 | 234 | $info["props"][] = $this->mkprop("getcontenttype", "httpd/unix-directory"); |
| 225 | - } else { |
|
| 235 | + } |
|
| 236 | + else |
|
| 237 | + { |
|
| 226 | 238 | // plain file (WebDAV resource) |
| 227 | 239 | $info["props"][] = $this->mkprop("resourcetype", ""); |
| 228 | - if ($this->_is_readable($fspath)) { |
|
| 240 | + if ($this->_is_readable($fspath)) |
|
| 241 | + { |
|
| 229 | 242 | $info["props"][] = $this->mkprop("getcontenttype", $this->_mimetype($fspath)); |
| 230 | - } else { |
|
| 243 | + } |
|
| 244 | + else |
|
| 245 | + { |
|
| 231 | 246 | $info["props"][] = $this->mkprop("getcontenttype", "application/x-non-readable"); |
| 232 | 247 | } |
| 233 | 248 | $info["props"][] = $this->mkprop("getcontentlength", filesize($fspath)); |
@@ -238,7 +253,8 @@ discard block |
||
| 238 | 253 | FROM {$this->db_prefix}properties |
| 239 | 254 | WHERE path = '$path'"; |
| 240 | 255 | $res = mysql_query($query); |
| 241 | - while ($row = mysql_fetch_assoc($res)) { |
|
| 256 | + while ($row = mysql_fetch_assoc($res)) |
|
| 257 | + { |
|
| 242 | 258 | $info["props"][] = $this->mkprop($row["ns"], $row["name"], $row["value"]); |
| 243 | 259 | } |
| 244 | 260 | mysql_free_result($res); |
@@ -259,30 +275,45 @@ discard block |
||
| 259 | 275 | function _can_execute($name, $path = false) |
| 260 | 276 | { |
| 261 | 277 | // path defaults to PATH from environment if not set |
| 262 | - if ($path === false) { |
|
| 278 | + if ($path === false) |
|
| 279 | + { |
|
| 263 | 280 | $path = getenv("PATH"); |
| 264 | 281 | } |
| 265 | 282 | |
| 266 | 283 | // check method depends on operating system |
| 267 | - if (!strncmp(PHP_OS, "WIN", 3)) { |
|
| 284 | + if (!strncmp(PHP_OS, "WIN", 3)) |
|
| 285 | + { |
|
| 268 | 286 | // on Windows an appropriate COM or EXE file needs to exist |
| 269 | 287 | $exts = array(".exe", ".com"); |
| 270 | 288 | $check_fn = "file_exists"; |
| 271 | - } else { |
|
| 289 | + } |
|
| 290 | + else |
|
| 291 | + { |
|
| 272 | 292 | // anywhere else we look for an executable file of that name |
| 273 | 293 | $exts = array(""); |
| 274 | 294 | $check_fn = "is_executable"; |
| 275 | 295 | } |
| 276 | 296 | |
| 277 | 297 | // now check the directories in the path for the program |
| 278 | - foreach (explode(PATH_SEPARATOR, $path) as $dir) { |
|
| 298 | + foreach (explode(PATH_SEPARATOR, $path) as $dir) |
|
| 299 | + { |
|
| 279 | 300 | // skip invalid path entries |
| 280 | - if (!file_exists($dir)) continue; |
|
| 281 | - if (!is_dir($dir)) continue; |
|
| 301 | + if (!file_exists($dir)) |
|
| 302 | + { |
|
| 303 | + continue; |
|
| 304 | + } |
|
| 305 | + if (!is_dir($dir)) |
|
| 306 | + { |
|
| 307 | + continue; |
|
| 308 | + } |
|
| 282 | 309 | |
| 283 | 310 | // and now look for the file |
| 284 | - foreach ($exts as $ext) { |
|
| 285 | - if ($check_fn("$dir/$name".$ext)) return true; |
|
| 311 | + foreach ($exts as $ext) |
|
| 312 | + { |
|
| 313 | + if ($check_fn("$dir/$name".$ext)) |
|
| 314 | + { |
|
| 315 | + return true; |
|
| 316 | + } |
|
| 286 | 317 | } |
| 287 | 318 | } |
| 288 | 319 | |
@@ -323,13 +354,18 @@ discard block |
||
| 323 | 354 | */ |
| 324 | 355 | function _mimetype($fspath) |
| 325 | 356 | { |
| 326 | - if (is_dir($fspath)) { |
|
| 357 | + if (is_dir($fspath)) |
|
| 358 | + { |
|
| 327 | 359 | // directories are easy |
| 328 | 360 | return "httpd/unix-directory"; |
| 329 | - } else if (function_exists("mime_content_type")) { |
|
| 361 | + } |
|
| 362 | + else if (function_exists("mime_content_type")) |
|
| 363 | + { |
|
| 330 | 364 | // use mime magic extension if available |
| 331 | 365 | $mime_type = mime_content_type($fspath); |
| 332 | - } else if ($this->_can_execute("file")) { |
|
| 366 | + } |
|
| 367 | + else if ($this->_can_execute("file")) |
|
| 368 | + { |
|
| 333 | 369 | // it looks like we have a 'file' command, |
| 334 | 370 | // lets see it it does have mime support |
| 335 | 371 | $fp = popen("file -i '$fspath' 2>/dev/null", "r"); |
@@ -341,16 +377,19 @@ discard block |
||
| 341 | 377 | // so we test the format of the returned string |
| 342 | 378 | |
| 343 | 379 | // the reply begins with the requested filename |
| 344 | - if (!strncmp($reply, "$fspath: ", strlen($fspath)+2)) { |
|
| 380 | + if (!strncmp($reply, "$fspath: ", strlen($fspath)+2)) |
|
| 381 | + { |
|
| 345 | 382 | $reply = substr($reply, strlen($fspath)+2); |
| 346 | 383 | // followed by the mime type (maybe including options) |
| 347 | - if (preg_match('|^[[:alnum:]_-]+/[[:alnum:]_-]+;?.*|', $reply, $matches)) { |
|
| 384 | + if (preg_match('|^[[:alnum:]_-]+/[[:alnum:]_-]+;?.*|', $reply, $matches)) |
|
| 385 | + { |
|
| 348 | 386 | $mime_type = $matches[0]; |
| 349 | 387 | } |
| 350 | 388 | } |
| 351 | 389 | } |
| 352 | 390 | |
| 353 | - if (empty($mime_type)) { |
|
| 391 | + if (empty($mime_type)) |
|
| 392 | + { |
|
| 354 | 393 | // Fallback solution: try to guess the type by the file extension |
| 355 | 394 | // TODO: add more ... |
| 356 | 395 | // TODO: it has been suggested to delegate mimetype detection |
@@ -364,7 +403,8 @@ discard block |
||
| 364 | 403 | // anyway (overriding it with information taken from |
| 365 | 404 | // the registry) |
| 366 | 405 | // TODO: have a seperate PEAR class for mimetype detection? |
| 367 | - switch (strtolower(strrchr(basename($fspath), "."))) { |
|
| 406 | + switch (strtolower(strrchr(basename($fspath), "."))) |
|
| 407 | + { |
|
| 368 | 408 | case ".html": |
| 369 | 409 | $mime_type = "text/html"; |
| 370 | 410 | break; |
@@ -395,7 +435,10 @@ discard block |
||
| 395 | 435 | $fspath = $this->base . $options["path"]; |
| 396 | 436 | |
| 397 | 437 | // sanity check |
| 398 | - if (!file_exists($fspath)) return false; |
|
| 438 | + if (!file_exists($fspath)) |
|
| 439 | + { |
|
| 440 | + return false; |
|
| 441 | + } |
|
| 399 | 442 | |
| 400 | 443 | // detect resource type |
| 401 | 444 | $options['mimetype'] = $this->_mimetype($fspath); |
@@ -424,12 +467,14 @@ discard block |
||
| 424 | 467 | $fspath = $this->base . $options["path"]; |
| 425 | 468 | |
| 426 | 469 | // is this a collection? |
| 427 | - if (is_dir($fspath)) { |
|
| 470 | + if (is_dir($fspath)) |
|
| 471 | + { |
|
| 428 | 472 | return $this->GetDir($fspath, $options); |
| 429 | 473 | } |
| 430 | 474 | |
| 431 | 475 | // the header output is the same as for HEAD |
| 432 | - if (!$this->HEAD($options)) { |
|
| 476 | + if (!$this->HEAD($options)) |
|
| 477 | + { |
|
| 433 | 478 | return false; |
| 434 | 479 | } |
| 435 | 480 | |
@@ -451,7 +496,8 @@ discard block |
||
| 451 | 496 | function GetDir($fspath, &$options) |
| 452 | 497 | { |
| 453 | 498 | $path = $this->_slashify($options["path"]); |
| 454 | - if ($path != $options["path"]) { |
|
| 499 | + if ($path != $options["path"]) |
|
| 500 | + { |
|
| 455 | 501 | header("Location: ".$this->base_uri.$path); |
| 456 | 502 | exit; |
| 457 | 503 | } |
@@ -459,12 +505,14 @@ discard block |
||
| 459 | 505 | // fixed width directory column format |
| 460 | 506 | $format = "%15s %-19s %-s\n"; |
| 461 | 507 | |
| 462 | - if (!$this->_is_readable($fspath)) { |
|
| 508 | + if (!$this->_is_readable($fspath)) |
|
| 509 | + { |
|
| 463 | 510 | return false; |
| 464 | 511 | } |
| 465 | 512 | |
| 466 | 513 | $handle = opendir($fspath); |
| 467 | - if (!$handle) { |
|
| 514 | + if (!$handle) |
|
| 515 | + { |
|
| 468 | 516 | return false; |
| 469 | 517 | } |
| 470 | 518 | |
@@ -476,8 +524,10 @@ discard block |
||
| 476 | 524 | printf($format, "Size", "Last modified", "Filename"); |
| 477 | 525 | echo "<hr>"; |
| 478 | 526 | |
| 479 | - while ($filename = readdir($handle)) { |
|
| 480 | - if ($filename != "." && $filename != "..") { |
|
| 527 | + while ($filename = readdir($handle)) |
|
| 528 | + { |
|
| 529 | + if ($filename != "." && $filename != "..") |
|
| 530 | + { |
|
| 481 | 531 | $fullpath = $fspath.$filename; |
| 482 | 532 | $name = htmlspecialchars($filename); |
| 483 | 533 | printf($format, |
@@ -507,19 +557,23 @@ discard block |
||
| 507 | 557 | $fspath = $this->base . $options["path"]; |
| 508 | 558 | |
| 509 | 559 | $dir = dirname($fspath); |
| 510 | - if (!file_exists($dir) || !is_dir($dir)) { |
|
| 560 | + if (!file_exists($dir) || !is_dir($dir)) |
|
| 561 | + { |
|
| 511 | 562 | return "409 Conflict"; // TODO right status code for both? |
| 512 | 563 | } |
| 513 | 564 | |
| 514 | 565 | $options["new"] = ! file_exists($fspath); |
| 515 | 566 | |
| 516 | - if ($options["new"] && !$this->_is_writable($dir)) { |
|
| 567 | + if ($options["new"] && !$this->_is_writable($dir)) |
|
| 568 | + { |
|
| 517 | 569 | return "403 Forbidden"; |
| 518 | 570 | } |
| 519 | - if (!$options["new"] && !$this->_is_writable($fspath)) { |
|
| 571 | + if (!$options["new"] && !$this->_is_writable($fspath)) |
|
| 572 | + { |
|
| 520 | 573 | return "403 Forbidden"; |
| 521 | 574 | } |
| 522 | - if (!$options["new"] && is_dir($fspath)) { |
|
| 575 | + if (!$options["new"] && is_dir($fspath)) |
|
| 576 | + { |
|
| 523 | 577 | return "403 Forbidden"; |
| 524 | 578 | } |
| 525 | 579 | |
@@ -541,24 +595,30 @@ discard block |
||
| 541 | 595 | $parent = dirname($path); |
| 542 | 596 | $name = basename($path); |
| 543 | 597 | |
| 544 | - if (!file_exists($parent)) { |
|
| 598 | + if (!file_exists($parent)) |
|
| 599 | + { |
|
| 545 | 600 | return "409 Conflict"; |
| 546 | 601 | } |
| 547 | 602 | |
| 548 | - if (!is_dir($parent)) { |
|
| 603 | + if (!is_dir($parent)) |
|
| 604 | + { |
|
| 549 | 605 | return "403 Forbidden"; |
| 550 | 606 | } |
| 551 | 607 | |
| 552 | - if ( file_exists($parent."/".$name) ) { |
|
| 608 | + if ( file_exists($parent."/".$name) ) |
|
| 609 | + { |
|
| 553 | 610 | return "405 Method not allowed"; |
| 554 | 611 | } |
| 555 | 612 | |
| 556 | - if (!empty($this->_SERVER["CONTENT_LENGTH"])) { // no body parsing yet |
|
| 613 | + if (!empty($this->_SERVER["CONTENT_LENGTH"])) |
|
| 614 | + { |
|
| 615 | +// no body parsing yet |
|
| 557 | 616 | return "415 Unsupported media type"; |
| 558 | 617 | } |
| 559 | 618 | |
| 560 | 619 | $stat = mkdir($parent."/".$name, 0777); |
| 561 | - if (!$stat) { |
|
| 620 | + if (!$stat) |
|
| 621 | + { |
|
| 562 | 622 | return "403 Forbidden"; |
| 563 | 623 | } |
| 564 | 624 | |
@@ -576,16 +636,20 @@ discard block |
||
| 576 | 636 | { |
| 577 | 637 | $path = $this->base . "/" .$options["path"]; |
| 578 | 638 | |
| 579 | - if (!file_exists($path)) { |
|
| 639 | + if (!file_exists($path)) |
|
| 640 | + { |
|
| 580 | 641 | return "404 Not found"; |
| 581 | 642 | } |
| 582 | 643 | |
| 583 | - if (is_dir($path)) { |
|
| 644 | + if (is_dir($path)) |
|
| 645 | + { |
|
| 584 | 646 | $query = "DELETE FROM {$this->db_prefix}properties |
| 585 | 647 | WHERE path LIKE '".$this->_slashify($options["path"])."%'"; |
| 586 | 648 | mysql_query($query); |
| 587 | 649 | System::rm(array("-rf", $path)); |
| 588 | - } else { |
|
| 650 | + } |
|
| 651 | + else |
|
| 652 | + { |
|
| 589 | 653 | unlink($path); |
| 590 | 654 | } |
| 591 | 655 | $query = "DELETE FROM {$this->db_prefix}properties |
@@ -617,26 +681,35 @@ discard block |
||
| 617 | 681 | { |
| 618 | 682 | // TODO Property updates still broken (Litmus should detect this?) |
| 619 | 683 | |
| 620 | - if (!empty($this->_SERVER["CONTENT_LENGTH"])) { // no body parsing yet |
|
| 684 | + if (!empty($this->_SERVER["CONTENT_LENGTH"])) |
|
| 685 | + { |
|
| 686 | +// no body parsing yet |
|
| 621 | 687 | return "415 Unsupported media type"; |
| 622 | 688 | } |
| 623 | 689 | |
| 624 | 690 | // no copying to different WebDAV Servers yet |
| 625 | - if (isset($options["dest_url"])) { |
|
| 691 | + if (isset($options["dest_url"])) |
|
| 692 | + { |
|
| 626 | 693 | return "502 bad gateway"; |
| 627 | 694 | } |
| 628 | 695 | |
| 629 | 696 | $source = $this->base . $options["path"]; |
| 630 | - if (!file_exists($source)) { |
|
| 697 | + if (!file_exists($source)) |
|
| 698 | + { |
|
| 631 | 699 | return "404 Not found"; |
| 632 | 700 | } |
| 633 | 701 | |
| 634 | - if (is_dir($source)) { // resource is a collection |
|
| 635 | - switch ($options["depth"]) { |
|
| 702 | + if (is_dir($source)) |
|
| 703 | + { |
|
| 704 | +// resource is a collection |
|
| 705 | + switch ($options["depth"]) |
|
| 706 | + { |
|
| 636 | 707 | case "infinity": // valid |
| 637 | 708 | break; |
| 638 | 709 | case "0": // valid for COPY only |
| 639 | - if ($del) { // MOVE? |
|
| 710 | + if ($del) |
|
| 711 | + { |
|
| 712 | +// MOVE? |
|
| 640 | 713 | return "400 Bad request"; |
| 641 | 714 | } |
| 642 | 715 | break; |
@@ -649,7 +722,8 @@ discard block |
||
| 649 | 722 | $dest = $this->base . $options["dest"]; |
| 650 | 723 | $destdir = dirname($dest); |
| 651 | 724 | |
| 652 | - if (!file_exists($destdir) || !is_dir($destdir)) { |
|
| 725 | + if (!file_exists($destdir) || !is_dir($destdir)) |
|
| 726 | + { |
|
| 653 | 727 | return "409 Conflict"; |
| 654 | 728 | } |
| 655 | 729 | |
@@ -657,38 +731,52 @@ discard block |
||
| 657 | 731 | $new = !file_exists($dest); |
| 658 | 732 | $existing_col = false; |
| 659 | 733 | |
| 660 | - if (!$new) { |
|
| 661 | - if ($del && is_dir($dest)) { |
|
| 662 | - if (!$options["overwrite"]) { |
|
| 734 | + if (!$new) |
|
| 735 | + { |
|
| 736 | + if ($del && is_dir($dest)) |
|
| 737 | + { |
|
| 738 | + if (!$options["overwrite"]) |
|
| 739 | + { |
|
| 663 | 740 | return "412 precondition failed"; |
| 664 | 741 | } |
| 665 | 742 | $dest .= basename($source); |
| 666 | - if (file_exists($dest)) { |
|
| 743 | + if (file_exists($dest)) |
|
| 744 | + { |
|
| 667 | 745 | $options["dest"] .= basename($source); |
| 668 | - } else { |
|
| 746 | + } |
|
| 747 | + else |
|
| 748 | + { |
|
| 669 | 749 | $new = true; |
| 670 | 750 | $existing_col = true; |
| 671 | 751 | } |
| 672 | 752 | } |
| 673 | 753 | } |
| 674 | 754 | |
| 675 | - if (!$new) { |
|
| 676 | - if ($options["overwrite"]) { |
|
| 755 | + if (!$new) |
|
| 756 | + { |
|
| 757 | + if ($options["overwrite"]) |
|
| 758 | + { |
|
| 677 | 759 | $stat = $this->DELETE(array("path" => $options["dest"])); |
| 678 | - if (($stat{0} != "2") && (substr($stat, 0, 3) != "404")) { |
|
| 760 | + if (($stat{0} != "2") && (substr($stat, 0, 3) != "404")) |
|
| 761 | + { |
|
| 679 | 762 | return $stat; |
| 680 | 763 | } |
| 681 | - } else { |
|
| 764 | + } |
|
| 765 | + else |
|
| 766 | + { |
|
| 682 | 767 | return "412 precondition failed"; |
| 683 | 768 | } |
| 684 | 769 | } |
| 685 | 770 | |
| 686 | - if ($del) { |
|
| 687 | - if (!rename($source, $dest)) { |
|
| 771 | + if ($del) |
|
| 772 | + { |
|
| 773 | + if (!rename($source, $dest)) |
|
| 774 | + { |
|
| 688 | 775 | return "500 Internal server error"; |
| 689 | 776 | } |
| 690 | 777 | $destpath = $this->_unslashify($options["dest"]); |
| 691 | - if (is_dir($source)) { |
|
| 778 | + if (is_dir($source)) |
|
| 779 | + { |
|
| 692 | 780 | $query = "UPDATE {$this->db_prefix}properties |
| 693 | 781 | SET path = REPLACE(path, '".$options["path"]."', '".$destpath."') |
| 694 | 782 | WHERE path LIKE '".$this->_slashify($options["path"])."%'"; |
@@ -699,40 +787,58 @@ discard block |
||
| 699 | 787 | SET path = '".$destpath."' |
| 700 | 788 | WHERE path = '".$options["path"]."'"; |
| 701 | 789 | mysql_query($query); |
| 702 | - } else { |
|
| 703 | - if (is_dir($source) && $options["depth"] == "infinity") { // no find for depth="0" |
|
| 790 | + } |
|
| 791 | + else |
|
| 792 | + { |
|
| 793 | + if (is_dir($source) && $options["depth"] == "infinity") |
|
| 794 | + { |
|
| 795 | +// no find for depth="0" |
|
| 704 | 796 | $files = System::find($source); |
| 705 | 797 | $files = array_reverse($files); |
| 706 | - } else { |
|
| 798 | + } |
|
| 799 | + else |
|
| 800 | + { |
|
| 707 | 801 | $files = array($source); |
| 708 | 802 | } |
| 709 | 803 | |
| 710 | - if (!is_array($files) || empty($files)) { |
|
| 804 | + if (!is_array($files) || empty($files)) |
|
| 805 | + { |
|
| 711 | 806 | return "500 Internal server error"; |
| 712 | 807 | } |
| 713 | 808 | |
| 714 | 809 | |
| 715 | - foreach ($files as $file) { |
|
| 716 | - if (is_dir($file)) { |
|
| 810 | + foreach ($files as $file) |
|
| 811 | + { |
|
| 812 | + if (is_dir($file)) |
|
| 813 | + { |
|
| 717 | 814 | $file = $this->_slashify($file); |
| 718 | 815 | } |
| 719 | 816 | |
| 720 | 817 | $destfile = str_replace($source, $dest, $file); |
| 721 | 818 | |
| 722 | - if (is_dir($file)) { |
|
| 723 | - if (!file_exists($destfile)) { |
|
| 724 | - if (!$this->_is_writable(dirname($destfile))) { |
|
| 819 | + if (is_dir($file)) |
|
| 820 | + { |
|
| 821 | + if (!file_exists($destfile)) |
|
| 822 | + { |
|
| 823 | + if (!$this->_is_writable(dirname($destfile))) |
|
| 824 | + { |
|
| 725 | 825 | return "403 Forbidden"; |
| 726 | 826 | } |
| 727 | - if (!mkdir($destfile)) { |
|
| 827 | + if (!mkdir($destfile)) |
|
| 828 | + { |
|
| 728 | 829 | return "409 Conflict"; |
| 729 | 830 | } |
| 730 | - } else if (!is_dir($destfile)) { |
|
| 831 | + } |
|
| 832 | + else if (!is_dir($destfile)) |
|
| 833 | + { |
|
| 731 | 834 | return "409 Conflict"; |
| 732 | 835 | } |
| 733 | - } else { |
|
| 836 | + } |
|
| 837 | + else |
|
| 838 | + { |
|
| 734 | 839 | |
| 735 | - if (!copy($file, $destfile)) { |
|
| 840 | + if (!copy($file, $destfile)) |
|
| 841 | + { |
|
| 736 | 842 | return "409 Conflict"; |
| 737 | 843 | } |
| 738 | 844 | } |
@@ -762,17 +868,24 @@ discard block |
||
| 762 | 868 | $dir = dirname($path)."/"; |
| 763 | 869 | $base = basename($path); |
| 764 | 870 | |
| 765 | - foreach ($options["props"] as $key => $prop) { |
|
| 766 | - if ($prop["ns"] == "DAV:") { |
|
| 871 | + foreach ($options["props"] as $key => $prop) |
|
| 872 | + { |
|
| 873 | + if ($prop["ns"] == "DAV:") |
|
| 874 | + { |
|
| 767 | 875 | $options["props"][$key]['status'] = "403 Forbidden"; |
| 768 | - } else { |
|
| 769 | - if (isset($prop["val"])) { |
|
| 876 | + } |
|
| 877 | + else |
|
| 878 | + { |
|
| 879 | + if (isset($prop["val"])) |
|
| 880 | + { |
|
| 770 | 881 | $query = "REPLACE INTO {$this->db_prefix}properties |
| 771 | 882 | SET path = '$options[path]' |
| 772 | 883 | , name = '$prop[name]' |
| 773 | 884 | , ns= '$prop[ns]' |
| 774 | 885 | , value = '$prop[val]'"; |
| 775 | - } else { |
|
| 886 | + } |
|
| 887 | + else |
|
| 888 | + { |
|
| 776 | 889 | $query = "DELETE FROM {$this->db_prefix}properties |
| 777 | 890 | WHERE path = '$options[path]' |
| 778 | 891 | AND name = '$prop[name]' |
@@ -799,13 +912,16 @@ discard block |
||
| 799 | 912 | |
| 800 | 913 | // TODO recursive locks on directories not supported yet |
| 801 | 914 | // makes litmus test "32. lock_collection" fail |
| 802 | - if (is_dir($fspath) && !empty($options["depth"])) { |
|
| 915 | + if (is_dir($fspath) && !empty($options["depth"])) |
|
| 916 | + { |
|
| 803 | 917 | return "409 Conflict"; |
| 804 | 918 | } |
| 805 | 919 | |
| 806 | 920 | $options["timeout"] = time()+300; // 5min. hardcoded |
| 807 | 921 | |
| 808 | - if (isset($options["update"])) { // Lock Update |
|
| 922 | + if (isset($options["update"])) |
|
| 923 | + { |
|
| 924 | +// Lock Update |
|
| 809 | 925 | $where = "WHERE path = '$options[path]' AND token = '$options[update]'"; |
| 810 | 926 | |
| 811 | 927 | $query = "SELECT owner, exclusivelock FROM {$this->db_prefix}locks $where"; |
@@ -813,7 +929,8 @@ discard block |
||
| 813 | 929 | $row = mysql_fetch_assoc($res); |
| 814 | 930 | mysql_free_result($res); |
| 815 | 931 | |
| 816 | - if (is_array($row)) { |
|
| 932 | + if (is_array($row)) |
|
| 933 | + { |
|
| 817 | 934 | $query = "UPDATE {$this->db_prefix}locks |
| 818 | 935 | SET expires = '$options[timeout]' |
| 819 | 936 | , modified = ".time()." |
@@ -825,7 +942,9 @@ discard block |
||
| 825 | 942 | $options['type'] = $row["exclusivelock"] ? "write" : "read"; |
| 826 | 943 | |
| 827 | 944 | return true; |
| 828 | - } else { |
|
| 945 | + } |
|
| 946 | + else |
|
| 947 | + { |
|
| 829 | 948 | return false; |
| 830 | 949 | } |
| 831 | 950 | } |
@@ -876,11 +995,13 @@ discard block |
||
| 876 | 995 | "; |
| 877 | 996 | $res = mysql_query($query); |
| 878 | 997 | |
| 879 | - if ($res) { |
|
| 998 | + if ($res) |
|
| 999 | + { |
|
| 880 | 1000 | $row = mysql_fetch_array($res); |
| 881 | 1001 | mysql_free_result($res); |
| 882 | 1002 | |
| 883 | - if ($row) { |
|
| 1003 | + if ($row) |
|
| 1004 | + { |
|
| 884 | 1005 | $result = array( "type" => "write", |
| 885 | 1006 | "scope" => $row["exclusivelock"] ? "exclusive" : "shared", |
| 886 | 1007 | "depth" => 0, |
@@ -290,7 +290,10 @@ discard block |
||
| 290 | 290 | ); |
| 291 | 291 | //_debug_array($this->contact_fields); |
| 292 | 292 | $this->own_account_acl = $GLOBALS['egw_info']['server']['own_account_acl']; |
| 293 | - if (!is_array($this->own_account_acl)) $this->own_account_acl = json_php_unserialize($this->own_account_acl, true); |
|
| 293 | + if (!is_array($this->own_account_acl)) |
|
| 294 | + { |
|
| 295 | + $this->own_account_acl = json_php_unserialize($this->own_account_acl, true); |
|
| 296 | + } |
|
| 294 | 297 | // we have only one acl (n_fn) for the whole name, as not all backends store every part in an own field |
| 295 | 298 | if ($this->own_account_acl && in_array('n_fn',$this->own_account_acl)) |
| 296 | 299 | { |
@@ -299,7 +302,10 @@ discard block |
||
| 299 | 302 | if ($GLOBALS['egw_info']['server']['org_fileds_to_update']) |
| 300 | 303 | { |
| 301 | 304 | $this->org_fields = $GLOBALS['egw_info']['server']['org_fileds_to_update']; |
| 302 | - if (!is_array($this->org_fields)) $this->org_fields = unserialize($this->org_fields); |
|
| 305 | + if (!is_array($this->org_fields)) |
|
| 306 | + { |
|
| 307 | + $this->org_fields = unserialize($this->org_fields); |
|
| 308 | + } |
|
| 303 | 309 | |
| 304 | 310 | // Set country code if country name is selected |
| 305 | 311 | $supported_fields = $this->get_fields('supported',null,0); |
@@ -356,7 +362,10 @@ discard block |
||
| 356 | 362 | } |
| 357 | 363 | |
| 358 | 364 | $addressbooks = $to_sort = array(); |
| 359 | - if ($extra_label) $addressbooks[''] = $extra_label; |
|
| 365 | + if ($extra_label) |
|
| 366 | + { |
|
| 367 | + $addressbooks[''] = $extra_label; |
|
| 368 | + } |
|
| 360 | 369 | $addressbooks[$user] = lang('Personal'); |
| 361 | 370 | // add all group addressbooks the user has the necessary rights too |
| 362 | 371 | foreach($grants as $uid => $rights) |
@@ -410,10 +419,19 @@ discard block |
||
| 410 | 419 | */ |
| 411 | 420 | function fileas($contact,$type=null, $isUpdate=false) |
| 412 | 421 | { |
| 413 | - if (is_null($type)) $type = $contact['fileas_type']; |
|
| 414 | - if (!$type) $type = $this->prefs['fileas_default'] ? $this->prefs['fileas_default'] : $this->fileas_types[0]; |
|
| 422 | + if (is_null($type)) |
|
| 423 | + { |
|
| 424 | + $type = $contact['fileas_type']; |
|
| 425 | + } |
|
| 426 | + if (!$type) |
|
| 427 | + { |
|
| 428 | + $type = $this->prefs['fileas_default'] ? $this->prefs['fileas_default'] : $this->fileas_types[0]; |
|
| 429 | + } |
|
| 415 | 430 | |
| 416 | - if (strpos($type,'n_fn') !== false) $contact['n_fn'] = $this->fullname($contact); |
|
| 431 | + if (strpos($type,'n_fn') !== false) |
|
| 432 | + { |
|
| 433 | + $contact['n_fn'] = $this->fullname($contact); |
|
| 434 | + } |
|
| 417 | 435 | |
| 418 | 436 | if($isUpdate) |
| 419 | 437 | { |
@@ -423,7 +441,10 @@ discard block |
||
| 423 | 441 | { |
| 424 | 442 | if(!isset($contact[$field])) |
| 425 | 443 | { |
| 426 | - if(is_null($old)) $old = $this->read($contact['id']); |
|
| 444 | + if(is_null($old)) |
|
| 445 | + { |
|
| 446 | + $old = $this->read($contact['id']); |
|
| 447 | + } |
|
| 427 | 448 | $contact[$field] = $old[$field]; |
| 428 | 449 | } |
| 429 | 450 | } |
@@ -466,7 +487,10 @@ discard block |
||
| 466 | 487 | */ |
| 467 | 488 | function fileas_type($contact,$file_as=null) |
| 468 | 489 | { |
| 469 | - if (is_null($file_as)) $file_as = $contact['n_fileas']; |
|
| 490 | + if (is_null($file_as)) |
|
| 491 | + { |
|
| 492 | + $file_as = $contact['n_fileas']; |
|
| 493 | + } |
|
| 470 | 494 | |
| 471 | 495 | if ($file_as) |
| 472 | 496 | { |
@@ -519,7 +543,10 @@ discard block |
||
| 519 | 543 | ); |
| 520 | 544 | foreach(array_keys($labels) as $name) |
| 521 | 545 | { |
| 522 | - if ($contact[$name]) $labels[$name] = $contact[$name]; |
|
| 546 | + if ($contact[$name]) |
|
| 547 | + { |
|
| 548 | + $labels[$name] = $contact[$name]; |
|
| 549 | + } |
|
| 523 | 550 | } |
| 524 | 551 | foreach($this->fileas_types as $fileas_type) |
| 525 | 552 | { |
@@ -632,7 +659,11 @@ discard block |
||
| 632 | 659 | $fields_to_update = array(); |
| 633 | 660 | foreach($contact as $field_name => $field_value) |
| 634 | 661 | { |
| 635 | - if($fields_exclude[$field_name] === true) continue; // dont touch specified field |
|
| 662 | + if($fields_exclude[$field_name] === true) |
|
| 663 | + { |
|
| 664 | + continue; |
|
| 665 | + } |
|
| 666 | + // dont touch specified field |
|
| 636 | 667 | |
| 637 | 668 | if (is_string($field_value) && $field_name != 'pubkey' && $field_name != 'jpegphoto') |
| 638 | 669 | { |
@@ -691,15 +722,21 @@ discard block |
||
| 691 | 722 | */ |
| 692 | 723 | function fullname($contact) |
| 693 | 724 | { |
| 694 | - if (empty($contact['n_family']) && empty($contact['n_given'])) { |
|
| 725 | + if (empty($contact['n_family']) && empty($contact['n_given'])) |
|
| 726 | + { |
|
| 695 | 727 | $cpart = array('org_name'); |
| 696 | - } else { |
|
| 728 | + } |
|
| 729 | + else |
|
| 730 | + { |
|
| 697 | 731 | $cpart = array('n_prefix','n_given','n_middle','n_family','n_suffix'); |
| 698 | 732 | } |
| 699 | 733 | $parts = array(); |
| 700 | 734 | foreach($cpart as $n) |
| 701 | 735 | { |
| 702 | - if ($contact[$n]) $parts[] = $contact[$n]; |
|
| 736 | + if ($contact[$n]) |
|
| 737 | + { |
|
| 738 | + $parts[] = $contact[$n]; |
|
| 739 | + } |
|
| 703 | 740 | } |
| 704 | 741 | return implode(' ',$parts); |
| 705 | 742 | } |
@@ -810,7 +847,10 @@ discard block |
||
| 810 | 847 | $ok = false; |
| 811 | 848 | if ($this->check_perms(Acl::DELETE,$c,$deny_account_delete)) |
| 812 | 849 | { |
| 813 | - if (!($old = $this->read($id))) return false; |
|
| 850 | + if (!($old = $this->read($id))) |
|
| 851 | + { |
|
| 852 | + return false; |
|
| 853 | + } |
|
| 814 | 854 | // check if we only mark contacts as deleted, or really delete them |
| 815 | 855 | // already marked as deleted item and accounts are always really deleted |
| 816 | 856 | // we cant mark accounts as deleted, as no such thing exists for accounts! |
@@ -818,8 +858,15 @@ discard block |
||
| 818 | 858 | { |
| 819 | 859 | $delete = $old; |
| 820 | 860 | $delete['tid'] = self::DELETED_TYPE; |
| 821 | - if ($check_etag) $delete['etag'] = $check_etag; |
|
| 822 | - if (($ok = $this->save($delete))) $ok = true; // we have to return true or false |
|
| 861 | + if ($check_etag) |
|
| 862 | + { |
|
| 863 | + $delete['etag'] = $check_etag; |
|
| 864 | + } |
|
| 865 | + if (($ok = $this->save($delete))) |
|
| 866 | + { |
|
| 867 | + $ok = true; |
|
| 868 | + } |
|
| 869 | + // we have to return true or false |
|
| 823 | 870 | Link::unlink(0,'addressbook',$id,'','','',true); |
| 824 | 871 | } |
| 825 | 872 | elseif (($ok = parent::delete($id,$check_etag))) |
@@ -830,7 +877,10 @@ discard block |
||
| 830 | 877 | // Don't notify of final purge |
| 831 | 878 | if ($ok && $old['tid'] != self::DELETED_TYPE) |
| 832 | 879 | { |
| 833 | - if (!isset($this->tracking)) $this->tracking = new Contacts\Tracking($this); |
|
| 880 | + if (!isset($this->tracking)) |
|
| 881 | + { |
|
| 882 | + $this->tracking = new Contacts\Tracking($this); |
|
| 883 | + } |
|
| 834 | 884 | $this->tracking->track(array('id' => $id), array('id' => $id), null, true); |
| 835 | 885 | } |
| 836 | 886 | } |
@@ -855,13 +905,16 @@ discard block |
||
| 855 | 905 | // remember if we add or update a entry |
| 856 | 906 | if (($isUpdate = $contact['id'])) |
| 857 | 907 | { |
| 858 | - if (!isset($contact['owner']) || !isset($contact['private'])) // owner/private not set on update, eg. SyncML |
|
| 908 | + if (!isset($contact['owner']) || !isset($contact['private'])) |
|
| 909 | + { |
|
| 910 | + // owner/private not set on update, eg. SyncML |
|
| 859 | 911 | { |
| 860 | 912 | if (($old = $this->read($contact['id']))) // --> try reading the old entry and set it from there |
| 861 | 913 | { |
| 862 | 914 | if(!isset($contact['owner'])) |
| 863 | 915 | { |
| 864 | 916 | $contact['owner'] = $old['owner']; |
| 917 | + } |
|
| 865 | 918 | } |
| 866 | 919 | if(!isset($contact['private'])) |
| 867 | 920 | { |
@@ -877,18 +930,33 @@ discard block |
||
| 877 | 930 | else |
| 878 | 931 | { |
| 879 | 932 | // if no owner/addressbook set use the setting of the add_default prefs (if set, otherwise the users personal addressbook) |
| 880 | - if (!isset($contact['owner'])) $contact['owner'] = $this->default_addressbook; |
|
| 881 | - if (!isset($contact['private'])) $contact['private'] = (int)$this->default_private; |
|
| 933 | + if (!isset($contact['owner'])) |
|
| 934 | + { |
|
| 935 | + $contact['owner'] = $this->default_addressbook; |
|
| 936 | + } |
|
| 937 | + if (!isset($contact['private'])) |
|
| 938 | + { |
|
| 939 | + $contact['private'] = (int)$this->default_private; |
|
| 940 | + } |
|
| 882 | 941 | // do NOT allow to create new accounts via addressbook, they are broken without an account_id |
| 883 | 942 | if (!$contact['owner'] && empty($contact['account_id'])) |
| 884 | 943 | { |
| 885 | 944 | $contact['owner'] = $this->default_addressbook ? $this->default_addressbook : $this->user; |
| 886 | 945 | } |
| 887 | 946 | // allow admins to import contacts with creator / created date set |
| 888 | - if (!$contact['creator'] || !$this->is_admin($contact)) $contact['creator'] = $this->user; |
|
| 889 | - if (!$contact['created'] || !$this->is_admin($contact)) $contact['created'] = $this->now_su; |
|
| 947 | + if (!$contact['creator'] || !$this->is_admin($contact)) |
|
| 948 | + { |
|
| 949 | + $contact['creator'] = $this->user; |
|
| 950 | + } |
|
| 951 | + if (!$contact['created'] || !$this->is_admin($contact)) |
|
| 952 | + { |
|
| 953 | + $contact['created'] = $this->now_su; |
|
| 954 | + } |
|
| 890 | 955 | |
| 891 | - if (!$contact['tid']) $contact['tid'] = 'n'; |
|
| 956 | + if (!$contact['tid']) |
|
| 957 | + { |
|
| 958 | + $contact['tid'] = 'n'; |
|
| 959 | + } |
|
| 892 | 960 | } |
| 893 | 961 | // ensure accounts and group addressbooks are never private! |
| 894 | 962 | if ($contact['owner'] <= 0) |
@@ -912,7 +980,8 @@ discard block |
||
| 912 | 980 | } |
| 913 | 981 | |
| 914 | 982 | // Update country codes |
| 915 | - foreach(array('adr_one_', 'adr_two_') as $c_prefix) { |
|
| 983 | + foreach(array('adr_one_', 'adr_two_') as $c_prefix) |
|
| 984 | + { |
|
| 916 | 985 | if($contact[$c_prefix.'countryname'] && !$contact[$c_prefix.'countrycode'] && |
| 917 | 986 | $code = Country::country_code($contact[$c_prefix.'countryname'])) |
| 918 | 987 | { |
@@ -939,7 +1008,10 @@ discard block |
||
| 939 | 1008 | { |
| 940 | 1009 | $contact['n_fn'] = $this->fullname($contact); |
| 941 | 1010 | } |
| 942 | - if (isset($contact['org_name'])) $contact['n_fileas'] = $this->fileas($contact, null, false); |
|
| 1011 | + if (isset($contact['org_name'])) |
|
| 1012 | + { |
|
| 1013 | + $contact['n_fileas'] = $this->fileas($contact, null, false); |
|
| 1014 | + } |
|
| 943 | 1015 | |
| 944 | 1016 | // Get old record for tracking changes |
| 945 | 1017 | if (!isset($old) && $isUpdate) |
@@ -1015,7 +1087,10 @@ discard block |
||
| 1015 | 1087 | if(!$contact['account_id'] || $contact['account_id'] && $this->account_repository == 'sql') |
| 1016 | 1088 | { |
| 1017 | 1089 | $deleted = ($old['tid'] == self::DELETED_TYPE || $contact['tid'] == self::DELETED_TYPE); |
| 1018 | - if (!isset($this->tracking)) $this->tracking = new Contacts\Tracking($this); |
|
| 1090 | + if (!isset($this->tracking)) |
|
| 1091 | + { |
|
| 1092 | + $this->tracking = new Contacts\Tracking($this); |
|
| 1093 | + } |
|
| 1019 | 1094 | $this->tracking->track($to_write, $old ? $old : null, null, $deleted); |
| 1020 | 1095 | } |
| 1021 | 1096 | } |
@@ -1097,10 +1172,12 @@ discard block |
||
| 1097 | 1172 | $data['fileas_type'] = $this->fileas_type($data); |
| 1098 | 1173 | |
| 1099 | 1174 | // Update country name from code |
| 1100 | - if($data['adr_one_countrycode'] != null) { |
|
| 1175 | + if($data['adr_one_countrycode'] != null) |
|
| 1176 | + { |
|
| 1101 | 1177 | $data['adr_one_countryname'] = Country::get_full_name($data['adr_one_countrycode'], true); |
| 1102 | 1178 | } |
| 1103 | - if($data['adr_two_countrycode'] != null) { |
|
| 1179 | + if($data['adr_two_countrycode'] != null) |
|
| 1180 | + { |
|
| 1104 | 1181 | $data['adr_two_countryname'] = Country::get_full_name($data['adr_two_countrycode'], true); |
| 1105 | 1182 | } |
| 1106 | 1183 | } |
@@ -1126,7 +1203,10 @@ discard block |
||
| 1126 | 1203 | */ |
| 1127 | 1204 | function check_perms($needed,$contact,$deny_account_delete=false,$user=null) |
| 1128 | 1205 | { |
| 1129 | - if (!$user) $user = $this->user; |
|
| 1206 | + if (!$user) |
|
| 1207 | + { |
|
| 1208 | + $user = $this->user; |
|
| 1209 | + } |
|
| 1130 | 1210 | if ($user == $this->user) |
| 1131 | 1211 | { |
| 1132 | 1212 | $grants = $this->grants; |
@@ -1196,8 +1276,14 @@ discard block |
||
| 1196 | 1276 | */ |
| 1197 | 1277 | function read_org($org_id) |
| 1198 | 1278 | { |
| 1199 | - if (!$org_id) return false; |
|
| 1200 | - if (strpos($org_id,'*AND*')!== false) $org_id = str_replace('*AND*','&',$org_id); |
|
| 1279 | + if (!$org_id) |
|
| 1280 | + { |
|
| 1281 | + return false; |
|
| 1282 | + } |
|
| 1283 | + if (strpos($org_id,'*AND*')!== false) |
|
| 1284 | + { |
|
| 1285 | + $org_id = str_replace('*AND*','&',$org_id); |
|
| 1286 | + } |
|
| 1201 | 1287 | $org = array(); |
| 1202 | 1288 | foreach(explode('|||',$org_id) as $part) |
| 1203 | 1289 | { |
@@ -1227,7 +1313,10 @@ discard block |
||
| 1227 | 1313 | } |
| 1228 | 1314 | // read the regular fields |
| 1229 | 1315 | $contacts = parent::search('',$regular_fields,'','','',false,'AND',false,$org); |
| 1230 | - if (!$contacts) return false; |
|
| 1316 | + if (!$contacts) |
|
| 1317 | + { |
|
| 1318 | + return false; |
|
| 1319 | + } |
|
| 1231 | 1320 | |
| 1232 | 1321 | // if we have custom fields, read and merge them in |
| 1233 | 1322 | if ($custom_fields) |
@@ -1275,7 +1364,10 @@ discard block |
||
| 1275 | 1364 | } |
| 1276 | 1365 | foreach($fields as $name => $values) |
| 1277 | 1366 | { |
| 1278 | - if (!in_array($name,$this->org_fields)) continue; |
|
| 1367 | + if (!in_array($name,$this->org_fields)) |
|
| 1368 | + { |
|
| 1369 | + continue; |
|
| 1370 | + } |
|
| 1279 | 1371 | |
| 1280 | 1372 | arsort($values,SORT_NUMERIC); |
| 1281 | 1373 | list($value,$num) = each($values); |
@@ -1345,16 +1437,25 @@ discard block |
||
| 1345 | 1437 | 'adr_two_countryname' => 'adr_one_countrycode', |
| 1346 | 1438 | ) as $name => $code) |
| 1347 | 1439 | { |
| 1348 | - if (!empty($from[$code])) $from[$name] = ''; |
|
| 1349 | - if (!empty($to[$code])) $to[$name] = ''; |
|
| 1440 | + if (!empty($from[$code])) |
|
| 1441 | + { |
|
| 1442 | + $from[$name] = ''; |
|
| 1443 | + } |
|
| 1444 | + if (!empty($to[$code])) |
|
| 1445 | + { |
|
| 1446 | + $to[$name] = ''; |
|
| 1447 | + } |
|
| 1350 | 1448 | } |
| 1351 | 1449 | $changed = array(); |
| 1352 | 1450 | foreach($only_org_fields ? $this->org_fields : array_keys($this->contact_fields) as $name) |
| 1353 | 1451 | { |
| 1354 | - if (in_array($name,array('modified','modifier'))) // never count these |
|
| 1452 | + if (in_array($name,array('modified','modifier'))) |
|
| 1453 | + { |
|
| 1454 | + // never count these |
|
| 1355 | 1455 | { |
| 1356 | 1456 | continue; |
| 1357 | 1457 | } |
| 1458 | + } |
|
| 1358 | 1459 | if ((string) $from[$name] != (string) $to[$name]) |
| 1359 | 1460 | { |
| 1360 | 1461 | $changed[$name] = $from[$name]; |
@@ -1374,13 +1475,19 @@ discard block |
||
| 1374 | 1475 | */ |
| 1375 | 1476 | function change_org($org_name,$from,$to,$members=null) |
| 1376 | 1477 | { |
| 1377 | - if (!($changed = $this->changed_fields($from,$to,true))) return false; |
|
| 1478 | + if (!($changed = $this->changed_fields($from,$to,true))) |
|
| 1479 | + { |
|
| 1480 | + return false; |
|
| 1481 | + } |
|
| 1378 | 1482 | |
| 1379 | 1483 | if (is_null($members) || !is_array($members)) |
| 1380 | 1484 | { |
| 1381 | 1485 | $members = $this->org_similar($org_name,$changed); |
| 1382 | 1486 | } |
| 1383 | - if (!$members) return false; |
|
| 1487 | + if (!$members) |
|
| 1488 | + { |
|
| 1489 | + return false; |
|
| 1490 | + } |
|
| 1384 | 1491 | |
| 1385 | 1492 | $ids = array(); |
| 1386 | 1493 | foreach($members as $member) |
@@ -1445,7 +1552,10 @@ discard block |
||
| 1445 | 1552 | $type = $this->prefs['link_title']; |
| 1446 | 1553 | if (!$type || $type === 'n_fileas') |
| 1447 | 1554 | { |
| 1448 | - if ($contact['n_fileas']) return $contact['n_fileas']; |
|
| 1555 | + if ($contact['n_fileas']) |
|
| 1556 | + { |
|
| 1557 | + return $contact['n_fileas']; |
|
| 1558 | + } |
|
| 1449 | 1559 | $type = null; |
| 1450 | 1560 | } |
| 1451 | 1561 | $title = $this->fileas($contact,$type); |
@@ -1513,7 +1623,10 @@ discard block |
||
| 1513 | 1623 | $limit = array($options['start'], $options['num_rows']); |
| 1514 | 1624 | } |
| 1515 | 1625 | $filter = (array)$options['filter']; |
| 1516 | - if ($GLOBALS['egw_info']['user']['preferences']['addressbook']['hide_accounts']) $filter['account_id'] = null; |
|
| 1626 | + if ($GLOBALS['egw_info']['user']['preferences']['addressbook']['hide_accounts']) |
|
| 1627 | + { |
|
| 1628 | + $filter['account_id'] = null; |
|
| 1629 | + } |
|
| 1517 | 1630 | if (($contacts =& parent::search($criteria,false,'org_name,n_family,n_given,cat_id,contact_email','','%',false,'OR', $limit, $filter))) |
| 1518 | 1631 | { |
| 1519 | 1632 | $ids = array(); |
@@ -1576,12 +1689,18 @@ discard block |
||
| 1576 | 1689 | */ |
| 1577 | 1690 | function calendar_info($ids) |
| 1578 | 1691 | { |
| 1579 | - if (!$ids) return null; |
|
| 1692 | + if (!$ids) |
|
| 1693 | + { |
|
| 1694 | + return null; |
|
| 1695 | + } |
|
| 1580 | 1696 | |
| 1581 | 1697 | $data = array(); |
| 1582 | 1698 | foreach(!is_array($ids) ? array($ids) : $ids as $id) |
| 1583 | 1699 | { |
| 1584 | - if (!($contact = $this->read($id))) continue; |
|
| 1700 | + if (!($contact = $this->read($id))) |
|
| 1701 | + { |
|
| 1702 | + continue; |
|
| 1703 | + } |
|
| 1585 | 1704 | |
| 1586 | 1705 | $data[] = array( |
| 1587 | 1706 | 'res_id' => $id, |
@@ -1603,21 +1722,33 @@ discard block |
||
| 1603 | 1722 | */ |
| 1604 | 1723 | function read_calendar($ids,$extra_title=true) |
| 1605 | 1724 | { |
| 1606 | - if (!$GLOBALS['egw_info']['user']['apps']['calendar']) return array(); |
|
| 1725 | + if (!$GLOBALS['egw_info']['user']['apps']['calendar']) |
|
| 1726 | + { |
|
| 1727 | + return array(); |
|
| 1728 | + } |
|
| 1607 | 1729 | |
| 1608 | 1730 | $uids = array(); |
| 1609 | 1731 | foreach($ids as $id) |
| 1610 | 1732 | { |
| 1611 | - if (is_numeric($id)) $uids[] = 'c'.$id; |
|
| 1733 | + if (is_numeric($id)) |
|
| 1734 | + { |
|
| 1735 | + $uids[] = 'c'.$id; |
|
| 1736 | + } |
|
| 1737 | + } |
|
| 1738 | + if (!$uids) |
|
| 1739 | + { |
|
| 1740 | + return array(); |
|
| 1612 | 1741 | } |
| 1613 | - if (!$uids) return array(); |
|
| 1614 | 1742 | |
| 1615 | 1743 | $bocal = new calendar_bo(); |
| 1616 | 1744 | $events = $bocal->search(array( |
| 1617 | 1745 | 'users' => $uids, |
| 1618 | 1746 | 'enum_recuring' => true, |
| 1619 | 1747 | )); |
| 1620 | - if (!$events) return array(); |
|
| 1748 | + if (!$events) |
|
| 1749 | + { |
|
| 1750 | + return array(); |
|
| 1751 | + } |
|
| 1621 | 1752 | |
| 1622 | 1753 | //_debug_array($events); |
| 1623 | 1754 | $calendars = array(); |
@@ -1631,11 +1762,14 @@ discard block |
||
| 1631 | 1762 | } |
| 1632 | 1763 | $id = (int)substr($uid,1); |
| 1633 | 1764 | |
| 1634 | - if ($event['start'] < $this->now_su) // past event --> check for last event |
|
| 1765 | + if ($event['start'] < $this->now_su) |
|
| 1766 | + { |
|
| 1767 | + // past event --> check for last event |
|
| 1635 | 1768 | { |
| 1636 | 1769 | if (!isset($calendars[$id]['last_event']) || $event['start'] > $calendars[$id]['last_event']) |
| 1637 | 1770 | { |
| 1638 | 1771 | $calendars[$id]['last_event'] = $event['start']; |
| 1772 | + } |
|
| 1639 | 1773 | $link = array( |
| 1640 | 1774 | 'id' => $event['id'], |
| 1641 | 1775 | 'app' => 'calendar', |
@@ -1737,27 +1871,36 @@ discard block |
||
| 1737 | 1871 | $account = null; |
| 1738 | 1872 | $custom_fields = Storage\Customfields::get('addressbook', true); |
| 1739 | 1873 | $custom_field_list = $this->read_customfields($ids); |
| 1740 | - foreach(parent::search(array('id'=>$ids),false) as $contact) // $this->search calls the extended search from ui! |
|
| 1874 | + foreach(parent::search(array('id'=>$ids),false) as $contact) |
|
| 1875 | + { |
|
| 1876 | + // $this->search calls the extended search from ui! |
|
| 1741 | 1877 | { |
| 1742 | 1878 | if ($contact['account_id']) |
| 1743 | 1879 | { |
| 1744 | 1880 | if (!is_null($account)) |
| 1745 | 1881 | { |
| 1746 | 1882 | echo $this->error = 'Can not merge more then one account!'; |
| 1883 | + } |
|
| 1747 | 1884 | return false; // we dont deal with two accounts! |
| 1748 | 1885 | } |
| 1749 | 1886 | $account = $contact; |
| 1750 | 1887 | continue; |
| 1751 | 1888 | } |
| 1752 | 1889 | // Add in custom fields |
| 1753 | - if (is_array($custom_field_list[$contact['id']])) $contact = array_merge($contact, $custom_field_list[$contact['id']]); |
|
| 1890 | + if (is_array($custom_field_list[$contact['id']])) |
|
| 1891 | + { |
|
| 1892 | + $contact = array_merge($contact, $custom_field_list[$contact['id']]); |
|
| 1893 | + } |
|
| 1754 | 1894 | |
| 1755 | 1895 | $pos = array_search($contact['id'],$ids); |
| 1756 | 1896 | $contacts[$pos] = $contact; |
| 1757 | 1897 | } |
| 1758 | - if (!is_null($account)) // we found an account, so we merge the contacts into it |
|
| 1898 | + if (!is_null($account)) |
|
| 1899 | + { |
|
| 1900 | + // we found an account, so we merge the contacts into it |
|
| 1759 | 1901 | { |
| 1760 | 1902 | $target = $account; |
| 1903 | + } |
|
| 1761 | 1904 | unset($account); |
| 1762 | 1905 | } |
| 1763 | 1906 | else // we found no account, so we merge all but the first into the first |
@@ -1774,7 +1917,10 @@ discard block |
||
| 1774 | 1917 | { |
| 1775 | 1918 | foreach($contact as $name => $value) |
| 1776 | 1919 | { |
| 1777 | - if (!$value) continue; |
|
| 1920 | + if (!$value) |
|
| 1921 | + { |
|
| 1922 | + continue; |
|
| 1923 | + } |
|
| 1778 | 1924 | |
| 1779 | 1925 | switch($name) |
| 1780 | 1926 | { |
@@ -1786,25 +1932,39 @@ discard block |
||
| 1786 | 1932 | break; // ignored |
| 1787 | 1933 | |
| 1788 | 1934 | case 'cat_id': // cats are all merged together |
| 1789 | - if (!is_array($target['cat_id'])) $target['cat_id'] = $target['cat_id'] ? explode(',',$target['cat_id']) : array(); |
|
| 1935 | + if (!is_array($target['cat_id'])) |
|
| 1936 | + { |
|
| 1937 | + $target['cat_id'] = $target['cat_id'] ? explode(',',$target['cat_id']) : array(); |
|
| 1938 | + } |
|
| 1790 | 1939 | $target['cat_id'] = array_unique(array_merge($target['cat_id'],is_array($value)?$value:explode(',',$value))); |
| 1791 | 1940 | break; |
| 1792 | 1941 | |
| 1793 | 1942 | default: |
| 1794 | 1943 | // Multi-select custom fields can also be merged |
| 1795 | - if($name[0] == '#') { |
|
| 1944 | + if($name[0] == '#') |
|
| 1945 | + { |
|
| 1796 | 1946 | $c_name = substr($name, 1); |
| 1797 | - if($custom_fields[$c_name]['type'] == 'select' && $custom_fields[$c_name]['rows'] > 1) { |
|
| 1798 | - if (!is_array($target[$name])) $target[$name] = $target[$name] ? explode(',',$target[$name]) : array(); |
|
| 1947 | + if($custom_fields[$c_name]['type'] == 'select' && $custom_fields[$c_name]['rows'] > 1) |
|
| 1948 | + { |
|
| 1949 | + if (!is_array($target[$name])) |
|
| 1950 | + { |
|
| 1951 | + $target[$name] = $target[$name] ? explode(',',$target[$name]) : array(); |
|
| 1952 | + } |
|
| 1799 | 1953 | $target[$name] = implode(',',array_unique(array_merge($target[$name],is_array($value)?$value:explode(',',$value)))); |
| 1800 | 1954 | } |
| 1801 | 1955 | } |
| 1802 | - if (!$target[$name]) $target[$name] = $value; |
|
| 1956 | + if (!$target[$name]) |
|
| 1957 | + { |
|
| 1958 | + $target[$name] = $value; |
|
| 1959 | + } |
|
| 1803 | 1960 | break; |
| 1804 | 1961 | } |
| 1805 | 1962 | } |
| 1806 | 1963 | } |
| 1807 | - if (!$this->save($target)) return 0; |
|
| 1964 | + if (!$this->save($target)) |
|
| 1965 | + { |
|
| 1966 | + return 0; |
|
| 1967 | + } |
|
| 1808 | 1968 | |
| 1809 | 1969 | $success = 1; |
| 1810 | 1970 | foreach($contacts as $contact) |
@@ -1834,7 +1994,10 @@ discard block |
||
| 1834 | 1994 | unset($newlinkID); |
| 1835 | 1995 | } |
| 1836 | 1996 | } |
| 1837 | - if ($this->delete($contact['id'])) $success++; |
|
| 1997 | + if ($this->delete($contact['id'])) |
|
| 1998 | + { |
|
| 1999 | + $success++; |
|
| 2000 | + } |
|
| 1838 | 2001 | } |
| 1839 | 2002 | return $success; |
| 1840 | 2003 | } |
@@ -1875,11 +2038,17 @@ discard block |
||
| 1875 | 2038 | */ |
| 1876 | 2039 | function add_list($keys,$owner,$contacts=array(),array &$data=array()) |
| 1877 | 2040 | { |
| 1878 | - if (!$this->check_list(null,Acl::ADD|Acl::EDIT,$owner)) return false; |
|
| 2041 | + if (!$this->check_list(null,Acl::ADD|Acl::EDIT,$owner)) |
|
| 2042 | + { |
|
| 2043 | + return false; |
|
| 2044 | + } |
|
| 1879 | 2045 | |
| 1880 | 2046 | try { |
| 1881 | 2047 | $ret = parent::add_list($keys,$owner,$contacts,$data); |
| 1882 | - if ($ret) unset(self::$list_cache[$ret]); |
|
| 2048 | + if ($ret) |
|
| 2049 | + { |
|
| 2050 | + unset(self::$list_cache[$ret]); |
|
| 2051 | + } |
|
| 1883 | 2052 | } |
| 1884 | 2053 | // catch sql error, as creating same name&owner list gives a sql error doublicate key |
| 1885 | 2054 | catch(Api\Db\Exception\InvalidSql $e) { |
@@ -1899,7 +2068,10 @@ discard block |
||
| 1899 | 2068 | */ |
| 1900 | 2069 | function add2list($contact,$list,array $existing=null) |
| 1901 | 2070 | { |
| 1902 | - if (!$this->check_list($list,Acl::EDIT)) return false; |
|
| 2071 | + if (!$this->check_list($list,Acl::EDIT)) |
|
| 2072 | + { |
|
| 2073 | + return false; |
|
| 2074 | + } |
|
| 1903 | 2075 | |
| 1904 | 2076 | unset(self::$list_cache[$list]); |
| 1905 | 2077 | |
@@ -1915,7 +2087,10 @@ discard block |
||
| 1915 | 2087 | */ |
| 1916 | 2088 | function remove_from_list($contact,$list=null) |
| 1917 | 2089 | { |
| 1918 | - if ($list && !$this->check_list($list,Acl::EDIT)) return false; |
|
| 2090 | + if ($list && !$this->check_list($list,Acl::EDIT)) |
|
| 2091 | + { |
|
| 2092 | + return false; |
|
| 2093 | + } |
|
| 1919 | 2094 | |
| 1920 | 2095 | if ($list) |
| 1921 | 2096 | { |
@@ -1937,7 +2112,10 @@ discard block |
||
| 1937 | 2112 | */ |
| 1938 | 2113 | function delete_list($list) |
| 1939 | 2114 | { |
| 1940 | - if (!$this->check_list($list,Acl::DELETE)) return false; |
|
| 2115 | + if (!$this->check_list($list,Acl::DELETE)) |
|
| 2116 | + { |
|
| 2117 | + return false; |
|
| 2118 | + } |
|
| 1941 | 2119 | |
| 1942 | 2120 | foreach((array)$list as $l) |
| 1943 | 2121 | { |
@@ -1955,7 +2133,10 @@ discard block |
||
| 1955 | 2133 | */ |
| 1956 | 2134 | function read_list($list) |
| 1957 | 2135 | { |
| 1958 | - if (isset(self::$list_cache[$list])) return self::$list_cache[$list]; |
|
| 2136 | + if (isset(self::$list_cache[$list])) |
|
| 2137 | + { |
|
| 2138 | + return self::$list_cache[$list]; |
|
| 2139 | + } |
|
| 1959 | 2140 | |
| 1960 | 2141 | return self::$list_cache[$list] = parent::read_list($list); |
| 1961 | 2142 | } |
@@ -2210,7 +2391,10 @@ discard block |
||
| 2210 | 2391 | |
| 2211 | 2392 | foreach ($columns_to_search as $field) |
| 2212 | 2393 | { |
| 2213 | - if ($relax && in_array($field, $tolerance_fields)) continue; |
|
| 2394 | + if ($relax && in_array($field, $tolerance_fields)) |
|
| 2395 | + { |
|
| 2396 | + continue; |
|
| 2397 | + } |
|
| 2214 | 2398 | |
| 2215 | 2399 | if (empty($contact[$field])) |
| 2216 | 2400 | { |
@@ -2275,7 +2459,10 @@ discard block |
||
| 2275 | 2459 | } |
| 2276 | 2460 | |
| 2277 | 2461 | // No need for more searches for relaxed matching |
| 2278 | - if ($relax || count($matchingContacts)) return $matchingContacts; |
|
| 2462 | + if ($relax || count($matchingContacts)) |
|
| 2463 | + { |
|
| 2464 | + return $matchingContacts; |
|
| 2465 | + } |
|
| 2279 | 2466 | |
| 2280 | 2467 | |
| 2281 | 2468 | if (!$empty_addr_one && $empty_addr_two) |
@@ -2328,7 +2515,8 @@ discard block |
||
| 2328 | 2515 | } |
| 2329 | 2516 | } |
| 2330 | 2517 | elseif (!$empty_addr_one && !$empty_addr_two) |
| 2331 | - { // try again after address swap |
|
| 2518 | + { |
|
| 2519 | +// try again after address swap |
|
| 2332 | 2520 | |
| 2333 | 2521 | foreach ($addr_one_fields as $key => $field) |
| 2334 | 2522 | { |
@@ -2375,7 +2563,10 @@ discard block |
||
| 2375 | 2563 | { |
| 2376 | 2564 | $filter = array('tid' => null); // tid=null --> use all entries incl. deleted (tid='D') |
| 2377 | 2565 | // show addressbook of a single user? |
| 2378 | - if (!is_null($owner)) $filter['owner'] = $owner; |
|
| 2566 | + if (!is_null($owner)) |
|
| 2567 | + { |
|
| 2568 | + $filter['owner'] = $owner; |
|
| 2569 | + } |
|
| 2379 | 2570 | |
| 2380 | 2571 | // should we hide the accounts addressbook |
| 2381 | 2572 | if (!$owner && $GLOBALS['egw_info']['user']['preferences']['addressbook']['hide_accounts']) |
@@ -57,7 +57,10 @@ discard block |
||
| 57 | 57 | { |
| 58 | 58 | foreach($app_additional as $addtional) |
| 59 | 59 | { |
| 60 | - if ($addtional) $attrs = array_unique(array_merge($attrs, $addtional)); |
|
| 60 | + if ($addtional) |
|
| 61 | + { |
|
| 62 | + $attrs = array_unique(array_merge($attrs, $addtional)); |
|
| 63 | + } |
|
| 61 | 64 | } |
| 62 | 65 | } |
| 63 | 66 | } |
@@ -154,10 +157,13 @@ discard block |
||
| 154 | 157 | { |
| 155 | 158 | header("X-Webkit-CSP: $csp"); // Chrome: <= 24, Safari incl. iOS |
| 156 | 159 | } |
| 157 | - elseif ($user_agent == 'firefox' && $version < 23 || $user_agent == 'msie') // Edge is reported as 'edge'! |
|
| 160 | + elseif ($user_agent == 'firefox' && $version < 23 || $user_agent == 'msie') |
|
| 161 | + { |
|
| 162 | + // Edge is reported as 'edge'! |
|
| 158 | 163 | { |
| 159 | 164 | header("X-Content-Security-Policy: $csp"); |
| 160 | 165 | } |
| 166 | + } |
|
| 161 | 167 | else |
| 162 | 168 | { |
| 163 | 169 | header("Content-Security-Policy: $csp"); |
@@ -82,7 +82,10 @@ discard block |
||
| 82 | 82 | error_log(__METHOD__.'() PHP_AUTH_USER='.array2string($_SERVER['PHP_AUTH_USER']).', PHP_AUTH_PW='.array2string($pw).', PHP_AUTH_DIGEST='.array2string($_SERVER['PHP_AUTH_DIGEST'])); |
| 83 | 83 | } |
| 84 | 84 | $realm = $GLOBALS['egw_info']['flags']['auth_realm']; |
| 85 | - if (empty($realm)) $realm = 'EGroupware'; |
|
| 85 | + if (empty($realm)) |
|
| 86 | + { |
|
| 87 | + $realm = 'EGroupware'; |
|
| 88 | + } |
|
| 86 | 89 | |
| 87 | 90 | $username = $_SERVER['PHP_AUTH_USER']; $password = $_SERVER['PHP_AUTH_PW']; |
| 88 | 91 | // Support for basic auth when using PHP CGI (what about digest auth?) |
@@ -109,7 +112,10 @@ discard block |
||
| 109 | 112 | if (!isset($username) || !($sessionid = $GLOBALS['egw']->session->create($username, $password, 'text', true))) |
| 110 | 113 | { |
| 111 | 114 | // if the session class gives a reason why the login failed --> append it to the REALM |
| 112 | - if ($GLOBALS['egw']->session->reason) $realm .= ': '.$GLOBALS['egw']->session->reason; |
|
| 115 | + if ($GLOBALS['egw']->session->reason) |
|
| 116 | + { |
|
| 117 | + $realm .= ': '.$GLOBALS['egw']->session->reason; |
|
| 118 | + } |
|
| 113 | 119 | |
| 114 | 120 | header('WWW-Authenticate: Basic realm="'.$realm.'"');// draft-reschke-basicauth-enc-06 adds, accept-charset="'.translation::charset().'"'); |
| 115 | 121 | self::digest_header($realm); |
@@ -135,7 +141,8 @@ discard block |
||
| 135 | 141 | // replace \x encoded non-ascii chars in password, as they are used eg. by Thunderbird for German umlauts |
| 136 | 142 | if (strpos($password, '\\x') !== false) |
| 137 | 143 | { |
| 138 | - $password = preg_replace_callback('/\\\\x([0-9A-F]{2})/i', function($matches){ |
|
| 144 | + $password = preg_replace_callback('/\\\\x([0-9A-F]{2})/i', function($matches) |
|
| 145 | + { |
|
| 139 | 146 | return chr(hexdec($matches[1])); |
| 140 | 147 | }, $password); |
| 141 | 148 | } |
@@ -163,7 +170,10 @@ discard block |
||
| 163 | 170 | if (!($GLOBALS['egw_info']['server']['auth_type'] == 'sql' && $GLOBALS['egw_info']['server']['sql_encryption_type'] == 'plain') || |
| 164 | 171 | $GLOBALS['egw_info']['server']['auth_type'] == 'ldap' && $GLOBALS['egw_info']['server']['ldap_encryption_type'] == 'plain') |
| 165 | 172 | { |
| 166 | - if (self::ERROR_LOG) error_log(__METHOD__."('$username') return false (no plaintext passwords used)"); |
|
| 173 | + if (self::ERROR_LOG) |
|
| 174 | + { |
|
| 175 | + error_log(__METHOD__."('$username') return false (no plaintext passwords used)"); |
|
| 176 | + } |
|
| 167 | 177 | return false; // no plain-text passwords used |
| 168 | 178 | } |
| 169 | 179 | // check for specific user, if given |
@@ -171,10 +181,16 @@ discard block |
||
| 171 | 181 | $GLOBALS['egw_info']['server']['auth_type'] == 'sql' && substr($user_pw,0,7) != '{PLAIN}')) |
| 172 | 182 | { |
| 173 | 183 | unset($user_pw); |
| 174 | - if (self::ERROR_LOG) error_log(__METHOD__."('$realm','$username') return false (unknown user or NO plaintext password for user)"); |
|
| 184 | + if (self::ERROR_LOG) |
|
| 185 | + { |
|
| 186 | + error_log(__METHOD__."('$realm','$username') return false (unknown user or NO plaintext password for user)"); |
|
| 187 | + } |
|
| 175 | 188 | return false; // user does NOT exist, or has no plaintext passwords (ldap server requires real root_dn or special ACL!) |
| 176 | 189 | } |
| 177 | - if (substr($user_pw,0,7) == '{PLAIN}') $user_pw = substr($user_pw,7); |
|
| 190 | + if (substr($user_pw,0,7) == '{PLAIN}') |
|
| 191 | + { |
|
| 192 | + $user_pw = substr($user_pw,7); |
|
| 193 | + } |
|
| 178 | 194 | |
| 179 | 195 | if (self::ERROR_LOG) |
| 180 | 196 | { |
@@ -196,7 +212,10 @@ discard block |
||
| 196 | 212 | { |
| 197 | 213 | $nonce = uniqid(); |
| 198 | 214 | header('WWW-Authenticate: Digest realm="'.$realm.'",qop="auth",nonce="'.$nonce.'",opaque="'.md5($realm).'"'); |
| 199 | - if (self::ERROR_LOG) error_log(__METHOD__."() offering digest auth for realm '$realm' using nonce='$nonce'"); |
|
| 215 | + if (self::ERROR_LOG) |
|
| 216 | + { |
|
| 217 | + error_log(__METHOD__."() offering digest auth for realm '$realm' using nonce='$nonce'"); |
|
| 218 | + } |
|
| 200 | 219 | } |
| 201 | 220 | } |
| 202 | 221 | |
@@ -211,7 +230,10 @@ discard block |
||
| 211 | 230 | */ |
| 212 | 231 | static public function is_valid($realm,$auth_digest=null,&$username=null,&$password=null) |
| 213 | 232 | { |
| 214 | - if (is_null($auth_digest)) $auth_digest = $_SERVER['PHP_AUTH_DIGEST']; |
|
| 233 | + if (is_null($auth_digest)) |
|
| 234 | + { |
|
| 235 | + $auth_digest = $_SERVER['PHP_AUTH_DIGEST']; |
|
| 236 | + } |
|
| 215 | 237 | |
| 216 | 238 | $data = self::parse_digest($auth_digest); |
| 217 | 239 | |
@@ -224,7 +246,10 @@ discard block |
||
| 224 | 246 | |
| 225 | 247 | $valid_response = md5($A1.':'.$data['nonce'].':'.$data['nc'].':'.$data['cnonce'].':'.$data['qop'].':'.$A2); |
| 226 | 248 | |
| 227 | - if (self::ERROR_LOG) error_log(__METHOD__."('$realm','$auth_digest','$username') response='$data[response]', valid_response='$valid_response' returning ".array2string($data['response'] === $valid_response)); |
|
| 249 | + if (self::ERROR_LOG) |
|
| 250 | + { |
|
| 251 | + error_log(__METHOD__."('$realm','$auth_digest','$username') response='$data[response]', valid_response='$valid_response' returning ".array2string($data['response'] === $valid_response)); |
|
| 252 | + } |
|
| 228 | 253 | return $data['response'] === $valid_response; |
| 229 | 254 | } |
| 230 | 255 | |
@@ -243,10 +268,16 @@ discard block |
||
| 243 | 268 | { |
| 244 | 269 | return false; |
| 245 | 270 | } |
| 246 | - if (is_null($password)) $password = $user_pw; |
|
| 271 | + if (is_null($password)) |
|
| 272 | + { |
|
| 273 | + $password = $user_pw; |
|
| 274 | + } |
|
| 247 | 275 | |
| 248 | 276 | $A1 = md5($username . ':' . $realm . ':' . $password); |
| 249 | - if (self::ERROR_LOG > 1) error_log(__METHOD__."('$realm','$username','$password') returning ".array2string($A1)); |
|
| 277 | + if (self::ERROR_LOG > 1) |
|
| 278 | + { |
|
| 279 | + error_log(__METHOD__."('$realm','$username','$password') returning ".array2string($A1)); |
|
| 280 | + } |
|
| 250 | 281 | return $A1; |
| 251 | 282 | } |
| 252 | 283 | |
@@ -90,7 +90,10 @@ |
||
| 90 | 90 | } |
| 91 | 91 | } |
| 92 | 92 | list(,self::$user_agent,self::$ua_version) = $parts; |
| 93 | - if ((self::$user_agent = strtolower(self::$user_agent)) == 'version') self::$user_agent = 'opera'; |
|
| 93 | + if ((self::$user_agent = strtolower(self::$user_agent)) == 'version') |
|
| 94 | + { |
|
| 95 | + self::$user_agent = 'opera'; |
|
| 96 | + } |
|
| 94 | 97 | // IE no longer reports MSIE, but "Trident/7.0; rv:11.0" |
| 95 | 98 | if (self::$user_agent=='trident') |
| 96 | 99 | { |
@@ -80,9 +80,13 @@ discard block |
||
| 80 | 80 | // mobile FF 24 on Android does NOT honor CSP! |
| 81 | 81 | UserAgent::type() == 'firefox' && !UserAgent::mobile() && UserAgent::version() >= 24 || |
| 82 | 82 | UserAgent::type() == 'safari' && !UserAgent::mobile() && UserAgent::version() >= 536 || // OS X |
| 83 | - UserAgent::type() == 'safari' && UserAgent::mobile() && UserAgent::version() >= 9537) // iOS 7 |
|
| 83 | + UserAgent::type() == 'safari' && UserAgent::mobile() && UserAgent::version() >= 9537) |
|
| 84 | 84 | { |
| 85 | - $csp = "script-src 'none'"; // forbid to execute any javascript |
|
| 85 | + // iOS 7 |
|
| 86 | + { |
|
| 87 | + $csp = "script-src 'none'"; |
|
| 88 | + } |
|
| 89 | + // forbid to execute any javascript |
|
| 86 | 90 | header("Content-Security-Policy: $csp"); |
| 87 | 91 | header("X-Webkit-CSP: $csp"); // Chrome: <= 24, Safari incl. iOS |
| 88 | 92 | //header("X-Content-Security-Policy: $csp"); // FF <= 22 |
@@ -96,7 +100,10 @@ discard block |
||
| 96 | 100 | } |
| 97 | 101 | if ($no_content_type) |
| 98 | 102 | { |
| 99 | - if ($force_download) self::disposition(Api\Vfs::basename($path), $force_download); |
|
| 103 | + if ($force_download) |
|
| 104 | + { |
|
| 105 | + self::disposition(Api\Vfs::basename($path), $force_download); |
|
| 106 | + } |
|
| 100 | 107 | } |
| 101 | 108 | else |
| 102 | 109 | { |
@@ -29,12 +29,19 @@ discard block |
||
| 29 | 29 | static function get($default='',$referer='') |
| 30 | 30 | { |
| 31 | 31 | // HTTP_REFERER seems NOT to get urldecoded |
| 32 | - if (!$referer) $referer = urldecode($_SERVER['HTTP_REFERER']); |
|
| 32 | + if (!$referer) |
|
| 33 | + { |
|
| 34 | + $referer = urldecode($_SERVER['HTTP_REFERER']); |
|
| 35 | + } |
|
| 33 | 36 | |
| 34 | 37 | $webserver_url = $GLOBALS['egw_info']['server']['webserver_url']; |
| 35 | - if (empty($webserver_url) || $webserver_url{0} == '/') // url is just a path |
|
| 38 | + if (empty($webserver_url) || $webserver_url{0} == '/') |
|
| 39 | + { |
|
| 40 | + // url is just a path |
|
| 36 | 41 | { |
| 37 | - $referer = preg_replace('/^https?:\/\/[^\/]+/','',$referer); // removing the domain part |
|
| 42 | + $referer = preg_replace('/^https?:\/\/[^\/]+/','',$referer); |
|
| 43 | + } |
|
| 44 | + // removing the domain part |
|
| 38 | 45 | } |
| 39 | 46 | if (strlen($webserver_url) > 1) |
| 40 | 47 | { |
@@ -42,7 +49,10 @@ discard block |
||
| 42 | 49 | } |
| 43 | 50 | $ret = str_replace('/etemplate/process_exec.php', '/index.php', $referer); |
| 44 | 51 | |
| 45 | - if (empty($ret) || strpos($ret, 'cd=yes') !== false) $ret = $default; |
|
| 52 | + if (empty($ret) || strpos($ret, 'cd=yes') !== false) |
|
| 53 | + { |
|
| 54 | + $ret = $default; |
|
| 55 | + } |
|
| 46 | 56 | |
| 47 | 57 | return $ret; |
| 48 | 58 | } |
@@ -71,7 +71,10 @@ discard block |
||
| 71 | 71 | $data_id = $attrs['value'] ? self::form_name($cname, $attrs['value']) : self::form_name($cname, self::ID_PREFIX . $this->id); |
| 72 | 72 | |
| 73 | 73 | // No need to proceed |
| 74 | - if(!$data_id) return; |
|
| 74 | + if(!$data_id) |
|
| 75 | + { |
|
| 76 | + return; |
|
| 77 | + } |
|
| 75 | 78 | |
| 76 | 79 | // Find out which record to load |
| 77 | 80 | $value = self::get_array(self::$request->content, $form_name, false, true); |
@@ -93,7 +96,10 @@ discard block |
||
| 93 | 96 | |
| 94 | 97 | // Set the new value so transformer can find it. Use prefix to avoid changing the original value |
| 95 | 98 | $new_value =& self::get_array(self::$request->content, self::ID_PREFIX .$this->id, true, false); |
| 96 | - if (true) $new_value = $data; |
|
| 99 | + if (true) |
|
| 100 | + { |
|
| 101 | + $new_value = $data; |
|
| 102 | + } |
|
| 97 | 103 | $this->id = self::ID_PREFIX . $this->id . "[{$attrs['field']}]"; |
| 98 | 104 | |
| 99 | 105 | $old_type = self::getElementAttribute($this->id, 'type'); |
@@ -86,7 +86,10 @@ discard block |
||
| 86 | 86 | } |
| 87 | 87 | |
| 88 | 88 | $parts = explode('.',$c_name); |
| 89 | - if($name == $parts[count($parts)-1]) return $c_template; |
|
| 89 | + if($name == $parts[count($parts)-1]) |
|
| 90 | + { |
|
| 91 | + return $c_template; |
|
| 92 | + } |
|
| 90 | 93 | } |
| 91 | 94 | } |
| 92 | 95 | // Template not found, try again with content expansion |
@@ -106,7 +109,10 @@ discard block |
||
| 106 | 109 | return false; |
| 107 | 110 | } |
| 108 | 111 | $reader = new XMLReader(); |
| 109 | - if (!$reader->open(self::rel2path($path))) return false; |
|
| 112 | + if (!$reader->open(self::rel2path($path))) |
|
| 113 | + { |
|
| 114 | + return false; |
|
| 115 | + } |
|
| 110 | 116 | |
| 111 | 117 | while($reader->read()) |
| 112 | 118 | { |
@@ -208,7 +214,10 @@ discard block |
||
| 208 | 214 | { |
| 209 | 215 | $url = Api\Vfs::download_url($path); |
| 210 | 216 | |
| 211 | - if ($url[0] == '/') $url = Api\Framework::link($url); |
|
| 217 | + if ($url[0] == '/') |
|
| 218 | + { |
|
| 219 | + $url = Api\Framework::link($url); |
|
| 220 | + } |
|
| 212 | 221 | |
| 213 | 222 | // mtime postfix has to use '?download=', as our WebDAV treats everything else literal and not ignore them like Apache for static files! |
| 214 | 223 | $url .= '?download='.filemtime($path); |
@@ -231,7 +240,10 @@ discard block |
||
| 231 | 240 | { |
| 232 | 241 | $cname =& $params[0]; |
| 233 | 242 | $old_cname = $params[0]; |
| 234 | - if ($this->attrs['content']) $cname = self::form_name($cname, $this->attrs['content'], $params[1]); |
|
| 243 | + if ($this->attrs['content']) |
|
| 244 | + { |
|
| 245 | + $cname = self::form_name($cname, $this->attrs['content'], $params[1]); |
|
| 246 | + } |
|
| 235 | 247 | |
| 236 | 248 | // Check for template from content, and run over it |
| 237 | 249 | // templates included via template tag have their name to load them from in attribute "template" |