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('event', 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 'ShoweventAction':
83 case 'ShowrsvpAction':
84 include_once $dir . '/' . strtolower(mb_substr($cls, 0, -6)) . '.php';
87 include_once $dir . '/'.strtolower($cls).'.php';
91 include_once $dir . '/'.$cls.'.php';
101 * @param Net_URL_Mapper $m path-to-action mapper
103 * @return boolean hook value; true means continue processing, false means stop.
106 function onRouterInitialized($m)
108 $m->connect('main/event/new',
109 array('action' => 'newevent'));
110 $m->connect('main/event/rsvp',
111 array('action' => 'newrsvp'));
112 $m->connect('event/:id',
113 array('action' => 'showevent'),
114 array('id' => '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}'));
115 $m->connect('rsvp/:id',
116 array('action' => 'showrsvp'),
117 array('id' => '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}'));
121 function onPluginVersion(&$versions)
123 $versions[] = array('name' => 'Event',
124 'version' => STATUSNET_VERSION,
125 'author' => 'Evan Prodromou',
126 'homepage' => 'http://status.net/wiki/Plugin:Event',
128 _m('Event invitations and RSVPs.'));
132 function appTitle() {
141 return array(Happening::OBJECT_TYPE,
148 * Given a parsed ActivityStreams activity, save it into a notice
149 * and other data structures.
151 * @param Activity $activity
152 * @param Profile $actor
153 * @param array $options=array()
155 * @return Notice the resulting notice
157 function saveNoticeFromActivity($activity, $actor, $options=array())
159 if (count($activity->objects) != 1) {
160 throw new Exception('Too many activity objects.');
163 $happeningObj = $activity->objects[0];
165 if ($happeningObj->type != Happening::OBJECT_TYPE) {
166 throw new Exception('Wrong type for object.');
171 switch ($activity->verb) {
172 case ActivityVerb::POST:
173 $notice = Happening::saveNew($actor,
176 $happeningObj->title,
178 $happeningObj->summary,
184 $happening = Happening::staticGet('uri', $happeningObj->id);
185 if (empty($happening)) {
186 // FIXME: save the event
187 throw new Exception("RSVP for unknown event.");
189 $notice = RSVP::saveNew($actor, $happening, $activity->verb, $options);
192 throw new Exception("Unknown verb for events");
199 * Turn a Notice into an activity object
201 * @param Notice $notice
203 * @return ActivityObject
206 function activityObjectFromNotice($notice)
210 switch ($notice->object_type) {
211 case Happening::OBJECT_TYPE:
212 $happening = Happening::fromNotice($notice);
217 $rsvp = RSVP::fromNotice($notice);
218 $happening = $rsvp->getEvent();
222 if (empty($happening)) {
223 throw new Exception("Unknown object type.");
226 $notice = $happening->getNotice();
228 if (empty($notice)) {
229 throw new Exception("Unknown event notice.");
232 $obj = new ActivityObject();
234 $obj->id = $happening->uri;
235 $obj->type = Happening::OBJECT_TYPE;
236 $obj->title = $happening->title;
237 $obj->summary = $happening->description;
238 $obj->link = $notice->bestUrl();
240 // XXX: how to get this stuff into JSON?!
242 $obj->extra[] = array('dtstart',
243 array('xmlns' => 'urn:ietf:params:xml:ns:xcal'),
244 common_date_iso8601($happening->start_date));
246 $obj->extra[] = array('dtend',
247 array('xmlns' => 'urn:ietf:params:xml:ns:xcal'),
248 common_date_iso8601($happening->end_date));
250 // XXX: probably need other stuff here
256 * Change the verb on RSVP notices
258 * @param Notice $notice
260 * @return ActivityObject
263 function onEndNoticeAsActivity($notice, &$act) {
264 switch ($notice->object_type) {
268 $act->verb = $notice->object_type;
275 * Custom HTML output for our notices
277 * @param Notice $notice
278 * @param HTMLOutputter $out
281 function showNotice($notice, $out)
283 switch ($notice->object_type) {
284 case Happening::OBJECT_TYPE:
285 $this->showEventNotice($notice, $out);
290 $this->showRSVPNotice($notice, $out);
295 function showRSVPNotice($notice, $out)
297 $out->element('span', null, 'RSVP');
301 function showEventNotice($notice, $out)
303 $out->raw($notice->rendered);
310 * @param HTMLOutputter $out
314 function entryForm($out)
316 return new EventForm($out);
320 * When a notice is deleted, clean up related tables.
322 * @param Notice $notice
325 function deleteRelated($notice)
327 switch ($notice->object_type) {
328 case Happening::OBJECT_TYPE:
329 $happening = Happening::fromNotice($notice);
330 $happening->delete();
335 $rsvp = RSVP::fromNotice($notice);