diff --git a/phpBB/adm/admin_forums.php b/phpBB/adm/admin_forums.php index 12391d3371..5264c22bf5 100644 --- a/phpBB/adm/admin_forums.php +++ b/phpBB/adm/admin_forums.php @@ -6,6 +6,7 @@ * @copyright (c) 2005 phpBB Group * @license http://opensource.org/licenses/gpl-license.php GNU Public License * +* @todo add show_active flag (& 16) */ /** @@ -1445,6 +1446,7 @@ function delete_forum_content($forum_id) REPORTS_TABLE => 're.post_id', TOPICS_WATCH_TABLE => 'tw.topic_id', TOPICS_TRACK_TABLE => 'tt.topic_id', + TOPICS_POSTED_TABLE => 'tp.topic_id', POLL_OPTIONS_TABLE => 'po.topic_id', POLL_VOTES_TABLE => 'pv.post_id' ); @@ -1515,6 +1517,7 @@ function delete_forum_content($forum_id) 'topic_id' => array( TOPICS_WATCH_TABLE, TOPICS_TRACK_TABLE, + TOPICS_POSTED_TABLE, POLL_OPTIONS_TABLE, POLL_VOTES_TABLE ) diff --git a/phpBB/cron.php b/phpBB/cron.php index 9fbbb812e6..6c4fdf6b7a 100644 --- a/phpBB/cron.php +++ b/phpBB/cron.php @@ -20,8 +20,12 @@ $cron_type = request_var('cron_type', ''); $use_shutdown_function = (@function_exists('register_shutdown_function')) ? true : false; -// Run cron-like action -// Real cron-based layer will be introduced in 3.2 +/** +* Run cron-like action +* Real cron-based layer will be introduced in 3.2 +* +* @todo: check gc-intervals here too (important!) +*/ switch ($cron_type) { case 'queue': @@ -35,7 +39,7 @@ switch ($cron_type) { $queue->process(); } - break; + break; case 'tidy_cache': if ($use_shutdown_function) @@ -46,7 +50,7 @@ switch ($cron_type) { $cache->tidy(); } - break; + break; case 'tidy_database': include_once($phpbb_root_path . 'includes/functions_admin.'.$phpEx); @@ -59,17 +63,66 @@ switch ($cron_type) { tidy_database(); } - break; + break; - case 'tidy_login_keys': + case 'tidy_sessions': if ($use_shutdown_function) { - register_shutdown_function(array(&$user, 'tidy_login_keys')); + register_shutdown_function(array(&$user, 'session_gc')); } else { - $user->tidy_login_keys(); + $user->session_gc(); } + break; + + case 'prune_forum': + + $forum_id = request_var('f', 0); + + $sql = 'SELECT forum_id, prune_next, enable_prune, prune_days, prune_viewed, forum_flags, prune_freq + FROM ' . FORUMS_TABLE . " + WHERE forum_id = $forum_id"; + $result = $db->sql_query($sql); + $row = $db->sql_fetchrow($result); + $db->sql_freeresult($result); + + if (!$row) + { + break; + } + + // Do the forum Prune thang + if ($row['prune_next'] < time() && $row['enable_prune']) + { + include_once($phpbb_root_path . 'includes/functions_admin.'.$phpEx); + + if ($row['prune_days']) + { + if ($use_shutdown_function) + { + register_shutdown_function('auto_prune', $row['forum_id'], 'posted', $row['forum_flags'], $row['prune_days'], $row['prune_freq']); + } + else + { + auto_prune($row['forum_id'], 'posted', $row['forum_flags'], $row['prune_days'], $row['prune_freq']); + } + } + + if ($row['prune_viewed']) + { + if ($use_shutdown_function) + { + register_shutdown_function('auto_prune', $row['forum_id'], 'viewed', $row['forum_flags'], $row['prune_viewed'], $row['prune_freq']); + } + else + { + auto_prune($row['forum_id'], 'viewed', $row['forum_flags'], $row['prune_viewed'], $row['prune_freq']); + } + } + } + + break; } // Output transparent gif diff --git a/phpBB/includes/acm/acm_main.php b/phpBB/includes/acm/acm_main.php index bdb8189bd7..27c59ea7c4 100644 --- a/phpBB/includes/acm/acm_main.php +++ b/phpBB/includes/acm/acm_main.php @@ -65,7 +65,7 @@ class cache extends acm */ function obtain_word_list(&$censors) { - global $db, $user; + global $config, $user, $db; if (!$user->optionget('viewcensors') && $config['allow_nocensors']) { @@ -101,14 +101,14 @@ class cache extends acm */ function obtain_icons(&$icons) { - global $db; - if ($this->exists('icons')) { $icons = $this->get('icons'); } else { + global $db; + // Topic icons $sql = 'SELECT * FROM ' . ICONS_TABLE . ' @@ -136,14 +136,14 @@ class cache extends acm */ function obtain_ranks(&$ranks) { - global $db; - if ($this->exists('ranks')) { $ranks = $this->get('ranks'); } else { + global $db; + $sql = 'SELECT * FROM ' . RANKS_TABLE . ' ORDER BY rank_min DESC'; @@ -181,14 +181,14 @@ class cache extends acm */ function obtain_attach_extensions(&$extensions, $forum_id = false) { - global $db; - - if ($this->exists('extensions')) + if ($this->exists('_extensions')) { - $extensions = $this->get('extensions'); + $extensions = $this->get('_extensions'); } else { + global $db; + // The rule is to only allow those extensions defined. ;) $sql = 'SELECT e.extension, g.* FROM ' . EXTENSIONS_TABLE . ' e, ' . EXTENSION_GROUPS_TABLE . ' g @@ -220,7 +220,7 @@ class cache extends acm } $db->sql_freeresult($result); - $this->put('extensions', $extensions); + $this->put('_extensions', $extensions); } if ($forum_id !== false) @@ -265,14 +265,14 @@ class cache extends acm */ function obtain_bots(&$bots) { - global $db; - if ($this->exists('bots')) { $bots = $this->get('bots'); } else { + global $db; + switch (SQL_LAYER) { case 'mssql': diff --git a/phpBB/includes/constants.php b/phpBB/includes/constants.php index 2b333c50cb..89c224bafe 100644 --- a/phpBB/includes/constants.php +++ b/phpBB/includes/constants.php @@ -169,8 +169,9 @@ define('STYLES_TPLDATA_TABLE', $table_prefix.'styles_template_data'); define('STYLES_CSS_TABLE', $table_prefix.'styles_theme'); define('STYLES_IMAGE_TABLE', $table_prefix.'styles_imageset'); define('TOPICS_TABLE', $table_prefix.'topics'); -define('TOPICS_TRACK_TABLE', $table_prefix.'topics_marking'); +define('TOPICS_POSTED_TABLE', $table_prefix.'topics_posted'); define('TOPICS_WATCH_TABLE', $table_prefix.'topics_watch'); +define('TOPICS_TRACK_TABLE', $table_prefix.'topics_marking'); define('USER_GROUP_TABLE', $table_prefix.'user_group'); define('USERS_TABLE', $table_prefix.'users'); define('USERS_PASSWD_TABLE', $table_prefix.'users_passwd'); diff --git a/phpBB/includes/db/firebird.php b/phpBB/includes/db/firebird.php index 7f57f33ff2..dda1094498 100644 --- a/phpBB/includes/db/firebird.php +++ b/phpBB/includes/db/firebird.php @@ -160,7 +160,7 @@ class dbal_firebird extends dbal } else { - return ($this->query_result) ? true : false; + return false; //($this->query_result) ? true : false; } } diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 4daab71c90..477a7f7ac3 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -473,196 +473,419 @@ function watch_topic_forum($mode, &$s_watching, &$s_watching_img, $user_id, $mat } /** -* Marks a topic or form as read +* Marks a topic/forum as read +* Marks a topic as posted to */ -function markread($mode, $forum_id = 0, $topic_id = 0, $marktime = false) +function markread($mode, $forum_id = false, $topic_id = false, $post_time = 0) { - global $config, $db, $user; - - if (!$user->data['is_registered']) + global $db, $user, $config; + + if ($mode == 'all') { - return; - } - - if (!is_array($forum_id)) - { - $forum_id = array($forum_id); - } - - // Default tracking type - $type = TRACK_NORMAL; - $current_time = ($marktime) ? $marktime : time(); - $topic_id = (int) $topic_id; - - switch ($mode) - { - case 'mark': - if ($config['load_db_lastread']) + if ($forum_id === false || !sizeof($forum_id)) + { + if ($config['load_db_lastread'] && $user->data['is_registered']) { - $sql = 'SELECT forum_id - FROM ' . FORUMS_TRACK_TABLE . ' - WHERE user_id = ' . $user->data['user_id'] . ' - AND forum_id IN (' . implode(', ', array_map('intval', $forum_id)) . ')'; - $result = $db->sql_query($sql); - - $sql_update = array(); - while ($row = $db->sql_fetchrow($result)) - { - $sql_update[] = $row['forum_id']; - } - $db->sql_freeresult($result); - - if (sizeof($sql_update)) - { - $sql = 'UPDATE ' . FORUMS_TRACK_TABLE . " - SET mark_time = $current_time - WHERE user_id = " . $user->data['user_id'] . ' - AND forum_id IN (' . implode(', ', $sql_update) . ')'; - $db->sql_query($sql); - - $sql = 'DELETE FROM ' . TOPICS_TRACK_TABLE . ' - WHERE user_id = ' . $user->data['user_id'] . ' - AND forum_id IN (' . implode(', ', $sql_update) . ') - AND mark_type = ' . TRACK_NORMAL; - $db->sql_query($sql); - } - - if ($sql_insert = array_diff($forum_id, $sql_update)) - { - foreach ($sql_insert as $forum_id) - { - $sql = ''; - switch (SQL_LAYER) - { - case 'mysql': - $sql .= (($sql != '') ? ', ' : '') . '(' . $user->data['user_id'] . ", $forum_id, $current_time)"; - $sql = 'VALUES ' . $sql; - break; - - case 'mysql4': - case 'mysqli': - case 'mssql': - case 'mssql_odbc': - case 'sqlite': - $sql .= (($sql != '') ? ' UNION ALL ' : '') . ' SELECT ' . $user->data['user_id'] . ", $forum_id, $current_time"; - break; - - default: - $sql = 'INSERT INTO ' . FORUMS_TRACK_TABLE . ' (user_id, forum_id, mark_time) - VALUES (' . $user->data['user_id'] . ", $forum_id, $current_time)"; - $db->sql_query($sql); - $sql = ''; - } - - if ($sql) - { - $sql = 'INSERT INTO ' . FORUMS_TRACK_TABLE . " (user_id, forum_id, mark_time) $sql"; - $db->sql_query($sql); - } - - $sql = 'DELETE FROM ' . TOPICS_TRACK_TABLE . ' - WHERE user_id = ' . $user->data['user_id'] . ' - AND forum_id = ' . $forum_id . ' - AND mark_type = ' . TRACK_NORMAL; - $db->sql_query($sql); - } - } - unset($sql_update); - unset($sql_insert); + // Mark all forums read (index page) + $db->sql_query('DELETE FROM ' . TOPICS_TRACK_TABLE . " WHERE user_id = {$user->data['user_id']}"); + $db->sql_query('DELETE FROM ' . FORUMS_TRACK_TABLE . " WHERE user_id = {$user->data['user_id']}"); + $db->sql_query('UPDATE ' . USERS_TABLE . ' SET user_lastmark = ' . time() . " WHERE user_id = {$user->data['user_id']}"); } else { $tracking = (isset($_COOKIE[$config['cookie_name'] . '_track'])) ? unserialize(stripslashes($_COOKIE[$config['cookie_name'] . '_track'])) : array(); - foreach ($forum_id as $f_id) - { - unset($tracking[$f_id]); - $tracking[$f_id][0] = base_convert($current_time - $config['board_startdate'], 10, 36); - } - + unset($tracking['tf']); + unset($tracking['t']); + unset($tracking['f']); + $tracking['l'] = base_convert(time() - $config['board_startdate'], 10, 36); + $user->set_cookie('track', serialize($tracking), time() + 31536000); unset($tracking); } - break; - - case 'post': - // Mark a topic as read and mark it as a topic where the user has made a post. - $type = TRACK_POSTED; - - case 'topic': - if (!isset($type)) - { - $type = TRACK_NORMAL; - } + } - $forum_id = (int) $forum_id[0]; + return; + } + else if ($mode == 'topics') + { + // Mark all topics in forums read + if (!is_array($forum_id)) + { + $forum_id = array($forum_id); + } - /// Mark a topic as read - if ($config['load_db_lastread'] || ($config['load_db_track'] && $type == TRACK_POSTED)) + // Add 0 to forums array to mark global announcements correctly + $forum_id[] = 0; + + if ($config['load_db_lastread'] && $user->data['is_registered']) + { + $db->sql_query('DELETE FROM ' . TOPICS_TRACK_TABLE . " + WHERE user_id = {$user->data['user_id']} + AND forum_id IN (" . implode(', ', $forum_id) . ")"); + + $sql = 'SELECT forum_id + FROM ' . FORUMS_TRACK_TABLE . " + WHERE user_id = {$user->data['user_id']} + AND forum_id IN (" . implode(', ', $forum_id) . ')'; + $result = $db->sql_query($sql); + + $sql_update = array(); + while ($row = $db->sql_fetchrow($result)) { - $track_type = ($type == TRACK_POSTED) ? ', mark_type = ' . $type : ''; - $sql = 'UPDATE ' . TOPICS_TRACK_TABLE . " - SET forum_id = $forum_id, mark_time = $current_time $track_type - WHERE topic_id = $topic_id - AND user_id = {$user->data['user_id']} - AND mark_time < $current_time"; - if (!$db->sql_query($sql) || !$db->sql_affectedrows()) + $sql_update[] = $row['forum_id']; + } + $db->sql_freeresult($result); + + if (sizeof($sql_update)) + { + $sql = 'UPDATE ' . FORUMS_TRACK_TABLE . ' + SET mark_time = ' . time() . " + WHERE user_id = {$user->data['user_id']} + AND forum_id IN (" . implode(', ', $sql_update) . ')'; + $db->sql_query($sql); + } + + if ($sql_insert = array_diff($forum_id, $sql_update)) + { + $sql_ary = array(); + foreach ($sql_insert as $f_id) { - $db->sql_return_on_error(true); - - $sql_ary = array( - 'user_id' => $user->data['user_id'], - 'topic_id' => $topic_id, - 'forum_id' => $forum_id, - 'mark_type' => $type, - 'mark_time' => $current_time + $sql_ary[] = array( + 'user_id' => $user->data['user_id'], + 'forum_id' => $f_id, + 'mark_time' => time() ); - - $db->sql_query('INSERT INTO ' . TOPICS_TRACK_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary)); - - $db->sql_return_on_error(false); } + + if (sizeof($sql_ary)) + { + $db->sql_query('INSERT INTO ' . FORUMS_TRACK_TABLE . ' ' . $db->sql_build_array('MULTI_INSERT', $sql_ary)); + } + } + } + else + { + $tracking = (isset($_COOKIE[$config['cookie_name'] . '_track'])) ? unserialize(stripslashes($_COOKIE[$config['cookie_name'] . '_track'])) : array(); + + foreach ($forum_id as $f_id) + { + $topic_ids36 = (isset($tracking['tf'][$f_id])) ? $tracking['tf'][$f_id] : array(); + + unset($tracking['tf'][$f_id]); + foreach ($topic_ids36 as $topic_id36) + { + unset($tracking['t'][$topic_id36]); + } + unset($tracking['f'][$f_id]); + $tracking['f'][$f_id] = base_convert(time() - $config['board_startdate'], 10, 36); + } + + $user->set_cookie('track', serialize($tracking), time() + 31536000); + unset($tracking); + } + + return; + } + else if ($mode == 'topic') + { + if ($topic_id === false || $forum_id === false) + { + return; + } + + if ($config['load_db_lastread'] && $user->data['is_registered']) + { + $sql = 'UPDATE ' . TOPICS_TRACK_TABLE . ' + SET mark_time = ' . (($post_time) ? $post_time : time()) . " + WHERE user_id = {$user->data['user_id']} + AND topic_id = $topic_id"; + $db->sql_query($sql); + + // insert row + if (!$db->sql_affectedrows()) + { + $db->sql_return_on_error(true); + + $sql_ary = array( + 'user_id' => $user->data['user_id'], + 'topic_id' => $topic_id, + 'forum_id' => (int) $forum_id, + 'mark_time' => ($post_time) ? $post_time : time(), + ); + + $db->sql_query('INSERT INTO ' . TOPICS_TRACK_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary)); + + $db->sql_return_on_error(false); + } + } + else + { + $tracking = (isset($_COOKIE[$config['cookie_name'] . '_track'])) ? unserialize(stripslashes($_COOKIE[$config['cookie_name'] . '_track'])) : array(); + + $topic_id36 = base_convert($topic_id, 10, 36); + + if (!isset($tracking['t'][$topic_id36])) + { + $tracking['tf'][$forum_id][$topic_id36] = true; } - if (!$config['load_db_lastread']) - { - $tracking = array(); - if (isset($_COOKIE[$config['cookie_name'] . '_track'])) - { - $tracking = unserialize(stripslashes($_COOKIE[$config['cookie_name'] . '_track'])); + $post_time = ($post_time) ? $post_time : time(); + $tracking['t'][$topic_id36] = base_convert($post_time - $config['board_startdate'], 10, 36); - // If the cookie grows larger than 2000 characters we will remove - // the smallest value - if (strlen($_COOKIE[$config['cookie_name'] . '_track']) > 2000) + // If the cookie grows larger than 5000 characters we will remove the smallest value + if (isset($_COOKIE[$config['cookie_name'] . '_track']) && strlen($_COOKIE[$config['cookie_name'] . '_track']) > 5000) + { +// echo 'Cookie grown too large' . print_r($tracking, true); + + $min_value = min($tracking['t']); + $m_tkey = array_search($min_value, $t_ary); + unset($tracking['t'][$m_tkey]); + + foreach ($tracking['tf'] as $f_id => $topic_id_ary) + { + if (in_array($m_tkey, array_keys($topic_id_ary))) { - foreach ($tracking as $f => $t_ary) - { - if (!isset($m_value) || min($t_ary) < $m_value) - { - $m_value = min($t_ary); - $m_tkey = array_search($m_value, $t_ary); - $m_fkey = $f; - } - } - unset($tracking[$m_fkey][$m_tkey]); + unset($tracking['tf'][$f_id][$m_tkey]); + break; } } - - if (isset($tracking[$forum_id]) && base_convert($tracking[$forum_id][0], 36, 10) < $current_time) - { - $tracking[$forum_id][base_convert($topic_id, 10, 36)] = base_convert($current_time - $config['board_startdate'], 10, 36); - - $user->set_cookie('track', serialize($tracking), time() + 31536000); - } - else if (!isset($tracking[$forum_id])) - { - $tracking[$forum_id][0] = base_convert($current_time - $config['board_startdate'], 10, 36); - $user->set_cookie('track', serialize($tracking), time() + 31536000); - } - unset($tracking); } - break; + + $user->set_cookie('track', serialize($tracking), time() + 31536000); + } + + return; } + else if ($mode == 'post') + { + if ($topic_id === false) + { + return; + } + + $db->sql_return_on_error(true); + + $sql_ary = array( + 'user_id' => $user->data['user_id'], + 'topic_id' => $topic_id, + 'topic_posted' => 1 + ); + + $db->sql_query('INSERT INTO ' . TOPICS_POSTED_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary)); + + $db->sql_return_on_error(false); + + return; + } +} + +/** +* Get topic tracking info by using already fetched info +*/ +function get_topic_tracking($forum_id, $topic_ids, &$rowset, $forum_mark_time, $global_announce_list = false) +{ + global $config, $user; + + $last_read = array(); + + if (!is_array($topic_ids)) + { + $topic_ids = array($topic_ids); + } + + foreach ($topic_ids as $topic_id) + { + if (!empty($rowset[$topic_id]['mark_time'])) + { + $last_read[$topic_id] = $rowset[$topic_id]['mark_time']; + } + } + + $topic_ids = array_diff($topic_ids, array_keys($last_read)); + + if (sizeof($topic_ids)) + { + $mark_time = array(); + + // Get global announcement info + if ($global_announce_list && sizeof($global_announce_list)) + { + if (!isset($forum_mark_time[0])) + { + global $db; + + $sql = 'SELECT mark_time + FROM ' . FORUMS_TRACK_TABLE . " + WHERE user_id = {$user->data['user_id']} + AND forum_id = 0"; + $result = $db->sql_query($sql); + $row = $db->sql_fetchrow($result); + $db->sql_freeresult($result); + + if ($row) + { + $mark_time[0] = $row['mark_time']; + } + } + else + { + if ($forum_mark_time[0] !== false) + { + $mark_time[0] = $forum_mark_time[0]; + } + } + } + + if (!empty($forum_mark_time[$forum_id]) && $forum_mark_time[$forum_id] !== false) + { + $mark_time[$forum_id] = $forum_mark_time[$forum_id]; + } + + $user_lastmark = (isset($mark_time[$forum_id])) ? $mark_time[$forum_id] : $user->data['user_lastmark']; + + foreach ($topic_ids as $topic_id) + { + if ($global_announce_list && isset($global_announce_list[$topic_id])) + { + $last_read[$topic_id] = (isset($mark_time[0])) ? $mark_time[0] : $user_lastmark; + } + else + { + $last_read[$topic_id] = $user_lastmark; + } + } + } + + return $last_read; +} + +/** +* Get topic tracking info from db (for cookie based tracking only this function is used) +*/ +function get_complete_topic_tracking($forum_id, $topic_ids, $global_announce_list = false) +{ + global $config, $user; + + $last_read = array(); + + if (!is_array($topic_ids)) + { + $topic_ids = array($topic_ids); + } + + if ($config['load_db_lastread'] && $user->data['is_registered']) + { + global $db; + + $sql = 'SELECT topic_id, mark_time + FROM ' . TOPICS_TRACK_TABLE . " + WHERE user_id = {$user->data['user_id']} + AND topic_id IN (" . implode(', ', $topic_ids) . ")"; + $result = $db->sql_query($sql); + + while ($row = $db->sql_fetchrow($result)) + { + $last_read[$row['topic_id']] = $row['mark_time']; + } + $db->sql_freeresult($result); + + $topic_ids = array_diff($topic_ids, array_keys($last_read)); + + if (sizeof($topic_ids)) + { + $sql = 'SELECT forum_id, mark_time + FROM ' . FORUMS_TRACK_TABLE . " + WHERE user_id = {$user->data['user_id']} + AND forum_id " . + (($global_announce_list && sizeof($global_announce_list)) ? "IN (0, $forum_id)" : "= $forum_id"); + $result = $db->sql_query($sql); + + $mark_time = array(); + while ($row = $db->sql_fetchrow($result)) + { + $mark_time[$row['forum_id']] = $row['mark_time']; + } + $db->sql_freeresult($result); + + $user_lastmark = (isset($mark_time[$forum_id])) ? $mark_time[$forum_id] : $user->data['user_lastmark']; + + foreach ($topic_ids as $topic_id) + { + if ($global_announce_list && isset($global_announce_list[$topic_id])) + { + $last_read[$topic_id] = (isset($mark_time[0])) ? $mark_time[0] : $user_lastmark; + } + else + { + $last_read[$topic_id] = $user_lastmark; + } + } + } + } + else + { + global $tracking_topics; + + if (!isset($tracking_topics) || !sizeof($tracking_topics)) + { + $tracking_topics = (isset($_COOKIE[$config['cookie_name'] . '_track'])) ? unserialize(stripslashes($_COOKIE[$config['cookie_name'] . '_track'])) : array(); + } + + if (!$user->data['is_registered']) + { + $user_lastmark = (isset($tracking_topics['l'])) ? base_convert($tracking_topics['l'], 36, 10) + $config['board_startdate'] : 0; + } + else + { + $user_lastmark = $user->data['user_lastmark']; + } + + foreach ($topic_ids as $topic_id) + { + $topic_id36 = base_convert($topic_id, 10, 36); + + if (isset($tracking_topics['t'][$topic_id36])) + { + $last_read[$topic_id] = base_convert($tracking_topics['t'][$topic_id36], 36, 10) + $config['board_startdate']; + } + } + + $topic_ids = array_diff($topic_ids, array_keys($last_read)); + + if (sizeof($topic_ids)) + { + $mark_time = array(); + if ($global_announce_list && sizeof($global_announce_list)) + { + if (isset($tracking_topics['f'][0])) + { + $mark_time[0] = base_convert($tracking_topics['f'][0], 36, 10) + $config['board_startdate']; + } + } + + if (isset($tracking_topics['f'][$forum_id])) + { + $mark_time[$forum_id] = base_convert($tracking_topics['f'][$forum_id], 36, 10) + $config['board_startdate']; + } + + $user_lastmark = (isset($mark_time[$forum_id])) ? $mark_time[$forum_id] : $user_lastmark; + + foreach ($topic_ids as $topic_id) + { + if ($global_announce_list && isset($global_announce_list[$topic_id])) + { + $last_read[$topic_id] = (isset($mark_time[0])) ? $mark_time[0] : $user_lastmark; + } + else + { + $last_read[$topic_id] = $user_lastmark; + } + } + } + } + + return $last_read; } /** @@ -877,7 +1100,14 @@ function confirm_box($check, $title = '', $hidden = '', $html_body = 'confirm_bo // generate activation key $confirm_key = gen_rand_string(10); - page_header((!isset($user->lang[$title])) ? $user->lang['CONFIRM'] : $user->lang[$title]); + if (defined('IN_ADMIN') && isset($user->data['session_admin']) && $user->data['session_admin']) + { + adm_page_header((!isset($user->lang[$title])) ? $user->lang['CONFIRM'] : $user->lang[$title]); + } + else + { + page_header((!isset($user->lang[$title])) ? $user->lang['CONFIRM'] : $user->lang[$title]); + } $template->set_filenames(array( 'body' => $html_body) @@ -908,7 +1138,14 @@ function confirm_box($check, $title = '', $hidden = '', $html_body = 'confirm_bo WHERE user_id = " . $user->data['user_id']; $db->sql_query($sql); - page_footer(); + if (defined('IN_ADMIN') && isset($user->data['session_admin']) && $user->data['session_admin']) + { + adm_page_footer(); + } + else + { + page_footer(); + } } /** @@ -1292,11 +1529,12 @@ function msg_handler($errno, $msg_text, $errfile, $errline) { if (defined('IN_ADMIN') && isset($user->data['session_admin']) && $user->data['session_admin']) { - adm_page_header('', '', false); + // adm_page_header('', '', false); + adm_page_header(''); } else { - page_header(); + page_header(''); } } @@ -1304,26 +1542,19 @@ function msg_handler($errno, $msg_text, $errfile, $errline) $msg_title = (!isset($msg_title)) ? $user->lang['INFORMATION'] : ((!empty($user->lang[$msg_title])) ? $user->lang[$msg_title] : $msg_title); $display_header = (!isset($display_header)) ? false : (bool) $display_header; - if (defined('IN_ADMIN') && isset($user->data['session_admin']) && $user->data['session_admin']) - { - adm_page_message($msg_title, $msg_text, $display_header); - adm_page_footer(); - } - else - { - $template->set_filenames(array( - 'body' => 'message_body.html') - ); + $template->set_filenames(array( + 'body' => 'message_body.html') + ); - $template->assign_vars(array( - 'MESSAGE_TITLE' => $msg_title, - 'MESSAGE_TEXT' => $msg_text) - ); + $template->assign_vars(array( + 'MESSAGE_TITLE' => $msg_title, + 'MESSAGE_TEXT' => $msg_text) + ); + + // We do not want the cron script to be called on error messages + define('IN_CRON', true); + page_footer(); - // We do not want the cron script to be called on error messages - define('IN_CRON', true); - page_footer(); - } exit; break; } @@ -1700,6 +1931,14 @@ function page_footer() // Tidy some table rows every week $cron_type = 'tidy_database'; } +/** +* @todo add session garbage collection + + else if (time() - $config['session_gc'] > $config['session_last_gc']) + { + $cron_type = 'tidy_sessions'; + } +*/ if ($cron_type) { diff --git a/phpBB/includes/functions_admin.php b/phpBB/includes/functions_admin.php index 7fb8148726..6b2f9bb83e 100644 --- a/phpBB/includes/functions_admin.php +++ b/phpBB/includes/functions_admin.php @@ -11,7 +11,7 @@ /** * Recalculate Binary Tree */ -function recalc_btree($sql_id, $sql_table) +function recalc_btree($sql_id, $sql_table, $module_class = '') { global $db; @@ -25,8 +25,29 @@ function recalc_btree($sql_id, $sql_table) return; } + $sql_where = ($module_class) ? " WHERE module_class = '" . $db->sql_escape($module_class) . "'" : ' WHERE 1 '; + + // Reset to minimum possible left and right id + $sql = "SELECT MIN(left_id) as min_left_id, MIN(right_id) as min_right_id + FROM $sql_table + $sql_where"; + $result = $db->sql_query($sql); + $row = $db->sql_fetchrow($result); + $db->sql_freeresult($result); + + $substract = (int) (min($row['min_left_id'], $row['min_right_id']) - 1); + + if ($substract > 0) + { + $sql = "UPDATE $sql_table + SET left_id = left_id - $substract, right_id = right_id - $substract + $sql_where"; + $db->sql_query($sql); + } + $sql = "SELECT $sql_id, parent_id, left_id, right_id FROM $sql_table + $sql_where ORDER BY left_id ASC, parent_id ASC, $sql_id ASC"; $f_result = $db->sql_query($sql); @@ -36,7 +57,8 @@ function recalc_btree($sql_id, $sql_table) { $sql = "SELECT left_id, right_id FROM $sql_table - WHERE $sql_id = {$item_data['parent_id']}"; + $sql_where + AND $sql_id = {$item_data['parent_id']}"; $result = $db->sql_query($sql); if (!$row = $db->sql_fetchrow($result)) @@ -48,12 +70,14 @@ function recalc_btree($sql_id, $sql_table) $sql = "UPDATE $sql_table SET left_id = left_id + 2, right_id = right_id + 2 - WHERE left_id > {$row['right_id']}"; + $sql_where + AND left_id > {$row['right_id']}"; $db->sql_query($sql); $sql = "UPDATE $sql_table SET right_id = right_id + 2 - WHERE {$row['left_id']} BETWEEN left_id AND right_id"; + $sql_where + AND {$row['left_id']} BETWEEN left_id AND right_id"; $db->sql_query($sql); $item_data['left_id'] = $row['right_id']; @@ -62,7 +86,8 @@ function recalc_btree($sql_id, $sql_table) else { $sql = "SELECT MAX(right_id) AS right_id - FROM $sql_table"; + FROM $sql_table + $sql_where"; $result = $db->sql_query($sql); $row = $db->sql_fetchrow($result); @@ -450,7 +475,7 @@ function delete_topics($where_type, $where_ids, $auto_sync = TRUE) $db->sql_transaction('begin'); - $table_ary = array(TOPICS_TRACK_TABLE, POLL_VOTES_TABLE, POLL_OPTIONS_TABLE, TOPICS_WATCH_TABLE, TOPICS_TABLE); + $table_ary = array(TOPICS_TRACK_TABLE, TOPICS_POSTED_TABLE, POLL_VOTES_TABLE, POLL_OPTIONS_TABLE, TOPICS_WATCH_TABLE, TOPICS_TABLE); foreach ($table_ary as $table) { $sql = "DELETE FROM $table @@ -2335,13 +2360,13 @@ function update_post_information($type, $ids) } /** -* Tidy topic tracking tables +* Tidy database * Removes all tracking rows older than 6 months, including mark_posted informations */ function tidy_database() { global $db; - +/* $remove_date = time() - (3 * 62 * 24 * 3600); $sql = 'DELETE FROM ' . FORUMS_TRACK_TABLE . ' @@ -2351,7 +2376,7 @@ function tidy_database() $sql = 'DELETE FROM ' . TOPICS_TRACK_TABLE . ' WHERE mark_time < ' . $remove_date; $db->sql_query($sql); - +*/ set_config('database_last_gc', time(), true); } diff --git a/phpBB/includes/functions_display.php b/phpBB/includes/functions_display.php index 9622af8b26..c887c28aef 100644 --- a/phpBB/includes/functions_display.php +++ b/phpBB/includes/functions_display.php @@ -11,18 +11,30 @@ /** * Display Forums */ -function display_forums($root_data = '', $display_moderators = TRUE) +function display_forums($root_data = '', $display_moderators = true, $return_moderators = false) { - global $config, $db, $template, $auth, $user, $phpEx, $SID, $forum_moderators, $phpbb_root_path; + global $db, $auth, $user, $template; + global $phpbb_root_path, $phpEx, $SID, $config; - // Get posted/get info + $forum_rows = $subforums = $forum_ids = $forum_ids_moderator = $forum_moderators = $active_forum_ary = array(); + $parent_id = $visible_forums = 0; + $sql_from = $lastread_select = ''; + + // Mark forums read? $mark_read = request_var('mark', ''); - $forum_id_ary = $active_forum_ary = $forum_rows = $subforums = $forum_moderators = $mark_forums = array(); - $visible_forums = 0; + if ($mark_read == 'all') + { + $mark_read = ''; + } if (!$root_data) { + if ($mark_read == 'forums') + { + $mark_read = 'all'; + } + $root_data = array('forum_id' => 0); $sql_where = ''; } @@ -34,17 +46,9 @@ function display_forums($root_data = '', $display_moderators = TRUE) // Display list of active topics for this category? $show_active = (isset($root_data['forum_flags']) && $root_data['forum_flags'] & 16) ? true : false; - if ($config['load_db_lastread'] && $user->data['is_registered']) + if ($config['load_db_track'] && $user->data['is_registered']) { - switch (SQL_LAYER) - { - case 'oracle': - break; - - default: - $sql_from = '(' . FORUMS_TABLE . ' f LEFT JOIN ' . FORUMS_TRACK_TABLE . ' ft ON (ft.user_id = ' . $user->data['user_id'] . ' AND ft.forum_id = f.forum_id))'; - break; - } + $sql_from = '(' . FORUMS_TABLE . ' f LEFT JOIN ' . FORUMS_TRACK_TABLE . ' ft ON (ft.user_id = ' . $user->data['user_id'] . ' AND ft.forum_id = f.forum_id))'; $lastread_select = ', ft.mark_time '; } else @@ -53,6 +57,11 @@ function display_forums($root_data = '', $display_moderators = TRUE) $lastread_select = $sql_lastread = ''; $tracking_topics = (isset($_COOKIE[$config['cookie_name'] . '_track'])) ? unserialize(stripslashes($_COOKIE[$config['cookie_name'] . '_track'])) : array(); + + if (!$user->data['is_registered']) + { + $user->data['user_lastmark'] = (isset($tracking_topics['l'])) ? base_convert($tracking_topics['l'], 36, 10) + $config['board_startdate'] : 0; + } } $sql = "SELECT f.* $lastread_select @@ -61,20 +70,29 @@ function display_forums($root_data = '', $display_moderators = TRUE) ORDER BY f.left_id"; $result = $db->sql_query($sql); + $forum_tracking_info = array(); $branch_root_id = $root_data['forum_id']; - $forum_ids = array($root_data['forum_id']); while ($row = $db->sql_fetchrow($result)) { - if ($mark_read == 'forums' && $user->data['is_registered']) - { - if ($auth->acl_get('f_list', $row['forum_id'])) - { - $forum_id_ary[] = $row['forum_id']; - } + $forum_id = $row['forum_id']; + // Mark forums read? + if ($mark_read == 'forums' || $mark_read == 'all') + { + if ($auth->acl_get('f_list', $forum_id)) + { + $forum_ids[] = $forum_id; + continue; + } + } + + // Category with no members + if ($row['forum_type'] == FORUM_CAT && ($row['left_id'] + 1 == $row['right_id'])) + { continue; } + // Skip branch if (isset($right_id)) { if ($row['left_id'] < $right_id) @@ -84,14 +102,6 @@ function display_forums($root_data = '', $display_moderators = TRUE) unset($right_id); } - if ($row['forum_type'] == FORUM_CAT && ($row['left_id'] + 1 == $row['right_id'])) - { - // Non-postable forum with no subforums: don't display - continue; - } - - $forum_id = $row['forum_id']; - if (!$auth->acl_get('f_list', $forum_id)) { // if the user does not have permissions to list this forum, skip everything until next branch @@ -99,8 +109,17 @@ function display_forums($root_data = '', $display_moderators = TRUE) continue; } - - + $forum_ids[] = $forum_id; + + if ($config['load_db_lastread'] && $user->data['is_registered']) + { + $forum_tracking_info[$forum_id] = (!empty($row['mark_time'])) ? $row['mark_time'] : $user->data['user_lastmark']; + } + else + { + $forum_tracking_info[$forum_id] = (isset($tracking_topics['f'][$forum_id])) ? base_convert($tracking_topics['f'][$forum_id], 36, 10) + $config['board_startdate'] : $user->data['user_lastmark']; + } + // Display active topics from this forum? if ($show_active && $row['forum_type'] == FORUM_POST && $auth->acl_get('f_read', $forum_id) && ($row['forum_flags'] & 16)) { @@ -110,24 +129,26 @@ function display_forums($root_data = '', $display_moderators = TRUE) $active_forum_ary['forum_posts'] += $row['forum_posts']; } + // if ($row['parent_id'] == $root_data['forum_id'] || $row['parent_id'] == $branch_root_id) { - // Direct child + // Direct child of current branch $parent_id = $forum_id; $forum_rows[$forum_id] = $row; - $forum_ids[] = $forum_id; if (!$row['parent_id'] && $row['forum_type'] == FORUM_CAT && $row['parent_id'] == $root_data['forum_id']) { $branch_root_id = $forum_id; } $forum_rows[$parent_id]['forum_id_last_post'] = $row['forum_id']; + $forum_rows[$parent_id]['orig_forum_last_post_time'] = $row['forum_last_post_time']; } - elseif ($row['forum_type'] != FORUM_CAT) + else if ($row['forum_type'] != FORUM_CAT) { - $subforums[$parent_id]['display'] = ($row['display_on_index']) ? true : false;; - $subforums[$parent_id]['name'][$forum_id] = $row['forum_name']; - + $subforums[$parent_id][$forum_id]['display'] = ($row['display_on_index']) ? true : false; + $subforums[$parent_id][$forum_id]['name'] = $row['forum_name']; + $subforums[$parent_id][$forum_id]['orig_forum_last_post_time'] = $row['forum_last_post_time']; + $forum_rows[$parent_id]['forum_topics'] += ($auth->acl_get('m_approve', $forum_id)) ? $row['forum_topics_real'] : $row['forum_topics']; // Do not list redirects in LINK Forums as Posts. @@ -136,7 +157,7 @@ function display_forums($root_data = '', $display_moderators = TRUE) $forum_rows[$parent_id]['forum_posts'] += $row['forum_posts']; } - if (isset($forum_rows[$parent_id]) && $row['forum_last_post_time'] > $forum_rows[$parent_id]['forum_last_post_time']) + if ($row['forum_last_post_time'] > $forum_rows[$parent_id]['forum_last_post_time']) { $forum_rows[$parent_id]['forum_last_post_id'] = $row['forum_last_post_id']; $forum_rows[$parent_id]['forum_last_post_time'] = $row['forum_last_post_time']; @@ -150,113 +171,104 @@ function display_forums($root_data = '', $display_moderators = TRUE) } } - if (!isset($row['mark_time'])) - { - $row['mark_time'] = 0; - } + $forum_ids_moderator[$parent_id] = $forum_rows[$parent_id]['forum_id_last_post']; - $mark_time_forum = ($config['load_db_lastread']) ? $row['mark_time'] : ((isset($tracking_topics[$forum_id][0])) ? base_convert($tracking_topics[$forum_id][0], 36, 10) + $config['board_startdate'] : 0); - - if ($mark_time_forum < $row['forum_last_post_time'] && $user->data['is_registered']) - { - $forum_unread[$parent_id] = true; - } } $db->sql_freeresult($result); // Handle marking posts - if ($mark_read == 'forums') + if ($mark_read == 'forums' || $mark_read == 'all') { - markread('mark', $forum_id_ary); - $redirect = (!empty($_SERVER['REQUEST_URI'])) ? preg_replace('#^(.*?)&(amp;)?mark=.*$#', '\1', htmlspecialchars($_SERVER['REQUEST_URI'])) : "index.$phpEx$SID"; - meta_refresh(3, $redirect); - $message = (strpos($redirect, 'viewforum') !== false) ? 'RETURN_FORUM' : 'RETURN_INDEX'; - $message = $user->lang['FORUMS_MARKED'] . '

' . sprintf($user->lang[$message], '', ' '); + if ($mark_read == 'all') + { + markread('all'); + + $message = sprintf($user->lang['RETURN_INDEX'], '', ''); + } + else + { + markread('topics', $forum_ids); + + $message = sprintf($user->lang['RETURN_FORUM'], '', ''); + } + + meta_refresh(3, $redirect); + + $message = $user->lang['FORUMS_MARKED'] . '

' . $message; trigger_error($message); } // Grab moderators ... if necessary if ($display_moderators) { - get_moderators($forum_moderators, $forum_ids); + if ($return_moderators) + { + $forum_ids_moderator[] = $root_data['forum_id']; + } + get_moderators($forum_moderators, $forum_ids_moderator); } - // Loop through the forums - $root_id = $root_data['forum_id']; - foreach ($forum_rows as $row) { - if ($row['parent_id'] == $root_id && !$row['parent_id']) - { - if ($row['forum_type'] == FORUM_CAT) - { - $hold = $row; - continue; - } - else - { - unset($hold); - } - } - else if (!empty($hold)) + // Empty category + if (!$row['parent_id'] && $row['forum_type'] == FORUM_CAT) { $template->assign_block_vars('forumrow', array( - 'S_IS_CAT' => TRUE, - 'FORUM_ID' => $hold['forum_id'], - 'FORUM_NAME' => $hold['forum_name'], - 'FORUM_DESC' => $hold['forum_desc'], - 'U_VIEWFORUM' => "viewforum.$phpEx$SID&f=" . $hold['forum_id']) + 'S_IS_CAT' => true, + 'FORUM_ID' => $row['forum_id'], + 'FORUM_NAME' => $row['forum_name'], + 'FORUM_DESC' => $row['forum_desc'], + 'U_VIEWFORUM' => "{$phpbb_root_path}viewforum.$phpEx$SID&f=" . $row['forum_id']) ); - unset($hold); + + continue; } $visible_forums++; $forum_id = $row['forum_id']; - $subforums_list = $l_subforums = ''; + $forum_unread = (isset($forum_tracking_info[$forum_id]) && $row['orig_forum_last_post_time'] > $forum_tracking_info[$forum_id]) ? true : false; + + $folder_image = $folder_alt = $subforums_list = $l_subforums = ''; // Generate list of subforums if we need to if (isset($subforums[$forum_id])) { - if ($subforums[$forum_id]['display']) + foreach ($subforums[$forum_id] as $subforum_id => $subforum_row) { - $alist = array(); - foreach ($subforums[$forum_id]['name'] as $sub_forum_id => $subforum_name) + // Update unread information if needed + if (!$forum_unread) { - if (!empty($subforum_name)) - { - $alist[$sub_forum_id] = $subforum_name; - } + $forum_unread = (isset($forum_tracking_info[$subforum_id]) && $subforum_row['orig_forum_last_post_time'] > $forum_tracking_info[$subforum_id]) ? true : false; } - if (sizeof($alist)) + if ($subforum_row['display'] && $subforum_row['name']) { - $links = array(); - foreach ($alist as $subforum_id => $subforum_name) - { - $links[] = '' . $subforum_name . ''; - } - $subforums_list = implode(', ', $links); - - $l_subforums = (sizeof($subforums[$forum_id]) == 1) ? $user->lang['SUBFORUM'] . ': ' : $user->lang['SUBFORUMS'] . ': '; + $subforums_list .= ($subforums_list == '') ? '' : ', '; + $subforums_list .= '{$subforum_row['name']}"; + } + else + { + unset($subforums[$forum_id][$subforum_id]); } } - - $folder_image = (!empty($forum_unread[$forum_id])) ? 'sub_forum_new' : 'sub_forum'; + + $l_subforums = (sizeof($subforums[$forum_id]) == 1) ? $user->lang['SUBFORUM'] . ': ' : $user->lang['SUBFORUMS'] . ': '; + $folder_image = ($forum_unread) ? 'sub_forum_new' : 'sub_forum'; } else { switch ($row['forum_type']) { case FORUM_POST: - $folder_image = (!empty($forum_unread[$forum_id])) ? 'forum_new' : 'forum'; - break; + $folder_image = ($forum_unread) ? 'forum_new' : 'forum'; + break; case FORUM_LINK: $folder_image = 'forum_link'; - break; + break; } } @@ -268,7 +280,7 @@ function display_forums($root_data = '', $display_moderators = TRUE) } else { - $folder_alt = (!empty($forum_unread[$forum_id])) ? 'NEW_POSTS' : 'NO_NEW_POSTS'; + $folder_alt = ($forum_unread) ? 'NEW_POSTS' : 'NO_NEW_POSTS'; } // Create last post link information, if appropriate @@ -277,9 +289,9 @@ function display_forums($root_data = '', $display_moderators = TRUE) $last_post_time = $user->format_date($row['forum_last_post_time']); $last_poster = ($row['forum_last_poster_name'] != '') ? $row['forum_last_poster_name'] : $user->lang['GUEST']; - $last_poster_url = ($row['forum_last_poster_id'] == ANONYMOUS) ? '' : "memberlist.$phpEx$SID&mode=viewprofile&u=" . $row['forum_last_poster_id']; + $last_poster_url = ($row['forum_last_poster_id'] == ANONYMOUS) ? '' : "{$phpbb_root_path}memberlist.$phpEx$SID&mode=viewprofile&u={$row['forum_last_poster_id']}"; - $last_post_url = "viewtopic.$phpEx$SID&f=" . $row['forum_id_last_post'] . '&p=' . $row['forum_last_post_id'] . '#' . $row['forum_last_post_id']; + $last_post_url = "{$phpbb_root_path}viewtopic.$phpEx$SID&f=" . $row['forum_id_last_post'] . '&p=' . $row['forum_last_post_id'] . '#' . $row['forum_last_post_id']; } else { @@ -299,40 +311,44 @@ function display_forums($root_data = '', $display_moderators = TRUE) $template->assign_block_vars('forumrow', array( 'S_IS_CAT' => false, - 'S_IS_LINK' => ($row['forum_type'] != FORUM_LINK) ? false : true, + 'S_IS_LINK' => ($row['forum_type'] == FORUM_LINK) ? true : false, - 'LAST_POST_IMG' => $user->img('icon_post_latest', 'VIEW_LATEST_POST'), - - 'FORUM_ID' => $row['forum_id'], - 'FORUM_FOLDER_IMG' => ($row['forum_image']) ? '' . $folder_alt . '' : $user->img($folder_image, $folder_alt), + 'FORUM_ID' => $row['forum_id'], + 'FORUM_NAME' => $row['forum_name'], + 'FORUM_DESC' => $row['forum_desc'], + 'TOPICS' => $row['forum_topics'], + $l_post_click_count => $post_click_count, + 'FORUM_FOLDER_IMG' => ($row['forum_image']) ? '' . $user->lang['folder_alt'] . '' : $user->img($folder_image, $folder_alt), 'FORUM_FOLDER_IMG_SRC' => ($row['forum_image']) ? $phpbb_root_path . $row['forum_image'] : $user->img($folder_image, $folder_alt, false, '', 'src'), - 'FORUM_NAME' => $row['forum_name'], - 'FORUM_DESC' => $row['forum_desc'], - $l_post_click_count => $post_click_count, - 'TOPICS' => $row['forum_topics'], - 'LAST_POST_TIME' => $last_post_time, - 'LAST_POSTER' => $last_poster, - 'MODERATORS' => $moderators_list, - 'SUBFORUMS' => $subforums_list, + 'SUBFORUMS' => $subforums_list, + 'LAST_POST_TIME' => $last_post_time, + 'LAST_POSTER' => $last_poster, + 'MODERATORS' => $moderators_list, 'L_SUBFORUM_STR' => $l_subforums, - 'L_MODERATOR_STR' => $l_moderator, 'L_FORUM_FOLDER_ALT'=> $folder_alt, + 'L_MODERATOR_STR' => $l_moderator, + 'U_VIEWFORUM' => ($row['forum_type'] != FORUM_LINK || $row['forum_flags'] & 1) ? "{$phpbb_root_path}viewforum.$phpEx$SID&f={$row['forum_id']}" : $row['forum_link'], 'U_LAST_POSTER' => $last_poster_url, 'U_LAST_POST' => $last_post_url, - 'U_VIEWFORUM' => ($row['forum_type'] != FORUM_LINK || $row['forum_flags'] & 1) ? "viewforum.$phpEx$SID&f=" . $row['forum_id'] : $row['forum_link']) + ) ); } $template->assign_vars(array( - 'U_MARK_FORUMS' => "viewforum.$phpEx$SID&f=" . $root_data['forum_id'] . '&mark=forums', - - 'S_HAS_SUBFORUM' => ($visible_forums) ? true : false, - - 'L_SUBFORUM' => ($visible_forums == 1) ? $user->lang['SUBFORUM'] : $user->lang['SUBFORUMS']) + 'U_MARK_FORUMS' => "{$phpbb_root_path}viewforum.$phpEx$SID&f=" . $root_data['forum_id'] . '&mark=forums', + 'S_HAS_SUBFORUM' => ($visible_forums) ? true : false, + 'L_SUBFORUM' => ($visible_forums == 1) ? $user->lang['SUBFORUM'] : $user->lang['SUBFORUMS'], + 'LAST_POST_IMG' => $user->img('icon_post_latest', 'VIEW_LATEST_POST'), + ) ); + if ($return_moderators) + { + return array($active_forum_ary, $forum_moderators); + } + return $active_forum_ary; } @@ -509,33 +525,33 @@ function topic_generate_pagination($replies, $url) */ function get_moderators(&$forum_moderators, $forum_id = false) { - global $config, $template, $db, $phpEx, $SID; + global $config, $template, $db, $phpbb_root_path, $phpEx, $SID; // Have we disabled the display of moderators? If so, then return // from whence we came ... - if (empty($config['load_moderators'])) + if (!$config['load_moderators']) { return; } - if (!empty($forum_id) && is_array($forum_id)) + if ($forum_id !== false && is_array($forum_id)) { $forum_sql = 'AND forum_id IN (' . implode(', ', $forum_id) . ')'; } else { - $forum_sql = ($forum_id) ? 'AND forum_id = ' . $forum_id : ''; + $forum_sql = ($forum_id !== false) ? 'AND forum_id = ' . $forum_id : ''; } $sql = 'SELECT * FROM ' . MODERATOR_TABLE . " WHERE display_on_index = 1 $forum_sql"; - $result = $db->sql_query($sql); + $result = $db->sql_query($sql, 3600); while ($row = $db->sql_fetchrow($result)) { - $forum_moderators[$row['forum_id']][] = (!empty($row['user_id'])) ? '' . $row['username'] . '' : '' . $row['groupname'] . ''; + $forum_moderators[$row['forum_id']][] = (!empty($row['user_id'])) ? '' . $row['username'] . '' : '' . $row['groupname'] . ''; } $db->sql_freeresult($result); @@ -568,12 +584,11 @@ function gen_forum_auth_level($mode, $forum_id) /** * Generate topic status */ -function topic_status(&$topic_row, $replies, $mark_time_topic, $mark_time_forum, &$folder_img, &$folder_alt, &$topic_type) +function topic_status(&$topic_row, $replies, $unread_topic, &$folder_img, &$folder_alt, &$topic_type) { global $user, $config; $folder = $folder_new = ''; - $unread_topic = false; if ($topic_row['topic_status'] == ITEM_MOVED) { @@ -619,34 +634,11 @@ function topic_status(&$topic_row, $replies, $mark_time_topic, $mark_time_forum, $folder_new = 'folder_locked_new'; } - if ($user->data['is_registered']) - { - $unread_topic = $new_votes = true; - - if ($mark_time_topic >= $topic_row['topic_last_post_time'] || $mark_time_forum >= $topic_row['topic_last_post_time']) //|| ($topic_row['topic_last_post_time'] == $topic_row['poll_last_vote'] && $replies)) - { - $unread_topic = false; - } -/* - if ($topic_row['poll_start'] && ($mark_time_topic >= $topic_row['poll_last_vote'] || $mark_time_forum >= $topic_row['poll_last_vote'])) - { - $new_votes = false; - } -*/ - } - else - { - $unread_topic = false; - //$unread_topic = $new_votes = false; - } - -// $folder_new .= ($new_votes) ? '_vote' : ''; - $folder_img = ($unread_topic) ? $folder_new : $folder; $folder_alt = ($unread_topic) ? 'NEW_POSTS' : (($topic_row['topic_status'] == ITEM_LOCKED) ? 'TOPIC_LOCKED' : 'NO_NEW_POSTS'); // Posted image? - if (!empty($topic_row['mark_type'])) + if (!empty($topic_row['topic_posted']) && $topic_row['topic_posted']) { $folder_img .= '_posted'; } @@ -656,8 +648,6 @@ function topic_status(&$topic_row, $replies, $mark_time_topic, $mark_time_forum, { $topic_type .= $user->lang['VIEW_TOPIC_POLL']; } - - return $unread_topic; } /** diff --git a/phpBB/includes/functions_module.php b/phpBB/includes/functions_module.php index f40feb9415..e88a506121 100644 --- a/phpBB/includes/functions_module.php +++ b/phpBB/includes/functions_module.php @@ -105,7 +105,11 @@ class p_master foreach ($this->module_cache['modules'] as $row) { - // Authorisation is required ... not authed, skip + /** + * Authorisation is required ... not authed, skip + * @todo implement $this->is_module_id + * @todo put in seperate method for authentication + */ if ($row['module_auth']) { $is_auth = false; @@ -141,7 +145,7 @@ class p_master $right = $row['right_id']; - $module_data = array( + $this->module_ary[$i] = array( 'depth' => $depth, 'id' => (int) $row['module_id'], @@ -151,15 +155,13 @@ class p_master 'name' => (string) $row['module_name'], 'mode' => (string) $row['module_mode'], - 'lang' => (function_exists($row['module_name'])) ? $row['module_name']($row['module_mode'], $row['module_langname']) : ((!empty($user->lang[$row['module_langname']])) ? $user->lang[$row['module_langname']] : ucfirst(str_replace('_', ' ', strtolower($row['module_langname'])))), + 'lang' => (function_exists($row['module_name'])) ? $row['module_name']($row['module_mode'], $row['module_langname']) : ((!empty($user->lang[$row['module_langname']])) ? $user->lang[$row['module_langname']] : $row['module_langname']), 'langname' => $row['module_langname'], 'left' => $row['left_id'], 'right' => $row['right_id'], ); - $this->module_ary[$i] = $module_data; - $i++; } @@ -274,9 +276,7 @@ class p_master function assign_tpl_vars($module_url) { - global $template, $db; - - $parents = $this->module_cache['parents']; + global $template; $current_padding = $current_depth = 0; $linear_offset = 'l_block1'; @@ -305,13 +305,13 @@ class p_master } // Only output a categories items if it's currently selected - if (!$depth || ($depth && (in_array($itep_ary['parent'], array_values($parents)) || $itep_ary['parent'] == $this->p_parent))) + if (!$depth || ($depth && (in_array($itep_ary['parent'], array_values($this->module_cache['parents'])) || $itep_ary['parent'] == $this->p_parent))) { $use_tabular_offset = (!$depth) ? 't_block1' : $tabular_offset; $tpl_ary = array( 'L_TITLE' => $itep_ary['lang'], - 'S_SELECTED' => (in_array($itep_ary['id'], array_keys($parents)) || $itep_ary['id'] == $this->p_id) ? true : false, + 'S_SELECTED' => (in_array($itep_ary['id'], array_keys($this->module_cache['parents'])) || $itep_ary['id'] == $this->p_id) ? true : false, 'U_TITLE' => $module_url . '&i=' . (($itep_ary['cat']) ? $itep_ary['id'] : $itep_ary['name'] . '&mode=' . $itep_ary['mode']) ); @@ -320,7 +320,7 @@ class p_master $tpl_ary = array( 'L_TITLE' => $itep_ary['lang'], - 'S_SELECTED' => (in_array($itep_ary['id'], array_keys($parents)) || $itep_ary['id'] == $this->p_id) ? true : false, + 'S_SELECTED' => (in_array($itep_ary['id'], array_keys($this->module_cache['parents'])) || $itep_ary['id'] == $this->p_id) ? true : false, 'U_TITLE' => $module_url . '&i=' . (($itep_ary['cat']) ? $itep_ary['id'] : $itep_ary['name'] . '&mode=' . $itep_ary['mode']) ); diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index d868235319..f4e27b4138 100644 --- a/phpBB/includes/functions_user.php +++ b/phpBB/includes/functions_user.php @@ -66,7 +66,7 @@ function user_get_id_name(&$user_id_ary, &$username_ary) */ function user_update_name($old_name, $new_name) { - global $config, $db; + global $config, $db, $cache; $update_ary = array( FORUMS_TABLE => array('forum_last_poster_name'), @@ -176,7 +176,7 @@ function user_delete($mode, $user_id) break; } - $table_ary = array(USERS_TABLE, USER_GROUP_TABLE, TOPICS_WATCH_TABLE, FORUMS_WATCH_TABLE, ACL_USERS_TABLE, TOPICS_TRACK_TABLE, FORUMS_TRACK_TABLE); + $table_ary = array(USERS_TABLE, USER_GROUP_TABLE, TOPICS_WATCH_TABLE, FORUMS_WATCH_TABLE, ACL_USERS_TABLE, TOPICS_TRACK_TABLE, TOPICS_POSTED_TABLE, FORUMS_TRACK_TABLE); foreach ($table_ary as $table) { diff --git a/phpBB/includes/session.php b/phpBB/includes/session.php index 62d100156d..e2141dde59 100644 --- a/phpBB/includes/session.php +++ b/phpBB/includes/session.php @@ -43,8 +43,6 @@ class session $this->time_now = time(); $this->browser = (!empty($_SERVER['HTTP_USER_AGENT'])) ? $_SERVER['HTTP_USER_AGENT'] : ''; -// $this->page = (!empty($_SERVER['REQUEST_URI'])) ? preg_replace('#/?' . preg_quote($config['script_path'], '#') . '/?([a-z]+?\.' . $phpEx . '\?)sid=[a-z0-9]*(.*?)$#i', '\1\2', $_SERVER['REQUEST_URI']) . ((isset($_POST['f'])) ? 'f=' . intval($_POST['f']) : '') : ''; - $this->page = (!empty($_SERVER['REQUEST_URI'])) ? $_SERVER['REQUEST_URI'] . ((isset($_POST['f'])) ? 'f=' . intval($_POST['f']) : '') : ''; $sid = substr($this->page, strpos($this->page, 'sid='), 36); $this->page = str_replace(array('/' . $config['script_path'] . '/', (strlen($sid) == 36 && strpos($sid, '&') === false) ? $sid : 'sid='), '', $this->page); @@ -175,8 +173,7 @@ class session foreach ($active_bots as $row) { -// if ($row['bot_agent'] && preg_match('#' . preg_quote($row['bot_agent'], '#') . '#i', $this->browser)) - if ($row['bot_agent'] && strpos($this->browser, $row['bot_agent']) !== false) + if ($row['bot_agent'] && strpos(strtolower($this->browser), strtolower($row['bot_agent'])) !== false) { $bot = $row['user_id']; } @@ -270,7 +267,7 @@ class session $this->data = array_merge($sdata, $this->data); unset($sdata); $this->session_id = $this->data['session_id']; - } + } $db->sql_freeresult($result); $this->data['session_last_visit'] = (isset($this->data['session_time']) && $this->data['session_time']) ? $this->data['session_time'] : (($this->data['user_lastvisit']) ? $this->data['user_lastvisit'] : time()); @@ -440,11 +437,18 @@ class session * data before those sessions are destroyed. In addition this method * removes autologin key information that is older than an admin defined * limit. + * + * @todo add to cron */ function session_gc() { global $db, $config; + if (!$this->time_now) + { + $this->time_now = time(); + } + switch (SQL_LAYER) { case 'mysql4': @@ -531,6 +535,13 @@ class session break; } + if (!empty($config['max_autologin_time'])) + { + $sql = 'DELETE FROM ' . SESSIONS_KEYS_TABLE . ' + WHERE last_login < ' . (time() - (86400 * (int) $config['max_autologin_time'])); + $db->sql_query($sql); + } + return; } @@ -611,7 +622,7 @@ class session if ($this->data['user_id'] != ANONYMOUS) { $this->session_kill(); - } + } // Determine which message to output $till_date = (!empty($ban_row['ban_end'])) ? $this->format_date($ban_row['ban_end']) : ''; $message = (!empty($ban_row['ban_end'])) ? 'BOARD_BAN_TIME' : 'BOARD_BAN_PERM'; @@ -666,25 +677,6 @@ class session return false; } - - /** - * Remove stale login keys - * - * @private - */ - function tidy_login_keys() - { - global $config, $db; - - if (!empty($config['max_autologin_time'])) - { - $sql = 'DELETE FROM ' . SESSIONS_KEYS_TABLE . ' - WHERE last_login < ' . (time() - (86400 * (int) $config['max_autologin_time'])); - $db->sql_query($sql); - } - - return false; - } } diff --git a/phpBB/includes/ucp/ucp_main.php b/phpBB/includes/ucp/ucp_main.php index d7e16caabb..72c43a6f7b 100644 --- a/phpBB/includes/ucp/ucp_main.php +++ b/phpBB/includes/ucp/ucp_main.php @@ -32,6 +32,7 @@ class ucp_main $user->add_lang('memberlist'); +/* if ($config['load_db_lastread'] || $config['load_db_track']) { if ($config['load_db_lastread']) @@ -75,6 +76,23 @@ class ucp_main { $forum_check = (isset($tracking_topics[0][0])) ? base_convert($tracking_topics[0][0], 36, 10) + $config['board_startdate'] : 0; } +*/ + $sql_from = TOPICS_TABLE . ' t '; + $sql_select = ''; + + if ($config['load_db_track']) + { + $sql_from .= ' LEFT JOIN ' . TOPICS_POSTED_TABLE . ' tp ON (tp.topic_id = t.topic_id + AND tp.user_id = ' . $user->data['user_id'] . ')'; + $sql_select .= ', tp.topic_posted'; + } + + if ($config['load_db_lastread']) + { + $sql_from .= ' LEFT JOIN ' . TOPICS_TRACK_TABLE . ' tt ON (tt.topic_id = t.topic_id + AND tt.user_id = ' . $user->data['user_id'] . ')'; + $sql_select .= ', tt.mark_time'; + } $topic_type = $user->lang['VIEW_TOPIC_ANNOUNCEMENT']; $folder = 'folder_announce'; @@ -108,11 +126,25 @@ class ucp_main ORDER BY t.topic_last_post_time DESC'; $result = $db->sql_query($sql); + $topic_list = $rowset = array(); while ($row = $db->sql_fetchrow($result)) { + $topic_list[] = $row['topic_id']; + $rowset[$row['topic_id']] = $row; + } + $db->sql_freeresult($result); + + $topic_tracking_info = get_topic_tracking(0, $topic_list, $rowset, array(0 => false), $topic_list); + + foreach ($topic_list as $topic_id) + { + $row = &$rowset[$topic_id]; + $forum_id = $row['forum_id']; $topic_id = $row['topic_id']; + $unread_topic = (isset($topic_tracking_info[$topic_id]) && $row['topic_last_post_time'] > $topic_tracking_info[$topic_id]) ? true : false; + if ($row['topic_status'] == ITEM_LOCKED) { $topic_type = $user->lang['VIEW_TOPIC_LOCKED']; @@ -120,38 +152,20 @@ class ucp_main $folder_new = 'folder_locked_new'; } - $unread_topic = true; - - if ($config['load_db_lastread']) - { - $topic_check = $row['mark_time']; - } - else - { - $topic_id36 = base_convert($topic_id, 10, 36); - $topic_check = (isset($tracking_topics[0][$topic_id36])) ? base_convert($tracking_topics[0][$topic_id36], 36, 10) + $config['board_startdate'] : 0; - } - - if ($topic_check >= $row['topic_last_post_time'] || $forum_check >= $row['topic_last_post_time']) - { - $unread_topic = false; - } - - $newest_post_img = ($unread_topic) ? "" . $user->img('icon_post_newest', 'VIEW_NEWEST_POST') . ' ' : ''; + $newest_post_img = ($unread_topic) ? "" . $user->img('icon_post_newest', 'VIEW_NEWEST_POST') . ' ' : ''; $folder_img = ($unread_topic) ? $folder_new : $folder; $folder_alt = ($unread_topic) ? 'NEW_POSTS' : (($row['topic_status'] == ITEM_LOCKED) ? 'TOPIC_LOCKED' : 'NO_NEW_POSTS'); // Posted image? - if (!empty($row['mark_type'])) + if (!empty($row['topic_posted']) && $row['topic_posted']) { $folder_img .= '_posted'; } - $view_topic_url = "viewtopic.$phpEx$SID&f=$g_forum_id&t=$topic_id"; + $view_topic_url = "{$phpbb_root_path}viewtopic.$phpEx$SID&f=$g_forum_id&t=$topic_id"; + $last_post_img = "' . $user->img('icon_post_latest', 'VIEW_LATEST_POST') . ''; - $last_post_img = "' . $user->img('icon_post_latest', 'VIEW_LATEST_POST') . ''; - - $last_post_author = ($row['topic_last_poster_id'] == ANONYMOUS) ? (($row['topic_last_poster_name'] != '') ? $row['topic_last_poster_name'] . ' ' : $user->lang['GUEST'] . ' ') : "' . $row['topic_last_poster_name'] . ''; + $last_post_author = ($row['topic_last_poster_id'] == ANONYMOUS) ? (($row['topic_last_poster_name'] != '') ? $row['topic_last_poster_name'] . ' ' : $user->lang['GUEST'] . ' ') : "' . $row['topic_last_poster_name'] . ''; $template->assign_block_vars('topicrow', array( 'FORUM_ID' => $forum_id, @@ -166,12 +180,11 @@ class ucp_main 'TOPIC_FOLDER_IMG' => $user->img($folder_img, $folder_alt), 'ATTACH_ICON_IMG' => ($auth->acl_gets('f_download', 'u_download', $forum_id) && $row['topic_attachment']) ? $user->img('icon_attach', '') : '', - 'S_USER_POSTED' => (!empty($row['mark_type'])) ? true : false, + 'S_USER_POSTED' => (!empty($row['topic_posted']) && $row['topic_posted']) ? true : false, 'U_VIEW_TOPIC' => $view_topic_url) ); } - $db->sql_freeresult($result); $post_count_ary = $auth->acl_getf('f_postcount'); @@ -328,15 +341,7 @@ class ucp_main if ($config['load_db_lastread']) { - switch (SQL_LAYER) - { - case 'oracle': - break; - - default: - $sql_from = '(' . FORUMS_TABLE . ' f LEFT JOIN ' . FORUMS_TRACK_TABLE . ' ft ON (ft.user_id = ' . $user->data['user_id'] . ' AND ft.forum_id = f.forum_id))'; - break; - } + $sql_from = '(' . FORUMS_TABLE . ' f LEFT JOIN ' . FORUMS_TRACK_TABLE . ' ft ON (ft.user_id = ' . $user->data['user_id'] . ' AND ft.forum_id = f.forum_id))'; $lastread_select = ', ft.mark_time '; } else @@ -358,14 +363,17 @@ class ucp_main { $forum_id = $row['forum_id']; - $unread_forum = false; - $forum_check = (!$config['load_db_lastread']) ? $tracking_topics[$forum_id][0] : $row['mark_time']; - - if ($forum_check < $row['forum_last_post_time']) + if ($config['load_db_lastread']) { - $unread_forum = true; + $forum_check = (!empty($row['mark_time'])) ? $row['mark_time'] : $user->data['user_lastmark']; } - + else + { + $forum_check = (isset($tracking_topics['f'][$forum_id])) ? base_convert($tracking_topics['f'][$forum_id], 36, 10) + $config['board_startdate'] : $user->data['user_lastmark']; + } + + $unread_forum = ($row['forum_last_post_time'] > $forum_check) ? true : false; + // Which folder should we display? if ($row['forum_status'] == ITEM_LOCKED) { @@ -429,12 +437,35 @@ class ucp_main ); } + /* $sql_from = ($config['load_db_lastread'] || $config['load_db_track']) ? '(' . TOPICS_TABLE . ' t LEFT JOIN ' . TOPICS_TRACK_TABLE . ' tt ON (tt.topic_id = t.topic_id AND tt.user_id = ' . $user->data['user_id'] . '))' : TOPICS_TABLE . ' t'; $sql_f_tracking = ($config['load_db_lastread']) ? 'LEFT JOIN ' . FORUMS_TRACK_TABLE . ' ft ON (ft.forum_id = t.forum_id AND ft.user_id = ' . $user->data['user_id'] . ')' : ''; $sql_t_select = ($config['load_db_lastread'] || $config['load_db_track']) ? ', tt.mark_type, tt.mark_time' : ''; $sql_f_select = ($config['load_db_lastread']) ? ', ft.mark_time AS forum_mark_time' : ''; - + */ + + $sql_f_tracking = ($config['load_db_lastread']) ? 'LEFT JOIN ' . FORUMS_TRACK_TABLE . ' ft ON (ft.forum_id = t.forum_id AND ft.user_id = ' . $user->data['user_id'] . ')' : ''; + $sql_f_select = ($config['load_db_lastread']) ? ', ft.mark_time AS forum_mark_time' : ''; + + $sql_from = TOPICS_TABLE . ' t'; + $sql_t_select = ''; + + if ($config['load_db_track']) + { + $sql_from .= ' LEFT JOIN ' . TOPICS_POSTED_TABLE . ' tp ON (tp.topic_id = t.topic_id + AND tp.user_id = ' . $user->data['user_id'] . ')'; + $sql_t_select .= ', tp.topic_posted'; + } + + if ($config['load_db_lastread']) + { + $sql_from .= ' LEFT JOIN ' . TOPICS_TRACK_TABLE . ' tt ON (tt.topic_id = t.topic_id + AND tt.user_id = ' . $user->data['user_id'] . ')'; + $sql_t_select .= ', tt.mark_time'; + } + + $sql = "SELECT t.* $sql_f_select $sql_t_select FROM $sql_from $sql_f_tracking, " . TOPICS_WATCH_TABLE . ' tw WHERE tw.user_id = ' . $user->data['user_id'] . ' @@ -442,24 +473,32 @@ class ucp_main ORDER BY t.topic_last_post_time DESC'; $result = $db->sql_query_limit($sql, $config['topics_per_page'], $start); + $topic_list = $global_announce_list = $rowset = array(); while ($row = $db->sql_fetchrow($result)) { - $topic_id = $row['topic_id']; - $forum_id = $row['forum_id']; - - if ($config['load_db_lastread']) - { - $mark_time_topic = ($user->data['is_registered']) ? $row['mark_time'] : 0; - $mark_time_forum = $row['forum_mark_time']; - } - else - { - $topic_id36 = base_convert($topic_id, 10, 36); - $forum_id36 = ($row['topic_type'] == POST_GLOBAL) ? 0 : $forum_id; - $mark_time_topic = (isset($tracking_topics[$forum_id36][$topic_id36])) ? base_convert($tracking_topics[$forum_id36][$topic_id36], 36, 10) + $config['board_startdate'] : 0; + $topic_list[] = $row['topic_id']; + $rowset[$row['topic_id']] = $row; - $mark_time_forum = (isset($tracking_topics[$forum_id][0])) ? base_convert($tracking_topics[$forum_id][0], 36, 10) + $config['board_startdate'] : 0; + if ($row['topic_type'] == POST_GLOBAL) + { + $global_announce_list[] = $row['topic_id']; } + } + $db->sql_freeresult($result); + + /** + * @todo get_topic_tracking able to fetch from multiple forums + */ + $topic_tracking_info = get_topic_tracking(0, $topic_list, $rowset, array(0 => false), $global_announce_list); + + foreach ($topic_list as $topic_id) + { + $row = &$rowset[$topic_id]; + + $forum_id = $row['forum_id']; + $topic_id = $row['topic_id']; + + $unread_topic = (isset($topic_tracking_info[$topic_id]) && $row['topic_last_post_time'] > $topic_tracking_info[$topic_id]) ? true : false; // Replies $replies = ($auth->acl_get('m_approve', $forum_id)) ? $row['topic_replies_real'] : $row['topic_replies']; @@ -471,7 +510,7 @@ class ucp_main // Get folder img, topic status/type related informations $folder_img = $folder_alt = $topic_type = ''; - $unread_topic = topic_status($row, $replies, $mark_time_topic, $mark_time_forum, $folder_img, $folder_alt, $topic_type); + topic_status($row, $replies, $unread_topic, $folder_img, $folder_alt, $topic_type); $newest_post_img = ($unread_topic) ? "" . $user->img('icon_post_newest', 'VIEW_NEWEST_POST') . ' ' : ''; @@ -502,7 +541,7 @@ class ucp_main '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' => (!empty($row['mark_type'])) ? true : false, + 'S_USER_POSTED' => (!empty($row['topic_posted'])) ? true : false, 'S_UNREAD_TOPIC' => $unread_topic, 'U_LAST_POST' => $view_topic_url . '&p=' . $row['topic_last_post_id'] . '#' . $row['topic_last_post_id'], diff --git a/phpBB/includes/ucp/ucp_register.php b/phpBB/includes/ucp/ucp_register.php index 3ed7e7668f..a010f1575c 100644 --- a/phpBB/includes/ucp/ucp_register.php +++ b/phpBB/includes/ucp/ucp_register.php @@ -245,6 +245,7 @@ class ucp_register 'user_actkey' => $user_actkey, 'user_ip' => $user->ip, 'user_regdate' => time(), + 'user_lastmark' => time(), ); $sql = 'INSERT INTO ' . USERS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary); diff --git a/phpBB/install/schemas/firebird_schema.sql b/phpBB/install/schemas/firebird_schema.sql index 8873ade3d6..74e5dbef8f 100644 --- a/phpBB/install/schemas/firebird_schema.sql +++ b/phpBB/install/schemas/firebird_schema.sql @@ -708,10 +708,16 @@ CREATE TABLE phpbb_topics_marking ( user_id INTEGER DEFAULT 0 NOT NULL, topic_id INTEGER DEFAULT 0 NOT NULL, forum_id INTEGER DEFAULT 0 NOT NULL, - mark_type INTEGER DEFAULT 0 NOT NULL, mark_time INTEGER DEFAULT 0 NOT NULL );; +# phpbb_topics_posted +CREATE TABLE phpbb_topics_posted ( + user_id INTEGER DEFAULT 0 NOT NULL, + topic_id INTEGER DEFAULT 0 NOT NULL, + topic_posted INTEGER DEFAULT 0 NOT NULL +);; + # phpbb_topics_watch CREATE TABLE phpbb_topics_watch ( topic_id INTEGER DEFAULT 0 NOT NULL, @@ -742,6 +748,7 @@ CREATE TABLE phpbb_users ( user_email_hash DOUBLE PRECISION DEFAULT 0 NOT NULL, user_birthday VARCHAR(10) NOT NULL, user_lastvisit INTEGER DEFAULT 0 NOT NULL, + user_lastmark INTEGER DEFAULT 0 NOT NULL, user_lastpost_time INTEGER DEFAULT 0 NOT NULL, user_lastpage VARCHAR(100) NOT NULL, user_last_confirm_key VARCHAR(10) NOT NULL, @@ -1376,6 +1383,17 @@ ADD PRIMARY KEY ( topic_id );; +CREATE INDEX forum_idtp +ON phpbb_topics_marking( + forum_id +);; + +ALTER TABLE phpbb_topics_posted +ADD PRIMARY KEY ( + user_id, + topic_id +);; + CREATE INDEX notify_status71 ON phpbb_topics_watch( notify_status diff --git a/phpBB/install/schemas/mssql_schema.sql b/phpBB/install/schemas/mssql_schema.sql index ac13607e3b..74a8b3be0c 100644 --- a/phpBB/install/schemas/mssql_schema.sql +++ b/phpBB/install/schemas/mssql_schema.sql @@ -713,11 +713,17 @@ CREATE TABLE [phpbb_topics_marking] ( [user_id] [int] NOT NULL , [topic_id] [int] NOT NULL , [forum_id] [int] NOT NULL , - [mark_type] [int] NOT NULL , [mark_time] [int] NOT NULL ) ON [PRIMARY] GO +CREATE TABLE [phpbb_topics_posted] ( + [user_id] [int] NOT NULL , + [topic_id] [int] NOT NULL , + [topic_posted] [int] NOT NULL +) ON [PRIMARY] +GO + CREATE TABLE [phpbb_topics_watch] ( [topic_id] [int] NOT NULL , [user_id] [int] NOT NULL , @@ -747,6 +753,7 @@ CREATE TABLE [phpbb_users] ( [user_email_hash] [float] NOT NULL , [user_birthday] [varchar] (10) NOT NULL , [user_lastvisit] [int] NOT NULL , + [user_lastmark] [int] NOT NULL , [user_lastpost_time] [int] NOT NULL , [user_lastpage] [varchar] (100) NOT NULL , [user_last_confirm_key] [varchar] (10) NOT NULL , @@ -1140,6 +1147,14 @@ ALTER TABLE [phpbb_topics_marking] WITH NOCHECK ADD ) ON [PRIMARY] GO +ALTER TABLE [phpbb_topics_posted] WITH NOCHECK ADD + CONSTRAINT [PK_phpbb_topics_posted] PRIMARY KEY CLUSTERED + ( + [user_id], + [topic_id] + ) ON [PRIMARY] +GO + ALTER TABLE [phpbb_users] WITH NOCHECK ADD CONSTRAINT [PK_phpbb_users] PRIMARY KEY CLUSTERED ( @@ -1552,10 +1567,15 @@ ALTER TABLE [phpbb_topics_marking] WITH NOCHECK ADD CONSTRAINT [DF_tmarki_user_id] DEFAULT (0) FOR [user_id], CONSTRAINT [DF_tmarki_topic_id] DEFAULT (0) FOR [topic_id], CONSTRAINT [DF_tmarki_forum_id] DEFAULT (0) FOR [forum_id], - CONSTRAINT [DF_tmarki_mark_type] DEFAULT (0) FOR [mark_type], CONSTRAINT [DF_tmarki_mark_time] DEFAULT (0) FOR [mark_time] GO +ALTER TABLE [phpbb_topics_posted] WITH NOCHECK ADD + CONSTRAINT [DF_tposte_user_id] DEFAULT (0) FOR [user_id], + CONSTRAINT [DF_tposte_topic_id] DEFAULT (0) FOR [topic_id], + CONSTRAINT [DF_tposte_topic_posted] DEFAULT (0) FOR [topic_posted] +GO + ALTER TABLE [phpbb_topics_watch] WITH NOCHECK ADD CONSTRAINT [DF_twatch_topic_id] DEFAULT (0) FOR [topic_id], CONSTRAINT [DF_twatch_user_id] DEFAULT (0) FOR [user_id], @@ -1575,6 +1595,7 @@ ALTER TABLE [phpbb_users] WITH NOCHECK ADD CONSTRAINT [DF_users__user_passchg] DEFAULT (0) FOR [user_passchg], CONSTRAINT [DF_users__user_email_hash] DEFAULT (0) FOR [user_email_hash], CONSTRAINT [DF_users__user_lastvisit] DEFAULT (0) FOR [user_lastvisit], + CONSTRAINT [DF_users__user_lastmark] DEFAULT (0) FOR [user_lastmark], CONSTRAINT [DF_users__user_lastpost_time] DEFAULT (0) FOR [user_lastpost_time], CONSTRAINT [DF_users__user_warnings] DEFAULT (0) FOR [user_warnings], CONSTRAINT [DF_users__user_posts] DEFAULT (0) FOR [user_posts], @@ -1833,6 +1854,9 @@ GO CREATE INDEX [topic_last_post_time] ON [phpbb_topics]([topic_last_post_time]) ON [PRIMARY] GO +CREATE INDEX [forum_id] ON [phpbb_topics_marking]([forum_id]) ON [PRIMARY] +GO + CREATE INDEX [topic_id] ON [phpbb_topics_watch]([topic_id]) ON [PRIMARY] GO diff --git a/phpBB/install/schemas/mysql_schema.sql b/phpBB/install/schemas/mysql_schema.sql index cec502c424..f7e5fea293 100644 --- a/phpBB/install/schemas/mysql_schema.sql +++ b/phpBB/install/schemas/mysql_schema.sql @@ -821,8 +821,16 @@ CREATE TABLE phpbb_topics_marking ( user_id mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, topic_id mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, forum_id mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, - mark_type tinyint(4) DEFAULT '0' NOT NULL, mark_time int(11) DEFAULT '0' NOT NULL, + PRIMARY KEY (user_id, topic_id), + KEY forum_id (forum_id) +); + +# Table: 'phpbb_topic_posted' +CREATE TABLE phpbb_topics_posted ( + user_id mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, + topic_id mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, + topic_posted tinyint(4) DEFAULT '0' NOT NULL, PRIMARY KEY (user_id, topic_id) ); @@ -862,6 +870,7 @@ CREATE TABLE phpbb_users ( user_email_hash bigint(20) DEFAULT '0' NOT NULL, user_birthday varchar(10) DEFAULT '' NOT NULL, user_lastvisit int(11) DEFAULT '0' NOT NULL, + user_lastmark int(11) DEFAULT '0' NOT NULL, user_lastpost_time int(11) DEFAULT '0' NOT NULL, user_lastpage varchar(100) DEFAULT '' NOT NULL, user_last_confirm_key varchar(10) DEFAULT '' NOT NULL, diff --git a/phpBB/install/schemas/oracle_schema.sql b/phpBB/install/schemas/oracle_schema.sql index 8add2daeb1..5b9f14baea 100644 --- a/phpBB/install/schemas/oracle_schema.sql +++ b/phpBB/install/schemas/oracle_schema.sql @@ -1578,12 +1578,25 @@ CREATE TABLE phpbb_topics_marking ( user_id number(8) DEFAULT '0' NOT NULL, topic_id number(8) DEFAULT '0' NOT NULL, forum_id number(8) DEFAULT '0' NOT NULL, - mark_type number(4) DEFAULT '0' NOT NULL, mark_time number(11) DEFAULT '0' NOT NULL, CONSTRAINT pk_phpbb_topics_marking PRIMARY KEY (user_id, topic_id) ) / +CREATE INDEX forum_id06 on phpbb_topics_marking (forum_id) +/ + +/* + Table: phpbb_topics_posted +*/ +CREATE TABLE phpbb_topics_posted ( + user_id number(8) DEFAULT '0' NOT NULL, + topic_id number(8) DEFAULT '0' NOT NULL, + topic_posted number(4) DEFAULT '0' NOT NULL, + CONSTRAINT pk_phpbb_topics_posted PRIMARY KEY (user_id, topic_id) +) +/ + /* Table: phpbb_topics_watch */ @@ -1636,6 +1649,7 @@ CREATE TABLE phpbb_users ( user_email_hash number(20) DEFAULT '0' NOT NULL, user_birthday varchar2(10) DEFAULT '', user_lastvisit number(11) DEFAULT '0' NOT NULL, + user_lastmark number(11) DEFAULT '0' NOT NULL, user_lastpost_time number(11) DEFAULT '0' NOT NULL, user_lastpage varchar2(100) DEFAULT '', user_last_confirm_key varchar2(10) DEFAULT '', diff --git a/phpBB/install/schemas/postgres_schema.sql b/phpBB/install/schemas/postgres_schema.sql index 9f7e4c4493..805001e2fc 100644 --- a/phpBB/install/schemas/postgres_schema.sql +++ b/phpBB/install/schemas/postgres_schema.sql @@ -1094,12 +1094,11 @@ CREATE INDEX topic_last_post_time_phpbb_topics_index ON phpbb_topics (topic_last SELECT SETVAL('phpbb_topics_topic_id_seq',(select case when max(topic_id)>0 then max(topic_id)+1 else 1 end from phpbb_topics)); -/* Table: phpbb_topic_marking */ +/* Table: phpbb_topics_marking */ CREATE TABLE phpbb_topics_marking ( user_id INT4 DEFAULT '0' NOT NULL, topic_id INT4 DEFAULT '0' NOT NULL, forum_id INT4 DEFAULT '0' NOT NULL, - mark_type INT2 DEFAULT '0' NOT NULL, mark_time INT4 DEFAULT '0' NOT NULL, PRIMARY KEY (user_id,topic_id), CHECK (user_id>=0), @@ -1107,6 +1106,18 @@ CREATE TABLE phpbb_topics_marking ( CHECK (forum_id>=0) ); +CREATE INDEX forum_id_phpbb_topics_marking_index ON phpbb_topics_marking (forum_id); + +/* Table: phpbb_topics_posted */ +CREATE TABLE phpbb_topics_posted ( + user_id INT4 DEFAULT '0' NOT NULL, + topic_id INT4 DEFAULT '0' NOT NULL, + topic_posted INT2 DEFAULT '0' NOT NULL, + PRIMARY KEY (user_id,topic_id), + CHECK (user_id>=0), + CHECK (topic_id>=0) +); + /* Table: phpbb_topics_watch */ CREATE TABLE phpbb_topics_watch ( topic_id INT4 DEFAULT '0' NOT NULL, @@ -1147,6 +1158,7 @@ CREATE TABLE phpbb_users ( user_email_hash INT8 DEFAULT '0' NOT NULL, user_birthday varchar(10) DEFAULT '' NOT NULL, user_lastvisit INT4 DEFAULT '0' NOT NULL, + user_lastmark INT4 DEFAULT '0' NOT NULL, user_lastpost_time INT4 DEFAULT '0' NOT NULL, user_lastpage varchar(100) DEFAULT '' NOT NULL, user_last_confirm_key varchar(10) DEFAULT '' NOT NULL, diff --git a/phpBB/install/schemas/sqlite_schema.sql b/phpBB/install/schemas/sqlite_schema.sql index 906e934646..320d86d8f3 100644 --- a/phpBB/install/schemas/sqlite_schema.sql +++ b/phpBB/install/schemas/sqlite_schema.sql @@ -823,11 +823,20 @@ CREATE TABLE phpbb_topics_marking ( user_id mediumint(8) NOT NULL DEFAULT '0', topic_id mediumint(8) NOT NULL DEFAULT '0', forum_id mediumint(8) NOT NULL DEFAULT '0', - mark_type tinyint(4) NOT NULL DEFAULT '0', mark_time int(11) NOT NULL DEFAULT '0', PRIMARY KEY (user_id, topic_id) ); +CREATE INDEX forum_id_phpbb_topics_posted on phpbb_topics_posted (forum_id); + +# Table: phpbb_topics_posted +CREATE TABLE phpbb_topics_posted ( + user_id mediumint(8) NOT NULL DEFAULT '0', + topic_id mediumint(8) NOT NULL DEFAULT '0', + topic_posted tinyint(4) NOT NULL DEFAULT '0', + PRIMARY KEY (user_id, topic_id) +); + # Table: phpbb_topics_watch CREATE TABLE phpbb_topics_watch ( topic_id mediumint(8) NOT NULL DEFAULT '0', @@ -866,6 +875,7 @@ CREATE TABLE phpbb_users ( user_email_hash bigint(20) NOT NULL DEFAULT '0', user_birthday varchar(10) NOT NULL DEFAULT '', user_lastvisit int(11) NOT NULL DEFAULT '0', + user_lastmark int(11) NOT NULL DEFAULT '0', user_lastpost_time int(11) NOT NULL DEFAULT '0', user_lastpage varchar(100) NOT NULL DEFAULT '', user_last_confirm_key varchar(10) NOT NULL DEFAULT '', diff --git a/phpBB/posting.php b/phpBB/posting.php index c79757809a..d986f958a5 100644 --- a/phpBB/posting.php +++ b/phpBB/posting.php @@ -1843,9 +1843,14 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u $db->sql_query($sql); } - // Mark this topic as read and posted to. - $mark_mode = ($mode == 'post' || $mode == 'reply' || $mode == 'quote') ? 'post' : 'topic'; - markread($mark_mode, $data['forum_id'], $data['topic_id'], $data['post_time']); + if ($mode == 'post' || $mode == 'reply' || $mode == 'quote') + { + // Mark this topic as posted to + markread('post', $data['forum_id'], $data['topic_id'], $data['post_time']); + } + + // Mark this topic as read + markread('topic', $data['forum_id'], $data['topic_id'], $data['post_time']); // Send Notifications if ($mode != 'edit' && $mode != 'delete' && (!$auth->acl_get('f_moderate', $data['forum_id']) || $auth->acl_get('m_approve'))) diff --git a/phpBB/search.php b/phpBB/search.php index a092105b94..75ca8b57d3 100644 --- a/phpBB/search.php +++ b/phpBB/search.php @@ -36,7 +36,7 @@ $search_fields = request_var('search_fields', 'all'); $search_child = request_var('search_child', true); $return_chars = request_var('return_chars', 200); -$search_forum = request_var('search_forum', 0); +$search_forum = request_var('search_forum', array(0)); $sort_days = request_var('st', 0); $sort_key = request_var('sk', 't'); @@ -251,7 +251,7 @@ if ($keywords || $author || $search_id || $search_session_id) /** * @todo add to config */ - $config['search_type'] = 'mysql'; + $config['search_type'] = 'phpbb'; // Select which method we'll use to obtain the post_id information $smid = ''; @@ -468,7 +468,7 @@ if ($keywords || $author || $search_id || $search_session_id) $replies = ($auth->acl_get('m_approve', $forum_id)) ? $row['topic_replies_real'] : $row['topic_replies']; $folder_img = $folder_alt = $topic_type = ''; - topic_status($row, $replies, time(), time(), $folder_img, $folder_alt, $topic_type); + topic_status($row, $replies, false, $folder_img, $folder_alt, $topic_type); $tpl_ary = array( 'TOPIC_AUTHOR' => topic_topic_author($row), diff --git a/phpBB/styles/subSilver/template/index_body.html b/phpBB/styles/subSilver/template/index_body.html index 51b0ddff2d..25daf5a92c 100644 --- a/phpBB/styles/subSilver/template/index_body.html +++ b/phpBB/styles/subSilver/template/index_body.html @@ -56,7 +56,7 @@ {forumrow.LAST_POSTER} - {forumrow.LAST_POST_IMG} + {LAST_POST_IMG}

