diff options
Diffstat (limited to 'phpBB/includes')
| -rw-r--r-- | phpBB/includes/db/postgres.php | 122 | ||||
| -rw-r--r-- | phpBB/includes/functions.php | 200 | ||||
| -rw-r--r-- | phpBB/includes/functions_display.php | 156 |
3 files changed, 266 insertions, 212 deletions
diff --git a/phpBB/includes/db/postgres.php b/phpBB/includes/db/postgres.php index 96a90fbb1a..644fba48b0 100644 --- a/phpBB/includes/db/postgres.php +++ b/phpBB/includes/db/postgres.php @@ -19,7 +19,7 @@ * ***************************************************************************/ -if(!defined("SQL_LAYER")) +if (!defined("SQL_LAYER")) { define("SQL_LAYER","postgresql"); @@ -42,33 +42,33 @@ class sql_db { $this->connect_string = ""; - if( $sqluser ) + if ($sqluser) { $this->connect_string .= "user=$sqluser "; } - if( $sqlpassword ) + if ($sqlpassword) { $this->connect_string .= "password=$sqlpassword "; } - if( $sqlserver ) + if ($sqlserver) { - if( ereg(":", $sqlserver) ) + if (ereg(":", $sqlserver)) { list($sqlserver, $sqlport) = split(":", $sqlserver); $this->connect_string .= "host=$sqlserver port=$sqlport "; } else { - if( $sqlserver != "localhost" ) + if ($sqlserver != "localhost") { $this->connect_string .= "host=$sqlserver "; } } } - if( $database ) + if ($database) { $this->dbname = $database; $this->connect_string .= "dbname=$database"; @@ -76,9 +76,9 @@ class sql_db $this->persistency = $persistency; - $this->db_connect_id = ( $this->persistency ) ? pg_pconnect($this->connect_string) : pg_connect($this->connect_string); + $this->db_connect_id = ($this->persistency) ? pg_pconnect($this->connect_string) : pg_connect($this->connect_string); - return ( $this->db_connect_id ) ? $this->db_connect_id : false; + return ($this->db_connect_id) ? $this->db_connect_id : false; } // @@ -86,17 +86,17 @@ class sql_db // function sql_close() { - if( $this->db_connect_id ) + if ($this->db_connect_id) { // // Commit any remaining transactions // - if( $this->in_transaction ) + if ($this->in_transaction) { @pg_exec($this->db_connect_id, "COMMIT"); } - if( $this->query_result ) + if ($this->query_result) { @pg_freeresult($this->query_result); } @@ -118,30 +118,30 @@ class sql_db // Remove any pre-existing queries // unset($this->query_result); - if( $query != "" ) + if ($query != "") { $this->num_queries++; $query = preg_replace("/LIMIT ([0-9]+),([ 0-9]+)/", "LIMIT \\2 OFFSET \\1", $query); - if( $transaction == BEGIN_TRANSACTION && !$this->in_transaction ) + if ($transaction == BEGIN_TRANSACTION && !$this->in_transaction) { $this->in_transaction = TRUE; - if( !@pg_exec($this->db_connect_id, "BEGIN") ) + if (!@pg_exec($this->db_connect_id, "BEGIN")) { return false; } } $this->query_result = @pg_exec($this->db_connect_id, $query); - if( $this->query_result ) + if ($this->query_result) { - if( $transaction == END_TRANSACTION ) + if ($transaction == END_TRANSACTION) { $this->in_transaction = FALSE; - if( !@pg_exec($this->db_connect_id, "COMMIT") ) + if (!@pg_exec($this->db_connect_id, "COMMIT")) { @pg_exec($this->db_connect_id, "ROLLBACK"); return false; @@ -158,7 +158,7 @@ class sql_db } else { - if( $this->in_transaction ) + if ($this->in_transaction) { @pg_exec($this->db_connect_id, "ROLLBACK"); } @@ -169,11 +169,11 @@ class sql_db } else { - if( $transaction == END_TRANSACTION && $this->in_transaction ) + if ($transaction == END_TRANSACTION && $this->in_transaction) { $this->in_transaction = FALSE; - if( !@pg_exec($this->db_connect_id, "COMMIT") ) + if (!@pg_exec($this->db_connect_id, "COMMIT")) { @pg_exec($this->db_connect_id, "ROLLBACK"); return false; @@ -189,56 +189,56 @@ class sql_db // function sql_numrows($query_id = 0) { - if( !$query_id ) + if (!$query_id) { $query_id = $this->query_result; } - return ( $query_id ) ? @pg_numrows($query_id) : false; + return ($query_id) ? @pg_numrows($query_id) : false; } function sql_numfields($query_id = 0) { - if( !$query_id ) + if (!$query_id) { $query_id = $this->query_result; } - return ( $query_id ) ? @pg_numfields($query_id) : false; + return ($query_id) ? @pg_numfields($query_id) : false; } function sql_fieldname($offset, $query_id = 0) { - if( !$query_id ) + if (!$query_id) { $query_id = $this->query_result; } - return ( $query_id ) ? @pg_fieldname($query_id, $offset) : false; + return ($query_id) ? @pg_fieldname($query_id, $offset) : false; } function sql_fieldtype($offset, $query_id = 0) { - if( !$query_id ) + if (!$query_id) { $query_id = $this->query_result; } - return ( $query_id ) ? @pg_fieldtype($query_id, $offset) : false; + return ($query_id) ? @pg_fieldtype($query_id, $offset) : false; } function sql_fetchrow($query_id = 0) { - if( !$query_id ) + if (!$query_id) { $query_id = $this->query_result; } - if($query_id) + if ($query_id) { $this->row = @pg_fetch_array($query_id, $this->rownum[$query_id]); - if( $this->row ) + if ($this->row) { $this->rownum[$query_id]++; return $this->row; @@ -250,18 +250,18 @@ class sql_db function sql_fetchrowset($query_id = 0) { - if( !$query_id ) + if (!$query_id) { $query_id = $this->query_result; } - if( $query_id ) + if ($query_id) { unset($this->rowset[$query_id]); unset($this->row[$query_id]); $this->rownum[$query_id] = 0; - while( $this->rowset = @pg_fetch_array($query_id, $this->rownum[$query_id], PGSQL_ASSOC) ) + while($this->rowset = @pg_fetch_array($query_id, $this->rownum[$query_id], PGSQL_ASSOC)) { $result[] = $this->rowset; $this->rownum[$query_id]++; @@ -275,51 +275,25 @@ class sql_db function sql_fetchfield($field, $row_offset=-1, $query_id = 0) { - if( !$query_id ) + if (!$query_id) { $query_id = $this->query_result; } - if( $query_id ) - { - if( $row_offset != -1 ) - { - $this->row = @pg_fetch_array($query_id, $row_offset, PGSQL_ASSOC); - } - else - { - if( $this->rownum[$query_id] ) - { - $this->row = @pg_fetch_array($query_id, $this->rownum[$query_id]-1, PGSQL_ASSOC); - } - else - { - $this->row = @pg_fetch_array($query_id, $this->rownum[$query_id], PGSQL_ASSOC); - - if( $this->row ) - { - $this->rownum[$query_id]++; - } - } - } - - return $this->row[$field]; - } - return false; } function sql_rowseek($offset, $query_id = 0) { - if(!$query_id) + if (!$query_id) { $query_id = $this->query_result; } - if( $query_id ) + if ($query_id) { - if( $offset > -1 ) + if ($offset > -1) { $this->rownum[$query_id] = $offset; return true; @@ -337,20 +311,20 @@ class sql_db { $query_id = $this->query_result; - if($query_id && $this->last_query_text[$query_id] != "") + if ($query_id && $this->last_query_text[$query_id] != "") { - if( preg_match("/^INSERT[\t\n ]+INTO[\t\n ]+([a-z0-9\_\-]+)/is", $this->last_query_text[$query_id], $tablename) ) + if (preg_match("/^INSERT[\t\n ]+INTO[\t\n ]+([a-z0-9\_\-]+)/is", $this->last_query_text[$query_id], $tablename)) { $query = "SELECT currval('" . $tablename[1] . "_id_seq') AS last_value"; $temp_q_id = @pg_exec($this->db_connect_id, $query); - if( !$temp_q_id ) + if (!$temp_q_id) { return false; } $temp_result = @pg_fetch_array($temp_q_id, 0, PGSQL_ASSOC); - return ( $temp_result ) ? $temp_result['last_value'] : false; + return ($temp_result) ? $temp_result['last_value'] : false; } } @@ -359,27 +333,27 @@ class sql_db function sql_affectedrows($query_id = 0) { - if( !$query_id ) + if (!$query_id) { $query_id = $this->query_result; } - return ( $query_id ) ? @pg_cmdtuples($query_id) : false; + return ($query_id) ? @pg_cmdtuples($query_id) : false; } function sql_freeresult($query_id = 0) { - if( !$query_id ) + if (!$query_id) { $query_id = $this->query_result; } - return ( $query_id ) ? @pg_freeresult($query_id) : false; + return ($query_id) ? @pg_freeresult($query_id) : false; } function sql_error($query_id = 0) { - if( !$query_id ) + if (!$query_id) { $query_id = $this->query_result; } diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 966b253466..8adc170b1f 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -528,122 +528,158 @@ function markread($mode, $forum_id = 0, $topic_id = 0, $post_id = 0) return; } + // Default tracking type + $type = TRACK_NORMAL; + $current_time = time(); + switch ($mode) { case 'mark': - // Mark one forum as read. - // Do this by inserting a record with -$forum_id in the 'forum_id' field. - $sql = "SELECT forum_id - FROM " . TOPICS_TRACK_TABLE . " - WHERE user_id = " . $user->data['user_id'] . " - AND forum_id = -$forum_id"; - $result = $db->sql_query($sql); - - if ($db->sql_fetchrow($result)) + if ($config['load_db_lastread']) { + // Mark one forum as read. + // Do this by inserting a record with -$forum_id in the 'forum_id' field. // User has marked this topic as read before: Update the record - $sql = "UPDATE " . TOPICS_TRACK_TABLE . " - SET mark_time = " . time() . " + $db->sql_return_on_error = true; + + $sql = 'UPDATE ' . FORUMS_TRACK_TABLE . " + SET mark_time = $current_time WHERE user_id = " . $user->data['user_id'] . " - AND forum_id = -$forum_id"; - $db->sql_query($sql); + AND forum_id = $forum_id"; + if (!$db->sql_query($sql) || !$db->sql_affectedrows()) + { + // User is marking this forum for the first time. + // Insert dummy topic_id to satisfy PRIMARY KEY (user_id, topic_id) + // dummy id = -forum_id + $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); + } + + $db->sql_return_on_error = false; } else { - // User is marking this forum for the first time. - // Insert dummy topic_id to satisfy PRIMARY KEY (user_id, topic_id) - // dummy id = -forum_id - $sql = "INSERT INTO " . TOPICS_TRACK_TABLE . " - (user_id, forum_id, topic_id, mark_time) - VALUES - (" . $user->data['user_id'] . ", -$forum_id, -$forum_id, " . time() . ")"; - $db->sql_query($sql); + $tracking_forums = (isset($_COOKIE[$config['cookie_name'] . '_f'])) ? unserialize($_COOKIE[$config['cookie_name'] . '_f']) : array(); + $tracking_forums[$forum_id] = time(); + + setcookie($config['cookie_name'] . '_f', serialize($tracking_forums), time() + 31536000, $config['cookie_path'], $config['cookie_domain'], $config['cookie_secure']); + unset($tracking_forums); } break; case 'markall': - // Mark all forums as read. + // Mark all forums as read + + if ($config['load_db_lastread']) + { + $sql = 'UPDATE ' . FORUMS_TRACK_TABLE . ' + SET mark_time = ' . $current_time . ' + WHERE user_id = ' . $user->data['user_id']; + $db->sql_query($sql); + } + else + { + $tracking_forums = array(); + } + // Select all forum_id's that are not yet in the lastread table - $sql = "SELECT f.forum_id - FROM " . FORUMS_TABLE . " f - LEFT JOIN (" . TOPICS_TRACK_TABLE . " lr ON ( - lr.user_id = " . $user->data['user_id'] . " - AND f.forum_id = -lr.forum_id)) - WHERE lr.forum_id IS NULL"; + switch (SQL_LAYER) + { + case 'oracle': + break; + + default: + $sql = ($config['load_db_lastread']) ? 'SELECT f.forum_id 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)) WHERE ft.forum_id IS NULL' : 'SELECT forum_id FROM ' . FORUMS_TABLE; + } $result = $db->sql_query($sql); + $db->sql_return_on_error = true; if ($row = $db->sql_fetchrow($result)) { - // Some forum_id's are missing. We are not taking into account - // the auth data, even forums the user can't see are marked as read. - $sql = "INSERT INTO " . TOPICS_TRACK_TABLE . " - (user_id, forum_id, topic_id, lastread_time) - VALUES"; - $forum_insert = array(); - - do + do { - // Insert dummy topic_id to satisfy PRIMARY KEY - // dummy id = -forum_id - $forum_insert[] = "(" . $user->data['user_id'] . ", -".$row['forum_id'].", -".$row['forum_id'].", " . time() . ")"; + if ($config['load_db_lastread']) + { + $sql = ''; + // Some forum_id's are missing. We are not taking into account + // the auth data, even forums the user can't see are marked as read. + switch (SQL_LAYER) + { + case 'mysql': + case 'mysql4': + $sql .= (($sql != '') ? ', ' : '') . '(' . $user->data['user_id'] . ', ' . $row['forum_id'] . ", $current_time)"; + break; + + case 'mssql': + $sql = (($sql != '') ? ' UNION ALL ' : '') . ' SELECT ' . $user->data['user_id'] . ', ' . $row['forum_id'] . ", $current_time"; + break; + + default: + $sql = 'INSERT INTO ' . FORUMS_TRACK_TABLE . ' (user_id, forum_id, mark_time) + VALUES (' . $user->data['user_id'] . ', ' . $row['forum_id'] . ", $current_time)"; + $db->sql_query($sql); + $sql = ''; + } + + if ($sql != '') + { + $sql = 'INSERT INTO ' . FORUMS_TRACK_TABLE . ' (user_id, forum_id, mark_time) + VALUES ' . $sql; + $db->sql_query($sql); + } + } + else + { + $tracking_forums[$row['forum_id']] = $current_time; + } } while ($row = $db->sql_fetchrow($result)); + $db->sql_freeresult($result); - $forum_insert = implode(",\n", $forum_insert); - $sql .= $forum_insert; + $db->sql_return_on_error = false; - $db->sql_query($sql); + if (!$config['load_db_lastread']) + { + setcookie($config['cookie_name'] . '_f', serialize($tracking_forums), time() + 31536000, $config['cookie_path'], $config['cookie_domain'], $config['cookie_secure']); + unset($tracking_forums); + } } - - // Mark all forums as read - $sql = "UPDATE " . TOPICS_TRACK_TABLE . " - SET mark_time = " . time() . " - WHERE user_id = " . $user->data['user_id'] . " - AND forum_id < 0"; - $db->sql_query($sql); break; case 'post': // Mark a topic as read and mark it as a topic where the user has made a post. - $type = 1; + $type = TRACK_POSTED; case 'topic': - // Mark a topic as read. - - // Type: - // 0 = Normal topic - // 1 = user made a post in this topic - $type_update = (isset($type) && $type = 1) ? 'mark_type = 1,' : ''; - $sql = "UPDATE " . TOPICS_TRACK_TABLE . " - SET $type_update forum_id = $forum_id, mark_time = " . time() . " - WHERE topic_id = $topic_id - AND user_id = " . $user->data['user_id']; - $result = $db->sql_query($sql); - - if (!$db->sql_affectedrows($result)) + // Mark a topic as read + if ($config['load_db_lastread'] || ($config['load_db_track'] && $type == TRACK_POSTED)) { - // Couldn't update. Row probably doesn't exist. Insert one. - if(isset($type) && $type = 1) - { - $type_name = 'mark_type, '; - $type_value = '1, '; - } - else + $sql = 'UPDATE ' . TOPICS_TRACK_TABLE . " + SET mark_type = $type, mark_time = " . time() . " + WHERE topic_id = $topic_id + AND user_id = " . $user->data['user_id']; + if (!$db->sql_query($sql) || !$db->sql_affectedrows()) { - $type_name = ''; - $type_value = ''; + $sql = 'INSERT INTO ' . TOPICS_TRACK_TABLE . ' (user_id, topic_id, mark_type, mark_time) + VALUES (' . $user->data['user_id'] . ", $topic_id, $type, " . time() . ")"; + $db->sql_query($sql); } + } - $sql = "INSERT INTO " . TOPICS_TRACK_TABLE . " - (user_id, topic_id, forum_id, $type_name mark_time) - VALUES - (" . $user->data['user_id'] . ", $topic_id, $forum_id, $type_value " . time() . ")"; - $db->sql_query($sql); + if (!$config['load_db_lastread']) + { + $tracking = (isset($_COOKIE[$config['cookie_name'] . '_t'])) ? unserialize($_COOKIE[$config['cookie_name'] . '_t']) : array(); + $tracking[$topic_id] = $current_time; + + setcookie($config['cookie_name'] . '_t', serialize($tracking), time() + 31536000, $config['cookie_path'], $config['cookie_domain'], $config['cookie_secure']); + unset($tracking); } break; } } + // Pagination routine, generates page number sequence function generate_pagination($base_url, $num_items, $per_page, $start_item, $add_prevnext_text = TRUE) { @@ -848,6 +884,16 @@ function redirect($url) exit; } +// Meta refresh assignment +function meta_refresh($time, $url) +{ + global $template; + + $template->assign_vars(array( + 'META' => '<meta http-equiv="refresh" content="' . $time . ';url=' . $url . '">') + ); +} + // Generate login box or verify password function login_box($s_action, $s_hidden_fields = '', $login_explain = '') diff --git a/phpBB/includes/functions_display.php b/phpBB/includes/functions_display.php index 6fa6a7375c..563728f7b6 100644 --- a/phpBB/includes/functions_display.php +++ b/phpBB/includes/functions_display.php @@ -21,8 +21,8 @@ function display_forums($root_data = '', $display_moderators = TRUE) { - global $db, $template, $auth, $user; - global $config, $phpEx, $SID, $forum_moderators; + global $config, $db, $template, $auth, $user; + global $phpEx, $SID, $forum_moderators; $visible_forums = 0; @@ -38,20 +38,25 @@ function display_forums($root_data = '', $display_moderators = TRUE) if ($config['load_db_lastread'] && $user->data['user_id'] != ANONYMOUS) { - $lastread_select = ", lr.lastread_time "; -/* $sql_lastread = 'LEFT JOIN ' . FORUMS_TRACK_TABLE . ' ft ON (ft.user_id = ' . $user->data['user_id'] . ' - AND ft.forum_id = f.forum_id)';*/ - $sql_lastread = 'LEFT JOIN ' . TOPICS_TRACK_TABLE . ' tt ON (tt.user_id = ' . $user->data['user_id'] . ' - AND tt.forum_id IN (f.forum_id, -f.forum_id) - AND tt.lastread_time >= f.forum_last_post_time)'; - $sql_where .= ' GROUP BY f.forum_id'; + switch (SQL_LAYER) + { + case 'oracle': + break; + + default: + $sql_lastread = 'LEFT JOIN ' . FORUMS_TRACK_TABLE . ' ft ON (ft.user_id = ' . $user->data['user_id'] . ' + AND ft.forum_id = f.forum_id)'; + break; + } + $lastread_select = ', ft.mark_time '; } else { $lastread_select = ''; $sql_lastread = ''; - // Cookie based tracking + $tracking_forums = (isset($_COOKIE[$config['cookie_name'] . '_f'])) ? unserialize($_COOKIE[$config['cookie_name'] . '_f']) : array(); + $tracking_topics = (isset($_COOKIE[$config['cookie_name'] . '_t'])) ? unserialize($_COOKIE[$config['cookie_name'] . '_t']) : array(); } $sql = "SELECT f.* $lastread_select @@ -82,57 +87,101 @@ function display_forums($root_data = '', $display_moderators = TRUE) continue; } - if (!$auth->acl_get('f_list', $row['forum_id'])) + $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 - $right_id = $row['right_id']; continue; } - if ($row['parent_id'] == $root_data['forum_id']) + if ($row['parent_id'] == $root_data['forum_id'] || $row['parent_id'] == $branch_root_id) { // Direct child - $forum_rows[] = $row; - $parent_id = $row['forum_id']; - $forum_ids[] = $row['forum_id']; + $parent_id = $forum_id; + $forum_rows[$forum_id] = $row; + $forum_ids[] = $forum_id; - if (!$row['forum_postable']) + if (!$row['forum_postable'] && $row['parent_id'] == $root_data['forum_id']) { - $branch_root_id = $row['forum_id']; + $branch_root_id = $forum_id; } } - elseif ($row['parent_id'] == $branch_root_id) - { - // Forum directly under a category - $forum_rows[] = $row; - $parent_id = $row['forum_id']; - $forum_ids[] = $row['forum_id']; - } elseif ($row['forum_postable']) { if ($row['display_on_index']) { - $subforums[$parent_id][$row['forum_id']]['forum_name'] = $row['forum_name']; + $subforums[$parent_id][$forum_id] = $row['forum_name']; } + } +/* + if (!empty($forum_unread[$forum_id])) + { + $forum_unread[$parent_id] = true; + } +*/ + + if (!isset($forum_unread[$parent_id])) + { + $forum_unread[$parent_id] = false; + } - $subforums[$parent_id][$row['forum_id']]['unread_count'] = $row['unread_count']; - $subforums[$parent_id][$row['forum_id']]['forum_last_post_time'] = $row['forum_last_post_time']; + $check_time = (!$config['load_db_lastread']) ? $tracking_forums[$forum_id] : $row['mark_time']; + if ($check_time < $row['forum_last_post_time'] && $user->data['user_id'] != ANONYMOUS) + { + $forum_unread[$parent_id] = true; + } - $subforums[$parent_id][$row['forum_id']]['forum_id'] = $row['forum_id']; - $subforums[$parent_id][$row['forum_id']]['forum_last_post_id'] = $row['forum_last_post_id']; - $subforums[$parent_id][$row['forum_id']]['forum_last_post_time'] = $row['forum_last_post_time']; - $subforums[$parent_id][$row['forum_id']]['forum_last_poster_name'] = $row['forum_last_poster_name']; - $subforums[$parent_id][$row['forum_id']]['forum_last_poster_id'] = $row['forum_last_poster_id']; + + // Show most recent last post info on parent if we're a subforum + if (isset($forum_rows[$parent_id]) && $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']; + $forum_rows[$parent_id]['forum_last_poster_id'] = $row['forum_last_poster_id']; + $forum_rows[$parent_id]['forum_last_poster_name'] = $row['forum_last_poster_name']; + $forum_rows[$parent_id]['forum_id_last_post'] = $row['forum_id']; + } + else + { + $forum_rows[$forum_id]['forum_id_last_post'] = $row['forum_id']; } } $db->sql_freeresult(); +/* + if ($config['load_db_lastread']) + { + } + else + { + $forum_unread = array(); + $sql = "SELECT forum_id, topic_id, topic_last_post_time + FROM " . TOPICS_TABLE . " + WHERE topic_last_post_time > " . ((sizeof($tracking_forums)) ? min($tracking_forums) : time() - 86400) . " + $sql_forum_track; + $result = $db->sql_query($sql); + + while ($row = $db->sql_fetchrow($result)) + { + if (($tracking_forums[$row['forum_id']] > $tracking_topics[$row['topic_id']] && + $row['topic_last_post_time'] > $tracking_forums[$row['forum_id']]) || + ($tracking_topics[$row['topic_id']] > $tracking_forums[$row['forum_id']] && + $row['topic_last_post_time'] > $tracking_topics[$row['topic_id']])) + { + $forum_unread[$row['forum_id']] = $row['topic_last_post_time']; + } + } + } +*/ + if ($display_moderators) { get_moderators($forum_moderators, $forum_ids); } + $root_id = $root_data['forum_id']; foreach ($forum_rows as $row) { @@ -161,40 +210,23 @@ function display_forums($root_data = '', $display_moderators = TRUE) } $visible_forums++; - $forum_id = $row['forum_id']; - // - $unread_topics = ($user->data['user_id'] != ANONYMOUS && $row['unread_count'] < $row['forum_last_post_time']) ? 1 : 0; - // + // Generate list of subforums if we need to if (isset($subforums[$forum_id])) { - $alist = array(); - foreach ($subforums[$forum_id] as $sub_forum_id => $subforum_row) + foreach ($subforums[$forum_id] as $sub_forum_id => $subforum_name) { - $unread_topics += ($user->data['user_id'] != ANONYMOUS && $subforum_row['unread_count'] < $subforum_row['forum_last_post_time']) ? 1 : 0; - - if (!empty($subforum_row['forum_name'])) - { - $alist[$sub_forum_id] = $subforum_row['forum_name']; - } - - if ($subforum_row['forum_last_post_time'] > $row['forum_last_post_time']) + if (!empty($subforum_name)) { - $row['forum_last_post_time'] = $subforum_row['forum_last_post_time']; - $row['forum_last_post_id'] = $subforum_row['forum_last_post_id']; - $row['forum_last_poster_name'] = $subforum_row['forum_last_poster_name']; - $row['forum_last_poster_id'] = $subforum_row['forum_last_poster_id']; - $row['forum_id_last_post'] = $subforum_row['forum_id']; + $alist[$sub_forum_id] = $subforum_name; } } if (sizeof($alist)) { - @natsort($alist); - $links = array(); foreach ($alist as $subforum_id => $subforum_name) { @@ -205,18 +237,18 @@ function display_forums($root_data = '', $display_moderators = TRUE) $l_subforums = (count($subforums[$forum_id]) == 1) ? $user->lang['SUBFORUM'] . ': ' : $user->lang['SUBFORUMS'] . ': '; } - $folder_image = ($unread_topics) ? 'sub_forum_new' : 'sub_forum'; + $folder_image = ($forum_unread[$forum_id]) ? 'sub_forum_new' : 'sub_forum'; } else { - $folder_image = ($unread_topics) ? 'forum_new' : 'forum'; - $row['forum_id_last_post'] = $row['forum_id']; + $folder_image = ($forum_unread[$forum_id]) ? 'forum_new' : 'forum'; $subforums_list = ''; $l_subforums = ''; } - // + + // Which folder should we display? if ($row['forum_status'] == ITEM_LOCKED) { $folder_image = 'forum_locked'; @@ -224,10 +256,11 @@ function display_forums($root_data = '', $display_moderators = TRUE) } else { - $folder_alt = ($unread_topics) ? 'NEW_POSTS' : 'NO_NEW_POSTS'; + $folder_alt = ($forum_unread[$forum_id]) ? 'NEW_POSTS' : 'NO_NEW_POSTS'; } - // + + // Create last post link information, if appropriate if ($row['forum_last_post_id']) { $last_post_time = $user->format_date($row['forum_last_post_time']); @@ -242,7 +275,8 @@ function display_forums($root_data = '', $display_moderators = TRUE) $last_post_time = $last_poster = $last_poster_url = $last_post_url = ''; } - // + + // Output moderator listing ... if applicable $l_moderator = $moderators_list = ''; if ($display_moderators && !empty($forum_moderators[$forum_id])) { |
