예제 #1
0
 /**
  * Given a parsed ActivityStreams activity, save it into a notice
  * and other data structures.
  *
  * @param Activity $activity
  * @param Profile $actor
  * @param array $options=array()
  *
  * @return Notice the resulting notice
  */
 function saveNoticeFromActivity(Activity $activity, Profile $actor, array $options = array())
 {
     if (count($activity->objects) != 1) {
         // TRANS: Exception thrown when there are too many activity objects.
         throw new Exception(_m('Too many activity objects.'));
     }
     $happeningObj = $activity->objects[0];
     if ($happeningObj->type != Happening::OBJECT_TYPE) {
         // TRANS: Exception thrown when event plugin comes across a non-event type object.
         throw new Exception(_m('Wrong type for object.'));
     }
     $dtstart = $happeningObj->element->getElementsByTagName('dtstart');
     if ($dtstart->length == 0) {
         // TRANS: Exception thrown when has no start date
         throw new Exception(_m('No start date for event.'));
     }
     $dtend = $happeningObj->element->getElementsByTagName('dtend');
     if ($dtend->length == 0) {
         // TRANS: Exception thrown when has no end date
         throw new Exception(_m('No end date for event.'));
     }
     // convert RFC3339 dates delivered in Activity Stream to MySQL DATETIME date format
     $start_time = new DateTime($dtstart->item(0)->nodeValue);
     $start_time->setTimezone(new DateTimeZone('UTC'));
     $start_time = $start_time->format('Y-m-d H:i:s');
     $end_time = new DateTime($dtend->item(0)->nodeValue);
     $end_time->setTimezone(new DateTimeZone('UTC'));
     $end_time = $end_time->format('Y-m-d H:i:s');
     // location is optional
     $location = null;
     $location_object = $happeningObj->element->getElementsByTagName('location');
     if ($location_object->length > 0) {
         $location = $location_object->item(0)->nodeValue;
     }
     // url is optional
     $url = null;
     $url_object = $happeningObj->element->getElementsByTagName('url');
     if ($url_object->length > 0) {
         $url = $url_object->item(0)->nodeValue;
     }
     switch ($activity->verb) {
         case ActivityVerb::POST:
             // FIXME: get startTime, endTime, location and URL
             $notice = Happening::saveNew($actor, $start_time, $end_time, $happeningObj->title, $location, $happeningObj->summary, $url, $options);
             break;
         case RSVP::POSITIVE:
         case RSVP::NEGATIVE:
         case RSVP::POSSIBLE:
             return Notice::saveActivity($activity, $actor, $options);
             break;
         default:
             // TRANS: Exception thrown when event plugin comes across a undefined verb.
             throw new Exception(_m('Unknown verb for events.'));
     }
 }
예제 #2
0
 /**
  * Given a parsed ActivityStreams activity, save it into a notice
  * and other data structures.
  *
  * @param Activity $activity
  * @param Profile $actor
  * @param array $options=array()
  *
  * @return Notice the resulting notice
  */
 function saveNoticeFromActivity(Activity $activity, Profile $actor, array $options = array())
 {
     if (count($activity->objects) != 1) {
         // TRANS: Exception thrown when there are too many activity objects.
         throw new Exception(_m('Too many activity objects.'));
     }
     $happeningObj = $activity->objects[0];
     if ($happeningObj->type != Happening::OBJECT_TYPE) {
         // TRANS: Exception thrown when event plugin comes across a non-event type object.
         throw new Exception(_m('Wrong type for object.'));
     }
     $notice = null;
     switch ($activity->verb) {
         case ActivityVerb::POST:
             // FIXME: get startTime, endTime, location and URL
             $notice = Happening::saveNew($actor, $start_time, $end_time, $happeningObj->title, null, $happeningObj->summary, null, $options);
             break;
         case RSVP::POSITIVE:
         case RSVP::NEGATIVE:
         case RSVP::POSSIBLE:
             $happening = Happening::getKV('uri', $happeningObj->id);
             if (empty($happening)) {
                 // FIXME: save the event
                 // TRANS: Exception thrown when trying to RSVP for an unknown event.
                 throw new Exception(_m('RSVP for unknown event.'));
             }
             $notice = RSVP::saveNew($actor, $happening, $activity->verb, $options);
             break;
         default:
             // TRANS: Exception thrown when event plugin comes across a undefined verb.
             throw new Exception(_m('Unknown verb for events.'));
     }
     return $notice;
 }
예제 #3
0
 /**
  * Add a new event
  *
  * @return void
  */
 function newEvent()
 {
     try {
         if (empty($this->title)) {
             // TRANS: Client exception thrown when trying to post an event without providing a title.
             throw new ClientException(_m('Event must have a title.'));
         }
         if (empty($this->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.'));
         }
         if (empty($this->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.'));
         }
         if (!empty($this->url) && Validate::uri($this->url) === false) {
             // TRANS: Client exception thrown when trying to post an event with an invalid URL.
             throw new ClientException(_m('URL must be valid.'));
         }
         $options = array();
         // Does the heavy-lifting for getting "To:" information
         ToSelector::fillOptions($this, $options);
         $profile = $this->user->getProfile();
         $saved = Happening::saveNew($profile, $this->startTime, $this->endTime, $this->title, $this->location, $this->description, $this->url, $options);
         $event = Happening::fromNotice($saved);
         RSVP::saveNew($profile, $event, RSVP::POSITIVE);
     } catch (ClientException $ce) {
         if ($this->boolean('ajax')) {
             $this->outputAjaxError($ce->getMessage());
             return;
         } else {
             $this->error = $ce->getMessage();
             $this->showPage();
             return;
         }
     }
     if ($this->boolean('ajax')) {
         $this->startHTML('text/xml;charset=utf-8');
         $this->elementStart('head');
         // TRANS: Page title after sending a notice.
         $this->element('title', null, _m('Event saved'));
         $this->elementEnd('head');
         $this->elementStart('body');
         $this->showNotice($saved);
         $this->elementEnd('body');
         $this->endHTML();
     } else {
         common_redirect($saved->getUrl(), 303);
     }
 }