page_matches("post/list") && isset($_POST['search'])) { $trigger = $config->get_string("link_scan_trigger", "https?://"); if (preg_match("#.*{$trigger}.*#", $_POST['search'])) { $ids = $this->scan($_POST['search']); $page->set_mode(PageMode::REDIRECT); $page->set_redirect(search_link(["id=".implode(",", $ids)])); $event->stop_processing = true; } } } /** * @return int[] */ private function scan(string $text): array { $ids = []; $matches = []; preg_match_all("/post\/view\/(\d+)/", $text, $matches); foreach($matches[1] as $match) { $img = Image::by_id((int)$match); if ($img) { $ids[] = $img->id; } } preg_match_all("/\b([0-9a-fA-F]{32})\b/", $text, $matches); foreach($matches[1] as $match) { $img = Image::by_hash($match); if ($img) { $ids[] = $img->id; } } return array_unique($ids); } }