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