From 74517fc38f868849057e64ae67eb96de05aeedeb Mon Sep 17 00:00:00 2001 From: Nada Date: Mon, 3 Aug 2015 10:28:27 +0200 Subject: [PATCH 1/2] Adding dynamic patterns Some dynamic patters are now understandable by the plugin for the filter function, for example : filter=contrib:@NAME@ filter=mdate:@DATE@ There's also : @USER@ and @MAIL@ --- inc/pagequery.php | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/inc/pagequery.php b/inc/pagequery.php index 8b25b55..c00a487 100644 --- a/inc/pagequery.php +++ b/inc/pagequery.php @@ -10,6 +10,7 @@ class PageQuery { function __construct(Array $lang) { $this->lang = $lang; + $this->prepareReplacements(); } @@ -936,11 +937,16 @@ function filter_meta($sort_array, $filter) { foreach ($filter as $metakey => $expr) { // allow for exclusion matches (put ^ or ! in front of meta key) $exclude = false; + $match=array(); if ($metakey[0] == '^' || $metakey[0] == '!') { $exclude = true; $metakey = substr($metakey, 1); } $that = $this; + // replacements + if (preg_match('/^\@([A-Z]+)\@$/', $expr, $match )){ + $expr = $this->replace($match[0]); + } $sort_array = array_filter($sort_array, function($row) use ($metakey, $expr, $exclude, $that) { if ( ! isset($row[$metakey])) return false; if (strpos($metakey, 'date') !== false) { @@ -955,6 +961,16 @@ function filter_meta($sort_array, $filter) { return $sort_array; } + /** + * Apply replacement patterns and values as prepared earlier + * @param string $input The text to work on + * @return string processed text + */ + function replace($input) { + $input = preg_replace($this->patterns, $this->values, $input); + var_dump($input); + return $input; + } private function _filter_by_date($filter, $date) { $filter = str_replace('/', '.', $filter); // allow for Euro style date formats @@ -1200,5 +1216,23 @@ private function _add_heading(&$results, &$sort_array, &$group_opts, $level, $id } } } + + /** + * Same replacements as applied at template namespaces + */ + function prepareReplacements() { + /* @var Input $INPUT */ + global $INPUT; + global $USERINFO; + global $conf; + $this->patterns['__user__'] = '/@USER@/'; + $this->patterns['__name__'] = '/@NAME@/'; + $this->patterns['__mail__'] = '/@MAIL@/'; + $this->patterns['__date__'] = '/@DATE@/'; + $this->values['__user__'] = $INPUT->server->str('REMOTE_USER'); + $this->values['__name__'] = $USERINFO['name']; + $this->values['__mail__'] = $USERINFO['mail']; + $this->values['__date__'] = strftime('%d.%m.%Y'); + } } From 2231fceacf33e8dcecef83c96c8bde6613f20608 Mon Sep 17 00:00:00 2001 From: Nada Date: Mon, 3 Aug 2015 10:52:18 +0200 Subject: [PATCH 2/2] Deleting a var_dump --- inc/pagequery.php | 1 - 1 file changed, 1 deletion(-) diff --git a/inc/pagequery.php b/inc/pagequery.php index c00a487..6a35d00 100644 --- a/inc/pagequery.php +++ b/inc/pagequery.php @@ -968,7 +968,6 @@ function filter_meta($sort_array, $filter) { */ function replace($input) { $input = preg_replace($this->patterns, $this->values, $input); - var_dump($input); return $input; }