Esempio n. 1
0
 /**
  * For initializing members of the class.
  *
  * @param array $argarray misc. arguments
  *
  * @return boolean true
  */
 function prepare($argarray)
 {
     parent::prepare($argarray);
     if ($this->boolean('ajax')) {
         GNUsocial::setApi(true);
         // short error results!
     }
     $rsvpId = $this->trimmed('rsvp');
     if (empty($rsvpId)) {
         // TRANS: Client exception thrown when referring to a non-existing RSVP ("please respond") item.
         throw new ClientException(_m('No such RSVP.'));
     }
     $this->rsvp = RSVP::getKV('id', $rsvpId);
     if (empty($this->rsvp)) {
         // TRANS: Client exception thrown when referring to a non-existing RSVP ("please respond") item.
         throw new ClientException(_m('No such RSVP.'));
     }
     $this->event = Happening::getKV('id', $this->rsvp->event_id);
     if (empty($this->event)) {
         // TRANS: Client exception thrown when referring to a non-existing event.
         throw new ClientException(_m('No such event.'));
     }
     $this->user = common_current_user();
     if (empty($this->user)) {
         // TRANS: Client exception thrown when trying tp RSVP ("please respond") while not logged in.
         throw new ClientException(_m('You must be logged in to RSVP for an event.'));
     }
     return true;
 }
Esempio n. 2
0
 function getNotice()
 {
     $this->id = $this->trimmed('id');
     $this->event = Happening::getKV('id', $this->id);
     if (empty($this->event)) {
         // TRANS: Client exception thrown when referring to a non-existing event.
         throw new ClientException(_m('No such event.'), 404);
     }
     $notice = $this->event->getNotice();
     if (empty($notice)) {
         // Did we used to have it, and it got deleted?
         // TRANS: Client exception thrown when referring to a non-existing event.
         throw new ClientException(_m('No such event.'), 404);
     }
     return $notice;
 }
Esempio n. 3
0
 /**
  * For initializing members of the class.
  *
  * @param array $argarray misc. arguments
  *
  * @return boolean true
  */
 function prepare($argarray)
 {
     parent::prepare($argarray);
     if ($this->boolean('ajax')) {
         StatusNet::setApi(true);
         // short error results!
     }
     $eventId = $this->trimmed('event');
     if (empty($eventId)) {
         // TRANS: Client exception thrown when requesting a non-exsting event.
         throw new ClientException(_m('No such event.'));
     }
     $this->event = Happening::staticGet('id', $eventId);
     if (empty($this->event)) {
         // TRANS: Client exception thrown when requesting a non-exsting event.
         throw new ClientException(_m('No such event.'));
     }
     $this->user = common_current_user();
     if (empty($this->user)) {
         // TRANS: Client exception thrown when trying to RSVP ("please respond") while not logged in.
         throw new ClientException(_m('You must be logged in to RSVP for an event.'));
     }
     common_debug(print_r($this->args, true));
     switch (strtolower($this->trimmed('submitvalue'))) {
         case 'yes':
             $this->verb = RSVP::POSITIVE;
             break;
         case 'no':
             $this->verb = RSVP::NEGATIVE;
             break;
         case 'maybe':
             $this->verb = RSVP::POSSIBLE;
             break;
         default:
             // TRANS: Client exception thrown when using an invalid value for RSVP ("please respond").
             throw new ClientException(_m('Unknown submit value.'));
     }
     return true;
 }
 function showContent()
 {
     $notice = $this->nli->notice;
     $out = $this->nli->out;
     $profile = $notice->getProfile();
     $event = Happening::fromNotice($notice);
     if (empty($event)) {
         // TRANS: Content for a deleted RSVP list item (RSVP stands for "please respond").
         $out->element('p', null, _m('Deleted.'));
         return;
     }
     $out->elementStart('div', 'vevent event');
     // VEVENT IN
     $out->elementStart('h3');
     // VEVENT/H3 IN
     if (!empty($event->url)) {
         $out->element('a', array('href' => $event->url, 'class' => 'event-title entry-title summary'), $event->title);
     } else {
         $out->text($event->title);
     }
     $out->elementEnd('h3');
     // VEVENT/H3 OUT
     $startDate = strftime("%x", strtotime($event->start_time));
     $startTime = strftime("%R", strtotime($event->start_time));
     $endDate = strftime("%x", strtotime($event->end_time));
     $endTime = strftime("%R", strtotime($event->end_time));
     // FIXME: better dates
     $out->elementStart('div', 'event-times');
     // VEVENT/EVENT-TIMES IN
     // TRANS: Field label for event description.
     $out->element('strong', null, _m('Time:'));
     $out->element('abbr', array('class' => 'dtstart', 'title' => common_date_iso8601($event->start_time)), $startDate . ' ' . $startTime);
     $out->text(' - ');
     if ($startDate == $endDate) {
         $out->element('span', array('class' => 'dtend', 'title' => common_date_iso8601($event->end_time)), $endTime);
     } else {
         $out->element('span', array('class' => 'dtend', 'title' => common_date_iso8601($event->end_time)), $endDate . ' ' . $endTime);
     }
     $out->elementEnd('div');
     // VEVENT/EVENT-TIMES OUT
     if (!empty($event->location)) {
         $out->elementStart('div', 'event-location');
         // TRANS: Field label for event description.
         $out->element('strong', null, _m('Location:'));
         $out->element('span', 'location', $event->location);
         $out->elementEnd('div');
     }
     if (!empty($event->description)) {
         $out->elementStart('div', 'event-description');
         // TRANS: Field label for event description.
         $out->element('strong', null, _m('Description:'));
         $out->element('span', 'description', $event->description);
         $out->elementEnd('div');
     }
     $rsvps = $event->getRSVPs();
     $out->elementStart('div', 'event-rsvps');
     // TRANS: Field label for event description.
     $out->element('strong', null, _m('Attending:'));
     $out->element('span', 'event-rsvps', sprintf(_m('Yes: %1$d No: %2$d Maybe: %3$d'), count($rsvps[RSVP::POSITIVE]), count($rsvps[RSVP::NEGATIVE]), count($rsvps[RSVP::POSSIBLE])));
     $out->elementEnd('div');
     $user = common_current_user();
     if (!empty($user)) {
         $rsvp = $event->getRSVP($user->getProfile());
         if (empty($rsvp)) {
             $form = new RSVPForm($event, $out);
         } else {
             $form = new CancelRSVPForm($rsvp, $out);
         }
         $form->show();
     }
     $out->elementEnd('div');
     // vevent out
 }
