mirror of
https://github.com/friendica/friendica
synced 2024-12-23 04:40:15 +00:00
Merge pull request #12726 from MrPetovan/bug/12721-missing-host
Remove Text\BBCode::scaleExternalImage
This commit is contained in:
commit
a86fbe37c9
3 changed files with 1 additions and 71 deletions
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
*
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue