3 * @file mod/profperm.php
6 use Friendica\Core\Config;
7 use Friendica\Core\Protocol;
8 use Friendica\Content\Text\HTML;
9 use Friendica\Database\DBA;
11 use Friendica\Model\Profile;
13 function profperm_init(App $a)
19 $which = $a->user['nickname'];
20 $profile = $a->argv[1];
22 Profile::load($a, $which, $profile);
26 function profperm_content(App $a) {
29 notice(DI::l10n()->t('Permission denied') . EOL);
35 notice(DI::l10n()->t('Invalid profile identifier.') . EOL );
41 // Switch to text mod interface if we have more than 'n' contacts or group members
43 $switchtotext = DI::pConfig()->get(local_user(),'system','groupedit_image_limit');
44 if (is_null($switchtotext)) {
45 $switchtotext = Config::get('system','groupedit_image_limit', 400);
48 if (($a->argc > 2) && intval($a->argv[1]) && intval($a->argv[2])) {
49 $r = q("SELECT `id` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `self` = 0
50 AND `network` = '%s' AND `id` = %d AND `uid` = %d LIMIT 1",
51 DBA::escape(Protocol::DFRN),
56 if (DBA::isResult($r)) {
57 $change = intval($a->argv[2]);
62 if (($a->argc > 1) && (intval($a->argv[1]))) {
63 $r = q("SELECT * FROM `profile` WHERE `id` = %d AND `uid` = %d AND `is-default` = 0 LIMIT 1",
67 if (!DBA::isResult($r)) {
68 notice(DI::l10n()->t('Invalid profile identifier.') . EOL );
73 $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `profile-id` = %d",
79 if (DBA::isResult($r))
80 foreach($r as $member)
81 $ingroup[] = $member['id'];
85 if (!empty($change)) {
86 if (in_array($change,$ingroup)) {
87 q("UPDATE `contact` SET `profile-id` = 0 WHERE `id` = %d AND `uid` = %d",
93 q("UPDATE `contact` SET `profile-id` = %d WHERE `id` = %d AND `uid` = %d",
101 $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `profile-id` = %d",
102 intval(local_user()),
109 if (DBA::isResult($r))
110 foreach($r as $member)
111 $ingroup[] = $member['id'];
114 $o .= '<h2>' . DI::l10n()->t('Profile Visibility Editor') . '</h2>';
116 $o .= '<h3>' . DI::l10n()->t('Profile') . ' \'' . $profile['profile-name'] . '\'</h3>';
118 $o .= '<div id="prof-edit-desc">' . DI::l10n()->t('Click on a contact to add or remove.') . '</div>';
122 $o .= '<div id="prof-update-wrapper">';
126 $o .= '<div id="prof-members-title">';
127 $o .= '<h3>' . DI::l10n()->t('Visible To') . '</h3>';
129 $o .= '<div id="prof-members">';
131 $textmode = (($switchtotext && (count($members) > $switchtotext)) ? true : false);
133 foreach($members as $member) {
134 if ($member['url']) {
135 $member['click'] = 'profChangeMember(' . $profile['id'] . ',' . $member['id'] . '); return true;';
136 $o .= HTML::micropro($member,true,'mpprof', $textmode);
139 $o .= '</div><div id="prof-members-end"></div>';
140 $o .= '<hr id="prof-separator" />';
142 $o .= '<div id="prof-all-contcts-title">';
143 $o .= '<h3>' . DI::l10n()->t("All Contacts \x28with secure profile access\x29") . '</h3>';
145 $o .= '<div id="prof-all-contacts">';
147 $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `blocked` = 0 and `pending` = 0 and `self` = 0
148 AND `network` = '%s' ORDER BY `name` ASC",
149 intval(local_user()),
150 DBA::escape(Protocol::DFRN)
153 if (DBA::isResult($r)) {
154 $textmode = (($switchtotext && (count($r) > $switchtotext)) ? true : false);
155 foreach($r as $member) {
156 if (!in_array($member['id'],$ingroup)) {
157 $member['click'] = 'profChangeMember(' . $profile['id'] . ',' . $member['id'] . '); return true;';
158 $o .= HTML::micropro($member,true,'mpprof',$textmode);
163 $o .= '</div><div id="prof-all-contacts-end"></div>';
165 if (!empty($change)) {