{L_NO_POSTS}

diff --git a/phpBB/styles/subSilver/template/viewforum_body.html b/phpBB/styles/subSilver/template/viewforum_body.html index 0f9f4b1829..e1d98a1abd 100644 --- a/phpBB/styles/subSilver/template/viewforum_body.html +++ b/phpBB/styles/subSilver/template/viewforum_body.html @@ -48,7 +48,7 @@ {REPORTED_IMG}  -

{topicrow.NEWEST_POST_IMG} {topicrow.ATTACH_ICON_IMG} {topicrow.TOPIC_TITLE}

+

{NEWEST_POST_IMG} {topicrow.ATTACH_ICON_IMG} {topicrow.TOPIC_TITLE}

[ {GOTO_PAGE_IMG}{L_GOTO_PAGE}: {topicrow.PAGINATION} ]

@@ -59,7 +59,7 @@

{topicrow.LAST_POST_TIME}

{topicrow.LAST_POST_AUTHOR}{topicrow.LAST_POST_AUTHOR} - {topicrow.LAST_POST_IMG} + {LAST_POST_IMG}

@@ -167,7 +167,7 @@ {REPORTED_IMG}  -

{topicrow.NEWEST_POST_IMG} {topicrow.ATTACH_ICON_IMG} {topicrow.TOPIC_TITLE}

