From 10d6884ab3d60b009a083a665289e4deaccc518c Mon Sep 17 00:00:00 2001 From: Michael Save Date: Sun, 12 Feb 2012 22:45:48 +1100 Subject: [PATCH] experimental "filters" in mod ?/search --- mod.php | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/mod.php b/mod.php index 065d3d3c..5f8991bf 100644 --- a/mod.php +++ b/mod.php @@ -990,7 +990,7 @@ $body = '

Search

' . '

' . '' . '' . '

' . @@ -1001,6 +1001,25 @@ $phrase = &$_POST['search']; $_body = ''; + $filters = Array(); + + function search_filters($m) { + global $filters; + $name = $m[2]; + $value = isset($m[4]) ? $m[4] : $m[3]; + + if(!in_array($name, Array('id', 'thread', 'subject', 'email', 'name', 'trip', 'capcode', 'filename', 'filehash', 'ip'))) { + // unknown filter + return $m[0]; + } + + $filters[$name] = $value; + + return $m[1]; + } + + $phrase = trim(preg_replace_callback('/(^|\s)(\w+):("(.*)?"|[^\s]*)/', 'search_filters', $phrase)); + // Escape escape character $phrase = str_replace('!', '!!', $phrase); @@ -1036,8 +1055,14 @@ $like .= '`body` LIKE ' . $phrase . ' ESCAPE \'!\''; } + foreach($filters as $name => $value) { + $like .= ' AND `' . $name . '` = '. $pdo->quote($value); + } + $like = str_replace('%', '%%', $like); + // die(var_dump($like)); + $boards = listBoards(); foreach($boards as &$_b) { openBoard($_b['uri']);