parent
7b51a73a1c
commit
d0f29ee96b
|
@ -5,14 +5,5 @@ use Grav\Common\Theme;
|
||||||
|
|
||||||
class FourCreative extends Theme
|
class FourCreative extends Theme
|
||||||
{
|
{
|
||||||
public static function getSubscribedEvents()
|
// Access plugin events in this class
|
||||||
{
|
|
||||||
return ['onTwigExtensions' => ['onTwigExtensions', 0]];
|
|
||||||
}
|
|
||||||
|
|
||||||
public function onTwigExtensions()
|
|
||||||
{
|
|
||||||
require_once __DIR__.DIRECTORY_SEPARATOR.'php'.DIRECTORY_SEPARATOR.'DirFilesExtension.php';
|
|
||||||
$this->grav['twig']->twig->addExtension(new DirFilesExtension());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue