Revert "Add dirFiles Twig function"

This reverts commit c70ae88a2a.
main
Anonymous Contributor 2023-09-15 14:37:06 +02:00
parent 7b51a73a1c
commit d0f29ee96b
2 changed files with 1 additions and 45 deletions

View File

@ -5,14 +5,5 @@ use Grav\Common\Theme;
class FourCreative extends Theme
{
public static function getSubscribedEvents()
{
return ['onTwigExtensions' => ['onTwigExtensions', 0]];
}
public function onTwigExtensions()
{
require_once __DIR__.DIRECTORY_SEPARATOR.'php'.DIRECTORY_SEPARATOR.'DirFilesExtension.php';
$this->grav['twig']->twig->addExtension(new DirFilesExtension());
}
// Access plugin events in this class
}

View File

@ -1,35 +0,0 @@
<?php
declare(strict_types=1);
namespace Grav\Theme;
use Grav\Common\Twig\Extension\GravExtension;
class DirFilesExtension extends GravExtension
{
public function getName(): string
{
return 'DirFilesExtension';
}
public function getFunctions(): array
{
return [new \Twig_SimpleFunction('dirFiles', [$this, 'getDirFiles'])];
}
public function getDirFiles(string $dir, string $exts): array
{
$res = array();
$dir = '..'.DIRECTORY_SEPARATOR.(str_starts_with($dir, '/') ? substr($dir, 1) : $dir);
if (file_exists($dir) && $dirHandle = opendir($dir))
{
while ($entry = readdir($dirHandle)) {
if (preg_match('/^[a-zA-Z0-9-_][a-zA-Z0-9-_.]*\.('.$exts.')$/', $entry)) {
$res[] = $dir.DIRECTORY_SEPARATOR.$entry;
}
}
}
return $res;
}
}