$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')) {
// 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.
}
}
- /**
- * 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
*