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