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