|
@@ 185-214 (lines=30) @@
|
| 182 |
|
* |
| 183 |
|
* @return bool true on success |
| 184 |
|
*/ |
| 185 |
|
public static function rmove($src, $dest) |
| 186 |
|
{ |
| 187 |
|
// Only continue if user is a 'global' Admin |
| 188 |
|
if (!($GLOBALS['xoopsUser'] instanceof \XoopsUser) || !$GLOBALS['xoopsUser']->isAdmin()) { |
| 189 |
|
return false; |
| 190 |
|
} |
| 191 |
|
|
| 192 |
|
// If source is not a directory stop processing |
| 193 |
|
if (!is_dir($src)) { |
| 194 |
|
return false; |
| 195 |
|
} |
| 196 |
|
|
| 197 |
|
// If the destination directory does not exist and could not be created stop processing |
| 198 |
|
if (!is_dir($dest) && !mkdir($dest, 0755)) { |
| 199 |
|
return false; |
| 200 |
|
} |
| 201 |
|
|
| 202 |
|
// Open the source directory to read in files |
| 203 |
|
$iterator = new \DirectoryIterator($src); |
| 204 |
|
foreach ($iterator as $fObj) { |
| 205 |
|
if ($fObj->isFile()) { |
| 206 |
|
rename($fObj->getPathname(), $dest . '/' . $fObj->getFilename()); |
| 207 |
|
} elseif (!$fObj->isDot() && $fObj->isDir()) { |
| 208 |
|
// Try recursively on directory |
| 209 |
|
static::rmove($fObj->getPathname(), $dest . '/' . $fObj->getFilename()); |
| 210 |
|
} |
| 211 |
|
} |
| 212 |
|
$iterator = null; // clear iterator Obj to close file/directory |
| 213 |
|
return rmdir($src); // remove the directory & return results |
| 214 |
|
} |
| 215 |
|
|
| 216 |
|
/** |
| 217 |
|
* Recursively copy directories and files from one directory to another |
|
@@ 227-254 (lines=28) @@
|
| 224 |
|
* |
| 225 |
|
* @see \XoopsModules\Xoopsfaq\Helper::getHelper() |
| 226 |
|
*/ |
| 227 |
|
public static function rcopy($src, $dest) |
| 228 |
|
{ |
| 229 |
|
// Only continue if user is a 'global' Admin |
| 230 |
|
if (!($GLOBALS['xoopsUser'] instanceof \XoopsUser) || !$GLOBALS['xoopsUser']->isAdmin()) { |
| 231 |
|
return false; |
| 232 |
|
} |
| 233 |
|
|
| 234 |
|
// If source is not a directory stop processing |
| 235 |
|
if (!is_dir($src)) { |
| 236 |
|
return false; |
| 237 |
|
} |
| 238 |
|
|
| 239 |
|
// If the destination directory does not exist and could not be created stop processing |
| 240 |
|
if (!is_dir($dest) && !mkdir($dest, 0755)) { |
| 241 |
|
return false; |
| 242 |
|
} |
| 243 |
|
|
| 244 |
|
// Open the source directory to read in files |
| 245 |
|
$iterator = new \DirectoryIterator($src); |
| 246 |
|
foreach ($iterator as $fObj) { |
| 247 |
|
if ($fObj->isFile()) { |
| 248 |
|
copy($fObj->getPathname(), $dest . '/' . $fObj->getFilename()); |
| 249 |
|
} elseif (!$fObj->isDot() && $fObj->isDir()) { |
| 250 |
|
static::rcopy($fObj->getPathname(), $dest . '/' . $fObj->getFilename()); |
| 251 |
|
} |
| 252 |
|
} |
| 253 |
|
return true; |
| 254 |
|
} |
| 255 |
|
|
| 256 |
|
/** |
| 257 |
|
* Render the icon links |