]> git.mxchange.org Git - friendica.git/blobdiff - src/Object/Post.php
Avoid warning " Undefined variable $browsershare"
[friendica.git] / src / Object / Post.php
index 827f1dc23809b55b1b618a1ebfff957367e36aa7..2cf02f8e2a1892ffd60fbedba5e03cb428407e4c 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
         *
@@ -135,8 +158,6 @@ class Post
         */
        public function getTemplateData(array $conv_responses, string $formSecurityToken, $thread_level = 1)
        {
-               $a = DI::app();
-
                $item = $this->getData();
                $edited = false;
                // If the time between "created" and "edited" differs we add
@@ -172,10 +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);
+               $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]);
@@ -211,7 +231,7 @@ class Post
 
                $origin = $item['origin'] || $item['parent-origin'];
 
-               if ($item['pinned']) {
+               if (!empty($item['featured'])) {
                        $pinned = DI::l10n()->t('Pinned item');
                }
 
@@ -229,7 +249,7 @@ class Post
                        ];
                }
 
-               if (!$item['self']) {
+               if (!$item['self'] && local_user()) {
                        $block = [
                                'blocking' => true,
                                'block'   => DI::l10n()->t('Block %s', $item['author-name']),
@@ -323,14 +343,14 @@ class Post
 
                                if ($conv->getProfileOwner() == local_user() && ($item['uid'] != 0)) {
                                        if ($origin) {
-                                               $ispinned = ($item['pinned'] ? 'pinned' : 'unpinned');
+                                               $ispinned = ($item['featured'] ? 'pinned' : 'unpinned');
 
                                                $pin = [
                                                        'do'        => DI::l10n()->t('Pin'),
                                                        'undo'      => DI::l10n()->t('Unpin'),
                                                        'toggle'    => DI::l10n()->t('Toggle pin status'),
-                                                       'classdo'   => $item['pinned'] ? 'hidden' : '',
-                                                       'classundo' => $item['pinned'] ? '' : 'hidden',
+                                                       'classdo'   => $item['featured'] ? 'hidden' : '',
+                                                       'classundo' => $item['featured'] ? '' : 'hidden',
                                                        'pinned'   => DI::l10n()->t('Pinned'),
                                                ];
                                        }
@@ -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')) {
@@ -416,12 +438,6 @@ class Post
                $direction = [];
                if (!empty($item['direction'])) {
                        $direction = $item['direction'];
-               } elseif (DI::config()->get('debug', 'show_direction')) {
-                       $conversation = DBA::selectFirst('conversation', ['direction'], ['item-uri' => $item['uri']]);
-                       if (!empty($conversation['direction']) && in_array($conversation['direction'], [1, 2])) {
-                               $direction_title = [1 => DI::l10n()->t('Pushed'), 2 => DI::l10n()->t('Pulled')];
-                               $direction = ['direction' => $conversation['direction'], 'title' => $direction_title[$conversation['direction']]];
-                       }
                }
 
                $languages = [];
@@ -429,6 +445,12 @@ class Post
                        $languages = [DI::l10n()->t('Languages'), Item::getLanguageMessage($item)];
                }
 
+               if (in_array($item['private'], [Item::PUBLIC, Item::UNLISTED]) && in_array($item['network'], Protocol::FEDERATED)) {
+                       $browsershare = [DI::l10n()->t('Share via ...'), DI::l10n()->t('Share via external services')];
+               } else {
+                       $browsershare = null;
+               }
+
                $tmp_item = [
                        'template'        => $this->getTemplate(),
                        'type'            => implode("", array_slice(explode("/", $item['verb']), -1)),
@@ -469,6 +491,9 @@ class Post
                        'app'             => $item['app'],
                        'created'         => $ago,
                        'lock'            => $lock,
+                       'private'         => $item['private'],
+                       'privacy'         => $privacy,
+                       'connector'       => $connector,
                        'location_html'   => $location_html,
                        'indent'          => $indent,
                        'shiny'           => $shiny,
@@ -477,6 +502,7 @@ class Post
                        'owner_photo'     => DI::baseUrl()->remove(Contact::getAvatarUrlForUrl($item['owner-link'], $item['uid'], Proxy::SIZE_THUMB)),
                        'owner_name'      => $this->getOwnerName(),
                        'plink'           => Item::getPlink($item),
+                       'browsershare'    => $browsershare,
                        'edpost'          => $edpost,
                        'ispinned'        => $ispinned,
                        'pin'             => $pin,
@@ -873,22 +899,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']) {