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