3 * @file mod/profperm.php
6 use Friendica\Core\Config;
7 use Friendica\Core\PConfig;
8 use Friendica\Database\DBM;
9 use Friendica\Model\Profile;
11 function profperm_init(App $a)
17 $which = $a->user['nickname'];
18 $profile = $a->argv[1];
20 Profile::load($a, $which, $profile);
24 function profperm_content(App $a) {
27 notice( t('Permission denied') . EOL);
33 notice( t('Invalid profile identifier.') . EOL );
37 // Switch to text mod interface if we have more than 'n' contacts or group members
39 $switchtotext = PConfig::get(local_user(),'system','groupedit_image_limit');
40 if (is_null($switchtotext)) {
41 $switchtotext = Config::get('system','groupedit_image_limit', 400);
44 if(($a->argc > 2) && intval($a->argv[1]) && intval($a->argv[2])) {
45 $r = q("SELECT `id` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `self` = 0
46 AND `network` = '%s' AND `id` = %d AND `uid` = %d LIMIT 1",
51 if (DBM::is_result($r))
52 $change = intval($a->argv[2]);
56 if(($a->argc > 1) && (intval($a->argv[1]))) {
57 $r = q("SELECT * FROM `profile` WHERE `id` = %d AND `uid` = %d AND `is-default` = 0 LIMIT 1",
61 if (! DBM::is_result($r)) {
62 notice( t('Invalid profile identifier.') . EOL );
67 $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `profile-id` = %d",
73 if (DBM::is_result($r))
74 foreach($r as $member)
75 $ingroup[] = $member['id'];
80 if(in_array($change,$ingroup)) {
81 q("UPDATE `contact` SET `profile-id` = 0 WHERE `id` = %d AND `uid` = %d",
87 q("UPDATE `contact` SET `profile-id` = %d WHERE `id` = %d AND `uid` = %d",
95 $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `profile-id` = %d",
103 if (DBM::is_result($r))
104 foreach($r as $member)
105 $ingroup[] = $member['id'];
108 $o .= '<h2>' . t('Profile Visibility Editor') . '</h2>';
110 $o .= '<h3>' . t('Profile') . ' \'' . $profile['profile-name'] . '\'</h3>';
112 $o .= '<div id="prof-edit-desc">' . t('Click on a contact to add or remove.') . '</div>';
116 $o .= '<div id="prof-update-wrapper">';
120 $o .= '<div id="prof-members-title">';
121 $o .= '<h3>' . t('Visible To') . '</h3>';
123 $o .= '<div id="prof-members">';
125 $textmode = (($switchtotext && (count($members) > $switchtotext)) ? true : false);
127 foreach($members as $member) {
129 $member['click'] = 'profChangeMember(' . $profile['id'] . ',' . $member['id'] . '); return true;';
130 $o .= micropro($member,true,'mpprof', $textmode);
133 $o .= '</div><div id="prof-members-end"></div>';
134 $o .= '<hr id="prof-separator" />';
136 $o .= '<div id="prof-all-contcts-title">';
137 $o .= '<h3>' . t("All Contacts \x28with secure profile access\x29") . '</h3>';
139 $o .= '<div id="prof-all-contacts">';
141 $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `blocked` = 0 and `pending` = 0 and `self` = 0
142 AND `network` = '%s' ORDER BY `name` ASC",
143 intval(local_user()),
147 if (DBM::is_result($r)) {
148 $textmode = (($switchtotext && (count($r) > $switchtotext)) ? true : false);
149 foreach($r as $member) {
150 if(! in_array($member['id'],$ingroup)) {
151 $member['click'] = 'profChangeMember(' . $profile['id'] . ',' . $member['id'] . '); return true;';
152 $o .= micropro($member,true,'mpprof',$textmode);
157 $o .= '</div><div id="prof-all-contacts-end"></div>';