3 * StatusNet - the distributed open-source microblogging tool
4 * Copyright (C) 2011, StatusNet, Inc.
6 * Microapp plugin for event invitations and RSVPs
10 * This program is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU Affero General Public License as published by
12 * the Free Software Foundation, either version 3 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Affero General Public License for more details.
20 * You should have received a copy of the GNU Affero General Public License
21 * along with this program. If not, see <http://www.gnu.org/licenses/>.
25 * @author Evan Prodromou <evan@status.net>
26 * @copyright 2011 StatusNet, Inc.
27 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
28 * @link http://status.net/
31 if (!defined('STATUSNET')) {
32 // This check helps protect against security problems;
33 // your code file can't be executed directly from the web.
42 * @author Evan Prodromou <evan@status.net>
43 * @copyright 2011 StatusNet, Inc.
44 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
45 * @link http://status.net/
47 class EventPlugin extends MicroappPlugin
50 * Set up our tables (event and rsvp)
55 * @return boolean hook value; true means continue processing, false means stop.
57 function onCheckSchema()
59 $schema = Schema::get();
61 $schema->ensureTable('happening', Happening::schemaDef());
62 $schema->ensureTable('rsvp', RSVP::schemaDef());
68 * Load related modules when needed
70 * @param string $cls Name of the class to be loaded
72 * @return boolean hook value; true means continue processing, false means stop.
74 function onAutoload($cls)
76 $dir = dirname(__FILE__);
80 case 'NeweventAction':
82 case 'CancelrsvpAction':
83 case 'ShoweventAction':
84 case 'ShowrsvpAction':
85 case 'TimelistAction':
86 include_once $dir . '/' . strtolower(mb_substr($cls, 0, -6)) . '.php';
92 case 'CancelRSVPForm':
94 include_once $dir . '/'.strtolower($cls).'.php';
98 include_once $dir . '/'.$cls.'.php';
106 * Map URLs to actions
108 * @param Net_URL_Mapper $m path-to-action mapper
110 * @return boolean hook value; true means continue processing, false means stop.
112 function onRouterInitialized($m)
114 $m->connect('main/event/new',
115 array('action' => 'newevent'));
116 $m->connect('main/event/rsvp',
117 array('action' => 'newrsvp'));
118 $m->connect('main/event/rsvp/cancel',
119 array('action' => 'cancelrsvp'));
120 $m->connect('event/:id',
121 array('action' => 'showevent'),
122 array('id' => '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}'));
123 $m->connect('rsvp/:id',
124 array('action' => 'showrsvp'),
125 array('id' => '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}'));
126 $m->connect('main/event/updatetimes',
127 array('action' => 'timelist'));
131 function onPluginVersion(&$versions)
133 $versions[] = array('name' => 'Event',
134 'version' => STATUSNET_VERSION,
135 'author' => 'Evan Prodromou',
136 'homepage' => 'http://status.net/wiki/Plugin:Event',
138 // TRANS: Plugin description.
139 _m('Event invitations and RSVPs.'));
143 function appTitle() {
144 // TRANS: Title for event application.
145 return _m('TITLE','Event');
153 return array(Happening::OBJECT_TYPE,
160 * Given a parsed ActivityStreams activity, save it into a notice
161 * and other data structures.
163 * @param Activity $activity
164 * @param Profile $actor
165 * @param array $options=array()
167 * @return Notice the resulting notice
169 function saveNoticeFromActivity($activity, $actor, $options=array())
171 if (count($activity->objects) != 1) {
172 // TRANS: Exception thrown when there are too many activity objects.
173 throw new Exception(_m('Too many activity objects.'));
176 $happeningObj = $activity->objects[0];
178 if ($happeningObj->type != Happening::OBJECT_TYPE) {
179 // TRANS: Exception thrown when event plugin comes across a non-event type object.
180 throw new Exception(_m('Wrong type for object.'));
185 switch ($activity->verb) {
186 case ActivityVerb::POST:
187 // FIXME: get startTime, endTime, location and URL
188 $notice = Happening::saveNew($actor,
191 $happeningObj->title,
193 $happeningObj->summary,
200 $happening = Happening::staticGet('uri', $happeningObj->id);
201 if (empty($happening)) {
202 // FIXME: save the event
203 // TRANS: Exception thrown when trying to RSVP for an unknown event.
204 throw new Exception(_m('RSVP for unknown event.'));
206 $notice = RSVP::saveNew($actor, $happening, $activity->verb, $options);
209 // TRANS: Exception thrown when event plugin comes across a undefined verb.
210 throw new Exception(_m('Unknown verb for events.'));
217 * Turn a Notice into an activity object
219 * @param Notice $notice
221 * @return ActivityObject
223 function activityObjectFromNotice($notice)
227 switch ($notice->object_type) {
228 case Happening::OBJECT_TYPE:
229 $happening = Happening::fromNotice($notice);
234 $rsvp = RSVP::fromNotice($notice);
235 $happening = $rsvp->getEvent();
239 if (empty($happening)) {
240 // TRANS: Exception thrown when event plugin comes across a unknown object type.
241 throw new Exception(_m('Unknown object type.'));
244 $notice = $happening->getNotice();
246 if (empty($notice)) {
247 // TRANS: Exception thrown when referring to a notice that is not an event an in event context.
248 throw new Exception(_m('Unknown event notice.'));
251 $obj = new ActivityObject();
253 $obj->id = $happening->uri;
254 $obj->type = Happening::OBJECT_TYPE;
255 $obj->title = $happening->title;
256 $obj->summary = $happening->description;
257 $obj->link = $notice->bestUrl();
259 // XXX: how to get this stuff into JSON?!
261 $obj->extra[] = array('dtstart',
262 array('xmlns' => 'urn:ietf:params:xml:ns:xcal'),
263 common_date_iso8601($happening->start_time));
265 $obj->extra[] = array('dtend',
266 array('xmlns' => 'urn:ietf:params:xml:ns:xcal'),
267 common_date_iso8601($happening->end_time));
269 // FIXME: add location
272 // XXX: probably need other stuff here
278 * Change the verb on RSVP notices
280 * @param Notice $notice
282 * @return ActivityObject
284 function onEndNoticeAsActivity($notice, &$act) {
285 switch ($notice->object_type) {
289 $act->verb = $notice->object_type;
295 function adaptNoticeListItem($nli)
297 $notice = $nli->notice;
299 switch ($notice->object_type) {
300 case Happening::OBJECT_TYPE:
301 return new EventListItem($nli);
306 return new RSVPListItem($nli);
316 * @param HTMLOutputter $out
319 function entryForm($out)
321 return new EventForm($out);
325 * When a notice is deleted, clean up related tables.
327 * @param Notice $notice
329 function deleteRelated($notice)
331 switch ($notice->object_type) {
332 case Happening::OBJECT_TYPE:
333 common_log(LOG_DEBUG, "Deleting event from notice...");
334 $happening = Happening::fromNotice($notice);
335 $happening->delete();
340 common_log(LOG_DEBUG, "Deleting rsvp from notice...");
341 $rsvp = RSVP::fromNotice($notice);
342 common_log(LOG_DEBUG, "to delete: $rsvp->id");
346 common_log(LOG_DEBUG, "Not deleting related, wtf...");
350 function onEndShowScripts($action)
352 $action->script($this->path('event.js'));
355 function onEndShowStyles($action)
357 $action->cssLink($this->path('event.css'));
361 function onStartAddNoticeReply($nli, $parent, $child)
363 // Filter out any poll responses
364 if (($parent->object_type == Happening::OBJECT_TYPE) &&
365 in_array($child->object_type, array(RSVP::POSITIVE, RSVP::NEGATIVE, RSVP::POSSIBLE))) {