@@ 134-168 (lines=35) @@ | ||
131 | * |
|
132 | * @uses \Xmf\Module\Helper::getHelper() |
|
133 | */ |
|
134 | public static function deleteDirectory($src) |
|
135 | { |
|
136 | // Only continue if user is a 'global' Admin |
|
137 | if (!($GLOBALS['xoopsUser'] instanceof \XoopsUser) || !$GLOBALS['xoopsUser']->isAdmin()) { |
|
138 | return false; |
|
139 | } |
|
140 | ||
141 | $success = true; |
|
142 | // remove old files |
|
143 | $dirInfo = new \SplFileInfo($src); |
|
144 | // validate is a directory |
|
145 | if ($dirInfo->isDir()) { |
|
146 | $fileList = array_diff(scandir($src, SCANDIR_SORT_NONE), ['..', '.']); |
|
147 | foreach ($fileList as $k => $v) { |
|
148 | $fileInfo = new \SplFileInfo("{$src}/{$v}"); |
|
149 | if ($fileInfo->isDir()) { |
|
150 | // recursively handle subdirectories |
|
151 | if (!$success = self::deleteDirectory($fileInfo->getRealPath())) { |
|
152 | break; |
|
153 | } |
|
154 | } elseif (!($success = unlink($fileInfo->getRealPath()))) { |
|
155 | break; |
|
156 | } |
|
157 | } |
|
158 | // now delete this (sub)directory if all the files are gone |
|
159 | if ($success) { |
|
160 | $success = rmdir($dirInfo->getRealPath()); |
|
161 | } |
|
162 | } else { |
|
163 | // input is not a valid directory |
|
164 | $success = false; |
|
165 | } |
|
166 | ||
167 | return $success; |
|
168 | } |
|
169 | ||
170 | /** |
|
171 | * Recursively remove directory |
@@ 102-135 (lines=34) @@ | ||
99 | * |
|
100 | * @see \XoopsModules\Xoopsfaq\Helper::getHelper() |
|
101 | */ |
|
102 | public static function deleteDirectory($src) |
|
103 | { |
|
104 | // Only continue if user is a 'global' Admin |
|
105 | if (!($GLOBALS['xoopsUser'] instanceof \XoopsUser) || !$GLOBALS['xoopsUser']->isAdmin()) { |
|
106 | return false; |
|
107 | } |
|
108 | ||
109 | $success = true; |
|
110 | // remove old files |
|
111 | $dirInfo = new \SplFileInfo($src); |
|
112 | // validate is a directory |
|
113 | if ($dirInfo->isDir()) { |
|
114 | $fileList = array_diff(scandir($src), ['..', '.']); |
|
115 | foreach ($fileList as $k => $v) { |
|
116 | $fileInfo = new \SplFileInfo($src . '/' . $v); |
|
117 | if ($fileInfo->isDir()) { |
|
118 | // recursively handle subdirectories |
|
119 | if (!$success = static::deleteDirectory($fileInfo->getRealPath())) { |
|
120 | break; |
|
121 | } |
|
122 | } elseif (!($success = unlink($fileInfo->getRealPath()))) { |
|
123 | break; |
|
124 | } |
|
125 | } |
|
126 | // now delete this (sub)directory if all the files are gone |
|
127 | if ($success) { |
|
128 | $success = rmdir($dirInfo->getRealPath()); |
|
129 | } |
|
130 | } else { |
|
131 | // input is not a valid directory |
|
132 | $success = false; |
|
133 | } |
|
134 | return $success; |
|
135 | } |
|
136 | ||
137 | /** |
|
138 | * |