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