- The real code fixes ;)

4.6.x
Steven Wittens 2005-01-17 19:00:03 +00:00
parent a1579a3aee
commit e7edb55d63
17 changed files with 63 additions and 67 deletions

View File

@ -106,7 +106,7 @@ function book_menu($may_cache) {
// We don't want to cache these menu items because they could change whenever
// a book page or outline node is edited.
if (arg(0) == 'admin' && arg(1) == 'node' && arg(2) == 'book') {
$result = db_query(node_rewrite_sql("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(node_rewrite_sql('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)) {
$items[] = array('path' => 'admin/node/book/'. $book->nid, 'title' => t('"%title" book', array('%title' => $book->title)));
}
@ -131,7 +131,7 @@ function book_block($op = 'list', $delta = 0) {
else if ($op == 'view') {
// Only display this block when the user is browsing a book:
if (arg(0) == 'node' && is_numeric(arg(1))) {
$result = db_query(node_rewrite_sql("SELECT n.nid, n.title, b.parent FROM {node} n INNER JOIN {book} b ON n.nid = b.nid WHERE n.nid = %d"), arg(1));
$result = db_query(node_rewrite_sql('SELECT n.nid, n.title, b.parent FROM {node} n INNER JOIN {book} b ON n.nid = b.nid WHERE n.nid = %d'), arg(1));
if (db_num_rows($result) > 0) {
$node = db_fetch_object($result);
@ -320,7 +320,7 @@ function book_revision_load($page, $conditions = array()) {
* Return the path (call stack) to a certain book page.
*/
function book_location($node, $nodes = array()) {
$parent = db_fetch_object(db_query(node_rewrite_sql("SELECT n.nid, n.title, b.parent, b.weight FROM {node} n INNER JOIN {book} b ON n.nid = b.nid WHERE n.nid = %d"), $node->parent));
$parent = db_fetch_object(db_query(node_rewrite_sql('SELECT n.nid, n.title, b.parent, b.weight FROM {node} n INNER JOIN {book} b ON n.nid = b.nid WHERE n.nid = %d'), $node->parent));
if ($parent->title) {
$nodes = book_location($parent, $nodes);
array_push($nodes, $parent);
@ -356,7 +356,7 @@ function book_prev($node) {
}
else {
// Direct parent:
$prev = db_fetch_object(db_query(node_rewrite_sql("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"), $node->parent));
$prev = db_fetch_object(db_query(node_rewrite_sql('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'), $node->parent));
return $prev;
}
}
@ -366,7 +366,7 @@ function book_prev($node) {
*/
function book_next($node) {
// get first direct child
$child = db_fetch_object(db_query(node_rewrite_sql("SELECT n.nid, n.title, b.weight FROM {node} n INNER JOIN {book} b ON n.nid = b.nid WHERE b.parent = %d AND n.status = 1 AND n.moderate = 0 ORDER BY b.weight ASC, n.title ASC"), $node->nid));
$child = db_fetch_object(db_query(node_rewrite_sql('SELECT n.nid, n.title, b.weight FROM {node} n INNER JOIN {book} b ON n.nid = b.nid WHERE b.parent = %d AND n.status = 1 AND n.moderate = 0 ORDER BY b.weight ASC, n.title ASC'), $node->nid));
if ($child) {
return $child;
}
@ -639,7 +639,7 @@ function book_print($nid = 0, $depth = 1) {
}
function book_print_recurse($parent = '', $depth = 1) {
$result = db_query(node_rewrite_sql("SELECT n.nid, n.title, b.weight FROM {node} n INNER JOIN {book} b ON n.nid = b.nid WHERE n.status = 1 AND b.parent = '$parent' AND n.moderate = 0 ORDER BY b.weight, n.title"));
$result = db_query(node_rewrite_sql('SELECT n.nid, n.title, b.weight FROM {node} n INNER JOIN {book} b ON n.nid = b.nid WHERE n.status = 1 AND b.parent = %d AND n.moderate = 0 ORDER BY b.weight, n.title', $parent));
while ($page = db_fetch_object($result)) {
// Load the node:

View File

@ -106,7 +106,7 @@ function book_menu($may_cache) {
// We don't want to cache these menu items because they could change whenever
// a book page or outline node is edited.
if (arg(0) == 'admin' && arg(1) == 'node' && arg(2) == 'book') {
$result = db_query(node_rewrite_sql("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(node_rewrite_sql('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)) {
$items[] = array('path' => 'admin/node/book/'. $book->nid, 'title' => t('"%title" book', array('%title' => $book->title)));
}
@ -131,7 +131,7 @@ function book_block($op = 'list', $delta = 0) {
else if ($op == 'view') {
// Only display this block when the user is browsing a book:
if (arg(0) == 'node' && is_numeric(arg(1))) {
$result = db_query(node_rewrite_sql("SELECT n.nid, n.title, b.parent FROM {node} n INNER JOIN {book} b ON n.nid = b.nid WHERE n.nid = %d"), arg(1));
$result = db_query(node_rewrite_sql('SELECT n.nid, n.title, b.parent FROM {node} n INNER JOIN {book} b ON n.nid = b.nid WHERE n.nid = %d'), arg(1));
if (db_num_rows($result) > 0) {
$node = db_fetch_object($result);
@ -320,7 +320,7 @@ function book_revision_load($page, $conditions = array()) {
* Return the path (call stack) to a certain book page.
*/
function book_location($node, $nodes = array()) {
$parent = db_fetch_object(db_query(node_rewrite_sql("SELECT n.nid, n.title, b.parent, b.weight FROM {node} n INNER JOIN {book} b ON n.nid = b.nid WHERE n.nid = %d"), $node->parent));
$parent = db_fetch_object(db_query(node_rewrite_sql('SELECT n.nid, n.title, b.parent, b.weight FROM {node} n INNER JOIN {book} b ON n.nid = b.nid WHERE n.nid = %d'), $node->parent));
if ($parent->title) {
$nodes = book_location($parent, $nodes);
array_push($nodes, $parent);
@ -356,7 +356,7 @@ function book_prev($node) {
}
else {
// Direct parent:
$prev = db_fetch_object(db_query(node_rewrite_sql("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"), $node->parent));
$prev = db_fetch_object(db_query(node_rewrite_sql('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'), $node->parent));
return $prev;
}
}
@ -366,7 +366,7 @@ function book_prev($node) {
*/
function book_next($node) {
// get first direct child
$child = db_fetch_object(db_query(node_rewrite_sql("SELECT n.nid, n.title, b.weight FROM {node} n INNER JOIN {book} b ON n.nid = b.nid WHERE b.parent = %d AND n.status = 1 AND n.moderate = 0 ORDER BY b.weight ASC, n.title ASC"), $node->nid));
$child = db_fetch_object(db_query(node_rewrite_sql('SELECT n.nid, n.title, b.weight FROM {node} n INNER JOIN {book} b ON n.nid = b.nid WHERE b.parent = %d AND n.status = 1 AND n.moderate = 0 ORDER BY b.weight ASC, n.title ASC'), $node->nid));
if ($child) {
return $child;
}
@ -639,7 +639,7 @@ function book_print($nid = 0, $depth = 1) {
}
function book_print_recurse($parent = '', $depth = 1) {
$result = db_query(node_rewrite_sql("SELECT n.nid, n.title, b.weight FROM {node} n INNER JOIN {book} b ON n.nid = b.nid WHERE n.status = 1 AND b.parent = '$parent' AND n.moderate = 0 ORDER BY b.weight, n.title"));
$result = db_query(node_rewrite_sql('SELECT n.nid, n.title, b.weight FROM {node} n INNER JOIN {book} b ON n.nid = b.nid WHERE n.status = 1 AND b.parent = %d AND n.moderate = 0 ORDER BY b.weight, n.title', $parent));
while ($page = db_fetch_object($result)) {
// Load the node:

View File

@ -436,14 +436,13 @@ function forum_get_topics($tid, $sortby, $forum_per_page) {
}
$term = taxonomy_get_term($tid);
$check_tid = $tid ? "'". db_escape_string($tid) ."'" : 'NULL';
$sql = node_rewrite_sql("SELECT n.nid, f.tid, n.title, n.sticky, u.name, u.uid, n.created AS timestamp, n.comment AS comment_mode, l.last_comment_timestamp, IF(l.last_comment_uid, cu.name, l.last_comment_name) as last_comment_name, l.last_comment_uid, l.comment_count AS num_comments FROM {node} n, {node_comment_statistics} l, {users} cu, {term_node} r, {users} u, {forum} f WHERE n.status = 1 AND l.last_comment_uid = cu.uid AND n.nid = l.nid AND n.nid = r.nid AND r.tid = $check_tid AND n.uid = u.uid AND n.nid = f.nid");
$sql = node_rewrite_sql("SELECT n.nid, f.tid, n.title, n.sticky, u.name, u.uid, n.created AS timestamp, n.comment AS comment_mode, l.last_comment_timestamp, IF(l.last_comment_uid, cu.name, l.last_comment_name) AS last_comment_name, l.last_comment_uid, l.comment_count AS num_comments FROM {node} n, {node_comment_statistics} l, {users} cu, {term_node} r, {users} u, {forum} f WHERE n.status = 1 AND l.last_comment_uid = cu.uid AND n.nid = l.nid AND n.nid = r.nid AND r.tid = '%s' AND n.uid = u.uid AND n.nid = f.nid");
$sql .= tablesort_sql($forum_topic_list_header, 'n.sticky DESC,');
$sql_count = node_rewrite_sql("SELECT COUNT(n.nid) FROM {node} n INNER JOIN {term_node} r ON n.nid = r.nid AND r.tid = $check_tid WHERE n.status = 1 AND n.type = 'forum'");
$sql_count = node_rewrite_sql("SELECT COUNT(n.nid) FROM {node} n INNER JOIN {term_node} r ON n.nid = r.nid AND r.tid = '%s' WHERE 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, $tid);
while ($topic = db_fetch_object($result)) {
if ($user->uid) {

View File

@ -436,14 +436,13 @@ function forum_get_topics($tid, $sortby, $forum_per_page) {
}
$term = taxonomy_get_term($tid);
$check_tid = $tid ? "'". db_escape_string($tid) ."'" : 'NULL';
$sql = node_rewrite_sql("SELECT n.nid, f.tid, n.title, n.sticky, u.name, u.uid, n.created AS timestamp, n.comment AS comment_mode, l.last_comment_timestamp, IF(l.last_comment_uid, cu.name, l.last_comment_name) as last_comment_name, l.last_comment_uid, l.comment_count AS num_comments FROM {node} n, {node_comment_statistics} l, {users} cu, {term_node} r, {users} u, {forum} f WHERE n.status = 1 AND l.last_comment_uid = cu.uid AND n.nid = l.nid AND n.nid = r.nid AND r.tid = $check_tid AND n.uid = u.uid AND n.nid = f.nid");
$sql = node_rewrite_sql("SELECT n.nid, f.tid, n.title, n.sticky, u.name, u.uid, n.created AS timestamp, n.comment AS comment_mode, l.last_comment_timestamp, IF(l.last_comment_uid, cu.name, l.last_comment_name) AS last_comment_name, l.last_comment_uid, l.comment_count AS num_comments FROM {node} n, {node_comment_statistics} l, {users} cu, {term_node} r, {users} u, {forum} f WHERE n.status = 1 AND l.last_comment_uid = cu.uid AND n.nid = l.nid AND n.nid = r.nid AND r.tid = '%s' AND n.uid = u.uid AND n.nid = f.nid");
$sql .= tablesort_sql($forum_topic_list_header, 'n.sticky DESC,');
$sql_count = node_rewrite_sql("SELECT COUNT(n.nid) FROM {node} n INNER JOIN {term_node} r ON n.nid = r.nid AND r.tid = $check_tid WHERE n.status = 1 AND n.type = 'forum'");
$sql_count = node_rewrite_sql("SELECT COUNT(n.nid) FROM {node} n INNER JOIN {term_node} r ON n.nid = r.nid AND r.tid = '%s' WHERE 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, $tid);
while ($topic = db_fetch_object($result)) {
if ($user->uid) {

View File

@ -1806,7 +1806,7 @@ function node_node_rewrite_sql () {
return $return;
}
/*
/**
* Helper function for node_rewrite_sql.
*
* Collects JOIN and WHERE statements via hook_sql.
@ -1822,7 +1822,6 @@ function node_node_rewrite_sql () {
* An associative array: join => join statements, where => where statements, nid_to_select => nid or DISTINCT(nid)
*/
function _node_rewrite_sql($query = '', $nid_alias = 'n', $args = array()) {
$where = array();
$join = array();
$distinct = FALSE;
@ -1844,13 +1843,13 @@ function _node_rewrite_sql($query = '', $nid_alias = 'n', $args = array()) {
}
}
$swhere = empty($where) ? '' : '('. implode(') AND (',$where).')';
$sjoin = empty($join) ? '' : implode(' ',$join);
$where = empty($where) ? '' : '('. implode(') AND (',$where).')';
$join = empty($join) ? '' : implode(' ',$join);
return array($sjoin, $swhere, $distinct ? 'DISTINCT('.$nid_alias.'.nid)' : $nid_alias.'.nid');
return array($join, $where, $distinct ? 'DISTINCT('. $nid_alias .'.nid)' : $nid_alias .'.nid');
}
/*
/**
* Rewrites node queries.
*
* @param $query
@ -1863,7 +1862,6 @@ function _node_rewrite_sql($query = '', $nid_alias = 'n', $args = array()) {
* The original query with JOIN and WHERE statements inserted from hook_node_rewrite_sql implementations. nid is rewritten if needed.
*/
function node_rewrite_sql($query, $nid_alias = 'n', $args = array()) {
list($join, $where,$nid_to_select) = _node_rewrite_sql($query, $nid_alias, $args);
$query = preg_replace('/(SELECT.*)('. $nid_alias .'\.)?nid(.*FROM)/AUs', '\1'. $nid_to_select .'\3', $query);
@ -1885,8 +1883,9 @@ function node_rewrite_sql($query, $nid_alias = 'n', $args = array()) {
$replace = 'LIMIT';
$add = 'LIMIT';
}
else
else {
$query .= ' WHERE '. $where;
}
if (isset($replace)) {
$query = str_replace($replace, 'WHERE '. $where .' '. $add .' ', $query);
}

View File

@ -1806,7 +1806,7 @@ function node_node_rewrite_sql () {
return $return;
}
/*
/**
* Helper function for node_rewrite_sql.
*
* Collects JOIN and WHERE statements via hook_sql.
@ -1822,7 +1822,6 @@ function node_node_rewrite_sql () {
* An associative array: join => join statements, where => where statements, nid_to_select => nid or DISTINCT(nid)
*/
function _node_rewrite_sql($query = '', $nid_alias = 'n', $args = array()) {
$where = array();
$join = array();
$distinct = FALSE;
@ -1844,13 +1843,13 @@ function _node_rewrite_sql($query = '', $nid_alias = 'n', $args = array()) {
}
}
$swhere = empty($where) ? '' : '('. implode(') AND (',$where).')';
$sjoin = empty($join) ? '' : implode(' ',$join);
$where = empty($where) ? '' : '('. implode(') AND (',$where).')';
$join = empty($join) ? '' : implode(' ',$join);
return array($sjoin, $swhere, $distinct ? 'DISTINCT('.$nid_alias.'.nid)' : $nid_alias.'.nid');
return array($join, $where, $distinct ? 'DISTINCT('. $nid_alias .'.nid)' : $nid_alias .'.nid');
}
/*
/**
* Rewrites node queries.
*
* @param $query
@ -1863,7 +1862,6 @@ function _node_rewrite_sql($query = '', $nid_alias = 'n', $args = array()) {
* The original query with JOIN and WHERE statements inserted from hook_node_rewrite_sql implementations. nid is rewritten if needed.
*/
function node_rewrite_sql($query, $nid_alias = 'n', $args = array()) {
list($join, $where,$nid_to_select) = _node_rewrite_sql($query, $nid_alias, $args);
$query = preg_replace('/(SELECT.*)('. $nid_alias .'\.)?nid(.*FROM)/AUs', '\1'. $nid_to_select .'\3', $query);
@ -1885,8 +1883,9 @@ function node_rewrite_sql($query, $nid_alias = 'n', $args = array()) {
$replace = 'LIMIT';
$add = 'LIMIT';
}
else
else {
$query .= ' WHERE '. $where;
}
if (isset($replace)) {
$query = str_replace($replace, 'WHERE '. $where .' '. $add .' ', $query);
}

View File

@ -126,9 +126,9 @@ function queue_overview() {
$sql = 'SELECT n.nid, n.title, n.type, u.name, u.uid, SUM(IF(q.uid = %d, 1, 0)) AS voted, SUM(q.vote) AS score FROM {node} n INNER JOIN {users} u ON n.uid = u.uid INNER JOIN {queue} q ON n.nid = q.nid WHERE n.moderate = 1 GROUP BY n.nid, n.title, n.type, u.name, u.uid, q.uid, q.vote';
$sql = node_rewrite_sql($sql);
$sql_count = node_rewrite_sql('SELECT COUNT(n.nid) FROM {node} n INNER JOIN {queue} q ON n.nid = q.nid WHERE n.moderate = 1');
$sresult = pager_query($sql, 10, 0,$sql_count , $user->uid);
$result = pager_query($sql, 10, 0, $sql_count, $user->uid);
while ($node = db_fetch_object($sresult)) {
while ($node = db_fetch_object($result)) {
if ($user->uid == $node->uid || $node->voted) {
$rows[] = array(array('data' => l($node->title, 'queue/'. $node->nid), 'class' => 'title'), array('data' => format_name($node), 'class' => 'name'), array('data' => module_invoke($node->type, 'node_name', $node), 'class' => 'type'), array('data' => $node->score, 'class' => 'score'));
}

View File

@ -103,7 +103,7 @@ function taxonomy_block($op = 'list', $delta = 0) {
return $blocks;
}
else if ($op == 'view' && user_access('access content')) {
$result = db_query(node_rewrite_sql("SELECT d.tid, d.name, MAX(n.created) AS updated, COUNT(*) AS count FROM {term_data} d INNER JOIN {term_node} USING (tid) INNER JOIN {node} n USING (nid) WHERE n.status = 1 GROUP BY d.tid, d.name ORDER BY updated DESC, d.name"));
$result = db_query(node_rewrite_sql('SELECT d.tid, d.name, MAX(n.created) AS updated, COUNT(*) AS count FROM {term_data} d INNER JOIN {term_node} USING (tid) INNER JOIN {node} n USING (nid) WHERE n.status = 1 GROUP BY d.tid, d.name ORDER BY updated DESC, d.name'));
$items = array();
while ($category = db_fetch_object($result)) {
$items[] = l($category->name .' ('. $category->count .')', 'taxonomy/term/'. $category->tid) .'<br />'. t('%time ago', array('%time' => format_interval(time() - $category->updated)));

View File

@ -103,7 +103,7 @@ function taxonomy_block($op = 'list', $delta = 0) {
return $blocks;
}
else if ($op == 'view' && user_access('access content')) {
$result = db_query(node_rewrite_sql("SELECT d.tid, d.name, MAX(n.created) AS updated, COUNT(*) AS count FROM {term_data} d INNER JOIN {term_node} USING (tid) INNER JOIN {node} n USING (nid) WHERE n.status = 1 GROUP BY d.tid, d.name ORDER BY updated DESC, d.name"));
$result = db_query(node_rewrite_sql('SELECT d.tid, d.name, MAX(n.created) AS updated, COUNT(*) AS count FROM {term_data} d INNER JOIN {term_node} USING (tid) INNER JOIN {node} n USING (nid) WHERE n.status = 1 GROUP BY d.tid, d.name ORDER BY updated DESC, d.name'));
$items = array();
while ($category = db_fetch_object($result)) {
$items[] = l($category->name .' ('. $category->count .')', 'taxonomy/term/'. $category->tid) .'<br />'. t('%time ago', array('%time' => format_interval(time() - $category->updated)));