diff options
author | 2022-10-16 12:03:57 +0200 | |
---|---|---|
committer | 2022-10-16 12:03:57 +0200 | |
commit | e21394d2d32b2ce739cf4236b4e955621e4e9308 (patch) | |
tree | 453c3e9111c2ff595ab2816ba13fe4f1d036378c /lib/html.php | |
parent | 78fa03238c523ed0067c58ac5a0ac7e951f4dbc1 (diff) | |
download | rss-bridge-e21394d2d32b2ce739cf4236b4e955621e4e9308.tar.gz rss-bridge-e21394d2d32b2ce739cf4236b4e955621e4e9308.tar.zst rss-bridge-e21394d2d32b2ce739cf4236b4e955621e4e9308.zip |
refactor: html format (#3062)
* refactor: html format
Fix a few small bugs too
* fix
* fix
* trigger build
* striptags instead of encode title
Diffstat (limited to 'lib/html.php')
-rw-r--r-- | lib/html.php | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/lib/html.php b/lib/html.php index 693504b0..1e852928 100644 --- a/lib/html.php +++ b/lib/html.php @@ -18,15 +18,26 @@ function render(string $template, array $context = []): string return render_template('base.html.php', $context); } +/** + * Render template as absolute path or relative to templates folder. + * Do not pass user input in $template + */ function render_template(string $template, array $context = []): string { if (isset($context['template'])) { throw new \Exception("Don't use `template` as a context key"); } + $templateFilepath = __DIR__ . '/../templates/' . $template; extract($context); ob_start(); try { - require __DIR__ . '/../templates/' . $template; + if (is_file($template)) { + require $template; + } elseif (is_file($templateFilepath)) { + require $templateFilepath; + } else { + throw new \Exception(sprintf('Unable to find template `%s`', $template)); + } } catch (\Throwable $e) { ob_end_clean(); throw $e; |