Remove Text\BBCode::scaleExternalImage
- Image size is a CSS concern, not a PHP one
This commit is contained in:
parent
23e0ce3c1b
commit
b4cbe4250e
3 changed files with 1 additions and 71 deletions
|
@ -972,7 +972,7 @@ class Item
|
||||||
$post['deny_cid'] = $owner['deny_cid'];
|
$post['deny_cid'] = $owner['deny_cid'];
|
||||||
$post['deny_gid'] = $owner['deny_gid'];
|
$post['deny_gid'] = $owner['deny_gid'];
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($post['allow_gid'] || $post['allow_cid'] || $post['deny_gid'] || $post['deny_cid']) {
|
if ($post['allow_gid'] || $post['allow_cid'] || $post['deny_gid'] || $post['deny_cid']) {
|
||||||
$post['private'] = ItemModel::PRIVATE;
|
$post['private'] = ItemModel::PRIVATE;
|
||||||
} elseif ($this->pConfig->get($post['uid'], 'system', 'unlisted')) {
|
} 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
|
// 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'] = trim(preg_replace('#\[url=([^\]]*?)\]\[/url\]#ism', '[url]$1[/url]', $post['body']));
|
||||||
$post['body'] = $this->bbCodeVideo->transform($post['body']);
|
$post['body'] = $this->bbCodeVideo->transform($post['body']);
|
||||||
$post['body'] = BBCode::scaleExternalImages($post['body']);
|
|
||||||
$post = $this->setObjectType($post);
|
$post = $this->setObjectType($post);
|
||||||
|
|
||||||
// Personal notes must never be altered to a forum 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
|
* Truncates imported message body string length to max_import_size
|
||||||
*
|
*
|
||||||
|
|
|
@ -145,9 +145,6 @@ class Markdown
|
||||||
// remove duplicate adjacent code tags
|
// remove duplicate adjacent code tags
|
||||||
$s = preg_replace('/(\[code\])+(.*?)(\[\/code\])+/ism', '[code]$2[/code]', $s);
|
$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();
|
DI::profiler()->stopRecording();
|
||||||
return $s;
|
return $s;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue