2011-03-08 16:15:17 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2011-03-09 07:33:26 +00:00
|
|
|
* StatusNet - the distributed open-source microblogging tool
|
|
|
|
* Copyright (C) 2011, StatusNet, Inc.
|
2011-03-08 16:15:17 +00:00
|
|
|
*
|
2011-03-09 07:33:26 +00:00
|
|
|
* Add a new event
|
2011-04-07 13:01:40 +01:00
|
|
|
*
|
2011-03-08 16:15:17 +00:00
|
|
|
* PHP version 5
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2011-03-09 07:33:26 +00:00
|
|
|
*
|
|
|
|
* @category Event
|
|
|
|
* @package StatusNet
|
|
|
|
* @author Evan Prodromou <evan@status.net>
|
|
|
|
* @copyright 2011 StatusNet, Inc.
|
|
|
|
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
|
|
|
|
* @link http://status.net/
|
2011-03-08 16:15:17 +00:00
|
|
|
*/
|
2011-04-07 13:01:40 +01:00
|
|
|
|
2016-01-18 16:23:33 +00:00
|
|
|
if (!defined('GNUSOCIAL')) { exit(1); }
|
2011-03-08 16:15:17 +00:00
|
|
|
|
|
|
|
/**
|
2011-03-09 07:33:26 +00:00
|
|
|
* Add a new event
|
2011-03-08 16:15:17 +00:00
|
|
|
*
|
2011-03-09 07:33:26 +00:00
|
|
|
* @category Event
|
|
|
|
* @package StatusNet
|
|
|
|
* @author Evan Prodromou <evan@status.net>
|
|
|
|
* @copyright 2011 StatusNet, Inc.
|
|
|
|
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
|
|
|
|
* @link http://status.net/
|
2011-03-08 16:15:17 +00:00
|
|
|
*/
|
2016-01-18 16:23:33 +00:00
|
|
|
class NeweventAction extends FormAction
|
2011-03-08 16:15:17 +00:00
|
|
|
{
|
2016-01-18 16:23:33 +00:00
|
|
|
protected $form = 'Event';
|
2011-03-08 16:15:17 +00:00
|
|
|
|
|
|
|
/**
|
2011-03-09 07:33:26 +00:00
|
|
|
* Returns the title of the action
|
2011-03-08 16:15:17 +00:00
|
|
|
*
|
2011-03-09 07:33:26 +00:00
|
|
|
* @return string Action title
|
|
|
|
*/
|
|
|
|
function title()
|
|
|
|
{
|
2011-04-07 13:01:40 +01:00
|
|
|
// TRANS: Title for new event form.
|
|
|
|
return _m('TITLE','New event');
|
2011-03-09 07:33:26 +00:00
|
|
|
}
|
|
|
|
|
2016-01-18 16:23:33 +00:00
|
|
|
protected function doPost()
|
2011-03-08 16:15:17 +00:00
|
|
|
{
|
2016-01-18 16:23:33 +00:00
|
|
|
// HUMAN TEXT DATA
|
|
|
|
$title = $this->trimmed('title');
|
|
|
|
if (empty($title)) {
|
|
|
|
// TRANS: Client exception thrown when trying to post an event without providing a title.
|
|
|
|
throw new ClientException(_m('Event must have a title.'));
|
2011-03-09 07:33:26 +00:00
|
|
|
}
|
2016-01-18 16:23:33 +00:00
|
|
|
$description = $this->trimmed('description');
|
2011-03-09 07:33:26 +00:00
|
|
|
|
2011-03-16 23:08:35 +00:00
|
|
|
|
2016-01-18 16:23:33 +00:00
|
|
|
// TIME PARSING
|
|
|
|
$tz = $this->trimmed('tz');
|
2011-03-16 23:08:35 +00:00
|
|
|
|
2016-01-18 16:23:33 +00:00
|
|
|
$startDate = $this->trimmed('startdate');
|
|
|
|
if (empty($startDate)) {
|
|
|
|
// TRANS: Client exception thrown when trying to post an event without providing a start date.
|
|
|
|
throw new ClientException(_m('Start date required.'));
|
2011-03-16 23:08:35 +00:00
|
|
|
}
|
2016-01-18 16:23:33 +00:00
|
|
|
$startTime = $this->trimmed('event-starttime');
|
|
|
|
if (empty($startTime)) {
|
|
|
|
// TRANS: Client exception thrown when trying to post an event without providing a start time.
|
|
|
|
throw new ClientException(_m('Event must have a start time.'));
|
|
|
|
}
|
|
|
|
$start_str = sprintf('%s %s %s', $startDate, $startTime, $tz);
|
|
|
|
$start = strtotime($start_str);
|
|
|
|
if ($start === false) {
|
|
|
|
// TRANS: Client exception thrown when trying to post an event with a date that cannot be processed.
|
|
|
|
// TRANS: %s is the data that could not be processed.
|
|
|
|
throw new ClientException(sprintf(_m('Could not parse date %s.'), _ve($start_str)));
|
2011-03-09 07:33:26 +00:00
|
|
|
}
|
2011-03-08 16:15:17 +00:00
|
|
|
|
2016-01-18 16:23:33 +00:00
|
|
|
$endDate = $this->trimmed('enddate');
|
|
|
|
if (empty($endDate)) {
|
|
|
|
// TRANS: Client exception thrown when trying to post an event without providing an end date.
|
|
|
|
throw new ClientException(_m('End date required.'));
|
|
|
|
}
|
|
|
|
$endTime = $this->trimmed('event-endtime');
|
|
|
|
if (empty($endTime)) {
|
|
|
|
// TRANS: Client exception thrown when trying to post an event without providing an end time.
|
|
|
|
throw new ClientException(_m('Event must have an end time.'));
|
|
|
|
}
|
|
|
|
$end_str = sprintf('%s %s %s', $endDate, $endTime, $tz);
|
|
|
|
$end = strtotime($end_str);
|
|
|
|
if ($end === false) {
|
|
|
|
// TRANS: Client exception thrown when trying to post an event with a date that cannot be processed.
|
|
|
|
// TRANS: %s is the data that could not be processed.
|
|
|
|
throw new ClientException(sprintf(_m('Could not parse date %s.'), _ve($end_str)));
|
|
|
|
}
|
2011-03-09 07:33:26 +00:00
|
|
|
|
2016-01-18 16:23:33 +00:00
|
|
|
$url = $this->trimmed('url');
|
|
|
|
if (!empty($url) && !common_valid_http_url($url)) {
|
|
|
|
// TRANS: Client exception thrown when trying to post an event with an invalid (non-empty) URL.
|
|
|
|
throw new ClientException(_m('An event URL must be a valid HTTP/HTTPS link.'));
|
|
|
|
}
|
2011-03-09 07:33:26 +00:00
|
|
|
|
2011-09-08 09:14:24 +01:00
|
|
|
|
2016-01-18 16:23:33 +00:00
|
|
|
// LOCATION DATA
|
|
|
|
$location = $this->trimmed('location');
|
2011-04-05 03:16:38 +01:00
|
|
|
|
|
|
|
|
2011-04-07 13:01:40 +01:00
|
|
|
|
2016-01-18 16:23:33 +00:00
|
|
|
$options = [ 'source' => 'web' ];
|
2011-03-09 15:07:30 +00:00
|
|
|
|
2016-01-18 16:23:33 +00:00
|
|
|
$act = new Activity();
|
|
|
|
$act->verb = ActivityVerb::POST;
|
|
|
|
$act->time = time();
|
|
|
|
$act->actor = $this->scoped->asActivityObject();
|
2011-03-09 07:33:26 +00:00
|
|
|
|
2016-01-18 16:23:33 +00:00
|
|
|
$act->context = new ActivityContext();
|
|
|
|
// FIXME: Add location here? Let's make it possible to include current location with less code...
|
2011-03-09 17:28:25 +00:00
|
|
|
|
|
|
|
|
2016-01-18 16:23:33 +00:00
|
|
|
$actobj = new ActivityObject();
|
|
|
|
$actobj->id = UUID::gen();
|
|
|
|
$actobj->type = Happening::OBJECT_TYPE;
|
|
|
|
$actobj->title = $title;
|
|
|
|
// TRANS: Rendered microformats2 tagged event 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));
|
2011-03-09 07:33:26 +00:00
|
|
|
|
2016-01-18 16:23:33 +00:00
|
|
|
$actobj->extra[] = array('dtstart',
|
|
|
|
array('xmlns' => 'urn:ietf:params:xml:ns:xcal'),
|
|
|
|
common_date_iso8601($start_str));
|
|
|
|
$actobj->extra[] = array('dtend',
|
|
|
|
array('xmlns' => 'urn:ietf:params:xml:ns:xcal'),
|
|
|
|
common_date_iso8601($start_str));
|
|
|
|
$actobj->extra[] = array('location', false, $location);
|
|
|
|
$actobj->extra[] = array('url', false, $url);
|
2011-03-09 07:33:26 +00:00
|
|
|
|
2016-01-18 16:23:33 +00:00
|
|
|
$act->objects = array($actobj);
|
2011-03-09 07:33:26 +00:00
|
|
|
|
2016-01-18 16:23:33 +00:00
|
|
|
$stored = Notice::saveActivity($act, $this->scoped);
|
2011-03-09 07:33:26 +00:00
|
|
|
|
2016-01-18 16:23:33 +00:00
|
|
|
return _m('Saved the event.');
|
2011-03-09 07:48:14 +00:00
|
|
|
}
|
2011-03-08 16:15:17 +00:00
|
|
|
}
|