+

{NEWEST_POST_IMG} {topicrow.ATTACH_ICON_IMG} {topicrow.TOPIC_TITLE}

[ {GOTO_PAGE_IMG}{L_GOTO_PAGE}: {topicrow.PAGINATION} ]

@@ -178,7 +178,7 @@

{topicrow.LAST_POST_TIME}

{topicrow.LAST_POST_AUTHOR}{topicrow.LAST_POST_AUTHOR} - {topicrow.LAST_POST_IMG} + {LAST_POST_IMG}

diff --git a/phpBB/styles/subSilver/template/viewforum_subforum.html b/phpBB/styles/subSilver/template/viewforum_subforum.html index e7baeeb705..c80b2b3cfe 100644 --- a/phpBB/styles/subSilver/template/viewforum_subforum.html +++ b/phpBB/styles/subSilver/template/viewforum_subforum.html @@ -39,7 +39,7 @@ {forumrow.L_MODERATOR_STR}: {forumrow.MODERATORS}

{forumrow.L_SUBFORUM_STR} {forumrow.SUBFORUMS}
{forumrow.TOPICS} {forumrow.POSTS} - {forumrow.LAST_POST_TIME}
{forumrow.LAST_POSTER}{forumrow.LAST_POSTER} {forumrow.LAST_POST_IMG}{L_NO_POSTS}
+ {forumrow.LAST_POST_TIME}
{forumrow.LAST_POSTER}{forumrow.LAST_POSTER} {LAST_POST_IMG}{L_NO_POSTS}
diff --git a/phpBB/viewforum.php b/phpBB/viewforum.php index 8422d226f2..3e261d1d4c 100644 --- a/phpBB/viewforum.php +++ b/phpBB/viewforum.php @@ -37,32 +37,31 @@ if (!$forum_id) } // Grab appropriate forum data -if (!$user->data['is_registered']) +if ($config['load_db_lastread'] && $user->data['is_registered']) { - $sql = 'SELECT * - FROM ' . FORUMS_TABLE . ' - WHERE forum_id = ' . $forum_id; + $sql_lastread = 'LEFT JOIN ' . FORUMS_TRACK_TABLE . ' ft ON (ft.user_id = ' . $user->data['user_id'] . ' + AND ft.forum_id = f.forum_id)'; + $lastread_select = ', ft.mark_time'; } else { - if ($config['load_db_lastread']) - { - $sql_lastread = 'LEFT JOIN ' . FORUMS_TRACK_TABLE . ' ft ON (ft.user_id = ' . $user->data['user_id'] . ' - AND ft.forum_id = f.forum_id)'; - $lastread_select = ', ft.mark_time '; - } - else - { - $sql_lastread = $lastread_select = ''; - $tracking_topics = (isset($_COOKIE[$config['cookie_name'] . '_track'])) ? unserialize(stripslashes($_COOKIE[$config['cookie_name'] . '_track'])) : array(); - } - - $sql_from = ($sql_lastread) ? '((' . FORUMS_TABLE . ' f LEFT JOIN ' . FORUMS_WATCH_TABLE . ' fw ON (fw.forum_id = f.forum_id AND fw.user_id = ' . $user->data['user_id'] . ")) $sql_lastread)" : '(' . FORUMS_TABLE . ' f LEFT JOIN ' . FORUMS_WATCH_TABLE . ' fw ON (fw.forum_id = f.forum_id AND fw.user_id = ' . $user->data['user_id'] . '))'; - - $sql = "SELECT f.*, fw.notify_status $lastread_select - FROM $sql_from - WHERE f.forum_id = $forum_id"; + $sql_lastread = $lastread_select = ''; + $tracking_topics = (isset($_COOKIE[$config['cookie_name'] . '_track'])) ? unserialize(stripslashes($_COOKIE[$config['cookie_name'] . '_track'])) : array(); } + +if ($user->data['is_registered']) +{ + $sql_from = ($sql_lastread) ? '((' . FORUMS_TABLE . ' f LEFT JOIN ' . FORUMS_WATCH_TABLE . ' fw ON (fw.forum_id = f.forum_id AND fw.user_id = ' . $user->data['user_id'] . ")) $sql_lastread)" : '(' . FORUMS_TABLE . ' f LEFT JOIN ' . FORUMS_WATCH_TABLE . ' fw ON (fw.forum_id = f.forum_id AND fw.user_id = ' . $user->data['user_id'] . '))'; + $lastread_select .= ', fw.notify_status'; +} +else +{ + $sql_from = FORUMS_TABLE . ' f'; +} + +$sql = "SELECT f.* $lastread_select + FROM $sql_from + WHERE f.forum_id = $forum_id"; $result = $db->sql_query($sql); if (!($forum_data = $db->sql_fetchrow($result))) @@ -71,11 +70,6 @@ if (!($forum_data = $db->sql_fetchrow($result))) } $db->sql_freeresult($result); -if (!$user->data['is_registered'] && $config['load_db_lastread']) -{ - $forum_data['mark_time'] = 0; -} - // Is this forum a link? ... User got here either because the // number of clicks is being tracked or they guessed the id if ($forum_data['forum_link']) @@ -130,13 +124,13 @@ $active_forum_ary = $moderators = array(); if ($forum_data['left_id'] != $forum_data['right_id'] - 1) { - $active_forum_ary = display_forums($forum_data); + list($active_forum_ary, $moderators) = display_forums($forum_data, $config['load_moderators'], $config['load_moderators']); } else { $template->assign_var('S_HAS_SUBFORUM', false); + get_moderators($moderators, $forum_id); } -get_moderators($moderators, $forum_id); // Output forum listing if it is postable if ($forum_data['forum_type'] == FORUM_POST || ($forum_data['forum_flags'] & 16)) @@ -144,10 +138,7 @@ if ($forum_data['forum_type'] == FORUM_POST || ($forum_data['forum_flags'] & 16) // Handle marking posts if ($mark_read == 'topics') { - if ($user->data['is_registered']) - { - markread('mark', $forum_id); - } + markread('topics', $forum_id); meta_refresh(3, "viewforum.$phpEx$SID&f=$forum_id"); @@ -164,16 +155,7 @@ if ($forum_data['forum_type'] == FORUM_POST || ($forum_data['forum_flags'] & 16) // Do the forum Prune thang - cron type job ... if ($forum_data['prune_next'] < time() && $forum_data['enable_prune']) { - include_once($phpbb_root_path . 'includes/functions_admin.'.$phpEx); - - if ($forum_data['prune_days']) - { - auto_prune($forum_id, 'posted', $forum_data['forum_flags'], $forum_data['prune_days'], $forum_data['prune_freq']); - } - if ($forum_data['prune_viewed']) - { - auto_prune($forum_id, 'viewed', $forum_data['forum_flags'], $forum_data['prune_viewed'], $forum_data['prune_freq']); - } + $template->assign_var('RUN_CRON_TASK', ''); } // Forum rules amd subscription info @@ -207,7 +189,7 @@ if ($forum_data['forum_type'] == FORUM_POST || ($forum_data['forum_flags'] & 16) $sql = 'SELECT COUNT(topic_id) AS num_topics FROM ' . TOPICS_TABLE . " WHERE forum_id = $forum_id - AND topic_type <> " . POST_ANNOUNCE . " + 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); @@ -237,12 +219,14 @@ if ($forum_data['forum_type'] == FORUM_POST || ($forum_data['forum_flags'] & 16) $post_alt = ($forum_data['forum_status'] == ITEM_LOCKED) ? $user->lang['FORUM_LOCKED'] : $user->lang['POST_NEW_TOPIC']; $template->assign_vars(array( - 'PAGINATION' => generate_pagination("viewforum.$phpEx$SID&f=$forum_id&$u_sort_param", $topics_count, $config['topics_per_page'], $start), + 'PAGINATION' => generate_pagination("{$phpbb_root_path}viewforum.$phpEx$SID&f=$forum_id&$u_sort_param", $topics_count, $config['topics_per_page'], $start), 'PAGE_NUMBER' => on_page($topics_count, $config['topics_per_page'], $start), 'TOTAL_TOPICS' => ($forum_data['forum_flags'] & 16) ? 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), + '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'), @@ -263,21 +247,21 @@ if ($forum_data['forum_type'] == FORUM_POST || ($forum_data['forum_flags'] & 16) '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_DISPLAY_ACTIVE' => ($forum_data['forum_type'] == FORUM_CAT && $forum_data['forum_flags'] & 16) ? true : false, + 'S_DISPLAY_ACTIVE' => ($forum_data['forum_type'] == FORUM_CAT && ($forum_data['forum_flags'] & 16)) ? true : false, 'S_SELECT_SORT_DIR' => $s_sort_dir, 'S_SELECT_SORT_KEY' => $s_sort_key, 'S_SELECT_SORT_DAYS' => $s_limit_days, - 'S_TOPIC_ICONS' => ($forum_data['forum_type'] == FORUM_CAT && $forum_data['forum_flags'] & 16) ? max($active_forum_ary['enable_icons']) : (($forum_data['enable_icons']) ? true : false), + '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_WATCH_FORUM_LINK' => $s_watching_forum['link'], 'S_WATCH_FORUM_TITLE' => $s_watching_forum['title'], - 'S_FORUM_ACTION' => "viewforum.$phpEx$SID&f=$forum_id&start=$start", + 'S_FORUM_ACTION' => "{$phpbb_root_path}viewforum.$phpEx$SID&f=$forum_id&start=$start", 'S_DISPLAY_SEARCHBOX' => ($auth->acl_get('f_search', $forum_id)) ? true : false, - 'S_SEARCHBOX_ACTION' => "search.$phpEx$SID&search_forum[]=$forum_id", + 'S_SEARCHBOX_ACTION' => "{$phpbb_root_path}search.$phpEx$SID&search_forum[]=$forum_id", - 'U_MCP' => ($auth->acl_gets('m_', $forum_id)) ? "mcp.$phpEx?sid=$user->session_id&f=$forum_id&mode=forum_view" : '', - 'U_POST_NEW_TOPIC' => "posting.$phpEx$SID&mode=post&f=$forum_id", - 'U_VIEW_FORUM' => "viewforum.$phpEx$SID&f=$forum_id&$u_sort_param&start=$start", - 'U_MARK_TOPICS' => "viewforum.$phpEx$SID&f=$forum_id&mark=topics") + 'U_MCP' => ($auth->acl_gets('m_', $forum_id)) ? "{$phpbb_root_path}mcp.$phpEx?sid=$user->session_id&f=$forum_id&mode=forum_view" : '', + 'U_POST_NEW_TOPIC' => "{$phpbb_root_path}posting.$phpEx$SID&mode=post&f=$forum_id", + 'U_VIEW_FORUM' => "{$phpbb_root_path}viewforum.$phpEx$SID&f=$forum_id&$u_sort_param&start=$start", + 'U_MARK_TOPICS' => "{$phpbb_root_path}viewforum.$phpEx$SID&f=$forum_id&mark=topics") ); // Grab icons @@ -285,11 +269,28 @@ if ($forum_data['forum_type'] == FORUM_POST || ($forum_data['forum_flags'] & 16) $cache->obtain_icons($icons); // Grab all topic data - $rowset = $announcement_list = $topic_list = array(); + $rowset = $announcement_list = $topic_list = $global_announce_list = array(); - $sql_from = (($config['load_db_lastread'] || $config['load_db_track']) && $user->data['is_registered']) ? '(' . TOPICS_TABLE . ' t LEFT JOIN ' . TOPICS_TRACK_TABLE . ' tt ON (tt.topic_id = t.topic_id AND tt.user_id = ' . $user->data['user_id'] . '))' : TOPICS_TABLE . ' t '; + $sql_from = TOPICS_TABLE . ' t '; $sql_approved = ($auth->acl_get('m_approve', $forum_id)) ? '' : 'AND t.topic_approved = 1'; - $sql_select = (($config['load_db_lastread'] || $config['load_db_track']) && $user->data['is_registered']) ? ', tt.mark_type, tt.mark_time' : ''; + $sql_select = ''; + + if ($user->data['is_registered']) + { + if ($config['load_db_track']) + { + $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) { @@ -305,6 +306,11 @@ if ($forum_data['forum_type'] == FORUM_POST || ($forum_data['forum_flags'] & 16) { $rowset[$row['topic_id']] = $row; $announcement_list[] = $row['topic_id']; + + if ($row['topic_type'] == POST_GLOBAL) + { + $global_announce_list[$row['topic_id']] = true; + } } $db->sql_freeresult($result); } @@ -352,37 +358,34 @@ if ($forum_data['forum_type'] == FORUM_POST || ($forum_data['forum_flags'] & 16) $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)) { - if ($config['load_db_lastread']) + $mark_forum_read = true; + + if ($config['load_db_lastread'] && $user->data['is_registered']) { - $mark_time_forum = $forum_data['mark_time']; + $topic_tracking_info = get_topic_tracking($forum_id, $topic_list, $rowset, array($forum_id => $forum_data['mark_time']), $global_announce_list); + $mark_time_forum = (!empty($forum_data['mark_time'])) ? $forum_data['mark_time'] : $user->data['user_lastmark']; } else { - $mark_time_forum = (isset($tracking_topics[$forum_id][0])) ? base_convert($tracking_topics[$forum_id][0], 36, 10) + $config['board_startdate'] : 0; - } + $topic_tracking_info = get_complete_topic_tracking($forum_id, $topic_list, $global_announce_list); - $mark_forum_read = true; + if (!$user->data['is_registered']) + { + $user->data['user_lastmark'] = (isset($tracking_topics['l'])) ? base_convert($tracking_topics['l'], 36, 10) + $config['board_startdate'] : 0; + } + $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]; - if ($config['load_db_lastread']) - { - $mark_time_topic = ($user->data['is_registered']) ? $row['mark_time'] : 0; - } - else - { - $topic_id36 = base_convert($topic_id, 10, 36); - $forum_id36 = ($row['topic_type'] == POST_GLOBAL) ? 0 : $forum_id; - $mark_time_topic = (isset($tracking_topics[$forum_id36][$topic_id36])) ? base_convert($tracking_topics[$forum_id36][$topic_id36], 36, 10) + $config['board_startdate'] : 0; - } - // This will allow the style designer to output a different header // or even seperate the list of announcements from sticky and normal // topics @@ -396,14 +399,14 @@ if ($forum_data['forum_type'] == FORUM_POST || ($forum_data['forum_flags'] & 16) $topic_id = $row['topic_moved_id']; } + $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 = ''; - $unread_topic = topic_status($row, $replies, $mark_time_topic, $mark_time_forum, $folder_img, $folder_alt, $topic_type); - - $newest_post_img = ($unread_topic) ? "" . $user->img('icon_post_newest', 'VIEW_NEWEST_POST') . ' ' : ''; + topic_status($row, $replies, $unread_topic, $folder_img, $folder_alt, $topic_type); // Generate all the URIs ... - $view_topic_url = "viewtopic.$phpEx$SID&f=" . (($row['forum_id']) ? $row['forum_id'] : $forum_id) . "&t=$topic_id"; + $view_topic_url = "{$phpbb_root_path}viewtopic.$phpEx$SID&f=" . (($row['forum_id']) ? $row['forum_id'] : $forum_id) . "&t=$topic_id"; // Send vars to template $template->assign_block_vars('topicrow', array( @@ -414,40 +417,39 @@ if ($forum_data['forum_type'] == FORUM_POST || ($forum_data['forum_flags'] & 16) '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, "viewtopic.$phpEx$SID&f=" . (($row['forum_id']) ? $row['forum_id'] : $forum_id) . "&t=$topic_id"), + '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, - 'LAST_POST_IMG' => $user->img('icon_post_latest', 'VIEW_LATEST_POST'), - 'NEWEST_POST_IMG' => $newest_post_img, - 'TOPIC_FOLDER_IMG' => $user->img($folder_img, $folder_alt), + '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' => (!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']) : '', + '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' => (!empty($row['mark_type'])) ? true : false, + '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_', $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 . '&view=unread#unread', 'U_LAST_POST' => $view_topic_url . '&p=' . $row['topic_last_post_id'] . '#' . $row['topic_last_post_id'], - 'U_LAST_POST_AUTHOR'=> ($row['topic_last_poster_id'] != ANONYMOUS && $row['topic_last_poster_id']) ? "memberlist.$phpEx$SID&mode=viewprofile&u={$row['topic_last_poster_id']}" : '', + 'U_LAST_POST_AUTHOR'=> ($row['topic_last_poster_id'] != ANONYMOUS && $row['topic_last_poster_id']) ? "{$phpbb_root_path}memberlist.$phpEx$SID&mode=viewprofile&u={$row['topic_last_poster_id']}" : '', 'U_VIEW_TOPIC' => $view_topic_url, - 'U_MCP_REPORT' => "mcp.$phpEx?sid={$user->session_id}&mode=reports&t=$topic_id", - 'U_MCP_QUEUE' => "mcp.$phpEx?sid={$user->session_id}&i=queue&mode=approve_details&t=$topic_id", + 'U_MCP_REPORT' => "{$phpbb_root_path}mcp.$phpEx?sid={$user->session_id}&mode=reports&t=$topic_id", + 'U_MCP_QUEUE' => "{$phpbb_root_path}mcp.$phpEx?sid={$user->session_id}&i=queue&mode=approve_details&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 ($mark_time_topic < $row['topic_last_post_time'] && $mark_time_forum < $row['topic_last_post_time']) + if ($unread_topic) { $mark_forum_read = false; } @@ -460,13 +462,68 @@ if ($forum_data['forum_type'] == FORUM_POST || ($forum_data['forum_flags'] & 16) // 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 && $user->data['is_registered'] && sizeof($topic_list) && $mark_forum_read) + if ($forum_data['forum_type'] == FORUM_POST && sizeof($topic_list) && $mark_forum_read) { - markread('mark', $forum_id); + // 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.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 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; + + 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; + $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); + } } } - // Dump out the page header and load viewforum template page_header($user->lang['VIEW_FORUM'] . ' - ' . $forum_data['forum_name']); diff --git a/phpBB/viewtopic.php b/phpBB/viewtopic.php index 7c83cedd46..b302e4c84c 100644 --- a/phpBB/viewtopic.php +++ b/phpBB/viewtopic.php @@ -45,7 +45,6 @@ if (!$topic_id && !$post_id) } // Find topic id if user requested a newer or older topic -$unread_post_id = 0; if ($view && !$post_id) { if (!$forum_id) @@ -67,14 +66,10 @@ if ($view && !$post_id) if ($view == 'unread') { - if ($user->data['is_registered']) - { - $topic_last_read = get_topic_last_read($topic_id, $forum_id); - } - else - { - $topic_last_read = 0; - } + // Get topic tracking info + $topic_tracking_info = get_complete_topic_tracking($forum_id, $topic_id); + + $topic_last_read = (isset($topic_tracking_info[$topic_id])) ? $topic_tracking_info[$topic_id] : 0; $sql = 'SELECT p.post_id, p.topic_id, p.forum_id FROM (' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . " t) @@ -97,7 +92,7 @@ if ($view && !$post_id) } $db->sql_freeresult($result); - $unread_post_id = $post_id = $row['post_id']; + $post_id = $row['post_id']; $topic_id = $row['topic_id']; } else if ($view == 'next' || $view == 'previous') @@ -146,10 +141,12 @@ if ($view && !$post_id) } } + // This rather complex gaggle of code handles querying for topics but // also allows for direct linking to a post (and the calculation of which // page the post is on and the correct display of viewtopic) -$join_sql_table = (!$post_id) ? '' : ', ' . POSTS_TABLE . ' p, ' . POSTS_TABLE . ' p2 '; +$join_sql_table = ''; + if (!$post_id) { $join_sql = "t.topic_id = $topic_id"; @@ -170,19 +167,36 @@ $order_sql = (!$post_id) ? '' : 'GROUP BY p.post_id, t.topic_id, t.topic_title, if ($user->data['is_registered']) { - $extra_fields .= ', tw.notify_status' . (($config['allow_bookmarks']) ? ', bm.order_id as bookmarked' : ''); + $extra_fields .= ', tw.notify_status'; $join_sql_table .= ' LEFT JOIN ' . TOPICS_WATCH_TABLE . ' tw ON (tw.user_id = ' . $user->data['user_id'] . ' AND t.topic_id = tw.topic_id)'; - $join_sql_table .= ($config['allow_bookmarks']) ? ' LEFT JOIN ' . BOOKMARKS_TABLE . ' bm ON (bm.user_id = ' . $user->data['user_id'] . ' - AND t.topic_id = bm.topic_id)' : ''; + + if ($config['allow_bookmarks']) + { + $extra_fields .= ', bm.order_id as bookmarked'; + $join_sql_table .= ' LEFT JOIN ' . BOOKMARKS_TABLE . ' bm ON (bm.user_id = ' . $user->data['user_id'] . ' + AND t.topic_id = bm.topic_id)'; + } + + if ($config['load_db_lastread']) + { + $extra_fields .= ', tt.mark_time, ft.mark_time as forum_mark_time'; + $join_sql_table .= ' LEFT JOIN ' . TOPICS_TRACK_TABLE . ' tt ON (tt.user_id = ' . $user->data['user_id'] . ' + AND t.topic_id = tt.topic_id)'; + + $join_sql_table .= ' LEFT JOIN ' . FORUMS_TRACK_TABLE . ' ft ON (ft.user_id = ' . $user->data['user_id'] . ' + AND f.forum_id = ft.forum_id)'; + } } +$join_sql_table .= (!$post_id) ? '' : ', ' . POSTS_TABLE . ' p, ' . POSTS_TABLE . ' p2 '; + // Join to forum table on topic forum_id unless topic forum_id is zero // whereupon we join on the forum_id passed as a parameter ... this // is done so navigation, forum name, etc. remain consistent with where // user clicked to view a global topic $sql = 'SELECT t.topic_id, t.forum_id, t.topic_title, t.topic_attachment, t.topic_status, t.topic_approved, t.topic_replies_real, t.topic_replies, t.topic_first_post_id, t.topic_last_post_id, t.topic_last_poster_id, t.topic_last_post_time, t.topic_poster, t.topic_time, t.topic_time_limit, t.topic_type, t.topic_bumped, t.topic_bumper, t.poll_max_options, t.poll_start, t.poll_length, t.poll_title, t.poll_vote_change, f.forum_name, f.forum_desc, f.forum_parents, f.parent_id, f.left_id, f.right_id, f.forum_status, f.forum_type, f.forum_id, f.forum_style, f.forum_password, f.forum_rules, f.forum_rules_link, f.forum_rules_flags, f.forum_rules_bbcode_uid, f.forum_rules_bbcode_bitfield' . $extra_fields . ' - FROM ' . TOPICS_TABLE . ' t, ' . FORUMS_TABLE . ' f' . $join_sql_table . " + FROM ' . FORUMS_TABLE . ' f, ' . TOPICS_TABLE . ' t' . $join_sql_table . " WHERE $join_sql AND (f.forum_id = t.forum_id " . ((!$forum_id) ? '' : 'OR (t.topic_type = ' . POST_GLOBAL . " AND f.forum_id = $forum_id)") . " @@ -200,38 +214,28 @@ if (!($topic_data = $db->sql_fetchrow($result))) trigger_error('NO_TOPIC'); } -// Extract the data -extract($topic_data); +$forum_id = (int) $topic_data['forum_id']; +$topic_id = (int) $topic_data['topic_id']; // -$topic_replies = ($auth->acl_get('m_approve', $forum_id)) ? $topic_replies_real : $topic_replies; -unset($topic_replies_real); - -if ($user->data['is_registered'] && !isset($topic_last_read)) -{ - $topic_last_read = get_topic_last_read($topic_id, $forum_id); -} -else -{ - $topic_last_read = 0; -} +$topic_replies = ($auth->acl_get('m_approve', $forum_id)) ? $topic_data['topic_replies_real'] : $topic_data['topic_replies']; // Check sticky/announcement time limit -if (($topic_type == POST_STICKY || $topic_type == POST_ANNOUNCE) && $topic_time_limit && ($topic_time + $topic_time_limit) < time()) +if (($topic_data['topic_type'] == POST_STICKY || $topic_data['topic_type'] == POST_ANNOUNCE) && $topic_data['topic_time_limit'] && ($topic_data['topic_time'] + $topic_data['topic_time_limit']) < time()) { $sql = 'UPDATE ' . TOPICS_TABLE . ' SET topic_type = ' . POST_NORMAL . ', topic_time_limit = 0 WHERE topic_id = ' . $topic_id; $db->sql_query($sql); - $topic_type = POST_NORMAL; - $topic_time_limit = 0; + $topic_data['topic_type'] = POST_NORMAL; + $topic_data['topic_time_limit'] = 0; } // Setup look and feel -$user->setup('viewtopic', $forum_style); +$user->setup('viewtopic', $topic_data['forum_style']); -if (!$topic_approved && !$auth->acl_get('m_approve', $forum_id)) +if (!$topic_data['topic_approved'] && !$auth->acl_get('m_approve', $forum_id)) { trigger_error('NO_TOPIC'); } @@ -249,7 +253,7 @@ if (!$auth->acl_get('f_read', $forum_id)) // Forum is passworded ... check whether access has been granted to this // user this session, if not show login box -if ($forum_password) +if ($topic_data['forum_password']) { login_forum_box($topic_data); } @@ -274,9 +278,25 @@ if (isset($_GET['e'])) } // What is start equal to? -if (!empty($post_id)) +if ($post_id) { - $start = floor(($prev_posts - 1) / $config['posts_per_page']) * $config['posts_per_page']; + $start = floor(($topic_data['prev_posts'] - 1) / $config['posts_per_page']) * $config['posts_per_page']; +} + +// Get topic tracking info +if (!isset($topic_tracking_info)) +{ + // Get topic tracking info + if ($config['load_db_lastread'] && $user->data['is_registered']) + { + $tmp_topic_data = array($topic_id => $topic_data); + $topic_tracking_info = get_topic_tracking($forum_id, $topic_id, $tmp_topic_data, array($forum_id => $topic_data['forum_mark_time'])); + unset($tmp_topic_data); + } + else + { + $topic_tracking_info = get_complete_topic_tracking($forum_id, $topic_id); + } } // Post ordering options @@ -337,13 +357,13 @@ $s_watching_topic = $s_watching_topic_img = array(); $s_watching_topic['link'] = $s_watching_topic['title'] = ''; if ($config['email_enable'] && $config['allow_topic_notify'] && $user->data['is_registered']) { - watch_topic_forum('topic', $s_watching_topic, $s_watching_topic_img, $user->data['user_id'], $topic_id, $notify_status, $start); + watch_topic_forum('topic', $s_watching_topic, $s_watching_topic_img, $user->data['user_id'], $topic_id, $topic_data['notify_status'], $start); } // Bookmarks if ($config['allow_bookmarks'] && $user->data['is_registered'] && request_var('bookmark', 0)) { - if (!$bookmarked) + if (!$topic_data['bookmarked']) { $sql = 'INSERT INTO ' . BOOKMARKS_TABLE . ' ' . $db->sql_build_array('INSERT', array( 'user_id' => $user->data['user_id'], @@ -363,7 +383,7 @@ if ($config['allow_bookmarks'] && $user->data['is_registered'] && request_var('b $db->sql_query($sql); // Works because of current order_id selected as bookmark value (please do not change because of simplicity) - $where_sql = " AND order_id > $bookmarked"; + $where_sql = " AND order_id > {$topic_data['bookmarked']}"; $sign = '-'; } @@ -376,7 +396,7 @@ if ($config['allow_bookmarks'] && $user->data['is_registered'] && request_var('b meta_refresh(3, $viewtopic_url); - $message = (($bookmarked) ? $user->lang['BOOKMARK_REMOVED'] : $user->lang['BOOKMARK_ADDED']) . '

