Commit 7a9bc86b authored by Dries's avatar Dries
Browse files

- 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().
parent f7e9bab1
<?php
function search_form($keys) {
/*
** Format a single result entry of a search query:
*/
$output .= " <input size=\"50\" value=\"". check_form($keys) ."\" name=\"keys\">";
$output .= " <input type=\"submit\" value=\"". t("Search") ."\">\n";
function search_item($item, $type) {
$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 .= "<br /><br />";
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 .= " <input type=\"text\" size=\"50\" value=\"". check_form($keys) ."\" name=\"keys\">";
$output .= " <input type=\"submit\" value=\"". t("Search") ."\">\n";
if ($keys && $type && $result = module_invoke($type, "search", check_query($keys))) {
foreach ($result as $entry) {
$output .= "<p>\n";
$output .= " <b><u><a href=\"$entry[link]\">$entry[title]</a></u></b><br />";
$output .= " <small>$entry[link]". ($entry[user] ? " - $entry[user]" : "") ."". ($entry[date] ? " - ". format_date($entry[date], "small") : "") ."</small>";
$output .= "</p>\n";
if ($options != 0) {
$output .= "<br />";
$output .= t("Restrict search to") .": ";
foreach (module_list() as $name) {
if (module_hook($name, "search")) {
$output .= " <input type=\"checkbox\" name=\"edit[type][$name]\" ". ($edit["type"][$name] ? " checked=\"checked\"" : "") ."/> ". 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();
}
?>
......@@ -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":
......
......@@ -70,8 +70,7 @@ function comment_admin() {
print comment_edit($id);
break;
case "search":
print search_form($keys);
print search_data($keys, $mod);
print search_type("comment", "admin.php?mod=comment&op=search");
break;
case "delete":
print comment_delete(check_input($id));
......
......@@ -70,8 +70,7 @@ function comment_admin() {
print comment_edit($id);
break;
case "search":
print search_form($keys);
print search_data($keys, $mod);
print search_type("comment", "admin.php?mod=comment&op=search");
break;
case "delete":
print comment_delete(check_input($id));
......
......@@ -274,21 +274,6 @@ function node_admin_save($edit) {
}
}
function node_module_find() {
foreach (module_list() as $name) {
if (module_hook($name, "user")) {
$options .= "<OPTION VALUE=\"$name\">$name</OPTION>\n";
}
}
$output .= " <input size=\"50\" value=\"". check_form($keys) ."\" name=\"keys\" type=\"text\">\n";
$output .= " <select name=\"type\">$options</select>\n";
$output .= " <input type=\"submit\" value=\"Search\">\n";
return form($output);
}
function node_edit($node) {
$output .= form_item("Title", $node->title);
$output .= form_item("Operations", implode("<br />", node_links($node->nid, $node->type)));
......@@ -318,8 +303,7 @@ function node_admin() {
print node_help();
break;
case "search":
print node_module_find($id);
print search_data($keys, $type);
print search_type($type, "admin.php?mod=node&op=search", $keys, 1);
break;
case "status":
print node_edit_status($id);
......
......@@ -274,21 +274,6 @@ function node_admin_save($edit) {
}
}
function node_module_find() {
foreach (module_list() as $name) {
if (module_hook($name, "user")) {
$options .= "<OPTION VALUE=\"$name\">$name</OPTION>\n";
}
}
$output .= " <input size=\"50\" value=\"". check_form($keys) ."\" name=\"keys\" type=\"text\">\n";
$output .= " <select name=\"type\">$options</select>\n";
$output .= " <input type=\"submit\" value=\"Search\">\n";
return form($output);
}
function node_edit($node) {
$output .= form_item("Title", $node->title);
$output .= form_item("Operations", implode("<br />", node_links($node->nid, $node->type)));
......@@ -318,8 +303,7 @@ function node_admin() {
print node_help();
break;
case "search":
print node_module_find($id);
print search_data($keys, $type);
print search_type($type, "admin.php?mod=node&op=search", $keys, 1);
break;
case "status":
print node_edit_status($id);
......
......@@ -12,6 +12,7 @@ function search_link($type) {
return $links ? $links : array();
}
/*
function search_item($item, $type) {
$output .= "<p>";
$output .= " <b><u><a href=\"". $item["link"] ."\">". $item["title"] ."</a></u></b><br />";
......@@ -20,19 +21,13 @@ function search_item($item, $type) {
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:
*/
......
......@@ -12,6 +12,7 @@ function search_link($type) {
return $links ? $links : array();
}
/*
function search_item($item, $type) {
$output .= "<p>";
$output .= " <b><u><a href=\"". $item["link"] ."\">". $item["title"] ."</a></u></b><br />";
......@@ -20,19 +21,13 @@ function search_item($item, $type) {
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:
*/
......
......@@ -109,6 +109,7 @@ function user_validate_name($name) {
if (eregi(" ", $name)) return t("The name can not contain multiple spaces in a row.");
if (eregi("[^a-zA-Z0-9 ]", $name)) return t("The name contains an illegal character.");
if (strlen($name) > 32) return t("The name '$name' is too long: it must be less than 32 characters.");
}
function user_validate_mail($mail) {
......@@ -1136,7 +1137,7 @@ function admin_access_init() {
function user_admin() {
global $edit, $id, $keys, $op, $user;
global $edit, $id, $op, $user;
if (user_access("administer users")) {
......@@ -1166,8 +1167,7 @@ function user_admin() {
print user_help();
break;
case "search":
print search_form($keys);
print search_data($keys, "user");
print search_type("user", "admin.php?mod=user&op=search");
break;
case "Save configuration":
case "Reset to defaults":
......
......@@ -109,6 +109,7 @@ function user_validate_name($name) {
if (eregi(" ", $name)) return t("The name can not contain multiple spaces in a row.");
if (eregi("[^a-zA-Z0-9 ]", $name)) return t("The name contains an illegal character.");
if (strlen($name) > 32) return t("The name '$name' is too long: it must be less than 32 characters.");
}
function user_validate_mail($mail) {
......@@ -1136,7 +1137,7 @@ function admin_access_init() {
function user_admin() {
global $edit, $id, $keys, $op, $user;
global $edit, $id, $op, $user;
if (user_access("administer users")) {
......@@ -1166,8 +1167,7 @@ function user_admin() {
print user_help();
break;
case "search":
print search_form($keys);
print search_data($keys, "user");
print search_type("user", "admin.php?mod=user&op=search");
break;
case "Save configuration":
case "Reset to defaults":
......
......@@ -3,7 +3,7 @@
function weblogs_cron() {
if (db_num_rows(db_query("SELECT nid FROM node WHERE status = '". node_status("posted") ."' AND timestamp > '". variable_get("weblogs_cron_last", time()) ."'", 1))) {
weblogs_notify(variable_get("site_name", "drupal") , path_uri());
weblogs_notify(variable_get("site_name", "drupal") , path_uri());
}
variable_set("weblogs_cron_last", time());
}
......@@ -13,7 +13,7 @@ function weblogs_notify($name, $url) {
$client = new xmlrpc_client("/RPC2", "rpc.weblogs.com", 80);
$message = new xmlrpcmsg("weblogUpdates.ping", array(new xmlrpcval($name), new xmlrpcval($url)));
$result = $client->send($message);
if (!$result || $result->faultCode()) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment