]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - lib/util.php
Merge branch '0.8.x' of git://gitorious.org/laconica/dev into 0.8.x
[quix0rs-gnu-social.git] / lib / util.php
index 46aa7b9df907b2691f0ce782376a7005da573a98..91b15ccf554afcb3f7080493b73956b016335122 100644 (file)
@@ -81,7 +81,7 @@ function common_language()
 
     // If there is a user logged in and they've set a language preference
     // then return that one...
-    if (common_logged_in()) {
+    if (_have_config() && common_logged_in()) {
         $user = common_current_user();
         $user_language = $user->language;
         if ($user_language)
@@ -315,6 +315,10 @@ function common_current_user()
 {
     global $_cur;
 
+    if (!_have_config()) {
+        return null;
+    }
+
     if ($_cur === false) {
 
         if (isset($_REQUEST[session_name()]) || (isset($_SESSION['userid']) && $_SESSION['userid'])) {
@@ -456,6 +460,9 @@ function common_replace_urls_callback($text, $callback) {
 
         if (!in_array($url_parts[2], $tlds)) continue;
 
+        // Make sure we didn't capture a hash tag
+        if (strpos($url, '#') === 0) continue;
+
         // Put the url back the way we found it.
         $url = (mb_strpos($orig_url, htmlspecialchars($url)) === FALSE) ? $url:htmlspecialchars($url);
 
@@ -615,9 +622,15 @@ function common_at_link($sender_id, $nickname)
     $sender = Profile::staticGet($sender_id);
     $recipient = common_relative_profile($sender, common_canonical_nickname($nickname));
     if ($recipient) {
+        $user = User::staticGet('id', $recipient->id);
+        if ($user) {
+            $url = common_local_url('userbyid', array('id' => $user->id));
+        } else {
+            $url = $recipient->profileurl;
+        }
         $xs = new XMLStringer(false);
         $xs->elementStart('span', 'vcard');
-        $xs->elementStart('a', array('href' => $recipient->profileurl,
+        $xs->elementStart('a', array('href' => $url,
                                      'class' => 'url'));
         $xs->element('span', 'fn nickname', $nickname);
         $xs->elementEnd('a');
@@ -705,10 +718,10 @@ function common_relative_profile($sender, $nickname, $dt=null)
     return null;
 }
 
-function common_local_url($action, $args=null, $fragment=null)
+function common_local_url($action, $args=null, $params=null, $fragment=null)
 {
     $r = Router::get();
-    $path = $r->build($action, $args, $fragment);
+    $path = $r->build($action, $args, $params, $fragment);
     if ($path) {
     }
     if (common_config('site','fancy')) {
@@ -839,18 +852,58 @@ function common_broadcast_notice($notice, $remote=false)
 
 function common_enqueue_notice($notice)
 {
-    foreach (array('jabber', 'omb', 'sms', 'public', 'twitter', 'facebook') as $transport) {
-        $qi = new Queue_item();
-        $qi->notice_id = $notice->id;
-        $qi->transport = $transport;
-        $qi->created = $notice->created;
-        $result = $qi->insert();
-        if (!$result) {
-            $last_error = &PEAR::getStaticProperty('DB_DataObject','lastError');
-            common_log(LOG_ERR, 'DB error inserting queue item: ' . $last_error->message);
-            return false;
+    if (common_config('queue','subsystem') == 'stomp') {
+       // use an external message queue system via STOMP
+       require_once("Stomp.php");
+       $con = new Stomp(common_config('queue','stomp_server'));
+       if (!$con->connect()) {
+               common_log(LOG_ERR, 'Failed to connect to queue server');
+               return false;
+       }
+       $queue_basename = common_config('queue','queue_basename');
+       foreach (array('jabber', 'omb', 'sms', 'public', 'twitter', 'facebook', 'ping') as $transport) {
+               if (!$con->send(
+                       '/queue/'.$queue_basename.'-'.$transport, // QUEUE
+                       $notice->id,            // BODY of the message
+                       array (                 // HEADERS of the msg
+                       'created' => $notice->created
+                       ))) {
+                       common_log(LOG_ERR, 'Error sending to '.$transport.' queue');
+                       return false;
+               }
+        common_log(LOG_DEBUG, 'complete remote queueing notice ID = ' . $notice->id . ' for ' . $transport);
+       }
+       $con->send('/topic/laconica.'.$notice->profile_id,
+                       $notice->content,
+                       array(
+                               'profile_id' => $notice->profile_id,
+                               'created' => $notice->created
+                               )
+                       );
+       $con->send('/topic/laconica.allusers',
+                       $notice->content,
+                       array(
+                               'profile_id' => $notice->profile_id,
+                               'created' => $notice->created
+                               )
+                       );
+       $result = true;
+    }
+    else {
+       // in any other case, 'internal'
+       foreach (array('jabber', 'omb', 'sms', 'public', 'twitter', 'facebook', 'ping') as $transport) {
+               $qi = new Queue_item();
+               $qi->notice_id = $notice->id;
+               $qi->transport = $transport;
+               $qi->created = $notice->created;
+               $result = $qi->insert();
+               if (!$result) {
+                   $last_error = &PEAR::getStaticProperty('DB_DataObject','lastError');
+                   common_log(LOG_ERR, 'DB error inserting queue item: ' . $last_error->message);
+                   return false;
+               }
+               common_log(LOG_DEBUG, 'complete queueing notice ID = ' . $notice->id . ' for ' . $transport);
         }
-        common_log(LOG_DEBUG, 'complete queueing notice ID = ' . $notice->id . ' for ' . $transport);
     }
     return $result;
 }