1
0
mirror of https://github.com/RSS-Bridge/rss-bridge.git synced 2025-07-31 13:50:23 +02:00

refactor: html format (#3062)

* refactor: html format

Fix a few small bugs too

* fix

* fix

* trigger build

* striptags instead of encode title
This commit is contained in:
Dag
2022-10-16 12:03:57 +02:00
committed by GitHub
parent 78fa03238c
commit e21394d2d3
5 changed files with 141 additions and 121 deletions

View File

@@ -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();

View File

@@ -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;