X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FModule%2FPermissionTooltip.php;h=453bb5d3ac70bdf7d2000b98be1db6f755a7652d;hb=b36d4eb0dd4bdc25a468c95c749bfae1b6324be9;hp=3f23032d6d838b4618f1806357d99e9f16515ba9;hpb=62eb16e9ad9adbd2fa712cccbb40ab53b8b16e5b;p=friendica.git
diff --git a/src/Module/PermissionTooltip.php b/src/Module/PermissionTooltip.php
index 3f23032d6d..453bb5d3ac 100644
--- a/src/Module/PermissionTooltip.php
+++ b/src/Module/PermissionTooltip.php
@@ -1,37 +1,66 @@
.
+ *
+ */
namespace Friendica\Module;
use Friendica\Core\Hook;
+use Friendica\Core\Session;
+use Friendica\Core\System;
use Friendica\Database\DBA;
use Friendica\DI;
-use Friendica\Model\Item;
+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 static function rawContent(array $parameters = [])
+ protected function rawContent(array $request = [])
{
- $type = $parameters['type'];
- $referenceId = $parameters['id'];
+ $type = $this->parameters['type'];
+ $referenceId = $this->parameters['id'];
$expectedTypes = ['item', 'photo', 'event'];
if (!in_array($type, $expectedTypes)) {
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, Session::getLocalUser()]];
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'];
$model = DBA::selectFirst($type, $fields, $condition);
+ $model['allow_cid'] = DI::aclFormatter()->expand($model['allow_cid']);
+ $model['allow_gid'] = DI::aclFormatter()->expand($model['allow_gid']);
+ $model['deny_cid'] = DI::aclFormatter()->expand($model['deny_cid']);
+ $model['deny_gid'] = DI::aclFormatter()->expand($model['deny_gid']);
}
if (!DBA::isResult($model)) {
@@ -39,7 +68,7 @@ class PermissionTooltip extends \Friendica\BaseModule
}
if (isset($model['psid'])) {
- $permissionSet = DI::permissionSet()->selectOneById($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;
@@ -49,13 +78,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;
@@ -113,7 +161,81 @@ class PermissionTooltip extends \Friendica\BaseModule
$l[] = '' . $contact['name'] . '';
}
- 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 = Session::getLocalUser();
+ 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('To: %s
', implode(', ', $receiver));
+ break;
+ case Tag::CC:
+ $output .= DI::l10n()->t('CC: %s
', implode(', ', $receiver));
+ break;
+ case Tag::BCC:
+ $output .= DI::l10n()->t('BCC: %s
', implode(', ', $receiver));
+ break;
+ }
+ }
+
+ return $output;
}
}