From b4cbe4250ed56e043fdf2f63df6ceeef4167d8f2 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Mon, 23 Jan 2023 20:40:20 -0500 Subject: [PATCH] Remove Text\BBCode::scaleExternalImage - Image size is a CSS concern, not a PHP one --- src/Content/Item.php | 3 +- src/Content/Text/BBCode.php | 66 ----------------------------------- src/Content/Text/Markdown.php | 3 -- 3 files changed, 1 insertion(+), 71 deletions(-) diff --git a/src/Content/Item.php b/src/Content/Item.php index 1bf3e68726..87d719719b 100644 --- a/src/Content/Item.php +++ b/src/Content/Item.php @@ -972,7 +972,7 @@ class Item $post['deny_cid'] = $owner['deny_cid']; $post['deny_gid'] = $owner['deny_gid']; } - + if ($post['allow_gid'] || $post['allow_cid'] || $post['deny_gid'] || $post['deny_cid']) { $post['private'] = ItemModel::PRIVATE; } elseif ($this->pConfig->get($post['uid'], 'system', 'unlisted')) { @@ -1011,7 +1011,6 @@ class Item // Convert links with empty descriptions to links without an explicit description $post['body'] = trim(preg_replace('#\[url=([^\]]*?)\]\[/url\]#ism', '[url]$1[/url]', $post['body'])); $post['body'] = $this->bbCodeVideo->transform($post['body']); - $post['body'] = BBCode::scaleExternalImages($post['body']); $post = $this->setObjectType($post); // Personal notes must never be altered to a forum post. diff --git a/src/Content/Text/BBCode.php b/src/Content/Text/BBCode.php index e95ed06759..c6fd7f8c5e 100644 --- a/src/Content/Text/BBCode.php +++ b/src/Content/Text/BBCode.php @@ -489,72 +489,6 @@ class BBCode } } - /** - * This function changing the visual size (not the real size) of images. - * The function does not work for pictures with an alternate text description. - * This could only be changed by using some new "img" BBCode format. - * - * @param string $srctext The body with images - * @return string The body with possibly scaled images - */ - public static function scaleExternalImages(string $srctext): string - { - DI::profiler()->startRecording('rendering'); - $s = $srctext; - - // Simplify image links - $s = preg_replace("/\[img\=([0-9]*)x([0-9]*)\](.*?)\[\/img\]/ism", '[img]$3[/img]', $s); - - $matches = null; - $c = preg_match_all('/\[img.*?\](.*?)\[\/img\]/ism', $s, $matches, PREG_SET_ORDER); - if ($c) { - foreach ($matches as $mtch) { - Logger::debug('scale_external_image', ['image' => $mtch[1]]); - - $hostname = str_replace('www.', '', substr(DI::baseUrl(), strpos(DI::baseUrl(), '://') + 3)); - if (stristr($mtch[1], $hostname)) { - continue; - } - - $curlResult = DI::httpClient()->get($mtch[1], HttpClientAccept::IMAGE); - if (!$curlResult->isSuccess()) { - continue; - } - - Logger::debug('Got picture', ['Content-Type' => $curlResult->getHeader('Content-Type'), 'url' => $mtch[1]]); - - $i = $curlResult->getBody(); - $type = $curlResult->getContentType(); - $type = Images::getMimeTypeByData($i, $mtch[1], $type); - - if ($i) { - $Image = new Image($i, $type); - if ($Image->isValid()) { - $orig_width = $Image->getWidth(); - $orig_height = $Image->getHeight(); - - if ($orig_width > 640 || $orig_height > 640) { - $Image->scaleDown(640); - $new_width = $Image->getWidth(); - $new_height = $Image->getHeight(); - Logger::debug('External images scaled', ['orig_width' => $orig_width, 'new_width' => $new_width, 'orig_height' => $orig_height, 'new_height' => $new_height, 'match' => $mtch[0]]); - $s = str_replace( - $mtch[0], - '[img=' . $new_width . 'x' . $new_height. ']' . $mtch[1] . '[/img]' - . "\n", - $s - ); - Logger::debug('New string', ['image' => $s]); - } - } - } - } - } - - DI::profiler()->stopRecording(); - return $s; - } - /** * Truncates imported message body string length to max_import_size * diff --git a/src/Content/Text/Markdown.php b/src/Content/Text/Markdown.php index 5e4db77605..33e023bc03 100644 --- a/src/Content/Text/Markdown.php +++ b/src/Content/Text/Markdown.php @@ -145,9 +145,6 @@ class Markdown // remove duplicate adjacent code tags $s = preg_replace('/(\[code\])+(.*?)(\[\/code\])+/ism', '[code]$2[/code]', $s); - // Don't show link to full picture (until it is fixed) - $s = BBCode::scaleExternalImages($s); - DI::profiler()->stopRecording(); return $s; } -- 2.39.5