twig.inc.php 860 B

123456789101112131415161718192021222324252627
  1. <?php
  2. use Twig\Environment;
  3. use Twig\Loader\FilesystemLoader;
  4. use Twig\TwigFilter;
  5. use Twig\TwigFunction;
  6. $loader = new FilesystemLoader($_SERVER['DOCUMENT_ROOT'].'/templates');
  7. $twig = new Environment($loader, [
  8. 'debug' => $DEV_MODE,
  9. 'cache' => $_SERVER['DOCUMENT_ROOT'].'/templates/cache',
  10. ]);
  11. // functions
  12. $twig->addFunction(new TwigFunction('query_string', function (array $params = []) {
  13. return http_build_query(array_merge($_GET, $params));
  14. }));
  15. $twig->addFunction(new TwigFunction('is_uri', function (string $uri, string $where = null) {
  16. if (is_null($where)) $where = $_SERVER['REQUEST_URI'];
  17. return preg_match('/'.$uri.'/i', $where);
  18. }));
  19. // filters
  20. $twig->addFilter(new TwigFilter('rot13', 'str_rot13'));
  21. $twig->addFilter(new TwigFilter('base64_encode', 'base64_encode'));
  22. $twig->addFilter(new TwigFilter('formatBytes', 'formatBytes'));