$auth_sql .= ( $auth_sql != '' ) ? " AND f.forum_id NOT IN ($ignore_forum_sql) " : "f.forum_id NOT IN ($ignore_forum_sql) ";
}
}
if ( $recent_author == '' && $auth_sql == '' )
{
$sql = "SELECT topic_id FROM " . POSTS_TABLE . "
WHERE post_id IN (" . implode(", ", $recent_ids) . ")
$where_sql GROUP BY topic_id";
}
else
{
$from_sql = POSTS_TABLE . " p";
if ( $auth_sql != '' )
{
$from_sql .= ", " . FORUMS_TABLE . " f";
$where_sql .= " AND f.forum_id = p.forum_id AND $auth_sql";
}
$sql = "SELECT p.topic_id FROM $from_sql
WHERE p.post_id IN (" . implode(", ", $recent_ids) . ")
$where_sql GROUP BY p.topic_id";
}
if ( !($result = $db->sql_query($sql)) )
{
message_die(GENERAL_ERROR, 'Could not obtain topic ids', '', __LINE__, __FILE__, $sql);
}
$recent_ids = array();
while( $row = $db->sql_fetchrow($result) )
{
$recent_ids[] = $row['topic_id'];
}
$db->sql_freeresult($result);
$auth_results = implode(', ', $recent_ids);
$where_part1 = ( $special_forums == '0' ) ? 't.topic_id IN ('.$auth_results.')' : 'f.forum_id IN ('.$forums.')';
$part1 = "SELECT from_unixtime(p.post_time, '%d.%m.%y %H:%i:%s') as topic_time, f.forum_name as forum_name, f.forum_id as forum_id,
u.username as username, u2.username as username2, u2.user_id as user_id2, p.poster_id as poster_id, p.post_username as post_username, p.post_id as post_id, t.*, p.post_time as post_time
FROM ".TOPICS_TABLE." t, ".POSTS_TABLE." p
LEFT OUTER JOIN ".FORUMS_TABLE." f on p.forum_id = f.forum_id
LEFT OUTER JOIN ".USERS_TABLE." u on p.poster_id = u.user_id
LEFT OUTER JOIN ".USERS_TABLE." u2 on u2.user_id = t.topic_poster
WHERE $where_part1 AND p.post_id = t.topic_last_post_id AND ";
$part2 = " ORDER BY p.post_time desc LIMIT $start, ".$board_config['topics_per_page'];
$sql = "SELECT count(*) AS total FROM ".TOPICS_TABLE." t , ".POSTS_TABLE." p $select_special $where AND p.post_id = t.topic_last_post_id $where_special";
if ( !($result = $db->sql_query($sql)) )
{
message_die(GENERAL_ERROR, 'Error getting total topics', '', __LINE__, __FILE__, $sql);