4) {
if (file_exists("includes/$file.php")) {
return $file;
}
else {
$file = substr($file, strpos($file, ".") + 1);
}
}
return "conf";
}
function error_handler($errno, $message, $filename, $line, $variables) {
$types = array(1 => "error", 2 => "warning", 4 => "parse error", 8 => "notice", 16 => "core error", 32 => "core warning", 64 => "compile error", 128 => "compile warning", 256 => "user error", 512 => "user warning", 1024 => "user notice");
$entry = $types[$errno] .": $message in $filename on line $line.";
if (($errno == 1 || $errno == 2 || $errno == 4) && error_reporting()) {
watchdog("error", $types[$errno] .": $message in $filename on line $line.");
print $entry;
}
}
function watchdog($type, $message) {
global $user;
db_query("INSERT INTO watchdog (uid, type, message, location, hostname, timestamp) VALUES ('$user->uid', '". check_input($type) ."', '". check_input($message) ."', '". check_input(getenv("REQUEST_URI")) ."', '". check_input(getenv("REMOTE_ADDR")) ."', '". time() ."')");
}
function throttle($type, $rate) {
if (!user_access("access administration pages")) {
if ($throttle = db_fetch_object(db_query("SELECT * FROM watchdog WHERE type = '$type' AND hostname = '". getenv("REMOTE_ADDR") ."' AND ". time() ." - timestamp < $rate"))) {
watchdog("warning", "throttle: '". getenv("REMOTE_ADDR") ."' exceeded submission rate - $throttle->type");
die(message_throttle());
}
else {
watchdog($type, "throttle");
}
}
}
function path_uri() {
global $HTTP_HOST, $REQUEST_URI;
return "http://". $HTTP_HOST . substr($REQUEST_URI, 0, strrpos($REQUEST_URI, "/")) ."/";
}
function path_img() {
// use "http://your-image-server.com/ if you want to host images on a seperate server.
return "./images/";
}
function message_access() {
return t("You are not authorized to access to this page.");
}
function message_na() {
return t("n/a");
}
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 .= " ". $item["title"] ."
";
$output .= " $type ". ($item["user"] ? " - ". $item["user"] : "") ."". ($item["date"] ? " - ". format_date($item["date"], "small") : "") ."";
$output .= "
";
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 .= " ";
$output .= " \n";
if ($options != 0) {
$output .= "
";
$output .= t("Restrict search to") .": ";
foreach (module_list() as $name) {
if (module_hook($name, "search")) {
$output .= " ". 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) {
/*
** It is advised to use "drupal_goto()" instead of PHP's "header()" as
** "drupal_goto()" will append the user's session ID to the URI when PHP
** is compiled with "--enable-trans-sid".
*/
if (SID == "" || strstr($url, SID)) {
header("Location: $url");
}
else if (strstr($url, "?") && !strstr($url, SID)) {
header("Location: $url&". SID);
}
else {
header("Location: $url?". SID);
}
/*
** The "Location" header sends a REDIRECT status code to the http
** deamon. In some cases this can go wrong, so we make sure none
** of the code /below/ gets executed when we redirect.
*/
exit();
}
/*
** Stores the referer in a persistent variable:
*/
function referer_save() {
global $referer, $HTTP_REFERER, $REQUEST_URI;
if (!strstr($HTTP_REFERER, $REQUEST_URI)) {
$referer = $HTTP_REFERER;
session_register("referer");
}
}
/*
** Restores the referer from a persistent variable:
*/
function referer_load() {
global $referer;
if (session_is_registered("referer")) {
return $referer;
}
else {
return 0;
}
}
function check_form($text) {
return htmlspecialchars(stripslashes($text));
}
function check_export($text) {
return htmlspecialchars(stripslashes($text));
}
function check_code($text) {
return $text;
}
function check_preview($text) {
return check_output(check_input($text));
}
function check_query($text) {
return addslashes(stripslashes($text));
}
function filter($text) {
foreach (module_list() as $name) {
if (module_hook($name, "filter")) $text = module_invoke($name, "filter", $text);
}
return $text;
}
function check_input($text) {
return check_query($text);
}
function check_output($text, $nl2br = 0) {
return ($text) ? ($nl2br ? nl2br(stripslashes($text)) : stripslashes($text)) : message_na();
}
function check_file($filename) {
if (is_uploaded_file($filename)) {
return 1;
}
else {
return 0;
}
}
function file_encode($filename) {
$edit[filedata] = base64_encode(fread($fd, filesize($edit[upload_file])));
}
function format_info($body, $block) {
return "
|
". ($title ? "$title:
" : "") . $value . ($description ? "
$description" : "") ."
execution time: $diff ms"; } function query_print() { global $queries; print "
"; print_r($queries); print ""; } function page_header() { if (variable_get("dev_timer", 0)) { timer_start(); } if (variable_get("cache", 0)) { if ($data = cache_get()) { print $data; exit(); } } } function page_footer() { if (variable_get("dev_timer", 0)) { timer_print(); } if (variable_get("dev_query", 0)) { query_print(); } if (variable_get("cache", 0)) { cache_set(); } } $config = conf_init(); unset($conf); include_once "includes/$config.php"; include_once "includes/database.inc"; include_once "includes/xmlrpc.inc"; include_once "includes/module.inc"; include_once "includes/theme.inc"; // initialize configuration variables: $conf = variable_init($conf); // initialize installed modules: module_init(); // initialize localization system: $locale = locale_init(); // initialize theme: $theme = theme_init(); // set error handler: set_error_handler("error_handler"); ?>