]> git.mxchange.org Git - friendica.git/blob - src/Module/PermissionTooltip.php
Fix: Use correct condition to update the avatar
[friendica.git] / src / Module / PermissionTooltip.php
1 <?php
2
3 namespace Friendica\Module;
4
5 use Friendica\Core\Hook;
6 use Friendica\Database\DBA;
7 use Friendica\DI;
8 use Friendica\Model\Item;
9 use Friendica\Model\Group;
10 use Friendica\Model\Post;
11 use Friendica\Network\HTTPException;
12
13 /**
14  * Outputs the permission tooltip HTML content for the provided item, photo or event id.
15  */
16 class PermissionTooltip extends \Friendica\BaseModule
17 {
18         public static function rawContent(array $parameters = [])
19         {
20                 $type = $parameters['type'];
21                 $referenceId = $parameters['id'];
22
23                 $expectedTypes = ['item', 'photo', 'event'];
24                 if (!in_array($type, $expectedTypes)) {
25                         throw new HTTPException\BadRequestException(DI::l10n()->t('Wrong type "%s", expected one of: %s', $type, implode(', ', $expectedTypes)));
26                 }
27
28                 $condition = ['id' => $referenceId];
29                 if ($type == 'item') {
30                         $fields = ['uid', 'psid', 'private'];
31                         $model = Post::selectFirst($fields, $condition);
32                 } else {
33                         $fields = ['uid', 'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid'];
34                         $model = DBA::selectFirst($type, $fields, $condition);
35                 }
36
37                 if (!DBA::isResult($model)) {
38                         throw new HttpException\NotFoundException(DI::l10n()->t('Model not found'));
39                 }
40
41                 if (isset($model['psid'])) {
42                         $permissionSet = DI::permissionSet()->selectOneById($model['psid'], $model['uid']);
43                         $model['allow_cid'] = $permissionSet->allow_cid;
44                         $model['allow_gid'] = $permissionSet->allow_gid;
45                         $model['deny_cid']  = $permissionSet->deny_cid;
46                         $model['deny_gid']  = $permissionSet->deny_gid;
47                 }
48
49                 // Kept for backwards compatiblity
50                 Hook::callAll('lockview_content', $model);
51
52                 if ($model['uid'] != local_user() ||
53                         isset($model['private'])
54                         && $model['private'] == Item::PRIVATE
55                         && empty($model['allow_cid'])
56                         && empty($model['allow_gid'])
57                         && empty($model['deny_cid'])
58                         && empty($model['deny_gid']))
59                 {
60                         echo DI::l10n()->t('Remote privacy information not available.');
61                         exit;
62                 }
63
64                 $allowed_users  = $model['allow_cid'];
65                 $allowed_groups = $model['allow_gid'];
66                 $deny_users     = $model['deny_cid'];
67                 $deny_groups    = $model['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                         foreach (DI::dba()->selectToArray('group', ['name'], ['id' => $allowed_groups]) as $group) {
86                                 $l[] = '<b>' . $group['name'] . '</b>';
87                         }
88                 }
89
90                 foreach (DI::dba()->selectToArray('contact', ['name'], ['id' => $allowed_users]) as $contact) {
91                         $l[] = $contact['name'];
92                 }
93
94                 if (count($deny_groups)) {
95                         $key = array_search(Group::FOLLOWERS, $deny_groups);
96                         if ($key !== false) {
97                                 $l[] = '<b><strike>' . DI::l10n()->t('Followers') . '</strike></b>';
98                                 unset($deny_groups[$key]);
99                         }
100
101                         $key = array_search(Group::MUTUALS, $deny_groups);
102                         if ($key !== false) {
103                                 $l[] = '<b><strike>' . DI::l10n()->t('Mutuals') . '</strike></b>';
104                                 unset($deny_groups[$key]);
105                         }
106
107                         foreach (DI::dba()->selectToArray('group', ['name'], ['id' => $allowed_groups]) as $group) {
108                                 $l[] = '<b><strike>' . $group['name'] . '</strike></b>';
109                         }
110                 }
111
112                 foreach (DI::dba()->selectToArray('contact', ['name'], ['id' => $deny_users]) as $contact) {
113                         $l[] = '<strike>' . $contact['name'] . '</strike>';
114                 }
115
116                 echo $o . implode(', ', $l);
117                 exit();
118         }
119 }