X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=lib%2Fmicroappplugin.php;h=4da3bef935a7e60c7a6c6da3e00511df18f4c2f3;hb=33e2f5b449d477e55bda7029f9e826d889e41eb5;hp=1dfb90036e7c451c6f93ea4821ed58ba3daaa57c;hpb=5e97047f8ff328e514ae84760692e43190f131e6;p=quix0rs-gnu-social.git diff --git a/lib/microappplugin.php b/lib/microappplugin.php index 1dfb90036e..4da3bef935 100644 --- a/lib/microappplugin.php +++ b/lib/microappplugin.php @@ -162,6 +162,14 @@ abstract class MicroAppPlugin extends Plugin */ 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. @@ -175,7 +183,7 @@ abstract class MicroAppPlugin extends 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); } /** @@ -193,6 +201,8 @@ abstract class MicroAppPlugin extends Plugin 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)); } @@ -345,13 +355,13 @@ abstract class MicroAppPlugin extends Plugin * * @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.')); } @@ -360,11 +370,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; } @@ -388,19 +398,19 @@ abstract class MicroAppPlugin extends Plugin 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 thrown when ... - throw new ClientException(_('Bookmark not posted to this group.')); + 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). @@ -418,7 +428,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 @@ -446,9 +456,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; } @@ -534,7 +544,9 @@ abstract class MicroAppPlugin extends Plugin function onStartShowEntryForms(&$tabs) { - $tabs[$this->tag()] = $this->appTitle(); + $tabs[$this->tag()] = array('title' => $this->appTitle(), + 'href' => common_local_url($this->newFormAction()), + ); return true; }