]> git.mxchange.org Git - friendica.git/blobdiff - src/Model/Item.php
Preview of attached links work again
[friendica.git] / src / Model / Item.php
index 33ba8ee7a4d1b849631bec1e245d17c4f91f8fc9..1eaa7cff2313d32a031319fb1834269880abe600 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * @copyright Copyright (C) 2010-2022, the Friendica project
+ * @copyright Copyright (C) 2010-2023, the Friendica project
  *
  * @license GNU AGPL version 3 or any later version
  *
@@ -33,6 +33,7 @@ use Friendica\Database\DBA;
 use Friendica\DI;
 use Friendica\Protocol\Activity;
 use Friendica\Protocol\ActivityPub;
+use Friendica\Protocol\Delivery;
 use Friendica\Protocol\Diaspora;
 use Friendica\Util\DateTimeFormat;
 use Friendica\Util\Map;
@@ -40,7 +41,6 @@ use Friendica\Util\Network;
 use Friendica\Util\Proxy;
 use Friendica\Util\Strings;
 use Friendica\Util\Temporal;
-use Friendica\Worker\Delivery;
 use GuzzleHttp\Psr7\Uri;
 use LanguageDetection\Language;
 
@@ -819,43 +819,14 @@ class Item
 
        private static function prepareOriginPost(array $item): array
        {
-               $item['wall'] = 1;
-               $item['origin'] = 1;
-               $item['network'] = Protocol::DFRN;
-               $item['protocol'] = Conversation::PARCEL_DIRECT;
-               $item['direction'] = Conversation::PUSH;
+               $item = DI::contentItem()->initializePost($item);
 
-               $owner = User::getOwnerDataById($item['uid']);
-
-               if (empty($item['contact-id'])) {
-                       $item['contact-id'] = $owner['id'];
-               }
-
-               if (empty($item['author-link']) && empty($item['author-id'])) {
-                       $item['author-link']   = $owner['url'];
-                       $item['author-name']   = $owner['name'];
-                       $item['author-avatar'] = $owner['thumb'];
+               if (Photo::setPermissionFromBody($item['body'], $item['uid'], $item['contact-id'], $item['allow_cid'], $item['allow_gid'], $item['deny_cid'], $item['deny_gid'])) {
+                       $item['object-type'] = Activity\ObjectType::IMAGE;
                }
 
-               if (empty($item['owner-link']) && empty($item['owner-id'])) {
-                       $item['owner-link']   = $item['author-link'];
-                       $item['owner-name']   = $item['author-name'];
-                       $item['owner-avatar'] = $item['author-avatar'];
-               }
-
-               // Setting the object type if not defined before
-               if (empty($item['object-type'])) {
-                       $item['object-type'] = Activity\ObjectType::NOTE; // Default value
-                       $objectdata = BBCode::getAttachedData($item['body']);
-
-                       if ($objectdata['type'] == 'link') {
-                               $item['object-type'] = Activity\ObjectType::BOOKMARK;
-                       } elseif ($objectdata['type'] == 'video') {
-                               $item['object-type'] = Activity\ObjectType::VIDEO;
-                       } elseif ($objectdata['type'] == 'photo') {
-                               $item['object-type'] = Activity\ObjectType::IMAGE;
-                       }
-               }
+               $item = DI::contentItem()->moveAttachmentsFromBodyToAttach($item);
+               $item = DI::contentItem()->finalizePost($item);
 
                return $item;
        }
@@ -1336,10 +1307,7 @@ class Item
                }
 
                if ($notify) {
-                       if (!\Friendica\Content\Feature::isEnabled($posted_item['uid'], 'explicit_mentions') && ($posted_item['gravity'] == self::GRAVITY_COMMENT)) {
-                               Tag::createImplicitMentions($posted_item['uri-id'], $posted_item['thr-parent-id']);
-                       }
-                       Hook::callAll('post_local_end', $posted_item);
+                       DI::contentItem()->postProcessPost($posted_item);
                } else {
                        Hook::callAll('post_remote_end', $posted_item);
                }
@@ -3017,10 +2985,14 @@ class Item
                $item['mentions'] = $tags['mentions'];
 
                if (!$is_preview) {
+                       $item['body'] = preg_replace("#\s*\[attachment .*?].*?\[/attachment]\s*#ism", "\n", $item['body']);
                        $item['body'] = Post\Media::removeFromEndOfBody($item['body'] ?? '');
                }
 
                $body = $item['body'];
+               if ($is_preview) {
+                       $item['body'] = preg_replace("#\s*\[attachment .*?].*?\[/attachment]\s*#ism", "\n", $item['body']);
+               }
 
                $fields = ['uri-id', 'uri', 'body', 'title', 'author-name', 'author-link', 'author-avatar', 'guid', 'created', 'plink', 'network', 'has-media', 'quote-uri-id', 'post-type'];
 
@@ -3030,6 +3002,7 @@ class Item
                $shared = DI::contentItem()->getSharedPost($item, $fields);
                if (!empty($shared['post'])) {
                        $shared_item  = $shared['post'];
+                       $shared_item['body'] = Post\Media::removeFromEndOfBody($shared_item['body']);
                        $quote_uri_id = $shared['post']['uri-id'];
                        $shared_links[] = strtolower($shared['post']['uri']);
                        $item['body'] = BBCode::removeSharedData($item['body']);
@@ -3064,8 +3037,6 @@ class Item
                $attachments = Post\Media::splitAttachments($item['uri-id'], $shared_links, $item['has-media'] ?? false);
                $item['body'] = self::replaceVisualAttachments($attachments, $item['body'] ?? '');
 
-               $item['body'] = preg_replace("/\s*\[attachment .*?\].*?\[\/attachment\]\s*/ism", "\n", $item['body']);
-
                self::putInCache($item);
                $item['body'] = $body;
                $s = $item["rendered-html"];
@@ -3165,7 +3136,7 @@ class Item
                        ],
                ]);
        }
-       
+
 
        /**
         * Check if the body contains a link
@@ -3448,13 +3419,15 @@ class Item
                                }
 
                                // @todo Use a template
-                               $preview_mode =  DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'preview_mode', BBCode::PREVIEW_LARGE);
+                               $preview_mode = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'preview_mode', BBCode::PREVIEW_LARGE);
                                if ($preview_mode != BBCode::PREVIEW_NONE) {
                                        $rendered = BBCode::convertAttachment('', BBCode::INTERNAL, false, $data, $uriid, $preview_mode);
+                               } else {
+                                       $rendered = '';
                                }
                        } elseif (!self::containsLink($content, $data['url'], Post\Media::HTML)) {
                                $rendered = Renderer::replaceMacros(Renderer::getMarkupTemplate('content/link.tpl'), [
-                                       '$url'  => $data['url'],
+                                       '$url'   => $data['url'],
                                        '$title' => $data['title'],
                                ]);
                        } else {