]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - lib/microappplugin.php
Merge branch '1.0.x' of git://gitorious.org/statusnet/mainline
[quix0rs-gnu-social.git] / lib / microappplugin.php
index 1dfc44634fdb2017fa6c55253a62faff2c0c1f32..1dfb90036e7c451c6f93ea4821ed58ba3daaa57c 100644 (file)
@@ -137,21 +137,6 @@ abstract class MicroAppPlugin extends Plugin
      */
     abstract function activityObjectFromNotice($notice);
 
-    /**
-     * Custom HTML output for your special notice; called when a
-     * matching notice turns up in a NoticeListItem.
-     *
-     * All micro-app classes must override this method.
-     *
-     * @param Notice $notice
-     * @param HTMLOutputter $out
-     *
-     * @fixme WARNING WARNING WARNING base plugin stuff below tries to close
-     * a div that this function opens in the BookmarkPlugin child class.
-     * This is probably wrong.
-     */
-    abstract function showNotice($notice, $out);
-
     /**
      * When building the primary notice form, we'll fetch also some
      * alternate forms for specialized types -- that's you!
@@ -281,6 +266,35 @@ abstract class MicroAppPlugin extends Plugin
             return true;
         }
 
+        $adapter = $this->adaptNoticeListItem($nli);
+
+        if (!empty($adapter)) {
+            $adapter->showNotice();
+            $adapter->showNoticeAttachments();
+            $adapter->showNoticeInfo();
+            $adapter->showNoticeOptions();
+        } else {
+            $this->oldShowNotice($nli);
+        }
+
+        return false;
+    }
+
+    /**
+     * Given a notice list item, returns an adapter specific
+     * to this plugin.
+     *
+     * @param NoticeListItem $nli item to adapt
+     *
+     * @return NoticeListItemAdapter adapter or null
+     */
+    function adaptNoticeListItem($nli)
+    {
+      return null;
+    }
+
+    function oldShowNotice($nli)
+    {
         $out = $nli->out;
         $notice = $nli->notice;
 
@@ -303,8 +317,6 @@ abstract class MicroAppPlugin extends Plugin
         $out->elementEnd('div');
 
         $nli->showNoticeOptions();
-
-        return false;
     }
 
     /**
@@ -378,7 +390,7 @@ abstract class MicroAppPlugin extends Plugin
                 $uri = $target->getUri();
                 if (!in_array($uri, $activity->context->attention)) {
                     // @todo FIXME: please document (i18n).
-                    // TRANS: Client exception.
+                    // TRANS: Client exception thrown when ...
                     throw new ClientException(_('Bookmark not posted to this group.'));
                 }
             } else if ($target instanceof User) {
@@ -392,7 +404,7 @@ abstract class MicroAppPlugin extends Plugin
                     (empty($original) ||
                      $original->profile_id != $target->id)) {
                     // @todo FIXME: Please document (i18n).
-                    // TRANS: Client exception.
+                    // TRANS: Client exception when ...
                     throw new ClientException(_('Object not posted to this user.'));
                 }
             } else {
@@ -535,4 +547,10 @@ abstract class MicroAppPlugin extends Plugin
 
         return true;
     }
+
+    function showNotice($notice, $out)
+    {
+        // TRANS: Server exception thrown when a micro app plugin developer has not done his job too well.
+        throw new ServerException(_('You must implement either adaptNoticeListItem() or showNotice().'));
+    }
 }