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