function template_preprocess_calendar_main in Calendar 7
Same name in this branch
- 7 theme/theme.inc \template_preprocess_calendar_main()
- 7 calendar_multiday/theme/theme.inc \template_preprocess_calendar_main()
Same name and namespace in other branches
- 6.2 theme/theme.inc \template_preprocess_calendar_main()
- 6.2 calendar_multiday/theme/theme.inc \template_preprocess_calendar_main()
- 7.2 theme/theme.inc \template_preprocess_calendar_main()
- 7.2 calendar_multiday/theme/theme.inc \template_preprocess_calendar_main()
Display a calendar navigation and links
File
- theme/
theme.inc, line 11 - Theme functions for the Calendar module.
Code
function template_preprocess_calendar_main(&$vars) {
module_load_include('inc', 'calendar', 'includes/calendar');
$view = $vars['view'];
$result = (array) $view->result;
$options = $view->style_plugin->options;
$handler = $view->style_plugin;
$vars['display_type'] = $view->date_info->granularity;
$vars['min_date_formatted'] = !empty($view->date_info->min_date) ? date_format($view->date_info->min_date, DATE_FORMAT_DATETIME) : '';
$vars['max_date_formatted'] = !empty($view->date_info->end_date) ? date_format($view->date_info->max_date, DATE_FORMAT_DATETIME) : '';
$view->date_info->mini = isset($view->date_info->mini) ? $view->date_info->mini : $view->date_info->granularity == 'year';
// Create the links to other displays.
$url = $view
->get_url();
$view->date_info->url = $url;
$arg = $view->date_info->date_arg;
$displays = $view->date_info->display_types;
// Set up the links to other calendar views.
$current_date = $view->date_info->min_date;
if (!empty($date->info->day)) {
$current_date = new DateObject($date_info->date_arg . ' 00:00:00');
}
elseif (!empty($view->date_info->week)) {
$week = date_week_range($view->date_info->week, $view->date_info->year);
$current_date = $week[0];
}
elseif (!empty($view->date_info->month)) {
$current_date = new DateObject($view->date_info->year . '-' . date_pad($view->date_info->month) . '-01 00:00:00');
}
else {
$current_date = new DateObject($view->date_info->year . '-01-01 00:00:00');
}
if (empty($view->date_info->month) || $view->date_info->month == $view->argument['date_argument']->options['wildcard']) {
$view->date_info->month = date_format($current_date, 'm');
}
if (empty($view->date_info->day) || $view->date_info->day == $view->argument['date_argument']->options['wildcard']) {
$view->date_info->day = date_format($current_date, 'd');
}
if (empty($view->date_info->week) || $view->date_info->week == $view->argument['date_argument']->options['wildcard']) {
$view->date_info->week = date_week($view->date_info->year . '-' . date_pad($view->date_info->month) . '-' . date_pad($view->date_info->day));
}
$calendar_links = array();
$base = array(
'attributes' => array(
'rel' => 'nofollow',
),
);
if (!empty($displays['year'])) {
$calendar_links['calendar calendar-year'] = $base + array(
'title' => t('Year', array(), array(
'context' => 'datetime',
)),
'href' => date_real_url($view, 'year'),
);
}
if (!empty($displays['month'])) {
$calendar_links['calendar calendar-month'] = $base + array(
'title' => t('Month', array(), array(
'context' => 'datetime',
)),
'href' => date_real_url($view, 'month'),
);
}
if (!empty($displays['week'])) {
$calendar_links['calendar calendar-week'] = $base + array(
'title' => t('Week', array(), array(
'context' => 'datetime',
)),
'href' => date_real_url($view, 'week'),
);
}
if (!empty($displays['day'])) {
$calendar_links['calendar calendar-day'] = $base + array(
'title' => t('Day', array(), array(
'context' => 'datetime',
)),
'href' => date_real_url($view, 'day'),
);
}
$vars['calendar_links'] = $calendar_links;
// If the Date Popup module is enabled, add a popup date selector.
if (!empty($view->date_info->calendar_popup)) {
$vars['calendar_popup'] = '<div class="clear-block">' . calendar_date_select($view) . '</div>';
}
// If an 'Add new ... link is provided, add it here.
// the query will bring the user back here after adding the node.
if (!empty($view->date_info->calendar_date_link) && (user_access("administer nodes") || user_access('create ' . $view->date_info->calendar_date_link . ' content'))) {
$name = node_type_get_name($view->date_info->calendar_date_link);
$href = 'node/add/' . str_replace('_', '-', $view->date_info->calendar_date_link);
$query = drupal_get_query_parameters(array(
'destination' => $view->date_info->url,
));
$vars['calendar_links']['calendar calendar-add'] = $base + array(
'title' => t('Add+'),
'href' => $href,
'query' => $query,
);
}
$vars['view'] = $view;
$vars['mini'] = !empty($view->date_info->mini);
$vars['block'] = !empty($view->date_info->block);
$vars['block_identifier'] = date_block_identifier($view);
}