streams/mod/profperm.php

166 lines
3.9 KiB
PHP
Raw Normal View History

2011-04-13 04:25:00 +00:00
<?php
2014-01-23 22:35:59 +00:00
require_once('include/Contact.php');
2011-04-13 04:25:00 +00:00
function profperm_init(&$a) {
if(! local_user())
return;
2014-01-23 22:35:59 +00:00
$channel = $a->get_channel();
$which = $channel['channel_address'];
$profile = $a->argv[1];
2011-04-13 04:25:00 +00:00
profile_load($a,$which,$profile);
}
function profperm_content(&$a) {
if(! local_user()) {
notice( t('Permission denied') . EOL);
return;
}
2014-01-23 22:35:59 +00:00
if(argc() < 2) {
2011-04-13 04:25:00 +00:00
notice( t('Invalid profile identifier.') . EOL );
return;
}
// Switch to text mod interface if we have more than 'n' contacts or group members
$switchtotext = get_pconfig(local_user(),'system','groupedit_image_limit');
if($switchtotext === false)
$switchtotext = get_config('system','groupedit_image_limit');
if($switchtotext === false)
$switchtotext = 400;
2014-01-23 22:35:59 +00:00
if((argc() > 2) && intval(argv(1)) && intval(argv(2))) {
$r = q("SELECT abook_id FROM abook WHERE abook_id = %d and abook_channel = %d limit 1",
intval(argv(2)),
2011-04-13 04:25:00 +00:00
intval(local_user())
);
2014-01-23 22:35:59 +00:00
if($r)
$change = intval(argv(2));
2011-04-13 04:25:00 +00:00
}
2014-01-23 22:35:59 +00:00
if((argc() > 1) && (intval(argv(1)))) {
2012-08-31 01:17:38 +00:00
$r = q("SELECT * FROM `profile` WHERE `id` = %d AND `uid` = %d AND `is_default` = 0 LIMIT 1",
2014-01-23 22:35:59 +00:00
intval(argv(1)),
2011-04-13 04:25:00 +00:00
intval(local_user())
);
2014-01-23 22:35:59 +00:00
if(! $r) {
2011-04-13 04:25:00 +00:00
notice( t('Invalid profile identifier.') . EOL );
return;
}
2014-01-23 22:35:59 +00:00
2011-04-13 04:25:00 +00:00
$profile = $r[0];
$r = q("SELECT * FROM abook left join xchan on abook_xchan = xchan_hash WHERE abook_channel = %d AND abook_profile = '%s'",
2011-04-13 04:25:00 +00:00
intval(local_user()),
dbesc($profile['profile_guid'])
2011-04-13 04:25:00 +00:00
);
$ingroup = array();
2014-01-23 22:35:59 +00:00
if($r)
2011-04-13 04:25:00 +00:00
foreach($r as $member)
2014-01-23 22:35:59 +00:00
$ingroup[] = $member['abook_id'];
2011-04-13 04:25:00 +00:00
$members = $r;
if($change) {
if(in_array($change,$ingroup)) {
q("UPDATE abook SET abook_profile = '' WHERE abook_id = %d AND abook_channel = %d LIMIT 1",
2011-04-13 04:25:00 +00:00
intval($change),
intval(local_user())
);
}
else {
q("UPDATE abook SET abook_profile = '%s' WHERE abook_id = %d AND abook_channel = %d LIMIT 1",
dbesc($profile['profile_guid']),
2011-04-13 04:25:00 +00:00
intval($change),
intval(local_user())
);
}
2014-04-15 22:40:01 +00:00
//Time to update the permissions on the profile-pictures as well
require_once('mod/profile_photo.php');
profile_photo_set_profile_perms($profile['id']);
$r = q("SELECT * FROM abook left join xchan on abook_xchan = xchan_hash WHERE abook_channel = %d AND abook_profile = '%s'",
2011-04-13 04:25:00 +00:00
intval(local_user()),
dbesc($profile['profile_guid'])
2011-04-13 04:25:00 +00:00
);
$members = $r;
$ingroup = array();
if(count($r))
foreach($r as $member)
2014-01-23 22:35:59 +00:00
$ingroup[] = $member['abook_id'];
2011-04-13 04:25:00 +00:00
}
$o .= '<h2>' . t('Profile Visibility Editor') . '</h2>';
2012-08-27 08:22:08 +00:00
$o .= '<h3>' . t('Profile') . ' \'' . $profile['profile_name'] . '\'</h3>';
2011-04-13 04:25:00 +00:00
$o .= '<div id="prof-edit-desc">' . t('Click on a contact to add or remove.') . '</div>';
}
$o .= '<div id="prof-update-wrapper">';
if($change)
2011-04-13 04:25:00 +00:00
$o = '';
$o .= '<div id="prof-members-title">';
2011-04-13 04:25:00 +00:00
$o .= '<h3>' . t('Visible To') . '</h3>';
$o .= '</div>';
$o .= '<div id="prof-members">';
$textmode = (($switchtotext && (count($members) > $switchtotext)) ? true : false);
2011-04-13 04:25:00 +00:00
foreach($members as $member) {
2014-01-23 22:35:59 +00:00
if($member['xchan_url']) {
$member['click'] = 'profChangeMember(' . $profile['id'] . ',' . $member['abook_id'] . '); return false;';
$o .= micropro($member,true,'mpprof', $textmode);
2011-04-13 04:25:00 +00:00
}
}
$o .= '</div><div id="prof-members-end"></div>';
$o .= '<hr id="prof-separator" />';
$o .= '<div id="prof-all-contcts-title">';
2014-01-23 22:35:59 +00:00
$o .= '<h3>' . t("All Connections") . '</h3>';
$o .= '</div>';
$o .= '<div id="prof-all-contacts">';
2014-01-23 22:35:59 +00:00
$r = abook_connections(local_user());
2011-04-13 04:25:00 +00:00
2014-01-23 22:35:59 +00:00
if($r) {
$textmode = (($switchtotext && (count($r) > $switchtotext)) ? true : false);
2011-04-13 04:25:00 +00:00
foreach($r as $member) {
2014-01-23 22:35:59 +00:00
if(! in_array($member['abook_id'],$ingroup)) {
$member['click'] = 'profChangeMember(' . $profile['id'] . ',' . $member['abook_id'] . '); return false;';
$o .= micropro($member,true,'mpprof',$textmode);
2011-04-13 04:25:00 +00:00
}
}
}
$o .= '</div><div id="prof-all-contacts-end"></div>';
if($change) {
echo $o;
killme();
}
$o .= '</div>';
return $o;
}