4 use Friendica\Core\Config;
5 use Friendica\Core\PConfig;
6 use Friendica\Database\DBM;
8 function profperm_init(App $a) {
14 $which = $a->user['nickname'];
15 $profile = $a->argv[1];
17 profile_load($a,$which,$profile);
22 function profperm_content(App $a) {
25 notice( t('Permission denied') . EOL);
31 notice( t('Invalid profile identifier.') . EOL );
35 // Switch to text mod interface if we have more than 'n' contacts or group members
37 $switchtotext = PConfig::get(local_user(),'system','groupedit_image_limit');
38 if (is_null($switchtotext)) {
39 $switchtotext = Config::get('system','groupedit_image_limit', 400);
42 if(($a->argc > 2) && intval($a->argv[1]) && intval($a->argv[2])) {
43 $r = q("SELECT `id` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `self` = 0
44 AND `network` = '%s' AND `id` = %d AND `uid` = %d LIMIT 1",
49 if (DBM::is_result($r))
50 $change = intval($a->argv[2]);
54 if(($a->argc > 1) && (intval($a->argv[1]))) {
55 $r = q("SELECT * FROM `profile` WHERE `id` = %d AND `uid` = %d AND `is-default` = 0 LIMIT 1",
59 if (! DBM::is_result($r)) {
60 notice( t('Invalid profile identifier.') . EOL );
65 $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `profile-id` = %d",
71 if (DBM::is_result($r))
72 foreach($r as $member)
73 $ingroup[] = $member['id'];
78 if(in_array($change,$ingroup)) {
79 q("UPDATE `contact` SET `profile-id` = 0 WHERE `id` = %d AND `uid` = %d",
85 q("UPDATE `contact` SET `profile-id` = %d WHERE `id` = %d AND `uid` = %d",
93 $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `profile-id` = %d",
101 if (DBM::is_result($r))
102 foreach($r as $member)
103 $ingroup[] = $member['id'];
106 $o .= '<h2>' . t('Profile Visibility Editor') . '</h2>';
108 $o .= '<h3>' . t('Profile') . ' \'' . $profile['profile-name'] . '\'</h3>';
110 $o .= '<div id="prof-edit-desc">' . t('Click on a contact to add or remove.') . '</div>';
114 $o .= '<div id="prof-update-wrapper">';
118 $o .= '<div id="prof-members-title">';
119 $o .= '<h3>' . t('Visible To') . '</h3>';
121 $o .= '<div id="prof-members">';
123 $textmode = (($switchtotext && (count($members) > $switchtotext)) ? true : false);
125 foreach($members as $member) {
127 $member['click'] = 'profChangeMember(' . $profile['id'] . ',' . $member['id'] . '); return true;';
128 $o .= micropro($member,true,'mpprof', $textmode);
131 $o .= '</div><div id="prof-members-end"></div>';
132 $o .= '<hr id="prof-separator" />';
134 $o .= '<div id="prof-all-contcts-title">';
135 $o .= '<h3>' . t("All Contacts \x28with secure profile access\x29") . '</h3>';
137 $o .= '<div id="prof-all-contacts">';
139 $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `blocked` = 0 and `pending` = 0 and `self` = 0
140 AND `network` = '%s' ORDER BY `name` ASC",
141 intval(local_user()),
145 if (DBM::is_result($r)) {
146 $textmode = (($switchtotext && (count($r) > $switchtotext)) ? true : false);
147 foreach($r as $member) {
148 if(! in_array($member['id'],$ingroup)) {
149 $member['click'] = 'profChangeMember(' . $profile['id'] . ',' . $member['id'] . '); return true;';
150 $o .= micropro($member,true,'mpprof',$textmode);
155 $o .= '</div><div id="prof-all-contacts-end"></div>';