- seperate queries and cached queries

- display correct read/unread information while displaying active topics
- fix for SELECT DISTINCT in mssql using sql_query_limit
- fix for forum updating in ACP using mssql (and probably other dbal having problems with primary keys in updates)


git-svn-id: file:///svn/phpbb/trunk@5940 89ea8834-ac86-4346-8a33-228a782c2dd0
This commit is contained in:
Meik Sievertsen 2006-05-20 13:20:38 +00:00
parent c81a44ea30
commit 0115e94cfd
12 changed files with 452 additions and 364 deletions

View file

@ -952,11 +952,18 @@ class acp_forums
$db->sql_query($sql); $db->sql_query($sql);
} }
// Setting the forum id to the forum id is not really received well by some dbs. ;)
$forum_id = $forum_data['forum_id'];
unset($forum_data['forum_id']);
$sql = 'UPDATE ' . FORUMS_TABLE . ' $sql = 'UPDATE ' . FORUMS_TABLE . '
SET ' . $db->sql_build_array('UPDATE', $forum_data) . ' SET ' . $db->sql_build_array('UPDATE', $forum_data) . '
WHERE forum_id = ' . $forum_data['forum_id']; WHERE forum_id = ' . $forum_id;
$db->sql_query($sql); $db->sql_query($sql);
// Add it back
$forum_data['forum_id'] = $forum_id;
add_log('admin', 'LOG_FORUM_EDIT', $forum_data['forum_name']); add_log('admin', 'LOG_FORUM_EDIT', $forum_data['forum_name']);
} }
} }

View file

