search.module 2.18 KB
Newer Older
Dries's avatar
 
Dries committed
1
<?php
2
// $Id$
Dries's avatar
 
Dries committed
3 4 5 6 7 8 9

function search_perm() {
  return array("search content");
}

function search_link($type) {
  if ($type == "page" && user_access("search content")) {
Dries's avatar
 
Dries committed
10
    $links[] = "<a href=\"module.php?mod=search\">". t("search") ."</a>";
Dries's avatar
 
Dries committed
11 12 13 14 15
  }

  return $links ? $links : array();
}

Dries's avatar
 
Dries committed
16
/*
Dries's avatar
 
Dries committed
17 18 19 20 21
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>";
Dries's avatar
 
Dries committed
22

Dries's avatar
 
Dries committed
23 24
  return $output;
}
Dries's avatar
 
Dries committed
25
*/
Dries's avatar
 
Dries committed
26

Dries's avatar
 
Dries committed
27
function search_page() {
Dries's avatar
 
Dries committed
28
  global $theme, $edit, $type, $keys;
Dries's avatar
 
Dries committed
29 30

  if (user_access("search content")) {
Dries's avatar
 
Dries committed
31

Dries's avatar
 
Dries committed
32 33 34 35 36 37 38
    /*
    ** Verify the user input:
    */

    $type = check_input($type);
    $keys = check_input($keys);

Dries's avatar
 
Dries committed
39 40 41 42 43 44 45 46
    /*
    ** 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") .": ";

Dries's avatar
 
Dries committed
47 48
    foreach (module_list() as $name) {
      if (module_hook($name, "search")) {
Dries's avatar
 
Dries committed
49
        $form .= " <input type=\"checkbox\" name=\"edit[type][$name]\" ". ($edit["type"][$name] ? " checked=\"checked\"" : "") ."/> ". t($name);
Dries's avatar
 
Dries committed
50 51 52
      }
    }

Dries's avatar
 
Dries committed
53
    $form = form($form);
Dries's avatar
 
Dries committed
54

Dries's avatar
 
Dries committed
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
    /*
    ** 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:
    */
Dries's avatar
 
Dries committed
74

Dries's avatar
 
Dries committed
75 76 77 78 79 80 81
    $theme->header();

    if ($form) {
      $theme->box(t("Search"), $form);
    }

    if ($keys) {
Dries's avatar
 
Dries committed
82 83 84 85 86 87
      if ($output) {
        $theme->box(t("Result"), $output);
      }
      else {
        $theme->box(t("Result"), t("Your search yielded no results."));
      }
Dries's avatar
 
Dries committed
88 89 90 91 92 93
    }

    $theme->footer();
  }
  else {
    $theme->header();
Dries's avatar
 
Dries committed
94
    $theme->box(t("Access denied"), message_access());
Dries's avatar
 
Dries committed
95 96 97
    $theme->footer();
  }
}
98

Dries's avatar
 
Dries committed
99
?>