diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/FormatInterface.php | 2 | ||||
| -rw-r--r-- | lib/html.php | 13 |
2 files changed, 13 insertions, 2 deletions
diff --git a/lib/FormatInterface.php b/lib/FormatInterface.php index 8f98d6e4..c0355804 100644 --- a/lib/FormatInterface.php +++ b/lib/FormatInterface.php @@ -42,7 +42,7 @@ interface FormatInterface * Return items * * @throws \LogicException if the items are not set - * @return array The items + * @return FeedItem[] The items */ public function getItems(); 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; |
