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;
12 use Friendica\Model\Profile;
14 function profperm_init(App $a)
20 $which = $a->user['nickname'];
21 $profile = $a->argv[1];
23 Profile::load($a, $which, $profile);
27 function profperm_content(App $a) {
30 notice(L10n::t('Permission denied') . EOL);
36 notice(L10n::t('Invalid profile identifier.') . EOL );
42 // Switch to text mod interface if we have more than 'n' contacts or group members
44 $switchtotext = PConfig::get(local_user(),'system','groupedit_image_limit');
45 if (is_null($switchtotext)) {
46 $switchtotext = Config::get('system','groupedit_image_limit', 400);
49 if (($a->argc > 2) && intval($a->argv[1]) && intval($a->argv[2])) {
50 $r = q("SELECT `id` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `self` = 0
51 AND `network` = '%s' AND `id` = %d AND `uid` = %d LIMIT 1",
52 DBA::escape(Protocol::DFRN),
57 if (DBA::isResult($r)) {
58 $change = intval($a->argv[2]);
63 if (($a->argc > 1) && (intval($a->argv[1]))) {
64 $r = q("SELECT * FROM `profile` WHERE `id` = %d AND `uid` = %d AND `is-default` = 0 LIMIT 1",
68 if (!DBA::isResult($r)) {
69 notice(L10n::t('Invalid profile identifier.') . EOL );
74 $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `profile-id` = %d",
80 if (DBA::isResult($r))
81 foreach($r as $member)
82 $ingroup[] = $member['id'];
86 if (!empty($change)) {
87 if (in_array($change,$ingroup)) {
88 q("UPDATE `contact` SET `profile-id` = 0 WHERE `id` = %d AND `uid` = %d",
94 q("UPDATE `contact` SET `profile-id` = %d WHERE `id` = %d AND `uid` = %d",
102 $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `profile-id` = %d",
103 intval(local_user()),
110 if (DBA::isResult($r))
111 foreach($r as $member)
112 $ingroup[] = $member['id'];
115 $o .= '<h2>' . L10n::t('Profile Visibility Editor') . '</h2>';
117 $o .= '<h3>' . L10n::t('Profile') . ' \'' . $profile['profile-name'] . '\'</h3>';
119 $o .= '<div id="prof-edit-desc">' . L10n::t('Click on a contact to add or remove.') . '</div>';
123 $o .= '<div id="prof-update-wrapper">';
127 $o .= '<div id="prof-members-title">';
128 $o .= '<h3>' . L10n::t('Visible To') . '</h3>';
130 $o .= '<div id="prof-members">';
132 $textmode = (($switchtotext && (count($members) > $switchtotext)) ? true : false);
134 foreach($members as $member) {
135 if ($member['url']) {
136 $member['click'] = 'profChangeMember(' . $profile['id'] . ',' . $member['id'] . '); return true;';
137 $o .= HTML::micropro($member,true,'mpprof', $textmode);
140 $o .= '</div><div id="prof-members-end"></div>';
141 $o .= '<hr id="prof-separator" />';
143 $o .= '<div id="prof-all-contcts-title">';
144 $o .= '<h3>' . L10n::t("All Contacts \x28with secure profile access\x29") . '</h3>';
146 $o .= '<div id="prof-all-contacts">';
148 $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `blocked` = 0 and `pending` = 0 and `self` = 0
149 AND `network` = '%s' ORDER BY `name` ASC",
150 intval(local_user()),
151 DBA::escape(Protocol::DFRN)
154 if (DBA::isResult($r)) {
155 $textmode = (($switchtotext && (count($r) > $switchtotext)) ? true : false);
156 foreach($r as $member) {
157 if (!in_array($member['id'],$ingroup)) {
158 $member['click'] = 'profChangeMember(' . $profile['id'] . ',' . $member['id'] . '); return true;';
159 $o .= HTML::micropro($member,true,'mpprof',$textmode);
164 $o .= '</div><div id="prof-all-contacts-end"></div>';
166 if (!empty($change)) {