]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - lib/microappplugin.php
Let showNotice() go unimplemented
[quix0rs-gnu-social.git] / lib / microappplugin.php
index cd325560d32f07d5eb5d4efc436d5271c5781f0d..0fd6868f8c25242beb19c3033e0f67accbe547a2 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,10 +266,44 @@ abstract class MicroAppPlugin extends Plugin
             return true;
         }
 
+        $adapter = $this->adaptNoticeListItem($nli);
+
+        if (!empty($adapter)) {
+            $adapter->show();
+        } 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;
 
-        $this->showNotice($notice, $out);
+        try {
+            $this->showNotice($notice, $out);
+        } catch (Exception $e) {
+            common_log(LOG_ERR, $e->getMessage());
+            // try to fall back
+            $out->elementStart('div');
+            $nli->showAuthor();
+            $nli->showContent();
+        }
 
         $nli->showNoticeLink();
         $nli->showNoticeSource();
@@ -295,8 +314,6 @@ abstract class MicroAppPlugin extends Plugin
         $out->elementEnd('div');
 
         $nli->showNoticeOptions();
-
-        return false;
     }
 
     /**
@@ -527,4 +544,9 @@ abstract class MicroAppPlugin extends Plugin
 
         return true;
     }
+
+    function showNotice($notice, $out)
+    {
+        throw new ServerException("You must implement either adaptNoticeListItem() or showNotice()");
+    }
 }