Commit 3c2dc18c authored by Dries's avatar Dries

- Fixed bug #1545: incorrect sequence tables on PostgreSQL.  Patch by Neil.

  In addition, I have updated update.php so it makes the corresponding
  changes for MySQL users.
parent b85cf719
......@@ -92,7 +92,7 @@ function import_bundle_block($attributes) {
}
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));
while ($item = db_fetch_object($result)) {
$output .= import_format_item($item);
......@@ -119,13 +119,13 @@ function import_block($op, $delta) {
list($type, $id) = split(":", $delta);
switch ($type) {
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["content"] .= import_feed_block($feed) ."<div align=\"right\">". l(t("more"), "import/feed/$feed->fid", array("title" => t("View this feed's recent news."))) ."</div>";
break;
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["content"] .= import_bundle_block($bundle->attributes) ."<div align=\"right\">". l(t("more"), "import/bundle/$bundle->bid", array("title" => t("View this bundle's recent news."))) ."</div>";
break;
......@@ -168,7 +168,7 @@ function import_get_feeds($attributes = 0) {
}
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"]));
}
......@@ -270,7 +270,7 @@ function import_refresh($feed) {
$channel[$key] = filter(strtr(trim($value), $tt));
}
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,
......@@ -316,10 +316,10 @@ function import_refresh($feed) {
*/
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 {
$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"]));
......@@ -331,7 +331,7 @@ function import_refresh($feed) {
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)) {
$items[] = "iid = '$item->iid'";
......@@ -351,10 +351,10 @@ function import_refresh($feed) {
function import_save_item($edit) {
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"]) {
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"]) {
db_query("INSERT INTO item (fid, title, link, author, description, attributes, timestamp) VALUES ('%s', '%s', '%s', '%s', '%s', '%s', '%s')", $edit["fid"], $edit["title"], $edit["link"], $edit["author"], $edit["description"], $edit["attributes"], time());
......@@ -378,15 +378,15 @@ function import_form_bundle($edit = array()) {
function import_save_bundle($edit) {
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"]) {
db_query("DELETE FROM bundle WHERE bid = '%d'", $edit["bid"]);
db_query("DELETE FROM bundle WHERE bid = %d", $edit["bid"]);
}
else if ($edit["title"]) {
// a single unique id for bundles and feeds, to use in blocks
$next_id = db_next_id("import");
db_query("INSERT INTO bundle (bid, title, attributes) VALUES ('%d', '%s', '%s')", $next_id, $edit["title"], $edit["attributes"]);
$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"]);
}
}
......@@ -415,33 +415,33 @@ function import_form_feed($edit = array()) {
function import_save_feed($edit) {
if ($edit["fid"] && $edit["title"]) {
db_query("UPDATE feed SET title = '%s', url = '%s', attributes = '%s', refresh = '%s' 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("UPDATE feed SET title = '%s', url = '%s', attributes = '%s', refresh = '%s' WHERE fid = %d", $edit["title"], $edit["url"], $edit["attributes"], $edit["refresh"], $edit["fid"]);
db_query("DELETE FROM item WHERE fid = %d", $edit["fid"]);
}
else if ($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 feed WHERE fid = %d", $edit["fid"]);
db_query("DELETE FROM item WHERE fid = %d", $edit["fid"]);
}
else if ($edit["title"]) {
// a single unique id for bundles and feeds, to use in blocks
$next_id = db_next_id("import");
db_query("INSERT INTO feed (fid, title, url, attributes, refresh) VALUES ('%d', '%s', '%s', '%s', '%s')", $next_id, $edit["title"], $edit["url"], $edit["attributes"], $edit["refresh"]);
$next_id = db_next_id("feed_fid");
db_query("INSERT INTO feed (fid, title, url, attributes, refresh) VALUES (%d, '%s', '%s', '%s', '%s')", $next_id, $edit["title"], $edit["url"], $edit["attributes"], $edit["refresh"]);
}
}
function import_save_attributes($edit) {
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";
}
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) {
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() {
......@@ -594,13 +594,13 @@ function import_page_last() {
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("Description") .":</b><div style=\"margin-left: 20px;\">$feed->description</div></p>";
$header .= "<p><b>". t("Last update") .":</b><div style=\"margin-left: 20px;\">". format_interval(time() - $feed->timestamp) ." ". t("ago") ." <a href=\"$feed->url\"><img src=\"". theme("image", "xml.gif") ."\" width=\"36\" height=\"14\" align=\"right\" border=\"0\" alt=\"\" /></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\">";
while ($item = db_fetch_object($result)) {
......@@ -630,7 +630,7 @@ function import_page_feed($fid) {
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("Description") .":</b><div style=\"margin-left: 20px;\">". t("A composite news feed about") ." $bundle->attributes.</div></p>";
......
......@@ -92,7 +92,7 @@ function import_bundle_block($attributes) {
}
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));
while ($item = db_fetch_object($result)) {
$output .= import_format_item($item);
......@@ -119,13 +119,13 @@ function import_block($op, $delta) {
list($type, $id) = split(":", $delta);
switch ($type) {
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["content"] .= import_feed_block($feed) ."<div align=\"right\">". l(t("more"), "import/feed/$feed->fid", array("title" => t("View this feed's recent news."))) ."</div>";
break;
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["content"] .= import_bundle_block($bundle->attributes) ."<div align=\"right\">". l(t("more"), "import/bundle/$bundle->bid", array("title" => t("View this bundle's recent news."))) ."</div>";
break;
......@@ -168,7 +168,7 @@ function import_get_feeds($attributes = 0) {
}
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"]));
}
......@@ -270,7 +270,7 @@ function import_refresh($feed) {
$channel[$key] = filter(strtr(trim($value), $tt));
}
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,
......@@ -316,10 +316,10 @@ function import_refresh($feed) {
*/
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 {
$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"]));
......@@ -331,7 +331,7 @@ function import_refresh($feed) {
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)) {
$items[] = "iid = '$item->iid'";
......@@ -351,10 +351,10 @@ function import_refresh($feed) {
function import_save_item($edit) {
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"]) {
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"]) {
db_query("INSERT INTO item (fid, title, link, author, description, attributes, timestamp) VALUES ('%s', '%s', '%s', '%s', '%s', '%s', '%s')", $edit["fid"], $edit["title"], $edit["link"], $edit["author"], $edit["description"], $edit["attributes"], time());
......@@ -378,15 +378,15 @@ function import_form_bundle($edit = array()) {
function import_save_bundle($edit) {
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"]) {
db_query("DELETE FROM bundle WHERE bid = '%d'", $edit["bid"]);
db_query("DELETE FROM bundle WHERE bid = %d", $edit["bid"]);
}
else if ($edit["title"]) {
// a single unique id for bundles and feeds, to use in blocks
$next_id = db_next_id("import");
db_query("INSERT INTO bundle (bid, title, attributes) VALUES ('%d', '%s', '%s')", $next_id, $edit["title"], $edit["attributes"]);
$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"]);
}
}
......@@ -415,33 +415,33 @@ function import_form_feed($edit = array()) {
function import_save_feed($edit) {
if ($edit["fid"] && $edit["title"]) {
db_query("UPDATE feed SET title = '%s', url = '%s', attributes = '%s', refresh = '%s' 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("UPDATE feed SET title = '%s', url = '%s', attributes = '%s', refresh = '%s' WHERE fid = %d", $edit["title"], $edit["url"], $edit["attributes"], $edit["refresh"], $edit["fid"]);
db_query("DELETE FROM item WHERE fid = %d", $edit["fid"]);
}
else if ($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 feed WHERE fid = %d", $edit["fid"]);
db_query("DELETE FROM item WHERE fid = %d", $edit["fid"]);
}
else if ($edit["title"]) {
// a single unique id for bundles and feeds, to use in blocks
$next_id = db_next_id("import");
db_query("INSERT INTO feed (fid, title, url, attributes, refresh) VALUES ('%d', '%s', '%s', '%s', '%s')", $next_id, $edit["title"], $edit["url"], $edit["attributes"], $edit["refresh"]);
$next_id = db_next_id("feed_fid");
db_query("INSERT INTO feed (fid, title, url, attributes, refresh) VALUES (%d, '%s', '%s', '%s', '%s')", $next_id, $edit["title"], $edit["url"], $edit["attributes"], $edit["refresh"]);
}
}
function import_save_attributes($edit) {
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";
}
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) {
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() {
......@@ -594,13 +594,13 @@ function import_page_last() {
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("Description") .":</b><div style=\"margin-left: 20px;\">$feed->description</div></p>";
$header .= "<p><b>". t("Last update") .":</b><div style=\"margin-left: 20px;\">". format_interval(time() - $feed->timestamp) ." ". t("ago") ." <a href=\"$feed->url\"><img src=\"". theme("image", "xml.gif") ."\" width=\"36\" height=\"14\" align=\"right\" border=\"0\" alt=\"\" /></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\">";
while ($item = db_fetch_object($result)) {
......@@ -630,7 +630,7 @@ function import_page_feed($fid) {
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("Description") .":</b><div style=\"margin-left: 20px;\">". t("A composite news feed about") ." $bundle->attributes.</div></p>";
......
......@@ -113,7 +113,7 @@ function comment_form($edit) {
function comment_edit($cid) {
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)) {
comment_preview(object2array($comment));
......@@ -130,7 +130,7 @@ function comment_reply($pid, $nid) {
*/
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);
}
else {
......@@ -181,7 +181,7 @@ function comment_preview($edit) {
theme("box", t("Reply"), comment_form($edit));
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);
}
else {
......@@ -221,7 +221,7 @@ function comment_post($edit) {
** 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) {
watchdog("warning", "comment: duplicate '". $edit["subject"] ."'");
......@@ -237,7 +237,7 @@ function comment_post($edit) {
** 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
......@@ -268,9 +268,9 @@ function comment_post($edit) {
$score = $roles[$user->rid] ? $roles[$user->rid] : 0;
$users = serialize(array(0 => $score));
$edit["cid"] = db_next_id("comments");
$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', '%s', '%s', '%s', '%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', '%s', '%s', '%s', '%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:
......@@ -397,7 +397,7 @@ function comment_render($node, $cid = 0) {
if (empty($threshold)) {
$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)) {
$comment_page = 1;
......@@ -417,7 +417,7 @@ function comment_render($node, $cid = 0) {
print "<form method=\"post\" action=\"". url("comment") ."\">\n";
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)) {
comment_view($comment, comment_links($comment));
......@@ -734,7 +734,7 @@ function comment_node_link($node) {
** 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));
......@@ -754,7 +754,7 @@ function comment_node_link($node) {
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);
// if a comment is "deleted", it's deleted
......@@ -774,7 +774,7 @@ function comment_admin_edit($id) {
function comment_delete($edit) {
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"]);
$output = "deleted comment.";
}
......@@ -790,7 +790,7 @@ function comment_delete($edit) {
}
function comment_save($id, $edit) {
db_query("UPDATE comments SET subject = '%s', comment = '%s', status = '%s' WHERE cid = '%d'", filter($edit["subject"]), filter($edit["comment"]), $edit["status"], $id);
db_query("UPDATE comments SET subject = '%s', comment = '%s', status = '%s' WHERE cid = %d", filter($edit["subject"]), filter($edit["comment"]), $edit["status"], $id);
watchdog("special", "comment: modified '". $edit["subject"] ."'");
return "updated comment.";
}
......@@ -889,16 +889,16 @@ function comment_mod_votes($edit) {
$mid = arg(3);
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;
}
else if ($op == t("Delete vote")) {
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_votes WHERE mid = %d", $mid);
db_query("DELETE FROM moderation_roles WHERE mid = %d", $mid);
$mid = 0;
}
else if ($op == t("Add new vote")) {
db_query("INSERT INTO moderation_votes (mid, vote, weight) VALUES (NULL, '%s', '%d')", $edit["vote"], $edit["weight"]);
db_query("INSERT INTO moderation_votes (mid, vote, weight) VALUES (NULL, '%s', %d)", $edit["vote"], $edit["weight"]);
$mid = 0;
}
......@@ -913,7 +913,7 @@ function comment_mod_votes($edit) {
$output .= "</table>";
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 .= "<h3>Add new moderation option</h3>";
......@@ -938,15 +938,15 @@ function comment_mod_filters($edit) {
$fid = arg(3);
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;
}
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;
}
else if ($op == t("Add new threshold")) {
db_query("INSERT INTO moderation_filters (fid, filter, minimum) VALUES (NULL, '%s', '%d')", $edit["filter"], $edit["minimum"]);
db_query("INSERT INTO moderation_filters (fid, filter, minimum) VALUES (NULL, '%s', %d)", $edit["filter"], $edit["minimum"]);
$fid = 0;
}
......@@ -962,7 +962,7 @@ function comment_mod_filters($edit) {
$output .= "</table>";
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 .= "<h3>Add new threshold</h3>";
......@@ -1138,7 +1138,7 @@ function comment_moderation_form($comment) {
// comment hasn't been moderated yet:
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();
while ($vote = db_fetch_object($result)) {
if ($vote->value != 0) {
......@@ -1257,18 +1257,18 @@ function comment_moderate() {
global $moderation, $user;
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)) {
$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)) {
foreach ($moderation as $cid => $vote) {
if ($vote) {
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);
/*
......@@ -1278,7 +1278,7 @@ function comment_moderate() {
module_invoke_all("comment", "unpublish", $cid);
}
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);
if ($user->uid != $comment->uid && !(comment_already_moderated($user->uid, $comment->users))) {
$users[$user->uid] = $vote;
......@@ -1293,7 +1293,7 @@ function comment_moderate() {
}
}
$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
......@@ -1320,7 +1320,7 @@ function comment_num_all($nid) {
static $cache;
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;
}
return $cache[$nid];
......@@ -1330,7 +1330,7 @@ function comment_num_replies($id) {
static $cache;
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;
}
......@@ -1360,7 +1360,7 @@ function comment_num_new($nid, $timestamp = 0) {
** 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;
}
......
......@@ -113,7 +113,7 @@ function comment_form($edit) {
function comment_edit($cid) {
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)) {
comment_preview(object2array($comment));
......@@ -130,7 +130,7 @@ function comment_reply($pid, $nid) {
*/
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);
}
else {
......@@ -181,7 +181,7 @@ function comment_preview($edit) {
theme("box", t("Reply"), comment_form($edit));
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);
}
else {
......@@ -221,7 +221,7 @@ function comment_post($edit) {
** 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) {
watchdog("warning", "comment: duplicate '". $edit["subject"] ."'");
......@@ -237,7 +237,7 @@ function comment_post($edit) {