X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=lib%2Fmicroappplugin.php;h=a723ecde420f805e0ace47e0ecf6244ddbe324d2;hb=b5c5d8d3933c9694bd105fc1e1f06bc96da2dc79;hp=cd325560d32f07d5eb5d4efc436d5271c5781f0d;hpb=36b331d469b6dcd1101783f21265f7be624bc58f;p=quix0rs-gnu-social.git diff --git a/lib/microappplugin.php b/lib/microappplugin.php index cd325560d3..a723ecde42 100644 --- a/lib/microappplugin.php +++ b/lib/microappplugin.php @@ -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! @@ -208,6 +193,7 @@ abstract class MicroAppPlugin extends Plugin function isMyActivity($activity) { $types = $this->types(); return (count($activity->objects) == 1 && + ($activity->objects[0] instanceof ActivityObject) && in_array($activity->objects[0]->type, $types)); } @@ -281,10 +267,47 @@ 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; - $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 +318,6 @@ abstract class MicroAppPlugin extends Plugin $out->elementEnd('div'); $nli->showNoticeOptions(); - - return false; } /** @@ -325,7 +346,7 @@ abstract class MicroAppPlugin extends Plugin * * @return boolean hook value */ - function onStartHandleFeedEntryWithProfile($activity, $oprofile) + function onStartHandleFeedEntryWithProfile($activity, $oprofile, &$notice) { if ($this->isMyActivity($activity)) { @@ -340,11 +361,11 @@ abstract class MicroAppPlugin extends Plugin $options = array('uri' => $object->id, 'url' => $object->link, - 'is_local' => Notice::REMOTE_OMB, + 'is_local' => Notice::REMOTE, 'source' => 'ostatus'); // $actor is an ostatus_profile - $this->saveNoticeFromActivity($activity, $actor->localProfile(), $options); + $notice = $this->saveNoticeFromActivity($activity, $actor->localProfile(), $options); return false; } @@ -370,7 +391,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) { @@ -384,7 +405,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 { @@ -398,7 +419,7 @@ abstract class MicroAppPlugin extends Plugin $options = array('uri' => $object->id, 'url' => $object->link, - 'is_local' => Notice::REMOTE_OMB, + 'is_local' => Notice::REMOTE, 'source' => 'ostatus'); // $actor is an ostatus_profile @@ -426,9 +447,9 @@ abstract class MicroAppPlugin extends Plugin $options = array('source' => 'atompub'); // $user->getProfile() is a Profile - $this->saveNoticeFromActivity($activity, - $user->getProfile(), - $options); + $notice = $this->saveNoticeFromActivity($activity, + $user->getProfile(), + $options); return false; } @@ -527,4 +548,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().')); + } }