X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=application%2Fhelper%2FFileUtils.php;fp=application%2FFileUtils.php;h=e8a2168cca98be947e8aba2da18b499543084fa0;hb=af50eba28a7bd286de4c8c9ee6dc5216b915d149;hp=30560bfc3a929a272a7932c893a7212f5d598da1;hpb=b6f678a5a1d15acf284ebcec16c905e976671ce1;p=github%2Fshaarli%2FShaarli.git diff --git a/application/FileUtils.php b/application/helper/FileUtils.php similarity index 57% rename from application/FileUtils.php rename to application/helper/FileUtils.php index 30560bfc..e8a2168c 100644 --- a/application/FileUtils.php +++ b/application/helper/FileUtils.php @@ -1,6 +1,6 @@ isDot()) { + continue; + } + + if (in_array($file->getBasename(), $exclude, true)) { + $skipped = true; + continue; + } + + if ($file->isFile()) { + unlink($file->getPathname()); + } elseif ($file->isDir()) { + $skipped = static::clearFolder($file->getRealPath(), true, $exclude) || $skipped; + } + } + + if ($selfDelete && !$skipped) { + rmdir($path); + } + + return $skipped; + } + + /** + * Checks that the given path is inside Shaarli directory. + */ + public static function isPathInShaarliFolder(string $path): bool + { + $rootDirectory = dirname(dirname(dirname(__FILE__))); + + return strpos(realpath($path), $rootDirectory) !== false; + } }