Esempio n. 5
0
 protected function showEvent(Notice $stored, HTMLOutputter $out, Profile $scoped = null)
 {
     $profile = $stored->getProfile();
     $event = Happening::fromNotice($stored);
     if (!$event instanceof Happening) {
         // TRANS: Content for a deleted RSVP list item (RSVP stands for "please respond").
         $out->element('p', null, _m('Deleted.'));
         return;
     }
     $out->elementStart('div', 'h-event');
     $out->elementStart('h3', 'p-summary p-name');
     try {
         $out->element('a', array('href' => $event->getUrl()), $event->title);
     } catch (InvalidUrlException $e) {
         $out->text($event->title);
     }
     $out->elementEnd('h3');
     $now = new DateTime();
     $startDate = new DateTime($event->start_time);
     $endDate = new DateTime($event->end_time);
     $userTz = new DateTimeZone(common_timezone());
     // Localize the time for the observer
     $now->setTimeZone($userTz);
     $startDate->setTimezone($userTz);
     $endDate->setTimezone($userTz);
     $thisYear = $now->format('Y');
     $startYear = $startDate->format('Y');
     $endYear = $endDate->format('Y');
     $dateFmt = 'D, F j, ';
     // e.g.: Mon, Aug 31
     if ($startYear != $thisYear || $endYear != $thisYear) {
         $dateFmt .= 'Y,';
         // append year if we need to think about years
     }
     $startDateStr = $startDate->format($dateFmt);
     $endDateStr = $endDate->format($dateFmt);
     $timeFmt = 'g:ia';
     $startTimeStr = $startDate->format($timeFmt);
     $endTimeStr = $endDate->format("{$timeFmt} (T)");
     $out->elementStart('div', 'event-times');
     // VEVENT/EVENT-TIMES IN
     // TRANS: Field label for event description.
     $out->element('strong', null, _m('Time:'));
     $out->element('time', array('class' => 'dt-start', 'datetime' => common_date_iso8601($event->start_time)), $startDateStr . ' ' . $startTimeStr);
     $out->text(' – ');
     $out->element('time', array('class' => 'dt-end', 'datetime' => common_date_iso8601($event->end_time)), $startDateStr != $endDateStr ? "{$endDateStr} {$endTimeStr}" : $endTimeStr);
     $out->elementEnd('div');
     // VEVENT/EVENT-TIMES OUT
     if (!empty($event->location)) {
         $out->elementStart('div', 'event-location');
         // TRANS: Field label for event description.
         $out->element('strong', null, _m('Location:'));
         $out->element('span', 'p-location', $event->location);
         $out->elementEnd('div');
     }
     if (!empty($event->description)) {
         $out->elementStart('div', 'event-description');
         // TRANS: Field label for event description.
         $out->element('strong', null, _m('Description:'));
         $out->element('div', 'p-description', $event->description);
         $out->elementEnd('div');
     }
     $rsvps = $event->getRSVPs();
     $out->elementStart('div', 'event-rsvps');
     // TRANS: Field label for event description.
     $out->element('strong', null, _m('Attending:'));
     $out->elementStart('ul', 'attending-list');
     foreach ($rsvps as $verb => $responses) {
         $out->elementStart('li', 'rsvp-list');
         switch ($verb) {
             case RSVP::POSITIVE:
                 $out->text(_('Yes:'));
                 break;
             case RSVP::NEGATIVE:
                 $out->text(_('No:'));
                 break;
             case RSVP::POSSIBLE:
                 $out->text(_('Maybe:'));
                 break;
         }
         $ids = array();
         foreach ($responses as $response) {
             $ids[] = $response->profile_id;
         }
         $ids = array_slice($ids, 0, ProfileMiniList::MAX_PROFILES + 1);
         $minilist = new ProfileMiniList(Profile::multiGet('id', $ids), $out);
         $minilist->show();
         $out->elementEnd('li');
     }
     $out->elementEnd('ul');
     $out->elementEnd('div');
     if ($scoped instanceof Profile) {
         $rsvp = $event->getRSVP($scoped);
         if (empty($rsvp)) {
             $form = new RSVPForm($event, $out);
         } else {
             $form = new CancelRSVPForm($rsvp, $out);
         }
         $form->show();
     }
     $out->elementEnd('div');
 }
