}
$item['body'] = $this->contentItem->addSharedPost($item);
+ $item['body'] = Post\Media::addHTMLAttachmentToBody($uriId, $item['body']);
if (!is_null($item['raw-body'])) {
$item['raw-body'] = $this->contentItem->addSharedPost($item, $item['raw-body']);
+ $item['raw-body'] = Post\Media::addHTMLLinkToBody($uriId, $item['raw-body']);
}
}
*/
private function createFromArray(array $item, int $uid, bool $include_entities): \Friendica\Object\Api\Twitter\Status
{
+ $item = Post\Media::addHTMLAttachmentToItem($item);
$author = $this->twitterUser->createFromContactId($item['author-id'], $uid, true);
if (!empty($item['causer-id']) && ($item['post-reason'] == Item::PR_ANNOUNCEMENT)) {
namespace Friendica\Model\Post;
+use Friendica\Content\PageInfo;
use Friendica\Content\Text\BBCode;
use Friendica\Core\Logger;
use Friendica\Core\Protocol;
return $body;
}
+ public static function addHTMLAttachmentToBody(int $uriid, string $body): string
+ {
+ if (preg_match("/.*(\[attachment.*?\].*?\[\/attachment\]).*/ism", $body, $match)) {
+ return $body;
+ }
+
+ $links = self::getByURIId($uriid, [self::HTML]);
+ if (empty($links)) {
+ return $body;
+ }
+
+ $data = [
+ 'type' => 'link',
+ 'url' => $links[0]['url'],
+ 'title' => $links[0]['name'],
+ 'text' => $links[0]['description'],
+ 'alternative_title' => '',
+ 'publisher_name' => $links[0]['publisher-name'],
+ 'publisher_url' => $links[0]['publisher-url'],
+ 'publisher_img' => $links[0]['publisher-image'],
+ 'author_name' => $links[0]['author-name'],
+ 'author_url' => $links[0]['author-url'],
+ 'author_img' => $links[0]['author-image'],
+ 'images' => [[
+ 'src' => $links[0]['preview'],
+ 'height' => $links[0]['preview-height'],
+ 'width' => $links[0]['preview-width'],
+ ]]
+ ];
+ $body .= "\n" . PageInfo::getFooterFromData($data);
+
+ return $body;
+ }
+
+ public static function addHTMLLinkToBody(int $uriid, string $body): string
+ {
+ $links = self::getByURIId($uriid, [self::HTML]);
+ if (empty($links)) {
+ return $body;
+ }
+
+ if (strpos($body, $links[0]['url'])) {
+ return $body;
+ }
+
+ if (!empty($links[0]['name']) && ($links[0]['name'] != $links[0]['url'])) {
+ return $body . "\n[url=" . $links[0]['url'] . ']' . $links[0]['name'] . "[/url]";
+ } else {
+ return $body . "\n[url]" . $links[0]['url'] . "[/url]";
+ }
+ }
+
+ public static function addHTMLAttachmentToItem(array $item): array
+ {
+ if (($item['gravity'] == Item::GRAVITY_ACTIVITY) || empty($item['uri-id'])) {
+ return $item;
+ }
+
+ $item['body'] = self::addHTMLAttachmentToBody($item['uri-id'], $item['body']);
+
+ if (!empty($item['raw-body'])) {
+ $item['raw-body'] = self::addHTMLLinkToBody($item['uri-id'], $item['raw-body']);
+ }
+
+ return $item;
+ }
+
/**
* Get preview link for given media id
*
}
$item['body'] = Post\Media::addAttachmentsToBody($item['uri-id'], $item['body']);
+ $item = Post\Media::addHTMLAttachmentToItem($item);
$jotplugins = '';
$real_quote = false;
+ $item = Post\Media::addHTMLAttachmentToItem($item);
+
$body = $item['body'];
if ($type == 'Note') {
}
$body = Post\Media::addAttachmentsToBody($item['uri-id'], DI::contentItem()->addSharedPost($item));
+ $body = Post\Media::addHTMLAttachmentToBody($item['uri-id'], $body);
if ($item['private'] == Item::PRIVATE) {
$body = Item::fixPrivatePhotos($body, $owner['uid'], $item, $cid);
$title = $item['title'];
$body = Post\Media::addAttachmentsToBody($item['uri-id'], DI::contentItem()->addSharedPost($item), $attach_media);
+ $body = Post\Media::addHTMLLinkToBody($item['uri-id'], $body);
// Fetch the title from an attached link - if there is one
if (empty($item['title']) && DI::pConfig()->get($owner['uid'], 'system', 'attach_link_title')) {
}
$body = Post\Media::addAttachmentsToBody($item['uri-id'], DI::contentItem()->addSharedPost($item));
+ $body = Post\Media::addHTMLLinkToBody($item['uri-id'], $body);
// The replied to autor mention is prepended for clarity if:
// - Item replied isn't yours
XML::addElement($doc, $entry, 'title', html_entity_decode($title, ENT_QUOTES, 'UTF-8'));
$body = Post\Media::addAttachmentsToBody($item['uri-id'], DI::contentItem()->addSharedPost($item));
+ $body = Post\Media::addHTMLAttachmentToBody($item['uri-id'], $body);
$body = BBCode::convertForUriId($item['uri-id'], $body, BBCode::ACTIVITYPUB);
XML::addElement($doc, $entry, 'title', html_entity_decode($title, ENT_QUOTES, 'UTF-8'));
$body = Post\Media::addAttachmentsToBody($item['uri-id'], DI::contentItem()->addSharedPost($item));
+ $body = Post\Media::addHTMLAttachmentToBody($item['uri-id'], $body);
if (!empty($item['title'])) {
$body = '[b]' . $item['title'] . "[/b]\n\n" . $body;
// find ancestors
$condition = ['id' => $target_id, 'visible' => true];
$target_item = Post::selectFirst(Item::DELIVER_FIELDLIST, $condition);
+ $target_item = Post\Media::addHTMLAttachmentToItem($target_item);
if (!DBA::isResult($target_item) || !intval($target_item['parent'])) {
Logger::info('No target item', ['cmd' => $cmd, 'target' => $target_id]);