Remove <html>, <head>, <body> tags from header and footer scripts

This commit is contained in:
Kijin Sung 2023-06-20 17:03:34 +09:00
parent 0de42bebaf
commit be6cc58311
2 changed files with 22 additions and 2 deletions

View file

@ -14,6 +14,7 @@ use Rhymix\Framework\Storage;
use Rhymix\Framework\URL;
use Rhymix\Modules\Admin\Controllers\Base;
use Rhymix\Modules\Admin\Models\Icon as IconModel;
use Rhymix\Modules\Admin\Models\Utility as UtilityModel;
class Domains extends Base
{
@ -340,8 +341,8 @@ class Domains extends Base
$vars->meta_description = utf8_trim($vars->meta_description);
// Clean up the header and footer scripts.
$vars->html_header = utf8_trim($vars->html_header);
$vars->html_footer = utf8_trim($vars->html_footer);
$vars->html_header = UtilityModel::cleanHeaderAndFooterScripts($vars->html_header ?? '');
$vars->html_footer = UtilityModel::cleanHeaderAndFooterScripts($vars->html_footer ?? '');
// Validate the color scheme setting.
$valid_color_scheme_options = array('auto', 'light', 'dark');

View file

@ -0,0 +1,19 @@
<?php
namespace Rhymix\Modules\Admin\Models;
class Utility
{
/**
* Clean up header and footer scripts.
*
* @param string $content
* @return string
*/
public static function cleanHeaderAndFooterScripts(string $content)
{
$content = utf8_clean($content);
$content = preg_replace('!</?(html|head|body)[^>]*>!', '', $content);
return utf8_trim($content);
}
}