]> git.mxchange.org Git - friendica.git/blob - mod/lockview.php
Merge remote-tracking branch 'upstream/develop' into aria
[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\Core\L10n;
8 use Friendica\Database\DBA;
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 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 L10n::t('Remote privacy information not available.') . '<br />';
59                 exit();
60         }
61
62         $allowed_users  = expand_acl($item['allow_cid']);
63         $allowed_groups = expand_acl($item['allow_gid']);
64         $deny_users     = expand_acl($item['deny_cid']);
65         $deny_groups    = expand_acl($item['deny_gid']);
66
67         $o = L10n::t('Visible to:') . '<br />';
68         $l = [];
69
70         if (count($allowed_groups)) {
71                 $key = array_search(Group::FOLLOWERS, $allowed_groups);
72                 if ($key !== false) {
73                         $l[] = '<b>' . L10n::t('Followers') . '</b>';
74                         unset($allowed_groups[$key]);
75                 }
76
77                 $key = array_search(Group::MUTUALS, $allowed_groups);
78                 if ($key !== false) {
79                         $l[] = '<b>' . L10n::t('Mutuals') . '</b>';
80                         unset($allowed_groups[$key]);
81                 }
82
83
84                 $r = q("SELECT `name` FROM `group` WHERE `id` IN ( %s )",
85                         DBA::escape(implode(', ', $allowed_groups))
86                 );
87                 if (DBA::isResult($r)) {
88                         foreach ($r as $rr) {
89                                 $l[] = '<b>' . $rr['name'] . '</b>';
90                         }
91                 }
92         }
93
94         if (count($allowed_users)) {
95                 $r = q("SELECT `name` FROM `contact` WHERE `id` IN ( %s )",
96                         DBA::escape(implode(', ', $allowed_users))
97                 );
98                 if (DBA::isResult($r)) {
99                         foreach ($r as $rr) {
100                                 $l[] = $rr['name'];
101                         }
102                 }
103         }
104
105         if (count($deny_groups)) {
106                 $key = array_search(Group::FOLLOWERS, $deny_groups);
107                 if ($key !== false) {
108                         $l[] = '<b><strike>' . L10n::t('Followers') . '</strike></b>';
109                         unset($deny_groups[$key]);
110                 }
111
112                 $key = array_search(Group::MUTUALS, $deny_groups);
113                 if ($key !== false) {
114                         $l[] = '<b><strike>' . L10n::t('Mutuals') . '</strike></b>';
115                         unset($deny_groups[$key]);
116                 }
117
118                 $r = q("SELECT `name` FROM `group` WHERE `id` IN ( %s )",
119                         DBA::escape(implode(', ', $deny_groups))
120                 );
121                 if (DBA::isResult($r)) {
122                         foreach ($r as $rr) {
123                                 $l[] = '<b><strike>' . $rr['name'] . '</strike></b>';
124                         }
125                 }
126         }
127
128         if (count($deny_users)) {
129                 $r = q("SELECT `name` FROM `contact` WHERE `id` IN ( %s )",
130                         DBA::escape(implode(', ', $deny_users))
131                 );
132                 if (DBA::isResult($r)) {
133                         foreach ($r as $rr) {
134                                 $l[] = '<strike>' . $rr['name'] . '</strike>';
135                         }
136                 }
137         }
138
139         echo $o . implode(', ', $l);
140         exit();
141
142 }