From efabb002e45756ee2e10edcd80b3641a58a4690f Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Tue, 19 Apr 2011 15:43:06 -0400 Subject: [PATCH] use an adapter pattern to customize notice list item output --- lib/microappplugin.php | 45 ++++++++++++++++++++- lib/noticelistitemadapter.php | 75 +++++++++++++++++++++++++++++++++++ 2 files changed, 118 insertions(+), 2 deletions(-) create mode 100644 lib/noticelistitemadapter.php diff --git a/lib/microappplugin.php b/lib/microappplugin.php index 1dfc44634f..5df76a074f 100644 --- a/lib/microappplugin.php +++ b/lib/microappplugin.php @@ -281,6 +281,32 @@ 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; @@ -303,8 +329,6 @@ abstract class MicroAppPlugin extends Plugin $out->elementEnd('div'); $nli->showNoticeOptions(); - - return false; } /** @@ -535,4 +559,21 @@ abstract class MicroAppPlugin extends Plugin return true; } + + /** + * 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); + + } diff --git a/lib/noticelistitemadapter.php b/lib/noticelistitemadapter.php new file mode 100644 index 0000000000..48530a9c1a --- /dev/null +++ b/lib/noticelistitemadapter.php @@ -0,0 +1,75 @@ +. + * + * @category Microapp + * @package StatusNet + * @author Evan Prodromou + * @copyright 2011 StatusNet, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0 + * @link http://status.net/ + */ + +if (!defined('STATUSNET')) { + // This check helps protect against security problems; + // your code file can't be executed directly from the web. + exit(1); +} + +/** + * For use by microapps to customize NoticeListItem output + * + * @category Microapp + * @package StatusNet + * @author Evan Prodromou + * @copyright 2011 StatusNet, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0 + * @link http://status.net/ + */ + +class NoticeListItemAdapter +{ + protected $nli; + + /** + * Wrap a notice list item. + * + * @param NoticeListItem $nli item to wrap + */ + + function __construct($nli) + { + $this->nli = $nli; + } + + /** + * Delegate unimplemented methods to the notice list item attribute. + * + * @param string $name Name of the method + * @param array $arguments Arguments called + * + * @return mixed Return value of the method. + */ + function __call($name, $arguments) + { + return call_user_func_array(array($this->nli, $name), $arguments); + } +} -- 2.39.5