]> git.mxchange.org Git - friendica.git/blobdiff - src/Object/Post.php
show "parent unknown" when parent not federated
[friendica.git] / src / Object / Post.php
index 2f68b1c53e1e951e7ecdb6e72ca354d8d6fb894c..91500cb99f8b1f00cc0e86d81a3daece1c5f1d31 100644 (file)
@@ -31,16 +31,15 @@ use Friendica\Core\Renderer;
 use Friendica\DI;
 use Friendica\Model\Contact;
 use Friendica\Model\Item;
-use Friendica\Model\Photo;
 use Friendica\Model\Post as PostModel;
 use Friendica\Model\Tag;
 use Friendica\Model\User;
 use Friendica\Protocol\Activity;
 use Friendica\Util\Crypto;
 use Friendica\Util\DateTimeFormat;
-use Friendica\Util\Proxy;
 use Friendica\Util\Strings;
 use Friendica\Util\Temporal;
+use GuzzleHttp\Psr7\Uri;
 use InvalidArgumentException;
 
 /**
@@ -157,15 +156,16 @@ class Post
        /**
         * Get data in a form usable by a conversation template
         *
-        * @param array   $conv_responses conversation responses
-        * @param string $formSecurityToken A security Token to avoid CSF attacks
-        * @param integer $thread_level   default = 1
+        * @param array   $conv_responses    conversation responses
+        * @param string  $formSecurityToken A security Token to avoid CSF attacks
+        * @param integer $thread_level      default = 1
+        * @param array   $thread_parent     Array of parent guid and parent author names
         *
         * @return mixed The data requested on success, false on failure
         * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         * @throws \ImagickException
         */
-       public function getTemplateData(array $conv_responses, string $formSecurityToken, int $thread_level = 1)
+       public function getTemplateData(array $conv_responses, string $formSecurityToken, int $thread_level = 1, array $thread_parent = [])
        {
                $item = $this->getData();
                $edited = false;
@@ -248,38 +248,47 @@ class Post
                        $pinned = DI::l10n()->t('Pinned item');
                }
 
-               // Showing the one or the other text, depending upon if we can only hide it or really delete it.
-               $delete = $origin ? DI::l10n()->t('Delete globally') : DI::l10n()->t('Remove locally');
-
-               $drop     = false;
-               $block    = false;
-               $ignore   = false;
-               $collapse = false;
+               $drop         = false;
+               $block        = false;
+               $ignore       = false;
+               $collapse     = false;
+               $report       = false;
+               $ignoreServer = false;
                if (DI::userSession()->getLocalUserId()) {
                        $drop = [
                                'dropping' => $dropping,
                                'pagedrop' => $item['pagedrop'],
                                'select' => DI::l10n()->t('Select'),
-                               'delete' => $delete,
+                               'label' => $origin ? DI::l10n()->t('Delete globally') : DI::l10n()->t('Remove locally'),
                        ];
                }
 
                if (!$item['self'] && DI::userSession()->getLocalUserId()) {
                        $block = [
                                'blocking'  => true,
-                               'block'     => DI::l10n()->t('Block %s', $item['author-name']),
+                               'label'     => DI::l10n()->t('Block %s', $item['author-name']),
                                'author_id' => $item['author-id'],
                        ];
                        $ignore = [
                                'ignoring'  => true,
-                               'ignore'    => DI::l10n()->t('Ignore %s', $item['author-name']),
+                               'label'     => DI::l10n()->t('Ignore %s', $item['author-name']),
                                'author_id' => $item['author-id'],
                        ];
                        $collapse = [
                                'collapsing' => true,
-                               'collapse'   => DI::l10n()->t('Collapse %s', $item['author-name']),
+                               'label'      => DI::l10n()->t('Collapse %s', $item['author-name']),
                                'author_id'  => $item['author-id'],
                        ];
+                       $report = [
+                               'label' => DI::l10n()->t('Report post'),
+                               'href'  => 'moderation/report/create?' . http_build_query(['cid' => $item['author-id'], 'uri-ids' => [$item['uri-id']]]),
+                       ];
+                       $authorBaseUri = new Uri($item['author-baseurl'] ?? '');
+                       if ($authorBaseUri->getHost() && !DI::baseUrl()->isLocalUrl($authorBaseUri)) {
+                               $ignoreServer = [
+                                       'label' => DI::l10n()->t("Ignore %s server", $authorBaseUri->getHost()),
+                               ];
+                       }
                }
 
                $filer = DI::userSession()->getLocalUserId() ? DI::l10n()->t('Save to folder') : false;
@@ -488,7 +497,15 @@ class Post
                        $browsershare = null;
                }
 
+               $parent_guid     = $thread_parent[$item['thr-parent-id']]['guid'] ?? '';
+               $parent_username = $thread_parent[$item['thr-parent-id']]['name'] ?? '';
+               $parent_unknown  = $parent_username ? '' : DI::l10n()->t('parent unknown');
+
                $tmp_item = [
+                       'parentguid'      => $parent_guid,
+                       'isreplyto'       => DI::l10n()->t('is reply to %s', $parent_username),
+                       'isunknown'       => $parent_unknown,
+                       'isunknown_label' => DI::l10n()->t('parent is probably private or not federated'),
                        'template'        => $this->getTemplate(),
                        'type'            => implode('', array_slice(explode('/', $item['verb']), -1)),
                        'comment_firstcollapsed' => false,
@@ -554,6 +571,8 @@ class Post
                        'block'           => $block,
                        'ignore_author'   => $ignore,
                        'collapse'        => $collapse,
+                       'report'          => $report,
+                       'ignore_server'     => $ignoreServer,
                        'vote'            => $buttons,
                        'like_html'       => $responses['like']['output'],
                        'dislike_html'    => $responses['dislike']['output'],
@@ -568,6 +587,7 @@ class Post
                        'wait'            => DI::l10n()->t('Please wait'),
                        'thread_level'    => $thread_level,
                        'edited'          => $edited,
+                       'author_gsid'     => $item['author-gsid'],
                        'network'         => $item['network'],
                        'network_name'    => ContactSelector::networkToName($item['author-network'], $item['author-link'], $item['network'], $item['author-gsid']),
                        'network_icon'    => ContactSelector::networkToIcon($item['network'], $item['author-link'], $item['author-gsid']),
@@ -598,8 +618,10 @@ class Post
                $children = $this->getChildren();
                $nb_children = count($children);
                if ($nb_children > 0) {
+                       $thread_parent[$item['uri-id']] = ['guid' => $item['guid'], 'name' => $item['author-name']];
                        foreach ($children as $child) {
-                               $result['children'][] = $child->getTemplateData($conv_responses, $formSecurityToken, $thread_level + 1);
+                               $thread_parent[$child->getDataValue('uri-id')] = ['guid' => $child->getDataValue('guid'), 'name' => $child->getDataValue('author-name')];
+                               $result['children'][] = $child->getTemplateData($conv_responses, $formSecurityToken, $thread_level + 1, $thread_parent);
                        }
 
                        // Collapse
@@ -1086,6 +1108,7 @@ class Post
                                '$edbold'      => DI::l10n()->t('Bold'),
                                '$editalic'    => DI::l10n()->t('Italic'),
                                '$eduline'     => DI::l10n()->t('Underline'),
+                               '$contentwarn' => DI::l10n()->t('Content Warning'),
                                '$edquote'     => DI::l10n()->t('Quote'),
                                '$edemojis'    => DI::l10n()->t('Add emojis'),
                                '$edcode'      => DI::l10n()->t('Code'),