X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=plugins%2FEvent%2FEventPlugin.php;h=ed6a01e9b48a5c88f5e02cff11c7418c09444b6f;hb=e186ad57d07307e2c12e9080bb51fd5beedff409;hp=56081b1a8ea71dd0106f5577df0aaaae91411ac9;hpb=84dda697d642060210e0d7029008997a0215ceeb;p=quix0rs-gnu-social.git diff --git a/plugins/Event/EventPlugin.php b/plugins/Event/EventPlugin.php index 56081b1a8e..ed6a01e9b4 100644 --- a/plugins/Event/EventPlugin.php +++ b/plugins/Event/EventPlugin.php @@ -78,9 +78,10 @@ class EventPlugin extends ActivityVerbHandlerPlugin $m->connect('main/event/new', array('action' => 'newevent')); $m->connect('main/event/rsvp', - array('action' => 'newrsvp')); - $m->connect('main/event/rsvp/cancel', - array('action' => 'cancelrsvp')); + array('action' => 'rsvp')); + $m->connect('main/event/rsvp/:rsvp', // this will probably change to include event notice id + array('action' => 'rsvp'), + array('rsvp' => '[a-z]+')); $m->connect('event/:id', array('action' => 'showevent'), array('id' => '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}')); @@ -101,7 +102,7 @@ class EventPlugin extends ActivityVerbHandlerPlugin $versions[] = array('name' => 'Event', 'version' => GNUSOCIAL_VERSION, 'author' => 'Evan Prodromou', - 'homepage' => 'http://status.net/wiki/Plugin:Event', + 'homepage' => 'https://git.gnu.io/gnu/gnu-social/tree/master/plugins/Event', 'description' => // TRANS: Plugin description. _m('Event invitations and RSVPs.')); @@ -128,6 +129,13 @@ class EventPlugin extends ActivityVerbHandlerPlugin RSVP::POSSIBLE); } + function isMyNotice(Notice $notice) { + if (!empty($notice->object_type)) { + return parent::isMyNotice($notice); + } + return $this->isMyVerb($notice->verb); + } + public function newFormAction() { // such as 'newbookmark' or 'newevent' route return 'new'.$this->tag(); @@ -190,57 +198,22 @@ class EventPlugin extends ActivityVerbHandlerPlugin $happening = null; switch (true) { - case ActivityUtils::compareVerbs($stored->verb, array(ActivityVerb::POST)) && - ActivityUtils::compareTypes($stored->object_type, array(Happening::OBJECT_TYPE)): - $happening = Happening::fromStored($stored); + case $stored->isVerb([ActivityVerb::POST]) && $stored->isObjectType([Happening::OBJECT_TYPE]): + $obj = Happening::fromStored($stored)->asActivityObject(); break; - // FIXME: Why are these object_type?? - case ActivityUtils::compareTypes($stored->object_type, array(RSVP::POSITIVE, RSVP::NEGATIVE, RSVP::POSSIBLE)): - $rsvp = RSVP::fromNotice($stored); - $happening = $rsvp->getEvent(); + // isObjectType here is because we had the verb stored in object_type previously for unknown reasons + case $stored->isObjectType([RSVP::POSITIVE, RSVP::NEGATIVE, RSVP::POSSIBLE]): + case $stored->isVerb([RSVP::POSITIVE, RSVP::NEGATIVE, RSVP::POSSIBLE]): + $obj = RSVP::fromStored($stored)->asActivityObject(); break; default: // TRANS: Exception thrown when event plugin comes across a unknown object type. throw new Exception(_m('Unknown object type.')); } - $obj = new ActivityObject(); - - $obj->id = $happening->getUri(); - $obj->type = Happening::OBJECT_TYPE; - $obj->title = $happening->title; - $obj->summary = $happening->description; - $obj->link = $happening->getStored()->getUrl(); - - $obj->extra[] = array('dtstart', - array('xmlns' => 'urn:ietf:params:xml:ns:xcal'), - common_date_iso8601($happening->start_time)); - $obj->extra[] = array('dtend', - array('xmlns' => 'urn:ietf:params:xml:ns:xcal'), - common_date_iso8601($happening->end_time)); - $obj->extra[] = array('location', false, $happening->location); - $obj->extra[] = array('url', false, $happening->url); - return $obj; } - /** - * Change the verb on RSVP notices - * - * @param Notice $notice - * - * @return ActivityObject - */ - protected function extendActivity(Notice $stored, Activity $act, Profile $scoped=null) { - switch (true) { - // FIXME: Why are these object_type?? - case ActivityUtils::compareTypes($stored->object_type, array(RSVP::POSITIVE, RSVP::NEGATIVE, RSVP::POSSIBLE)): - $act->verb = $stored->object_type; - break; - } - return true; - } - /** * Form for our app * @@ -252,33 +225,29 @@ class EventPlugin extends ActivityVerbHandlerPlugin return new EventForm($out); } - /** - * When a notice is deleted, clean up related tables. - * - * @param Notice $notice - */ - function deleteRelated(Notice $notice) + function deleteRelated(Notice $stored) { - switch ($notice->object_type) { - case Happening::OBJECT_TYPE: + switch (true) { + case $stored->isObjectType([Happening::OBJECT_TYPE]): common_log(LOG_DEBUG, "Deleting event from notice..."); try { - $happening = Happening::fromStored($notice); + $happening = Happening::fromStored($stored); $happening->delete(); } catch (NoResultException $e) { // already gone } break; - case RSVP::POSITIVE: - case RSVP::NEGATIVE: - case RSVP::POSSIBLE: + // isObjectType here is because we had the verb stored in object_type previously for unknown reasons + case $stored->isObjectType([RSVP::POSITIVE, RSVP::NEGATIVE, RSVP::POSSIBLE]): + case $stored->isVerb([RSVP::POSITIVE, RSVP::NEGATIVE, RSVP::POSSIBLE]): common_log(LOG_DEBUG, "Deleting rsvp from notice..."); - $rsvp = RSVP::fromNotice($notice); - common_log(LOG_DEBUG, "to delete: $rsvp->id"); - $rsvp->delete(); + try { + $rsvp = RSVP::fromStored($stored); + $rsvp->delete(); + } catch (NoResultException $e) { + // already gone + } break; - default: - common_log(LOG_DEBUG, "Not deleting related, wtf..."); } } @@ -320,7 +289,6 @@ class EventPlugin extends ActivityVerbHandlerPlugin protected function showEvent(Notice $stored, HTMLOutputter $out, Profile $scoped=null) { - common_debug('shownotice'.$stored->getID()); $profile = $stored->getProfile(); $event = Happening::fromStored($stored); @@ -433,14 +401,7 @@ class EventPlugin extends ActivityVerbHandlerPlugin $out->elementEnd('div'); if ($scoped instanceof Profile) { - $rsvp = $event->getRSVP($scoped); - - if (empty($rsvp)) { - $form = new RSVPForm($event, $out); - } else { - $form = new CancelRSVPForm($rsvp, $out); - } - + $form = new RSVPForm($out, array('event'=>$event, 'scoped'=>$scoped)); $form->show(); } $out->elementEnd('div'); @@ -448,9 +409,9 @@ class EventPlugin extends ActivityVerbHandlerPlugin protected function showRSVP(Notice $stored, HTMLOutputter $out, Profile $scoped=null) { - $rsvp = RSVP::fromNotice($stored); - - if (empty($rsvp)) { + try { + $rsvp = RSVP::fromStored($stored); + } catch (NoResultException $e) { // TRANS: Content for a deleted RSVP list item (RSVP stands for "please respond"). $out->element('p', null, _m('Deleted.')); return;