/**
  * Output a list of times in half-hour intervals
  *
  * @param string  $start       Time to start with (date string, usually a ts)
  * @param boolean $duration    Whether to include the duration of the event
  *                             (from the start)
  * @return array  $times (localized 24 hour time string => fancy time string)
  */
 public static function getTimes($start = 'now', $duration = false)
 {
     $newTime = new DateTime($start);
     $times = array();
     $len = 0;
     $newTime->setTimezone(new DateTimeZone(common_timezone()));
     for ($i = 0; $i < 47; $i++) {
         $localTime = $newTime->format("g:ia");
         // pretty up the end-time option list a bit
         if ($duration) {
             $hours = $len / 60;
             switch ($hours) {
                 case 0:
                     // TRANS: 0 minutes abbreviated. Used in a list.
                     $total = ' ' . _m('(0 min)');
                     break;
                 case 0.5:
                     // TRANS: 30 minutes abbreviated. Used in a list.
                     $total = ' ' . _m('(30 min)');
                     break;
                 case 1:
                     // TRANS: 1 hour. Used in a list.
                     $total = ' ' . _m('(1 hour)');
                     break;
                 default:
                     // TRANS: Number of hours (%.1f and %d). Used in a list.
                     $format = is_float($hours) ? _m('(%.1f hours)') : _m('(%d hours)');
                     $total = ' ' . sprintf($format, $hours);
                     break;
             }
             $localTime .= $total;
             $len += 30;
         }
         $times[$newTime->format('g:ia')] = $localTime;
         $newTime->modify('+30min');
         // 30 min intervals
     }
     return $times;
 }
Example #2
0
 function dateTwitter($dt)
 {
     $dateStr = date('d F Y H:i:s', strtotime($dt));
     $d = new DateTime($dateStr, new DateTimeZone('UTC'));
     $d->setTimezone(new DateTimeZone(common_timezone()));
     return $d->format('D M d H:i:s O Y');
 }
Example #3
0
function common_date_iso8601($dt)
{
    $dateStr = date('d F Y H:i:s', strtotime($dt));
    $d = new DateTime($dateStr, new DateTimeZone('UTC'));
    $d->setTimezone(new DateTimeZone(common_timezone()));
    return $d->format('c');
}
Example #4
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');
 }
