FileSystem
class FileSystem extends FileSystem (View source)
The FileSystem class provides all methods related to file system operations.
Properties
static private | $packageDirectoryItems | The cached array of items in the packages directory. |
Methods
Get file extension for images based on mime types.
Return the path of the temp dir if it is writable by the webserver.
A wrapper for PHP's built-in glob function.
Find files by using the glob() method and filter the resulting array by a regex pattern.
Tests if a string is a file name with an allowed file extension.
Replace all backslashes in a given path with forward slashes.
Write content to a file and create the parent directory if needed.
Append a suffix to a path just before the trailing slash.
Open a data text file under the given path, read the data, append a suffix to the title variable and write back the data.
Unlike self::movePageDir(), this method only copies all files within a page directory without (!) any subdirectories.
Get the full file system path for the given path.
Get all items in the packages directory, optionally filtered by a regex string.
Return the file system path for the directory of a page based on $_POST['url'].
Recursively list all items in a directory.
Move a directory to a new location.
Move all items in /cache to the PHP temp directory.
Renames a file and its caption (if existing).
Creates an unique suffix for a path to avoid conflicts with existing directories.
Format, filter and write the data array a text file.
Details
in FileSystem at line 55
static bool
deleteFile(string $file)
Delete a file.
in FileSystem at line 69
static string
getExtension(string $file)
Return the extension for a given file.
in FileSystem at line 85
static mixed
getImageExtensionFromMimeType(string $file)
Get file extension for images based on mime types.
in FileSystem at line 124
static string
getTmpDir()
Return the path of the temp dir if it is writable by the webserver.
In any case, '/tmp' is the preferred directory, because of automatic cleanup at reboot, while other locations like '/var/tmp' do not get purged by the system. But since '/tmp' is only available on macos and linux, sys_get_temp_dir() is used as fallback.
in FileSystem at line 145
static array
glob(string $pattern, int $flags = 0)
A wrapper for PHP's built-in glob function.
This method always returns an array, even though glob() returns false on some systems instead of empty arrays.
in FileSystem at line 169
static array
globGrep(string $pattern, string $regex, int $flags = 0)
Find files by using the glob() method and filter the resulting array by a regex pattern.
Note that this method should basically replace the usage of GLOB_BRACE to be fully compatible to systems where this constant is not defined. Instead of a glob pattern like "/path/.{jpg,png}" it is more safe to use a generic pattern like "/path/.*" filtered by a regex like "/.(jpg|png)$/i" without using the GLOB_BRACE flag.
in FileSystem at line 183
static bool
isAllowedFileType(string $str)
Tests if a string is a file name with an allowed file extension.
Basically a possibly existing file extension is checked against the array of allowed file extensions.
"/url/file.jpg" will return true, "/url/file" or "/url/file.something" will return false.
in FileSystem at line 206
static bool
makeDir(string $path)
Create directory if not existing.
in FileSystem at line 223
static string
normalizeSlashes(string $path)
Replace all backslashes in a given path with forward slashes.
in FileSystem at line 234
static bool
write(string $file, string $content)
Write content to a file and create the parent directory if needed.
at line 68
static string
appendSuffixToPath(string $path, string $suffix)
Append a suffix to a path just before the trailing slash.
at line 79
static
appendSuffixToTitle(string $path, string $suffix)
Open a data text file under the given path, read the data, append a suffix to the title variable and write back the data.
at line 100
static
copyPageFiles(string $source, string $dest)
Unlike self::movePageDir(), this method only copies all files within a page directory without (!) any subdirectories.
at line 126
static bool
deleteMedia(string $file, Messenger $Messenger)
Deletes a file and its caption (if existing).
at line 167
static string
fullPagePath(string $path)
Get the full file system path for the given path.
at line 181
static array
getPackagesDirectoryItems(string $filter = '')
Get all items in the packages directory, optionally filtered by a regex string.
at line 200
static string
getPathByPostUrl(Automad $Automad)
Return the file system path for the directory of a page based on $_POST['url'].
In case URL is empty, return the '/shared' directory.
at line 217
static array
listDirectoryRecursively(string $directory, string $base = AM_BASE_DIR)
Recursively list all items in a directory.
at line 245
static string
movePageDir(string $oldPath, string $newParentPath, string $prefix, string $slug)
Move a directory to a new location.
The final path is composed of the parent directoy, the prefix and the title. In case the resulting path is already occupied, an index get appended to the prefix, to be reproducible when resaving the page.
at line 283
static string
purgeCache()
Move all items in /cache to the PHP temp directory.
at line 342
static bool
renameMedia(string $oldFile, string $newFile, Messenger $Messenger)
Renames a file and its caption (if existing).
at line 391
static string
uniquePathSuffix(string $path, string $prefix = '')
Creates an unique suffix for a path to avoid conflicts with existing directories.
at line 408
static
writeData(array $data, string $file)
Format, filter and write the data array a text file.