示例#1
0
 /**
  * Prepare week specific event start/end timestamps.
  *
  * @param Ai1ec_Event $event Instance of event.
  *
  * @return array Start and end respectively in 0 and 1 positions.
  */
 protected function _get_view_specific_timestamps(Ai1ec_Event $event)
 {
     if ($event->is_allday()) {
         // reset to be day-contained with respect to current timezone
         $event_start = $this->_registry->get('date.time', $event->get('start'), 'sys.default')->set_time(0, 0, 0)->format();
         $event_end = $this->_registry->get('date.time', $event->get('end'), 'sys.default')->set_time(0, 0, 0)->format();
     } else {
         $event_start = $event->get('start')->format();
         $event_end = $event->get('end')->format();
     }
     return array($event_start, $event_end);
 }
示例#2
0
 /**
  * Returns timespan expression for the event.
  *
  * Properly handles:
  * 	- instantaneous events
  * 	- all-day events
  * 	- multi-day events
  * Display of start date can be hidden (non-all-day events only) or full
  * date. All-day status, if any, is enclosed in a span.ai1ec-allday-badge
  * element.
  *
  * @param Ai1ec_Event $event              Rendered event.
  * @param string      $start_date_display Can be one of 'hidden', 'short',
  *                                        or 'long'.
  *
  * @return string Formatted timespan HTML element.
  */
 public function get_timespan_html(Ai1ec_Event $event, $start_date_display = 'long')
 {
     // Makes no sense to hide start date for all-day events, so fix argument
     if ('hidden' === $start_date_display && $event->is_allday()) {
         $start_date_display = 'short';
     }
     // Localize time.
     $start = $this->_registry->get('date.time', $event->get('start'));
     $end = $this->_registry->get('date.time', $event->get('end'));
     // All-day events need to have their end time shifted by 1 second less
     // to land on the correct day.
     $end_offset = 0;
     if ($event->is_allday()) {
         $end->set_time($end->format('H'), $end->format('i'), $end->format('s') - 1);
     }
     // Get timestamps of start & end dates without time component.
     $start_ts = $this->_registry->get('date.time', $start)->set_time(0, 0, 0)->format();
     $end_ts = $this->_registry->get('date.time', $end)->set_time(0, 0, 0)->format();
     $break_years = $start->format('Y') !== $end->format('Y');
     $output = '';
     // Display start date, depending on $start_date_display.
     switch ($start_date_display) {
         case 'hidden':
             break;
         case 'short':
         case 'long':
             $property = $start_date_display . '_date';
             $output .= $this->{'get_' . $property}($start, $break_years);
             break;
         default:
             $start_date_display = 'long';
     }
     // Output start time for non-all-day events.
     if (!$event->is_allday()) {
         if ('hidden' !== $start_date_display) {
             $output .= apply_filters('ai1ec_get_timespan_html_time_separator', Ai1ec_I18n::_x(' @ ', 'Event time separator'));
         }
         $output .= $this->get_short_time($start);
     }
     // Find out if we need to output the end time/date. Do not output it for
     // instantaneous events and all-day events lasting only one day.
     if (!($event->is_instant() || $event->is_allday() && $start_ts === $end_ts)) {
         $output .= apply_filters('ai1ec_get_timespan_html_date_separator', Ai1ec_I18n::_x(' – ', 'Event start/end separator'));
         // If event ends on a different day, output end date.
         if ($start_ts !== $end_ts) {
             // for short date, use short display type
             if ('short' === $start_date_display) {
                 $output .= $this->get_short_date($end, $break_years);
             } else {
                 $output .= $this->get_long_date($end);
             }
         }
         // Output end time for non-all-day events.
         if (!$event->is_allday()) {
             if ($start_ts !== $end_ts) {
                 $output .= apply_filters('ai1ec_get_timespan_html_time_separator', Ai1ec_I18n::_x(' @ ', 'Event time separator'));
             }
             $output .= $this->get_short_time($end);
         }
     }
     $output = esc_html($output);
     // Add all-day label.
     if ($event->is_allday()) {
         $output .= apply_filters('ai1ec_get_timespan_html_allday_badge', ' <span class="ai1ec-allday-badge">' . Ai1ec_I18n::__('all-day') . '</span>');
     }
     return apply_filters('ai1ec_get_timespan_html', $output, $event, $start_date_display);
 }
 /**
  * Style attribute for event bg color
  */
 public function get_category_text_color(Ai1ec_Event $event)
 {
     $category_text_color = null;
     $categories = $this->_taxonomy_model->get_post_categories($event->get('post_id'));
     if (!empty($categories)) {
         $category_text_color = $this->get_event_category_text_color($categories[0]->term_id, $event->is_allday() || $event->is_multiday());
     }
     return $category_text_color;
 }