]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - xmppdaemon.php
make init of lang environment happen earlier, or when user language may have changed
[quix0rs-gnu-social.git] / xmppdaemon.php
index 91ea833ce746881b28d3a65db37851cecc8ec9fe..37b349f5889464bc2a13428f5fd06d79577e6943 100755 (executable)
 function xmppdaemon_error_handler($errno, $errstr, $errfile, $errline, $errcontext) {
     switch ($errno) {
      case E_USER_ERROR:
-       echo "ERROR: [$errno] $errstr\n";
+       echo "ERROR: [$errno] $errstr ($errfile:$errline)\n";
        echo "  Fatal error on line $errline in file $errfile";
        echo ", PHP " . PHP_VERSION . " (" . PHP_OS . ")\n";
        echo "Aborting...\n";
        exit(1);
        break;
 
-     case E_USER_WARNING:
-       echo "WARNING [$errno] $errstr\n";
+    case E_USER_WARNING:
+       echo "WARNING [$errno] $errstr ($errfile:$errline)\n";
        break;
 
      case E_USER_NOTICE:
-       echo "My NOTICE [$errno] $errstr\n";
+       echo "My NOTICE [$errno] $errstr ($errfile:$errline)\n";
        break;
 
      default:
-       echo "Unknown error type: [$errno] $errstr\n";
+       echo "Unknown error type: [$errno] $errstr ($errfile:$errline)\n";
        break;
     }
 
@@ -172,6 +172,9 @@ class XMPPDaemon {
                } else if ($this->is_autoreply($pl['body'])) {
                        $this->log(LOG_INFO, 'Ignoring auto reply from ' . $from);
                        return;
+               } else if ($this->is_otr($pl['body'])) {
+                       $this->log(LOG_INFO, 'Ignoring OTR from ' . $from);
+                       return;
                } else {
                        $this->add_notice($user, $pl);
                }
@@ -185,6 +188,14 @@ class XMPPDaemon {
                }
        }
 
+       function is_otr($txt) {
+               if (preg_match('/^\?OTR/', $txt)) {
+                       return true;
+               } else {
+                       return false;
+               }
+       }
+       
        function from_site($address, $msg) {
                $text = '['.common_config('site', 'name') . '] ' . $msg;
                jabber_send_message($address, $text);
@@ -223,36 +234,11 @@ class XMPPDaemon {
        }
 
        function add_notice(&$user, &$pl) {
-               $notice = new Notice();
-               $notice->is_local = 1;
-               $notice->profile_id = $user->id;
-               $notice->content = trim(substr($pl['body'], 0, 140));
-               $notice->rendered = common_render_content($notice->content, $notice);
-               $notice->created = DB_DataObject_Cast::dateTime();
-               $notice->query('BEGIN');
-               $id = $notice->insert();
-               if (!$id) {
-                       $last_error = &PEAR::getStaticProperty('DB_DataObject','lastError');
-                       $this->log(LOG_ERR,
-                                          'Could not insert ' . common_log_objstring($notice) .
-                                          ' for user ' . common_log_objstring($user) .
-                                          ': ' . $last_error->message);
-                       return;
-               }
-               $orig = clone($notice);
-               $notice->uri = common_notice_uri($notice);
-               $result = $notice->update($orig);
-               if (!$result) {
-                       $last_error = &PEAR::getStaticProperty('DB_DataObject','lastError');
-                       $this->log(LOG_ERR,
-                                          'Could not add URI to ' . common_log_objstring($notice) .
-                                          ' for user ' . common_log_objstring($user) .
-                                          ': ' . $last_error->message);
+               $notice = Notice::saveNew($user->id, trim(substr($pl['body'], 0, 140)), 'xmpp');
+               if (is_string($notice)) {
+                       $this->log(LOG_ERR, $notice);
                        return;
                }
-               $notice->query('COMMIT');
-               common_save_replies($notice);
-               $notice->saveTags();
                common_real_broadcast($notice);
                $this->log(LOG_INFO,
                                   'Added notice ' . $notice->id . ' from user ' . $user->nickname);