* easily as email does today.
*/
-use Friendica\Model\Contact;
+use Friendica\Core\Session;
/**
* Constant with a HTML line break.
define('SIGTERM', 15);
}
-/**
- * Depending on the PHP version this constant does exist - or not.
- * See here: http://php.net/manual/en/curl.constants.php#117928
- */
-if (!defined('CURLE_OPERATION_TIMEDOUT')) {
- define('CURLE_OPERATION_TIMEDOUT', CURLE_OPERATION_TIMEOUTED);
-}
-
-if (!function_exists('exif_imagetype')) {
- function exif_imagetype($file)
- {
- $size = getimagesize($file);
- return $size[2];
- }
-}
-
/**
* Returns the user id of locally logged in user or false.
*
*/
function local_user()
{
- if (!empty($_SESSION['authenticated']) && !empty($_SESSION['uid'])) {
- return intval($_SESSION['uid']);
- }
-
- return false;
+ return Session::getLocalUser();
}
/**
*/
function public_contact()
{
- static $public_contact_id = false;
-
- if (!$public_contact_id && !empty($_SESSION['authenticated'])) {
- if (!empty($_SESSION['my_address'])) {
- // Local user
- $public_contact_id = intval(Contact::getIdForURL($_SESSION['my_address'], 0, false));
- } elseif (!empty($_SESSION['visitor_home'])) {
- // Remote user
- $public_contact_id = intval(Contact::getIdForURL($_SESSION['visitor_home'], 0, false));
- }
- } elseif (empty($_SESSION['authenticated'])) {
- $public_contact_id = false;
- }
-
- return $public_contact_id;
+ return Session::getPublicContact();
}
/**
*/
function remote_user()
{
- if (empty($_SESSION['authenticated'])) {
- return false;
- }
-
- if (!empty($_SESSION['visitor_id'])) {
- return intval($_SESSION['visitor_id']);
- }
-
- return false;
+ return Session::getRemoteUser();
}
public static function getFormSecurityStandardErrorMessage(): string
{
- return DI::l10n()->t("The form security token was not correct. This probably happened because the form has been opened for too long \x28>3 hours\x29 before submitting it.") . EOL;
+ return DI::l10n()->t("The form security token was not correct. This probably happened because the form has been opened for too long \x28>3 hours\x29 before submitting it.");
}
public static function checkFormSecurityTokenRedirectOnError(string $err_redirect, string $typename = '', string $formname = 'form_security_token')
DI::session()->clear();
}
+ /**
+ * Returns the user id of locally logged in user or false.
+ *
+ * @return int|bool user id or false
+ */
+ public static function getLocalUser()
+ {
+ $session = DI::session();
+
+ if (!empty($session->get('authenticated')) && !empty($session->get('uid'))) {
+ return intval($session->get('uid'));
+ }
+
+ return false;
+ }
+
+ /**
+ * Returns the public contact id of logged in user or false.
+ *
+ * @return int|bool public contact id or false
+ */
+ public static function getPublicContact()
+ {
+ static $public_contact_id = false;
+
+ $session = DI::session();
+
+ if (!$public_contact_id && !empty($session->get('authenticated'))) {
+ if (!empty($session->get('my_address'))) {
+ // Local user
+ $public_contact_id = intval(Contact::getIdForURL($session->get('my_address'), 0, false));
+ } elseif (!empty($session->get('visitor_home'))) {
+ // Remote user
+ $public_contact_id = intval(Contact::getIdForURL($session->get('visitor_home'), 0, false));
+ }
+ } elseif (empty($session->get('authenticated'))) {
+ $public_contact_id = false;
+ }
+
+ return $public_contact_id;
+ }
+
+ /**
+ * Returns public contact id of authenticated site visitor or false
+ *
+ * @return int|bool visitor_id or false
+ */
+ public static function getRemoteUser()
+ {
+ $session = DI::session();
+
+ if (empty($session->get('authenticated'))) {
+ return false;
+ }
+
+ if (!empty($session->get('visitor_id'))) {
+ return intval($session->get('visitor_id'));
+ }
+
+ return false;
+ }
+
/**
* Return the user contact ID of a visitor for the given user ID they are visiting
*