date.theme in Date 5.2
Same filename and directory in other branches
Theme functions.
File
date/date.themeView source
<?php
/**
* @file
* Theme functions.
*/
/**
* @addtogroup themeable
* @{
*
* Formatter themes
*/
/**
* Theme from/to date combination in the view.
*
* @param $field = the field settings
* @param $node = node information, this is not always available and not
* always the full node, it depends on what value was provided to the formatter.
* Only the nid is always guaranteed to be available.
* @param $dates - an array of date information, see explanation for date_field_object() for details.
*
* Useful values:
* $field['type_name'] is the content type
* $field['type'] is the field type
*
* $node->nid is the node nid, get other node values using node_load($node->nid)
*
* $node->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 colons:
* - 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'
*
* $node->date_repeat_show
* 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 From date
* $dates['value2']['local']['object'] - the local date object for the To date
* $dates['value']['local']['datetime'] - the datetime value of the From date database (GMT) value
* $dates['value2']['local']['datetime'] - the datetime value of the To date database (GMT) value
* $dates['value']['formatted'] = formatted From date, i.e. 'February 15, 2007 2:00 pm';
* $dates['value']['formatted_date'] - only the date part of the formatted From date
* $dates['value']['formatted_time'] - only the time part of the formatted From date
* $dates['value2']['formatted'] = formatted To date, i.e. 'February 15, 2007 6:00 pm';
* $dates['value2']['formatted_date'] - only the date part of the formatted To date
* $dates['value2']['formatted_time'] - only the time part of the formatted To date
*/
function theme_date_display_combination($field, $item, $dates, $node = NULL) {
$date1 = $dates['value']['formatted'];
if (isset($dates['value2'])) {
$date2 = $dates['value2']['formatted'];
}
else {
$date2 = $date1;
}
// Pull the timezone, if any, out of the formatted result and tack it
// back on at the end, if it is in the current formatted date.
$timezone = $dates['value']['formatted_timezone'];
if ($timezone) {
$timezone = ' ' . $timezone;
}
$date1 = str_replace($timezone, '', $date1);
$date2 = str_replace($timezone, '', $date2);
// No date values, display nothing.
if (empty($date1) && empty($date2)) {
$output .= '';
}
elseif ($date1 == $date2 || empty($date2)) {
$output .= theme('date_display_single', $date1, $timezone);
}
elseif (date_has_time($field['granularity']) && $dates['value']['formatted_date'] == $dates['value2']['formatted_date']) {
// Replace the original time with the from/to time in the formatted start date.
// Make sure that parentheses or brackets wrapping the time will be retained in the
// final result.
$time1 = preg_replace('`^([\\(\\[])`', '', $dates['value']['formatted_time']);
$time1 = preg_replace('([\\)\\]]$)', '', $time1);
$time2 = preg_replace('`^([\\(\\[])`', '', $dates['value2']['formatted_time']);
$time2 = preg_replace('([\\)\\]]$)', '', $time2);
$time = theme('date_display_range', $time1, $time2);
$replaced = str_replace($time1, $time, $date1);
$output .= theme('date_display_single', $replaced, $timezone);
}
else {
$output .= theme('date_display_range', $date1, $date2, $timezone);
}
return $output;
}
function theme_date_display_single($date, $timezone = NULL) {
return '<span class="date-display-single">' . $date . $timezone . '</span>';
}
function theme_date_display_range($date1, $date2, $timezone = NULL) {
return '<span class="date-display-start">' . $date1 . '</span>' . '<span class="date-display-separator"> - </span>' . '<span class="date-display-end">' . $date2 . $timezone . '</span>';
}
/**
* Theme a format interval for a date element
*
* @param $field = the field settings
* @param $node = node information, this is not always available and not
* always the full node, it depends on what value was provided to the formatter.
* Only the nid is always guaranteed to be available.
* @param $dates - an array of date information, see explanation for date_field_object for details.
* @return a formatted display
*
*/
function theme_date_format_interval($field, $item, $dates, $node = NULL) {
// Time to compare dates to
$now = date_format(date_now(), DATE_FORMAT_DATETIME);
$start = $dates['value']['local']['datetime'];
$end = $dates['value2']['local']['datetime'];
// 1) The date is entirely in the future
if ($now < $start) {
return t('!time from now', array(
'!time' => $dates['value']['interval'],
));
}
elseif ($now > $start && $now <= $end) {
//return t('Started !time ago', array('!time' => $dates['value']['interval']));
return t('ongoing');
}
else {
return $dates['value']['interval'];
}
}
/**
* Theme the human-readable description for a Date Repeat rule.
*
* TODO -
* add in ways to store the description in the date so it isn't regenerated
* over and over and find a way to allow description to be shown or hidden.
*/
function theme_date_repeat_display($field, $item, $node = NULL, $dates) {
// If $field['field_name'] isn't set, this isn't a node, and is
// probably on a calendar view. The description is too expensive an
// operation to run on every field in a view, so don't do it.
$output = '';
if (isset($node->{$field}['field_name']) && ($item['#delta'] == 0 || !empty($item['#show_rrule']))) {
$output = date_repeat_rrule_description($item['rrule'], $dates['value']['local']['object']);
$output = '<div>' . $output . '</div>';
}
return $output;
}
/**
* Theme for the current period label name
*/
function theme_date_views_browser_period_label($period, $date) {
switch ($period) {
case 'year':
$format = 'Y';
break;
case 'month':
$format = 'F Y';
break;
case 'week':
case 'day':
// Use just the year/month/day part of the short date format.
$format = date_limit_format(variable_get('date_format_short', 'm/d/Y - H:i'), array(
'month',
'day',
'year',
));
break;
case 'hour':
// Use just the year/month/day/hour part of the short date format.
$format = date_limit_format(variable_get('date_format_short', 'm/d/Y - H:i'), array(
'month',
'day',
'year',
'hour',
));
break;
}
return t('%period of %date', array(
'%period' => ucwords($period),
'%date' => date_format_date($date, 'custom', $format),
));
}
/**
* Theme for page navigation
*/
function theme_date_views_browser_navigation($heading, $period, $prev_url, $next_url, $view) {
$output = '<div class="date-nav clear-block">';
$output .= '<div class="date-prev">';
$output .= l(t('‹ prev !period ', array(
'!period' => $period,
)), $prev_url, array(
'rel' => 'nofollow',
));
$output .= '</div><div class="date-heading"><h3>' . $heading . '</h3></div>';
$output .= '<div class="date-next">';
$output .= l(t(' next !period ›', array(
'!period' => $period,
)), $next_url, array(
'rel' => 'nofollow',
));
$output .= '</div></div>';
return $output;
}
/**
* Display a summary version of a view.
*/
function theme_date_views_browser_summary_view($view, $type, $level, $nodes, $args) {
return theme('date_views_browser_full_view', $view, $nodes, $type);
}
/**
* View, themed so it can be overridden
*
* Set $display to views_view_list, views_view_table, views_view_teasers,
* or views_view_nodes
*
* As an alternative, override this theme and set the display to
* date_views_browser_items for a display of only the current item
* value to keep multiple value dates from repeating the whole
* teaser each time.
*/
function theme_date_views_browser_full_view($view, $nodes, $type) {
$teasers = true;
$links = true;
$date_views_browser_views = date_views_browser_get_views();
$period = $date_views_browser_views[$view->name]->options;
switch ($type) {
case 'block':
$arg = date_views_browser_period_arg(NULL, $view->argument[0]['options']);
if ($view->url) {
$url = $view->url . '/' . $arg;
}
$output .= '<h5 class="date-browser-block-label">' . l(date_views_browser_period_label($arg, $period), $url, array(), NULL, NULL, FALSE, TRUE) . '</h5>';
$display = 'views_view_list';
break;
default:
$output .= date_views_browser_navigation($view, $period);
$display = 'date_view_nodes';
break;
}
$output .= theme($display, $view, $nodes, $type, $teasers, $links);
return $output;
}
/**
* Display the nodes of a view as teasers.
*/
function theme_date_view_teasers($view, $nodes, $type) {
return views_theme('date_view_nodes', $view, $nodes, $type, true);
}
/**
* Display the nodes of a view as plain nodes.
*
* Add the $view to the $node for use in themes.
*/
function theme_date_view_nodes($view, $nodes, $type, $teasers = false, $links = true) {
$output = '';
foreach ($nodes as $n) {
$node = node_load($n->nid);
$node->view = $view;
// Add view field values to the node so the theme can use them.
foreach ($n as $key => $value) {
$node->{$key} = $value;
}
$output .= node_view($node, $teasers, false, $links);
}
return $output;
}
/**
* Alternative Date Browser Display
*
* Display only the selected browser items instead of teasers or nodes,
* use for multiple date values to keep the entire teaser or node from being
* repeated for every multiple value of the date.
*/
function theme_date_views_browser_items($view, $nodes, $type, $teasers, $links) {
$fields = _views_get_fields();
$items = array();
foreach ($nodes as $node) {
$item = '';
foreach ($view->field as $field) {
if ($fields[$field['id']]['visible'] !== FALSE) {
if ($field['label']) {
$item .= "<div class='view-label " . views_css_safe('view-label-' . $field['queryname']) . "'>" . $field['label'] . "</div>";
}
// If this is the date field, format and display the current value.
if (strstr($field['handler'], 'date_views_field_handler_')) {
$field_name = explode('_value', $field['field']);
if (!empty($node->date_combo)) {
$values = explode('|', $node->date_combo);
$node_item = array(
'value' => $values[0],
'value2' => $values[1],
);
}
else {
$node_item = array(
'value' => $node->{$field}['field'],
);
}
$item .= "<div class='view-field " . views_css_safe('view-data-' . $field['queryname']) . "'>" . content_format($field_name[0], $node_item, $field['options'], $node) . "</div>";
}
else {
$item .= "<div class='view-field " . views_css_safe('view-data-' . $field['queryname']) . "'>" . views_theme_field('views_handle_field', $field['queryname'], $fields, $field, $node, $view) . "</div>";
}
}
}
$items[] = "<div class='view-item " . views_css_safe('view-item-' . $view->name) . "'>{$item}</div>\n";
}
if ($items) {
return theme('item_list', $items);
}
}
/**
* Adjust from/to date format to account for 'all day'.
*
* @param array $field, the field definition for this date field.
* @param string $which, which value to return, 'date1' or 'date2'.
* @param object $date1, a date/time object for the 'from' date.
* @param object $date2, a date/time object for the 'to' date.
* @param string $format
* @param object $node, the node this date comes from (may be incomplete, always contains nid).
* @param object $view, the view this node comes from, if applicable.
* @return formatted date.
*/
function theme_date_all_day($field, $which, $date1, $date2, $format, $node, $view = NULL) {
if (empty($date1) || !is_object($date1) || $format == 'format_interval') {
return '';
}
if (empty($date2)) {
$date2 = $date1;
}
$granularity = array_pop(date_format_order($format));
if (empty($field['granularity'])) {
$field['granularity'] = date_format_order($format);
}
$increment = $field['widget']['increment'];
$max_seconds = array_pop(date_seconds('s', TRUE, $increment));
$max_minutes = array_pop(date_minutes('i', TRUE, $increment));
switch ($granularity) {
case 'second':
$min_comp = date_format($date1, 'H:i:s') == '00:00:00';
$max_comp = date_format($date2, 'H:i:s') == '00:00:00' || date_format($date2, 'H:i:s') == '23:' . $max_minutes . ':' . $max_seconds;
break;
case 'minute':
$min_comp = date_format($date1, 'H:i') == '00:00';
$max_comp = date_format($date2, 'H:i:s') == '00:00:00' || date_format($date2, 'H:i') == '23:' . $max_minutes;
break;
case 'hour':
$min_comp = date_format($date1, 'H') == '00';
$max_comp = date_format($date2, 'H:i:s') == '00:00:00' || date_format($date2, 'H') == '23';
break;
default:
$min_comp = TRUE;
$max_comp = FALSE;
}
// Time runs from midnight to the maximum time -- call it 'All day'.
if (date_has_time($field['granularity']) && $min_comp && $max_comp) {
$format = date_limit_format($format, array(
'year',
'month',
'day',
));
return trim(date_format_date(${$which}, 'custom', $format) . ' ' . theme('date_all_day_label'));
}
elseif (!date_has_time($field['granularity'])) {
$format = date_limit_format($format, array(
'year',
'month',
'day',
));
return date_format_date(${$which}, 'custom', $format);
}
else {
return date_format_date(${$which}, 'custom', $format);
}
}
/**
* Theme the way an 'all day' label will look.
*/
function theme_date_all_day_label() {
return t('(All day)');
}
/** @} End of addtogroup themeable */
Functions
Name | Description |
---|---|
theme_date_all_day | Adjust from/to date format to account for 'all day'. |
theme_date_all_day_label | Theme the way an 'all day' label will look. |
theme_date_display_combination | Theme from/to date combination in the view. |
theme_date_display_range | |
theme_date_display_single | |
theme_date_format_interval | Theme a format interval for a date element |
theme_date_repeat_display | Theme the human-readable description for a Date Repeat rule. |
theme_date_views_browser_full_view | View, themed so it can be overridden |
theme_date_views_browser_items | Alternative Date Browser Display |
theme_date_views_browser_navigation | Theme for page navigation |
theme_date_views_browser_period_label | Theme for the current period label name |
theme_date_views_browser_summary_view | Display a summary version of a view. |
theme_date_view_nodes | Display the nodes of a view as plain nodes. |
theme_date_view_teasers | Display the nodes of a view as teasers. |