4 * @file src/Core/Session.php
6 namespace Friendica\Core;
8 use Friendica\BaseObject;
9 use Friendica\Core\Session\ISession;
10 use Friendica\Database\DBA;
11 use Friendica\Model\Contact;
12 use Friendica\Util\Strings;
15 * High-level Session service class
17 * @author Hypolite Petovan <hypolite@mrpetovan.com>
19 class Session extends BaseObject
21 public static $exists = false;
22 public static $expire = 180000;
24 public static function exists($name)
26 return self::getClass(ISession::class)->exists($name);
29 public static function get($name, $defaults = null)
31 return self::getClass(ISession::class)->get($name, $defaults);
34 public static function set($name, $value)
36 self::getClass(ISession::class)->set($name, $value);
39 public static function setMultiple(array $values)
41 self::getClass(ISession::class)->setMultiple($values);
44 public static function remove($name)
46 self::getClass(ISession::class)->remove($name);
49 public static function clear()
51 self::getClass(ISession::class)->clear();
55 * Returns contact ID for given user ID
57 * @param integer $uid User ID
58 * @return integer Contact ID of visitor for given user ID
60 public static function getRemoteContactID($uid)
62 if (empty($_SESSION['remote'][$uid])) {
66 return $_SESSION['remote'][$uid];
70 * Returns User ID for given contact ID of the visitor
72 * @param integer $cid Contact ID
73 * @return integer User ID for given contact ID of the visitor
75 public static function getUserIDForVisitorContactID($cid)
77 if (empty($_SESSION['remote'])) {
81 return array_search($cid, $_SESSION['remote']);
85 * Set the session variable that contains the contact IDs for the visitor's contact URL
87 * @param string $url Contact URL
89 public static function setVisitorsContacts()
91 $_SESSION['remote'] = [];
93 $remote_contacts = DBA::select('contact', ['id', 'uid'], ['nurl' => Strings::normaliseLink($_SESSION['my_url']), 'rel' => [Contact::FOLLOWER, Contact::FRIEND], 'self' => false]);
94 while ($contact = DBA::fetch($remote_contacts)) {
95 if (($contact['uid'] == 0) || Contact::isBlockedByUser($contact['id'], $contact['uid'])) {
99 $_SESSION['remote'][$contact['uid']] = $contact['id'];
101 DBA::close($remote_contacts);
105 * Returns if the current visitor is authenticated
107 * @return boolean "true" when visitor is either a local or remote user
109 public static function isAuthenticated()
111 if (empty($_SESSION['authenticated'])) {
115 return $_SESSION['authenticated'];
118 public static function delete()
120 self::getClass(ISession::class)->delete();