]> git.mxchange.org Git - friendica.git/blobdiff - src/Object/Post.php
Merge pull request #8695 from annando/no-parent
[friendica.git] / src / Object / Post.php
index 73389d877c6ae76295451c4ffd7fa633188460ac..1ca02873d7f0d6b7a9144b53d5e46c98180c055c 100644 (file)
@@ -1,13 +1,29 @@
 <?php
 /**
- * @file src/Object/Post.php
+ * @copyright Copyright (C) 2020, Friendica
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ *
  */
+
 namespace Friendica\Object;
 
 use Friendica\Content\ContactSelector;
 use Friendica\Content\Feature;
 use Friendica\Core\Addon;
-use Friendica\Core\Config;
 use Friendica\Core\Hook;
 use Friendica\Core\Logger;
 use Friendica\Core\Protocol;
@@ -17,7 +33,7 @@ use Friendica\Database\DBA;
 use Friendica\DI;
 use Friendica\Model\Contact;
 use Friendica\Model\Item;
-use Friendica\Model\Term;
+use Friendica\Model\Tag;
 use Friendica\Model\User;
 use Friendica\Protocol\Activity;
 use Friendica\Util\Crypto;
@@ -135,7 +151,11 @@ class Post
                        ];
                }
                $sparkle = '';
-               $buttons = '';
+               $buttons = [
+                       'like'    => null,
+                       'dislike' => null,
+                       'share'   => null,
+               ];
                $dropping = false;
                $pinned = '';
                $pin = false;
@@ -150,12 +170,12 @@ class Post
 
                $conv = $this->getThread();
 
