]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
IM/XMPP Plugin classes use throwing getParent
authorMikael Nordfeldth <mmn@hethane.se>
Sat, 5 Oct 2013 10:30:52 +0000 (12:30 +0200)
committerMikael Nordfeldth <mmn@hethane.se>
Sat, 5 Oct 2013 10:30:52 +0000 (12:30 +0200)
lib/implugin.php
plugins/Xmpp/XmppPlugin.php

index a6a9a3dad95fde75e94de6a7dca3f0b1b5242b68..def9a942c90b27620053f0b826c26a072a00f0ca 100644 (file)
@@ -84,7 +84,7 @@ abstract class ImPlugin extends Plugin
      *
      * @return boolean success value
      */
-    function sendNotice($screenname, $notice)
+    function sendNotice($screenname, Notice $notice)
     {
         return $this->sendMessage($screenname, $this->formatNotice($notice));
     }
@@ -370,19 +370,18 @@ abstract class ImPlugin extends Plugin
      * @return string plain-text version of the notice, with user nickname prefixed
      */
 
-    function formatNotice($notice)
+    protected function formatNotice(Notice $notice)
     {
         $profile = $notice->getProfile();
-        $nicknames = $profile->nickname;
-        if (!empty($notice->reply_to)) {
-            $orig_notice = $notice->getParent();
-            $orig_profile = $orig_notice->getProfile();
-            $nicknames = $nicknames . " => " . $orig_profile->nickname;
+
+        try {
+            $orig_profile = $notice->getParent()->getProfile();
+            $nicknames = sprintf('%1$s => %2$s', $profile->nickname, $orig_profile->nickname);
+        } catch (Exception $e) {
+            $nicknames = $profile->nickname;
         }
-        common_log(LOG_INFO, "Notice: " . $notice->content, __FILE__);
-        $data = $nicknames . ': ' . $notice->content . ' [' . $notice->id . ']';
-        return $data;
 
+        return sprintf('%1$s: %2$s [%3$u]', $nicknames, $notice->content, $notice->id);
     }
     //========================UTILITY FUNCTIONS USEFUL TO IMPLEMENTATIONS - RECEIVING ========================\
 
index 3d20c14c4c82bc178e07254d4bac48c64a628c36..a5666e5aa6700b045fb656c92c81bb6f8361e63f 100644 (file)
@@ -335,7 +335,7 @@ class XmppPlugin extends ImPlugin
      *
      * @return string Extra information (Atom, HTML, addresses) in string format
      */
-    function format_entry($notice)
+    protected function format_entry(Notice $notice)
     {
         $profile = $notice->getProfile();
 
@@ -344,16 +344,16 @@ class XmppPlugin extends ImPlugin
         $xs = new XMLStringer();
         $xs->elementStart('html', array('xmlns' => 'http://jabber.org/protocol/xhtml-im'));
         $xs->elementStart('body', array('xmlns' => 'http://www.w3.org/1999/xhtml'));
-        $xs->element('a', array('href' => $profile->profileurl),
-                     $profile->nickname);
-        if (!empty($notice->reply_to)) {
-            $orig_notice = Notice::getKV('id', $notice->reply_to);
-            $orig_profile = $orig_notice->getProfile();
+        $xs->element('a', array('href' => $profile->profileurl), $profile->nickname);
+        try {
+            $orig_profile = $notice->getParent()->getProfile();
+            $orig_profurl = $orig_profile->getUrl();
             $xs->text(" => ");
-            $xs->element('a', array('href' => $orig_profile->profileurl),
-                $orig_profile->nickname);
+            $xs->element('a', array('href' => $orig_profurl), $orig_profile->nickname);
             $xs->text(": ");
-        } else {
+        } catch (InvalidUrlException $e) {
+            $xs->text(sprintf(' => %s', $orig_profile->nickname));
+        } catch (Exception $e) {
             $xs->text(": ");
         }
         if (!empty($notice->rendered)) {
@@ -368,7 +368,7 @@ class XmppPlugin extends ImPlugin
                 array('id' => $notice->conversation)).'#notice-'.$notice->id),
              // TRANS: Link description to notice in conversation.
              // TRANS: %s is a notice ID.
-             sprintf(_m('[%s]'),$notice->id));
+             sprintf(_m('[%u]'),$notice->id));
         $xs->elementEnd('body');
         $xs->elementEnd('html');