2020-07-27 00:35:02 +02:00
|
|
|
<?php
|
2022-01-02 10:49:50 +01:00
|
|
|
/**
|
2024-01-02 21:57:26 +01:00
|
|
|
* @copyright Copyright (C) 2010-2024, the Friendica project
|
2022-01-02 10:49:50 +01:00
|
|
|
*
|
|
|
|
* @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/>.
|
|
|
|
*
|
|
|
|
*/
|
2020-07-27 00:35:02 +02:00
|
|
|
|
|
|
|
namespace Friendica\Module;
|
|
|
|
|
|
|
|
use Friendica\Core\Hook;
|
2023-03-22 22:43:03 +01:00
|
|
|
use Friendica\Core\Protocol;
|
2022-05-18 04:13:54 +02:00
|
|
|
use Friendica\Core\System;
|
2020-07-27 00:35:02 +02:00
|
|
|
use Friendica\Database\DBA;
|
|
|
|
use Friendica\DI;
|
2022-02-24 08:09:34 +01:00
|
|
|
use Friendica\Model\APContact;
|
2023-05-14 01:54:35 +02:00
|
|
|
use Friendica\Model\Circle;
|
2022-03-10 08:38:12 +01:00
|
|
|
use Friendica\Model\Item;
|
2021-01-16 05:16:09 +01:00
|
|
|
use Friendica\Model\Post;
|
2022-02-20 20:25:55 +01:00
|
|
|
use Friendica\Model\Tag;
|
2022-02-24 08:09:34 +01:00
|
|
|
use Friendica\Model\User;
|
2020-07-27 00:35:02 +02:00
|
|
|
use Friendica\Network\HTTPException;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Outputs the permission tooltip HTML content for the provided item, photo or event id.
|
|
|
|
*/
|
|
|
|
class PermissionTooltip extends \Friendica\BaseModule
|
|
|
|
{
|
2021-11-20 15:38:03 +01:00
|
|
|
protected function rawContent(array $request = [])
|
2020-07-27 00:35:02 +02:00
|
|
|
{
|
2021-11-14 23:19:25 +01:00
|
|
|
$type = $this->parameters['type'];
|
|
|
|
$referenceId = $this->parameters['id'];
|
2020-07-27 00:35:02 +02:00
|
|
|
|
|
|
|
$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)));
|
|
|
|
}
|
|
|
|
|
2022-10-20 22:59:12 +02:00
|
|
|
$condition = ['id' => $referenceId, 'uid' => [0, DI::userSession()->getLocalUserId()]];
|
2020-07-27 00:35:02 +02:00
|
|
|
if ($type == 'item') {
|
2023-03-22 22:43:03 +01:00
|
|
|
$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'] = [];
|
|
|
|
}
|
2020-07-27 00:35:02 +02:00
|
|
|
} else {
|
|
|
|
$fields = ['uid', 'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid'];
|
|
|
|
$model = DBA::selectFirst($type, $fields, $condition);
|
2021-10-22 00:49:22 +02:00
|
|
|
$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']);
|
2020-07-27 00:35:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!DBA::isResult($model)) {
|
|
|
|
throw new HttpException\NotFoundException(DI::l10n()->t('Model not found'));
|
|
|
|
}
|
|
|
|
|
2023-03-22 04:17:09 +01:00
|
|
|
// Kept for backwards compatibility
|
2020-07-27 00:35:02 +02:00
|
|
|
Hook::callAll('lockview_content', $model);
|
|
|
|
|
2022-02-20 20:25:55 +01:00
|
|
|
if ($type == 'item') {
|
|
|
|
$receivers = $this->fetchReceivers($model['uri-id']);
|
2022-03-10 08:38:12 +01:00
|
|
|
if (empty($receivers)) {
|
|
|
|
switch ($model['private']) {
|
|
|
|
case Item::PUBLIC:
|
|
|
|
$receivers = DI::l10n()->t('Public');
|
|
|
|
break;
|
2022-04-23 14:32:29 +02:00
|
|
|
|
2022-03-10 08:38:12 +01:00
|
|
|
case Item::UNLISTED:
|
|
|
|
$receivers = DI::l10n()->t('Unlisted');
|
|
|
|
break;
|
2022-04-23 14:32:29 +02:00
|
|
|
|
2022-03-10 08:38:12 +01:00
|
|
|
case Item::PRIVATE:
|
|
|
|
$receivers = DI::l10n()->t('Limited/Private');
|
|
|
|
break;
|
2022-04-23 14:32:29 +02:00
|
|
|
}
|
2022-03-10 08:38:12 +01:00
|
|
|
}
|
2022-02-20 20:25:55 +01:00
|
|
|
} else {
|
|
|
|
$receivers = '';
|
|
|
|
}
|
|
|
|
|
2022-03-10 08:38:12 +01:00
|
|
|
if (empty($model['allow_cid'])
|
2020-07-27 00:35:02 +02:00
|
|
|
&& empty($model['allow_gid'])
|
|
|
|
&& empty($model['deny_cid'])
|
2022-02-20 20:25:55 +01:00
|
|
|
&& empty($model['deny_gid'])
|
|
|
|
&& empty($receivers))
|
2020-07-27 00:35:02 +02:00
|
|
|
{
|
|
|
|
echo DI::l10n()->t('Remote privacy information not available.');
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
2023-10-29 09:49:24 +01:00
|
|
|
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)
|
|
|
|
{
|
2023-05-14 01:54:35 +02:00
|
|
|
$allowed_users = $model['allow_cid'];
|
|
|
|
$allowed_circles = $model['allow_gid'];
|
|
|
|
$deny_users = $model['deny_cid'];
|
|
|
|
$deny_circles = $model['deny_gid'];
|
2020-07-27 00:35:02 +02:00
|
|
|
|
|
|
|
$l = [];
|
|
|
|
|
2023-05-14 01:54:35 +02:00
|
|
|
if (count($allowed_circles)) {
|
|
|
|
$key = array_search(Circle::FOLLOWERS, $allowed_circles);
|
2020-07-27 00:35:02 +02:00
|
|
|
if ($key !== false) {
|
|
|
|
$l[] = '<b>' . DI::l10n()->t('Followers') . '</b>';
|
2023-05-14 01:54:35 +02:00
|
|
|
unset($allowed_circles[$key]);
|
2020-07-27 00:35:02 +02:00
|
|
|
}
|
|
|
|
|
2023-05-14 01:54:35 +02:00
|
|
|
$key = array_search(Circle::MUTUALS, $allowed_circles);
|
2020-07-27 00:35:02 +02:00
|
|
|
if ($key !== false) {
|
|
|
|
$l[] = '<b>' . DI::l10n()->t('Mutuals') . '</b>';
|
2023-05-14 01:54:35 +02:00
|
|
|
unset($allowed_circles[$key]);
|
2020-07-27 00:35:02 +02:00
|
|
|
}
|
|
|
|
|
2023-05-14 01:54:35 +02:00
|
|
|
foreach (DI::dba()->selectToArray('group', ['name'], ['id' => $allowed_circles]) as $circle) {
|
|
|
|
$l[] = '<b>' . $circle['name'] . '</b>';
|
2020-07-27 00:35:02 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach (DI::dba()->selectToArray('contact', ['name'], ['id' => $allowed_users]) as $contact) {
|
|
|
|
$l[] = $contact['name'];
|
|
|
|
}
|
|
|
|
|
2023-05-14 01:54:35 +02:00
|
|
|
if (count($deny_circles)) {
|
|
|
|
$key = array_search(Circle::FOLLOWERS, $deny_circles);
|
2020-07-27 00:35:02 +02:00
|
|
|
if ($key !== false) {
|
|
|
|
$l[] = '<b><strike>' . DI::l10n()->t('Followers') . '</strike></b>';
|
2023-05-14 01:54:35 +02:00
|
|
|
unset($deny_circles[$key]);
|
2020-07-27 00:35:02 +02:00
|
|
|
}
|
|
|
|
|
2023-05-14 01:54:35 +02:00
|
|
|
$key = array_search(Circle::MUTUALS, $deny_circles);
|
2020-07-27 00:35:02 +02:00
|
|
|
if ($key !== false) {
|
|
|
|
$l[] = '<b><strike>' . DI::l10n()->t('Mutuals') . '</strike></b>';
|
2023-05-14 01:54:35 +02:00
|
|
|
unset($deny_circles[$key]);
|
2020-07-27 00:35:02 +02:00
|
|
|
}
|
|
|
|
|
2023-05-14 01:54:35 +02:00
|
|
|
foreach (DI::dba()->selectToArray('group', ['name'], ['id' => $allowed_circles]) as $circle) {
|
|
|
|
$l[] = '<b><strike>' . $circle['name'] . '</strike></b>';
|
2020-07-27 00:35:02 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach (DI::dba()->selectToArray('contact', ['name'], ['id' => $deny_users]) as $contact) {
|
|
|
|
$l[] = '<strike>' . $contact['name'] . '</strike>';
|
|
|
|
}
|
|
|
|
|
2023-10-29 09:49:24 +01:00
|
|
|
return implode(', ', $l);
|
2020-07-27 00:35:02 +02:00
|
|
|
}
|
2022-02-20 20:25:55 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Fetch a list of receivers
|
|
|
|
*
|
|
|
|
* @param int $uriId
|
2022-04-23 14:32:29 +02:00
|
|
|
* @return string
|
2022-02-20 20:25:55 +01:00
|
|
|
*/
|
2022-06-23 11:39:45 +02:00
|
|
|
private function fetchReceivers(int $uriId): string
|
2022-02-20 20:25:55 +01:00
|
|
|
{
|
2022-02-24 08:09:34 +01:00
|
|
|
$own_url = '';
|
2022-10-20 22:59:12 +02:00
|
|
|
$uid = DI::userSession()->getLocalUserId();
|
2022-02-24 08:09:34 +01:00
|
|
|
if ($uid) {
|
|
|
|
$owner = User::getOwnerDataById($uid);
|
|
|
|
if (!empty($owner['url'])) {
|
|
|
|
$own_url = $owner['url'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-20 20:25:55 +01:00
|
|
|
$receivers = [];
|
2023-04-14 19:21:20 +02:00
|
|
|
foreach (Tag::getByURIId($uriId, [Tag::TO, Tag::CC, Tag::BCC, Tag::AUDIENCE, Tag::ATTRIBUTED]) as $receiver) {
|
2022-02-24 08:09:34 +01:00
|
|
|
// We only display BCC when it contains the current user
|
|
|
|
if (($receiver['type'] == Tag::BCC) && ($receiver['url'] != $own_url)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2022-04-23 14:32:29 +02:00
|
|
|
switch (Tag::getTargetType($receiver['url'], false)) {
|
|
|
|
case Tag::PUBLIC_COLLECTION:
|
|
|
|
$receivers[$receiver['type']][] = DI::l10n()->t('Public');
|
|
|
|
break;
|
|
|
|
case Tag::GENERAL_COLLECTION:
|
2022-04-23 13:39:19 +02:00
|
|
|
$receivers[$receiver['type']][] = DI::l10n()->t('Collection (%s)', $receiver['name']);
|
2022-04-23 14:32:29 +02:00
|
|
|
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:
|
2022-02-23 21:18:37 +01:00
|
|
|
$receivers[$receiver['type']][] = $receiver['name'];
|
2022-04-23 14:32:29 +02:00
|
|
|
break;
|
2022-02-23 21:18:37 +01:00
|
|
|
}
|
2022-02-20 20:25:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$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;
|
2022-02-24 08:09:34 +01:00
|
|
|
case Tag::BCC:
|
|
|
|
$output .= DI::l10n()->t('<b>BCC:</b> %s<br>', implode(', ', $receiver));
|
|
|
|
break;
|
2023-04-14 19:21:20 +02:00
|
|
|
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;
|
2023-04-14 20:56:43 +02:00
|
|
|
}
|
2022-02-20 20:25:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return $output;
|
|
|
|
}
|
2020-07-27 00:35:02 +02:00
|
|
|
}
|