View source
<?php
function date_views_theme() {
$path = drupal_get_path('module', 'date_views');
$base = array(
'file' => 'theme.inc',
'path' => "{$path}/theme",
);
return array(
'date_nav_title' => $base + array(
'variables' => array(
'granularity' => NULL,
'view' => NULL,
'link' => NULL,
'format' => NULL,
),
),
'date_vcalendar' => $base + array(
'variables' => array(
'events' => NULL,
'calname' => NULL,
),
),
'date_vevent' => $base + array(
'variables' => array(
'event' => NULL,
),
),
'date_valarm' => $base + array(
'variables' => array(
'alarm' => NULL,
),
),
'date_views_filter_form' => $base + array(
'template' => 'date-views-filter-form',
'render element' => 'form',
),
'date_calendar_day' => $base + array(
'variables' => array(
'date' => NULL,
),
),
);
}
function date_views_views_api() {
return array(
'api' => 3,
'path' => drupal_get_path('module', 'date_views') . '/includes',
);
}
function date_views_views_fetch_fields($base, $type) {
if (!module_exists('views')) {
return array();
}
module_load_include('inc', 'views', 'includes/admin');
return views_fetch_fields($base, $type);
}
function date_views_date_views_tables() {
return array(
'node',
'comments',
'users',
'files',
);
}
function date_views_date_views_fields($field) {
$values = array(
'sql_type' => DATE_UNIX,
'tz_handling' => 'site',
'timezone_field' => '',
'offset_field' => '',
'related_fields' => array(),
'granularity' => array(
'year',
'month',
'day',
'hour',
'minute',
'second',
),
);
switch ($field) {
case 'users.created':
case 'users.access':
case 'users.login':
case 'node.created':
case 'node.changed':
case 'node_revisions.timestamp':
case 'files.timestamp':
case 'node_counter.timestamp':
case 'accesslog.timestamp':
case 'comments.timestamp':
case 'node_comment_statistics.last_comment_timestamp':
return $values;
}
}
function date_api_views_clear() {
if (db_table_exists('cache_content')) {
db_query('DELETE FROM {cache_content}');
}
if (db_table_exists('cache_views')) {
db_query('DELETE FROM {cache_views}');
}
if (db_table_exists('views_object_cache')) {
db_query('DELETE FROM {views_object_cache}');
}
db_query("DELETE FROM {cache} where cid LIKE 'theme_registry%'");
}
function date_real_url($view, $date_type = NULL, $date_arg = NULL, $force_view_url = FALSE) {
$args = $view->args;
$pos = $view->date_info->date_arg_pos;
ksort($args);
if (count($args) < $pos) {
foreach ($view->argument as $name => $argument) {
if ($argument->position == $pos) {
break;
}
$args[] = $argument->options['wildcard'];
}
}
if (!empty($date_type)) {
switch ($date_type) {
case 'year':
$args[$pos] = date_pad($view->date_info->year, 4);
break;
case 'week':
$args[$pos] = date_pad($view->date_info->year, 4) . '-W' . date_pad($view->date_info->week);
break;
case 'day':
$args[$pos] = date_pad($view->date_info->year, 4) . '-' . date_pad($view->date_info->month) . '-' . date_pad($view->date_info->day);
break;
default:
$args[$pos] = date_pad($view->date_info->year, 4) . '-' . date_pad($view->date_info->month);
break;
}
}
elseif (!empty($date_arg)) {
$args[$pos] = $date_arg;
}
else {
$args = $view->args;
}
if (!$force_view_url && (!empty($view->preview) || !empty($view->date_info->block_identifier))) {
$url = $view
->get_url($args);
$key = date_block_identifier($view);
if (!empty($key)) {
return url($_GET['q'], array(
'query' => drupal_get_query_parameters(NULL, array(
$key => $url,
)),
'absolute' => TRUE,
));
}
}
return url($view
->get_url($args), array(
'query' => drupal_get_query_parameters(),
'absolute' => TRUE,
));
}
function date_block_identifier($view) {
if (!empty($view->block_identifier)) {
return $view->block_identifier;
}
return isset($view->date_info->block_identifier) ? $view->date_info->block_identifier : NULL;
}
function date_handler_fields($view) {
$field_names = array();
if (empty($view->date_info->date_fields)) {
$view->date_info->date_fields = array();
}
foreach ($view->field as $field) {
if ($field->definition['handler'] == 'date_handler_field_multiple') {
$name = $field->field;
$group = $field->options['multiple'];
if (substr($name, -7) == '_value2') {
$field_name = substr($name, 0, strlen($name) - 7);
}
elseif (substr($name, -6) == '_value') {
$field_name = substr($name, 0, strlen($name) - 6);
}
else {
$field_name = '';
$group = array();
continue;
}
foreach ($view->date_info->date_fields as $date_field) {
if (strstr($date_field, ' . ' . $field_name)) {
$delta_field = 'entity_data_' . $field_name . '_delta';
$field_names[$field_name] = array(
'options' => $group,
'delta_field' => $delta_field,
'view_field' => clone $field,
);
unset($field_names[$field_name]['view_field']->view);
}
}
}
}
return $field_names;
}
function date_field_views_data_alter(&$result, $field, $module) {
if ($module == 'date') {
foreach ($result as $table => $data) {
$additional = array();
$field_name = $field['field_name'];
$key = array_key_exists('entity_id', $data) ? $field_name : $field_name . '-revision_id';
$field_name_data = $data[$key]['field'];
foreach ($data as $column => $value) {
if (array_key_exists('argument', $value)) {
$result[$table][$column]['argument']['handler'] = 'date_views_argument_handler';
}
if (array_key_exists('filter', $value)) {
$result[$table][$column]['filter']['handler'] = 'date_views_filter_handler';
}
if (array_key_exists('field', $value) && !array_key_exists('moved to', $value['field'])) {
$result[$table][$column]['field']['add fields to query'] = TRUE;
}
}
}
}
}