Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions inc/pagequery.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class PageQuery {

function __construct(Array $lang) {
$this->lang = $lang;
$this->prepareReplacements();
}


Expand Down Expand Up @@ -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) {
Expand All @@ -955,6 +961,15 @@ 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);
return $input;
}

private function _filter_by_date($filter, $date) {
$filter = str_replace('/', '.', $filter); // allow for Euro style date formats
Expand Down Expand Up @@ -1200,5 +1215,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');
}

}