Skip to content

Commit c1bfd81

Browse files
committed
Merge remote-tracking branch 'saggi-dw/date-filter'
2 parents 0342c2f + 888559e commit c1bfd81

File tree

4 files changed

+15
-1
lines changed

4 files changed

+15
-1
lines changed

_test/SearchConfigTest.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
@@ -89,6 +89,7 @@
8989
$lang['Exception No data saved'] = 'No data saved';
9090
$lang['Exception no sqlite'] = 'The struct plugin requires the sqlite plugin. Please install and enable it.';
9191
$lang['Exception column not in table'] = 'There is no column %s in schema %s.';
92+
$lang['Exception datefilter'] = 'The filter: \'<code>$Date(%s)$</code>\' contains an unsupported value.';
9293

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

meta/SearchConfig.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,22 @@ protected function applyFilterVars($filter)
137137
);
138138

139139
// apply struct column placeholder (we support only one!)
140+
// or apply date formula, given as strtotime
140141
if (preg_match('/^(.*?)(?:\$STRUCT\.(.*?)\$)(.*?)$/', $filter, $match)) {
141142
$filter = $this->applyFilterVarsStruct($match);
142143
} elseif (preg_match('/^(.*?)(?:\$USER\.(.*?)\$)(.*?)$/', $filter, $match)) {
143144
$filter = $this->applyFilterVarsUser($match);
145+
} elseif (preg_match('/^(.*?)(?:\$DATE\((.*?)\)\$?)(.*?)$/', $filter, $match)) {
146+
$toparse = $match[2];
147+
if ($toparse == '') {
148+
$toparse = 'now';
149+
}
150+
$timestamp = strtotime($toparse);
151+
if ($timestamp === false) {
152+
throw new StructException('datefilter', hsc($toparse));
153+
} else {
154+
$filter = str_replace($filter, date('Y-m-d', $timestamp), $filter);
155+
}
144156
}
145157

146158
return $filter;

0 commit comments

Comments
 (0)