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