// Fetch nodes for the selected date, if one was specified.
$result=db_query_range('SELECT nid FROM {node} WHERE status = 1 AND created > %d AND created < %d ORDER BY created',$date,$date_end,0,20);
$result=db_query_range('SELECT DISTINCT(n.nid) FROM {node} n '.node_access_join_sql().' WHERE n.status = 1 AND n.created > %d AND n.created < %d AND '.node_access_where_sql().' ORDER BY n.created',$date,$date_end,0,20);
// Fetch nodes for the selected date, if one was specified.
$result=db_query_range('SELECT nid FROM {node} WHERE status = 1 AND created > %d AND created < %d ORDER BY created',$date,$date_end,0,20);
$result=db_query_range('SELECT DISTINCT(n.nid) FROM {node} n '.node_access_join_sql().' WHERE n.status = 1 AND n.created > %d AND n.created < %d AND '.node_access_where_sql().' ORDER BY n.created',$date,$date_end,0,20);
$result=pager_query("SELECT nid FROM {node} WHERE type = 'blog' AND uid = %d AND status = 1 ORDER BY sticky DESC, created DESC",variable_get('default_nodes_main',10),0,NULL,$account->uid);
$result=pager_query('SELECT DISTINCT(n.nid) FROM {node} n '.node_access_join_sql()." WHERE type = 'blog' AND n.uid = %d AND n.status = 1 AND ".node_access_where_sql().' ORDER BY n.sticky DESC, n.created DESC',variable_get('default_nodes_main',10),0,NULL,$account->uid);
$result=pager_query("SELECT nid FROM {node} WHERE type = 'blog' AND status = 1 ORDER BY created DESC",variable_get('default_nodes_main',10));
$result=pager_query('SELECT DISTINCT(n.nid) FROM {node} n '.node_access_join_sql()." WHERE n.type = 'blog' AND n.status = 1 AND ".node_access_where_sql().' ORDER BY n.created DESC',variable_get('default_nodes_main',10));
$block['content']=node_title_list(db_query_range("SELECT n.title, n.nid FROM {node} n WHERE n.type = 'blog' AND n.status = 1 ORDER BY n.created DESC",0,10));
$block['content']=node_title_list(db_query_range('SELECT DISTINCT(n.nid), n.title FROM {node} n '.node_access_join_sql()." WHERE n.type = 'blog' AND n.status = 1 AND ".node_access_where_sql().' ORDER BY n.created DESC',0,10));
$block['content'].='<div class="more-link">'.l(t('more'),'blog',array('title'=>t('Read the latest blog entries.'))).'</div>';
$result=pager_query("SELECT nid FROM {node} WHERE type = 'blog' AND uid = %d AND status = 1 ORDER BY sticky DESC, created DESC",variable_get('default_nodes_main',10),0,NULL,$account->uid);
$result=pager_query('SELECT DISTINCT(n.nid) FROM {node} n '.node_access_join_sql()." WHERE type = 'blog' AND n.uid = %d AND n.status = 1 AND ".node_access_where_sql().' ORDER BY n.sticky DESC, n.created DESC',variable_get('default_nodes_main',10),0,NULL,$account->uid);
$result=pager_query("SELECT nid FROM {node} WHERE type = 'blog' AND status = 1 ORDER BY created DESC",variable_get('default_nodes_main',10));
$result=pager_query('SELECT DISTINCT(n.nid) FROM {node} n '.node_access_join_sql()." WHERE n.type = 'blog' AND n.status = 1 AND ".node_access_where_sql().' ORDER BY n.created DESC',variable_get('default_nodes_main',10));
$block['content']=node_title_list(db_query_range("SELECT n.title, n.nid FROM {node} n WHERE n.type = 'blog' AND n.status = 1 ORDER BY n.created DESC",0,10));
$block['content']=node_title_list(db_query_range('SELECT DISTINCT(n.nid), n.title FROM {node} n '.node_access_join_sql()." WHERE n.type = 'blog' AND n.status = 1 AND ".node_access_where_sql().' ORDER BY n.created DESC',0,10));
$block['content'].='<div class="more-link">'.l(t('more'),'blog',array('title'=>t('Read the latest blog entries.'))).'</div>';
$child=db_fetch_object(db_query("SELECT n.nid, n.title FROM {node} n INNER JOIN {book} b ON n.nid = b.nid WHERE b.parent = %d AND n.status = 1 AND (n.moderate = 0 OR n.revisions != '') ORDER BY b.weight ASC, n.title ASC",$node->nid));
$child=db_fetch_object(db_query("SELECT DISTINCT(n.nid), n.title FROM {node} n ".node_access_join_sql()." INNER JOIN {book} b ON n.nid = b.nid WHERE b.parent = %d AND n.status = 1 AND ".node_access_where_sql()." AND (n.moderate = 0 OR n.revisions != '') ORDER BY b.weight ASC, n.title ASC",$node->nid));
if($child){
return$child;
}
...
...
@@ -380,7 +380,7 @@ function book_next($node) {
array_push($path=book_location($node),$node);// Path to top-level node including this one.
while(($leaf=array_pop($path))&&count($path)){
$next=db_fetch_object(db_query("SELECT n.nid, n.title FROM {node} n INNER JOIN {book} b ON n.nid = b.nid WHERE b.parent = %d AND n.status = 1 AND (n.moderate = 0 OR n.revisions != '') AND (b.weight > %d OR (b.weight = %d AND n.title > '%s')) ORDER BY b.weight ASC, n.title ASC",$leaf->parent,$leaf->weight,$leaf->weight,$leaf->title));
$next=db_fetch_object(db_query("SELECT DISTINCT(n.nid), n.title FROM {node} n ".node_access_join_sql()." INNER JOIN {book} b ON n.nid = b.nid WHERE b.parent = %d AND n.status = 1 AND ".node_access_where_sql()." AND (n.moderate = 0 OR n.revisions != '') AND (b.weight > %d OR (b.weight = %d AND n.title > '%s')) ORDER BY b.weight ASC, n.title ASC",$leaf->parent,$leaf->weight,$leaf->weight,$leaf->title));
if($next){
return$next;
}
...
...
@@ -536,7 +536,7 @@ function book_toc_recurse($nid, $indent, $toc, $children) {
$result=db_query('SELECT n.nid, n.title, b.parent FROM {node} n INNER JOIN {book} b ON n.nid = b.nid WHERE n.status = 1 ORDER BY b.weight, n.title');
$result=db_query('SELECT DISTINCT(n.nid), n.title, b.parent FROM {node} n '.node_access_join_sql().' INNER JOIN {book} b ON n.nid = b.nid WHERE n.status = 1 AND '.node_access_where_sql().' ORDER BY b.weight, n.title');
$result=db_query('SELECT n.nid, n.title, b.parent FROM {node} n INNER JOIN {book} b ON n.nid = b.nid WHERE n.status = 1 AND n.moderate = 0 ORDER BY b.weight, n.title');
$result=db_query('SELECT DISTINCT(n.nid), n.title, b.parent FROM {node} n '.node_access_join_sql().' INNER JOIN {book} b ON n.nid = b.nid WHERE n.status = 1 AND '.node_access_where_sql().' AND n.moderate = 0 ORDER BY b.weight, n.title');
$result=db_query('SELECT n.nid FROM {node} n INNER JOIN {book} b ON n.nid = b.nid WHERE n.status = 1 AND n.nid = %d AND (n.moderate = 0 OR n.revisions IS NOT NULL) ORDER BY b.weight, n.title',$nid);
$result=db_query('SELECT DISTINCT(n.nid) FROM {node} n '.node_access_join_sql().' INNER JOIN {book} b ON n.nid = b.nid WHERE n.status = 1 AND '.node_access_where_sql().' AND n.nid = %d AND (n.moderate = 0 OR n.revisions IS NOT NULL) ORDER BY b.weight, n.title',$nid);
$result=db_query("SELECT n.nid FROM {node} n INNER JOIN {book} b ON n.nid = b.nid WHERE n.status = 1 AND b.parent = '$parent' AND (n.moderate = 0 OR n.revisions IS NOT NULL) ORDER BY b.weight, n.title");
$result=db_query("SELECT DISTINCT(n.nid) FROM {node} n ".node_access_join_sql()." INNER JOIN {book} b ON n.nid = b.nid WHERE n.status = 1 AND ".node_access_where_sql()." AND b.parent = '$parent' AND (n.moderate = 0 OR n.revisions IS NOT NULL) ORDER BY b.weight, n.title");
$child=db_fetch_object(db_query("SELECT n.nid, n.title FROM {node} n INNER JOIN {book} b ON n.nid = b.nid WHERE b.parent = %d AND n.status = 1 AND (n.moderate = 0 OR n.revisions != '') ORDER BY b.weight ASC, n.title ASC",$node->nid));
$child=db_fetch_object(db_query("SELECT DISTINCT(n.nid), n.title FROM {node} n ".node_access_join_sql()." INNER JOIN {book} b ON n.nid = b.nid WHERE b.parent = %d AND n.status = 1 AND ".node_access_where_sql()." AND (n.moderate = 0 OR n.revisions != '') ORDER BY b.weight ASC, n.title ASC",$node->nid));
if($child){
return$child;
}
...
...
@@ -380,7 +380,7 @@ function book_next($node) {
array_push($path=book_location($node),$node);// Path to top-level node including this one.
while(($leaf=array_pop($path))&&count($path)){
$next=db_fetch_object(db_query("SELECT n.nid, n.title FROM {node} n INNER JOIN {book} b ON n.nid = b.nid WHERE b.parent = %d AND n.status = 1 AND (n.moderate = 0 OR n.revisions != '') AND (b.weight > %d OR (b.weight = %d AND n.title > '%s')) ORDER BY b.weight ASC, n.title ASC",$leaf->parent,$leaf->weight,$leaf->weight,$leaf->title));
$next=db_fetch_object(db_query("SELECT DISTINCT(n.nid), n.title FROM {node} n ".node_access_join_sql()." INNER JOIN {book} b ON n.nid = b.nid WHERE b.parent = %d AND n.status = 1 AND ".node_access_where_sql()." AND (n.moderate = 0 OR n.revisions != '') AND (b.weight > %d OR (b.weight = %d AND n.title > '%s')) ORDER BY b.weight ASC, n.title ASC",$leaf->parent,$leaf->weight,$leaf->weight,$leaf->title));
if($next){
return$next;
}
...
...
@@ -536,7 +536,7 @@ function book_toc_recurse($nid, $indent, $toc, $children) {
$result=db_query('SELECT n.nid, n.title, b.parent FROM {node} n INNER JOIN {book} b ON n.nid = b.nid WHERE n.status = 1 ORDER BY b.weight, n.title');
$result=db_query('SELECT DISTINCT(n.nid), n.title, b.parent FROM {node} n '.node_access_join_sql().' INNER JOIN {book} b ON n.nid = b.nid WHERE n.status = 1 AND '.node_access_where_sql().' ORDER BY b.weight, n.title');
$result=db_query('SELECT n.nid, n.title, b.parent FROM {node} n INNER JOIN {book} b ON n.nid = b.nid WHERE n.status = 1 AND n.moderate = 0 ORDER BY b.weight, n.title');
$result=db_query('SELECT DISTINCT(n.nid), n.title, b.parent FROM {node} n '.node_access_join_sql().' INNER JOIN {book} b ON n.nid = b.nid WHERE n.status = 1 AND '.node_access_where_sql().' AND n.moderate = 0 ORDER BY b.weight, n.title');
$result=db_query('SELECT n.nid FROM {node} n INNER JOIN {book} b ON n.nid = b.nid WHERE n.status = 1 AND n.nid = %d AND (n.moderate = 0 OR n.revisions IS NOT NULL) ORDER BY b.weight, n.title',$nid);
$result=db_query('SELECT DISTINCT(n.nid) FROM {node} n '.node_access_join_sql().' INNER JOIN {book} b ON n.nid = b.nid WHERE n.status = 1 AND '.node_access_where_sql().' AND n.nid = %d AND (n.moderate = 0 OR n.revisions IS NOT NULL) ORDER BY b.weight, n.title',$nid);
$result=db_query("SELECT n.nid FROM {node} n INNER JOIN {book} b ON n.nid = b.nid WHERE n.status = 1 AND b.parent = '$parent' AND (n.moderate = 0 OR n.revisions IS NOT NULL) ORDER BY b.weight, n.title");
$result=db_query("SELECT DISTINCT(n.nid) FROM {node} n ".node_access_join_sql()." INNER JOIN {book} b ON n.nid = b.nid WHERE n.status = 1 AND ".node_access_where_sql()." AND b.parent = '$parent' AND (n.moderate = 0 OR n.revisions IS NOT NULL) ORDER BY b.weight, n.title");
$content=node_title_list(db_query_range("SELECT n.nid, n.title, GREATEST(n.created, MAX(c.timestamp)) AS sort FROM {node} n LEFT JOIN {comments} c ON n.nid = c.nid WHERE n.type = 'forum' AND n.status = 1 GROUP BY n.nid, n.title, n.created ORDER BY sort DESC",0,variable_get('forum_block_num','5')),t('Active forum topics:'));
$content=node_title_list(db_query_range("SELECT DISTINCT(n.nid), n.title, GREATEST(n.created, MAX(c.timestamp)) AS sort FROM {node} n ".node_access_join_sql()." LEFT JOIN {comments} c ON n.nid = c.nid WHERE n.type = 'forum' AND n.status = 1 AND ".node_access_where_sql()." GROUP BY n.nid, n.title, n.created ORDER BY sort DESC",0,variable_get('forum_block_num','5')),t('Active forum topics:'));
$content.=node_title_list(db_query_range("SELECT nid, title FROM {node} WHERE type = 'forum' AND status = 1 ORDER BY nid DESC",0,variable_get('forum_block_num','5')),t('New forum topics:'));
$content.=node_title_list(db_query_range("SELECT DISTINCT(n.nid), n.title FROM {node} n ".node_access_join_sql()." WHERE n.type = 'forum' AND n.status = 1 AND ".node_access_where_sql()." ORDER BY n.nid DESC",0,variable_get('forum_block_num','5')),t('New forum topics:'));
if($content){
$content.='<div class="more-link">'.l(t('more'),'forum',array('title'=>t('Read the latest forum topics.'))).'</div>';
$result=db_query('SELECT n.nid, n.title, n.sticky, GREATEST(n.created, MAX(c.timestamp)) AS date_sort, COUNT(c.nid) AS num_comments FROM {node} n INNER JOIN {forum} f ON n.nid = f.nid INNER JOIN {comments} c ON n.nid = c.nid WHERE n.nid = f.nid AND f.tid = %d AND n.status = 1 GROUP BY n.nid, n.title, n.created ORDER BY n.sticky DESC, '._forum_get_topic_order(isset($user->sortby)?$user->sortby:variable_get('forum_order',1)),$node->tid);
$result=db_query('SELECT DISTINCT(n.nid), n.title, n.sticky, GREATEST(n.created, MAX(c.timestamp)) AS date_sort, COUNT(c.nid) AS num_comments FROM {node} n '.node_access_join_sql().' INNER JOIN {forum} f ON n.nid = f.nid INNER JOIN {comments} c ON n.nid = c.nid WHERE n.nid = f.nid AND f.tid = %d AND n.status = 1 AND '.node_access_where_sql().' GROUP BY n.nid, n.title, n.created ORDER BY n.sticky DESC, '._forum_get_topic_order(isset($user->sortby)?$user->sortby:variable_get('forum_order',1)),$node->tid);
while($topic=db_fetch_object($result)){
if($stop==1){
...
...
@@ -357,27 +354,27 @@ function forum_get_forums($tid = 0) {
}
function_forum_num_topics($term){
returndb_result(db_query('SELECT COUNT(*) FROM {forum} f INNER JOIN {node} n ON n.nid = f.nid WHERE f.tid = %d AND n.status = 1 AND f.shadow = 0',$term));
returndb_result(db_query('SELECT COUNT(DISTINCT(n.nid)) FROM {forum} f INNER JOIN {node} n ON n.nid = f.nid '.node_access_join_sql().' WHERE f.tid = %d AND n.status = 1 AND '.node_access_where_sql().' AND f.shadow = 0',$term));
}
function_forum_num_replies($term){
returndb_result(db_query("SELECT COUNT(*) AS count FROM {comments} c INNER JOIN {node} n ON n.nid = c.nid INNER JOIN {forum} f ON n.nid = f.nid WHERE f.tid = %d AND n.nid = f.nid AND n.nid = c.nid AND n.status = 1 AND c.status = 0 AND n.type = 'forum'",$term));
returndb_result(db_query('SELECT COUNT(DISTINCT(n.nid)) AS count FROM {comments} c INNER JOIN {node} n ON n.nid = c.nid '.node_access_join_sql().' INNER JOIN {forum} f ON n.nid = f.nid WHERE f.tid = %d AND n.nid = f.nid AND n.nid = c.nid AND n.status = 1 AND '.node_access_where_sql()." AND c.status = 0 AND n.type = 'forum'",$term));
}
function_forum_topics_read($term,$uid){
// Calculate the number of topics the user has read. Assume all entries older
// than NODE_NEW_LIMIT are read, and include the recent posts that user has
// read.
$ancient=db_result(db_query('SELECT COUNT(*) FROM {forum} f INNER JOIN {node} n ON f.nid = n.nid WHERE f.tid = %d AND n.status = 1 AND n.created <= %d AND f.shadow = 0',$term,NODE_NEW_LIMIT));
$recent=db_result(db_query('SELECT COUNT(*) FROM {forum} f INNER JOIN {node} n ON f.nid = n.nid INNER JOIN {history} h ON n.nid = h.nid WHERE n.status = 1 AND f.tid = %d AND h.uid = %d AND n.created > %d AND f.shadow = 0',$term,$uid,NODE_NEW_LIMIT));
$ancient=db_result(db_query('SELECT COUNT(DISTINCT(n.nid)) FROM {forum} f INNER JOIN {node} n ON f.nid = n.nid '.node_access_join_sql().' WHERE f.tid = %d AND n.status = 1 AND '.node_access_where_sql().' AND n.created <= %d AND f.shadow = 0',$term,NODE_NEW_LIMIT));
$recent=db_result(db_query('SELECT COUNT(DISTINCT(n.nid)) FROM {forum} f INNER JOIN {node} n ON f.nid = n.nid '.node_access_join_sql().' INNER JOIN {history} h ON n.nid = h.nid WHERE n.status = 1 AND '.node_access_where_sql().' AND f.tid = %d AND h.uid = %d AND n.created > %d AND f.shadow = 0',$term,$uid,NODE_NEW_LIMIT));
return$ancient+$recent;
}
function_forum_last_post($term){
$topic=db_fetch_object(db_query_range("SELECT n.nid, n.created AS timestamp, u.name AS name, u.uid AS uid FROM {forum} f INNER JOIN {node} n ON n.nid = f.nid INNER JOIN {users} u ON n.uid = u.uid WHERE f.tid = %d AND n.nid = f.nid AND n.type = 'forum' AND n.status = 1 ORDER BY timestamp DESC",$term,0,1));
$topic=db_fetch_object(db_query_range("SELECT DISTINCT(n.nid), n.created AS timestamp, u.name AS name, u.uid AS uid FROM {forum} f INNER JOIN {node} n ON n.nid = f.nid ".node_access_join_sql()." INNER 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 AND ".node_access_where_sql()." ORDER BY timestamp DESC",$term,0,1));
$reply=db_fetch_object(db_query_range("SELECT n.nid, c.timestamp, c.name AS anonymous_name, u.name AS name, u.uid AS uid FROM {forum} f INNER JOIN {node} n ON n.nid = f.nid INNER JOIN {comments} c ON n.nid = c.nid INNER JOIN {users} u ON c.uid = u.uid WHERE f.tid = %d AND n.nid = f.nid AND n.type = 'forum' AND n.status = 1 AND c.status = 0 ORDER BY c.timestamp DESC",$term,0,1));
$reply=db_fetch_object(db_query_range("SELECT DISTINCT(n.nid), c.timestamp, c.name AS anonymous_name, u.name AS name, u.uid AS uid FROM {forum} f INNER JOIN {node} n ON n.nid = f.nid ".node_access_join_sql()." INNER JOIN {comments} c ON n.nid = c.nid INNER 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 ".node_access_where_sql()." AND c.status = 0 ORDER BY c.timestamp DESC",$term,0,1));
@@ -410,10 +407,10 @@ function forum_get_topics($tid, $sortby, $forum_per_page) {
// show topics with the correct tid, or in the forum but with shadow = 1
// @TODO: this is not ANSI SQL! ("user error: 'n.created' isn't in GROUP BY")
// @TODO: timestamp is a sql reserved word. are there more?
$sql="SELECT n.nid, n.title, n.sticky, 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, n.comment AS comment_mode, f.tid FROM {node} n INNER JOIN {term_node} r ON n.nid = r.nid INNER JOIN {users} u ON n.uid = u.uid LEFT JOIN {comments} c ON n.nid = c.nid INNER JOIN {forum} f ON n.nid = f.nid WHERE n.nid = r.nid AND ((r.tid = $check_tid AND f.shadow = 1) OR f.tid = $check_tid) AND n.status = 1 AND n.type = 'forum' GROUP BY n.nid, n.title, u.name, u.uid, n.created, n.comment, f.tid";
$sql="SELECT DISTINCT(n.nid), n.title, n.sticky, 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, n.comment AS comment_mode, f.tid FROM {node} n ".node_access_join_sql()." INNER JOIN {term_node} r ON n.nid = r.nid INNER JOIN {users} u ON n.uid = u.uid LEFT JOIN {comments} c ON n.nid = c.nid INNER JOIN {forum} f ON n.nid = f.nid WHERE n.nid = r.nid AND ((r.tid = $check_tid AND f.shadow = 1) OR f.tid = $check_tid) AND n.status = 1 AND ".node_access_where_sql()." AND n.type = 'forum' GROUP BY n.nid, n.title, u.name, u.uid, n.created, n.comment, f.tid";
$sql_count="SELECT COUNT(DISTINCT(n.nid)) FROM {node} n INNER JOIN {forum} f ON n.nid = f.nid INNER JOIN {term_node} r ON n.nid = r.nid WHERE n.nid = r.nid AND ( (r.tid = $check_tid AND f.shadow = 1) OR f.tid = $check_tid) AND n.status = 1 AND n.type = 'forum'";
$sql_count="SELECT COUNT(DISTINCT(n.nid)) FROM {node} n ".node_access_join_sql()." INNER JOIN {forum} f ON n.nid = f.nid INNER JOIN {term_node} r ON n.nid = r.nid WHERE n.nid = r.nid AND ( (r.tid = $check_tid AND f.shadow = 1) OR f.tid = $check_tid) AND n.status = 1 AND ".node_access_where_sql()." AND n.type = 'forum'";
@@ -427,7 +424,7 @@ function forum_get_topics($tid, $sortby, $forum_per_page) {
$topic->new=0;
}
else{
$topic->new_replies=db_result(db_query('SELECT COUNT(c.nid) FROM {node} n INNER JOIN {comments} c ON n.nid = c.nid WHERE n.nid = %d AND n.status = 1 AND c.status = 0 AND c.timestamp > %d',$topic->nid,$history));
$topic->new_replies=db_result(db_query('SELECT COUNT(DISTINCT(c.nid)) FROM {node} n '.node_access_join_sql().' INNER JOIN {comments} c ON n.nid = c.nid WHERE n.nid = %d AND n.status = 1 AND '.node_access_where_sql().' AND c.status = 0 AND c.timestamp > %d',$topic->nid,$history));
@@ -446,12 +443,12 @@ function forum_get_topics($tid, $sortby, $forum_per_page) {
function_forum_new($tid){
global$user;
$result=db_query("SELECT n.nid FROM {node} n, {history} h, {forum} f WHERE n.type = 'forum' AND n.status = 1 AND h.nid = n.nid AND f.nid = h.nid AND f.tid = %d AND h.uid = %d",$tid,$user->uid);
$result=db_query("SELECT DISTINCT(n.nid) FROM {node} n, {history} h, {forum} f ".node_access_join_sql()." WHERE n.type = 'forum' AND n.status = 1 AND ".node_access_where_sql()." AND h.nid = n.nid AND f.nid = h.nid AND f.tid = %d AND h.uid = %d",$tid,$user->uid);
while($r=db_fetch_object($result)){
$read[]=$r->nid;
}
$nid=db_result(db_query_range("SELECT n.nid FROM {node} n INNER JOIN {forum} f ON n.nid = f.nid WHERE n.type = 'forum' AND f.nid = n.nid AND n.status = 1 AND f.tid = %d ".($read?'AND NOT (n.nid IN ('.implode(',',$read).')) ':'').'ORDER BY created',$tid,0,1));
$nid=db_result(db_query_range("SELECT DISTINCT(n.nid) FROM {node} n ".node_access_join_sql()." INNER JOIN {forum} f ON n.nid = f.nid WHERE n.type = 'forum' AND f.nid = n.nid AND n.status = 1 AND ".node_access_where_sql()." AND f.tid = %d ".($read?'AND NOT (n.nid IN ('.implode(',',$read).')) ':'').'ORDER BY created',$tid,0,1));
$content=node_title_list(db_query_range("SELECT n.nid, n.title, GREATEST(n.created, MAX(c.timestamp)) AS sort FROM {node} n LEFT JOIN {comments} c ON n.nid = c.nid WHERE n.type = 'forum' AND n.status = 1 GROUP BY n.nid, n.title, n.created ORDER BY sort DESC",0,variable_get('forum_block_num','5')),t('Active forum topics:'));
$content=node_title_list(db_query_range("SELECT DISTINCT(n.nid), n.title, GREATEST(n.created, MAX(c.timestamp)) AS sort FROM {node} n ".node_access_join_sql()." LEFT JOIN {comments} c ON n.nid = c.nid WHERE n.type = 'forum' AND n.status = 1 AND ".node_access_where_sql()." GROUP BY n.nid, n.title, n.created ORDER BY sort DESC",0,variable_get('forum_block_num','5')),t('Active forum topics:'));
$content.=node_title_list(db_query_range("SELECT nid, title FROM {node} WHERE type = 'forum' AND status = 1 ORDER BY nid DESC",0,variable_get('forum_block_num','5')),t('New forum topics:'));
$content.=node_title_list(db_query_range("SELECT DISTINCT(n.nid), n.title FROM {node} n ".node_access_join_sql()." WHERE n.type = 'forum' AND n.status = 1 AND ".node_access_where_sql()." ORDER BY n.nid DESC",0,variable_get('forum_block_num','5')),t('New forum topics:'));
if($content){
$content.='<div class="more-link">'.l(t('more'),'forum',array('title'=>t('Read the latest forum topics.'))).'</div>';
$result=db_query('SELECT n.nid, n.title, n.sticky, GREATEST(n.created, MAX(c.timestamp)) AS date_sort, COUNT(c.nid) AS num_comments FROM {node} n INNER JOIN {forum} f ON n.nid = f.nid INNER JOIN {comments} c ON n.nid = c.nid WHERE n.nid = f.nid AND f.tid = %d AND n.status = 1 GROUP BY n.nid, n.title, n.created ORDER BY n.sticky DESC, '._forum_get_topic_order(isset($user->sortby)?$user->sortby:variable_get('forum_order',1)),$node->tid);
$result=db_query('SELECT DISTINCT(n.nid), n.title, n.sticky, GREATEST(n.created, MAX(c.timestamp)) AS date_sort, COUNT(c.nid) AS num_comments FROM {node} n '.node_access_join_sql().' INNER JOIN {forum} f ON n.nid = f.nid INNER JOIN {comments} c ON n.nid = c.nid WHERE n.nid = f.nid AND f.tid = %d AND n.status = 1 AND '.node_access_where_sql().' GROUP BY n.nid, n.title, n.created ORDER BY n.sticky DESC, '._forum_get_topic_order(isset($user->sortby)?$user->sortby:variable_get('forum_order',1)),$node->tid);
while($topic=db_fetch_object($result)){
if($stop==1){
...
...
@@ -357,27 +354,27 @@ function forum_get_forums($tid = 0) {
}
function_forum_num_topics($term){
returndb_result(db_query('SELECT COUNT(*) FROM {forum} f INNER JOIN {node} n ON n.nid = f.nid WHERE f.tid = %d AND n.status = 1 AND f.shadow = 0',$term));
returndb_result(db_query('SELECT COUNT(DISTINCT(n.nid)) FROM {forum} f INNER JOIN {node} n ON n.nid = f.nid '.node_access_join_sql().' WHERE f.tid = %d AND n.status = 1 AND '.node_access_where_sql().' AND f.shadow = 0',$term));
}
function_forum_num_replies($term){
returndb_result(db_query("SELECT COUNT(*) AS count FROM {comments} c INNER JOIN {node} n ON n.nid = c.nid INNER JOIN {forum} f ON n.nid = f.nid WHERE f.tid = %d AND n.nid = f.nid AND n.nid = c.nid AND n.status = 1 AND c.status = 0 AND n.type = 'forum'",$term));
returndb_result(db_query('SELECT COUNT(DISTINCT(n.nid)) AS count FROM {comments} c INNER JOIN {node} n ON n.nid = c.nid '.node_access_join_sql().' INNER JOIN {forum} f ON n.nid = f.nid WHERE f.tid = %d AND n.nid = f.nid AND n.nid = c.nid AND n.status = 1 AND '.node_access_where_sql()." AND c.status = 0 AND n.type = 'forum'",$term));
}
function_forum_topics_read($term,$uid){
// Calculate the number of topics the user has read. Assume all entries older
// than NODE_NEW_LIMIT are read, and include the recent posts that user has
// read.
$ancient=db_result(db_query('SELECT COUNT(*) FROM {forum} f INNER JOIN {node} n ON f.nid = n.nid WHERE f.tid = %d AND n.status = 1 AND n.created <= %d AND f.shadow = 0',$term,NODE_NEW_LIMIT));
$recent=db_result(db_query('SELECT COUNT(*) FROM {forum} f INNER JOIN {node} n ON f.nid = n.nid INNER JOIN {history} h ON n.nid = h.nid WHERE n.status = 1 AND f.tid = %d AND h.uid = %d AND n.created > %d AND f.shadow = 0',$term,$uid,NODE_NEW_LIMIT));
$ancient=db_result(db_query('SELECT COUNT(DISTINCT(n.nid)) FROM {forum} f INNER JOIN {node} n ON f.nid = n.nid '.node_access_join_sql().' WHERE f.tid = %d AND n.status = 1 AND '.node_access_where_sql().' AND n.created <= %d AND f.shadow = 0',$term,NODE_NEW_LIMIT));
$recent=db_result(db_query('SELECT COUNT(DISTINCT(n.nid)) FROM {forum} f INNER JOIN {node} n ON f.nid = n.nid '.node_access_join_sql().' INNER JOIN {history} h ON n.nid = h.nid WHERE n.status = 1 AND '.node_access_where_sql().' AND f.tid = %d AND h.uid = %d AND n.created > %d AND f.shadow = 0',$term,$uid,NODE_NEW_LIMIT));
return$ancient+$recent;
}
function_forum_last_post($term){
$topic=db_fetch_object(db_query_range("SELECT n.nid, n.created AS timestamp, u.name AS name, u.uid AS uid FROM {forum} f INNER JOIN {node} n ON n.nid = f.nid INNER JOIN {users} u ON n.uid = u.uid WHERE f.tid = %d AND n.nid = f.nid AND n.type = 'forum' AND n.status = 1 ORDER BY timestamp DESC",$term,0,1));
$topic=db_fetch_object(db_query_range("SELECT DISTINCT(n.nid), n.created AS timestamp, u.name AS name, u.uid AS uid FROM {forum} f INNER JOIN {node} n ON n.nid = f.nid ".node_access_join_sql()." INNER 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 AND ".node_access_where_sql()." ORDER BY timestamp DESC",$term,0,1));
$reply=db_fetch_object(db_query_range("SELECT n.nid, c.timestamp, c.name AS anonymous_name, u.name AS name, u.uid AS uid FROM {forum} f INNER JOIN {node} n ON n.nid = f.nid INNER JOIN {comments} c ON n.nid = c.nid INNER JOIN {users} u ON c.uid = u.uid WHERE f.tid = %d AND n.nid = f.nid AND n.type = 'forum' AND n.status = 1 AND c.status = 0 ORDER BY c.timestamp DESC",$term,0,1));
$reply=db_fetch_object(db_query_range("SELECT DISTINCT(n.nid), c.timestamp, c.name AS anonymous_name, u.name AS name, u.uid AS uid FROM {forum} f INNER JOIN {node} n ON n.nid = f.nid ".node_access_join_sql()." INNER JOIN {comments} c ON n.nid = c.nid INNER 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 ".node_access_where_sql()." AND c.status = 0 ORDER BY c.timestamp DESC",$term,0,1));
@@ -410,10 +407,10 @@ function forum_get_topics($tid, $sortby, $forum_per_page) {
// show topics with the correct tid, or in the forum but with shadow = 1
// @TODO: this is not ANSI SQL! ("user error: 'n.created' isn't in GROUP BY")
// @TODO: timestamp is a sql reserved word. are there more?
$sql="SELECT n.nid, n.title, n.sticky, 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, n.comment AS comment_mode, f.tid FROM {node} n INNER JOIN {term_node} r ON n.nid = r.nid INNER JOIN {users} u ON n.uid = u.uid LEFT JOIN {comments} c ON n.nid = c.nid INNER JOIN {forum} f ON n.nid = f.nid WHERE n.nid = r.nid AND ((r.tid = $check_tid AND f.shadow = 1) OR f.tid = $check_tid) AND n.status = 1 AND n.type = 'forum' GROUP BY n.nid, n.title, u.name, u.uid, n.created, n.comment, f.tid";
$sql="SELECT DISTINCT(n.nid), n.title, n.sticky, 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, n.comment AS comment_mode, f.tid FROM {node} n ".node_access_join_sql()." INNER JOIN {term_node} r ON n.nid = r.nid INNER JOIN {users} u ON n.uid = u.uid LEFT JOIN {comments} c ON n.nid = c.nid INNER JOIN {forum} f ON n.nid = f.nid WHERE n.nid = r.nid AND ((r.tid = $check_tid AND f.shadow = 1) OR f.tid = $check_tid) AND n.status = 1 AND ".node_access_where_sql()." AND n.type = 'forum' GROUP BY n.nid, n.title, u.name, u.uid, n.created, n.comment, f.tid";
$sql_count="SELECT COUNT(DISTINCT(n.nid)) FROM {node} n INNER JOIN {forum} f ON n.nid = f.nid INNER JOIN {term_node} r ON n.nid = r.nid WHERE n.nid = r.nid AND ( (r.tid = $check_tid AND f.shadow = 1) OR f.tid = $check_tid) AND n.status = 1 AND n.type = 'forum'";
$sql_count="SELECT COUNT(DISTINCT(n.nid)) FROM {node} n ".node_access_join_sql()." INNER JOIN {forum} f ON n.nid = f.nid INNER JOIN {term_node} r ON n.nid = r.nid WHERE n.nid = r.nid AND ( (r.tid = $check_tid