From fa893eba3d1f04f96c54b360c46b5017a437694c Mon Sep 17 00:00:00 2001 From: Banana Date: Sat, 12 Nov 2022 13:05:36 +0100 Subject: [PATCH] search --- webroot/lib/entry.class.php | 2 +- webroot/view/list/list.html | 9 +++++++-- webroot/view/list/list.php | 17 +++++++++++++++-- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/webroot/lib/entry.class.php b/webroot/lib/entry.class.php index e6ce324..629a9e3 100644 --- a/webroot/lib/entry.class.php +++ b/webroot/lib/entry.class.php @@ -163,7 +163,7 @@ class Entry { * */ private function _words(string $data): array { - preg_match_all('/\w{3,}+/',$data,$matches); + preg_match_all('/\w{3,}+/u',$data,$matches); return array_unique($matches[0]); } } diff --git a/webroot/view/list/list.html b/webroot/view/list/list.html index 20e4436..fc06f15 100644 --- a/webroot/view/list/list.html +++ b/webroot/view/list/list.html @@ -1,3 +1,7 @@ +
+ + +

Home | New

@@ -17,5 +21,6 @@ +} else { ?> +

Nothing here.

+ diff --git a/webroot/view/list/list.php b/webroot/view/list/list.php index eee4c82..7ed9806 100644 --- a/webroot/view/list/list.php +++ b/webroot/view/list/list.php @@ -17,9 +17,16 @@ $TemplateData['entries'] = array(); -$queryStr = "SELECT `e`.`ident`, `e`.`date`, SUBSTRING(`e`.`body`,1,100) AS body FROM `".DB_PREFIX."_entry` AS e"; +$queryStr = "SELECT e.ident, e.date, e.words, SUBSTRING(e.body,1,100) AS body FROM `".DB_PREFIX."_entry` AS e"; $queryLimit = " LIMIT 100"; +$searchTerm = ''; +if(isset($_POST['submitForm']) && isset($_POST['searchInput'])) { + if(Summoner::validate($_POST['searchInput'])) { + $searchTerm = trim($_POST['searchInput']); + } +} + // why? // mysql knows the dates and validates them. There is no 2020-02-31 // the single date infos come from index.php @@ -51,10 +58,16 @@ if(!empty($_requestDateProvided)) { } if(!empty($_intervalStart) && !empty($_intervalEnd)) { - $queryStr .= " WHERE `date` >= '".$_intervalStart."' AND `date` <= '".$_intervalEnd."'"; + $queryStr .= " WHERE e.date >= '".$_intervalStart."' AND e.date <= '".$_intervalEnd."'"; + if(!empty($searchTerm)) { + $queryStr .= " AND MATCH(e.words) AGAINST('".$DB->real_escape_string($searchTerm)."' IN BOOLEAN MODE)"; + } } } else { $_requestDateProvided = 'Y'; + if(!empty($searchTerm)) { + $queryStr .= " WHERE MATCH(e.words) AGAINST('".$DB->real_escape_string($searchTerm)."' IN BOOLEAN MODE)"; + } } $queryStr .= " ORDER BY `created` DESC"; -- 2.39.5