]> git.mxchange.org Git - friendica.git/blob - mod/profperm.php
Merge branch 'dispy' of github.com:fabrixxm/friendika into dispy
[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">';
114         $o .= '<h3>' . t('Visible To') . '</h3>';
115
116         $textmode = (($switchtotext && (count($members) > $switchtotext)) ? true : false);
117
118         foreach($members as $member) {
119                 if($member['url']) {
120                         $member['click'] = 'profChangeMember(' . $profile['id'] . ',' . $member['id'] . '); return true;';
121                         $o .= micropro($member,true,'mpprof', $textmode);
122                 }
123         }
124         $o .= '</div><div id="prof-members-end"></div>';
125         $o .= '<hr id="prof-separator" />';
126         $o .= '<div id="prof-all-contacts">';
127
128                 $o .= '<h3>' . t("All Contacts \x28with secure profile access\x29") . '</h3>';
129                 $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `blocked` = 0 and `pending` = 0 and `self` = 0 
130                         AND `network` = 'dfrn' ORDER BY `name` ASC",
131                         intval(local_user())
132                 );
133
134                 if(count($r)) {
135                         $textmode = (($switchtotext && (count($r) > $switchtotext)) ? true : false);
136                         foreach($r as $member) {
137                                 if(! in_array($member['id'],$ingroup)) {
138                                         $member['click'] = 'profChangeMember(' . $profile['id'] . ',' . $member['id'] . '); return true;';
139                                         $o .= micropro($member,true,'mpprof',$textmode);
140                                 }
141                         }
142                 }
143
144                 $o .= '</div><div id="prof-all-contacts-end"></div>';
145
146         if($change) {
147                 echo $o;
148                 killme();
149         }
150         $o .= '</div>';
151         return $o;
152
153 }
154