3 * @file mod/profperm.php
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;
13 use Friendica\Model\Profile;
15 function profperm_init(App $a)
21 $which = $a->user['nickname'];
22 $profile = $a->argv[1];
24 Profile::load($a, $which, $profile);
28 function profperm_content(App $a) {
31 notice(L10n::t('Permission denied') . EOL);
37 notice(L10n::t('Invalid profile identifier.') . EOL );
43 // Switch to text mod interface if we have more than 'n' contacts or group members
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);
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),
58 if (DBA::isResult($r)) {
59 $change = intval($a->argv[2]);
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",
69 if (!DBA::isResult($r)) {
70 notice(L10n::t('Invalid profile identifier.') . EOL );
75 $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `profile-id` = %d",
81 if (DBA::isResult($r))
82 foreach($r as $member)
83 $ingroup[] = $member['id'];
87 if (!empty($change)) {
88 if (in_array($change,$ingroup)) {
89 q("UPDATE `contact` SET `profile-id` = 0 WHERE `id` = %d AND `uid` = %d",
95 q("UPDATE `contact` SET `profile-id` = %d WHERE `id` = %d AND `uid` = %d",
103 $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `profile-id` = %d",
104 intval(local_user()),
111 if (DBA::isResult($r))
112 foreach($r as $member)
113 $ingroup[] = $member['id'];
116 $o .= '<h2>' . L10n::t('Profile Visibility Editor') . '</h2>';
118 $o .= '<h3>' . L10n::t('Profile') . ' \'' . $profile['profile-name'] . '\'</h3>';
120 $o .= '<div id="prof-edit-desc">' . L10n::t('Click on a contact to add or remove.') . '</div>';
124 $o .= '<div id="prof-update-wrapper">';
128 $o .= '<div id="prof-members-title">';
129 $o .= '<h3>' . L10n::t('Visible To') . '</h3>';
131 $o .= '<div id="prof-members">';
133 $textmode = (($switchtotext && (count($members) > $switchtotext)) ? true : false);
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);
141 $o .= '</div><div id="prof-members-end"></div>';
142 $o .= '<hr id="prof-separator" />';
144 $o .= '<div id="prof-all-contcts-title">';
145 $o .= '<h3>' . L10n::t("All Contacts \x28with secure profile access\x29") . '</h3>';
147 $o .= '<div id="prof-all-contacts">';
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)
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);
165 $o .= '</div><div id="prof-all-contacts-end"></div>';
167 if (!empty($change)) {