]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - scripts/xmppdaemon.php
Merge branch '0.8.x' into cmdline
[quix0rs-gnu-social.git] / scripts / xmppdaemon.php
index 01fe8914f1aae18bcc0874878b5507bc0d520864..0f98becdac510860f497b9055c94bb97104e50a9 100755 (executable)
@@ -2,7 +2,7 @@
 <?php
 /*
  * Laconica - a distributed open-source microblogging tool
- * Copyright (C) 2008, Controlez-Vous, Inc.
+ * Copyright (C) 2008, 2009, Control Yourself, Inc.
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU Affero General Public License as published by
@@ -27,6 +27,11 @@ if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) {
 define('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
 define('LACONICA', true);
 
+// Preset the server at the command line
+
+$server = ($argc > 2) ? $argv[2] : null;
+$path   = ($argc > 3) ? $argv[3] : null;
+
 require_once(INSTALLDIR . '/lib/common.php');
 require_once(INSTALLDIR . '/lib/jabber.php');
 require_once(INSTALLDIR . '/lib/daemon.php');
@@ -39,7 +44,6 @@ set_error_handler('common_error_handler');
 
 class XMPPDaemon extends Daemon
 {
-
     function XMPPDaemon($resource=null)
     {
         static $attrs = array('server', 'port', 'user', 'password', 'host');
@@ -152,11 +156,6 @@ class XMPPDaemon extends Daemon
             $body = preg_replace('/d[\ ]*('. $to .')[\ ]*/', '', $pl['body']);
             $this->add_direct($user, $body, $to, $from);
         } else {
-            $len = mb_strlen($pl['body']);
-            if($len > 140) {
-                $this->from_site($from, 'Message too long - maximum is 140 characters, you sent ' . $len);
-                return;
-            }
             $this->add_notice($user, $pl);
         }
 
@@ -208,6 +207,8 @@ class XMPPDaemon extends Daemon
     {
         if (preg_match('/[\[\(]?[Aa]uto[-\s]?[Rr]e(ply|sponse)[\]\)]/', $txt)) {
             return true;
+        } else if (preg_match('/^System: Message wasn\'t delivered. Offline storage size was exceeded.$/', $txt)) {
+            return true;
         } else {
             return false;
         }
@@ -253,15 +254,13 @@ class XMPPDaemon extends Daemon
     function add_notice(&$user, &$pl)
     {
         $body = trim($pl['body']);
-        $content_shortened = common_shorten_link($body);
+        $content_shortened = common_shorten_links($body);
         if (mb_strlen($content_shortened) > 140) {
-            $content = trim(mb_substr($body, 0, 140));
-            $content_shortened = common_shorten_link($content);
-        }
-        else {
-            $content = $body;
+          $from = jabber_normalize_jid($pl['from']);
+          $this->from_site($from, "Message too long - maximum is 140 characters, you sent ".mb_strlen($content_shortened));
+          return;
         }
-        $notice = Notice::saveNew($user->id, $content, 'xmpp');
+        $notice = Notice::saveNew($user->id, $content_shortened, 'xmpp');
         if (is_string($notice)) {
             $this->log(LOG_ERR, $notice);
             return;
@@ -319,6 +318,13 @@ class XMPPDaemon extends Daemon
     }
 }
 
+// Abort immediately if xmpp is not enabled, otherwise the daemon chews up
+// lots of CPU trying to connect to unconfigured servers
+if (common_config('xmpp','enabled')==false) {
+    print "Aborting daemon - xmpp is disabled\n";
+    exit();
+}
+
 ini_set("max_execution_time", "0");
 ini_set("max_input_time", "0");
 set_time_limit(0);