]> git.mxchange.org Git - friendica.git/blob - mod/lockview.php
Merge pull request #8888 from annando/rename-keywordlist
[friendica.git] / mod / lockview.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2020, Friendica
4  *
5  * @license GNU AGPL version 3 or any later version
6  *
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.
11  *
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.
16  *
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/>.
19  *
20  */
21
22 use Friendica\App;
23 use Friendica\Core\Hook;
24 use Friendica\Database\DBA;
25 use Friendica\DI;
26 use Friendica\Model\Group;
27 use Friendica\Model\Item;
28
29 function lockview_content(App $a)
30 {
31         $type = (($a->argc > 1) ? $a->argv[1] : 0);
32         if (is_numeric($type)) {
33                 $item_id = intval($type);
34                 $type = 'item';
35         } else {
36                 $item_id = (($a->argc > 2) ? intval($a->argv[2]) : 0);
37         }
38
39         if (!$item_id) {
40                 exit();
41         }
42
43         if (!in_array($type, ['item','photo','event'])) {
44                 exit();
45         }
46
47         $fields = ['uid', 'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid'];
48         $condition = ['id' => $item_id];
49
50         if ($type != 'item') {
51                 $item = DBA::selectFirst($type, $fields, $condition);
52         } else {
53                 $fields[] = 'private';
54                 $item = Item::selectFirst($fields, $condition);
55         }
56
57         if (!DBA::isResult($item)) {
58                 exit();
59         }
60
61         Hook::callAll('lockview_content', $item);
62
63         if ($item['uid'] != local_user()) {
64                 echo DI::l10n()->t('Remote privacy information not available.') . '<br />';
65                 exit();
66         }
67
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']))
74         {
75                 echo DI::l10n()->t('Remote privacy information not available.') . '<br />';
76                 exit();
77         }
78
79         $aclFormatter = DI::aclFormatter();
80
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']);
85
86         $o = DI::l10n()->t('Visible to:') . '<br />';
87         $l = [];
88
89         if (count($allowed_groups)) {
90                 $key = array_search(Group::FOLLOWERS, $allowed_groups);
91                 if ($key !== false) {
92                         $l[] = '<b>' . DI::l10n()->t('Followers') . '</b>';
93                         unset($allowed_groups[$key]);
94                 }
95
96                 $key = array_search(Group::MUTUALS, $allowed_groups);
97                 if ($key !== false) {
98                         $l[] = '<b>' . DI::l10n()->t('Mutuals') . '</b>';
99                         unset($allowed_groups[$key]);
100                 }
101
102
103                 $r = q("SELECT `name` FROM `group` WHERE `id` IN ( %s )",
104                         DBA::escape(implode(', ', $allowed_groups))
105                 );
106                 if (DBA::isResult($r)) {
107                         foreach ($r as $rr) {
108                                 $l[] = '<b>' . $rr['name'] . '</b>';
109                         }
110                 }
111         }
112
113         if (count($allowed_users)) {
114                 $r = q("SELECT `name` FROM `contact` WHERE `id` IN ( %s )",
115                         DBA::escape(implode(', ', $allowed_users))
116                 );
117                 if (DBA::isResult($r)) {
118                         foreach ($r as $rr) {
119                                 $l[] = $rr['name'];
120                         }
121                 }
122         }
123
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]);
129                 }
130
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]);
135                 }
136
137                 $r = q("SELECT `name` FROM `group` WHERE `id` IN ( %s )",
138                         DBA::escape(implode(', ', $deny_groups))
139                 );
140                 if (DBA::isResult($r)) {
141                         foreach ($r as $rr) {
142                                 $l[] = '<b><strike>' . $rr['name'] . '</strike></b>';
143                         }
144                 }
145         }
146
147         if (count($deny_users)) {
148                 $r = q("SELECT `name` FROM `contact` WHERE `id` IN ( %s )",
149                         DBA::escape(implode(', ', $deny_users))
150                 );
151                 if (DBA::isResult($r)) {
152                         foreach ($r as $rr) {
153                                 $l[] = '<strike>' . $rr['name'] . '</strike>';
154                         }
155                 }
156         }
157
158         echo $o . implode(', ', $l);
159         exit();
160
161 }