From 0b609899e3be85e70d925c60f72aff090b5bd5d1 Mon Sep 17 00:00:00 2001 From: "Paul S. Owen" Date: Sat, 2 Feb 2002 18:04:21 +0000 Subject: Introduce an additional DB field for first_topic_id ... RUN update_to_RC3 ONCE YOU'VE UPDATED git-svn-id: file:///svn/phpbb/trunk@2036 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/posting.php | 32 ++++++--- phpBB/update_to_RC3.php | 110 ++++++++++++++++++++++++++++++ phpBB/viewforum.php | 175 +++++++++++++++++++++++------------------------- 3 files changed, 216 insertions(+), 101 deletions(-) create mode 100644 phpBB/update_to_RC3.php (limited to 'phpBB') diff --git a/phpBB/posting.php b/phpBB/posting.php index 282902b1c7..d6a2776f68 100644 --- a/phpBB/posting.php +++ b/phpBB/posting.php @@ -418,15 +418,11 @@ if( $mode != "newtopic" ) { if( $post_id ) { - $sql = "SELECT p2.post_id, t.topic_id, t.topic_status, t.topic_last_post_id, t.topic_vote, f.forum_id, f.forum_name, f.forum_status, f.forum_last_post_id - FROM " . POSTS_TABLE . " p, " . POSTS_TABLE . " p2, " . TOPICS_TABLE . " t, " . FORUMS_TABLE . " f + $sql = "SELECT t.topic_id, t.topic_status, t.topic_first_post_id, t.topic_last_post_id, t.topic_vote, f.forum_id, f.forum_name, f.forum_status, f.forum_last_post_id + FROM " . POSTS_TABLE . " p, " . TOPICS_TABLE . " t, " . FORUMS_TABLE . " f WHERE p.post_id = $post_id - AND p2.topic_id = p.topic_id AND t.topic_id = p.topic_id - AND f.forum_id = t.forum_id - ORDER BY p2.post_time ASC - LIMIT 1"; - + AND f.forum_id = t.forum_id"; } else { @@ -452,7 +448,7 @@ if( $mode != "newtopic" ) { $topic_id = $check_row['topic_id']; - $is_first_post_topic = ($check_row['post_id'] == $post_id) ? TRUE : 0; + $is_first_post_topic = ($check_row['topic_first_post_id'] == $post_id) ? TRUE : 0; $is_last_post_topic = ($check_row['topic_last_post_id'] == $post_id) ? TRUE : 0; $is_last_post_forum = ($check_row['forum_last_post_id'] == $post_id) ? TRUE : 0; @@ -931,8 +927,9 @@ if( ( $submit || $confirm || $mode == "delete" ) && !$error ) if( $db->sql_query($sql) ) { + $first_post_sql = ( $mode == "newtopic" ) ?", topic_first_post_id = $new_post_id" : ""; $sql = "UPDATE " . TOPICS_TABLE . " - SET topic_last_post_id = $new_post_id"; + SET topic_last_post_id = $new_post_id" . $first_post_sql; if($mode == "reply") { $sql .= ", topic_replies = topic_replies + 1 "; @@ -1436,8 +1433,23 @@ if( ( $submit || $confirm || $mode == "delete" ) && !$error ) // the middle(!) Only moderators can delete these posts, all we need do // is update the forums table data as necessary // + $first_post_sql = ""; + if( $is_first_post_topic ) + { + $sql = "SELECT MIN(post_id) AS first_post + FROM " . POSTS_TABLE . " + WHERE topic_id = $topic_id"; + if($result = $db->sql_query($sql)) + { + if( $row = $db->sql_fetchrow($result) ) + { + $first_post_sql = ", topic_first_post_id = " . $row['first_post']; + } + } + } + $sql = "UPDATE " . TOPICS_TABLE . " - SET topic_replies = topic_replies - 1 + SET topic_replies = topic_replies - 1" . $first_post_sql . " WHERE topic_id = $topic_id"; $sql_forum_upd = "forum_posts = forum_posts - 1"; diff --git a/phpBB/update_to_RC3.php b/phpBB/update_to_RC3.php new file mode 100644 index 0000000000..e0759b61a5 --- /dev/null +++ b/phpBB/update_to_RC3.php @@ -0,0 +1,110 @@ + + +>> " . $sql[$i]; + + $result = $db->sql_query($sql[$i]); + + if( !$result ) + { + $errored = true; + $error = $db->sql_error(); + echo " :: FAILED ( " . $error['message'] . " )