Example #5
0
 /**
  * Content area of the page
  *
  * Shows a form for uploading an avatar.
  *
  * @return void
  */
 function showContent()
 {
     $user = common_current_user();
     $profile = $user->getProfile();
     $this->elementStart('form', array('method' => 'post', 'id' => 'form_settings_profile', 'class' => 'form_settings', 'action' => common_local_url('profilesettings')));
     $this->elementStart('fieldset');
     // TRANS: Profile settings form legend.
     $this->element('legend', null, _('Profile information'));
     $this->hidden('token', common_session_token());
     // too much common patterns here... abstractable?
     $this->elementStart('ul', 'form_data');
     if (Event::handle('StartProfileFormData', array($this))) {
         $this->elementStart('li');
         // TRANS: Field label in form for profile settings.
         $this->input('nickname', _('Nickname'), $this->arg('nickname') ? $this->arg('nickname') : $profile->nickname, _('1-64 lowercase letters or numbers, no punctuation or spaces.'));
         $this->elementEnd('li');
         $this->elementStart('li');
         // TRANS: Field label in form for profile settings.
         $this->input('fullname', _('Full name'), $this->arg('fullname') ? $this->arg('fullname') : $profile->fullname);
         $this->elementEnd('li');
         $this->elementStart('li');
         // TRANS: Field label in form for profile settings.
         $this->input('homepage', _('Homepage'), $this->arg('homepage') ? $this->arg('homepage') : $profile->homepage, _('URL of your homepage, blog, or profile on another site.'));
         $this->elementEnd('li');
         $this->elementStart('li');
         $maxBio = Profile::maxBio();
         if ($maxBio > 0) {
             // TRANS: Tooltip for field label in form for profile settings. Plural
             // TRANS: is decided by the number of characters available for the
             // TRANS: biography (%d).
             $bioInstr = sprintf(_m('Describe yourself and your interests in %d character.', 'Describe yourself and your interests in %d characters.', $maxBio), $maxBio);
         } else {
             // TRANS: Tooltip for field label in form for profile settings.
             $bioInstr = _('Describe yourself and your interests.');
         }
         // TRANS: Text area label in form for profile settings where users can provide
         // TRANS: their biography.
         $this->textarea('bio', _('Bio'), $this->arg('bio') ? $this->arg('bio') : $profile->bio, $bioInstr);
         $this->elementEnd('li');
         $this->elementStart('li');
         // TRANS: Field label in form for profile settings.
         $this->input('location', _('Location'), $this->arg('location') ? $this->arg('location') : $profile->location, _('Where you are, like "City, State (or Region), Country".'));
         $this->elementEnd('li');
         if (common_config('location', 'share') == 'user') {
             $this->elementStart('li');
             // TRANS: Checkbox label in form for profile settings.
             $this->checkbox('sharelocation', _('Share my current location when posting notices'), $this->arg('sharelocation') ? $this->arg('sharelocation') : $user->shareLocation());
             $this->elementEnd('li');
         }
         Event::handle('EndProfileFormData', array($this));
         $this->elementStart('li');
         // TRANS: Field label in form for profile settings.
         $this->input('tags', _('Tags'), $this->arg('tags') ? $this->arg('tags') : implode(' ', $user->getSelfTags()), _('Tags for yourself (letters, numbers, -, ., and _), comma- or space- separated.'));
         $this->elementEnd('li');
         $this->elementStart('li');
         $language = common_language();
         // TRANS: Dropdownlist label in form for profile settings.
         $this->dropdown('language', _('Language'), get_nice_language_list(), _('Preferred language.'), false, $language);
         $this->elementEnd('li');
         $timezone = common_timezone();
         $timezones = array();
         foreach (DateTimeZone::listIdentifiers() as $k => $v) {
             $timezones[$v] = $v;
         }
         $this->elementStart('li');
         // TRANS: Dropdownlist label in form for profile settings.
         $this->dropdown('timezone', _('Timezone'), $timezones, _('What timezone are you normally in?'), true, $timezone);
         $this->elementEnd('li');
         $this->elementStart('li');
         $this->checkbox('autosubscribe', _('Automatically subscribe to whoever ' . 'subscribes to me (best for non-humans)'), $this->arg('autosubscribe') ? $this->boolean('autosubscribe') : $user->autosubscribe);
         $this->elementEnd('li');
         $this->elementStart('li');
         $this->dropdown('subscribe_policy', _('Subscription policy'), array(User::SUBSCRIBE_POLICY_OPEN => _('Let anyone follow me'), User::SUBSCRIBE_POLICY_MODERATE => _('Ask me first')), _('Whether other users need your permission to follow your updates.'), false, empty($user->subscribe_policy) ? User::SUBSCRIBE_POLICY_OPEN : $user->subscribe_policy);
         $this->elementEnd('li');
     }
     $this->elementStart('li');
     $this->checkbox('private_stream', _('Make updates visible only to my followers'), $this->arg('private_stream') ? $this->boolean('private_stream') : $user->private_stream);
     $this->elementEnd('li');
     $this->elementEnd('ul');
     // TRANS: Button to save input in profile settings.
     $this->submit('save', _m('BUTTON', 'Save'));
     $this->elementEnd('fieldset');
     $this->elementEnd('form');
 }
 /**
  * Content area of the page
  *
  * Shows a form for uploading an avatar.
  *
  * @return void
  */
 function showContent()
 {
     $user = common_current_user();
     $profile = $user->getProfile();
     $this->elementStart('form', array('method' => 'post', 'id' => 'form_settings_profile', 'class' => 'form_settings', 'action' => common_local_url('profilesettings')));
     $this->elementStart('fieldset');
     $this->element('legend', null, _('Profile information'));
     $this->hidden('token', common_session_token());
     // too much common patterns here... abstractable?
     $this->elementStart('ul', 'form_data');
     if (Event::handle('StartProfileFormData', array($this))) {
         $this->elementStart('li');
         $this->input('nickname', _('Nickname'), $this->arg('nickname') ? $this->arg('nickname') : $profile->nickname, _('1-64 lowercase letters or numbers, no punctuation or spaces'));
         $this->elementEnd('li');
         $this->elementStart('li');
         $this->input('fullname', _('Full name'), $this->arg('fullname') ? $this->arg('fullname') : $profile->fullname);
         $this->elementEnd('li');
         $this->elementStart('li');
         $this->input('homepage', _('Homepage'), $this->arg('homepage') ? $this->arg('homepage') : $profile->homepage, _('URL of your homepage, blog, or profile on another site'));
         $this->elementEnd('li');
         $this->elementStart('li');
         $maxBio = Profile::maxBio();
         if ($maxBio > 0) {
             $bioInstr = sprintf(_('Describe yourself and your interests in %d chars'), $maxBio);
         } else {
             $bioInstr = _('Describe yourself and your interests');
         }
         $this->textarea('bio', _('Bio'), $this->arg('bio') ? $this->arg('bio') : $profile->bio, $bioInstr);
         $this->elementEnd('li');
         $this->elementStart('li');
         $this->input('location', _('Location'), $this->arg('location') ? $this->arg('location') : $profile->location, _('Where you are, like "City, State (or Region), Country"'));
         $this->elementEnd('li');
         if (common_config('location', 'share') == 'user') {
             $this->elementStart('li');
             $this->checkbox('sharelocation', _('Share my current location when posting notices'), $this->arg('sharelocation') ? $this->arg('sharelocation') : $user->shareLocation());
             $this->elementEnd('li');
         }
         Event::handle('EndProfileFormData', array($this));
         $this->elementStart('li');
         $this->input('tags', _('Tags'), $this->arg('tags') ? $this->arg('tags') : implode(' ', $user->getSelfTags()), _('Tags for yourself (letters, numbers, -, ., and _), comma- or space- separated'));
         $this->elementEnd('li');
         $this->elementStart('li');
         $language = common_language();
         $this->dropdown('language', _('Language'), get_nice_language_list(), _('Preferred language'), false, $language);
         $this->elementEnd('li');
         $timezone = common_timezone();
         $timezones = array();
         foreach (DateTimeZone::listIdentifiers() as $k => $v) {
             $timezones[$v] = $v;
         }
         $this->elementStart('li');
         $this->dropdown('timezone', _('Timezone'), $timezones, _('What timezone are you normally in?'), true, $timezone);
         $this->elementEnd('li');
         $this->elementStart('li');
         $this->checkbox('autosubscribe', _('Automatically subscribe to whoever ' . 'subscribes to me (best for non-humans)'), $this->arg('autosubscribe') ? $this->boolean('autosubscribe') : $user->autosubscribe);
         $this->elementEnd('li');
     }
     $this->elementEnd('ul');
     $this->submit('save', _('Save'));
     $this->elementEnd('fieldset');
     $this->elementEnd('form');
 }
