3 * @file mod/profperm.php
6 use Friendica\Core\Config;
7 use Friendica\Core\L10n;
8 use Friendica\Core\PConfig;
9 use Friendica\Database\DBM;
10 use Friendica\Model\Profile;
12 function profperm_init(App $a)
18 $which = $a->user['nickname'];
19 $profile = $a->argv[1];
21 Profile::load($a, $which, $profile);
25 function profperm_content(App $a) {
28 notice(L10n::t('Permission denied') . EOL);
34 notice(L10n::t('Invalid profile identifier.') . EOL );
38 // Switch to text mod interface if we have more than 'n' contacts or group members
40 $switchtotext = PConfig::get(local_user(),'system','groupedit_image_limit');
41 if (is_null($switchtotext)) {
42 $switchtotext = Config::get('system','groupedit_image_limit', 400);
45 if(($a->argc > 2) && intval($a->argv[1]) && intval($a->argv[2])) {
46 $r = q("SELECT `id` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `self` = 0
47 AND `network` = '%s' AND `id` = %d AND `uid` = %d LIMIT 1",
52 if (DBM::is_result($r))
53 $change = intval($a->argv[2]);
57 if(($a->argc > 1) && (intval($a->argv[1]))) {
58 $r = q("SELECT * FROM `profile` WHERE `id` = %d AND `uid` = %d AND `is-default` = 0 LIMIT 1",
62 if (! DBM::is_result($r)) {
63 notice(L10n::t('Invalid profile identifier.') . EOL );
68 $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `profile-id` = %d",
74 if (DBM::is_result($r))
75 foreach($r as $member)
76 $ingroup[] = $member['id'];
81 if(in_array($change,$ingroup)) {
82 q("UPDATE `contact` SET `profile-id` = 0 WHERE `id` = %d AND `uid` = %d",
88 q("UPDATE `contact` SET `profile-id` = %d WHERE `id` = %d AND `uid` = %d",
96 $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `profile-id` = %d",
104 if (DBM::is_result($r))
105 foreach($r as $member)
106 $ingroup[] = $member['id'];
109 $o .= '<h2>' . L10n::t('Profile Visibility Editor') . '</h2>';
111 $o .= '<h3>' . L10n::t('Profile') . ' \'' . $profile['profile-name'] . '\'</h3>';
113 $o .= '<div id="prof-edit-desc">' . L10n::t('Click on a contact to add or remove.') . '</div>';
117 $o .= '<div id="prof-update-wrapper">';
121 $o .= '<div id="prof-members-title">';
122 $o .= '<h3>' . L10n::t('Visible To') . '</h3>';
124 $o .= '<div id="prof-members">';
126 $textmode = (($switchtotext && (count($members) > $switchtotext)) ? true : false);
128 foreach($members as $member) {
130 $member['click'] = 'profChangeMember(' . $profile['id'] . ',' . $member['id'] . '); return true;';
131 $o .= micropro($member,true,'mpprof', $textmode);
134 $o .= '</div><div id="prof-members-end"></div>';
135 $o .= '<hr id="prof-separator" />';
137 $o .= '<div id="prof-all-contcts-title">';
138 $o .= '<h3>' . L10n::t("All Contacts \x28with secure profile access\x29") . '</h3>';
140 $o .= '<div id="prof-all-contacts">';
142 $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `blocked` = 0 and `pending` = 0 and `self` = 0
143 AND `network` = '%s' ORDER BY `name` ASC",
144 intval(local_user()),
148 if (DBM::is_result($r)) {
149 $textmode = (($switchtotext && (count($r) > $switchtotext)) ? true : false);
150 foreach($r as $member) {
151 if(! in_array($member['id'],$ingroup)) {
152 $member['click'] = 'profChangeMember(' . $profile['id'] . ',' . $member['id'] . '); return true;';
153 $o .= micropro($member,true,'mpprof',$textmode);
158 $o .= '</div><div id="prof-all-contacts-end"></div>';