From 7a9bc86bd2f0ba3ba343e014a2e4c7f99d7f0946 Mon Sep 17 00:00:00 2001 From: Dries Buytaert Date: Wed, 3 Oct 2001 20:57:01 +0000 Subject: - Improved search architecture derived from Axel's new search patches. (There is room for improvement so let's go from these ... and build on them.) - Removed some $status's by calls to node_status(). --- includes/search.inc | 86 ++++++++++++++++++++++++++++++++++++++++++++--------- includes/theme.inc | 4 +-- 2 files changed, 74 insertions(+), 16 deletions(-) (limited to 'includes') diff --git a/includes/search.inc b/includes/search.inc index 801fa037e..fb7a636b6 100644 --- a/includes/search.inc +++ b/includes/search.inc @@ -1,28 +1,86 @@ "; - $output .= " \n"; +function search_item($item, $type) { + $output .= " ". $item["title"] ."
"; + $output .= " $type ". ($item["user"] ? " - ". $item["user"] : "") ."". ($item["date"] ? " - ". format_date($item["date"], "small") : "") .""; + $output .= "

"; - return form($output); + return $output; } -function search_data($keys, $type) { +/* +** Render a generic search form: +*/ + +function search_form($action = 0, $query = 0, $options = 0) { + global $keys; + + if (!$action) { + $action = "module.php?mod=search"; + } + + if (!$query) { + $query = $keys; + } + + $output .= " "; + $output .= " \n"; - if ($keys && $type && $result = module_invoke($type, "search", check_query($keys))) { - foreach ($result as $entry) { - $output .= "

\n"; - $output .= " $entry[title]
"; - $output .= " $entry[link]". ($entry[user] ? " - $entry[user]" : "") ."". ($entry[date] ? " - ". format_date($entry[date], "small") : "") .""; - $output .= "

\n"; + if ($options != 0) { + $output .= "
"; + $output .= t("Restrict search to") .": "; + + foreach (module_list() as $name) { + if (module_hook($name, "search")) { + $output .= " ". t($name); + } } } - else { - $output .= t("Your search yielded no results."); + + return form($output, "post", $action); +} + +/* +** Collect the search results: +*/ + +function search_data() { + global $keys, $edit; + + $keys = check_input($keys); + + if ($keys) { + foreach (module_list() as $name) { + if (module_hook($name, "search") && (!$edit["type"] || $edit["type"][$name]) && ($result = module_invoke($name, "search", check_query($keys)))) { + foreach ($result as $entry) { + $output .= search_item($entry, $name); + } + } + } + if(!$output) { + $output .= t("Your search yielded no results."); + } } return $output; } -?> \ No newline at end of file +/* +** Display the search form and the resulting data: +*/ + +function search_type($type = 0, $action = 0, $query = 0, $options = 0) { + global $edit; + + if ($type) { + $edit["type"][$type] = "on"; + } + + return search_form($action, $query, $options) . search_data(); +} + +?> diff --git a/includes/theme.inc b/includes/theme.inc index 7b9d58055..d35a75d76 100644 --- a/includes/theme.inc +++ b/includes/theme.inc @@ -78,13 +78,13 @@ function theme_account($region, $theme) { } function theme_blocks($region, $theme) { - global $id, $PHP_SELF, $status, $user; + global $id, $PHP_SELF, $user; switch (strrchr($PHP_SELF, "/")) { case "/node.php": if ($region != "left") { if ($user->uid) $node = db_fetch_object(db_query("SELECT * FROM node WHERE nid = '$id'")); - if ($node->status == $status[queued]) theme_moderation_results($theme, $node, $region); + if ($node->status == node_status("queued")) theme_moderation_results($theme, $node, $region); } break; case "/index.php": -- cgit v1.2.3