]> git.mxchange.org Git - friendica.git/blobdiff - src/Module/PermissionTooltip.php
Changes:
[friendica.git] / src / Module / PermissionTooltip.php
index 07faa72e3e1a63b0fd7df5962ae4b2ba14944b68..f4fd5665022b2c42579f6fe5b6a5e3a0361caa79 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * @copyright Copyright (C) 2010-2022, the Friendica project
+ * @copyright Copyright (C) 2010-2024, the Friendica project
  *
  * @license GNU AGPL version 3 or any later version
  *
 namespace Friendica\Module;
 
 use Friendica\Core\Hook;
+use Friendica\Core\Protocol;
 use Friendica\Core\System;
 use Friendica\Database\DBA;
 use Friendica\DI;
 use Friendica\Model\APContact;
-use Friendica\Model\Group;
+use Friendica\Model\Circle;
 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.
@@ -49,10 +49,23 @@ 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, 'uid' => [0, local_user()]];
+               $condition = ['id' => $referenceId, 'uid' => [0, DI::userSession()->getLocalUserId()]];
                if ($type == 'item') {
-                       $fields = ['uid', 'psid', 'private', 'uri-id'];
-                       $model = Post::selectFirst($fields, $condition);
+                       $fields = ['uid', 'psid', 'private', 'uri-id', 'origin', 'network'];
+                       $model = Post::selectFirst($fields, $condition, ['order' => ['uid' => true]]);
+
+                       if ($model['origin'] || ($model['network'] != Protocol::ACTIVITYPUB)) {
+                               $permissionSet = DI::permissionSet()->selectOneById($model['psid'], $model['uid']);
+                               $model['allow_cid'] = $permissionSet->allow_cid;
+                               $model['allow_gid'] = $permissionSet->allow_gid;
+                               $model['deny_cid']  = $permissionSet->deny_cid;
+                               $model['deny_gid']  = $permissionSet->deny_gid;
+                       } else {
+                               $model['allow_cid'] = [];
+                               $model['allow_gid'] = [];
+                               $model['deny_cid']  = [];
+                               $model['deny_gid']  = [];
+                       }
                } else {
                        $fields = ['uid', 'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid'];
                        $model = DBA::selectFirst($type, $fields, $condition);
@@ -66,15 +79,7 @@ class PermissionTooltip extends \Friendica\BaseModule
                        throw new HttpException\NotFoundException(DI::l10n()->t('Model not found'));
                }
 
-               if (isset($model['psid'])) {
-                       $permissionSet = DI::permissionSet()->selectOneById($model['psid'], $model['uid']);
-                       $model['allow_cid'] = $permissionSet->allow_cid;
-                       $model['allow_gid'] = $permissionSet->allow_gid;
-                       $model['deny_cid']  = $permissionSet->deny_cid;
-                       $model['deny_gid']  = $permissionSet->deny_gid;
-               }
-
-               // Kept for backwards compatiblity
+               // Kept for backwards compatibility
                Hook::callAll('lockview_content', $model);
 
                if ($type == 'item') {
@@ -108,29 +113,43 @@ class PermissionTooltip extends \Friendica\BaseModule
                        exit;
                }
 