@ -19,20 +19,31 @@ class dbal
var $return_on_error = false; var $return_on_error = false;
var $transaction = false; var $transaction = false;
var $sql_time = 0; var $sql_time = 0;
var $num_queries = 0; var $num_queries = array();
var $open_queries = array(); var $open_queries = array();
var $curtime = 0; var $curtime = 0;
var $query_hold = ''; var $query_hold = '';
var $html_hold = ''; var $html_hold = '';
var $sql_report = ''; var $sql_report = '';
var $cache_num_queries = 0;
var $persistency = false; var $persistency = false;
var $user = ''; var $user = '';
var $server = ''; var $server = '';
var $dbname = ''; var $dbname = '';
/**
* Constructor
*/
function dbal()
{
$this->num_queries = array(
'cached' => 0,
'normal' => 0,
'total' => 0,
);
}
/** /**
* return on error or display error message * return on error or display error message
*/ */
@ -42,11 +53,21 @@ class dbal
} }
/** /**
* Return number of sql queries used (cached and real queries are counted the same) * Return number of sql queries and cached sql queries used
*/ */
function sql_num_queries() function sql_num_queries($cached = false)
{ {
return $this->num_queries; return ($cached) ? $this->num_queries['cached'] : $this->num_queries['normal'];
}
/**
* Add to query count
*/
function sql_add_num_queries($cached = false)
{
$this->num_queries['cached'] += ($cached) ? 1 : 0;
$this->num_queries['normal'] += ($cached) ? 0 : 1;
$this->num_queries['total'] += 1;
} }
/** /**
@ -360,7 +381,7 @@ class dbal
<div id="content"> <div id="content">
<h1>SQL Report</h1> <h1>SQL Report</h1>
<br /> <br />
<p><b>Page generated in ' . round($totaltime, 4) . " seconds with {$this->num_queries} queries" . (($this->cache_num_queries) ? " + {$this->cache_num_queries} " . (($this->cache_num_queries == 1) ? 'query' : 'queries') . ' returning data from cache' : '') . '</b></p> <p><b>Page generated in ' . round($totaltime, 4) . " seconds with {$this->num_queries['normal']} queries" . (($this->num_queries['cached']) ? " + {$this->num_queries['cached']} " . (($this->num_queries['cached'] == 1) ? 'query' : 'queries') . ' returning data from cache' : '') . '</b></p>
<p>Time spent on ' . SQL_LAYER . ' queries: <b>' . round($this->sql_time, 5) . 's</b> | Time spent on PHP: <b>' . round($totaltime - $this->sql_time, 5) . 's</b></p> <p>Time spent on ' . SQL_LAYER . ' queries: <b>' . round($this->sql_time, 5) . 's</b> | Time spent on PHP: <b>' . round($totaltime - $this->sql_time, 5) . 's</b></p>
@ -388,7 +409,7 @@ class dbal
<table cellspacing="1"> <table cellspacing="1">
<thead> <thead>
<tr> <tr>
<th>Query #' . $this->num_queries . '</th> <th>Query #' . $this->num_queries['total'] . '</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@ -466,7 +487,7 @@ class dbal
$this->_sql_report($mode, $query); $this->_sql_report($mode, $query);
$this->cache_num_queries++; // $this->num_queries['cache']++;
break; break;

View file

@ -94,11 +94,10 @@ class dbal_firebird extends dbal
$this->last_query_text = $query; $this->last_query_text = $query;
$this->query_result = ($cache_ttl && method_exists($cache, 'sql_load')) ? $cache->sql_load($query) : false; $this->query_result = ($cache_ttl && method_exists($cache, 'sql_load')) ? $cache->sql_load($query) : false;
$this->sql_add_num_queries($this->query_result);
if (!$this->query_result) if (!$this->query_result)
{ {
$this->num_queries++;
if (($this->query_result = @ibase_query($this->db_connect_id, $query)) === false) if (($this->query_result = @ibase_query($this->db_connect_id, $query)) === false)
{ {
$this->sql_error($query); $this->sql_error($query);

View file

@ -105,10 +105,10 @@ class dbal_mssql extends dbal
} }
$this->query_result = ($cache_ttl && method_exists($cache, 'sql_load')) ? $cache->sql_load($query) : false; $this->query_result = ($cache_ttl && method_exists($cache, 'sql_load')) ? $cache->sql_load($query) : false;
$this->sql_add_num_queries($this->query_result);
if (!$this->query_result) if (!$this->query_result)
{ {
$this->num_queries++;
if (($this->query_result = @mssql_query($query, $this->db_connect_id)) === false) if (($this->query_result = @mssql_query($query, $this->db_connect_id)) === false)
{ {
$this->sql_error($query); $this->sql_error($query);
@ -160,7 +160,14 @@ class dbal_mssql extends dbal
$row_offset = ($total) ? $offset : ''; $row_offset = ($total) ? $offset : '';
$num_rows = ($total) ? $total : $offset; $num_rows = ($total) ? $total : $offset;
$query = 'SELECT TOP ' . ($row_offset + $num_rows) . ' ' . substr($query, 6); if (strpos($query, 'SELECT DISTINCT') === 0)
{
$query = 'SELECT DISTINCT TOP ' . ($row_offset + $num_rows) . ' ' . substr($query, 15);
}
else
{
$query = 'SELECT TOP ' . ($row_offset + $num_rows) . ' ' . substr($query, 6);
}
return $this->sql_query($query, $cache_ttl); return $this->sql_query($query, $cache_ttl);
} }

View file

@ -104,11 +104,10 @@ class dbal_mssql_odbc extends dbal
$this->last_query_text = $query; $this->last_query_text = $query;
$this->query_result = ($cache_ttl && method_exists($cache, 'sql_load')) ? $cache->sql_load($query) : false; $this->query_result = ($cache_ttl && method_exists($cache, 'sql_load')) ? $cache->sql_load($query) : false;
$this->sql_add_num_queries($this->query_result);
if (!$this->query_result) if (!$this->query_result)
{ {
$this->num_queries++;
if (($this->query_result = @odbc_exec($this->db_connect_id, $query)) === false) if (($this->query_result = @odbc_exec($this->db_connect_id, $query)) === false)
{ {
$this->sql_error($query); $this->sql_error($query);
@ -160,7 +159,14 @@ class dbal_mssql_odbc extends dbal
$row_offset = ($total) ? $offset : ''; $row_offset = ($total) ? $offset : '';
$num_rows = ($total) ? $total : $offset; $num_rows = ($total) ? $total : $offset;
$query = 'SELECT TOP ' . ($row_offset + $num_rows) . ' ' . substr($query, 6); if (strpos($query, 'SELECT DISTINCT') === 0)
{
$query = 'SELECT DISTINCT TOP ' . ($row_offset + $num_rows) . ' ' . substr($query, 15);
}
else
{
$query = 'SELECT TOP ' . ($row_offset + $num_rows) . ' ' . substr($query, 6);
}
return $this->sql_query($query, $cache_ttl); return $this->sql_query($query, $cache_ttl);
} }

View file

@ -105,11 +105,10 @@ class dbal_mysql extends dbal
} }
$this->query_result = ($cache_ttl && method_exists($cache, 'sql_load')) ? $cache->sql_load($query) : false; $this->query_result = ($cache_ttl && method_exists($cache, 'sql_load')) ? $cache->sql_load($query) : false;
$this->sql_add_num_queries($this->query_result);
if (!$this->query_result) if (!$this->query_result)
{ {
$this->num_queries++;
if (($this->query_result = @mysql_query($query, $this->db_connect_id)) === false) if (($this->query_result = @mysql_query($query, $this->db_connect_id)) === false)
{ {
$this->sql_error($query); $this->sql_error($query);

View file

@ -107,11 +107,10 @@ class dbal_mysql4 extends dbal
} }
$this->query_result = ($cache_ttl && method_exists($cache, 'sql_load')) ? $cache->sql_load($query) : false; $this->query_result = ($cache_ttl && method_exists($cache, 'sql_load')) ? $cache->sql_load($query) : false;
$this->sql_add_num_queries($this->query_result);
if (!$this->query_result) if (!$this->query_result)
{ {
$this->num_queries++;
if (($this->query_result = @mysql_query($query, $this->db_connect_id)) === false) if (($this->query_result = @mysql_query($query, $this->db_connect_id)) === false)
{ {
$this->sql_error($query); $this->sql_error($query);

View file

@ -110,11 +110,10 @@ class dbal_mysqli extends dbal
} }
$this->query_result = ($cache_ttl && method_exists($cache, 'sql_load')) ? $cache->sql_load($query) : false; $this->query_result = ($cache_ttl && method_exists($cache, 'sql_load')) ? $cache->sql_load($query) : false;
$this->sql_add_num_queries($this->query_result);
if (!$this->query_result) if (!$this->query_result)
{ {
$this->num_queries++;
if (($this->query_result = @mysqli_query($this->db_connect_id, $query)) === false) if (($this->query_result = @mysqli_query($this->db_connect_id, $query)) === false)
{ {
$this->sql_error($query); $this->sql_error($query);

View file

@ -99,11 +99,10 @@ class dbal_oracle extends dbal
$this->last_query_text = $query; $this->last_query_text = $query;
$this->query_result = ($cache_ttl && method_exists($cache, 'sql_load')) ? $cache->sql_load($query) : false; $this->query_result = ($cache_ttl && method_exists($cache, 'sql_load')) ? $cache->sql_load($query) : false;
$this->sql_add_num_queries($this->query_result);
if (!$this->query_result) if (!$this->query_result)
{ {
$this->num_queries++;
$in_transaction = false; $in_transaction = false;
if (!$this->transaction) if (!$this->transaction)
{ {

View file

@ -136,11 +136,10 @@ class dbal_postgres extends dbal
$this->last_query_text = $query; $this->last_query_text = $query;
$this->query_result = ($cache_ttl && method_exists($cache, 'sql_load')) ? $cache->sql_load($query) : false; $this->query_result = ($cache_ttl && method_exists($cache, 'sql_load')) ? $cache->sql_load($query) : false;
$this->sql_add_num_queries($this->query_result);
if (!$this->query_result) if (!$this->query_result)
{ {
$this->num_queries++;
if (($this->query_result = @pg_query($this->db_connect_id, $query)) === false) if (($this->query_result = @pg_query($this->db_connect_id, $query)) === false)
{ {
$this->sql_error($query); $this->sql_error($query);

View file

@ -102,11 +102,10 @@ class dbal_sqlite extends dbal
} }
$this->query_result = ($cache_ttl && method_exists($cache, 'sql_load')) ? $cache->sql_load($query) : false; $this->query_result = ($cache_ttl && method_exists($cache, 'sql_load')) ? $cache->sql_load($query) : false;
$this->sql_add_num_queries($this->query_result);
if (!$this->query_result) if (!$this->query_result)
{ {
$this->num_queries++;
if (($this->query_result = @sqlite_query($query, $this->db_connect_id)) === false) if (($this->query_result = @sqlite_query($query, $this->db_connect_id)) === false)
{ {
$this->sql_error($query); $this->sql_error($query);

View file

@ -131,239 +131,302 @@ else
get_moderators($moderators, $forum_id); get_moderators($moderators, $forum_id);
} }
// Output forum listing if it is postable or active topics // Dump out the page header and load viewforum template
if ($forum_data['forum_type'] == FORUM_POST || (($forum_data['forum_flags'] & 16) && $forum_data['forum_type'] == FORUM_CAT)) page_header($user->lang['VIEW_FORUM'] . ' - ' . $forum_data['forum_name']);
$template->set_filenames(array(
'body' => 'viewforum_body.html')
);
make_jumpbox("{$phpbb_root_path}viewforum.$phpEx$SID", $forum_id);
// Not postable forum or showing active topics?
if (!($forum_data['forum_type'] == FORUM_POST || (($forum_data['forum_flags'] & 16) && $forum_data['forum_type'] == FORUM_CAT)))
{ {
// Handle marking posts page_footer();
if ($mark_read == 'topics') }
// Handle marking posts
if ($mark_read == 'topics')
{
markread('topics', $forum_id);
$redirect_url = "{$phpbb_root_path}viewforum.$phpEx$SID&amp;f=$forum_id";
meta_refresh(3, $redirect_url);
trigger_error($user->lang['TOPICS_MARKED'] . '<br /><br />' . sprintf($user->lang['RETURN_FORUM'], '<a href="' . $redirect_url . '">', '</a>'));
}
// Is a forum specific topic count required?
if ($forum_data['forum_topics_per_page'])
{
$config['topics_per_page'] = $forum_data['forum_topics_per_page'];
}
// Do the forum Prune thang - cron type job ...
if ($forum_data['prune_next'] < time() && $forum_data['enable_prune'])
{
$template->assign_var('RUN_CRON_TASK', '<img src="' . $phpbb_root_path . 'cron.' . $phpEx . '?cron_type=prune_forum&amp;f=' . $forum_id . '" width="1" height="1" />');
}
// Forum rules and subscription info
$s_watching_forum = $s_watching_forum_img = array();
$s_watching_forum['link'] = $s_watching_forum['title'] = '';
if (($config['email_enable'] || $config['jab_enable']) && $config['allow_forum_notify'] && $auth->acl_get('f_subscribe', $forum_id))
{
$notify_status = (isset($forum_data['notify_status'])) ? $forum_data['notify_status'] : NULL;
watch_topic_forum('forum', $s_watching_forum, $s_watching_forum_img, $user->data['user_id'], $forum_id, 0, $notify_status);
}
$s_forum_rules = '';
gen_forum_auth_level('forum', $forum_id, $forum_data['forum_status']);
// Topic ordering options
$limit_days = array(0 => $user->lang['ALL_TOPICS'], 1 => $user->lang['1_DAY'], 7 => $user->lang['7_DAYS'], 14 => $user->lang['2_WEEKS'], 30 => $user->lang['1_MONTH'], 90 => $user->lang['3_MONTHS'], 180 => $user->lang['6_MONTHS'], 365 => $user->lang['1_YEAR']);
$sort_by_text = array('a' => $user->lang['AUTHOR'], 't' => $user->lang['POST_TIME'], 'r' => $user->lang['REPLIES'], 's' => $user->lang['SUBJECT'], 'v' => $user->lang['VIEWS']);
$sort_by_sql = array('a' => 't.topic_first_poster_name', 't' => 't.topic_last_post_time', 'r' => 't.topic_replies', 's' => 't.topic_title', 'v' => 't.topic_views');
$sort_key = (!in_array($sort_key, array('a', 't', 'r', 's', 'v'))) ? 't' : $sort_key;
$s_limit_days = $s_sort_key = $s_sort_dir = $u_sort_param = '';
gen_sort_selects($limit_days, $sort_by_text, $sort_days, $sort_key, $sort_dir, $s_limit_days, $s_sort_key, $s_sort_dir, $u_sort_param);
// Limit topics to certain time frame, obtain correct topic count
if ($sort_days)
{
$min_post_time = time() - ($sort_days * 86400);
$sql = 'SELECT COUNT(topic_id) AS num_topics
FROM ' . TOPICS_TABLE . "
WHERE forum_id = $forum_id
AND topic_type NOT IN (" . POST_ANNOUNCE . ', ' . POST_GLOBAL . ")
AND topic_last_post_time >= $min_post_time
" . (($auth->acl_get('m_approve', $forum_id)) ? '' : 'AND topic_approved = 1');
$result = $db->sql_query($sql);
$topics_count = (int) $db->sql_fetchfield('num_topics');
$db->sql_freeresult($result);
if (isset($_POST['sort']))
{ {
markread('topics', $forum_id); $start = 0;
meta_refresh(3, "viewforum.$phpEx$SID&amp;f=$forum_id");
$message = $user->lang['TOPICS_MARKED'] . '<br /><br />' . sprintf($user->lang['RETURN_FORUM'], '<a href="' . "viewforum.$phpEx$SID&amp;f=$forum_id" . '">', '</a> ');
trigger_error($message);
} }
$sql_limit_time = "AND t.topic_last_post_time >= $min_post_time";
// Is a forum specific topic count required? }
if ($forum_data['forum_topics_per_page']) else
{
if ($auth->acl_get('m_approve', $forum_id))
{ {
$config['topics_per_page'] = $forum_data['forum_topics_per_page']; $topics_count = ($forum_data['forum_topics_real']) ? $forum_data['forum_topics_real'] : 1;
}
// Do the forum Prune thang - cron type job ...
if ($forum_data['prune_next'] < time() && $forum_data['enable_prune'])
{
$template->assign_var('RUN_CRON_TASK', '<img src="' . $phpbb_root_path . 'cron.' . $phpEx . '?cron_type=prune_forum&amp;f=' . $forum_id . '" width="1" height="1" />');
}
// Forum rules amd subscription info
$s_watching_forum = $s_watching_forum_img = array();
$s_watching_forum['link'] = $s_watching_forum['title'] = '';
if (($config['email_enable'] || $config['jab_enable']) && $config['allow_forum_notify'] && $auth->acl_get('f_subscribe', $forum_id))
{
$notify_status = (isset($forum_data['notify_status'])) ? $forum_data['notify_status'] : NULL;
watch_topic_forum('forum', $s_watching_forum, $s_watching_forum_img, $user->data['user_id'], $forum_id, 0, $notify_status);
}
$s_forum_rules = '';
gen_forum_auth_level('forum', $forum_id, $forum_data['forum_status']);
// Topic ordering options
$limit_days = array(0 => $user->lang['ALL_TOPICS'], 1 => $user->lang['1_DAY'], 7 => $user->lang['7_DAYS'], 14 => $user->lang['2_WEEKS'], 30 => $user->lang['1_MONTH'], 90 => $user->lang['3_MONTHS'], 180 => $user->lang['6_MONTHS'], 365 => $user->lang['1_YEAR']);
$sort_by_text = array('a' => $user->lang['AUTHOR'], 't' => $user->lang['POST_TIME'], 'r' => $user->lang['REPLIES'], 's' => $user->lang['SUBJECT'], 'v' => $user->lang['VIEWS']);
$sort_by_sql = array('a' => 't.topic_first_poster_name', 't' => 't.topic_last_post_time', 'r' => 't.topic_replies', 's' => 't.topic_title', 'v' => 't.topic_views');
$sort_key = (!in_array($sort_key, array('a', 't', 'r', 's', 'v'))) ? 't' : $sort_key;
$s_limit_days = $s_sort_key = $s_sort_dir = $u_sort_param = '';
gen_sort_selects($limit_days, $sort_by_text, $sort_days, $sort_key, $sort_dir, $s_limit_days, $s_sort_key, $s_sort_dir, $u_sort_param);
// Limit topics to certain time frame, obtain correct topic count
if ($sort_days)
{
$min_post_time = time() - ($sort_days * 86400);
$sql = 'SELECT COUNT(topic_id) AS num_topics
FROM ' . TOPICS_TABLE . "
WHERE forum_id = $forum_id
AND topic_type NOT IN (" . POST_ANNOUNCE . ', ' . POST_GLOBAL . ")
AND topic_last_post_time >= $min_post_time
" . (($auth->acl_get('m_approve', $forum_id)) ? '' : 'AND topic_approved = 1');
$result = $db->sql_query($sql);
if (isset($_POST['sort']))
{
$start = 0;
}
$topics_count = ($row = $db->sql_fetchrow($result)) ? $row['num_topics'] : 0;
$sql_limit_time = "AND t.topic_last_post_time >= $min_post_time";
} }
else else
{ {
if ($auth->acl_get('m_approve', $forum_id)) $topics_count = ($forum_data['forum_topics']) ? $forum_data['forum_topics'] : 1;
{
$topics_count = ($forum_data['forum_topics_real']) ? $forum_data['forum_topics_real'] : 1;
}
else
{
$topics_count = ($forum_data['forum_topics']) ? $forum_data['forum_topics'] : 1;
}
$sql_limit_time = '';
} }
// Basic pagewide vars $sql_limit_time = '';
$post_alt = ($forum_data['forum_status'] == ITEM_LOCKED) ? $user->lang['FORUM_LOCKED'] : $user->lang['POST_NEW_TOPIC']; }
$template->assign_vars(array( // Basic pagewide vars
'PAGINATION' => generate_pagination("{$phpbb_root_path}viewforum.$phpEx$SID&amp;f=$forum_id&amp;$u_sort_param", $topics_count, $config['topics_per_page'], $start), $post_alt = ($forum_data['forum_status'] == ITEM_LOCKED) ? $user->lang['FORUM_LOCKED'] : $user->lang['POST_NEW_TOPIC'];
'PAGE_NUMBER' => on_page($topics_count, $config['topics_per_page'], $start),
'TOTAL_TOPICS' => ($forum_data['forum_flags'] & 16 && $forum_data['forum_type'] == FORUM_CAT) ? false : (($topics_count == 1) ? $user->lang['VIEW_FORUM_TOPIC'] : sprintf($user->lang['VIEW_FORUM_TOPICS'], $topics_count)),
'MODERATORS' => (!empty($moderators[$forum_id])) ? implode(', ', $moderators[$forum_id]) : '',
'POST_IMG' => ($forum_data['forum_status'] == ITEM_LOCKED) ? $user->img('btn_locked', $post_alt) : $user->img('btn_post', $post_alt), // Display active topics?
'NEWEST_POST_IMG' => $user->img('icon_post_newest', 'VIEW_NEWEST_POST'), $s_display_active = ($forum_data['forum_type'] == FORUM_CAT && ($forum_data['forum_flags'] & 16)) ? true : false;
'LAST_POST_IMG' => $user->img('icon_post_latest', 'VIEW_LATEST_POST'),
'FOLDER_IMG' => $user->img('folder', 'NO_NEW_POSTS'),
'FOLDER_NEW_IMG' => $user->img('folder_new', 'NEW_POSTS'),
'FOLDER_HOT_IMG' => $user->img('folder_hot', 'NO_NEW_POSTS_HOT'),
'FOLDER_HOT_NEW_IMG' => $user->img('folder_hot_new', 'NEW_POSTS_HOT'),
'FOLDER_LOCKED_IMG' => $user->img('folder_locked', 'NO_NEW_POSTS_LOCKED'),
'FOLDER_LOCKED_NEW_IMG' => $user->img('folder_locked_new', 'NEW_POSTS_LOCKED'),
'FOLDER_STICKY_IMG' => $user->img('folder_sticky', 'POST_STICKY'),
'FOLDER_STICKY_NEW_IMG' => $user->img('folder_sticky_new', 'POST_STICKY'),
'FOLDER_ANNOUNCE_IMG' => $user->img('folder_announce', 'POST_ANNOUNCEMENT'),
'FOLDER_ANNOUNCE_NEW_IMG'=> $user->img('folder_announce_new', 'POST_ANNOUNCEMENT'),
'FOLDER_MOVED_IMG' => $user->img('folder_moved', 'TOPIC_MOVED'),
'REPORTED_IMG' => $user->img('icon_reported', 'TOPIC_REPORTED'), $template->assign_vars(array(
'UNAPPROVED_IMG' => $user->img('icon_unapproved', 'TOPIC_UNAPPROVED'), 'PAGINATION' => generate_pagination("{$phpbb_root_path}viewforum.$phpEx$SID&amp;f=$forum_id&amp;$u_sort_param", $topics_count, $config['topics_per_page'], $start),
'PAGE_NUMBER' => on_page($topics_count, $config['topics_per_page'], $start),
'TOTAL_TOPICS' => ($s_display_active) ? false : (($topics_count == 1) ? $user->lang['VIEW_FORUM_TOPIC'] : sprintf($user->lang['VIEW_FORUM_TOPICS'], $topics_count)),
'MODERATORS' => (!empty($moderators[$forum_id])) ? implode(', ', $moderators[$forum_id]) : '',
'GOTO_PAGE_IMG' => $user->img('icon_post', 'GOTO_PAGE'), 'POST_IMG' => ($forum_data['forum_status'] == ITEM_LOCKED) ? $user->img('btn_locked', $post_alt) : $user->img('btn_post', $post_alt),
'NEWEST_POST_IMG' => $user->img('icon_post_newest', 'VIEW_NEWEST_POST'),
'LAST_POST_IMG' => $user->img('icon_post_latest', 'VIEW_LATEST_POST'),
'FOLDER_IMG' => $user->img('folder', 'NO_NEW_POSTS'),
'FOLDER_NEW_IMG' => $user->img('folder_new', 'NEW_POSTS'),
'FOLDER_HOT_IMG' => $user->img('folder_hot', 'NO_NEW_POSTS_HOT'),
'FOLDER_HOT_NEW_IMG' => $user->img('folder_hot_new', 'NEW_POSTS_HOT'),
'FOLDER_LOCKED_IMG' => $user->img('folder_locked', 'NO_NEW_POSTS_LOCKED'),
'FOLDER_LOCKED_NEW_IMG' => $user->img('folder_locked_new', 'NEW_POSTS_LOCKED'),
'FOLDER_STICKY_IMG' => $user->img('folder_sticky', 'POST_STICKY'),
'FOLDER_STICKY_NEW_IMG' => $user->img('folder_sticky_new', 'POST_STICKY'),
'FOLDER_ANNOUNCE_IMG' => $user->img('folder_announce', 'POST_ANNOUNCEMENT'),
'FOLDER_ANNOUNCE_NEW_IMG' => $user->img('folder_announce_new', 'POST_ANNOUNCEMENT'),
'FOLDER_MOVED_IMG' => $user->img('folder_moved', 'TOPIC_MOVED'),
'REPORTED_IMG' => $user->img('icon_reported', 'TOPIC_REPORTED'),
'UNAPPROVED_IMG' => $user->img('icon_unapproved', 'TOPIC_UNAPPROVED'),
'GOTO_PAGE_IMG' => $user->img('icon_post', 'GOTO_PAGE'),
'L_NO_TOPICS' => ($forum_data['forum_status'] == ITEM_LOCKED) ? $user->lang['POST_FORUM_LOCKED'] : $user->lang['NO_TOPICS'], 'L_NO_TOPICS' => ($forum_data['forum_status'] == ITEM_LOCKED) ? $user->lang['POST_FORUM_LOCKED'] : $user->lang['NO_TOPICS'],
'S_IS_POSTABLE' => ($forum_data['forum_type'] == FORUM_POST) ? true : false, 'S_IS_POSTABLE' => ($forum_data['forum_type'] == FORUM_POST) ? true : false,
'S_DISPLAY_ACTIVE' => ($forum_data['forum_type'] == FORUM_CAT && ($forum_data['forum_flags'] & 16)) ? true : false, 'S_DISPLAY_ACTIVE' => $s_display_active,
'S_SELECT_SORT_DIR' => $s_sort_dir, 'S_SELECT_SORT_DIR' => $s_sort_dir,
'S_SELECT_SORT_KEY' => $s_sort_key, 'S_SELECT_SORT_KEY' => $s_sort_key,
'S_SELECT_SORT_DAYS' => $s_limit_days, 'S_SELECT_SORT_DAYS' => $s_limit_days,
'S_TOPIC_ICONS' => ($forum_data['forum_type'] == FORUM_CAT && sizeof($active_forum_ary) && ($forum_data['forum_flags'] & 16)) ? max($active_forum_ary['enable_icons']) : (($forum_data['enable_icons']) ? true : false), 'S_TOPIC_ICONS' => ($s_display_active && sizeof($active_forum_ary)) ? max($active_forum_ary['enable_icons']) : (($forum_data['enable_icons']) ? true : false),
'S_WATCH_FORUM_LINK' => $s_watching_forum['link'], 'S_WATCH_FORUM_LINK' => $s_watching_forum['link'],
'S_WATCH_FORUM_TITLE' => $s_watching_forum['title'], 'S_WATCH_FORUM_TITLE' => $s_watching_forum['title'],
'S_FORUM_ACTION' => "{$phpbb_root_path}viewforum.$phpEx$SID&amp;f=$forum_id&amp;start=$start", 'S_FORUM_ACTION' => "{$phpbb_root_path}viewforum.$phpEx$SID&amp;f=$forum_id&amp;start=$start",
'S_DISPLAY_SEARCHBOX' => ($auth->acl_get('f_search', $forum_id)) ? true : false, 'S_DISPLAY_SEARCHBOX' => ($auth->acl_get('f_search', $forum_id)) ? true : false,
'S_SEARCHBOX_ACTION' => "{$phpbb_root_path}search.$phpEx$SID&amp;fid%5B%5D=$forum_id", 'S_SEARCHBOX_ACTION' => "{$phpbb_root_path}search.$phpEx$SID&amp;fid[]=$forum_id",
'U_MCP' => ($auth->acl_gets('m_', $forum_id)) ? "{$phpbb_root_path}mcp.$phpEx?sid=$user->session_id&amp;f=$forum_id&amp;i=main&amp;mode=forum_view" : '', 'U_MCP' => ($auth->acl_gets('m_', $forum_id)) ? "{$phpbb_root_path}mcp.$phpEx?sid=$user->session_id&amp;f=$forum_id&amp;i=main&amp;mode=forum_view" : '',
'U_POST_NEW_TOPIC' => "{$phpbb_root_path}posting.$phpEx$SID&amp;mode=post&amp;f=$forum_id", 'U_POST_NEW_TOPIC' => "{$phpbb_root_path}posting.$phpEx$SID&amp;mode=post&amp;f=$forum_id",
'U_VIEW_FORUM' => "{$phpbb_root_path}viewforum.$phpEx$SID&amp;f=$forum_id&amp;$u_sort_param&amp;start=$start", 'U_VIEW_FORUM' => "{$phpbb_root_path}viewforum.$phpEx$SID&amp;f=$forum_id&amp;$u_sort_param&amp;start=$start",
'U_MARK_TOPICS' => "{$phpbb_root_path}viewforum.$phpEx$SID&amp;f=$forum_id&amp;mark=topics") 'U_MARK_TOPICS' => "{$phpbb_root_path}viewforum.$phpEx$SID&amp;f=$forum_id&amp;mark=topics")
); );
// Grab icons // Grab icons
$icons = array(); $icons = array();
$cache->obtain_icons($icons); $cache->obtain_icons($icons);
// Grab all topic data // Grab all topic data
$rowset = $announcement_list = $topic_list = $global_announce_list = array(); $rowset = $announcement_list = $topic_list = $global_announce_list = array();
$sql_from = TOPICS_TABLE . ' t '; $sql_array = array(
$sql_approved = ($auth->acl_get('m_approve', $forum_id)) ? '' : 'AND t.topic_approved = 1'; 'SELECT' => 't.*',
$sql_select = ''; 'FROM' => array(
TOPICS_TABLE => 't'
),
'LEFT_JOIN' => array(),
);
if ($user->data['is_registered']) $sql_approved = ($auth->acl_get('m_approve', $forum_id)) ? '' : 'AND t.topic_approved = 1';
if ($user->data['is_registered'])
{
if ($config['load_db_track'])
{ {
if ($config['load_db_track']) $sql_array['LEFT_JOIN'][] = array('FROM' => array(TOPICS_POSTED_TABLE => 'tp'), 'ON' => 'tp.topic_id = t.topic_id AND tp.user_id = ' . $user->data['user_id']);
{ $sql_array['SELECT'] .= ', tp.topic_posted';
$sql_from .= ' LEFT JOIN ' . TOPICS_POSTED_TABLE . ' tp ON (tp.user_id = ' . $user->data['user_id'] . '
AND t.topic_id = tp.topic_id)';
$sql_select .= ', tp.topic_posted';
}
if ($config['load_db_lastread'])
{
$sql_from .= ' LEFT JOIN ' . TOPICS_TRACK_TABLE . ' tt ON (tt.user_id = ' . $user->data['user_id'] . '
AND t.topic_id = tt.topic_id)';
$sql_select .= ', tt.mark_time';
}
} }
if ($forum_data['forum_type'] == FORUM_POST) if ($config['load_db_lastread'])
{ {
// Obtain announcements ... removed sort ordering, sort by time in all cases $sql_array['LEFT_JOIN'][] = array('FROM' => array(TOPICS_TRACK_TABLE => 'tt'), 'ON' => 'tt.topic_id = t.topic_id AND tt.user_id = ' . $user->data['user_id']);
$sql = "SELECT t.* $sql_select $sql_array['SELECT'] .= ', tt.mark_time';
FROM $sql_from
WHERE t.forum_id IN ($forum_id, 0)
AND t.topic_type IN (" . POST_ANNOUNCE . ', ' . POST_GLOBAL . ')
ORDER BY t.topic_time DESC';
$result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result)) if ($s_display_active && sizeof($active_forum_ary))
{ {
$rowset[$row['topic_id']] = $row; $sql_array['LEFT_JOIN'][] = array('FROM' => array(FORUMS_TRACK_TABLE => 'ft'), 'ON' => 'ft.forum_id = t.forum_id AND ft.user_id = ' . $user->data['user_id']);
$announcement_list[] = $row['topic_id']; $sql_array['SELECT'] .= ', ft.mark_time AS forum_mark_time';
if ($row['topic_type'] == POST_GLOBAL)
{
$global_announce_list[$row['topic_id']] = true;
}
} }
$db->sql_freeresult($result);
} }
}
// If the user is trying to reach late pages, start searching from the end if ($forum_data['forum_type'] == FORUM_POST)
$store_reverse = false; {
$sql_limit = $config['topics_per_page']; // Obtain announcements ... removed sort ordering, sort by time in all cases
if ($start > $topics_count / 2) $sql = $db->sql_build_query('SELECT', array(
{ 'SELECT' => $sql_array['SELECT'],
$store_reverse = true; 'FROM' => $sql_array['FROM'],
'LEFT_JOIN' => $sql_array['LEFT_JOIN'],
'WHERE' => 't.forum_id IN (' . $forum_id . ', 0)
AND t.topic_type IN (' . POST_ANNOUNCE . ', ' . POST_GLOBAL . ')',
if ($start + $config['topics_per_page'] > $topics_count) 'ORDER_BY' => 't.topic_time DESC',
{ ));
$sql_limit = min($config['topics_per_page'], max(1, $topics_count - $start)); $result = $db->sql_query($sql);
}
// Select the sort order
$sql_sort_order = $sort_by_sql[$sort_key] . ' ' . (($sort_dir == 'd') ? 'ASC' : 'DESC');
$sql_start = max(0, $topics_count - $sql_limit - $start);
}
else
{
// Select the sort order
$sql_sort_order = $sort_by_sql[$sort_key] . ' ' . (($sort_dir == 'd') ? 'DESC' : 'ASC');
$sql_start = $start;
}
// Obtain other topics
$sql_where = ($forum_data['forum_type'] == FORUM_POST || !sizeof($active_forum_ary)) ? "= $forum_id" : 'IN (' . implode(', ', $active_forum_ary['forum_id']) . ')';
$sql = "SELECT t.* $sql_select
FROM $sql_from
WHERE t.forum_id $sql_where
AND t.topic_type NOT IN (" . POST_ANNOUNCE . ', ' . POST_GLOBAL . ")
$sql_approved
$sql_limit_time
ORDER BY t.topic_type " . ((!$store_reverse) ? 'DESC' : 'ASC') . ', ' . $sql_sort_order;
$result = $db->sql_query_limit($sql, $sql_limit, $sql_start);
while ($row = $db->sql_fetchrow($result)) while ($row = $db->sql_fetchrow($result))
{ {
$rowset[$row['topic_id']] = $row; $rowset[$row['topic_id']] = $row;
$topic_list[] = $row['topic_id']; $announcement_list[] = $row['topic_id'];
if ($row['topic_type'] == POST_GLOBAL)
{
$global_announce_list[$row['topic_id']] = true;
}
} }
$db->sql_freeresult($result); $db->sql_freeresult($result);
}
$topic_list = ($store_reverse) ? array_merge($announcement_list, array_reverse($topic_list)) : array_merge($announcement_list, $topic_list); // If the user is trying to reach late pages, start searching from the end
$topic_tracking_info = $tracking_topics = array(); $store_reverse = false;
$sql_limit = $config['topics_per_page'];
if ($start > $topics_count / 2)
{
$store_reverse = true;
// Okay, lets dump out the page ... if ($start + $config['topics_per_page'] > $topics_count)
if (sizeof($topic_list))
{ {
$mark_forum_read = true; $sql_limit = min($config['topics_per_page'], max(1, $topics_count - $start));
}
// Select the sort order
$sql_sort_order = $sort_by_sql[$sort_key] . ' ' . (($sort_dir == 'd') ? 'ASC' : 'DESC');
$sql_start = max(0, $topics_count - $sql_limit - $start);
}
else
{
// Select the sort order
$sql_sort_order = $sort_by_sql[$sort_key] . ' ' . (($sort_dir == 'd') ? 'DESC' : 'ASC');
$sql_start = $start;
}
// Obtain other topics
$sql_array = array(
'SELECT' => $sql_array['SELECT'],
'FROM' => $sql_array['FROM'],
'LEFT_JOIN' => $sql_array['LEFT_JOIN'],
'WHERE' => (($forum_data['forum_type'] == FORUM_POST || !sizeof($active_forum_ary)) ? 't.forum_id = ' . $forum_id : 't.forum_id IN (' . implode(', ', $active_forum_ary['forum_id']) . ')') . '
AND t.topic_type NOT IN (' . POST_ANNOUNCE . ', ' . POST_GLOBAL . ")
$sql_approved
$sql_limit_time",
'ORDER_BY' => 't.topic_type ' . ((!$store_reverse) ? 'DESC' : 'ASC') . ', ' . $sql_sort_order,
);
$sql = $db->sql_build_query('SELECT', $sql_array);
$result = $db->sql_query_limit($sql, $sql_limit, $sql_start);
while ($row = $db->sql_fetchrow($result))
{
$rowset[$row['topic_id']] = $row;
$topic_list[] = $row['topic_id'];
}
$db->sql_freeresult($result);
$topic_list = ($store_reverse) ? array_merge($announcement_list, array_reverse($topic_list)) : array_merge($announcement_list, $topic_list);
$topic_tracking_info = $tracking_topics = array();
// Okay, lets dump out the page ...
if (sizeof($topic_list))
{
$mark_forum_read = true;
// Active topics?
if ($s_display_active && sizeof($active_forum_ary))
{
// Generate topic forum list...
$topic_forum_list = array();
foreach ($rowset as $t_id => $row)
{
$topic_forum_list[$row['forum_id']]['forum_mark_time'] = ($config['load_db_lastread']) ? $row['forum_mark_time'] : 0;
$topic_forum_list[$row['forum_id']]['topics'][] = $t_id;
}
if ($config['load_db_lastread'] && $user->data['is_registered'])
{
foreach ($topic_forum_list as $f_id => $topic_row)
{
$topic_tracking_info += get_topic_tracking($f_id, $topic_row['topics'], $rowset, array($f_id => $topic_row['forum_mark_time']), false);
}
}
else
{
foreach ($topic_forum_list as $f_id => $topic_row)
{
$topic_tracking_info += get_complete_topic_tracking($f_id, $topic_row['topics'], false);
}
}
unset($topic_forum_list);
}
else
{
if ($config['load_db_lastread'] && $user->data['is_registered']) if ($config['load_db_lastread'] && $user->data['is_registered'])
{ {
$topic_tracking_info = get_topic_tracking($forum_id, $topic_list, $rowset, array($forum_id => $forum_data['mark_time']), $global_announce_list); $topic_tracking_info = get_topic_tracking($forum_id, $topic_list, $rowset, array($forum_id => $forum_data['mark_time']), $global_announce_list);
@ -379,161 +442,152 @@ if ($forum_data['forum_type'] == FORUM_POST || (($forum_data['forum_flags'] & 16
} }
$mark_time_forum = (isset($tracking_topics['f'][$forum_id])) ? base_convert($tracking_topics['f'][$forum_id], 36, 10) + $config['board_startdate'] : $user->data['user_lastmark']; $mark_time_forum = (isset($tracking_topics['f'][$forum_id])) ? base_convert($tracking_topics['f'][$forum_id], 36, 10) + $config['board_startdate'] : $user->data['user_lastmark'];
} }
$s_type_switch = 0;
foreach ($topic_list as $topic_id)
{
$row = &$rowset[$topic_id];
// This will allow the style designer to output a different header
// or even seperate the list of announcements from sticky and normal topics
$s_type_switch_test = ($row['topic_type'] == POST_ANNOUNCE || $row['topic_type'] == POST_GLOBAL) ? 1 : 0;
// Replies
$replies = ($auth->acl_get('m_approve', $forum_id)) ? $row['topic_replies_real'] : $row['topic_replies'];
if ($row['topic_status'] == ITEM_MOVED)
{
$topic_id = $row['topic_moved_id'];
$unread_topic = false;
}
else
{
$unread_topic = (isset($topic_tracking_info[$topic_id]) && $row['topic_last_post_time'] > $topic_tracking_info[$topic_id]) ? true : false;
}
// Get folder img, topic status/type related informations
$folder_img = $folder_alt = $topic_type = '';
topic_status($row, $replies, $unread_topic, $folder_img, $folder_alt, $topic_type);
// Generate all the URIs ...
$view_topic_url = "{$phpbb_root_path}viewtopic.$phpEx$SID&amp;f=" . (($row['forum_id']) ? $row['forum_id'] : $forum_id) . "&amp;t=$topic_id";
// Send vars to template
$template->assign_block_vars('topicrow', array(
'FORUM_ID' => $forum_id,
'TOPIC_ID' => $topic_id,
'TOPIC_AUTHOR' => topic_topic_author($row),
'FIRST_POST_TIME' => $user->format_date($row['topic_time']),
'LAST_POST_TIME' => $user->format_date($row['topic_last_post_time']),
'LAST_VIEW_TIME' => $user->format_date($row['topic_last_view_time']),
'LAST_POST_AUTHOR' => ($row['topic_last_poster_name'] != '') ? $row['topic_last_poster_name'] : $user->lang['GUEST'],
'PAGINATION' => topic_generate_pagination($replies, $view_topic_url),
'REPLIES' => $replies,
'VIEWS' => $row['topic_views'],
'TOPIC_TITLE' => censor_text($row['topic_title']),
'TOPIC_TYPE' => $topic_type,
'TOPIC_FOLDER_IMG' => $user->img($folder_img, $folder_alt),
'TOPIC_FOLDER_IMG_SRC' => $user->img($folder_img, $folder_alt, false, '', 'src'),
'TOPIC_ICON_IMG' => (!empty($icons[$row['icon_id']])) ? $icons[$row['icon_id']]['img'] : '',
'TOPIC_ICON_IMG_WIDTH' => (!empty($icons[$row['icon_id']])) ? $icons[$row['icon_id']]['width'] : '',
'TOPIC_ICON_IMG_HEIGHT' => (!empty($icons[$row['icon_id']])) ? $icons[$row['icon_id']]['height'] : '',
'ATTACH_ICON_IMG' => ($auth->acl_gets('f_download', 'u_download', $forum_id) && $row['topic_attachment']) ? $user->img('icon_attach', $user->lang['TOTAL_ATTACHMENTS']) : '',
'S_TOPIC_TYPE' => $row['topic_type'],
'S_USER_POSTED' => (isset($row['topic_posted']) && $row['topic_posted']) ? true : false,
'S_UNREAD_TOPIC' => $unread_topic,
'S_TOPIC_REPORTED' => (!empty($row['topic_reported']) && $auth->acl_gets('m_report', $forum_id)) ? true : false,
'S_TOPIC_UNAPPROVED' => (!$row['topic_approved'] && $auth->acl_gets('m_approve', $forum_id)) ? true : false,
'U_NEWEST_POST' => $view_topic_url . '&amp;view=unread#unread',
'U_LAST_POST' => $view_topic_url . '&amp;p=' . $row['topic_last_post_id'] . '#p' . $row['topic_last_post_id'],
'U_LAST_POST_AUTHOR'=> ($row['topic_last_poster_id'] != ANONYMOUS && $row['topic_last_poster_id']) ? "{$phpbb_root_path}memberlist.$phpEx$SID&amp;mode=viewprofile&amp;u={$row['topic_last_poster_id']}" : '',
'U_VIEW_TOPIC' => $view_topic_url,
'U_MCP_REPORT' => "{$phpbb_root_path}mcp.$phpEx?sid={$user->session_id}&amp;i=reports&amp;mode=reports&amp;t=$topic_id",
'U_MCP_QUEUE' => "{$phpbb_root_path}mcp.$phpEx?sid={$user->session_id}&amp;i=queue&amp;mode=approve_details&amp;t=$topic_id",
'S_TOPIC_TYPE_SWITCH' => ($s_type_switch == $s_type_switch_test) ? -1 : $s_type_switch_test)
);
$s_type_switch = ($row['topic_type'] == POST_ANNOUNCE || $row['topic_type'] == POST_GLOBAL) ? 1 : 0;
if ($unread_topic)
{
$mark_forum_read = false;
}
unset($rowset[$topic_id]);
}
} }
// This is rather a fudge but it's the best I can think of without requiring information $s_type_switch = 0;
// on all topics (as we do in 2.0.x). It looks for unread or new topics, if it doesn't find foreach ($topic_list as $topic_id)
// any it updates the forum last read cookie. This requires that the user visit the forum
// after reading a topic
if ($forum_data['forum_type'] == FORUM_POST && sizeof($topic_list) && $mark_forum_read)
{ {
// Make sure there are not additional topics unread $row = &$rowset[$topic_id];
if ($config['load_db_lastread'] && $user->data['is_registered'])
// This will allow the style designer to output a different header
// or even seperate the list of announcements from sticky and normal topics
$s_type_switch_test = ($row['topic_type'] == POST_ANNOUNCE || $row['topic_type'] == POST_GLOBAL) ? 1 : 0;
// Replies
$replies = ($auth->acl_get('m_approve', $forum_id)) ? $row['topic_replies_real'] : $row['topic_replies'];
if ($row['topic_status'] == ITEM_MOVED)
{ {
if ($mark_time_forum >= $forum_data['forum_last_post_time']) $topic_id = $row['topic_moved_id'];
{ $unread_topic = false;
$row = true;
}
else
{
$sql = 'SELECT t.forum_id FROM ' . TOPICS_TABLE . ' t
LEFT JOIN ' . TOPICS_TRACK_TABLE . ' tt ON (tt.user_id = ' . $user->data['user_id'] . ' AND tt.topic_id = t.topic_id)
WHERE t.forum_id = ' . $forum_id . '
AND t.topic_last_post_time > ' . $mark_time_forum . '
AND t.topic_moved_id = 0
AND tt.topic_id IS NULL
GROUP BY t.forum_id';
$result = $db->sql_query($sql);
$row = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
}
} }
else else
{ {
// Get information from cookie $unread_topic = (isset($topic_tracking_info[$topic_id]) && $row['topic_last_post_time'] > $topic_tracking_info[$topic_id]) ? true : false;
$row = false;
if (!isset($tracking_topics['tf'][$forum_id]))
{
// We do not need to mark read, this has happened before. Therefore setting this to true
$row = true;
}
else
{
$sql = 'SELECT topic_id FROM ' . TOPICS_TABLE . '
WHERE forum_id = ' . $forum_id . '
AND topic_last_post_time > ' . $mark_time_forum . '
AND topic_moved_id = 0';
$result = $db->sql_query($sql);
$check_forum = $tracking_topics['tf'][$forum_id];
$unread = false;
while ($row = $db->sql_fetchrow($result))
{
if (!in_array(base_convert($row['topic_id'], 10, 36), array_keys($check_forum)))
{
$unread = true;
break;
}
}
$db->sql_freeresult($result);
$row = $unread;
}
} }
if (!$row) // Get folder img, topic status/type related informations
$folder_img = $folder_alt = $topic_type = '';
topic_status($row, $replies, $unread_topic, $folder_img, $folder_alt, $topic_type);
// Generate all the URIs ...
$view_topic_url = "{$phpbb_root_path}viewtopic.$phpEx$SID&amp;f=" . (($row['forum_id']) ? $row['forum_id'] : $forum_id) . "&amp;t=$topic_id";
// Send vars to template
$template->assign_block_vars('topicrow', array(
'FORUM_ID' => $forum_id,
'TOPIC_ID' => $topic_id,
'TOPIC_AUTHOR' => topic_topic_author($row),
'FIRST_POST_TIME' => $user->format_date($row['topic_time']),
'LAST_POST_TIME' => $user->format_date($row['topic_last_post_time']),
'LAST_VIEW_TIME' => $user->format_date($row['topic_last_view_time']),
'LAST_POST_AUTHOR' => ($row['topic_last_poster_name']) ? $row['topic_last_poster_name'] : $user->lang['GUEST'],
'PAGINATION' => topic_generate_pagination($replies, $view_topic_url),
'REPLIES' => $replies,
'VIEWS' => $row['topic_views'],
'TOPIC_TITLE' => censor_text($row['topic_title']),
'TOPIC_TYPE' => $topic_type,
'TOPIC_FOLDER_IMG' => $user->img($folder_img, $folder_alt),
'TOPIC_FOLDER_IMG_SRC' => $user->img($folder_img, $folder_alt, false, '', 'src'),
'TOPIC_ICON_IMG' => (!empty($icons[$row['icon_id']])) ? $icons[$row['icon_id']]['img'] : '',
'TOPIC_ICON_IMG_WIDTH' => (!empty($icons[$row['icon_id']])) ? $icons[$row['icon_id']]['width'] : '',
'TOPIC_ICON_IMG_HEIGHT' => (!empty($icons[$row['icon_id']])) ? $icons[$row['icon_id']]['height'] : '',
'ATTACH_ICON_IMG' => ($auth->acl_gets('f_download', 'u_download', $forum_id) && $row['topic_attachment']) ? $user->img('icon_attach', $user->lang['TOTAL_ATTACHMENTS']) : '',
'S_TOPIC_TYPE' => $row['topic_type'],
'S_USER_POSTED' => (isset($row['topic_posted']) && $row['topic_posted']) ? true : false,
'S_UNREAD_TOPIC' => $unread_topic,
'S_TOPIC_REPORTED' => (!empty($row['topic_reported']) && $auth->acl_gets('m_report', $forum_id)) ? true : false,
'S_TOPIC_UNAPPROVED' => (!$row['topic_approved'] && $auth->acl_gets('m_approve', $forum_id)) ? true : false,
'U_NEWEST_POST' => $view_topic_url . '&amp;view=unread#unread',
'U_LAST_POST' => $view_topic_url . '&amp;p=' . $row['topic_last_post_id'] . '#p' . $row['topic_last_post_id'],
'U_LAST_POST_AUTHOR' => ($row['topic_last_poster_id'] != ANONYMOUS && $row['topic_last_poster_id']) ? "{$phpbb_root_path}memberlist.$phpEx$SID&amp;mode=viewprofile&amp;u={$row['topic_last_poster_id']}" : '',
'U_VIEW_TOPIC' => $view_topic_url,
'U_MCP_REPORT' => "{$phpbb_root_path}mcp.$phpEx?sid={$user->session_id}&amp;i=reports&amp;mode=reports&amp;t=$topic_id",
'U_MCP_QUEUE' => "{$phpbb_root_path}mcp.$phpEx?sid={$user->session_id}&amp;i=queue&amp;mode=approve_details&amp;t=$topic_id",
'S_TOPIC_TYPE_SWITCH' => ($s_type_switch == $s_type_switch_test) ? -1 : $s_type_switch_test)
);
$s_type_switch = ($row['topic_type'] == POST_ANNOUNCE || $row['topic_type'] == POST_GLOBAL) ? 1 : 0;
if ($unread_topic)
{ {
markread('topics', $forum_id); $mark_forum_read = false;
} }
unset($rowset[$topic_id]);
} }
} }
// Dump out the page header and load viewforum template // This is rather a fudge but it's the best I can think of without requiring information
page_header($user->lang['VIEW_FORUM'] . ' - ' . $forum_data['forum_name']); // on all topics (as we do in 2.0.x). It looks for unread or new topics, if it doesn't find
// any it updates the forum last read cookie. This requires that the user visit the forum
// after reading a topic
if ($forum_data['forum_type'] == FORUM_POST && sizeof($topic_list) && $mark_forum_read)
{
// Make sure there are not additional topics unread
if ($config['load_db_lastread'] && $user->data['is_registered'])
{
if ($mark_time_forum >= $forum_data['forum_last_post_time'])
{
$row = true;
}
else
{
$sql = 'SELECT t.forum_id FROM ' . TOPICS_TABLE . ' t
LEFT JOIN ' . TOPICS_TRACK_TABLE . ' tt ON (tt.topic_id = t.topic_id AND tt.user_id = ' . $user->data['user_id'] . ')
WHERE t.forum_id = ' . $forum_id . '
AND t.topic_last_post_time > ' . $mark_time_forum . '
AND t.topic_moved_id = 0
AND tt.topic_id IS NULL
GROUP BY t.forum_id';
$result = $db->sql_query($sql);
$row = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
}
}
else
{
// Get information from cookie
$row = false;
$template->set_filenames(array( if (!isset($tracking_topics['tf'][$forum_id]))
'body' => 'viewforum_body.html') {
); // We do not need to mark read, this has happened before. Therefore setting this to true
make_jumpbox("viewforum.$phpEx$SID", $forum_id); $row = true;
}
else
{
$sql = 'SELECT topic_id FROM ' . TOPICS_TABLE . '
WHERE forum_id = ' . $forum_id . '
AND topic_last_post_time > ' . $mark_time_forum . '
AND topic_moved_id = 0';
$result = $db->sql_query($sql);
$check_forum = $tracking_topics['tf'][$forum_id];
$unread = false;
while ($row = $db->sql_fetchrow($result))
{
if (!in_array(base_convert($row['topic_id'], 10, 36), array_keys($check_forum)))
{
$unread = true;
break;
}
}
$db->sql_freeresult($result);
$row = $unread;
}
}
if (!$row)
{
markread('topics', $forum_id);
}
}
page_footer(); page_footer();