]> git.mxchange.org Git - friendica.git/blob - mod/profperm.php
Merge pull request #6483 from MrPetovan/bug/fixes-after-2019-03-develop-rebase
[friendica.git] / mod / profperm.php
1 <?php
2 /**
3  * @file mod/profperm.php
4  */
5 use Friendica\App;
6 use Friendica\Core\Config;
7 use Friendica\Core\L10n;
8 use Friendica\Core\PConfig;
9 use Friendica\Core\Protocol;
10 use Friendica\Content\Text\HTML;
11 use Friendica\Database\DBA;
12 use Friendica\Model\Profile;
13
14 function profperm_init(App $a)
15 {
16         if (!local_user()) {
17                 return;
18         }
19
20         $which = $a->user['nickname'];
21         $profile = $a->argv[1];
22
23         Profile::load($a, $which, $profile);
24 }
25
26
27 function profperm_content(App $a) {
28
29         if (!local_user()) {
30                 notice(L10n::t('Permission denied') . EOL);
31                 return;
32         }
33
34
35         if ($a->argc < 2) {
36                 notice(L10n::t('Invalid profile identifier.') . EOL );
37                 return;
38         }
39
40         $o = '';
41
42         // Switch to text mod interface if we have more than 'n' contacts or group members
43
44         $switchtotext = PConfig::get(local_user(),'system','groupedit_image_limit');
45         if (is_null($switchtotext)) {
46                 $switchtotext = Config::get('system','groupedit_image_limit', 400);
47         }
48
49         if (($a->argc > 2) && intval($a->argv[1]) && intval($a->argv[2])) {
50                 $r = q("SELECT `id` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `self` = 0
51                         AND `network` = '%s' AND `id` = %d AND `uid` = %d LIMIT 1",
52                         DBA::escape(Protocol::DFRN),
53                         intval($a->argv[2]),
54                         intval(local_user())
55                 );
56
57                 if (DBA::isResult($r)) {
58                         $change = intval($a->argv[2]);
59                 }
60         }
61
62
63         if (($a->argc > 1) && (intval($a->argv[1]))) {
64                 $r = q("SELECT * FROM `profile` WHERE `id` = %d AND `uid` = %d AND `is-default` = 0 LIMIT 1",
65                         intval($a->argv[1]),
66                         intval(local_user())
67                 );
68                 if (!DBA::isResult($r)) {
69                         notice(L10n::t('Invalid profile identifier.') . EOL );
70                         return;
71                 }
72                 $profile = $r[0];
73
74                 $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `profile-id` = %d",
75                         intval(local_user()),
76                         intval($a->argv[1])
77                 );
78
79                 $ingroup = [];
80                 if (DBA::isResult($r))
81                         foreach($r as $member)
82                                 $ingroup[] = $member['id'];
83
84                 $members = $r;
85
86                 if (!empty($change)) {
87                         if (in_array($change,$ingroup)) {
88                                 q("UPDATE `contact` SET `profile-id` = 0 WHERE `id` = %d AND `uid` = %d",
89                                         intval($change),
90                                         intval(local_user())
91                                 );
92                         }
93                         else {
94                                 q("UPDATE `contact` SET `profile-id` = %d WHERE `id` = %d AND `uid` = %d",
95                                         intval($a->argv[1]),
96                                         intval($change),
97                                         intval(local_user())
98                                 );
99
100                         }
101
102                         $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `profile-id` = %d",
103                                 intval(local_user()),
104                                 intval($a->argv[1])
105                         );
106
107                         $members = $r;
108
109                         $ingroup = [];
110                         if (DBA::isResult($r))
111                                 foreach($r as $member)
112                                         $ingroup[] = $member['id'];
113                 }
114
115                 $o .= '<h2>' . L10n::t('Profile Visibility Editor') . '</h2>';
116
117                 $o .= '<h3>' . L10n::t('Profile') . ' \'' . $profile['profile-name'] . '\'</h3>';
118
119                 $o .= '<div id="prof-edit-desc">' . L10n::t('Click on a contact to add or remove.') . '</div>';
120
121         }
122
123         $o .= '<div id="prof-update-wrapper">';
124         if (!empty($change))
125                 $o = '';
126
127         $o .= '<div id="prof-members-title">';
128         $o .= '<h3>' . L10n::t('Visible To') . '</h3>';
129         $o .= '</div>';
130         $o .= '<div id="prof-members">';
131
132         $textmode = (($switchtotext && (count($members) > $switchtotext)) ? true : false);
133
134         foreach($members as $member) {
135                 if ($member['url']) {
136                         $member['click'] = 'profChangeMember(' . $profile['id'] . ',' . $member['id'] . '); return true;';
137                         $o .= HTML::micropro($member,true,'mpprof', $textmode);
138                 }
139         }
140         $o .= '</div><div id="prof-members-end"></div>';
141         $o .= '<hr id="prof-separator" />';
142
143         $o .= '<div id="prof-all-contcts-title">';
144         $o .= '<h3>' . L10n::t("All Contacts \x28with secure profile access\x29") . '</h3>';
145         $o .= '</div>';
146         $o .= '<div id="prof-all-contacts">';
147
148                 $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `blocked` = 0 and `pending` = 0 and `self` = 0
149                         AND `network` = '%s' ORDER BY `name` ASC",
150                         intval(local_user()),
151                         DBA::escape(Protocol::DFRN)
152                 );
153
154                 if (DBA::isResult($r)) {
155                         $textmode = (($switchtotext && (count($r) > $switchtotext)) ? true : false);
156                         foreach($r as $member) {
157                                 if (!in_array($member['id'],$ingroup)) {
158                                         $member['click'] = 'profChangeMember(' . $profile['id'] . ',' . $member['id'] . '); return true;';
159                                         $o .= HTML::micropro($member,true,'mpprof',$textmode);
160                                 }
161                         }
162                 }
163
164                 $o .= '</div><div id="prof-all-contacts-end"></div>';
165
166         if (!empty($change)) {
167                 echo $o;
168                 exit();
169         }
170         $o .= '</div>';
171         return $o;
172
173 }