- Committed a slightly modified version of Slavica's table prefix patch.

4.3.x
Dries Buytaert 2003-07-10 17:46:44 +00:00
parent 1c2fc43b51
commit 337b3c9de9
54 changed files with 810 additions and 782 deletions

View File

@ -1,3 +1,9 @@
Drupal x.x.x, xxxx-xx-xx (to be released)
------------------------
- database backend:
* added support for database table prefxing.
Drupal 4.2.0, xxxx-xx-xx (to be released) Drupal 4.2.0, xxxx-xx-xx (to be released)
------------------------ ------------------------
@ -69,7 +75,7 @@ Drupal 4.0.0, 2002-06-15
- themes: - themes:
* cleaned up the theme system. * cleaned up the theme system.
* moved themes that are not maintained to contributions CVS repository. * moved themes that are not maintained to contributions CVS repository.
- database abstraction: - database backend:
* changed to PEAR database abstraction layer. * changed to PEAR database abstraction layer.
* using ANSI SQL queries to be more portable. * using ANSI SQL queries to be more portable.
- rewrote the user system: - rewrote the user system:

View File

@ -37,12 +37,12 @@ function error_handler($errno, $message, $filename, $line, $variables) {
function watchdog($type, $message, $link = NULL) { function watchdog($type, $message, $link = NULL) {
global $user; 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) { function throttle($type, $rate) {
if (!user_access("access administration pages")) { 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"); watchdog("warning", "throttle: '". getenv("REMOTE_ADDR") ."' exceeded submission rate - $throttle->type");
die(message_throttle()); die(message_throttle());
} }
@ -169,7 +169,7 @@ function t($string, $args = 0) {
} }
function variable_init($conf = array()) { function variable_init($conf = array()) {
$result = db_query("SELECT * FROM variable"); $result = db_query("SELECT * FROM {variable} ");
while ($variable = db_fetch_object($result)) { while ($variable = db_fetch_object($result)) {
if (!isset($conf[$variable->name])) { if (!isset($conf[$variable->name])) {
$conf[$variable->name] = unserialize($variable->value); $conf[$variable->name] = unserialize($variable->value);
@ -188,8 +188,8 @@ function variable_get($name, $default) {
function variable_set($name, $value) { function variable_set($name, $value) {
global $conf; global $conf;
db_query("DELETE FROM variable WHERE name = '%s'", $name); db_query("DELETE FROM {variable} WHERE name = '%s'", $name);
db_query("INSERT INTO variable (name, value) VALUES ('%s', '%s')", $name, serialize($value)); db_query("INSERT INTO {variable} (name, value) VALUES ('%s', '%s')", $name, serialize($value));
$conf[$name] = $value; $conf[$name] = $value;
} }
@ -197,7 +197,7 @@ function variable_set($name, $value) {
function variable_del($name) { function variable_del($name) {
global $conf; global $conf;
db_query("DELETE FROM variable WHERE name = '%s'", $name); db_query("DELETE FROM {variable} WHERE name = '%s'", $name);
unset($conf[$name]); unset($conf[$name]);
} }
@ -490,7 +490,7 @@ function xss_check_input_data($data) {
// check attributes: // check attributes:
$match += preg_match("/\W(dynsrc|datasrc|data|lowsrc|on[a-z]+)\s*=[^>]+?>/i", $data); $match += preg_match("/\W(dynsrc|datasrc|data|lowsrc|on[a-z]+)\s*=[^>]+?>/i", $data);
// check tags: // check tags:
$match += preg_match("/<\s*(applet|script|object|style|embed|form|blink|meta|html|frame|iframe|layer|ilayer|head|frameset|xml)/i", $data); $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) { 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; return $cache->data ? $cache : 0;
} }
function cache_set($cid, $data, $expire = 0) { function cache_set($cid, $data, $expire = 0) {
if (db_fetch_object(db_query("SELECT cid FROM cache WHERE cid = '%s'", $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); db_query("UPDATE {cache} SET data = '%s', created = %d, expire = %d WHERE cid = '%s'", $data, time(), $expire, $cid);
} }
else { 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) { function cache_clear_all($cid = NULL) {
if (empty($cid)) { if (empty($cid)) {
db_query("DELETE FROM cache WHERE expire <> 0"); db_query("DELETE FROM {cache} WHERE expire <> 0");
} }
else { else {
db_query("DELETE FROM cache WHERE cid = %d", $cid); db_query("DELETE FROM {cache} WHERE cid = %d", $cid);
} }
} }

View File

@ -15,9 +15,14 @@
# $db_url = "mysql://user:password@hostname/database"; # $db_url = "mysql://user:password@hostname/database";
# $db_url = "pgsql://user:password@hostname/database"; # $db_url = "pgsql://user:password@hostname/database";
# $db_url = "mssql://user:password@hostname/database"; # $db_url = "mssql://user:password@hostname/database";
$db_url = "mysql://drupal:drupal@localhost/drupal"; $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: # Base URL:
# #

View File

@ -1,4 +1,11 @@
<?php <?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, "://")); $db_type = substr($db_url, 0, strpos($db_url, "://"));
@ -11,4 +18,4 @@ else {
db_connect($db_url); db_connect($db_url);
?> ?>

View File

@ -23,6 +23,7 @@ function db_connect($url) {
function db_query($query) { function db_query($query) {
$args = func_get_args(); $args = func_get_args();
$query = db_prefix_tables($query);
if (count($args) > 1) { if (count($args) > 1) {
$args = array_map("check_query", $args); $args = array_map("check_query", $args);
$args[0] = $query; $args[0] = $query;
@ -36,6 +37,7 @@ function db_query($query) {
// debug version // debug version
function db_queryd($query) { function db_queryd($query) {
$args = func_get_args(); $args = func_get_args();
$query = db_prefix_tables($query);
if (count($args) > 1) { if (count($args) > 1) {
$args = array_map("check_query", $args); $args = array_map("check_query", $args);
$args[0] = $query; $args[0] = $query;
@ -111,9 +113,9 @@ function db_next_id($name) {
** when needed ** when needed
*/ */
db_query("LOCK TABLES sequences WRITE"); db_query("LOCK TABLES {sequences} WRITE");
$id = db_result(db_query("SELECT id FROM sequences WHERE name = '%s'", $name)) + 1; $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("REPLACE INTO {sequences} VALUES ('%s', %d)", $name, $id);
db_query("UNLOCK TABLES"); db_query("UNLOCK TABLES");
return $id; return $id;
@ -136,11 +138,13 @@ function db_query_range($query) {
$from = array_pop($args); $from = array_pop($args);
if (count(func_get_args()) > 3) { if (count(func_get_args()) > 3) {
$args = array_map("check_query", $args); $args = array_map("check_query", $args);
$query = db_prefix_tables($query);
$args[0] = $query; $args[0] = $query;
$query = call_user_func_array("sprintf", $args); $query = call_user_func_array("sprintf", $args);
} }
else { else {
$query = func_get_arg(0); $query = func_get_arg(0);
$query = db_prefix_tables($query);
} }
$query .= " LIMIT $from, $count"; $query .= " LIMIT $from, $count";
return _db_query($query); return _db_query($query);

View File

@ -25,6 +25,7 @@ function db_connect($url) {
function db_query($query) { function db_query($query) {
$args = func_get_args(); $args = func_get_args();
$query = db_prefix_tables($query);
if (count($args) > 1) { if (count($args) > 1) {
$args = array_map("check_query", $args); $args = array_map("check_query", $args);
$args[0] = $query; $args[0] = $query;
@ -38,6 +39,7 @@ function db_query($query) {
// debug version // debug version
function db_queryd($query) { function db_queryd($query) {
$args = func_get_args(); $args = func_get_args();
$query = db_prefix_tables($query);
if (count($args) > 1) { if (count($args) > 1) {
$args = array_map("check_query", $args); $args = array_map("check_query", $args);
$args[0] = $query; $args[0] = $query;
@ -147,11 +149,14 @@ function db_query_range($query) {
$from = array_pop($args); $from = array_pop($args);
if (count(func_get_args()) > 3) { if (count(func_get_args()) > 3) {
$args = array_map("check_query", $args); $args = array_map("check_query", $args);
$query = db_prefix_tables($query);
$args[0] = $query; $args[0] = $query;
$result = $db_handle->limitQuery(call_user_func_array("sprintf", $args), $from, $count); $result = $db_handle->limitQuery(call_user_func_array("sprintf", $args), $from, $count);
} }
else { 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)) { if (variable_get("dev_query", 0)) {

View File

@ -50,7 +50,7 @@ function module_list($refresh = 0) {
if (!$list) { if (!$list) {
$list = array("admin" => "admin", "system" => "system", "user" => "user", "watchdog" => "watchdog"); $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)) { while ($module = db_fetch_object($result)) {
if (file_exists($module->filename)) { if (file_exists($module->filename)) {
$list[$module->name] = $module->name; $list[$module->name] = $module->name;

View File

@ -84,7 +84,7 @@ class BaseTheme {
print $output; print $output;
} }
} } // End of BaseTheme class //
function theme_mark() { function theme_mark() {
/* /*
@ -130,7 +130,7 @@ function theme_list($refresh = 0) {
if (!$list) { if (!$list) {
$list = array(); $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)) { while ($theme = db_fetch_object($result)) {
if (file_exists($theme->filename)) { if (file_exists($theme->filename)) {
$list[$theme->name] = $theme; $list[$theme->name] = $theme;
@ -189,7 +189,7 @@ function theme_init() {
function theme_blocks($region) { function theme_blocks($region) {
global $user; 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))) { 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())))) { 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())))) {

View File

@ -644,8 +644,9 @@ class xmlrpcmsg {
$xmlrpc_value=new xmlrpcval; $xmlrpc_value=new xmlrpcval;
if ($this->debug) if ($this->debug)
print "<pre>---GOT---\n" . htmlspecialchars($data) . ##print "<pre>---GOT---\n" . htmlspecialchars($data) . "\n---END---\n</pre>";
"\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=="") { if ($data=="") {
error_log("No response received from server."); error_log("No response received from server.");
$r=new xmlrpcresp(0, $xmlrpcerr["no_data"], $r=new xmlrpcresp(0, $xmlrpcerr["no_data"],

View File

@ -95,14 +95,14 @@ function import_link($type) {
} }
function import_cron() { function import_cron() {
$result = db_query("SELECT * FROM feed WHERE timestamp + refresh < ". time()); $result = db_query("SELECT * FROM {feed} WHERE timestamp + refresh < ". time());
while ($feed = db_fetch_array($result)) { while ($feed = db_fetch_array($result)) {
import_refresh($feed); import_refresh($feed);
} }
} }
function import_update() { function import_update() {
$result = db_query("SELECT * FROM feed"); $result = db_query("SELECT * FROM {feed} ");
while ($feed = db_fetch_array($result)) { while ($feed = db_fetch_array($result)) {
import_refresh($feed); import_refresh($feed);
} }
@ -127,7 +127,7 @@ function import_bundle_block($attributes) {
$keys = explode(",", $attributes); $keys = explode(",", $attributes);
foreach ($keys as $key) $where[] = "attributes LIKE '%". trim($key) ."%'"; foreach ($keys as $key) $where[] = "attributes LIKE '%". trim($key) ."%'";
$result = db_query_range("SELECT * FROM item WHERE ". implode(" OR ", $where) ." ORDER BY iid DESC", 0, variable_get("import_block_limit", 15)); $result = db_query_range("SELECT * FROM {item} WHERE ". implode(" OR ", $where) ." ORDER BY iid DESC", 0, variable_get("import_block_limit", 15));
} }
$items = array(); $items = array();
@ -143,7 +143,7 @@ function import_bundle_block($attributes) {
} }
function import_feed_block($feed) { function import_feed_block($feed) {
$result = db_query_range("SELECT * FROM item WHERE fid = %d ORDER BY iid DESC ", $feed->fid, 0, variable_get("import_block_limit", 15)); $result = db_query_range("SELECT * FROM {item} WHERE fid = %d ORDER BY iid DESC ", $feed->fid, 0, variable_get("import_block_limit", 15));
$items = array(); $items = array();
while ($item = db_fetch_object($result)) { while ($item = db_fetch_object($result)) {
@ -159,12 +159,12 @@ function import_feed_block($feed) {
function import_block($op, $delta) { function import_block($op, $delta) {
if ($op == "list") { if ($op == "list") {
$result = db_query("SELECT * FROM bundle ORDER BY title"); $result = db_query("SELECT * FROM {bundle} ORDER BY title");
while ($bundle = db_fetch_object($result)) { while ($bundle = db_fetch_object($result)) {
$block["bundle:$bundle->bid"]["info"] = "$bundle->title bundle"; $block["bundle:$bundle->bid"]["info"] = "$bundle->title bundle";
} }
$result = db_query("SELECT * FROM feed ORDER BY fid"); $result = db_query("SELECT * FROM {feed} ORDER BY fid");
while ($feed = db_fetch_object($result)) { while ($feed = db_fetch_object($result)) {
$block["feed:$feed->fid"]["info"] = "$feed->title feed"; $block["feed:$feed->fid"]["info"] = "$feed->title feed";
} }
@ -175,13 +175,13 @@ function import_block($op, $delta) {
list($type, $id) = split(":", $delta); list($type, $id) = split(":", $delta);
switch ($type) { switch ($type) {
case "feed": case "feed":
$feed = db_fetch_object(db_query("SELECT * FROM feed WHERE fid = %d", $id)); $feed = db_fetch_object(db_query("SELECT * FROM {feed} WHERE fid = %d", $id));
$block["subject"] = $feed->title; $block["subject"] = $feed->title;
$block["content"] .= import_feed_block($feed) ."<div style=\"text-align: right;\">". l(t("more"), "import/feed/$feed->fid", array("title" => t("View this feed's recent news."))) ."</div>"; $block["content"] .= import_feed_block($feed) ."<div style=\"text-align: right;\">". l(t("more"), "import/feed/$feed->fid", array("title" => t("View this feed's recent news."))) ."</div>";
break; break;
case "bundle": case "bundle":
$bundle = db_fetch_object(db_query("SELECT * FROM bundle WHERE bid = %d", $id)); $bundle = db_fetch_object(db_query("SELECT * FROM {bundle} WHERE bid = %d", $id));
$block["subject"] = $bundle->title; $block["subject"] = $bundle->title;
$block["content"] .= import_bundle_block($bundle->attributes) ."<div style=\"text-align: right;\">". l(t("more"), "import/bundle/$bundle->bid", array("title" => t("View this bundle's recent news."))) ."</div>"; $block["content"] .= import_bundle_block($bundle->attributes) ."<div style=\"text-align: right;\">". l(t("more"), "import/bundle/$bundle->bid", array("title" => t("View this bundle's recent news."))) ."</div>";
break; break;
@ -195,7 +195,7 @@ function import_get_bundles($attributes = 0) {
$block = array(); $block = array();
$result = db_query("SELECT * FROM bundle ORDER BY title"); $result = db_query("SELECT * FROM {bundle} ORDER BY title");
while ($bundle = db_fetch_object($result)) { while ($bundle = db_fetch_object($result)) {
$block["bundle:$bundle->bid"]["subject"] = $bundle->title; $block["bundle:$bundle->bid"]["subject"] = $bundle->title;
$block["bundle:$bundle->bid"]["content"] = import_bundle_block($bundle->attributes) ."<div style=\"text-align: right;\">". $block["bundle:$bundle->bid"]["content"] = import_bundle_block($bundle->attributes) ."<div style=\"text-align: right;\">".
@ -211,7 +211,7 @@ function import_get_feeds($attributes = 0) {
$block = array(); $block = array();
$result = db_query("SELECT * FROM feed ORDER BY fid"); $result = db_query("SELECT * FROM {feed} ORDER BY fid");
while ($feed = db_fetch_object($result)) { while ($feed = db_fetch_object($result)) {
$block["feed:$feed->fid"]["subject"] = $feed->title; $block["feed:$feed->fid"]["subject"] = $feed->title;
$block["feed:$feed->fid"]["content"] = import_feed_block($feed) ."<div style=\"text-align: right;\">". $block["feed:$feed->fid"]["content"] = import_feed_block($feed) ."<div style=\"text-align: right;\">".
@ -224,7 +224,7 @@ function import_get_feeds($attributes = 0) {
} }
function import_remove($feed) { function import_remove($feed) {
db_query("DELETE FROM item WHERE fid = %d", $feed["fid"]); db_query("DELETE FROM {item} WHERE fid = %d", $feed["fid"]);
return t("removed news items from '%site'.", array("%site" => $feed["title"])); return t("removed news items from '%site'.", array("%site" => $feed["title"]));
} }
@ -323,7 +323,7 @@ function import_refresh($feed) {
$tt = array_flip(get_html_translation_table(HTML_ENTITIES)); $tt = array_flip(get_html_translation_table(HTML_ENTITIES));
$tt["&apos;"] = "'"; $tt["&apos;"] = "'";
db_query("UPDATE feed SET timestamp = %d, link = '%s', description = '%s' WHERE fid = %d", time(), $channel["LINK"], $channel["DESCRIPTION"], $feed["fid"]); db_query("UPDATE {feed} SET timestamp = %d, link = '%s', description = '%s' WHERE fid = %d", time(), $channel["LINK"], $channel["DESCRIPTION"], $feed["fid"]);
/* /*
** We reverse the array such that we store the first item last, ** We reverse the array such that we store the first item last,
@ -369,10 +369,10 @@ function import_refresh($feed) {
*/ */
if ($link && $link != $feed["link"] && $link != $feed["url"]) { if ($link && $link != $feed["link"] && $link != $feed["url"]) {
$entry = db_fetch_object(db_query("SELECT iid FROM item WHERE fid = %d AND link = '%s'", $feed["fid"], $link)); $entry = db_fetch_object(db_query("SELECT iid FROM {item} WHERE fid = %d AND link = '%s'", $feed["fid"], $link));
} }
else { else {
$entry = db_fetch_object(db_query("SELECT iid FROM item WHERE fid = %d AND title = '%s'", $feed["fid"], $title)); $entry = db_fetch_object(db_query("SELECT iid FROM {item} WHERE fid = %d AND title = '%s'", $feed["fid"], $title));
} }
import_save_item(array(iid => $entry->iid, fid => $feed["fid"], title => $title, link => $link, author => $item["AUTHOR"], description => $item["DESCRIPTION"], attributes => $feed["attributes"])); import_save_item(array(iid => $entry->iid, fid => $feed["fid"], title => $title, link => $link, author => $item["AUTHOR"], description => $item["DESCRIPTION"], attributes => $feed["attributes"]));
@ -384,14 +384,14 @@ function import_refresh($feed) {
unset($items); unset($items);
$result = db_query("SELECT iid FROM item WHERE fid = %d ORDER BY timestamp", $feed["fid"]); $result = db_query("SELECT iid FROM {item} WHERE fid = %d ORDER BY timestamp", $feed["fid"]);
while ($item = db_fetch_object($result)) { while ($item = db_fetch_object($result)) {
$items[] = "iid = '$item->iid'"; $items[] = "iid = '$item->iid'";
} }
if (sizeof($items) > 50) { if (sizeof($items) > 50) {
db_query("DELETE FROM item WHERE ". implode(" OR ", array_slice($items, 0, - 50))); db_query("DELETE FROM {item} WHERE ". implode(" OR ", array_slice($items, 0, - 50)));
} }
cache_clear_all(); cache_clear_all();
@ -405,13 +405,13 @@ function import_refresh($feed) {
function import_save_item($edit) { function import_save_item($edit) {
if ($edit["iid"] && $edit["title"]) { if ($edit["iid"] && $edit["title"]) {
db_query("UPDATE item SET title = '%s', link = '%s', author = '%s', description = '%s', attributes = '%s' WHERE iid = %d", $edit["title"], $edit["link"], $edit["author"], $edit["description"], $edit["attributes"], $edit["iid"]); db_query("UPDATE {item} SET title = '%s', link = '%s', author = '%s', description = '%s', attributes = '%s' WHERE iid = %d", $edit["title"], $edit["link"], $edit["author"], $edit["description"], $edit["attributes"], $edit["iid"]);
} }
else if ($edit["iid"]) { else if ($edit["iid"]) {
db_query("DELETE FROM item WHERE iid = %d", $edit["iid"]); db_query("DELETE FROM {item} WHERE iid = %d", $edit["iid"]);
} }
else if ($edit["title"] && $edit["link"]) { else if ($edit["title"] && $edit["link"]) {
db_query("INSERT INTO item (fid, title, link, author, description, attributes, timestamp) VALUES (%d, '%s', '%s', '%s', '%s', '%s', %d)", $edit["fid"], $edit["title"], $edit["link"], $edit["author"], $edit["description"], $edit["attributes"], time()); db_query("INSERT INTO {item} (fid, title, link, author, description, attributes, timestamp) VALUES (%d, '%s', '%s', '%s', '%s', '%s', %d)", $edit["fid"], $edit["title"], $edit["link"], $edit["author"], $edit["description"], $edit["attributes"], time());
} }
} }
@ -432,15 +432,15 @@ function import_form_bundle($edit = array()) {
function import_save_bundle($edit) { function import_save_bundle($edit) {
if ($edit["bid"] && $edit["title"]) { if ($edit["bid"] && $edit["title"]) {
db_query("UPDATE bundle SET title = '%s', attributes = '%s' WHERE bid = %d", $edit["title"], $edit["attributes"], $edit["bid"]); db_query("UPDATE {bundle} SET title = '%s', attributes = '%s' WHERE bid = %d", $edit["title"], $edit["attributes"], $edit["bid"]);
} }
else if ($edit["bid"]) { else if ($edit["bid"]) {
db_query("DELETE FROM bundle WHERE bid = %d", $edit["bid"]); db_query("DELETE FROM {bundle} WHERE bid = %d", $edit["bid"]);
} }
else if ($edit["title"]) { else if ($edit["title"]) {
// a single unique id for bundles and feeds, to use in blocks // a single unique id for bundles and feeds, to use in blocks
$next_id = db_next_id("bundle_bid"); $next_id = db_next_id("bundle_bid");
db_query("INSERT INTO bundle (bid, title, attributes) VALUES (%d, '%s', '%s')", $next_id, $edit["title"], $edit["attributes"]); db_query("INSERT INTO {bundle} (bid, title, attributes) VALUES (%d, '%s', '%s')", $next_id, $edit["title"], $edit["attributes"]);
} }
} }
@ -469,37 +469,37 @@ function import_form_feed($edit = array()) {
function import_save_feed($edit) { function import_save_feed($edit) {
if ($edit["fid"] && $edit["title"]) { if ($edit["fid"] && $edit["title"]) {
db_query("UPDATE feed SET title = '%s', url = '%s', attributes = '%s', refresh = %d WHERE fid = %d", $edit["title"], $edit["url"], $edit["attributes"], $edit["refresh"], $edit["fid"]); db_query("UPDATE {feed} SET title = '%s', url = '%s', attributes = '%s', refresh = %d WHERE fid = %d", $edit["title"], $edit["url"], $edit["attributes"], $edit["refresh"], $edit["fid"]);
db_query("DELETE FROM item WHERE fid = %d", $edit["fid"]); db_query("DELETE FROM {item} WHERE fid = %d", $edit["fid"]);
} }
else if ($edit["fid"]) { else if ($edit["fid"]) {
db_query("DELETE FROM feed WHERE fid = %d", $edit["fid"]); db_query("DELETE FROM {feed} WHERE fid = %d", $edit["fid"]);
db_query("DELETE FROM item WHERE fid = %d", $edit["fid"]); db_query("DELETE FROM {item} WHERE fid = %d", $edit["fid"]);
} }
else if ($edit["title"]) { else if ($edit["title"]) {
// a single unique id for bundles and feeds, to use in blocks // a single unique id for bundles and feeds, to use in blocks
$next_id = db_next_id("feed_fid"); $next_id = db_next_id("feed_fid");
db_query("INSERT INTO feed (fid, title, url, attributes, refresh) VALUES (%d, '%s', '%s', '%s', %d)", $next_id, $edit["title"], $edit["url"], $edit["attributes"], $edit["refresh"]); db_query("INSERT INTO {feed} (fid, title, url, attributes, refresh) VALUES (%d, '%s', '%s', '%s', %d)", $next_id, $edit["title"], $edit["url"], $edit["attributes"], $edit["refresh"]);
} }
} }
function import_save_attributes($edit) { function import_save_attributes($edit) {
foreach ($edit as $iid => $value) { foreach ($edit as $iid => $value) {
db_query("UPDATE item SET attributes = '%s' WHERE iid = %d", $value, $iid); db_query("UPDATE {item} SET attributes = '%s' WHERE iid = %d", $value, $iid);
} }
return "attributes has been saved"; return "attributes has been saved";
} }
function import_get_feed($fid) { function import_get_feed($fid) {
return db_fetch_array(db_query("SELECT * FROM feed WHERE fid = %d", $fid)); return db_fetch_array(db_query("SELECT * FROM {feed} WHERE fid = %d", $fid));
} }
function import_get_bundle($bid) { function import_get_bundle($bid) {
return db_fetch_array(db_query("SELECT * FROM bundle WHERE bid = %d", $bid)); return db_fetch_array(db_query("SELECT * FROM {bundle} WHERE bid = %d", $bid));
} }
function import_view() { function import_view() {
$result = db_query("SELECT f.*, COUNT(i.iid) AS items FROM feed f LEFT JOIN item i ON f.fid = i.fid GROUP BY f.fid, f.title, f.url, f.refresh, f.timestamp, f.attributes, f.link, f.description ORDER BY f.title"); $result = db_query("SELECT f.*, COUNT(i.iid) AS items FROM {feed} f LEFT JOIN {item} i ON f.fid = i.fid GROUP BY f.fid, f.title, f.url, f.refresh, f.timestamp, f.attributes, f.link, f.description ORDER BY f.title");
$output .= "<h3>Feed overview</h3>"; $output .= "<h3>Feed overview</h3>";
@ -510,7 +510,7 @@ function import_view() {
} }
$output .= table($header, $rows); $output .= table($header, $rows);
$result = db_query("SELECT * FROM bundle ORDER BY title"); $result = db_query("SELECT * FROM {bundle} ORDER BY title");
$output .= "<h3>Bundle overview</h3>"; $output .= "<h3>Bundle overview</h3>";
@ -526,7 +526,7 @@ function import_view() {
function import_tag() { function import_tag() {
$result = db_query_range("SELECT i.*, f.title AS feed FROM item i LEFT JOIN feed f ON i.fid = f.fid ORDER BY i.iid DESC", 0, 50); $result = db_query_range("SELECT i.*, f.title AS feed FROM {item} i LEFT JOIN {feed} f ON i.fid = f.fid ORDER BY i.iid DESC", 0, 50);
$header = array(t("date"), t("feed"), t("news item")); $header = array(t("date"), t("feed"), t("news item"));
while ($item = db_fetch_object($result)) { while ($item = db_fetch_object($result)) {
@ -619,7 +619,7 @@ function import_page_info() {
function import_page_last() { function import_page_last() {
$result = db_query_range("SELECT i.*, f.title AS ftitle, f.link AS flink FROM item i LEFT JOIN feed f ON i.fid = f.fid ORDER BY i.iid DESC", 0, variable_get("import_page_limit", 75)); $result = db_query_range("SELECT i.*, f.title AS ftitle, f.link AS flink FROM {item} i LEFT JOIN {feed} f ON i.fid = f.fid ORDER BY i.iid DESC", 0, variable_get("import_page_limit", 75));
$output .= "<table border=\"0\" cellpadding=\"4\" cellspacing=\"2\">"; $output .= "<table border=\"0\" cellpadding=\"4\" cellspacing=\"2\">";
while ($item = db_fetch_object($result)) { while ($item = db_fetch_object($result)) {
@ -649,13 +649,13 @@ function import_page_last() {
function import_page_feed($fid) { function import_page_feed($fid) {
$feed = db_fetch_object(db_query("SELECT * FROM feed WHERE fid = %d", $fid)); $feed = db_fetch_object(db_query("SELECT * FROM {feed} WHERE fid = %d", $fid));
$header .= "<p><b>". t("Website") .":</b><div style=\"margin-left: 20px;\"><a href=\"$feed->link\">$feed->link</a></div></p>"; $header .= "<p><b>". t("Website") .":</b><div style=\"margin-left: 20px;\"><a href=\"$feed->link\">$feed->link</a></div></p>";
$header .= "<p><b>". t("Description") .":</b><div style=\"margin-left: 20px;\">$feed->description</div></p>"; $header .= "<p><b>". t("Description") .":</b><div style=\"margin-left: 20px;\">$feed->description</div></p>";
$header .= "<p><b>". t("Last update") .":</b><div style=\"margin-left: 20px; text-align: right;\">". format_interval(time() - $feed->timestamp) ." ". t("ago") ." <a href=\"$feed->url\"><img src=\"". theme("image", "xml.gif") ."\" width=\"36\" height=\"14\" style=\"border: 0px;\" alt=\"\" title=\"\" /></a><br /><br /></div></p>\n"; $header .= "<p><b>". t("Last update") .":</b><div style=\"margin-left: 20px; text-align: right;\">". format_interval(time() - $feed->timestamp) ." ". t("ago") ." <a href=\"$feed->url\"><img src=\"". theme("image", "xml.gif") ."\" width=\"36\" height=\"14\" style=\"border: 0px;\" alt=\"\" title=\"\" /></a><br /><br /></div></p>\n";
$result = db_query_range("SELECT * FROM item WHERE fid = %d ORDER BY iid DESC", $fid, 0, variable_get("import_page_limit", 75)); $result = db_query_range("SELECT * FROM {item} WHERE fid = %d ORDER BY iid DESC", $fid, 0, variable_get("import_page_limit", 75));
$output .= "<table border=\"0\" cellpadding=\"4\" cellspacing=\"2\">"; $output .= "<table border=\"0\" cellpadding=\"4\" cellspacing=\"2\">";
while ($item = db_fetch_object($result)) { while ($item = db_fetch_object($result)) {
@ -685,14 +685,14 @@ function import_page_feed($fid) {
function import_page_bundle($bid) { function import_page_bundle($bid) {
$bundle = db_fetch_object(db_query("SELECT * FROM bundle WHERE bid = %d", $bid)); $bundle = db_fetch_object(db_query("SELECT * FROM {bundle} WHERE bid = %d", $bid));
$header .= "<p><b>". t("Website") .":</b><div style=\"margin-left: 20px;\">". l($bundle->title, "import/bundle/$bundle->bid") ."</div></p>"; $header .= "<p><b>". t("Website") .":</b><div style=\"margin-left: 20px;\">". l($bundle->title, "import/bundle/$bundle->bid") ."</div></p>";
$header .= "<p><b>". t("Description") .":</b><div style=\"margin-left: 20px;\">". t("A composite news feed about") ." $bundle->attributes.</div></p>"; $header .= "<p><b>". t("Description") .":</b><div style=\"margin-left: 20px;\">". t("A composite news feed about") ." $bundle->attributes.</div></p>";
$keys = explode(",", $bundle->attributes); $keys = explode(",", $bundle->attributes);
foreach ($keys as $key) $where[] = "i.attributes LIKE '%". trim($key) ."%'"; foreach ($keys as $key) $where[] = "i.attributes LIKE '%". trim($key) ."%'";
$result = db_query_range("SELECT i.*, f.title AS ftitle, f.link AS flink FROM item i, feed f WHERE (". implode(" OR ", $where) .") AND i.fid = f.fid ORDER BY iid DESC", 0, variable_get("import_page_limit", 75)); $result = db_query_range("SELECT i.*, f.title AS ftitle, f.link AS flink FROM {item} i, {feed} f WHERE (". implode(" OR ", $where) .") AND i.fid = f.fid ORDER BY iid DESC", 0, variable_get("import_page_limit", 75));
$output .= "<table border=\"0\" cellpadding=\"4\" cellspacing=\"2\">"; $output .= "<table border=\"0\" cellpadding=\"4\" cellspacing=\"2\">";
while ($item = db_fetch_object($result)) { while ($item = db_fetch_object($result)) {
@ -725,7 +725,7 @@ function import_page_bundle($bid) {
function import_page_sources() { function import_page_sources() {
$result = db_query("SELECT * FROM feed ORDER BY title"); $result = db_query("SELECT * FROM {feed} ORDER BY title");
while ($feed = db_fetch_object($result)) { while ($feed = db_fetch_object($result)) {
$output .= l($feed->title, "import/feed/$feed->fid"); $output .= l($feed->title, "import/feed/$feed->fid");
@ -742,7 +742,7 @@ function import_page_sources() {
function import_page_fd() { function import_page_fd() {
$result = db_query("SELECT * FROM feed ORDER BY title"); $result = db_query("SELECT * FROM {feed} ORDER BY title");
$output .= "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n\n"; $output .= "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n\n";
$output .= "<rssfeeds version=\"0.1\">\n\n"; $output .= "<rssfeeds version=\"0.1\">\n\n";

View File

@ -95,14 +95,14 @@ function import_link($type) {
} }
function import_cron() { function import_cron() {
$result = db_query("SELECT * FROM feed WHERE timestamp + refresh < ". time()); $result = db_query("SELECT * FROM {feed} WHERE timestamp + refresh < ". time());
while ($feed = db_fetch_array($result)) { while ($feed = db_fetch_array($result)) {
import_refresh($feed); import_refresh($feed);
} }
} }
function import_update() { function import_update() {
$result = db_query("SELECT * FROM feed"); $result = db_query("SELECT * FROM {feed} ");
while ($feed = db_fetch_array($result)) { while ($feed = db_fetch_array($result)) {
import_refresh($feed); import_refresh($feed);
} }
@ -127,7 +127,7 @@ function import_bundle_block($attributes) {
$keys = explode(",", $attributes); $keys = explode(",", $attributes);
foreach ($keys as $key) $where[] = "attributes LIKE '%". trim($key) ."%'"; foreach ($keys as $key) $where[] = "attributes LIKE '%". trim($key) ."%'";
$result = db_query_range("SELECT * FROM item WHERE ". implode(" OR ", $where) ." ORDER BY iid DESC", 0, variable_get("import_block_limit", 15)); $result = db_query_range("SELECT * FROM {item} WHERE ". implode(" OR ", $where) ." ORDER BY iid DESC", 0, variable_get("import_block_limit", 15));
} }
$items = array(); $items = array();
@ -143,7 +143,7 @@ function import_bundle_block($attributes) {
} }
function import_feed_block($feed) { function import_feed_block($feed) {
$result = db_query_range("SELECT * FROM item WHERE fid = %d ORDER BY iid DESC ", $feed->fid, 0, variable_get("import_block_limit", 15)); $result = db_query_range("SELECT * FROM {item} WHERE fid = %d ORDER BY iid DESC ", $feed->fid, 0, variable_get("import_block_limit", 15));
$items = array(); $items = array();
while ($item = db_fetch_object($result)) { while ($item = db_fetch_object($result)) {
@ -159,12 +159,12 @@ function import_feed_block($feed) {
function import_block($op, $delta) { function import_block($op, $delta) {
if ($op == "list") { if ($op == "list") {
$result = db_query("SELECT * FROM bundle ORDER BY title"); $result = db_query("SELECT * FROM {bundle} ORDER BY title");
while ($bundle = db_fetch_object($result)) { while ($bundle = db_fetch_object($result)) {
$block["bundle:$bundle->bid"]["info"] = "$bundle->title bundle"; $block["bundle:$bundle->bid"]["info"] = "$bundle->title bundle";
} }
$result = db_query("SELECT * FROM feed ORDER BY fid"); $result = db_query("SELECT * FROM {feed} ORDER BY fid");
while ($feed = db_fetch_object($result)) { while ($feed = db_fetch_object($result)) {
$block["feed:$feed->fid"]["info"] = "$feed->title feed"; $block["feed:$feed->fid"]["info"] = "$feed->title feed";
} }
@ -175,13 +175,13 @@ function import_block($op, $delta) {
list($type, $id) = split(":", $delta); list($type, $id) = split(":", $delta);
switch ($type) { switch ($type) {
case "feed": case "feed":
$feed = db_fetch_object(db_query("SELECT * FROM feed WHERE fid = %d", $id)); $feed = db_fetch_object(db_query("SELECT * FROM {feed} WHERE fid = %d", $id));
$block["subject"] = $feed->title; $block["subject"] = $feed->title;
$block["content"] .= import_feed_block($feed) ."<div style=\"text-align: right;\">". l(t("more"), "import/feed/$feed->fid", array("title" => t("View this feed's recent news."))) ."</div>"; $block["content"] .= import_feed_block($feed) ."<div style=\"text-align: right;\">". l(t("more"), "import/feed/$feed->fid", array("title" => t("View this feed's recent news."))) ."</div>";
break; break;
case "bundle": case "bundle":
$bundle = db_fetch_object(db_query("SELECT * FROM bundle WHERE bid = %d", $id)); $bundle = db_fetch_object(db_query("SELECT * FROM {bundle} WHERE bid = %d", $id));
$block["subject"] = $bundle->title; $block["subject"] = $bundle->title;
$block["content"] .= import_bundle_block($bundle->attributes) ."<div style=\"text-align: right;\">". l(t("more"), "import/bundle/$bundle->bid", array("title" => t("View this bundle's recent news."))) ."</div>"; $block["content"] .= import_bundle_block($bundle->attributes) ."<div style=\"text-align: right;\">". l(t("more"), "import/bundle/$bundle->bid", array("title" => t("View this bundle's recent news."))) ."</div>";
break; break;
@ -195,7 +195,7 @@ function import_get_bundles($attributes = 0) {
$block = array(); $block = array();
$result = db_query("SELECT * FROM bundle ORDER BY title"); $result = db_query("SELECT * FROM {bundle} ORDER BY title");
while ($bundle = db_fetch_object($result)) { while ($bundle = db_fetch_object($result)) {
$block["bundle:$bundle->bid"]["subject"] = $bundle->title; $block["bundle:$bundle->bid"]["subject"] = $bundle->title;
$block["bundle:$bundle->bid"]["content"] = import_bundle_block($bundle->attributes) ."<div style=\"text-align: right;\">". $block["bundle:$bundle->bid"]["content"] = import_bundle_block($bundle->attributes) ."<div style=\"text-align: right;\">".
@ -211,7 +211,7 @@ function import_get_feeds($attributes = 0) {
$block = array(); $block = array();
$result = db_query("SELECT * FROM feed ORDER BY fid"); $result = db_query("SELECT * FROM {feed} ORDER BY fid");
while ($feed = db_fetch_object($result)) { while ($feed = db_fetch_object($result)) {
$block["feed:$feed->fid"]["subject"] = $feed->title; $block["feed:$feed->fid"]["subject"] = $feed->title;
$block["feed:$feed->fid"]["content"] = import_feed_block($feed) ."<div style=\"text-align: right;\">". $block["feed:$feed->fid"]["content"] = import_feed_block($feed) ."<div style=\"text-align: right;\">".
@ -224,7 +224,7 @@ function import_get_feeds($attributes = 0) {
} }
function import_remove($feed) { function import_remove($feed) {
db_query("DELETE FROM item WHERE fid = %d", $feed["fid"]); db_query("DELETE FROM {item} WHERE fid = %d", $feed["fid"]);
return t("removed news items from '%site'.", array("%site" => $feed["title"])); return t("removed news items from '%site'.", array("%site" => $feed["title"]));
} }
@ -323,7 +323,7 @@ function import_refresh($feed) {
$tt = array_flip(get_html_translation_table(HTML_ENTITIES)); $tt = array_flip(get_html_translation_table(HTML_ENTITIES));
$tt["&apos;"] = "'"; $tt["&apos;"] = "'";
db_query("UPDATE feed SET timestamp = %d, link = '%s', description = '%s' WHERE fid = %d", time(), $channel["LINK"], $channel["DESCRIPTION"], $feed["fid"]); db_query("UPDATE {feed} SET timestamp = %d, link = '%s', description = '%s' WHERE fid = %d", time(), $channel["LINK"], $channel["DESCRIPTION"], $feed["fid"]);
/* /*
** We reverse the array such that we store the first item last, ** We reverse the array such that we store the first item last,
@ -369,10 +369,10 @@ function import_refresh($feed) {
*/ */
if ($link && $link != $feed["link"] && $link != $feed["url"]) { if ($link && $link != $feed["link"] && $link != $feed["url"]) {
$entry = db_fetch_object(db_query("SELECT iid FROM item WHERE fid = %d AND link = '%s'", $feed["fid"], $link)); $entry = db_fetch_object(db_query("SELECT iid FROM {item} WHERE fid = %d AND link = '%s'", $feed["fid"], $link));
} }
else { else {
$entry = db_fetch_object(db_query("SELECT iid FROM item WHERE fid = %d AND title = '%s'", $feed["fid"], $title)); $entry = db_fetch_object(db_query("SELECT iid FROM {item} WHERE fid = %d AND title = '%s'", $feed["fid"], $title));
} }
import_save_item(array(iid => $entry->iid, fid => $feed["fid"], title => $title, link => $link, author => $item["AUTHOR"], description => $item["DESCRIPTION"], attributes => $feed["attributes"])); import_save_item(array(iid => $entry->iid, fid => $feed["fid"], title => $title, link => $link, author => $item["AUTHOR"], description => $item["DESCRIPTION"], attributes => $feed["attributes"]));
@ -384,14 +384,14 @@ function import_refresh($feed) {
unset($items); unset($items);
$result = db_query("SELECT iid FROM item WHERE fid = %d ORDER BY timestamp", $feed["fid"]); $result = db_query("SELECT iid FROM {item} WHERE fid = %d ORDER BY timestamp", $feed["fid"]);
while ($item = db_fetch_object($result)) { while ($item = db_fetch_object($result)) {
$items[] = "iid = '$item->iid'"; $items[] = "iid = '$item->iid'";
} }
if (sizeof($items) > 50) { if (sizeof($items) > 50) {
db_query("DELETE FROM item WHERE ". implode(" OR ", array_slice($items, 0, - 50))); db_query("DELETE FROM {item} WHERE ". implode(" OR ", array_slice($items, 0, - 50)));
} }
cache_clear_all(); cache_clear_all();
@ -405,13 +405,13 @@ function import_refresh($feed) {
function import_save_item($edit) { function import_save_item($edit) {
if ($edit["iid"] && $edit["title"]) { if ($edit["iid"] && $edit["title"]) {
db_query("UPDATE item SET title = '%s', link = '%s', author = '%s', description = '%s', attributes = '%s' WHERE iid = %d", $edit["title"], $edit["link"], $edit["author"], $edit["description"], $edit["attributes"], $edit["iid"]); db_query("UPDATE {item} SET title = '%s', link = '%s', author = '%s', description = '%s', attributes = '%s' WHERE iid = %d", $edit["title"], $edit["link"], $edit["author"], $edit["description"], $edit["attributes"], $edit["iid"]);
} }
else if ($edit["iid"]) { else if ($edit["iid"]) {
db_query("DELETE FROM item WHERE iid = %d", $edit["iid"]); db_query("DELETE FROM {item} WHERE iid = %d", $edit["iid"]);
} }
else if ($edit["title"] && $edit["link"]) { else if ($edit["title"] && $edit["link"]) {
db_query("INSERT INTO item (fid, title, link, author, description, attributes, timestamp) VALUES (%d, '%s', '%s', '%s', '%s', '%s', %d)", $edit["fid"], $edit["title"], $edit["link"], $edit["author"], $edit["description"], $edit["attributes"], time()); db_query("INSERT INTO {item} (fid, title, link, author, description, attributes, timestamp) VALUES (%d, '%s', '%s', '%s', '%s', '%s', %d)", $edit["fid"], $edit["title"], $edit["link"], $edit["author"], $edit["description"], $edit["attributes"], time());
} }
} }
@ -432,15 +432,15 @@ function import_form_bundle($edit = array()) {
function import_save_bundle($edit) { function import_save_bundle($edit) {
if ($edit["bid"] && $edit["title"]) { if ($edit["bid"] && $edit["title"]) {
db_query("UPDATE bundle SET title = '%s', attributes = '%s' WHERE bid = %d", $edit["title"], $edit["attributes"], $edit["bid"]); db_query("UPDATE {bundle} SET title = '%s', attributes = '%s' WHERE bid = %d", $edit["title"], $edit["attributes"], $edit["bid"]);
} }
else if ($edit["bid"]) { else if ($edit["bid"]) {
db_query("DELETE FROM bundle WHERE bid = %d", $edit["bid"]); db_query("DELETE FROM {bundle} WHERE bid = %d", $edit["bid"]);
} }
else if ($edit["title"]) { else if ($edit["title"]) {
// a single unique id for bundles and feeds, to use in blocks // a single unique id for bundles and feeds, to use in blocks
$next_id = db_next_id("bundle_bid"); $next_id = db_next_id("bundle_bid");
db_query("INSERT INTO bundle (bid, title, attributes) VALUES (%d, '%s', '%s')", $next_id, $edit["title"], $edit["attributes"]); db_query("INSERT INTO {bundle} (bid, title, attributes) VALUES (%d, '%s', '%s')", $next_id, $edit["title"], $edit["attributes"]);
} }
} }
@ -469,37 +469,37 @@ function import_form_feed($edit = array()) {
function import_save_feed($edit) { function import_save_feed($edit) {
if ($edit["fid"] && $edit["title"]) { if ($edit["fid"] && $edit["title"]) {
db_query("UPDATE feed SET title = '%s', url = '%s', attributes = '%s', refresh = %d WHERE fid = %d", $edit["title"], $edit["url"], $edit["attributes"], $edit["refresh"], $edit["fid"]); db_query("UPDATE {feed} SET title = '%s', url = '%s', attributes = '%s', refresh = %d WHERE fid = %d", $edit["title"], $edit["url"], $edit["attributes"], $edit["refresh"], $edit["fid"]);
db_query("DELETE FROM item WHERE fid = %d", $edit["fid"]); db_query("DELETE FROM {item} WHERE fid = %d", $edit["fid"]);
} }
else if ($edit["fid"]) { else if ($edit["fid"]) {
db_query("DELETE FROM feed WHERE fid = %d", $edit["fid"]); db_query("DELETE FROM {feed} WHERE fid = %d", $edit["fid"]);
db_query("DELETE FROM item WHERE fid = %d", $edit["fid"]); db_query("DELETE FROM {item} WHERE fid = %d", $edit["fid"]);
} }
else if ($edit["title"]) { else if ($edit["title"]) {
// a single unique id for bundles and feeds, to use in blocks // a single unique id for bundles and feeds, to use in blocks
$next_id = db_next_id("feed_fid"); $next_id = db_next_id("feed_fid");
db_query("INSERT INTO feed (fid, title, url, attributes, refresh) VALUES (%d, '%s', '%s', '%s', %d)", $next_id, $edit["title"], $edit["url"], $edit["attributes"], $edit["refresh"]); db_query("INSERT INTO {feed} (fid, title, url, attributes, refresh) VALUES (%d, '%s', '%s', '%s', %d)", $next_id, $edit["title"], $edit["url"], $edit["attributes"], $edit["refresh"]);
} }
} }
function import_save_attributes($edit) { function import_save_attributes($edit) {
foreach ($edit as $iid => $value) { foreach ($edit as $iid => $value) {
db_query("UPDATE item SET attributes = '%s' WHERE iid = %d", $value, $iid); db_query("UPDATE {item} SET attributes = '%s' WHERE iid = %d", $value, $iid);
} }
return "attributes has been saved"; return "attributes has been saved";
} }
function import_get_feed($fid) { function import_get_feed($fid) {
return db_fetch_array(db_query("SELECT * FROM feed WHERE fid = %d", $fid)); return db_fetch_array(db_query("SELECT * FROM {feed} WHERE fid = %d", $fid));
} }
function import_get_bundle($bid) { function import_get_bundle($bid) {
return db_fetch_array(db_query("SELECT * FROM bundle WHERE bid = %d", $bid)); return db_fetch_array(db_query("SELECT * FROM {bundle} WHERE bid = %d", $bid));
} }
function import_view() { function import_view() {
$result = db_query("SELECT f.*, COUNT(i.iid) AS items FROM feed f LEFT JOIN item i ON f.fid = i.fid GROUP BY f.fid, f.title, f.url, f.refresh, f.timestamp, f.attributes, f.link, f.description ORDER BY f.title"); $result = db_query("SELECT f.*, COUNT(i.iid) AS items FROM {feed} f LEFT JOIN {item} i ON f.fid = i.fid GROUP BY f.fid, f.title, f.url, f.refresh, f.timestamp, f.attributes, f.link, f.description ORDER BY f.title");
$output .= "<h3>Feed overview</h3>"; $output .= "<h3>Feed overview</h3>";
@ -510,7 +510,7 @@ function import_view() {
} }
$output .= table($header, $rows); $output .= table($header, $rows);
$result = db_query("SELECT * FROM bundle ORDER BY title"); $result = db_query("SELECT * FROM {bundle} ORDER BY title");
$output .= "<h3>Bundle overview</h3>"; $output .= "<h3>Bundle overview</h3>";
@ -526,7 +526,7 @@ function import_view() {
function import_tag() { function import_tag() {
$result = db_query_range("SELECT i.*, f.title AS feed FROM item i LEFT JOIN feed f ON i.fid = f.fid ORDER BY i.iid DESC", 0, 50); $result = db_query_range("SELECT i.*, f.title AS feed FROM {item} i LEFT JOIN {feed} f ON i.fid = f.fid ORDER BY i.iid DESC", 0, 50);
$header = array(t("date"), t("feed"), t("news item")); $header = array(t("date"), t("feed"), t("news item"));
while ($item = db_fetch_object($result)) { while ($item = db_fetch_object($result)) {
@ -619,7 +619,7 @@ function import_page_info() {
function import_page_last() { function import_page_last() {
$result = db_query_range("SELECT i.*, f.title AS ftitle, f.link AS flink FROM item i LEFT JOIN feed f ON i.fid = f.fid ORDER BY i.iid DESC", 0, variable_get("import_page_limit", 75)); $result = db_query_range("SELECT i.*, f.title AS ftitle, f.link AS flink FROM {item} i LEFT JOIN {feed} f ON i.fid = f.fid ORDER BY i.iid DESC", 0, variable_get("import_page_limit", 75));
$output .= "<table border=\"0\" cellpadding=\"4\" cellspacing=\"2\">"; $output .= "<table border=\"0\" cellpadding=\"4\" cellspacing=\"2\">";
while ($item = db_fetch_object($result)) { while ($item = db_fetch_object($result)) {
@ -649,13 +649,13 @@ function import_page_last() {
function import_page_feed($fid) { function import_page_feed($fid) {
$feed = db_fetch_object(db_query("SELECT * FROM feed WHERE fid = %d", $fid)); $feed = db_fetch_object(db_query("SELECT * FROM {feed} WHERE fid = %d", $fid));
$header .= "<p><b>". t("Website") .":</b><div style=\"margin-left: 20px;\"><a href=\"$feed->link\">$feed->link</a></div></p>"; $header .= "<p><b>". t("Website") .":</b><div style=\"margin-left: 20px;\"><a href=\"$feed->link\">$feed->link</a></div></p>";
$header .= "<p><b>". t("Description") .":</b><div style=\"margin-left: 20px;\">$feed->description</div></p>"; $header .= "<p><b>". t("Description") .":</b><div style=\"margin-left: 20px;\">$feed->description</div></p>";
$header .= "<p><b>". t("Last update") .":</b><div style=\"margin-left: 20px; text-align: right;\">". format_interval(time() - $feed->timestamp) ." ". t("ago") ." <a href=\"$feed->url\"><img src=\"". theme("image", "xml.gif") ."\" width=\"36\" height=\"14\" style=\"border: 0px;\" alt=\"\" title=\"\" /></a><br /><br /></div></p>\n"; $header .= "<p><b>". t("Last update") .":</b><div style=\"margin-left: 20px; text-align: right;\">". format_interval(time() - $feed->timestamp) ." ". t("ago") ." <a href=\"$feed->url\"><img src=\"". theme("image", "xml.gif") ."\" width=\"36\" height=\"14\" style=\"border: 0px;\" alt=\"\" title=\"\" /></a><br /><br /></div></p>\n";
$result = db_query_range("SELECT * FROM item WHERE fid = %d ORDER BY iid DESC", $fid, 0, variable_get("import_page_limit", 75)); $result = db_query_range("SELECT * FROM {item} WHERE fid = %d ORDER BY iid DESC", $fid, 0, variable_get("import_page_limit", 75));
$output .= "<table border=\"0\" cellpadding=\"4\" cellspacing=\"2\">"; $output .= "<table border=\"0\" cellpadding=\"4\" cellspacing=\"2\">";
while ($item = db_fetch_object($result)) { while ($item = db_fetch_object($result)) {
@ -685,14 +685,14 @@ function import_page_feed($fid) {
function import_page_bundle($bid) { function import_page_bundle($bid) {
$bundle = db_fetch_object(db_query("SELECT * FROM bundle WHERE bid = %d", $bid)); $bundle = db_fetch_object(db_query("SELECT * FROM {bundle} WHERE bid = %d", $bid));
$header .= "<p><b>". t("Website") .":</b><div style=\"margin-left: 20px;\">". l($bundle->title, "import/bundle/$bundle->bid") ."</div></p>"; $header .= "<p><b>". t("Website") .":</b><div style=\"margin-left: 20px;\">". l($bundle->title, "import/bundle/$bundle->bid") ."</div></p>";
$header .= "<p><b>". t("Description") .":</b><div style=\"margin-left: 20px;\">". t("A composite news feed about") ." $bundle->attributes.</div></p>"; $header .= "<p><b>". t("Description") .":</b><div style=\"margin-left: 20px;\">". t("A composite news feed about") ." $bundle->attributes.</div></p>";
$keys = explode(",", $bundle->attributes); $keys = explode(",", $bundle->attributes);
foreach ($keys as $key) $where[] = "i.attributes LIKE '%". trim($key) ."%'"; foreach ($keys as $key) $where[] = "i.attributes LIKE '%". trim($key) ."%'";
$result = db_query_range("SELECT i.*, f.title AS ftitle, f.link AS flink FROM item i, feed f WHERE (". implode(" OR ", $where) .") AND i.fid = f.fid ORDER BY iid DESC", 0, variable_get("import_page_limit", 75)); $result = db_query_range("SELECT i.*, f.title AS ftitle, f.link AS flink FROM {item} i, {feed} f WHERE (". implode(" OR ", $where) .") AND i.fid = f.fid ORDER BY iid DESC", 0, variable_get("import_page_limit", 75));
$output .= "<table border=\"0\" cellpadding=\"4\" cellspacing=\"2\">"; $output .= "<table border=\"0\" cellpadding=\"4\" cellspacing=\"2\">";
while ($item = db_fetch_object($result)) { while ($item = db_fetch_object($result)) {
@ -725,7 +725,7 @@ function import_page_bundle($bid) {
function import_page_sources() { function import_page_sources() {
$result = db_query("SELECT * FROM feed ORDER BY title"); $result = db_query("SELECT * FROM {feed} ORDER BY title");
while ($feed = db_fetch_object($result)) { while ($feed = db_fetch_object($result)) {
$output .= l($feed->title, "import/feed/$feed->fid"); $output .= l($feed->title, "import/feed/$feed->fid");
@ -742,7 +742,7 @@ function import_page_sources() {
function import_page_fd() { function import_page_fd() {
$result = db_query("SELECT * FROM feed ORDER BY title"); $result = db_query("SELECT * FROM {feed} ORDER BY title");
$output .= "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n\n"; $output .= "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n\n";
$output .= "<rssfeeds version=\"0.1\">\n\n"; $output .= "<rssfeeds version=\"0.1\">\n\n";

View File

@ -62,7 +62,7 @@ function archive_calendar($original = 0) {
$next = mktime(23, 59, 59, $month + 1, min(date("t", $nextmonth), $day), $year); $next = mktime(23, 59, 59, $month + 1, min(date("t", $nextmonth), $day), $year);
$result = db_query("SELECT created FROM node WHERE status = 1 AND created > $start_of_month AND created < $end_of_month"); $result = db_query("SELECT created FROM {node} WHERE status = 1 AND created > $start_of_month AND created < $end_of_month");
$days_with_posts = array(); $days_with_posts = array();
while ($day_with_post = db_fetch_object($result)) { while ($day_with_post = db_fetch_object($result)) {
@ -223,7 +223,7 @@ function archive_page() {
*/ */
if ($year && $month && $day) { if ($year && $month && $day) {
$result = db_query_range("SELECT nid FROM node WHERE status = '1' AND created > %d ORDER BY created", $date, 0, 20); $result = db_query_range("SELECT nid FROM {node} WHERE status = '1' AND created > %d ORDER BY created", $date, 0, 20);
while ($nid = db_fetch_object($result)) { while ($nid = db_fetch_object($result)) {
node_view(node_load(array("nid" => $nid->nid)), 1); node_view(node_load(array("nid" => $nid->nid)), 1);

View File

@ -62,7 +62,7 @@ function archive_calendar($original = 0) {
$next = mktime(23, 59, 59, $month + 1, min(date("t", $nextmonth), $day), $year); $next = mktime(23, 59, 59, $month + 1, min(date("t", $nextmonth), $day), $year);
$result = db_query("SELECT created FROM node WHERE status = 1 AND created > $start_of_month AND created < $end_of_month"); $result = db_query("SELECT created FROM {node} WHERE status = 1 AND created > $start_of_month AND created < $end_of_month");
$days_with_posts = array(); $days_with_posts = array();
while ($day_with_post = db_fetch_object($result)) { while ($day_with_post = db_fetch_object($result)) {
@ -223,7 +223,7 @@ function archive_page() {
*/ */
if ($year && $month && $day) { if ($year && $month && $day) {
$result = db_query_range("SELECT nid FROM node WHERE status = '1' AND created > %d ORDER BY created", $date, 0, 20); $result = db_query_range("SELECT nid FROM {node} WHERE status = '1' AND created > %d ORDER BY created", $date, 0, 20);
while ($nid = db_fetch_object($result)) { while ($nid = db_fetch_object($result)) {
node_view(node_load(array("nid" => $nid->nid)), 1); node_view(node_load(array("nid" => $nid->nid)), 1);

View File

@ -58,14 +58,14 @@ function block_link($type) {
function block_block($op = "list", $delta = 0) { function block_block($op = "list", $delta = 0) {
if ($op == "list") { if ($op == "list") {
$result = db_query("SELECT bid, title, info FROM boxes ORDER BY title"); $result = db_query("SELECT bid, title, info FROM {boxes} ORDER BY title");
while ($block = db_fetch_object($result)) { while ($block = db_fetch_object($result)) {
$blocks[$block->bid]["info"] = $block->info; $blocks[$block->bid]["info"] = $block->info;
} }
return $blocks; return $blocks;
} }
else { else {
$block = db_fetch_object(db_query("SELECT * FROM boxes WHERE bid = %d", $delta)); $block = db_fetch_object(db_query("SELECT * FROM {boxes} WHERE bid = %d", $delta));
$data["subject"] = $block->title; $data["subject"] = $block->title;
$data["content"] = ($block->type == 1) ? eval($block->body) : $block->body; $data["content"] = ($block->type == 1) ? eval($block->body) : $block->body;
return $data; return $data;
@ -75,7 +75,7 @@ function block_block($op = "list", $delta = 0) {
function block_admin_save($edit) { function block_admin_save($edit) {
foreach ($edit as $module => $blocks) { foreach ($edit as $module => $blocks) {
foreach ($blocks as $delta => $block) { foreach ($blocks as $delta => $block) {
db_query("UPDATE blocks SET region = %d, status = %d, custom = %d, path = '%s', weight = %d WHERE module = '%s' AND delta = '%s'", db_query("UPDATE {blocks} SET region = %d, status = %d, custom = %d, path = '%s', weight = %d WHERE module = '%s' AND delta = '%s'",
$block["region"], $block["status"], $block["custom"], $block["path"], $block["weight"], $module, $delta); $block["region"], $block["status"], $block["custom"], $block["path"], $block["weight"], $module, $delta);
} }
} }
@ -91,12 +91,12 @@ function block_admin_save($edit) {
* @access private * @access private
*/ */
function _block_rehash($order_by = array("weight")) { function _block_rehash($order_by = array("weight")) {
$result = db_query("SELECT * FROM blocks"); $result = db_query("SELECT * FROM {blocks} ");
while ($old_block = db_fetch_object($result)) { while ($old_block = db_fetch_object($result)) {
$old_blocks[$old_block->module][$old_block->delta] = $old_block; $old_blocks[$old_block->module][$old_block->delta] = $old_block;
} }
db_query("DELETE FROM blocks"); db_query("DELETE FROM {blocks} ");
foreach (module_list() as $module) { foreach (module_list() as $module) {
$module_blocks = module_invoke($module, "block", "list"); $module_blocks = module_invoke($module, "block", "list");
@ -117,7 +117,7 @@ function _block_rehash($order_by = array("weight")) {
} }
// reinsert blocks into table // reinsert blocks into table
db_query("INSERT INTO blocks (module, delta, status, weight, region, path, custom) VALUES ('%s', '%s', %d, %d, %d, '%s', %d)", db_query("INSERT INTO {blocks} (module, delta, status, weight, region, path, custom) VALUES ('%s', '%s', %d, %d, %d, '%s', %d)",
$block["module"], $block["delta"], $block["status"], $block["weight"], $block["region"], $block["path"], $block["custom"]); $block["module"], $block["delta"], $block["status"], $block["weight"], $block["region"], $block["path"], $block["custom"]);
$blocks[] = $block; $blocks[] = $block;
@ -161,7 +161,7 @@ function block_admin_display() {
function block_admin_preview() { function block_admin_preview() {
$result = db_query("SELECT * FROM blocks WHERE status > 0 AND region = 0 ORDER BY weight"); $result = db_query("SELECT * FROM {blocks} WHERE status > 0 AND region = 0 ORDER BY weight");
$lblocks .= "<table border=\"0\" cellpadding=\"2\" cellspacing=\"2\">\n"; $lblocks .= "<table border=\"0\" cellpadding=\"2\" cellspacing=\"2\">\n";
while ($block = db_fetch_object($result)) { while ($block = db_fetch_object($result)) {
$block_data = module_invoke($block->module, "block", "list"); $block_data = module_invoke($block->module, "block", "list");
@ -170,7 +170,7 @@ function block_admin_preview() {
} }
$lblocks .= "</table>\n"; $lblocks .= "</table>\n";
$result = db_query("SELECT * FROM blocks WHERE status > 0 AND region = 1 ORDER BY weight"); $result = db_query("SELECT * FROM {blocks} WHERE status > 0 AND region = 1 ORDER BY weight");
$rblocks .= "<table border=\"0\" cellpadding=\"2\" cellspacing=\"2\">\n"; $rblocks .= "<table border=\"0\" cellpadding=\"2\" cellspacing=\"2\">\n";
while ($block = db_fetch_object($result)) { while ($block = db_fetch_object($result)) {
$block_data = module_invoke($block->module, "block", "list"); $block_data = module_invoke($block->module, "block", "list");
@ -186,7 +186,7 @@ function block_admin_preview() {
$output .= " <tr><td colspan=\"3\" style=\"text-align: center;\">". t("footer") ."</td></tr>\n"; $output .= " <tr><td colspan=\"3\" style=\"text-align: center;\">". t("footer") ."</td></tr>\n";
$output .= "</table>\n"; $output .= "</table>\n";
$result = db_query("SELECT * FROM blocks WHERE status > 0 ORDER BY weight"); $result = db_query("SELECT * FROM {blocks} WHERE status > 0 ORDER BY weight");
$blocks .= "<table border=\"0\" cellpadding=\"2\" cellspacing=\"2\">\n"; $blocks .= "<table border=\"0\" cellpadding=\"2\" cellspacing=\"2\">\n";
while ($block = db_fetch_object($result)) { while ($block = db_fetch_object($result)) {
$block_data = module_invoke($block->module, "block", "list"); $block_data = module_invoke($block->module, "block", "list");
@ -213,7 +213,7 @@ function block_admin_preview() {
} }
function block_box_get($bid) { function block_box_get($bid) {
return db_fetch_array(db_query("SELECT * FROM boxes WHERE bid = %d", $bid)); return db_fetch_array(db_query("SELECT * FROM {boxes} WHERE bid = %d", $bid));
} }
function block_box_form($edit = array()) { function block_box_form($edit = array()) {
@ -241,18 +241,18 @@ function block_box_save($edit) {
} }
if ($edit["bid"]) { if ($edit["bid"]) {
db_query("UPDATE boxes SET title = '%s', body = '%s', info = '%s', type = %d WHERE bid = %d", $edit["title"], $edit["body"], $edit["info"], $edit["type"], $edit["bid"]); db_query("UPDATE {boxes} SET title = '%s', body = '%s', info = '%s', type = %d WHERE bid = %d", $edit["title"], $edit["body"], $edit["info"], $edit["type"], $edit["bid"]);
return t("the block has been updated."); return t("the block has been updated.");
} }
else { else {
db_query("INSERT INTO boxes (title, body, info, type) VALUES ('%s', '%s', '%s', %d)", $edit["title"], $edit["body"], $edit["info"], $edit["type"]); db_query("INSERT INTO {boxes} (title, body, info, type) VALUES ('%s', '%s', '%s', %d)", $edit["title"], $edit["body"], $edit["info"], $edit["type"]);
return t("the new block has been added."); return t("the new block has been added.");
} }
} }
function block_box_delete($bid) { function block_box_delete($bid) {
if ($bid) { if ($bid) {
db_query("DELETE FROM boxes WHERE bid = %d", $bid); db_query("DELETE FROM {boxes} WHERE bid = %d", $bid);
return t("the block has been deleted."); return t("the block has been deleted.");
} }
} }
@ -303,7 +303,7 @@ function block_admin() {
function block_user($type, &$edit, &$user) { function block_user($type, &$edit, &$user) {
switch ($type) { switch ($type) {
case "register_form": case "register_form":
$result = db_query("SELECT * FROM blocks WHERE custom = %d ORDER BY module, delta", 1); $result = db_query("SELECT * FROM {blocks} WHERE custom = %d ORDER BY module, delta", 1);
while ($block = db_fetch_object($result)) { while ($block = db_fetch_object($result)) {
$form .= form_hidden("block][$block->module][$block->delta", $block->status); $form .= form_hidden("block][$block->module][$block->delta", $block->status);
@ -311,7 +311,7 @@ function block_user($type, &$edit, &$user) {
return $form; return $form;
case "edit_form": case "edit_form":
$result = db_query("SELECT * FROM blocks WHERE custom = %d ORDER BY module, delta", 1); $result = db_query("SELECT * FROM {blocks} WHERE custom = %d ORDER BY module, delta", 1);
while ($block = db_fetch_object($result)) { while ($block = db_fetch_object($result)) {
$data = module_invoke($block->module, "block", "list"); $data = module_invoke($block->module, "block", "list");

View File

@ -58,14 +58,14 @@ function block_link($type) {
function block_block($op = "list", $delta = 0) { function block_block($op = "list", $delta = 0) {
if ($op == "list") { if ($op == "list") {
$result = db_query("SELECT bid, title, info FROM boxes ORDER BY title"); $result = db_query("SELECT bid, title, info FROM {boxes} ORDER BY title");
while ($block = db_fetch_object($result)) { while ($block = db_fetch_object($result)) {
$blocks[$block->bid]["info"] = $block->info; $blocks[$block->bid]["info"] = $block->info;
} }
return $blocks; return $blocks;
} }
else { else {
$block = db_fetch_object(db_query("SELECT * FROM boxes WHERE bid = %d", $delta)); $block = db_fetch_object(db_query("SELECT * FROM {boxes} WHERE bid = %d", $delta));
$data["subject"] = $block->title; $data["subject"] = $block->title;
$data["content"] = ($block->type == 1) ? eval($block->body) : $block->body; $data["content"] = ($block->type == 1) ? eval($block->body) : $block->body;
return $data; return $data;
@ -75,7 +75,7 @@ function block_block($op = "list", $delta = 0) {
function block_admin_save($edit) { function block_admin_save($edit) {
foreach ($edit as $module => $blocks) { foreach ($edit as $module => $blocks) {
foreach ($blocks as $delta => $block) { foreach ($blocks as $delta => $block) {
db_query("UPDATE blocks SET region = %d, status = %d, custom = %d, path = '%s', weight = %d WHERE module = '%s' AND delta = '%s'", db_query("UPDATE {blocks} SET region = %d, status = %d, custom = %d, path = '%s', weight = %d WHERE module = '%s' AND delta = '%s'",
$block["region"], $block["status"], $block["custom"], $block["path"], $block["weight"], $module, $delta); $block["region"], $block["status"], $block["custom"], $block["path"], $block["weight"], $module, $delta);
} }
} }
@ -91,12 +91,12 @@ function block_admin_save($edit) {
* @access private * @access private
*/ */
function _block_rehash($order_by = array("weight")) { function _block_rehash($order_by = array("weight")) {
$result = db_query("SELECT * FROM blocks"); $result = db_query("SELECT * FROM {blocks} ");
while ($old_block = db_fetch_object($result)) { while ($old_block = db_fetch_object($result)) {
$old_blocks[$old_block->module][$old_block->delta] = $old_block; $old_blocks[$old_block->module][$old_block->delta] = $old_block;
} }
db_query("DELETE FROM blocks"); db_query("DELETE FROM {blocks} ");
foreach (module_list() as $module) { foreach (module_list() as $module) {
$module_blocks = module_invoke($module, "block", "list"); $module_blocks = module_invoke($module, "block", "list");
@ -117,7 +117,7 @@ function _block_rehash($order_by = array("weight")) {
} }
// reinsert blocks into table // reinsert blocks into table
db_query("INSERT INTO blocks (module, delta, status, weight, region, path, custom) VALUES ('%s', '%s', %d, %d, %d, '%s', %d)", db_query("INSERT INTO {blocks} (module, delta, status, weight, region, path, custom) VALUES ('%s', '%s', %d, %d, %d, '%s', %d)",
$block["module"], $block["delta"], $block["status"], $block["weight"], $block["region"], $block["path"], $block["custom"]); $block["module"], $block["delta"], $block["status"], $block["weight"], $block["region"], $block["path"], $block["custom"]);
$blocks[] = $block; $blocks[] = $block;
@ -161,7 +161,7 @@ function block_admin_display() {
function block_admin_preview() { function block_admin_preview() {
$result = db_query("SELECT * FROM blocks WHERE status > 0 AND region = 0 ORDER BY weight"); $result = db_query("SELECT * FROM {blocks} WHERE status > 0 AND region = 0 ORDER BY weight");
$lblocks .= "<table border=\"0\" cellpadding=\"2\" cellspacing=\"2\">\n"; $lblocks .= "<table border=\"0\" cellpadding=\"2\" cellspacing=\"2\">\n";
while ($block = db_fetch_object($result)) { while ($block = db_fetch_object($result)) {
$block_data = module_invoke($block->module, "block", "list"); $block_data = module_invoke($block->module, "block", "list");
@ -170,7 +170,7 @@ function block_admin_preview() {
} }
$lblocks .= "</table>\n"; $lblocks .= "</table>\n";
$result = db_query("SELECT * FROM blocks WHERE status > 0 AND region = 1 ORDER BY weight"); $result = db_query("SELECT * FROM {blocks} WHERE status > 0 AND region = 1 ORDER BY weight");
$rblocks .= "<table border=\"0\" cellpadding=\"2\" cellspacing=\"2\">\n"; $rblocks .= "<table border=\"0\" cellpadding=\"2\" cellspacing=\"2\">\n";
while ($block = db_fetch_object($result)) { while ($block = db_fetch_object($result)) {
$block_data = module_invoke($block->module, "block", "list"); $block_data = module_invoke($block->module, "block", "list");
@ -186,7 +186,7 @@ function block_admin_preview() {
$output .= " <tr><td colspan=\"3\" style=\"text-align: center;\">". t("footer") ."</td></tr>\n"; $output .= " <tr><td colspan=\"3\" style=\"text-align: center;\">". t("footer") ."</td></tr>\n";
$output .= "</table>\n"; $output .= "</table>\n";
$result = db_query("SELECT * FROM blocks WHERE status > 0 ORDER BY weight"); $result = db_query("SELECT * FROM {blocks} WHERE status > 0 ORDER BY weight");
$blocks .= "<table border=\"0\" cellpadding=\"2\" cellspacing=\"2\">\n"; $blocks .= "<table border=\"0\" cellpadding=\"2\" cellspacing=\"2\">\n";
while ($block = db_fetch_object($result)) { while ($block = db_fetch_object($result)) {
$block_data = module_invoke($block->module, "block", "list"); $block_data = module_invoke($block->module, "block", "list");
@ -213,7 +213,7 @@ function block_admin_preview() {
} }
function block_box_get($bid) { function block_box_get($bid) {
return db_fetch_array(db_query("SELECT * FROM boxes WHERE bid = %d", $bid)); return db_fetch_array(db_query("SELECT * FROM {boxes} WHERE bid = %d", $bid));
} }
function block_box_form($edit = array()) { function block_box_form($edit = array()) {
@ -241,18 +241,18 @@ function block_box_save($edit) {
} }
if ($edit["bid"]) { if ($edit["bid"]) {
db_query("UPDATE boxes SET title = '%s', body = '%s', info = '%s', type = %d WHERE bid = %d", $edit["title"], $edit["body"], $edit["info"], $edit["type"], $edit["bid"]); db_query("UPDATE {boxes} SET title = '%s', body = '%s', info = '%s', type = %d WHERE bid = %d", $edit["title"], $edit["body"], $edit["info"], $edit["type"], $edit["bid"]);
return t("the block has been updated."); return t("the block has been updated.");
} }
else { else {
db_query("INSERT INTO boxes (title, body, info, type) VALUES ('%s', '%s', '%s', %d)", $edit["title"], $edit["body"], $edit["info"], $edit["type"]); db_query("INSERT INTO {boxes} (title, body, info, type) VALUES ('%s', '%s', '%s', %d)", $edit["title"], $edit["body"], $edit["info"], $edit["type"]);
return t("the new block has been added."); return t("the new block has been added.");
} }
} }
function block_box_delete($bid) { function block_box_delete($bid) {
if ($bid) { if ($bid) {
db_query("DELETE FROM boxes WHERE bid = %d", $bid); db_query("DELETE FROM {boxes} WHERE bid = %d", $bid);
return t("the block has been deleted."); return t("the block has been deleted.");
} }
} }
@ -303,7 +303,7 @@ function block_admin() {
function block_user($type, &$edit, &$user) { function block_user($type, &$edit, &$user) {
switch ($type) { switch ($type) {
case "register_form": case "register_form":
$result = db_query("SELECT * FROM blocks WHERE custom = %d ORDER BY module, delta", 1); $result = db_query("SELECT * FROM {blocks} WHERE custom = %d ORDER BY module, delta", 1);
while ($block = db_fetch_object($result)) { while ($block = db_fetch_object($result)) {
$form .= form_hidden("block][$block->module][$block->delta", $block->status); $form .= form_hidden("block][$block->module][$block->delta", $block->status);
@ -311,7 +311,7 @@ function block_user($type, &$edit, &$user) {
return $form; return $form;
case "edit_form": case "edit_form":
$result = db_query("SELECT * FROM blocks WHERE custom = %d ORDER BY module, delta", 1); $result = db_query("SELECT * FROM {blocks} WHERE custom = %d ORDER BY module, delta", 1);
while ($block = db_fetch_object($result)) { while ($block = db_fetch_object($result)) {
$data = module_invoke($block->module, "block", "list"); $data = module_invoke($block->module, "block", "list");

View File

@ -91,7 +91,7 @@ function blog_feed_user($uid = 0) {
$account = $user; $account = $user;
} }
$result = db_query_range("SELECT n.nid, n.title, n.teaser, n.created, u.name, u.uid FROM node n LEFT JOIN users u ON n.uid = u.uid WHERE n.type = 'blog' AND u.uid = %d AND n.status = 1 ORDER BY n.nid DESC", $uid, 0, 15); $result = db_query_range("SELECT n.nid, n.title, n.teaser, n.created, u.name, u.uid FROM {node} n LEFT JOIN {users} u ON n.uid = u.uid WHERE n.type = 'blog' AND u.uid = %d AND n.status = 1 ORDER BY n.nid DESC", $uid, 0, 15);
$channel["title"] = $account->name. "'s blog"; $channel["title"] = $account->name. "'s blog";
$channel["link"] = url("blog/view/$uid"); $channel["link"] = url("blog/view/$uid");
$channel["description"] = $term->description; $channel["description"] = $term->description;
@ -99,7 +99,7 @@ function blog_feed_user($uid = 0) {
} }
function blog_feed_last() { function blog_feed_last() {
$result = db_query_range("SELECT n.nid, n.title, n.teaser, n.created, u.name, u.uid FROM node n LEFT JOIN users u ON n.uid = u.uid WHERE n.type = 'blog' AND n.status = 1 ORDER BY n.nid DESC", 0, 15); $result = db_query_range("SELECT n.nid, n.title, n.teaser, n.created, u.name, u.uid FROM {node} n LEFT JOIN {users} u ON n.uid = u.uid WHERE n.type = 'blog' AND n.status = 1 ORDER BY n.nid DESC", 0, 15);
$channel["title"] = variable_get("site_name", "drupal") ." blogs"; $channel["title"] = variable_get("site_name", "drupal") ." blogs";
$channel["link"] = url("blog"); $channel["link"] = url("blog");
$channel["description"] = $term->description; $channel["description"] = $term->description;
@ -116,7 +116,7 @@ function blog_page_user($uid = 0) {
$account = $user; $account = $user;
} }
$result = pager_query("SELECT nid FROM node WHERE type = 'blog' AND uid = '$account->uid' AND status = 1 ORDER BY nid DESC", variable_get("default_nodes_main", 10)); $result = pager_query("SELECT nid FROM {node} WHERE type = 'blog' AND uid = '$account->uid' AND status = 1 ORDER BY nid DESC", variable_get("default_nodes_main", 10));
while ($node = db_fetch_object($result)) { while ($node = db_fetch_object($result)) {
node_view(node_load(array("nid" => $node->nid)), 1); node_view(node_load(array("nid" => $node->nid)), 1);
} }
@ -127,7 +127,7 @@ function blog_page_user($uid = 0) {
function blog_page_last() { function blog_page_last() {
global $user; global $user;
$result = pager_query("SELECT nid FROM node WHERE type = 'blog' AND status = 1 ORDER BY nid DESC", variable_get("default_nodes_main", 10)); $result = pager_query("SELECT nid FROM {node} WHERE type = 'blog' AND status = 1 ORDER BY nid DESC", variable_get("default_nodes_main", 10));
while ($node = db_fetch_object($result)) { while ($node = db_fetch_object($result)) {
$output = node_view(node_load(array("nid" => $node->nid)), 1); $output = node_view(node_load(array("nid" => $node->nid)), 1);
@ -157,7 +157,7 @@ function blog_form(&$node, &$help, &$error) {
$node->body = "<i>". $blog->body ."</i> [". l($blog->name, "node/view/$nid") ."]"; $node->body = "<i>". $blog->body ."</i> [". l($blog->name, "node/view/$nid") ."]";
} }
if ($iid && $item = db_fetch_object(db_query("SELECT i.*, f.title as ftitle, f.link as flink FROM item i, feed f WHERE i.iid = %d AND i.fid = f.fid", $iid))) { if ($iid && $item = db_fetch_object(db_query("SELECT i.*, f.title as ftitle, f.link as flink FROM {item} i, {feed} f WHERE i.iid = %d AND i.fid = f.fid", $iid))) {
$node->title = $item->title; $node->title = $item->title;
$node->body = "<a href=\"$item->link\">$item->title</a> - <i>". check_output($item->description) ."</i> [<a href=\"$item->flink\">$item->ftitle</a>]\n"; $node->body = "<a href=\"$item->link\">$item->title</a> - <i>". check_output($item->description) ."</i> [<a href=\"$item->flink\">$item->ftitle</a>]\n";
} }
@ -250,7 +250,7 @@ function blog_block($op = "list", $delta = 0) {
} }
else { else {
if (user_access("access content")) { if (user_access("access content")) {
$block["content"] = node_title_list(db_query_range("SELECT n.title, n.nid FROM node n WHERE n.type = 'blog' AND n.status = 1 ORDER BY n.nid DESC", 0, 10)); $block["content"] = node_title_list(db_query_range("SELECT n.title, n.nid FROM {node} n WHERE n.type = 'blog' AND n.status = 1 ORDER BY n.nid DESC", 0, 10));
$block["content"] .= "<div align=\"right\" id=\"blog_more\">". l(t("more"), "blog", array("title" => t("Read the latest blog entries."))) ."</div>"; $block["content"] .= "<div align=\"right\" id=\"blog_more\">". l(t("more"), "blog", array("title" => t("Read the latest blog entries."))) ."</div>";
$block["subject"] = t("Blogs"); $block["subject"] = t("Blogs");
} }

View File

@ -91,7 +91,7 @@ function blog_feed_user($uid = 0) {
$account = $user; $account = $user;
} }
$result = db_query_range("SELECT n.nid, n.title, n.teaser, n.created, u.name, u.uid FROM node n LEFT JOIN users u ON n.uid = u.uid WHERE n.type = 'blog' AND u.uid = %d AND n.status = 1 ORDER BY n.nid DESC", $uid, 0, 15); $result = db_query_range("SELECT n.nid, n.title, n.teaser, n.created, u.name, u.uid FROM {node} n LEFT JOIN {users} u ON n.uid = u.uid WHERE n.type = 'blog' AND u.uid = %d AND n.status = 1 ORDER BY n.nid DESC", $uid, 0, 15);
$channel["title"] = $account->name. "'s blog"; $channel["title"] = $account->name. "'s blog";
$channel["link"] = url("blog/view/$uid"); $channel["link"] = url("blog/view/$uid");
$channel["description"] = $term->description; $channel["description"] = $term->description;
@ -99,7 +99,7 @@ function blog_feed_user($uid = 0) {
} }
function blog_feed_last() { function blog_feed_last() {
$result = db_query_range("SELECT n.nid, n.title, n.teaser, n.created, u.name, u.uid FROM node n LEFT JOIN users u ON n.uid = u.uid WHERE n.type = 'blog' AND n.status = 1 ORDER BY n.nid DESC", 0, 15); $result = db_query_range("SELECT n.nid, n.title, n.teaser, n.created, u.name, u.uid FROM {node} n LEFT JOIN {users} u ON n.uid = u.uid WHERE n.type = 'blog' AND n.status = 1 ORDER BY n.nid DESC", 0, 15);
$channel["title"] = variable_get("site_name", "drupal") ." blogs"; $channel["title"] = variable_get("site_name", "drupal") ." blogs";
$channel["link"] = url("blog"); $channel["link"] = url("blog");
$channel["description"] = $term->description; $channel["description"] = $term->description;
@ -116,7 +116,7 @@ function blog_page_user($uid = 0) {
$account = $user; $account = $user;
} }
$result = pager_query("SELECT nid FROM node WHERE type = 'blog' AND uid = '$account->uid' AND status = 1 ORDER BY nid DESC", variable_get("default_nodes_main", 10)); $result = pager_query("SELECT nid FROM {node} WHERE type = 'blog' AND uid = '$account->uid' AND status = 1 ORDER BY nid DESC", variable_get("default_nodes_main", 10));
while ($node = db_fetch_object($result)) { while ($node = db_fetch_object($result)) {
node_view(node_load(array("nid" => $node->nid)), 1); node_view(node_load(array("nid" => $node->nid)), 1);
} }
@ -127,7 +127,7 @@ function blog_page_user($uid = 0) {
function blog_page_last() { function blog_page_last() {
global $user; global $user;
$result = pager_query("SELECT nid FROM node WHERE type = 'blog' AND status = 1 ORDER BY nid DESC", variable_get("default_nodes_main", 10)); $result = pager_query("SELECT nid FROM {node} WHERE type = 'blog' AND status = 1 ORDER BY nid DESC", variable_get("default_nodes_main", 10));
while ($node = db_fetch_object($result)) { while ($node = db_fetch_object($result)) {
$output = node_view(node_load(array("nid" => $node->nid)), 1); $output = node_view(node_load(array("nid" => $node->nid)), 1);
@ -157,7 +157,7 @@ function blog_form(&$node, &$help, &$error) {
$node->body = "<i>". $blog->body ."</i> [". l($blog->name, "node/view/$nid") ."]"; $node->body = "<i>". $blog->body ."</i> [". l($blog->name, "node/view/$nid") ."]";
} }
if ($iid && $item = db_fetch_object(db_query("SELECT i.*, f.title as ftitle, f.link as flink FROM item i, feed f WHERE i.iid = %d AND i.fid = f.fid", $iid))) { if ($iid && $item = db_fetch_object(db_query("SELECT i.*, f.title as ftitle, f.link as flink FROM {item} i, {feed} f WHERE i.iid = %d AND i.fid = f.fid", $iid))) {
$node->title = $item->title; $node->title = $item->title;
$node->body = "<a href=\"$item->link\">$item->title</a> - <i>". check_output($item->description) ."</i> [<a href=\"$item->flink\">$item->ftitle</a>]\n"; $node->body = "<a href=\"$item->link\">$item->title</a> - <i>". check_output($item->description) ."</i> [<a href=\"$item->flink\">$item->ftitle</a>]\n";
} }
@ -250,7 +250,7 @@ function blog_block($op = "list", $delta = 0) {
} }
else { else {
if (user_access("access content")) { if (user_access("access content")) {
$block["content"] = node_title_list(db_query_range("SELECT n.title, n.nid FROM node n WHERE n.type = 'blog' AND n.status = 1 ORDER BY n.nid DESC", 0, 10)); $block["content"] = node_title_list(db_query_range("SELECT n.title, n.nid FROM {node} n WHERE n.type = 'blog' AND n.status = 1 ORDER BY n.nid DESC", 0, 10));
$block["content"] .= "<div align=\"right\" id=\"blog_more\">". l(t("more"), "blog", array("title" => t("Read the latest blog entries."))) ."</div>"; $block["content"] .= "<div align=\"right\" id=\"blog_more\">". l(t("more"), "blog", array("title" => t("Read the latest blog entries."))) ."</div>";
$block["subject"] = t("Blogs"); $block["subject"] = t("Blogs");
} }

View File

@ -267,7 +267,7 @@ function bloggerapi_node_recent($num) {
global $user; global $user;
if (($num == 0) or ($num > 100)) $num = 50; if (($num == 0) or ($num > 100)) $num = 50;
$result = db_query_range("SELECT n.*, u.name FROM node n LEFT JOIN users u ON n.uid = u.uid WHERE n.uid = %d ORDER BY n.nid DESC", $user->uid, 0, $num); $result = db_query_range("SELECT n.*, u.name FROM {node} n LEFT JOIN {users} u ON n.uid = u.uid WHERE n.uid = %d ORDER BY n.nid DESC", $user->uid, 0, $num);
if ($result) { if ($result) {
while ($blog = db_fetch_object($result)) { while ($blog = db_fetch_object($result)) {
$body = "<title>$blog->title</title>\n". $blog->body; $body = "<title>$blog->title</title>\n". $blog->body;
@ -296,8 +296,8 @@ function bloggerapi_node_delete($nid) {
** Delete the specified node and its comments: ** Delete the specified node and its comments:
*/ */
db_query("DELETE FROM node WHERE nid = '$node->nid'"); db_query("DELETE FROM {node} WHERE nid = '$node->nid'");
db_query("DELETE FROM comments WHERE nid = '$node->nid'"); db_query("DELETE FROM {comments} WHERE nid = '$node->nid'");
watchdog("special", "$node->type: deleted '$node->title', via Blogger API"); watchdog("special", "$node->type: deleted '$node->title', via Blogger API");
$message = "Node: $node->nid, was deleted"; $message = "Node: $node->nid, was deleted";

View File

@ -86,7 +86,7 @@ function book_link($type, $node = 0, $main = 0) {
menu("admin/node/book/orphan", "orphan pages", "book_admin", $help["orphan"], 8); menu("admin/node/book/orphan", "orphan pages", "book_admin", $help["orphan"], 8);
menu("admin/node/book/help", "help", "book_help", NULL, 9); menu("admin/node/book/help", "help", "book_help", NULL, 9);
$result = db_query("SELECT n.nid, n.title FROM node n INNER JOIN book b ON n.nid = b.nid WHERE b.parent = 0 ORDER BY b.weight, n.title"); $result = db_query("SELECT n.nid, n.title FROM {node} n INNER JOIN {book} b ON n.nid = b.nid WHERE b.parent = 0 ORDER BY b.weight, n.title");
while ($book = db_fetch_object($result)) { while ($book = db_fetch_object($result)) {
menu("admin/node/book/$book->nid", "'$book->title' book", "book_admin"); menu("admin/node/book/$book->nid", "'$book->title' book", "book_admin");
} }
@ -98,7 +98,7 @@ function book_link($type, $node = 0, $main = 0) {
function book_load($node) { function book_load($node) {
global $user; global $user;
$book = db_fetch_object(db_query("SELECT format, parent, weight, log FROM book WHERE nid = %d", $node->nid)); $book = db_fetch_object(db_query("SELECT format, parent, weight, log FROM {book} WHERE nid = %d", $node->nid));
if (strstr(request_uri(), "node/edit")) { if (strstr(request_uri(), "node/edit")) {
@ -131,15 +131,15 @@ function book_load($node) {
} }
function book_insert($node) { function book_insert($node) {
db_query("INSERT INTO book (nid, format, parent, weight, log) VALUES (%d, %d, %d, %d, '%s')", $node->nid, $node->format, $node->parent, $node->weight, $node->log); db_query("INSERT INTO {book} (nid, format, parent, weight, log) VALUES (%d, %d, %d, %d, '%s')", $node->nid, $node->format, $node->parent, $node->weight, $node->log);
} }
function book_update($node) { function book_update($node) {
db_query("UPDATE book SET format = %d, parent = %d, weight = %d, log = '%s' WHERE nid = %d", $node->format, $node->parent, $node->weight, $node->log, $node->nid); db_query("UPDATE {book} SET format = %d, parent = %d, weight = %d, log = '%s' WHERE nid = %d", $node->format, $node->parent, $node->weight, $node->log, $node->nid);
} }
function book_delete(&$node) { function book_delete(&$node) {
db_query("DELETE FROM book WHERE nid = %d", $node->nid); db_query("DELETE FROM {book} WHERE nid = %d", $node->nid);
} }
function book_validate(&$node) { function book_validate(&$node) {
@ -210,24 +210,24 @@ function book_node_link($node = 0) {
} }
if ($op == t("Add to book outline")) { if ($op == t("Add to book outline")) {
db_query("INSERT INTO book (nid, parent, weight) VALUES (%d, %d, %d)", $node->nid, $edit["parent"], $edit["weight"]); db_query("INSERT INTO {book} (nid, parent, weight) VALUES (%d, %d, %d)", $node->nid, $edit["parent"], $edit["weight"]);
$output .= status(t("added the node to the book.")); $output .= status(t("added the node to the book."));
} }
if ($op == t("Update book outline")) { if ($op == t("Update book outline")) {
db_query("UPDATE book SET parent = %d, weight = %d WHERE nid = %d", $edit["parent"], $edit["weight"], $node->nid); db_query("UPDATE {book} SET parent = %d, weight = %d WHERE nid = %d", $edit["parent"], $edit["weight"], $node->nid);
$output .= status(t("updated the book outline.")); $output .= status(t("updated the book outline."));
} }
if ($op == t("Remove from book outline")) { if ($op == t("Remove from book outline")) {
db_query("DELETE FROM book WHERE nid = %d", $node->nid); db_query("DELETE FROM {book} WHERE nid = %d", $node->nid);
$output .= status(t("removed the node form the book.")); $output .= status(t("removed the node form the book."));
} }
$output .= "<h3>". t("Edit book outline for node <i>%booktitle</i>", array("%booktitle" => $node->title)) ."</h3>"; $output .= "<h3>". t("Edit book outline for node <i>%booktitle</i>", array("%booktitle" => $node->title)) ."</h3>";
if ($edit["nid"]) { if ($edit["nid"]) {
$page = db_fetch_object(db_query("SELECT * FROM book WHERE nid = %d", $node->nid)); $page = db_fetch_object(db_query("SELECT * FROM {book} WHERE nid = %d", $node->nid));
$output .= form_select(t("Parent"), "parent", $page->parent, book_toc(), t("The parent subject or category the page belongs in.")); $output .= form_select(t("Parent"), "parent", $page->parent, book_toc(), t("The parent subject or category the page belongs in."));
$output .= form_weight(t("Weight"), "weight", $node->weight, 15, t("The heavier pages will sink and the lighter pages will be positioned nearer the top.")); $output .= form_weight(t("Weight"), "weight", $node->weight, 15, t("The heavier pages will sink and the lighter pages will be positioned nearer the top."));
@ -290,7 +290,7 @@ function book_revision_load($page, $conditions = array()) {
** Return the path (call stack) to a certain book page. ** Return the path (call stack) to a certain book page.
*/ */
function book_location($node, $nodes = array()) { function book_location($node, $nodes = array()) {
$parent = db_fetch_object(db_query("SELECT n.nid, n.title, b.parent FROM node n INNER JOIN book b ON n.nid = b.nid WHERE n.nid = %d", $node->parent)); $parent = db_fetch_object(db_query("SELECT n.nid, n.title, b.parent FROM {node} n INNER JOIN {book} b ON n.nid = b.nid WHERE n.nid = %d", $node->parent));
if ($parent->title) { if ($parent->title) {
$nodes = book_location($parent, $nodes); $nodes = book_location($parent, $nodes);
array_push($nodes, $parent); array_push($nodes, $parent);
@ -299,7 +299,7 @@ function book_location($node, $nodes = array()) {
} }
function book_location_down($node, $nodes = array()) { function book_location_down($node, $nodes = array()) {
$last_direct_child = db_fetch_object(db_query("SELECT n.nid, n.title, b.parent FROM node n INNER JOIN book b ON n.nid = b.nid WHERE b.parent = %d ORDER BY b.weight DESC, n.title DESC", $node->nid)); $last_direct_child = db_fetch_object(db_query("SELECT n.nid, n.title, b.parent FROM {node} n INNER JOIN {book} b ON n.nid = b.nid WHERE b.parent = %d ORDER BY b.weight DESC, n.title DESC", $node->nid));
if ($last_direct_child) { if ($last_direct_child) {
array_push($nodes, $last_direct_child); array_push($nodes, $last_direct_child);
$nodes = book_location_down($last_direct_child, $nodes); $nodes = book_location_down($last_direct_child, $nodes);
@ -314,7 +314,7 @@ function book_prev($node) {
} }
// previous on the same level // previous on the same level
$direct_above = db_fetch_object(db_query("SELECT n.nid, n.title FROM node n INNER JOIN book b ON n.nid = b.nid WHERE b.parent = %d AND n.status = 1 AND (n.moderate = 0 OR n.revisions != '') AND (b.weight < %d OR (b.weight = %d AND n.title < '%s')) ORDER BY b.weight DESC, n.title DESC", $node->parent, $node->weight, $node->weight, $node->title)); $direct_above = db_fetch_object(db_query("SELECT n.nid, n.title FROM {node} n INNER JOIN {book} b ON n.nid = b.nid WHERE b.parent = %d AND n.status = 1 AND (n.moderate = 0 OR n.revisions != '') AND (b.weight < %d OR (b.weight = %d AND n.title < '%s')) ORDER BY b.weight DESC, n.title DESC", $node->parent, $node->weight, $node->weight, $node->title));
if ($direct_above) { if ($direct_above) {
// get last leaf of $above // get last leaf of $above
$path = book_location_down($direct_above); $path = book_location_down($direct_above);
@ -323,14 +323,14 @@ function book_prev($node) {
} }
else { else {
// direct parent // direct parent
$prev = db_fetch_object(db_query("SELECT n.nid, n.title FROM node n INNER JOIN book b ON n.nid = b.nid WHERE n.nid = %d AND n.status = 1 AND (n.moderate = 0 OR n.revisions != '')", $node->parent)); $prev = db_fetch_object(db_query("SELECT n.nid, n.title FROM {node} n INNER JOIN {book} b ON n.nid = b.nid WHERE n.nid = %d AND n.status = 1 AND (n.moderate = 0 OR n.revisions != '')", $node->parent));
return $prev; return $prev;
} }
} }
function book_next($node) { function book_next($node) {
// get first direct child // get first direct child
$child = db_fetch_object(db_query("SELECT n.nid, n.title FROM node n INNER JOIN book b ON n.nid = b.nid WHERE b.parent = %d AND n.status = 1 AND (n.moderate = 0 OR n.revisions != '') ORDER BY b.weight ASC, n.title ASC", $node->nid)); $child = db_fetch_object(db_query("SELECT n.nid, n.title FROM {node} n INNER JOIN {book} b ON n.nid = b.nid WHERE b.parent = %d AND n.status = 1 AND (n.moderate = 0 OR n.revisions != '') ORDER BY b.weight ASC, n.title ASC", $node->nid));
if ($child) { if ($child) {
return $child; return $child;
} }
@ -339,7 +339,7 @@ function book_next($node) {
array_push($path = book_location($node), $node); // path to root node including this one array_push($path = book_location($node), $node); // path to root node including this one
// loop through nodes to book root, starting with this node // loop through nodes to book root, starting with this node
while (($leaf = array_pop($path)) && count($path)) { while (($leaf = array_pop($path)) && count($path)) {
$next = db_fetch_object(db_query("SELECT n.nid, n.title FROM node n INNER JOIN book b ON n.nid = b.nid WHERE b.parent = %d AND n.status = 1 AND (n.moderate = 0 OR n.revisions != '') AND (b.weight > %d OR (b.weight = %d AND n.title > '%s')) ORDER BY b.weight ASC, n.title ASC", $leaf->parent, $leaf->weight, $leaf->weight, $leaf->title)); $next = db_fetch_object(db_query("SELECT n.nid, n.title FROM {node} n INNER JOIN {book} b ON n.nid = b.nid WHERE b.parent = %d AND n.status = 1 AND (n.moderate = 0 OR n.revisions != '') AND (b.weight > %d OR (b.weight = %d AND n.title > '%s')) ORDER BY b.weight ASC, n.title ASC", $leaf->parent, $leaf->weight, $leaf->weight, $leaf->title));
if ($next) { if ($next) {
return $next; return $next;
} }
@ -477,7 +477,7 @@ function book_toc_recurse($nid, $indent, $toc, $children) {
function book_toc($parent = 0, $indent = "", $toc = array()) { function book_toc($parent = 0, $indent = "", $toc = array()) {
$result = db_query("SELECT n.nid, n.title, b.parent FROM node n INNER JOIN book b ON n.nid = b.nid WHERE n.status = '1' ORDER BY b.weight, n.title"); $result = db_query("SELECT n.nid, n.title, b.parent FROM {node} n INNER JOIN {book} b ON n.nid = b.nid WHERE n.status = '1' ORDER BY b.weight, n.title");
while ($node = db_fetch_object($result)) { while ($node = db_fetch_object($result)) {
$list = $children[$node->parent] ? $children[$node->parent] : array(); $list = $children[$node->parent] ? $children[$node->parent] : array();
@ -525,7 +525,7 @@ function book_tree_recurse($nid, $depth, $children) {
function book_tree($parent = 0, $depth = 3) { function book_tree($parent = 0, $depth = 3) {
$result = db_query("SELECT n.nid, n.title, b.parent FROM node n INNER JOIN book b ON n.nid = b.nid WHERE n.status = '1' AND n.moderate = '0' ORDER BY b.weight, n.title"); $result = db_query("SELECT n.nid, n.title, b.parent FROM {node} n INNER JOIN {book} b ON n.nid = b.nid WHERE n.status = '1' AND n.moderate = '0' ORDER BY b.weight, n.title");
while ($node = db_fetch_object($result)) { while ($node = db_fetch_object($result)) {
$list = $children[$node->parent] ? $children[$node->parent] : array(); $list = $children[$node->parent] ? $children[$node->parent] : array();
@ -542,7 +542,7 @@ function book_tree($parent = 0, $depth = 3) {
function book_render() { function book_render() {
$result = db_query("SELECT n.nid FROM node n INNER JOIN book b ON n.nid = b.nid WHERE b.parent = 0 AND n.status = 1 AND (n.moderate = 0 OR n.revisions IS NOT NULL) ORDER BY b.weight, n.title"); $result = db_query("SELECT n.nid FROM {node} n INNER JOIN {book} b ON n.nid = b.nid WHERE b.parent = 0 AND n.status = 1 AND (n.moderate = 0 OR n.revisions IS NOT NULL) ORDER BY b.weight, n.title");
while ($page = db_fetch_object($result)) { while ($page = db_fetch_object($result)) {
// load the node: // load the node:
@ -588,7 +588,7 @@ function book_page() {
function book_print($id = "", $depth = 1) { function book_print($id = "", $depth = 1) {
global $base_url; global $base_url;
$result = db_query("SELECT n.nid FROM node n INNER JOIN book b ON n.nid = b.nid WHERE n.status = 1 AND n.nid = %d AND (n.moderate = 0 OR n.revisions IS NOT NULL) ORDER BY b.weight, n.title", $id); $result = db_query("SELECT n.nid FROM {node} n INNER JOIN book b ON n.nid = b.nid WHERE n.status = 1 AND n.nid = %d AND (n.moderate = 0 OR n.revisions IS NOT NULL) ORDER BY b.weight, n.title", $id);
while ($page = db_fetch_object($result)) { while ($page = db_fetch_object($result)) {
// load the node: // load the node:
@ -620,7 +620,7 @@ function book_print($id = "", $depth = 1) {
} }
function book_print_recurse($parent = "", $depth = 1) { function book_print_recurse($parent = "", $depth = 1) {
$result = db_query("SELECT n.nid FROM node n INNER JOIN book b ON n.nid = b.nid WHERE n.status = 1 AND b.parent = '$parent' AND (n.moderate = 0 OR n.revisions IS NOT NULL) ORDER BY b.weight, n.title"); $result = db_query("SELECT n.nid FROM {node} n INNER JOIN {book} b ON n.nid = b.nid WHERE n.status = 1 AND b.parent = '$parent' AND (n.moderate = 0 OR n.revisions IS NOT NULL) ORDER BY b.weight, n.title");
while ($page = db_fetch_object($result)) { while ($page = db_fetch_object($result)) {
// load the node: // load the node:
@ -654,7 +654,7 @@ function book_admin_view_line($node, $depth = 0) {
} }
function book_admin_view_book($nid, $depth = 1) { function book_admin_view_book($nid, $depth = 1) {
$result = db_query("SELECT n.nid FROM node n INNER JOIN book b ON n.nid = b.nid WHERE b.parent = %d ORDER BY b.weight, n.title", $nid); $result = db_query("SELECT n.nid FROM {node} n INNER JOIN {book} b ON n.nid = b.nid WHERE b.parent = %d ORDER BY b.weight, n.title", $nid);
while ($node = db_fetch_object($result)) { while ($node = db_fetch_object($result)) {
$node = node_load(array("nid" => $node->nid)); $node = node_load(array("nid" => $node->nid));
@ -693,18 +693,18 @@ function book_admin_save($nid, $edit = array()) {
** Check to see whether the title needs updating: ** Check to see whether the title needs updating:
*/ */
$title = db_result(db_query("SELECT title FROM node WHERE nid = %d", $nid)); $title = db_result(db_query("SELECT title FROM {node} WHERE nid = %d", $nid));
if ($title != $value["title"]) { if ($title != $value["title"]) {
db_query("UPDATE node SET title = '%s' WHERE nid = %d", $value["title"], $nid); db_query("UPDATE {node} SET title = '%s' WHERE nid = %d", $value["title"], $nid);
} }
/* /*
** Check to see whether the weight needs updating: ** Check to see whether the weight needs updating:
*/ */
$weight = db_result(db_query("SELECT weight FROM book WHERE nid = %d", $nid)); $weight = db_result(db_query("SELECT weight FROM {book} WHERE nid = %d", $nid));
if ($weight != $value["weight"]) { if ($weight != $value["weight"]) {
db_query("UPDATE book SET weight = %d WHERE nid = %d", $value["weight"], $nid); db_query("UPDATE {book} SET weight = %d WHERE nid = %d", $value["weight"], $nid);
} }
} }
@ -717,7 +717,7 @@ function book_admin_save($nid, $edit = array()) {
function book_admin_orphan() { function book_admin_orphan() {
$result = db_query("SELECT n.nid, n.title, n.status, b.parent FROM node n INNER JOIN book b ON n.nid = b.nid WHERE n.type = 'book'"); $result = db_query("SELECT n.nid, n.title, n.status, b.parent FROM {node} n INNER JOIN {book} b ON n.nid = b.nid WHERE n.type = 'book'");
while ($page = db_fetch_object($result)) { while ($page = db_fetch_object($result)) {
$pages[$page->nid] = $page; $pages[$page->nid] = $page;

View File

@ -86,7 +86,7 @@ function book_link($type, $node = 0, $main = 0) {
menu("admin/node/book/orphan", "orphan pages", "book_admin", $help["orphan"], 8); menu("admin/node/book/orphan", "orphan pages", "book_admin", $help["orphan"], 8);
menu("admin/node/book/help", "help", "book_help", NULL, 9); menu("admin/node/book/help", "help", "book_help", NULL, 9);
$result = db_query("SELECT n.nid, n.title FROM node n INNER JOIN book b ON n.nid = b.nid WHERE b.parent = 0 ORDER BY b.weight, n.title"); $result = db_query("SELECT n.nid, n.title FROM {node} n INNER JOIN {book} b ON n.nid = b.nid WHERE b.parent = 0 ORDER BY b.weight, n.title");
while ($book = db_fetch_object($result)) { while ($book = db_fetch_object($result)) {
menu("admin/node/book/$book->nid", "'$book->title' book", "book_admin"); menu("admin/node/book/$book->nid", "'$book->title' book", "book_admin");
} }
@ -98,7 +98,7 @@ function book_link($type, $node = 0, $main = 0) {
function book_load($node) { function book_load($node) {
global $user; global $user;
$book = db_fetch_object(db_query("SELECT format, parent, weight, log FROM book WHERE nid = %d", $node->nid)); $book = db_fetch_object(db_query("SELECT format, parent, weight, log FROM {book} WHERE nid = %d", $node->nid));
if (strstr(request_uri(), "node/edit")) { if (strstr(request_uri(), "node/edit")) {
@ -131,15 +131,15 @@ function book_load($node) {
} }
function book_insert($node) { function book_insert($node) {
db_query("INSERT INTO book (nid, format, parent, weight, log) VALUES (%d, %d, %d, %d, '%s')", $node->nid, $node->format, $node->parent, $node->weight, $node->log); db_query("INSERT INTO {book} (nid, format, parent, weight, log) VALUES (%d, %d, %d, %d, '%s')", $node->nid, $node->format, $node->parent, $node->weight, $node->log);
} }
function book_update($node) { function book_update($node) {
db_query("UPDATE book SET format = %d, parent = %d, weight = %d, log = '%s' WHERE nid = %d", $node->format, $node->parent, $node->weight, $node->log, $node->nid); db_query("UPDATE {book} SET format = %d, parent = %d, weight = %d, log = '%s' WHERE nid = %d", $node->format, $node->parent, $node->weight, $node->log, $node->nid);
} }
function book_delete(&$node) { function book_delete(&$node) {
db_query("DELETE FROM book WHERE nid = %d", $node->nid); db_query("DELETE FROM {book} WHERE nid = %d", $node->nid);
} }
function book_validate(&$node) { function book_validate(&$node) {
@ -210,24 +210,24 @@ function book_node_link($node = 0) {
} }
if ($op == t("Add to book outline")) { if ($op == t("Add to book outline")) {
db_query("INSERT INTO book (nid, parent, weight) VALUES (%d, %d, %d)", $node->nid, $edit["parent"], $edit["weight"]); db_query("INSERT INTO {book} (nid, parent, weight) VALUES (%d, %d, %d)", $node->nid, $edit["parent"], $edit["weight"]);
$output .= status(t("added the node to the book.")); $output .= status(t("added the node to the book."));
} }
if ($op == t("Update book outline")) { if ($op == t("Update book outline")) {
db_query("UPDATE book SET parent = %d, weight = %d WHERE nid = %d", $edit["parent"], $edit["weight"], $node->nid); db_query("UPDATE {book} SET parent = %d, weight = %d WHERE nid = %d", $edit["parent"], $edit["weight"], $node->nid);
$output .= status(t("updated the book outline.")); $output .= status(t("updated the book outline."));
} }
if ($op == t("Remove from book outline")) { if ($op == t("Remove from book outline")) {
db_query("DELETE FROM book WHERE nid = %d", $node->nid); db_query("DELETE FROM {book} WHERE nid = %d", $node->nid);
$output .= status(t("removed the node form the book.")); $output .= status(t("removed the node form the book."));
} }
$output .= "<h3>". t("Edit book outline for node <i>%booktitle</i>", array("%booktitle" => $node->title)) ."</h3>"; $output .= "<h3>". t("Edit book outline for node <i>%booktitle</i>", array("%booktitle" => $node->title)) ."</h3>";
if ($edit["nid"]) { if ($edit["nid"]) {
$page = db_fetch_object(db_query("SELECT * FROM book WHERE nid = %d", $node->nid)); $page = db_fetch_object(db_query("SELECT * FROM {book} WHERE nid = %d", $node->nid));
$output .= form_select(t("Parent"), "parent", $page->parent, book_toc(), t("The parent subject or category the page belongs in.")); $output .= form_select(t("Parent"), "parent", $page->parent, book_toc(), t("The parent subject or category the page belongs in."));
$output .= form_weight(t("Weight"), "weight", $node->weight, 15, t("The heavier pages will sink and the lighter pages will be positioned nearer the top.")); $output .= form_weight(t("Weight"), "weight", $node->weight, 15, t("The heavier pages will sink and the lighter pages will be positioned nearer the top."));
@ -290,7 +290,7 @@ function book_revision_load($page, $conditions = array()) {
** Return the path (call stack) to a certain book page. ** Return the path (call stack) to a certain book page.
*/ */
function book_location($node, $nodes = array()) { function book_location($node, $nodes = array()) {
$parent = db_fetch_object(db_query("SELECT n.nid, n.title, b.parent FROM node n INNER JOIN book b ON n.nid = b.nid WHERE n.nid = %d", $node->parent)); $parent = db_fetch_object(db_query("SELECT n.nid, n.title, b.parent FROM {node} n INNER JOIN {book} b ON n.nid = b.nid WHERE n.nid = %d", $node->parent));
if ($parent->title) { if ($parent->title) {
$nodes = book_location($parent, $nodes); $nodes = book_location($parent, $nodes);
array_push($nodes, $parent); array_push($nodes, $parent);
@ -299,7 +299,7 @@ function book_location($node, $nodes = array()) {
} }
function book_location_down($node, $nodes = array()) { function book_location_down($node, $nodes = array()) {
$last_direct_child = db_fetch_object(db_query("SELECT n.nid, n.title, b.parent FROM node n INNER JOIN book b ON n.nid = b.nid WHERE b.parent = %d ORDER BY b.weight DESC, n.title DESC", $node->nid)); $last_direct_child = db_fetch_object(db_query("SELECT n.nid, n.title, b.parent FROM {node} n INNER JOIN {book} b ON n.nid = b.nid WHERE b.parent = %d ORDER BY b.weight DESC, n.title DESC", $node->nid));
if ($last_direct_child) { if ($last_direct_child) {
array_push($nodes, $last_direct_child); array_push($nodes, $last_direct_child);
$nodes = book_location_down($last_direct_child, $nodes); $nodes = book_location_down($last_direct_child, $nodes);
@ -314,7 +314,7 @@ function book_prev($node) {
} }
// previous on the same level // previous on the same level
$direct_above = db_fetch_object(db_query("SELECT n.nid, n.title FROM node n INNER JOIN book b ON n.nid = b.nid WHERE b.parent = %d AND n.status = 1 AND (n.moderate = 0 OR n.revisions != '') AND (b.weight < %d OR (b.weight = %d AND n.title < '%s')) ORDER BY b.weight DESC, n.title DESC", $node->parent, $node->weight, $node->weight, $node->title)); $direct_above = db_fetch_object(db_query("SELECT n.nid, n.title FROM {node} n INNER JOIN {book} b ON n.nid = b.nid WHERE b.parent = %d AND n.status = 1 AND (n.moderate = 0 OR n.revisions != '') AND (b.weight < %d OR (b.weight = %d AND n.title < '%s')) ORDER BY b.weight DESC, n.title DESC", $node->parent, $node->weight, $node->weight, $node->title));
if ($direct_above) { if ($direct_above) {
// get last leaf of $above // get last leaf of $above
$path = book_location_down($direct_above); $path = book_location_down($direct_above);
@ -323,14 +323,14 @@ function book_prev($node) {
} }
else { else {
// direct parent // direct parent
$prev = db_fetch_object(db_query("SELECT n.nid, n.title FROM node n INNER JOIN book b ON n.nid = b.nid WHERE n.nid = %d AND n.status = 1 AND (n.moderate = 0 OR n.revisions != '')", $node->parent)); $prev = db_fetch_object(db_query("SELECT n.nid, n.title FROM {node} n INNER JOIN {book} b ON n.nid = b.nid WHERE n.nid = %d AND n.status = 1 AND (n.moderate = 0 OR n.revisions != '')", $node->parent));
return $prev; return $prev;
} }
} }
function book_next($node) { function book_next($node) {
// get first direct child // get first direct child
$child = db_fetch_object(db_query("SELECT n.nid, n.title FROM node n INNER JOIN book b ON n.nid = b.nid WHERE b.parent = %d AND n.status = 1 AND (n.moderate = 0 OR n.revisions != '') ORDER BY b.weight ASC, n.title ASC", $node->nid)); $child = db_fetch_object(db_query("SELECT n.nid, n.title FROM {node} n INNER JOIN {book} b ON n.nid = b.nid WHERE b.parent = %d AND n.status = 1 AND (n.moderate = 0 OR n.revisions != '') ORDER BY b.weight ASC, n.title ASC", $node->nid));
if ($child) { if ($child) {
return $child; return $child;
} }
@ -339,7 +339,7 @@ function book_next($node) {
array_push($path = book_location($node), $node); // path to root node including this one array_push($path = book_location($node), $node); // path to root node including this one
// loop through nodes to book root, starting with this node // loop through nodes to book root, starting with this node
while (($leaf = array_pop($path)) && count($path)) { while (($leaf = array_pop($path)) && count($path)) {
$next = db_fetch_object(db_query("SELECT n.nid, n.title FROM node n INNER JOIN book b ON n.nid = b.nid WHERE b.parent = %d AND n.status = 1 AND (n.moderate = 0 OR n.revisions != '') AND (b.weight > %d OR (b.weight = %d AND n.title > '%s')) ORDER BY b.weight ASC, n.title ASC", $leaf->parent, $leaf->weight, $leaf->weight, $leaf->title)); $next = db_fetch_object(db_query("SELECT n.nid, n.title FROM {node} n INNER JOIN {book} b ON n.nid = b.nid WHERE b.parent = %d AND n.status = 1 AND (n.moderate = 0 OR n.revisions != '') AND (b.weight > %d OR (b.weight = %d AND n.title > '%s')) ORDER BY b.weight ASC, n.title ASC", $leaf->parent, $leaf->weight, $leaf->weight, $leaf->title));
if ($next) { if ($next) {
return $next; return $next;
} }
@ -477,7 +477,7 @@ function book_toc_recurse($nid, $indent, $toc, $children) {
function book_toc($parent = 0, $indent = "", $toc = array()) { function book_toc($parent = 0, $indent = "", $toc = array()) {
$result = db_query("SELECT n.nid, n.title, b.parent FROM node n INNER JOIN book b ON n.nid = b.nid WHERE n.status = '1' ORDER BY b.weight, n.title"); $result = db_query("SELECT n.nid, n.title, b.parent FROM {node} n INNER JOIN {book} b ON n.nid = b.nid WHERE n.status = '1' ORDER BY b.weight, n.title");
while ($node = db_fetch_object($result)) { while ($node = db_fetch_object($result)) {
$list = $children[$node->parent] ? $children[$node->parent] : array(); $list = $children[$node->parent] ? $children[$node->parent] : array();
@ -525,7 +525,7 @@ function book_tree_recurse($nid, $depth, $children) {
function book_tree($parent = 0, $depth = 3) { function book_tree($parent = 0, $depth = 3) {
$result = db_query("SELECT n.nid, n.title, b.parent FROM node n INNER JOIN book b ON n.nid = b.nid WHERE n.status = '1' AND n.moderate = '0' ORDER BY b.weight, n.title"); $result = db_query("SELECT n.nid, n.title, b.parent FROM {node} n INNER JOIN {book} b ON n.nid = b.nid WHERE n.status = '1' AND n.moderate = '0' ORDER BY b.weight, n.title");
while ($node = db_fetch_object($result)) { while ($node = db_fetch_object($result)) {
$list = $children[$node->parent] ? $children[$node->parent] : array(); $list = $children[$node->parent] ? $children[$node->parent] : array();
@ -542,7 +542,7 @@ function book_tree($parent = 0, $depth = 3) {
function book_render() { function book_render() {
$result = db_query("SELECT n.nid FROM node n INNER JOIN book b ON n.nid = b.nid WHERE b.parent = 0 AND n.status = 1 AND (n.moderate = 0 OR n.revisions IS NOT NULL) ORDER BY b.weight, n.title"); $result = db_query("SELECT n.nid FROM {node} n INNER JOIN {book} b ON n.nid = b.nid WHERE b.parent = 0 AND n.status = 1 AND (n.moderate = 0 OR n.revisions IS NOT NULL) ORDER BY b.weight, n.title");
while ($page = db_fetch_object($result)) { while ($page = db_fetch_object($result)) {
// load the node: // load the node:
@ -588,7 +588,7 @@ function book_page() {
function book_print($id = "", $depth = 1) { function book_print($id = "", $depth = 1) {
global $base_url; global $base_url;
$result = db_query("SELECT n.nid FROM node n INNER JOIN book b ON n.nid = b.nid WHERE n.status = 1 AND n.nid = %d AND (n.moderate = 0 OR n.revisions IS NOT NULL) ORDER BY b.weight, n.title", $id); $result = db_query("SELECT n.nid FROM {node} n INNER JOIN book b ON n.nid = b.nid WHERE n.status = 1 AND n.nid = %d AND (n.moderate = 0 OR n.revisions IS NOT NULL) ORDER BY b.weight, n.title", $id);
while ($page = db_fetch_object($result)) { while ($page = db_fetch_object($result)) {
// load the node: // load the node:
@ -620,7 +620,7 @@ function book_print($id = "", $depth = 1) {
} }
function book_print_recurse($parent = "", $depth = 1) { function book_print_recurse($parent = "", $depth = 1) {
$result = db_query("SELECT n.nid FROM node n INNER JOIN book b ON n.nid = b.nid WHERE n.status = 1 AND b.parent = '$parent' AND (n.moderate = 0 OR n.revisions IS NOT NULL) ORDER BY b.weight, n.title"); $result = db_query("SELECT n.nid FROM {node} n INNER JOIN {book} b ON n.nid = b.nid WHERE n.status = 1 AND b.parent = '$parent' AND (n.moderate = 0 OR n.revisions IS NOT NULL) ORDER BY b.weight, n.title");
while ($page = db_fetch_object($result)) { while ($page = db_fetch_object($result)) {
// load the node: // load the node:
@ -654,7 +654,7 @@ function book_admin_view_line($node, $depth = 0) {
} }
function book_admin_view_book($nid, $depth = 1) { function book_admin_view_book($nid, $depth = 1) {
$result = db_query("SELECT n.nid FROM node n INNER JOIN book b ON n.nid = b.nid WHERE b.parent = %d ORDER BY b.weight, n.title", $nid); $result = db_query("SELECT n.nid FROM {node} n INNER JOIN {book} b ON n.nid = b.nid WHERE b.parent = %d ORDER BY b.weight, n.title", $nid);
while ($node = db_fetch_object($result)) { while ($node = db_fetch_object($result)) {
$node = node_load(array("nid" => $node->nid)); $node = node_load(array("nid" => $node->nid));
@ -693,18 +693,18 @@ function book_admin_save($nid, $edit = array()) {
** Check to see whether the title needs updating: ** Check to see whether the title needs updating:
*/ */
$title = db_result(db_query("SELECT title FROM node WHERE nid = %d", $nid)); $title = db_result(db_query("SELECT title FROM {node} WHERE nid = %d", $nid));
if ($title != $value["title"]) { if ($title != $value["title"]) {
db_query("UPDATE node SET title = '%s' WHERE nid = %d", $value["title"], $nid); db_query("UPDATE {node} SET title = '%s' WHERE nid = %d", $value["title"], $nid);
} }
/* /*
** Check to see whether the weight needs updating: ** Check to see whether the weight needs updating:
*/ */
$weight = db_result(db_query("SELECT weight FROM book WHERE nid = %d", $nid)); $weight = db_result(db_query("SELECT weight FROM {book} WHERE nid = %d", $nid));
if ($weight != $value["weight"]) { if ($weight != $value["weight"]) {
db_query("UPDATE book SET weight = %d WHERE nid = %d", $value["weight"], $nid); db_query("UPDATE {book} SET weight = %d WHERE nid = %d", $value["weight"], $nid);
} }
} }
@ -717,7 +717,7 @@ function book_admin_save($nid, $edit = array()) {
function book_admin_orphan() { function book_admin_orphan() {
$result = db_query("SELECT n.nid, n.title, n.status, b.parent FROM node n INNER JOIN book b ON n.nid = b.nid WHERE n.type = 'book'"); $result = db_query("SELECT n.nid, n.title, n.status, b.parent FROM {node} n INNER JOIN {book} b ON n.nid = b.nid WHERE n.type = 'book'");
while ($page = db_fetch_object($result)) { while ($page = db_fetch_object($result)) {
$pages[$page->nid] = $page; $pages[$page->nid] = $page;

View File

@ -23,7 +23,7 @@ function cloud_system($field){
} }
function cloud_cron() { function cloud_cron() {
$result = db_query("SELECT * FROM site WHERE checked = 0 OR checked + refresh < %d", time()); $result = db_query("SELECT * FROM {site} WHERE checked = 0 OR checked + refresh < %d", time());
while ($site = db_fetch_array($result)) { while ($site = db_fetch_array($result)) {
cloud_update($site); cloud_update($site);
@ -78,10 +78,10 @@ function cloud_update($site) {
} }
if (abs($site["size"] - strlen($data)) >= $site["threshold"]) { if (abs($site["size"] - strlen($data)) >= $site["threshold"]) {
db_query("UPDATE site SET size = %d, changed = %d, checked = %d WHERE link = '%s'", strlen($data), time(), time(), $site["link"]); db_query("UPDATE {site} SET size = %d, changed = %d, checked = %d WHERE link = '%s'", strlen($data), time(), time(), $site["link"]);
} }
else { else {
db_query("UPDATE site SET checked = %d WHERE link = '%s'", time(), $site["link"]); db_query("UPDATE {site} SET checked = %d WHERE link = '%s'", time(), $site["link"]);
} }
fclose($fp); fclose($fp);
@ -113,23 +113,23 @@ function cloud_form($edit = array()) {
} }
function cloud_get_site($sid) { function cloud_get_site($sid) {
return db_fetch_array(db_query("SELECT * FROM site WHERE sid = %d", $sid)); return db_fetch_array(db_query("SELECT * FROM {site} WHERE sid = %d", $sid));
} }
function cloud_save($edit) { function cloud_save($edit) {
if ($edit["sid"] && $edit["name"]) { if ($edit["sid"] && $edit["name"]) {
db_query("UPDATE site SET name = '%s', link = '%s', feed = '%s', refresh = %d, threshold = %d WHERE sid = %d", $edit["name"], $edit["link"], $edit["feed"], $edit["refresh"], $edit["threshold"], $edit["sid"]); db_query("UPDATE {site} SET name = '%s', link = '%s', feed = '%s', refresh = %d, threshold = %d WHERE sid = %d", $edit["name"], $edit["link"], $edit["feed"], $edit["refresh"], $edit["threshold"], $edit["sid"]);
} }
else if ($edit["sid"]) { else if ($edit["sid"]) {
db_query("DELETE FROM site WHERE sid = %d", $edit["sid"]); db_query("DELETE FROM {site} WHERE sid = %d", $edit["sid"]);
} }
else { else {
db_query("INSERT INTO site (name, link, feed, refresh, threshold) VALUES ('%s', '%s', '%s', %d, %d)", $edit["name"], $edit["link"], $edit["feed"], $edit["refresh"], $edit["threshold"]); db_query("INSERT INTO {site} (name, link, feed, refresh, threshold) VALUES ('%s', '%s', '%s', %d, %d)", $edit["name"], $edit["link"], $edit["feed"], $edit["refresh"], $edit["threshold"]);
} }
} }
function cloud_display() { function cloud_display() {
$result = db_query("SELECT * FROM site ORDER BY name"); $result = db_query("SELECT * FROM {site} ORDER BY name");
$header = array(t("site"), t("last update"), array("data" => t("operations"), "colspan" => 2)); $header = array(t("site"), t("last update"), array("data" => t("operations"), "colspan" => 2));
while ($site = db_fetch_object($result)) { while ($site = db_fetch_object($result)) {
@ -140,7 +140,7 @@ function cloud_display() {
} }
function cloud_list($limit = 10) { function cloud_list($limit = 10) {
$result = db_query_range("SELECT * FROM site WHERE changed > ". (time() - 604800) ." ORDER BY changed DESC", 0, $limit); $result = db_query_range("SELECT * FROM {site} WHERE changed > ". (time() - 604800) ." ORDER BY changed DESC", 0, $limit);
$hour = -1; $hour = -1;
$list = -1; $list = -1;

View File

@ -84,7 +84,7 @@ function comment_settings() {
$output .= form_select(t("Default display order"), "comment_default_order", variable_get("comment_default_order", 1), $corder, t("The default sorting for new users and anonymous users while viewing comments. These users may change their view using the comment control panel. For registered users, this change is remembered as a persistent user preference.")); $output .= form_select(t("Default display order"), "comment_default_order", variable_get("comment_default_order", 1), $corder, t("The default sorting for new users and anonymous users while viewing comments. These users may change their view using the comment control panel. For registered users, this change is remembered as a persistent user preference."));
$output .= form_textfield(t("Default comments per page"), "comment_default_per_page", variable_get("comment_default_per_page", "50"), 5, 5, t("Default number of comments for each page; more comments are distributed in several pages.")); $output .= form_textfield(t("Default comments per page"), "comment_default_per_page", variable_get("comment_default_per_page", "50"), 5, 5, t("Default number of comments for each page; more comments are distributed in several pages."));
$result = db_query("SELECT fid, filter FROM moderation_filters"); $result = db_query("SELECT fid, filter FROM {moderation_filters} ");
while ($filter = db_fetch_object($result)) { while ($filter = db_fetch_object($result)) {
$thresholds[$filter->fid] = ($filter->filter); $thresholds[$filter->fid] = ($filter->filter);
} }
@ -170,7 +170,7 @@ function comment_form($edit) {
function comment_edit($cid) { function comment_edit($cid) {
global $user; global $user;
$comment = db_fetch_object(db_query("SELECT c.*, u.uid, u.name, u.data FROM comments c LEFT JOIN users u ON c.uid = u.uid WHERE c.cid = %d AND c.status != 2", $cid)); $comment = db_fetch_object(db_query("SELECT c.*, u.uid, u.name, u.data FROM {comments} c LEFT JOIN {users} u ON c.uid = u.uid WHERE c.cid = %d AND c.status != 2", $cid));
if (comment_access("edit", $comment)) { if (comment_access("edit", $comment)) {
comment_preview(object2array($comment)); comment_preview(object2array($comment));
@ -187,7 +187,7 @@ function comment_reply($pid, $nid) {
*/ */
if ($pid) { if ($pid) {
$comment = db_fetch_object(db_query("SELECT c.*, u.uid, u.name, u.data FROM comments c LEFT JOIN users u ON c.uid = u.uid WHERE c.cid = %d AND c.status = 0", $pid)); $comment = db_fetch_object(db_query("SELECT c.*, u.uid, u.name, u.data FROM {comments} c LEFT JOIN {users} u ON c.uid = u.uid WHERE c.cid = %d AND c.status = 0", $pid));
comment_view($comment); comment_view($comment);
} }
else { else {
@ -238,7 +238,7 @@ function comment_preview($edit) {
theme("box", t("Reply"), comment_form($edit)); theme("box", t("Reply"), comment_form($edit));
if ($edit["pid"]) { if ($edit["pid"]) {
$comment = db_fetch_object(db_query("SELECT c.*, u.uid, u.name, u.data FROM comments c LEFT JOIN users u ON c.uid = u.uid WHERE c.cid = %d AND c.status = 0", $edit["pid"])); $comment = db_fetch_object(db_query("SELECT c.*, u.uid, u.name, u.data FROM {comments} c LEFT JOIN {users} u ON c.uid = u.uid WHERE c.cid = %d AND c.status = 0", $edit["pid"]));
comment_view($comment); comment_view($comment);
} }
else { else {
@ -276,7 +276,7 @@ function comment_post($edit) {
** validated/filtered data to perform such check. ** validated/filtered data to perform such check.
*/ */
$duplicate = db_result(db_query("SELECT COUNT(cid) FROM comments WHERE pid = %d AND nid = %d AND subject = '%s' AND comment = '%s'", $edit["pid"], $edit["nid"], $edit["subject"], $edit["comment"]), 0); $duplicate = db_result(db_query("SELECT COUNT(cid) FROM {comments} WHERE pid = %d AND nid = %d AND subject = '%s' AND comment = '%s'", $edit["pid"], $edit["nid"], $edit["subject"], $edit["comment"]), 0);
if ($duplicate != 0) { if ($duplicate != 0) {
watchdog("warning", "comment: duplicate '". $edit["subject"] ."'"); watchdog("warning", "comment: duplicate '". $edit["subject"] ."'");
@ -292,7 +292,7 @@ function comment_post($edit) {
** user. ** user.
*/ */
db_query("UPDATE comments SET subject = '%s', comment = '%s' WHERE cid = %d AND uid = '$user->uid'", $edit["subject"], $edit["comment"], $edit["cid"]); db_query("UPDATE {comments} SET subject = '%s', comment = '%s' WHERE cid = %d AND uid = '$user->uid'", $edit["subject"], $edit["comment"], $edit["cid"]);
/* /*
** Fire a hook ** Fire a hook
@ -325,7 +325,7 @@ function comment_post($edit) {
$edit["cid"] = db_next_id("comments_cid"); $edit["cid"] = db_next_id("comments_cid");
db_query("INSERT INTO comments (cid, nid, pid, uid, subject, comment, hostname, timestamp, status, score, users) VALUES (%d, %d, %d, %d, '%s', '%s', '%s', %d, %d, %d, '%s')", $edit["cid"], $edit["nid"], $edit["pid"], $user->uid, $edit["subject"], $edit["comment"], getenv("REMOTE_ADDR"), time(), $status, $score, $users); db_query("INSERT INTO {comments} (cid, nid, pid, uid, subject, comment, hostname, timestamp, status, score, users) VALUES (%d, %d, %d, %d, '%s', '%s', '%s', %d, %d, %d, '%s')", $edit["cid"], $edit["nid"], $edit["pid"], $user->uid, $edit["subject"], $edit["comment"], getenv("REMOTE_ADDR"), time(), $status, $score, $users);
/* /*
** Tell the other modules a new comment has been submitted: ** Tell the other modules a new comment has been submitted:
@ -459,7 +459,7 @@ function comment_render($node, $cid = 0) {
if (empty($threshold)) { if (empty($threshold)) {
$threshold = $user->uid ? $user->threshold : variable_get("comment_default_threshold", 0); $threshold = $user->uid ? $user->threshold : variable_get("comment_default_threshold", 0);
} }
$threshold_min = db_result(db_query("SELECT minimum FROM moderation_filters WHERE fid = %d", $threshold)); $threshold_min = db_result(db_query("SELECT minimum FROM {moderation_filters} WHERE fid = %d", $threshold));
if (empty($comment_page)) { if (empty($comment_page)) {
$comment_page = 1; $comment_page = 1;
@ -481,7 +481,7 @@ function comment_render($node, $cid = 0) {
print "<form method=\"post\" action=\"". url("comment") ."\"><div>\n"; print "<form method=\"post\" action=\"". url("comment") ."\"><div>\n";
print form_hidden("nid", $nid); print form_hidden("nid", $nid);
$result = db_query("SELECT c.cid, c.pid, c.nid, c.subject, c.comment, c.timestamp, u.uid, u.name, u.data, c.score, c.users FROM comments c LEFT JOIN users u ON c.uid = u.uid WHERE c.cid = %d AND c.status = 0 GROUP BY c.cid, c.pid, c.nid, c.subject, c.comment, c.timestamp, u.uid, u.name, u.data, c.score, c.users", $cid); $result = db_query("SELECT c.cid, c.pid, c.nid, c.subject, c.comment, c.timestamp, u.uid, u.name, u.data, c.score, c.users FROM {comments} c LEFT JOIN {users} u ON c.uid = u.uid WHERE c.cid = %d AND c.status = 0 GROUP BY c.cid, c.pid, c.nid, c.subject, c.comment, c.timestamp, u.uid, u.name, u.data, c.score, c.users", $cid);
if ($comment = db_fetch_object($result)) { if ($comment = db_fetch_object($result)) {
comment_view($comment, comment_links($comment)); comment_view($comment, comment_links($comment));
@ -498,7 +498,7 @@ function comment_render($node, $cid = 0) {
** Multiple comments view ** Multiple comments view
*/ */
$query .= "SELECT c.cid as cid, c.pid, c.nid, c.subject, c.comment, c.timestamp, u.uid, u.name, u.data, c.score, c.users FROM comments c LEFT JOIN users u ON c.uid = u.uid WHERE c.nid = '". check_query($nid) ."' AND c.status = 0"; $query .= "SELECT c.cid as cid, c.pid, c.nid, c.subject, c.comment, c.timestamp, u.uid, u.name, u.data, c.score, c.users FROM {comments} c LEFT JOIN {users} u ON c.uid = u.uid WHERE c.nid = '". check_query($nid) ."' AND c.status = 0";
$query .= " GROUP BY c.cid, c.pid, c.nid, c.subject, c.comment, c.timestamp, u.uid, u.name, u.data, c.score, c.users"; $query .= " GROUP BY c.cid, c.pid, c.nid, c.subject, c.comment, c.timestamp, u.uid, u.name, u.data, c.score, c.users";
@ -809,7 +809,7 @@ function comment_node_link($node) {
** Edit comments: ** Edit comments:
*/ */
$result = db_query("SELECT c.cid, c.subject, u.uid, u.name FROM comments c LEFT JOIN users u ON u.uid = c.uid WHERE nid = %d AND c.status = 0 ORDER BY c.timestamp", $node->nid); $result = db_query("SELECT c.cid, c.subject, u.uid, u.name FROM {comments} c LEFT JOIN {users} u ON u.uid = c.uid WHERE nid = %d AND c.status = 0 ORDER BY c.timestamp", $node->nid);
$header = array(t("title"), t("author"), array("data" => t("operations"), "colspan" => 3)); $header = array(t("title"), t("author"), array("data" => t("operations"), "colspan" => 3));
@ -829,7 +829,7 @@ function comment_node_link($node) {
function comment_admin_edit($id) { function comment_admin_edit($id) {
$result = db_query("SELECT c.*, u.name, u.uid FROM comments c LEFT JOIN users u ON c.uid = u.uid WHERE c.cid = %d AND c.status != 2", $id); $result = db_query("SELECT c.*, u.name, u.uid FROM {comments} c LEFT JOIN {users} u ON c.uid = u.uid WHERE c.cid = %d AND c.status != 2", $id);
$comment = db_fetch_object($result); $comment = db_fetch_object($result);
// if a comment is "deleted", it's deleted // if a comment is "deleted", it's deleted
@ -849,7 +849,7 @@ function comment_admin_edit($id) {
function comment_delete($edit) { function comment_delete($edit) {
if ($edit["confirm"]) { if ($edit["confirm"]) {
db_query("UPDATE comments SET status = 2 WHERE cid = %d", $edit["cid"]); db_query("UPDATE {comments} SET status = 2 WHERE cid = %d", $edit["cid"]);
watchdog("special", "comment: deleted comment #". $edit["cid"]); watchdog("special", "comment: deleted comment #". $edit["cid"]);
$output = "deleted comment."; $output = "deleted comment.";
} }
@ -865,14 +865,14 @@ function comment_delete($edit) {
} }
function comment_save($id, $edit) { function comment_save($id, $edit) {
db_query("UPDATE comments SET subject = '%s', comment = '%s', status = %d WHERE cid = %d", $edit["subject"], $edit["comment"], $edit["status"], $id); db_query("UPDATE {comments} SET subject = '%s', comment = '%s', status = %d WHERE cid = %d", $edit["subject"], $edit["comment"], $edit["status"], $id);
watchdog("special", "comment: modified '". $edit["subject"] ."'"); watchdog("special", "comment: modified '". $edit["subject"] ."'");
return "updated comment."; return "updated comment.";
} }
function comment_admin_overview($status = 0) { function comment_admin_overview($status = 0) {
$result = pager_query("SELECT c.*, u.name, u.uid FROM comments c LEFT JOIN users u ON u.uid = c.uid WHERE c.status = '". check_query($status). "' ORDER BY c.timestamp DESC", 50); $result = pager_query("SELECT c.*, u.name, u.uid FROM {comments} c LEFT JOIN {users} u ON u.uid = c.uid WHERE c.status = '". check_query($status). "' ORDER BY c.timestamp DESC", 50);
$header = array(t("subject"), t("author"), t("status"), array("data" => t("operations"), "colspan" => 2)); $header = array(t("subject"), t("author"), t("status"), array("data" => t("operations"), "colspan" => 2));
while ($comment = db_fetch_object($result)) { while ($comment = db_fetch_object($result)) {
@ -891,29 +891,29 @@ function comment_mod_matrix($edit) {
$output .= "<h3>Moderators/vote values matrix</h3>"; $output .= "<h3>Moderators/vote values matrix</h3>";
if ($edit) { if ($edit) {
db_query("DELETE FROM moderation_roles"); db_query("DELETE FROM {moderation_roles} ");
foreach ($edit as $role_id => $votes) { foreach ($edit as $role_id => $votes) {
foreach ($votes as $mid => $value) { foreach ($votes as $mid => $value) {
$sql[] = "('$mid', '$role_id', '". ($value ? $value : 0 ) ."')"; $sql[] = "('$mid', '$role_id', '". ($value ? $value : 0 ) ."')";
} }
} }
db_query("INSERT INTO moderation_roles (mid, rid, value) VALUES ". implode(", ", $sql)); db_query("INSERT INTO {moderation_roles} (mid, rid, value) VALUES ". implode(", ", $sql));
} }
$result = db_query("SELECT r.rid, r.name FROM role r, permission p WHERE r.rid = p.rid AND p.perm LIKE '%moderate comments%'"); $result = db_query("SELECT r.rid, r.name FROM {role} r, {permission} p WHERE r.rid = p.rid AND p.perm LIKE '%moderate comments%'");
$role_names = array(); $role_names = array();
while ($role = db_fetch_object($result)) { while ($role = db_fetch_object($result)) {
$role_names[$role->rid] = $role->name; $role_names[$role->rid] = $role->name;
} }
$result = db_query("SELECT rid, mid, value FROM moderation_roles"); $result = db_query("SELECT rid, mid, value FROM {moderation_roles} ");
while ($role = db_fetch_object($result)) { while ($role = db_fetch_object($result)) {
$mod_roles[$role->rid][$role->mid] = $role->value; $mod_roles[$role->rid][$role->mid] = $role->value;
} }
$header = array_merge(array(t("votes")), array_values($role_names)); $header = array_merge(array(t("votes")), array_values($role_names));
$result = db_query("SELECT mid, vote FROM moderation_votes ORDER BY weight"); $result = db_query("SELECT mid, vote FROM {moderation_votes} ORDER BY weight");
while ($vote = db_fetch_object($result)) { while ($vote = db_fetch_object($result)) {
$row = array($vote->vote); $row = array($vote->vote);
foreach (array_keys($role_names) as $rid) { foreach (array_keys($role_names) as $rid) {
@ -937,7 +937,7 @@ function comment_mod_roles($edit) {
$start_values = variable_get("comment_roles", array()); $start_values = variable_get("comment_roles", array());
$result = db_query("SELECT r.rid, r.name FROM role r, permission p WHERE r.rid = p.rid AND p.perm LIKE '%post comments%'"); $result = db_query("SELECT r.rid, r.name FROM {role} r, {permission} p WHERE r.rid = p.rid AND p.perm LIKE '%post comments%'");
$header = array(t("user role"), t("initial score")); $header = array(t("user role"), t("initial score"));
@ -957,30 +957,30 @@ function comment_mod_votes($edit) {
$mid = arg(4); $mid = arg(4);
if ($op == t("Save vote")) { if ($op == t("Save vote")) {
db_query("UPDATE moderation_votes SET vote = '%s', weight = %d WHERE mid = %d", $edit["vote"], $edit["weight"], $mid); db_query("UPDATE {moderation_votes} SET vote = '%s', weight = %d WHERE mid = %d", $edit["vote"], $edit["weight"], $mid);
$mid = 0; $mid = 0;
} }
else if ($op == t("Delete vote")) { else if ($op == t("Delete vote")) {
db_query("DELETE FROM moderation_votes WHERE mid = %d", $mid); db_query("DELETE FROM {moderation_votes} WHERE mid = %d", $mid);
db_query("DELETE FROM moderation_roles WHERE mid = %d", $mid); db_query("DELETE FROM {moderation_roles} WHERE mid = %d", $mid);
$mid = 0; $mid = 0;
} }
else if ($op == t("Add new vote")) { else if ($op == t("Add new vote")) {
db_query("INSERT INTO moderation_votes (vote, weight) VALUES ('%s', %d)", $edit["vote"], $edit["weight"]); db_query("INSERT INTO {moderation_votes} (vote, weight) VALUES ('%s', %d)", $edit["vote"], $edit["weight"]);
$mid = 0; $mid = 0;
} }
$output .= "<h3>" . t("Moderation votes overview") . "</h3>"; $output .= "<h3>" . t("Moderation votes overview") . "</h3>";
$header = array(t("votes"), t("weight"), t("operations")); $header = array(t("votes"), t("weight"), t("operations"));
$result = db_query("SELECT mid, vote, weight FROM moderation_votes ORDER BY weight"); $result = db_query("SELECT mid, vote, weight FROM {moderation_votes} ORDER BY weight");
while ($vote = db_fetch_object($result)) { while ($vote = db_fetch_object($result)) {
$rows[] = array($vote->vote, array("data" => $vote->weight, "align" => "center"), array("data" => l(t("edit"), "admin/comment/moderation/votes/$vote->mid"), "align" => "center")); $rows[] = array($vote->vote, array("data" => $vote->weight, "align" => "center"), array("data" => l(t("edit"), "admin/comment/moderation/votes/$vote->mid"), "align" => "center"));
} }
$output .= table($header, $rows); $output .= table($header, $rows);
if ($mid) { if ($mid) {
$vote = db_fetch_object(db_query("SELECT vote, weight FROM moderation_votes WHERE mid = %d", $mid)); $vote = db_fetch_object(db_query("SELECT vote, weight FROM {moderation_votes} WHERE mid = %d", $mid));
} }
$output .= "<br /><h3>". (isset($mid) ? "Edit" : "Add new") ."moderation option</h3>"; $output .= "<br /><h3>". (isset($mid) ? "Edit" : "Add new") ."moderation option</h3>";
@ -1005,15 +1005,15 @@ function comment_mod_filters($edit) {
$fid = arg(4); $fid = arg(4);
if ($op == t("Save threshold")) { if ($op == t("Save threshold")) {
db_query("UPDATE moderation_filters SET filter = '%s', minimum = %d WHERE fid = %d", $edit["filter"], $edit["minimum"], $fid); db_query("UPDATE {moderation_filters} SET filter = '%s', minimum = %d WHERE fid = %d", $edit["filter"], $edit["minimum"], $fid);
$fid = 0; $fid = 0;
} }
else if ($op == t("Delete threshold")) { else if ($op == t("Delete threshold")) {
db_query("DELETE FROM moderation_filters WHERE fid = %d", $fid); db_query("DELETE FROM {moderation_filters} WHERE fid = %d", $fid);
$fid = 0; $fid = 0;
} }
else if ($op == t("Add new threshold")) { else if ($op == t("Add new threshold")) {
db_query("INSERT INTO moderation_filters (filter, minimum) VALUES ('%s', %d)", $edit["filter"], $edit["minimum"]); db_query("INSERT INTO {moderation_filters} (filter, minimum) VALUES ('%s', %d)", $edit["filter"], $edit["minimum"]);
$fid = 0; $fid = 0;
} }
@ -1021,14 +1021,14 @@ function comment_mod_filters($edit) {
$header = array(t("name"), t("minimum score"), t("operations")); $header = array(t("name"), t("minimum score"), t("operations"));
$result = db_query("SELECT fid, filter, minimum FROM moderation_filters ORDER BY minimum"); $result = db_query("SELECT fid, filter, minimum FROM {moderation_filters} ORDER BY minimum");
while ($filter = db_fetch_object($result)) { while ($filter = db_fetch_object($result)) {
$rows[] = array($filter->filter, array("data" => $filter->minimum, "align" => "center"), array("data" => l(t("edit"), "admin/comment/moderation/filters/$filter->fid"), "align" => "center")); $rows[] = array($filter->filter, array("data" => $filter->minimum, "align" => "center"), array("data" => l(t("edit"), "admin/comment/moderation/filters/$filter->fid"), "align" => "center"));
} }
$output .= table($header, $rows); $output .= table($header, $rows);
if ($fid) { if ($fid) {
$filter = db_fetch_object(db_query("SELECT filter, fid, minimum FROM moderation_filters WHERE fid = %d", $fid)); $filter = db_fetch_object(db_query("SELECT filter, fid, minimum FROM {moderation_filters} WHERE fid = %d", $fid));
} }
$output .= "<br /><h3>". (isset($fid) ? "Edit" : "Add new") ." threshold</h3>"; $output .= "<br /><h3>". (isset($fid) ? "Edit" : "Add new") ." threshold</h3>";
@ -1154,7 +1154,7 @@ function comment_per_page_form($comments_per_page) {
} }
function comment_threshold($threshold) { function comment_threshold($threshold) {
$result = db_query("SELECT fid, filter FROM moderation_filters"); $result = db_query("SELECT fid, filter FROM {moderation_filters} ");
$options .= " <option value=\"0\">". t("-- threshold --") ."</option>"; $options .= " <option value=\"0\">". t("-- threshold --") ."</option>";
while ($filter = db_fetch_object($result)) { while ($filter = db_fetch_object($result)) {
$filters .= " <option value=\"$filter->fid\"". ($threshold == $filter->fid ? " selected=\"selected\"" : "") .">". t($filter->filter) ."</option>"; $filters .= " <option value=\"$filter->fid\"". ($threshold == $filter->fid ? " selected=\"selected\"" : "") .">". t($filter->filter) ."</option>";
@ -1210,7 +1210,7 @@ function comment_moderation_form($comment) {
// comment hasn't been moderated yet: // comment hasn't been moderated yet:
if (!isset($votes)) { if (!isset($votes)) {
$result = db_query("SELECT v.mid, v.vote, r.value FROM moderation_votes v, moderation_roles r WHERE v.mid = r.mid AND r.rid = %d ORDER BY weight", $user->rid); $result = db_query("SELECT v.mid, v.vote, r.value FROM {moderation_votes} v, {moderation_roles} r WHERE v.mid = r.mid AND r.rid = %d ORDER BY weight", $user->rid);
$votes = array(); $votes = array();
while ($vote = db_fetch_object($result)) { while ($vote = db_fetch_object($result)) {
if ($vote->value != 0) { if ($vote->value != 0) {
@ -1328,18 +1328,18 @@ function comment_moderate() {
global $moderation, $user; global $moderation, $user;
if ($moderation) { if ($moderation) {
$result = db_query("SELECT mid, value FROM moderation_roles WHERE rid = %d", $user->rid); $result = db_query("SELECT mid, value FROM {moderation_roles} WHERE rid = %d", $user->rid);
while ($mod = db_fetch_object($result)) { while ($mod = db_fetch_object($result)) {
$votes[$mod->mid] = $mod->value; $votes[$mod->mid] = $mod->value;
} }
$node = node_load(array("nid" => db_result(db_query("SELECT nid FROM comments WHERE cid = %d", key($moderation))))); $node = node_load(array("nid" => db_result(db_query("SELECT nid FROM {comments} WHERE cid = %d", key($moderation)))));
if (user_access("administer comments") || comment_user_can_moderate($node)) { if (user_access("administer comments") || comment_user_can_moderate($node)) {
foreach ($moderation as $cid => $vote) { foreach ($moderation as $cid => $vote) {
if ($vote) { if ($vote) {
if (($vote == 'offline') && (user_access("administer comments"))) { if (($vote == 'offline') && (user_access("administer comments"))) {
db_query("UPDATE comments SET status = 1 WHERE cid = %d", $cid); db_query("UPDATE {comments} SET status = 1 WHERE cid = %d", $cid);
watchdog("special", "comment: unpublished comment #". $cid); watchdog("special", "comment: unpublished comment #". $cid);
/* /*
@ -1349,7 +1349,7 @@ function comment_moderate() {
module_invoke_all("comment", "unpublish", $cid); module_invoke_all("comment", "unpublish", $cid);
} }
else { else {
$comment = db_fetch_object(db_query("SELECT * FROM comments WHERE cid = %d", $cid)); $comment = db_fetch_object(db_query("SELECT * FROM {comments} WHERE cid = %d", $cid));
$users = unserialize($comment->users); $users = unserialize($comment->users);
if ($user->uid != $comment->uid && !(comment_already_moderated($user->uid, $comment->users))) { if ($user->uid != $comment->uid && !(comment_already_moderated($user->uid, $comment->users))) {
$users[$user->uid] = $vote; $users[$user->uid] = $vote;
@ -1364,7 +1364,7 @@ function comment_moderate() {
} }
} }
$new_score = round($tot_score / count($users)); $new_score = round($tot_score / count($users));
db_query("UPDATE comments SET score = '$new_score', users = '%s' WHERE cid = %d", serialize($users), $cid); db_query("UPDATE {comments} SET score = '$new_score', users = '%s' WHERE cid = %d", serialize($users), $cid);
/* /*
** Fire a hook ** Fire a hook
@ -1391,7 +1391,7 @@ function comment_num_all($nid) {
static $cache; static $cache;
if (!isset($cache[$nid])) { if (!isset($cache[$nid])) {
$comment = db_fetch_object(db_query("SELECT COUNT(c.nid) AS number FROM node n LEFT JOIN comments c ON n.nid = c.nid WHERE n.nid = %d AND c.status = 0 GROUP BY n.nid", $nid)); $comment = db_fetch_object(db_query("SELECT COUNT(c.nid) AS number FROM {node} n LEFT JOIN {comments} c ON n.nid = c.nid WHERE n.nid = %d AND c.status = 0 GROUP BY n.nid", $nid));
$cache[$nid] = $comment->number ? $comment->number : 0; $cache[$nid] = $comment->number ? $comment->number : 0;
} }
return $cache[$nid]; return $cache[$nid];
@ -1401,7 +1401,7 @@ function comment_num_replies($id) {
static $cache; static $cache;
if (!isset($cache[$nid])) { if (!isset($cache[$nid])) {
$result = db_query("SELECT COUNT(cid) FROM comments WHERE pid = %d AND status = 0", $id); $result = db_query("SELECT COUNT(cid) FROM {comments} WHERE pid = %d AND status = 0", $id);
$cache[$nid] = $result ? db_result($result, 0) : 0; $cache[$nid] = $result ? db_result($result, 0) : 0;
} }
@ -1431,7 +1431,7 @@ function comment_num_new($nid, $timestamp = 0) {
** Use the timestamp to retrieve the number of new comments ** Use the timestamp to retrieve the number of new comments
*/ */
$result = db_result(db_query("SELECT COUNT(c.cid) FROM node n LEFT JOIN comments c ON n.nid = c.nid WHERE n.nid = %d AND timestamp > %d AND c.status = 0", $nid, $timestamp)); $result = db_result(db_query("SELECT COUNT(c.cid) FROM {node} n LEFT JOIN {comments} c ON n.nid = c.nid WHERE n.nid = %d AND timestamp > %d AND c.status = 0", $nid, $timestamp));
return $result; return $result;
} }
@ -1493,7 +1493,7 @@ function comment_search($keys) {
** identifier which is currently used byt the comment module. ** identifier which is currently used byt the comment module.
*/ */
$find = do_search(array("keys" => $keys, "type" => "comment", "select" => "select s.lno as lno, c.nid as nid, c.subject as title, c.timestamp as created, u.uid as uid, u.name as name, s.count as count FROM search_index s, comments c LEFT JOIN users u ON c.uid = u.uid WHERE s.lno = c.cid AND s.type = 'comment' AND c.status = 0 AND s.word like '%'")); $find = do_search(array("keys" => $keys, "type" => "comment", "select" => "select s.lno as lno, c.nid as nid, c.subject as title, c.timestamp as created, u.uid as uid, u.name as name, s.count as count FROM {search_index} s, {comments} c LEFT JOIN {users} u ON c.uid = u.uid WHERE s.lno = c.cid AND s.type = 'comment' AND c.status = 0 AND s.word like '%'"));
return $find; return $find;
} }
@ -1515,7 +1515,7 @@ function comment_update_index() {
** last run date for the comments update. ** last run date for the comments update.
*/ */
return array("last_update" => "comment_cron_last", "node_type" => "comment", "select" => "SELECT c.cid as lno, c.subject as text1, c.comment as text2 FROM comments c WHERE c.status = 0 AND timestamp > ". variable_get("comment_cron_last", 1)); return array("last_update" => "comment_cron_last", "node_type" => "comment", "select" => "SELECT c.cid as lno, c.subject as text1, c.comment as text2 FROM {comments} c WHERE c.status = 0 AND timestamp > ". variable_get("comment_cron_last", 1));
} }
function comment_nodeapi(&$node, $op, $arg = 0) { function comment_nodeapi(&$node, $op, $arg = 0) {
@ -1541,7 +1541,7 @@ function comment_nodeapi(&$node, $op, $arg = 0) {
} }
break; break;
case "delete": case "delete":
db_query("DELETE FROM comments WHERE nid = '$node->nid'"); db_query("DELETE FROM {comments} WHERE nid = '$node->nid'");
break; break;
} }
} }

View File

@ -84,7 +84,7 @@ function comment_settings() {
$output .= form_select(t("Default display order"), "comment_default_order", variable_get("comment_default_order", 1), $corder, t("The default sorting for new users and anonymous users while viewing comments. These users may change their view using the comment control panel. For registered users, this change is remembered as a persistent user preference.")); $output .= form_select(t("Default display order"), "comment_default_order", variable_get("comment_default_order", 1), $corder, t("The default sorting for new users and anonymous users while viewing comments. These users may change their view using the comment control panel. For registered users, this change is remembered as a persistent user preference."));
$output .= form_textfield(t("Default comments per page"), "comment_default_per_page", variable_get("comment_default_per_page", "50"), 5, 5, t("Default number of comments for each page; more comments are distributed in several pages.")); $output .= form_textfield(t("Default comments per page"), "comment_default_per_page", variable_get("comment_default_per_page", "50"), 5, 5, t("Default number of comments for each page; more comments are distributed in several pages."));
$result = db_query("SELECT fid, filter FROM moderation_filters"); $result = db_query("SELECT fid, filter FROM {moderation_filters} ");
while ($filter = db_fetch_object($result)) { while ($filter = db_fetch_object($result)) {
$thresholds[$filter->fid] = ($filter->filter); $thresholds[$filter->fid] = ($filter->filter);
} }
@ -170,7 +170,7 @@ function comment_form($edit) {
function comment_edit($cid) { function comment_edit($cid) {
global $user; global $user;
$comment = db_fetch_object(db_query("SELECT c.*, u.uid, u.name, u.data FROM comments c LEFT JOIN users u ON c.uid = u.uid WHERE c.cid = %d AND c.status != 2", $cid)); $comment = db_fetch_object(db_query("SELECT c.*, u.uid, u.name, u.data FROM {comments} c LEFT JOIN {users} u ON c.uid = u.uid WHERE c.cid = %d AND c.status != 2", $cid));
if (comment_access("edit", $comment)) { if (comment_access("edit", $comment)) {
comment_preview(object2array($comment)); comment_preview(object2array($comment));
@ -187,7 +187,7 @@ function comment_reply($pid, $nid) {
*/ */
if ($pid) { if ($pid) {
$comment = db_fetch_object(db_query("SELECT c.*, u.uid, u.name, u.data FROM comments c LEFT JOIN users u ON c.uid = u.uid WHERE c.cid = %d AND c.status = 0", $pid)); $comment = db_fetch_object(db_query("SELECT c.*, u.uid, u.name, u.data FROM {comments} c LEFT JOIN {users} u ON c.uid = u.uid WHERE c.cid = %d AND c.status = 0", $pid));
comment_view($comment); comment_view($comment);
} }
else { else {
@ -238,7 +238,7 @@ function comment_preview($edit) {
theme("box", t("Reply"), comment_form($edit)); theme("box", t("Reply"), comment_form($edit));
if ($edit["pid"]) { if ($edit["pid"]) {
$comment = db_fetch_object(db_query("SELECT c.*, u.uid, u.name, u.data FROM comments c LEFT JOIN users u ON c.uid = u.uid WHERE c.cid = %d AND c.status = 0", $edit["pid"])); $comment = db_fetch_object(db_query("SELECT c.*, u.uid, u.name, u.data FROM {comments} c LEFT JOIN {users} u ON c.uid = u.uid WHERE c.cid = %d AND c.status = 0", $edit["pid"]));
comment_view($comment); comment_view($comment);
} }
else { else {
@ -276,7 +276,7 @@ function comment_post($edit) {
** validated/filtered data to perform such check. ** validated/filtered data to perform such check.
*/ */
$duplicate = db_result(db_query("SELECT COUNT(cid) FROM comments WHERE pid = %d AND nid = %d AND subject = '%s' AND comment = '%s'", $edit["pid"], $edit["nid"], $edit["subject"], $edit["comment"]), 0); $duplicate = db_result(db_query("SELECT COUNT(cid) FROM {comments} WHERE pid = %d AND nid = %d AND subject = '%s' AND comment = '%s'", $edit["pid"], $edit["nid"], $edit["subject"], $edit["comment"]), 0);
if ($duplicate != 0) { if ($duplicate != 0) {
watchdog("warning", "comment: duplicate '". $edit["subject"] ."'"); watchdog("warning", "comment: duplicate '". $edit["subject"] ."'");
@ -292,7 +292,7 @@ function comment_post($edit) {
** user. ** user.
*/ */
db_query("UPDATE comments SET subject = '%s', comment = '%s' WHERE cid = %d AND uid = '$user->uid'", $edit["subject"], $edit["comment"], $edit["cid"]); db_query("UPDATE {comments} SET subject = '%s', comment = '%s' WHERE cid = %d AND uid = '$user->uid'", $edit["subject"], $edit["comment"], $edit["cid"]);
/* /*
** Fire a hook ** Fire a hook
@ -325,7 +325,7 @@ function comment_post($edit) {
$edit["cid"] = db_next_id("comments_cid"); $edit["cid"] = db_next_id("comments_cid");
db_query("INSERT INTO comments (cid, nid, pid, uid, subject, comment, hostname, timestamp, status, score, users) VALUES (%d, %d, %d, %d, '%s', '%s', '%s', %d, %d, %d, '%s')", $edit["cid"], $edit["nid"], $edit["pid"], $user->uid, $edit["subject"], $edit["comment"], getenv("REMOTE_ADDR"), time(), $status, $score, $users); db_query("INSERT INTO {comments} (cid, nid, pid, uid, subject, comment, hostname, timestamp, status, score, users) VALUES (%d, %d, %d, %d, '%s', '%s', '%s', %d, %d, %d, '%s')", $edit["cid"], $edit["nid"], $edit["pid"], $user->uid, $edit["subject"], $edit["comment"], getenv("REMOTE_ADDR"), time(), $status, $score, $users);
/* /*
** Tell the other modules a new comment has been submitted: ** Tell the other modules a new comment has been submitted:
@ -459,7 +459,7 @@ function comment_render($node, $cid = 0) {
if (empty($threshold)) { if (empty($threshold)) {
$threshold = $user->uid ? $user->threshold : variable_get("comment_default_threshold", 0); $threshold = $user->uid ? $user->threshold : variable_get("comment_default_threshold", 0);
} }
$threshold_min = db_result(db_query("SELECT minimum FROM moderation_filters WHERE fid = %d", $threshold)); $threshold_min = db_result(db_query("SELECT minimum FROM {moderation_filters} WHERE fid = %d", $threshold));
if (empty($comment_page)) { if (empty($comment_page)) {
$comment_page = 1; $comment_page = 1;
@ -481,7 +481,7 @@ function comment_render($node, $cid = 0) {
print "<form method=\"post\" action=\"". url("comment") ."\"><div>\n"; print "<form method=\"post\" action=\"". url("comment") ."\"><div>\n";
print form_hidden("nid", $nid); print form_hidden("nid", $nid);
$result = db_query("SELECT c.cid, c.pid, c.nid, c.subject, c.comment, c.timestamp, u.uid, u.name, u.data, c.score, c.users FROM comments c LEFT JOIN users u ON c.uid = u.uid WHERE c.cid = %d AND c.status = 0 GROUP BY c.cid, c.pid, c.nid, c.subject, c.comment, c.timestamp, u.uid, u.name, u.data, c.score, c.users", $cid); $result = db_query("SELECT c.cid, c.pid, c.nid, c.subject, c.comment, c.timestamp, u.uid, u.name, u.data, c.score, c.users FROM {comments} c LEFT JOIN {users} u ON c.uid = u.uid WHERE c.cid = %d AND c.status = 0 GROUP BY c.cid, c.pid, c.nid, c.subject, c.comment, c.timestamp, u.uid, u.name, u.data, c.score, c.users", $cid);
if ($comment = db_fetch_object($result)) { if ($comment = db_fetch_object($result)) {
comment_view($comment, comment_links($comment)); comment_view($comment, comment_links($comment));
@ -498,7 +498,7 @@ function comment_render($node, $cid = 0) {
** Multiple comments view ** Multiple comments view
*/ */
$query .= "SELECT c.cid as cid, c.pid, c.nid, c.subject, c.comment, c.timestamp, u.uid, u.name, u.data, c.score, c.users FROM comments c LEFT JOIN users u ON c.uid = u.uid WHERE c.nid = '". check_query($nid) ."' AND c.status = 0"; $query .= "SELECT c.cid as cid, c.pid, c.nid, c.subject, c.comment, c.timestamp, u.uid, u.name, u.data, c.score, c.users FROM {comments} c LEFT JOIN {users} u ON c.uid = u.uid WHERE c.nid = '". check_query($nid) ."' AND c.status = 0";
$query .= " GROUP BY c.cid, c.pid, c.nid, c.subject, c.comment, c.timestamp, u.uid, u.name, u.data, c.score, c.users"; $query .= " GROUP BY c.cid, c.pid, c.nid, c.subject, c.comment, c.timestamp, u.uid, u.name, u.data, c.score, c.users";
@ -809,7 +809,7 @@ function comment_node_link($node) {
** Edit comments: ** Edit comments:
*/ */
$result = db_query("SELECT c.cid, c.subject, u.uid, u.name FROM comments c LEFT JOIN users u ON u.uid = c.uid WHERE nid = %d AND c.status = 0 ORDER BY c.timestamp", $node->nid); $result = db_query("SELECT c.cid, c.subject, u.uid, u.name FROM {comments} c LEFT JOIN {users} u ON u.uid = c.uid WHERE nid = %d AND c.status = 0 ORDER BY c.timestamp", $node->nid);
$header = array(t("title"), t("author"), array("data" => t("operations"), "colspan" => 3)); $header = array(t("title"), t("author"), array("data" => t("operations"), "colspan" => 3));
@ -829,7 +829,7 @@ function comment_node_link($node) {
function comment_admin_edit($id) { function comment_admin_edit($id) {
$result = db_query("SELECT c.*, u.name, u.uid FROM comments c LEFT JOIN users u ON c.uid = u.uid WHERE c.cid = %d AND c.status != 2", $id); $result = db_query("SELECT c.*, u.name, u.uid FROM {comments} c LEFT JOIN {users} u ON c.uid = u.uid WHERE c.cid = %d AND c.status != 2", $id);
$comment = db_fetch_object($result); $comment = db_fetch_object($result);
// if a comment is "deleted", it's deleted // if a comment is "deleted", it's deleted
@ -849,7 +849,7 @@ function comment_admin_edit($id) {
function comment_delete($edit) { function comment_delete($edit) {
if ($edit["confirm"]) { if ($edit["confirm"]) {
db_query("UPDATE comments SET status = 2 WHERE cid = %d", $edit["cid"]); db_query("UPDATE {comments} SET status = 2 WHERE cid = %d", $edit["cid"]);
watchdog("special", "comment: deleted comment #". $edit["cid"]); watchdog("special", "comment: deleted comment #". $edit["cid"]);
$output = "deleted comment."; $output = "deleted comment.";
} }
@ -865,14 +865,14 @@ function comment_delete($edit) {
} }
function comment_save($id, $edit) { function comment_save($id, $edit) {
db_query("UPDATE comments SET subject = '%s', comment = '%s', status = %d WHERE cid = %d", $edit["subject"], $edit["comment"], $edit["status"], $id); db_query("UPDATE {comments} SET subject = '%s', comment = '%s', status = %d WHERE cid = %d", $edit["subject"], $edit["comment"], $edit["status"], $id);
watchdog("special", "comment: modified '". $edit["subject"] ."'"); watchdog("special", "comment: modified '". $edit["subject"] ."'");
return "updated comment."; return "updated comment.";
} }
function comment_admin_overview($status = 0) { function comment_admin_overview($status = 0) {
$result = pager_query("SELECT c.*, u.name, u.uid FROM comments c LEFT JOIN users u ON u.uid = c.uid WHERE c.status = '". check_query($status). "' ORDER BY c.timestamp DESC", 50); $result = pager_query("SELECT c.*, u.name, u.uid FROM {comments} c LEFT JOIN {users} u ON u.uid = c.uid WHERE c.status = '". check_query($status). "' ORDER BY c.timestamp DESC", 50);
$header = array(t("subject"), t("author"), t("status"), array("data" => t("operations"), "colspan" => 2)); $header = array(t("subject"), t("author"), t("status"), array("data" => t("operations"), "colspan" => 2));
while ($comment = db_fetch_object($result)) { while ($comment = db_fetch_object($result)) {
@ -891,29 +891,29 @@ function comment_mod_matrix($edit) {
$output .= "<h3>Moderators/vote values matrix</h3>"; $output .= "<h3>Moderators/vote values matrix</h3>";
if ($edit) { if ($edit) {
db_query("DELETE FROM moderation_roles"); db_query("DELETE FROM {moderation_roles} ");
foreach ($edit as $role_id => $votes) { foreach ($edit as $role_id => $votes) {
foreach ($votes as $mid => $value) { foreach ($votes as $mid => $value) {
$sql[] = "('$mid', '$role_id', '". ($value ? $value : 0 ) ."')"; $sql[] = "('$mid', '$role_id', '". ($value ? $value : 0 ) ."')";
} }
} }
db_query("INSERT INTO moderation_roles (mid, rid, value) VALUES ". implode(", ", $sql)); db_query("INSERT INTO {moderation_roles} (mid, rid, value) VALUES ". implode(", ", $sql));
} }
$result = db_query("SELECT r.rid, r.name FROM role r, permission p WHERE r.rid = p.rid AND p.perm LIKE '%moderate comments%'"); $result = db_query("SELECT r.rid, r.name FROM {role} r, {permission} p WHERE r.rid = p.rid AND p.perm LIKE '%moderate comments%'");
$role_names = array(); $role_names = array();
while ($role = db_fetch_object($result)) { while ($role = db_fetch_object($result)) {
$role_names[$role->rid] = $role->name; $role_names[$role->rid] = $role->name;
} }
$result = db_query("SELECT rid, mid, value FROM moderation_roles"); $result = db_query("SELECT rid, mid, value FROM {moderation_roles} ");
while ($role = db_fetch_object($result)) { while ($role = db_fetch_object($result)) {
$mod_roles[$role->rid][$role->mid] = $role->value; $mod_roles[$role->rid][$role->mid] = $role->value;
} }
$header = array_merge(array(t("votes")), array_values($role_names)); $header = array_merge(array(t("votes")), array_values($role_names));
$result = db_query("SELECT mid, vote FROM moderation_votes ORDER BY weight"); $result = db_query("SELECT mid, vote FROM {moderation_votes} ORDER BY weight");
while ($vote = db_fetch_object($result)) { while ($vote = db_fetch_object($result)) {
$row = array($vote->vote); $row = array($vote->vote);
foreach (array_keys($role_names) as $rid) { foreach (array_keys($role_names) as $rid) {
@ -937,7 +937,7 @@ function comment_mod_roles($edit) {
$start_values = variable_get("comment_roles", array()); $start_values = variable_get("comment_roles", array());
$result = db_query("SELECT r.rid, r.name FROM role r, permission p WHERE r.rid = p.rid AND p.perm LIKE '%post comments%'"); $result = db_query("SELECT r.rid, r.name FROM {role} r, {permission} p WHERE r.rid = p.rid AND p.perm LIKE '%post comments%'");
$header = array(t("user role"), t("initial score")); $header = array(t("user role"), t("initial score"));
@ -957,30 +957,30 @@ function comment_mod_votes($edit) {
$mid = arg(4); $mid = arg(4);
if ($op == t("Save vote")) { if ($op == t("Save vote")) {
db_query("UPDATE moderation_votes SET vote = '%s', weight = %d WHERE mid = %d", $edit["vote"], $edit["weight"], $mid); db_query("UPDATE {moderation_votes} SET vote = '%s', weight = %d WHERE mid = %d", $edit["vote"], $edit["weight"], $mid);
$mid = 0; $mid = 0;
} }
else if ($op == t("Delete vote")) { else if ($op == t("Delete vote")) {
db_query("DELETE FROM moderation_votes WHERE mid = %d", $mid); db_query("DELETE FROM {moderation_votes} WHERE mid = %d", $mid);
db_query("DELETE FROM moderation_roles WHERE mid = %d", $mid); db_query("DELETE FROM {moderation_roles} WHERE mid = %d", $mid);
$mid = 0; $mid = 0;
} }
else if ($op == t("Add new vote")) { else if ($op == t("Add new vote")) {
db_query("INSERT INTO moderation_votes (vote, weight) VALUES ('%s', %d)", $edit["vote"], $edit["weight"]); db_query("INSERT INTO {moderation_votes} (vote, weight) VALUES ('%s', %d)", $edit["vote"], $edit["weight"]);
$mid = 0; $mid = 0;
} }
$output .= "<h3>" . t("Moderation votes overview") . "</h3>"; $output .= "<h3>" . t("Moderation votes overview") . "</h3>";
$header = array(t("votes"), t("weight"), t("operations")); $header = array(t("votes"), t("weight"), t("operations"));
$result = db_query("SELECT mid, vote, weight FROM moderation_votes ORDER BY weight"); $result = db_query("SELECT mid, vote, weight FROM {moderation_votes} ORDER BY weight");
while ($vote = db_fetch_object($result)) { while ($vote = db_fetch_object($result)) {
$rows[] = array($vote->vote, array("data" => $vote->weight, "align" => "center"), array("data" => l(t("edit"), "admin/comment/moderation/votes/$vote->mid"), "align" => "center")); $rows[] = array($vote->vote, array("data" => $vote->weight, "align" => "center"), array("data" => l(t("edit"), "admin/comment/moderation/votes/$vote->mid"), "align" => "center"));
} }
$output .= table($header, $rows); $output .= table($header, $rows);
if ($mid) { if ($mid) {
$vote = db_fetch_object(db_query("SELECT vote, weight FROM moderation_votes WHERE mid = %d", $mid)); $vote = db_fetch_object(db_query("SELECT vote, weight FROM {moderation_votes} WHERE mid = %d", $mid));
} }
$output .= "<br /><h3>". (isset($mid) ? "Edit" : "Add new") ."moderation option</h3>"; $output .= "<br /><h3>". (isset($mid) ? "Edit" : "Add new") ."moderation option</h3>";
@ -1005,15 +1005,15 @@ function comment_mod_filters($edit) {
$fid = arg(4); $fid = arg(4);
if ($op == t("Save threshold")) { if ($op == t("Save threshold")) {
db_query("UPDATE moderation_filters SET filter = '%s', minimum = %d WHERE fid = %d", $edit["filter"], $edit["minimum"], $fid); db_query("UPDATE {moderation_filters} SET filter = '%s', minimum = %d WHERE fid = %d", $edit["filter"], $edit["minimum"], $fid);
$fid = 0; $fid = 0;
} }
else if ($op == t("Delete threshold")) { else if ($op == t("Delete threshold")) {
db_query("DELETE FROM moderation_filters WHERE fid = %d", $fid); db_query("DELETE FROM {moderation_filters} WHERE fid = %d", $fid);
$fid = 0; $fid = 0;
} }
else if ($op == t("Add new threshold")) { else if ($op == t("Add new threshold")) {
db_query("INSERT INTO moderation_filters (filter, minimum) VALUES ('%s', %d)", $edit["filter"], $edit["minimum"]); db_query("INSERT INTO {moderation_filters} (filter, minimum) VALUES ('%s', %d)", $edit["filter"], $edit["minimum"]);
$fid = 0; $fid = 0;
} }
@ -1021,14 +1021,14 @@ function comment_mod_filters($edit) {
$header = array(t("name"), t("minimum score"), t("operations")); $header = array(t("name"), t("minimum score"), t("operations"));
$result = db_query("SELECT fid, filter, minimum FROM moderation_filters ORDER BY minimum"); $result = db_query("SELECT fid, filter, minimum FROM {moderation_filters} ORDER BY minimum");
while ($filter = db_fetch_object($result)) { while ($filter = db_fetch_object($result)) {
$rows[] = array($filter->filter, array("data" => $filter->minimum, "align" => "center"), array("data" => l(t("edit"), "admin/comment/moderation/filters/$filter->fid"), "align" => "center")); $rows[] = array($filter->filter, array("data" => $filter->minimum, "align" => "center"), array("data" => l(t("edit"), "admin/comment/moderation/filters/$filter->fid"), "align" => "center"));
} }
$output .= table($header, $rows); $output .= table($header, $rows);
if ($fid) { if ($fid) {
$filter = db_fetch_object(db_query("SELECT filter, fid, minimum FROM moderation_filters WHERE fid = %d", $fid)); $filter = db_fetch_object(db_query("SELECT filter, fid, minimum FROM {moderation_filters} WHERE fid = %d", $fid));
} }
$output .= "<br /><h3>". (isset($fid) ? "Edit" : "Add new") ." threshold</h3>"; $output .= "<br /><h3>". (isset($fid) ? "Edit" : "Add new") ." threshold</h3>";
@ -1154,7 +1154,7 @@ function comment_per_page_form($comments_per_page) {
} }
function comment_threshold($threshold) { function comment_threshold($threshold) {
$result = db_query("SELECT fid, filter FROM moderation_filters"); $result = db_query("SELECT fid, filter FROM {moderation_filters} ");
$options .= " <option value=\"0\">". t("-- threshold --") ."</option>"; $options .= " <option value=\"0\">". t("-- threshold --") ."</option>";
while ($filter = db_fetch_object($result)) { while ($filter = db_fetch_object($result)) {
$filters .= " <option value=\"$filter->fid\"". ($threshold == $filter->fid ? " selected=\"selected\"" : "") .">". t($filter->filter) ."</option>"; $filters .= " <option value=\"$filter->fid\"". ($threshold == $filter->fid ? " selected=\"selected\"" : "") .">". t($filter->filter) ."</option>";
@ -1210,7 +1210,7 @@ function comment_moderation_form($comment) {
// comment hasn't been moderated yet: // comment hasn't been moderated yet:
if (!isset($votes)) { if (!isset($votes)) {
$result = db_query("SELECT v.mid, v.vote, r.value FROM moderation_votes v, moderation_roles r WHERE v.mid = r.mid AND r.rid = %d ORDER BY weight", $user->rid); $result = db_query("SELECT v.mid, v.vote, r.value FROM {moderation_votes} v, {moderation_roles} r WHERE v.mid = r.mid AND r.rid = %d ORDER BY weight", $user->rid);
$votes = array(); $votes = array();
while ($vote = db_fetch_object($result)) { while ($vote = db_fetch_object($result)) {
if ($vote->value != 0) { if ($vote->value != 0) {
@ -1328,18 +1328,18 @@ function comment_moderate() {
global $moderation, $user; global $moderation, $user;
if ($moderation) { if ($moderation) {
$result = db_query("SELECT mid, value FROM moderation_roles WHERE rid = %d", $user->rid); $result = db_query("SELECT mid, value FROM {moderation_roles} WHERE rid = %d", $user->rid);
while ($mod = db_fetch_object($result)) { while ($mod = db_fetch_object($result)) {
$votes[$mod->mid] = $mod->value; $votes[$mod->mid] = $mod->value;
} }
$node = node_load(array("nid" => db_result(db_query("SELECT nid FROM comments WHERE cid = %d", key($moderation))))); $node = node_load(array("nid" => db_result(db_query("SELECT nid FROM {comments} WHERE cid = %d", key($moderation)))));
if (user_access("administer comments") || comment_user_can_moderate($node)) { if (user_access("administer comments") || comment_user_can_moderate($node)) {
foreach ($moderation as $cid => $vote) { foreach ($moderation as $cid => $vote) {
if ($vote) { if ($vote) {
if (($vote == 'offline') && (user_access("administer comments"))) { if (($vote == 'offline') && (user_access("administer comments"))) {
db_query("UPDATE comments SET status = 1 WHERE cid = %d", $cid); db_query("UPDATE {comments} SET status = 1 WHERE cid = %d", $cid);
watchdog("special", "comment: unpublished comment #". $cid); watchdog("special", "comment: unpublished comment #". $cid);
/* /*
@ -1349,7 +1349,7 @@ function comment_moderate() {
module_invoke_all("comment", "unpublish", $cid); module_invoke_all("comment", "unpublish", $cid);
} }
else { else {
$comment = db_fetch_object(db_query("SELECT * FROM comments WHERE cid = %d", $cid)); $comment = db_fetch_object(db_query("SELECT * FROM {comments} WHERE cid = %d", $cid));
$users = unserialize($comment->users); $users = unserialize($comment->users);
if ($user->uid != $comment->uid && !(comment_already_moderated($user->uid, $comment->users))) { if ($user->uid != $comment->uid && !(comment_already_moderated($user->uid, $comment->users))) {
$users[$user->uid] = $vote; $users[$user->uid] = $vote;
@ -1364,7 +1364,7 @@ function comment_moderate() {
} }
} }
$new_score = round($tot_score / count($users)); $new_score = round($tot_score / count($users));
db_query("UPDATE comments SET score = '$new_score', users = '%s' WHERE cid = %d", serialize($users), $cid); db_query("UPDATE {comments} SET score = '$new_score', users = '%s' WHERE cid = %d", serialize($users), $cid);
/* /*
** Fire a hook ** Fire a hook
@ -1391,7 +1391,7 @@ function comment_num_all($nid) {
static $cache; static $cache;
if (!isset($cache[$nid])) { if (!isset($cache[$nid])) {
$comment = db_fetch_object(db_query("SELECT COUNT(c.nid) AS number FROM node n LEFT JOIN comments c ON n.nid = c.nid WHERE n.nid = %d AND c.status = 0 GROUP BY n.nid", $nid)); $comment = db_fetch_object(db_query("SELECT COUNT(c.nid) AS number FROM {node} n LEFT JOIN {comments} c ON n.nid = c.nid WHERE n.nid = %d AND c.status = 0 GROUP BY n.nid", $nid));
$cache[$nid] = $comment->number ? $comment->number : 0; $cache[$nid] = $comment->number ? $comment->number : 0;
} }
return $cache[$nid]; return $cache[$nid];
@ -1401,7 +1401,7 @@ function comment_num_replies($id) {
static $cache; static $cache;
if (!isset($cache[$nid])) { if (!isset($cache[$nid])) {
$result = db_query("SELECT COUNT(cid) FROM comments WHERE pid = %d AND status = 0", $id); $result = db_query("SELECT COUNT(cid) FROM {comments} WHERE pid = %d AND status = 0", $id);
$cache[$nid] = $result ? db_result($result, 0) : 0; $cache[$nid] = $result ? db_result($result, 0) : 0;
} }
@ -1431,7 +1431,7 @@ function comment_num_new($nid, $timestamp = 0) {
** Use the timestamp to retrieve the number of new comments ** Use the timestamp to retrieve the number of new comments
*/ */
$result = db_result(db_query("SELECT COUNT(c.cid) FROM node n LEFT JOIN comments c ON n.nid = c.nid WHERE n.nid = %d AND timestamp > %d AND c.status = 0", $nid, $timestamp)); $result = db_result(db_query("SELECT COUNT(c.cid) FROM {node} n LEFT JOIN {comments} c ON n.nid = c.nid WHERE n.nid = %d AND timestamp > %d AND c.status = 0", $nid, $timestamp));
return $result; return $result;
} }
@ -1493,7 +1493,7 @@ function comment_search($keys) {
** identifier which is currently used byt the comment module. ** identifier which is currently used byt the comment module.
*/ */
$find = do_search(array("keys" => $keys, "type" => "comment", "select" => "select s.lno as lno, c.nid as nid, c.subject as title, c.timestamp as created, u.uid as uid, u.name as name, s.count as count FROM search_index s, comments c LEFT JOIN users u ON c.uid = u.uid WHERE s.lno = c.cid AND s.type = 'comment' AND c.status = 0 AND s.word like '%'")); $find = do_search(array("keys" => $keys, "type" => "comment", "select" => "select s.lno as lno, c.nid as nid, c.subject as title, c.timestamp as created, u.uid as uid, u.name as name, s.count as count FROM {search_index} s, {comments} c LEFT JOIN {users} u ON c.uid = u.uid WHERE s.lno = c.cid AND s.type = 'comment' AND c.status = 0 AND s.word like '%'"));
return $find; return $find;
} }
@ -1515,7 +1515,7 @@ function comment_update_index() {
** last run date for the comments update. ** last run date for the comments update.
*/ */
return array("last_update" => "comment_cron_last", "node_type" => "comment", "select" => "SELECT c.cid as lno, c.subject as text1, c.comment as text2 FROM comments c WHERE c.status = 0 AND timestamp > ". variable_get("comment_cron_last", 1)); return array("last_update" => "comment_cron_last", "node_type" => "comment", "select" => "SELECT c.cid as lno, c.subject as text1, c.comment as text2 FROM {comments} c WHERE c.status = 0 AND timestamp > ". variable_get("comment_cron_last", 1));
} }
function comment_nodeapi(&$node, $op, $arg = 0) { function comment_nodeapi(&$node, $op, $arg = 0) {
@ -1541,7 +1541,7 @@ function comment_nodeapi(&$node, $op, $arg = 0) {
} }
break; break;
case "delete": case "delete":
db_query("DELETE FROM comments WHERE nid = '$node->nid'"); db_query("DELETE FROM {comments} WHERE nid = '$node->nid'");
break; break;
} }
} }

View File

@ -37,7 +37,7 @@ function drupal_cron() {
** stopped sending "ping" messages. ** stopped sending "ping" messages.
*/ */
db_query("DELETE FROM directory WHERE timestamp < '". (time() - 259200) ."'"); db_query("DELETE FROM {directory} WHERE timestamp < '". (time() - 259200) ."'");
/* /*
** If this site acts as a Drupal XML-RPC client, send a message to the ** If this site acts as a Drupal XML-RPC client, send a message to the
@ -72,8 +72,8 @@ function drupal_directory_ping($arguments) {
*/ */
if ($link && $name && $mail && $slogan && $mission) { if ($link && $name && $mail && $slogan && $mission) {
db_query("DELETE FROM directory WHERE link = '%s' OR mail = '%s'", $link, $mail); db_query("DELETE FROM {directory} WHERE link = '%s' OR mail = '%s'", $link, $mail);
db_query("INSERT INTO directory (link, name, mail, slogan, mission, timestamp) VALUES ('%s', '%s', '%s', '%s', '%s', %d)", $link, $name, $mail, $slogan, $mission, time()); db_query("INSERT INTO {directory} (link, name, mail, slogan, mission, timestamp) VALUES ('%s', '%s', '%s', '%s', '%s', %d)", $link, $name, $mail, $slogan, $mission, time());
watchdog("message", "directory: ping from '$name' ($link)"); watchdog("message", "directory: ping from '$name' ($link)");
@ -86,7 +86,7 @@ function drupal_directory_ping($arguments) {
} }
function drupal_directory_page() { function drupal_directory_page() {
$result = db_query("SELECT * FROM directory ORDER BY name"); $result = db_query("SELECT * FROM {directory} ORDER BY name");
while ($site = db_fetch_object($result)) { while ($site = db_fetch_object($result)) {
$output .= "<a href=\"$site->link\">$site->name</a> - $site->slogan<div style=\"padding-left: 20px;\">$site->mission</div><br />"; $output .= "<a href=\"$site->link\">$site->name</a> - $site->slogan<div style=\"padding-left: 20px;\">$site->mission</div><br />";

View File

@ -37,7 +37,7 @@ function drupal_cron() {
** stopped sending "ping" messages. ** stopped sending "ping" messages.
*/ */
db_query("DELETE FROM directory WHERE timestamp < '". (time() - 259200) ."'"); db_query("DELETE FROM {directory} WHERE timestamp < '". (time() - 259200) ."'");
/* /*
** If this site acts as a Drupal XML-RPC client, send a message to the ** If this site acts as a Drupal XML-RPC client, send a message to the
@ -72,8 +72,8 @@ function drupal_directory_ping($arguments) {
*/ */
if ($link && $name && $mail && $slogan && $mission) { if ($link && $name && $mail && $slogan && $mission) {
db_query("DELETE FROM directory WHERE link = '%s' OR mail = '%s'", $link, $mail); db_query("DELETE FROM {directory} WHERE link = '%s' OR mail = '%s'", $link, $mail);
db_query("INSERT INTO directory (link, name, mail, slogan, mission, timestamp) VALUES ('%s', '%s', '%s', '%s', '%s', %d)", $link, $name, $mail, $slogan, $mission, time()); db_query("INSERT INTO {directory} (link, name, mail, slogan, mission, timestamp) VALUES ('%s', '%s', '%s', '%s', '%s', %d)", $link, $name, $mail, $slogan, $mission, time());
watchdog("message", "directory: ping from '$name' ($link)"); watchdog("message", "directory: ping from '$name' ($link)");
@ -86,7 +86,7 @@ function drupal_directory_ping($arguments) {
} }
function drupal_directory_page() { function drupal_directory_page() {
$result = db_query("SELECT * FROM directory ORDER BY name"); $result = db_query("SELECT * FROM {directory} ORDER BY name");
while ($site = db_fetch_object($result)) { while ($site = db_fetch_object($result)) {
$output .= "<a href=\"$site->link\">$site->name</a> - $site->slogan<div style=\"padding-left: 20px;\">$site->mission</div><br />"; $output .= "<a href=\"$site->link\">$site->name</a> - $site->slogan<div style=\"padding-left: 20px;\">$site->mission</div><br />";

View File

@ -71,7 +71,7 @@ function forum_taxonomy($op, $type, $object) {
} }
function forum_load($node) { function forum_load($node) {
$forum = db_fetch_object(db_query("SELECT * FROM forum WHERE nid = %d", $node->nid)); $forum = db_fetch_object(db_query("SELECT * FROM {forum} WHERE nid = %d", $node->nid));
return $forum; return $forum;
} }
@ -86,10 +86,10 @@ function forum_block($op = "list", $delta = 0) {
if (empty($cache)) { if (empty($cache)) {
unset($items); unset($items);
$content = node_title_list(db_query_range("SELECT n.nid, n.title, u.uid, u.name, GREATEST(n.created, MAX(c.timestamp)) AS sort FROM node n LEFT JOIN forum f ON n.nid = f.nid LEFT JOIN comments c ON n.nid = c.nid LEFT JOIN users u ON n.uid = u.uid WHERE n.type = 'forum' AND n.nid = f.nid AND n.status = 1 GROUP BY n.nid, n.title, n.created, u.uid, u.name ORDER BY sort DESC", 0, variable_get("forum_block_num", "5")), t("Active forum topics:")); $content = node_title_list(db_query_range("SELECT n.nid, n.title, u.uid, u.name, GREATEST(n.created, MAX(c.timestamp)) AS sort FROM {node} n LEFT JOIN {forum} f ON n.nid = f.nid LEFT JOIN {comments} c ON n.nid = c.nid LEFT JOIN {users} u ON n.uid = u.uid WHERE n.type = 'forum' AND n.nid = f.nid AND n.status = 1 GROUP BY n.nid, n.title, n.created, u.uid, u.name ORDER BY sort DESC", 0, variable_get("forum_block_num", "5")), t("Active forum topics:"));
unset ($items); unset ($items);
$content .= node_title_list(db_query_range("SELECT n.nid, n.title, u.uid, u.name FROM node n LEFT JOIN forum f ON n.nid = f.nid LEFT JOIN users u ON n.uid = u.uid WHERE n.type = 'forum' ORDER BY n.nid DESC", 0, variable_get("forum_block_num", "5")), t("New forum topics:")); $content .= node_title_list(db_query_range("SELECT n.nid, n.title, u.uid, u.name FROM {node} n LEFT JOIN {forum} f ON n.nid = f.nid LEFT JOIN {users} u ON n.uid = u.uid WHERE n.type = 'forum' ORDER BY n.nid DESC", 0, variable_get("forum_block_num", "5")), t("New forum topics:"));
if ($content) { if ($content) {
$content .= "<div id=\"forum_more\" style=\"text-align: right;\">". l(t("more"), "forum", array("title" => t("Read the latest forum topics."))) ."</div>"; $content .= "<div id=\"forum_more\" style=\"text-align: right;\">". l(t("more"), "forum", array("title" => t("Read the latest forum topics."))) ."</div>";
@ -121,7 +121,7 @@ function forum_link($type, $node = 0, $main = 0) {
if (!$main && $type == "node" && $node->type == "forum") { if (!$main && $type == "node" && $node->type == "forum") {
// get previous and next topic // get previous and next topic
$result = db_query("SELECT n.nid, n.title, n.body, GREATEST(n.created, MAX(c.timestamp)) AS date_sort, COUNT(c.nid) AS num_comments FROM node n LEFT JOIN forum f ON n.nid = f.nid LEFT JOIN comments c ON n.nid = c.nid WHERE n.nid = f.nid AND f.tid = %d AND n.status = 1 GROUP BY n.nid, n.title, n.body, n.created ORDER BY ". _forum_get_topic_order(isset($user->sortby) ? $user->sortby : variable_get("forum_order",1)), $node->tid); $result = db_query("SELECT n.nid, n.title, n.body, GREATEST(n.created, MAX(c.timestamp)) AS date_sort, COUNT(c.nid) AS num_comments FROM {node} n LEFT JOIN {forum} f ON n.nid = f.nid LEFT JOIN {comments} c ON n.nid = c.nid WHERE n.nid = f.nid AND f.tid = %d AND n.status = 1 GROUP BY n.nid, n.title, n.body, n.created ORDER BY ". _forum_get_topic_order(isset($user->sortby) ? $user->sortby : variable_get("forum_order",1)), $node->tid);
while ($topic = db_fetch_object($result)) { while ($topic = db_fetch_object($result)) {
if ($stop == 1) { if ($stop == 1) {
@ -241,12 +241,12 @@ function forum_form(&$node, &$help, &$error) {
function forum_insert($node) { function forum_insert($node) {
$node->icon = _forum_decode_icon($node); $node->icon = _forum_decode_icon($node);
db_query("INSERT INTO forum (nid, icon, shadow, tid) VALUES (%d, '%s', %d, %d)", $node->nid, $node->icon, $node->shadow, $node->tid[0]); db_query("INSERT INTO {forum} (nid, icon, shadow, tid) VALUES (%d, '%s', %d, %d)", $node->nid, $node->icon, $node->shadow, $node->tid[0]);
} }
function forum_update($node) { function forum_update($node) {
$node->icon = _forum_decode_icon($node); $node->icon = _forum_decode_icon($node);
db_query("UPDATE forum SET icon = '%s', shadow = %d, tid = %d WHERE nid = %d", $node->icon, $node->shadow, $node->tid[0], $node->nid); db_query("UPDATE {forum} SET icon = '%s', shadow = %d, tid = %d WHERE nid = %d", $node->icon, $node->shadow, $node->tid[0], $node->nid);
} }
function _forum_decode_icon($node) { function _forum_decode_icon($node) {
@ -266,21 +266,21 @@ function _forum_decode_icon($node) {
} }
function forum_delete(&$node) { function forum_delete(&$node) {
db_query("DELETE FROM forum WHERE nid = %d", $node->nid); db_query("DELETE FROM {forum} WHERE nid = %d", $node->nid);
} }
function _forum_num_comments($nid) { function _forum_num_comments($nid) {
$value = db_fetch_object(db_query("SELECT COUNT(cid) AS count FROM comments WHERE nid = %d AND status = 0", $nid)); $value = db_fetch_object(db_query("SELECT COUNT(cid) AS count FROM {comments} WHERE nid = %d AND status = 0", $nid));
return ($value) ? $value->count : 0; return ($value) ? $value->count : 0;
} }
function _forum_last_comment($nid) { function _forum_last_comment($nid) {
$value = db_fetch_object(db_query_range("SELECT timestamp FROM comments WHERE nid = %d AND status = 0 ORDER BY timestamp DESC", $nid, 0, 1)); $value = db_fetch_object(db_query_range("SELECT timestamp FROM {comments} WHERE nid = %d AND status = 0 ORDER BY timestamp DESC", $nid, 0, 1));
return ($value) ? format_date($value->timestamp, "small") : "&nbsp;"; return ($value) ? format_date($value->timestamp, "small") : "&nbsp;";
} }
function _forum_last_reply($nid) { function _forum_last_reply($nid) {
$value = db_fetch_object(db_query_range("SELECT c.timestamp, u.name, u.uid FROM comments c LEFT JOIN users u ON c.uid = u.uid WHERE c.nid = %d AND c.status = 0 ORDER BY c.timestamp DESC", $nid, 0, 1)); $value = db_fetch_object(db_query_range("SELECT c.timestamp, u.name, u.uid FROM {comments} c LEFT JOIN {users} u ON c.uid = u.uid WHERE c.nid = %d AND c.status = 0 ORDER BY c.timestamp DESC", $nid, 0, 1));
return $value; return $value;
} }
@ -349,17 +349,17 @@ function forum_get_parents($tid) {
} }
function _forum_num_topics($term) { function _forum_num_topics($term) {
$value = db_fetch_object(db_query("SELECT COUNT(n.nid) AS count FROM node n LEFT JOIN forum f ON n.nid = f.nid WHERE f.tid = %d AND n.nid = f.nid AND n.status = 1 AND n.type = 'forum'", $term)); $value = db_fetch_object(db_query("SELECT COUNT(n.nid) AS count FROM {node} n LEFT JOIN {forum} f ON n.nid = f.nid WHERE f.tid = %d AND n.nid = f.nid AND n.status = 1 AND n.type = 'forum'", $term));
return ($value) ? $value->count : 0; return ($value) ? $value->count : 0;
} }
function _forum_num_replies($term) { function _forum_num_replies($term) {
$value = db_fetch_object(db_query("SELECT COUNT(*) AS count FROM comments c LEFT JOIN node n ON n.nid = c.nid LEFT JOIN forum f ON n.nid = f.nid WHERE f.tid = %d AND n.nid = f.nid AND n.nid = c.nid AND n.status = 1 AND c.status = 0 AND n.type = 'forum'", $term)); $value = db_fetch_object(db_query("SELECT COUNT(*) AS count FROM {comments} c LEFT JOIN {node} n ON n.nid = c.nid LEFT JOIN {forum} f ON n.nid = f.nid WHERE f.tid = %d AND n.nid = f.nid AND n.nid = c.nid AND n.status = 1 AND c.status = 0 AND n.type = 'forum'", $term));
return ($value) ? $value->count : 0; return ($value) ? $value->count : 0;
} }
function _forum_topics_read($uid) { function _forum_topics_read($uid) {
$result = db_query("SELECT tid, count(*) AS c FROM history h LEFT JOIN node n ON n.nid = h.nid LEFT JOIN forum f ON n.nid = f.nid WHERE f.nid = n.nid AND n.nid = h.nid AND n.type = 'forum' AND n.status = 1 AND h.uid = %d GROUP BY tid", $uid); $result = db_query("SELECT tid, count(*) AS c FROM {history} h LEFT JOIN {node} n ON n.nid = h.nid LEFT JOIN {forum} f ON n.nid = f.nid WHERE f.nid = n.nid AND n.nid = h.nid AND n.type = 'forum' AND n.status = 1 AND h.uid = %d GROUP BY tid", $uid);
while ($obj = db_fetch_object($result)) { while ($obj = db_fetch_object($result)) {
$topics_read[$obj->tid] = $obj->c; $topics_read[$obj->tid] = $obj->c;
@ -369,9 +369,9 @@ function _forum_topics_read($uid) {
} }
function _forum_last_post($term) { function _forum_last_post($term) {
$topic = db_fetch_object(db_query_range("SELECT n.nid, n.created AS timestamp, u.name AS name, u.uid AS uid FROM forum f LEFT JOIN node n ON n.nid = f.nid LEFT JOIN users u ON n.uid = u.uid WHERE f.tid = %d AND n.nid = f.nid AND n.type = 'forum' AND n.status = 1 ORDER BY timestamp DESC", $term, 0, 1)); $topic = db_fetch_object(db_query_range("SELECT n.nid, n.created AS timestamp, u.name AS name, u.uid AS uid FROM {forum} f LEFT JOIN {node} n ON n.nid = f.nid LEFT JOIN {users} u ON n.uid = u.uid WHERE f.tid = %d AND n.nid = f.nid AND n.type = 'forum' AND n.status = 1 ORDER BY timestamp DESC", $term, 0, 1));
$reply = db_fetch_object(db_query_range("SELECT n.nid, c.timestamp, u.name AS name, u.uid AS uid FROM forum f LEFT JOIN node n ON n.nid = f.nid LEFT JOIN comments c ON n.nid = c.nid LEFT JOIN users u ON c.uid = u.uid WHERE f.tid = %d AND n.nid = f.nid AND n.type = 'forum' AND n.status = 1 AND c.status = 0 ORDER BY c.timestamp DESC", $term, 0, 1)); $reply = db_fetch_object(db_query_range("SELECT n.nid, c.timestamp, u.name AS name, u.uid AS uid FROM {forum} f LEFT JOIN {node} n ON n.nid = f.nid LEFT JOIN {comments} c ON n.nid = c.nid LEFT JOIN {users} u ON c.uid = u.uid WHERE f.tid = %d AND n.nid = f.nid AND n.type = 'forum' AND n.status = 1 AND c.status = 0 ORDER BY c.timestamp DESC", $term, 0, 1));
$value = ($topic->timestamp > $reply->timestamp) ? $topic : $reply; $value = ($topic->timestamp > $reply->timestamp) ? $topic : $reply;
@ -387,9 +387,9 @@ function forum_get_topics($tid, $sortby, $forum_per_page) {
$sql_sortby = _forum_get_topic_order($sortby); $sql_sortby = _forum_get_topic_order($sortby);
// show topics with the correct tid, or in the forum but with shadow = 1 // show topics with the correct tid, or in the forum but with shadow = 1
$sql = "SELECT n.nid, n.title, u.name AS name, u.uid AS uid, n.created AS timestamp, GREATEST(n.created, MAX(c.timestamp)) AS date_sort, COUNT(c.nid) AS num_comments, f.icon, n.comment AS comment_mode, f.tid FROM node n LEFT JOIN term_node r ON n.nid = r.nid LEFT JOIN users u ON n.uid = u.uid LEFT JOIN comments c ON n.nid = c.nid LEFT JOIN forum f ON n.nid = f.nid WHERE n.nid = r.nid AND ((r.tid = '".check_query($tid)."' AND f.shadow = 1) OR f.tid = '".check_query($tid)."') AND n.status = 1 AND n.type = 'forum' GROUP BY n.nid, n.title, u.name, u.uid, n.created, n.comment, f.tid, f.icon ORDER BY $sql_sortby"; $sql = "SELECT n.nid, n.title, u.name AS name, u.uid AS uid, n.created AS timestamp, GREATEST(n.created, MAX(c.timestamp)) AS date_sort, COUNT(c.nid) AS num_comments, f.icon, n.comment AS comment_mode, f.tid FROM {node} n LEFT JOIN {term_node} r ON n.nid = r.nid LEFT JOIN {users} u ON n.uid = u.uid LEFT JOIN {comments} c ON n.nid = c.nid LEFT JOIN {forum} f ON n.nid = f.nid WHERE n.nid = r.nid AND ((r.tid = '".check_query($tid)."' AND f.shadow = 1) OR f.tid = '".check_query($tid)."') AND n.status = 1 AND n.type = 'forum' GROUP BY n.nid, n.title, u.name, u.uid, n.created, n.comment, f.tid, f.icon ORDER BY $sql_sortby";
$sql_count = "SELECT COUNT(DISTINCT(n.nid)) FROM node n LEFT JOIN forum f ON n.nid = f.nid LEFT JOIN term_node r ON n.nid = r.nid WHERE n.nid = r.nid AND ( (r.tid = '".check_query($tid)."' AND f.shadow = 1) OR f.tid = '".check_query($tid)."') AND n.status = 1 AND n.type = 'forum'"; $sql_count = "SELECT COUNT(DISTINCT(n.nid)) FROM {node} n LEFT JOIN {forum} f ON n.nid = f.nid LEFT JOIN {term_node} r ON n.nid = r.nid WHERE n.nid = r.nid AND ( (r.tid = '".check_query($tid)."' AND f.shadow = 1) OR f.tid = '".check_query($tid)."') AND n.status = 1 AND n.type = 'forum'";
$result = pager_query($sql, $forum_per_page, 0, $sql_count); $result = pager_query($sql, $forum_per_page, 0, $sql_count);
$topic_num = db_num_rows($result); $topic_num = db_num_rows($result);
@ -408,7 +408,7 @@ function forum_get_topics($tid, $sortby, $forum_per_page) {
$topic->new = 1; $topic->new = 1;
} }
else { else {
$comments = db_result(db_query("SELECT COUNT(c.nid) FROM node n LEFT JOIN comments c ON n.nid = c.nid WHERE n.nid = '$topic->nid' AND n.status = 1 AND c.status = 0 AND timestamp > '$history' GROUP BY n.nid")); $comments = db_result(db_query("SELECT COUNT(c.nid) FROM {node} n LEFT JOIN {comments} c ON n.nid = c.nid WHERE n.nid = '$topic->nid' AND n.status = 1 AND c.status = 0 AND timestamp > '$history' GROUP BY n.nid"));
$topic->new_replies = $comments ? $comments : 0; $topic->new_replies = $comments ? $comments : 0;
if ($topic->new_replies) { if ($topic->new_replies) {
@ -435,12 +435,12 @@ function forum_get_topics($tid, $sortby, $forum_per_page) {
function _forum_new($tid) { function _forum_new($tid) {
global $user; global $user;
$result = db_query("SELECT n.nid FROM node n, history h, forum f WHERE n.type = 'forum' AND n.status = 1 AND h.nid = n.nid AND f.nid = h.nid AND f.tid = %d AND h.uid = %d", $tid, $user->uid); $result = db_query("SELECT n.nid FROM {node} n, {history} h, {forum} f WHERE n.type = 'forum' AND n.status = 1 AND h.nid = n.nid AND f.nid = h.nid AND f.tid = %d AND h.uid = %d", $tid, $user->uid);
while ($r = db_fetch_object($result)) { while ($r = db_fetch_object($result)) {
$read[] = $r->nid; $read[] = $r->nid;
} }
$nid = db_result(db_query_range("SELECT n.nid FROM node n LEFT JOIN forum f ON n.nid = f.nid WHERE n.type = 'forum' AND f.nid = n.nid AND n.status = 1 AND f.tid = %d ".($read ? "AND NOT (n.nid IN (".implode(",", $read).")) " : "") ."ORDER BY created", $tid, 0, 1)); $nid = db_result(db_query_range("SELECT n.nid FROM {node} n LEFT JOIN {forum} f ON n.nid = f.nid WHERE n.type = 'forum' AND f.nid = n.nid AND n.status = 1 AND f.tid = %d ".($read ? "AND NOT (n.nid IN (".implode(",", $read).")) " : "") ."ORDER BY created", $tid, 0, 1));
return $nid ? $nid : 0; return $nid ? $nid : 0;
} }
@ -688,7 +688,7 @@ function _forum_user_last_visit($nid) {
global $user; global $user;
static $history; static $history;
if (!$history) { if (!$history) {
$result = db_query("SELECT nid, timestamp FROM history WHERE uid = %d", $user->uid); $result = db_query("SELECT nid, timestamp FROM {history} WHERE uid = %d", $user->uid);
while ($t = db_fetch_object($result)) { while ($t = db_fetch_object($result)) {
$history[$t->nid] = $t->timestamp; $history[$t->nid] = $t->timestamp;
} }

View File

@ -71,7 +71,7 @@ function forum_taxonomy($op, $type, $object) {
} }
function forum_load($node) { function forum_load($node) {
$forum = db_fetch_object(db_query("SELECT * FROM forum WHERE nid = %d", $node->nid)); $forum = db_fetch_object(db_query("SELECT * FROM {forum} WHERE nid = %d", $node->nid));
return $forum; return $forum;
} }
@ -86,10 +86,10 @@ function forum_block($op = "list", $delta = 0) {
if (empty($cache)) { if (empty($cache)) {
unset($items); unset($items);
$content = node_title_list(db_query_range("SELECT n.nid, n.title, u.uid, u.name, GREATEST(n.created, MAX(c.timestamp)) AS sort FROM node n LEFT JOIN forum f ON n.nid = f.nid LEFT JOIN comments c ON n.nid = c.nid LEFT JOIN users u ON n.uid = u.uid WHERE n.type = 'forum' AND n.nid = f.nid AND n.status = 1 GROUP BY n.nid, n.title, n.created, u.uid, u.name ORDER BY sort DESC", 0, variable_get("forum_block_num", "5")), t("Active forum topics:")); $content = node_title_list(db_query_range("SELECT n.nid, n.title, u.uid, u.name, GREATEST(n.created, MAX(c.timestamp)) AS sort FROM {node} n LEFT JOIN {forum} f ON n.nid = f.nid LEFT JOIN {comments} c ON n.nid = c.nid LEFT JOIN {users} u ON n.uid = u.uid WHERE n.type = 'forum' AND n.nid = f.nid AND n.status = 1 GROUP BY n.nid, n.title, n.created, u.uid, u.name ORDER BY sort DESC", 0, variable_get("forum_block_num", "5")), t("Active forum topics:"));
unset ($items); unset ($items);
$content .= node_title_list(db_query_range("SELECT n.nid, n.title, u.uid, u.name FROM node n LEFT JOIN forum f ON n.nid = f.nid LEFT JOIN users u ON n.uid = u.uid WHERE n.type = 'forum' ORDER BY n.nid DESC", 0, variable_get("forum_block_num", "5")), t("New forum topics:")); $content .= node_title_list(db_query_range("SELECT n.nid, n.title, u.uid, u.name FROM {node} n LEFT JOIN {forum} f ON n.nid = f.nid LEFT JOIN {users} u ON n.uid = u.uid WHERE n.type = 'forum' ORDER BY n.nid DESC", 0, variable_get("forum_block_num", "5")), t("New forum topics:"));
if ($content) { if ($content) {
$content .= "<div id=\"forum_more\" style=\"text-align: right;\">". l(t("more"), "forum", array("title" => t("Read the latest forum topics."))) ."</div>"; $content .= "<div id=\"forum_more\" style=\"text-align: right;\">". l(t("more"), "forum", array("title" => t("Read the latest forum topics."))) ."</div>";
@ -121,7 +121,7 @@ function forum_link($type, $node = 0, $main = 0) {
if (!$main && $type == "node" && $node->type == "forum") { if (!$main && $type == "node" && $node->type == "forum") {
// get previous and next topic // get previous and next topic
$result = db_query("SELECT n.nid, n.title, n.body, GREATEST(n.created, MAX(c.timestamp)) AS date_sort, COUNT(c.nid) AS num_comments FROM node n LEFT JOIN forum f ON n.nid = f.nid LEFT JOIN comments c ON n.nid = c.nid WHERE n.nid = f.nid AND f.tid = %d AND n.status = 1 GROUP BY n.nid, n.title, n.body, n.created ORDER BY ". _forum_get_topic_order(isset($user->sortby) ? $user->sortby : variable_get("forum_order",1)), $node->tid); $result = db_query("SELECT n.nid, n.title, n.body, GREATEST(n.created, MAX(c.timestamp)) AS date_sort, COUNT(c.nid) AS num_comments FROM {node} n LEFT JOIN {forum} f ON n.nid = f.nid LEFT JOIN {comments} c ON n.nid = c.nid WHERE n.nid = f.nid AND f.tid = %d AND n.status = 1 GROUP BY n.nid, n.title, n.body, n.created ORDER BY ". _forum_get_topic_order(isset($user->sortby) ? $user->sortby : variable_get("forum_order",1)), $node->tid);
while ($topic = db_fetch_object($result)) { while ($topic = db_fetch_object($result)) {
if ($stop == 1) { if ($stop == 1) {
@ -241,12 +241,12 @@ function forum_form(&$node, &$help, &$error) {
function forum_insert($node) { function forum_insert($node) {
$node->icon = _forum_decode_icon($node); $node->icon = _forum_decode_icon($node);
db_query("INSERT INTO forum (nid, icon, shadow, tid) VALUES (%d, '%s', %d, %d)", $node->nid, $node->icon, $node->shadow, $node->tid[0]); db_query("INSERT INTO {forum} (nid, icon, shadow, tid) VALUES (%d, '%s', %d, %d)", $node->nid, $node->icon, $node->shadow, $node->tid[0]);
} }
function forum_update($node) { function forum_update($node) {
$node->icon = _forum_decode_icon($node); $node->icon = _forum_decode_icon($node);
db_query("UPDATE forum SET icon = '%s', shadow = %d, tid = %d WHERE nid = %d", $node->icon, $node->shadow, $node->tid[0], $node->nid); db_query("UPDATE {forum} SET icon = '%s', shadow = %d, tid = %d WHERE nid = %d", $node->icon, $node->shadow, $node->tid[0], $node->nid);
} }
function _forum_decode_icon($node) { function _forum_decode_icon($node) {
@ -266,21 +266,21 @@ function _forum_decode_icon($node) {
} }
function forum_delete(&$node) { function forum_delete(&$node) {
db_query("DELETE FROM forum WHERE nid = %d", $node->nid); db_query("DELETE FROM {forum} WHERE nid = %d", $node->nid);
} }
function _forum_num_comments($nid) { function _forum_num_comments($nid) {
$value = db_fetch_object(db_query("SELECT COUNT(cid) AS count FROM comments WHERE nid = %d AND status = 0", $nid)); $value = db_fetch_object(db_query("SELECT COUNT(cid) AS count FROM {comments} WHERE nid = %d AND status = 0", $nid));
return ($value) ? $value->count : 0; return ($value) ? $value->count : 0;
} }
function _forum_last_comment($nid) { function _forum_last_comment($nid) {
$value = db_fetch_object(db_query_range("SELECT timestamp FROM comments WHERE nid = %d AND status = 0 ORDER BY timestamp DESC", $nid, 0, 1)); $value = db_fetch_object(db_query_range("SELECT timestamp FROM {comments} WHERE nid = %d AND status = 0 ORDER BY timestamp DESC", $nid, 0, 1));
return ($value) ? format_date($value->timestamp, "small") : "&nbsp;"; return ($value) ? format_date($value->timestamp, "small") : "&nbsp;";
} }
function _forum_last_reply($nid) { function _forum_last_reply($nid) {
$value = db_fetch_object(db_query_range("SELECT c.timestamp, u.name, u.uid FROM comments c LEFT JOIN users u ON c.uid = u.uid WHERE c.nid = %d AND c.status = 0 ORDER BY c.timestamp DESC", $nid, 0, 1)); $value = db_fetch_object(db_query_range("SELECT c.timestamp, u.name, u.uid FROM {comments} c LEFT JOIN {users} u ON c.uid = u.uid WHERE c.nid = %d AND c.status = 0 ORDER BY c.timestamp DESC", $nid, 0, 1));
return $value; return $value;
} }
@ -349,17 +349,17 @@ function forum_get_parents($tid) {
} }
function _forum_num_topics($term) { function _forum_num_topics($term) {
$value = db_fetch_object(db_query("SELECT COUNT(n.nid) AS count FROM node n LEFT JOIN forum f ON n.nid = f.nid WHERE f.tid = %d AND n.nid = f.nid AND n.status = 1 AND n.type = 'forum'", $term)); $value = db_fetch_object(db_query("SELECT COUNT(n.nid) AS count FROM {node} n LEFT JOIN {forum} f ON n.nid = f.nid WHERE f.tid = %d AND n.nid = f.nid AND n.status = 1 AND n.type = 'forum'", $term));
return ($value) ? $value->count : 0; return ($value) ? $value->count : 0;
} }
function _forum_num_replies($term) { function _forum_num_replies($term) {
$value = db_fetch_object(db_query("SELECT COUNT(*) AS count FROM comments c LEFT JOIN node n ON n.nid = c.nid LEFT JOIN forum f ON n.nid = f.nid WHERE f.tid = %d AND n.nid = f.nid AND n.nid = c.nid AND n.status = 1 AND c.status = 0 AND n.type = 'forum'", $term)); $value = db_fetch_object(db_query("SELECT COUNT(*) AS count FROM {comments} c LEFT JOIN {node} n ON n.nid = c.nid LEFT JOIN {forum} f ON n.nid = f.nid WHERE f.tid = %d AND n.nid = f.nid AND n.nid = c.nid AND n.status = 1 AND c.status = 0 AND n.type = 'forum'", $term));
return ($value) ? $value->count : 0; return ($value) ? $value->count : 0;
} }
function _forum_topics_read($uid) { function _forum_topics_read($uid) {
$result = db_query("SELECT tid, count(*) AS c FROM history h LEFT JOIN node n ON n.nid = h.nid LEFT JOIN forum f ON n.nid = f.nid WHERE f.nid = n.nid AND n.nid = h.nid AND n.type = 'forum' AND n.status = 1 AND h.uid = %d GROUP BY tid", $uid); $result = db_query("SELECT tid, count(*) AS c FROM {history} h LEFT JOIN {node} n ON n.nid = h.nid LEFT JOIN {forum} f ON n.nid = f.nid WHERE f.nid = n.nid AND n.nid = h.nid AND n.type = 'forum' AND n.status = 1 AND h.uid = %d GROUP BY tid", $uid);
while ($obj = db_fetch_object($result)) { while ($obj = db_fetch_object($result)) {
$topics_read[$obj->tid] = $obj->c; $topics_read[$obj->tid] = $obj->c;
@ -369,9 +369,9 @@ function _forum_topics_read($uid) {
} }
function _forum_last_post($term) { function _forum_last_post($term) {
$topic = db_fetch_object(db_query_range("SELECT n.nid, n.created AS timestamp, u.name AS name, u.uid AS uid FROM forum f LEFT JOIN node n ON n.nid = f.nid LEFT JOIN users u ON n.uid = u.uid WHERE f.tid = %d AND n.nid = f.nid AND n.type = 'forum' AND n.status = 1 ORDER BY timestamp DESC", $term, 0, 1)); $topic = db_fetch_object(db_query_range("SELECT n.nid, n.created AS timestamp, u.name AS name, u.uid AS uid FROM {forum} f LEFT JOIN {node} n ON n.nid = f.nid LEFT JOIN {users} u ON n.uid = u.uid WHERE f.tid = %d AND n.nid = f.nid AND n.type = 'forum' AND n.status = 1 ORDER BY timestamp DESC", $term, 0, 1));
$reply = db_fetch_object(db_query_range("SELECT n.nid, c.timestamp, u.name AS name, u.uid AS uid FROM forum f LEFT JOIN node n ON n.nid = f.nid LEFT JOIN comments c ON n.nid = c.nid LEFT JOIN users u ON c.uid = u.uid WHERE f.tid = %d AND n.nid = f.nid AND n.type = 'forum' AND n.status = 1 AND c.status = 0 ORDER BY c.timestamp DESC", $term, 0, 1)); $reply = db_fetch_object(db_query_range("SELECT n.nid, c.timestamp, u.name AS name, u.uid AS uid FROM {forum} f LEFT JOIN {node} n ON n.nid = f.nid LEFT JOIN {comments} c ON n.nid = c.nid LEFT JOIN {users} u ON c.uid = u.uid WHERE f.tid = %d AND n.nid = f.nid AND n.type = 'forum' AND n.status = 1 AND c.status = 0 ORDER BY c.timestamp DESC", $term, 0, 1));
$value = ($topic->timestamp > $reply->timestamp) ? $topic : $reply; $value = ($topic->timestamp > $reply->timestamp) ? $topic : $reply;
@ -387,9 +387,9 @@ function forum_get_topics($tid, $sortby, $forum_per_page) {
$sql_sortby = _forum_get_topic_order($sortby); $sql_sortby = _forum_get_topic_order($sortby);
// show topics with the correct tid, or in the forum but with shadow = 1 // show topics with the correct tid, or in the forum but with shadow = 1
$sql = "SELECT n.nid, n.title, u.name AS name, u.uid AS uid, n.created AS timestamp, GREATEST(n.created, MAX(c.timestamp)) AS date_sort, COUNT(c.nid) AS num_comments, f.icon, n.comment AS comment_mode, f.tid FROM node n LEFT JOIN term_node r ON n.nid = r.nid LEFT JOIN users u ON n.uid = u.uid LEFT JOIN comments c ON n.nid = c.nid LEFT JOIN forum f ON n.nid = f.nid WHERE n.nid = r.nid AND ((r.tid = '".check_query($tid)."' AND f.shadow = 1) OR f.tid = '".check_query($tid)."') AND n.status = 1 AND n.type = 'forum' GROUP BY n.nid, n.title, u.name, u.uid, n.created, n.comment, f.tid, f.icon ORDER BY $sql_sortby"; $sql = "SELECT n.nid, n.title, u.name AS name, u.uid AS uid, n.created AS timestamp, GREATEST(n.created, MAX(c.timestamp)) AS date_sort, COUNT(c.nid) AS num_comments, f.icon, n.comment AS comment_mode, f.tid FROM {node} n LEFT JOIN {term_node} r ON n.nid = r.nid LEFT JOIN {users} u ON n.uid = u.uid LEFT JOIN {comments} c ON n.nid = c.nid LEFT JOIN {forum} f ON n.nid = f.nid WHERE n.nid = r.nid AND ((r.tid = '".check_query($tid)."' AND f.shadow = 1) OR f.tid = '".check_query($tid)."') AND n.status = 1 AND n.type = 'forum' GROUP BY n.nid, n.title, u.name, u.uid, n.created, n.comment, f.tid, f.icon ORDER BY $sql_sortby";
$sql_count = "SELECT COUNT(DISTINCT(n.nid)) FROM node n LEFT JOIN forum f ON n.nid = f.nid LEFT JOIN term_node r ON n.nid = r.nid WHERE n.nid = r.nid AND ( (r.tid = '".check_query($tid)."' AND f.shadow = 1) OR f.tid = '".check_query($tid)."') AND n.status = 1 AND n.type = 'forum'"; $sql_count = "SELECT COUNT(DISTINCT(n.nid)) FROM {node} n LEFT JOIN {forum} f ON n.nid = f.nid LEFT JOIN {term_node} r ON n.nid = r.nid WHERE n.nid = r.nid AND ( (r.tid = '".check_query($tid)."' AND f.shadow = 1) OR f.tid = '".check_query($tid)."') AND n.status = 1 AND n.type = 'forum'";
$result = pager_query($sql, $forum_per_page, 0, $sql_count); $result = pager_query($sql, $forum_per_page, 0, $sql_count);
$topic_num = db_num_rows($result); $topic_num = db_num_rows($result);
@ -408,7 +408,7 @@ function forum_get_topics($tid, $sortby, $forum_per_page) {
$topic->new = 1; $topic->new = 1;
} }
else { else {
$comments = db_result(db_query("SELECT COUNT(c.nid) FROM node n LEFT JOIN comments c ON n.nid = c.nid WHERE n.nid = '$topic->nid' AND n.status = 1 AND c.status = 0 AND timestamp > '$history' GROUP BY n.nid")); $comments = db_result(db_query("SELECT COUNT(c.nid) FROM {node} n LEFT JOIN {comments} c ON n.nid = c.nid WHERE n.nid = '$topic->nid' AND n.status = 1 AND c.status = 0 AND timestamp > '$history' GROUP BY n.nid"));
$topic->new_replies = $comments ? $comments : 0; $topic->new_replies = $comments ? $comments : 0;
if ($topic->new_replies) { if ($topic->new_replies) {
@ -435,12 +435,12 @@ function forum_get_topics($tid, $sortby, $forum_per_page) {
function _forum_new($tid) { function _forum_new($tid) {
global $user; global $user;
$result = db_query("SELECT n.nid FROM node n, history h, forum f WHERE n.type = 'forum' AND n.status = 1 AND h.nid = n.nid AND f.nid = h.nid AND f.tid = %d AND h.uid = %d", $tid, $user->uid); $result = db_query("SELECT n.nid FROM {node} n, {history} h, {forum} f WHERE n.type = 'forum' AND n.status = 1 AND h.nid = n.nid AND f.nid = h.nid AND f.tid = %d AND h.uid = %d", $tid, $user->uid);
while ($r = db_fetch_object($result)) { while ($r = db_fetch_object($result)) {
$read[] = $r->nid; $read[] = $r->nid;
} }
$nid = db_result(db_query_range("SELECT n.nid FROM node n LEFT JOIN forum f ON n.nid = f.nid WHERE n.type = 'forum' AND f.nid = n.nid AND n.status = 1 AND f.tid = %d ".($read ? "AND NOT (n.nid IN (".implode(",", $read).")) " : "") ."ORDER BY created", $tid, 0, 1)); $nid = db_result(db_query_range("SELECT n.nid FROM {node} n LEFT JOIN {forum} f ON n.nid = f.nid WHERE n.type = 'forum' AND f.nid = n.nid AND n.status = 1 AND f.tid = %d ".($read ? "AND NOT (n.nid IN (".implode(",", $read).")) " : "") ."ORDER BY created", $tid, 0, 1));
return $nid ? $nid : 0; return $nid ? $nid : 0;
} }
@ -688,7 +688,7 @@ function _forum_user_last_visit($nid) {
global $user; global $user;
static $history; static $history;
if (!$history) { if (!$history) {
$result = db_query("SELECT nid, timestamp FROM history WHERE uid = %d", $user->uid); $result = db_query("SELECT nid, timestamp FROM {history} WHERE uid = %d", $user->uid);
while ($t = db_fetch_object($result)) { while ($t = db_fetch_object($result)) {
$history[$t->nid] = $t->timestamp; $history[$t->nid] = $t->timestamp;
} }

View File

@ -95,14 +95,14 @@ function import_link($type) {
} }
function import_cron() { function import_cron() {
$result = db_query("SELECT * FROM feed WHERE timestamp + refresh < ". time()); $result = db_query("SELECT * FROM {feed} WHERE timestamp + refresh < ". time());
while ($feed = db_fetch_array($result)) { while ($feed = db_fetch_array($result)) {
import_refresh($feed); import_refresh($feed);
} }
} }
function import_update() { function import_update() {
$result = db_query("SELECT * FROM feed"); $result = db_query("SELECT * FROM {feed} ");
while ($feed = db_fetch_array($result)) { while ($feed = db_fetch_array($result)) {
import_refresh($feed); import_refresh($feed);
} }
@ -127,7 +127,7 @@ function import_bundle_block($attributes) {
$keys = explode(",", $attributes); $keys = explode(",", $attributes);
foreach ($keys as $key) $where[] = "attributes LIKE '%". trim($key) ."%'"; foreach ($keys as $key) $where[] = "attributes LIKE '%". trim($key) ."%'";
$result = db_query_range("SELECT * FROM item WHERE ". implode(" OR ", $where) ." ORDER BY iid DESC", 0, variable_get("import_block_limit", 15)); $result = db_query_range("SELECT * FROM {item} WHERE ". implode(" OR ", $where) ." ORDER BY iid DESC", 0, variable_get("import_block_limit", 15));
} }
$items = array(); $items = array();
@ -143,7 +143,7 @@ function import_bundle_block($attributes) {
} }
function import_feed_block($feed) { function import_feed_block($feed) {
$result = db_query_range("SELECT * FROM item WHERE fid = %d ORDER BY iid DESC ", $feed->fid, 0, variable_get("import_block_limit", 15)); $result = db_query_range("SELECT * FROM {item} WHERE fid = %d ORDER BY iid DESC ", $feed->fid, 0, variable_get("import_block_limit", 15));
$items = array(); $items = array();
while ($item = db_fetch_object($result)) { while ($item = db_fetch_object($result)) {
@ -159,12 +159,12 @@ function import_feed_block($feed) {
function import_block($op, $delta) { function import_block($op, $delta) {
if ($op == "list") { if ($op == "list") {
$result = db_query("SELECT * FROM bundle ORDER BY title"); $result = db_query("SELECT * FROM {bundle} ORDER BY title");
while ($bundle = db_fetch_object($result)) { while ($bundle = db_fetch_object($result)) {
$block["bundle:$bundle->bid"]["info"] = "$bundle->title bundle"; $block["bundle:$bundle->bid"]["info"] = "$bundle->title bundle";
} }
$result = db_query("SELECT * FROM feed ORDER BY fid"); $result = db_query("SELECT * FROM {feed} ORDER BY fid");
while ($feed = db_fetch_object($result)) { while ($feed = db_fetch_object($result)) {
$block["feed:$feed->fid"]["info"] = "$feed->title feed"; $block["feed:$feed->fid"]["info"] = "$feed->title feed";
} }
@ -175,13 +175,13 @@ function import_block($op, $delta) {
list($type, $id) = split(":", $delta); list($type, $id) = split(":", $delta);
switch ($type) { switch ($type) {
case "feed": case "feed":
$feed = db_fetch_object(db_query("SELECT * FROM feed WHERE fid = %d", $id)); $feed = db_fetch_object(db_query("SELECT * FROM {feed} WHERE fid = %d", $id));
$block["subject"] = $feed->title; $block["subject"] = $feed->title;
$block["content"] .= import_feed_block($feed) ."<div style=\"text-align: right;\">". l(t("more"), "import/feed/$feed->fid", array("title" => t("View this feed's recent news."))) ."</div>"; $block["content"] .= import_feed_block($feed) ."<div style=\"text-align: right;\">". l(t("more"), "import/feed/$feed->fid", array("title" => t("View this feed's recent news."))) ."</div>";
break; break;
case "bundle": case "bundle":
$bundle = db_fetch_object(db_query("SELECT * FROM bundle WHERE bid = %d", $id)); $bundle = db_fetch_object(db_query("SELECT * FROM {bundle} WHERE bid = %d", $id));
$block["subject"] = $bundle->title; $block["subject"] = $bundle->title;
$block["content"] .= import_bundle_block($bundle->attributes) ."<div style=\"text-align: right;\">". l(t("more"), "import/bundle/$bundle->bid", array("title" => t("View this bundle's recent news."))) ."</div>"; $block["content"] .= import_bundle_block($bundle->attributes) ."<div style=\"text-align: right;\">". l(t("more"), "import/bundle/$bundle->bid", array("title" => t("View this bundle's recent news."))) ."</div>";
break; break;
@ -195,7 +195,7 @@ function import_get_bundles($attributes = 0) {
$block = array(); $block = array();
$result = db_query("SELECT * FROM bundle ORDER BY title"); $result = db_query("SELECT * FROM {bundle} ORDER BY title");
while ($bundle = db_fetch_object($result)) { while ($bundle = db_fetch_object($result)) {
$block["bundle:$bundle->bid"]["subject"] = $bundle->title; $block["bundle:$bundle->bid"]["subject"] = $bundle->title;
$block["bundle:$bundle->bid"]["content"] = import_bundle_block($bundle->attributes) ."<div style=\"text-align: right;\">". $block["bundle:$bundle->bid"]["content"] = import_bundle_block($bundle->attributes) ."<div style=\"text-align: right;\">".
@ -211,7 +211,7 @@ function import_get_feeds($attributes = 0) {
$block = array(); $block = array();
$result = db_query("SELECT * FROM feed ORDER BY fid"); $result = db_query("SELECT * FROM {feed} ORDER BY fid");
while ($feed = db_fetch_object($result)) { while ($feed = db_fetch_object($result)) {
$block["feed:$feed->fid"]["subject"] = $feed->title; $block["feed:$feed->fid"]["subject"] = $feed->title;
$block["feed:$feed->fid"]["content"] = import_feed_block($feed) ."<div style=\"text-align: right;\">". $block["feed:$feed->fid"]["content"] = import_feed_block($feed) ."<div style=\"text-align: right;\">".
@ -224,7 +224,7 @@ function import_get_feeds($attributes = 0) {
} }
function import_remove($feed) { function import_remove($feed) {
db_query("DELETE FROM item WHERE fid = %d", $feed["fid"]); db_query("DELETE FROM {item} WHERE fid = %d", $feed["fid"]);
return t("removed news items from '%site'.", array("%site" => $feed["title"])); return t("removed news items from '%site'.", array("%site" => $feed["title"]));
} }
@ -323,7 +323,7 @@ function import_refresh($feed) {
$tt = array_flip(get_html_translation_table(HTML_ENTITIES)); $tt = array_flip(get_html_translation_table(HTML_ENTITIES));
$tt["&apos;"] = "'"; $tt["&apos;"] = "'";
db_query("UPDATE feed SET timestamp = %d, link = '%s', description = '%s' WHERE fid = %d", time(), $channel["LINK"], $channel["DESCRIPTION"], $feed["fid"]); db_query("UPDATE {feed} SET timestamp = %d, link = '%s', description = '%s' WHERE fid = %d", time(), $channel["LINK"], $channel["DESCRIPTION"], $feed["fid"]);
/* /*
** We reverse the array such that we store the first item last, ** We reverse the array such that we store the first item last,
@ -369,10 +369,10 @@ function import_refresh($feed) {
*/ */
if ($link && $link != $feed["link"] && $link != $feed["url"]) { if ($link && $link != $feed["link"] && $link != $feed["url"]) {
$entry = db_fetch_object(db_query("SELECT iid FROM item WHERE fid = %d AND link = '%s'", $feed["fid"], $link)); $entry = db_fetch_object(db_query("SELECT iid FROM {item} WHERE fid = %d AND link = '%s'", $feed["fid"], $link));
} }
else { else {
$entry = db_fetch_object(db_query("SELECT iid FROM item WHERE fid = %d AND title = '%s'", $feed["fid"], $title)); $entry = db_fetch_object(db_query("SELECT iid FROM {item} WHERE fid = %d AND title = '%s'", $feed["fid"], $title));
} }
import_save_item(array(iid => $entry->iid, fid => $feed["fid"], title => $title, link => $link, author => $item["AUTHOR"], description => $item["DESCRIPTION"], attributes => $feed["attributes"])); import_save_item(array(iid => $entry->iid, fid => $feed["fid"], title => $title, link => $link, author => $item["AUTHOR"], description => $item["DESCRIPTION"], attributes => $feed["attributes"]));
@ -384,14 +384,14 @@ function import_refresh($feed) {
unset($items); unset($items);
$result = db_query("SELECT iid FROM item WHERE fid = %d ORDER BY timestamp", $feed["fid"]); $result = db_query("SELECT iid FROM {item} WHERE fid = %d ORDER BY timestamp", $feed["fid"]);
while ($item = db_fetch_object($result)) { while ($item = db_fetch_object($result)) {
$items[] = "iid = '$item->iid'"; $items[] = "iid = '$item->iid'";
} }
if (sizeof($items) > 50) { if (sizeof($items) > 50) {
db_query("DELETE FROM item WHERE ". implode(" OR ", array_slice($items, 0, - 50))); db_query("DELETE FROM {item} WHERE ". implode(" OR ", array_slice($items, 0, - 50)));
} }
cache_clear_all(); cache_clear_all();
@ -405,13 +405,13 @@ function import_refresh($feed) {
function import_save_item($edit) { function import_save_item($edit) {
if ($edit["iid"] && $edit["title"]) { if ($edit["iid"] && $edit["title"]) {
db_query("UPDATE item SET title = '%s', link = '%s', author = '%s', description = '%s', attributes = '%s' WHERE iid = %d", $edit["title"], $edit["link"], $edit["author"], $edit["description"], $edit["attributes"], $edit["iid"]); db_query("UPDATE {item} SET title = '%s', link = '%s', author = '%s', description = '%s', attributes = '%s' WHERE iid = %d", $edit["title"], $edit["link"], $edit["author"], $edit["description"], $edit["attributes"], $edit["iid"]);
} }
else if ($edit["iid"]) { else if ($edit["iid"]) {
db_query("DELETE FROM item WHERE iid = %d", $edit["iid"]); db_query("DELETE FROM {item} WHERE iid = %d", $edit["iid"]);
} }
else if ($edit["title"] && $edit["link"]) { else if ($edit["title"] && $edit["link"]) {
db_query("INSERT INTO item (fid, title, link, author, description, attributes, timestamp) VALUES (%d, '%s', '%s', '%s', '%s', '%s', %d)", $edit["fid"], $edit["title"], $edit["link"], $edit["author"], $edit["description"], $edit["attributes"], time()); db_query("INSERT INTO {item} (fid, title, link, author, description, attributes, timestamp) VALUES (%d, '%s', '%s', '%s', '%s', '%s', %d)", $edit["fid"], $edit["title"], $edit["link"], $edit["author"], $edit["description"], $edit["attributes"], time());
} }
} }
@ -432,15 +432,15 @@ function import_form_bundle($edit = array()) {
function import_save_bundle($edit) { function import_save_bundle($edit) {
if ($edit["bid"] && $edit["title"]) { if ($edit["bid"] && $edit["title"]) {
db_query("UPDATE bundle SET title = '%s', attributes = '%s' WHERE bid = %d", $edit["title"], $edit["attributes"], $edit["bid"]); db_query("UPDATE {bundle} SET title = '%s', attributes = '%s' WHERE bid = %d", $edit["title"], $edit["attributes"], $edit["bid"]);
} }
else if ($edit["bid"]) { else if ($edit["bid"]) {
db_query("DELETE FROM bundle WHERE bid = %d", $edit["bid"]); db_query("DELETE FROM {bundle} WHERE bid = %d", $edit["bid"]);
} }
else if ($edit["title"]) { else if ($edit["title"]) {
// a single unique id for bundles and feeds, to use in blocks // a single unique id for bundles and feeds, to use in blocks
$next_id = db_next_id("bundle_bid"); $next_id = db_next_id("bundle_bid");
db_query("INSERT INTO bundle (bid, title, attributes) VALUES (%d, '%s', '%s')", $next_id, $edit["title"], $edit["attributes"]); db_query("INSERT INTO {bundle} (bid, title, attributes) VALUES (%d, '%s', '%s')", $next_id, $edit["title"], $edit["attributes"]);
} }
} }
@ -469,37 +469,37 @@ function import_form_feed($edit = array()) {
function import_save_feed($edit) { function import_save_feed($edit) {
if ($edit["fid"] && $edit["title"]) { if ($edit["fid"] && $edit["title"]) {
db_query("UPDATE feed SET title = '%s', url = '%s', attributes = '%s', refresh = %d WHERE fid = %d", $edit["title"], $edit["url"], $edit["attributes"], $edit["refresh"], $edit["fid"]); db_query("UPDATE {feed} SET title = '%s', url = '%s', attributes = '%s', refresh = %d WHERE fid = %d", $edit["title"], $edit["url"], $edit["attributes"], $edit["refresh"], $edit["fid"]);
db_query("DELETE FROM item WHERE fid = %d", $edit["fid"]); db_query("DELETE FROM {item} WHERE fid = %d", $edit["fid"]);
} }
else if ($edit["fid"]) { else if ($edit["fid"]) {
db_query("DELETE FROM feed WHERE fid = %d", $edit["fid"]); db_query("DELETE FROM {feed} WHERE fid = %d", $edit["fid"]);
db_query("DELETE FROM item WHERE fid = %d", $edit["fid"]); db_query("DELETE FROM {item} WHERE fid = %d", $edit["fid"]);
} }
else if ($edit["title"]) { else if ($edit["title"]) {
// a single unique id for bundles and feeds, to use in blocks // a single unique id for bundles and feeds, to use in blocks
$next_id = db_next_id("feed_fid"); $next_id = db_next_id("feed_fid");
db_query("INSERT INTO feed (fid, title, url, attributes, refresh) VALUES (%d, '%s', '%s', '%s', %d)", $next_id, $edit["title"], $edit["url"], $edit["attributes"], $edit["refresh"]); db_query("INSERT INTO {feed} (fid, title, url, attributes, refresh) VALUES (%d, '%s', '%s', '%s', %d)", $next_id, $edit["title"], $edit["url"], $edit["attributes"], $edit["refresh"]);
} }
} }
function import_save_attributes($edit) { function import_save_attributes($edit) {
foreach ($edit as $iid => $value) { foreach ($edit as $iid => $value) {
db_query("UPDATE item SET attributes = '%s' WHERE iid = %d", $value, $iid); db_query("UPDATE {item} SET attributes = '%s' WHERE iid = %d", $value, $iid);
} }
return "attributes has been saved"; return "attributes has been saved";
} }
function import_get_feed($fid) { function import_get_feed($fid) {
return db_fetch_array(db_query("SELECT * FROM feed WHERE fid = %d", $fid)); return db_fetch_array(db_query("SELECT * FROM {feed} WHERE fid = %d", $fid));
} }
function import_get_bundle($bid) { function import_get_bundle($bid) {
return db_fetch_array(db_query("SELECT * FROM bundle WHERE bid = %d", $bid)); return db_fetch_array(db_query("SELECT * FROM {bundle} WHERE bid = %d", $bid));
} }
function import_view() { function import_view() {
$result = db_query("SELECT f.*, COUNT(i.iid) AS items FROM feed f LEFT JOIN item i ON f.fid = i.fid GROUP BY f.fid, f.title, f.url, f.refresh, f.timestamp, f.attributes, f.link, f.description ORDER BY f.title"); $result = db_query("SELECT f.*, COUNT(i.iid) AS items FROM {feed} f LEFT JOIN {item} i ON f.fid = i.fid GROUP BY f.fid, f.title, f.url, f.refresh, f.timestamp, f.attributes, f.link, f.description ORDER BY f.title");
$output .= "<h3>Feed overview</h3>"; $output .= "<h3>Feed overview</h3>";
@ -510,7 +510,7 @@ function import_view() {
} }
$output .= table($header, $rows); $output .= table($header, $rows);
$result = db_query("SELECT * FROM bundle ORDER BY title"); $result = db_query("SELECT * FROM {bundle} ORDER BY title");
$output .= "<h3>Bundle overview</h3>"; $output .= "<h3>Bundle overview</h3>";
@ -526,7 +526,7 @@ function import_view() {
function import_tag() { function import_tag() {
$result = db_query_range("SELECT i.*, f.title AS feed FROM item i LEFT JOIN feed f ON i.fid = f.fid ORDER BY i.iid DESC", 0, 50); $result = db_query_range("SELECT i.*, f.title AS feed FROM {item} i LEFT JOIN {feed} f ON i.fid = f.fid ORDER BY i.iid DESC", 0, 50);
$header = array(t("date"), t("feed"), t("news item")); $header = array(t("date"), t("feed"), t("news item"));
while ($item = db_fetch_object($result)) { while ($item = db_fetch_object($result)) {
@ -619,7 +619,7 @@ function import_page_info() {
function import_page_last() { function import_page_last() {
$result = db_query_range("SELECT i.*, f.title AS ftitle, f.link AS flink FROM item i LEFT JOIN feed f ON i.fid = f.fid ORDER BY i.iid DESC", 0, variable_get("import_page_limit", 75)); $result = db_query_range("SELECT i.*, f.title AS ftitle, f.link AS flink FROM {item} i LEFT JOIN {feed} f ON i.fid = f.fid ORDER BY i.iid DESC", 0, variable_get("import_page_limit", 75));
$output .= "<table border=\"0\" cellpadding=\"4\" cellspacing=\"2\">"; $output .= "<table border=\"0\" cellpadding=\"4\" cellspacing=\"2\">";
while ($item = db_fetch_object($result)) { while ($item = db_fetch_object($result)) {
@ -649,13 +649,13 @@ function import_page_last() {
function import_page_feed($fid) { function import_page_feed($fid) {
$feed = db_fetch_object(db_query("SELECT * FROM feed WHERE fid = %d", $fid)); $feed = db_fetch_object(db_query("SELECT * FROM {feed} WHERE fid = %d", $fid));
$header .= "<p><b>". t("Website") .":</b><div style=\"margin-left: 20px;\"><a href=\"$feed->link\">$feed->link</a></div></p>"; $header .= "<p><b>". t("Website") .":</b><div style=\"margin-left: 20px;\"><a href=\"$feed->link\">$feed->link</a></div></p>";
$header .= "<p><b>". t("Description") .":</b><div style=\"margin-left: 20px;\">$feed->description</div></p>"; $header .= "<p><b>". t("Description") .":</b><div style=\"margin-left: 20px;\">$feed->description</div></p>";
$header .= "<p><b>". t("Last update") .":</b><div style=\"margin-left: 20px; text-align: right;\">". format_interval(time() - $feed->timestamp) ." ". t("ago") ." <a href=\"$feed->url\"><img src=\"". theme("image", "xml.gif") ."\" width=\"36\" height=\"14\" style=\"border: 0px;\" alt=\"\" title=\"\" /></a><br /><br /></div></p>\n"; $header .= "<p><b>". t("Last update") .":</b><div style=\"margin-left: 20px; text-align: right;\">". format_interval(time() - $feed->timestamp) ." ". t("ago") ." <a href=\"$feed->url\"><img src=\"". theme("image", "xml.gif") ."\" width=\"36\" height=\"14\" style=\"border: 0px;\" alt=\"\" title=\"\" /></a><br /><br /></div></p>\n";
$result = db_query_range("SELECT * FROM item WHERE fid = %d ORDER BY iid DESC", $fid, 0, variable_get("import_page_limit", 75)); $result = db_query_range("SELECT * FROM {item} WHERE fid = %d ORDER BY iid DESC", $fid, 0, variable_get("import_page_limit", 75));
$output .= "<table border=\"0\" cellpadding=\"4\" cellspacing=\"2\">"; $output .= "<table border=\"0\" cellpadding=\"4\" cellspacing=\"2\">";
while ($item = db_fetch_object($result)) { while ($item = db_fetch_object($result)) {
@ -685,14 +685,14 @@ function import_page_feed($fid) {
function import_page_bundle($bid) { function import_page_bundle($bid) {
$bundle = db_fetch_object(db_query("SELECT * FROM bundle WHERE bid = %d", $bid)); $bundle = db_fetch_object(db_query("SELECT * FROM {bundle} WHERE bid = %d", $bid));
$header .= "<p><b>". t("Website") .":</b><div style=\"margin-left: 20px;\">". l($bundle->title, "import/bundle/$bundle->bid") ."</div></p>"; $header .= "<p><b>". t("Website") .":</b><div style=\"margin-left: 20px;\">". l($bundle->title, "import/bundle/$bundle->bid") ."</div></p>";
$header .= "<p><b>". t("Description") .":</b><div style=\"margin-left: 20px;\">". t("A composite news feed about") ." $bundle->attributes.</div></p>"; $header .= "<p><b>". t("Description") .":</b><div style=\"margin-left: 20px;\">". t("A composite news feed about") ." $bundle->attributes.</div></p>";
$keys = explode(",", $bundle->attributes); $keys = explode(",", $bundle->attributes);
foreach ($keys as $key) $where[] = "i.attributes LIKE '%". trim($key) ."%'"; foreach ($keys as $key) $where[] = "i.attributes LIKE '%". trim($key) ."%'";
$result = db_query_range("SELECT i.*, f.title AS ftitle, f.link AS flink FROM item i, feed f WHERE (". implode(" OR ", $where) .") AND i.fid = f.fid ORDER BY iid DESC", 0, variable_get("import_page_limit", 75)); $result = db_query_range("SELECT i.*, f.title AS ftitle, f.link AS flink FROM {item} i, {feed} f WHERE (". implode(" OR ", $where) .") AND i.fid = f.fid ORDER BY iid DESC", 0, variable_get("import_page_limit", 75));
$output .= "<table border=\"0\" cellpadding=\"4\" cellspacing=\"2\">"; $output .= "<table border=\"0\" cellpadding=\"4\" cellspacing=\"2\">";
while ($item = db_fetch_object($result)) { while ($item = db_fetch_object($result)) {
@ -725,7 +725,7 @@ function import_page_bundle($bid) {
function import_page_sources() { function import_page_sources() {
$result = db_query("SELECT * FROM feed ORDER BY title"); $result = db_query("SELECT * FROM {feed} ORDER BY title");
while ($feed = db_fetch_object($result)) { while ($feed = db_fetch_object($result)) {
$output .= l($feed->title, "import/feed/$feed->fid"); $output .= l($feed->title, "import/feed/$feed->fid");
@ -742,7 +742,7 @@ function import_page_sources() {
function import_page_fd() { function import_page_fd() {
$result = db_query("SELECT * FROM feed ORDER BY title"); $result = db_query("SELECT * FROM {feed} ORDER BY title");
$output .= "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n\n"; $output .= "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n\n";
$output .= "<rssfeeds version=\"0.1\">\n\n"; $output .= "<rssfeeds version=\"0.1\">\n\n";

View File

@ -22,9 +22,9 @@ function locale_help() {
</pre>"; </pre>";
$output .= "<p>After having edited your configuration file, make sure your SQL table \"locales\" has the required database fields setup to host your new translations. You can add the required rows to your \"locales\" table from the MySQL prompt:</p>"; $output .= "<p>After having edited your configuration file, make sure your SQL table \"locales\" has the required database fields setup to host your new translations. You can add the required rows to your \"locales\" table from the MySQL prompt:</p>";
$output .= "<pre> $output .= "<pre>
mysql> ALTER TABLE locales ADD en TEXT DEFAULT '' NOT NULL; mysql> ALTER TABLE {locales} ADD en TEXT DEFAULT '' NOT NULL;
mysql> ALTER TABLE locales ADD nl TEXT DEFAULT '' NOT NULL; mysql> ALTER TABLE {locales} ADD nl TEXT DEFAULT '' NOT NULL;
mysql> ALTER TABLE locales ADD fr TEXT DEFAULT '' NOT NULL; mysql> ALTER TABLE {locales} ADD fr TEXT DEFAULT '' NOT NULL;
</pre>"; </pre>";
return t($output); return t($output);
} }
@ -62,7 +62,7 @@ function locale_link($type) {
} }
function locale_delete($lid) { function locale_delete($lid) {
db_query("DELETE FROM locales WHERE lid = %d", $lid); db_query("DELETE FROM {locales} WHERE lid = %d", $lid);
locale_refresh_cache(); locale_refresh_cache();
return t("deleted string"); return t("deleted string");
@ -71,7 +71,7 @@ function locale_delete($lid) {
function locale_save($lid) { function locale_save($lid) {
$edit =& $_POST["edit"]; $edit =& $_POST["edit"];
foreach ($edit as $key=>$value) { foreach ($edit as $key=>$value) {
db_query("UPDATE locales SET $key = '%s' WHERE lid = %d", $value, $lid); db_query("UPDATE {locales} SET $key = '%s' WHERE lid = %d", $value, $lid);
} }
locale_refresh_cache(); locale_refresh_cache();
// delete form data so it will remember where it came from // delete form data so it will remember where it came from
@ -84,7 +84,7 @@ function locale_refresh_cache() {
global $languages; global $languages;
foreach (array_keys($languages) as $locale) { foreach (array_keys($languages) as $locale) {
$result = db_query("SELECT string, %s FROM locales", $locale); $result = db_query("SELECT string, %s FROM {locales} ", $locale);
while ($data = db_fetch_object($result)) { while ($data = db_fetch_object($result)) {
if (empty($data->$locale)) { if (empty($data->$locale)) {
$t[$data->string] = $data->string; $t[$data->string] = $data->string;
@ -100,7 +100,7 @@ function locale_refresh_cache() {
function locale_edit($lid) { function locale_edit($lid) {
global $languages; global $languages;
$result = db_query("SELECT * FROM locales WHERE lid = '$lid'"); $result = db_query("SELECT * FROM {locales} WHERE lid = '$lid'");
if ($translation = db_fetch_object($result)) { if ($translation = db_fetch_object($result)) {
$form .= form_item(t("Original text"), wordwrap(drupal_specialchars($translation->string, 0))); $form .= form_item(t("Original text"), wordwrap(drupal_specialchars($translation->string, 0)));
@ -173,7 +173,7 @@ function locale_seek() {
$query[] = "(". implode(" || ", $string_query) .")"; $query[] = "(". implode(" || ", $string_query) .")";
} }
$result = pager_query("SELECT * FROM locales". (count($query) ? " WHERE ". implode(" && ", $query) : "") ." ORDER BY string", 50); $result = pager_query("SELECT * FROM {locales} ". (count($query) ? " WHERE ". implode(" && ", $query) : "") ." ORDER BY string", 50);
$header = array(t("string"), (($edit["status"] != 2 && strlen($edit["language"]) == 2) ? t("translated string") : t("languages")), array("data" => t("operations"), "colspan" => "2")); $header = array(t("string"), (($edit["status"] != 2 && strlen($edit["language"]) == 2) ? t("translated string") : t("languages")), array("data" => t("operations"), "colspan" => "2"));
while ($locale = db_fetch_object($result)) { while ($locale = db_fetch_object($result)) {
@ -182,8 +182,8 @@ function locale_seek() {
if ($pager = pager_display(NULL, 50, 0, "admin")) { if ($pager = pager_display(NULL, 50, 0, "admin")) {
$rows[] = array(array("data" => "$pager", "colspan" => "5")); $rows[] = array(array("data" => "$pager", "colspan" => "5"));
} }
$output .= table($header, $rows); $output .= table($header, $rows);
} }
@ -294,9 +294,9 @@ function locale($string) {
$string = $locale_t[$string]; $string = $locale_t[$string];
} }
else { else {
$result = db_query("SELECT lid, $locale FROM locales WHERE string = '%s'", $string); $result = db_query("SELECT lid, $locale FROM {locales} WHERE string = '%s'", $string);
if (!db_fetch_object($result)) { if (!db_fetch_object($result)) {
db_query("INSERT INTO locales (string, location) VALUES ('%s', '%s')", $string, request_uri()); db_query("INSERT INTO {locales} (string, location) VALUES ('%s', '%s')", $string, request_uri());
cache_clear_all("locale:$locale"); cache_clear_all("locale:$locale");
} }
} }

View File

@ -22,9 +22,9 @@ function locale_help() {
</pre>"; </pre>";
$output .= "<p>After having edited your configuration file, make sure your SQL table \"locales\" has the required database fields setup to host your new translations. You can add the required rows to your \"locales\" table from the MySQL prompt:</p>"; $output .= "<p>After having edited your configuration file, make sure your SQL table \"locales\" has the required database fields setup to host your new translations. You can add the required rows to your \"locales\" table from the MySQL prompt:</p>";
$output .= "<pre> $output .= "<pre>
mysql> ALTER TABLE locales ADD en TEXT DEFAULT '' NOT NULL; mysql> ALTER TABLE {locales} ADD en TEXT DEFAULT '' NOT NULL;
mysql> ALTER TABLE locales ADD nl TEXT DEFAULT '' NOT NULL; mysql> ALTER TABLE {locales} ADD nl TEXT DEFAULT '' NOT NULL;
mysql> ALTER TABLE locales ADD fr TEXT DEFAULT '' NOT NULL; mysql> ALTER TABLE {locales} ADD fr TEXT DEFAULT '' NOT NULL;
</pre>"; </pre>";
return t($output); return t($output);
} }
@ -62,7 +62,7 @@ function locale_link($type) {
} }
function locale_delete($lid) { function locale_delete($lid) {
db_query("DELETE FROM locales WHERE lid = %d", $lid); db_query("DELETE FROM {locales} WHERE lid = %d", $lid);
locale_refresh_cache(); locale_refresh_cache();
return t("deleted string"); return t("deleted string");
@ -71,7 +71,7 @@ function locale_delete($lid) {
function locale_save($lid) { function locale_save($lid) {
$edit =& $_POST["edit"]; $edit =& $_POST["edit"];
foreach ($edit as $key=>$value) { foreach ($edit as $key=>$value) {
db_query("UPDATE locales SET $key = '%s' WHERE lid = %d", $value, $lid); db_query("UPDATE {locales} SET $key = '%s' WHERE lid = %d", $value, $lid);
} }
locale_refresh_cache(); locale_refresh_cache();
// delete form data so it will remember where it came from // delete form data so it will remember where it came from
@ -84,7 +84,7 @@ function locale_refresh_cache() {
global $languages; global $languages;
foreach (array_keys($languages) as $locale) { foreach (array_keys($languages) as $locale) {
$result = db_query("SELECT string, %s FROM locales", $locale); $result = db_query("SELECT string, %s FROM {locales} ", $locale);
while ($data = db_fetch_object($result)) { while ($data = db_fetch_object($result)) {
if (empty($data->$locale)) { if (empty($data->$locale)) {
$t[$data->string] = $data->string; $t[$data->string] = $data->string;
@ -100,7 +100,7 @@ function locale_refresh_cache() {
function locale_edit($lid) { function locale_edit($lid) {
global $languages; global $languages;
$result = db_query("SELECT * FROM locales WHERE lid = '$lid'"); $result = db_query("SELECT * FROM {locales} WHERE lid = '$lid'");
if ($translation = db_fetch_object($result)) { if ($translation = db_fetch_object($result)) {
$form .= form_item(t("Original text"), wordwrap(drupal_specialchars($translation->string, 0))); $form .= form_item(t("Original text"), wordwrap(drupal_specialchars($translation->string, 0)));
@ -173,7 +173,7 @@ function locale_seek() {
$query[] = "(". implode(" || ", $string_query) .")"; $query[] = "(". implode(" || ", $string_query) .")";
} }
$result = pager_query("SELECT * FROM locales". (count($query) ? " WHERE ". implode(" && ", $query) : "") ." ORDER BY string", 50); $result = pager_query("SELECT * FROM {locales} ". (count($query) ? " WHERE ". implode(" && ", $query) : "") ." ORDER BY string", 50);
$header = array(t("string"), (($edit["status"] != 2 && strlen($edit["language"]) == 2) ? t("translated string") : t("languages")), array("data" => t("operations"), "colspan" => "2")); $header = array(t("string"), (($edit["status"] != 2 && strlen($edit["language"]) == 2) ? t("translated string") : t("languages")), array("data" => t("operations"), "colspan" => "2"));
while ($locale = db_fetch_object($result)) { while ($locale = db_fetch_object($result)) {
@ -182,8 +182,8 @@ function locale_seek() {
if ($pager = pager_display(NULL, 50, 0, "admin")) { if ($pager = pager_display(NULL, 50, 0, "admin")) {
$rows[] = array(array("data" => "$pager", "colspan" => "5")); $rows[] = array(array("data" => "$pager", "colspan" => "5"));
} }
$output .= table($header, $rows); $output .= table($header, $rows);
} }
@ -294,9 +294,9 @@ function locale($string) {
$string = $locale_t[$string]; $string = $locale_t[$string];
} }
else { else {
$result = db_query("SELECT lid, $locale FROM locales WHERE string = '%s'", $string); $result = db_query("SELECT lid, $locale FROM {locales} WHERE string = '%s'", $string);
if (!db_fetch_object($result)) { if (!db_fetch_object($result)) {
db_query("INSERT INTO locales (string, location) VALUES ('%s', '%s')", $string, request_uri()); db_query("INSERT INTO {locales} (string, location) VALUES ('%s', '%s')", $string, request_uri());
cache_clear_all("locale:$locale"); cache_clear_all("locale:$locale");
} }
} }

View File

@ -64,12 +64,12 @@ function node_tag_new($nid) {
global $user; global $user;
if ($user->uid) { if ($user->uid) {
$result = db_query("SELECT timestamp FROM history WHERE uid = %d AND nid = %d", $user->uid, $nid); $result = db_query("SELECT timestamp FROM {history} WHERE uid = %d AND nid = %d", $user->uid, $nid);
if (db_fetch_object($result)) { if (db_fetch_object($result)) {
db_query("UPDATE history SET timestamp = %d WHERE uid = %d AND nid = %d", time(), $user->uid, $nid); db_query("UPDATE {history} SET timestamp = %d WHERE uid = %d AND nid = %d", time(), $user->uid, $nid);
} }
else { else {
db_query("INSERT INTO history (uid, nid, timestamp) VALUES (%d, %d, %d)", $user->uid, $nid, time()); db_query("INSERT INTO {history} (uid, nid, timestamp) VALUES (%d, %d, %d)", $user->uid, $nid, time());
} }
} }
} }
@ -81,7 +81,7 @@ function node_tag_new($nid) {
function node_last_viewed($nid) { function node_last_viewed($nid) {
global $user; global $user;
$history = db_fetch_object(db_query("SELECT timestamp FROM history WHERE uid = '$user->uid' AND nid = %d", $nid)); $history = db_fetch_object(db_query("SELECT timestamp FROM {history} WHERE uid = '$user->uid' AND nid = %d", $nid));
return ($history->timestamp ? $history->timestamp : 0); return ($history->timestamp ? $history->timestamp : 0);
} }
@ -97,7 +97,7 @@ function node_is_new($nid, $timestamp) {
if (!isset($cache[$nid])) { if (!isset($cache[$nid])) {
if ($user->uid) { if ($user->uid) {
$history = db_fetch_object(db_query("SELECT timestamp FROM history WHERE uid = %d AND nid = %d", $user->uid, $nid)); $history = db_fetch_object(db_query("SELECT timestamp FROM {history} WHERE uid = %d AND nid = %d", $user->uid, $nid));
$cache[$nid] = $history->timestamp ? $history->timestamp : 0; $cache[$nid] = $history->timestamp ? $history->timestamp : 0;
} }
else { else {
@ -235,7 +235,7 @@ function node_load($conditions, $revision = -1) {
** Retrieve the node: ** Retrieve the node:
*/ */
$node = db_fetch_object(db_query("SELECT n.*, u.uid, u.name FROM node n LEFT JOIN users u ON u.uid = n.uid WHERE ". implode(" AND ", $cond))); $node = db_fetch_object(db_query("SELECT n.*, u.uid, u.name FROM {node} n LEFT JOIN {users} u ON u.uid = n.uid WHERE ". implode(" AND ", $cond)));
/* /*
** Unserialize the revisions field: ** Unserialize the revisions field:
@ -307,7 +307,7 @@ function node_save($node) {
} }
// Insert the node into the database: // Insert the node into the database:
db_query("INSERT INTO node (". implode(", ", $k) .") VALUES (". implode(", ", $v) .")"); db_query("INSERT INTO {node} (". implode(", ", $k) .") VALUES (". implode(", ", $v) .")");
// Call the node specific callback (if any): // Call the node specific callback (if any):
node_invoke($node, "insert"); node_invoke($node, "insert");
@ -330,7 +330,7 @@ function node_save($node) {
} }
// Update the node in the database: // Update the node in the database:
db_query("UPDATE node SET ". implode(", ", $q) ." WHERE nid = '$node->nid'"); db_query("UPDATE {node} SET ". implode(", ", $q) ." WHERE nid = '$node->nid'");
// Call the node specific callback (if any): // Call the node specific callback (if any):
node_invoke($node, "update"); node_invoke($node, "update");
@ -460,7 +460,7 @@ function node_search($keys) {
// The select must always provide the following fields - lno, title, // The select must always provide the following fields - lno, title,
// created, uid, name, count // created, uid, name, count
// //
$find = do_search(array("keys" => $keys, "type" => "node", "select" => "select s.lno as lno, n.title as title, n.created as created, u.uid as uid, u.name as name, s.count as count FROM search_index s, node n LEFT JOIN users u ON n.uid = u.uid WHERE s.lno = n.nid AND s.type = 'node' AND s.word like '%' AND n.status = 1")); $find = do_search(array("keys" => $keys, "type" => "node", "select" => "select s.lno as lno, n.title as title, n.created as created, u.uid as uid, u.name as name, s.count as count FROM {search_index} s, {node} n LEFT JOIN {users} u ON n.uid = u.uid WHERE s.lno = n.nid AND s.type = 'node' AND s.word like '%' AND n.status = 1"));
return $find; return $find;
} }
@ -493,7 +493,7 @@ function node_filter_link($text) {
function node_comment_mode($nid) { function node_comment_mode($nid) {
static $comment_mode; static $comment_mode;
if (!isset($comment_mode[$nid])) { if (!isset($comment_mode[$nid])) {
$comment_mode[$nid] = db_result(db_query("SELECT comment FROM node WHERE nid = %d", $nid)); $comment_mode[$nid] = db_result(db_query("SELECT comment FROM {node} WHERE nid = %d", $nid));
} }
return $comment_mode[$nid]; return $comment_mode[$nid];
} }
@ -598,7 +598,7 @@ function node_admin_nodes() {
$query = arg(3); $query = arg(3);
$queries = array("ORDER BY n.changed DESC", "WHERE n.status = 0 OR n.moderate = 1 ORDER BY n.changed DESC"); $queries = array("ORDER BY n.changed DESC", "WHERE n.status = 0 OR n.moderate = 1 ORDER BY n.changed DESC");
$result = pager_query("SELECT n.*, u.name, u.uid FROM node n LEFT JOIN users u ON n.uid = u.uid ". $queries[$query ? $query : 0], 50); $result = pager_query("SELECT n.*, u.name, u.uid FROM {node} n LEFT JOIN {users} u ON n.uid = u.uid ". $queries[$query ? $query : 0], 50);
$header = array(t("title"), t("type"), t("author"), t("status"), array("data" => t("operations"), "colspan" => 2)); $header = array(t("title"), t("type"), t("author"), t("status"), array("data" => t("operations"), "colspan" => 2));
@ -863,7 +863,7 @@ function node_feed($nodes = 0, $channel = array()) {
*/ */
if (!$nodes) { if (!$nodes) {
$nodes = db_query_range("SELECT nid FROM node WHERE promote = '1' AND status = '1' ORDER BY created DESC", 0, 15); $nodes = db_query_range("SELECT nid FROM {node} WHERE promote = '1' AND status = '1' ORDER BY created DESC", 0, 15);
} }
while ($node = db_fetch_object($nodes)) { while ($node = db_fetch_object($nodes)) {
@ -1351,7 +1351,7 @@ function node_delete($edit) {
** Delete the specified node: ** Delete the specified node:
*/ */
db_query("DELETE FROM node WHERE nid = '$node->nid'"); db_query("DELETE FROM {node} WHERE nid = '$node->nid'");
/* /*
** Call the node specific callback (if any): ** Call the node specific callback (if any):
@ -1427,7 +1427,7 @@ function node_page() {
theme("box", t("Delete $name"), node_delete($edit)); theme("box", t("Delete $name"), node_delete($edit));
break; break;
default: default:
$result = pager_query("SELECT nid, type FROM node WHERE promote = '1' AND status = '1' ORDER BY static DESC, created DESC", variable_get("default_nodes_main", 10)); $result = pager_query("SELECT nid, type FROM {node} WHERE promote = '1' AND status = '1' ORDER BY static DESC, created DESC", variable_get("default_nodes_main", 10));
while ($node = db_fetch_object($result)) { while ($node = db_fetch_object($result)) {
node_view(node_load(array("nid" => $node->nid, "type" => $node->type)), 1); node_view(node_load(array("nid" => $node->nid, "type" => $node->type)), 1);
@ -1461,7 +1461,7 @@ function node_update_index() {
// last run date for the nodes update. // last run date for the nodes update.
return array("last_update" => "node_cron_last", return array("last_update" => "node_cron_last",
"node_type" => "node", "node_type" => "node",
"select" => "SELECT n.nid as lno, n.title as text1, n.body as text2 FROM node n WHERE n.status = 1 AND moderate = 0 and (created > " . variable_get("node_cron_last", 1) . " or changed > " . variable_get("node_cron_last", 1) . ")"); "select" => "SELECT n.nid as lno, n.title as text1, n.body as text2 FROM {node} n WHERE n.status = 1 AND moderate = 0 and (created > " . variable_get("node_cron_last", 1) . " or changed > " . variable_get("node_cron_last", 1) . ")");
} }
function node_nodeapi(&$node, $op, $arg = 0) { function node_nodeapi(&$node, $op, $arg = 0) {

View File

@ -64,12 +64,12 @@ function node_tag_new($nid) {
global $user; global $user;
if ($user->uid) { if ($user->uid) {
$result = db_query("SELECT timestamp FROM history WHERE uid = %d AND nid = %d", $user->uid, $nid); $result = db_query("SELECT timestamp FROM {history} WHERE uid = %d AND nid = %d", $user->uid, $nid);
if (db_fetch_object($result)) { if (db_fetch_object($result)) {
db_query("UPDATE history SET timestamp = %d WHERE uid = %d AND nid = %d", time(), $user->uid, $nid); db_query("UPDATE {history} SET timestamp = %d WHERE uid = %d AND nid = %d", time(), $user->uid, $nid);
} }
else { else {
db_query("INSERT INTO history (uid, nid, timestamp) VALUES (%d, %d, %d)", $user->uid, $nid, time()); db_query("INSERT INTO {history} (uid, nid, timestamp) VALUES (%d, %d, %d)", $user->uid, $nid, time());
} }
} }
} }
@ -81,7 +81,7 @@ function node_tag_new($nid) {
function node_last_viewed($nid) { function node_last_viewed($nid) {
global $user; global $user;
$history = db_fetch_object(db_query("SELECT timestamp FROM history WHERE uid = '$user->uid' AND nid = %d", $nid)); $history = db_fetch_object(db_query("SELECT timestamp FROM {history} WHERE uid = '$user->uid' AND nid = %d", $nid));
return ($history->timestamp ? $history->timestamp : 0); return ($history->timestamp ? $history->timestamp : 0);
} }
@ -97,7 +97,7 @@ function node_is_new($nid, $timestamp) {
if (!isset($cache[$nid])) { if (!isset($cache[$nid])) {
if ($user->uid) { if ($user->uid) {
$history = db_fetch_object(db_query("SELECT timestamp FROM history WHERE uid = %d AND nid = %d", $user->uid, $nid)); $history = db_fetch_object(db_query("SELECT timestamp FROM {history} WHERE uid = %d AND nid = %d", $user->uid, $nid));
$cache[$nid] = $history->timestamp ? $history->timestamp : 0; $cache[$nid] = $history->timestamp ? $history->timestamp : 0;
} }
else { else {
@ -235,7 +235,7 @@ function node_load($conditions, $revision = -1) {
** Retrieve the node: ** Retrieve the node:
*/ */
$node = db_fetch_object(db_query("SELECT n.*, u.uid, u.name FROM node n LEFT JOIN users u ON u.uid = n.uid WHERE ". implode(" AND ", $cond))); $node = db_fetch_object(db_query("SELECT n.*, u.uid, u.name FROM {node} n LEFT JOIN {users} u ON u.uid = n.uid WHERE ". implode(" AND ", $cond)));
/* /*
** Unserialize the revisions field: ** Unserialize the revisions field:
@ -307,7 +307,7 @@ function node_save($node) {
} }
// Insert the node into the database: // Insert the node into the database:
db_query("INSERT INTO node (". implode(", ", $k) .") VALUES (". implode(", ", $v) .")"); db_query("INSERT INTO {node} (". implode(", ", $k) .") VALUES (". implode(", ", $v) .")");
// Call the node specific callback (if any): // Call the node specific callback (if any):
node_invoke($node, "insert"); node_invoke($node, "insert");
@ -330,7 +330,7 @@ function node_save($node) {
} }
// Update the node in the database: // Update the node in the database:
db_query("UPDATE node SET ". implode(", ", $q) ." WHERE nid = '$node->nid'"); db_query("UPDATE {node} SET ". implode(", ", $q) ." WHERE nid = '$node->nid'");
// Call the node specific callback (if any): // Call the node specific callback (if any):
node_invoke($node, "update"); node_invoke($node, "update");
@ -460,7 +460,7 @@ function node_search($keys) {
// The select must always provide the following fields - lno, title, // The select must always provide the following fields - lno, title,
// created, uid, name, count // created, uid, name, count
// //
$find = do_search(array("keys" => $keys, "type" => "node", "select" => "select s.lno as lno, n.title as title, n.created as created, u.uid as uid, u.name as name, s.count as count FROM search_index s, node n LEFT JOIN users u ON n.uid = u.uid WHERE s.lno = n.nid AND s.type = 'node' AND s.word like '%' AND n.status = 1")); $find = do_search(array("keys" => $keys, "type" => "node", "select" => "select s.lno as lno, n.title as title, n.created as created, u.uid as uid, u.name as name, s.count as count FROM {search_index} s, {node} n LEFT JOIN {users} u ON n.uid = u.uid WHERE s.lno = n.nid AND s.type = 'node' AND s.word like '%' AND n.status = 1"));
return $find; return $find;
} }
@ -493,7 +493,7 @@ function node_filter_link($text) {
function node_comment_mode($nid) { function node_comment_mode($nid) {
static $comment_mode; static $comment_mode;
if (!isset($comment_mode[$nid])) { if (!isset($comment_mode[$nid])) {
$comment_mode[$nid] = db_result(db_query("SELECT comment FROM node WHERE nid = %d", $nid)); $comment_mode[$nid] = db_result(db_query("SELECT comment FROM {node} WHERE nid = %d", $nid));
} }
return $comment_mode[$nid]; return $comment_mode[$nid];
} }
@ -598,7 +598,7 @@ function node_admin_nodes() {
$query = arg(3); $query = arg(3);
$queries = array("ORDER BY n.changed DESC", "WHERE n.status = 0 OR n.moderate = 1 ORDER BY n.changed DESC"); $queries = array("ORDER BY n.changed DESC", "WHERE n.status = 0 OR n.moderate = 1 ORDER BY n.changed DESC");
$result = pager_query("SELECT n.*, u.name, u.uid FROM node n LEFT JOIN users u ON n.uid = u.uid ". $queries[$query ? $query : 0], 50); $result = pager_query("SELECT n.*, u.name, u.uid FROM {node} n LEFT JOIN {users} u ON n.uid = u.uid ". $queries[$query ? $query : 0], 50);
$header = array(t("title"), t("type"), t("author"), t("status"), array("data" => t("operations"), "colspan" => 2)); $header = array(t("title"), t("type"), t("author"), t("status"), array("data" => t("operations"), "colspan" => 2));
@ -863,7 +863,7 @@ function node_feed($nodes = 0, $channel = array()) {
*/ */
if (!$nodes) { if (!$nodes) {
$nodes = db_query_range("SELECT nid FROM node WHERE promote = '1' AND status = '1' ORDER BY created DESC", 0, 15); $nodes = db_query_range("SELECT nid FROM {node} WHERE promote = '1' AND status = '1' ORDER BY created DESC", 0, 15);
} }
while ($node = db_fetch_object($nodes)) { while ($node = db_fetch_object($nodes)) {
@ -1351,7 +1351,7 @@ function node_delete($edit) {
** Delete the specified node: ** Delete the specified node:
*/ */
db_query("DELETE FROM node WHERE nid = '$node->nid'"); db_query("DELETE FROM {node} WHERE nid = '$node->nid'");
/* /*
** Call the node specific callback (if any): ** Call the node specific callback (if any):
@ -1427,7 +1427,7 @@ function node_page() {
theme("box", t("Delete $name"), node_delete($edit)); theme("box", t("Delete $name"), node_delete($edit));
break; break;
default: default:
$result = pager_query("SELECT nid, type FROM node WHERE promote = '1' AND status = '1' ORDER BY static DESC, created DESC", variable_get("default_nodes_main", 10)); $result = pager_query("SELECT nid, type FROM {node} WHERE promote = '1' AND status = '1' ORDER BY static DESC, created DESC", variable_get("default_nodes_main", 10));
while ($node = db_fetch_object($result)) { while ($node = db_fetch_object($result)) {
node_view(node_load(array("nid" => $node->nid, "type" => $node->type)), 1); node_view(node_load(array("nid" => $node->nid, "type" => $node->type)), 1);
@ -1461,7 +1461,7 @@ function node_update_index() {
// last run date for the nodes update. // last run date for the nodes update.
return array("last_update" => "node_cron_last", return array("last_update" => "node_cron_last",
"node_type" => "node", "node_type" => "node",
"select" => "SELECT n.nid as lno, n.title as text1, n.body as text2 FROM node n WHERE n.status = 1 AND moderate = 0 and (created > " . variable_get("node_cron_last", 1) . " or changed > " . variable_get("node_cron_last", 1) . ")"); "select" => "SELECT n.nid as lno, n.title as text1, n.body as text2 FROM {node} n WHERE n.status = 1 AND moderate = 0 and (created > " . variable_get("node_cron_last", 1) . " or changed > " . variable_get("node_cron_last", 1) . ")");
} }
function node_nodeapi(&$node, $op, $arg = 0) { function node_nodeapi(&$node, $op, $arg = 0) {

View File

@ -53,19 +53,19 @@ function page_save($op, $node) {
} }
function page_insert($node) { function page_insert($node) {
db_query("INSERT INTO page (nid, format, link, description) VALUES (%d, %d, '%s', '%s')", $node->nid, $node->format, $node->link, $node->description); db_query("INSERT INTO {page} (nid, format, link, description) VALUES (%d, %d, '%s', '%s')", $node->nid, $node->format, $node->link, $node->description);
} }
function page_update($node) { function page_update($node) {
db_query("UPDATE page SET format = %d, link = '%s', description = '%s' WHERE nid = %d", $node->format, $node->link, $node->description, $node->nid); db_query("UPDATE {page} SET format = %d, link = '%s', description = '%s' WHERE nid = %d", $node->format, $node->link, $node->description, $node->nid);
} }
function page_delete(&$node) { function page_delete(&$node) {
db_query("DELETE FROM page WHERE nid = %d", $node->nid); db_query("DELETE FROM {page} WHERE nid = %d", $node->nid);
} }
function page_load($node) { function page_load($node) {
$page = db_fetch_object(db_query("SELECT format, link, description FROM page WHERE nid = %d", $node->nid)); $page = db_fetch_object(db_query("SELECT format, link, description FROM {page} WHERE nid = %d", $node->nid));
return $page; return $page;
} }
@ -75,7 +75,7 @@ function page_link($type) {
$links = array(); $links = array();
if ($type == "page" && user_access("access content")) { if ($type == "page" && user_access("access content")) {
$result = db_query("SELECT n.nid, n.title, p.link, p.description FROM page p LEFT JOIN node n ON p.nid = n.nid WHERE n.status = '1' AND p.link != '' ORDER BY p.link"); $result = db_query("SELECT n.nid, n.title, p.link, p.description FROM {page} p LEFT JOIN {node} n ON p.nid = n.nid WHERE n.status = '1' AND p.link != '' ORDER BY p.link");
while ($page = db_fetch_object($result)) { while ($page = db_fetch_object($result)) {
$links[] = l($page->link, "node/view/$page->nid", array("title" => $page->description)); $links[] = l($page->link, "node/view/$page->nid", array("title" => $page->description));
} }

View File

@ -53,19 +53,19 @@ function page_save($op, $node) {
} }
function page_insert($node) { function page_insert($node) {
db_query("INSERT INTO page (nid, format, link, description) VALUES (%d, %d, '%s', '%s')", $node->nid, $node->format, $node->link, $node->description); db_query("INSERT INTO {page} (nid, format, link, description) VALUES (%d, %d, '%s', '%s')", $node->nid, $node->format, $node->link, $node->description);
} }
function page_update($node) { function page_update($node) {
db_query("UPDATE page SET format = %d, link = '%s', description = '%s' WHERE nid = %d", $node->format, $node->link, $node->description, $node->nid); db_query("UPDATE {page} SET format = %d, link = '%s', description = '%s' WHERE nid = %d", $node->format, $node->link, $node->description, $node->nid);
} }
function page_delete(&$node) { function page_delete(&$node) {
db_query("DELETE FROM page WHERE nid = %d", $node->nid); db_query("DELETE FROM {page} WHERE nid = %d", $node->nid);
} }
function page_load($node) { function page_load($node) {
$page = db_fetch_object(db_query("SELECT format, link, description FROM page WHERE nid = %d", $node->nid)); $page = db_fetch_object(db_query("SELECT format, link, description FROM {page} WHERE nid = %d", $node->nid));
return $page; return $page;
} }
@ -75,7 +75,7 @@ function page_link($type) {
$links = array(); $links = array();
if ($type == "page" && user_access("access content")) { if ($type == "page" && user_access("access content")) {
$result = db_query("SELECT n.nid, n.title, p.link, p.description FROM page p LEFT JOIN node n ON p.nid = n.nid WHERE n.status = '1' AND p.link != '' ORDER BY p.link"); $result = db_query("SELECT n.nid, n.title, p.link, p.description FROM {page} p LEFT JOIN {node} n ON p.nid = n.nid WHERE n.status = '1' AND p.link != '' ORDER BY p.link");
while ($page = db_fetch_object($result)) { while ($page = db_fetch_object($result)) {
$links[] = l($page->link, "node/view/$page->nid", array("title" => $page->description)); $links[] = l($page->link, "node/view/$page->nid", array("title" => $page->description));
} }

View File

@ -21,7 +21,7 @@ function ping_cron() {
global $base_url; global $base_url;
if (variable_get("site_name", 0) && variable_get("site_slogan", 0)) { if (variable_get("site_name", 0) && variable_get("site_slogan", 0)) {
if (db_num_rows(db_query("SELECT nid FROM node WHERE status = 1 AND moderate = 0 AND (created > '". variable_get("ping_cron_last", time()) ."' OR changed > '". variable_get("ping_cron_last", time()) ."')"), 1)) { if (db_num_rows(db_query("SELECT nid FROM {node} WHERE status = 1 AND moderate = 0 AND (created > '". variable_get("ping_cron_last", time()) ."' OR changed > '". variable_get("ping_cron_last", time()) ."')"), 1)) {
_ping_notify(variable_get("site_name", "") ." - ". variable_get("site_slogan", ""), $base_url); _ping_notify(variable_get("site_name", "") ." - ". variable_get("site_slogan", ""), $base_url);
} }

View File

@ -21,7 +21,7 @@ function ping_cron() {
global $base_url; global $base_url;
if (variable_get("site_name", 0) && variable_get("site_slogan", 0)) { if (variable_get("site_name", 0) && variable_get("site_slogan", 0)) {
if (db_num_rows(db_query("SELECT nid FROM node WHERE status = 1 AND moderate = 0 AND (created > '". variable_get("ping_cron_last", time()) ."' OR changed > '". variable_get("ping_cron_last", time()) ."')"), 1)) { if (db_num_rows(db_query("SELECT nid FROM {node} WHERE status = 1 AND moderate = 0 AND (created > '". variable_get("ping_cron_last", time()) ."' OR changed > '". variable_get("ping_cron_last", time()) ."')"), 1)) {
_ping_notify(variable_get("site_name", "") ." - ". variable_get("site_slogan", ""), $base_url); _ping_notify(variable_get("site_name", "") ." - ". variable_get("site_slogan", ""), $base_url);
} }

View File

@ -49,7 +49,7 @@ function poll_block($op = "list", $delta = 0) {
return $blocks; return $blocks;
} }
else { else {
$timestamp = db_result(db_query("SELECT MAX(created) FROM node WHERE type = 'poll' AND status = '1' AND moderate = '0'")); $timestamp = db_result(db_query("SELECT MAX(created) FROM {node} WHERE type = 'poll' AND status = '1' AND moderate = '0'"));
if ($timestamp) { if ($timestamp) {
$poll = node_load(array("type" => "poll", "created" => $timestamp, "moderate" => "0", "status" => "1")); $poll = node_load(array("type" => "poll", "created" => $timestamp, "moderate" => "0", "status" => "1"));
if ($poll->nid) { if ($poll->nid) {
@ -66,15 +66,15 @@ function poll_block($op = "list", $delta = 0) {
function poll_cron() { function poll_cron() {
// Close polls that have exceeded their allowed runtime // Close polls that have exceeded their allowed runtime
$result = db_query("SELECT p.nid FROM poll p LEFT JOIN node n ON p.nid=n.nid WHERE (n.created + p.runtime) < '". time() ."' AND p.active = '1' AND p.runtime != '0'"); $result = db_query("SELECT p.nid FROM {poll} p LEFT JOIN {node} n ON p.nid=n.nid WHERE (n.created + p.runtime) < '". time() ."' AND p.active = '1' AND p.runtime != '0'");
while ($poll = db_fetch_object($result)) { while ($poll = db_fetch_object($result)) {
db_query("UPDATE poll SET active='0' WHERE nid = %d", $poll->nid); db_query("UPDATE {poll} SET active='0' WHERE nid = %d", $poll->nid);
} }
} }
function poll_delete($node) { function poll_delete($node) {
db_query("DELETE FROM poll WHERE nid=%d", $node->nid); db_query("DELETE FROM {poll} WHERE nid=%d", $node->nid);
db_query("DELETE FROM poll_choices WHERE nid = %d", $node->nid); db_query("DELETE FROM {poll_choices} WHERE nid = %d", $node->nid);
} }
function poll_form(&$node, &$help, &$error) { function poll_form(&$node, &$help, &$error) {
@ -143,11 +143,11 @@ function poll_insert($node) {
$node->active = 1; $node->active = 1;
} }
db_query("INSERT INTO poll (nid, runtime, voters, active) VALUES (%d, %d, '', %d)", $node->nid, $node->runtime, $node->active); db_query("INSERT INTO {poll} (nid, runtime, voters, active) VALUES (%d, %d, '', %d)", $node->nid, $node->runtime, $node->active);
for ($i = 0; $i < $node->choices; $i++) { for ($i = 0; $i < $node->choices; $i++) {
if ($node->choice[$i] != "") { if ($node->choice[$i] != "") {
db_query("INSERT INTO poll_choices (nid, chtext, chvotes, chorder) VALUES (%d, '%s', %d, %d)", $node->nid, $node->choice[$i], $node->chvotes[$i], $i); db_query("INSERT INTO {poll_choices} (nid, chtext, chvotes, chorder) VALUES (%d, '%s', %d, %d)", $node->nid, $node->choice[$i], $node->chvotes[$i], $i);
} }
} }
} }
@ -199,9 +199,9 @@ function poll_link($type, $node = 0, $main) {
function poll_load($node) { function poll_load($node) {
// Load the appropriate choices into the $node object // Load the appropriate choices into the $node object
$poll = db_fetch_object(db_query("SELECT runtime, voters, active FROM poll WHERE nid = %d", $node->nid)); $poll = db_fetch_object(db_query("SELECT runtime, voters, active FROM {poll} WHERE nid = %d", $node->nid));
$result = db_query("SELECT chtext, chvotes, chorder FROM poll_choices WHERE nid=%d ORDER BY chorder", $node->nid); $result = db_query("SELECT chtext, chvotes, chorder FROM {poll_choices} WHERE nid=%d ORDER BY chorder", $node->nid);
while ($choice = db_fetch_object($result)) { while ($choice = db_fetch_object($result)) {
$poll->choice[$choice->chorder] = $choice->chtext; $poll->choice[$choice->chorder] = $choice->chtext;
$poll->chvotes[$choice->chorder] = $choice->chvotes; $poll->chvotes[$choice->chorder] = $choice->chvotes;
@ -221,7 +221,7 @@ function poll_node($field) {
function poll_page() { function poll_page() {
theme("header"); theme("header");
$result = db_query("SELECT n.nid, n.title, p.active, SUM(c.chvotes) AS votes FROM node n LEFT JOIN poll p ON n.nid=p.nid LEFT JOIN poll_choices c ON n.nid=c.nid WHERE type = 'poll' AND status = '1' AND moderate = '0' GROUP BY n.nid, n.title, p.active, n.created ORDER BY n.created DESC"); $result = db_query("SELECT n.nid, n.title, p.active, SUM(c.chvotes) AS votes FROM {node} n LEFT JOIN {poll} p ON n.nid=p.nid LEFT JOIN {poll_choices} c ON n.nid=c.nid WHERE type = 'poll' AND status = '1' AND moderate = '0' GROUP BY n.nid, n.title, p.active, n.created ORDER BY n.created DESC");
$output = "<ul>"; $output = "<ul>";
while ($node = db_fetch_object($result)) { while ($node = db_fetch_object($result)) {
$output .= "<li>".l($node->title, "node/view/$node->nid") ." - ". format_plural($node->votes, "1 vote", "%count votes") ." - ". ($node->active ? t("open") : t("closed")) ."</li>"; $output .= "<li>".l($node->title, "node/view/$node->nid") ." - ". format_plural($node->votes, "1 vote", "%count votes") ." - ". ($node->active ? t("open") : t("closed")) ."</li>";
@ -293,7 +293,7 @@ function poll_view_results(&$node, $main, $block, $links) {
if ($node->choice) { if ($node->choice) {
foreach ($node->choice as $key => $value) { foreach ($node->choice as $key => $value) {
if ($value != "") { if ($value != "") {
$width = round($node->chvotes[$key] * 100 / $votesmax); $width = round($node->chvotes[$key] * 100 / $votestotal);
$percentage = round($node->chvotes[$key] * 100 / max($votestotal, 1)); $percentage = round($node->chvotes[$key] * 100 / max($votestotal, 1));
$output .= "<div class=\"text\">". filter($value) ."</div>"; $output .= "<div class=\"text\">". filter($value) ."</div>";
$output .= "<div class=\"bar\">"; $output .= "<div class=\"bar\">";
@ -317,8 +317,8 @@ function poll_view_processvote(&$node) {
if (isset($pollvote[$node->nid]) && ($node->allowvotes == 1)) { if (isset($pollvote[$node->nid]) && ($node->allowvotes == 1)) {
if (!empty($node->choice[$pollvote[$node->nid]])) { if (!empty($node->choice[$pollvote[$node->nid]])) {
$node->voters = $node->voters ? ($node->voters ." ". $node->polluserid) : $node->polluserid; $node->voters = $node->voters ? ($node->voters ." ". $node->polluserid) : $node->polluserid;
db_query("UPDATE poll SET voters='%s' WHERE nid = %d", $node->voters, $node->nid); db_query("UPDATE {poll} SET voters='%s' WHERE nid = %d", $node->voters, $node->nid);
db_query("UPDATE poll_choices SET chvotes = chvotes + 1 WHERE nid = %d AND chorder = %d", $node->nid, $pollvote[$node->nid]); db_query("UPDATE {poll_choices} SET chvotes = chvotes + 1 WHERE nid = %d AND chorder = %d", $node->nid, $pollvote[$node->nid]);
$node->allowvotes = 0; $node->allowvotes = 0;
$node->chvotes[$pollvote[$node->nid]]++; $node->chvotes[$pollvote[$node->nid]]++;
} }
@ -366,16 +366,16 @@ function poll_view(&$node, $main = 0, $block = 0) {
} }
function poll_update($node) { function poll_update($node) {
db_query("UPDATE poll SET runtime = %d, active = %d WHERE nid = %d", $node->runtime, $node->active, $node->nid); db_query("UPDATE {poll} SET runtime = %d, active = %d WHERE nid = %d", $node->runtime, $node->active, $node->nid);
db_query("DELETE FROM poll_choices WHERE nid = %d", $node->nid); db_query("DELETE FROM {poll_choices} WHERE nid = %d", $node->nid);
for ($i = 0; $i < $node->choices; $i++) { for ($i = 0; $i < $node->choices; $i++) {
$choice->chtext = $node->choice[$i]; $choice->chtext = $node->choice[$i];
$choice->chvotes = (int)$node->chvotes[$i]; $choice->chvotes = (int)$node->chvotes[$i];
$choice->chorder = $i; $choice->chorder = $i;
if ($choice->chtext != "") { if ($choice->chtext != "") {
db_query("INSERT INTO poll_choices (nid, chtext, chvotes, chorder) VALUES (%d, '%s', %d, %d)", $node->nid, $choice->chtext, $choice->chvotes, $choice->chorder); db_query("INSERT INTO {poll_choices} (nid, chtext, chvotes, chorder) VALUES (%d, '%s', %d, %d)", $node->nid, $choice->chtext, $choice->chvotes, $choice->chorder);
} }
} }
} }

View File

@ -49,7 +49,7 @@ function poll_block($op = "list", $delta = 0) {
return $blocks; return $blocks;
} }
else { else {
$timestamp = db_result(db_query("SELECT MAX(created) FROM node WHERE type = 'poll' AND status = '1' AND moderate = '0'")); $timestamp = db_result(db_query("SELECT MAX(created) FROM {node} WHERE type = 'poll' AND status = '1' AND moderate = '0'"));
if ($timestamp) { if ($timestamp) {
$poll = node_load(array("type" => "poll", "created" => $timestamp, "moderate" => "0", "status" => "1")); $poll = node_load(array("type" => "poll", "created" => $timestamp, "moderate" => "0", "status" => "1"));
if ($poll->nid) { if ($poll->nid) {
@ -66,15 +66,15 @@ function poll_block($op = "list", $delta = 0) {
function poll_cron() { function poll_cron() {
// Close polls that have exceeded their allowed runtime // Close polls that have exceeded their allowed runtime
$result = db_query("SELECT p.nid FROM poll p LEFT JOIN node n ON p.nid=n.nid WHERE (n.created + p.runtime) < '". time() ."' AND p.active = '1' AND p.runtime != '0'"); $result = db_query("SELECT p.nid FROM {poll} p LEFT JOIN {node} n ON p.nid=n.nid WHERE (n.created + p.runtime) < '". time() ."' AND p.active = '1' AND p.runtime != '0'");
while ($poll = db_fetch_object($result)) { while ($poll = db_fetch_object($result)) {
db_query("UPDATE poll SET active='0' WHERE nid = %d", $poll->nid); db_query("UPDATE {poll} SET active='0' WHERE nid = %d", $poll->nid);
} }
} }
function poll_delete($node) { function poll_delete($node) {
db_query("DELETE FROM poll WHERE nid=%d", $node->nid); db_query("DELETE FROM {poll} WHERE nid=%d", $node->nid);
db_query("DELETE FROM poll_choices WHERE nid = %d", $node->nid); db_query("DELETE FROM {poll_choices} WHERE nid = %d", $node->nid);
} }
function poll_form(&$node, &$help, &$error) { function poll_form(&$node, &$help, &$error) {
@ -143,11 +143,11 @@ function poll_insert($node) {
$node->active = 1; $node->active = 1;
} }
db_query("INSERT INTO poll (nid, runtime, voters, active) VALUES (%d, %d, '', %d)", $node->nid, $node->runtime, $node->active); db_query("INSERT INTO {poll} (nid, runtime, voters, active) VALUES (%d, %d, '', %d)", $node->nid, $node->runtime, $node->active);
for ($i = 0; $i < $node->choices; $i++) { for ($i = 0; $i < $node->choices; $i++) {
if ($node->choice[$i] != "") { if ($node->choice[$i] != "") {
db_query("INSERT INTO poll_choices (nid, chtext, chvotes, chorder) VALUES (%d, '%s', %d, %d)", $node->nid, $node->choice[$i], $node->chvotes[$i], $i); db_query("INSERT INTO {poll_choices} (nid, chtext, chvotes, chorder) VALUES (%d, '%s', %d, %d)", $node->nid, $node->choice[$i], $node->chvotes[$i], $i);
} }
} }
} }
@ -199,9 +199,9 @@ function poll_link($type, $node = 0, $main) {
function poll_load($node) { function poll_load($node) {
// Load the appropriate choices into the $node object // Load the appropriate choices into the $node object
$poll = db_fetch_object(db_query("SELECT runtime, voters, active FROM poll WHERE nid = %d", $node->nid)); $poll = db_fetch_object(db_query("SELECT runtime, voters, active FROM {poll} WHERE nid = %d", $node->nid));
$result = db_query("SELECT chtext, chvotes, chorder FROM poll_choices WHERE nid=%d ORDER BY chorder", $node->nid); $result = db_query("SELECT chtext, chvotes, chorder FROM {poll_choices} WHERE nid=%d ORDER BY chorder", $node->nid);
while ($choice = db_fetch_object($result)) { while ($choice = db_fetch_object($result)) {
$poll->choice[$choice->chorder] = $choice->chtext; $poll->choice[$choice->chorder] = $choice->chtext;
$poll->chvotes[$choice->chorder] = $choice->chvotes; $poll->chvotes[$choice->chorder] = $choice->chvotes;
@ -221,7 +221,7 @@ function poll_node($field) {
function poll_page() { function poll_page() {
theme("header"); theme("header");
$result = db_query("SELECT n.nid, n.title, p.active, SUM(c.chvotes) AS votes FROM node n LEFT JOIN poll p ON n.nid=p.nid LEFT JOIN poll_choices c ON n.nid=c.nid WHERE type = 'poll' AND status = '1' AND moderate = '0' GROUP BY n.nid, n.title, p.active, n.created ORDER BY n.created DESC"); $result = db_query("SELECT n.nid, n.title, p.active, SUM(c.chvotes) AS votes FROM {node} n LEFT JOIN {poll} p ON n.nid=p.nid LEFT JOIN {poll_choices} c ON n.nid=c.nid WHERE type = 'poll' AND status = '1' AND moderate = '0' GROUP BY n.nid, n.title, p.active, n.created ORDER BY n.created DESC");
$output = "<ul>"; $output = "<ul>";
while ($node = db_fetch_object($result)) { while ($node = db_fetch_object($result)) {
$output .= "<li>".l($node->title, "node/view/$node->nid") ." - ". format_plural($node->votes, "1 vote", "%count votes") ." - ". ($node->active ? t("open") : t("closed")) ."</li>"; $output .= "<li>".l($node->title, "node/view/$node->nid") ." - ". format_plural($node->votes, "1 vote", "%count votes") ." - ". ($node->active ? t("open") : t("closed")) ."</li>";
@ -293,7 +293,7 @@ function poll_view_results(&$node, $main, $block, $links) {
if ($node->choice) { if ($node->choice) {
foreach ($node->choice as $key => $value) { foreach ($node->choice as $key => $value) {
if ($value != "") { if ($value != "") {
$width = round($node->chvotes[$key] * 100 / $votesmax); $width = round($node->chvotes[$key] * 100 / $votestotal);
$percentage = round($node->chvotes[$key] * 100 / max($votestotal, 1)); $percentage = round($node->chvotes[$key] * 100 / max($votestotal, 1));
$output .= "<div class=\"text\">". filter($value) ."</div>"; $output .= "<div class=\"text\">". filter($value) ."</div>";
$output .= "<div class=\"bar\">"; $output .= "<div class=\"bar\">";
@ -317,8 +317,8 @@ function poll_view_processvote(&$node) {
if (isset($pollvote[$node->nid]) && ($node->allowvotes == 1)) { if (isset($pollvote[$node->nid]) && ($node->allowvotes == 1)) {
if (!empty($node->choice[$pollvote[$node->nid]])) { if (!empty($node->choice[$pollvote[$node->nid]])) {
$node->voters = $node->voters ? ($node->voters ." ". $node->polluserid) : $node->polluserid; $node->voters = $node->voters ? ($node->voters ." ". $node->polluserid) : $node->polluserid;
db_query("UPDATE poll SET voters='%s' WHERE nid = %d", $node->voters, $node->nid); db_query("UPDATE {poll} SET voters='%s' WHERE nid = %d", $node->voters, $node->nid);
db_query("UPDATE poll_choices SET chvotes = chvotes + 1 WHERE nid = %d AND chorder = %d", $node->nid, $pollvote[$node->nid]); db_query("UPDATE {poll_choices} SET chvotes = chvotes + 1 WHERE nid = %d AND chorder = %d", $node->nid, $pollvote[$node->nid]);
$node->allowvotes = 0; $node->allowvotes = 0;
$node->chvotes[$pollvote[$node->nid]]++; $node->chvotes[$pollvote[$node->nid]]++;
} }
@ -366,16 +366,16 @@ function poll_view(&$node, $main = 0, $block = 0) {
} }
function poll_update($node) { function poll_update($node) {
db_query("UPDATE poll SET runtime = %d, active = %d WHERE nid = %d", $node->runtime, $node->active, $node->nid); db_query("UPDATE {poll} SET runtime = %d, active = %d WHERE nid = %d", $node->runtime, $node->active, $node->nid);
db_query("DELETE FROM poll_choices WHERE nid = %d", $node->nid); db_query("DELETE FROM {poll_choices} WHERE nid = %d", $node->nid);
for ($i = 0; $i < $node->choices; $i++) { for ($i = 0; $i < $node->choices; $i++) {
$choice->chtext = $node->choice[$i]; $choice->chtext = $node->choice[$i];
$choice->chvotes = (int)$node->chvotes[$i]; $choice->chvotes = (int)$node->chvotes[$i];
$choice->chorder = $i; $choice->chorder = $i;
if ($choice->chtext != "") { if ($choice->chtext != "") {
db_query("INSERT INTO poll_choices (nid, chtext, chvotes, chorder) VALUES (%d, '%s', %d, %d)", $node->nid, $choice->chtext, $choice->chvotes, $choice->chorder); db_query("INSERT INTO {poll_choices} (nid, chtext, chvotes, chorder) VALUES (%d, '%s', %d, %d)", $node->nid, $choice->chtext, $choice->chvotes, $choice->chorder);
} }
} }
} }

View File

@ -33,12 +33,12 @@ function queue_link($type) {
} }
function queue_count() { function queue_count() {
$result = db_query("SELECT COUNT(nid) FROM node WHERE moderate = 1"); $result = db_query("SELECT COUNT(nid) FROM {node} WHERE moderate = 1");
return ($result) ? db_result($result, 0) : 0; return ($result) ? db_result($result, 0) : 0;
} }
function queue_score($id) { function queue_score($id) {
$result = db_query("SELECT score FROM node WHERE nid = %d", $id); $result = db_query("SELECT score FROM {node} WHERE nid = %d", $id);
return ($result) ? db_result($result, 0) : 0; return ($result) ? db_result($result, 0) : 0;
} }
@ -47,7 +47,7 @@ function queue_vote($node, $vote) {
if (!field_get($node->users, $user->uid)) { if (!field_get($node->users, $user->uid)) {
// Update submission's score- and votes-field: // Update submission's score- and votes-field:
db_query("UPDATE node SET score = score $vote, votes = votes + 1, users = '". field_set($node->users, $user->uid, $vote) ."' WHERE nid = '$node->nid'"); db_query("UPDATE {node} SET score = score $vote, votes = votes + 1, users = '". field_set($node->users, $user->uid, $vote) ."' WHERE nid = '$node->nid'");
// Reload the updated node from the database: // Reload the updated node from the database:
$node = node_load(array("nid" => $node->nid)); $node = node_load(array("nid" => $node->nid));
@ -88,7 +88,7 @@ function queue_vote($node, $vote) {
function queue_overview() { function queue_overview() {
global $user; global $user;
$result = db_query("SELECT n.*, u.name, u.uid FROM node n LEFT JOIN users u ON n.uid = u.uid WHERE n.moderate = 1"); $result = db_query("SELECT n.*, u.name, u.uid FROM {node} n LEFT JOIN {users} u ON n.uid = u.uid WHERE n.moderate = 1");
$output .= "<table border=\"0\" cellspacing=\"4\" cellpadding=\"4\">"; $output .= "<table border=\"0\" cellspacing=\"4\" cellpadding=\"4\">";
$output .= " <tr><th>". t("Subject") ."</th><th>". t("Author") ."</th><th>". t("Type") ."</th><th>". t("Score") ."</th></tr>"; $output .= " <tr><th>". t("Subject") ."</th><th>". t("Author") ."</th><th>". t("Type") ."</th><th>". t("Score") ."</th></tr>";

View File

@ -226,7 +226,7 @@ function update_index($search_array) {
** Trash any existing entries in the search index for this node, ** Trash any existing entries in the search index for this node,
** in case its a modified node. ** in case its a modified node.
*/ */
db_query("DELETE from search_index where lno = '". $node["lno"] ."' and type = '". $node_type ."'"); db_query("DELETE from {search_index} where lno = '". $node["lno"] ."' and type = '". $node_type ."'");
/* /*
** Build the wordlist, teaser not included, as it then gives a ** Build the wordlist, teaser not included, as it then gives a
@ -284,7 +284,7 @@ function update_index($search_array) {
*/ */
if ($newwords) { if ($newwords) {
foreach ($newwords as $key => $value) { foreach ($newwords as $key => $value) {
db_query("INSERT INTO search_index VALUES('%s', %d, '%s', %d)", $key, $node["lno"], $node_type, $value); db_query("INSERT INTO {search_index} VALUES('%s', %d, '%s', %d)", $key, $node["lno"], $node_type, $value);
} }
} }

View File

@ -226,7 +226,7 @@ function update_index($search_array) {
** Trash any existing entries in the search index for this node, ** Trash any existing entries in the search index for this node,
** in case its a modified node. ** in case its a modified node.
*/ */
db_query("DELETE from search_index where lno = '". $node["lno"] ."' and type = '". $node_type ."'"); db_query("DELETE from {search_index} where lno = '". $node["lno"] ."' and type = '". $node_type ."'");
/* /*
** Build the wordlist, teaser not included, as it then gives a ** Build the wordlist, teaser not included, as it then gives a
@ -284,7 +284,7 @@ function update_index($search_array) {
*/ */
if ($newwords) { if ($newwords) {
foreach ($newwords as $key => $value) { foreach ($newwords as $key => $value) {
db_query("INSERT INTO search_index VALUES('%s', %d, '%s', %d)", $key, $node["lno"], $node_type, $value); db_query("INSERT INTO {search_index} VALUES('%s', %d, '%s', %d)", $key, $node["lno"], $node_type, $value);
} }
} }

View File

@ -27,7 +27,7 @@ function statistics_init() {
if ($throttle < 5) { if ($throttle < 5) {
$multiplier = variable_get("statistics_throttle_multiplier", 60); $multiplier = variable_get("statistics_throttle_multiplier", 60);
// count all hits in past sixty seconds // count all hits in past sixty seconds
$result = db_query("SELECT COUNT(timestamp) AS hits FROM accesslog WHERE timestamp >= %d", (time() - 60)); $result = db_query("SELECT COUNT(timestamp) AS hits FROM {accesslog} WHERE timestamp >= %d", (time() - 60));
$recent_activity = db_fetch_array($result); $recent_activity = db_fetch_array($result);
throttle_update($recent_activity["hits"]); throttle_update($recent_activity["hits"]);
} }
@ -42,11 +42,11 @@ function statistics_exit() {
// node view counters are enabled // node view counters are enabled
if ((arg(0) == "node") && (arg(1) == "view") && arg(2)) { if ((arg(0) == "node") && (arg(1) == "view") && arg(2)) {
// a node has been viewed, so updated the node's counters // a node has been viewed, so updated the node's counters
db_query("UPDATE statistics SET daycount = daycount + 1, totalcount = totalcount + 1, timestamp = %d WHERE nid = %d", time(), arg(2)); db_query("UPDATE {statistics} SET daycount = daycount + 1, totalcount = totalcount + 1, timestamp = %d WHERE nid = %d", time(), arg(2));
// if we affected 0 rows, this is the first time viewing the node // if we affected 0 rows, this is the first time viewing the node
if (!db_affected_rows()) { if (!db_affected_rows()) {
// must create a new row to store counter's for new node // must create a new row to store counter's for new node
db_query("INSERT INTO statistics (nid, daycount, totalcount) VALUES(%d, 1, 1)", arg(2)); db_query("INSERT INTO {statistics} (nid, daycount, totalcount) VALUES(%d, 1, 1)", arg(2));
} }
} }
} }
@ -57,10 +57,10 @@ function statistics_exit() {
$hostname = getenv("REMOTE_ADDR"); $hostname = getenv("REMOTE_ADDR");
// log this page access // log this page access
if ((arg(0) == "node") && (arg(1) == "view") && arg(2)) { if ((arg(0) == "node") && (arg(1) == "view") && arg(2)) {
db_query("INSERT INTO accesslog (nid, url, hostname, uid, timestamp) values(%d, '%s', '%s', %d, %d)", arg(2), $referrer, $hostname, $user->uid, time()); db_query("INSERT INTO {accesslog} (nid, url, hostname, uid, timestamp) values(%d, '%s', '%s', %d, %d)", arg(2), $referrer, $hostname, $user->uid, time());
} }
else { else {
db_query("INSERT INTO accesslog (url, hostname, uid, timestamp) values('%s', '%s', %d, %d)", $referrer, $hostname, $user->uid, time()); db_query("INSERT INTO {accesslog} (url, hostname, uid, timestamp) values('%s', '%s', %d, %d)", $referrer, $hostname, $user->uid, time());
} }
} }
} }
@ -261,7 +261,7 @@ function statistics_admin() {
/* Displays the various admin tables */ /* Displays the various admin tables */
function statistics_admin_count_table($dbfield, $dbrows) { function statistics_admin_count_table($dbfield, $dbrows) {
$result = db_query_range("SELECT s.nid, s.daycount, s.totalcount, s.timestamp, n.title FROM statistics s LEFT JOIN node n USING (nid) WHERE s.%s <> '0' ORDER BY s.%s DESC", $dbfield, $dbfield, 0, $dbrows); $result = db_query_range("SELECT s.nid, s.daycount, s.totalcount, s.timestamp, n.title FROM {statistics} s LEFT JOIN {node} n USING (nid) WHERE s.%s <> '0' ORDER BY s.%s DESC", $dbfield, $dbfield, 0, $dbrows);
$header = array(t("title"), t("today"), t("all time"), t("last hit"), t("operations")); $header = array(t("title"), t("today"), t("all time"), t("last hit"), t("operations"));
@ -279,24 +279,24 @@ function statistics_admin_accesslog_table($type, $id) {
/* retrieve user access logs */ /* retrieve user access logs */
if ($id) { if ($id) {
/* retrieve recent access logs for user $id */ /* retrieve recent access logs for user $id */
$result = pager_query("SELECT nid, url, hostname, uid, timestamp FROM accesslog WHERE uid = '". check_query($id) ."' ORDER BY timestamp DESC", 50); $result = pager_query("SELECT nid, url, hostname, uid, timestamp FROM {accesslog} WHERE uid = '". check_query($id) ."' ORDER BY timestamp DESC", 50);
} }
else { else {
/* retrieve recent access logs for all users */ /* retrieve recent access logs for all users */
$result = pager_query("SELECT nid, url, hostname, uid, MAX(timestamp) AS timestamp FROM accesslog WHERE uid <> '0' GROUP BY uid, nid, url, hostname ORDER BY timestamp DESC", 50); $result = pager_query("SELECT nid, url, hostname, uid, MAX(timestamp) AS timestamp FROM {accesslog} WHERE uid <> '0' GROUP BY uid, nid, url, hostname ORDER BY timestamp DESC", 50);
} }
} }
else if ($type == 2) { else if ($type == 2) {
/* retrieve recent access logs for node $id */ /* retrieve recent access logs for node $id */
$result = pager_query("SELECT nid, url, hostname, uid, timestamp FROM accesslog WHERE nid = '". check_query($id) ."' ORDER BY timestamp DESC", 50); $result = pager_query("SELECT nid, url, hostname, uid, timestamp FROM {accesslog} WHERE nid = '". check_query($id) ."' ORDER BY timestamp DESC", 50);
} }
else if ($type == 3) { else if ($type == 3) {
/* retrieve recent access logs for hostname $id */ /* retrieve recent access logs for hostname $id */
$result = pager_query("SELECT nid, url, hostname, uid, timestamp FROM accesslog WHERE hostname = '". check_query($id) ."' ORDER BY timestamp DESC", 50); $result = pager_query("SELECT nid, url, hostname, uid, timestamp FROM {accesslog} WHERE hostname = '". check_query($id) ."' ORDER BY timestamp DESC", 50);
} }
else { else {
/* retrieve all recent access logs */ /* retrieve all recent access logs */
$result = pager_query("SELECT nid, url, hostname, uid, timestamp FROM accesslog ORDER BY timestamp DESC", 50); $result = pager_query("SELECT nid, url, hostname, uid, timestamp FROM {accesslog} ORDER BY timestamp DESC", 50);
} }
$header = array(t("timestamp"), t("post"), t("user"), t("hostname"), t("referrer"), array("data" => t("operations"), "colspan" => "3")); $header = array(t("timestamp"), t("post"), t("user"), t("hostname"), t("referrer"), array("data" => t("operations"), "colspan" => "3"));
@ -330,14 +330,14 @@ function statistics_recent_refer() {
$view = arg(3); $view = arg(3);
if ($view == "all") { if ($view == "all") {
$query = "SELECT url,timestamp FROM accesslog WHERE url <> '' ORDER BY timestamp DESC"; $query = "SELECT url,timestamp FROM {accesslog} WHERE url <> '' ORDER BY timestamp DESC";
} }
elseif ($view == "internal") { elseif ($view == "internal") {
$query = "SELECT url,timestamp FROM accesslog WHERE url LIKE '%". check_query($_SERVER["HTTP_HOST"]) ."%' ORDER BY timestamp DESC"; $query = "SELECT url,timestamp FROM {accesslog} WHERE url LIKE '%". check_query($_SERVER["HTTP_HOST"]) ."%' ORDER BY timestamp DESC";
$describe = "internal "; $describe = "internal ";
} }
else { else {
$query = "SELECT url,timestamp FROM accesslog WHERE url NOT LIKE '%". check_query($_SERVER["HTTP_HOST"]) ."%' AND url <> '' ORDER BY timestamp DESC"; $query = "SELECT url,timestamp FROM {accesslog} WHERE url NOT LIKE '%". check_query($_SERVER["HTTP_HOST"]) ."%' AND url <> '' ORDER BY timestamp DESC";
$describe = "external "; $describe = "external ";
} }
@ -360,15 +360,15 @@ function statistics_top_refer() {
$view = arg(3); $view = arg(3);
if ($view == "all") { if ($view == "all") {
$query = "SELECT url, COUNT(url) AS count FROM accesslog WHERE url <> '' GROUP BY url ORDER BY count DESC"; $query = "SELECT url, COUNT(url) AS count FROM {accesslog} WHERE url <> '' GROUP BY url ORDER BY count DESC";
} }
elseif ($view == "internal") { elseif ($view == "internal") {
$query = "SELECT url, COUNT(url) AS count FROM accesslog WHERE url LIKE '%". check_query($_SERVER["HTTP_HOST"]) ."%' GROUP BY url ORDER BY count DESC"; $query = "SELECT url, COUNT(url) AS count FROM {accesslog} WHERE url LIKE '%". check_query($_SERVER["HTTP_HOST"]) ."%' GROUP BY url ORDER BY count DESC";
$describe = "internal "; $describe = "internal ";
} }
else { else {
/* default to external */ /* default to external */
$query = "SELECT url, COUNT(url) AS count FROM accesslog WHERE url NOT LIKE '%". check_query($_SERVER["HTTP_HOST"]) ."%' AND url <> '' GROUP BY url ORDER BY count DESC"; $query = "SELECT url, COUNT(url) AS count FROM {accesslog} WHERE url NOT LIKE '%". check_query($_SERVER["HTTP_HOST"]) ."%' AND url <> '' GROUP BY url ORDER BY count DESC";
$describe = "external "; $describe = "external ";
} }
@ -565,12 +565,12 @@ function statistics_cron() {
if ((time() - $statistics_timestamp) >= 86400) { if ((time() - $statistics_timestamp) >= 86400) {
/* reset day counts */ /* reset day counts */
db_query("UPDATE statistics SET daycount='0'"); db_query("UPDATE {statistics} SET daycount='0'");
variable_set("statistics_day_timestamp", time()); variable_set("statistics_day_timestamp", time());
} }
/* clean expired access logs */ /* clean expired access logs */
db_query("DELETE FROM accesslog WHERE ". time() ." - timestamp > ". variable_get("statistics_flush_accesslog_timer", 259200)); db_query("DELETE FROM {accesslog} WHERE ". time() ." - timestamp > ". variable_get("statistics_flush_accesslog_timer", 259200));
$throttle = variable_get("statistics_throttle_level", 0); $throttle = variable_get("statistics_throttle_level", 0);
/* check if throttle is currently on and if it's time to drop level */ /* check if throttle is currently on and if it's time to drop level */
@ -626,7 +626,7 @@ function statistics_display_online_block() {
** This call gathers all the info we need on users/guests in a single ** This call gathers all the info we need on users/guests in a single
** database call, thus is quite efficient. ** database call, thus is quite efficient.
*/ */
$result = db_query("SELECT COUNT(DISTINCT hostname) AS count, uid, MAX(timestamp) AS max_timestamp FROM accesslog WHERE timestamp >= %d GROUP BY uid ORDER BY max_timestamp DESC", (time() - $time_period)); $result = db_query("SELECT COUNT(DISTINCT hostname) AS count, uid, MAX(timestamp) AS max_timestamp FROM {accesslog} WHERE timestamp >= %d GROUP BY uid ORDER BY max_timestamp DESC", (time() - $time_period));
$users = $guests = 0; $users = $guests = 0;
/* Count number of users & guests currently online based on db query */ /* Count number of users & guests currently online based on db query */
@ -682,7 +682,7 @@ function statistics_display_online_block() {
/* Display linked title based on field name */ /* Display linked title based on field name */
function statistics_title_list($dbfield, $dbrows) { function statistics_title_list($dbfield, $dbrows) {
/* valid dbfields: totalcount, daycount, timestamp */ /* valid dbfields: totalcount, daycount, timestamp */
return db_query_range("SELECT s.nid, n.title, u.uid, u.name FROM statistics s LEFT JOIN node n ON s.nid = n.nid LEFT JOIN users u ON n.uid = u.uid WHERE %s <> '0' AND n.status = 1 ORDER BY %s DESC", "s.". $dbfield, "s.". $dbfield, 0, $dbrows); return db_query_range("SELECT s.nid, n.title, u.uid, u.name FROM {statistics} s LEFT JOIN {node} n ON s.nid = n.nid LEFT JOIN {users} u ON n.uid = u.uid WHERE %s <> '0' AND n.status = 1 ORDER BY %s DESC", "s.". $dbfield, "s.". $dbfield, 0, $dbrows);
} }
@ -691,7 +691,7 @@ function statistics_get($nid) {
if ($nid > 0) { if ($nid > 0) {
/* retrieves an array with both totalcount and daycount */ /* retrieves an array with both totalcount and daycount */
$statistics = db_fetch_array(db_query("SELECT totalcount, daycount, timestamp FROM statistics WHERE nid = %d", $nid)); $statistics = db_fetch_array(db_query("SELECT totalcount, daycount, timestamp FROM {statistics} WHERE nid = %d", $nid));
} }
return $statistics; return $statistics;
@ -782,7 +782,7 @@ function statistics_summary($dbfield, $dbrows) {
/* valid dbfields: totalcount, daycount, timestamp */ /* valid dbfields: totalcount, daycount, timestamp */
$output = ""; $output = "";
$result = db_query_range("SELECT n.nid, n.title FROM statistics s LEFT JOIN node n ON s.nid = n.nid ORDER BY %s DESC", $dbfield, 0, $dbrows); $result = db_query_range("SELECT n.nid, n.title FROM {statistics} s LEFT JOIN {node} n ON s.nid = n.nid ORDER BY %s DESC", $dbfield, 0, $dbrows);
while ($nid = db_fetch_array($result)) { while ($nid = db_fetch_array($result)) {
$content = node_load(array("nid" => $nid["nid"])); $content = node_load(array("nid" => $nid["nid"]));
$links = link_node($content, 1); $links = link_node($content, 1);
@ -799,7 +799,7 @@ function statistics_nodeapi(&$node, $op, $arg = 0) {
switch ($op) { switch ($op) {
case "delete": case "delete":
// clean up statistics table when node is deleted // clean up statistics table when node is deleted
db_query("DELETE FROM statistics WHERE nid = %d", $node->nid); db_query("DELETE FROM {statistics} WHERE nid = %d", $node->nid);
} }
} }

View File

@ -27,7 +27,7 @@ function statistics_init() {
if ($throttle < 5) { if ($throttle < 5) {
$multiplier = variable_get("statistics_throttle_multiplier", 60); $multiplier = variable_get("statistics_throttle_multiplier", 60);
// count all hits in past sixty seconds // count all hits in past sixty seconds
$result = db_query("SELECT COUNT(timestamp) AS hits FROM accesslog WHERE timestamp >= %d", (time() - 60)); $result = db_query("SELECT COUNT(timestamp) AS hits FROM {accesslog} WHERE timestamp >= %d", (time() - 60));
$recent_activity = db_fetch_array($result); $recent_activity = db_fetch_array($result);
throttle_update($recent_activity["hits"]); throttle_update($recent_activity["hits"]);
} }
@ -42,11 +42,11 @@ function statistics_exit() {
// node view counters are enabled // node view counters are enabled
if ((arg(0) == "node") && (arg(1) == "view") && arg(2)) { if ((arg(0) == "node") && (arg(1) == "view") && arg(2)) {
// a node has been viewed, so updated the node's counters // a node has been viewed, so updated the node's counters
db_query("UPDATE statistics SET daycount = daycount + 1, totalcount = totalcount + 1, timestamp = %d WHERE nid = %d", time(), arg(2)); db_query("UPDATE {statistics} SET daycount = daycount + 1, totalcount = totalcount + 1, timestamp = %d WHERE nid = %d", time(), arg(2));
// if we affected 0 rows, this is the first time viewing the node // if we affected 0 rows, this is the first time viewing the node
if (!db_affected_rows()) { if (!db_affected_rows()) {
// must create a new row to store counter's for new node // must create a new row to store counter's for new node
db_query("INSERT INTO statistics (nid, daycount, totalcount) VALUES(%d, 1, 1)", arg(2)); db_query("INSERT INTO {statistics} (nid, daycount, totalcount) VALUES(%d, 1, 1)", arg(2));
} }
} }
} }
@ -57,10 +57,10 @@ function statistics_exit() {
$hostname = getenv("REMOTE_ADDR"); $hostname = getenv("REMOTE_ADDR");
// log this page access // log this page access
if ((arg(0) == "node") && (arg(1) == "view") && arg(2)) { if ((arg(0) == "node") && (arg(1) == "view") && arg(2)) {
db_query("INSERT INTO accesslog (nid, url, hostname, uid, timestamp) values(%d, '%s', '%s', %d, %d)", arg(2), $referrer, $hostname, $user->uid, time()); db_query("INSERT INTO {accesslog} (nid, url, hostname, uid, timestamp) values(%d, '%s', '%s', %d, %d)", arg(2), $referrer, $hostname, $user->uid, time());
} }
else { else {
db_query("INSERT INTO accesslog (url, hostname, uid, timestamp) values('%s', '%s', %d, %d)", $referrer, $hostname, $user->uid, time()); db_query("INSERT INTO {accesslog} (url, hostname, uid, timestamp) values('%s', '%s', %d, %d)", $referrer, $hostname, $user->uid, time());
} }
} }
} }
@ -261,7 +261,7 @@ function statistics_admin() {
/* Displays the various admin tables */ /* Displays the various admin tables */
function statistics_admin_count_table($dbfield, $dbrows) { function statistics_admin_count_table($dbfield, $dbrows) {
$result = db_query_range("SELECT s.nid, s.daycount, s.totalcount, s.timestamp, n.title FROM statistics s LEFT JOIN node n USING (nid) WHERE s.%s <> '0' ORDER BY s.%s DESC", $dbfield, $dbfield, 0, $dbrows); $result = db_query_range("SELECT s.nid, s.daycount, s.totalcount, s.timestamp, n.title FROM {statistics} s LEFT JOIN {node} n USING (nid) WHERE s.%s <> '0' ORDER BY s.%s DESC", $dbfield, $dbfield, 0, $dbrows);
$header = array(t("title"), t("today"), t("all time"), t("last hit"), t("operations")); $header = array(t("title"), t("today"), t("all time"), t("last hit"), t("operations"));
@ -279,24 +279,24 @@ function statistics_admin_accesslog_table($type, $id) {
/* retrieve user access logs */ /* retrieve user access logs */
if ($id) { if ($id) {
/* retrieve recent access logs for user $id */ /* retrieve recent access logs for user $id */
$result = pager_query("SELECT nid, url, hostname, uid, timestamp FROM accesslog WHERE uid = '". check_query($id) ."' ORDER BY timestamp DESC", 50); $result = pager_query("SELECT nid, url, hostname, uid, timestamp FROM {accesslog} WHERE uid = '". check_query($id) ."' ORDER BY timestamp DESC", 50);
} }
else { else {
/* retrieve recent access logs for all users */ /* retrieve recent access logs for all users */
$result = pager_query("SELECT nid, url, hostname, uid, MAX(timestamp) AS timestamp FROM accesslog WHERE uid <> '0' GROUP BY uid, nid, url, hostname ORDER BY timestamp DESC", 50); $result = pager_query("SELECT nid, url, hostname, uid, MAX(timestamp) AS timestamp FROM {accesslog} WHERE uid <> '0' GROUP BY uid, nid, url, hostname ORDER BY timestamp DESC", 50);
} }
} }
else if ($type == 2) { else if ($type == 2) {
/* retrieve recent access logs for node $id */ /* retrieve recent access logs for node $id */
$result = pager_query("SELECT nid, url, hostname, uid, timestamp FROM accesslog WHERE nid = '". check_query($id) ."' ORDER BY timestamp DESC", 50); $result = pager_query("SELECT nid, url, hostname, uid, timestamp FROM {accesslog} WHERE nid = '". check_query($id) ."' ORDER BY timestamp DESC", 50);
} }
else if ($type == 3) { else if ($type == 3) {
/* retrieve recent access logs for hostname $id */ /* retrieve recent access logs for hostname $id */
$result = pager_query("SELECT nid, url, hostname, uid, timestamp FROM accesslog WHERE hostname = '". check_query($id) ."' ORDER BY timestamp DESC", 50); $result = pager_query("SELECT nid, url, hostname, uid, timestamp FROM {accesslog} WHERE hostname = '". check_query($id) ."' ORDER BY timestamp DESC", 50);
} }
else { else {
/* retrieve all recent access logs */ /* retrieve all recent access logs */
$result = pager_query("SELECT nid, url, hostname, uid, timestamp FROM accesslog ORDER BY timestamp DESC", 50); $result = pager_query("SELECT nid, url, hostname, uid, timestamp FROM {accesslog} ORDER BY timestamp DESC", 50);
} }
$header = array(t("timestamp"), t("post"), t("user"), t("hostname"), t("referrer"), array("data" => t("operations"), "colspan" => "3")); $header = array(t("timestamp"), t("post"), t("user"), t("hostname"), t("referrer"), array("data" => t("operations"), "colspan" => "3"));
@ -330,14 +330,14 @@ function statistics_recent_refer() {
$view = arg(3); $view = arg(3);
if ($view == "all") { if ($view == "all") {
$query = "SELECT url,timestamp FROM accesslog WHERE url <> '' ORDER BY timestamp DESC"; $query = "SELECT url,timestamp FROM {accesslog} WHERE url <> '' ORDER BY timestamp DESC";
} }
elseif ($view == "internal") { elseif ($view == "internal") {
$query = "SELECT url,timestamp FROM accesslog WHERE url LIKE '%". check_query($_SERVER["HTTP_HOST"]) ."%' ORDER BY timestamp DESC"; $query = "SELECT url,timestamp FROM {accesslog} WHERE url LIKE '%". check_query($_SERVER["HTTP_HOST"]) ."%' ORDER BY timestamp DESC";
$describe = "internal "; $describe = "internal ";
} }
else { else {
$query = "SELECT url,timestamp FROM accesslog WHERE url NOT LIKE '%". check_query($_SERVER["HTTP_HOST"]) ."%' AND url <> '' ORDER BY timestamp DESC"; $query = "SELECT url,timestamp FROM {accesslog} WHERE url NOT LIKE '%". check_query($_SERVER["HTTP_HOST"]) ."%' AND url <> '' ORDER BY timestamp DESC";
$describe = "external "; $describe = "external ";
} }
@ -360,15 +360,15 @@ function statistics_top_refer() {
$view = arg(3); $view = arg(3);
if ($view == "all") { if ($view == "all") {
$query = "SELECT url, COUNT(url) AS count FROM accesslog WHERE url <> '' GROUP BY url ORDER BY count DESC"; $query = "SELECT url, COUNT(url) AS count FROM {accesslog} WHERE url <> '' GROUP BY url ORDER BY count DESC";
} }
elseif ($view == "internal") { elseif ($view == "internal") {
$query = "SELECT url, COUNT(url) AS count FROM accesslog WHERE url LIKE '%". check_query($_SERVER["HTTP_HOST"]) ."%' GROUP BY url ORDER BY count DESC"; $query = "SELECT url, COUNT(url) AS count FROM {accesslog} WHERE url LIKE '%". check_query($_SERVER["HTTP_HOST"]) ."%' GROUP BY url ORDER BY count DESC";
$describe = "internal "; $describe = "internal ";
} }
else { else {
/* default to external */ /* default to external */
$query = "SELECT url, COUNT(url) AS count FROM accesslog WHERE url NOT LIKE '%". check_query($_SERVER["HTTP_HOST"]) ."%' AND url <> '' GROUP BY url ORDER BY count DESC"; $query = "SELECT url, COUNT(url) AS count FROM {accesslog} WHERE url NOT LIKE '%". check_query($_SERVER["HTTP_HOST"]) ."%' AND url <> '' GROUP BY url ORDER BY count DESC";
$describe = "external "; $describe = "external ";
} }
@ -565,12 +565,12 @@ function statistics_cron() {
if ((time() - $statistics_timestamp) >= 86400) { if ((time() - $statistics_timestamp) >= 86400) {
/* reset day counts */ /* reset day counts */
db_query("UPDATE statistics SET daycount='0'"); db_query("UPDATE {statistics} SET daycount='0'");
variable_set("statistics_day_timestamp", time()); variable_set("statistics_day_timestamp", time());
} }
/* clean expired access logs */ /* clean expired access logs */
db_query("DELETE FROM accesslog WHERE ". time() ." - timestamp > ". variable_get("statistics_flush_accesslog_timer", 259200)); db_query("DELETE FROM {accesslog} WHERE ". time() ." - timestamp > ". variable_get("statistics_flush_accesslog_timer", 259200));
$throttle = variable_get("statistics_throttle_level", 0); $throttle = variable_get("statistics_throttle_level", 0);
/* check if throttle is currently on and if it's time to drop level */ /* check if throttle is currently on and if it's time to drop level */
@ -626,7 +626,7 @@ function statistics_display_online_block() {
** This call gathers all the info we need on users/guests in a single ** This call gathers all the info we need on users/guests in a single
** database call, thus is quite efficient. ** database call, thus is quite efficient.
*/ */
$result = db_query("SELECT COUNT(DISTINCT hostname) AS count, uid, MAX(timestamp) AS max_timestamp FROM accesslog WHERE timestamp >= %d GROUP BY uid ORDER BY max_timestamp DESC", (time() - $time_period)); $result = db_query("SELECT COUNT(DISTINCT hostname) AS count, uid, MAX(timestamp) AS max_timestamp FROM {accesslog} WHERE timestamp >= %d GROUP BY uid ORDER BY max_timestamp DESC", (time() - $time_period));
$users = $guests = 0; $users = $guests = 0;
/* Count number of users & guests currently online based on db query */ /* Count number of users & guests currently online based on db query */
@ -682,7 +682,7 @@ function statistics_display_online_block() {
/* Display linked title based on field name */ /* Display linked title based on field name */
function statistics_title_list($dbfield, $dbrows) { function statistics_title_list($dbfield, $dbrows) {
/* valid dbfields: totalcount, daycount, timestamp */ /* valid dbfields: totalcount, daycount, timestamp */
return db_query_range("SELECT s.nid, n.title, u.uid, u.name FROM statistics s LEFT JOIN node n ON s.nid = n.nid LEFT JOIN users u ON n.uid = u.uid WHERE %s <> '0' AND n.status = 1 ORDER BY %s DESC", "s.". $dbfield, "s.". $dbfield, 0, $dbrows); return db_query_range("SELECT s.nid, n.title, u.uid, u.name FROM {statistics} s LEFT JOIN {node} n ON s.nid = n.nid LEFT JOIN {users} u ON n.uid = u.uid WHERE %s <> '0' AND n.status = 1 ORDER BY %s DESC", "s.". $dbfield, "s.". $dbfield, 0, $dbrows);
} }
@ -691,7 +691,7 @@ function statistics_get($nid) {
if ($nid > 0) { if ($nid > 0) {
/* retrieves an array with both totalcount and daycount */ /* retrieves an array with both totalcount and daycount */
$statistics = db_fetch_array(db_query("SELECT totalcount, daycount, timestamp FROM statistics WHERE nid = %d", $nid)); $statistics = db_fetch_array(db_query("SELECT totalcount, daycount, timestamp FROM {statistics} WHERE nid = %d", $nid));
} }
return $statistics; return $statistics;
@ -782,7 +782,7 @@ function statistics_summary($dbfield, $dbrows) {
/* valid dbfields: totalcount, daycount, timestamp */ /* valid dbfields: totalcount, daycount, timestamp */
$output = ""; $output = "";
$result = db_query_range("SELECT n.nid, n.title FROM statistics s LEFT JOIN node n ON s.nid = n.nid ORDER BY %s DESC", $dbfield, 0, $dbrows); $result = db_query_range("SELECT n.nid, n.title FROM {statistics} s LEFT JOIN {node} n ON s.nid = n.nid ORDER BY %s DESC", $dbfield, 0, $dbrows);
while ($nid = db_fetch_array($result)) { while ($nid = db_fetch_array($result)) {
$content = node_load(array("nid" => $nid["nid"])); $content = node_load(array("nid" => $nid["nid"]));
$links = link_node($content, 1); $links = link_node($content, 1);
@ -799,7 +799,7 @@ function statistics_nodeapi(&$node, $op, $arg = 0) {
switch ($op) { switch ($op) {
case "delete": case "delete":
// clean up statistics table when node is deleted // clean up statistics table when node is deleted
db_query("DELETE FROM statistics WHERE nid = %d", $node->nid); db_query("DELETE FROM {statistics} WHERE nid = %d", $node->nid);
} }
} }

View File

@ -167,9 +167,9 @@ function system_view_filters() {
function system_save_settings($edit = array()) { function system_save_settings($edit = array()) {
if ($edit["type"]) { if ($edit["type"]) {
db_query("UPDATE system SET status = '0' WHERE type = '%s'", $edit["type"]); db_query("UPDATE {system} SET status = '0' WHERE type = '%s'", $edit["type"]);
foreach ($edit["status"] as $filename => $status) { foreach ($edit["status"] as $filename => $status) {
db_query("UPDATE system SET status = %d WHERE filename = '$filename'", $status); db_query("UPDATE {system} SET status = %d WHERE filename = '$filename'", $status);
} }
if ($edit["type"] == "theme") { if ($edit["type"] == "theme") {
variable_set("theme_default", $edit["theme_default"]); variable_set("theme_default", $edit["theme_default"]);
@ -257,7 +257,7 @@ function system_listing($type, $directory, $required = array()) {
$files = system_dirscan($directory, "\.$type$"); $files = system_dirscan($directory, "\.$type$");
// Extract current files from database. // Extract current files from database.
$result = db_query("SELECT filename, type, status FROM system WHERE type = '%s'", $type); $result = db_query("SELECT filename, type, status FROM {system} WHERE type = '%s'", $type);
while ($file = db_fetch_object($result)) { while ($file = db_fetch_object($result)) {
if (is_object($files[$file->filename])) { if (is_object($files[$file->filename])) {
foreach ($file as $key => $value) { foreach ($file as $key => $value) {
@ -290,8 +290,8 @@ function system_listing($type, $directory, $required = array()) {
} }
// Update the contents of the system table: // Update the contents of the system table:
db_query("DELETE FROM system WHERE filename = '%s' AND type = '%s'", $filename, $type); db_query("DELETE FROM {system} WHERE filename = '%s' AND type = '%s'", $filename, $type);
db_query("INSERT INTO system (name, description, type, filename, status) VALUES ('%s', '%s', '%s', '%s', %d)", $info->name, $info->description, $type, $filename, $file->status); db_query("INSERT INTO {system} (name, description, type, filename, status) VALUES ('%s', '%s', '%s', '%s', %d)", $info->name, $info->description, $type, $filename, $file->status);
$rows[] = array($info->name, $info->description, array("data" => (in_array($filename, $required) ? form_hidden("status][$filename", 1) . t("required") : form_checkbox("", "status][$filename", 1, $file->status)), "align" => "center")); $rows[] = array($info->name, $info->description, array("data" => (in_array($filename, $required) ? form_hidden("status][$filename", 1) . t("required") : form_checkbox("", "status][$filename", 1, $file->status)), "align" => "center"));
} }

View File

@ -167,9 +167,9 @@ function system_view_filters() {
function system_save_settings($edit = array()) { function system_save_settings($edit = array()) {
if ($edit["type"]) { if ($edit["type"]) {
db_query("UPDATE system SET status = '0' WHERE type = '%s'", $edit["type"]); db_query("UPDATE {system} SET status = '0' WHERE type = '%s'", $edit["type"]);
foreach ($edit["status"] as $filename => $status) { foreach ($edit["status"] as $filename => $status) {
db_query("UPDATE system SET status = %d WHERE filename = '$filename'", $status); db_query("UPDATE {system} SET status = %d WHERE filename = '$filename'", $status);
} }
if ($edit["type"] == "theme") { if ($edit["type"] == "theme") {
variable_set("theme_default", $edit["theme_default"]); variable_set("theme_default", $edit["theme_default"]);
@ -257,7 +257,7 @@ function system_listing($type, $directory, $required = array()) {
$files = system_dirscan($directory, "\.$type$"); $files = system_dirscan($directory, "\.$type$");
// Extract current files from database. // Extract current files from database.
$result = db_query("SELECT filename, type, status FROM system WHERE type = '%s'", $type); $result = db_query("SELECT filename, type, status FROM {system} WHERE type = '%s'", $type);
while ($file = db_fetch_object($result)) { while ($file = db_fetch_object($result)) {
if (is_object($files[$file->filename])) { if (is_object($files[$file->filename])) {
foreach ($file as $key => $value) { foreach ($file as $key => $value) {
@ -290,8 +290,8 @@ function system_listing($type, $directory, $required = array()) {
} }
// Update the contents of the system table: // Update the contents of the system table:
db_query("DELETE FROM system WHERE filename = '%s' AND type = '%s'", $filename, $type); db_query("DELETE FROM {system} WHERE filename = '%s' AND type = '%s'", $filename, $type);
db_query("INSERT INTO system (name, description, type, filename, status) VALUES ('%s', '%s', '%s', '%s', %d)", $info->name, $info->description, $type, $filename, $file->status); db_query("INSERT INTO {system} (name, description, type, filename, status) VALUES ('%s', '%s', '%s', '%s', %d)", $info->name, $info->description, $type, $filename, $file->status);
$rows[] = array($info->name, $info->description, array("data" => (in_array($filename, $required) ? form_hidden("status][$filename", 1) . t("required") : form_checkbox("", "status][$filename", 1, $file->status)), "align" => "center")); $rows[] = array($info->name, $info->description, array("data" => (in_array($filename, $required) ? form_hidden("status][$filename", 1) . t("required") : form_checkbox("", "status][$filename", 1, $file->status)), "align" => "center"));
} }

View File

@ -99,7 +99,7 @@ function taxonomy_save_vocabulary($edit) {
$data = array("name" => $edit["name"], "nodes" => implode(",", $edit["nodes"]), "description" => $edit["description"], "multiple" => $edit["multiple"], "required" => $edit["required"], "hierarchy" => $edit["hierarchy"], "relations" => $edit["relations"], "weight" => $edit["weight"]); $data = array("name" => $edit["name"], "nodes" => implode(",", $edit["nodes"]), "description" => $edit["description"], "multiple" => $edit["multiple"], "required" => $edit["required"], "hierarchy" => $edit["hierarchy"], "relations" => $edit["relations"], "weight" => $edit["weight"]);
if ($edit["vid"] && $edit["name"]) { if ($edit["vid"] && $edit["name"]) {
db_query("UPDATE vocabulary SET ". _prepare_update($data) ." WHERE vid = %d", $edit["vid"]); db_query("UPDATE {vocabulary} SET ". _prepare_update($data) ." WHERE vid = %d", $edit["vid"]);
module_invoke_all("taxonomy", "update", "vocabulary", $edit); module_invoke_all("taxonomy", "update", "vocabulary", $edit);
$message = t("updated vocabulary '%name'.", array("%name" => $edit["name"])); $message = t("updated vocabulary '%name'.", array("%name" => $edit["name"]));
} }
@ -108,7 +108,7 @@ function taxonomy_save_vocabulary($edit) {
} }
else { else {
$data["vid"] = $edit["vid"] = db_next_id("vocabulary_vid"); $data["vid"] = $edit["vid"] = db_next_id("vocabulary_vid");
db_query("INSERT INTO vocabulary ". _prepare_insert($data, 1) ." VALUES ". _prepare_insert($data, 2)); db_query("INSERT INTO {vocabulary} ". _prepare_insert($data, 1) ." VALUES ". _prepare_insert($data, 2));
module_invoke_all("taxonomy", "insert", "vocabulary", $edit); module_invoke_all("taxonomy", "insert", "vocabulary", $edit);
$message = t("created new vocabulary '%name'.", array("%name" => $edit["name"])); $message = t("created new vocabulary '%name'.", array("%name" => $edit["name"]));
} }
@ -121,8 +121,8 @@ function taxonomy_save_vocabulary($edit) {
function taxonomy_del_vocabulary($vid) { function taxonomy_del_vocabulary($vid) {
$vocabulary = taxonomy_get_vocabulary($vid); $vocabulary = taxonomy_get_vocabulary($vid);
db_query("DELETE FROM vocabulary WHERE vid = %d", $vid); db_query("DELETE FROM {vocabulary} WHERE vid = %d", $vid);
$result = db_query("SELECT tid FROM term_data WHERE vid = %d", $vid); $result = db_query("SELECT tid FROM {term_data} WHERE vid = %d", $vid);
while ($term = db_fetch_object($result)) { while ($term = db_fetch_object($result)) {
taxonomy_del_term($term->tid); taxonomy_del_term($term->tid);
} }
@ -192,7 +192,7 @@ function taxonomy_save_term($edit) {
if ($edit["tid"] && $edit["name"]) { if ($edit["tid"] && $edit["name"]) {
$data = array("name" => $edit["name"], "description" => $edit["description"], "weight" => $edit["weight"]); $data = array("name" => $edit["name"], "description" => $edit["description"], "weight" => $edit["weight"]);
db_query("UPDATE term_data SET ". _prepare_update($data) ." WHERE tid = %d", $edit["tid"]); db_query("UPDATE {term_data} SET ". _prepare_update($data) ." WHERE tid = %d", $edit["tid"]);
module_invoke_all("taxonomy", "update", "term", $edit); module_invoke_all("taxonomy", "update", "term", $edit);
$message = t("the term '%a' has been updated.", array("%a" => $edit["name"])); $message = t("the term '%a' has been updated.", array("%a" => $edit["name"]));
} }
@ -202,40 +202,40 @@ function taxonomy_save_term($edit) {
else { else {
$edit["tid"] = db_next_id("term_data_tid"); $edit["tid"] = db_next_id("term_data_tid");
$data = array("tid" => $edit["tid"], "name" => $edit["name"], "description" => $edit["description"], "vid" => $edit["vid"], "weight" => $edit["weight"]); $data = array("tid" => $edit["tid"], "name" => $edit["name"], "description" => $edit["description"], "vid" => $edit["vid"], "weight" => $edit["weight"]);
db_query("INSERT INTO term_data ". _prepare_insert($data, 1) ." VALUES ". _prepare_insert($data, 2)); db_query("INSERT INTO {term_data} ". _prepare_insert($data, 1) ." VALUES ". _prepare_insert($data, 2));
module_invoke_all("taxonomy", "insert", "term", $edit); module_invoke_all("taxonomy", "insert", "term", $edit);
$message = t("created new term '%name'.", array("%name" => $edit["name"])); $message = t("created new term '%name'.", array("%name" => $edit["name"]));
} }
// relations (seem very powerful, but I have to understand it completely) // relations (seem very powerful, but I have to understand it completely)
db_query("DELETE FROM term_relation WHERE tid1 = %d OR tid2 = %d", $edit["tid"], $edit["tid"]); db_query("DELETE FROM {term_relation} WHERE tid1 = %d OR tid2 = %d", $edit["tid"], $edit["tid"]);
if ($edit["relations"]) { if ($edit["relations"]) {
foreach ($edit["relations"] as $related_id) { foreach ($edit["relations"] as $related_id) {
if ($related_id != 0) { if ($related_id != 0) {
db_query("INSERT INTO term_relation (tid1, tid2) VALUES (%d, %d)", $edit["tid"], $related_id); db_query("INSERT INTO {term_relation} (tid1, tid2) VALUES (%d, %d)", $edit["tid"], $related_id);
} }
} }
} }
// hierarchy // hierarchy
db_query("DELETE FROM term_hierarchy WHERE tid = %d", $edit["tid"]); db_query("DELETE FROM {term_hierarchy} WHERE tid = %d", $edit["tid"]);
if (!isset($edit["parent"])) { if (!isset($edit["parent"])) {
$edit["parent"] = 0; $edit["parent"] = 0;
} }
if (is_array($edit["parent"])) { if (is_array($edit["parent"])) {
foreach ($edit["parent"] as $parent) { foreach ($edit["parent"] as $parent) {
db_query("INSERT INTO term_hierarchy (tid, parent) VALUES (%d, %d)", $edit["tid"], $parent); db_query("INSERT INTO {term_hierarchy} (tid, parent) VALUES (%d, %d)", $edit["tid"], $parent);
} }
} }
else { else {
db_query("INSERT INTO term_hierarchy (tid, parent) VALUES (%d, %d)", $edit["tid"], $edit["parent"][0]); db_query("INSERT INTO {term_hierarchy} (tid, parent) VALUES (%d, %d)", $edit["tid"], $edit["parent"][0]);
} }
db_query("DELETE FROM term_synonym WHERE tid = %d", $edit["tid"]); db_query("DELETE FROM {term_synonym} WHERE tid = %d", $edit["tid"]);
if ($edit["synonyms"]) { if ($edit["synonyms"]) {
foreach (explode ("\n", str_replace("\r", "", $edit["synonyms"])) as $synonym) { foreach (explode ("\n", str_replace("\r", "", $edit["synonyms"])) as $synonym) {
if ($synonym) { if ($synonym) {
db_query("INSERT INTO term_synonym (tid, name) VALUES (%d, '%s')", $edit["tid"], chop($synonym)); db_query("INSERT INTO {term_synonym} (tid, name) VALUES (%d, '%s')", $edit["tid"], chop($synonym));
} }
} }
} }
@ -248,11 +248,11 @@ function taxonomy_save_term($edit) {
function taxonomy_del_term($tid) { function taxonomy_del_term($tid) {
$term = taxonomy_get_term($tid); $term = taxonomy_get_term($tid);
db_query("DELETE FROM term_data WHERE tid = %d", $tid); db_query("DELETE FROM {term_data} WHERE tid = %d", $tid);
db_query("DELETE FROM term_hierarchy WHERE tid = %d", $tid); db_query("DELETE FROM {term_hierarchy} WHERE tid = %d", $tid);
db_query("DELETE FROM term_relation WHERE tid1 = %d OR tid2 = %d", $tid, $tid); db_query("DELETE FROM {term_relation} WHERE tid1 = %d OR tid2 = %d", $tid, $tid);
db_query("DELETE FROM term_synonym WHERE tid = %d", $tid); db_query("DELETE FROM {term_synonym} WHERE tid = %d", $tid);
db_query("DELETE FROM term_node WHERE tid = %d", $tid); db_query("DELETE FROM {term_node} WHERE tid = %d", $tid);
module_invoke_all("taxonomy", "delete", "term", $term); module_invoke_all("taxonomy", "delete", "term", $term);
@ -327,10 +327,10 @@ function taxonomy_form($vocabulary_id, $value = 0) {
// return array of vocabularies, as objects // return array of vocabularies, as objects
function taxonomy_get_vocabularies($type = '', $key = "vid") { function taxonomy_get_vocabularies($type = '', $key = "vid") {
if ($type) { if ($type) {
$result = db_query("SELECT * FROM vocabulary WHERE nodes LIKE '%%%s%%' ORDER BY weight, name", $type); $result = db_query("SELECT * FROM {vocabulary} WHERE nodes LIKE '%%%s%%' ORDER BY weight, name", $type);
} }
else { else {
$result = db_query("SELECT * FROM vocabulary ORDER BY weight, name"); $result = db_query("SELECT * FROM {vocabulary} ORDER BY weight, name");
} }
$vocabularies = array(); $vocabularies = array();
while ($voc = db_fetch_object($result)) { while ($voc = db_fetch_object($result)) {
@ -354,7 +354,7 @@ function taxonomy_node_form($type, $node = '') {
$terms = $node->taxonomy; $terms = $node->taxonomy;
} }
$c = db_query("SELECT * FROM vocabulary WHERE nodes LIKE '%%%s%%' ORDER BY weight, name", $type); $c = db_query("SELECT * FROM {vocabulary} WHERE nodes LIKE '%%%s%%' ORDER BY weight, name", $type);
while ($vocabulary = db_fetch_object($c)) { while ($vocabulary = db_fetch_object($c)) {
$result[] .= taxonomy_form($vocabulary->vid, $terms); $result[] .= taxonomy_form($vocabulary->vid, $terms);
} }
@ -363,14 +363,14 @@ function taxonomy_node_form($type, $node = '') {
// return 1 if node identified by $nid contains a taxonomy term identified by $tid in his body or title // return 1 if node identified by $nid contains a taxonomy term identified by $tid in his body or title
function taxonomy_node_has_term($nid, $tid) { function taxonomy_node_has_term($nid, $tid) {
$term_name = db_result(db_query("SELECT name FROM term_data WHERE tid = %d", $tid)); $term_name = db_result(db_query("SELECT name FROM {term_data} WHERE tid = %d", $tid));
return db_result(db_query("SELECT COUNT(n.nid) FROM node n WHERE n.nid = %d AND ((n.body LIKE '%%%s%%') OR (n.body LIKE '%%%s%%'))", $nid, $term_name, $term_name)); return db_result(db_query("SELECT COUNT(n.nid) FROM {node} n WHERE n.nid = %d AND ((n.body LIKE '%%%s%%') OR (n.body LIKE '%%%s%%'))", $nid, $term_name, $term_name));
} }
// return array of terms of a node beloging to a particular vocabulary identified by $vid // return array of terms of a node beloging to a particular vocabulary identified by $vid
function taxonomy_node_get_terms_by_vocabulary($nid, $vid, $key = "tid") { function taxonomy_node_get_terms_by_vocabulary($nid, $vid, $key = "tid") {
$result = db_query("SELECT t.* FROM term_data t, term_node r WHERE t.tid = r.tid AND t.vid = %d AND r.nid = %d ORDER BY weight", $vid, $nid); $result = db_query("SELECT t.* FROM {term_data} t, {term_node} r WHERE t.tid = r.tid AND t.vid = %d AND r.nid = %d ORDER BY weight", $vid, $nid);
$terms = array(); $terms = array();
while ($term = db_fetch_object($result)) { while ($term = db_fetch_object($result)) {
$terms[$term->$key] = $term; $terms[$term->$key] = $term;
@ -383,7 +383,7 @@ function taxonomy_node_get_terms($nid, $key = "tid") {
static $terms; static $terms;
if (!isset($terms[$nid])) { if (!isset($terms[$nid])) {
$result = db_query("SELECT t.* FROM term_data t, term_node r WHERE r.tid = t.tid AND r.nid = %d ORDER BY weight, name", $nid); $result = db_query("SELECT t.* FROM {term_data} t, {term_node} r WHERE r.tid = t.tid AND r.nid = %d ORDER BY weight, name", $nid);
$terms[$nid] = array(); $terms[$nid] = array();
while ($term = db_fetch_object($result)) { while ($term = db_fetch_object($result)) {
$terms[$nid][$term->$key] = $term; $terms[$nid][$term->$key] = $term;
@ -398,20 +398,20 @@ function taxonomy_node_save($nid, $terms) {
if ($terms) { if ($terms) {
foreach ($terms as $term) { foreach ($terms as $term) {
db_query("INSERT INTO term_node (nid, tid) VALUES (%d, %d)", $nid, $term); db_query("INSERT INTO {term_node} (nid, tid) VALUES (%d, %d)", $nid, $term);
} }
} }
} }
// clean up terms // clean up terms
function taxonomy_node_delete($nid) { function taxonomy_node_delete($nid) {
db_query("DELETE FROM term_node WHERE nid = %d", $nid); db_query("DELETE FROM {term_node} WHERE nid = %d", $nid);
} }
// relations: return array of related terms // relations: return array of related terms
function taxonomy_get_related($tid, $key = "tid") { function taxonomy_get_related($tid, $key = "tid") {
if ($tid) { if ($tid) {
$result = db_query("SELECT t.*, tid1, tid2 FROM term_relation, term_data t WHERE (t.tid = tid1 OR t.tid = tid2) AND (tid1 = %d OR tid2 = %d) AND t.tid != %d ORDER BY weight, name", $tid, $tid, $tid); $result = db_query("SELECT t.*, tid1, tid2 FROM {term_relation} , {term_data} t WHERE (t.tid = tid1 OR t.tid = tid2) AND (tid1 = %d OR tid2 = %d) AND t.tid != %d ORDER BY weight, name", $tid, $tid, $tid);
$related = array(); $related = array();
while ($term = db_fetch_object($result)) { while ($term = db_fetch_object($result)) {
$related[$term->$key] = $term; $related[$term->$key] = $term;
@ -426,7 +426,7 @@ function taxonomy_get_related($tid, $key = "tid") {
// hierarchy: get parent terms // hierarchy: get parent terms
function taxonomy_get_parents($tid, $key = "tid") { function taxonomy_get_parents($tid, $key = "tid") {
if ($tid) { if ($tid) {
$result = db_query("SELECT t.* FROM term_hierarchy h, term_data t WHERE h.parent = t.tid AND h.tid = %d ORDER BY weight, name", $tid); $result = db_query("SELECT t.* FROM {term_hierarchy} h, {term_data} t WHERE h.parent = t.tid AND h.tid = %d ORDER BY weight, name", $tid);
$parents = array(); $parents = array();
while ($parent = db_fetch_object($result)) { while ($parent = db_fetch_object($result)) {
$parents[$parent->$key] = $parent; $parents[$parent->$key] = $parent;
@ -441,10 +441,10 @@ function taxonomy_get_parents($tid, $key = "tid") {
// hierarchy: get children // hierarchy: get children
function taxonomy_get_children($tid, $vid = 0, $key = "tid") { function taxonomy_get_children($tid, $vid = 0, $key = "tid") {
if ($vid) { if ($vid) {
$result = db_query("SELECT t.* FROM term_hierarchy h, term_data t WHERE t.vid = %d AND h.tid = t.tid AND h.parent = %d ORDER BY weight, name", $vid, $tid); $result = db_query("SELECT t.* FROM {term_hierarchy} h, {term_data} t WHERE t.vid = %d AND h.tid = t.tid AND h.parent = %d ORDER BY weight, name", $vid, $tid);
} }
else { else {
$result = db_query("SELECT t.* FROM term_hierarchy h, term_data t WHERE h.tid = t.tid AND parent = %d ORDER BY weight", $tid); $result = db_query("SELECT t.* FROM {term_hierarchy} h, {term_data} t WHERE h.tid = t.tid AND parent = %d ORDER BY weight", $tid);
} }
$children = array(); $children = array();
while ($term = db_fetch_object($result)) { while ($term = db_fetch_object($result)) {
@ -463,7 +463,7 @@ function taxonomy_get_tree($vocabulary_id, $parent = 0, $depth = -1, $key = "tid
if (!isset($children[$vocabulary_id])) { if (!isset($children[$vocabulary_id])) {
$children[$vocabulary_id] = array(); $children[$vocabulary_id] = array();
$result = db_query("SELECT t.*, parent FROM term_data t, term_hierarchy h WHERE t.tid = h.tid AND t.vid = %d ORDER BY weight, name", $vocabulary_id); $result = db_query("SELECT t.*, parent FROM {term_data} t, {term_hierarchy} h WHERE t.tid = h.tid AND t.vid = %d ORDER BY weight, name", $vocabulary_id);
while ($term = db_fetch_object($result)) { while ($term = db_fetch_object($result)) {
$children[$vocabulary_id][$term->parent][] = $term->tid; $children[$vocabulary_id][$term->parent][] = $term->tid;
$parents[$vocabulary_id][$term->tid][] = $term->parent; $parents[$vocabulary_id][$term->tid][] = $term->parent;
@ -488,7 +488,7 @@ function taxonomy_get_tree($vocabulary_id, $parent = 0, $depth = -1, $key = "tid
// synonyms: return array of synonyms // synonyms: return array of synonyms
function taxonomy_get_synonyms($tid) { function taxonomy_get_synonyms($tid) {
if ($tid) { if ($tid) {
$result = db_query("SELECT name FROM term_synonym WHERE tid = %d", $tid); $result = db_query("SELECT name FROM {term_synonym} WHERE tid = %d", $tid);
while ($synonym = db_fetch_array($result)) { while ($synonym = db_fetch_array($result)) {
$synonyms[] = $synonym["name"]; $synonyms[] = $synonym["name"];
} }
@ -501,7 +501,7 @@ function taxonomy_get_synonyms($tid) {
// synonyms: return original term // synonyms: return original term
function taxonomy_get_synonym_root($term) { function taxonomy_get_synonym_root($term) {
return db_fetch_object(db_query("SELECT * FROM term_synonym s, term_data t WHERE t.tid = s.tid AND s.name = '%s'", $term)); return db_fetch_object(db_query("SELECT * FROM {term_synonym} s, {term_data} t WHERE t.tid = s.tid AND s.name = '%s'", $term));
} }
// given a term id, count number of published nodes in it // given a term id, count number of published nodes in it
@ -511,10 +511,10 @@ function taxonomy_term_count_nodes($tid, $type = 0) {
if (!isset($count[$type])) { if (!isset($count[$type])) {
// $type == 0 always evaluates true is $type is a string // $type == 0 always evaluates true is $type is a string
if (is_numeric($type)) { if (is_numeric($type)) {
$result = db_query("SELECT t.tid, COUNT(*) AS c FROM term_node t LEFT JOIN node n ON t.nid = n.nid WHERE n.status = 1 GROUP BY t.tid"); $result = db_query("SELECT t.tid, COUNT(*) AS c FROM {term_node} t LEFT JOIN {node} n ON t.nid = n.nid WHERE n.status = 1 GROUP BY t.tid");
} }
else { else {
$result = db_query("SELECT t.tid, COUNT(*) AS c FROM term_node t, node n WHERE t.nid = n.nid AND n.status = 1 AND n.type = '%s' GROUP BY t.tid", $type); $result = db_query("SELECT t.tid, COUNT(*) AS c FROM {term_node} t, {node} n WHERE t.nid = n.nid AND n.status = 1 AND n.type = '%s' GROUP BY t.tid", $type);
} }
while ($term = db_fetch_object($result)) { while ($term = db_fetch_object($result)) {
$count[$type][$term->tid] = $term->c; $count[$type][$term->tid] = $term->c;
@ -532,7 +532,7 @@ function _taxonomy_term_children($tid) {
static $children; static $children;
if (!isset($children)) { if (!isset($children)) {
$result = db_query("SELECT tid, parent FROM term_hierarchy"); $result = db_query("SELECT tid, parent FROM {term_hierarchy} ");
while ($term = db_fetch_object($result)) { while ($term = db_fetch_object($result)) {
$children[$term->parent][] = $term->tid; $children[$term->parent][] = $term->tid;
} }
@ -550,7 +550,7 @@ function _taxonomy_term_children($tid) {
*/ */
function taxonomy_get_vocabulary_by_name($name) { function taxonomy_get_vocabulary_by_name($name) {
// LOWER is ANSI SQL-92 // LOWER is ANSI SQL-92
$db_result = db_query("SELECT * FROM vocabulary WHERE LOWER('%s') LIKE LOWER(name)", trim($name)); $db_result = db_query("SELECT * FROM {vocabulary} WHERE LOWER('%s') LIKE LOWER(name)", trim($name));
$result = array(); $result = array();
while ($vocabulary = db_fetch_object($db_result)) { while ($vocabulary = db_fetch_object($db_result)) {
$result[] = $vocabulary; $result[] = $vocabulary;
@ -569,7 +569,7 @@ function taxonomy_get_vocabulary_by_name($name) {
*/ */
function taxonomy_get_term_by_name($name) { function taxonomy_get_term_by_name($name) {
// LOWER is ANSI SQL-92 // LOWER is ANSI SQL-92
$db_result = db_query("SELECT * FROM term_data WHERE LOWER('%s') LIKE LOWER(name)", trim($name)); $db_result = db_query("SELECT * FROM {term_data} WHERE LOWER('%s') LIKE LOWER(name)", trim($name));
$result = array(); $result = array();
while ($term = db_fetch_object($db_result)) { while ($term = db_fetch_object($db_result)) {
$result[] = $term; $result[] = $term;
@ -580,12 +580,12 @@ function taxonomy_get_term_by_name($name) {
function taxonomy_get_vocabulary($vid) { function taxonomy_get_vocabulary($vid) {
// simple cache using a static var? // simple cache using a static var?
return db_fetch_object(db_query("SELECT * FROM vocabulary WHERE vid = %d", $vid)); return db_fetch_object(db_query("SELECT * FROM {vocabulary} WHERE vid = %d", $vid));
} }
function taxonomy_get_term($tid) { function taxonomy_get_term($tid) {
// simple cache using a static var? // simple cache using a static var?
return db_fetch_object(db_query("SELECT * FROM term_data WHERE tid = %d", $tid)); return db_fetch_object(db_query("SELECT * FROM {term_data} WHERE tid = %d", $tid));
} }
/* /*
@ -660,14 +660,14 @@ function taxonomy_select_nodes($taxonomy, $pager = 1) {
if ($taxonomy->str_tids) { if ($taxonomy->str_tids) {
if ($taxonomy->operator == "or") { if ($taxonomy->operator == "or") {
$sql = "SELECT DISTINCT(n.nid), n.title, n.type, n.created, n.changed, n.uid, n.static, n.created, u.name FROM node n LEFT JOIN term_node r ON n.nid = r.nid LEFT JOIN users u ON n.uid = u.uid WHERE r.tid IN ($taxonomy->str_tids) AND n.status = '1' ORDER BY static DESC, created DESC"; $sql = "SELECT DISTINCT(n.nid), n.title, n.type, n.created, n.changed, n.uid, n.static, n.created, u.name FROM {node} n LEFT JOIN {term_node} r ON n.nid = r.nid LEFT JOIN {users} u ON n.uid = u.uid WHERE r.tid IN ($taxonomy->str_tids) AND n.status = '1' ORDER BY static DESC, created DESC";
$sql_count = "SELECT COUNT(DISTINCT(n.nid)) FROM node n LEFT JOIN term_node r ON n.nid = r.nid LEFT JOIN users u ON n.uid = u.uid WHERE r.tid IN ($taxonomy->str_tids) AND n.status = '1'"; $sql_count = "SELECT COUNT(DISTINCT(n.nid)) FROM {node} n LEFT JOIN {term_node} r ON n.nid = r.nid LEFT JOIN {users} u ON n.uid = u.uid WHERE r.tid IN ($taxonomy->str_tids) AND n.status = '1'";
} }
else { else {
$sql = "SELECT n.nid, n.title, n.type, n.created, n.changed, n.uid, u.name FROM node n LEFT JOIN term_node r ON n.nid = r.nid LEFT JOIN users u ON n.uid = u.uid WHERE r.tid IN ($taxonomy->str_tids) AND n.status = '1' GROUP BY n.nid, n.title, n.type, n.created, n.changed, n.uid, u.name HAVING COUNT(n.nid) = ".count($taxonomy->tids)." ORDER BY static DESC, created DESC"; $sql = "SELECT n.nid, n.title, n.type, n.created, n.changed, n.uid, u.name FROM {node} n LEFT JOIN {term_node} r ON n.nid = r.nid LEFT JOIN {users} u ON n.uid = u.uid WHERE r.tid IN ($taxonomy->str_tids) AND n.status = '1' GROUP BY n.nid, n.title, n.type, n.created, n.changed, n.uid, u.name HAVING COUNT(n.nid) = ".count($taxonomy->tids)." ORDER BY static DESC, created DESC";
// Special trick as we could not find anything better: // Special trick as we could not find anything better:
$count = db_num_rows(db_query("SELECT n.nid FROM node n LEFT JOIN term_node r ON n.nid = r.nid WHERE r.tid IN ($taxonomy->str_tids) AND n.status = '1' GROUP BY n.nid HAVING COUNT(n.nid) = ". count($taxonomy->tids))); $count = db_num_rows(db_query("SELECT n.nid FROM {node} n LEFT JOIN {term_node} r ON n.nid = r.nid WHERE r.tid IN ($taxonomy->str_tids) AND n.status = '1' GROUP BY n.nid HAVING COUNT(n.nid) = ". count($taxonomy->tids)));
$sql_count = "SELECT $count"; $sql_count = "SELECT $count";
} }

View File

@ -99,7 +99,7 @@ function taxonomy_save_vocabulary($edit) {
$data = array("name" => $edit["name"], "nodes" => implode(",", $edit["nodes"]), "description" => $edit["description"], "multiple" => $edit["multiple"], "required" => $edit["required"], "hierarchy" => $edit["hierarchy"], "relations" => $edit["relations"], "weight" => $edit["weight"]); $data = array("name" => $edit["name"], "nodes" => implode(",", $edit["nodes"]), "description" => $edit["description"], "multiple" => $edit["multiple"], "required" => $edit["required"], "hierarchy" => $edit["hierarchy"], "relations" => $edit["relations"], "weight" => $edit["weight"]);
if ($edit["vid"] && $edit["name"]) { if ($edit["vid"] && $edit["name"]) {
db_query("UPDATE vocabulary SET ". _prepare_update($data) ." WHERE vid = %d", $edit["vid"]); db_query("UPDATE {vocabulary} SET ". _prepare_update($data) ." WHERE vid = %d", $edit["vid"]);
module_invoke_all("taxonomy", "update", "vocabulary", $edit); module_invoke_all("taxonomy", "update", "vocabulary", $edit);
$message = t("updated vocabulary '%name'.", array("%name" => $edit["name"])); $message = t("updated vocabulary '%name'.", array("%name" => $edit["name"]));
} }
@ -108,7 +108,7 @@ function taxonomy_save_vocabulary($edit) {
} }
else { else {
$data["vid"] = $edit["vid"] = db_next_id("vocabulary_vid"); $data["vid"] = $edit["vid"] = db_next_id("vocabulary_vid");
db_query("INSERT INTO vocabulary ". _prepare_insert($data, 1) ." VALUES ". _prepare_insert($data, 2)); db_query("INSERT INTO {vocabulary} ". _prepare_insert($data, 1) ." VALUES ". _prepare_insert($data, 2));
module_invoke_all("taxonomy", "insert", "vocabulary", $edit); module_invoke_all("taxonomy", "insert", "vocabulary", $edit);
$message = t("created new vocabulary '%name'.", array("%name" => $edit["name"])); $message = t("created new vocabulary '%name'.", array("%name" => $edit["name"]));
} }
@ -121,8 +121,8 @@ function taxonomy_save_vocabulary($edit) {
function taxonomy_del_vocabulary($vid) { function taxonomy_del_vocabulary($vid) {
$vocabulary = taxonomy_get_vocabulary($vid); $vocabulary = taxonomy_get_vocabulary($vid);
db_query("DELETE FROM vocabulary WHERE vid = %d", $vid); db_query("DELETE FROM {vocabulary} WHERE vid = %d", $vid);
$result = db_query("SELECT tid FROM term_data WHERE vid = %d", $vid); $result = db_query("SELECT tid FROM {term_data} WHERE vid = %d", $vid);
while ($term = db_fetch_object($result)) { while ($term = db_fetch_object($result)) {
taxonomy_del_term($term->tid); taxonomy_del_term($term->tid);
} }
@ -192,7 +192,7 @@ function taxonomy_save_term($edit) {
if ($edit["tid"] && $edit["name"]) { if ($edit["tid"] && $edit["name"]) {
$data = array("name" => $edit["name"], "description" => $edit["description"], "weight" => $edit["weight"]); $data = array("name" => $edit["name"], "description" => $edit["description"], "weight" => $edit["weight"]);
db_query("UPDATE term_data SET ". _prepare_update($data) ." WHERE tid = %d", $edit["tid"]); db_query("UPDATE {term_data} SET ". _prepare_update($data) ." WHERE tid = %d", $edit["tid"]);
module_invoke_all("taxonomy", "update", "term", $edit); module_invoke_all("taxonomy", "update", "term", $edit);
$message = t("the term '%a' has been updated.", array("%a" => $edit["name"])); $message = t("the term '%a' has been updated.", array("%a" => $edit["name"]));
} }
@ -202,40 +202,40 @@ function taxonomy_save_term($edit) {
else { else {
$edit["tid"] = db_next_id("term_data_tid"); $edit["tid"] = db_next_id("term_data_tid");
$data = array("tid" => $edit["tid"], "name" => $edit["name"], "description" => $edit["description"], "vid" => $edit["vid"], "weight" => $edit["weight"]); $data = array("tid" => $edit["tid"], "name" => $edit["name"], "description" => $edit["description"], "vid" => $edit["vid"], "weight" => $edit["weight"]);
db_query("INSERT INTO term_data ". _prepare_insert($data, 1) ." VALUES ". _prepare_insert($data, 2)); db_query("INSERT INTO {term_data} ". _prepare_insert($data, 1) ." VALUES ". _prepare_insert($data, 2));
module_invoke_all("taxonomy", "insert", "term", $edit); module_invoke_all("taxonomy", "insert", "term", $edit);
$message = t("created new term '%name'.", array("%name" => $edit["name"])); $message = t("created new term '%name'.", array("%name" => $edit["name"]));
} }
// relations (seem very powerful, but I have to understand it completely) // relations (seem very powerful, but I have to understand it completely)
db_query("DELETE FROM term_relation WHERE tid1 = %d OR tid2 = %d", $edit["tid"], $edit["tid"]); db_query("DELETE FROM {term_relation} WHERE tid1 = %d OR tid2 = %d", $edit["tid"], $edit["tid"]);
if ($edit["relations"]) { if ($edit["relations"]) {
foreach ($edit["relations"] as $related_id) { foreach ($edit["relations"] as $related_id) {
if ($related_id != 0) { if ($related_id != 0) {
db_query("INSERT INTO term_relation (tid1, tid2) VALUES (%d, %d)", $edit["tid"], $related_id); db_query("INSERT INTO {term_relation} (tid1, tid2) VALUES (%d, %d)", $edit["tid"], $related_id);
} }
} }
} }
// hierarchy // hierarchy
db_query("DELETE FROM term_hierarchy WHERE tid = %d", $edit["tid"]); db_query("DELETE FROM {term_hierarchy} WHERE tid = %d", $edit["tid"]);
if (!isset($edit["parent"])) { if (!isset($edit["parent"])) {
$edit["parent"] = 0; $edit["parent"] = 0;
} }
if (is_array($edit["parent"])) { if (is_array($edit["parent"])) {
foreach ($edit["parent"] as $parent) { foreach ($edit["parent"] as $parent) {
db_query("INSERT INTO term_hierarchy (tid, parent) VALUES (%d, %d)", $edit["tid"], $parent); db_query("INSERT INTO {term_hierarchy} (tid, parent) VALUES (%d, %d)", $edit["tid"], $parent);
} }
} }
else { else {
db_query("INSERT INTO term_hierarchy (tid, parent) VALUES (%d, %d)", $edit["tid"], $edit["parent"][0]); db_query("INSERT INTO {term_hierarchy} (tid, parent) VALUES (%d, %d)", $edit["tid"], $edit["parent"][0]);
} }
db_query("DELETE FROM term_synonym WHERE tid = %d", $edit["tid"]); db_query("DELETE FROM {term_synonym} WHERE tid = %d", $edit["tid"]);
if ($edit["synonyms"]) { if ($edit["synonyms"]) {
foreach (explode ("\n", str_replace("\r", "", $edit["synonyms"])) as $synonym) { foreach (explode ("\n", str_replace("\r", "", $edit["synonyms"])) as $synonym) {
if ($synonym) { if ($synonym) {
db_query("INSERT INTO term_synonym (tid, name) VALUES (%d, '%s')", $edit["tid"], chop($synonym)); db_query("INSERT INTO {term_synonym} (tid, name) VALUES (%d, '%s')", $edit["tid"], chop($synonym));
} }
} }
} }
@ -248,11 +248,11 @@ function taxonomy_save_term($edit) {
function taxonomy_del_term($tid) { function taxonomy_del_term($tid) {
$term = taxonomy_get_term($tid); $term = taxonomy_get_term($tid);
db_query("DELETE FROM term_data WHERE tid = %d", $tid); db_query("DELETE FROM {term_data} WHERE tid = %d", $tid);
db_query("DELETE FROM term_hierarchy WHERE tid = %d", $tid); db_query("DELETE FROM {term_hierarchy} WHERE tid = %d", $tid);
db_query("DELETE FROM term_relation WHERE tid1 = %d OR tid2 = %d", $tid, $tid); db_query("DELETE FROM {term_relation} WHERE tid1 = %d OR tid2 = %d", $tid, $tid);
db_query("DELETE FROM term_synonym WHERE tid = %d", $tid); db_query("DELETE FROM {term_synonym} WHERE tid = %d", $tid);
db_query("DELETE FROM term_node WHERE tid = %d", $tid); db_query("DELETE FROM {term_node} WHERE tid = %d", $tid);
module_invoke_all("taxonomy", "delete", "term", $term); module_invoke_all("taxonomy", "delete", "term", $term);
@ -327,10 +327,10 @@ function taxonomy_form($vocabulary_id, $value = 0) {
// return array of vocabularies, as objects // return array of vocabularies, as objects
function taxonomy_get_vocabularies($type = '', $key = "vid") { function taxonomy_get_vocabularies($type = '', $key = "vid") {
if ($type) { if ($type) {
$result = db_query("SELECT * FROM vocabulary WHERE nodes LIKE '%%%s%%' ORDER BY weight, name", $type); $result = db_query("SELECT * FROM {vocabulary} WHERE nodes LIKE '%%%s%%' ORDER BY weight, name", $type);
} }
else { else {
$result = db_query("SELECT * FROM vocabulary ORDER BY weight, name"); $result = db_query("SELECT * FROM {vocabulary} ORDER BY weight, name");
} }
$vocabularies = array(); $vocabularies = array();
while ($voc = db_fetch_object($result)) { while ($voc = db_fetch_object($result)) {
@ -354,7 +354,7 @@ function taxonomy_node_form($type, $node = '') {
$terms = $node->taxonomy; $terms = $node->taxonomy;
} }
$c = db_query("SELECT * FROM vocabulary WHERE nodes LIKE '%%%s%%' ORDER BY weight, name", $type); $c = db_query("SELECT * FROM {vocabulary} WHERE nodes LIKE '%%%s%%' ORDER BY weight, name", $type);
while ($vocabulary = db_fetch_object($c)) { while ($vocabulary = db_fetch_object($c)) {
$result[] .= taxonomy_form($vocabulary->vid, $terms); $result[] .= taxonomy_form($vocabulary->vid, $terms);
} }
@ -363,14 +363,14 @@ function taxonomy_node_form($type, $node = '') {
// return 1 if node identified by $nid contains a taxonomy term identified by $tid in his body or title // return 1 if node identified by $nid contains a taxonomy term identified by $tid in his body or title
function taxonomy_node_has_term($nid, $tid) { function taxonomy_node_has_term($nid, $tid) {
$term_name = db_result(db_query("SELECT name FROM term_data WHERE tid = %d", $tid)); $term_name = db_result(db_query("SELECT name FROM {term_data} WHERE tid = %d", $tid));
return db_result(db_query("SELECT COUNT(n.nid) FROM node n WHERE n.nid = %d AND ((n.body LIKE '%%%s%%') OR (n.body LIKE '%%%s%%'))", $nid, $term_name, $term_name)); return db_result(db_query("SELECT COUNT(n.nid) FROM {node} n WHERE n.nid = %d AND ((n.body LIKE '%%%s%%') OR (n.body LIKE '%%%s%%'))", $nid, $term_name, $term_name));
} }
// return array of terms of a node beloging to a particular vocabulary identified by $vid // return array of terms of a node beloging to a particular vocabulary identified by $vid
function taxonomy_node_get_terms_by_vocabulary($nid, $vid, $key = "tid") { function taxonomy_node_get_terms_by_vocabulary($nid, $vid, $key = "tid") {
$result = db_query("SELECT t.* FROM term_data t, term_node r WHERE t.tid = r.tid AND t.vid = %d AND r.nid = %d ORDER BY weight", $vid, $nid); $result = db_query("SELECT t.* FROM {term_data} t, {term_node} r WHERE t.tid = r.tid AND t.vid = %d AND r.nid = %d ORDER BY weight", $vid, $nid);
$terms = array(); $terms = array();
while ($term = db_fetch_object($result)) { while ($term = db_fetch_object($result)) {
$terms[$term->$key] = $term; $terms[$term->$key] = $term;
@ -383,7 +383,7 @@ function taxonomy_node_get_terms($nid, $key = "tid") {
static $terms; static $terms;
if (!isset($terms[$nid])) { if (!isset($terms[$nid])) {
$result = db_query("SELECT t.* FROM term_data t, term_node r WHERE r.tid = t.tid AND r.nid = %d ORDER BY weight, name", $nid); $result = db_query("SELECT t.* FROM {term_data} t, {term_node} r WHERE r.tid = t.tid AND r.nid = %d ORDER BY weight, name", $nid);
$terms[$nid] = array(); $terms[$nid] = array();
while ($term = db_fetch_object($result)) { while ($term = db_fetch_object($result)) {
$terms[$nid][$term->$key] = $term; $terms[$nid][$term->$key] = $term;
@ -398,20 +398,20 @@ function taxonomy_node_save($nid, $terms) {
if ($terms) { if ($terms) {
foreach ($terms as $term) { foreach ($terms as $term) {
db_query("INSERT INTO term_node (nid, tid) VALUES (%d, %d)", $nid, $term); db_query("INSERT INTO {term_node} (nid, tid) VALUES (%d, %d)", $nid, $term);
} }
} }
} }
// clean up terms // clean up terms
function taxonomy_node_delete($nid) { function taxonomy_node_delete($nid) {
db_query("DELETE FROM term_node WHERE nid = %d", $nid); db_query("DELETE FROM {term_node} WHERE nid = %d", $nid);
} }
// relations: return array of related terms // relations: return array of related terms
function taxonomy_get_related($tid, $key = "tid") { function taxonomy_get_related($tid, $key = "tid") {
if ($tid) { if ($tid) {
$result = db_query("SELECT t.*, tid1, tid2 FROM term_relation, term_data t WHERE (t.tid = tid1 OR t.tid = tid2) AND (tid1 = %d OR tid2 = %d) AND t.tid != %d ORDER BY weight, name", $tid, $tid, $tid); $result = db_query("SELECT t.*, tid1, tid2 FROM {term_relation} , {term_data} t WHERE (t.tid = tid1 OR t.tid = tid2) AND (tid1 = %d OR tid2 = %d) AND t.tid != %d ORDER BY weight, name", $tid, $tid, $tid);
$related = array(); $related = array();
while ($term = db_fetch_object($result)) { while ($term = db_fetch_object($result)) {
$related[$term->$key] = $term; $related[$term->$key] = $term;
@ -426,7 +426,7 @@ function taxonomy_get_related($tid, $key = "tid") {
// hierarchy: get parent terms // hierarchy: get parent terms
function taxonomy_get_parents($tid, $key = "tid") { function taxonomy_get_parents($tid, $key = "tid") {
if ($tid) { if ($tid) {
$result = db_query("SELECT t.* FROM term_hierarchy h, term_data t WHERE h.parent = t.tid AND h.tid = %d ORDER BY weight, name", $tid); $result = db_query("SELECT t.* FROM {term_hierarchy} h, {term_data} t WHERE h.parent = t.tid AND h.tid = %d ORDER BY weight, name", $tid);
$parents = array(); $parents = array();
while ($parent = db_fetch_object($result)) { while ($parent = db_fetch_object($result)) {
$parents[$parent->$key] = $parent; $parents[$parent->$key] = $parent;
@ -441,10 +441,10 @@ function taxonomy_get_parents($tid, $key = "tid") {
// hierarchy: get children // hierarchy: get children
function taxonomy_get_children($tid, $vid = 0, $key = "tid") { function taxonomy_get_children($tid, $vid = 0, $key = "tid") {
if ($vid) { if ($vid) {
$result = db_query("SELECT t.* FROM term_hierarchy h, term_data t WHERE t.vid = %d AND h.tid = t.tid AND h.parent = %d ORDER BY weight, name", $vid, $tid); $result = db_query("SELECT t.* FROM {term_hierarchy} h, {term_data} t WHERE t.vid = %d AND h.tid = t.tid AND h.parent = %d ORDER BY weight, name", $vid, $tid);
} }
else { else {
$result = db_query("SELECT t.* FROM term_hierarchy h, term_data t WHERE h.tid = t.tid AND parent = %d ORDER BY weight", $tid); $result = db_query("SELECT t.* FROM {term_hierarchy} h, {term_data} t WHERE h.tid = t.tid AND parent = %d ORDER BY weight", $tid);
} }
$children = array(); $children = array();
while ($term = db_fetch_object($result)) { while ($term = db_fetch_object($result)) {
@ -463,7 +463,7 @@ function taxonomy_get_tree($vocabulary_id, $parent = 0, $depth = -1, $key = "tid
if (!isset($children[$vocabulary_id])) { if (!isset($children[$vocabulary_id])) {
$children[$vocabulary_id] = array(); $children[$vocabulary_id] = array();
$result = db_query("SELECT t.*, parent FROM term_data t, term_hierarchy h WHERE t.tid = h.tid AND t.vid = %d ORDER BY weight, name", $vocabulary_id); $result = db_query("SELECT t.*, parent FROM {term_data} t, {term_hierarchy} h WHERE t.tid = h.tid AND t.vid = %d ORDER BY weight, name", $vocabulary_id);
while ($term = db_fetch_object($result)) { while ($term = db_fetch_object($result)) {
$children[$vocabulary_id][$term->parent][] = $term->tid; $children[$vocabulary_id][$term->parent][] = $term->tid;
$parents[$vocabulary_id][$term->tid][] = $term->parent; $parents[$vocabulary_id][$term->tid][] = $term->parent;
@ -488,7 +488,7 @@ function taxonomy_get_tree($vocabulary_id, $parent = 0, $depth = -1, $key = "tid
// synonyms: return array of synonyms // synonyms: return array of synonyms
function taxonomy_get_synonyms($tid) { function taxonomy_get_synonyms($tid) {
if ($tid) { if ($tid) {
$result = db_query("SELECT name FROM term_synonym WHERE tid = %d", $tid); $result = db_query("SELECT name FROM {term_synonym} WHERE tid = %d", $tid);
while ($synonym = db_fetch_array($result)) { while ($synonym = db_fetch_array($result)) {
$synonyms[] = $synonym["name"]; $synonyms[] = $synonym["name"];
} }
@ -501,7 +501,7 @@ function taxonomy_get_synonyms($tid) {
// synonyms: return original term // synonyms: return original term
function taxonomy_get_synonym_root($term) { function taxonomy_get_synonym_root($term) {
return db_fetch_object(db_query("SELECT * FROM term_synonym s, term_data t WHERE t.tid = s.tid AND s.name = '%s'", $term)); return db_fetch_object(db_query("SELECT * FROM {term_synonym} s, {term_data} t WHERE t.tid = s.tid AND s.name = '%s'", $term));
} }
// given a term id, count number of published nodes in it // given a term id, count number of published nodes in it
@ -511,10 +511,10 @@ function taxonomy_term_count_nodes($tid, $type = 0) {
if (!isset($count[$type])) { if (!isset($count[$type])) {
// $type == 0 always evaluates true is $type is a string // $type == 0 always evaluates true is $type is a string
if (is_numeric($type)) { if (is_numeric($type)) {
$result = db_query("SELECT t.tid, COUNT(*) AS c FROM term_node t LEFT JOIN node n ON t.nid = n.nid WHERE n.status = 1 GROUP BY t.tid"); $result = db_query("SELECT t.tid, COUNT(*) AS c FROM {term_node} t LEFT JOIN {node} n ON t.nid = n.nid WHERE n.status = 1 GROUP BY t.tid");
} }
else { else {
$result = db_query("SELECT t.tid, COUNT(*) AS c FROM term_node t, node n WHERE t.nid = n.nid AND n.status = 1 AND n.type = '%s' GROUP BY t.tid", $type); $result = db_query("SELECT t.tid, COUNT(*) AS c FROM {term_node} t, {node} n WHERE t.nid = n.nid AND n.status = 1 AND n.type = '%s' GROUP BY t.tid", $type);
} }
while ($term = db_fetch_object($result)) { while ($term = db_fetch_object($result)) {
$count[$type][$term->tid] = $term->c; $count[$type][$term->tid] = $term->c;
@ -532,7 +532,7 @@ function _taxonomy_term_children($tid) {
static $children; static $children;
if (!isset($children)) { if (!isset($children)) {
$result = db_query("SELECT tid, parent FROM term_hierarchy"); $result = db_query("SELECT tid, parent FROM {term_hierarchy} ");
while ($term = db_fetch_object($result)) { while ($term = db_fetch_object($result)) {
$children[$term->parent][] = $term->tid; $children[$term->parent][] = $term->tid;
} }
@ -550,7 +550,7 @@ function _taxonomy_term_children($tid) {
*/ */
function taxonomy_get_vocabulary_by_name($name) { function taxonomy_get_vocabulary_by_name($name) {
// LOWER is ANSI SQL-92 // LOWER is ANSI SQL-92
$db_result = db_query("SELECT * FROM vocabulary WHERE LOWER('%s') LIKE LOWER(name)", trim($name)); $db_result = db_query("SELECT * FROM {vocabulary} WHERE LOWER('%s') LIKE LOWER(name)", trim($name));
$result = array(); $result = array();
while ($vocabulary = db_fetch_object($db_result)) { while ($vocabulary = db_fetch_object($db_result)) {
$result[] = $vocabulary; $result[] = $vocabulary;
@ -569,7 +569,7 @@ function taxonomy_get_vocabulary_by_name($name) {
*/ */
function taxonomy_get_term_by_name($name) { function taxonomy_get_term_by_name($name) {
// LOWER is ANSI SQL-92 // LOWER is ANSI SQL-92
$db_result = db_query("SELECT * FROM term_data WHERE LOWER('%s') LIKE LOWER(name)", trim($name)); $db_result = db_query("SELECT * FROM {term_data} WHERE LOWER('%s') LIKE LOWER(name)", trim($name));
$result = array(); $result = array();
while ($term = db_fetch_object($db_result)) { while ($term = db_fetch_object($db_result)) {
$result[] = $term; $result[] = $term;
@ -580,12 +580,12 @@ function taxonomy_get_term_by_name($name) {
function taxonomy_get_vocabulary($vid) { function taxonomy_get_vocabulary($vid) {
// simple cache using a static var? // simple cache using a static var?
return db_fetch_object(db_query("SELECT * FROM vocabulary WHERE vid = %d", $vid)); return db_fetch_object(db_query("SELECT * FROM {vocabulary} WHERE vid = %d", $vid));
} }
function taxonomy_get_term($tid) { function taxonomy_get_term($tid) {
// simple cache using a static var? // simple cache using a static var?
return db_fetch_object(db_query("SELECT * FROM term_data WHERE tid = %d", $tid)); return db_fetch_object(db_query("SELECT * FROM {term_data} WHERE tid = %d", $tid));
} }
/* /*
@ -660,14 +660,14 @@ function taxonomy_select_nodes($taxonomy, $pager = 1) {
if ($taxonomy->str_tids) { if ($taxonomy->str_tids) {
if ($taxonomy->operator == "or") { if ($taxonomy->operator == "or") {
$sql = "SELECT DISTINCT(n.nid), n.title, n.type, n.created, n.changed, n.uid, n.static, n.created, u.name FROM node n LEFT JOIN term_node r ON n.nid = r.nid LEFT JOIN users u ON n.uid = u.uid WHERE r.tid IN ($taxonomy->str_tids) AND n.status = '1' ORDER BY static DESC, created DESC"; $sql = "SELECT DISTINCT(n.nid), n.title, n.type, n.created, n.changed, n.uid, n.static, n.created, u.name FROM {node} n LEFT JOIN {term_node} r ON n.nid = r.nid LEFT JOIN {users} u ON n.uid = u.uid WHERE r.tid IN ($taxonomy->str_tids) AND n.status = '1' ORDER BY static DESC, created DESC";
$sql_count = "SELECT COUNT(DISTINCT(n.nid)) FROM node n LEFT JOIN term_node r ON n.nid = r.nid LEFT JOIN users u ON n.uid = u.uid WHERE r.tid IN ($taxonomy->str_tids) AND n.status = '1'"; $sql_count = "SELECT COUNT(DISTINCT(n.nid)) FROM {node} n LEFT JOIN {term_node} r ON n.nid = r.nid LEFT JOIN {users} u ON n.uid = u.uid WHERE r.tid IN ($taxonomy->str_tids) AND n.status = '1'";
} }
else { else {
$sql = "SELECT n.nid, n.title, n.type, n.created, n.changed, n.uid, u.name FROM node n LEFT JOIN term_node r ON n.nid = r.nid LEFT JOIN users u ON n.uid = u.uid WHERE r.tid IN ($taxonomy->str_tids) AND n.status = '1' GROUP BY n.nid, n.title, n.type, n.created, n.changed, n.uid, u.name HAVING COUNT(n.nid) = ".count($taxonomy->tids)." ORDER BY static DESC, created DESC"; $sql = "SELECT n.nid, n.title, n.type, n.created, n.changed, n.uid, u.name FROM {node} n LEFT JOIN {term_node} r ON n.nid = r.nid LEFT JOIN {users} u ON n.uid = u.uid WHERE r.tid IN ($taxonomy->str_tids) AND n.status = '1' GROUP BY n.nid, n.title, n.type, n.created, n.changed, n.uid, u.name HAVING COUNT(n.nid) = ".count($taxonomy->tids)." ORDER BY static DESC, created DESC";
// Special trick as we could not find anything better: // Special trick as we could not find anything better:
$count = db_num_rows(db_query("SELECT n.nid FROM node n LEFT JOIN term_node r ON n.nid = r.nid WHERE r.tid IN ($taxonomy->str_tids) AND n.status = '1' GROUP BY n.nid HAVING COUNT(n.nid) = ". count($taxonomy->tids))); $count = db_num_rows(db_query("SELECT n.nid FROM {node} n LEFT JOIN {term_node} r ON n.nid = r.nid WHERE r.tid IN ($taxonomy->str_tids) AND n.status = '1' GROUP BY n.nid HAVING COUNT(n.nid) = ". count($taxonomy->tids)));
$sql_count = "SELECT $count"; $sql_count = "SELECT $count";
} }

View File

@ -10,10 +10,10 @@ function title_page() {
if (user_access("access content")) { if (user_access("access content")) {
$title = urldecode(arg(1)); $title = urldecode(arg(1));
$result = db_query("SELECT n.*, u.name, u.uid FROM node n LEFT JOIN users u ON n.uid = u.uid WHERE n.title = '%s' AND n.status = 1 ORDER BY created DESC", $title); $result = db_query("SELECT n.*, u.name, u.uid FROM {node} n LEFT JOIN {users} u ON n.uid = u.uid WHERE n.title = '%s' AND n.status = 1 ORDER BY created DESC", $title);
if (db_num_rows($result) == 0) { if (db_num_rows($result) == 0) {
// No node with exact title found, try substring. // No node with exact title found, try substring.
$result = db_query("SELECT n.* FROM node n WHERE n.title LIKE '%". check_query($title). "%' AND n.status = 1 ORDER BY created DESC"); $result = db_query("SELECT n.* FROM {node} n WHERE n.title LIKE '%". check_query($title). "%' AND n.status = 1 ORDER BY created DESC");
} }
if (db_num_rows($result) == 0 && module_exist("search")) { if (db_num_rows($result) == 0 && module_exist("search")) {
// still no matches ... return a full text search // still no matches ... return a full text search

View File

@ -25,20 +25,20 @@ function tracker_link($type) {
function tracker_posts($id = 0) { function tracker_posts($id = 0) {
if ($id) { if ($id) {
$sresult = pager_query("SELECT n.nid, n.title, n.type, n.changed, n.uid, u.name, MAX(GREATEST(n.changed, c.timestamp)) AS last_activity FROM node n LEFT JOIN comments c ON n.nid = c.nid LEFT JOIN users u ON n.uid = u.uid WHERE n.uid = '". check_query($id) ."' AND n.status = 1 GROUP BY n.nid, n.title, n.type, n.changed, n.uid, u.name ORDER BY last_activity DESC", 10, 0, "SELECT COUNT(nid) FROM node WHERE status = 1 AND uid = '". check_query($id) ."'"); $sresult = pager_query("SELECT n.nid, n.title, n.type, n.changed, n.uid, u.name, MAX(GREATEST(n.changed, c.timestamp)) AS last_activity FROM {node} n LEFT JOIN {comments} c ON n.nid = c.nid LEFT JOIN {users} u ON n.uid = u.uid WHERE n.uid = '". check_query($id) ."' AND n.status = 1 GROUP BY n.nid, n.title, n.type, n.changed, n.uid, u.name ORDER BY last_activity DESC", 10, 0, "SELECT COUNT(nid) FROM {node} WHERE status = 1 AND uid = '". check_query($id) ."'");
} }
else { else {
$sresult = pager_query("SELECT n.nid, n.title, n.type, n.changed, n.uid, u.name, MAX(GREATEST(n.changed, c.timestamp)) AS last_activity FROM node n LEFT JOIN comments c ON n.nid = c.nid LEFT JOIN users u ON n.uid = u.uid WHERE n.status = 1 GROUP BY n.nid, n.title, n.type, n.changed, n.uid, u.name ORDER BY last_activity DESC", 10, 0, "SELECT COUNT(nid) FROM node WHERE status = 1"); $sresult = pager_query("SELECT n.nid, n.title, n.type, n.changed, n.uid, u.name, MAX(GREATEST(n.changed, c.timestamp)) AS last_activity FROM {node} n LEFT JOIN {comments} c ON n.nid = c.nid LEFT JOIN {users} u ON n.uid = u.uid WHERE n.status = 1 GROUP BY n.nid, n.title, n.type, n.changed, n.uid, u.name ORDER BY last_activity DESC", 10, 0, "SELECT COUNT(nid) FROM {node} WHERE status = 1");
} }
$header = array(t("Type"), t("Title"), t("Author")); $header = array(t("Type"), t("Title"), t("Author"));
while ($node = db_fetch_object($sresult)) { while ($node = db_fetch_object($sresult)) {
if ($id) { if ($id) {
$cresult = db_query("SELECT c.*, u.name FROM comments c LEFT JOIN users u ON c.uid = u.uid WHERE c.uid = %d AND c.nid = %d AND c.status = 0 ORDER BY cid DESC", $id, $node->nid); $cresult = db_query("SELECT c.*, u.name FROM {comments} c LEFT JOIN {users} u ON c.uid = u.uid WHERE c.uid = %d AND c.nid = %d AND c.status = 0 ORDER BY cid DESC", $id, $node->nid);
} }
else { else {
$cresult = db_query("SELECT c.*, u.name FROM comments c LEFT JOIN users u ON c.uid = u.uid WHERE c.nid = %d AND c.status = 0 ORDER BY cid DESC", $node->nid); $cresult = db_query("SELECT c.*, u.name FROM {comments} c LEFT JOIN {users} u ON c.uid = u.uid WHERE c.nid = %d AND c.status = 0 ORDER BY cid DESC", $node->nid);
} }
$type = ucfirst(module_invoke($node->type, "node", "name")); $type = ucfirst(module_invoke($node->type, "node", "name"));

View File

@ -25,20 +25,20 @@ function tracker_link($type) {
function tracker_posts($id = 0) { function tracker_posts($id = 0) {
if ($id) { if ($id) {
$sresult = pager_query("SELECT n.nid, n.title, n.type, n.changed, n.uid, u.name, MAX(GREATEST(n.changed, c.timestamp)) AS last_activity FROM node n LEFT JOIN comments c ON n.nid = c.nid LEFT JOIN users u ON n.uid = u.uid WHERE n.uid = '". check_query($id) ."' AND n.status = 1 GROUP BY n.nid, n.title, n.type, n.changed, n.uid, u.name ORDER BY last_activity DESC", 10, 0, "SELECT COUNT(nid) FROM node WHERE status = 1 AND uid = '". check_query($id) ."'"); $sresult = pager_query("SELECT n.nid, n.title, n.type, n.changed, n.uid, u.name, MAX(GREATEST(n.changed, c.timestamp)) AS last_activity FROM {node} n LEFT JOIN {comments} c ON n.nid = c.nid LEFT JOIN {users} u ON n.uid = u.uid WHERE n.uid = '". check_query($id) ."' AND n.status = 1 GROUP BY n.nid, n.title, n.type, n.changed, n.uid, u.name ORDER BY last_activity DESC", 10, 0, "SELECT COUNT(nid) FROM {node} WHERE status = 1 AND uid = '". check_query($id) ."'");
} }
else { else {
$sresult = pager_query("SELECT n.nid, n.title, n.type, n.changed, n.uid, u.name, MAX(GREATEST(n.changed, c.timestamp)) AS last_activity FROM node n LEFT JOIN comments c ON n.nid = c.nid LEFT JOIN users u ON n.uid = u.uid WHERE n.status = 1 GROUP BY n.nid, n.title, n.type, n.changed, n.uid, u.name ORDER BY last_activity DESC", 10, 0, "SELECT COUNT(nid) FROM node WHERE status = 1"); $sresult = pager_query("SELECT n.nid, n.title, n.type, n.changed, n.uid, u.name, MAX(GREATEST(n.changed, c.timestamp)) AS last_activity FROM {node} n LEFT JOIN {comments} c ON n.nid = c.nid LEFT JOIN {users} u ON n.uid = u.uid WHERE n.status = 1 GROUP BY n.nid, n.title, n.type, n.changed, n.uid, u.name ORDER BY last_activity DESC", 10, 0, "SELECT COUNT(nid) FROM {node} WHERE status = 1");
} }
$header = array(t("Type"), t("Title"), t("Author")); $header = array(t("Type"), t("Title"), t("Author"));
while ($node = db_fetch_object($sresult)) { while ($node = db_fetch_object($sresult)) {
if ($id) { if ($id) {
$cresult = db_query("SELECT c.*, u.name FROM comments c LEFT JOIN users u ON c.uid = u.uid WHERE c.uid = %d AND c.nid = %d AND c.status = 0 ORDER BY cid DESC", $id, $node->nid); $cresult = db_query("SELECT c.*, u.name FROM {comments} c LEFT JOIN {users} u ON c.uid = u.uid WHERE c.uid = %d AND c.nid = %d AND c.status = 0 ORDER BY cid DESC", $id, $node->nid);
} }
else { else {
$cresult = db_query("SELECT c.*, u.name FROM comments c LEFT JOIN users u ON c.uid = u.uid WHERE c.nid = %d AND c.status = 0 ORDER BY cid DESC", $node->nid); $cresult = db_query("SELECT c.*, u.name FROM {comments} c LEFT JOIN {users} u ON c.uid = u.uid WHERE c.nid = %d AND c.status = 0 ORDER BY cid DESC", $node->nid);
} }
$type = ucfirst(module_invoke($node->type, "node", "name")); $type = ucfirst(module_invoke($node->type, "node", "name"));

View File

@ -29,14 +29,14 @@ function sess_read($key) {
function sess_write($key, $value) { function sess_write($key, $value) {
db_query("UPDATE users SET hostname = '%s', session = '%s', timestamp = %d WHERE sid = '$key'", $_SERVER["REMOTE_ADDR"], $value, time()); db_query("UPDATE {users} SET hostname = '%s', session = '%s', timestamp = %d WHERE sid = '$key'", $_SERVER["REMOTE_ADDR"], $value, time());
return ''; return '';
} }
function sess_destroy($key) { function sess_destroy($key) {
db_query("UPDATE users SET hostname = '%s', timestamp = %d, sid = '' WHERE sid = '$key'", $_SERVER["REMOTE_ADDR"], time()); db_query("UPDATE {users} SET hostname = '%s', timestamp = %d, sid = '' WHERE sid = '$key'", $_SERVER["REMOTE_ADDR"], time());
} }
function sess_gc($lifetime) { function sess_gc($lifetime) {
@ -46,7 +46,7 @@ function sess_gc($lifetime) {
/*** Common functions ******************************************************/ /*** Common functions ******************************************************/
function user_external_load($authname) { function user_external_load($authname) {
$arr_uid = db_query("SELECT uid FROM authmap WHERE authname = '%s'", $authname); $arr_uid = db_query("SELECT uid FROM {authmap} WHERE authname = '%s'", $authname);
if (db_fetch_object($arr_uid)) { if (db_fetch_object($arr_uid)) {
$uid = db_result($arr_uid); $uid = db_result($arr_uid);
@ -73,7 +73,7 @@ function user_load($array = array()) {
$query .= "u.$key = '". check_query($value) ."' AND "; $query .= "u.$key = '". check_query($value) ."' AND ";
} }
} }
$result = db_query_range("SELECT u.*, r.name AS role FROM role r INNER JOIN users u ON r.rid = u.rid WHERE $query u.status < 3", 0, 1); $result = db_query_range("SELECT u.*, r.name AS role FROM {role} r INNER JOIN {users} u ON r.rid = u.rid WHERE $query u.status < 3", 0, 1);
$user = db_fetch_object($result); $user = db_fetch_object($result);
if ($user->data && $data = unserialize($user->data)) { if ($user->data && $data = unserialize($user->data)) {
@ -94,7 +94,7 @@ function user_save($account, $array = array()) {
$user_fields = user_fields(); $user_fields = user_fields();
if ($account->uid) { if ($account->uid) {
$data = unserialize(db_result(db_query("SELECT data FROM users WHERE uid = %d", $account->uid))); $data = unserialize(db_result(db_query("SELECT data FROM {users} WHERE uid = %d", $account->uid)));
foreach ($array as $key => $value) { foreach ($array as $key => $value) {
if ($key == "pass") { if ($key == "pass") {
$query .= "$key = '". md5($value) ."', "; $query .= "$key = '". md5($value) ."', ";
@ -112,7 +112,7 @@ function user_save($account, $array = array()) {
} }
$query .= "data = '". check_query(serialize($data)) ."', "; $query .= "data = '". check_query(serialize($data)) ."', ";
db_query("UPDATE users SET $query timestamp = %d WHERE uid = %d", time(), $account->uid); db_query("UPDATE {users} SET $query timestamp = %d WHERE uid = %d", time(), $account->uid);
$user = user_load(array("uid" => $account->uid)); $user = user_load(array("uid" => $account->uid));
} }
@ -138,7 +138,7 @@ function user_save($account, $array = array()) {
$fields[] = "data"; $fields[] = "data";
$values[] = "'". check_query(serialize($data)) ."'"; $values[] = "'". check_query(serialize($data)) ."'";
db_query("INSERT INTO users (". implode(", ", $fields) .") VALUES (". implode(", ", $values) .")"); db_query("INSERT INTO {users} (". implode(", ", $fields) .") VALUES (". implode(", ", $values) .")");
$user = user_load(array("name" => $array["name"])); $user = user_load(array("name" => $array["name"]));
} }
@ -188,7 +188,7 @@ function user_validate_mail($mail) {
} }
function user_validate_authmap($account, $authname, $module) { function user_validate_authmap($account, $authname, $module) {
$result = db_query("SELECT COUNT(*) from authmap WHERE uid != %d AND authname = '%s'", $account->uid, $authname); $result = db_query("SELECT COUNT(*) from {authmap} WHERE uid != %d AND authname = '%s'", $account->uid, $authname);
if (db_result($result) > 0) { if (db_result($result) > 0) {
$name = module_invoke($module, "info", "name"); $name = module_invoke($module, "info", "name");
return t("The %u ID %s is already taken.", array("%u" => ucfirst($name), "%s" => "<i>$authname</i>")); return t("The %u ID %s is already taken.", array("%u" => ucfirst($name), "%s" => "<i>$authname</i>"));
@ -242,10 +242,10 @@ function user_access($string) {
if (!$perm) { if (!$perm) {
if ($user->uid) { if ($user->uid) {
$perm = db_result(db_query("SELECT p.perm FROM role r, permission p WHERE r.rid = p.rid AND name = '%s'", $user->role), 0); $perm = db_result(db_query("SELECT p.perm FROM {role} r, {permission} p WHERE r.rid = p.rid AND name = '%s'", $user->role), 0);
} }
else { else {
$perm = db_result(db_query("SELECT p.perm FROM role r, permission p WHERE r.rid = p.rid AND name = 'anonymous user'"), 0); $perm = db_result(db_query("SELECT p.perm FROM {role} r, {permission} p WHERE r.rid = p.rid AND name = 'anonymous user'"), 0);
} }
} }
@ -284,9 +284,9 @@ function user_mail($mail, $subject, $message, $header) {
function user_deny($type, $mask) { function user_deny($type, $mask) {
$allow = db_fetch_object(db_query("SELECT * FROM access WHERE status = '1' AND type = '%s' AND LOWER('%s') LIKE LOWER(mask)", $type, $mask)); $allow = db_fetch_object(db_query("SELECT * FROM {access} WHERE status = '1' AND type = '%s' AND LOWER('%s') LIKE LOWER(mask)", $type, $mask));
$deny = db_fetch_object(db_query("SELECT * FROM access WHERE status = '0' AND type = '%s' AND LOWER('%s') LIKE LOWER(mask)", $type, $mask)); $deny = db_fetch_object(db_query("SELECT * FROM {access} WHERE status = '0' AND type = '%s' AND LOWER('%s') LIKE LOWER(mask)", $type, $mask));
if ($deny && !$allow) { if ($deny && !$allow) {
return 1; return 1;
@ -300,7 +300,7 @@ function user_fields() {
static $fields; static $fields;
if (!$fields) { if (!$fields) {
$result = db_query("SELECT * FROM users WHERE uid = 1"); $result = db_query("SELECT * FROM {users} WHERE uid = 1");
if (db_num_rows($result)) { if (db_num_rows($result)) {
$fields = array_keys(db_fetch_array($result)); $fields = array_keys(db_fetch_array($result));
} }
@ -318,7 +318,7 @@ function user_perm() {
function user_search($keys) { function user_search($keys) {
$result = db_query_range("SELECT * FROM users WHERE name LIKE '%$keys%'", 0, 20); $result = db_query_range("SELECT * FROM {users} WHERE name LIKE '%$keys%'", 0, 20);
while ($account = db_fetch_object($result)) { while ($account = db_fetch_object($result)) {
$find[$i++] = array("title" => $account->name, "link" => (strstr(request_uri(), "admin") ? url("admin/user/edit/$account->uid") : url("user/view/$account->uid")), "user" => $account->name); $find[$i++] = array("title" => $account->name, "link" => (strstr(request_uri(), "admin") ? url("admin/user/edit/$account->uid") : url("user/view/$account->uid")), "user" => $account->name);
} }
@ -388,7 +388,7 @@ function user_block($op = "list", $delta = 0) {
$output .= theme("theme_item_list", $items); $output .= theme("theme_item_list", $items);
$block["subject"] = t("User login"); $block["subject"] = t("User login");
$block["content"] = $output; $block["content"] = "<div class=\"user-login-link\">$output</div>";
return $block; return $block;
} }
break; break;
@ -402,12 +402,12 @@ function user_block($op = "list", $delta = 0) {
$output .= "</div>\n"; $output .= "</div>\n";
$block["subject"] = $user->name; $block["subject"] = $user->name;
$block["content"] = $output; $block["content"] = "<div class=\"user-login-link\">$output</div>";
return $block; return $block;
} }
break; break;
case 2: case 2:
$result = db_query_range("SELECT uid, name FROM users WHERE status != '0' ORDER BY uid DESC", 0, 5); $result = db_query_range("SELECT uid, name FROM {users} WHERE status != '0' ORDER BY uid DESC", 0, 5);
while ($account = db_fetch_object($result)) { while ($account = db_fetch_object($result)) {
$items[] = l((strlen($account->name) > 15 ? substr($account->name, 0, 15) . '...' : $account->name), "user/view/$account->uid"); $items[] = l((strlen($account->name) > 15 ? substr($account->name, 0, 15) . '...' : $account->name), "user/view/$account->uid");
} }
@ -497,7 +497,7 @@ function user_get_authname($account, $module) {
** Called by authentication modules in order to edit/view their authmap information. ** Called by authentication modules in order to edit/view their authmap information.
*/ */
$result = db_query("SELECT authname FROM authmap WHERE uid = %d AND module = '%s'", $account->uid, $module); $result = db_query("SELECT authname FROM {authmap} WHERE uid = %d AND module = '%s'", $account->uid, $module);
return db_result($result); return db_result($result);
} }
@ -509,7 +509,7 @@ function user_get_authmaps($authname = NULL) {
** associtive array of modules and DA names. Called at external login. ** associtive array of modules and DA names. Called at external login.
*/ */
$result = db_query("SELECT authname, module FROM authmap WHERE authname = '%s'", $authname); $result = db_query("SELECT authname, module FROM {authmap} WHERE authname = '%s'", $authname);
if (db_num_rows($result) > 0) { if (db_num_rows($result) > 0) {
while ($authmap = db_fetch_object($result)) { while ($authmap = db_fetch_object($result)) {
$authmaps[$authmap->module] = $authmap->authname; $authmaps[$authmap->module] = $authmap->authname;
@ -525,16 +525,16 @@ function user_set_authmaps($account, $authmaps) {
foreach ($authmaps as $key => $value) { foreach ($authmaps as $key => $value) {
$module = explode("_", $key, 2); $module = explode("_", $key, 2);
if ($value) { if ($value) {
$result = db_query("SELECT COUNT(*) from authmap WHERE uid = %d AND module = '%s'", $account->uid, $module["1"]); $result = db_query("SELECT COUNT(*) from {authmap} WHERE uid = %d AND module = '%s'", $account->uid, $module["1"]);
if (db_result($result) == 0) { if (db_result($result) == 0) {
$result = db_query("INSERT INTO authmap (authname, uid, module) VALUES ('%s', %d, '%s')", $value, $account->uid, $module[1]); $result = db_query("INSERT INTO {authmap} (authname, uid, module) VALUES ('%s', %d, '%s')", $value, $account->uid, $module[1]);
} }
else { else {
$result = db_query("UPDATE authmap SET authname = '%s' WHERE uid = %d AND module = '%s'", $value, $account->uid, $module["1"]); $result = db_query("UPDATE {authmap} SET authname = '%s' WHERE uid = %d AND module = '%s'", $value, $account->uid, $module["1"]);
} }
} }
else { else {
$result = db_query("DELETE FROM authmap WHERE uid = %d AND module = '%s'", $account->uid, $module["1"]); $result = db_query("DELETE FROM {authmap} WHERE uid = %d AND module = '%s'", $account->uid, $module["1"]);
} }
} }
return $result; return $result;
@ -705,7 +705,7 @@ function user_login($edit = array(), $msg = "") {
} }
function _user_authenticated_id() { function _user_authenticated_id() {
return db_result(db_query("SELECT rid FROM role WHERE name = 'authenticated user'")); return db_result(db_query("SELECT rid FROM {role} WHERE name = 'authenticated user'"));
} }
function user_logout() { function user_logout() {
@ -735,11 +735,11 @@ function user_pass($edit = array()) {
global $base_url; global $base_url;
if ($edit["name"]) { if ($edit["name"]) {
$account = db_fetch_object(db_query("SELECT uid, name, mail FROM users WHERE name = '%s'", $edit["name"])); $account = db_fetch_object(db_query("SELECT uid, name, mail FROM {users} WHERE name = '%s'", $edit["name"]));
if (!$account) $error = t("Sorry. The username <i>%s</i> is not recognized.", array("%s" => $edit["name"])); if (!$account) $error = t("Sorry. The username <i>%s</i> is not recognized.", array("%s" => $edit["name"]));
} }
else if ($edit["mail"]) { else if ($edit["mail"]) {
$account = db_fetch_object(db_query("SELECT uid, name, mail FROM users WHERE mail = '%s'", $edit["mail"])); $account = db_fetch_object(db_query("SELECT uid, name, mail FROM {users} WHERE mail = '%s'", $edit["mail"]));
if (!$account) $error = t("Sorry. The e-mail address <i>%s</i> is not recognized.", array("%s" => $edit["mail"])); if (!$account) $error = t("Sorry. The e-mail address <i>%s</i> is not recognized.", array("%s" => $edit["mail"]));
} }
if ($account) { if ($account) {
@ -822,10 +822,10 @@ function user_register($edit = array()) {
else if (user_deny("mail", $edit["mail"])) { else if (user_deny("mail", $edit["mail"])) {
$error = t("The e-mail address '%s' has been denied access.", array("%s" => $edit["mail"])); $error = t("The e-mail address '%s' has been denied access.", array("%s" => $edit["mail"]));
} }
else if (db_num_rows(db_query("SELECT name FROM users WHERE LOWER(name) = LOWER('%s')", $edit["name"])) > 0) { else if (db_num_rows(db_query("SELECT name FROM {users} WHERE LOWER(name) = LOWER('%s')", $edit["name"])) > 0) {
$error = t("The name '%s' is already taken.", array("%s" => $edit["name"])); $error = t("The name '%s' is already taken.", array("%s" => $edit["name"]));
} }
else if (db_num_rows(db_query("SELECT mail FROM users WHERE LOWER(mail) = LOWER('%s') OR LOWER(init) = LOWER('%s')", $edit["mail"], $edit["mail"])) > 0) { else if (db_num_rows(db_query("SELECT mail FROM {users} WHERE LOWER(mail) = LOWER('%s') OR LOWER(init) = LOWER('%s')", $edit["mail"], $edit["mail"])) > 0) {
$error = t("The e-mail address '%s' is already taken.", array("%s" => $edit["mail"])); $error = t("The e-mail address '%s' is already taken.", array("%s" => $edit["mail"]));
} }
else if (variable_get("user_register", 1) == 0) { else if (variable_get("user_register", 1) == 0) {
@ -934,7 +934,7 @@ function user_delete() {
if ($edit["confirm"]) { if ($edit["confirm"]) {
watchdog("user","$user->name deactivated her own account."); watchdog("user","$user->name deactivated her own account.");
db_query("UPDATE users SET mail = 'deleted', status = '0' WHERE uid = %d", $user->uid); db_query("UPDATE {users} SET mail = 'deleted', status = '0' WHERE uid = %d", $user->uid);
$output .= t("Your account has been deactivated."); $output .= t("Your account has been deactivated.");
} }
else { else {
@ -957,10 +957,10 @@ function user_edit($edit = array()) {
else if ($error = user_validate_mail($edit["mail"])) { else if ($error = user_validate_mail($edit["mail"])) {
// do nothing // do nothing
} }
else if (db_num_rows(db_query("SELECT uid FROM users WHERE uid != '$user->uid' AND LOWER(name) = LOWER('%s')", $edit["name"])) > 0) { else if (db_num_rows(db_query("SELECT uid FROM {users} WHERE uid != '$user->uid' AND LOWER(name) = LOWER('%s')", $edit["name"])) > 0) {
$error = t("The name '%s' is already taken.", array("%s" => $edit["name"])); $error = t("The name '%s' is already taken.", array("%s" => $edit["name"]));
} }
else if ($edit["mail"] && db_num_rows(db_query("SELECT uid FROM users WHERE uid != '$user->uid' AND LOWER(mail) = LOWER('%s')", $edit["mail"])) > 0) { else if ($edit["mail"] && db_num_rows(db_query("SELECT uid FROM {users} WHERE uid != '$user->uid' AND LOWER(mail) = LOWER('%s')", $edit["mail"])) > 0) {
$error = t("The e-mail address '%s' is already taken.", array("%s" => $edit["mail"])); $error = t("The e-mail address '%s' is already taken.", array("%s" => $edit["mail"]));
} }
else if ($user->uid) { else if ($user->uid) {
@ -1244,10 +1244,10 @@ function user_admin_create($edit = array()) {
else if ($error = user_validate_mail($edit["mail"])) { else if ($error = user_validate_mail($edit["mail"])) {
// do nothing // do nothing
} }
else if (db_num_rows(db_query("SELECT name FROM users WHERE LOWER(name) = LOWER('%s')", $edit["name"])) > 0) { else if (db_num_rows(db_query("SELECT name FROM {users} WHERE LOWER(name) = LOWER('%s')", $edit["name"])) > 0) {
$error = t("The name '%s' is already taken.", array("%s" => $edit["name"])); $error = t("The name '%s' is already taken.", array("%s" => $edit["name"]));
} }
else if (db_num_rows(db_query("SELECT mail FROM users WHERE LOWER(mail) = LOWER('%s')", $edit["mail"])) > 0) { else if (db_num_rows(db_query("SELECT mail FROM {users} WHERE LOWER(mail) = LOWER('%s')", $edit["mail"])) > 0) {
$error = t("The e-mail address '%s' is already taken.", array("%s" => $edit["mail"])); $error = t("The e-mail address '%s' is already taken.", array("%s" => $edit["mail"]));
} }
else { else {
@ -1296,7 +1296,7 @@ function user_admin_access($edit = array()) {
} }
if ($op == t("Add rule")) { if ($op == t("Add rule")) {
db_query("INSERT INTO access (mask, type, status) VALUES ('%s', '%s', %d)", $edit["mask"], $type, $edit["status"]); db_query("INSERT INTO {access} (mask, type, status) VALUES ('%s', '%s', %d)", $edit["mask"], $type, $edit["status"]);
} }
else if ($op == t("Check")) { else if ($op == t("Check")) {
if (user_deny($type, $edit["test"])) { if (user_deny($type, $edit["test"])) {
@ -1307,18 +1307,18 @@ function user_admin_access($edit = array()) {
} }
} }
else if ($id) { else if ($id) {
db_query("DELETE FROM access WHERE aid = %d", $id); db_query("DELETE FROM {access} WHERE aid = %d", $id);
} }
$header = array(t("type"), t("mask"), t("operations")); $header = array(t("type"), t("mask"), t("operations"));
$result = db_query("SELECT * FROM access WHERE type = '%s' AND status = '1' ORDER BY mask", $type); $result = db_query("SELECT * FROM {access} WHERE type = '%s' AND status = '1' ORDER BY mask", $type);
while ($rule = db_fetch_object($result)) { while ($rule = db_fetch_object($result)) {
$rows[] = array(t("Allow"), $rule->mask, array("data" => l(t("delete rule"), "admin/user/access/$type/$rule->aid"), "align" => "center")); $rows[] = array(t("Allow"), $rule->mask, array("data" => l(t("delete rule"), "admin/user/access/$type/$rule->aid"), "align" => "center"));
} }
$result = db_query("SELECT * FROM access WHERE type = '%s' AND status = '0' ORDER BY mask", $type); $result = db_query("SELECT * FROM {access} WHERE type = '%s' AND status = '0' ORDER BY mask", $type);
while ($rule = db_fetch_object($result)) { while ($rule = db_fetch_object($result)) {
$rows[] = array(t("Deny"), $rule->mask, l(t("delete rule"), "admin/user/access/$type/$rule->aid")); $rows[] = array(t("Deny"), $rule->mask, l(t("delete rule"), "admin/user/access/$type/$rule->aid"));
@ -1343,7 +1343,7 @@ function user_admin_access($edit = array()) {
} }
function user_roles($membersonly = 0) { function user_roles($membersonly = 0) {
$result = db_query("SELECT * FROM role ORDER BY name"); $result = db_query("SELECT * FROM {role} ORDER BY name");
while ($role = db_fetch_object($result)) { while ($role = db_fetch_object($result)) {
if (!$membersonly || ($membersonly && $role->name != "anonymous user")) { if (!$membersonly || ($membersonly && $role->name != "anonymous user")) {
$roles[$role->rid] = $role->name; $roles[$role->rid] = $role->name;
@ -1360,14 +1360,14 @@ function user_admin_perm($edit = array()) {
** Save permissions: ** Save permissions:
*/ */
$result = db_query("SELECT * FROM role"); $result = db_query("SELECT * FROM {role} ");
while ($role = db_fetch_object($result)) { while ($role = db_fetch_object($result)) {
// delete, so if we clear every checkbox we reset that role; // delete, so if we clear every checkbox we reset that role;
// otherwise permissions are active and denied everywhere // otherwise permissions are active and denied everywhere
db_query("DELETE FROM permission WHERE rid = %d", $role->rid); db_query("DELETE FROM {permission} WHERE rid = %d", $role->rid);
$perm = $edit[$role->rid] ? implode(", ", array_keys($edit[$role->rid])) : ""; $perm = $edit[$role->rid] ? implode(", ", array_keys($edit[$role->rid])) : "";
if ($perm) { if ($perm) {
db_query("INSERT INTO permission (rid, perm) VALUES (%d, '%s')", $role->rid, $perm); db_query("INSERT INTO {permission} (rid, perm) VALUES (%d, '%s')", $role->rid, $perm);
} }
} }
@ -1388,13 +1388,13 @@ function user_admin_perm($edit = array()) {
** Compile role array: ** Compile role array:
*/ */
$result = db_query("SELECT r.rid, p.perm FROM role r LEFT JOIN permission p ON r.rid = p.rid ORDER BY name"); $result = db_query("SELECT r.rid, p.perm FROM {role} r LEFT JOIN {permission} p ON r.rid = p.rid ORDER BY name");
$roles = array(); $roles = array();
while ($role = db_fetch_object($result)) { while ($role = db_fetch_object($result)) {
$role_perms[$role->rid] = $role->perm; $role_perms[$role->rid] = $role->perm;
} }
$result = db_query("SELECT rid, name FROM role ORDER BY name"); $result = db_query("SELECT rid, name FROM {role} ORDER BY name");
$role_names = array(); $role_names = array();
while ($role = db_fetch_object($result)) { while ($role = db_fetch_object($result)) {
$role_names[$role->rid] = $role->name; $role_names[$role->rid] = $role->name;
@ -1427,21 +1427,21 @@ function user_admin_role($edit = array()) {
$id = arg(3); $id = arg(3);
if ($op == t("Save role")) { if ($op == t("Save role")) {
db_query("UPDATE role SET name = '%s' WHERE rid = %d", $edit["name"], $id); db_query("UPDATE {role} SET name = '%s' WHERE rid = %d", $edit["name"], $id);
} }
else if ($op == t("Delete role")) { else if ($op == t("Delete role")) {
db_query("DELETE FROM role WHERE rid = %d", $id); db_query("DELETE FROM {role} WHERE rid = %d", $id);
db_query("DELETE FROM permission WHERE rid = %d", $id); db_query("DELETE FROM {permission} WHERE rid = %d", $id);
} }
else if ($op == t("Add role")) { else if ($op == t("Add role")) {
db_query("INSERT INTO role (name) VALUES ('%s')", $edit["name"]); db_query("INSERT INTO {role} (name) VALUES ('%s')", $edit["name"]);
} }
else if ($id) { else if ($id) {
/* /*
** Display role form: ** Display role form:
*/ */
$role = db_fetch_object(db_query("SELECT * FROM role WHERE rid = %d", $id)); $role = db_fetch_object(db_query("SELECT * FROM {role} WHERE rid = %d", $id));
$output .= form_textfield(t("Role name"), "name", $role->name, 32, 64, t("The name for this role. Example: 'moderator', 'editorial board', 'site architect'.")); $output .= form_textfield(t("Role name"), "name", $role->name, 32, 64, t("The name for this role. Example: 'moderator', 'editorial board', 'site architect'."));
$output .= form_submit(t("Save role")); $output .= form_submit(t("Save role"));
@ -1455,7 +1455,7 @@ function user_admin_role($edit = array()) {
** Render role overview: ** Render role overview:
*/ */
$result = db_query("SELECT * FROM role ORDER BY name"); $result = db_query("SELECT * FROM {role} ORDER BY name");
$header = array(t("name"), t("operations")); $header = array(t("name"), t("operations"));
while ($role = db_fetch_object($result)) { while ($role = db_fetch_object($result)) {
@ -1503,10 +1503,10 @@ function user_admin_edit($edit = array()) {
else if ($error = user_validate_mail($edit["mail"])) { else if ($error = user_validate_mail($edit["mail"])) {
// do nothing // do nothing
} }
else if (db_num_rows(db_query("SELECT uid FROM users WHERE uid != %d AND LOWER(name) = LOWER('%s')", $account->uid, $edit["name"])) > 0) { else if (db_num_rows(db_query("SELECT uid FROM {users} WHERE uid != %d AND LOWER(name) = LOWER('%s')", $account->uid, $edit["name"])) > 0) {
$error = t("The name '%s' is already taken.", array("%s" => $edit["name"])); $error = t("The name '%s' is already taken.", array("%s" => $edit["name"]));
} }
else if ($edit["mail"] && db_num_rows(db_query("SELECT uid FROM users WHERE uid != %d AND LOWER(mail) = LOWER('%s')", $account->uid, $edit["mail"])) > 0) { else if ($edit["mail"] && db_num_rows(db_query("SELECT uid FROM {users} WHERE uid != %d AND LOWER(mail) = LOWER('%s')", $account->uid, $edit["mail"])) > 0) {
$error = t("The e-mail address '%s' is already taken.", array("%s" => $edit["mail"])); $error = t("The e-mail address '%s' is already taken.", array("%s" => $edit["mail"]));
} }
@ -1535,8 +1535,8 @@ function user_admin_edit($edit = array()) {
} }
else if ($op == t("Delete account")) { else if ($op == t("Delete account")) {
if ($edit["status"] == 0) { if ($edit["status"] == 0) {
db_query("DELETE FROM users WHERE uid = %d", $account->uid); db_query("DELETE FROM {users} WHERE uid = %d", $account->uid);
db_query("DELETE FROM authmap WHERE uid = %d", $account->uid); db_query("DELETE FROM {authmap} WHERE uid = %d", $account->uid);
$output .= t("The account has been deleted."); $output .= t("The account has been deleted.");
} }
else { else {
@ -1591,7 +1591,7 @@ function user_admin_account() {
$queries[] = "WHERE r.name = '$value' ORDER BY u.uid DESC"; $queries[] = "WHERE r.name = '$value' ORDER BY u.uid DESC";
} }
$result = pager_query("SELECT u.uid, u.name, u.timestamp FROM role r INNER JOIN users u ON r.rid = u.rid ". $queries[$query ? $query : 0], 50); $result = pager_query("SELECT u.uid, u.name, u.timestamp FROM {role} r INNER JOIN users u ON r.rid = u.rid ". $queries[$query ? $query : 0], 50);
$header = array(t("username"), t("last access"), t("operations")); $header = array(t("username"), t("last access"), t("operations"));
while ($account = db_fetch_object($result)) { while ($account = db_fetch_object($result)) {
@ -1606,14 +1606,14 @@ function user_admin_account() {
} }
function user_role_init() { function user_role_init() {
$role = db_fetch_object(db_query("SELECT * FROM role WHERE name = 'anonymous user'")); $role = db_fetch_object(db_query("SELECT * FROM {role} WHERE name = 'anonymous user'"));
if (!$role) { if (!$role) {
db_query("INSERT INTO role (name) VALUES ('anonymous user')"); db_query("INSERT INTO {role} (name) VALUES ('anonymous user')");
} }
$role = db_fetch_object(db_query("SELECT * FROM role WHERE name = 'authenticated user'")); $role = db_fetch_object(db_query("SELECT * FROM {role} WHERE name = 'authenticated user'"));
if (!$role) { if (!$role) {
db_query("INSERT INTO role (name) VALUES ('authenticated user')"); db_query("INSERT INTO {role} (name) VALUES ('authenticated user')");
} }
} }

View File

@ -29,14 +29,14 @@ function sess_read($key) {
function sess_write($key, $value) { function sess_write($key, $value) {
db_query("UPDATE users SET hostname = '%s', session = '%s', timestamp = %d WHERE sid = '$key'", $_SERVER["REMOTE_ADDR"], $value, time()); db_query("UPDATE {users} SET hostname = '%s', session = '%s', timestamp = %d WHERE sid = '$key'", $_SERVER["REMOTE_ADDR"], $value, time());
return ''; return '';
} }
function sess_destroy($key) { function sess_destroy($key) {
db_query("UPDATE users SET hostname = '%s', timestamp = %d, sid = '' WHERE sid = '$key'", $_SERVER["REMOTE_ADDR"], time()); db_query("UPDATE {users} SET hostname = '%s', timestamp = %d, sid = '' WHERE sid = '$key'", $_SERVER["REMOTE_ADDR"], time());
} }
function sess_gc($lifetime) { function sess_gc($lifetime) {
@ -46,7 +46,7 @@ function sess_gc($lifetime) {
/*** Common functions ******************************************************/ /*** Common functions ******************************************************/
function user_external_load($authname) { function user_external_load($authname) {
$arr_uid = db_query("SELECT uid FROM authmap WHERE authname = '%s'", $authname); $arr_uid = db_query("SELECT uid FROM {authmap} WHERE authname = '%s'", $authname);
if (db_fetch_object($arr_uid)) { if (db_fetch_object($arr_uid)) {
$uid = db_result($arr_uid); $uid = db_result($arr_uid);
@ -73,7 +73,7 @@ function user_load($array = array()) {
$query .= "u.$key = '". check_query($value) ."' AND "; $query .= "u.$key = '". check_query($value) ."' AND ";
} }
} }
$result = db_query_range("SELECT u.*, r.name AS role FROM role r INNER JOIN users u ON r.rid = u.rid WHERE $query u.status < 3", 0, 1); $result = db_query_range("SELECT u.*, r.name AS role FROM {role} r INNER JOIN {users} u ON r.rid = u.rid WHERE $query u.status < 3", 0, 1);
$user = db_fetch_object($result); $user = db_fetch_object($result);
if ($user->data && $data = unserialize($user->data)) { if ($user->data && $data = unserialize($user->data)) {
@ -94,7 +94,7 @@ function user_save($account, $array = array()) {
$user_fields = user_fields(); $user_fields = user_fields();
if ($account->uid) { if ($account->uid) {
$data = unserialize(db_result(db_query("SELECT data FROM users WHERE uid = %d", $account->uid))); $data = unserialize(db_result(db_query("SELECT data FROM {users} WHERE uid = %d", $account->uid)));
foreach ($array as $key => $value) { foreach ($array as $key => $value) {
if ($key == "pass") { if ($key == "pass") {
$query .= "$key = '". md5($value) ."', "; $query .= "$key = '". md5($value) ."', ";
@ -112,7 +112,7 @@ function user_save($account, $array = array()) {
} }
$query .= "data = '". check_query(serialize($data)) ."', "; $query .= "data = '". check_query(serialize($data)) ."', ";
db_query("UPDATE users SET $query timestamp = %d WHERE uid = %d", time(), $account->uid); db_query("UPDATE {users} SET $query timestamp = %d WHERE uid = %d", time(), $account->uid);
$user = user_load(array("uid" => $account->uid)); $user = user_load(array("uid" => $account->uid));
} }
@ -138,7 +138,7 @@ function user_save($account, $array = array()) {
$fields[] = "data"; $fields[] = "data";
$values[] = "'". check_query(serialize($data)) ."'"; $values[] = "'". check_query(serialize($data)) ."'";
db_query("INSERT INTO users (". implode(", ", $fields) .") VALUES (". implode(", ", $values) .")"); db_query("INSERT INTO {users} (". implode(", ", $fields) .") VALUES (". implode(", ", $values) .")");
$user = user_load(array("name" => $array["name"])); $user = user_load(array("name" => $array["name"]));
} }
@ -188,7 +188,7 @@ function user_validate_mail($mail) {
} }
function user_validate_authmap($account, $authname, $module) { function user_validate_authmap($account, $authname, $module) {
$result = db_query("SELECT COUNT(*) from authmap WHERE uid != %d AND authname = '%s'", $account->uid, $authname); $result = db_query("SELECT COUNT(*) from {authmap} WHERE uid != %d AND authname = '%s'", $account->uid, $authname);
if (db_result($result) > 0) { if (db_result($result) > 0) {
$name = module_invoke($module, "info", "name"); $name = module_invoke($module, "info", "name");
return t("The %u ID %s is already taken.", array("%u" => ucfirst($name), "%s" => "<i>$authname</i>")); return t("The %u ID %s is already taken.", array("%u" => ucfirst($name), "%s" => "<i>$authname</i>"));
@ -242,10 +242,10 @@ function user_access($string) {
if (!$perm) { if (!$perm) {
if ($user->uid) { if ($user->uid) {
$perm = db_result(db_query("SELECT p.perm FROM role r, permission p WHERE r.rid = p.rid AND name = '%s'", $user->role), 0); $perm = db_result(db_query("SELECT p.perm FROM {role} r, {permission} p WHERE r.rid = p.rid AND name = '%s'", $user->role), 0);
} }
else { else {
$perm = db_result(db_query("SELECT p.perm FROM role r, permission p WHERE r.rid = p.rid AND name = 'anonymous user'"), 0); $perm = db_result(db_query("SELECT p.perm FROM {role} r, {permission} p WHERE r.rid = p.rid AND name = 'anonymous user'"), 0);
} }
} }
@ -284,9 +284,9 @@ function user_mail($mail, $subject, $message, $header) {
function user_deny($type, $mask) { function user_deny($type, $mask) {
$allow = db_fetch_object(db_query("SELECT * FROM access WHERE status = '1' AND type = '%s' AND LOWER('%s') LIKE LOWER(mask)", $type, $mask)); $allow = db_fetch_object(db_query("SELECT * FROM {access} WHERE status = '1' AND type = '%s' AND LOWER('%s') LIKE LOWER(mask)", $type, $mask));
$deny = db_fetch_object(db_query("SELECT * FROM access WHERE status = '0' AND type = '%s' AND LOWER('%s') LIKE LOWER(mask)", $type, $mask)); $deny = db_fetch_object(db_query("SELECT * FROM {access} WHERE status = '0' AND type = '%s' AND LOWER('%s') LIKE LOWER(mask)", $type, $mask));
if ($deny && !$allow) { if ($deny && !$allow) {
return 1; return 1;
@ -300,7 +300,7 @@ function user_fields() {
static $fields; static $fields;
if (!$fields) { if (!$fields) {
$result = db_query("SELECT * FROM users WHERE uid = 1"); $result = db_query("SELECT * FROM {users} WHERE uid = 1");
if (db_num_rows($result)) { if (db_num_rows($result)) {
$fields = array_keys(db_fetch_array($result)); $fields = array_keys(db_fetch_array($result));
} }
@ -318,7 +318,7 @@ function user_perm() {
function user_search($keys) { function user_search($keys) {
$result = db_query_range("SELECT * FROM users WHERE name LIKE '%$keys%'", 0, 20); $result = db_query_range("SELECT * FROM {users} WHERE name LIKE '%$keys%'", 0, 20);
while ($account = db_fetch_object($result)) { while ($account = db_fetch_object($result)) {
$find[$i++] = array("title" => $account->name, "link" => (strstr(request_uri(), "admin") ? url("admin/user/edit/$account->uid") : url("user/view/$account->uid")), "user" => $account->name); $find[$i++] = array("title" => $account->name, "link" => (strstr(request_uri(), "admin") ? url("admin/user/edit/$account->uid") : url("user/view/$account->uid")), "user" => $account->name);
} }
@ -388,7 +388,7 @@ function user_block($op = "list", $delta = 0) {
$output .= theme("theme_item_list", $items); $output .= theme("theme_item_list", $items);
$block["subject"] = t("User login"); $block["subject"] = t("User login");
$block["content"] = $output; $block["content"] = "<div class=\"user-login-link\">$output</div>";
return $block; return $block;
} }
break; break;
@ -402,12 +402,12 @@ function user_block($op = "list", $delta = 0) {
$output .= "</div>\n"; $output .= "</div>\n";
$block["subject"] = $user->name; $block["subject"] = $user->name;
$block["content"] = $output; $block["content"] = "<div class=\"user-login-link\">$output</div>";
return $block; return $block;
} }
break; break;
case 2: case 2:
$result = db_query_range("SELECT uid, name FROM users WHERE status != '0' ORDER BY uid DESC", 0, 5); $result = db_query_range("SELECT uid, name FROM {users} WHERE status != '0' ORDER BY uid DESC", 0, 5);
while ($account = db_fetch_object($result)) { while ($account = db_fetch_object($result)) {
$items[] = l((strlen($account->name) > 15 ? substr($account->name, 0, 15) . '...' : $account->name), "user/view/$account->uid"); $items[] = l((strlen($account->name) > 15 ? substr($account->name, 0, 15) . '...' : $account->name), "user/view/$account->uid");
} }
@ -497,7 +497,7 @@ function user_get_authname($account, $module) {
** Called by authentication modules in order to edit/view their authmap information. ** Called by authentication modules in order to edit/view their authmap information.
*/ */
$result = db_query("SELECT authname FROM authmap WHERE uid = %d AND module = '%s'", $account->uid, $module); $result = db_query("SELECT authname FROM {authmap} WHERE uid = %d AND module = '%s'", $account->uid, $module);
return db_result($result); return db_result($result);
} }
@ -509,7 +509,7 @@ function user_get_authmaps($authname = NULL) {
** associtive array of modules and DA names. Called at external login. ** associtive array of modules and DA names. Called at external login.
*/ */
$result = db_query("SELECT authname, module FROM authmap WHERE authname = '%s'", $authname); $result = db_query("SELECT authname, module FROM {authmap} WHERE authname = '%s'", $authname);
if (db_num_rows($result) > 0) { if (db_num_rows($result) > 0) {
while ($authmap = db_fetch_object($result)) { while ($authmap = db_fetch_object($result)) {
$authmaps[$authmap->module] = $authmap->authname; $authmaps[$authmap->module] = $authmap->authname;
@ -525,16 +525,16 @@ function user_set_authmaps($account, $authmaps) {
foreach ($authmaps as $key => $value) { foreach ($authmaps as $key => $value) {
$module = explode("_", $key, 2); $module = explode("_", $key, 2);
if ($value) { if ($value) {
$result = db_query("SELECT COUNT(*) from authmap WHERE uid = %d AND module = '%s'", $account->uid, $module["1"]); $result = db_query("SELECT COUNT(*) from {authmap} WHERE uid = %d AND module = '%s'", $account->uid, $module["1"]);
if (db_result($result) == 0) { if (db_result($result) == 0) {
$result = db_query("INSERT INTO authmap (authname, uid, module) VALUES ('%s', %d, '%s')", $value, $account->uid, $module[1]); $result = db_query("INSERT INTO {authmap} (authname, uid, module) VALUES ('%s', %d, '%s')", $value, $account->uid, $module[1]);
} }
else { else {
$result = db_query("UPDATE authmap SET authname = '%s' WHERE uid = %d AND module = '%s'", $value, $account->uid, $module["1"]); $result = db_query("UPDATE {authmap} SET authname = '%s' WHERE uid = %d AND module = '%s'", $value, $account->uid, $module["1"]);
} }
} }
else { else {
$result = db_query("DELETE FROM authmap WHERE uid = %d AND module = '%s'", $account->uid, $module["1"]); $result = db_query("DELETE FROM {authmap} WHERE uid = %d AND module = '%s'", $account->uid, $module["1"]);
} }
} }
return $result; return $result;
@ -705,7 +705,7 @@ function user_login($edit = array(), $msg = "") {
} }
function _user_authenticated_id() { function _user_authenticated_id() {
return db_result(db_query("SELECT rid FROM role WHERE name = 'authenticated user'")); return db_result(db_query("SELECT rid FROM {role} WHERE name = 'authenticated user'"));
} }
function user_logout() { function user_logout() {
@ -735,11 +735,11 @@ function user_pass($edit = array()) {
global $base_url; global $base_url;
if ($edit["name"]) { if ($edit["name"]) {
$account = db_fetch_object(db_query("SELECT uid, name, mail FROM users WHERE name = '%s'", $edit["name"])); $account = db_fetch_object(db_query("SELECT uid, name, mail FROM {users} WHERE name = '%s'", $edit["name"]));
if (!$account) $error = t("Sorry. The username <i>%s</i> is not recognized.", array("%s" => $edit["name"])); if (!$account) $error = t("Sorry. The username <i>%s</i> is not recognized.", array("%s" => $edit["name"]));
} }
else if ($edit["mail"]) { else if ($edit["mail"]) {
$account = db_fetch_object(db_query("SELECT uid, name, mail FROM users WHERE mail = '%s'", $edit["mail"])); $account = db_fetch_object(db_query("SELECT uid, name, mail FROM {users} WHERE mail = '%s'", $edit["mail"]));
if (!$account) $error = t("Sorry. The e-mail address <i>%s</i> is not recognized.", array("%s" => $edit["mail"])); if (!$account) $error = t("Sorry. The e-mail address <i>%s</i> is not recognized.", array("%s" => $edit["mail"]));
} }
if ($account) { if ($account) {
@ -822,10 +822,10 @@ function user_register($edit = array()) {
else if (user_deny("mail", $edit["mail"])) { else if (user_deny("mail", $edit["mail"])) {
$error = t("The e-mail address '%s' has been denied access.", array("%s" => $edit["mail"])); $error = t("The e-mail address '%s' has been denied access.", array("%s" => $edit["mail"]));
} }
else if (db_num_rows(db_query("SELECT name FROM users WHERE LOWER(name) = LOWER('%s')", $edit["name"])) > 0) { else if (db_num_rows(db_query("SELECT name FROM {users} WHERE LOWER(name) = LOWER('%s')", $edit["name"])) > 0) {
$error = t("The name '%s' is already taken.", array("%s" => $edit["name"])); $error = t("The name '%s' is already taken.", array("%s" => $edit["name"]));
} }
else if (db_num_rows(db_query("SELECT mail FROM users WHERE LOWER(mail) = LOWER('%s') OR LOWER(init) = LOWER('%s')", $edit["mail"], $edit["mail"])) > 0) { else if (db_num_rows(db_query("SELECT mail FROM {users} WHERE LOWER(mail) = LOWER('%s') OR LOWER(init) = LOWER('%s')", $edit["mail"], $edit["mail"])) > 0) {
$error = t("The e-mail address '%s' is already taken.", array("%s" => $edit["mail"])); $error = t("The e-mail address '%s' is already taken.", array("%s" => $edit["mail"]));
} }
else if (variable_get("user_register", 1) == 0) { else if (variable_get("user_register", 1) == 0) {
@ -934,7 +934,7 @@ function user_delete() {
if ($edit["confirm"]) { if ($edit["confirm"]) {
watchdog("user","$user->name deactivated her own account."); watchdog("user","$user->name deactivated her own account.");
db_query("UPDATE users SET mail = 'deleted', status = '0' WHERE uid = %d", $user->uid); db_query("UPDATE {users} SET mail = 'deleted', status = '0' WHERE uid = %d", $user->uid);
$output .= t("Your account has been deactivated."); $output .= t("Your account has been deactivated.");
} }
else { else {
@ -957,10 +957,10 @@ function user_edit($edit = array()) {
else if ($error = user_validate_mail($edit["mail"])) { else if ($error = user_validate_mail($edit["mail"])) {
// do nothing // do nothing
} }
else if (db_num_rows(db_query("SELECT uid FROM users WHERE uid != '$user->uid' AND LOWER(name) = LOWER('%s')", $edit["name"])) > 0) { else if (db_num_rows(db_query("SELECT uid FROM {users} WHERE uid != '$user->uid' AND LOWER(name) = LOWER('%s')", $edit["name"])) > 0) {
$error = t("The name '%s' is already taken.", array("%s" => $edit["name"])); $error = t("The name '%s' is already taken.", array("%s" => $edit["name"]));
} }
else if ($edit["mail"] && db_num_rows(db_query("SELECT uid FROM users WHERE uid != '$user->uid' AND LOWER(mail) = LOWER('%s')", $edit["mail"])) > 0) { else if ($edit["mail"] && db_num_rows(db_query("SELECT uid FROM {users} WHERE uid != '$user->uid' AND LOWER(mail) = LOWER('%s')", $edit["mail"])) > 0) {
$error = t("The e-mail address '%s' is already taken.", array("%s" => $edit["mail"])); $error = t("The e-mail address '%s' is already taken.", array("%s" => $edit["mail"]));
} }
else if ($user->uid) { else if ($user->uid) {
@ -1244,10 +1244,10 @@ function user_admin_create($edit = array()) {
else if ($error = user_validate_mail($edit["mail"])) { else if ($error = user_validate_mail($edit["mail"])) {
// do nothing // do nothing
} }
else if (db_num_rows(db_query("SELECT name FROM users WHERE LOWER(name) = LOWER('%s')", $edit["name"])) > 0) { else if (db_num_rows(db_query("SELECT name FROM {users} WHERE LOWER(name) = LOWER('%s')", $edit["name"])) > 0) {
$error = t("The name '%s' is already taken.", array("%s" => $edit["name"])); $error = t("The name '%s' is already taken.", array("%s" => $edit["name"]));
} }
else if (db_num_rows(db_query("SELECT mail FROM users WHERE LOWER(mail) = LOWER('%s')", $edit["mail"])) > 0) { else if (db_num_rows(db_query("SELECT mail FROM {users} WHERE LOWER(mail) = LOWER('%s')", $edit["mail"])) > 0) {
$error = t("The e-mail address '%s' is already taken.", array("%s" => $edit["mail"])); $error = t("The e-mail address '%s' is already taken.", array("%s" => $edit["mail"]));
} }
else { else {
@ -1296,7 +1296,7 @@ function user_admin_access($edit = array()) {
} }
if ($op == t("Add rule")) { if ($op == t("Add rule")) {
db_query("INSERT INTO access (mask, type, status) VALUES ('%s', '%s', %d)", $edit["mask"], $type, $edit["status"]); db_query("INSERT INTO {access} (mask, type, status) VALUES ('%s', '%s', %d)", $edit["mask"], $type, $edit["status"]);
} }
else if ($op == t("Check")) { else if ($op == t("Check")) {
if (user_deny($type, $edit["test"])) { if (user_deny($type, $edit["test"])) {
@ -1307,18 +1307,18 @@ function user_admin_access($edit = array()) {
} }
} }
else if ($id) { else if ($id) {
db_query("DELETE FROM access WHERE aid = %d", $id); db_query("DELETE FROM {access} WHERE aid = %d", $id);
} }
$header = array(t("type"), t("mask"), t("operations")); $header = array(t("type"), t("mask"), t("operations"));
$result = db_query("SELECT * FROM access WHERE type = '%s' AND status = '1' ORDER BY mask", $type); $result = db_query("SELECT * FROM {access} WHERE type = '%s' AND status = '1' ORDER BY mask", $type);
while ($rule = db_fetch_object($result)) { while ($rule = db_fetch_object($result)) {
$rows[] = array(t("Allow"), $rule->mask, array("data" => l(t("delete rule"), "admin/user/access/$type/$rule->aid"), "align" => "center")); $rows[] = array(t("Allow"), $rule->mask, array("data" => l(t("delete rule"), "admin/user/access/$type/$rule->aid"), "align" => "center"));
} }
$result = db_query("SELECT * FROM access WHERE type = '%s' AND status = '0' ORDER BY mask", $type); $result = db_query("SELECT * FROM {access} WHERE type = '%s' AND status = '0' ORDER BY mask", $type);
while ($rule = db_fetch_object($result)) { while ($rule = db_fetch_object($result)) {
$rows[] = array(t("Deny"), $rule->mask, l(t("delete rule"), "admin/user/access/$type/$rule->aid")); $rows[] = array(t("Deny"), $rule->mask, l(t("delete rule"), "admin/user/access/$type/$rule->aid"));
@ -1343,7 +1343,7 @@ function user_admin_access($edit = array()) {
} }
function user_roles($membersonly = 0) { function user_roles($membersonly = 0) {
$result = db_query("SELECT * FROM role ORDER BY name"); $result = db_query("SELECT * FROM {role} ORDER BY name");
while ($role = db_fetch_object($result)) { while ($role = db_fetch_object($result)) {
if (!$membersonly || ($membersonly && $role->name != "anonymous user")) { if (!$membersonly || ($membersonly && $role->name != "anonymous user")) {
$roles[$role->rid] = $role->name; $roles[$role->rid] = $role->name;
@ -1360,14 +1360,14 @@ function user_admin_perm($edit = array()) {
** Save permissions: ** Save permissions:
*/ */
$result = db_query("SELECT * FROM role"); $result = db_query("SELECT * FROM {role} ");
while ($role = db_fetch_object($result)) { while ($role = db_fetch_object($result)) {
// delete, so if we clear every checkbox we reset that role; // delete, so if we clear every checkbox we reset that role;
// otherwise permissions are active and denied everywhere // otherwise permissions are active and denied everywhere
db_query("DELETE FROM permission WHERE rid = %d", $role->rid); db_query("DELETE FROM {permission} WHERE rid = %d", $role->rid);
$perm = $edit[$role->rid] ? implode(", ", array_keys($edit[$role->rid])) : ""; $perm = $edit[$role->rid] ? implode(", ", array_keys($edit[$role->rid])) : "";
if ($perm) { if ($perm) {
db_query("INSERT INTO permission (rid, perm) VALUES (%d, '%s')", $role->rid, $perm); db_query("INSERT INTO {permission} (rid, perm) VALUES (%d, '%s')", $role->rid, $perm);
} }
} }
@ -1388,13 +1388,13 @@ function user_admin_perm($edit = array()) {
** Compile role array: ** Compile role array:
*/ */
$result = db_query("SELECT r.rid, p.perm FROM role r LEFT JOIN permission p ON r.rid = p.rid ORDER BY name"); $result = db_query("SELECT r.rid, p.perm FROM {role} r LEFT JOIN {permission} p ON r.rid = p.rid ORDER BY name");
$roles = array(); $roles = array();
while ($role = db_fetch_object($result)) { while ($role = db_fetch_object($result)) {
$role_perms[$role->rid] = $role->perm; $role_perms[$role->rid] = $role->perm;
} }
$result = db_query("SELECT rid, name FROM role ORDER BY name"); $result = db_query("SELECT rid, name FROM {role} ORDER BY name");
$role_names = array(); $role_names = array();
while ($role = db_fetch_object($result)) { while ($role = db_fetch_object($result)) {
$role_names[$role->rid] = $role->name; $role_names[$role->rid] = $role->name;
@ -1427,21 +1427,21 @@ function user_admin_role($edit = array()) {
$id = arg(3); $id = arg(3);
if ($op == t("Save role")) { if ($op == t("Save role")) {
db_query("UPDATE role SET name = '%s' WHERE rid = %d", $edit["name"], $id); db_query("UPDATE {role} SET name = '%s' WHERE rid = %d", $edit["name"], $id);
} }
else if ($op == t("Delete role")) { else if ($op == t("Delete role")) {
db_query("DELETE FROM role WHERE rid = %d", $id); db_query("DELETE FROM {role} WHERE rid = %d", $id);
db_query("DELETE FROM permission WHERE rid = %d", $id); db_query("DELETE FROM {permission} WHERE rid = %d", $id);
} }
else if ($op == t("Add role")) { else if ($op == t("Add role")) {
db_query("INSERT INTO role (name) VALUES ('%s')", $edit["name"]); db_query("INSERT INTO {role} (name) VALUES ('%s')", $edit["name"]);
} }
else if ($id) { else if ($id) {
/* /*
** Display role form: ** Display role form:
*/ */
$role = db_fetch_object(db_query("SELECT * FROM role WHERE rid = %d", $id)); $role = db_fetch_object(db_query("SELECT * FROM {role} WHERE rid = %d", $id));
$output .= form_textfield(t("Role name"), "name", $role->name, 32, 64, t("The name for this role. Example: 'moderator', 'editorial board', 'site architect'.")); $output .= form_textfield(t("Role name"), "name", $role->name, 32, 64, t("The name for this role. Example: 'moderator', 'editorial board', 'site architect'."));
$output .= form_submit(t("Save role")); $output .= form_submit(t("Save role"));
@ -1455,7 +1455,7 @@ function user_admin_role($edit = array()) {
** Render role overview: ** Render role overview:
*/ */
$result = db_query("SELECT * FROM role ORDER BY name"); $result = db_query("SELECT * FROM {role} ORDER BY name");
$header = array(t("name"), t("operations")); $header = array(t("name"), t("operations"));
while ($role = db_fetch_object($result)) { while ($role = db_fetch_object($result)) {
@ -1503,10 +1503,10 @@ function user_admin_edit($edit = array()) {
else if ($error = user_validate_mail($edit["mail"])) { else if ($error = user_validate_mail($edit["mail"])) {
// do nothing // do nothing
} }
else if (db_num_rows(db_query("SELECT uid FROM users WHERE uid != %d AND LOWER(name) = LOWER('%s')", $account->uid, $edit["name"])) > 0) { else if (db_num_rows(db_query("SELECT uid FROM {users} WHERE uid != %d AND LOWER(name) = LOWER('%s')", $account->uid, $edit["name"])) > 0) {
$error = t("The name '%s' is already taken.", array("%s" => $edit["name"])); $error = t("The name '%s' is already taken.", array("%s" => $edit["name"]));
} }
else if ($edit["mail"] && db_num_rows(db_query("SELECT uid FROM users WHERE uid != %d AND LOWER(mail) = LOWER('%s')", $account->uid, $edit["mail"])) > 0) { else if ($edit["mail"] && db_num_rows(db_query("SELECT uid FROM {users} WHERE uid != %d AND LOWER(mail) = LOWER('%s')", $account->uid, $edit["mail"])) > 0) {
$error = t("The e-mail address '%s' is already taken.", array("%s" => $edit["mail"])); $error = t("The e-mail address '%s' is already taken.", array("%s" => $edit["mail"]));
} }
@ -1535,8 +1535,8 @@ function user_admin_edit($edit = array()) {
} }
else if ($op == t("Delete account")) { else if ($op == t("Delete account")) {
if ($edit["status"] == 0) { if ($edit["status"] == 0) {
db_query("DELETE FROM users WHERE uid = %d", $account->uid); db_query("DELETE FROM {users} WHERE uid = %d", $account->uid);
db_query("DELETE FROM authmap WHERE uid = %d", $account->uid); db_query("DELETE FROM {authmap} WHERE uid = %d", $account->uid);
$output .= t("The account has been deleted."); $output .= t("The account has been deleted.");
} }
else { else {
@ -1591,7 +1591,7 @@ function user_admin_account() {
$queries[] = "WHERE r.name = '$value' ORDER BY u.uid DESC"; $queries[] = "WHERE r.name = '$value' ORDER BY u.uid DESC";
} }
$result = pager_query("SELECT u.uid, u.name, u.timestamp FROM role r INNER JOIN users u ON r.rid = u.rid ". $queries[$query ? $query : 0], 50); $result = pager_query("SELECT u.uid, u.name, u.timestamp FROM {role} r INNER JOIN users u ON r.rid = u.rid ". $queries[$query ? $query : 0], 50);
$header = array(t("username"), t("last access"), t("operations")); $header = array(t("username"), t("last access"), t("operations"));
while ($account = db_fetch_object($result)) { while ($account = db_fetch_object($result)) {
@ -1606,14 +1606,14 @@ function user_admin_account() {
} }
function user_role_init() { function user_role_init() {
$role = db_fetch_object(db_query("SELECT * FROM role WHERE name = 'anonymous user'")); $role = db_fetch_object(db_query("SELECT * FROM {role} WHERE name = 'anonymous user'"));
if (!$role) { if (!$role) {
db_query("INSERT INTO role (name) VALUES ('anonymous user')"); db_query("INSERT INTO {role} (name) VALUES ('anonymous user')");
} }
$role = db_fetch_object(db_query("SELECT * FROM role WHERE name = 'authenticated user'")); $role = db_fetch_object(db_query("SELECT * FROM {role} WHERE name = 'authenticated user'"));
if (!$role) { if (!$role) {
db_query("INSERT INTO role (name) VALUES ('authenticated user')"); db_query("INSERT INTO {role} (name) VALUES ('authenticated user')");
} }
} }

View File

@ -46,14 +46,14 @@ function watchdog_settings() {
} }
function watchdog_cron() { function watchdog_cron() {
db_query("DELETE FROM watchdog WHERE ". time() ." - timestamp > ". variable_get("watchdog_clear", 604800)); db_query("DELETE FROM {watchdog} WHERE ". time() ." - timestamp > ". variable_get("watchdog_clear", 604800));
} }
function watchdog_overview($type) { function watchdog_overview($type) {
$color = array("user" => "#FFEEAA", "message" => "#FFFFFF", "special" => "#A49FFF", "warning" => "#FFAA22", "httpd" => "#99DD99", "error" => "#EE4C4C"); $color = array("user" => "#FFEEAA", "message" => "#FFFFFF", "special" => "#A49FFF", "warning" => "#FFAA22", "httpd" => "#99DD99", "error" => "#EE4C4C");
$query = array("user" => "WHERE type = 'user'", "regular" => "WHERE type = 'message'", "special" => "WHERE type = 'special'", "warning" => "WHERE type = 'warning'", "error" => "WHERE type = 'error'", "httpd" => "WHERE type = 'httpd'", "actions" => "WHERE link != ''"); $query = array("user" => "WHERE type = 'user'", "regular" => "WHERE type = 'message'", "special" => "WHERE type = 'special'", "warning" => "WHERE type = 'warning'", "error" => "WHERE type = 'error'", "httpd" => "WHERE type = 'httpd'", "actions" => "WHERE link != ''");
$result = pager_query("SELECT w.*, u.name, u.uid FROM watchdog w LEFT JOIN users u ON w.uid = u.uid ". ($type ? $query[$type] : "") ." ORDER BY w.timestamp DESC", 50); $result = pager_query("SELECT w.*, u.name, u.uid FROM {watchdog} w LEFT JOIN {users} u ON w.uid = u.uid ". ($type ? $query[$type] : "") ." ORDER BY w.timestamp DESC", 50);
while ($watchdog = db_fetch_object($result)) { while ($watchdog = db_fetch_object($result)) {
if ($background = $color[$watchdog->type]) { if ($background = $color[$watchdog->type]) {
@ -72,7 +72,7 @@ function watchdog_overview($type) {
function watchdog_view($id) { function watchdog_view($id) {
$result = db_query("SELECT w.*, u.name, u.uid FROM watchdog w LEFT JOIN users u ON w.uid = u.uid WHERE w.wid = %d", $id); $result = db_query("SELECT w.*, u.name, u.uid FROM {watchdog} w LEFT JOIN {users} u ON w.uid = u.uid WHERE w.wid = %d", $id);
if ($watchdog = db_fetch_object($result)) { if ($watchdog = db_fetch_object($result)) {
$output .= "<table border=\"1\" cellpadding=\"2\" cellspacing=\"2\">"; $output .= "<table border=\"1\" cellpadding=\"2\" cellspacing=\"2\">";

View File

@ -46,14 +46,14 @@ function watchdog_settings() {
} }
function watchdog_cron() { function watchdog_cron() {
db_query("DELETE FROM watchdog WHERE ". time() ." - timestamp > ". variable_get("watchdog_clear", 604800)); db_query("DELETE FROM {watchdog} WHERE ". time() ." - timestamp > ". variable_get("watchdog_clear", 604800));
} }
function watchdog_overview($type) { function watchdog_overview($type) {
$color = array("user" => "#FFEEAA", "message" => "#FFFFFF", "special" => "#A49FFF", "warning" => "#FFAA22", "httpd" => "#99DD99", "error" => "#EE4C4C"); $color = array("user" => "#FFEEAA", "message" => "#FFFFFF", "special" => "#A49FFF", "warning" => "#FFAA22", "httpd" => "#99DD99", "error" => "#EE4C4C");
$query = array("user" => "WHERE type = 'user'", "regular" => "WHERE type = 'message'", "special" => "WHERE type = 'special'", "warning" => "WHERE type = 'warning'", "error" => "WHERE type = 'error'", "httpd" => "WHERE type = 'httpd'", "actions" => "WHERE link != ''"); $query = array("user" => "WHERE type = 'user'", "regular" => "WHERE type = 'message'", "special" => "WHERE type = 'special'", "warning" => "WHERE type = 'warning'", "error" => "WHERE type = 'error'", "httpd" => "WHERE type = 'httpd'", "actions" => "WHERE link != ''");
$result = pager_query("SELECT w.*, u.name, u.uid FROM watchdog w LEFT JOIN users u ON w.uid = u.uid ". ($type ? $query[$type] : "") ." ORDER BY w.timestamp DESC", 50); $result = pager_query("SELECT w.*, u.name, u.uid FROM {watchdog} w LEFT JOIN {users} u ON w.uid = u.uid ". ($type ? $query[$type] : "") ." ORDER BY w.timestamp DESC", 50);
while ($watchdog = db_fetch_object($result)) { while ($watchdog = db_fetch_object($result)) {
if ($background = $color[$watchdog->type]) { if ($background = $color[$watchdog->type]) {
@ -72,7 +72,7 @@ function watchdog_overview($type) {
function watchdog_view($id) { function watchdog_view($id) {
$result = db_query("SELECT w.*, u.name, u.uid FROM watchdog w LEFT JOIN users u ON w.uid = u.uid WHERE w.wid = %d", $id); $result = db_query("SELECT w.*, u.name, u.uid FROM {watchdog} w LEFT JOIN {users} u ON w.uid = u.uid WHERE w.wid = %d", $id);
if ($watchdog = db_fetch_object($result)) { if ($watchdog = db_fetch_object($result)) {
$output .= "<table border=\"1\" cellpadding=\"2\" cellspacing=\"2\">"; $output .= "<table border=\"1\" cellpadding=\"2\" cellspacing=\"2\">";