4 * @file src/Core/Session.php
6 namespace Friendica\Core;
8 use Friendica\Database\DBA;
10 use Friendica\Model\Contact;
11 use Friendica\Util\Strings;
14 * High-level Session service class
16 * @author Hypolite Petovan <hypolite@mrpetovan.com>
20 public static $exists = false;
21 public static $expire = 180000;
23 public static function exists($name)
25 return DI::session()->exists($name);
28 public static function get($name, $defaults = null)
30 return DI::session()->get($name, $defaults);
33 public static function set($name, $value)
35 DI::session()->set($name, $value);
38 public static function setMultiple(array $values)
40 DI::session()->setMultiple($values);
43 public static function remove($name)
45 DI::session()->remove($name);
48 public static function clear()
50 DI::session()->clear();
54 * Returns contact ID for given user ID
56 * @param integer $uid User ID
57 * @return integer Contact ID of visitor for given user ID
59 public static function getRemoteContactID($uid)
61 $session = DI::session();
63 if (empty($session->get('remote')[$uid])) {
67 return $session->get('remote')[$uid];
71 * Returns User ID for given contact ID of the visitor
73 * @param integer $cid Contact ID
74 * @return integer User ID for given contact ID of the visitor
76 public static function getUserIDForVisitorContactID($cid)
78 $session = DI::session();
80 if (empty($session->get('remote'))) {
84 return array_search($cid, $session->get('remote'));
88 * Set the session variable that contains the contact IDs for the visitor's contact URL
90 * @param string $url Contact URL
92 public static function setVisitorsContacts()
94 $session = DI::session();
96 $session->set('remote', []);
98 $remote_contacts = DBA::select('contact', ['id', 'uid'], ['nurl' => Strings::normaliseLink($session->get('my_url')), 'rel' => [Contact::FOLLOWER, Contact::FRIEND], 'self' => false]);
99 while ($contact = DBA::fetch($remote_contacts)) {
100 if (($contact['uid'] == 0) || Contact::isBlockedByUser($contact['id'], $contact['uid'])) {
104 $session->set('remote', [$contact['uid'] => $contact['id']]);
106 DBA::close($remote_contacts);
110 * Returns if the current visitor is authenticated
112 * @return boolean "true" when visitor is either a local or remote user
114 public static function isAuthenticated()
116 $session = DI::session();
118 return $session->get('authenticated', false);