| @@ 170-200 (lines=31) @@ | ||
| 167 | * |
|
| 168 | * @return bool true on success |
|
| 169 | */ |
|
| 170 | public static function rmove($src, $dest) |
|
| 171 | { |
|
| 172 | // Only continue if user is a 'global' Admin |
|
| 173 | if (!($GLOBALS['xoopsUser'] instanceof \XoopsUser) || !$GLOBALS['xoopsUser']->isAdmin()) { |
|
| 174 | return false; |
|
| 175 | } |
|
| 176 | ||
| 177 | // If source is not a directory stop processing |
|
| 178 | if (!\is_dir($src)) { |
|
| 179 | return false; |
|
| 180 | } |
|
| 181 | ||
| 182 | // If the destination directory does not exist and could not be created stop processing |
|
| 183 | if (!\is_dir($dest) && !\mkdir($dest) && !\is_dir($dest)) { |
|
| 184 | return false; |
|
| 185 | } |
|
| 186 | ||
| 187 | // Open the source directory to read in files |
|
| 188 | $iterator = new \DirectoryIterator($src); |
|
| 189 | foreach ($iterator as $fObj) { |
|
| 190 | if ($fObj->isFile()) { |
|
| 191 | \rename($fObj->getPathname(), "{$dest}/" . $fObj->getFilename()); |
|
| 192 | } elseif (!$fObj->isDot() && $fObj->isDir()) { |
|
| 193 | // Try recursively on directory |
|
| 194 | self::rmove($fObj->getPathname(), "{$dest}/" . $fObj->getFilename()); |
|
| 195 | // rmdir($fObj->getPath()); // now delete the directory |
|
| 196 | } |
|
| 197 | } |
|
| 198 | $iterator = null; // clear iterator Obj to close file/directory |
|
| 199 | return \rmdir($src); // remove the directory & return results |
|
| 200 | } |
|
| 201 | ||
| 202 | /** |
|
| 203 | * Recursively copy directories and files from one directory to another |
|
| @@ 213-241 (lines=29) @@ | ||
| 210 | * |
|
| 211 | * @uses \Xmf\Module\Helper::getHelper() |
|
| 212 | */ |
|
| 213 | public static function rcopy($src, $dest) |
|
| 214 | { |
|
| 215 | // Only continue if user is a 'global' Admin |
|
| 216 | if (!($GLOBALS['xoopsUser'] instanceof \XoopsUser) || !$GLOBALS['xoopsUser']->isAdmin()) { |
|
| 217 | return false; |
|
| 218 | } |
|
| 219 | ||
| 220 | // If source is not a directory stop processing |
|
| 221 | if (!\is_dir($src)) { |
|
| 222 | return false; |
|
| 223 | } |
|
| 224 | ||
| 225 | // If the destination directory does not exist and could not be created stop processing |
|
| 226 | if (!\is_dir($dest) && !\mkdir($dest) && !\is_dir($dest)) { |
|
| 227 | return false; |
|
| 228 | } |
|
| 229 | ||
| 230 | // Open the source directory to read in files |
|
| 231 | $iterator = new \DirectoryIterator($src); |
|
| 232 | foreach ($iterator as $fObj) { |
|
| 233 | if ($fObj->isFile()) { |
|
| 234 | \copy($fObj->getPathname(), "{$dest}/" . $fObj->getFilename()); |
|
| 235 | } elseif (!$fObj->isDot() && $fObj->isDir()) { |
|
| 236 | self::rcopy($fObj->getPathname(), "{$dest}/" . $fObj->getFilename()); |
|
| 237 | } |
|
| 238 | } |
|
| 239 | ||
| 240 | return true; |
|
| 241 | } |
|
| 242 | } |
|
| 243 | ||