count($view->real_args)) {
return;
}
include_once(drupal_get_path('module', 'calendar') .'/calendar.inc');
// Bail out here to display regular views views instead of calendar.
switch($view->calendar_display) {
case ('table') :
$view->table_header = _views_construct_header($view, _views_get_fields());
$out = theme('calendar_view_table', $view, $items, $type);
break;
case ('teasers') :
$out = theme('calendar_view_teasers', $view, $items, $type);
break;
case ('nodes') :
$out = theme('calendar_view_nodes', $view, $items, $type);
break;
case ('list') :
$out = theme('calendar_view_list', $view, $items, $type);
break;
default:
$params['url'] = calendar_real_url($view, $view->args);
$params['append'] = calendar_url_append($view);
$params['stripe'] = 'stripe';
// Set to TRUE to see week numbers in each row.
$formats = calendar_get_formats($view);
if ($view->build_type != 'block' && in_array($view->calendar_type, array('month', 'week'))) {
$params['with_weekno'] = variable_get('calendar_weekno_'. $view->name, 1);
}
else {
$params['with_weekno'] = FALSE;
}
$out = calendar_build_calendar($view, $items, $params);
}
return $out;
}
/**
* Display the nodes of a view as a list.
*/
function theme_calendar_view_list($view, $nodes, $type) {
$output = '
';
$output .= theme('calendar_links', $view, $view->build_type != 'block');
$output .= theme('calendar_nav', $view);
$output .= '
';
$fields = _views_get_fields();
$items = array();
foreach ($nodes as $node) {
$item = '';
foreach ($view->field as $field) {
if ($fields[$field['id']]['visible'] !== FALSE) {
$value = theme('calendar_views_field', $field['queryname'], $fields, $field, $node, $view, $type);
if (!empty($value)) {
if ($field['label']) {
$item .= "". $field['label'] ."
";
}
$item .= "";
$item .= $value ."
";
}
}
}
$items[] = "name) ."'>$item
\n"; // l($node->title, "node/$node->nid");
}
if (!empty($items)) {
$output .= theme('item_list', $items);
}
else {
$output .= views_get_textarea($view, $type, 'empty');
}
return $output;
}
/**
* Display the nodes of a view as a table.
*/
function theme_calendar_view_table($view, $nodes, $type) {
$output = '';
$output .= theme('calendar_links', $view, $view->build_type != 'block');
$output .= theme('calendar_nav', $view);
$output .= '
';
$fields = _views_get_fields();
$rows = array();
foreach ($nodes as $node) {
$row = array();
foreach ($view->field as $field) {
if ($fields[$field['id']]['visible'] !== FALSE) {
$cell['data'] = theme('calendar_views_field', $field['queryname'], $fields, $field, $node, $view, $type);
$cell['class'] = "view-field ". views_css_safe('view-field-'. $field['queryname']);
$row[] = $cell;
}
}
$rows[] = $row;
}
if (!empty($rows)) {
$output .= theme('table', $view->table_header, $rows);
}
else {
$output .= views_get_textarea($view, $type, 'empty');
}
return $output;
}
/**
* Display the nodes of a view as teasers.
*/
function theme_calendar_view_teasers($view, $nodes, $type) {
return views_theme('calendar_view_nodes', $view, $nodes, 'teasers', TRUE);
}
/**
* Display the nodes of a view as plain nodes.
*/
function theme_calendar_view_nodes($view, $nodes, $type, $teasers = false, $links = true) {
$output = '';
$output .= theme('calendar_links', $view, $view->build_type != 'block');
$output .= theme('calendar_nav', $view);
$output .= '
';
$data = array();
foreach ($nodes as $n) {
if (isset($n->calendar_node_theme)) {
$theme = $n->calendar_node_theme;
$data[] = theme($theme, $n, $view);
}
else {
$node = node_load($n->nid);
$data[] = node_view($node, $teasers, false, $links);
}
}
if (!empty($data)) {
$output .= implode($data);
}
else {
$output .= views_get_textarea($view, $type, 'empty');
}
return $output;
}
/**
* Theme the calendar page title.
*
* Views defaults to displaying the title of the last argument in the
* view, rather than the View title or other values. Use this theme
* to override that behavior.
*
* $view->build_type indicates whether this view is being rendered as a page
* or a block, use that to handle the title differently for each.
*
* views_get_title() $context can be:
* 'page' - The title that goes with the last argument in $args.
* 'menu' - The value in View Menu Title.
*
* or just use the values of:
* $view->page_title,
* $view->menu_title,
* $view->block_title.
*/
function theme_calendar_page_title($view, $items, $output) {
// Get rid of empty args to display the right title for the calendar.
$args = $view->args;
foreach($args as $delta => $arg) {
if ($arg == CALENDAR_EMPTY_ARG || empty($arg)) {
unset($args[$delta]);
}
}
$last_arg = array_pop($args);
return theme('calendar_arg_title', strtoupper($view->calendar_type), $last_arg, $last_arg);
switch ($view->build_type) {
case 'page':
if ($view->calendar_type == 'year') {
return $view->year;
}
else {
return views_get_title($view, 'page', $args);
}
case 'block':
return $view->block_title;
}
}
/**
* Theme the calendar title and breadcrumbs
* Arguments are evaluated in year, month, day or year, week order
* so you can track previous values in the session.
*
* @param string $field_type - 'YEAR', 'MONTH', 'DAY', 'WEEK'
* @param integer $value - the current number for the field type as selected in the view argument.
* @return string formatted title
*/
function theme_calendar_arg_title($field_type, $value, $query) {
$value = intval(check_plain($value));
if (empty($value)) {
return '';
}
else {
$view = $GLOBALS['current_view'];
switch (strtoupper($field_type)) {
case 'YEAR':
$view->year = $value;
return $view->year;
case 'MONTH':
return date_format_date($view->min_date, 'custom', 'F');
case 'DAY':
return date_format_date($view->min_date, 'custom', 'l, F j Y');
case 'WEEK':
return t('Week of @date', array('@date' => date_format($view->min_date, 'F j')));
}
}
return $value;
}
/**
* Function to construct back and next navigation from views arguments
*/
function theme_calendar_nav($view, $link = FALSE, $format = NULL) {
$mini = $view->mini && $view->calendar_type != 'year';
if (!calendar_part_is_valid($view->year, 'year')) {
return $view->subtitle;
}
// make the navigation into a header, with prev and next links
// use the calendar_nav themes to mimic standard calendar navigation
$paths = calendar_get_paths($view);
$prev_path = implode('/', array_reverse($paths[0]));
$next_path = implode('/', array_reverse($paths[1]));
$prev_query = $next_query = array();
if ($_GET['view']) {
$prev_query[] = 'view='. $_GET['view'];
$next_query[] = 'view='. $_GET['view'];
}
// for the mini calendar in a block, treat the url as a
// querystring to avoid actually changing the page
if ($mini) {
$prev_query[] = 'mini='. $prev_path;
$prev_path = $_GET['q'];
$next_query[] = 'mini='. $next_path;
$next_path = $_GET['q'];
}
$prev_query[] = calendar_url_append($view);
$next_query[] = calendar_url_append($view);
$output = '';
$output .= '
';
$querystring = implode('&', $prev_query);
$period = $view->build_type != 'block' ? t('prev') : '';
$output .= l(t('‹ !period ', array('!period' => $period)), $prev_path, array(), (!empty($querystring) ? $querystring : NULL));
$heading = theme('calendar_nav_title', $view->calendar_type, $view, $link, $format);
$output .= '
'. $heading .'
';
$output .= '
';
$querystring = implode('&', $next_query);
$period = $view->build_type != 'block' ? t('next') : '';
$output .= l(t(' !period ›', array('!period' => $period)), $next_path, array(), (!empty($querystring) ? $querystring : NULL));
$output .= '
';
return $output;
}
/**
* Theme the navigation bar title
*
* @param string $type - 'year', 'month', 'day', 'week'
* @param object $view - the current view object
* @return formatted title
*/
function theme_calendar_nav_title($type, $view, $link = FALSE, $format = NULL) {
$real_url = calendar_real_url($view, $view->args);
switch ($type) {
case 'year':
$title = $view->year;
$url = $real_url .'/'. $view->year;
break;
case 'month':
$title = date_format_date($view->min_date, 'custom', !empty($format) ? $format : 'F');
$url = $real_url .'/'. $view->year .'/'. $view->month;
break;
case 'day':
$title = date_format_date($view->min_date, 'custom', !empty($format) ? $format : 'l, F j Y');
$url = $real_url .'/'. $view->year .'/'. $view->month .'/'. $view->day;
break;
case 'week':
$title = t('Week of @date', array('@date' => date_format_date($view->min_date, 'custom', !empty($format) ? $format : 'F j')));
$url = $real_url .'/'. $view->year .'/'. $view->week;
break;
}
if ($view->mini || $link) {
// Month navigation titles are used as links in the mini view.
return l($title, $url, array(), calendar_url_append($view));
}
else {
return $title;
}
}
/**
* Links at the top of the calendar.
*
* @param links
* TRUE/FALSE, should links be shown.
* @param view
* The current view being rendered
*/
function theme_calendar_links($view, $links = FALSE) {
$now = date_now();
// add links to the top of the calendar to switch from one view to another
if ($links) {
$view->real_url = calendar_real_url($view, $view->args);
$base_url = $view->real_url .'/'. $view->year;
$view->month = $view->month && $view->month != CALENDAR_EMPTY_ARG ? $view->month : date_format($now, 'm');
$view->day = $view->day && $view->day != CALENDAR_EMPTY_ARG ? $view->day : date_format($now, 'j');
if (empty($view->week) || $view->week == CALENDAR_EMPTY_ARG) {
$view->week = date_week($view->year .'-'. date_pad($view->month) .'-'. date_pad($view->day));
}
$append = calendar_url_append($view);
if ($_GET['view']) {
$append .= '&view='. $_GET['view'];
}
$formats = calendar_get_formats($view);
if (!empty($formats['year'])) {
$calendar_links[] = array('title' => t('Year'), 'href' => $view->real_url .'/'. $view->year, 'query' => $append);
}
if (!empty($formats['month'])) {
$calendar_links[] = array('title' => t('Month'), 'href' => $view->real_url .'/'. $view->year .'/'. $view->month , 'query' => $append);
}
if (!empty($formats['week'])) {
$calendar_links[] = array('title' => t('Week'), 'href' => $view->real_url .'/'. $view->year .'/W'. $view->week, 'query' => $append);
}
if (!empty($formats['day'])) {
$calendar_links[] = array('title' => t('Day'), 'href' => $view->real_url .'/'. $view->year .'/'. $view->month .'/'. $view->day, 'query' => $append);
}
// If the Date Popup module is enabled, add a popup date selector.
if (module_exists('date_popup') && variable_get('calendar_popup_'. $view->name, module_exists('date_popup'))) {
$output = ''. calendar_date_select($view) .'
';
}
$output .= theme('links', $calendar_links);
return $output;
}
}
/**
* Format a node stripe legend
*/
function theme_calendar_stripe_legend($stripe_labels) {
$view = $GLOBALS['current_view'];
$header = array(
array('class' => 'legend', 'data' => t('Item')),
array('class' => 'legend', 'data' => t('Key'))
);
$type_names = node_get_types('names');
$colors = variable_get('calendar_color_'. $view->name, array());
foreach ($type_names as $type_name => $type) {
if (!empty($colors[$type_name])) {
$label = $type_names[$type_name];
$stripe = $colors[$type_name];
$node = new StdClass();
$node->type = $type_name;
$node->stripe = $stripe;
$node->stripe_label = $label;
$rows[] = array($label, theme('calendar_stripe_stripe', $node));
}
}
$output = theme('table', $header, $rows, array('class' => 'mini legend'));
return $output;
}
/**
* Format node stripes
* Add key value to text, then hide it with css for accessibility to screen readers
*/
function theme_calendar_stripe_stripe($node) {
if (empty($node->stripe)) {
return;
}
return 'Key '. $node->stripe_label .'
'."\n";
}
/**
* Format a year view
*/
function theme_calendar_year($view, $header, $rows) {
$output = '';
$rows_out = array();
$row = array();
$i = 1;
foreach ($rows as $month => $month_rows) {
$view->month = $month;
$view->min_date = date_make_date($view->year .'-'. date_pad($view->month) .'-01 00:00:00', date_default_timezone_name());
$month_header = array(array('data' => theme('calendar_nav_title', 'month', $view), 'colspan' => 7));
$row[] = array(
'data' => theme('calendar_month', 'mini', $month_header, $month_rows),
);
// Group three mini month calendars in each year row.
if ($i == 3) {
$rows_out[] = $row;
$row = array();
$i = 0;
}
$i++;
}
$output .= theme("table", $header, $rows_out, array('class' => 'mini-row'));
$output .= "
\n";
return $output;
}
/**
* Format a month view
*/
function theme_calendar_month($view, $header, $rows) {
$attrs = array();
if ($view->mini == 'mini') {
$attrs = array('class' => 'mini');
}
$output = theme("table", $header, $rows, $attrs);
return '\n";
}
/**
* Format a week view
*/
function theme_calendar_week($view, $header, $rows) {
$output = theme("table", $header, $rows);
return '\n";
}
/**
* Format a day view
*
* It's really not great to force this into a table, but the navigation
* is a table header and showing the header without a body is invalid html,
* so we force the data into a table cell.
*/
function theme_calendar_day($view, $header, $data) {
$rows = array(array(array('data' => $data, 'colspan' => 3)));
$output = theme("table", $header, $rows);
return '\n";
}
/**
* Format an calendar node for display in an expanded calendar, like a calendar page
*
* @param node
* The node being displayed
*/
function theme_calendar_node_day($node, $view) {
$output = ''."\n";
$output .= theme('calendar_stripe_stripe', $node);
$fields = _views_get_fields();
$item = '';
foreach ($view->field as $field) {
if ($fields[$field['id']]['visible'] !== FALSE) {
$value = theme('calendar_views_field', $field['queryname'], $fields, $field, $node, $view, $type);
if (!empty($value)) {
if ($field['label']) {
$item .= "
". $field['label'] ."
";
}
$item .= "
";
$item .= $value ."
";
}
}
}
// Remote items may have a teaser to show.
if ($node->remote && $node->teaser) {
$item .= '
'. ($node->teaser) ."
\n";
}
$output .= "
name) ."'>$item
\n";
$output .= "
\n";
return $output;
}
/**
* Format an calendar node for display in an expanded calendar, like a calendar page
*
* @param node
* The node being displayed
*/
function theme_calendar_node_week($node, $view) {
$output .= ''."\n";
$output .= theme('calendar_stripe_stripe', $node);
$fields = _views_get_fields();
$item = '';
foreach ($view->field as $field) {
if ($fields[$field['id']]['visible'] !== FALSE) {
// Skip the label in this small box, show only the value;
$value = theme('calendar_views_field', $field['queryname'], $fields, $field, $node, $view, $type);
if (!empty($value)) {
$item .= "
";
$item .= $value ."
";
}
}
}
$output .= "
name) ."'>$item
\n";
$output .= '
' . "\n";
return $output;
}
/**
* Format an calendar node for display in an expanded calendar, like a calendar page
*
* @param node
* The node being displayed
*/
function theme_calendar_node_month($node, $view) {
$output .= ''."\n";
$output .= theme('calendar_stripe_stripe', $node);
$fields = _views_get_fields();
$item = '';
foreach ($view->field as $field) {
if ($fields[$field['id']]['visible'] !== FALSE) {
// Skip the label in this small box, show only the value;
$value = theme('calendar_views_field', $field['queryname'], $fields, $field, $node, $view, $type);
if (!empty($value)) {
$item .= "
";
$item .= $value ."
";
}
}
}
$output .= "
name) ."'>$item
\n";
$output .= "
\n";
return $output;
}
/**
* Format an date's day box in a calendar
*
* @param date
* The day to display in YYYY-MM-DD format.
* @param view
* The view being displayed.
* @param items
* The list of all items in the current view.
* @param params
* An array of paramters.
* @param selected
* Whether the current date has nodes.
* @return
* A themed day.
*/
function theme_calendar_date_box($date, $view, $items, $params, $selected = FALSE) {
$parts = explode('-', substr($date, 0, 10));
$year = $parts[0];
$month = intval($parts[1]);
$day = intval($parts[2]);
$url = $params['url'] .'/'. $year .'/'. $month .'/'. $day;
$append = $params['append'];
if ($view->mini) {
if ($selected) {
return ''. l($day, $url, NULL, $append) .'
';
}
else {
return ''. l($day, $url, NULL, $append) .'
';
}
}
if ($view->calendar_type != 'day') {
return ''. l($day, $url, NULL, $append) .'
'."\n";
}
$output = ''. l($day, $url, NULL, $append) .'
'."\n";
return $output;
}
/**
* Format an empty day on a calendar
*
* @param day
* The day to display.
*/
function theme_calendar_empty_day() {
return '
'."\n";
}
/**
* Wrapper around views_theme_field() to properly format the dates in the view.
* Use the usual views field formatting for all other fields.
*/
function theme_calendar_views_field($fieldname, $fields, $field, $node, $view, $type) {
if (isset($node->calendar_field_theme)) {
$theme = $node->calendar_field_theme;
return theme($theme, $fieldname, $fields, $field, $node, $view, $type);
}
$calendar_fields = calendar_fields();
if (!in_array($field['field'], array_keys($calendar_fields))) {
$item = views_theme_field('views_handle_field', $fieldname, $fields, $field, $node, $view);
}
elseif ($fieldname != $node->datefield) {
$item = '';
}
else {
if (!empty($node->$fieldname)) {
$item = theme('calendar_date_combo', $node, $field['label'], $view);
}
}
return $item;
}
/**
* Format a from/to date in the calendar view.
*
* Alter the display as appropriate for the type of view.
* We can fine-tune the display to show only the time in
* the calendar month and week cells but the
* whole date in other places.
*/
function theme_calendar_date_combo($node, $label, $view) {
switch ($view->calendar_display) {
// Some of the calendar views need a smaller date format.
case 'calendar':
switch ($view->calendar_type) {
case 'year':
// We don't display individual dates in the calendar year view.
return;
case 'week':
case 'month':
// No room for a label or the full date in these small
// displays, show only the time.
$format = $node->format_time;
$label = '';
break;
case 'day':
$format = $node->format;
break;
}
break;
// For non-calendar views, like lists and tables, show the entire date.
default:
$format = $node->format;
break;
}
$date1 = theme('date_all_day', 'date1', $node->calendar_start_date, $node->calendar_end_date, $format, $node, $view);
$date2 = theme('date_all_day', 'date2', $node->calendar_start_date, $node->calendar_end_date, $format, $node, $view);
// No date values, display nothing.
if (empty($date1) && empty($date2)) {
$output = '';
}
// From and To dates match or there is no To date,
// display a complete single date.
elseif ($date1 == $date2 || empty($date2)) {
$output = ''. $date1 .'';
}
// Full date format, same day, different times, don't repeat the date
// but show both From and To times.
elseif (date_format($node->calendar_start_date, $node->format_time) != date_format($node->calendar_end_date, $node->format_time) && $format != $node->format_time) {
$date_format = date_limit_format($format, array('year', 'month', 'day'));
$output = ''. date_format($node->calendar_start_date, $date_format).' '.
''. date_format($node->calendar_start_date, $node->format_time) .''.
' - '.
''. date_format($node->calendar_end_date, $node->format_time) .'';
}
// Time format only or different days, display both in their entirety.
else {
$output = ''. $date1 .''.
' - '.
''. $date2 .'';
}
return $output;
}
/** @} End of addtogroup themeable */