diff options
author | Dries Buytaert <dries@buytaert.net> | 2003-07-10 17:46:44 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2003-07-10 17:46:44 +0000 |
commit | 337b3c9de997f4fcb27467e3d80d0f43fda7783e (patch) | |
tree | 392e4a56fa1ac3d09e9cb78998f87ab438229926 /includes | |
parent | 1c2fc43b51455e4895455798919e4c77e2b1bf21 (diff) | |
download | brdo-337b3c9de997f4fcb27467e3d80d0f43fda7783e.tar.gz brdo-337b3c9de997f4fcb27467e3d80d0f43fda7783e.tar.bz2 |
- Committed a slightly modified version of Slavica's table prefix patch.
Diffstat (limited to 'includes')
-rw-r--r-- | includes/common.inc | 26 | ||||
-rw-r--r-- | includes/conf.php | 7 | ||||
-rw-r--r-- | includes/database.inc | 9 | ||||
-rw-r--r-- | includes/database.mysql.inc | 10 | ||||
-rw-r--r-- | includes/database.pear.inc | 7 | ||||
-rw-r--r-- | includes/module.inc | 2 | ||||
-rw-r--r-- | includes/theme.inc | 6 | ||||
-rw-r--r-- | includes/xmlrpc.inc | 5 |
8 files changed, 47 insertions, 25 deletions
diff --git a/includes/common.inc b/includes/common.inc index 3ebfa13c0..145cb07a8 100644 --- a/includes/common.inc +++ b/includes/common.inc @@ -37,12 +37,12 @@ function error_handler($errno, $message, $filename, $line, $variables) { function watchdog($type, $message, $link = NULL) { global $user; - db_query("INSERT INTO watchdog (uid, type, message, link, location, hostname, timestamp) VALUES (%d, '%s', '%s', '%s', '%s', '%s', %d)", $user->uid, $type, $message, $link, request_uri(), getenv("REMOTE_ADDR"), time()); + db_query("INSERT INTO {watchdog} (uid, type, message, link, location, hostname, timestamp) VALUES (%d, '%s', '%s', '%s', '%s', '%s', %d)", $user->uid, $type, $message, $link, request_uri(), 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"))) { + 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()); } @@ -169,7 +169,7 @@ function t($string, $args = 0) { } function variable_init($conf = array()) { - $result = db_query("SELECT * FROM variable"); + $result = db_query("SELECT * FROM {variable} "); while ($variable = db_fetch_object($result)) { if (!isset($conf[$variable->name])) { $conf[$variable->name] = unserialize($variable->value); @@ -188,8 +188,8 @@ function variable_get($name, $default) { function variable_set($name, $value) { global $conf; - db_query("DELETE FROM variable WHERE name = '%s'", $name); - db_query("INSERT INTO variable (name, value) VALUES ('%s', '%s')", $name, serialize($value)); + db_query("DELETE FROM {variable} WHERE name = '%s'", $name); + db_query("INSERT INTO {variable} (name, value) VALUES ('%s', '%s')", $name, serialize($value)); $conf[$name] = $value; } @@ -197,7 +197,7 @@ function variable_set($name, $value) { function variable_del($name) { global $conf; - db_query("DELETE FROM variable WHERE name = '%s'", $name); + db_query("DELETE FROM {variable} WHERE name = '%s'", $name); unset($conf[$name]); } @@ -490,7 +490,7 @@ function xss_check_input_data($data) { // check attributes: $match += preg_match("/\W(dynsrc|datasrc|data|lowsrc|on[a-z]+)\s*=[^>]+?>/i", $data); - + // check tags: $match += preg_match("/<\s*(applet|script|object|style|embed|form|blink|meta|html|frame|iframe|layer|ilayer|head|frameset|xml)/i", $data); @@ -703,25 +703,25 @@ function format_size($size) { } function cache_get($key) { - $cache = db_fetch_object(db_query("SELECT data, created FROM cache WHERE cid = '%s'", $key)); + $cache = db_fetch_object(db_query("SELECT data, created FROM {cache} WHERE cid = '%s'", $key)); return $cache->data ? $cache : 0; } function cache_set($cid, $data, $expire = 0) { - if (db_fetch_object(db_query("SELECT cid FROM cache WHERE cid = '%s'", $cid))) { - db_query("UPDATE cache SET data = '%s', created = %d, expire = %d WHERE cid = '%s'", $data, time(), $expire, $cid); + if (db_fetch_object(db_query("SELECT cid FROM {cache} WHERE cid = '%s'", $cid))) { + db_query("UPDATE {cache} SET data = '%s', created = %d, expire = %d WHERE cid = '%s'", $data, time(), $expire, $cid); } else { - db_query("INSERT INTO cache (cid, data, created, expire) VALUES('%s', '%s', %d, %d)", $cid, $data, time(), $expire); + db_query("INSERT INTO {cache} (cid, data, created, expire) VALUES('%s', '%s', %d, %d)", $cid, $data, time(), $expire); } } function cache_clear_all($cid = NULL) { if (empty($cid)) { - db_query("DELETE FROM cache WHERE expire <> 0"); + db_query("DELETE FROM {cache} WHERE expire <> 0"); } else { - db_query("DELETE FROM cache WHERE cid = %d", $cid); + db_query("DELETE FROM {cache} WHERE cid = %d", $cid); } } diff --git a/includes/conf.php b/includes/conf.php index 920a94397..9d08aa61b 100644 --- a/includes/conf.php +++ b/includes/conf.php @@ -15,9 +15,14 @@ # $db_url = "mysql://user:password@hostname/database"; # $db_url = "pgsql://user:password@hostname/database"; # $db_url = "mssql://user:password@hostname/database"; - $db_url = "mysql://drupal:drupal@localhost/drupal"; +# If $db_prefix is specified all database table names will be +# prepended with this string. Be sure to use valid database +# characters only, usually alphanumeric and underscore. If no +# prefixes are desired, set to empty string "". +$db_prefix = ""; + # # Base URL: # diff --git a/includes/database.inc b/includes/database.inc index be815390e..dd5d28af9 100644 --- a/includes/database.inc +++ b/includes/database.inc @@ -1,4 +1,11 @@ <?php +// $Id$ + +function db_prefix_tables($sql) { + global $db_prefix; + + return strtr($sql, array("{" => $db_prefix, "}" => "")); +} $db_type = substr($db_url, 0, strpos($db_url, "://")); @@ -11,4 +18,4 @@ else { db_connect($db_url); -?>
\ No newline at end of file +?> diff --git a/includes/database.mysql.inc b/includes/database.mysql.inc index c3ac12876..38d4af71d 100644 --- a/includes/database.mysql.inc +++ b/includes/database.mysql.inc @@ -23,6 +23,7 @@ function db_connect($url) { function db_query($query) { $args = func_get_args(); + $query = db_prefix_tables($query); if (count($args) > 1) { $args = array_map("check_query", $args); $args[0] = $query; @@ -36,6 +37,7 @@ function db_query($query) { // debug version function db_queryd($query) { $args = func_get_args(); + $query = db_prefix_tables($query); if (count($args) > 1) { $args = array_map("check_query", $args); $args[0] = $query; @@ -111,9 +113,9 @@ function db_next_id($name) { ** when needed */ - db_query("LOCK TABLES sequences WRITE"); - $id = db_result(db_query("SELECT id FROM sequences WHERE name = '%s'", $name)) + 1; - db_query("REPLACE INTO sequences VALUES ('%s', %d)", $name, $id); + db_query("LOCK TABLES {sequences} WRITE"); + $id = db_result(db_query("SELECT id FROM {sequences} WHERE name = '%s'", $name)) + 1; + db_query("REPLACE INTO {sequences} VALUES ('%s', %d)", $name, $id); db_query("UNLOCK TABLES"); return $id; @@ -136,11 +138,13 @@ function db_query_range($query) { $from = array_pop($args); if (count(func_get_args()) > 3) { $args = array_map("check_query", $args); + $query = db_prefix_tables($query); $args[0] = $query; $query = call_user_func_array("sprintf", $args); } else { $query = func_get_arg(0); + $query = db_prefix_tables($query); } $query .= " LIMIT $from, $count"; return _db_query($query); diff --git a/includes/database.pear.inc b/includes/database.pear.inc index 1b93096b2..ff3b00e4f 100644 --- a/includes/database.pear.inc +++ b/includes/database.pear.inc @@ -25,6 +25,7 @@ function db_connect($url) { function db_query($query) { $args = func_get_args(); + $query = db_prefix_tables($query); if (count($args) > 1) { $args = array_map("check_query", $args); $args[0] = $query; @@ -38,6 +39,7 @@ function db_query($query) { // debug version function db_queryd($query) { $args = func_get_args(); + $query = db_prefix_tables($query); if (count($args) > 1) { $args = array_map("check_query", $args); $args[0] = $query; @@ -147,11 +149,14 @@ function db_query_range($query) { $from = array_pop($args); if (count(func_get_args()) > 3) { $args = array_map("check_query", $args); + $query = db_prefix_tables($query); $args[0] = $query; $result = $db_handle->limitQuery(call_user_func_array("sprintf", $args), $from, $count); } else { - $result = $db_handle->limitQuery(func_get_arg(0), $from, $count); + $query = func_get_arg(0); + $query = db_prefix_tables($query); + $result = $db_handle->limitQuery( $query, $from, $count); } if (variable_get("dev_query", 0)) { diff --git a/includes/module.inc b/includes/module.inc index 1732104a2..e80384343 100644 --- a/includes/module.inc +++ b/includes/module.inc @@ -50,7 +50,7 @@ function module_list($refresh = 0) { if (!$list) { $list = array("admin" => "admin", "system" => "system", "user" => "user", "watchdog" => "watchdog"); - $result = db_query("SELECT name, filename FROM system WHERE type = 'module' AND status = '1' ORDER BY name"); + $result = db_query("SELECT name, filename FROM {system} WHERE type = 'module' AND status = '1' ORDER BY name"); while ($module = db_fetch_object($result)) { if (file_exists($module->filename)) { $list[$module->name] = $module->name; diff --git a/includes/theme.inc b/includes/theme.inc index 05880fbd8..ec442b13c 100644 --- a/includes/theme.inc +++ b/includes/theme.inc @@ -84,7 +84,7 @@ class BaseTheme { print $output; } -} +} // End of BaseTheme class // function theme_mark() { /* @@ -130,7 +130,7 @@ function theme_list($refresh = 0) { if (!$list) { $list = array(); - $result = db_query("SELECT * FROM system where type = 'theme' AND status = '1' ORDER BY name"); + $result = db_query("SELECT * FROM {system} where type = 'theme' AND status = '1' ORDER BY name"); while ($theme = db_fetch_object($result)) { if (file_exists($theme->filename)) { $list[$theme->name] = $theme; @@ -189,7 +189,7 @@ function theme_init() { function theme_blocks($region) { global $user; - $result = db_query("SELECT * FROM blocks WHERE (status = '1' OR custom = '1') ". ($region != "all" ? "AND region = %d " : "") ."ORDER BY weight, module", $region == "left" ? 0 : 1); + $result = db_query("SELECT * FROM {blocks} WHERE (status = '1' OR custom = '1') ". ($region != "all" ? "AND region = %d " : "") ."ORDER BY weight, module", $region == "left" ? 0 : 1); while ($result && ($block = db_fetch_object($result))) { if ((($block->status && (!$user->uid || !$block->custom)) || ($block->custom && $user->block[$block->module][$block->delta])) && (!$block->path || preg_match($block->path, str_replace("?q=", "", request_uri())))) { diff --git a/includes/xmlrpc.inc b/includes/xmlrpc.inc index 77b1f7129..d8e863248 100644 --- a/includes/xmlrpc.inc +++ b/includes/xmlrpc.inc @@ -644,8 +644,9 @@ class xmlrpcmsg { $xmlrpc_value=new xmlrpcval; if ($this->debug) - print "<pre>---GOT---\n" . htmlspecialchars($data) . - "\n---END---\n</pre>"; + ##print "<pre>---GOT---\n" . htmlspecialchars($data) . "\n---END---\n</pre>"; + ##print "<p>---GOT---\n" . nl2br(htmlspecialchars($data)) . "\n---END---\n</p>"; + print "<p>---GOT---\n" . nl2br($data) . "\n---END---\n</p>"; if ($data=="") { error_log("No response received from server."); $r=new xmlrpcresp(0, $xmlrpcerr["no_data"], |