3 * @file mod/lockview.php
6 use Friendica\BaseObject;
7 use Friendica\Core\Hook;
8 use Friendica\Core\L10n;
9 use Friendica\Database\DBA;
10 use Friendica\Model\Group;
11 use Friendica\Model\Item;
12 use Friendica\Util\ACLFormatter;
14 function lockview_content(App $a)
16 $type = (($a->argc > 1) ? $a->argv[1] : 0);
17 if (is_numeric($type)) {
18 $item_id = intval($type);
21 $item_id = (($a->argc > 2) ? intval($a->argv[2]) : 0);
28 if (!in_array($type, ['item','photo','event'])) {
32 $fields = ['uid', 'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid'];
33 $condition = ['id' => $item_id];
35 if ($type != 'item') {
36 $item = DBA::selectFirst($type, $fields, $condition);
38 $fields[] = 'private';
39 $item = Item::selectFirst($fields, $condition);
42 if (!DBA::isResult($item)) {
46 Hook::callAll('lockview_content', $item);
48 if ($item['uid'] != local_user()) {
49 echo L10n::t('Remote privacy information not available.') . '<br />';
53 if (isset($item['private'])
54 && $item['private'] == 1
55 && empty($item['allow_cid'])
56 && empty($item['allow_gid'])
57 && empty($item['deny_cid'])
58 && empty($item['deny_gid']))
60 echo L10n::t('Remote privacy information not available.') . '<br />';
64 /** @var ACLFormatter $aclFormatter */
65 $aclFormatter = BaseObject::getClass(ACLFormatter::class);
67 $allowed_users = $aclFormatter->expand($item['allow_cid']);
68 $allowed_groups = $aclFormatter->expand($item['allow_gid']);
69 $deny_users = $aclFormatter->expand($item['deny_cid']);
70 $deny_groups = $aclFormatter->expand($item['deny_gid']);
72 $o = L10n::t('Visible to:') . '<br />';
75 if (count($allowed_groups)) {
76 $key = array_search(Group::FOLLOWERS, $allowed_groups);
78 $l[] = '<b>' . L10n::t('Followers') . '</b>';
79 unset($allowed_groups[$key]);
82 $key = array_search(Group::MUTUALS, $allowed_groups);
84 $l[] = '<b>' . L10n::t('Mutuals') . '</b>';
85 unset($allowed_groups[$key]);
89 $r = q("SELECT `name` FROM `group` WHERE `id` IN ( %s )",
90 DBA::escape(implode(', ', $allowed_groups))
92 if (DBA::isResult($r)) {
94 $l[] = '<b>' . $rr['name'] . '</b>';
99 if (count($allowed_users)) {
100 $r = q("SELECT `name` FROM `contact` WHERE `id` IN ( %s )",
101 DBA::escape(implode(', ', $allowed_users))
103 if (DBA::isResult($r)) {
104 foreach ($r as $rr) {
110 if (count($deny_groups)) {
111 $key = array_search(Group::FOLLOWERS, $deny_groups);
112 if ($key !== false) {
113 $l[] = '<b><strike>' . L10n::t('Followers') . '</strike></b>';
114 unset($deny_groups[$key]);
117 $key = array_search(Group::MUTUALS, $deny_groups);
118 if ($key !== false) {
119 $l[] = '<b><strike>' . L10n::t('Mutuals') . '</strike></b>';
120 unset($deny_groups[$key]);
123 $r = q("SELECT `name` FROM `group` WHERE `id` IN ( %s )",
124 DBA::escape(implode(', ', $deny_groups))
126 if (DBA::isResult($r)) {
127 foreach ($r as $rr) {
128 $l[] = '<b><strike>' . $rr['name'] . '</strike></b>';
133 if (count($deny_users)) {
134 $r = q("SELECT `name` FROM `contact` WHERE `id` IN ( %s )",
135 DBA::escape(implode(', ', $deny_users))
137 if (DBA::isResult($r)) {
138 foreach ($r as $rr) {
139 $l[] = '<strike>' . $rr['name'] . '</strike>';
144 echo $o . implode(', ', $l);