| @@ 97-129 (lines=33) @@ | ||
| 94 | * @param bool|int $empty |
|
| 95 | * @return bool |
|
| 96 | */ |
|
| 97 | public function smallworld_remDir($userid, $directory, $empty = false) |
|
| 98 | { |
|
| 99 | if ('' != $userid) { |
|
| 100 | if ('/' === mb_substr($directory, -1)) { |
|
| 101 | $directory = mb_substr($directory, 0, -1); |
|
| 102 | } |
|
| 103 | ||
| 104 | if (!file_exists($directory) || !is_dir($directory)) { |
|
| 105 | return false; |
|
| 106 | } elseif (!is_readable($directory)) { |
|
| 107 | return false; |
|
| 108 | } |
|
| 109 | $directoryHandle = opendir($directory); |
|
| 110 | while (false !== ($contents = readdir($directoryHandle))) { |
|
| 111 | if ('.' !== $contents && '..' !== $contents) { |
|
| 112 | $path = $directory . '/' . $contents; |
|
| 113 | if (is_dir($path)) { |
|
| 114 | $this->smallworld_remDir($userid, $path); |
|
| 115 | } else { |
|
| 116 | unlink($path); |
|
| 117 | } |
|
| 118 | } |
|
| 119 | } |
|
| 120 | closedir($directoryHandle); |
|
| 121 | if (false === $empty) { |
|
| 122 | if (!rmdir($directory)) { |
|
| 123 | return false; |
|
| 124 | } |
|
| 125 | } |
|
| 126 | ||
| 127 | return true; |
|
| 128 | } |
|
| 129 | } |
|
| 130 | ||
| 131 | /** |
|
| 132 | * SmallworldDeleteDirectory function |
|
| @@ 690-724 (lines=35) @@ | ||
| 687 | * @param bool|int $empty |
|
| 688 | * @return bool |
|
| 689 | */ |
|
| 690 | public function smallworld_remDir($userid, $directory, $empty = false) |
|
| 691 | { |
|
| 692 | //@todo verify $userid should be int and then sanitize $userid accordingly before |
|
| 693 | // executing this routine |
|
| 694 | if (!empty($userid)) { |
|
| 695 | if ('/' === mb_substr($directory, -1)) { |
|
| 696 | $directory = mb_substr($directory, 0, -1); |
|
| 697 | } |
|
| 698 | ||
| 699 | if (!file_exists($directory) || !is_dir($directory)) { |
|
| 700 | return false; |
|
| 701 | } elseif (!is_readable($directory)) { |
|
| 702 | return false; |
|
| 703 | } |
|
| 704 | $directoryHandle = opendir($directory); |
|
| 705 | while (false !== ($contents = readdir($directoryHandle))) { |
|
| 706 | if ('.' !== $contents && '..' !== $contents) { |
|
| 707 | $path = $directory . '/' . $contents; |
|
| 708 | if (is_dir($path)) { |
|
| 709 | $this->smallworld_remDir($userid, $path); |
|
| 710 | } else { |
|
| 711 | unlink($path); |
|
| 712 | } |
|
| 713 | } |
|
| 714 | } |
|
| 715 | closedir($directoryHandle); |
|
| 716 | if (false === $empty) { |
|
| 717 | if (!rmdir($directory)) { |
|
| 718 | return false; |
|
| 719 | } |
|
| 720 | } |
|
| 721 | ||
| 722 | return true; |
|
| 723 | } |
|
| 724 | } |
|
| 725 | ||
| 726 | /** |
|
| 727 | * Update private settings |
|