* @param string $text
* @param integer $simplehtml
* @param bool $tryoembed
+ * @param array $data
* @return string
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
- private static function convertAttachment($text, $simplehtml = self::INTERNAL, $tryoembed = true)
+ public static function convertAttachment($text, $simplehtml = self::INTERNAL, $tryoembed = true, array $data = [])
{
- $data = self::getAttachmentData($text);
+ $data = $data ?: self::getAttachmentData($text);
if (empty($data) || empty($data['url'])) {
return $text;
}
+ $stamp1 = microtime(true);
+
if (isset($data['title'])) {
$data['title'] = strip_tags($data['title']);
$data['title'] = str_replace(['http://', 'https://'], '', $data['title']);
}
if (!empty($data['description']) && $data['description'] != $data['title']) {
- // Sanitize the HTML by converting it to BBCode
- $bbcode = HTML::toBBCode($data['description']);
- $return .= sprintf('<blockquote>%s</blockquote>', trim(self::convert($bbcode)));
+ // Sanitize the HTML
+ $return .= sprintf('<blockquote>%s</blockquote>', trim(HTML::purify($data['description'])));
}
if (!empty($data['provider_url']) && !empty($data['provider_name'])) {
}
}
+ DI::profiler()->saveTimestamp($stamp1, 'rendering');
return trim(($data['text'] ?? '') . ' ' . $return . ' ' . ($data['after'] ?? ''));
}
*/
private static function addVisualAttachments(array $attachments, array $item, string $content, bool $shared)
{
+ $stamp1 = microtime(true);
$leading = '';
$trailing = '';
}
}
+ DI::profiler()->saveTimestamp($stamp1, 'rendering');
return $content;
}
*/
private static function addLinkAttachment(array $attachments, array $item, string $content, bool $shared, string $ignore_link)
{
+ $stamp1 = microtime(true);
// @ToDo Check only for audio and video
$preview = empty($attachments['visual']);
}
if (!empty($attachment)) {
+ $footer = '';
$data = [
- 'author_img' => $attachment['author-image'] ?? '',
- 'author_name' => $attachment['author-name'] ?? '',
- 'author_url' => $attachment['author-url'] ?? '',
- 'publisher_img' => $attachment['publisher-image'] ?? '',
- 'publisher_name' => $attachment['publisher-name'] ?? '',
- 'publisher_url' => $attachment['publisher-url'] ?? '',
- 'text' => $attachment['description'] ?? '',
- 'title' => $attachment['name'] ?? '',
- 'type' => 'link',
- 'url' => $attachment['url'] ?? '',
- ];
-
- if ($preview && !empty($attachment['preview']) && !empty($attachment['preview-height']) && !empty($attachment['preview-width'])) {
- $data['images'][] = ['src' => $attachment['preview'],
- 'width' => $attachment['preview-width'], 'height' => $attachment['preview-height']];
+ 'after' => '',
+ 'author_name' => $attachment['author-name'] ?? '',
+ 'author_url' => $attachment['author-url'] ?? '',
+ 'description' => $attachment['description'] ?? '',
+ 'image' => '',
+ 'preview' => '',
+ 'provider_name' => $attachment['publisher-name'] ?? '',
+ 'provider_url' => $attachment['publisher-url'] ?? '',
+ 'text' => '',
+ 'title' => $attachment['name'] ?? '',
+ 'type' => 'link',
+ 'url' => $attachment['url']];
+
+ if ($preview) {
+ if ($attachment['preview-width'] >= 500) {
+ $data['image'] = $attachment['preview'] ?? '';
+ } else {
+ $data['preview'] = $attachment['preview'] ?? '';
+ }
}
- $footer = PageInfo::getFooterFromData($data);
} elseif (preg_match("/.*(\[attachment.*?\].*?\[\/attachment\]).*/ism", $item['body'], $match)) {
$footer = $match[1];
+ $data = [];
}
+ DI::profiler()->saveTimestamp($stamp1, 'rendering');
- if (!empty($footer)) {
+ if (!empty($footer) || !empty($data)) {
// @todo Use a template
- $rendered = BBCode::convert($footer);
+ $rendered = BBCode::convertAttachment($footer, BBCode::INTERNAL, false, $data);
if ($shared) {
return str_replace(BBCode::ANCHOR, BBCode::ANCHOR . $rendered, $content);
} else {
*/
private static function addNonVisualAttachments(array $attachments, array $item, string $content)
{
+ $stamp1 = microtime(true);
$trailing = '';
foreach ($attachments['additional'] as $attachment) {
if (strpos($item['body'], $attachment['url'])) {
$content .= '<div class="body-attach">' . $trailing . '<div class="clear"></div></div>';
}
+ DI::profiler()->saveTimestamp($stamp1, 'rendering');
return $content;
}