123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167 |
- <?php
- if (!defined('GNUSOCIAL')) { exit(1); }
- class NeweventAction extends FormAction
- {
- protected $form = 'Event';
-
- function title()
- {
-
- return _m('TITLE','New event');
- }
- protected function doPost()
- {
-
- $title = $this->trimmed('title');
- if (empty($title)) {
-
- throw new ClientException(_m('Event must have a title.'));
- }
- $description = $this->trimmed('description');
-
- $tz = $this->trimmed('tz');
- $startDate = $this->trimmed('startdate');
- if (empty($startDate)) {
-
- throw new ClientException(_m('Start date required.'));
- }
- $startTime = $this->trimmed('event-starttime');
- if (empty($startTime)) {
-
- 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) {
-
-
- throw new ClientException(sprintf(_m('Could not parse date %s.'), _ve($start_str)));
- }
- $endDate = $this->trimmed('enddate');
- if (empty($endDate)) {
-
- throw new ClientException(_m('End date required.'));
- }
- $endTime = $this->trimmed('event-endtime');
- if (empty($endTime)) {
-
- 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) {
-
-
- throw new ClientException(sprintf(_m('Could not parse date %s.'), _ve($end_str)));
- }
- $url = $this->trimmed('url');
- if (!empty($url) && !common_valid_http_url($url)) {
-
- throw new ClientException(_m('An event URL must be a valid HTTP/HTTPS link.'));
- }
-
- $location = $this->trimmed('location');
- $options = [ 'source' => 'web' ];
- $act = new Activity();
- $act->verb = ActivityVerb::POST;
- $act->time = time();
- $act->actor = $this->scoped->asActivityObject();
- $act->context = new ActivityContext();
-
- $actobj = new ActivityObject();
- $actobj->id = UUID::gen();
- $actobj->type = Happening::OBJECT_TYPE;
- $actobj->title = $title;
- $actobj->summary = $description;
- $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($end_str));
- $actobj->extra[] = array('location',
- array('xmlns' => 'urn:ietf:params:xml:ns:xcal'),
- $location);
- $actobj->extra[] = array('url',
- array('xmlns' => 'urn:ietf:params:xml:ns:xcal'),
- $url);
-
- $actobj->extra[] = array('startdate',
- array('xmlns' => 'http://purl.org/rss/1.0/plugins/event/'),
- common_date_iso8601($start_str));
- $actobj->extra[] = array('enddate',
- array('xmlns' => 'http://purl.org/rss/1.0/plugins/event/'),
- common_date_iso8601($end_str));
- $actobj->extra[] = array('location',
- array('xmlns' => 'http://purl.org/rss/1.0/plugins/event/'),
- $location);
- $act->objects = array($actobj);
- $stored = Notice::saveActivity($act, $this->scoped, $options);
- return _m('Saved the event.');
- }
- }
|