]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - lib/implugin.php
Merge branch 'nightly' into deletenotice_form_fix
[quix0rs-gnu-social.git] / lib / implugin.php
index def9a942c90b27620053f0b826c26a072a00f0ca..87ca03716089dc4c06f5b7f419d964d8c47fde27 100644 (file)
@@ -49,6 +49,8 @@ abstract class ImPlugin extends Plugin
     //list of screennames that should get all public notices
     public $public = array();
 
+    protected $requires_cli = true;
+
     /**
      * normalize a screenname for comparison
      *
@@ -375,9 +377,10 @@ abstract class ImPlugin extends Plugin
         $profile = $notice->getProfile();
 
         try {
-            $orig_profile = $notice->getParent()->getProfile();
+            $parent = $notice->getParent();
+            $orig_profile = $parent->getProfile();
             $nicknames = sprintf('%1$s => %2$s', $profile->nickname, $orig_profile->nickname);
-        } catch (Exception $e) {
+        } catch (NoParentNoticeException $e) {
             $nicknames = $profile->nickname;
         }
 
@@ -399,9 +402,8 @@ abstract class ImPlugin extends Plugin
             $chan = new IMChannel($this);
             $cmd->execute($chan);
             return true;
-        } else {
-            return false;
         }
+        return false;
     }
 
     /**
@@ -529,9 +531,14 @@ abstract class ImPlugin extends Plugin
      */
     function onEndInitializeQueueManager($manager)
     {
-        $manager->connect($this->transport . '-in', new ImReceiverQueueHandler($this), 'im');
-        $manager->connect($this->transport, new ImQueueHandler($this));
-        $manager->connect($this->transport . '-out', new ImSenderQueueHandler($this), 'im');
+        // If we don't require CLI mode, or if we do and GNUSOCIAL_CLI _is_ set, then connect the transports
+        // This check is made mostly because some IM plugins can't deliver to transports unless they
+        // have continously running daemons (such as XMPP) and we can't have that over HTTP requests.
+        if (!$this->requires_cli || defined('GNUSOCIAL_CLI')) {
+            $manager->connect($this->transport . '-in', new ImReceiverQueueHandler($this), 'im');
+            $manager->connect($this->transport, new ImQueueHandler($this));
+            $manager->connect($this->transport . '-out', new ImSenderQueueHandler($this), 'im');
+        }
         return true;
     }
 
@@ -556,14 +563,12 @@ abstract class ImPlugin extends Plugin
         return true;
     }
 
-    function onEndShowHeadElements($action)
+    function onEndShowHeadElements(Action $action)
     {
-        $aname = $action->trimmed('action');
-
-        if ($aname == 'shownotice') {
+        if ($action instanceof ShownoticeAction) {
 
             $user_im_prefs = new User_im_prefs();
-            $user_im_prefs->user_id = $action->profile->id;
+            $user_im_prefs->user_id = $action->notice->getProfile()->getID();
             $user_im_prefs->transport = $this->transport;
 
             if ($user_im_prefs->find() && $user_im_prefs->fetch() && $user_im_prefs->microid && $action->notice->uri) {
@@ -573,13 +578,13 @@ abstract class ImPlugin extends Plugin
                                              'content' => $id->toString()));
             }
 
-        } else if ($aname == 'showstream') {
+        } elseif ($action instanceof ShowstreamAction) {
 
             $user_im_prefs = new User_im_prefs();
-            $user_im_prefs->user_id = $action->user->id;
+            $user_im_prefs->user_id = $action->getTarget()->getID();
             $user_im_prefs->transport = $this->transport;
 
-            if ($user_im_prefs->find() && $user_im_prefs->fetch() && $user_im_prefs->microid && $action->profile->profileurl) {
+            if ($user_im_prefs->find() && $user_im_prefs->fetch() && $user_im_prefs->microid && $action->getTarget()->getUrl()) {
                 $id = new Microid($this->microiduri($user_im_prefs->screenname),
                                   $action->selfUrl());
                 $action->element('meta', array('name' => 'microid',