-               $allowed_users  = $model['allow_cid'];
-               $allowed_groups = $model['allow_gid'];
-               $deny_users     = $model['deny_cid'];
-               $deny_groups    = $model['deny_gid'];
+               if (!empty($model['allow_cid']) || !empty($model['allow_gid']) || !empty($model['deny_cid']) || !empty($model['deny_gid'])) {
+                       $receivers = $this->fetchReceiversFromACL($model);
+               }
+
+               $this->httpExit(DI::l10n()->t('Visible to:') . '<br />' . $receivers);
+       }
+
+       /**
+        * Fetch a list of receivers based on the ACL data
+        *
+        * @param array $model
+        * @return string
+        */
+       private function fetchReceiversFromACL(array $model)
+       {
+               $allowed_users   = $model['allow_cid'];
+               $allowed_circles = $model['allow_gid'];
+               $deny_users      = $model['deny_cid'];
+               $deny_circles    = $model['deny_gid'];
 
-               $o = DI::l10n()->t('Visible to:') . '<br />';
                $l = [];
 
-               if (count($allowed_groups)) {
-                       $key = array_search(Group::FOLLOWERS, $allowed_groups);
+               if (count($allowed_circles)) {
+                       $key = array_search(Circle::FOLLOWERS, $allowed_circles);
                        if ($key !== false) {
                                $l[] = '<b>' . DI::l10n()->t('Followers') . '</b>';
-                               unset($allowed_groups[$key]);
+                               unset($allowed_circles[$key]);
                        }
 
-                       $key = array_search(Group::MUTUALS, $allowed_groups);
+                       $key = array_search(Circle::MUTUALS, $allowed_circles);
                        if ($key !== false) {
                                $l[] = '<b>' . DI::l10n()->t('Mutuals') . '</b>';
-                               unset($allowed_groups[$key]);
+                               unset($allowed_circles[$key]);
                        }
 
-                       foreach (DI::dba()->selectToArray('group', ['name'], ['id' => $allowed_groups]) as $group) {
-                               $l[] = '<b>' . $group['name'] . '</b>';
+                       foreach (DI::dba()->selectToArray('group', ['name'], ['id' => $allowed_circles]) as $circle) {
+                               $l[] = '<b>' . $circle['name'] . '</b>';
                        }
                }
 
@@ -138,21 +157,21 @@ class PermissionTooltip extends \Friendica\BaseModule
                        $l[] = $contact['name'];
                }
 
-               if (count($deny_groups)) {
-                       $key = array_search(Group::FOLLOWERS, $deny_groups);
+               if (count($deny_circles)) {
+                       $key = array_search(Circle::FOLLOWERS, $deny_circles);
                        if ($key !== false) {
                                $l[] = '<b><strike>' . DI::l10n()->t('Followers') . '</strike></b>';
-                               unset($deny_groups[$key]);
+                               unset($deny_circles[$key]);
                        }
 
-                       $key = array_search(Group::MUTUALS, $deny_groups);
+                       $key = array_search(Circle::MUTUALS, $deny_circles);
                        if ($key !== false) {
                                $l[] = '<b><strike>' . DI::l10n()->t('Mutuals') . '</strike></b>';
-                               unset($deny_groups[$key]);
+                               unset($deny_circles[$key]);
                        }
 
-                       foreach (DI::dba()->selectToArray('group', ['name'], ['id' => $allowed_groups]) as $group) {
-                               $l[] = '<b><strike>' . $group['name'] . '</strike></b>';
+                       foreach (DI::dba()->selectToArray('group', ['name'], ['id' => $allowed_circles]) as $circle) {
+                               $l[] = '<b><strike>' . $circle['name'] . '</strike></b>';
                        }
                }
 
@@ -160,12 +179,7 @@ class PermissionTooltip extends \Friendica\BaseModule
                        $l[] = '<strike>' . $contact['name'] . '</strike>';
                }
 
-               if (!empty($l)) {
-                       echo $o . implode(', ', $l);
-               } else {
-                       echo $o . $receivers;
-               }
-               System::exit();
+               return implode(', ', $l);
        }
 
        /**
@@ -174,10 +188,10 @@ class PermissionTooltip extends \Friendica\BaseModule
         * @param int $uriId
         * @return string
         */
-       private function fetchReceivers(int $uriId):string
+       private function fetchReceivers(int $uriId): string
        {
                $own_url = '';
-               $uid = local_user();
+               $uid = DI::userSession()->getLocalUserId();
                if ($uid) {
                        $owner = User::getOwnerDataById($uid);
                        if (!empty($owner['url'])) {
@@ -186,7 +200,7 @@ class PermissionTooltip extends \Friendica\BaseModule
                }
 
                $receivers = [];
-               foreach (Tag::getByURIId($uriId, [Tag::TO, Tag::CC, Tag::BCC]) as $receiver) {
+               foreach (Tag::getByURIId($uriId, [Tag::TO, Tag::CC, Tag::BCC, Tag::AUDIENCE, Tag::ATTRIBUTED]) as $receiver) {
                        // We only display BCC when it contains the current user
                        if (($receiver['type'] == Tag::BCC) && ($receiver['url'] != $own_url)) {
                                continue;
@@ -232,6 +246,12 @@ class PermissionTooltip extends \Friendica\BaseModule
                                case Tag::BCC:
                                        $output .= DI::l10n()->t('<b>BCC:</b> %s<br>', implode(', ', $receiver));
                                        break;
+                               case Tag::AUDIENCE:
+                                       $output .= DI::l10n()->t('<b>Audience:</b> %s<br>', implode(', ', $receiver));
+                                       break;
+                               case Tag::ATTRIBUTED:
+                                       $output .= DI::l10n()->t('<b>Attributed To:</b> %s<br>', implode(', ', $receiver));
+                                       break;
                        }
                }