' . sprintf($user->lang['RETURN_TOPIC'], '', ''); + $message = (($topic_data['bookmarked']) ? $user->lang['BOOKMARK_REMOVED'] : $user->lang['BOOKMARK_ADDED']) . '

' . sprintf($user->lang['RETURN_TOPIC'], '', ''); trigger_error($message); } @@ -390,7 +410,7 @@ $cache->obtain_icons($icons); // Grab extensions $extensions = array(); -if ($topic_attachment) +if ($topic_data['topic_attachment']) { $cache->obtain_attach_extensions($extensions); } @@ -401,16 +421,16 @@ gen_forum_auth_level('topic', $forum_id); // Quick mod tools $topic_mod = ''; -$topic_mod .= ($auth->acl_get('m_lock', $forum_id) || ($auth->acl_get('f_user_lock', $forum_id) && $user->data['is_registered'] && $user->data['user_id'] == $topic_poster)) ? (($topic_status == ITEM_UNLOCKED) ? '' : '') : ''; +$topic_mod .= ($auth->acl_get('m_lock', $forum_id) || ($auth->acl_get('f_user_lock', $forum_id) && $user->data['is_registered'] && $user->data['user_id'] == $topic_data['topic_poster'])) ? (($topic_data['topic_status'] == ITEM_UNLOCKED) ? '' : '') : ''; $topic_mod .= ($auth->acl_get('m_delete', $forum_id)) ? '' : ''; $topic_mod .= ($auth->acl_get('m_move', $forum_id)) ? '' : ''; $topic_mod .= ($auth->acl_get('m_split', $forum_id)) ? '' : ''; $topic_mod .= ($auth->acl_get('m_merge', $forum_id)) ? '' : ''; $topic_mod .= ($auth->acl_get('m_', $forum_id)) ? '' : ''; -$topic_mod .= ($auth->acl_get('m_', $forum_id) && $topic_type != POST_NORMAL) ? '' : ''; -$topic_mod .= ($auth->acl_get('f_sticky', $forum_id) && $topic_type != POST_STICKY) ? '' : ''; -$topic_mod .= ($auth->acl_get('f_announce', $forum_id) && $topic_type != POST_ANNOUNCE) ? '' : ''; -$topic_mod .= ($auth->acl_get('f_announce', $forum_id) && $topic_type != POST_GLOBAL) ? '' : ''; +$topic_mod .= ($auth->acl_get('m_', $forum_id) && $topic_data['topic_type'] != POST_NORMAL) ? '' : ''; +$topic_mod .= ($auth->acl_get('f_sticky', $forum_id) && $topic_data['topic_type'] != POST_STICKY) ? '' : ''; +$topic_mod .= ($auth->acl_get('f_announce', $forum_id) && $topic_data['topic_type'] != POST_ANNOUNCE) ? '' : ''; +$topic_mod .= ($auth->acl_get('f_announce', $forum_id) && $topic_data['topic_type'] != POST_GLOBAL) ? '' : ''; $topic_mod .= ($auth->acl_get('m_', $forum_id)) ? '' : ''; // If we've got a hightlight set pass it on to pagination. @@ -427,27 +447,27 @@ $forum_moderators = array(); get_moderators($forum_moderators, $forum_id); // This is only used for print view so ... -$server_path = (!$view) ? '' : generate_board_url() . '/'; +$server_path = (!$view) ? $phpbb_root_path : generate_board_url() . '/'; // Replace naughty words in title -$topic_title = censor_text($topic_title); +$topic_data['topic_title'] = censor_text($topic_data['topic_title']); // Send vars to template $template->assign_vars(array( 'FORUM_ID' => $forum_id, - 'FORUM_NAME' => $forum_name, - 'FORUM_DESC' => $forum_desc, + 'FORUM_NAME' => $topic_data['forum_name'], + 'FORUM_DESC' => $topic_data['forum_desc'], 'TOPIC_ID' => $topic_id, - 'TOPIC_TITLE' => $topic_title, + 'TOPIC_TITLE' => $topic_data['topic_title'], 'PAGINATION' => $pagination, 'PAGE_NUMBER' => on_page($total_posts, $config['posts_per_page'], $start), 'TOTAL_POSTS' => ($total_posts == 1) ? $user->lang['VIEW_TOPIC_POST'] : sprintf($user->lang['VIEW_TOPIC_POSTS'], $total_posts), - 'U_MCP' => ($auth->acl_get('m_', $forum_id)) ? "mcp.$phpEx?sid=" . $user->session_id . "&mode=topic_view&f=$forum_id&t=$topic_id&start=$start&$u_sort_param" : '', + 'U_MCP' => ($auth->acl_get('m_', $forum_id)) ? "{$phpbb_root_path}mcp.$phpEx?sid=" . $user->session_id . "&mode=topic_view&f=$forum_id&t=$topic_id&start=$start&$u_sort_param" : '', 'MODERATORS' => (isset($forum_moderators[$forum_id]) && sizeof($forum_moderators[$forum_id])) ? implode(', ', $forum_moderators[$forum_id]) : '', - 'POST_IMG' => ($forum_status == ITEM_LOCKED) ? $user->img('btn_locked', 'FORUM_LOCKED') : $user->img('btn_post', 'POST_NEW_TOPIC'), + 'POST_IMG' => ($topic_data['forum_status'] == ITEM_LOCKED) ? $user->img('btn_locked', 'FORUM_LOCKED') : $user->img('btn_post', 'POST_NEW_TOPIC'), 'QUOTE_IMG' => $user->img('btn_quote', 'REPLY_WITH_QUOTE'), - 'REPLY_IMG' => ($forum_status == ITEM_LOCKED || $topic_status == ITEM_LOCKED) ? $user->img('btn_locked', 'TOPIC_LOCKED') : $user->img('btn_reply', 'REPLY_TO_TOPIC'), + 'REPLY_IMG' => ($topic_data['forum_status'] == ITEM_LOCKED || $topic_data['topic_status'] == ITEM_LOCKED) ? $user->img('btn_locked', 'TOPIC_LOCKED') : $user->img('btn_reply', 'REPLY_TO_TOPIC'), 'EDIT_IMG' => $user->img('btn_edit', 'EDIT_POST'), 'DELETE_IMG' => $user->img('btn_delete', 'DELETE_POST'), 'INFO_IMG' => $user->img('btn_info', 'VIEW_INFO'), @@ -468,32 +488,32 @@ $template->assign_vars(array( 'S_SELECT_SORT_DIR' => $s_sort_dir, 'S_SELECT_SORT_KEY' => $s_sort_key, 'S_SELECT_SORT_DAYS' => $s_limit_days, - 'S_TOPIC_ACTION' => "viewtopic.$phpEx$SID&f=$forum_id&t=$topic_id&start=$start", + 'S_TOPIC_ACTION' => "{$phpbb_root_path}viewtopic.$phpEx$SID&f=$forum_id&t=$topic_id&start=$start", 'S_TOPIC_MOD' => ($topic_mod != '') ? '' : '', - 'S_MOD_ACTION' => "mcp.$phpEx?sid=" . $user->session_id . "&t=$topic_id&f=$forum_id&quickmod=1", + 'S_MOD_ACTION' => "{$phpbb_root_path}mcp.$phpEx?sid=" . $user->session_id . "&t=$topic_id&f=$forum_id&quickmod=1", 'S_DISPLAY_SEARCHBOX' => ($auth->acl_get('f_search', $forum_id)) ? true : false, - 'S_SEARCHBOX_ACTION' => "search.$phpEx$SID&search_forum[]=$forum_id", + 'S_SEARCHBOX_ACTION' => "{$phpbb_root_path}search.$phpEx$SID&search_forum[]=$forum_id", 'U_TOPIC' => "{$server_path}viewtopic.$phpEx?f=$forum_id&t=$topic_id", 'U_FORUM' => $server_path, - 'U_VIEW_UNREAD_POST' => "viewtopic.$phpEx$SID&f=$forum_id&t=$topic_id&view=unread#unread", + 'U_VIEW_UNREAD_POST' => "{$phpbb_root_path}viewtopic.$phpEx$SID&f=$forum_id&t=$topic_id&view=unread#unread", 'U_VIEW_TOPIC' => $viewtopic_url, - 'U_VIEW_FORUM' => "viewforum.$phpEx$SID&f=$forum_id", - 'U_VIEW_OLDER_TOPIC' => "viewtopic.$phpEx$SID&f=$forum_id&t=$topic_id&view=previous", - 'U_VIEW_NEWER_TOPIC' => "viewtopic.$phpEx$SID&f=$forum_id&t=$topic_id&view=next", + 'U_VIEW_FORUM' => "{$phpbb_root_path}viewforum.$phpEx$SID&f=$forum_id", + 'U_VIEW_OLDER_TOPIC' => "{$phpbb_root_path}viewtopic.$phpEx$SID&f=$forum_id&t=$topic_id&view=previous", + 'U_VIEW_NEWER_TOPIC' => "{$phpbb_root_path}viewtopic.$phpEx$SID&f=$forum_id&t=$topic_id&view=next", 'U_PRINT_TOPIC' => ($auth->acl_get('f_print', $forum_id)) ? $viewtopic_url . '&view=print' : '', - 'U_EMAIL_TOPIC' => ($auth->acl_get('f_email', $forum_id) && $config['email_enable']) ? "memberlist.$phpEx$SID&mode=email&t=$topic_id" : '', + 'U_EMAIL_TOPIC' => ($auth->acl_get('f_email', $forum_id) && $config['email_enable']) ? "{$phpbb_root_path}memberlist.$phpEx$SID&mode=email&t=$topic_id" : '', 'U_WATCH_TOPIC' => $s_watching_topic['link'], 'L_WATCH_TOPIC' => $s_watching_topic['title'], 'U_BOOKMARK_TOPIC' => ($user->data['is_registered'] && $config['allow_bookmarks']) ? $viewtopic_url . '&bookmark=1' : '', - 'L_BOOKMARK_TOPIC' => ($user->data['is_registered'] && $config['allow_bookmarks'] && $bookmarked) ? $user->lang['BOOKMARK_TOPIC_REMOVE'] : $user->lang['BOOKMARK_TOPIC'], + 'L_BOOKMARK_TOPIC' => ($user->data['is_registered'] && $config['allow_bookmarks'] && $topic_data['bookmarked']) ? $user->lang['BOOKMARK_TOPIC_REMOVE'] : $user->lang['BOOKMARK_TOPIC'], - 'U_POST_NEW_TOPIC' => "posting.$phpEx$SID&mode=post&f=$forum_id", - 'U_POST_REPLY_TOPIC' => "posting.$phpEx$SID&mode=reply&f=$forum_id&t=$topic_id", - 'U_BUMP_TOPIC' => (bump_topic_allowed($forum_id, $topic_bumped, $topic_last_post_time, $topic_poster, $topic_last_poster_id)) ? "posting.$phpEx$SID&mode=bump&f=$forum_id&t=$topic_id" : '') + 'U_POST_NEW_TOPIC' => "{$phpbb_root_path}posting.$phpEx$SID&mode=post&f=$forum_id", + 'U_POST_REPLY_TOPIC' => "{$phpbb_root_path}posting.$phpEx$SID&mode=reply&f=$forum_id&t=$topic_id", + 'U_BUMP_TOPIC' => (bump_topic_allowed($forum_id, $topic_data['topic_bumped'], $topic_data['topic_last_post_time'], $topic_data['topic_poster'], $topic_data['topic_last_poster_id'])) ? "{$phpbb_root_path}posting.$phpEx$SID&mode=bump&f=$forum_id&t=$topic_id" : '') ); // Does this topic contain a poll? @@ -502,7 +522,7 @@ if (!empty($poll_start)) $sql = 'SELECT o.*, p.bbcode_bitfield, p.bbcode_uid FROM ' . POLL_OPTIONS_TABLE . ' o, ' . POSTS_TABLE . " p WHERE o.topic_id = $topic_id - AND p.post_id = $topic_first_post_id + AND p.post_id = {$topic_data['topic_first_post_id']} AND p.topic_id = o.topic_id ORDER BY o.poll_option_id"; $result = $db->sql_query($sql); @@ -541,10 +561,10 @@ if (!empty($poll_start)) } $s_can_vote = (((!sizeof($cur_voted_id) && $auth->acl_get('f_vote', $forum_id)) || - ($auth->acl_get('f_votechg', $forum_id) && $poll_vote_change)) && - (($poll_length != 0 && $poll_start + $poll_length > time()) || $poll_length == 0) && - $topic_status != ITEM_LOCKED && - $forum_status != ITEM_LOCKED) ? true : false; + ($auth->acl_get('f_votechg', $forum_id) && $topic_data['poll_vote_change'])) && + (($topic_fata['poll_length'] != 0 && $topic_data['poll_start'] + $topic_data['poll_length'] > time()) || $topic_data['poll_length'] == 0) && + $topic_data['topic_status'] != ITEM_LOCKED && + $topic_data['forum_status'] != ITEM_LOCKED) ? true : false; $s_display_results = (!$s_can_vote || ($s_can_vote && sizeof($cur_voted_id)) || $view == 'viewpoll') ? true : false; if ($update && $s_can_vote) @@ -680,12 +700,12 @@ if (!empty($poll_start)) } // If the user is trying to reach the second half of the topic, fetch it starting from the end -$store_reverse = FALSE; +$store_reverse = false; $sql_limit = $config['posts_per_page']; if ($start > $total_posts / 2) { - $store_reverse = TRUE; + $store_reverse = true; if ($start + $config['posts_per_page'] > $total_posts) { @@ -727,11 +747,15 @@ while ($row = $db->sql_fetchrow($result)) } $db->sql_freeresult($result); -if (empty($post_list)) +if (!sizeof($post_list)) { trigger_error($user->lang['NO_TOPIC']); } +// Holding maximum post time for marking topic read +// We need to grab it because we do reverse ordering sometimes +$max_post_time = 0; + $sql = 'SELECT u.username, u.user_id, u.user_colour, u.user_posts, u.user_from, u.user_website, u.user_email, u.user_icq, u.user_aim, u.user_yim, u.user_jabber, u.user_regdate, u.user_msnm, u.user_allow_viewemail, u.user_allow_viewonline, u.user_rank, u.user_sig, u.user_sig_bbcode_uid, u.user_sig_bbcode_bitfield, u.user_avatar, u.user_avatar_type, u.user_avatar_width, u.user_avatar_height, z.friend, z.foe, p.* FROM (' . POSTS_TABLE . ' p LEFT JOIN ' . ZEBRA_TABLE . ' z ON (z.user_id = ' . $user->data['user_id'] . ' AND z.zebra_id = p.poster_id)), ' . USERS_TABLE . ' u @@ -743,6 +767,12 @@ $result = $db->sql_query($sql); // and the global bbcode_bitfield are built while ($row = $db->sql_fetchrow($result)) { + // Set max_post_time + if ($row['post_time'] > $max_post_time) + { + $max_post_time = $row['post_time']; + } + $poster_id = $row['poster_id']; $poster = ($poster_id == ANONYMOUS) ? ((!empty($row['post_username'])) ? $row['post_username'] : $user->lang['GUEST']) : $row['username']; @@ -767,7 +797,7 @@ while ($row = $db->sql_fetchrow($result)) if ($row['post_approved']) { - $has_attachments = TRUE; + $has_attachments = true; } } @@ -868,11 +898,11 @@ while ($row = $db->sql_fetchrow($result)) 'online' => false, 'profile' => "{$phpbb_root_path}memberlist.$phpEx$SID&mode=viewprofile&u=$poster_id", 'www' => $row['user_website'], - 'aim' => ($row['user_aim']) ? "memberlist.$phpEx$SID&mode=contact&action=aim&u=$poster_id" : '', - 'msn' => ($row['user_msnm']) ? "memberlist.$phpEx$SID&mode=contact&action=msnm&u=$poster_id" : '', + 'aim' => ($row['user_aim']) ? "{$phpbb_root_path}memberlist.$phpEx$SID&mode=contact&action=aim&u=$poster_id" : '', + 'msn' => ($row['user_msnm']) ? "{$phpbb_root_path}memberlist.$phpEx$SID&mode=contact&action=msnm&u=$poster_id" : '', 'yim' => ($row['user_yim']) ? 'http://edit.yahoo.com/config/send_webmesg?.target=' . $row['user_yim'] . '&.src=pg' : '', - 'jabber' => ($row['user_jabber']) ? "memberlist.$phpEx$SID&mode=contact&action=jabber&u=$poster_id" : '', - 'search' => ($auth->acl_get('u_search')) ? "search.$phpEx$SID&search_author=" . urlencode($row['username']) .'&showresults=posts' : '', + 'jabber' => ($row['user_jabber']) ? "{$phpbb_root_path}memberlist.$phpEx$SID&mode=contact&action=jabber&u=$poster_id" : '', + 'search' => ($auth->acl_get('u_search')) ? "{$phpbb_root_path}search.$phpEx$SID&search_author=" . urlencode($row['username']) .'&showresults=posts' : '', 'username' => ($row['user_colour']) ? '' . $poster . '' : $poster ); @@ -930,7 +960,7 @@ while ($row = $db->sql_fetchrow($result)) if (!empty($row['user_icq'])) { - $user_cache[$poster_id]['icq'] = "memberlist.$phpEx$SID&mode=contact&action=icq&u=$poster_id"; + $user_cache[$poster_id]['icq'] = "{$phpbb_root_path}memberlist.$phpEx$SID&mode=contact&action=icq&u=$poster_id"; $user_cache[$poster_id]['icq_status_img'] = ''; } else @@ -1055,7 +1085,7 @@ $template->assign_vars(array( ); // Output the posts -//foreach ($rowset as $i => $row) +$first_unread = false; for ($i = 0, $end = sizeof($post_list); $i < $end; ++$i) { $row =& $rowset[$post_list[$i]]; @@ -1195,11 +1225,11 @@ for ($i = 0, $end = sizeof($post_list); $i < $end; ++$i) } // Bump information - if ($topic_bumped && $row['post_id'] == $topic_last_post_id) + if ($topic_data['topic_bumped'] && $row['post_id'] == $topic_data['topic_last_post_id']) { // It is safe to grab the username from the user cache array, we are at the last // post and only the topic poster and last poster are allowed to bump - $l_bumped_by = '

