blob: a3bc02d9289b01c89ce35f778e23df4ef36e26be [file] [log] [blame]
Matthias Andreas Benkard12a57352021-12-28 18:02:04 +01001<?php
2
3use Twig\Environment;
4use Twig\Loader\FilesystemLoader;
5use Twig\TwigFilter;
6use 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 Benkard1ba53812022-12-27 17:32:58 +010027$twig->addFilter(new TwigFilter('formatBytes', 'formatBytes'));