]> git.mxchange.org Git - friendica.git/blob - mod/lockview.php
EN GB translation update THX AndyH3
[friendica.git] / mod / lockview.php
1 <?php
2 /**
3  * @file mod/lockview.php
4  */
5 use Friendica\App;
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;
13
14 function lockview_content(App $a)
15 {
16         $type = (($a->argc > 1) ? $a->argv[1] : 0);
17         if (is_numeric($type)) {
18                 $item_id = intval($type);
19                 $type = 'item';
20         } else {
21                 $item_id = (($a->argc > 2) ? intval($a->argv[2]) : 0);
22         }
23
24         if (!$item_id) {
25                 exit();
26         }
27
28         if (!in_array($type, ['item','photo','event'])) {
29                 exit();
30         }
31
32         $fields = ['uid', 'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid'];
33         $condition = ['id' => $item_id];
34
35         if ($type != 'item') {
36                 $item = DBA::selectFirst($type, $fields, $condition);
37         } else {
38                 $fields[] = 'private';
39                 $item = Item::selectFirst($fields, $condition);
40         }
41
42         if (!DBA::isResult($item)) {
43                 exit();
44         }
45
46         Hook::callAll('lockview_content', $item);
47
48         if ($item['uid'] != local_user()) {
49                 echo L10n::t('Remote privacy information not available.') . '<br />';
50                 exit();
51         }
52
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']))
59         {
60                 echo L10n::t('Remote privacy information not available.') . '<br />';
61                 exit();
62         }
63
64         /** @var ACLFormatter $aclFormatter */
65         $aclFormatter = BaseObject::getClass(ACLFormatter::class);
66
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']);
71
72         $o = L10n::t('Visible to:') . '<br />';
73         $l = [];
74
75         if (count($allowed_groups)) {
76                 $key = array_search(Group::FOLLOWERS, $allowed_groups);
77                 if ($key !== false) {
78                         $l[] = '<b>' . L10n::t('Followers') . '</b>';
79                         unset($allowed_groups[$key]);
80                 }
81
82                 $key = array_search(Group::MUTUALS, $allowed_groups);
83                 if ($key !== false) {
84                         $l[] = '<b>' . L10n::t('Mutuals') . '</b>';
85                         unset($allowed_groups[$key]);
86                 }
87
88
89                 $r = q("SELECT `name` FROM `group` WHERE `id` IN ( %s )",
90                         DBA::escape(implode(', ', $allowed_groups))
91                 );
92                 if (DBA::isResult($r)) {
93                         foreach ($r as $rr) {
94                                 $l[] = '<b>' . $rr['name'] . '</b>';
95                         }
96                 }
97         }
98
99         if (count($allowed_users)) {
100                 $r = q("SELECT `name` FROM `contact` WHERE `id` IN ( %s )",
101                         DBA::escape(implode(', ', $allowed_users))
102                 );
103                 if (DBA::isResult($r)) {
104                         foreach ($r as $rr) {
105                                 $l[] = $rr['name'];
106                         }
107                 }
108         }
109
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]);
115                 }
116
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]);
121                 }
122
123                 $r = q("SELECT `name` FROM `group` WHERE `id` IN ( %s )",
124                         DBA::escape(implode(', ', $deny_groups))
125                 );
126                 if (DBA::isResult($r)) {
127                         foreach ($r as $rr) {
128                                 $l[] = '<b><strike>' . $rr['name'] . '</strike></b>';
129                         }
130                 }
131         }
132
133         if (count($deny_users)) {
134                 $r = q("SELECT `name` FROM `contact` WHERE `id` IN ( %s )",
135                         DBA::escape(implode(', ', $deny_users))
136                 );
137                 if (DBA::isResult($r)) {
138                         foreach ($r as $rr) {
139                                 $l[] = '<strike>' . $rr['name'] . '</strike>';
140                         }
141                 }
142         }
143
144         echo $o . implode(', ', $l);
145         exit();
146
147 }