Example #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
 }
Example #8
0
 /**
  * Data elements of the form
  *
  * @return void
  */
 function formData()
 {
     $this->out->elementStart('fieldset', array('id' => 'new_event_data'));
     // Passing in the URL of the Ajax action that the .js for this form hits
     // when selecting event start and end times. JavaScript will try to
     // use a relative path, unless explicitely told where an action is,
     // and that's a bit difficult to calculate since the event form is on
     // so many pages with different paths. It might be worth solving this
     // globally by putting the base site path in the Identifier-URL meta tag
     // or something similar, so it would be easy to calculate the exact path
     // for actions and other things in JavaScripts. -z
     $this->out->hidden('timelist_action_url', common_local_url('timelist'));
     $this->out->elementStart('ul', 'form_data');
     $this->li();
     $this->out->input('event-title', _m('LABEL', 'Title'), null, _m('Title of the event.'), 'title', true);
     // HTML5 "required" attribute
     $this->unli();
     $this->li();
     $today = new DateTime('now');
     $today->setTimezone(new DateTimeZone(common_timezone()));
     $this->out->input('event-startdate', _m('LABEL', 'Start date'), $today->format('m/d/Y'), _m('Date the event starts.'), 'startdate');
     $this->unli();
     $this->li();
     $times = EventTimeList::getTimes($today->format('m/d/Y 12:00') . ' am ' . $today->format('T'));
     $start = EventTimeList::nearestHalfHour($today->format('c'));
     $start->setTimezone(new DateTimeZone(common_timezone()));
     $this->out->dropdown('event-starttime', _m('LABEL', 'Start time'), $times, sprintf(_m("Time the event starts (%s)."), $today->format('T')), false, $start->format('g:ia'));
     // Need to keep JavaScript TZ in sync with PHP TZ
     $this->out->hidden('tz', $today->format('T'));
     $this->out->hidden('now', $today->format('F d, Y H:i:s T'));
     $this->unli();
     $this->li();
     $this->out->input('event-enddate', _m('LABEL', 'End date'), $today->format('m/d/Y'), _m('Date the event ends.'), 'enddate');
     $this->unli();
     $this->li();
     $this->out->dropdown('event-endtime', _m('LABEL', 'End time'), EventTimeList::getTimes($start->format('c'), true), _m('Time the event ends.'), false, null);
     $this->unli();
     $this->li();
     $this->out->input('event-location', _m('LABEL', 'Where?'), null, _m('Event location.'), 'location');
     $this->unli();
     $this->li();
     $this->out->input('event-url', _m('LABEL', 'URL'), null, _m('URL for more information.'), 'url');
     $this->unli();
     $this->li();
     $this->out->input('event-description', _m('LABEL', 'Description'), null, _m('Description of the event.'), 'description', true);
     // HTML5 "required" attribute
     $this->unli();
     $this->out->elementEnd('ul');
     $toWidget = new ToSelector($this->out, common_current_user(), null);
     $toWidget->show();
     $this->out->elementEnd('fieldset');
 }
Example #9
0
 static function iso8601Date($tm)
 {
     $dateStr = date('d F Y H:i:s', $tm);
     $d = new DateTime($dateStr, new DateTimeZone('UTC'));
     $d->setTimezone(new DateTimeZone(common_timezone()));
     return $d->format('c');
 }