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