Reworked "remote" cookie handling
This commit is contained in:
@@ -120,7 +120,7 @@ class Session
|
||||
'my_url' => $a->getBaseURL() . '/profile/' . $user_record['nickname'],
|
||||
'my_address' => $user_record['nickname'] . '@' . substr($a->getBaseURL(), strpos($a->getBaseURL(), '://') + 3),
|
||||
'addr' => defaults($_SERVER, 'REMOTE_ADDR', '0.0.0.0'),
|
||||
'remote' => []
|
||||
'remote' => [],
|
||||
]);
|
||||
|
||||
$remote_contacts = DBA::select('contact', ['id', 'uid'], ['nurl' => Strings::normaliseLink($_SESSION['my_url']), 'rel' => [Contact::FOLLOWER, Contact::FRIEND], 'self' => false]);
|
||||
@@ -129,9 +129,7 @@ class Session
|
||||
continue;
|
||||
}
|
||||
|
||||
/// @todo Change it to this format to save space
|
||||
// $_SESSION['remote'][$contact['uid']] = $contact['id'];
|
||||
$_SESSION['remote'][$contact['uid']] = ['cid' => $contact['id'], 'uid' => $contact['uid']];
|
||||
$_SESSION['remote'][$contact['uid']] = $contact['id'];
|
||||
}
|
||||
DBA::close($remote_contacts);
|
||||
|
||||
@@ -216,4 +214,34 @@ class Session
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns contact ID for given user ID
|
||||
*
|
||||
* @param integer $uid User ID
|
||||
* @return integer Contact ID of visitor for given user ID
|
||||
*/
|
||||
public static function getVisitorContactIDForUserID($uid)
|
||||
{
|
||||
if (empty($_SESSION['remote'][$uid])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $_SESSION['remote'][$uid];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns User ID for given contact ID of the visitor
|
||||
*
|
||||
* @param integer $cid Contact ID
|
||||
* @return integer User ID for given contact ID of the visitor
|
||||
*/
|
||||
public static function getUserIDForVisitorContactID($cid)
|
||||
{
|
||||
if (empty($_SESSION['remote'])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return array_search($cid, $_SESSION['remote']);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -248,15 +248,10 @@ class Profile
|
||||
*/
|
||||
public static function getByNickname($nickname, $uid = 0, $profile_id = 0)
|
||||
{
|
||||
if (remote_user($uid) && !empty($_SESSION['remote'])) {
|
||||
foreach ($_SESSION['remote'] as $visitor) {
|
||||
if ($visitor['uid'] == $uid) {
|
||||
$contact = DBA::selectFirst('contact', ['profile-id'], ['id' => $visitor['cid']]);
|
||||
if (DBA::isResult($contact)) {
|
||||
$profile_id = $contact['profile-id'];
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (!empty(remote_user($uid))) {
|
||||
$contact = DBA::selectFirst('contact', ['profile-id'], ['id' => remote_user($uid)]);
|
||||
if (DBA::isResult($contact)) {
|
||||
$profile_id = $contact['profile-id'];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1130,7 +1125,7 @@ class Profile
|
||||
continue;
|
||||
}
|
||||
|
||||
$_SESSION['remote'][$contact['uid']] = ['cid' => $contact['id'], 'uid' => $contact['uid']];
|
||||
$_SESSION['remote'][$contact['uid']] = $contact['id'];
|
||||
}
|
||||
|
||||
$a->contact = $visitor;
|
||||
|
||||
@@ -14,8 +14,8 @@ use Friendica\Core\L10n;
|
||||
use Friendica\Core\Logger;
|
||||
use Friendica\Core\PConfig;
|
||||
use Friendica\Core\Protocol;
|
||||
use Friendica\Core\Renderer;
|
||||
use Friendica\Core\Session;
|
||||
use Friendica\Core\Renderer;
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\Model\Contact;
|
||||
use Friendica\Model\Item;
|
||||
@@ -71,13 +71,8 @@ class Post extends BaseObject
|
||||
$this->setTemplate('wall');
|
||||
$this->toplevel = $this->getId() == $this->getDataValue('parent');
|
||||
|
||||
if (!empty($_SESSION['remote']) && is_array($_SESSION['remote'])) {
|
||||
foreach ($_SESSION['remote'] as $visitor) {
|
||||
if ($visitor['cid'] == $this->getDataValue('contact-id')) {
|
||||
$this->visiting = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!empty(Session::getUserIDForVisitorContactID($this->getDataValue('contact-id')))) {
|
||||
$this->visiting = true;
|
||||
}
|
||||
|
||||
$this->writable = $this->getDataValue('writable') || $this->getDataValue('self');
|
||||
|
||||
Reference in New Issue
Block a user