diff options
author | vincent-peugnet <v.peugnet@free.fr> | 2020-02-10 10:59:49 +0100 |
---|---|---|
committer | vincent-peugnet <v.peugnet@free.fr> | 2020-02-10 10:59:49 +0100 |
commit | cb6f0e8c3f2abe2bf895320a58a466c7a766dbf9 (patch) | |
tree | cff62e97ab013cc39a181587c69c0f4a37aeabb4 /app/class/Modelhome.php | |
parent | c0a2817accea23837ab85b8ba31aabc7fbb20fc3 (diff) | |
download | wcms-cb6f0e8c3f2abe2bf895320a58a466c7a766dbf9.tar.gz wcms-cb6f0e8c3f2abe2bf895320a58a466c7a766dbf9.zip |
deep search bar close #53
Diffstat (limited to 'app/class/Modelhome.php')
-rw-r--r-- | app/class/Modelhome.php | 49 |
1 files changed, 48 insertions, 1 deletions
diff --git a/app/class/Modelhome.php b/app/class/Modelhome.php index 701eb73..541eb07 100644 --- a/app/class/Modelhome.php +++ b/app/class/Modelhome.php @@ -43,8 +43,9 @@ class Modelhome extends Modelpage /** * @param array $table * @param Opt $opt + * @param string $regex */ - public function table2($table, $opt) + public function table2(array $table, Opt $opt, string $regex, array $searchopt) { @@ -69,6 +70,10 @@ class Modelhome extends Modelpage $table2 = $table2invert; } + if(!empty($regex)) { + $table2 = $this->deepsearch($regex, $searchopt, $table2); + } + $this->pagelistsort($table2, $opt->sortby(), $opt->order()); if($opt->limit() !== 0) { @@ -79,6 +84,48 @@ class Modelhome extends Modelpage return $table2; } + + /** + * Search for regex and count occurences + * + * @param string $regex Regex to match. + * @param array $options Option search, could be `content` `title` `description`. + * @param array $page list Array of Pages. + * + * @return array associative array of Pages + */ + public function deepsearch(string $regex, array $options, array $pagelist) : array + { + $regex = '/' . $regex . '/'; + $pageselected = []; + foreach ($pagelist as $page) { + $count = 0; + if($options['content']) { + $count += preg_match($regex, $page->main()); + $count += preg_match($regex, $page->nav()); + $count += preg_match($regex, $page->aside()); + $count += preg_match($regex, $page->header()); + $count += preg_match($regex, $page->footer()); + } + if ($options['other']) { + $count += preg_match($regex, $page->body()); + $count += preg_match($regex, $page->css()); + $count += preg_match($regex, $page->javascript()); + } + if ($options['title']) { + $count += preg_match($regex, $page->title()); + } + if ($options['description']) { + $count += preg_match($regex, $page->description()); + } + if ($count !== 0) { + $pageselected[] = $page; + } + } + return $pageselected; + } + + /** * @param array array of the columns to show from the user * |