]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - lib/util.php
Merge branch 'testing' of git@gitorious.org:statusnet/mainline into testing
[quix0rs-gnu-social.git] / lib / util.php
index 9255b9b376bfe89a21aa6f994391f584952a85a2..ae812e8cf4d0aacdd6a7166461c761fed0eeb7e1 100644 (file)
@@ -173,14 +173,11 @@ function common_ensure_session()
         }
        if (array_key_exists(session_name(), $_GET)) {
            $id = $_GET[session_name()];
-           common_log(LOG_INFO, 'Setting session from GET parameter: '.$id);
        } else if (array_key_exists(session_name(), $_COOKIE)) {
            $id = $_COOKIE[session_name()];
-           common_log(LOG_INFO, 'Setting session from COOKIE: '.$id);
        }
        if (isset($id)) {
            session_id($id);
-           setcookie(session_name(), $id);
        }
         @session_start();
         if (!isset($_SESSION['started'])) {
@@ -370,7 +367,8 @@ function common_current_user()
 
     if ($_cur === false) {
 
-        if (isset($_REQUEST[session_name()]) || (isset($_SESSION['userid']) && $_SESSION['userid'])) {
+        if (isset($_COOKIE[session_name()]) || isset($_GET[session_name()])
+            || (isset($_SESSION['userid']) && $_SESSION['userid'])) {
             common_ensure_session();
             $id = isset($_SESSION['userid']) ? $_SESSION['userid'] : false;
             if ($id) {
@@ -668,6 +666,9 @@ function common_valid_profile_tag($str)
 function common_at_link($sender_id, $nickname)
 {
     $sender = Profile::staticGet($sender_id);
+    if (!$sender) {
+        return $nickname;
+    }
     $recipient = common_relative_profile($sender, common_canonical_nickname($nickname));
     if ($recipient) {
         $user = User::staticGet('id', $recipient->id);
@@ -697,7 +698,7 @@ function common_group_link($sender_id, $nickname)
 {
     $sender = Profile::staticGet($sender_id);
     $group = User_group::getForNickname($nickname);
-    if ($group && $sender->isMember($group)) {
+    if ($sender && $group && $sender->isMember($group)) {
         $attrs = array('href' => $group->permalink(),
                        'class' => 'url');
         if (!empty($group->fullname)) {
@@ -989,7 +990,7 @@ function common_redirect($url, $code=307)
 
 function common_broadcast_notice($notice, $remote=false)
 {
-    return common_enqueue_notice($notice);
+    // DO NOTHING!
 }
 
 // Stick the notice on the queue
@@ -999,9 +1000,13 @@ function common_enqueue_notice($notice)
     static $localTransports = array('omb',
                                     'ping');
 
-    static $allTransports = array('sms', 'plugin');
-
-    $transports = $allTransports;
+    $transports = array();
+    if (common_config('sms', 'enabled')) {
+        $transports[] = 'sms';
+    }
+    if (Event::hasHandler('HandleQueuedNotice')) {
+        $transports[] = 'plugin';
+    }
 
     $xmpp = common_config('xmpp', 'enabled');
 
@@ -1009,6 +1014,7 @@ function common_enqueue_notice($notice)
         $transports[] = 'jabber';
     }
 
+    // @fixme move these checks into QueueManager and/or individual handlers
     if ($notice->is_local == Notice::LOCAL_PUBLIC ||
         $notice->is_local == Notice::LOCAL_NONPUBLIC) {
         $transports = array_merge($transports, $localTransports);
@@ -1132,7 +1138,8 @@ function common_request_id()
     $pid = getmypid();
     $server = common_config('site', 'server');
     if (php_sapi_name() == 'cli') {
-        return "$server:$pid";
+        $script = basename($_SERVER['PHP_SELF']);
+        return "$server:$script:$pid";
     } else {
         static $req_id = null;
         if (!isset($req_id)) {
@@ -1566,3 +1573,56 @@ function common_client_ip()
 
     return array($proxy, $ip);
 }
+
+function common_url_to_nickname($url)
+{
+    static $bad = array('query', 'user', 'password', 'port', 'fragment');
+
+    $parts = parse_url($url);
+
+    # If any of these parts exist, this won't work
+
+    foreach ($bad as $badpart) {
+        if (array_key_exists($badpart, $parts)) {
+            return null;
+        }
+    }
+
+    # We just have host and/or path
+
+    # If it's just a host...
+    if (array_key_exists('host', $parts) &&
+        (!array_key_exists('path', $parts) || strcmp($parts['path'], '/') == 0))
+    {
+        $hostparts = explode('.', $parts['host']);
+
+        # Try to catch common idiom of nickname.service.tld
+
+        if ((count($hostparts) > 2) &&
+            (strlen($hostparts[count($hostparts) - 2]) > 3) && # try to skip .co.uk, .com.au
+            (strcmp($hostparts[0], 'www') != 0))
+        {
+            return common_nicknamize($hostparts[0]);
+        } else {
+            # Do the whole hostname
+            return common_nicknamize($parts['host']);
+        }
+    } else {
+        if (array_key_exists('path', $parts)) {
+            # Strip starting, ending slashes
+            $path = preg_replace('@/$@', '', $parts['path']);
+            $path = preg_replace('@^/@', '', $path);
+            if (strpos($path, '/') === false) {
+                return common_nicknamize($path);
+            }
+        }
+    }
+
+    return null;
+}
+
+function common_nicknamize($str)
+{
+    $str = preg_replace('/\W/', '', $str);
+    return strtolower($str);
+}