]> git.mxchange.org Git - friendica.git/blobdiff - src/Object/Post.php
Merge pull request #11369 from annando/empty-item
[friendica.git] / src / Object / Post.php
index 17303bd62d7540abd84de44e875fbf9da7d4380c..4e0d8d238923d37b77d0cf1e2dab14191d441060 100644 (file)
@@ -121,6 +121,29 @@ class Post
                }
        }
 
+       /**
+        * Fetch the privacy of the post
+        *
+        * @param array $item 
+        * @return string 
+        */
+       private function fetchPrivacy(array $item):string
+       {
+               switch ($item['private']) {
+                       case Item::PRIVATE:
+                               $output = DI::l10n()->t('Private Message');
+                               break;
+                       case Item::PUBLIC:
+                               $output = DI::l10n()->t('Public Message');
+                               break;
+                       case Item::UNLISTED:
+                               $output = DI::l10n()->t('Unlisted Message');
+                               break;
+               }
+
+               return $output;
+       }
+
        /**
         * Get data in a form usable by a conversation template
         *
@@ -170,12 +193,9 @@ class Post
 
                $conv = $this->getThread();
 
-               $lock = ((($item['private'] == Item::PRIVATE) || (($item['uid'] == local_user()) && (strlen($item['allow_cid']) || strlen($item['allow_gid'])
-                       || strlen($item['deny_cid']) || strlen($item['deny_gid']))))
-                       ? DI::l10n()->t('Private Message')
-                       : false);
-
-               $connector = !$item['global'] ? DI::l10n()->t('Connector Message') : false;
+               $privacy   = $this->fetchPrivacy($item);
+               $lock      = ($item['private'] == Item::PRIVATE) ? $privacy : false;
+               $connector = !in_array($item['network'], Protocol::NATIVE_SUPPORT) ? DI::l10n()->t('Connector Message') : false;
 
                $shareable = in_array($conv->getProfileOwner(), [0, local_user()]) && $item['private'] != Item::PRIVATE;
                $announceable = $shareable && in_array($item['network'], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::TWITTER]);
@@ -369,10 +389,12 @@ class Post
 
                list($categories, $folders) = DI::contentItem()->determineCategoriesTerms($item, local_user());
 
-               if (!empty($item['content-warning']) && DI::pConfig()->get(local_user(), 'system', 'disable_cw', false)) {
+               if (!empty($item['title'])) {
+                       $title = $item['title'];
+               } elseif (!empty($item['content-warning']) && DI::pConfig()->get(local_user(), 'system', 'disable_cw', false)) {
                        $title = ucfirst($item['content-warning']);
                } else {
-                       $title = $item['title'];
+                       $title = '';
                }
 
                if (DI::pConfig()->get(local_user(), 'system', 'hide_dislike')) {
@@ -463,6 +485,8 @@ class Post
                        'app'             => $item['app'],
                        'created'         => $ago,
                        'lock'            => $lock,
+                       'private'         => $item['private'],
+                       'privacy'         => $privacy,
                        'connector'       => $connector,
                        'location_html'   => $location_html,
                        'indent'          => $indent,
@@ -869,22 +893,26 @@ class Post
 
                $owner = User::getOwnerDataById($a->getLoggedInUserId());
 
-               if (!Feature::isEnabled(local_user(), 'explicit_mentions')) {
-                       return '';
-               }
-
-               $item = PostModel::selectFirst(['author-addr', 'uri-id', 'network', 'gravity'], ['id' => $this->getId()]);
+               $item = PostModel::selectFirst(['author-addr', 'uri-id', 'network', 'gravity', 'content-warning'], ['id' => $this->getId()]);
                if (!DBA::isResult($item) || empty($item['author-addr'])) {
                        // Should not happen
                        return '';
                }
 
-               if (($item['author-addr'] != $owner['addr']) && (($item['gravity'] != GRAVITY_PARENT) || !in_array($item['network'], [Protocol::DIASPORA]))) {
-                       $text = '@' . $item['author-addr'] . ' ';
+               if (!empty($item['content-warning']) && Feature::isEnabled(local_user(), 'add_abstract')) {
+                       $text = '[abstract=' . Protocol::ACTIVITYPUB . ']' . $item['content-warning'] . "[/abstract]\n";
                } else {
                        $text = '';
                }
 
+               if (!Feature::isEnabled(local_user(), 'explicit_mentions')) {
+                       return $text;
+               }
+
+               if (($item['author-addr'] != $owner['addr']) && (($item['gravity'] != GRAVITY_PARENT) || !in_array($item['network'], [Protocol::DIASPORA]))) {
+                       $text .= '@' . $item['author-addr'] . ' ';
+               }
+
                $terms = Tag::getByURIId($item['uri-id'], [Tag::MENTION, Tag::IMPLICIT_MENTION, Tag::EXCLUSIVE_MENTION]);
                foreach ($terms as $term) {
                        if (!$term['url']) {