diff options
Diffstat (limited to 'includes')
-rw-r--r-- | includes/common.inc | 130 | ||||
-rw-r--r-- | includes/locale.inc | 14 | ||||
-rw-r--r-- | includes/search.inc | 87 | ||||
-rw-r--r-- | includes/variable.inc | 38 |
4 files changed, 127 insertions, 142 deletions
diff --git a/includes/common.inc b/includes/common.inc index 3e5d6f936..6f70e4820 100644 --- a/includes/common.inc +++ b/includes/common.inc @@ -72,6 +72,133 @@ function message_throttle() { return t("You exceeded the maximum submission rate. Please wait a few minutes and try again."); } +function locale_init() { + global $languages, $user; + return ($languages ? (($user->uid && $user->language) ? $user->language : key($languages)) : 0); +} + +function t($string) { + global $languages; + return ($languages && function_exists("locale") ? locale($string) : $string); +} + +function variable_init($conf = array()) { + $result = db_query("SELECT * FROM variable"); + while ($variable = db_fetch_object($result)) { + if (!isset($conf[$variable->name])) { + $conf[$variable->name] = $variable->value; + } + } + + return $conf; +} + +function variable_get($name, $default, $object = 0) { + global $conf; + + return isset($conf[$name]) ? $conf[$name] : $default; +} + +function variable_set($name, $value) { + global $conf; + + db_query("DELETE FROM variable WHERE name = '". check_query($name) ."'"); + db_query("INSERT INTO variable (name, value) VALUES ('". check_query($name) ."', '". check_query($value) ."')"); + + $conf[$name] = $value; +} + +function variable_del($name) { + global $conf; + + db_query("DELETE FROM variable WHERE name = '". check_query($name) ."'"); + + unset($conf[$name]); +} + +/* +** Format a single result entry of a search query: +*/ + +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 $output; +} + +/* +** 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 ($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); + } + } + } + + 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; +} + +/* +** 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(); +} + function drupal_goto($url) { /* @@ -464,11 +591,8 @@ $config = conf_init(); unset($conf); include_once "includes/$config.php"; include_once "includes/database.inc"; -include_once "includes/variable.inc"; include_once "includes/xmlrpc.inc"; include_once "includes/module.inc"; -include_once "includes/locale.inc"; -include_once "includes/search.inc"; include_once "includes/theme.inc"; // initialize configuration variables: diff --git a/includes/locale.inc b/includes/locale.inc deleted file mode 100644 index f726156f3..000000000 --- a/includes/locale.inc +++ /dev/null @@ -1,14 +0,0 @@ -<?php -// $Id$ - -function locale_init() { - global $languages, $user; - return ($languages ? (($user->uid && $user->language) ? $user->language : key($languages)) : 0); -} - -function t($string) { - global $languages; - return ($languages && function_exists("locale") ? locale($string) : $string); -} - -?>
\ No newline at end of file diff --git a/includes/search.inc b/includes/search.inc deleted file mode 100644 index a4d3355f6..000000000 --- a/includes/search.inc +++ /dev/null @@ -1,87 +0,0 @@ -<?php -// $Id$ - -/* -** Format a single result entry of a search query: -*/ - -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 $output; -} - -/* -** 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 ($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); - } - } - } - - 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; -} - -/* -** 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/variable.inc b/includes/variable.inc deleted file mode 100644 index 9746cc8c6..000000000 --- a/includes/variable.inc +++ /dev/null @@ -1,38 +0,0 @@ -<?php -// $Id$ - -function variable_init($conf = array()) { - $result = db_query("SELECT * FROM variable"); - while ($variable = db_fetch_object($result)) { - if (!isset($conf[$variable->name])) { - $conf[$variable->name] = $variable->value; - } - } - - return $conf; -} - -function variable_get($name, $default, $object = 0) { - global $conf; - - return isset($conf[$name]) ? $conf[$name] : $default; -} - -function variable_set($name, $value) { - global $conf; - - db_query("DELETE FROM variable WHERE name = '". check_query($name) ."'"); - db_query("INSERT INTO variable (name, value) VALUES ('". check_query($name) ."', '". check_query($value) ."')"); - - $conf[$name] = $value; -} - -function variable_del($name) { - global $conf; - - db_query("DELETE FROM variable WHERE name = '". check_query($name) ."'"); - - unset($conf[$name]); -} - -?>
\ No newline at end of file |