diff --git a/app/class/Controllerrandom.php b/app/class/Controllerrandom.php index 6ac0921f..2b848fb2 100644 --- a/app/class/Controllerrandom.php +++ b/app/class/Controllerrandom.php @@ -18,14 +18,10 @@ public function direct() $pages = $this->pagemanager->pagelist(); $pages = $this->pagemanager->pagetable($pages, $this->optrandom); unset($pages[$origin->id()]); - if (!empty($pages)) { - $page = $pages[array_rand($pages)]; - - if (in_array($page->id(), $origin->linkto())) { - $this->routedirect('pageread', ['page' => $page->id()]); - } else { - $message = 'Wrong filters'; - } + $keys = array_intersect_key($pages, array_flip($origin->linkto())); + if (!empty($keys)) { + $page = $pages[array_rand($keys)]; + $this->routedirect('pageread', ['page' => $page->id()]); } else { $message = 'Empty set of page'; } diff --git a/app/class/Modelpage.php b/app/class/Modelpage.php index be75f268..c82ca563 100644 --- a/app/class/Modelpage.php +++ b/app/class/Modelpage.php @@ -496,7 +496,7 @@ public function renderpage(Page $page, AltoRouter $router): Page * @param string $regex Regex to match. * @param array $searchopt Option search, could be `content` `title` `description`. * - * @return Page[] associative array of `Page` objects * + * @return Page[] associative array of `Page` objects */ public function pagetable(array $pagelist, Opt $opt, $regex = '', $searchopt = []): array {