Commit 170b674a authored by Dries's avatar Dries

- All LIMIT queries must go through the pager or through db_query_range().

  The syntax for db_query_range() was enhanced so it matches db_query(). So
  you may pass extra arguments of the SQL statement which are checked via
  check_query() and then substituted into the SQL statement. After these
  optional arguments, you always pass $from and $count parameters which
  define your range.  Most often, the $from is 0 and the count is the max
  number of records you want returned.  Patch by Moshe.

- The pager_query() function for PEAR was enhanced so that it adds  proper
  GROUP BY statement counting the number of records to be paged. Patch by
  James Arthur.

- MSSQL database scheme by Moshe.
parent 6dc1cf59
Drupal x.x.x, xxxx-xx-xx (to be released)
------------------------
- clean urls.
- clean URLs.
- reorganized the administration pages.
- database backend:
* fixed numereous SQL queries to make Drupal work on PostgreSQL and MSSQL.
- search module:
* changed the search module to use implicit AND'ing instead of
implicit OR'ing.
* changed the search module to use implicit AND'ing instead of implicit OR'ing.
- node system improvements:
* replaced the "post content" permission by more fine-grained
permissions.
* replaced the "post content" permission by more fine-grained permissions.
* improved content submission:
+ improved teasers: teasers are now optional, teaser length can
be configured, teaser and body are edited in a single
textarea, users will no longer be bother with teasers when
the post is too short for a teaser.
+ added the ability to preview both the short and the full
version of your posts.
* extended the node api, allows for more advanced uses and cleans
up the interaction between modules.
* added default node settings to control the behaviour for
promotion, moderation and other options.
+ improved teasers: teasers are now optional, teaser length can be configured, teaser and body are edited in a single textarea, users will no longer be bother with teasers when the post is too short for a teaser.
+ added the ability to preview both the short and the full version of your posts.
* extended the node api, allows for more advanced uses and cleans up the interaction between modules.
* added default node settings to control the behaviour for promotion, moderation and other options.
- themes:
* replaced theme "Goofy" by "Xtemplate", a template driven theme.
......
......@@ -40,6 +40,10 @@ POLL MODULE
M: Steven Wittens <unconed@drop.org>
S: maintained
MSSQL PORT
M: Moshe Weitzman <weitzman@tejasa.com>
S: maintained
POSTGRES PORT
M: James Arthur <j_a_arthur@yahoo.com>
S: maintained
......
......@@ -104,7 +104,6 @@ CREATE TABLE cache (
cid varchar(255) NOT NULL default '',
data mediumtext,
expire int(11) NOT NULL default '0',
created int(11) NOT NULL default '0',
PRIMARY KEY (cid)
) TYPE=MyISAM;
......@@ -167,11 +166,9 @@ CREATE TABLE feed (
CREATE TABLE forum (
nid int(10) unsigned NOT NULL default '0',
tid int(10) unsigned NOT NULL default '0',
icon varchar(255) NOT NULL default '',
shadow int(10) unsigned NOT NULL default '0',
PRIMARY KEY (nid),
KEY tid (tid)
PRIMARY KEY (nid)
) TYPE=MyISAM;
--
......@@ -239,8 +236,8 @@ CREATE TABLE moderation_roles (
rid int(10) unsigned NOT NULL default '0',
mid int(10) unsigned NOT NULL default '0',
value tinyint(4) NOT NULL default '0',
KEY rid (rid),
KEY mid (mid)
KEY idx_rid (rid),
KEY idx_mid (mid)
) TYPE=MyISAM;
--
......@@ -541,7 +538,6 @@ CREATE TABLE watchdog (
uid int(10) NOT NULL default '0',
type varchar(16) NOT NULL default '',
message text NOT NULL,
link varchar(255) NOT NULL default '',
location varchar(128) NOT NULL default '',
hostname varchar(128) NOT NULL default '',
timestamp int(11) NOT NULL default '0',
......
......@@ -12,8 +12,9 @@
# and so on is likely to confuse the parser; use alpha-numerical
# characters instead.
# $db_url = "pgsql://user:password@hostname/database";
# $db_url = "mysql://user:password@hostname/database";
# $db_url = "pgsql://user:password@hostname/database";
# $db_url = "mssql://user:password@hostname/database";
$db_url = "mysql://drupal:drupal@localhost/drupal";
......
......@@ -23,6 +23,7 @@ function db_connect($url) {
* @return sql result resource
*/
function db_query($query) {
$args = func_get_args();
if (count($args) > 1) {
$args = array_map("check_query", $args);
......@@ -52,11 +53,19 @@ function _db_query($query, $debug = 0) {
global $db_handle, $queries;
if (variable_get("dev_query", 0)) {
$queries[] = $query;
list($usec, $sec) = explode(" ", microtime());
$timer = (float)$usec + (float)$sec;
}
$result = $db_handle->query($query);
if (variable_get("dev_query", 0)) {
list($usec, $sec) = explode(" ", microtime());
$stop = (float)$usec + (float)$sec;
$diff = $stop - $timer;
$queries[] = array($query, $diff);
}
if ($debug) {
print "<p>query: $query</p>";
}
......@@ -103,7 +112,13 @@ function db_error() {
function db_next_id($name) {
global $db_handle;
return $db_handle->nextID($name);
$result = $db_handle->nextID($name);
if (DB::isError($result)) {
watchdog("error", "database: ". $result->getMessage() ."\nquery: ". htmlspecialchars($query));
}
else {
return $result;
}
}
function db_affected_rows() {
......@@ -113,21 +128,46 @@ function db_affected_rows() {
}
/**
* Generates a limited query
*
* @param string $query query
* @param integer $from the row to start to fetching
* @param integer $count the numbers of rows to fetch
* Runs a LIMIT query in the database.
*
* @param $query sql query followed by 'from' and 'count' parameters, followed by a variable number of arguments which are substituted into query by sprintf. 'from' is the row to start to fetching. 'count' the numbers of rows to fetch.
* @return mixed a DB_Result object or a DB_Error
*
* @access public
*/
function db_query_range($query) {
global $db_handle, $queries;
function db_query_range($query, $from, $count) {
global $db_handle;
if (variable_get("dev_query", 0)) {
list($usec, $sec) = explode(" ", microtime());
$timer = (float)$usec + (float)$sec;
}
return $db_handle->limitQuery($query, $from, $count);
$args = func_get_args();
$count = array_pop($args);
$from = array_pop($args);
if (count(func_get_args()) > 3) {
$args = array_map("check_query", $args);
$args[0] = $query;
$result = $db_handle->limitQuery(call_user_func_array("sprintf", $args), $from, $count);
}
else {
$result = $db_handle->limitQuery(func_get_arg(0), $from, $count);
}
if (variable_get("dev_query", 0)) {
list($usec, $sec) = explode(" ", microtime());
$stop = (float)$usec + (float)$sec;
$diff = $stop - $timer;
$queries[] = array($query. " [LIMIT $from, $count]", $diff);
}
if (DB::isError($result)) {
watchdog("error", "database: ". $result->getMessage() ."\nquery: ". htmlspecialchars($query));
}
else {
return $result;
}
}
?>
?>
\ No newline at end of file
......@@ -287,6 +287,7 @@ function pager_query($query, $limit = 10, $element = 0, $count_query = "") {
// count the total number of records in this query:
if ($count_query == "") {
$pager_total[$element] = db_result(db_query(preg_replace(array("/SELECT.*FROM/i", "/ORDER BY .*/"), array("SELECT COUNT(*) FROM", ""), $query)));
}
else {
$pager_total[$element] = db_result(db_query($count_query));
......@@ -296,6 +297,7 @@ function pager_query($query, $limit = 10, $element = 0, $count_query = "") {
$pager_from_array = explode(",", $from);
return db_query_range($query, (int)$pager_from_array[$element], (int)$limit);
}
function pager_link($from_new, $attributes = array()) {
......@@ -329,4 +331,4 @@ function pager_load_array($value, $element, $old_array) {
return $new_array;
}
?>
?>
\ No newline at end of file
......@@ -81,7 +81,7 @@ function import_bundle_block($attributes) {
$keys = explode(",", $attributes);
foreach ($keys as $key) $where[] = "attributes LIKE '%". trim($key) ."%'";
$result = db_query("SELECT * FROM item WHERE ". implode(" OR ", $where) ." ORDER BY iid DESC LIMIT ". 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));
}
while ($item = db_fetch_object($result)) {
......@@ -92,7 +92,7 @@ function import_bundle_block($attributes) {
}
function import_feed_block($feed) {
$result = db_query("SELECT * FROM item WHERE fid = '%s' ORDER BY iid DESC LIMIT ". variable_get("import_block_limit", 15), $feed->fid);
$result = db_query_range("SELECT * FROM item WHERE fid = '%s' ORDER BY iid DESC ", 0, variable_get("import_block_limit", 15), $feed->fid);
while ($item = db_fetch_object($result)) {
$output .= import_format_item($item);
......@@ -429,7 +429,7 @@ function import_view() {
function import_tag() {
$result = db_query("SELECT i.*, f.title AS feed FROM item i LEFT JOIN feed f ON i.fid = f.fid ORDER BY i.iid DESC LIMIT 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"));
while ($item = db_fetch_object($result)) {
......@@ -519,7 +519,7 @@ function import_page_info() {
function import_page_last() {
$result = db_query("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 LIMIT ". 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\">";
while ($item = db_fetch_object($result)) {
......@@ -555,7 +555,7 @@ function import_page_feed($fid) {
$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("SELECT * FROM item WHERE fid = '%s' ORDER BY iid DESC LIMIT ". variable_get("import_page_limit", 75), $fid);
$result = db_query_range("SELECT * FROM item WHERE fid = '%s' ORDER BY iid DESC", 0, variable_get("import_page_limit", 75), $fid);
$output .= "<table border=\"0\" cellpadding=\"4\" cellspacing=\"2\">";
while ($item = db_fetch_object($result)) {
......@@ -592,7 +592,7 @@ function import_page_bundle($bid) {
$keys = explode(",", $bundle->attributes);
foreach ($keys as $key) $where[] = "i.attributes LIKE '%". trim($key) ."%'";
$result = db_query("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 LIMIT ". 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\">";
while ($item = db_fetch_object($result)) {
......
......@@ -81,7 +81,7 @@ function import_bundle_block($attributes) {
$keys = explode(",", $attributes);
foreach ($keys as $key) $where[] = "attributes LIKE '%". trim($key) ."%'";
$result = db_query("SELECT * FROM item WHERE ". implode(" OR ", $where) ." ORDER BY iid DESC LIMIT ". 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));
}
while ($item = db_fetch_object($result)) {
......@@ -92,7 +92,7 @@ function import_bundle_block($attributes) {
}
function import_feed_block($feed) {
$result = db_query("SELECT * FROM item WHERE fid = '%s' ORDER BY iid DESC LIMIT ". variable_get("import_block_limit", 15), $feed->fid);
$result = db_query_range("SELECT * FROM item WHERE fid = '%s' ORDER BY iid DESC ", 0, variable_get("import_block_limit", 15), $feed->fid);
while ($item = db_fetch_object($result)) {
$output .= import_format_item($item);
......@@ -429,7 +429,7 @@ function import_view() {
function import_tag() {
$result = db_query("SELECT i.*, f.title AS feed FROM item i LEFT JOIN feed f ON i.fid = f.fid ORDER BY i.iid DESC LIMIT 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"));
while ($item = db_fetch_object($result)) {
......@@ -519,7 +519,7 @@ function import_page_info() {
function import_page_last() {
$result = db_query("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 LIMIT ". 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\">";
while ($item = db_fetch_object($result)) {
......@@ -555,7 +555,7 @@ function import_page_feed($fid) {
$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("SELECT * FROM item WHERE fid = '%s' ORDER BY iid DESC LIMIT ". variable_get("import_page_limit", 75), $fid);
$result = db_query_range("SELECT * FROM item WHERE fid = '%s' ORDER BY iid DESC", 0, variable_get("import_page_limit", 75), $fid);
$output .= "<table border=\"0\" cellpadding=\"4\" cellspacing=\"2\">";
while ($item = db_fetch_object($result)) {
......@@ -592,7 +592,7 @@ function import_page_bundle($bid) {
$keys = explode(",", $bundle->attributes);
foreach ($keys as $key) $where[] = "i.attributes LIKE '%". trim($key) ."%'";
$result = db_query("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 LIMIT ". 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\">";
while ($item = db_fetch_object($result)) {
......
......@@ -174,7 +174,7 @@ function archive_page() {
*/
if ($year && $month && $day) {
$result = db_query("SELECT nid FROM node WHERE status = '1' AND created > %d ORDER BY created LIMIT 20", $date);
$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)) {
node_view(node_load(array("nid" => $nid->nid)), 1);
......
......@@ -174,7 +174,7 @@ function archive_page() {
*/
if ($year && $month && $day) {
$result = db_query("SELECT nid FROM node WHERE status = '1' AND created > %d ORDER BY created LIMIT 20", $date);
$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)) {
node_view(node_load(array("nid" => $nid->nid)), 1);
......
......@@ -86,7 +86,7 @@ function blog_feed_user($uid = 0) {
$account = $user;
}
$result = db_query("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 LIMIT 15", $uid);
$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["link"] = url("blog/view/$uid");
$channel["description"] = $term->description;
......@@ -94,7 +94,7 @@ function blog_feed_user($uid = 0) {
}
function blog_feed_last() {
$result = db_query("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 LIMIT 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["link"] = url("blog/view");
$channel["description"] = $term->description;
......@@ -242,7 +242,7 @@ function blog_block($op = "list", $delta = 0) {
}
else {
if (user_access("access content")) {
$block["content"] = node_title_list(db_query("SELECT u.uid, u.name, n.created, n.title, n.nid 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 LIMIT 10"));
$block["content"] = node_title_list(db_query_range("SELECT u.uid, u.name, n.created, n.title, n.nid 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, 10));
$block["content"] .= "<div align=\"right\" id=\"blog_more\">". l(t("more"), "blog", array("title" => t("Read the latest blog entries."))) ."</div>";
$block["subject"] = t("User blogs");
}
......
......@@ -86,7 +86,7 @@ function blog_feed_user($uid = 0) {
$account = $user;
}
$result = db_query("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 LIMIT 15", $uid);
$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["link"] = url("blog/view/$uid");
$channel["description"] = $term->description;
......@@ -94,7 +94,7 @@ function blog_feed_user($uid = 0) {
}
function blog_feed_last() {
$result = db_query("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 LIMIT 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["link"] = url("blog/view");
$channel["description"] = $term->description;
......@@ -242,7 +242,7 @@ function blog_block($op = "list", $delta = 0) {
}
else {
if (user_access("access content")) {
$block["content"] = node_title_list(db_query("SELECT u.uid, u.name, n.created, n.title, n.nid 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 LIMIT 10"));
$block["content"] = node_title_list(db_query_range("SELECT u.uid, u.name, n.created, n.title, n.nid 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, 10));
$block["content"] .= "<div align=\"right\" id=\"blog_more\">". l(t("more"), "blog", array("title" => t("Read the latest blog entries."))) ."</div>";
$block["subject"] = t("User blogs");
}
......
......@@ -269,7 +269,7 @@ function bloggerapi_node_recent($num) {
global $user;
if (($num == 0) or ($num > 100)) $num = 50;
$result = db_query("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 LIMIT %d", $user->uid, $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) {
while ($blog = db_fetch_object($result)) {
$body = "<title>$blog->title</title>\n". $blog->body;
......
......@@ -513,7 +513,7 @@ function book_tree($parent = 0, $depth = 3) {
function book_render() {
$result = db_query("SELECT n.nid FROM node n LEFT JOIN book b ON n.nid = b.nid WHERE b.parent = 0 AND n.status = 1 AND (n.moderate = 0 OR n.revisions != '') ORDER BY b.weight, n.title");
$result = db_query("SELECT n.nid FROM node n LEFT 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)) {
// load the node:
......@@ -555,7 +555,7 @@ function book_page() {
}
function book_print($id = "", $depth = 1) {
$result = db_query("SELECT n.nid FROM node n LEFT JOIN book b ON n.nid = b.nid WHERE n.status = 1 AND n.nid = '%d' AND (n.moderate = 0 OR n.revisions != '') ORDER BY b.weight, n.title", $id);
$result = db_query("SELECT n.nid FROM node n LEFT 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)) {
// load the node:
......@@ -582,7 +582,7 @@ function book_print($id = "", $depth = 1) {
}
function book_print_recurse($parent = "", $depth = 1) {
$result = db_query("SELECT n.nid FROM node n LEFT JOIN book b ON n.nid = b.nid WHERE n.status = 1 AND b.parent = '$parent' AND (n.moderate = 0 OR n.revisions != '') ORDER BY b.weight, n.title");
$result = db_query("SELECT n.nid FROM node n LEFT 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)) {
// load the node:
......@@ -756,4 +756,4 @@ function book_help() {
</ul>
<?php
}
?>
?>
\ No newline at end of file
......@@ -513,7 +513,7 @@ function book_tree($parent = 0, $depth = 3) {
function book_render() {
$result = db_query("SELECT n.nid FROM node n LEFT JOIN book b ON n.nid = b.nid WHERE b.parent = 0 AND n.status = 1 AND (n.moderate = 0 OR n.revisions != '') ORDER BY b.weight, n.title");
$result = db_query("SELECT n.nid FROM node n LEFT 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)) {
// load the node:
......@@ -555,7 +555,7 @@ function book_page() {
}
function book_print($id = "", $depth = 1) {
$result = db_query("SELECT n.nid FROM node n LEFT JOIN book b ON n.nid = b.nid WHERE n.status = 1 AND n.nid = '%d' AND (n.moderate = 0 OR n.revisions != '') ORDER BY b.weight, n.title", $id);
$result = db_query("SELECT n.nid FROM node n LEFT 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)) {
// load the node:
......@@ -582,7 +582,7 @@ function book_print($id = "", $depth = 1) {
}
function book_print_recurse($parent = "", $depth = 1) {
$result = db_query("SELECT n.nid FROM node n LEFT JOIN book b ON n.nid = b.nid WHERE n.status = 1 AND b.parent = '$parent' AND (n.moderate = 0 OR n.revisions != '') ORDER BY b.weight, n.title");
$result = db_query("SELECT n.nid FROM node n LEFT 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)) {
// load the node:
......@@ -756,4 +756,4 @@ function book_help() {
</ul>
<?php
}
?>
?>
\ No newline at end of file
......@@ -134,7 +134,7 @@ function cloud_display() {
}
function cloud_list($limit = 10) {
$result = db_query("SELECT * FROM site WHERE timestamp > ". (time() - 604800) ." ORDER BY timestamp DESC LIMIT $limit");
$result = db_query_range("SELECT * FROM site WHERE timestamp > ". (time() - 604800) ." ORDER BY timestamp DESC", 0, $limit);
$hour = -1;
$list = -1;
......
......@@ -797,7 +797,7 @@ function comment_save($id, $edit) {
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));
while ($comment = db_fetch_object($result)) {
......@@ -1465,4 +1465,4 @@ function comment_nodeapi(&$node, $op, $arg = 0) {
}
}
?>
?>
\ No newline at end of file
......@@ -797,7 +797,7 @@ function comment_save($id, $edit) {
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));
while ($comment = db_fetch_object($result)) {
......@@ -1465,4 +1465,4 @@ function comment_nodeapi(&$node, $op, $arg = 0) {
}
}
?>
?>
\ No newline at end of file
......@@ -85,11 +85,11 @@ function forum_block($op = "list", $delta = 0) {
if (empty($cache)) {
unset($items);
$content = node_title_list(db_query("SELECT n.nid, n.title, u.uid, u.name, GREATEST(n.created, MAX(c.timestamp)) AS sort FROM node n, forum f LEFT JOIN comments c ON c.nid = n.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 ORDER BY sort DESC LIMIT ". 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, forum f LEFT JOIN comments c ON c.nid = n.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 ORDER BY sort DESC", 0, variable_get("forum_block_num", "5")), t("Active forum topics:"));
$content .= "<br />";
unset ($items);
$content .= node_title_list(db_query("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 LIMIT ". 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) {
$content .= "<div id=\"forum_more\" align=\"right\">". l(t("more"), "forum") ."</div>";
......@@ -272,12 +272,12 @@ function _forum_num_comments($nid) {
}
function _forum_last_comment($nid) {
$value = db_fetch_object(db_query("SELECT timestamp FROM comments WHERE nid = '%d' AND status = 0 ORDER BY timestamp DESC LIMIT 1", $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));
return ($value) ? format_date($value->timestamp, "small") : "&nbsp;";
}
function _forum_last_reply($nid) {
$value = db_fetch_object(db_query("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 LIMIT 1", $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));
return $value;
}
......@@ -366,9 +366,9 @@ function _forum_topics_read($uid) {
}
function _forum_last_post($term) {
$topic = db_fetch_object(db_query("SELECT n.nid, n.created AS timestamp, u.name AS name, u.uid AS uid FROM node n, forum f 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 LIMIT 1", $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, node n 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("SELECT n.nid, c.timestamp, u.name AS name, u.uid AS uid FROM forum f, node n 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 LIMIT 1", $term));
$reply = db_fetch_object(db_query_range("SELECT n.nid, c.timestamp, u.name AS name, u.uid AS uid FROM forum f, node n 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;
......@@ -386,7 +386,7 @@ function forum_get_topics($tid, $sortby, $forum_per_page) {
// show topics with the correct tid, or in the forum but with shadow = 1
$sql = "SELECT n.nid, 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, icon, n.comment AS comment_mode, f.tid FROM node n, term_node r LEFT JOIN users u ON n.uid = u.uid LEFT JOIN comments c ON c.nid = n.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 ORDER BY $sql_sortby";
$sql_count = "SELECT COUNT(DISTINCT(n.nid)) FROM node n, term_node r 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'";
$sql_count = "SELECT COUNT(DISTINCT(n.nid)) FROM term_node r, node n 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'";
$result = pager_query($sql, $forum_per_page, 0, $sql_count);
$topic_num = db_num_rows($result);
......@@ -437,7 +437,7 @@ function _forum_new($tid) {
$read[] = $r->nid;
}
$nid = db_result(db_query("SELECT n.nid FROM node n, forum f 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 LIMIT 1", $tid));
$nid = db_result(db_query_range("SELECT n.nid FROM node n, forum f 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;
}
......
......@@ -85,11 +85,11 @@ function forum_block($op = "list", $delta = 0) {
if (empty($cache)) {
unset($items);
$content = node_title_list(db_query("SELECT n.nid, n.title, u.uid, u.name, GREATEST(n.created, MAX(c.timestamp)) AS sort FROM node n, forum f LEFT JOIN comments c ON c.nid = n.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 ORDER BY sort DESC LIMIT ". 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, forum f LEFT JOIN comments c ON c.nid = n.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 ORDER BY sort DESC", 0, variable_get("forum_block_num", "5")), t("Active forum topics:"));
$content .= "<br />";
unset ($items);
$content .= node_title_list(db_query("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 LIMIT ". 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) {
$content .= "<div id=\"forum_more\" align=\"right\">". l(t("more"), "forum") ."</div>";
......@@ -272,12 +272,12 @@ function _forum_num_comments($nid) {
}
function _forum_last_comment($nid) {
$value = db_fetch_object(db_query("SELECT timestamp FROM comments WHERE nid = '%d' AND status = 0 ORDER BY timestamp DESC LIMIT 1", $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));
return ($value) ? format_date($value->timestamp, "small") : "&nbsp;";
}
function _forum_last_reply($nid) {
$value = db_fetch_object(db_query("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 LIMIT 1", $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));
return $value;
}
......@@ -366,9 +366,9 @@ function _forum_topics_read($uid) {
}
function _forum_last_post($term) {
$topic = db_fetch_object(db_query("SELECT n.nid, n.created AS timestamp, u.name AS name, u.uid AS uid FROM node n, forum f 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 LIMIT 1", $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, node n 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("SELECT n.nid, c.timestamp, u.name AS name, u.uid AS uid FROM forum f, node n 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 LIMIT 1", $term));
$reply = db_fetch_object(db_query_range("SELECT n.nid, c.timestamp, u.name AS name, u.uid AS uid FROM forum f, node n 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;
......@@ -386,7 +386,7 @@ function forum_get_topics($tid, $sortby, $forum_per_page) {
// show topics with the correct tid, or in the forum but with shadow = 1
$sql = "SELECT n.nid, 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, icon, n.comment AS comment_mode, f.tid FROM node n, term_node r LEFT JOIN users u ON n.uid = u.uid LEFT JOIN comments c ON c.nid = n.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 ORDER BY $sql_sortby";
$sql_count = "SELECT COUNT(DISTINCT(n.nid)) FROM node n, term_node r 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'";
$sql_count = "SELECT COUNT(DISTINCT(n.nid)) FROM term_node r, node n 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'";
$result = pager_query($sql, $forum_per_page, 0, $sql_count);
$topic_num = db_num_rows($result);
......@@ -437,7 +437,7 @@ function _forum_new($tid) {
$read[] = $r->nid;
}
$nid = db_result(db_query("SELECT n.nid FROM node n, forum f 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 LIMIT 1", $tid));
$nid = db_result(db_query_range("SELECT n.nid FROM node n, forum f 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;
}
......
......@@ -81,7 +81,7 @@ function import_bundle_block($attributes) {
$keys = explode(",", $attributes);
foreach ($keys as $key) $where[] = "attributes LIKE '%". trim($key) ."%'";
$result = db_query("SELECT * FROM item WHERE ". implode(" OR ", $where) ." ORDER BY iid DESC LIMIT ". 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));
}
while ($item = db_fetch_object($result)) {
......@@ -92,7 +92,7 @@ function import_bundle_block($attributes) {
}
function import_feed_block($feed) {
$result = db_query("SELECT * FROM item WHERE fid = '%s' ORDER BY iid DESC LIMIT ". variable_get("import_block_limit", 15), $feed->fid);
$result = db_query_range("SELECT * FROM item WHERE fid = '%s' ORDER BY iid DESC ", 0, variable_get("import_block_limit", 15), $feed->fid);
while ($item = db_fetch_object($result)) {
$output .= import_format_item($item);
......@@ -429,7 +429,7 @@ function import_view() {
function import_tag() {
$result = db_query("SELECT i.*, f.title AS feed FROM item i LEFT JOIN feed f ON i.fid = f.fid ORDER BY i.iid DESC LIMIT 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"));
while ($item = db_fetch_object($result)) {
......@@ -519,7 +519,7 @@ function import_page_info() {
function import_page_last() {
$result = db_query("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 LIMIT ". 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\">";
while ($item = db_fetch_object($result)) {
......@@ -555,7 +555,7 @@ function import_page_feed($fid) {
$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("SELECT * FROM item WHERE fid = '%s' ORDER BY iid DESC LIMIT ". variable_get("import_page_limit", 75), $fid);
$result = db_query_range("SELECT * FROM item WHERE fid = '%s' ORDER BY iid DESC", 0, variable_get("import_page_limit", 75), $fid);
$output .= "<table border=\"0\" cellpadding=\"4\" cellspacing=\"2\">";
while ($item = db_fetch_object($result)) {
......@@ -592,7 +592,7 @@ function import_page_bundle($bid) {
$keys = explode(",", $bundle->attributes);
foreach ($keys as $key) $where[] = "i.attributes LIKE '%". trim($key) ."%'";
$result = db_query("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 LIMIT ". 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\">";
while ($item = db_fetch_object($result)) {
......
......@@ -142,7 +142,7 @@ function locale_seek() {
foreach ($languages as $key=>$value) {
$tmp[] = $key . (check_query($edit["status"]) == 1 ? " !=" : " =") ." ''";
}
$query[] = implode(" && ", $tmp);
$query[] = implode(" AND ", $tmp);
break;
case "any":
foreach ($languages as $key=>$value) {
......
......@@ -142,7 +142,7 @@ function locale_seek() {
foreach ($languages as $key=>$value) {
$tmp[] = $key . (check_query($edit["status"]) == 1 ? " !=" : " =") ." ''";
}