]> git.mxchange.org Git - friendica.git/commitdiff
remote_user can now support multiple contacts being logged in at once
authorfriendica <info@friendica.com>
Wed, 5 Sep 2012 05:50:28 +0000 (22:50 -0700)
committerfriendica <info@friendica.com>
Wed, 5 Sep 2012 05:50:28 +0000 (22:50 -0700)
13 files changed:
boot.php
include/contact_widgets.php
include/conversation.php
include/items.php
include/security.php
mod/dfrn_poll.php
mod/display.php
mod/item.php
mod/photos.php
mod/profile.php
mod/tagger.php
mod/wall_attach.php
mod/wall_upload.php

index 03999e31ac3e554e6b1ffaf11dde447c990ea47c..bb58d28086b2d3c26bb755a8b8e9e2b7f9fc4f12 100644 (file)
--- a/boot.php
+++ b/boot.php
@@ -1025,11 +1025,29 @@ if(! function_exists('get_max_import_size')) {
 
 if(! function_exists('profile_load')) {
        function profile_load(&$a, $nickname, $profile = 0) {
-               if(remote_user()) {
-                       $r = q("SELECT `profile-id` FROM `contact` WHERE `id` = %d LIMIT 1",
-                                       intval($_SESSION['visitor_id']));
-                       if(count($r))
-                               $profile = $r[0]['profile-id'];
+
+               $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",
+                                               intval($visitor['cid'])
+                                       );
+                                       if(count($r))
+                                               $profile = $r[0]['profile-id'];
+                                       break;
+                               }
+                       }
                }
 
                $r = null;
