remote_user can now support multiple contacts being logged in at once

This commit is contained in:
friendica 2012-09-04 22:50:28 -07:00
parent a9deda1e5e
commit 4cd8233f61
13 changed files with 226 additions and 73 deletions

View File

@ -1025,11 +1025,29 @@ if(! function_exists('get_max_import_size')) {
if(! function_exists('profile_load')) { if(! function_exists('profile_load')) {
function profile_load(&$a, $nickname, $profile = 0) { function profile_load(&$a, $nickname, $profile = 0) {
if(remote_user()) {
$user = q("select uid from user where nickname = '%s' limit 1",
dbesc($nickname)
);
if(! ($user && count($user))) {
logger('profile error: ' . $a->query_string, LOGGER_DEBUG);
notice( t('Requested account is not available.') . EOL );
$a->error = 404;
return;
}
if(remote_user() && count($_SESSION['remote'])) {
foreach($_SESSION['remote'] as $visitor) {
if($visitor['uid'] == $user[0]['uid']) {
$r = q("SELECT `profile-id` FROM `contact` WHERE `id` = %d LIMIT 1", $r = q("SELECT `profile-id` FROM `contact` WHERE `id` = %d LIMIT 1",
intval($_SESSION['visitor_id'])); intval($visitor['cid'])
);
if(count($r)) if(count($r))
$profile = $r[0]['profile-id']; $profile = $r[0]['profile-id'];
break;
}
}
} }
$r = null; $r = null;
@ -1144,8 +1162,14 @@ if(! function_exists('profile_sidebar')) {
// don't show connect link to authenticated visitors either // don't show connect link to authenticated visitors either
if((remote_user()) && ($_SESSION['visitor_visiting'] == $profile['uid'])) if(remote_user() && count($_SESSION['remote'])) {
$connect = False; foreach($_SESSION['remote'] as $visitor) {
if($visitor['uid'] == $profile['uid']) {
$connect = false;
break;
}
}
}
if(get_my_url() && $profile['unkmail']) if(get_my_url() && $profile['unkmail'])
$wallmessage = t('Message'); $wallmessage = t('Message');

View File

@ -142,9 +142,16 @@ function common_friends_visitor_widget($profile_uid) {
$cid = $zcid = 0; $cid = $zcid = 0;
if(can_write_wall($a,$profile_uid)) if(is_array($_SESSION['remote'])) {
$cid = remote_user(); foreach($_SESSION['remote'] as $visitor) {
else { if($visitor['uid'] == $profile_uid) {
$cid = $visitor['cid'];
break;
}
}
}
if(! $cid) {
if(get_my_url()) { if(get_my_url()) {
$r = q("select id from contact where nurl = '%s' and uid = %d limit 1", $r = q("select id from contact where nurl = '%s' and uid = %d limit 1",
dbesc(normalise_link(get_my_url())), dbesc(normalise_link(get_my_url())),

View File

@ -411,8 +411,17 @@ function prepare_threads_body($a, $items, $cmnt_tpl, $page_writeable, $mode, $pr
$edpost = array($a->get_baseurl($ssl_state)."/editpost/".$item['id'], t("Edit")); $edpost = array($a->get_baseurl($ssl_state)."/editpost/".$item['id'], t("Edit"));
else else
$edpost = false; $edpost = false;
if((intval($item['contact-id']) && $item['contact-id'] == remote_user()) || ($item['uid'] == local_user()))
if($item['uid'] == local_user())
$dropping = true; $dropping = true;
elseif(is_array($_SESSION['remote'])) {
foreach($_SESSION['remote'] as $visitor) {
if($visitor['cid'] == $item['contact-id']) {
$dropping = true;
break;
}
}
}
$drop = array( $drop = array(
'dropping' => $dropping, 'dropping' => $dropping,

View File

@ -3702,9 +3702,21 @@ function drop_item($id,$interactive = true) {
$owner = $item['uid']; $owner = $item['uid'];
$cid = 0;
// check if logged in user is either the author or owner of this item // check if logged in user is either the author or owner of this item
if((local_user() == $item['uid']) || (remote_user() == $item['contact-id']) || (! $interactive)) { if(is_array($_SESSION['remote'])) {
foreach($_SESSION['remote'] as $visitor) {
if($visitor['uid'] == $item['uid'] && $visitor['cid'] == $item['contact-id']) {
$cid = $visitor['cid'];
break;
}
}
}
if((local_user() == $item['uid']) || ($cid) || (! $interactive)) {
logger('delete item: ' . $item['id'], LOGGER_DEBUG); logger('delete item: ' . $item['id'], LOGGER_DEBUG);
// delete the item // delete the item

View File

@ -120,12 +120,26 @@ function can_write_wall(&$a,$owner) {
elseif($verified === 1) elseif($verified === 1)
return false; return false;
else { else {
$cid = 0;
if(is_array($_SESSION['remote'])) {
foreach($_SESSION['remote'] as $visitor) {
if($visitor['uid'] == $owner) {
$cid = $visitor['cid'];
break;
}
}
}
if(! $cid)
return false;
$r = q("SELECT `contact`.*, `user`.`page-flags` FROM `contact` LEFT JOIN `user` on `user`.`uid` = `contact`.`uid` $r = q("SELECT `contact`.*, `user`.`page-flags` FROM `contact` LEFT JOIN `user` on `user`.`uid` = `contact`.`uid`
WHERE `contact`.`uid` = %d AND `contact`.`id` = %d AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0 WHERE `contact`.`uid` = %d AND `contact`.`id` = %d AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
AND `user`.`blockwall` = 0 AND `readonly` = 0 AND ( `contact`.`rel` IN ( %d , %d ) OR `user`.`page-flags` = %d ) LIMIT 1", AND `user`.`blockwall` = 0 AND `readonly` = 0 AND ( `contact`.`rel` IN ( %d , %d ) OR `user`.`page-flags` = %d ) LIMIT 1",
intval($owner), intval($owner),
intval(remote_user()), intval($cid),
intval(CONTACT_IS_SHARING), intval(CONTACT_IS_SHARING),
intval(CONTACT_IS_FRIEND), intval(CONTACT_IS_FRIEND),
intval(PAGE_COMMUNITY) intval(PAGE_COMMUNITY)

View File

@ -87,6 +87,11 @@ function dfrn_poll_init(&$a) {
if((int) $xml->status == 1) { if((int) $xml->status == 1) {
$_SESSION['authenticated'] = 1; $_SESSION['authenticated'] = 1;
if(! x($_SESSION,'remote'))
$_SESSION['remote'] = array();
$_SESSION['remote'][] = array('cid' => $r[0]['id'],'uid' => $r[0]['uid'],'url' => $r[0]['url']);
$_SESSION['visitor_id'] = $r[0]['id']; $_SESSION['visitor_id'] = $r[0]['id'];
$_SESSION['visitor_home'] = $r[0]['url']; $_SESSION['visitor_home'] = $r[0]['url'];
$_SESSION['visitor_handle'] = $r[0]['addr']; $_SESSION['visitor_handle'] = $r[0]['addr'];
@ -516,6 +521,9 @@ function dfrn_poll_content(&$a) {
if(((int) $xml->status == 0) && ($xml->challenge == $hash) && ($xml->sec == $sec)) { if(((int) $xml->status == 0) && ($xml->challenge == $hash) && ($xml->sec == $sec)) {
$_SESSION['authenticated'] = 1; $_SESSION['authenticated'] = 1;
if(! x($_SESSION,'remote'))
$_SESSION['remote'] = array();
$_SESSION['remote'][] = array('cid' => $r[0]['id'],'uid' => $r[0]['uid'],'url' => $r[0]['url']);
$_SESSION['visitor_id'] = $r[0]['id']; $_SESSION['visitor_id'] = $r[0]['id'];
$_SESSION['visitor_home'] = $r[0]['url']; $_SESSION['visitor_home'] = $r[0]['url'];
$_SESSION['visitor_visiting'] = $r[0]['uid']; $_SESSION['visitor_visiting'] = $r[0]['uid'];

View File

@ -35,8 +35,18 @@ function display_content(&$a) {
$contact = null; $contact = null;
$remote_contact = false; $remote_contact = false;
if(remote_user()) { $contact_id = 0;
$contact_id = $_SESSION['visitor_id'];
if(is_array($_SESSION['remote'])) {
foreach($_SESSION['remote'] as $v) {
if($v['uid'] == $a->profile['uid']) {
$contact_id = $v['cid'];
break;
}
}
}
if($contact_id) {
$groups = init_groups_visitor($contact_id); $groups = init_groups_visitor($contact_id);
$r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1", $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
intval($contact_id), intval($contact_id),

View File

@ -306,6 +306,7 @@ function item_post(&$a) {
$author = null; $author = null;
$self = false; $self = false;
$contact_id = 0;
if((local_user()) && (local_user() == $profile_uid)) { if((local_user()) && (local_user() == $profile_uid)) {
$self = true; $self = true;
@ -314,10 +315,20 @@ function item_post(&$a) {
); );
} }
elseif(remote_user()) { elseif(remote_user()) {
if(is_array($_SESSION['remote'])) {
foreach($_SESSION['remote'] as $v) {
if($v['uid'] == $profile_uid) {
$contact_id = $v['cid'];
break;
}
}
}
if($contact_id) {
$r = q("SELECT * FROM `contact` WHERE `id` = %d LIMIT 1", $r = q("SELECT * FROM `contact` WHERE `id` = %d LIMIT 1",
intval(remote_user()) intval($contact_id)
); );
} }
}
if(count($r)) { if(count($r)) {
$author = $r[0]; $author = $r[0];

View File

@ -101,13 +101,25 @@ function photos_post(&$a) {
$can_post = true; $can_post = true;
else { else {
if($community_page && remote_user()) { if($community_page && remote_user()) {
$cid = 0;
if(is_array($_SESSION['remote'])) {
foreach($_SESSION['remote'] as $v) {
if($v['uid'] == $page_owner_uid) {
$cid = $v['cid'];
break;
}
}
}
if($cid) {
$r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1", $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
intval(remote_user()), intval($cid),
intval($page_owner_uid) intval($page_owner_uid)
); );
if(count($r)) { if(count($r)) {
$can_post = true; $can_post = true;
$visitor = remote_user(); $visitor = $cid;
}
} }
} }
} }
@ -871,6 +883,7 @@ function photos_content(&$a) {
$visitor = 0; $visitor = 0;
$contact = null; $contact = null;
$remote_contact = false; $remote_contact = false;
$contact_id = 0;
$owner_uid = $a->data['user']['uid']; $owner_uid = $a->data['user']['uid'];
@ -880,15 +893,26 @@ function photos_content(&$a) {
$can_post = true; $can_post = true;
else { else {
if($community_page && remote_user()) { if($community_page && remote_user()) {
if(is_array($_SESSION['remote'])) {
foreach($_SESSION['remote'] as $v) {
if($v['uid'] == $owner_uid) {
$contact_id = $v['cid'];
break;
}
}
}
if($contact_id) {
$r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1", $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
intval(remote_user()), intval($contact_id),
intval($owner_uid) intval($owner_uid)
); );
if(count($r)) { if(count($r)) {
$can_post = true; $can_post = true;
$contact = $r[0]; $contact = $r[0];
$remote_contact = true; $remote_contact = true;
$visitor = remote_user(); $visitor = $cid;
}
} }
} }
} }
@ -896,10 +920,19 @@ function photos_content(&$a) {
// perhaps they're visiting - but not a community page, so they wouldn't have write access // perhaps they're visiting - but not a community page, so they wouldn't have write access
if(remote_user() && (! $visitor)) { if(remote_user() && (! $visitor)) {
$contact_id = $_SESSION['visitor_id']; $contact_id = 0;
if(is_array($_SESSION['remote'])) {
foreach($_SESSION['remote'] as $v) {
if($v['uid'] == $owner_uid) {
$contact_id = $v['cid'];
break;
}
}
}
if($contact_id) {
$groups = init_groups_visitor($contact_id); $groups = init_groups_visitor($contact_id);
$r = q("SELECT * FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1", $r = q("SELECT * FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
intval(remote_user()), intval($contact_id),
intval($owner_uid) intval($owner_uid)
); );
if(count($r)) { if(count($r)) {
@ -907,6 +940,7 @@ function photos_content(&$a) {
$remote_contact = true; $remote_contact = true;
} }
} }
}
if(! $remote_contact) { if(! $remote_contact) {
if(local_user()) { if(local_user()) {
@ -1422,7 +1456,7 @@ function photos_content(&$a) {
$drop = ''; $drop = '';
if(($item['contact-id'] == remote_user()) || ($item['uid'] == local_user())) if(($item['contact-id'] == $contact_id) || ($item['uid'] == local_user()))
$drop = replace_macros(get_markup_template('photo_drop.tpl'), array('$id' => $item['id'], '$delete' => t('Delete'))); $drop = replace_macros(get_markup_template('photo_drop.tpl'), array('$id' => $item['id'], '$delete' => t('Delete')));

View File

@ -116,8 +116,18 @@ function profile_content(&$a, $update = 0) {
$contact = null; $contact = null;
$remote_contact = false; $remote_contact = false;
if(remote_user()) { $contact_id = 0;
$contact_id = $_SESSION['visitor_id'];
if(is_array($_SESSION['remote'])) {
foreach($_SESSION['remote'] as $v) {
if($v['uid'] == $a->profile['profile_uid']) {
$contact_id = $v['cid'];
break;
}
}
}
if($contact_id) {
$groups = init_groups_visitor($contact_id); $groups = init_groups_visitor($contact_id);
$r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1", $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
intval($contact_id), intval($contact_id),

View File

@ -47,17 +47,9 @@ function tagger_content(&$a) {
if(local_user() != $owner_uid) if(local_user() != $owner_uid)
return; return;
if(remote_user()) {
$r = q("select * from contact where id = %d AND `uid` = %d limit 1",
intval(remote_user()),
intval($item['uid'])
);
}
else {
$r = q("select * from contact where self = 1 and uid = %d limit 1", $r = q("select * from contact where self = 1 and uid = %d limit 1",
intval(local_user()) intval(local_user())
); );
}
if(count($r)) if(count($r))
$contact = $r[0]; $contact = $r[0];
else { else {

View File

@ -29,17 +29,28 @@ function wall_attach_post(&$a) {
$can_post = true; $can_post = true;
else { else {
if($community_page && remote_user()) { if($community_page && remote_user()) {
$cid = 0;
if(is_array($_SESSION['remote'])) {
foreach($_SESSION['remote'] as $v) {
if($v['uid'] == $page_owner_uid) {
$cid = $v['cid'];
break;
}
}
}
if($cid) {
$r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1", $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
intval(remote_user()), intval($cid),
intval($page_owner_uid) intval($page_owner_uid)
); );
if(count($r)) { if(count($r)) {
$can_post = true; $can_post = true;
$visitor = remote_user(); $visitor = $cid;
}
} }
} }
} }
if(! $can_post) { if(! $can_post) {
notice( t('Permission denied.') . EOL ); notice( t('Permission denied.') . EOL );
killme(); killme();

View File

@ -37,14 +37,25 @@ function wall_upload_post(&$a) {
$can_post = true; $can_post = true;
else { else {
if($community_page && remote_user()) { if($community_page && remote_user()) {
$cid = 0;
if(is_array($_SESSION['remote'])) {
foreach($_SESSION['remote'] as $v) {
if($v['uid'] == $page_owner_uid) {
$cid = $v['cid'];
break;
}
}
}
if($cid) {
$r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1", $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
intval(remote_user()), intval($cid),
intval($page_owner_uid) intval($page_owner_uid)
); );
if(count($r)) { if(count($r)) {
$can_post = true; $can_post = true;
$visitor = remote_user(); $visitor = $cid;
$default_cid = $visitor; }
} }
} }
} }