mirror of
https://code.castopod.org/adaures/castopod
synced 2025-05-11 08:45:45 +00:00
37 lines
903 B
PHP
37 lines
903 B
PHP
![]() |
<?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;
|
||
|
}
|
||
|
}
|