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);
// 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['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);
}
if (empty($items)) {
return $view->page_empty . $out;
}
else {
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 = 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;
}
}
/**
* 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 embedded calendars or the mini calendar in a block, treat the url as a
// querystring to avoid actually changing the page
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 = '';
$output .= '
';
$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 .= '
'. $heading .'
';
$output .= '
';
$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 .= '
';
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':
$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;
}
// Month navigation titles are used as links in the mini view.
if ($view->mini || $link) {
// We don't want to pass along the block_identifier, so we set it to NULL.
$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;
}
}
/**
* 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->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);
// For "page" views, add the arguments to the path.
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);
}
}
// For "embed" views, add the arguments to the 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 this is a page, add a popup date selector.
if ($view->build_type == 'page' && variable_get('calendar_popup_'. $view->name, 0)) {
$output = ''. calendar_date_select($view) .'
';
}
$output .= theme('links', $calendar_links);
return $output;
}
}
/**
* Format a node stripe legend
*/
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, '
');
}
$output = theme('table', $header, $rows, array('class' => 'mini calendar-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;
}
$GLOBALS['calendar_stripes'][$node->stripe_label] = $node->stripe;
return '
'."\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 = '
';
$row[] = array(
'data' => $month_header . theme('calendar_month', $view, $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'));
$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 calendar day with multiple nodes
* for display in an expanded month calendar, like a calendar page
*
* @param $curday_date
* date_format object
*
* @param $count
* number of events on that day
*
* @param $view
* The view object
*/
function theme_calendar_multiple_node_month($curday_date, $count, $view, $types) {
// get the year month and date
$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);
// create the link to the day
$link = $view->real_url .'/'. date_pad($year, 4) .'/'. date_pad($month) .'/'. date_pad($day);
// mak sure the divs match the theme_calendar_node_month
$output .= ''."\n";
if ($view->style_max_items_behavior != 'more') {
foreach ($types as $type) {
$output .= theme('calendar_stripe_stripe', $type);
}
$item = "
". l(t('Click to see all @count events', array('@count' => $count)), $link) ."
";
}
elseif ($count > 0) {
$item = '
'. l(t('more»'), $link) .'
';
}
$output .= "
name) ."'>$item
\n";
$output .= "
\n";
return $output;
}
/**
* Format an calendar day with multiple nodes
* for display in an expanded week calendar, like a calendar page
*
* @param $curday_date
* date_format object
*
* @param $count
* number of events on that day
*
* @param $view
* The view object
*/
function theme_calendar_multiple_node_week($curday_date, $count, $view, $types) {
// get the year month and date
$parts = explode('-', substr($curday_date, 0, 10));
$year = $parts[0];
$month = intval($parts[1]);
$day = intval($parts[2]);
// create the link to the day
$link = $view->real_url .'/'. date_pad($year, 4) .'/'. date_pad($month) .'/'. date_pad($day);
// make sure the divs line up with theme_calendar_node_week
$output .= ''."\n";
if ($view->style_max_items_behavior != 'more') {
foreach ($types as $type) {
$output .= theme('calendar_stripe_stripe', $type);
}
$item = "
". l(t('Click to see all @count events', array('@count' => $count)), $link) ."
";
}
else {
$item = '
'. l(t('more»'), $link) .'
';
}
$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]);
$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 ''. 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.
*
* Override the calendar's custom formating for calendar fields.
* This one we trim the node title to 12 chars so that it's formatted nicer.
*
*/
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;
}
/**
* 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($field, $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', $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);
// 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 */