Esempio n. 6
0
 function getEvent()
 {
     $event = Happening::getKV('uri', $this->event_uri);
     if (empty($event)) {
         // TRANS: Exception thrown when requesting a non-existing event.
         // TRANS: %s is the ID of the non-existing event.
         throw new Exception(sprintf(_m('No event with URI %s.'), $this->event_uri));
     }
     return $event;
 }
Esempio n. 7
0
 function showContent()
 {
     $notice = $this->nli->notice;
     $out = $this->nli->out;
     $profile = $notice->getProfile();
     $event = Happening::fromNotice($notice);
     if (empty($event)) {
         // TRANS: Content for a deleted RSVP list item (RSVP stands for "please respond").
         $out->element('p', null, _m('Deleted.'));
         return;
     }
     $out->elementStart('div', 'vevent event');
     // VEVENT IN
     $out->elementStart('h3');
     // VEVENT/H3 IN
     if (!empty($event->url)) {
         $out->element('a', array('href' => $event->url, 'class' => 'event-title entry-title summary'), $event->title);
     } else {
         $out->text($event->title);
     }
     $out->elementEnd('h3');
     // VEVENT/H3 OUT
     $now = new DateTime();
     $startDate = new DateTime($event->start_time);
     $endDate = new DateTime($event->end_time);
     $userTz = new DateTimeZone(common_timezone());
     // Localize the time for the observer
     $now->setTimeZone($userTz);
     $startDate->setTimezone($userTz);
     $endDate->setTimezone($userTz);
     $thisYear = $now->format('Y');
     $startYear = $startDate->format('Y');
     $endYear = $endDate->format('Y');
     $dateFmt = 'D, F j, ';
     // e.g.: Mon, Aug 31
     if ($startYear != $thisYear || $endYear != $thisYear) {
         $dateFmt .= 'Y,';
         // append year if we need to think about years
     }
     $startDateStr = $startDate->format($dateFmt);
     $endDateStr = $endDate->format($dateFmt);
     $timeFmt = 'g:ia';
     $startTimeStr = $startDate->format($timeFmt);
     $endTimeStr = $endDate->format("{$timeFmt} (T)");
     $out->elementStart('div', 'event-times');
     // VEVENT/EVENT-TIMES IN
     // TRANS: Field label for event description.
     $out->element('strong', null, _m('Time:'));
     $out->element('abbr', array('class' => 'dtstart', 'title' => common_date_iso8601($event->start_time)), $startDateStr . ' ' . $startTimeStr);
     $out->text(' – ');
     if ($startDateStr == $endDateStr) {
         $out->element('span', array('class' => 'dtend', 'title' => common_date_iso8601($event->end_time)), $endTimeStr);
     } else {
         $out->element('span', array('class' => 'dtend', 'title' => common_date_iso8601($event->end_time)), $endDateStr . ' ' . $endTimeStr);
     }
     $out->elementEnd('div');
     // VEVENT/EVENT-TIMES OUT
     if (!empty($event->location)) {
         $out->elementStart('div', 'event-location');
         // TRANS: Field label for event description.
         $out->element('strong', null, _m('Location:'));
         $out->element('span', 'location', $event->location);
         $out->elementEnd('div');
     }
     if (!empty($event->description)) {
         $out->elementStart('div', 'event-description');
         // TRANS: Field label for event description.
         $out->element('strong', null, _m('Description:'));
         $out->element('span', 'description', $event->description);
         $out->elementEnd('div');
     }
     $rsvps = $event->getRSVPs();
     $out->elementStart('div', 'event-rsvps');
     // TRANS: Field label for event description.
     $out->text(_m('Attending:'));
     $out->elementStart('ul', 'attending-list');
     foreach ($rsvps as $verb => $responses) {
         $out->elementStart('li', 'rsvp-list');
         switch ($verb) {
             case RSVP::POSITIVE:
                 $out->text(_m('Yes:'));
                 break;
             case RSVP::NEGATIVE:
                 $out->text(_('No:'));
                 break;
             case RSVP::POSSIBLE:
                 $out->text(_m('Maybe:'));
                 break;
         }
         $ids = array();
         foreach ($responses as $response) {
             $ids[] = $response->profile_id;
         }
         $ids = array_slice($ids, 0, ProfileMiniList::MAX_PROFILES + 1);
         $profiles = Profile::pivotGet('id', $ids);
         $profile = new ArrayWrapper(array_values($profiles));
         $minilist = new ProfileMiniList($profile, $out);
         $minilist->show();
         $out->elementEnd('li');
     }
     $out->elementEnd('ul');
     $out->elementEnd('div');
     $user = common_current_user();
     if (!empty($user)) {
         $rsvp = $event->getRSVP($user->getProfile());
         if (empty($rsvp)) {
             $form = new RSVPForm($event, $out);
         } else {
             $form = new CancelRSVPForm($rsvp, $out);
         }
         $form->show();
     }
     $out->elementEnd('div');
     // vevent out
 }
Esempio n. 8
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);
     }
 }
Esempio n. 9
0
 static function fromNotice($notice)
 {
     return Happening::getKV('uri', $notice->uri);
 }
Esempio n. 10
0
 function asString()
 {
     $event = Happening::staticGet('id', $this->event_id);
     return self::toString($this->getProfile(), $event, $this->response);
 }
Esempio n. 11
0
 /**
  * When a notice is deleted, clean up related tables.
  *
  * @param Notice $notice
  */
 function deleteRelated($notice)
 {
     switch ($notice->object_type) {
         case Happening::OBJECT_TYPE:
             common_log(LOG_DEBUG, "Deleting event from notice...");
             $happening = Happening::fromNotice($notice);
             $happening->delete();
             break;
         case RSVP::POSITIVE:
         case RSVP::NEGATIVE:
         case RSVP::POSSIBLE:
             common_log(LOG_DEBUG, "Deleting rsvp from notice...");
             $rsvp = RSVP::fromNotice($notice);
             common_log(LOG_DEBUG, "to delete: {$rsvp->id}");
             $rsvp->delete();
             break;
         default:
             common_log(LOG_DEBUG, "Not deleting related, wtf...");
     }
 }