Loading app/Config/View.php +2 −1 Original line number Diff line number Diff line Loading @@ -4,6 +4,7 @@ declare(strict_types=1); namespace Config; use App\Views\Decorators\SiteHead; use CodeIgniter\Config\View as BaseView; use CodeIgniter\View\ViewDecoratorInterface; use ViewComponents\Decorator; Loading Loading @@ -53,5 +54,5 @@ class View extends BaseView * * @var list<class-string<ViewDecoratorInterface>> */ public array $decorators = [Decorator::class]; public array $decorators = [Decorator::class, SiteHead::class]; } app/Helpers/rss_helper.php +2 −2 Original line number Diff line number Diff line Loading @@ -298,7 +298,7 @@ if (! function_exists('get_rss_feed')) { } // run plugins hook at the end $plugins->setChannelTag($podcast, $channel); $plugins->channelTag($podcast, $channel); foreach ($episodes as $episode) { if ($episode->is_premium && ! $subscription instanceof Subscription) { Loading Loading @@ -460,7 +460,7 @@ if (! function_exists('get_rss_feed')) { ], $item); } $plugins->setItemTag($episode, $item); $plugins->itemTag($episode, $item); } return $rss->asXML(); Loading app/Views/Decorators/SiteHead.php 0 → 100644 +36 −0 Original line number Diff line number Diff line <?php declare(strict_types=1); namespace App\Views\Decorators; use CodeIgniter\View\ViewDecoratorInterface; class SiteHead implements ViewDecoratorInterface { private static int $renderedCount = 0; public static function decorate(string $html): string { if (url_is(config('Admin')->gateway . '*') || url_is(config('Install')->gateway)) { return $html; } if (static::$renderedCount > 0) { return $html; } ob_start(); // Start output buffering // run hook to add tags to <head> service('plugins')->siteHead(); $metaTags = ob_get_contents(); // Store buffer in variable ob_end_clean(); if (str_contains($html, '</head>')) { $html = str_replace('</head>', "\n\t{$metaTags}\n</head>", $html); ++static::$renderedCount; } return $html; } } modules/Plugins/BasePlugin.php +6 −2 Original line number Diff line number Diff line Loading @@ -59,11 +59,15 @@ abstract class BasePlugin implements PluginInterface // TODO: setup navigation and views? } public function setChannelTag(Podcast $podcast, SimpleRSSElement $channel): void public function channelTag(Podcast $podcast, SimpleRSSElement $channel): void { } public function setItemTag(Episode $episode, SimpleRSSElement $item): void public function itemTag(Episode $episode, SimpleRSSElement $item): void { } public function siteHead(): void { } Loading modules/Plugins/PluginInterface.php +4 −2 Original line number Diff line number Diff line Loading @@ -10,7 +10,9 @@ use App\Libraries\SimpleRSSElement; interface PluginInterface { public function setChannelTag(Podcast $podcast, SimpleRSSElement $channel): void; public function channelTag(Podcast $podcast, SimpleRSSElement $channel): void; public function setItemTag(Episode $episode, SimpleRSSElement $item): void; public function itemTag(Episode $episode, SimpleRSSElement $item): void; public function siteHead(): void; } Loading
app/Config/View.php +2 −1 Original line number Diff line number Diff line Loading @@ -4,6 +4,7 @@ declare(strict_types=1); namespace Config; use App\Views\Decorators\SiteHead; use CodeIgniter\Config\View as BaseView; use CodeIgniter\View\ViewDecoratorInterface; use ViewComponents\Decorator; Loading Loading @@ -53,5 +54,5 @@ class View extends BaseView * * @var list<class-string<ViewDecoratorInterface>> */ public array $decorators = [Decorator::class]; public array $decorators = [Decorator::class, SiteHead::class]; }
app/Helpers/rss_helper.php +2 −2 Original line number Diff line number Diff line Loading @@ -298,7 +298,7 @@ if (! function_exists('get_rss_feed')) { } // run plugins hook at the end $plugins->setChannelTag($podcast, $channel); $plugins->channelTag($podcast, $channel); foreach ($episodes as $episode) { if ($episode->is_premium && ! $subscription instanceof Subscription) { Loading Loading @@ -460,7 +460,7 @@ if (! function_exists('get_rss_feed')) { ], $item); } $plugins->setItemTag($episode, $item); $plugins->itemTag($episode, $item); } return $rss->asXML(); Loading
app/Views/Decorators/SiteHead.php 0 → 100644 +36 −0 Original line number Diff line number Diff line <?php declare(strict_types=1); namespace App\Views\Decorators; use CodeIgniter\View\ViewDecoratorInterface; class SiteHead implements ViewDecoratorInterface { private static int $renderedCount = 0; public static function decorate(string $html): string { if (url_is(config('Admin')->gateway . '*') || url_is(config('Install')->gateway)) { return $html; } if (static::$renderedCount > 0) { return $html; } ob_start(); // Start output buffering // run hook to add tags to <head> service('plugins')->siteHead(); $metaTags = ob_get_contents(); // Store buffer in variable ob_end_clean(); if (str_contains($html, '</head>')) { $html = str_replace('</head>', "\n\t{$metaTags}\n</head>", $html); ++static::$renderedCount; } return $html; } }
modules/Plugins/BasePlugin.php +6 −2 Original line number Diff line number Diff line Loading @@ -59,11 +59,15 @@ abstract class BasePlugin implements PluginInterface // TODO: setup navigation and views? } public function setChannelTag(Podcast $podcast, SimpleRSSElement $channel): void public function channelTag(Podcast $podcast, SimpleRSSElement $channel): void { } public function setItemTag(Episode $episode, SimpleRSSElement $item): void public function itemTag(Episode $episode, SimpleRSSElement $item): void { } public function siteHead(): void { } Loading
modules/Plugins/PluginInterface.php +4 −2 Original line number Diff line number Diff line Loading @@ -10,7 +10,9 @@ use App\Libraries\SimpleRSSElement; interface PluginInterface { public function setChannelTag(Podcast $podcast, SimpleRSSElement $channel): void; public function channelTag(Podcast $podcast, SimpleRSSElement $channel): void; public function setItemTag(Episode $episode, SimpleRSSElement $item): void; public function itemTag(Episode $episode, SimpleRSSElement $item): void; public function siteHead(): void; }