Matthias Andreas Benkard | 12a5735 | 2021-12-28 18:02:04 +0100 | [diff] [blame] | 1 | <?php |
| 2 | |
| 3 | use Twig\Environment; |
| 4 | use Twig\Loader\FilesystemLoader; |
| 5 | use Twig\TwigFilter; |
| 6 | use Twig\TwigFunction; |
| 7 | |
| 8 | $loader = new FilesystemLoader($_SERVER['DOCUMENT_ROOT'].'/templates'); |
| 9 | $twig = new Environment($loader, [ |
| 10 | 'debug' => $DEV_MODE, |
| 11 | 'cache' => $_SERVER['DOCUMENT_ROOT'].'/templates/cache', |
| 12 | ]); |
| 13 | |
| 14 | // functions |
| 15 | $twig->addFunction(new TwigFunction('query_string', function (array $params = []) { |
| 16 | return http_build_query(array_merge($_GET, $params)); |
| 17 | })); |
| 18 | |
| 19 | $twig->addFunction(new TwigFunction('is_uri', function (string $uri, string $where = null) { |
| 20 | if (is_null($where)) $where = $_SERVER['REQUEST_URI']; |
| 21 | return preg_match('/'.$uri.'/i', $where); |
| 22 | })); |
| 23 | |
| 24 | // filters |
| 25 | $twig->addFilter(new TwigFilter('rot13', 'str_rot13')); |
| 26 | $twig->addFilter(new TwigFilter('base64_encode', 'base64_encode')); |
Matthias Andreas Benkard | 1ba5381 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 27 | $twig->addFilter(new TwigFilter('formatBytes', 'formatBytes')); |