]> git.mxchange.org Git - friendica.git/commitdiff
Remove Text\BBCode::scaleExternalImage
authorHypolite Petovan <hypolite@mrpetovan.com>
Tue, 24 Jan 2023 01:40:20 +0000 (20:40 -0500)
committerHypolite Petovan <hypolite@mrpetovan.com>
Tue, 24 Jan 2023 01:40:20 +0000 (20:40 -0500)
- Image size is a CSS concern, not a PHP one

src/Content/Item.php
src/Content/Text/BBCode.php
src/Content/Text/Markdown.php

index 1bf3e68726eb4586fc18d05d3fbd6a3800d2a67b..87d719719bb6b7ae5576e495f4249e5f69dce99e 100644 (file)
@@ -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.
index e95ed0675983e48f238c6930f99c9f5db5faf1a3..c6fd7f8c5e05fc7845f9a4df8d9fb30de5c8f72d 100644 (file)
@@ -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
         *
index 5e4db77605f9ff7be6c06c2dbe9b847f62095cfa..33e023bc03662b9f55bbec4913a12b6506d6463a 100644 (file)
@@ -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;
        }