Merge pull request #7841 from annando/ap-link
AP: Remove the link description from the "rich html" and adds it to the attachment
This commit is contained in:
commit
3ba9aa0e8e
|
@ -385,6 +385,28 @@ class BBCode extends BaseObject
|
||||||
return $post;
|
return $post;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove [attachment] BBCode and replaces it with a regular [url]
|
||||||
|
*
|
||||||
|
* @param string $body
|
||||||
|
*
|
||||||
|
* @return string with replaced body
|
||||||
|
*/
|
||||||
|
public static function removeAttachment($body)
|
||||||
|
{
|
||||||
|
return preg_replace_callback("/\[attachment (.*)\](.*?)\[\/attachment\]/ism",
|
||||||
|
function ($match) {
|
||||||
|
$attach_data = self::getAttachmentData($match[0]);
|
||||||
|
if (empty($attach_data['url'])) {
|
||||||
|
return $match[0];
|
||||||
|
} elseif (empty($attach_data['title'])) {
|
||||||
|
return '[url]' . $attach_data['url'] . '[/url]';
|
||||||
|
} else {
|
||||||
|
return '[url=' . $attach_data['url'] . ']' . $attach_data['title'] . '[/url]';
|
||||||
|
}
|
||||||
|
}, $body);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Converts a BBCode text into plaintext
|
* @brief Converts a BBCode text into plaintext
|
||||||
*
|
*
|
||||||
|
|
|
@ -1020,6 +1020,34 @@ class Transmitter
|
||||||
{
|
{
|
||||||
$attachments = [];
|
$attachments = [];
|
||||||
|
|
||||||
|
$attach_data = BBCode::getAttachmentData($item['body']);
|
||||||
|
if (!empty($attach_data['url'])) {
|
||||||
|
$attachment = ['type' => 'Page',
|
||||||
|
'mediaType' => 'text/html',
|
||||||
|
'url' => $attach_data['url']];
|
||||||
|
|
||||||
|
if (!empty($attach_data['title'])) {
|
||||||
|
$attachment['name'] = $attach_data['title'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($attach_data['description'])) {
|
||||||
|
$attachment['summary'] = $attach_data['description'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($attach_data['image'])) {
|
||||||
|
$imgdata = Images::getInfoFromURLCached($attach_data['image']);
|
||||||
|
if ($imgdata) {
|
||||||
|
$attachment['icon'] = ['type' => 'Image',
|
||||||
|
'mediaType' => $imgdata['mime'],
|
||||||
|
'width' => $imgdata[0],
|
||||||
|
'height' => $imgdata[1],
|
||||||
|
'url' => $attach_data['image']];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$attachments[] = $attachment;
|
||||||
|
}
|
||||||
|
|
||||||
$arr = explode('[/attach],', $item['attach']);
|
$arr = explode('[/attach],', $item['attach']);
|
||||||
if (count($arr)) {
|
if (count($arr)) {
|
||||||
foreach ($arr as $r) {
|
foreach ($arr as $r) {
|
||||||
|
@ -1272,6 +1300,7 @@ class Transmitter
|
||||||
|
|
||||||
$regexp = "/[@!]\[url\=([^\[\]]*)\].*?\[\/url\]/ism";
|
$regexp = "/[@!]\[url\=([^\[\]]*)\].*?\[\/url\]/ism";
|
||||||
$richbody = preg_replace_callback($regexp, ['self', 'mentionCallback'], $item['body']);
|
$richbody = preg_replace_callback($regexp, ['self', 'mentionCallback'], $item['body']);
|
||||||
|
$richbody = BBCode::removeAttachment($richbody);
|
||||||
|
|
||||||
$data['contentMap']['text/html'] = BBCode::convert($richbody, false);
|
$data['contentMap']['text/html'] = BBCode::convert($richbody, false);
|
||||||
$data['contentMap']['text/markdown'] = BBCode::toMarkdown($item["body"]);
|
$data['contentMap']['text/markdown'] = BBCode::toMarkdown($item["body"]);
|
||||||
|
|
Loading…
Reference in a new issue