' . sprintf($user->lang['BUMPED_BY'], $user_cache[$topic_bumper]['username'], $user->format_date($topic_last_post_time)); + $l_bumped_by = '

' . sprintf($user->lang['BUMPED_BY'], $user_cache[$topic_data['topic_bumper']]['username'], $user->format_date($topic_data['topic_last_post_time'])); } else { @@ -1214,6 +1244,14 @@ for ($i = 0, $end = sizeof($post_list); $i < $end; ++$i) $cp_row = (isset($profile_fields_cache[$poster_id])) ? $cp->generate_profile_fields_template('show', false, $profile_fields_cache[$poster_id]) : array(); } + $post_unread = (isset($topic_tracking_info[$topic_id]) && $row['post_time'] > $topic_tracking_info[$topic_id]) ? true : false; + + $s_first_unread = false; + if (!$first_unread && $post_unread) + { + $s_first_unread = $first_unread = true; + } + // $postrow = array( 'POSTER_NAME' => $row['poster'], @@ -1232,7 +1270,7 @@ for ($i = 0, $end = sizeof($post_list); $i < $end; ++$i) 'EDIT_REASON' => $row['post_edit_reason'], 'BUMPED_MESSAGE'=> $l_bumped_by, - 'MINI_POST_IMG' => ($user->data['is_registered'] && $row['post_time'] > $user->data['user_lastvisit'] && $row['post_time'] > $topic_last_read) ? $user->img('icon_post_new', 'NEW_POST') : $user->img('icon_post', 'POST'), + 'MINI_POST_IMG' => ($post_unread) ? $user->img('icon_post_new', 'NEW_POST') : $user->img('icon_post', 'POST'), 'POST_ICON_IMG' => (!empty($row['icon_id'])) ? $icons[$row['icon_id']]['img'] : '', 'POST_ICON_IMG_WIDTH' => (!empty($row['icon_id'])) ? $icons[$row['icon_id']]['width'] : '', 'POST_ICON_IMG_HEIGHT' => (!empty($row['icon_id'])) ? $icons[$row['icon_id']]['height'] : '', @@ -1255,10 +1293,10 @@ for ($i = 0, $end = sizeof($post_list); $i < $end; ++$i) 'U_YIM' => $user_cache[$poster_id]['yim'], 'U_JABBER' => $user_cache[$poster_id]['jabber'], - 'U_REPORT' => "report.$phpEx$SID&p=" . $row['post_id'], - 'U_MCP_REPORT' => ($auth->acl_gets('m_', 'a_', 'f_report', $forum_id)) ? "mcp.$phpEx$SID&mode=post_details&p=" . $row['post_id'] : '', - 'U_MCP_APPROVE' => ($auth->acl_get('m_approve', $forum_id)) ? "mcp.$phpEx$SID&i=queue&mode=approve&post_id_list[]=" . $row['post_id'] : '', - 'U_MINI_POST' => "viewtopic.$phpEx$SID&p=" . $row['post_id'] . '#' . $row['post_id'], + 'U_REPORT' => "{$phpbb_root_path}report.$phpEx$SID&p=" . $row['post_id'], + 'U_MCP_REPORT' => ($auth->acl_gets('m_', 'a_', 'f_report', $forum_id)) ? "{$phpbb_root_path}mcp.$phpEx$SID&mode=post_details&p=" . $row['post_id'] : '', + 'U_MCP_APPROVE' => ($auth->acl_get('m_approve', $forum_id)) ? "{$phpbb_root_path}mcp.$phpEx$SID&i=queue&mode=approve&post_id_list[]=" . $row['post_id'] : '', + 'U_MINI_POST' => "{$phpbb_root_path}viewtopic.$phpEx$SID&p=" . $row['post_id'] . '#' . $row['post_id'], 'U_NEXT_POST_ID' => ($i < $i_total && isset($rowset[$i + 1])) ? $rowset[$i + 1]['post_id'] : '', 'U_PREV_POST_ID' => $prev_post_id, @@ -1269,8 +1307,8 @@ for ($i = 0, $end = sizeof($post_list); $i < $end; ++$i) 'S_POST_REPORTED' => ($row['post_reported'] && $auth->acl_get('m_', $forum_id)) ? TRUE : FALSE, 'S_DISPLAY_NOTICE' => $display_notice && $row['post_attachment'], 'S_FRIEND' => ($row['friend']) ? true : false, - 'S_UNREAD_POST' => ($user->data['is_registered'] && $row['post_time'] > $user->data['user_lastvisit'] && $row['post_time'] > $topic_last_read) ? true : false, - 'S_FIRST_UNREAD' => ($unread_post_id == $row['post_id']) ? true : false, + 'S_UNREAD_POST' => $post_unread, + 'S_FIRST_UNREAD' => $s_first_unread, 'S_CUSTOM_FIELDS' => (isset($cp_row['row']) && sizeof($cp_row['row'])) ? true : false ); @@ -1328,9 +1366,11 @@ if (isset($user->data['session_page']) && !preg_match("#&t=$topic_id#", $user->d } } -// Mark topics read -$mark_forum_id = ($topic_type == POST_GLOBAL) ? 0 : $forum_id; -markread('topic', $mark_forum_id, $topic_id, $row['post_time']); +// Only mark topic if it's currently unread +if (isset($topic_tracking_info[$topic_id]) && $topic_data['topic_last_post_time'] > $topic_tracking_info[$topic_id]) +{ + markread('topic', $forum_id, $topic_id, $max_post_time); +} // Change encoding if appropriate if ($force_encoding != '') @@ -1339,7 +1379,7 @@ if ($force_encoding != '') } // Output the page -page_header($user->lang['VIEW_TOPIC'] .' - ' . $topic_title); +page_header($user->lang['VIEW_TOPIC'] .' - ' . $topic_data['topic_title']); $template->set_filenames(array( 'body' => ($view == 'print') ? 'viewtopic_print.html' : 'viewtopic_body.html') @@ -1348,56 +1388,4 @@ make_jumpbox('viewforum.'.$phpEx, $forum_id); page_footer(); - -// FUNCTIONS - -function get_topic_last_read($topic_id, $forum_id) -{ - global $config, $user, $db; - - $topic_last_read = 0; - - if ($config['load_db_lastread']) - { - $sql = 'SELECT mark_time - FROM ' . TOPICS_TRACK_TABLE . ' - WHERE user_id = ' . $user->data['user_id'] . " - AND topic_id = $topic_id"; - $result = $db->sql_query($sql); - $row = $db->sql_fetchrow($result); - $db->sql_freeresult($result); - - $topic_last_read = ($row) ? min($row['mark_time'], $user->data['session_last_visit']) : $user->data['session_last_visit']; - - if (!$row) - { - $sql = 'SELECT mark_time - FROM ' . FORUMS_TRACK_TABLE . ' - WHERE user_id = ' . $user->data['user_id'] . " - AND forum_id = $forum_id"; - $result = $db->sql_query($sql); - $forum_mark_time = (int) $db->sql_fetchfield('mark_time', 0, $result); - $db->sql_freeresult($result); - - $topic_last_read = ($forum_mark_time) ? min($topic_last_read, $forum_mark_time) : $topic_last_read; - } - } - else - { - $topic_last_read = 0; - if (isset($_COOKIE[$config['cookie_name'] . '_track'])) - { - $tracking_topics = unserialize(stripslashes($_COOKIE[$config['cookie_name'] . '_track'])); - if (isset($tracking_topics[$forum_id])) - { - $topic_last_read = base_convert(max($tracking_topics[$forum_id]), 36, 10); - $topic_last_read = max($topic_last_read, $user->data['session_last_visit']); - } - unset($tracking_topics); - } - } - - return $topic_last_read; -} - ?> \ No newline at end of file