-               $lock = ((($item['private'] == 1) || (($item['uid'] == local_user()) && (strlen($item['allow_cid']) || strlen($item['allow_gid'])
+               $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);
 
-               $shareable = in_array($conv->getProfileOwner(), [0, local_user()]) && $item['private'] != 1;
+               $shareable = in_array($conv->getProfileOwner(), [0, local_user()]) && $item['private'] != Item::PRIVATE;
 
                $edpost = false;
 
@@ -194,7 +214,7 @@ class Post
                        $pinned = DI::l10n()->t('pinned item');
                }
 
-               if ($origin && ($item['id'] != $item['parent']) && ($item['network'] == Protocol::ACTIVITYPUB)) {
+               if ($origin && ($item['gravity'] != GRAVITY_PARENT) && ($item['network'] == Protocol::ACTIVITYPUB)) {
                        // ActivityPub doesn't allow removal of remote comments
                        $delete = DI::l10n()->t('Delete locally');
                } else {
@@ -252,10 +272,12 @@ class Post
                        }
                }
 
-               $responses = get_responses($conv_responses, $response_verbs, $item, $this);
-
-               foreach ($response_verbs as $value => $verbs) {
-                       $responses[$verbs]['output'] = !empty($conv_responses[$verbs][$item['uri']]) ? format_like($conv_responses[$verbs][$item['uri']], $conv_responses[$verbs][$item['uri'] . '-l'], $verbs, $item['uri']) : '';
+               $responses = [];
+               foreach ($response_verbs as $value => $verb) {
+                       $responses[$verb] = [
+                               'self'   => $conv_responses[$verb][$item['uri'] . '-self'] ?? 0,
+                               'output' => !empty($conv_responses[$verb][$item['uri']]) ? format_like($conv_responses[$verb][$item['uri']], $conv_responses[$verb][$item['uri'] . '-l'], $verb, $item['uri']) : '',
+                       ];
                }
 
                /*
@@ -321,10 +343,8 @@ class Post
                }
 
                if ($conv->isWritable()) {
-                       $buttons = [
-                               'like'    => [DI::l10n()->t("I like this \x28toggle\x29"), DI::l10n()->t("like")],
-                               'dislike' => [DI::l10n()->t("I don't like this \x28toggle\x29"), DI::l10n()->t("dislike")],
-                       ];
+                       $buttons['like']    = [DI::l10n()->t("I like this \x28toggle\x29")      , DI::l10n()->t("like")];
+                       $buttons['dislike'] = [DI::l10n()->t("I don't like this \x28toggle\x29"), DI::l10n()->t("dislike")];
                        if ($shareable) {
                                $buttons['share'] = [DI::l10n()->t('Share this'), DI::l10n()->t('share')];
                        }
@@ -355,33 +375,50 @@ class Post
                $location_e   = $location;
                $owner_name_e = $this->getOwnerName();
 
+               if (DI::pConfig()->get(local_user(), 'system', 'hide_dislike')) {
+                       $buttons['dislike'] = false;
+               }
+
                // Disable features that aren't available in several networks
-               if (!in_array($item["network"], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA]) && isset($buttons["dislike"])) {
-                       unset($buttons["dislike"]);
+               if ($buttons["dislike"] && !in_array($item["network"], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA])) {
+                       $buttons["dislike"] = false;
                        $isevent = false;
                        $tagger = '';
                }
 
-               if (($item["network"] == Protocol::FEED) && isset($buttons["like"])) {
-                       unset($buttons["like"]);
+               if ($buttons["like"] && in_array($item["network"], [Protocol::FEED, Protocol::MAIL])) {
+                       $buttons["like"] = false;
                }
 
-               if (($item["network"] == Protocol::MAIL) && isset($buttons["like"])) {
-                       unset($buttons["like"]);
-               }
-
-               $tags = Term::populateTagsFromItem($item);
+               $tags = Tag::populateFromItem($item);
 
                $ago = Temporal::getRelativeDate($item['created']);
                $ago_received = Temporal::getRelativeDate($item['received']);
-               if (Config::get('system', 'show_received') && (abs(strtotime($item['created']) - strtotime($item['received'])) > Config::get('system', 'show_received_seconds')) && ($ago != $ago_received)) {
+               if (DI::config()->get('system', 'show_received') && (abs(strtotime($item['created']) - strtotime($item['received'])) > DI::config()->get('system', 'show_received_seconds')) && ($ago != $ago_received)) {
                        $ago = DI::l10n()->t('%s (Received %s)', $ago, $ago_received);
                }
 
+               // Fetching of Diaspora posts doesn't always work. There are issues with reshares and possibly comments
+               if (($item['network'] != Protocol::DIASPORA) && empty($comment) && !empty(Session::get('remote_comment'))) {
+                       $remote_comment = [DI::l10n()->t('Comment this item on your system'), DI::l10n()->t('remote comment'),
+                               str_replace('{uri}', urlencode($item['uri']), Session::get('remote_comment'))];
+               } else {
+                       $remote_comment = '';
+               }
+
+               $direction = [];
+               if (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])) {
+                               $title = [1 => DI::l10n()->t('Pushed'), 2 => DI::l10n()->t('Pulled')];
+                               $direction = ['direction' => $conversation['direction'], 'title' => $title[$conversation['direction']]];
+                       }
+               }
+
                $tmp_item = [
                        'template'        => $this->getTemplate(),
                        'type'            => implode("", array_slice(explode("/", $item['verb']), -1)),
-                       'suppress_tags'   => Config::get('system', 'suppress_tags'),
+                       'suppress_tags'   => DI::config()->get('system', 'suppress_tags'),
                        'tags'            => $tags['tags'],
                        'hashtags'        => $tags['hashtags'],
                        'mentions'        => $tags['mentions'],
@@ -441,6 +478,8 @@ class Post
                        'switchcomment'   => DI::l10n()->t('Comment'),
                        'reply_label'     => DI::l10n()->t('Reply to %s', $name_e),
                        'comment'         => $comment,
+                       'remote_comment'  => $remote_comment,
+                       'menu'            => DI::l10n()->t('More'),
                        'previewing'      => $conv->isPreview() ? ' preview ' : '',
                        'wait'            => DI::l10n()->t('Please wait'),
                        'thread_level'    => $thread_level,
@@ -452,6 +491,7 @@ class Post
                        'commented'       => $item['commented'],
                        'created_date'    => $item['created'],
                        'return'          => (DI::args()->getCommand()) ? bin2hex(DI::args()->getCommand()) : '',
+                       'direction'       => $direction,
                        'delivery'        => [
                                'queue_count'       => $item['delivery_queue_count'],
                                'queue_done'        => $item['delivery_queue_done'] + $item['delivery_queue_failed'], /// @todo Possibly display it separately in the future
@@ -820,7 +860,7 @@ class Post
                        return '';
                }
 
-               $item = Item::selectFirst(['author-addr'], ['id' => $this->getId()]);
+               $item = Item::selectFirst(['author-addr', 'uri-id'], ['id' => $this->getId()]);
                if (!DBA::isResult($item) || empty($item['author-addr'])) {
                        // Should not happen
                        return '';
@@ -832,7 +872,7 @@ class Post
                        $text = '';
                }
 
-               $terms = Term::tagArrayFromItemId($this->getId(), [Term::MENTION, Term::IMPLICIT_MENTION]);
+               $terms = Tag::getByURIId($item['uri-id'], [Tag::MENTION, Tag::IMPLICIT_MENTION, Tag::EXCLUSIVE_MENTION]);
                foreach ($terms as $term) {
                        $profile = Contact::getDetailsByURL($term['url']);
                        if (!empty($profile['addr']) && ((($profile['contact-type'] ?? '') ?: Contact::TYPE_UNKNOWN) != Contact::TYPE_COMMUNITY) &&
@@ -902,6 +942,7 @@ class Post
                                '$myphoto'     => DI::baseUrl()->remove($a->contact['thumb']),
                                '$comment'     => DI::l10n()->t('Comment'),
                                '$submit'      => DI::l10n()->t('Submit'),
+                               '$loading'     => DI::l10n()->t('Loading...'),
                                '$edbold'      => DI::l10n()->t('Bold'),
                                '$editalic'    => DI::l10n()->t('Italic'),
                                '$eduline'     => DI::l10n()->t('Underline'),