From 6c7b845b34d8b4d55175c7db02fa71cf62789ab6 Mon Sep 17 00:00:00 2001 From: Dries Buytaert Date: Sat, 22 Sep 2001 21:01:39 +0000 Subject: [PATCH] - improved search module (vaguely derived from axel's code) --- modules/search.module | 63 +++++++++++++++++++++++++++++------- modules/search/search.module | 63 +++++++++++++++++++++++++++++------- 2 files changed, 104 insertions(+), 22 deletions(-) diff --git a/modules/search.module b/modules/search.module index bb74db3c2e1..86049d67d45 100644 --- a/modules/search.module +++ b/modules/search.module @@ -12,29 +12,65 @@ function search_link($type) { return $links ? $links : array(); } +function search_item($item, $type) { + $output .= "

"; + $output .= " ". $item["title"] ."
"; + $output .= " $type ". ($item["user"] ? " - ". $item["user"] : "") ."". ($item["date"] ? " - ". format_date($item["date"], "small") : "") .""; + $output .= "

"; + + return $output; +} + function search_page() { - global $theme, $type, $keys, $REQUEST_URI; + global $theme, $edit, $type, $keys, $REQUEST_URI; if (user_access("search content")) { - // verify input: + + /* + ** Verify the user input: + */ + $type = check_input($type); $keys = check_input($keys); - // build options list: + + /* + ** Construct the search form: + */ + + $form .= "
"; + $form .= " "; + $form .= "
"; + $form .= t("Restrict search to") .": "; + foreach (module_list() as $name) { if (module_hook($name, "search")) { - $options .= "\n"; + $form .= " $name "; } } - // build form: - $form .= "\n"; - $form .= " \n"; - $form .= " \n"; - $form .= " \n"; $form .= "
\n"; - // visualize form: + /* + ** Collect the search results: + */ + + $array = array(); + + if ($keys) { + foreach (module_list() as $name) { + if ((!$edit["type"] || $edit["type"][$name]) && ($result = module_invoke($name, "search", $keys))) { + foreach ($result as $entry) { + $output .= search_item($entry, $name); + } + } + } + } + + /* + ** Display form and search results: + */ + $theme->header(); if ($form) { @@ -42,7 +78,12 @@ function search_page() { } if ($keys) { - $theme->box(t("Result"), search_data($keys, $type)); + if ($output) { + $theme->box(t("Result"), $output); + } + else { + $theme->box(t("Result"), t("Your search yielded no results.")); + } } $theme->footer(); diff --git a/modules/search/search.module b/modules/search/search.module index bb74db3c2e1..86049d67d45 100644 --- a/modules/search/search.module +++ b/modules/search/search.module @@ -12,29 +12,65 @@ function search_link($type) { return $links ? $links : array(); } +function search_item($item, $type) { + $output .= "

"; + $output .= " ". $item["title"] ."
"; + $output .= " $type ". ($item["user"] ? " - ". $item["user"] : "") ."". ($item["date"] ? " - ". format_date($item["date"], "small") : "") .""; + $output .= "

"; + + return $output; +} + function search_page() { - global $theme, $type, $keys, $REQUEST_URI; + global $theme, $edit, $type, $keys, $REQUEST_URI; if (user_access("search content")) { - // verify input: + + /* + ** Verify the user input: + */ + $type = check_input($type); $keys = check_input($keys); - // build options list: + + /* + ** Construct the search form: + */ + + $form .= "
"; + $form .= " "; + $form .= "
"; + $form .= t("Restrict search to") .": "; + foreach (module_list() as $name) { if (module_hook($name, "search")) { - $options .= "\n"; + $form .= " $name "; } } - // build form: - $form .= "\n"; - $form .= " \n"; - $form .= " \n"; - $form .= " \n"; $form .= "
\n"; - // visualize form: + /* + ** Collect the search results: + */ + + $array = array(); + + if ($keys) { + foreach (module_list() as $name) { + if ((!$edit["type"] || $edit["type"][$name]) && ($result = module_invoke($name, "search", $keys))) { + foreach ($result as $entry) { + $output .= search_item($entry, $name); + } + } + } + } + + /* + ** Display form and search results: + */ + $theme->header(); if ($form) { @@ -42,7 +78,12 @@ function search_page() { } if ($keys) { - $theme->box(t("Result"), search_data($keys, $type)); + if ($output) { + $theme->box(t("Result"), $output); + } + else { + $theme->box(t("Result"), t("Your search yielded no results.")); + } } $theme->footer();