3 * @copyright Copyright (C) 2010-2022, the Friendica project
5 * @license GNU AGPL version 3 or any later version
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 namespace Friendica\Module;
24 use Friendica\Core\Hook;
25 use Friendica\Database\DBA;
27 use Friendica\Model\Group;
28 use Friendica\Model\Item;
29 use Friendica\Model\Post;
30 use Friendica\Network\HTTPException;
33 * Outputs the permission tooltip HTML content for the provided item, photo or event id.
35 class PermissionTooltip extends \Friendica\BaseModule
37 protected function rawContent(array $request = [])
39 $type = $this->parameters['type'];
40 $referenceId = $this->parameters['id'];
42 $expectedTypes = ['item', 'photo', 'event'];
43 if (!in_array($type, $expectedTypes)) {
44 throw new HTTPException\BadRequestException(DI::l10n()->t('Wrong type "%s", expected one of: %s', $type, implode(', ', $expectedTypes)));
47 $condition = ['id' => $referenceId];
48 if ($type == 'item') {
49 $fields = ['uid', 'psid', 'private'];
50 $model = Post::selectFirst($fields, $condition);
52 $fields = ['uid', 'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid'];
53 $model = DBA::selectFirst($type, $fields, $condition);
54 $model['allow_cid'] = DI::aclFormatter()->expand($model['allow_cid']);
55 $model['allow_gid'] = DI::aclFormatter()->expand($model['allow_gid']);
56 $model['deny_cid'] = DI::aclFormatter()->expand($model['deny_cid']);
57 $model['deny_gid'] = DI::aclFormatter()->expand($model['deny_gid']);
60 if (!DBA::isResult($model)) {
61 throw new HttpException\NotFoundException(DI::l10n()->t('Model not found'));
64 if (isset($model['psid'])) {
65 $permissionSet = DI::permissionSet()->selectOneById($model['psid'], $model['uid']);
66 $model['allow_cid'] = $permissionSet->allow_cid;
67 $model['allow_gid'] = $permissionSet->allow_gid;
68 $model['deny_cid'] = $permissionSet->deny_cid;
69 $model['deny_gid'] = $permissionSet->deny_gid;
72 // Kept for backwards compatiblity
73 Hook::callAll('lockview_content', $model);
75 if ($model['uid'] != local_user() ||
76 isset($model['private'])
77 && $model['private'] == Item::PRIVATE
78 && empty($model['allow_cid'])
79 && empty($model['allow_gid'])
80 && empty($model['deny_cid'])
81 && empty($model['deny_gid']))
83 echo DI::l10n()->t('Remote privacy information not available.');
87 $allowed_users = $model['allow_cid'];
88 $allowed_groups = $model['allow_gid'];
89 $deny_users = $model['deny_cid'];
90 $deny_groups = $model['deny_gid'];
92 $o = DI::l10n()->t('Visible to:') . '<br />';
95 if (count($allowed_groups)) {
96 $key = array_search(Group::FOLLOWERS, $allowed_groups);
98 $l[] = '<b>' . DI::l10n()->t('Followers') . '</b>';
99 unset($allowed_groups[$key]);
102 $key = array_search(Group::MUTUALS, $allowed_groups);
103 if ($key !== false) {
104 $l[] = '<b>' . DI::l10n()->t('Mutuals') . '</b>';
105 unset($allowed_groups[$key]);
108 foreach (DI::dba()->selectToArray('group', ['name'], ['id' => $allowed_groups]) as $group) {
109 $l[] = '<b>' . $group['name'] . '</b>';
113 foreach (DI::dba()->selectToArray('contact', ['name'], ['id' => $allowed_users]) as $contact) {
114 $l[] = $contact['name'];
117 if (count($deny_groups)) {
118 $key = array_search(Group::FOLLOWERS, $deny_groups);
119 if ($key !== false) {
120 $l[] = '<b><strike>' . DI::l10n()->t('Followers') . '</strike></b>';
121 unset($deny_groups[$key]);
124 $key = array_search(Group::MUTUALS, $deny_groups);
125 if ($key !== false) {
126 $l[] = '<b><strike>' . DI::l10n()->t('Mutuals') . '</strike></b>';
127 unset($deny_groups[$key]);
130 foreach (DI::dba()->selectToArray('group', ['name'], ['id' => $allowed_groups]) as $group) {
131 $l[] = '<b><strike>' . $group['name'] . '</strike></b>';
135 foreach (DI::dba()->selectToArray('contact', ['name'], ['id' => $deny_users]) as $contact) {
136 $l[] = '<strike>' . $contact['name'] . '</strike>';
139 echo $o . implode(', ', $l);