]> git.mxchange.org Git - friendica.git/blobdiff - boot.php
Merge pull request #3226 from annando/1702-only-worker
[friendica.git] / boot.php
index 74830e4300d768d5435e34212ce6011d6d5fc306..72c2e45aa5834d3841184cb712ee114b5faf021f 100644 (file)
--- a/boot.php
+++ b/boot.php
@@ -1853,11 +1853,35 @@ function goaway($s) {
  * @return int|bool user id or false
  */
 function local_user() {
-       if((x($_SESSION,'authenticated')) && (x($_SESSION,'uid')))
+       if (x($_SESSION, 'authenticated') && x($_SESSION, 'uid')) {
                return intval($_SESSION['uid']);
+       }
        return false;
 }
 
+/**
+ * @brief Returns the public contact id of logged in user or false.
+ *
+ * @return int|bool public contact id or false
+ */
+function public_contact() {
+       static $public_contact_id = false;
+
+       if (!$public_contact_id && x($_SESSION, 'authenticated')) {
+               if (x($_SESSION, 'my_address')) {
+                       // Local user
+                       $public_contact_id = intval(get_contact($_SESSION['my_address'], 0));
+               } else if (x($_SESSION, 'visitor_home')) {
+                       // Remote user
+                       $public_contact_id = intval(get_contact($_SESSION['visitor_home'], 0));
+               }
+       } else if (!x($_SESSION, 'authenticated')) {
+               $public_contact_id = false;
+       }
+
+       return $public_contact_id;
+}
+
 /**
  * @brief Returns contact id of authenticated site visitor or false
  *