From b8b85d512b37f020b5c4e3c4a610dc87912020be Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Fri, 13 Apr 2018 22:18:21 +0200 Subject: [PATCH] Created template function --- Theme/Backend/template-functions.php | 85 ++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 Theme/Backend/template-functions.php diff --git a/Theme/Backend/template-functions.php b/Theme/Backend/template-functions.php new file mode 100644 index 0000000..27fa5bf --- /dev/null +++ b/Theme/Backend/template-functions.php @@ -0,0 +1,85 @@ +getPath() . $sub) + && phpOMS\Utils\StringUtils::startsWith( + str_replace('\\', '/', realpath($media->getPath() . $sub)), + $media->getPath() + ) + ) { + return $media->getPath() . $sub; + } + + return $media->getPath(); +}; + +$dirPathFunction = function ($media, string $sub) : string +{ + if (is_dir($media->getPath() . $sub) + && phpOMS\Utils\StringUtils::startsWith( + str_replace('\\', '/', realpath($media->getPath() . $sub)), + $media->getPath() + ) + ) { + return $media->getPath() . $sub; + } + + return $media->getPath(); +}; + +$isCollectionFunction = function ($media, string $sub) : bool +{ + return ($media->getExtension() === 'collection' + && !is_file($media->getPath() . $sub)) + || (is_dir($media->getPath()) + && ($sub === null || is_dir($media->getPath() . $sub)) + ); +}; + +$lineContentFunction = function (string $path) : array +{ + $output = file_get_contents($path); + $output = str_replace(["\r\n", "\r"], "\n", $output); + + return explode("\n", $output); +}; + +$isImageFunction = function ($media, string $path) : bool +{ + return FileUtils::getExtensionType($media->getExtension()) === ExtensionType::IMAGE + || FileUtils::getExtensionType(File::extension($path)) === ExtensionType::IMAGE; +};