\n\n"; + } + else + { + echo " :: COMPLETED

\n\n"; + } + } + + if( $errored ) + { + echo "\n

Errors occured! Please check and correct issues as required
\n"; + } + else + { + + $sql = "SELECT post_id, topic_id + FROM " . POSTS_TABLE . " + GROUP BY topic_id ASC + ORDER BY post_id ASC"; + if( !($result = $db->sql_query($sql)) ) + { + die("Couldn't obtain first post id list"); + } + + if( $row = $db->sql_fetchrow($result) ) + { + do + { + $post_id = $row['post_id']; + $topic_id = $row['topic_id']; + + $sql = "UPDATE " . TOPICS_TABLE . " + SET topic_first_post_id = $post_id + WHERE topic_id = $topic_id"; + if( !$db->sql_query($sql) ) + { + die("Couldn't update topic first post id in topic :: $topic_id"); + } + } + while ( $row = $db->sql_fetchrow($result) ); + } + + echo "\n

\nCOMPLETE! Please delete this file before continuing!
\n"; + } + + +?> + + \ No newline at end of file diff --git a/phpBB/viewforum.php b/phpBB/viewforum.php index 2f85c86054..2f15e0f487 100644 --- a/phpBB/viewforum.php +++ b/phpBB/viewforum.php @@ -274,43 +274,62 @@ for($i = 0; $i < count($previous_days); $i++) } $select_topic_days .= ""; + // -// Grab all the basic data (all topics except announcements) -// for this forum +// All announcement data, this keeps announcements +// on each viewforum page ... // $sql = "SELECT t.*, u.username, u.user_id, u2.username as user2, u2.user_id as id2, p.post_time, p.post_username FROM " . TOPICS_TABLE . " t, " . USERS_TABLE . " u, " . POSTS_TABLE . " p, " . USERS_TABLE . " u2 - WHERE t.forum_id = $forum_id + WHERE t.forum_id IN ($forum_id, -1) AND t.topic_poster = u.user_id AND p.post_id = t.topic_last_post_id AND p.poster_id = u2.user_id - AND t.topic_type <> " . POST_ANNOUNCE . " - $limit_topics_time - ORDER BY t.topic_type DESC, t.topic_last_post_id DESC - LIMIT $start, ".$board_config['topics_per_page']; -if( !$t_result = $db->sql_query($sql) ) + AND t.topic_type = " . POST_ANNOUNCE . " + ORDER BY t.topic_last_post_id DESC "; +if( !$result = $db->sql_query($sql) ) { message_die(GENERAL_ERROR, "Couldn't obtain topic information", "", __LINE__, __FILE__, $sql); } -$total_topics = $db->sql_numrows($t_result); + +$topic_rowset = array(); +$total_announcements = 0; +while( $row = $db->sql_fetchrow($result) ) +{ + $topic_rowset[] = $row; + $total_announcements++; +} + +$db->sql_freeresult($result); // -// All announcement data, this keeps announcements -// on each viewforum page ... +// Grab all the basic data (all topics except announcements) +// for this forum // -$sql = "SELECT t.*, u.username, u.user_id, u2.username as user2, u2.user_id as id2, p.post_time, p.post_username - FROM " . TOPICS_TABLE . " t, " . USERS_TABLE . " u, " . POSTS_TABLE . " p, " . USERS_TABLE . " u2 - WHERE t.forum_id IN ($forum_id, -1) +$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 " . TOPICS_TABLE . " t, " . USERS_TABLE . " u, " . POSTS_TABLE . " p, " . POSTS_TABLE . " p2, " . USERS_TABLE . " u2 + WHERE t.forum_id = $forum_id AND t.topic_poster = u.user_id - AND p.post_id = t.topic_last_post_id - AND p.poster_id = u2.user_id - AND t.topic_type = " . POST_ANNOUNCE . " - ORDER BY t.topic_last_post_id DESC "; -if( !$ta_result = $db->sql_query($sql) ) + 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 t.topic_type <> " . POST_ANNOUNCE . " + $limit_topics_time + ORDER BY t.topic_type DESC, t.topic_last_post_id DESC + LIMIT $start, ".$board_config['topics_per_page']; +if( !$result = $db->sql_query($sql) ) { message_die(GENERAL_ERROR, "Couldn't obtain topic information", "", __LINE__, __FILE__, $sql); } -$total_announcements = $db->sql_numrows($ta_result); + +$total_topics = 0; +while( $row = $db->sql_fetchrow($result) ) +{ + $topic_rowset[] = $row; + $total_topics++; +} + +$db->sql_freeresult($result); // // Total topics ... @@ -349,10 +368,20 @@ if( $is_auth['auth_mod'] ) { $s_auth_can .= sprintf($lang['Rules_moderate'], "", ""); } -else -{ - $s_auth_mod_img = ""; -} + +// +// Mozilla navigation bar +// +$nav_links['up'] = array( + 'url' => append_sid("index.".$phpEx), + 'title' => sprintf($lang['Forum_Index'], $board_config['sitename']) +); + +// +// Dump out the page header and load viewforum template +// +$page_title = $lang['View_forum'] . " - " . $forum_row['forum_name']; +include($phpbb_root_path . 'includes/page_header.'.$phpEx); $template->set_filenames(array( "body" => "viewforum_body.tpl", @@ -391,6 +420,8 @@ $template->assign_vars(array( "L_MARK_TOPICS_READ" => $lang['Mark_all_topics'], "L_POST_NEW_TOPIC" => ( $forum_row['forum_status'] == FORUM_LOCKED ) ? $lang['Forum_locked'] : $lang['Post_new_topic'], + "S_AUTH_LIST" => $s_auth_can, + "U_MARK_READ" => append_sid("viewforum.$phpEx?" . POST_FORUM_URL . "=$forum_id&mark=topics")) ); // @@ -402,31 +433,9 @@ $template->assign_vars(array( // if( $total_topics ) { - // - // First get announcements - // - while( $ta_row = $db->sql_fetchrow($ta_result) ) - { - $topic_rowset[] = $ta_row; - } - // - // Now get everything else - // - while( $t_row = $db->sql_fetchrow($t_result) ) - { - $topic_rowset[] = $t_row; - } - for($i = 0; $i < $total_topics; $i++) { - if( count($orig_word) ) - { - $topic_title = preg_replace($orig_word, $replacement_word, $topic_rowset[$i]['topic_title']); - } - else - { - $topic_title = $topic_rowset[$i]['topic_title']; - } + $topic_title = ( count($orig_word) ) ? preg_replace($orig_word, $replacement_word, $topic_rowset[$i]['topic_title']) : $topic_rowset[$i]['topic_title']; $topic_type = $topic_rowset[$i]['topic_type']; @@ -455,29 +464,29 @@ if( $total_topics ) if( ( $replies + 1 ) > $board_config['posts_per_page'] ) { $total_pages = ceil(($replies+1)/$board_config['posts_per_page']); - $goto_page = " [ \""" . $lang['Goto_page'] . ": "; + $goto_page = ' [ ' . $lang['Goto_page'] . '' . $lang['Goto_page'] . ': '; $times = 1; for($j = 0; $j < $replies + 1; $j += $board_config['posts_per_page']) { - $goto_page .= "$times"; - if( $times == 1 && $total_pages > 4) + $goto_page .= '' . $times . ''; + if( $times == 1 && $total_pages > 4 ) { - $goto_page .= " ... "; + $goto_page .= ' ... '; $times = $total_pages - 3; - $j += ($total_pages-4) * $board_config['posts_per_page']; + $j += ( $total_pages - 4 ) * $board_config['posts_per_page']; } - else if ($times < $total_pages) + else if ( $times < $total_pages ) { - $goto_page .= ", "; + $goto_page .= ', '; } $times++; } - $goto_page .= " ] "; + $goto_page .= ' ] '; } else { - $goto_page = ""; + $goto_page = ''; } if( $topic_rowset[$i]['topic_status'] == TOPIC_MOVED ) @@ -485,8 +494,8 @@ if( $total_topics ) $topic_type = $lang['Topic_Moved'] . " "; $topic_id = $topic_rowset[$i]['topic_moved_id']; - $folder_image = "\"""; - $newest_post_img = ""; + $folder_image = '' . $lang['No_new_posts'] . ''; + $newest_post_img = ''; } else { @@ -554,51 +563,51 @@ if( $total_topics ) if( $unread_topics ) { - $folder_image = "\"""; + $folder_image = '' . $lang['New_posts'] . ''; - $newest_post_img = "\"" "; + $newest_post_img = '' . $lang['View_newest_post'] . ' '; } else { $folder_alt = ( $topic_rowset[$i]['topic_status'] == TOPIC_LOCKED ) ? $lang['Topic_locked'] : $lang['No_new_posts']; - $folder_image = "\"$folder_alt\""; - $newest_post_img = ""; + $folder_image = '' . $folder_alt . ''; + $newest_post_img = ''; } } else { - $folder_image = "\"""; + $folder_image = '' . $lang['New_posts'] . ''; - $newest_post_img = "\"" "; + $newest_post_img = '' . $lang['View_newest_post'] . ' '; } } else { $folder_alt = ( $topic_rowset[$i]['topic_status'] == TOPIC_LOCKED ) ? $lang['Topic_locked'] : $lang['No_new_posts']; - $folder_image = "\"$folder_alt\""; - $newest_post_img = ""; + $folder_image = '' . $folder_alt . ''; + $newest_post_img = ''; } } else { $folder_alt = ( $topic_rowset[$i]['topic_status'] == TOPIC_LOCKED ) ? $lang['Topic_locked'] : $lang['No_new_posts']; - $folder_image = "\"$folder_alt\""; - $newest_post_img = ""; + $folder_image = '' . $folder_alt . ''; + $newest_post_img = ''; } } $view_topic_url = append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id"); - $topic_poster = ( $topic_rowset[$i]['user_id'] != ANONYMOUS ) ? "" : ""; + $topic_poster = ( $topic_rowset[$i]['user_id'] != ANONYMOUS ) ? '' : ''; $topic_poster .= ( $topic_rowset[$i]['user_id'] != ANONYMOUS ) ? $topic_rowset[$i]['username'] : ( ( $topic_rowset[$i]['post_username'] != "" ) ? $topic_rowset[$i]['post_username'] : $lang['Guest'] ); - $topic_poster .= ( $topic_rowset[$i]['user_id'] != ANONYMOUS ) ? "" : ""; + $topic_poster .= ( $topic_rowset[$i]['user_id'] != ANONYMOUS ) ? '' : ''; $last_post_time = create_date($board_config['default_dateformat'], $topic_rowset[$i]['post_time'], $board_config['board_timezone']); - $last_post = $last_post_time . "
"; - $last_post .= ( $topic_rowset[$i]['id2'] == ANONYMOUS ) ? ( ($topic_rowset[$i]['post_username'] != "" ) ? $topic_rowset[$i]['post_username'] . " " : $lang['Guest'] . " " ) : "" . $topic_rowset[$i]['user2'] . " "; - $last_post .= "\"""; + $last_post = $last_post_time . '
'; + $last_post .= ( $topic_rowset[$i]['id2'] == ANONYMOUS ) ? ( ($topic_rowset[$i]['post_username'] != "" ) ? $topic_rowset[$i]['post_username2'] . ' ' : $lang['Guest'] . ' ' ) : '' . $topic_rowset[$i]['user2'] . ' '; + $last_post .= '' . $lang['View_latest_post'] . ''; $views = $topic_rowset[$i]['topic_views']; @@ -628,9 +637,7 @@ if( $total_topics ) "PAGINATION" => generate_pagination("viewforum.$phpEx?" . POST_FORUM_URL . "=$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'] )), - "L_GOTO_PAGE" => $lang['Goto_page'], - - "S_NO_TOPICS" => FALSE) + "L_GOTO_PAGE" => $lang['Goto_page']) ); } @@ -648,20 +655,6 @@ else } -// -// Mozilla navigation bar -// -$nav_links['up'] = array( - 'url' => append_sid("index.".$phpEx), - 'title' => sprintf($lang['Forum_Index'], $board_config['sitename']) -); - -// -// Dump out the page header and load viewforum template -// -$page_title = $lang['View_forum'] . " - " . $forum_row['forum_name']; -include($phpbb_root_path . 'includes/page_header.'.$phpEx); - // // Parse the page and print // @@ -672,4 +665,4 @@ $template->pparse("body"); // include($phpbb_root_path . 'includes/page_tail.'.$phpEx); -?> +?> \ No newline at end of file -- cgit v1.2.1