View source
<?php
function theme_calendar_view_summary(&$view, $type, $level, &$items, $args) {
if (!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_view_calendar(&$view, &$items, $type) {
if ($type == 'block' || !calendar_is_calendar_arg($view)) {
$view->calendar_type = 'month';
}
$mini = $view->calendar_type == 'year' || $view->build_type == 'block' ? TRUE : FALSE;
$links = $view->build_type == 'block' ? FALSE : TRUE;
if ($_GET['view'] && $view->build_type == 'page') {
$display = check_plain($_GET['view']);
}
else {
$display_formats = calendar_get_formats($view);
$display = $view->build_type == 'block' ? $display_formats['block'] : $display_formats[$view->calendar_type];
}
switch ($display) {
case 'table':
$view->table_header = _views_construct_header($view, _views_get_fields());
return theme('calendar_show_nav', $view, $mini, $links) . theme('calendar_view_table', $view, $items, $type);
case 'teasers':
return theme('calendar_show_nav', $view, $mini, $links) . theme('calendar_view_teasers', $view, $items, $type);
case 'nodes':
return theme('calendar_show_nav', $view, $mini, $links) . theme('calendar_view_nodes', $view, $items, $type);
case 'list':
return theme('calendar_show_nav', $view, $mini, $links) . theme('calendar_view_list', $view, $items, $type);
}
$results = calendar_get_nodes($view, $items, $type);
$nodes = (array) $results['nodes'];
$params = (array) $results['params'];
$params[with_weekno] = FALSE;
$nodes = array_merge($nodes, (array) calendar_add_items($view, 'calendar'));
return theme('calendar_show_nav', $view, $mini, $links) . calendar_get_calendar($view->calendar_type, $nodes, 'calendar', '', $params);
}
function theme_calendar_view_list($view, $nodes, $type) {
$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>";
}
$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";
}
$items = array_merge($items, (array) calendar_add_items($view, 'list'));
if ($items) {
return theme('item_list', $items);
}
}
function theme_calendar_view_table($view, $nodes, $type) {
$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'] = views_theme_field('views_handle_field', $field['queryname'], $fields, $field, $node, $view);
$cell['class'] = "view-field " . views_css_safe('view-field-' . $field['queryname']);
$row[] = $cell;
}
}
$rows[] = $row;
}
$rows = array_merge($rows, (array) calendar_add_items($view, 'table'));
return theme('table', $view->table_header, $rows);
}
function theme_calendar_view_teasers($view, $nodes, $type) {
return views_theme('calendar_view_nodes', $view, $nodes, 'teasers');
}
function theme_calendar_view_nodes($view, $nodes, $type, $teasers = false, $links = true) {
$output = array();
foreach ($nodes as $n) {
$node = node_load($n->nid);
$output[] = node_view($node, $teasers, false, $links);
}
$output = array_merge($output, (array) calendar_add_items($view, $teasers ? 'teasers' : 'nodes'));
return implode($output);
}
function theme_calendar_calendar_node($node, $type) {
static $set_nodes;
if (in_array($node->nid . ':' . $node->instance, (array) $set_nodes)) {
return theme($type, $node);
}
if ($type == 'calendar_node_day') {
$node = node_load($node->nid);
$node->teaser = node_view($node, TRUE, FALSE);
$node->title = '';
}
else {
if (isset($node->fields) && !isset($node->teaser)) {
foreach ($node->fields as $field) {
$node->teaser .= '<div>' . $field . '</div>';
}
}
if (!$node->url) {
$node->url = "node/{$node->nid}";
}
}
$set_nodes[] = $node->nid . ':' . $node->instance;
return theme($type, $node);
}
function theme_calendar_page_title($view, $items, $output) {
switch ($view->build_type) {
case 'page':
return views_get_title($view, $context = 'page', $args = $view->real_args);
case 'block':
return $view->block_title;
}
}
function theme_calendar_arg_title($field_type, $value, $query) {
$view = $GLOBALS['current_view'];
calendar_load_date_api();
$value = intval(check_plain($value));
if (empty($value)) {
if ($view->month) {
if ($view->month == "all") {
$view->month = 1;
}
$stamp = date_gmmktime(array(
'year' => $view->year,
'mon' => $view->month,
'mday' => 1,
));
return date_format_date('F Y', $stamp);
}
elseif ($view->year) {
return $view->year;
}
}
else {
switch ($field_type) {
case 'YEAR':
$view->year = $value;
return $view->year;
case 'MONTH':
$view->month = $value;
$stamp = date_gmmktime(array(
'year' => $view->year,
'mon' => $view->month,
'mday' => 1,
));
return date_format_date('F Y', $stamp);
case 'DAY':
$stamp = date_gmmktime(array(
'year' => $view->year,
'mon' => $view->month,
'mday' => $value,
));
return date_format_date('l, F j Y', $stamp);
case 'WEEK':
return t('Week @week @year', array(
'@year' => $view->year,
'@week' => $value,
));
}
}
}
function theme_calendar_nav_title($field_type, $view) {
calendar_load_date_api();
switch ($field_type) {
case 'YEAR':
return $view->year;
case 'MONTH':
$timestamp = date_array2unix(array(
'year' => $view->year,
'mon' => $view->month,
'mday' => 2,
));
if ($view->build_type == 'block' || $view->calendar_type == 'year') {
return l(date_format_date('M Y', $timestamp), $view->real_url . '/' . $view->year . '/' . $view->month, array(), calendar_url_append($view));
}
else {
return date_format_date('F Y', $timestamp);
}
case 'DAY':
$timestamp = date_array2unix(array(
'year' => $view->year,
'mon' => $view->month,
'mday' => $view->day,
'hours' => 12,
));
return date_format_date('l, F j Y', $timestamp);
case 'WEEK':
return t("Week of @date", array(
'@date' => date_format_date('F j Y', calendar_week('start_timestamp', $view, $view->week)),
));
}
}
function theme_calendar_show_nav($view, $mini = FALSE, $links = FALSE) {
calendar_load_calendar_api();
if ($links) {
$view->real_url = calendar_real_url($view, $view->args);
$base_url = $view->real_url . '/' . $view->year;
$month = $view->month && $view->month != CALENDAR_EMPTY_ARG ? $view->month : calendar_user_date('month');
$day = $view->day && $view->day != CALENDAR_EMPTY_ARG ? $view->day : calendar_user_date('day');
$week = $view->week && $view->week != CALENDAR_EMPTY_ARG ? $view->week : calendar_user_date('week');
$append = calendar_url_append($view);
if ($_GET['view']) {
$append .= '&view=' . $_GET['view'];
}
$calendar_links[] = array(
'title' => t('Year'),
'href' => $view->real_url . '/' . $view->year,
'query' => $append,
);
$calendar_links[] = array(
'title' => t('Month'),
'href' => $view->real_url . '/' . $view->year . '/' . $month,
'query' => $append,
);
if ($view->year > 1970) {
}
$calendar_links[] = array(
'title' => t('Day'),
'href' => $view->real_url . '/' . $view->year . '/' . $month . '/' . $day,
'query' => $append,
);
$output .= theme('calendar_links', $calendar_links, 'month');
}
$output .= '<div class="calendar-calendar">' . theme('calendar_nav_wrapper', calendar_nav($view, $mini), array()) . '</div>';
return $output;
}
function theme_calendar_nav_next($url, $text = TRUE, $querystring = NULL) {
return '<span class="next">' . l(($text ? t('next') : '') . ' »', $url, array(), !empty($querystring) ? $querystring : NULL) . '</span>';
}
function theme_calendar_nav_prev($url, $text = TRUE, $querystring = NULL) {
return '<span class="prev">' . l('« ' . ($text ? t('prev') : ''), $url, array(), !empty($querystring) ? $querystring : NULL) . '</span>';
}
function theme_calendar_nav_wrapper($array) {
return theme('table', $array, array());
}
function theme_calendar_links($links, $view) {
return theme('links', $links);
}
function theme_calendar_stripe_legend($stripe_labels) {
$header = array(
array(
'class' => 'legend',
'data' => t('Item'),
),
array(
'class' => 'legend',
'data' => t('Key'),
),
);
foreach ($stripe_labels as $stripe => $label) {
$node = new StdClass();
$node->stripe = $stripe;
$rows[] = array(
$label,
theme('calendar_stripe_stripe', $node),
array(
'class' => 'stripe',
),
);
}
$output = theme('table', $header, $rows, array(
'class' => 'mini',
));
return $output;
}
function theme_calendar_stripe_stripe($node) {
static $stripe, $stripe_map;
if (!$stripe_map[$node->stripe]) {
if ($stripe >= 10) {
$stripe = 1;
}
else {
$stripe++;
}
$stripe_map[$node->stripe] = $stripe;
}
$output .= '<div class="stripe-' . $stripe_map[$node->stripe] . '" title="Key: ' . $stripe_map[$node->stripe] . '"><span class="stripe">Key ' . $stripe_map[$node->stripe] . '</span></div>' . "\n";
return $output;
}
function theme_calendar_year($op, $header, $rows, $month_rows) {
$year = array_shift($month_rows);
$output = '<div class="calendar-calendar"><div class="year-view">';
$output .= $year;
$i = 0;
foreach ($month_rows as $month) {
$i++;
$row .= '<div class="mini">' . $month . '</div>';
if ($i == 3) {
$output .= '<div class="mini-row">' . $row . '</div>';
$row = '';
$i = 0;
}
}
$output .= "</div></div>\n";
return $output;
}
function theme_calendar_month($op, $header, $rows) {
$attrs = array();
if ($op == '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($op, $header, $rows) {
$output = theme("table", $header, $rows);
return '<div class="calendar-calendar"><div class="week-view">' . $output . "</div></div>\n";
}
function theme_calendar_day($op, $header, $rows) {
if (strstr($header[0]['data'], '<table')) {
$output = $header[0]['data'];
$header = array();
}
$output .= theme("table", $header, $rows);
return '<div class="calendar-calendar"><div class="day-view">' . $output . "</div></div>\n";
}
function theme_calendar_node_day($node) {
$output .= '<div class="calendar dayview">' . "\n";
$output .= theme('calendar_stripe_stripe', $node);
$output .= '<h2 class="title">' . l($node->title, "{$node->url}", array(
'title' => t('view this item'),
)) . '</h2>' . "\n";
$output .= '<div class="times">';
$output .= '<span class="start">' . $start_label . $node->start_format . '</span>' . "\n";
if ($node->calendar_start != $node->calendar_end && $node->calendar_end) {
$output .= '<span class="end"> - ' . $end_label . $node->end_format . '</span>' . "\n";
}
$output .= '</div>';
if ($node->teaser) {
$output .= '<div class="content">' . $node->teaser . "</div>\n";
}
$output .= "</div>\n";
return $output;
}
function theme_calendar_node_week($node) {
$output .= '<div class="calendar weekview">' . "\n";
$output .= theme('calendar_stripe_stripe', $node);
switch ($node->calendar_state) {
case 'singleday':
$times = '<span class="start">' . $node->start_time_format . '</span>' . "\n";
if ($node->calendar_start != $node->calendar_end && $node->calendar_end) {
$times .= '<span class="end"> - ' . $node->end_time_format . '</span>' . "\n";
}
break;
case 'start':
$times = '<span class="start">' . $start_label . $node->start_time_format . '</span>' . "\n";
break;
case 'end':
$times = '<span class="end">' . $end_label . $node->end_time_format . '</span>' . "\n";
break;
case 'ongoing':
$times = '<span class="ongoing">' . t('all day') . '</span>' . "\n";
break;
}
$output .= '<div class="title">' . l($node->title, "{$node->url}", array(
'title' => t('view this item'),
)) . '</div>' . "\n";
$output .= '<div class="times">' . $times . '</div>';
$output .= '</div>' . "\n";
return $output;
}
function theme_calendar_node_month($node) {
$output .= '<div class="calendar monthview">' . "\n";
$output .= theme('calendar_stripe_stripe', $node);
switch ($node->calendar_state) {
case 'singleday':
if ($node->start_time_format != $node->end_time_format) {
$times = '<span class="start">' . $node->start_time_format . '</span>' . "\n";
}
if ($node->calendar_start != $node->calendar_end && $node->calendar_end) {
$times .= '<span class="end"> - ' . $node->end_time_format . '</span>' . "\n";
}
else {
$times = '<span class="start">' . $node->start_time_format . '</span>' . "\n";
}
break;
case 'start':
$times = '<span class="start">' . $start_label . $node->start_time_format . '</span>' . "\n";
break;
case 'end':
$times = '<span class="end">' . $end_label . $node->end_time_format . '</span>' . "\n";
break;
case 'ongoing':
$times = '<span class="ongoing">' . t('all day') . '</span>' . "\n";
break;
}
$replace = array(
'-' => '- ',
':' => ': ',
';' => '; ',
'/' => '/ ',
',' => ', ',
'.' => '. ',
);
$output .= '<div class="title">' . l(strtr($node->title, $replace), $node->url, array(
'title' => t('view this item'),
)) . '</div>' . "\n";
$output .= '<div class="times">' . $times . '</div>';
$output .= $node->teaser;
$output .= '</div>' . "\n";
return $output;
}
function theme_calendar_date_box($year, $month, $day, $view, $mini = FALSE, $selected = FALSE, $url, $append = '') {
$url = $url ? $url . '/' . $year . '/' . $month . '/' . $day : 'calendar/' . $year . '/' . $month . '/' . $day;
if ($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>';
}
}
switch ($view) {
case 'table':
$output = '<div class="day">' . l(t('!month / !day', array(
'!month' => $month,
'!day' => $day,
)), $url, NULL, $append) . '</div>' . "\n";
break;
case 'list':
$output = '<div class="day">' . l(date_format_date('l, F j, Y', date_mktime(array(
'mon' => $month,
'mday' => $day,
'year' => $year,
))), $url, NULL, $append) . '</div>' . "\n";
break;
case 'day':
break;
default:
$output = '<div class="day">' . l($day, $url, NULL, $append) . '</div>' . "\n";
break;
}
return $output;
}
function theme_calendar_empty_day() {
return '<div class="calendar-empty"> </div>' . "\n";
}