calendar_type = 'month'; } // 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 (!empty($formats['week']) && $view->build_type != 'block' && $view->calendar_type == 'month') { $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("table", calendar_nav($view), array()); $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("table", calendar_nav($view), array()); $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("table", calendar_nav($view), array()); $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) { switch ($view->build_type) { case 'page': if ($view->calendar_type == 'year') { return $view->year; } else { return views_get_title($view, $context = 'page', $args = $view->real_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) { $view = $GLOBALS['current_view']; $value = intval(check_plain($value)); if (empty($value)) { if ($view->month) { return date_format_date($view->min_date, 'custom', 'F Y'); } elseif ($view->year) { return $view->year; } } else { switch ($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'))); } } } /** * 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) { if ($type == 'year') { return $view->year; } if ($view->mini) { // Month navigation titles are used as links in the mini view. return l(date_format_date($view->min_date, 'custom', 'M Y'), $view->url .'/'. $view->year .'/'. $view->month, array(), calendar_url_append($view)); } else { // Otherwise, just show the date. switch ($view->calendar_type) { 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'))); default: return date_format_date($view->min_date, 'custom', 'M Y'); } } } /** * 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 the 'next' navigation controls for calendar calendars * * @param link * The url for the navigation */ function theme_calendar_nav_next($url, $text = TRUE, $querystring = NULL) { return ''. l(($text ? t('next') : '') .' »', $url, array(), (!empty($querystring) ? $querystring : NULL)) .''; } /** * Format the 'previous' navigation controls for calendar calendars * * @param link * The url for the navigation */ function theme_calendar_nav_prev($url, $text = TRUE, $querystring = NULL) { return ''. l('« '. ($text ? t('prev') : ''), $url, array(), (!empty($querystring) ? $querystring : NULL)) .''; } /** * Format a node stripe legend */ 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; } /** * Format node stripes * Add key value to text, then hide it with css for accessibility to screen readers */ 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 .= '
Key '.$stripe_map[$node->stripe] .'
'."\n"; return $output; } /** * 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 '
'. $output ."
\n"; } /** * Format a week view */ function theme_calendar_week($view, $header, $rows) { $output = theme("table", $header, $rows); return '
'. $output ."
\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 '
'. $output ."
\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 have to do our own display of the date because we altered the * value to the local timezone, and the built-in formatters assume * they're operating on a UTC date. Plus 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 = date_format_date($node->calendar_start_date, 'custom', $format); $date2 = date_format_date($node->calendar_end_date, 'custom', $format); // 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 */