Skip to content

Commit 7f610bd

Browse files
committed
Add variable date filter based on strtotime
1 parent 5c37a46 commit 7f610bd

File tree

4 files changed

+14
-1
lines changed

4 files changed

+14
-1
lines changed

_test/SearchConfig.test.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function test_filtervars_simple()
3030

3131
$this->assertEquals('user baz', $searchConfig->applyFilterVars('$USER$ $PAGE$'));
3232
$this->assertEquals('$user', $searchConfig->applyFilterVars('$user'));
33-
33+
$this->assertEquals(date('Y-m-d'), $searchConfig->applyFilterVars('$DATE(now)$'));
3434
}
3535

3636
public function test_filtervars_struct()

lang/de/lang.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
$lang['Exception No data saved'] = 'Keine Daten gespeichert';
8181
$lang['Exception no sqlite'] = 'Das \'Struct Plugin\' benötigt das \'Sqlite Plugin\'. Bitte installieren und aktivieren.';
8282
$lang['Exception column not in table'] = 'Die Spalte %s existiert im Schema %s nicht.';
83+
$lang['Exception datefilter'] = 'Der Filter: \'<code>$Date(%s)$</code>\' enthält einen ungültigen Wert';
8384
$lang['Warning: no filters for cloud'] = 'Filter werden in \'Struct Clouds\' nicht unterstützt';
8485
$lang['sort'] = 'Nach dieser Spalte sortieren';
8586
$lang['next'] = 'Nächste Seite';

lang/en/lang.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@
8888
$lang['Exception No data saved'] = 'No data saved';
8989
$lang['Exception no sqlite'] = 'The struct plugin requires the sqlite plugin. Please install and enable it.';
9090
$lang['Exception column not in table'] = 'There is no column %s in schema %s.';
91+
$lang['Exception datefilter'] = 'The filter: \'<code>$Date(%s)$</code>\' contains an unsupported value.';
9192

9293
$lang['Warning: no filters for cloud'] = 'Filters are not supported for struct clouds.';
9394

meta/SearchConfig.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,17 @@ protected function applyFilterVars($filter)
140140
$filter = $this->applyFilterVarsUser($match);
141141
}
142142

143+
// apply date formula, given as strtotime
144+
if(preg_match('/^(.*?)(?:\$DATE\((.*?)\)\$?)(.*?)$/', $filter, $match)) {
145+
$toparse = $match[2];
146+
if ($toparse == '') $toparse = 'now';
147+
if (($timestamp = strtotime($toparse)) === false) {
148+
throw new StructException('datefilter',hsc($toparse));
149+
} else {
150+
$filter = str_replace($filter,date('Y-m-d',$timestamp),$filter);
151+
}
152+
}
153+
143154
return $filter;
144155
}
145156

0 commit comments

Comments
 (0)