Commit abeee4ea authored by merlinofchaos's avatar merlinofchaos

Patch 70739 by eaton: Allow wildcard specifier on arguments. Plus: Bugfix to...

Patch 70739 by eaton: Allow wildcard specifier on arguments. Plus: Bugfix to titles in month argument and allow blocks to use substitutions.
parent f4deffcd
......@@ -476,7 +476,8 @@ function views_handler_arg_month($op, &$query, $argtype, $arg = '') {
case 'link':
return l(format_date($query->created, 'custom', 'F'), "$arg/$query->name");
case 'title':
return format_date(strtotime("2005${query}01"), 'custom', 'F', 0);
$month = str_pad($query, 2, '0', STR_PAD_LEFT);
return format_date(strtotime("2005{$month}01"), 'custom', 'F', 0);
}
}
function views_handler_arg_week($op, &$query, $argtype, $arg = '') {
......
......@@ -160,7 +160,7 @@ function taxonomy_views_default_views() {
$view->access = array (
);
$view->page = TRUE;
$view->page_title = '%1';
$view->page_title = t('taxonomy');
$view->page_header = '';
$view->page_header_format = '1';
$view->page_type = 'teaser';
......@@ -185,7 +185,7 @@ function taxonomy_views_default_views() {
array (
'type' => 'taxid',
'argdefault' => '1',
'title' => '',
'title' => '%1',
'options' => '0',
),
array (
......
......@@ -97,10 +97,10 @@ function user_views_default_views() {
$view = new stdClass();
$view->name = 'tracker';
$view->requires = array('node_comment_statistics');
$view->description = 'Shows all new activity on system.';
$view->description = t('Shows all new activity on system.');
$view->page = true;
$view->url = 'tracker';
$view->page_title = 'recent posts for %1';
$view->page_title = t('recent posts');
$view->page_type = 'table';
$view->use_pager = true;
$view->nodes_per_page = '25';
......@@ -149,7 +149,7 @@ function user_views_default_views() {
array (
'type' => 'uid',
'argdefault' => '2',
'title' => 'recent posts for all users',
'title' => t('recent posts for %1'),
),
);
$view->filter = array (
......
......@@ -73,6 +73,8 @@
title varchar(255),
options varchar(255),
position int(2),
wildcard varchar(32),
wildcard_substitution varchar(32),
KEY (vid)
) TYPE=MyISAM /*!40100 DEFAULT CHARACTER SET utf8 */;");
......@@ -182,6 +184,8 @@
title varchar(255),
options varchar(255),
position smallint
wildcard varchar(32),
wildcard_substitution varchar(32),
)");
db_query("CREATE INDEX {view_argument}_vid_idx ON {view_argument} (vid)");
......@@ -326,3 +330,10 @@ function views_update_8() {
$ret[] = update_sql("ALTER TABLE {view_view} MODIFY nodes_per_page int(5)");
return $ret;
}
function views_update_9() {
$ret = array();
db_add_column($ret, 'view_argument', 'wildcard', 'varchar(32)');
db_add_column($ret, 'view_argument', 'wildcard_substitution', 'varchar(32)');
return $ret;
}
\ No newline at end of file
......@@ -585,7 +585,7 @@ function views_view_block($vid) {
* on, in case for some reason a particular section of view is needed,
* without paging on.
*/
function views_build_view($type, $view, $args = array(), $use_pager = false, $limit = 0, $page = 0) {
function views_build_view($type, &$view, $args = array(), $use_pager = false, $limit = 0, $page = 0) {
// Fix a number of annoying whines when NULL is passed in..
if ($args == NULL) {
$args = array();
......@@ -597,7 +597,10 @@ function views_build_view($type, $view, $args = array(), $use_pager = false, $li
if ($view->view_args_php) {
ob_start();
$args = eval($view->view_args_php);
$result = eval($view->view_args_php);
if (is_array($result)) {
$args = $result;
}
ob_end_clean();
}
......@@ -783,17 +786,13 @@ function views_get_title($view, $context = 'menu', $args = NULL) {
if ($context == 'menu' && $view->menu_title)
return $view->menu_title;
if ($context == 'block' && $view->block_title) {
return $view->block_title;
}
if ($context == 'block-info') {
return $view->description ? $view->description : $view->name;
}
if ($args === NULL)
if ($args === NULL) {
$args = $view->args;
}
// Grab the title from the highest argument we got. If there is no such
// title, track back until we find a title.
......@@ -811,7 +810,12 @@ function views_get_title($view, $context = 'menu', $args = NULL) {
}
if (!$title) {
$title = $view->page_title;
if ($context == 'block' && $view->block_title) {
$title = $view->block_title;
}
else {
$title = $view->page_title;
}
}
if (!$view->argument) {
......@@ -824,11 +828,13 @@ function views_get_title($view, $context = 'menu', $args = NULL) {
break;
}
$argtype = $arg['type'];
if (function_exists($arginfo[$argtype]['handler'])) {
if ($arg['wildcard'] == $args[$i] && $arg['wildcard_substitution'] != '') {
$title = str_replace("%" . ($i + 1), $arg['wildcard_substitution'], $title);
}
else if (function_exists($arginfo[$argtype]['handler'])) {
// call the handler
$rep = $arginfo[$argtype]['handler']('title', $args[$i], $argtype);
$title = str_replace("%" . ($i + 1), $rep, $title);
}
}
return $title;
......@@ -1050,7 +1056,7 @@ function _views_save_view($view) {
}
foreach ($view->argument as $i => $arg) {
db_query("INSERT INTO {view_argument} (vid, type, argdefault, title, options, position) VALUES (%d, '%s', %d, '%s', '%s', %d)", $view->vid, $arg['type'], $arg['argdefault'], $arg['title'], $arg['options'], $i);
db_query("INSERT INTO {view_argument} (vid, type, argdefault, title, options, position, wildcard, wildcard_substitution) VALUES (%d, '%s', %d, '%s', '%s', %d, '%s', '%s')", $view->vid, $arg['type'], $arg['argdefault'], $arg['title'], $arg['options'], $i, $arg['wildcard'], $arg['wildcard_substitution']);
}
foreach ($view->field as $i => $arg) {
......
......@@ -160,7 +160,7 @@ function _views_view_build_arg(&$query, $arg, $argdata) {
}
// call the handler, unless the arg is the 'wildcard'.
if ($arg != '*') {
if ($arg != $argdata['wildcard']) {
$arginfo[$argdata['type']]['handler']('filter', $query, $argdata, $arg);
}
}
......
......@@ -1257,7 +1257,18 @@ function views_ui_add_argument(&$form, $argument, &$order, $key, $i) {
$widget['#default_value'] = $argument['options'];
$form['options'] = $widget;
}
$form['wildcard'] = array(
'#type' => 'textfield',
'#default_value' => $argument['wildcard'],
'#size' => 5,
'#maxlength' => 32,
);
$form['wildcard_substitution'] = array(
'#type' => 'textfield',
'#default_value' => $argument['wildcard_substitution'],
'#size' => 5,
'#maxlength' => 32,
);
if (isset($arginfo['help'])) {
$form['help'] = array(
'#type' => 'markup',
......@@ -1499,7 +1510,7 @@ function theme_views_edit_view($form) {
// arguments
$collapsed = $allbut && $allbut != 'argument';
$group = views_ui_render_section($form['argument'], array('name', 'argdefault', 'title', 'options'), array(t('Argument Type'), t('Default'), t('Title'), t('Option')), 'arguments', $collapsed);
$group = views_ui_render_section($form['argument'], array('name', 'argdefault', 'title', 'options', 'wildcard', 'wildcard_substitution'), array(t('Argument Type'), t('Default'), t('Title'), t('Option'), t('Wildcard'), t('Wildcard Sub')), 'arguments', $collapsed);
$group .= views_ui_render_section_add($form['argument']['add'], array('id', 'button'), 'Add Argument');
......@@ -1826,6 +1837,8 @@ function views_create_view_code($vid) {
$output .= " 'argdefault' => '$argument[argdefault]',\n";
$output .= " 'title' => '$argument[title]',\n";
$output .= " 'options' => '$argument[options]',\n";
$output .= " 'wildcard' => '$argument[wildcard]',\n";
$output .= " 'wildcard_substitution' => '$argument[wildcard_substitution]',\n";
$output .= " ),\n";
}
$output .= " );\n";
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment