View source
<?php
function theme_calendar_views_summary(&$view, $type, $level, &$items, $args) {
$summary = !empty($items) && array_key_exists('num_nodes', $items[0]);
if ($summary || !calendar_is_calendar($view) || !calendar_is_calendar_arg($view)) {
return theme('views_summary', $view, $type, $level, $items, $args);
}
else {
return theme('calendar_view_calendar', $view, $items, $type);
}
}
function theme_calendar_views_calendar(&$view, &$items, $type) {
if (!calendar_is_calendar($view)) {
return;
}
$pos = calendar_arg_positions($view);
if ($pos[0] > count($view->real_args)) {
return;
}
require_once './' . drupal_get_path('module', 'calendar') . '/calendar.inc';
$view->real_url = calendar_real_url($view, $view->args);
$view->page_url = calendar_page_url($view);
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['stripe'] = 'stripe';
$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);
}
if (empty($items)) {
return $view->page_empty . $out;
}
else {
return $out;
}
}
function theme_calendar_view_list($view, $nodes, $type) {
$output = '<div class="calendar-calendar">';
$output .= theme('calendar_links', $view, $view->build_type != 'block');
$output .= theme('calendar_nav', $view);
$output .= '</div>';
$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 .= "<div class='view-label " . views_css_safe('view-label-' . $field['queryname']) . "'>" . $field['label'] . "</div>";
}
$item .= "<div class='view-field " . views_css_safe('view-data-' . $field['queryname']) . "'>";
$item .= $value . "</div>";
}
}
}
$items[] = "<div class='view-item " . views_css_safe('view-item-' . $view->name) . "'>{$item}</div>\n";
}
if (!empty($items)) {
$output .= theme('item_list', $items);
}
else {
$output .= views_get_textarea($view, $type, 'empty');
}
return $output;
}
function theme_calendar_view_table($view, $nodes, $type) {
$output = '<div class="calendar-calendar">';
$output .= theme('calendar_links', $view, $view->build_type != 'block');
$output .= theme('calendar_nav', $view);
$output .= '</div>';
$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;
}
function theme_calendar_view_teasers($view, $nodes, $type) {
return views_theme('calendar_view_nodes', $view, $nodes, 'teasers', TRUE);
}
function theme_calendar_view_nodes($view, $nodes, $type, $teasers = false, $links = true) {
$output = '<div class="calendar-calendar">';
$output .= theme('calendar_links', $view, $view->build_type != 'block');
$output .= theme('calendar_nav', $view);
$output .= '</div>';
$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;
}
function theme_calendar_page_title($view, $items, $output) {
$args = $view->args;
foreach ($args as $delta => $arg) {
if ($arg == CALENDAR_EMPTY_ARG || empty($arg)) {
unset($args[$delta]);
}
}
$last_arg = str_replace('W', '', 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;
}
}
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 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;
}
$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'];
}
if ($mini || $view->build_type == 'embed') {
$block_identifier = isset($view->block_identifier) ? $view->block_identifier : 'mini';
$prev_query[$block_identifier] = $prev_path;
$prev_path = !empty($prev_path) ? $_GET['q'] : '';
$next_query[$block_identifier] = $next_path;
$next_path = !empty($next_path) ? $_GET['q'] : '';
}
$output = '<div class="calendar-calendar"><div class="date-nav clear-block">';
$output .= '<div class="date-prev">';
$querystring = calendar_querystring($view, $prev_query);
$period = $view->build_type != 'block' ? t('prev') : '';
if (!empty($prev_path)) {
$output .= l(t('‹ !period ', array(
'!period' => $period,
)), $prev_path, array(
'rel' => 'nofollow',
), !empty($querystring) ? $querystring : NULL);
}
else {
$output .= ' ';
}
$heading = theme('calendar_nav_title', $view->calendar_type, $view, $link, $format);
$output .= '</div><div class="date-heading"><h3>' . $heading . '</h3></div>';
$output .= '<div class="date-next">';
$querystring = calendar_querystring($view, $next_query);
$period = $view->build_type != 'block' ? t('next') : '';
if (!empty($next_path)) {
$output .= l(t(' !period ›', array(
'!period' => $period,
)), $next_path, array(
'rel' => 'nofollow',
), !empty($querystring) ? $querystring : NULL);
}
else {
$output .= ' ';
}
$output .= '</div></div></div>';
return $output;
}
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':
$format = !empty($format) ? $format : (!$view->mini ? 'F Y' : 'F');
$title = date_format_date($view->min_date, 'custom', $format);
$url = $real_url . '/' . $view->year . '/' . $view->month;
break;
case 'day':
$format = !empty($format) ? $format : (!$view->mini ? 'l, F j Y' : 'l, F j');
$title = date_format_date($view->min_date, 'custom', $format);
$url = $real_url . '/' . $view->year . '/' . $view->month . '/' . $view->day;
break;
case 'week':
$format = !empty($format) ? $format : (!$view->mini ? 'F j Y' : 'F j');
$title = t('Week of @date', array(
'@date' => date_format_date($view->min_date, 'custom', $format),
));
$url = $real_url . '/' . $view->year . '/' . $view->week;
break;
}
if ($view->mini || $link) {
$block_identifier = isset($view->block_identifier) ? $view->block_identifier : 'mini';
return l($title, $url, array(), calendar_querystring($view, array(
$block_identifier => NULL,
)));
}
else {
return $title;
}
}
function theme_calendar_links($view, $links = FALSE) {
$now = date_now();
if ($links) {
$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));
}
$formats = calendar_get_formats($view);
if ($view->build_type == 'page') {
$query_string = calendar_querystring($view, !empty($_GET['view']) ? array(
'view' => $_GET['view'],
) : array());
$base = array(
'attributes' => array(
'rel' => 'nofollow',
),
);
if (!empty($formats['year'])) {
$calendar_links[] = $base + array(
'title' => t('Year'),
'href' => $view->real_url . '/' . $view->year,
'query' => $query_string,
);
}
if (!empty($formats['month'])) {
$calendar_links[] = array(
'title' => t('Month'),
'href' => $view->real_url . '/' . $view->year . '/' . $view->month,
'query' => $query_string,
);
}
if (!empty($formats['week'])) {
$calendar_links[] = array(
'title' => t('Week'),
'href' => $view->real_url . '/' . $view->year . '/W' . $view->week,
'query' => $query_string,
);
}
if (!empty($formats['day'])) {
$calendar_links[] = array(
'title' => t('Day'),
'href' => $view->real_url . '/' . $view->year . '/' . $view->month . '/' . $view->day,
'query' => $query_string,
);
}
}
else {
$block_identifier = isset($view->block_identifier) ? $view->block_identifier : 'mini';
$base = array(
'href' => $view->page_url,
'attributes' => array(
'rel' => 'nofollow',
),
);
if (!empty($_GET['view'])) {
$query_params['view'] = $_GET['view'];
}
if (!empty($formats['year'])) {
$query_params[$block_identifier] = $view->real_url . '/' . $view->year;
$calendar_links[] = $base + array(
'title' => t('Year'),
'query' => calendar_querystring($view, $query_params),
);
}
if (!empty($formats['month'])) {
$query_params[$block_identifier] = $view->real_url . '/' . $view->year . '/' . $view->month;
$calendar_links[] = $base + array(
'title' => t('Month'),
'query' => calendar_querystring($view, $query_params),
);
}
if (!empty($formats['week'])) {
$query_params[$block_identifier] = $view->real_url . '/' . $view->year . '/W' . $view->week;
$calendar_links[] = $base + array(
'title' => t('Week'),
'query' => calendar_querystring($view, $query_params),
);
}
if (!empty($formats['day'])) {
$query_params[$block_identifier] = $view->real_url . '/' . $view->year . '/' . $view->month . '/' . $view->day;
$calendar_links[] = $base + array(
'title' => t('Day'),
'query' => calendar_querystring($view, $query_params),
);
}
}
if ($view->build_type == 'page' && variable_get('calendar_popup_' . $view->name, 0)) {
$output = '<div class="clear-block">' . calendar_date_select($view) . '</div>';
}
$output .= theme('links', $calendar_links);
return $output;
}
}
function theme_calendar_stripe_legend() {
if (empty($GLOBALS['calendar_stripes'])) {
return '';
}
$view = $GLOBALS['current_view'];
$header = array(
array(
'class' => 'calendar-legend',
'data' => t('Item'),
),
array(
'class' => 'calendar-legend',
'data' => t('Key'),
),
);
foreach ((array) $GLOBALS['calendar_stripes'] as $label => $stripe) {
$rows[] = array(
$label,
'<div style="background-color:' . $stripe . ';color:' . $stripe . '" class="stripe" title="Key: ' . $label . '"> </div>',
);
}
$output = theme('table', $header, $rows, array(
'class' => 'mini calendar-legend',
));
return $output;
}
function theme_calendar_stripe_stripe($node) {
if (empty($node->stripe)) {
return;
}
$GLOBALS['calendar_stripes'][$node->stripe_label] = $node->stripe;
return '<div style="background-color:' . $node->stripe . ';color:' . $node->stripe . '" class="stripe" title="Key: ' . $node->stripe_label . '"> </div>' . "\n";
}
function theme_calendar_year($view, $header, $rows) {
$output = '<div class="calendar-calendar"><div class="year-view">';
$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 = '<div class="date-nav"><div class="date-header"><h3>' . theme('calendar_nav_title', 'month', $view) . '</h3></div></div>';
$row[] = array(
'data' => $month_header . theme('calendar_month', $view, $header, $month_rows),
);
if ($i == 3) {
$rows_out[] = $row;
$row = array();
$i = 0;
}
$i++;
}
$output .= theme("table", $header, $rows_out, array(
'class' => 'mini',
));
$output .= "</div></div>\n";
return $output;
}
function theme_calendar_month($view, $header, $rows) {
$attrs = array();
if ($view->mini == 'mini') {
$attrs = array(
'class' => 'mini',
);
}
$output = theme("table", $header, $rows, $attrs);
return '<div class="calendar-calendar"><div class="month-view">' . $output . "</div></div>\n";
}
function theme_calendar_week($view, $header, $rows) {
$output = theme("table", $header, $rows);
return '<div class="calendar-calendar"><div class="week-view">' . $output . "</div></div>\n";
}
function theme_calendar_day($view, $header, $data) {
$rows = array(
array(
array(
'data' => $data,
'colspan' => 3,
),
),
);
$output = theme("table", $header, $rows);
return '<div class="calendar-calendar"><div class="day-view">' . $output . "</div></div>\n";
}
function theme_calendar_node_day($node, $view) {
$output = '<div class="calendar dayview" id="' . $node->date_id . '">' . "\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 .= "<div class='view-label " . views_css_safe('view-label-' . $field['queryname']) . "'>" . $field['label'] . "</div>";
}
$item .= "<div class='view-field " . views_css_safe('view-data-' . $field['queryname']) . "'>";
$item .= $value . "</div>";
}
}
}
if ($node->remote && $node->teaser) {
$item .= '<div class="content">' . $node->teaser . "</div>\n";
}
$output .= "<div class='view-item " . views_css_safe('view-item-' . $view->name) . "'>{$item}</div>\n";
$output .= "</div>\n";
return $output;
}
function theme_calendar_node_week($node, $view) {
$output .= '<div class="calendar weekview" id="' . $node->date_id . '">' . "\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)) {
$item .= "<div class='view-field " . views_css_safe('view-data-' . $field['queryname']) . "'>";
$item .= $value . "</div>";
}
}
}
$output .= "<div class='view-item " . views_css_safe('view-item-' . $view->name) . "'>{$item}</div>\n";
$output .= '</div>' . "\n";
return $output;
}
function theme_calendar_node_month($node, $view) {
$output .= '<div class="calendar monthview" id="' . $node->date_id . '">' . "\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)) {
$item .= "<div class='view-field " . views_css_safe('view-data-' . $field['queryname']) . "'>";
$item .= $value . "</div>";
}
}
}
$output .= "<div class='view-item " . views_css_safe('view-item-' . $view->name) . "'>{$item}</div>\n";
$output .= "</div>\n";
return $output;
}
function theme_calendar_multiple_node_month($curday_date, $count, $view, $types) {
$parts = explode('-', substr($curday_date, 0, 10));
$year = $parts[0];
$month = intval($parts[1]);
$day = intval($parts[2]);
$max_events = variable_get('calendar_limit_' . $view->name, 5);
$link = $view->real_url . '/' . date_pad($year, 4) . '/' . date_pad($month) . '/' . date_pad($day);
$output .= '<div class="calendar monthview">' . "\n";
if ($view->style_max_items_behavior != 'more') {
foreach ($types as $type) {
$output .= theme('calendar_stripe_stripe', $type);
}
$item = "<div class='multiple-events'>" . l(t('Click to see all @count events', array(
'@count' => $count,
)), $link) . "</div>";
}
elseif ($count > 0) {
$item = '<div class="calendar-more">' . l(t('more»'), $link) . '</div>';
}
$output .= "<div class='view-item " . views_css_safe('view-item-' . $view->name) . "'>{$item}</div>\n";
$output .= "</div>\n";
return $output;
}
function theme_calendar_multiple_node_week($curday_date, $count, $view, $types) {
$parts = explode('-', substr($curday_date, 0, 10));
$year = $parts[0];
$month = intval($parts[1]);
$day = intval($parts[2]);
$link = $view->real_url . '/' . date_pad($year, 4) . '/' . date_pad($month) . '/' . date_pad($day);
$output .= '<div class="calendar weekview">' . "\n";
if ($view->style_max_items_behavior != 'more') {
foreach ($types as $type) {
$output .= theme('calendar_stripe_stripe', $type);
}
$item = "<div class='multiple-events'>" . l(t('Click to see all @count events', array(
'@count' => $count,
)), $link) . "</div>";
}
else {
$item = '<div class="calendar-more">' . l(t('more»'), $link) . '</div>';
}
$output .= "<div class='view-item " . views_css_safe('view-item-' . $view->name) . "'>{$item}</div>\n";
$output .= "</div>\n";
return $output;
}
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]);
$querystring = calendar_querystring($view);
if ($view->build_type == 'embed') {
$url = $view->page_url;
$block_identifier = isset($view->block_identifier) ? $view->block_identifier : 'mini';
$append = (!empty($querystring) ? $querystring . '&' : '') . $block_identifier . '=' . $view->real_url . '/' . date_pad($year, 4) . '/' . date_pad($month) . '/' . date_pad($day);
}
else {
$url = $view->real_url . '/' . date_pad($year, 4) . '/' . date_pad($month) . '/' . date_pad($day);
$append = $params['append'];
}
if ($view->mini) {
if ($selected) {
return '<div class="mini-day-on">' . l($day, $url, NULL, $append) . '</div>';
}
else {
return '<div class="mini-day-off">' . l($day, $url, NULL, $append) . '</div>';
}
}
if ($view->calendar_type != 'day') {
return '<div class="day">' . l($day, $url, NULL, $append) . '</div>' . "\n";
}
$output = '<div class="day">' . l($day, $url, NULL, $append) . '</div>' . "\n";
return $output;
}
function theme_calendar_empty_day() {
return '<div class="calendar-empty"> </div>' . "\n";
}
function theme_calendar_views_field($fieldname, $fields, $field, $node, $view, $type) {
$length = variable_get('calendar_truncate_length_' . $view->name, '');
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);
if ($view->calendar_type != 'day' && !empty($length)) {
$item = str_replace(">" . check_plain($node->title), ' title="' . check_plain($node->title) . '">' . check_plain(calendar_trim_text($node->title, $length)), $item);
}
}
elseif ($fieldname != $node->datefield) {
$item = '';
}
else {
if (!empty($node->{$fieldname})) {
$item = theme('calendar_date_combo', $field, $node, $field['label'], $view);
}
}
return $item;
}
function theme_calendar_date_combo($field, $node, $label, $view) {
switch ($view->calendar_display) {
case 'calendar':
switch ($view->calendar_type) {
case 'year':
return;
case 'week':
case 'month':
$format = $node->format_time;
$label = '';
break;
case 'day':
$format = $node->format;
break;
}
break;
default:
$format = $node->format;
break;
}
$date1 = theme('date_all_day', $field, 'date1', $node->calendar_start_date, $node->calendar_end_date, $format, $node, $view);
$date2 = theme('date_all_day', $field, 'date2', $node->calendar_start_date, $node->calendar_end_date, $format, $node, $view);
if (empty($date1) && empty($date2)) {
$output = '';
}
elseif ($date1 == $date2 || empty($date2)) {
$output = '<span class="date-display-single">' . $date1 . '</span>';
}
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 = '<span class="date-display-single">' . date_format($node->calendar_start_date, $date_format) . '</span> ' . '<span class="date-display-start">' . date_format($node->calendar_start_date, $node->format_time) . '</span>' . '<span class="date-display-separator"> - </span>' . '<span class="date-display-end">' . date_format($node->calendar_end_date, $node->format_time) . '</span>';
}
else {
$output = '<span class="date-display-start">' . $date1 . '</span>' . '<span class="date-display-separator"> - </span>' . '<span class="date-display-end">' . $date2 . '</span>';
}
return $output;
}