]> git.mxchange.org Git - friendica.git/blobdiff - src/Module/PermissionTooltip.php
Remove the activity
[friendica.git] / src / Module / PermissionTooltip.php
index 1f6b58e4aa5503638e060f900ce51a411ba34668..c1ef4c2b4b794a5286cbd9d22ece63f98314d54e 100644 (file)
@@ -1,21 +1,45 @@
 <?php
+/**
+ * @copyright Copyright (C) 2010-2022, the Friendica project
+ *
+ * @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\Module;
 
 use Friendica\Core\Hook;
+use Friendica\Core\System;
 use Friendica\Database\DBA;
 use Friendica\DI;
+use Friendica\Model\APContact;
 use Friendica\Model\Group;
 use Friendica\Model\Item;
 use Friendica\Model\Post;
+use Friendica\Model\Tag;
+use Friendica\Model\User;
 use Friendica\Network\HTTPException;
+use Friendica\Protocol\ActivityPub;
 
 /**
  * Outputs the permission tooltip HTML content for the provided item, photo or event id.
  */
 class PermissionTooltip extends \Friendica\BaseModule
 {
-       public function rawContent()
+       protected function rawContent(array $request = [])
        {
                $type = $this->parameters['type'];
                $referenceId = $this->parameters['id'];
@@ -25,9 +49,9 @@ class PermissionTooltip extends \Friendica\BaseModule
                        throw new HTTPException\BadRequestException(DI::l10n()->t('Wrong type "%s", expected one of: %s', $type, implode(', ', $expectedTypes)));
                }
 
-               $condition = ['id' => $referenceId];
+               $condition = ['id' => $referenceId, 'uid' => [0, DI::userSession()->getLocalUserId()]];
                if ($type == 'item') {
-                       $fields = ['uid', 'psid', 'private'];
+                       $fields = ['uid', 'psid', 'private', 'uri-id'];
                        $model = Post::selectFirst($fields, $condition);
                } else {
                        $fields = ['uid', 'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid'];
@@ -53,13 +77,32 @@ class PermissionTooltip extends \Friendica\BaseModule
                // Kept for backwards compatiblity
                Hook::callAll('lockview_content', $model);
 
-               if ($model['uid'] != local_user() ||
-                       isset($model['private'])
-                       && $model['private'] == Item::PRIVATE
-                       && empty($model['allow_cid'])
+               if ($type == 'item') {
+                       $receivers = $this->fetchReceivers($model['uri-id']);
+                       if (empty($receivers)) {
+                               switch ($model['private']) {
+                                       case Item::PUBLIC:
+                                               $receivers = DI::l10n()->t('Public');
+                                               break;
+
+                                       case Item::UNLISTED:
+                                               $receivers = DI::l10n()->t('Unlisted');
+                                               break;
+
+                                       case Item::PRIVATE:
+                                               $receivers = DI::l10n()->t('Limited/Private');
+                                               break;
+                               }
+                       }
+               } else {
+                       $receivers = '';
+               }
+
+               if (empty($model['allow_cid'])
                        && empty($model['allow_gid'])
                        && empty($model['deny_cid'])
-                       && empty($model['deny_gid']))
+                       && empty($model['deny_gid'])
+                       && empty($receivers))
                {
                        echo DI::l10n()->t('Remote privacy information not available.');
                        exit;
@@ -117,7 +160,81 @@ class PermissionTooltip extends \Friendica\BaseModule
                        $l[] = '<strike>' . $contact['name'] . '</strike>';
                }
 
-               echo $o . implode(', ', $l);
-               exit();
+               if (!empty($l)) {
+                       echo $o . implode(', ', $l);
+               } else {
+                       echo $o . $receivers;
+               }
+               System::exit();
+       }
+
+       /**
+        * Fetch a list of receivers
+        *
+        * @param int $uriId
+        * @return string
+        */
+       private function fetchReceivers(int $uriId): string
+       {
+               $own_url = '';
+               $uid = DI::userSession()->getLocalUserId();
+               if ($uid) {
+                       $owner = User::getOwnerDataById($uid);
+                       if (!empty($owner['url'])) {
+                               $own_url = $owner['url'];
+                       }
+               }
+
+               $receivers = [];
+               foreach (Tag::getByURIId($uriId, [Tag::TO, Tag::CC, Tag::BCC]) as $receiver) {
+                       // We only display BCC when it contains the current user
+                       if (($receiver['type'] == Tag::BCC) && ($receiver['url'] != $own_url)) {
+                               continue;
+                       }
+
+                       switch (Tag::getTargetType($receiver['url'], false)) {
+                               case Tag::PUBLIC_COLLECTION:
+                                       $receivers[$receiver['type']][] = DI::l10n()->t('Public');
+                                       break;
+                               case Tag::GENERAL_COLLECTION:
+                                       $receivers[$receiver['type']][] = DI::l10n()->t('Collection (%s)', $receiver['name']);
+                                       break;
+                               case Tag::FOLLOWER_COLLECTION:
+                                       $apcontact = DBA::selectFirst('apcontact', ['name'], ['followers' => $receiver['url']]);
+                                       $receivers[$receiver['type']][] = DI::l10n()->t('Followers (%s)', $apcontact['name'] ?? $receiver['name']);
+                                       break;
+                               case Tag::ACCOUNT:
+                                       $apcontact = APContact::getByURL($receiver['url'], false);
+                                       $receivers[$receiver['type']][] = $apcontact['name'] ?? $receiver['name'];
+                                       break;
+                               default:
+                                       $receivers[$receiver['type']][] = $receiver['name'];
+                                       break;
+                       }
+               }
+
+               $output = '';
+
+               foreach ($receivers as $type => $receiver) {
+                       $max = DI::config()->get('system', 'max_receivers');
+                       $total = count($receiver);
+                       if ($total > $max) {
+                               $receiver = array_slice($receiver, 0, $max);
+                               $receiver[] = DI::l10n()->t('%d more', $total - $max);
+                       }
+                       switch ($type) {
+                               case Tag::TO:
+                                       $output .= DI::l10n()->t('<b>To:</b> %s<br>', implode(', ', $receiver));
+                                       break;
+                               case Tag::CC:
+                                       $output .= DI::l10n()->t('<b>CC:</b> %s<br>', implode(', ', $receiver));
+                                       break;
+                               case Tag::BCC:
+                                       $output .= DI::l10n()->t('<b>BCC:</b> %s<br>', implode(', ', $receiver));
+                                       break;
+                       }
+               }
+
+               return $output;
        }
 }