@@ -1144,8 +1162,14 @@ if(! function_exists('profile_sidebar')) {
 
                // don't show connect link to authenticated visitors either
 
-               if((remote_user()) && ($_SESSION['visitor_visiting'] == $profile['uid']))
-                       $connect = False;
+               if(remote_user() && count($_SESSION['remote'])) {
+                       foreach($_SESSION['remote'] as $visitor) {
+                               if($visitor['uid'] == $profile['uid']) {
+                                       $connect = false;
+                                       break;
+                               }
+                       }
+               }
 
                if(get_my_url() && $profile['unkmail'])
                        $wallmessage = t('Message');
index ce1cdbad55e003b647a0ca75c83e2b8e11a337ef..ea71b3b707b35b5a2fe3c3d5c976eb6be15ace63 100644 (file)
@@ -142,9 +142,16 @@ function common_friends_visitor_widget($profile_uid) {
 
        $cid = $zcid = 0;
 
-       if(can_write_wall($a,$profile_uid))
-               $cid = remote_user();
-       else {
+       if(is_array($_SESSION['remote'])) {
+               foreach($_SESSION['remote'] as $visitor) {
+                       if($visitor['uid'] == $profile_uid) {
+                               $cid = $visitor['cid'];
+                               break;
+                       }
+               }
+       }
+
+       if(! $cid) {
                if(get_my_url()) {
                        $r = q("select id from contact where nurl = '%s' and uid = %d limit 1",
                                dbesc(normalise_link(get_my_url())),
index 1fc0642856015b4b0d80f690460662f53547e09a..13dfeeadd6d0d088b94572ae9fdee03f6c0299b2 100644 (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"));
                else
                        $edpost = false;
-               if((intval($item['contact-id']) && $item['contact-id'] == remote_user()) || ($item['uid'] == local_user()))
+
+               if($item['uid'] == local_user())
                        $dropping = true;
+               elseif(is_array($_SESSION['remote'])) {
+                       foreach($_SESSION['remote'] as $visitor) {
+                               if($visitor['cid'] == $item['contact-id']) {
+                                       $dropping = true;
+                                       break;
+                               }
+                       }
+               }
 
                $drop = array(
                        'dropping' => $dropping,
index 8de6f7cc8eb2b4faa465e3a0715512f9aaee2f11..8039066af40002d525949f355106339476965d66 100755 (executable)
@@ -3702,9 +3702,21 @@ function drop_item($id,$interactive = true) {
 
        $owner = $item['uid'];
 
+       $cid = 0;
+
        // 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);
                // delete the item
index af201d2af1853afd41284ee5306e49d6fe9500ea..4621148cd921d0094f9f2a5046defa6e15bf0ffe 100644 (file)
@@ -120,12 +120,26 @@ function can_write_wall(&$a,$owner) {
                elseif($verified === 1)
                        return false;
                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` 
                                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",
                                intval($owner),
-                               intval(remote_user()),
+                               intval($cid),
                                intval(CONTACT_IS_SHARING),
                                intval(CONTACT_IS_FRIEND),
                                intval(PAGE_COMMUNITY)
index f3c14541024f39a0d9e4e4e2b20b62bae510039b..0d703dfb3122523a2b3484665e91ead80cef7e2d 100644 (file)
@@ -87,6 +87,11 @@ function dfrn_poll_init(&$a) {
 
                                if((int) $xml->status == 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_home'] = $r[0]['url'];
                                        $_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)) {
                                        $_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_home'] = $r[0]['url'];
                                        $_SESSION['visitor_visiting'] = $r[0]['uid'];
index afa61ef026022256304d3e846b2bb9f7b25ea594..64df4cc6a9d7fc36a952a107f2845ccfaa21bf7c 100644 (file)
@@ -35,8 +35,18 @@ function display_content(&$a) {
        $contact = null;
        $remote_contact = false;
 
-       if(remote_user()) {
-               $contact_id = $_SESSION['visitor_id'];
+       $contact_id = 0;
+
+       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);
                $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
                        intval($contact_id),
index 6c1c06f99a901ea505dba9368252285ad821936e..e3230c86436bebfb2f730bdb32ee7804d8d896aa 100644 (file)
@@ -306,6 +306,7 @@ function item_post(&$a) {
 
        $author = null;
        $self   = false;
+       $contact_id = 0;
 
        if((local_user()) && (local_user() == $profile_uid)) {
                $self = true;
@@ -314,9 +315,19 @@ function item_post(&$a) {
                );
        }
        elseif(remote_user()) {
-               $r = q("SELECT * FROM `contact` WHERE `id` = %d LIMIT 1",
-                       intval(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",
+                               intval($contact_id)
+                       );
+               }
        }
 
        if(count($r)) {
index fa2ddb347734056c37e41356bda0706ab4c88835..cf924f399d229ba5e4e5188980e00bb434732663 100644 (file)
@@ -101,13 +101,25 @@ function photos_post(&$a) {
                $can_post = true;
        else {
                if($community_page && remote_user()) {
-                       $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
-                               intval(remote_user()),
-                               intval($page_owner_uid)
-                       );
-                       if(count($r)) {
-                               $can_post = true;
-                               $visitor = 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",
+                                       intval($cid),
+                                       intval($page_owner_uid)
+                               );
+                               if(count($r)) {
+                                       $can_post = true;
+                                       $visitor = $cid;
+                               }
                        }
                }
        }
@@ -871,6 +883,7 @@ function photos_content(&$a) {
        $visitor        = 0;
        $contact        = null;
        $remote_contact = false;
+       $contact_id     = 0;
 
        $owner_uid = $a->data['user']['uid'];
 
@@ -880,15 +893,26 @@ function photos_content(&$a) {
                $can_post = true;
        else {
                if($community_page && remote_user()) {
-                       $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
-                               intval(remote_user()),
-                               intval($owner_uid)
-                       );
-                       if(count($r)) {
-                               $can_post = true;
-                               $contact  = $r[0];
-                               $remote_contact = true;
-                               $visitor = 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",
+                                       intval($contact_id),
+                                       intval($owner_uid)
+                               );
+                               if(count($r)) {
+                                       $can_post = true;
+                                       $contact = $r[0];
+                                       $remote_contact = true;
+                                       $visitor = $cid;
+                               }
                        }
                }
        }
@@ -896,15 +920,25 @@ function photos_content(&$a) {
        // perhaps they're visiting - but not a community page, so they wouldn't have write access
 
        if(remote_user() && (! $visitor)) {
-               $contact_id = $_SESSION['visitor_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",
-                       intval(remote_user()),
-                       intval($owner_uid)
-               );
-               if(count($r)) {
-                       $contact = $r[0];
-                       $remote_contact = true;
+               $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);
+                       $r = q("SELECT * FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
+                               intval($contact_id),
+                               intval($owner_uid)
+                       );
+                       if(count($r)) {
+                               $contact = $r[0];
+                               $remote_contact = true;
+                       }
                }
        }
 
@@ -1422,7 +1456,7 @@ function photos_content(&$a) {
 
                                        $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')));
 
 
index 24cadef3b26ae8e6683293a43ce2c60ade8d676f..a4dce791802b8ad974599846fd55185a0d04424c 100644 (file)
@@ -116,8 +116,18 @@ function profile_content(&$a, $update = 0) {
        $contact = null;
        $remote_contact = false;
 
-       if(remote_user()) {
-               $contact_id = $_SESSION['visitor_id'];
+       $contact_id = 0;
+
+       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);
                $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
                        intval($contact_id),
index 6212e2b9b3e82932b8ea2982051db4125b6caece..6ae0cebf718ef40774c70e2865aff3e77ce72328 100644 (file)
@@ -47,17 +47,9 @@ function tagger_content(&$a) {
        if(local_user() != $owner_uid)
                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",
-                       intval(local_user())
-               );
-       }
+       $r = q("select * from contact where self = 1 and uid = %d limit 1",
+               intval(local_user())
+       );
        if(count($r))
                        $contact = $r[0];
        else {
index f179b3ca5078bbb66a717d6b8d5bf2f1875ce0f9..c23efc7869a7181985afdd73c385dd5d43a74c2a 100644 (file)
@@ -29,17 +29,28 @@ function wall_attach_post(&$a) {
                $can_post = true;
        else {
                if($community_page && remote_user()) {
-                       $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
-                               intval(remote_user()),
-                               intval($page_owner_uid)
-                       );
-                       if(count($r)) {
-                               $can_post = true;
-                               $visitor = 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",
+                                       intval($cid),
+                                       intval($page_owner_uid)
+                               );
+                               if(count($r)) {
+                                       $can_post = true;
+                                       $visitor = $cid;
+                               }
                        }
                }
        }
-
        if(! $can_post) {
                notice( t('Permission denied.') . EOL );
                killme();
index 07d97d17a9e21fa15809a7f325d81c554409657d..ee1bf3c14c68742a8e78aeb0a64bcad7240dbc46 100644 (file)
@@ -37,14 +37,25 @@ function wall_upload_post(&$a) {
                $can_post = true;
        else {
                if($community_page && remote_user()) {
-                       $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
-                               intval(remote_user()),
-                               intval($page_owner_uid)
-                       );
-                       if(count($r)) {
-                               $can_post = true;
-                               $visitor = remote_user();
-                               $default_cid = $visitor;
+                       $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",
+                                       intval($cid),
+                                       intval($page_owner_uid)
+                               );
+                               if(count($r)) {
+                                       $can_post = true;
+                                       $visitor = $cid;
+                               }
                        }
                }
        }