*/
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!
*/
abstract function deleteRelated($notice);
+ /**
+ *
+ */
+ public function newFormAction() {
+ // such as 'newbookmark' or 'newevent' route
+ return 'new'.$this->tag();
+ }
+
/**
* Check if a given notice object should be handled by this micro-app
* plugin.
*/
function isMyNotice($notice) {
$types = $this->types();
- return in_array($notice->object_type, $types);
+ return ($notice->verb == ActivityVerb::POST) && in_array($notice->object_type, $types);
}
/**
function isMyActivity($activity) {
$types = $this->types();
return (count($activity->objects) == 1 &&
+ ($activity->objects[0] instanceof ActivityObject) &&
+ ($activity->verb == ActivityVerb::POST) &&
in_array($activity->objects[0]->type, $types));
}
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();
$out->elementEnd('div');
$nli->showNoticeOptions();
-
- return false;
}
/**
*
* @return boolean hook value
*/
- function onStartHandleFeedEntryWithProfile($activity, $oprofile)
+ function onStartHandleFeedEntryWithProfile($activity, $oprofile, &$notice)
{
if ($this->isMyActivity($activity)) {
$actor = $oprofile->checkAuthorship($activity);
- if (empty($actor)) {
+ if (!$actor instanceof Ostatus_profile) {
// TRANS: Client exception thrown when no author for an activity was found.
throw new ClientException(_('Cannot get author for activity.'));
}
$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;
}
if ($target instanceof User_group) {
$uri = $target->getUri();
- if (!in_array($uri, $activity->context->attention)) {
+ if (!array_key_exists($uri, $activity->context->attention)) {
// @todo FIXME: please document (i18n).
- // TRANS: Client exception.
- throw new ClientException(_('Bookmark not posted to this group.'));
+ // TRANS: Client exception thrown when ...
+ throw new ClientException(_('Object not posted to this group.'));
}
} else if ($target instanceof User) {
$uri = $target->uri;
$original = null;
if (!empty($activity->context->replyToID)) {
- $original = Notice::staticGet('uri',
+ $original = Notice::getKV('uri',
$activity->context->replyToID);
}
- if (!in_array($uri, $activity->context->attention) &&
+ if (!array_key_exists($uri, $activity->context->attention) &&
(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 {
$options = array('uri' => $object->id,
'url' => $object->link,
- 'is_local' => Notice::REMOTE_OMB,
+ 'is_local' => Notice::REMOTE,
'source' => 'ostatus');
// $actor is an ostatus_profile
$options = array('source' => 'atompub');
// $user->getProfile() is a Profile
- $this->saveNoticeFromActivity($activity,
- $user->getProfile(),
- $options);
+ $notice = $this->saveNoticeFromActivity($activity,
+ $user->getProfile(),
+ $options);
return false;
}
function onStartShowEntryForms(&$tabs)
{
- $tabs[$this->tag()] = $this->appTitle();
+ $tabs[$this->tag()] = array('title' => $this->appTitle(),
+ 'href' => common_local_url($this->newFormAction()),
+ );
return true;
}
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().'));
+ }
}