]> git.mxchange.org Git - friendica.git/blob - mod/profperm.php
Merge branch 'master' of https://github.com/friendica/friendica
[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` = 'dfrn' AND `id` = %d AND `uid` = %d LIMIT 1",
41                         intval($a->argv[2]),
42                         intval(local_user())
43                 );
44                 if(count($r))
45                         $change = intval($a->argv[2]);
46         }
47
48
49         if(($a->argc > 1) && (intval($a->argv[1]))) {
50                 $r = q("SELECT * FROM `profile` WHERE `id` = %d AND `uid` = %d AND `is-default` = 0 LIMIT 1",
51                         intval($a->argv[1]),
52                         intval(local_user())
53                 );
54                 if(! count($r)) {
55                         notice( t('Invalid profile identifier.') . EOL );
56                         return;
57                 }
58                 $profile = $r[0];
59
60                 $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `profile-id` = %d",
61                         intval(local_user()),
62                         intval($a->argv[1])
63                 );
64
65                 $ingroup = array();
66                 if(count($r))
67                         foreach($r as $member)
68                                 $ingroup[] = $member['id'];
69
70                 $members = $r;
71
72                 if($change) {
73                         if(in_array($change,$ingroup)) {
74                                 q("UPDATE `contact` SET `profile-id` = 0 WHERE `id` = %d AND `uid` = %d LIMIT 1",
75                                         intval($change),
76                                         intval(local_user())
77                                 );
78                         }
79                         else {
80                                 q("UPDATE `contact` SET `profile-id` = %d WHERE `id` = %d AND `uid` = %d LIMIT 1",
81                                         intval($a->argv[1]),
82                                         intval($change),
83                                         intval(local_user())
84                                 );
85
86                         }
87
88                         $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `profile-id` = %d",
89                                 intval(local_user()),
90                                 intval($a->argv[1])
91                         );
92
93                         $members = $r;
94
95                         $ingroup = array();
96                         if(count($r))
97                                 foreach($r as $member)
98                                         $ingroup[] = $member['id'];
99                 }
100
101                 $o .= '<h2>' . t('Profile Visibility Editor') . '</h2>';
102
103                 $o .= '<h3>' . t('Profile') . ' \'' . $profile['profile-name'] . '\'</h3>';
104
105                 $o .= '<div id="prof-edit-desc">' . t('Click on a contact to add or remove.') . '</div>';
106
107         }
108
109         $o .= '<div id="prof-update-wrapper">';
110         if($change) 
111                 $o = '';
112         
113         $o .= '<div id="prof-members-title">';
114         $o .= '<h3>' . t('Visible To') . '</h3>';
115         $o .= '</div>';
116         $o .= '<div id="prof-members">';
117
118         $textmode = (($switchtotext && (count($members) > $switchtotext)) ? true : false);
119
120         foreach($members as $member) {
121                 if($member['url']) {
122                         $member['click'] = 'profChangeMember(' . $profile['id'] . ',' . $member['id'] . '); return true;';
123                         $o .= micropro($member,true,'mpprof', $textmode);
124                 }
125         }
126         $o .= '</div><div id="prof-members-end"></div>';
127         $o .= '<hr id="prof-separator" />';
128
129         $o .= '<div id="prof-all-contcts-title">';
130         $o .= '<h3>' . t("All Contacts \x28with secure profile access\x29") . '</h3>';
131         $o .= '</div>';
132         $o .= '<div id="prof-all-contacts">';
133                 
134                 $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `blocked` = 0 and `pending` = 0 and `self` = 0 
135                         AND `network` = 'dfrn' ORDER BY `name` ASC",
136                         intval(local_user())
137                 );
138
139                 if(count($r)) {
140                         $textmode = (($switchtotext && (count($r) > $switchtotext)) ? true : false);
141                         foreach($r as $member) {
142                                 if(! in_array($member['id'],$ingroup)) {
143                                         $member['click'] = 'profChangeMember(' . $profile['id'] . ',' . $member['id'] . '); return true;';
144                                         $o .= micropro($member,true,'mpprof',$textmode);
145                                 }
146                         }
147                 }
148
149                 $o .= '</div><div id="prof-all-contacts-end"></div>';
150
151         if($change) {
152                 echo $o;
153                 killme();
154         }
155         $o .= '</div>';
156         return $o;
157
158 }
159