diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/class/Controllerhome.php | 27 | ||||
-rw-r--r-- | app/class/Modelhome.php | 49 | ||||
-rw-r--r-- | app/class/Opt.php | 4 | ||||
-rw-r--r-- | app/view/templates/home.php | 15 |
4 files changed, 87 insertions, 8 deletions
diff --git a/app/class/Controllerhome.php b/app/class/Controllerhome.php index c7d1792..2fa06fb 100644 --- a/app/class/Controllerhome.php +++ b/app/class/Controllerhome.php @@ -22,7 +22,7 @@ class Controllerhome extends Controllerpage public function desktop() { - if ($this->user->isvisitor() && Config::homepage() === 'redirect' && Config::homeredirect() !== null) { + if ($this->user->isvisitor() && Config::homepage() === 'redirect' && !empty(Config::homeredirect())) { $this->routedirect('pageread/', ['page' => Config::homeredirect()]); } else { @@ -30,13 +30,30 @@ class Controllerhome extends Controllerpage $table = $this->modelhome->getlister(); $this->opt = $this->modelhome->optinit($table); - $colors = new Colors($this->opt->taglist()); + $vars['colors'] = new Colors($this->opt->taglist()); + if (!isset($_GET['search'])) { + $searchopt = ['title' => 1, 'description' => 1, 'content' => 1, 'other' => 0]; + } else { + $searchopt['title'] = $_GET['title'] ?? 0; + $searchopt['description'] = $_GET['description'] ?? 0; + $searchopt['content'] = $_GET['content'] ?? 0; + $searchopt['other'] = $_GET['other'] ?? 0; - $table2 = $this->modelhome->table2($table, $this->opt); + } + $regex = $_GET['search'] ?? ''; + + $vars['table2'] = $this->modelhome->table2($table, $this->opt, $regex , $searchopt); + + $vars['columns'] = $this->modelhome->setcolumns($this->user->columns()); - $columns = $this->modelhome->setcolumns($this->user->columns()); + $vars['faviconlist'] = $this->mediamanager->listfavicon(); + $vars['thumbnaillist'] = $this->mediamanager->listthumbnail(); + $vars['editorlist'] = $this->usermanager->getlisterbylevel(2, '>='); + $vars['user'] = $this->user; + $vars['opt'] = $this->opt; + $vars['deepsearch'] = $regex; + $vars['searchopt'] = $searchopt; - $vars = ['user' => $this->user, 'table2' => $table2, 'opt' => $this->opt, 'columns' => $columns, 'faviconlist' => $this->mediamanager->listfavicon(), 'thumbnaillist' => $this->mediamanager->listthumbnail(), 'editorlist' => $this->usermanager->getlisterbylevel(2, '>='), 'colors' => $colors]; $vars['footer'] = ['version' => getversion(), 'total' => count($table), 'database' => Config::pagetable()]; if (isset($_POST['query']) && $this->user->iseditor()) { 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 * diff --git a/app/class/Opt.php b/app/class/Opt.php index 7ffbd62..e920cb7 100644 --- a/app/class/Opt.php +++ b/app/class/Opt.php @@ -106,9 +106,9 @@ class Opt extends Item } /** - * Get the link list for each tags of an page + * Get the link list for each tags of a page * - * @param array $taglist List of tag to be + * @param array $taglist List of tag to be abalysed * @return string html code to be printed */ public function taglinks(array $taglist = []): string diff --git a/app/view/templates/home.php b/app/view/templates/home.php index e6db85a..404e96d 100644 --- a/app/view/templates/home.php +++ b/app/view/templates/home.php @@ -19,6 +19,21 @@ $this->insert('homemenu', ['user' => $user, 'opt' => $opt, 'optlist' => $optlist, 'pagelist' => $pagelist, 'faviconlist' => $faviconlist, 'thumbnaillist' => $thumbnaillist, 'editorlist' => $editorlist, 'colors' => $colors]); ?> + <div id="deepsearchbar" class="hidephone"> + <form action="<?= $this->url('home') ?>" method="get"> + <input type="text" name="search" value="<?= $deepsearch ?>" id="search" placeholder="deep search"> + <input type="checkbox" name="title" id="deeptitle" value="1" <?= $searchopt['title'] ? 'checked' : '' ?>> + <label for="deeptitle">title</label> + <input type="checkbox" name="description" id="deepdescription" value="1" <?= $searchopt['description'] ? 'checked' : '' ?>> + <label for="deepdescription">description</label> + <input type="checkbox" name="content" id="deepcontent" value="1" <?= $searchopt['content'] ? 'checked' : '' ?>> + <label for="deepcontent" title="Markdown content : MAIN, HEADER, NAV, ASIDE, FOOTER">content</label> + <input type="checkbox" name="other" id="deepother" value="1" <?= $searchopt['other'] ? 'checked' : '' ?>> + <label for="deepother" title="Structure content : BODY, CSS, Javascript">other</label> + <input type="submit" value="search"> + </form> + </div> + <main class="home"> |