X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FContent%2FText%2FBBCode.php;h=83056b2692eb07d37d338b6725b34876818d41d4;hb=ba4860b7879f0dc6ea7a2dd0d09e698a913a9129;hp=2070d22d131d534b43f3040e6b6683f50f8d3ea1;hpb=44b2b97e80624aca5768511def80a95f0e6e0381;p=friendica.git diff --git a/src/Content/Text/BBCode.php b/src/Content/Text/BBCode.php index 2070d22d13..83056b2692 100644 --- a/src/Content/Text/BBCode.php +++ b/src/Content/Text/BBCode.php @@ -1,6 +1,6 @@ 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 * @@ -1415,8 +1349,8 @@ class BBCode public static function cleanPictureLinks(string $text): string { DI::profiler()->startRecording('rendering'); - $return = preg_replace_callback("&\[url=([^\[\]]*)\]\[img=(.*)\](.*)\[\/img\]\[\/url\]&Usi", 'self::cleanPictureLinksCallback', $text); - $return = preg_replace_callback("&\[url=([^\[\]]*)\]\[img\](.*)\[\/img\]\[\/url\]&Usi", 'self::cleanPictureLinksCallback', $return); + $return = preg_replace_callback("&\[url=([^\[\]]*)\]\[img=(.*)\](.*)\[\/img\]\[\/url\]&Usi", [self::class, 'cleanPictureLinksCallback'], $text); + $return = preg_replace_callback("&\[url=([^\[\]]*)\]\[img\](.*)\[\/img\]\[\/url\]&Usi", [self::class, 'cleanPictureLinksCallback'], $return); DI::profiler()->stopRecording(); return $return; } @@ -1450,7 +1384,7 @@ class BBCode { DI::profiler()->startRecording('rendering'); $regexp = "/([@!])\[url\=([^\[\]]*)\].*?\[\/url\]/ism"; - $body = preg_replace_callback($regexp, ['self', 'mentionCallback'], $body); + $body = preg_replace_callback($regexp, [self::class, 'mentionCallback'], $body); DI::profiler()->stopRecording(); return $body; } @@ -2002,12 +1936,12 @@ class BBCode if (!$for_plaintext) { if (in_array($simple_html, [self::OSTATUS, self::MASTODON_API, self::TWITTER_API, self::ACTIVITYPUB])) { - $text = preg_replace_callback("/\[url\](.*?)\[\/url\]/ism", 'self::convertUrlForActivityPubCallback', $text); - $text = preg_replace_callback("/\[url\=(.*?)\](.*?)\[\/url\]/ism", 'self::convertUrlForActivityPubCallback', $text); + $text = preg_replace_callback("/\[url\](.*?)\[\/url\]/ism", [self::class, 'convertUrlForActivityPubCallback'], $text); + $text = preg_replace_callback("/\[url\=(.*?)\](.*?)\[\/url\]/ism", [self::class, 'convertUrlForActivityPubCallback'], $text); } } else { $text = preg_replace("(\[url\](.*?)\[\/url\])ism", " $1 ", $text); - $text = preg_replace_callback("&\[url=([^\[\]]*)\]\[img\](.*)\[\/img\]\[\/url\]&Usi", 'self::removePictureLinksCallback', $text); + $text = preg_replace_callback("&\[url=([^\[\]]*)\]\[img\](.*)\[\/img\]\[\/url\]&Usi", [self::class, 'removePictureLinksCallback'], $text); } // Bookmarks in red - will be converted to bookmarks in friendica @@ -2017,7 +1951,7 @@ class BBCode "[bookmark=$1]$2[/bookmark]", $text); if (in_array($simple_html, [self::OSTATUS, self::TWITTER])) { - $text = preg_replace_callback("/([^#@!])\[url\=([^\]]*)\](.*?)\[\/url\]/ism", "self::expandLinksCallback", $text); + $text = preg_replace_callback("/([^#@!])\[url\=([^\]]*)\](.*?)\[\/url\]/ism", [self::class, 'expandLinksCallback'], $text); //$text = preg_replace("/[^#@!]\[url\=([^\]]*)\](.*?)\[\/url\]/ism", ' $2 [url]$1[/url]', $text); $text = preg_replace("/\[bookmark\=([^\]]*)\](.*?)\[\/bookmark\]/ism", ' $2 [url]$1[/url]', $text); } @@ -2327,7 +2261,7 @@ class BBCode $url_search_string = "^\[\]"; $text = preg_replace_callback( "/([@!])\[(.*?)\]\(([$url_search_string]*?)\)/ism", - ['self', 'bbCodeMention2DiasporaCallback'], + [self::class, 'bbCodeMention2DiasporaCallback'], $text ); }