X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FModule%2FPermissionTooltip.php;h=f4fd5665022b2c42579f6fe5b6a5e3a0361caa79;hb=3bca4fe2a64671d09e08346456cdfa6c12f996e9;hp=58b6df086d1f6ad01fcb753a3c0b2c0879dfd39a;hpb=4e45987f74ccbe61a53c711317c2e45894435ece;p=friendica.git diff --git a/src/Module/PermissionTooltip.php b/src/Module/PermissionTooltip.php index 58b6df086d..f4fd566502 100644 --- a/src/Module/PermissionTooltip.php +++ b/src/Module/PermissionTooltip.php @@ -1,6 +1,6 @@ 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); @@ -65,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') { @@ -83,15 +89,15 @@ class PermissionTooltip extends \Friendica\BaseModule 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 = ''; @@ -107,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:') . '
' . $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:') . '
'; $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[] = '' . DI::l10n()->t('Followers') . ''; - 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[] = '' . DI::l10n()->t('Mutuals') . ''; - unset($allowed_groups[$key]); + unset($allowed_circles[$key]); } - foreach (DI::dba()->selectToArray('group', ['name'], ['id' => $allowed_groups]) as $group) { - $l[] = '' . $group['name'] . ''; + foreach (DI::dba()->selectToArray('group', ['name'], ['id' => $allowed_circles]) as $circle) { + $l[] = '' . $circle['name'] . ''; } } @@ -137,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[] = '' . DI::l10n()->t('Followers') . ''; - 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[] = '' . DI::l10n()->t('Mutuals') . ''; - unset($deny_groups[$key]); + unset($deny_circles[$key]); } - foreach (DI::dba()->selectToArray('group', ['name'], ['id' => $allowed_groups]) as $group) { - $l[] = '' . $group['name'] . ''; + foreach (DI::dba()->selectToArray('group', ['name'], ['id' => $allowed_circles]) as $circle) { + $l[] = '' . $circle['name'] . ''; } } @@ -159,25 +179,19 @@ class PermissionTooltip extends \Friendica\BaseModule $l[] = '' . $contact['name'] . ''; } - if (!empty($l)) { - echo $o . implode(', ', $l); - } else { - echo $o . $receivers; - } - - exit(); + return implode(', ', $l); } /** * Fetch a list of receivers * * @param int $uriId - * @return string + * @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,23 +200,30 @@ 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; } - if ($receiver['url'] == ActivityPub::PUBLIC_COLLECTION) { - $receivers[$receiver['type']][] = DI::l10n()->t('Public'); - } else { - $apcontact = DBA::selectFirst('apcontact', ['name'], ['followers' => $receiver['url']]); - if (!empty($apcontact['name'])) { - $receivers[$receiver['type']][] = DI::l10n()->t('Followers (%s)', $apcontact['name']); - } elseif ($apcontact = APContact::getByURL($receiver['url'], false)) { - $receivers[$receiver['type']][] = $apcontact['name']; - } else { + 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; } } @@ -225,6 +246,12 @@ class PermissionTooltip extends \Friendica\BaseModule case Tag::BCC: $output .= DI::l10n()->t('BCC: %s
', implode(', ', $receiver)); break; + case Tag::AUDIENCE: + $output .= DI::l10n()->t('Audience: %s
', implode(', ', $receiver)); + break; + case Tag::ATTRIBUTED: + $output .= DI::l10n()->t('Attributed To: %s
', implode(', ', $receiver)); + break; } }