3 * StatusNet - the distributed open-source microblogging tool
4 * Copyright (C) 2011, StatusNet, Inc.
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('GNUSOCIAL')) { exit(1); }
38 * @author Evan Prodromou <evan@status.net>
39 * @copyright 2011 StatusNet, Inc.
40 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
41 * @link http://status.net/
43 class NeweventAction extends FormAction
45 protected $form = 'Event';
48 * Returns the title of the action
50 * @return string Action title
54 // TRANS: Title for new event form.
55 return _m('TITLE','New event');
58 protected function doPost()
61 $title = $this->trimmed('title');
63 // TRANS: Client exception thrown when trying to post an event without providing a title.
64 throw new ClientException(_m('Event must have a title.'));
66 $description = $this->trimmed('description');
70 $tz = $this->trimmed('tz');
72 $startDate = $this->trimmed('startdate');
73 if (empty($startDate)) {
74 // TRANS: Client exception thrown when trying to post an event without providing a start date.
75 throw new ClientException(_m('Start date required.'));
77 $startTime = $this->trimmed('event-starttime');
78 if (empty($startTime)) {
79 // TRANS: Client exception thrown when trying to post an event without providing a start time.
80 throw new ClientException(_m('Event must have a start time.'));
82 $start_str = sprintf('%s %s %s', $startDate, $startTime, $tz);
83 $start = strtotime($start_str);
84 if ($start === false) {
85 // TRANS: Client exception thrown when trying to post an event with a date that cannot be processed.
86 // TRANS: %s is the data that could not be processed.
87 throw new ClientException(sprintf(_m('Could not parse date %s.'), _ve($start_str)));
90 $endDate = $this->trimmed('enddate');
91 if (empty($endDate)) {
92 // TRANS: Client exception thrown when trying to post an event without providing an end date.
93 throw new ClientException(_m('End date required.'));
95 $endTime = $this->trimmed('event-endtime');
96 if (empty($endTime)) {
97 // TRANS: Client exception thrown when trying to post an event without providing an end time.
98 throw new ClientException(_m('Event must have an end time.'));
100 $end_str = sprintf('%s %s %s', $endDate, $endTime, $tz);
101 $end = strtotime($end_str);
102 if ($end === false) {
103 // TRANS: Client exception thrown when trying to post an event with a date that cannot be processed.
104 // TRANS: %s is the data that could not be processed.
105 throw new ClientException(sprintf(_m('Could not parse date %s.'), _ve($end_str)));
108 $url = $this->trimmed('url');
109 if (!empty($url) && !common_valid_http_url($url)) {
110 // TRANS: Client exception thrown when trying to post an event with an invalid (non-empty) URL.
111 throw new ClientException(_m('An event URL must be a valid HTTP/HTTPS link.'));
116 $location = $this->trimmed('location');
120 $options = [ 'source' => 'web' ];
122 $act = new Activity();
123 $act->verb = ActivityVerb::POST;
125 $act->actor = $this->scoped->asActivityObject();
127 $act->context = new ActivityContext();
128 // FIXME: Add location here? Let's make it possible to include current location with less code...
131 $actobj = new ActivityObject();
132 $actobj->id = UUID::gen();
133 $actobj->type = Happening::OBJECT_TYPE;
134 $actobj->title = $title;
135 $actobj->summary = $description;
137 $actobj->extra[] = array('dtstart',
138 array('xmlns' => 'urn:ietf:params:xml:ns:xcal'),
139 common_date_iso8601($start_str));
140 $actobj->extra[] = array('dtend',
141 array('xmlns' => 'urn:ietf:params:xml:ns:xcal'),
142 common_date_iso8601($end_str));
143 $actobj->extra[] = array('location', false, $location);
144 $actobj->extra[] = array('url', false, $url);
146 $act->objects = array($actobj);
148 $stored = Notice::saveActivity($act, $this->scoped);
150 return _m('Saved the event.');