drupal/modules/search.module

99 lines
2.2 KiB
Plaintext
Raw Normal View History

<?php
function search_perm() {
return array("search content");
}
function search_link($type) {
if ($type == "page" && user_access("search content")) {
$links[] = "<a href=\"module.php?mod=search\">". t("search") ."</a>";
}
return $links ? $links : array();
}
/*
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;
}
*/
function search_page() {
global $theme, $edit, $type, $keys;
if (user_access("search content")) {
/*
** Verify the user input:
*/
$type = check_input($type);
$keys = check_input($keys);
/*
** Construct the search form:
*/
$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") .": ";
foreach (module_list() as $name) {
if (module_hook($name, "search")) {
$form .= " <input type=\"checkbox\" name=\"edit[type][$name]\" ". ($edit["type"][$name] ? " checked=\"checked\"" : "") ."/> ". t($name);
}
}
$form = form($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) {
$theme->box(t("Search"), $form);
}
if ($keys) {
if ($output) {
$theme->box(t("Result"), $output);
}
else {
$theme->box(t("Result"), t("Your search yielded no results."));
}
}
$theme->footer();
}
else {
$theme->header();
$theme->box(t("Access denied"), message_access());
$theme->footer();
}
}
?>