2001-06-30 09:50:36 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
function search_perm() {
|
|
|
|
return array("search content");
|
|
|
|
}
|
|
|
|
|
|
|
|
function search_link($type) {
|
|
|
|
if ($type == "page" && user_access("search content")) {
|
2001-09-18 18:39:15 +00:00
|
|
|
$links[] = "<a href=\"module.php?mod=search\">". t("search") ."</a>";
|
2001-06-30 09:50:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return $links ? $links : array();
|
|
|
|
}
|
|
|
|
|
2001-09-22 21:01:39 +00:00
|
|
|
function search_item($item, $type) {
|
|
|
|
$output .= "<p>";
|
|
|
|
$output .= " <b><u><a href=\"". $item["link"] ."\">". $item["title"] ."</a></u></b><br />";
|
|
|
|
$output .= " <small>$type ". ($item["user"] ? " - ". $item["user"] : "") ."". ($item["date"] ? " - ". format_date($item["date"], "small") : "") ."</small>";
|
|
|
|
$output .= "</p>";
|
|
|
|
|
|
|
|
return $output;
|
|
|
|
}
|
|
|
|
|
2001-06-30 09:50:36 +00:00
|
|
|
function search_page() {
|
2001-09-22 21:01:39 +00:00
|
|
|
global $theme, $edit, $type, $keys, $REQUEST_URI;
|
2001-06-30 09:50:36 +00:00
|
|
|
|
|
|
|
if (user_access("search content")) {
|
2001-09-22 21:01:39 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
** Verify the user input:
|
|
|
|
*/
|
|
|
|
|
2001-06-30 09:50:36 +00:00
|
|
|
$type = check_input($type);
|
|
|
|
$keys = check_input($keys);
|
|
|
|
|
2001-09-22 21:01:39 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
** Construct the search form:
|
|
|
|
*/
|
|
|
|
|
|
|
|
$form .= "<form action=\"$REQUEST_URI\" method=\"POST\">";
|
|
|
|
$form .= " <input size=\"50\" value=\"". check_form($keys) ."\" name=\"keys\" type=\"text\">";
|
|
|
|
$form .= " <input type=\"submit\" value=\"". t("Search") ."\"><br />";
|
|
|
|
$form .= t("Restrict search to") .": ";
|
|
|
|
|
2001-06-30 09:50:36 +00:00
|
|
|
foreach (module_list() as $name) {
|
|
|
|
if (module_hook($name, "search")) {
|
2001-09-22 21:01:39 +00:00
|
|
|
$form .= "<input type=\"checkbox\" name=\"edit[type][$name]\" ". ($edit["type"][$name] ? " checked=\"checked\"" : "") ."/> $name ";
|
2001-06-30 09:50:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$form .= "</form>\n";
|
|
|
|
|
2001-09-22 21:01:39 +00:00
|
|
|
/*
|
|
|
|
** 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:
|
|
|
|
*/
|
|
|
|
|
2001-06-30 09:50:36 +00:00
|
|
|
$theme->header();
|
|
|
|
|
|
|
|
if ($form) {
|
|
|
|
$theme->box(t("Search"), $form);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($keys) {
|
2001-09-22 21:01:39 +00:00
|
|
|
if ($output) {
|
|
|
|
$theme->box(t("Result"), $output);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$theme->box(t("Result"), t("Your search yielded no results."));
|
|
|
|
}
|
2001-06-30 09:50:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$theme->footer();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$theme->header();
|
2001-09-18 18:39:15 +00:00
|
|
|
$theme->box(t("Access denied"), message_access());
|
2001-06-30 09:50:36 +00:00
|
|
|
$theme->footer();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|