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