View source
<?php
class views_handler_argument_date extends views_handler_argument_formula {
var $option_name = 'default_argument_date';
var $arg_format = 'Y-m-d';
function default_argument_form(&$form, &$form_state) {
parent::default_argument_form($form, $form_state);
$form['default_argument_type']['#options'] += array(
'date' => t('Current date'),
);
$form['default_argument_type']['#options'] += array(
'node_created' => t("Current node's creation time"),
);
$form['default_argument_type']['#options'] += array(
'node_changed' => t("Current node's update time"),
);
}
function get_default_argument($raw = FALSE) {
if (!$raw && $this->options['default_argument_type'] == 'date') {
return date($this->arg_format, time());
}
else {
if (!$raw && in_array($this->options['default_argument_type'], array(
'node_created',
'node_changed',
))) {
foreach (range(1, 3) as $i) {
$node = menu_get_object('node', $i);
if (!empty($node)) {
continue;
}
}
if (arg(0) == 'node' && is_numeric(arg(1))) {
$node = node_load(arg(1));
}
if (empty($node)) {
return parent::get_default_argument();
}
else {
if ($this->options['default_argument_type'] == 'node_created') {
return date($this->arg_format, $node->created);
}
else {
if ($this->options['default_argument_type'] == 'node_changed') {
return date($this->arg_format, $node->changed);
}
}
}
}
}
return parent::get_default_argument($raw);
}
function export_plugin($indent, $prefix, $storage, $option, $definition, $parents) {
if ($option == 'default_argument_type') {
$type = 'argument default';
$option_name = 'default_argument_options';
$plugin = $this
->get_plugin($type);
$name = $this->options[$option];
if (in_array($name, array(
'date',
'node_created',
'node_changed',
))) {
$output = $indent . $prefix . "['{$option}'] = '{$name}';\n";
return $output;
}
}
return parent::export_plugin($indent, $prefix, $storage, $option, $definition, $parents);
}
}