Skip to content

Commit

Permalink
Fix deprecation of mb_convert_encoding on HTML-ENTITIES
Browse files Browse the repository at this point in the history
  • Loading branch information
Victrid committed May 15, 2024
1 parent d473c71 commit f8cf410
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions extension.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,20 @@ 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)) {
return $content;
}
$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('<!DOCTYPE html><meta charset="'.$encoding.'">'.$content);
$imgs = $doc->getElementsByTagName('img');
foreach ($imgs as $img) {
if ($img->hasAttribute('src')) {
Expand All @@ -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('<!DOCTYPE html><meta charset="'.$encoding.'">'.$content);
$imgs = $doc->getElementsByTagName('img');
foreach ($imgs as $img) {
if ($img->hasAttribute('src')) {
Expand Down

0 comments on commit f8cf410

Please sign in to comment.