3 * @copyright Copyright (C) 2020, Friendica
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/>.
23 use Friendica\Core\Hook;
24 use Friendica\Database\DBA;
26 use Friendica\Model\Group;
27 use Friendica\Model\Item;
29 function lockview_content(App $a)
31 $type = (($a->argc > 1) ? $a->argv[1] : 0);
32 if (is_numeric($type)) {
33 $item_id = intval($type);
36 $item_id = (($a->argc > 2) ? intval($a->argv[2]) : 0);
43 if (!in_array($type, ['item','photo','event'])) {
47 $fields = ['uid', 'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid'];
48 $condition = ['id' => $item_id];
50 if ($type != 'item') {
51 $item = DBA::selectFirst($type, $fields, $condition);
53 $fields[] = 'private';
54 $item = Item::selectFirst($fields, $condition);
57 if (!DBA::isResult($item)) {
61 Hook::callAll('lockview_content', $item);
63 if ($item['uid'] != local_user()) {
64 echo DI::l10n()->t('Remote privacy information not available.') . '<br />';
68 if (isset($item['private'])
69 && $item['private'] == Item::PRIVATE
70 && empty($item['allow_cid'])
71 && empty($item['allow_gid'])
72 && empty($item['deny_cid'])
73 && empty($item['deny_gid']))
75 echo DI::l10n()->t('Remote privacy information not available.') . '<br />';
79 $aclFormatter = DI::aclFormatter();
81 $allowed_users = $aclFormatter->expand($item['allow_cid']);
82 $allowed_groups = $aclFormatter->expand($item['allow_gid']);
83 $deny_users = $aclFormatter->expand($item['deny_cid']);
84 $deny_groups = $aclFormatter->expand($item['deny_gid']);
86 $o = DI::l10n()->t('Visible to:') . '<br />';
89 if (count($allowed_groups)) {
90 $key = array_search(Group::FOLLOWERS, $allowed_groups);
92 $l[] = '<b>' . DI::l10n()->t('Followers') . '</b>';
93 unset($allowed_groups[$key]);
96 $key = array_search(Group::MUTUALS, $allowed_groups);
98 $l[] = '<b>' . DI::l10n()->t('Mutuals') . '</b>';
99 unset($allowed_groups[$key]);
103 $r = q("SELECT `name` FROM `group` WHERE `id` IN ( %s )",
104 DBA::escape(implode(', ', $allowed_groups))
106 if (DBA::isResult($r)) {
107 foreach ($r as $rr) {
108 $l[] = '<b>' . $rr['name'] . '</b>';
113 if (count($allowed_users)) {
114 $r = q("SELECT `name` FROM `contact` WHERE `id` IN ( %s )",
115 DBA::escape(implode(', ', $allowed_users))
117 if (DBA::isResult($r)) {
118 foreach ($r as $rr) {
124 if (count($deny_groups)) {
125 $key = array_search(Group::FOLLOWERS, $deny_groups);
126 if ($key !== false) {
127 $l[] = '<b><strike>' . DI::l10n()->t('Followers') . '</strike></b>';
128 unset($deny_groups[$key]);
131 $key = array_search(Group::MUTUALS, $deny_groups);
132 if ($key !== false) {
133 $l[] = '<b><strike>' . DI::l10n()->t('Mutuals') . '</strike></b>';
134 unset($deny_groups[$key]);
137 $r = q("SELECT `name` FROM `group` WHERE `id` IN ( %s )",
138 DBA::escape(implode(', ', $deny_groups))
140 if (DBA::isResult($r)) {
141 foreach ($r as $rr) {
142 $l[] = '<b><strike>' . $rr['name'] . '</strike></b>';
147 if (count($deny_users)) {
148 $r = q("SELECT `name` FROM `contact` WHERE `id` IN ( %s )",
149 DBA::escape(implode(', ', $deny_users))
151 if (DBA::isResult($r)) {
152 foreach ($r as $rr) {
153 $l[] = '<strike>' . $rr['name'] . '</strike>';
158 echo $o . implode(', ', $l);