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