From f8cf410f21bc193f4196cf88c3f63e7e7b4be6bf Mon Sep 17 00:00:00 2001 From: Weihao Jiang Date: Thu, 16 May 2024 01:51:07 +0800 Subject: [PATCH] Fix deprecation of mb_convert_encoding on HTML-ENTITIES https://stackoverflow.com/questions/8218230/php-domdocument-loadhtml-not-encoding-utf-8-correctly --- extension.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/extension.php b/extension.php index 3196c8b..8c6c7c5 100644 --- a/extension.php +++ b/extension.php @@ -97,6 +97,11 @@ public static function getCacheImageUri(string $url): string return FreshRSS_Context::userConf()->image_cache_url . $url; } + public static function small($string) +{ + return substr($string, 0, 20); +} + public static function cache_images(string $content): string { if (empty($content)) { @@ -104,7 +109,8 @@ public static function cache_images(string $content): string } $doc = new DOMDocument(); libxml_use_internal_errors(true); // prevent tag soup errors from showing - $doc->loadHTML(mb_convert_encoding($content, 'HTML-ENTITIES', 'UTF-8')); + $encoding = mb_detect_encoding($content); + $doc->loadHTML(''.$content); $imgs = $doc->getElementsByTagName('img'); foreach ($imgs as $img) { if ($img->hasAttribute('src')) { @@ -129,7 +135,8 @@ public static function swapUris(string $content): string } $doc = new DOMDocument(); libxml_use_internal_errors(true); // prevent tag soup errors from showing - $doc->loadHTML(mb_convert_encoding($content, 'HTML-ENTITIES', 'UTF-8')); + $encoding = mb_detect_encoding($content); + $doc->loadHTML(''.$content); $imgs = $doc->getElementsByTagName('img'); foreach ($imgs as $img) { if ($img->hasAttribute('src')) {