- <?php
- * @file
- * Theme and preprocess functions for output by Date module.
- */
-
- * @addtogroup themeable
- * @{
- */
-
- * Returns HTML for a date timezone element.
- */
- function theme_date_timezone($variables) {
- $element = $variables['element'];
- $attributes = $element['#attributes'];
-
-
- if (isset($element['#children'])) {
- $element['#children'] = '<div id="' . $element['#id'] . '" class="container-inline-date">' . $element['#children'] . '</div>';
- }
- return '<div ' . backdrop_attributes($attributes) . '>' . theme('form_element', $element) . '</div>';
- }
-
- * Returns HTML for a date text element.
- */
- function theme_date_text($variables) {
- $element = $variables['element'];
-
-
- if (isset($element['#children'])) {
- $element['#children'] = '<div id="' . $element['#id'] . '" class="container-inline-date">' . $element['#children'] . '</div>';
- }
- return theme('form_element', $element);
- }
-
- * Returns HTML for a "date_select" element, including all child elements.
- */
- function theme_date_select($variables) {
- $element = $variables['element'];
-
-
- if (isset($element['#children'])) {
- $element['#children'] = '<div id="' . $element['#id'] . '" class="container-inline-date">' . $element['#children'] . '</div>';
- }
- return theme('form_element', $element);
- }
-
- * Returns HTML for a date select input form element.
- *
- * This is for an individual select element (e.g. Year, Month, Day). The
- * complete element is wrapped in theme_date_select().
- */
- function theme_date_select_element($variables) {
- $element = $variables['element'];
- $parents = $element['#parents'];
- $part = array_pop($parents);
- return '<div class="date-' . $part . '">' . theme('select', $element) . '</div>';
- }
-
- * Returns HTML for a date textfield input form element.
- */
- function theme_date_textfield_element($variables) {
- $element = $variables['element'];
- $parents = $element['#parents'];
- $part = array_pop($parents);
- return '<div class="date-' . $part . '">' . theme('textfield', $element) . '</div>';
- }
-
- * Returns HTML for a date in the format 'time ago'.
- */
- function theme_date_time_ago($variables) {
- $start_date = $variables['start_date'];
- $end_date = $variables['end_date'];
- $interval = !empty($variables['interval']) ? $variables['interval'] : 2;
- $display = isset($variables['interval_display']) ? $variables['interval_display'] : 'time ago';
-
-
- if (empty($start_date) || empty($end_date)) {
- return '';
- }
-
-
- $now = date_format(date_now(), DATE_FORMAT_UNIX);
- $start = date_format($start_date, DATE_FORMAT_UNIX);
-
-
- $time_diff = $now - $start;
-
-
- switch ($display) {
- case 'raw time ago':
- return format_interval($time_diff, $interval);
-
- case 'time ago':
- return t('%time ago', array('%time' => format_interval($time_diff, $interval)));
-
- case 'raw time hence':
- return format_interval(-$time_diff, $interval);
-
- case 'time hence':
- return t('%time hence', array('%time' => format_interval(-$time_diff, $interval)));
-
- case 'raw time span':
- return ($time_diff < 0 ? '-' : '') . format_interval(abs($time_diff), $interval);
-
- case 'inverse time span':
- return ($time_diff > 0 ? '-' : '') . format_interval(abs($time_diff), $interval);
-
- case 'time span':
- return t(($time_diff < 0 ? '%time hence' : '%time ago'), array('%time' => format_interval(abs($time_diff), $interval)));
- }
-
- return '';
- }
-
- * Returns HTML for a date element formatted as a Start/End combination.
- *
- * $entity->date_id
- * If set, this will show only an individual date on a field with
- * multiple dates. The value should be a string that contains
- * the following values, separated with periods:
- * - module name of the module adding the item
- * - node nid
- * - field name
- * - delta value of the field to be displayed
- * - other information the module's custom theme might need
- *
- * Used by the calendar module and available for other uses.
- * example: 'date.217.field_date.3.test'
- *
- * $entity->date_repeat_show_all
- * If true, tells the theme to show all the computed values of a repeating
- * date. If not true or not set, only the start date and the repeat rule
- * will be displayed.
- *
- * $dates['format']
- * The format string used on these dates
- * $dates['value']['local']['object']
- * The local date object for the Start date
- * $dates['value2']['local']['object']
- * The local date object for the End date
- * $dates['value']['local']['datetime']
- * The datetime value of the Start date database (GMT) value
- * $dates['value2']['local']['datetime']
- * The datetime value of the End date database (GMT) value
- * $dates['value']['formatted']
- * Formatted Start date, i.e. 'February 15, 2007 2:00 pm';
- * $dates['value']['formatted_date']
- * Only the date part of the formatted Start date
- * $dates['value']['formatted_time']
- * Only the time part of the formatted Start date
- * $dates['value2']['formatted']
- * Formatted End date, i.e. 'February 15, 2007 6:00 pm';
- * $dates['value2']['formatted_date']
- * Only the date part of the formatted End date
- * $dates['value2']['formatted_time']
- * Only the time part of the formatted End date
- */
- function theme_date_display_combination($variables) {
- $entity_type = $variables['entity_type'];
- $entity = $variables['entity'];
- $field = $variables['field'];
- $instance = $variables['instance'];
- $langcode = $variables['langcode'];
- $item = $variables['item'];
- $delta = $variables['delta'];
- $display = $variables['display'];
- $field_name = $field['field_name'];
- $formatter = $display['type'];
- $options = $display['settings'];
- $dates = $variables['dates'];
- $attributes = $variables['attributes'];
- $precision = date_granularity_precision($field['settings']['granularity']);
- $show_remaining_days = $variables['show_remaining_days'];
-
- $output = '';
-
- if (!empty($entity->date_id)) {
- foreach ((array) $entity->date_id as $key => $id) {
- list($module, $nid, $field_name, $item_delta, $other) = explode('.', $id . '.');
- if ($field_name == $field['field_name'] && isset($delta) && $item_delta != $delta) {
- return $output;
- }
- }
- }
-
-
-
- if (isset($entity->$field_name)) {
- $entity = date_prepare_entity($formatter, $entity_type, $entity, $field, $instance, $langcode, $item, $display);
-
- if (empty($entity->{$field_name}[$langcode][$delta])) {
- return $output;
- }
-
- $element['#entity'] = $entity;
- }
-
- switch ($options['fromto']) {
- case 'value':
- $date1 = $dates['value']['formatted'];
- $date2 = $date1;
- break;
-
- case 'value2':
- $date2 = $dates['value2']['formatted'];
- $date1 = $date2;
- break;
-
- default:
- $date1 = $dates['value']['formatted'];
- $date2 = $dates['value2']['formatted'];
- break;
- }
-
-
-
- $timezone = $dates['value']['formatted_timezone'];
- if (date_timezone_is_valid($timezone) && $date1 !== $date2) {
-
-
-
-
-
- $date1 = str_replace($timezone, '', $date1);
- $date2 = str_replace($timezone, '', $date2);
- $timezone = ' ' . $timezone;
- }
- else {
- $timezone = '';
- }
- $time1 = preg_replace('`^([\(\[])`', '', $dates['value']['formatted_time']);
- $time1 = preg_replace('([\)\]]$)', '', $time1);
- $time2 = preg_replace('`^([\(\[])`', '', $dates['value2']['formatted_time']);
- $time2 = preg_replace('([\)\]]$)', '', $time2);
-
-
-
- $has_time_string = date_has_time($field['settings']['granularity']);
- if ($precision == 'hour') {
- $has_time_string = FALSE;
- }
-
-
- $show_remaining_days = '';
- if (!empty($variables['show_remaining_days'])) {
-
- $date = new DateTime('@' . strtotime($variables['dates']['value']['formatted_iso']));
-
-
- $remaining_days = date_diff($date, date_now())->days;
-
- if ($date->format('U') > REQUEST_TIME) {
- $show_remaining_days = theme('date_display_remaining', array(
- 'remaining_days' => $remaining_days,
- ));
- }
- }
-
-
- if (empty($date1) && empty($date2)) {
- $output .= '';
- }
-
-
- elseif ($date1 == $date2 || empty($date2)) {
- $output .= theme('date_display_single', array(
- 'date' => $date1,
- 'timezone' => $timezone,
- 'attributes' => $attributes,
- 'dates' => $dates,
- 'show_remaining_days' => $show_remaining_days,
- ));
- }
-
-
-
- elseif ($has_time_string && $dates['value']['formatted_date'] == $dates['value2']['formatted_date']) {
-
-
-
- $time = theme('date_display_range', array(
- 'date1' => $time1,
- 'date2' => $time2,
- 'timezone' => $timezone,
- 'attributes' => $attributes,
- 'dates' => $dates,
- 'show_remaining_days' => '',
- ));
- $replaced = str_replace($time1, $time, $date1);
- $output .= theme('date_display_single', array(
- 'date' => $replaced,
- 'timezone' => $timezone,
- 'attributes' => array(),
- 'dates' => $dates,
- 'show_remaining_days' => $show_remaining_days,
- ));
- }
-
- else {
- $output .= theme('date_display_range', array(
- 'date1' => $date1,
- 'date2' => $date2,
- 'timezone' => $timezone,
- 'attributes' => $attributes,
- 'dates' => $dates,
- 'show_remaining_days' => $show_remaining_days,
- ));
- }
-
- return $output;
- }
-
- * Returns HTML for a date element formatted as a single date.
- */
- function theme_date_display_single($variables) {
- $date = $variables['date'];
- $attributes = $variables['attributes'];
- $show_remaining_days = isset($variables['show_remaining_days']) ? $variables['show_remaining_days'] : '';
-
-
- $output = '<span class="date-display-single"' . backdrop_attributes($attributes) . '>' . $date . '</span>';
-
-
- return $output . $show_remaining_days;
- }
-
- * Returns HTML for a date element formatted as a range.
- */
- function theme_date_display_range($variables) {
- $date1 = $variables['date1'];
- $date2 = $variables['date2'];
- $timezone = $variables['timezone'];
- $attributes_start = $variables['attributes_start'];
- $attributes_end = $variables['attributes_end'];
- $show_remaining_days = $variables['show_remaining_days'];
-
- $start_date = '<span class="date-display-start"' . backdrop_attributes($attributes_start) . '>' . $date1 . '</span>';
- $end_date = '<span class="date-display-end"' . backdrop_attributes($attributes_end) . '>' . $date2 . $timezone . '</span>';
-
-
- $output = '<span class="date-display-range">' . t('!start-date to !end-date', array(
- '!start-date' => $start_date,
- '!end-date' => $end_date,
- )) . '</span>';
-
-
- return $output . $show_remaining_days;
- }
-
- * Returns HTML for a date element formatted as an interval.
- */
- function theme_date_display_interval($variables) {
- $entity = $variables['entity'];
- $options = $variables['display']['settings'];
- $dates = $variables['dates'];
- $attributes = $variables['attributes'];
-
-
-
- if (!empty($entity->date_info) && !empty($entity->date_info->formatter_settings)) {
- $options = $entity->date_info->formatter_settings;
- }
-
- $time_ago_vars = array(
- 'start_date' => $dates['value']['local']['object'],
- 'end_date' => $dates['value2']['local']['object'],
- 'interval' => $options['interval'],
- 'interval_display' => $options['interval_display'],
- );
-
- if ($return = theme('date_time_ago', $time_ago_vars)) {
- return '<span class="date-display-interval"' . backdrop_attributes($attributes) . ">$return</span>";
- }
- else {
- return '';
- }
- }
-
- * Returns HTML for a start/end date combination on form.
- */
- function theme_date_combo($variables) {
- $element = $variables['element'];
-
-
- $fieldset = array(
- '#title' => field_filter_xss(t($element['#title'])) . ' ' . ($element['#delta'] > 0 ? intval($element['#delta'] + 1) : ''),
- '#value' => '',
- '#description' => !empty($element['#fieldset_description']) ? $element['#fieldset_description'] : '',
- '#attributes' => array('class' => array('date-combo')),
- '#children' => $element['#children'],
- );
-
- if ($element['#required']) {
- $fieldset['#title'] .= " " . theme('form_required_marker');
- }
- return theme('fieldset', array('element' => $fieldset));
- }
-
- * Returns HTML for the text/select options for date parts in a table.
- */
- function theme_date_text_parts($variables) {
- $element = $variables['element'];
- $rows = array();
- foreach (date_granularity_names() as $key => $part) {
- if ($element[$key]['#type'] == 'hidden') {
- $rows[] = backdrop_render($element[$key]);
- }
- else {
- $rows[] = array(
- $part,
- backdrop_render($element[$key][0]),
- backdrop_render($element[$key][1]),
- );
- }
- }
- if ($element['year']['#type'] == 'hidden') {
- return implode($rows) . backdrop_render_children($element);
- }
- else {
- $header = array(t('Date part'), t('Select list'), t('Text field'));
- return theme('table', array('header' => $header, 'rows' => $rows)) . backdrop_render_children($element);
- }
- }
-
- * Format a date popup element.
- *
- * Use a class that will float date and time next to each other.
- */
- function theme_date_popup($variables) {
- $element = $variables['element'];
-
-
- if (isset($element['#children'])) {
- $element['#children'] = '<div id="' . $element['#id'] . '" class="container-inline-date">' . $element['#children'] . '</div>';
- }
- return theme('form_element', $element);
- }
-
- * Returns HTML for remaining message.
- */
- function theme_date_display_remaining($variables) {
- $remaining_days = $variables['remaining_days'];
- if ($remaining_days) {
- $show_remaining_text = format_plural($remaining_days, '1 day remaining to event.', '@count days remaining to event.');
- }
- else {
- $show_remaining_text = t('Less than 1 day remaining to event.');
- }
-
- return '<div class="date-display-remaining"><span class="date-display-remaining">' . $show_remaining_text . '</span></div>';
- }
-
- * Preprocessor for Date Views filter form.
- */
- function template_preprocess_date_views_filter_form(&$variables) {
- $form = $variables['form'];
- $variables['date'] = backdrop_render($form['valuedate']);
- $variables['mindate'] = backdrop_render($form['mindate']);
- $variables['maxdate'] = backdrop_render($form['maxdate']);
- $variables['adjustment'] = backdrop_render($form['valueadjustment']);
- $variables['minadjustment'] = backdrop_render($form['minadjustment']);
- $variables['maxadjustment'] = backdrop_render($form['maxadjustment']);
- $variables['description'] = backdrop_render($form['description']) . backdrop_render($form);
- }
-
- * Implements template_preprocess_views_view().
- *
- * Display the pager above view content, below or both.
- */
- function date_preprocess_views_view(&$variables) {
- $view = $variables['view'];
- if (!empty($view->date_info) && !empty($view->date_info->date_pager_position)) {
- switch ($view->date_info->date_pager_position) {
- case 'top':
- $variables['header'] .= $variables['pager'];
- $variables['pager'] = '';
- break;
-
- case 'both':
- $variables['header'] .= $variables['pager'];
- break;
-
- default:
-
- }
- }
- }
-
- * Preprocess function for Date pager template.
- */
- function template_preprocess_date_views_pager(&$variables) {
- backdrop_add_css(backdrop_get_path('module', 'date') . "/css/date-views.css");
-
- $plugin = $variables['plugin'];
- $input = $variables['input'];
- $view = $plugin->view;
-
- $variables['nav_title'] = '';
- $variables['next_url'] = '';
- $variables['prev_url'] = '';
- $variables['classes'] = array('date-nav-wrapper');
-
- if (empty($view->date_info) || empty($view->date_info->min_date)) {
- return;
- }
- $date_info = $view->date_info;
-
- $granularity = !empty($date_info->granularity) ? $date_info->granularity : 'month';
- $pos = $date_info->date_arg_pos;
- if (!empty($input)) {
- $id = $plugin->options['date_id'];
- if (array_key_exists($id, $input) && !empty($input[$id])) {
- $view->args[$pos] = $input[$id];
- }
- }
-
- $next_args = $view->args;
- $prev_args = $view->args;
- $min_date = $date_info->min_date;
- $max_date = $date_info->max_date;
-
-
-
- if ((isset($date_info->date_pager_format) && $date_info->date_pager_format != 'clean') || !empty($date_info->mini)) {
- if (empty($date_info->block_identifier)) {
- $date_info->block_identifier = $date_info->pager_id;
- }
- }
-
- if (empty($date_info->hide_nav)) {
- $prev_date = $date_info->prev_date;
- $next_date = $date_info->next_date;
-
- $format = array('year' => 'Y', 'month' => 'Y-m', 'day' => 'Y-m-d', 'hour' => 'Y-m-d\TH');
- if (!empty($prev_date)) {
- switch ($granularity) {
- case 'week':
- $prev_week = date_week(date_format($prev_date, 'Y-m-d'));
- $prev_arg = date_format($prev_date, 'o-\W') . date_pad($prev_week);
- break;
- default:
- $prev_arg = date_format($prev_date, $format[$granularity]);
- }
- $prev_path = str_replace($date_info->date_arg, $prev_arg, $date_info->url);
- $prev_args[$pos] = $prev_arg;
- $variables['prev_url'] = date_pager_url($view, NULL, $prev_arg);
- }
- if (!empty($next_date)) {
- switch ($granularity) {
- case 'week':
- $next_week = date_week(date_format($next_date, 'Y-m-d'));
- $next_arg = date_format($next_date, 'o-\W') . date_pad($next_week);
- break;
- default:
- $next_arg = date_format($next_date, $format[$granularity]);
- }
- $next_path = str_replace($date_info->date_arg, $next_arg, $date_info->url);
- $next_args[$pos] = $next_arg;
- $variables['next_url'] = date_pager_url($view, NULL, $next_arg);
- }
-
- $variables['next_options'] = $variables['prev_options'] = array();
- }
- else {
- $next_path = '';
- $prev_path = '';
- $variables['next_url'] = '';
- $variables['prev_url'] = '';
- $variables['next_options'] = $variables['prev_options'] = array();
- }
-
-
-
- if (!empty($next_date) && !empty($variables['next_url']) && date_format($next_date, 'Y') > $date_info->limit[1]) {
- $variables['next_url'] = '';
- }
- if (!empty($prev_date) && !empty($variables['prev_url']) && date_format($prev_date, 'Y') < $date_info->limit[0]) {
- $variables['prev_url'] = '';
- }
- $variables['prev_options'] += array('attributes' => array());
- $variables['next_options'] += array('attributes' => array());
- $prev_title = '';
- $next_title = '';
-
-
- switch ($granularity) {
- case 'year':
- $prev_title = t('Navigate to previous year');
- $next_title = t('Navigate to next year');
- break;
-
- case 'month':
- $prev_title = t('Navigate to previous month');
- $next_title = t('Navigate to next month');
- break;
-
- case 'week':
- $prev_title = t('Navigate to previous week');
- $next_title = t('Navigate to next week');
- break;
-
- case 'day':
- $prev_title = t('Navigate to previous day');
- $next_title = t('Navigate to next day');
- break;
- }
- $variables['prev_options']['attributes'] += array('title' => $prev_title);
- $variables['next_options']['attributes'] += array('title' => $next_title);
-
-
- $variables['prev_options']['attributes'] += array('rel' => 'nofollow');
- $variables['next_options']['attributes'] += array('rel' => 'nofollow');
-
-
- $variables['prev_options'] += array('html' => TRUE);
- $variables['next_options'] += array('html' => TRUE);
-
- $link = FALSE;
-
- if (!empty($date_info->mini) && $granularity == 'month') {
- $link = TRUE;
- }
- $params = array(
- 'granularity' => $granularity,
- 'view' => $view,
- 'link' => $link,
- );
- $nav_title = theme('date_nav_title', $params);
- $variables['nav_title'] = $nav_title;
- $variables['mini'] = !empty($date_info->mini);
- }
-
- * Theme the calendar title.
- */
- function theme_date_nav_title($params) {
- $date_views_config = config('date_views.settings');
- $title = '';
- $granularity = $params['granularity'];
- $view = $params['view'];
- $date_info = $view->date_info;
- $link = !empty($params['link']) ? $params['link'] : FALSE;
- $format = !empty($params['format']) ? $params['format'] : NULL;
- $format_with_year = $date_views_config->get("date_views_{$granularity}_format_with_year");
- $format_without_year = $date_views_config->get("date_views_{$granularity}_format_without_year");
- switch ($granularity) {
- case 'year':
- $title = $date_info->year;
- $date_arg = $date_info->year;
- break;
-
- case 'month':
- $format = !empty($format) ? $format : (empty($date_info->mini) ? $format_with_year : $format_without_year);
- $title = date_format_date($date_info->min_date, 'custom', $format);
- $date_arg = $date_info->year . '-' . date_pad($date_info->month);
- break;
-
- case 'day':
- $format = !empty($format) ? $format : (empty($date_info->mini) ? $format_with_year : $format_without_year);
- $title = date_format_date($date_info->min_date, 'custom', $format);
- $date_arg = $date_info->year;
- $date_arg .= '-';
- $date_arg .= date_pad($date_info->month);
- $date_arg .= '-';
- $date_arg .= date_pad($date_info->day);
- break;
-
- case 'week':
- $format = !empty($format) ? $format : (empty($date_info->mini) ? $format_with_year : $format_without_year);
- $title = t('Week of @date', array(
- '@date' => date_format_date($date_info->min_date, 'custom', $format),
- ));
- $date_arg = $date_info->year . '-W' . date_pad($date_info->week);
- break;
- }
- if (!empty($date_info->mini) || $link) {
-
- $attributes = array('title' => t('View full page month'));
- $url = date_pager_url($view, $granularity, $date_arg, TRUE);
- return l($title, $url, array('attributes' => $attributes));
- }
- else {
- return $title;
- }
- }
-
-