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());
70 * @param Net_URL_Mapper $m path-to-action mapper
72 * @return boolean hook value; true means continue processing, false means stop.
74 function onRouterInitialized($m)
76 $m->connect('main/event/new',
77 array('action' => 'newevent'));
78 $m->connect('main/event/rsvp',
79 array('action' => 'newrsvp'));
80 $m->connect('main/event/rsvp/cancel',
81 array('action' => 'cancelrsvp'));
82 $m->connect('event/:id',
83 array('action' => 'showevent'),
84 array('id' => '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}'));
85 $m->connect('rsvp/:id',
86 array('action' => 'showrsvp'),
87 array('id' => '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}'));
88 $m->connect('main/event/updatetimes',
89 array('action' => 'timelist'));
93 function onPluginVersion(&$versions)
95 $versions[] = array('name' => 'Event',
96 'version' => GNUSOCIAL_VERSION,
97 'author' => 'Evan Prodromou',
98 'homepage' => 'http://status.net/wiki/Plugin:Event',
100 // TRANS: Plugin description.
101 _m('Event invitations and RSVPs.'));
105 function appTitle() {
106 // TRANS: Title for event application.
107 return _m('TITLE','Event');
115 return array(Happening::OBJECT_TYPE,
122 * Given a parsed ActivityStreams activity, save it into a notice
123 * and other data structures.
125 * @param Activity $activity
126 * @param Profile $actor
127 * @param array $options=array()
129 * @return Notice the resulting notice
131 function saveNoticeFromActivity($activity, $actor, $options=array())
133 if (count($activity->objects) != 1) {
134 // TRANS: Exception thrown when there are too many activity objects.
135 throw new Exception(_m('Too many activity objects.'));
138 $happeningObj = $activity->objects[0];
140 if ($happeningObj->type != Happening::OBJECT_TYPE) {
141 // TRANS: Exception thrown when event plugin comes across a non-event type object.
142 throw new Exception(_m('Wrong type for object.'));
147 switch ($activity->verb) {
148 case ActivityVerb::POST:
149 // FIXME: get startTime, endTime, location and URL
150 $notice = Happening::saveNew($actor,
153 $happeningObj->title,
155 $happeningObj->summary,
162 $happening = Happening::getKV('uri', $happeningObj->id);
163 if (empty($happening)) {
164 // FIXME: save the event
165 // TRANS: Exception thrown when trying to RSVP for an unknown event.
166 throw new Exception(_m('RSVP for unknown event.'));
168 $notice = RSVP::saveNew($actor, $happening, $activity->verb, $options);
171 // TRANS: Exception thrown when event plugin comes across a undefined verb.
172 throw new Exception(_m('Unknown verb for events.'));
179 * Turn a Notice into an activity object
181 * @param Notice $notice
183 * @return ActivityObject
185 function activityObjectFromNotice($notice)
189 switch ($notice->object_type) {
190 case Happening::OBJECT_TYPE:
191 $happening = Happening::fromNotice($notice);
196 $rsvp = RSVP::fromNotice($notice);
197 $happening = $rsvp->getEvent();
201 if (empty($happening)) {
202 // TRANS: Exception thrown when event plugin comes across a unknown object type.
203 throw new Exception(_m('Unknown object type.'));
206 $notice = $happening->getNotice();
208 if (empty($notice)) {
209 // TRANS: Exception thrown when referring to a notice that is not an event an in event context.
210 throw new Exception(_m('Unknown event notice.'));
213 $obj = new ActivityObject();
215 $obj->id = $happening->uri;
216 $obj->type = Happening::OBJECT_TYPE;
217 $obj->title = $happening->title;
218 $obj->summary = $happening->description;
219 $obj->link = $notice->getUrl();
221 // XXX: how to get this stuff into JSON?!
223 $obj->extra[] = array('dtstart',
224 array('xmlns' => 'urn:ietf:params:xml:ns:xcal'),
225 common_date_iso8601($happening->start_time));
227 $obj->extra[] = array('dtend',
228 array('xmlns' => 'urn:ietf:params:xml:ns:xcal'),
229 common_date_iso8601($happening->end_time));
231 // FIXME: add location
234 // XXX: probably need other stuff here
240 * Change the verb on RSVP notices
242 * @param Notice $notice
244 * @return ActivityObject
246 function onEndNoticeAsActivity($notice, &$act) {
247 switch ($notice->object_type) {
251 $act->verb = $notice->object_type;
257 function adaptNoticeListItem($nli)
259 $notice = $nli->notice;
261 switch ($notice->object_type) {
262 case Happening::OBJECT_TYPE:
263 return new EventListItem($nli);
268 return new RSVPListItem($nli);
278 * @param HTMLOutputter $out
281 function entryForm($out)
283 return new EventForm($out);
287 * When a notice is deleted, clean up related tables.
289 * @param Notice $notice
291 function deleteRelated($notice)
293 switch ($notice->object_type) {
294 case Happening::OBJECT_TYPE:
295 common_log(LOG_DEBUG, "Deleting event from notice...");
296 $happening = Happening::fromNotice($notice);
297 $happening->delete();
302 common_log(LOG_DEBUG, "Deleting rsvp from notice...");
303 $rsvp = RSVP::fromNotice($notice);
304 common_log(LOG_DEBUG, "to delete: $rsvp->id");
308 common_log(LOG_DEBUG, "Not deleting related, wtf...");
312 function onEndShowScripts($action)
314 $action->script($this->path('js/event.js'));
317 function onEndShowStyles($action)
319 $action->cssLink($this->path('css/event.css'));
323 function onStartAddNoticeReply($nli, $parent, $child)
325 // Filter out any poll responses
326 if (($parent->object_type == Happening::OBJECT_TYPE) &&
327 in_array($child->object_type, array(RSVP::POSITIVE, RSVP::NEGATIVE, RSVP::POSSIBLE))) {