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