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