Events get rendered.

This commit is contained in:
Mikael Nordfeldth 2016-01-18 23:58:32 +01:00
parent 15d12b209d
commit 385705c65b
4 changed files with 31 additions and 59 deletions

View File

@ -306,7 +306,6 @@ class BookmarkPlugin extends MicroAppPlugin
return true; return true;
} }
common_debug('Extending activity '.$stored->id.' with '.get_called_class());
$this->extendActivity($stored, $act, $scoped); $this->extendActivity($stored, $act, $scoped);
return false; return false;
} }

View File

@ -168,7 +168,7 @@ class EventPlugin extends ActivityVerbHandlerPlugin
protected function getActivityForm(ManagedAction $action, $verb, Notice $target, Profile $scoped) protected function getActivityForm(ManagedAction $action, $verb, Notice $target, Profile $scoped)
{ {
return new RSVPForm(Happening::fromNotice($target), $action); return new RSVPForm(Happening::fromStored($target), $action);
} }
protected function saveObjectFromActivity(Activity $act, Notice $stored, array $options=array()) protected function saveObjectFromActivity(Activity $act, Notice $stored, array $options=array())
@ -218,33 +218,27 @@ class EventPlugin extends ActivityVerbHandlerPlugin
{ {
$happening = null; $happening = null;
switch ($notice->object_type) { switch (true) {
case Happening::OBJECT_TYPE: case ActivityUtils::compareVerbs($notice->verb, array(ActivityVerb::POST)) &&
$happening = Happening::fromNotice($notice); ActivityUtils::compareTypes($notice->object_type, array(Happening::OBJECT_TYPE)):
$happening = Happening::fromStored($notice);
break; break;
case RSVP::POSITIVE: // FIXME: Why are these object_type??
case RSVP::NEGATIVE: case ActivityUtils::compareTypes($stored->object_type, array(RSVP::POSITIVE, RSVP::NEGATIVE, RSVP::POSSIBLE)):
case RSVP::POSSIBLE:
$rsvp = RSVP::fromNotice($notice); $rsvp = RSVP::fromNotice($notice);
$happening = $rsvp->getEvent(); $happening = $rsvp->getEvent();
break; break;
} default:
if (empty($happening)) {
// TRANS: Exception thrown when event plugin comes across a unknown object type. // TRANS: Exception thrown when event plugin comes across a unknown object type.
throw new Exception(_m('Unknown object type.')); throw new Exception(_m('Unknown object type.'));
} }
// This is a bit weird, if it's a Notice for a Happening. We should only do this for RSVP.
$notice = $happening->getNotice(); $notice = $happening->getNotice();
if (empty($notice)) {
// TRANS: Exception thrown when referring to a notice that is not an event an in event context.
throw new Exception(_m('Unknown event notice.'));
}
$obj = new ActivityObject(); $obj = new ActivityObject();
$obj->id = $happening->uri; $obj->id = $happening->getUri();
$obj->type = Happening::OBJECT_TYPE; $obj->type = Happening::OBJECT_TYPE;
$obj->title = $happening->title; $obj->title = $happening->title;
$obj->summary = $happening->description; $obj->summary = $happening->description;
@ -255,16 +249,15 @@ class EventPlugin extends ActivityVerbHandlerPlugin
$obj->extra[] = array('dtstart', $obj->extra[] = array('dtstart',
array('xmlns' => 'urn:ietf:params:xml:ns:xcal'), array('xmlns' => 'urn:ietf:params:xml:ns:xcal'),
common_date_iso8601($happening->start_time)); common_date_iso8601($happening->start_time));
$obj->extra[] = array('dtend', $obj->extra[] = array('dtend',
array('xmlns' => 'urn:ietf:params:xml:ns:xcal'), array('xmlns' => 'urn:ietf:params:xml:ns:xcal'),
common_date_iso8601($happening->end_time)); common_date_iso8601($happening->end_time));
$obj->extra[] = array('location', false, $happening->location); $obj->extra[] = array('location', false, $happening->location);
$obj->extra[] = array('url', false, $happening->url); $obj->extra[] = array('url', false, $happening->url);
// XXX: probably need other stuff here // XXX: probably need other stuff here
common_debug('EVENTDEBUG: activity object from notice: '._ve($obj));
return $obj; return $obj;
} }
@ -276,10 +269,9 @@ class EventPlugin extends ActivityVerbHandlerPlugin
* @return ActivityObject * @return ActivityObject
*/ */
protected function extendActivity(Notice $stored, Activity $act, Profile $scoped=null) { protected function extendActivity(Notice $stored, Activity $act, Profile $scoped=null) {
switch ($stored->object_type) { switch (true) {
case RSVP::POSITIVE: // FIXME: Why are these object_type??
case RSVP::NEGATIVE: case ActivityUtils::compareTypes($stored->object_type, array(RSVP::POSITIVE, RSVP::NEGATIVE, RSVP::POSSIBLE)):
case RSVP::POSSIBLE:
$act->verb = $stored->object_type; $act->verb = $stored->object_type;
break; break;
} }
@ -307,7 +299,7 @@ class EventPlugin extends ActivityVerbHandlerPlugin
switch ($notice->object_type) { switch ($notice->object_type) {
case Happening::OBJECT_TYPE: case Happening::OBJECT_TYPE:
common_log(LOG_DEBUG, "Deleting event from notice..."); common_log(LOG_DEBUG, "Deleting event from notice...");
$happening = Happening::fromNotice($notice); $happening = Happening::fromStored($notice);
$happening->delete(); $happening->delete();
break; break;
case RSVP::POSITIVE: case RSVP::POSITIVE:
@ -352,28 +344,25 @@ class EventPlugin extends ActivityVerbHandlerPlugin
protected function showNoticeContent(Notice $stored, HTMLOutputter $out, Profile $scoped=null) protected function showNoticeContent(Notice $stored, HTMLOutputter $out, Profile $scoped=null)
{ {
switch ($stored->object_type) { switch (true) {
case Happening::OBJECT_TYPE: case ActivityUtils::compareTypes($stored->verb, array(ActivityVerb::POST)) &&
ActivityUtils::compareTypes($stored->object_type, array(Happening::OBJECT_TYPE)):
$this->showEvent($stored, $out, $scoped); $this->showEvent($stored, $out, $scoped);
break; break;
case RSVP::POSITIVE: case ActivityUtils::compareVerbs($stored->verb, array(RSVP::POSITIVE, RSVP::NEGATIVE, RSVP::POSSIBLE)):
case RSVP::NEGATIVE:
case RSVP::POSSIBLE:
$this->showRSVP($stored, $out, $scoped); $this->showRSVP($stored, $out, $scoped);
break; break;
default:
throw new ServerException('This is not an Event notice');
} }
return true;
} }
protected function showEvent(Notice $stored, HTMLOutputter $out, Profile $scoped=null) protected function showEvent(Notice $stored, HTMLOutputter $out, Profile $scoped=null)
{ {
common_debug('shownotice'.$stored->getID());
$profile = $stored->getProfile(); $profile = $stored->getProfile();
$event = Happening::fromNotice($stored); $event = Happening::fromStored($stored);
if (!$event instanceof Happening) {
// TRANS: Content for a deleted RSVP list item (RSVP stands for "please respond").
$out->element('p', null, _m('Deleted.'));
return;
}
$out->elementStart('div', 'h-event'); $out->elementStart('div', 'h-event');

View File

@ -132,24 +132,7 @@ class NeweventAction extends FormAction
$actobj->id = UUID::gen(); $actobj->id = UUID::gen();
$actobj->type = Happening::OBJECT_TYPE; $actobj->type = Happening::OBJECT_TYPE;
$actobj->title = $title; $actobj->title = $title;
// TRANS: Rendered microformats2 tagged event description. $actobj->summary = $description;
// TRANS: %1$s is a title, %2$s is iso8601 start time, %3$s is start time,
// TRANS: %4$s is iso8601 end time, %5$s is end time, %6$s is location, %7$s is description.
// TRANS: Class names should not be translated.
$actobj->summary = sprintf(_m('<div class="h-event">'.
'<p class="p-name p-summary">%1$s</p> '.
'<time class="dt-start" datetime="%2$s">%3$s</time> - '.
'<time class="dt-end" datetime="%4$s">%5$s</time> '.
'(<span class="p-location">%6$s</span>): '.
'<div class="p-description">%7$s</div> '.
'</div>'),
htmlspecialchars($title),
htmlspecialchars(common_date_iso8601($start_str)),
htmlspecialchars(common_exact_date($start_str)),
htmlspecialchars(common_date_iso8601($end_str)),
htmlspecialchars(common_exact_date($end_str)),
htmlspecialchars($location),
htmlspecialchars($description));
$actobj->extra[] = array('dtstart', $actobj->extra[] = array('dtstart',
array('xmlns' => 'urn:ietf:params:xml:ns:xcal'), array('xmlns' => 'urn:ietf:params:xml:ns:xcal'),

View File

@ -94,7 +94,8 @@ class Happening extends Managed_DataObject
'unique keys' => array( 'unique keys' => array(
'happening_uri_key' => array('uri'), 'happening_uri_key' => array('uri'),
), ),
'foreign keys' => array('happening_profile_id__key' => array('profile', array('profile_id' => 'id'))), 'foreign keys' => array('happening_profile_id__key' => array('profile', array('profile_id' => 'id')),
'happening_uri__key' => array('notice', array('uri' => 'uri'))),
'indexes' => array('happening_created_idx' => array('created'), 'indexes' => array('happening_created_idx' => array('created'),
'happening_start_end_idx' => array('start_time', 'end_time')), 'happening_start_end_idx' => array('start_time', 'end_time')),
); );
@ -192,14 +193,14 @@ class Happening extends Managed_DataObject
return $this->uri; return $this->uri;
} }
function getNotice() public function getNotice()
{ {
return Notice::getKV('uri', $this->getUri()); return Notice::getByKeys(array('uri'=>$this->getUri()));
} }
static function fromNotice($notice) static function fromStored(Notice $stored)
{ {
return Happening::getKV('uri', $notice->getUri()); return self::getByKeys(array('uri'=>$stored->getUri()));
} }
function getRSVPs() function getRSVPs()