diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php
index ce55a63155..ffcb49dc1b 100644
--- a/phpBB/includes/functions.php
+++ b/phpBB/includes/functions.php
@@ -73,7 +73,7 @@ function get_userdata($user)
global $db;
$sql = "SELECT *
- FROM " . USERS_TABLE . "
+ FROM " . USERS_TABLE . "
WHERE ";
$sql .= ( ( is_integer($user) ) ? "user_id = $user" : "username = '" . str_replace("\'", "''", $user) . "'" ) . " AND user_id <> " . ANONYMOUS;
$result = $db->sql_query($sql);
@@ -91,13 +91,13 @@ function get_moderators(&$forum_moderators, $forum_id = false)
$forum_sql = ( $forum_id ) ? 'AND au.forum_id = ' . $forum_id : '';
- $sql = "SELECT au.forum_id, u.user_id, u.username
+ $sql = "SELECT au.forum_id, u.user_id, u.username
FROM " . ACL_USERS_TABLE . " au, " . ACL_OPTIONS_TABLE . " ao, " . USERS_TABLE . " u
- WHERE ao.auth_type LIKE 'mod'
- AND au.auth_option_id = ao.auth_option_id
- $forum_sql
- AND u.user_id = au.user_id
- GROUP BY au.forum_id
+ WHERE ao.auth_value LIKE 'mod_%'
+ $forum_sql
+ AND au.auth_option_id = ao.auth_option_id
+ AND u.user_id = au.user_id
+ GROUP BY au.forum_id, u.user_id, u.username
ORDER BY au.forum_id, u.user_id";
$result = $db->sql_query($sql);
@@ -106,13 +106,13 @@ function get_moderators(&$forum_moderators, $forum_id = false)
$forum_moderators[$row['forum_id']][] = '' . $row['username'] . '';
}
- $sql = "SELECT au.forum_id, g.group_id, g.group_name
+ $sql = "SELECT au.forum_id, g.group_id, g.group_name
FROM " . ACL_GROUPS_TABLE . " au, " . ACL_OPTIONS_TABLE . " ao, " . GROUPS_TABLE . " g
- WHERE ao.auth_type LIKE 'mod'
- AND au.auth_option_id = ao.auth_option_id
- $forum_sql
- AND g.group_id = au.group_id
- GROUP BY au.forum_id
+ WHERE ao.auth_value LIKE 'mod_%'
+ $forum_sql
+ AND au.auth_option_id = ao.auth_option_id
+ AND g.group_id = au.group_id
+ GROUP BY au.forum_id, g.group_id, g.group_name
ORDER BY au.forum_id, g.group_id";
$result = $db->sql_query($sql);
@@ -149,12 +149,12 @@ function make_jumpbox($action, $match_forum_id = 0)
{
global $SID, $acl, $template, $lang, $db, $nav_links, $phpEx;
- $sql = "SELECT f.*, p.post_time, p.post_username, u.username, u.user_id
- FROM (( " . FORUMS_TABLE . " f
- LEFT JOIN " . POSTS_TABLE . " p ON p.post_id = f.forum_last_post_id )
- LEFT JOIN " . USERS_TABLE . " u ON u.user_id = p.poster_id )
- ORDER BY f.forum_id";
- $result = $db->sql_query($sql);
+// $sql = "SELECT f.*, p.post_time, p.post_username, u.username, u.user_id
+// FROM (( " . FORUMS_TABLE . " f
+// LEFT JOIN " . POSTS_TABLE . " p ON p.post_id = f.forum_last_post_id )
+// LEFT JOIN " . USERS_TABLE . " u ON u.user_id = p.poster_id )
+// ORDER BY f.forum_id";
+// $result = $db->sql_query($sql);
if ( $row = $db->sql_fetchrow($result) )
{
@@ -252,14 +252,14 @@ function language_select($default, $select_name = "language", $dirname="language
}
//
-// Pick a template/theme combo,
+// Pick a template/theme combo,
//
function style_select($default_style, $select_name = "style", $dirname = "templates")
{
global $db;
$sql = "SELECT style_id, style_name
- FROM " . STYLES_TABLE . "
+ FROM " . STYLES_TABLE . "
ORDER BY style_name, style_id";
$result = $db->sql_query($sql);
@@ -305,14 +305,14 @@ function watch_topic_forum($mode, &$s_watching, &$s_watching_img, $user_id, $mat
$u_url = ( $mode == 'forum' ) ? 'f' : 't';
//
- // Is user watching this thread?
+ // Is user watching this thread?
//
- if ( $user_id != ANONYMOUS )
+ if ( $user_id )
{
$can_watch = TRUE;
- $sql = "SELECT notify_status
- FROM " . $table_sql . "
+ $sql = "SELECT notify_status
+ FROM " . $table_sql . "
WHERE $where_sql = $match_id
AND user_id = $user_id";
$result = $db->sql_query($sql);
@@ -326,11 +326,11 @@ function watch_topic_forum($mode, &$s_watching, &$s_watching_img, $user_id, $mat
$is_watching = 0;
$sql = "DELETE FROM " . $table_sql . "
- WHERE $where_sql = $match_id
+ WHERE $where_sql = $match_id
AND user_id = $user_id";
$db->sql_query($sql);
}
-
+
$template->assign_vars(array(
'META' => '')
);
@@ -562,7 +562,7 @@ function obtain_word_list(&$orig_word, &$replacement_word)
if ( $row = $db->sql_fetchrow($result) )
{
- do
+ do
{
$orig_word[] = '#\b(' . str_replace('\*', '\w*?', preg_quote($row['word'], '#')) . ')\b#i';
$replacement_word[] = $row['replacement'];
diff --git a/phpBB/includes/session.php b/phpBB/includes/session.php
index d6ba64cd57..88d02d342d 100644
--- a/phpBB/includes/session.php
+++ b/phpBB/includes/session.php
@@ -386,21 +386,21 @@ class acl
if ( !($this->founder = $userdata['user_founder']) )
{
- $and_sql = "ao.auth_option LIKE 'list'";
+ $and_sql = "ao.auth_value LIKE 'forum_list'";
if ( $extra_options )
{
$tmp_ary = explode(',', $extra_options);
foreach ( $tmp_ary as $option )
{
- $and_sql .= " OR ao.auth_option LIKE '" . trim($option) . "'";
+ $and_sql .= " OR ao.auth_value LIKE '" . trim($option) . "'";
}
}
- $and_sql = ( !$forum_id ) ? $and_sql : "( a.forum_id = $forum_id ) OR ( a.forum_id <> $forum_id AND ( ao.auth_option LIKE 'list' OR ao.auth_type LIKE 'mod' ) )";
- $and_sql .= " OR ao.auth_type LIKE 'admin'";
+ $and_sql = ( !$forum_id ) ? $and_sql : "( a.forum_id = $forum_id ) OR ( a.forum_id <> $forum_id AND ( ao.auth_value LIKE 'forum_list' OR ao.auth_value LIKE 'mod_%' ) )";
+ $and_sql .= " OR ao.auth_value LIKE 'admin_%'";
- $sql = "SELECT a.forum_id, a.auth_allow_deny, ao.auth_type, ao.auth_option
+ $sql = "SELECT a.forum_id, a.auth_allow_deny, ao.auth_value
FROM " . ACL_GROUPS_TABLE . " a, " . ACL_OPTIONS_TABLE . " ao, " . USER_GROUP_TABLE . " ug
WHERE ug.user_id = " . $userdata['user_id'] . "
AND a.group_id = ug.group_id
@@ -412,21 +412,23 @@ class acl
{
do
{
- switch ( $this->acl[$row['forum_id']][$row['auth_type']][$row['auth_option']] )
+ list($type, $option) = explode('_', $row['auth_value']);
+
+ switch ( $this->acl[$row['forum_id']][$type][$option] )
{
case ACL_PERMIT:
case ACL_DENY:
case ACL_PREVENT:
break;
default:
- $this->acl[$row['forum_id']][$row['auth_type']][$row['auth_option']] = $row['auth_allow_deny'];
+ $this->acl[$row['forum_id']][$type][$option] = $row['auth_allow_deny'];
}
}
while ( $row = $db->sql_fetchrow($result) );
}
$db->sql_freeresult($result);
- $sql = "SELECT a.forum_id, a.auth_allow_deny, ao.auth_type, ao.auth_option
+ $sql = "SELECT a.forum_id, a.auth_allow_deny, ao.auth_value
FROM " . ACL_USERS_TABLE . " a, " . ACL_OPTIONS_TABLE . " ao
WHERE a.user_id = " . $userdata['user_id'] . "
AND ao.auth_option_id = a.auth_option_id
@@ -437,13 +439,15 @@ class acl
{
do
{
- switch ( $this->acl[$row['forum_id']][$row['auth_type']][$row['auth_option']] )
+ list($type, $option) = explode('_', $row['auth_value']);
+
+ switch ( $this->acl[$row['forum_id']][$type][$option] )
{
case ACL_PERMIT:
case ACL_PREVENT:
break;
default:
- $this->acl[$row['forum_id']][$row['auth_type']][$row['auth_option']] = $row['auth_allow_deny'];
+ $this->acl[$row['forum_id']][$type][$option] = $row['auth_allow_deny'];
break;
}
}
diff --git a/phpBB/index.php b/phpBB/index.php
index ae0a133b88..398596253a 100644
--- a/phpBB/index.php
+++ b/phpBB/index.php
@@ -127,18 +127,16 @@ if ( ( $total_categories = count($category_rows) ) )
switch ( SQL_LAYER )
{
case 'oracle':
- $sql = "SELECT f.*, p.post_time, p.post_username, u.username, u.user_id
- FROM " . FORUMS_TABLE . " f, " . POSTS_TABLE . " p, " . USERS_TABLE . " u
- WHERE p.post_id = f.forum_last_post_id(+)
- AND u.user_id = p.poster_id(+)
+ $sql = "SELECT f.*, u.username, u.user_id
+ FROM " . FORUMS_TABLE . " f, " . USERS_TABLE . " u
+ WHERE u.user_id = p.poster_id(+)
ORDER BY f.cat_id, f.forum_order";
break;
default:
- $sql = "SELECT f.*, p.post_time, p.post_username, u.username, u.user_id
- FROM (( " . FORUMS_TABLE . " f
- LEFT JOIN " . POSTS_TABLE . " p ON p.post_id = f.forum_last_post_id )
- LEFT JOIN " . USERS_TABLE . " u ON u.user_id = p.poster_id )
+ $sql = "SELECT f.*, u.username, u.user_id
+ FROM ( " . FORUMS_TABLE . " f
+ LEFT JOIN " . USERS_TABLE . " u ON u.user_id = f.forum_last_poster_id )
ORDER BY f.cat_id, f.forum_order";
break;
}
@@ -184,8 +182,6 @@ if ( ( $total_categories = count($category_rows) ) )
'L_LEGEND' => $lang['Legend'],
'L_NO_FORUMS' => $lang['No_forums'],
- 'S_LEGEND' => $legend,
-
'U_MARK_READ' => "index.$phpEx$SID&mark=forums")
);
@@ -247,20 +243,12 @@ if ( ( $total_categories = count($category_rows) ) )
foreach ( $new_topic_data[$row_forum_id] as $check_topic_id => $check_post_time )
{
- if ( empty($tracking_topics[$check_topic_id]) )
+ if ( empty($tracking_topics[$check_topic_id]) || $tracking_topics[$check_topic_id] < $check_post_time)
{
$unread_topics = true;
$forum_last_post_time = max($check_post_time, $forum_last_post_time);
}
- else
- {
- if ( $tracking_topics[$check_topic_id] < $check_post_time )
- {
- $unread_topics = true;
- $forum_last_post_time = max($check_post_time, $forum_last_post_time);
- }
- }
}
if ( !empty($tracking_forums[$row_forum_id]) )
@@ -278,7 +266,6 @@ if ( ( $total_categories = count($category_rows) ) )
$unread_topics = false;
}
}
-
}
}
@@ -291,11 +278,11 @@ if ( ( $total_categories = count($category_rows) ) )
if ( $forum_data[$j]['forum_last_post_id'] )
{
- $last_post_time = create_date($board_config['default_dateformat'], $forum_data[$j]['post_time'], $board_config['board_timezone']);
+ $last_post_time = create_date($board_config['default_dateformat'], $forum_data[$j]['forum_last_post_time'], $board_config['board_timezone']);
$last_post = $last_post_time . '
';
- $last_post .= ( $forum_data[$j]['user_id'] == ANONYMOUS ) ? ( ($forum_data[$j]['post_username'] != '' ) ? $forum_data[$j]['post_username'] . ' ' : $lang['Guest'] . ' ' ) : '' . $forum_data[$j]['username'] . ' ';
+ $last_post .= ( $forum_data[$j]['user_id'] == ANONYMOUS ) ? ( ($forum_data[$j]['forum_last_poster_name'] != '' ) ? $forum_data[$j]['forum_last_poster_name'] . ' ' : $lang['Guest'] . ' ' ) : '' . $forum_data[$j]['username'] . ' ';
$last_post .= '' . create_img($theme['goto_post_latest'], $lang['View_latest_post']) . '';
}
diff --git a/phpBB/install/schemas/mysql_schema.sql b/phpBB/install/schemas/mysql_schema.sql
index 3e8bc7bb51..85d67b37d9 100644
--- a/phpBB/install/schemas/mysql_schema.sql
+++ b/phpBB/install/schemas/mysql_schema.sql
@@ -28,7 +28,9 @@ CREATE TABLE phpbb_auth_groups (
group_id mediumint(8) unsigned NOT NULL default '0',
forum_id mediumint(8) unsigned NOT NULL default '0',
auth_option_id smallint(5) unsigned NOT NULL default '0',
- auth_allow_deny tinyint(4) NOT NULL default '1'
+ auth_allow_deny tinyint(4) NOT NULL default '1',
+ KEY group_id (group_id),
+ KEY auth_option_id (auth_option_id)
);
@@ -37,9 +39,8 @@ CREATE TABLE phpbb_auth_groups (
#
CREATE TABLE phpbb_auth_options (
auth_option_id tinyint(4) NOT NULL auto_increment,
- auth_type char(15) NOT NULL default '',
- auth_option char(15) NOT NULL default '',
- PRIMARY KEY (auth_option_id,auth_option)
+ auth_value char(20) NOT NULL,
+ PRIMARY KEY (auth_value, auth_option_id)
);
@@ -52,6 +53,8 @@ CREATE TABLE phpbb_auth_prefetch (
forum_id mediumint(8) unsigned NOT NULL default '0',
auth_option_id smallint(5) unsigned NOT NULL default '0',
auth_allow_deny tinyint(4) NOT NULL default '1'
+ KEY user_id (user_id),
+ KEY auth_option_id (auth_option_id)
);
@@ -64,6 +67,8 @@ CREATE TABLE phpbb_auth_users (
forum_id mediumint(8) unsigned NOT NULL default '0',
auth_option_id smallint(5) unsigned NOT NULL default '0',
auth_allow_deny tinyint(4) NOT NULL default '1'
+ KEY user_id (user_id),
+ KEY auth_option_id (auth_option_id)
);
@@ -552,7 +557,11 @@ CREATE TABLE phpbb_topics (
topic_status tinyint(3) DEFAULT '0' NOT NULL,
topic_type tinyint(3) DEFAULT '0' NOT NULL,
topic_first_post_id mediumint(8) UNSIGNED DEFAULT '0' NOT NULL,
+ topic_first_poster_name varchar(30),
topic_last_post_id mediumint(8) UNSIGNED DEFAULT '0' NOT NULL,
+ topic_last_poster_id mediumint(8) UNSIGNED DEFAULT '0' NOT NULL,
+ topic_last_poster_name varchar(30),
+ topic_last_post_time int(11) DEFAULT '0' NOT NULL,
topic_moved_id mediumint(8) UNSIGNED DEFAULT '0' NOT NULL,
post_count_inc tinyint(1) DEFAULT '1' NOT NULL,
poll_title varchar(255) NOT NULL,
diff --git a/phpBB/install/update_script.php b/phpBB/install/update_script.php
index 3d62122dac..4ed33a249f 100644
--- a/phpBB/install/update_script.php
+++ b/phpBB/install/update_script.php
@@ -1,6 +1,6 @@
post checksums');
+
+ $sql_ary[] = "UPDATE " . $table_prefix . "posts_text
+ SET post_checksum = MD5(post_text)";
+
+ foreach ( $sql_ary as $sql )
+ {
+ $db->sql_query($sql);
+ }
+
+ gen_str_ok();
+ gen_str_init('* Updating forum post info');
+
+ switch ( SQL_LAYER )
+ {
+ case 'oracle':
+ $sql = "SELECT f.*, p.post_time, p.post_username, u.username, u.user_id
+ FROM " . $table_prefix . "forums f, " . $table_prefix . "posts p, " . $table_prefix . "users u
+ WHERE p.post_id = f.forum_last_post_id(+)
+ AND u.user_id = p.poster_id(+)";
+ break;
+
+ default:
+ $sql = "SELECT f.forum_id, p.post_time, p.post_username, u.username, u.user_id
+ FROM (( " . $table_prefix . "forums f
+ LEFT JOIN " . $table_prefix . "posts p ON p.post_id = f.forum_last_post_id )
+ LEFT JOIN " . $table_prefix . "users u ON u.user_id = p.poster_id )";
+ break;
+ }
+ $result = $db->sql_query($sql);
+
+ $sql_ary = array();
+ while ( $row = $db->sql_fetchrow($result) )
+ {
+ $forum_id = $row['forum_id'];
+
+ $sql_ary[] = "UPDATE " . $table_prefix . "forums
+ SET forum_last_poster_id = " . $row['user_id'] . ", forum_last_poster_name = '" . $row['post_username'] . "', forum_last_post_time = " . $row['post_time'] . "
+ WHERE forum_id = $forum_id";
+
+ $sql = "SELECT t.*, u.username, u.user_id, u2.username as user2, u2.user_id as id2, p.post_username, p2.post_username AS post_username2, p2.post_time
+ FROM " . $table_prefix . "topics t, " . $table_prefix . "users u, " . $table_prefix . "posts p, " . $table_prefix . "posts p2, " . $table_prefix . "users u2
+ WHERE t.forum_id = $forum_id
+ AND u.user_id = t.topic_poster
+ AND p.post_id = t.topic_first_post_id
+ AND p2.post_id = t.topic_last_post_id
+ AND u2.user_id = p2.poster_id";
+ $result2 = $db->sql_query($sql);
+
+ while ( $row2 = $db->sql_fetchrow($result2) )
+ {
+ $sql_ary[] = "UPDATE " . $table_prefix . "topics
+ SET topic_first_poster_name = '" . $row2['post_username'] . "', topic_last_poster_id = " . $row2['id2'] . ", topic_last_post_time = " . $row2['post_time'] . ", topic_last_poster_name = '" . $row2['post_username2'] . "'
+ WHERE topic_id = " . $row2['topic_id'];
+ }
+ $db->sql_freeresult($result2);
+
+ unset($row2);
+ }
+ $db->sql_freeresult($result);
+
+ foreach ( $sql_ary as $sql )
+ {
+ $db->sql_query($sql);
+ }
+
+ gen_str_ok();
+
break;
default;
print "* No updates needed
\n";
}
-
$sql = "UPDATE " . $table_prefix . "config
SET config_value = '$version'
WHERE config_name = 'version'";
diff --git a/phpBB/viewforum.php b/phpBB/viewforum.php
index 476d06ff71..5f02634a0f 100644
--- a/phpBB/viewforum.php
+++ b/phpBB/viewforum.php
@@ -83,7 +83,7 @@ if ( !($forum_data = $db->sql_fetchrow($result)) )
//
// Configure style, language, etc.
//
-$userdata['user_style'] = ( $forum_data['forum_style'] ) ? $forum_data['user_style'] : $userdata['user_style'];
+$userdata['user_style'] = ( $forum_data['forum_style'] ) ? $forum_data['forum_style'] : $userdata['user_style'];
$session->configure($userdata);
//
@@ -91,7 +91,7 @@ $session->configure($userdata);
//
if ( !$acl->get_acl($forum_id, 'forum', 'read') )
{
- if ( $userdata['user_id'] == ANONYMOUS )
+ if ( $userdata['user_id'] )
{
$redirect = "f=$forum_id" . ( ( isset($start) ) ? "&start=$start" : '' );
$header_location = ( @preg_match('/Microsoft|WebSTAR|Xitami/', getenv('SERVER_SOFTWARE')) ) ? 'Refresh: 0; URL=' : 'Location: ';
@@ -119,10 +119,10 @@ $tracking_forums = ( isset($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_f'
//
if ( $mark_read == 'topics' )
{
- if ( $userdata['user_id'] != ANONYMOUS )
+ if ( $userdata['user_id'] )
{
- $sql = "SELECT MAX(post_time) AS last_post
- FROM " . POSTS_TABLE . "
+ $sql = "SELECT MAX(topic_last_post_time) AS last_post
+ FROM " . TOPICS_TABLE . "
WHERE forum_id = $forum_id";
$result = $db->sql_query($sql);
@@ -183,6 +183,9 @@ $orig_word = array();
$replacement_word = array();
obtain_word_list($orig_word, $replacement_word);
+
+
+
//
// Topic ordering options
//
@@ -195,18 +198,20 @@ if ( isset($HTTP_POST_VARS['sort']) )
if ( !empty($HTTP_POST_VARS['sort_days']) )
{
$sort_days = ( !empty($HTTP_POST_VARS['sort_days']) ) ? intval($HTTP_POST_VARS['sort_days']) : intval($HTTP_GET_VARS['sort_days']);
- $min_topic_time = time() - ($sort_days * 86400);
+ $min_topic_time = time() - ( $sort_days * 86400 );
- $sql = "SELECT COUNT(t.topic_id) AS forum_topics
- FROM " . TOPICS_TABLE . " t, " . POSTS_TABLE . " p
- WHERE t.forum_id = $forum_id
- AND p.post_id = t.topic_last_post_id
- AND p.post_time >= $min_topic_time";
+ //
+ // ref type on as rows as topics ... also not great
+ //
+ $sql = "SELECT COUNT(topic_id) AS forum_topics
+ FROM " . TOPICS_TABLE . "
+ WHERE forum_id = $forum_id
+ AND topic_last_post_time >= $min_topic_time";
$result = $db->sql_query($sql);
$start = 0;
$topics_count = ( $row = $db->sql_fetchrow($result) ) ? $row['forum_topics'] : 0;
- $limit_topics_time = "AND p.post_time >= $min_topic_time";
+ $limit_topics_time = "AND t.topic_last_post_time >= $min_topic_time";
}
else
{
@@ -248,13 +253,15 @@ $select_sort_dir = '';
+
+
+
$post_alt = ( $forum_data['forum_status'] == FORUM_LOCKED ) ? $lang['Forum_locked'] : $lang['Post_new_topic'];
-$post_img = '
';
$template->assign_vars(array(
'FORUM_ID' => $forum_id,
'FORUM_NAME' => $forum_data['forum_name'],
- 'POST_IMG' => $post_img,
+ 'POST_IMG' => '
',
'PAGINATION' => generate_pagination("viewforum.$phpEx$SID&f=$forum_id&topicdays=$topic_days", $topics_count, $board_config['topics_per_page'], $start),
'PAGE_NUMBER' => sprintf($lang['Page_of'], ( floor( $start / $board_config['topics_per_page'] ) + 1 ), ceil( $topics_count / $board_config['topics_per_page'] )),
@@ -314,14 +321,13 @@ $topic_rowset = array();
if ( $start )
{
- $sql = "SELECT t.*, i.icons_url, i.icons_width, i.icons_height, u.username, u.user_id, u2.username as user2, u2.user_id as id2, p.post_time, p.post_username AS post_username2
- FROM " . TOPICS_TABLE . " t, " . ICONS_TABLE . " i, " . USERS_TABLE . " u, " . POSTS_TABLE . " p, " . USERS_TABLE . " u2
+ $sql = "SELECT t.*, i.icons_url, i.icons_width, i.icons_height, u.username, u.user_id, u2.username as user2, u2.user_id as id2
+ FROM " . TOPICS_TABLE . " t, " . ICONS_TABLE . " i, " . USERS_TABLE . " u, " . USERS_TABLE . " u2
WHERE t.forum_id = $forum_id
AND t.topic_type = " . POST_ANNOUNCE . "
AND i.icons_id = t.topic_icon
AND u.user_id = t.topic_poster
- AND p.post_id = t.topic_last_post_id
- AND u2.user_id = p.poster_id
+ AND u2.user_id = t.topic_last_poster_id
ORDER BY $sort_order
LIMIT " . $board_config['topics_per_page'];
$result = $db->sql_query($sql);
@@ -333,14 +339,15 @@ if ( $start )
}
}
-$sql = "SELECT t.*, i.icons_url, i.icons_width, i.icons_height, u.username, u.user_id, u2.username as user2, u2.user_id as id2, p.post_username, p2.post_username AS post_username2, p2.post_time
- FROM " . TOPICS_TABLE . " t, " . ICONS_TABLE . " i, " . USERS_TABLE . " u, " . POSTS_TABLE . " p, " . POSTS_TABLE . " p2, " . USERS_TABLE . " u2
+//
+// topic icon join requires full table scan ... not good
+//
+$sql = "SELECT t.*, i.icons_url, i.icons_width, i.icons_height, u.username, u.user_id, u2.username as user2, u2.user_id as id2
+ FROM " . TOPICS_TABLE . " t, " . ICONS_TABLE . " i, " . USERS_TABLE . " u, " . USERS_TABLE . " u2
WHERE t.forum_id = $forum_id
AND i.icons_id = t.topic_icon
AND u.user_id = t.topic_poster
- AND p.post_id = t.topic_first_post_id
- AND p2.post_id = t.topic_last_post_id
- AND u2.user_id = p2.poster_id
+ AND u2.user_id = t.topic_last_poster_id
$limit_topics_time
ORDER BY t.topic_type DESC, $sort_order
LIMIT $start, " . $board_config['topics_per_page'];
@@ -520,15 +527,15 @@ if ( $total_topics )
$view_topic_url = 'viewtopic.' . $phpEx . $SID . '&f=' . $forum_id . '&t=' . $topic_id;
$topic_author = ( $topic_rowset[$i]['user_id'] != ANONYMOUS ) ? '' : '';
- $topic_author .= ( $topic_rowset[$i]['user_id'] != ANONYMOUS ) ? $topic_rowset[$i]['username'] : ( ( $topic_rowset[$i]['post_username'] != '' ) ? $topic_rowset[$i]['post_username'] : $lang['Guest'] );
+ $topic_author .= ( $topic_rowset[$i]['user_id'] != ANONYMOUS ) ? $topic_rowset[$i]['username'] : ( ( $topic_rowset[$i]['topic_first_poster_name'] != '' ) ? $topic_rowset[$i]['topic_first_poster_name'] : $lang['Guest'] );
$topic_author .= ( $topic_rowset[$i]['user_id'] != ANONYMOUS ) ? '' : '';
$first_post_time = create_date($board_config['default_dateformat'], $topic_rowset[$i]['topic_time'], $board_config['board_timezone']);
- $last_post_time = create_date($board_config['default_dateformat'], $topic_rowset[$i]['post_time'], $board_config['board_timezone']);
+ $last_post_time = create_date($board_config['default_dateformat'], $topic_rowset[$i]['topic_last_post_time'], $board_config['board_timezone']);
- $last_post_author = ( $topic_rowset[$i]['id2'] == ANONYMOUS ) ? ( ( $topic_rowset[$i]['post_username2'] != '' ) ? $topic_rowset[$i]['post_username2'] . ' ' : $lang['Guest'] . ' ' ) : '' . $topic_rowset[$i]['user2'] . '';
+ $last_post_author = ( $topic_rowset[$i]['id2'] == ANONYMOUS ) ? ( ( $topic_rowset[$i]['topic_last_poster_name'] != '' ) ? $topic_rowset[$i]['topic_last_poster_name'] . ' ' : $lang['Guest'] . ' ' ) : '' . $topic_rowset[$i]['user2'] . '';
$last_post_url = '' . create_img($theme['goto_post_latest'], $lang['View_latest_post']) . '';
diff --git a/phpBB/viewtopic.php b/phpBB/viewtopic.php
index 8370bca138..ee7fd0413f 100644
--- a/phpBB/viewtopic.php
+++ b/phpBB/viewtopic.php
@@ -58,7 +58,7 @@ if ( isset($HTTP_GET_VARS['view']) && empty($post_id) )
WHERE s.session_id = '$session_id'
AND u.user_id = s.session_user_id
AND p.topic_id = $topic_id
- AND p.post_approved = " . TRUE . "
+ AND p.post_approved = 1
AND p.post_time >= u.user_lastvisit
ORDER BY p.post_time ASC
LIMIT 1";
@@ -75,7 +75,7 @@ if ( isset($HTTP_GET_VARS['view']) && empty($post_id) )
}
}
- header($header_location . 'viewtopic.' . $phpEx . $SID . '&t=' . $topic_id);
+ header($header_location . 'index.' . $phpEx);
exit;
}
else if ( $HTTP_GET_VARS['view'] == 'next' || $HTTP_GET_VARS['view'] == 'previous' )
@@ -84,15 +84,11 @@ if ( isset($HTTP_GET_VARS['view']) && empty($post_id) )
$sql_ordering = ( $HTTP_GET_VARS['view'] == 'next' ) ? 'ASC' : 'DESC';
$sql = "SELECT t.topic_id
- FROM " . TOPICS_TABLE . " t, " . TOPICS_TABLE . " t2, " . POSTS_TABLE . " p, " . POSTS_TABLE . " p2
+ FROM " . TOPICS_TABLE . " t, " . TOPICS_TABLE . " t2
WHERE t2.topic_id = $topic_id
- AND p2.post_id = t2.topic_last_post_id
AND t.forum_id = t2.forum_id
- AND p.post_id = t.topic_last_post_id
- AND p.post_approved = " . TRUE . "
- AND p.post_time $sql_condition p2.post_time
- AND p.topic_id = t.topic_id
- ORDER BY p.post_time $sql_ordering
+ AND t.topic_last_post_time $sql_condition t2.topic_last_post_time
+ ORDER BY t.topic_last_post_time $sql_ordering
LIMIT 1";
$result = $db->sql_query($sql);
@@ -272,8 +268,7 @@ for($i = 0; $i < count($previous_days); $i++)
$select_post_days .= '';
$sql = "SELECT *
- FROM " . RANKS_TABLE . "
- ORDER BY rank_special, rank_min";
+ FROM " . RANKS_TABLE;
$result = $db->sql_query($sql);
$ranksrow = array();
@@ -284,7 +279,7 @@ while ( $row = $db->sql_fetchrow($result) )
$db->sql_freeresult($result);
$rating = '';
-if ( $userdata['user_id'] != ANONYMOUS )
+if ( $userdata['user_id'] )
{
$rating_text = array(-5 => $lang['Very_poor'], -2 => $lang['Quite_poor'], 0 => $lang['Unrated'], 2 => $lang['Quite_good'], 5 => $lang['Very_good']);
@@ -616,12 +611,16 @@ $poster_details = array();
//
// Go ahead and pull all data for this topic
//
-$sql = "SELECT u.username, u.user_id, u.user_posts, u.user_from, u.user_website, u.user_email, u.user_icq, u.user_aim, u.user_yim, u.user_regdate, u.user_msnm, u.user_viewemail, u.user_rank, u.user_sig, u.user_sig_bbcode_uid, u.user_avatar, u.user_avatar_type, u.user_allowavatar, u.user_allowsmile, p.*, pt.post_text, pt.post_subject, pt.bbcode_uid
+// FROM phpbb_posts2 p, " . USERS_TABLE . " u
+// AND pt.post_id = p.post_id
+// pt.post_text, pt.post_subject, pt.bbcode_uid
+
+$sql = "SELECT u.username, u.user_id, u.user_posts, u.user_from, u.user_website, u.user_email, u.user_icq, u.user_aim, u.user_yim, u.user_regdate, u.user_msnm, u.user_viewemail, u.user_rank, u.user_sig, u.user_sig_bbcode_uid, u.user_avatar, u.user_avatar_type, u.user_allowavatar, u.user_allowsmile, p.*, pt.post_text, pt.post_subject, pt.bbcode_uid
FROM " . POSTS_TABLE . " p, " . USERS_TABLE . " u, " . POSTS_TEXT_TABLE . " pt
WHERE p.topic_id = $topic_id
AND p.post_approved = " . TRUE . "
- $limit_posts_time
AND pt.post_id = p.post_id
+ $limit_posts_time
AND u.user_id = p.poster_id
ORDER BY $sort_order
LIMIT $start, " . $board_config['posts_per_page'];