1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-05-04 22:58:10 +02:00

Cleaned up viewforum/index, altered template class to replace missing lang strings with a nicely formatted text, pre-implemented topics prefetching and broke some things.

git-svn-id: file:///svn/phpbb/trunk@3018 89ea8834-ac86-4346-8a33-228a782c2dd0
This commit is contained in:
Ludovic Arnaud 2002-11-08 03:33:58 +00:00
parent 5d859740ee
commit 097a1caca8
8 changed files with 72 additions and 120 deletions

View File

@ -125,6 +125,7 @@ define('STYLES_TPL_TABLE', $table_prefix.'styles_template');
define('STYLES_CSS_TABLE', $table_prefix.'styles_theme');
define('STYLES_IMAGE_TABLE', $table_prefix.'styles_imageset');
define('TOPICS_TABLE', $table_prefix.'topics');
define('TOPICS_PREFETCH_TABLE', $table_prefix.'topics_prefetch');
define('TOPICS_RATINGS_TABLE', $table_prefix.'topics_rating');
define('TOPICS_WATCH_TABLE', $table_prefix.'topics_watch');
define('USER_GROUP_TABLE', $table_prefix.'user_group');

View File

@ -94,7 +94,7 @@ function get_moderators(&$forum_moderators, $forum_id = false)
{
global $SID, $db, $acl_options, $phpEx;
if (is_array($forum_id))
if (is_array($forum_id) && !empty($forum_id))
{
$forum_sql = 'AND a.forum_id IN (' . implode(', ', $forum_id) . ')';
}

View File

@ -19,18 +19,19 @@
*
***************************************************************************/
function display_forums($root_data, $display_moderators=TRUE)
function display_forums($root_data=array(), $display_moderators=TRUE)
{
global $db, $template, $auth, $user, $phpEx, $SID;
global $total_posts;
$where_sql = ($root_data['left_id'] && $root_data['right_id']) ? ' WHERE left_id > ' . $root_data['left_id'] . ' AND left_id < ' . $root_data['right_id'] : '';
$where_sql = ($root_data['forum_id']) ? ' WHERE left_id > ' . $root_data['left_id'] . ' AND left_id < ' . $root_data['right_id'] : '';
$sql = 'SELECT * FROM ' . FORUMS_TABLE . $where_sql . ' ORDER BY left_id ASC';
$sql = 'SELECT * FROM ' . FORUMS_TABLE . $where_sql . ' ORDER BY left_id';
$result = $db->sql_query($sql);
$branch_root_id = $total_posts = 0;
$forum_rows = $subforums = $alist = $forum_ids = $forum_moderators = array();
$total_posts = 0;
$branch_root_id = $root_data['forum_id'];
$forum_rows = $subforums = $forum_ids = $forum_moderators = array();
while ($row = $db->sql_fetchrow($result))
{
@ -91,15 +92,9 @@ function display_forums($root_data, $display_moderators=TRUE)
if ($row['display_on_index'])
{
// Subforum
$subforums[$parent_id][] = $row;
$subforums[$parent_id][$row['forum_id']] = $row['forum_name'];
}
}
else
{
// what the heck is happening here??
// echo '<pre>';print_r($row);echo'</pre>';
}
}
$db->sql_freeresult();
@ -172,16 +167,17 @@ function display_forums($root_data, $display_moderators=TRUE)
if (isset($subforums[$forum_id]))
{
foreach ($subforums[$forum_id] as $subrow)
$alist = array();
foreach ($subforums[$forum_id] as $forum_id => $forum_name)
{
$alist[$subrow['forum_id']] = $subrow['forum_name'];
$alist[$forum_id] = $forum_name;
}
asort($alist);
natsort($alist);
$links = array();
foreach ($alist as $subforum_id => $subforum_name)
{
$links[] = '<a href="viewforum.' . $phpEx . $SID . '&amp;f=' . $subforum_id . '">' . htmlspecialchars($subforum_name) . '</a>';
$links[] = '<a href="viewforum.' . $phpEx . $SID . '&amp;f=' . $subforum_id . '">' . $subforum_name . '</a>';
}
$subforums_list = implode(', ', $links);
@ -229,19 +225,5 @@ function display_forums($root_data, $display_moderators=TRUE)
'U_VIEWFORUM' => 'viewforum.' . $phpEx . $SID . '&amp;f=' . $row['forum_id']
));
}
$template->assign_vars(array(
'L_FORUM' => $user->lang['Forum'],
'L_TOPICS' => $user->lang['Topics'],
'L_REPLIES' => $user->lang['Replies'],
'L_VIEWS' => $user->lang['Views'],
'L_POSTS' => $user->lang['Posts'],
'L_LASTPOST' => $user->lang['Last_Post'],
'L_MODERATORS' => $user->lang['Moderators'],
'L_NO_NEW_POSTS' => $user->lang['No_new_posts'],
'L_NEW_POSTS' => $user->lang['New_posts'],
'L_NO_NEW_POSTS_LOCKED' => $user->lang['No_new_posts_locked'],
'L_NEW_POSTS_LOCKED' => $user->lang['New_posts_locked']
));
}
?>

View File

@ -409,7 +409,7 @@ class Template {
}
// This will handle the remaining root-level varrefs
$text_blocks = preg_replace('#\{L_([a-z0-9\-_]*?)\}#is', '\' . ((isset($this->_tpldata[\'.\'][0][\'L_\1\'])) ? $this->_tpldata[\'.\'][0][\'L_\1\'] : ((isset($user->lang[\'\1\'])) ? $user->lang[\'\1\'] : \'\')) . \'', $text_blocks);
$text_blocks = preg_replace('#\{L_([a-z0-9\-_]*?)\}#is', '\' . ((isset($this->_tpldata[\'.\'][0][\'L_\1\'])) ? $this->_tpldata[\'.\'][0][\'L_\1\'] : ((isset($user->lang[\'\1\'])) ? $user->lang[\'\1\'] : \'{ \' . ucfirst(strtolower(str_replace(\'_\', \' \', \'\1\'))) . \' }\')) . \'', $text_blocks);
$text_blocks = preg_replace('#\{([a-z0-9\-_]*?)\}#is', '\' . ((isset($this->_tpldata[\'.\'][0][\'\1\'])) ? $this->_tpldata[\'.\'][0][\'\1\'] : \'\') . \'', $text_blocks);
return;

View File

@ -81,45 +81,8 @@ else
$l_total_user_s = $user->lang['Registered_users_total'];
}
// Forum moderators ... a static template var could allow us
// to drop these queries ...
//$forum_moderators = array();
//get_moderators($forum_moderators);
// Set some vars
$root_id = $branch_root_id = $cat_id;
$forum_rows = $subforums = $nav_forums = array();
if ($cat_id == 0)
{
$is_nav = FALSE;
$total_posts = 0;
switch (SQL_LAYER)
{
case 'oracle':
$sql = 'SELECT f.*, u.username
FROM ' . FORUMS_TABLE . ' f, ' . USERS_TABLE . 'u
WHERE f.forum_last_poster_id = u.user_id(+)
ORDER BY f.left_id';
break;
default:
$sql = 'SELECT f.*, u.username
FROM ' . FORUMS_TABLE . ' f
LEFT JOIN ' . USERS_TABLE . ' u ON f.forum_last_poster_id = u.user_id
ORDER BY f.left_id';
}
$sql = 'SELECT * FROM ' . FORUMS_TABLE . ' ORDER BY left_id';
}
include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
display_forums(array(
'forum_id' => 0,
'left_id' => 0,
'right_id' => 0
));
display_forums(array('forum_id' => 0));
if ($total_posts == 0)
{
@ -154,23 +117,6 @@ $template->assign_vars(array(
'U_MARK_READ' => "index.$phpEx$SID&amp;mark=forums")
);
foreach ($nav_forums as $row)
{
if ($row['forum_status'] == ITEM_CATEGORY)
{
$link = 'index.' . $phpEx . $SID . '&amp;c=' . $row['forum_id'];
}
else
{
$link = 'viewforum.' . $phpEx . $SID . '&amp;f=' . $row['forum_id'];
}
$template->assign_block_vars('navlinks', array(
'FORUM_NAME' => $row['forum_name'],
'U_VIEW_FORUM' => $link
));
}
// Start output of page
$page_title = $user->lang['Index'];
include($phpbb_root_path . 'includes/page_header.'.$phpEx);

View File

@ -139,7 +139,7 @@ $lang = array_merge($lang, array(
'Last_Post' => 'Last Post',
'Moderator' => 'Moderator',
'Moderators' => 'Moderators',
'View_moderators' => 'List forum moderators',
'VIEW_MODERATORS' => 'List forum moderators',
'Login_check_pm' => 'Login to check your private messages',
'New_pms' => '<b>%d</b> new messages',
'New_pm' => '<b>%d</b> new message',

View File

@ -5,9 +5,6 @@
<td width="100%" align="left" valign="bottom"><table width="100%" cellspacing="0" cellpadding="0" border="0">
<tr>
<td align="left" valign="bottom"><p><span class="gensmall">{TOTAL_POSTS}<br />{TOTAL_USERS}<br />{NEWEST_USER}</span></p><span class="nav"><a href="{U_INDEX}" class="nav">{L_INDEX}</a>
<!-- BEGIN navlinks -->
-> <a class="nav" href="{navlinks.U_VIEW_FORUM}">{navlinks.FORUM_NAME}</a>
<!-- END navlinks -->
</span></td>
<td align="right" class="gensmall" valign="bottom"><!-- IF S_USER_LOGGED_IN --><a href="{U_SEARCH_NEW}" class="gensmall">{L_SEARCH_NEW}</a><br /><a href="{U_SEARCH_SELF}" class="gensmall">{L_SEARCH_SELF}</a><br /><!-- ENDIF --><a href="{U_SEARCH_UNANSWERED}" class="gensmall">{L_SEARCH_UNANSWERED}</a><br /><br /><!-- IF S_USER_LOGGED_IN -->{LAST_VISIT_DATE}<br /><!-- ENDIF -->{CURRENT_TIME}</td>
</tr>
@ -26,7 +23,7 @@
<!-- BEGIN forumrow -->
<!-- IF forumrow.S_IS_CAT -->
<tr>
<td class="catLeft" colspan="3" height="28"><span class="cattitle"><a href="{forumrow.U_VIEWCAT}" class="cattitle">{forumrow.CAT_NAME}</a></span></td>
<td class="catLeft" colspan="3" height="28"><span class="cattitle"><a href="{forumrow.U_VIEWFORUM}" class="cattitle">{forumrow.FORUM_NAME}</a></span></td>
<td class="rowpic" colspan="4" align="right">&nbsp;</td>
</tr>
<!-- ELSE -->

View File

@ -28,6 +28,8 @@ include($phpbb_root_path . 'common.'.$phpEx);
$mark_read = (!empty($_REQUEST['mark'])) ? $_REQUEST['mark'] : '';
$forum_id = (!empty($_REQUEST['f'])) ? intval($_REQUEST['f']) : 0;
$start = (isset($_GET['start'])) ? intval($_GET['start']) : 0;
$sort_key = (!empty($_REQUEST['sort_key'])) ? $_REQUEST['sort_key']{0} : 't';
$sort_dir = (!empty($_REQUEST['sort_dir'])) ? $_REQUEST['sort_dir']{0} : 'd';
// End initial var setup
// Start session
@ -53,6 +55,14 @@ else
break;
default:
/*
$sql = 'SELECT f.*, tw.topics_list, fw.notify_status
FROM ' . FORUMS_TABLE . ' f
LEFT JOIN ' . TOPICS_PREFETCH_TABLE . " tw ON tw.start = $start AND tw.forum_id = f.forum_id
LEFT JOIN " . FORUMS_WATCH_TABLE . ' fw ON fw.user_id = ' . $user->data['user_id'] . ' AND f.forum_id = fw.forum_id
WHERE f.forum_id = ' . $forum_id;
*/
$sql = 'SELECT f.*, fw.notify_status
FROM ' . FORUMS_TABLE . ' f
LEFT JOIN ' . FORUMS_WATCH_TABLE . ' fw ON fw.user_id = ' . $user->data['user_id'] . ' AND f.forum_id = fw.forum_id
@ -206,18 +216,11 @@ if ($forum_data['forum_postable'])
{
$topics_count = ($forum_data['forum_topics']) ? $forum_data['forum_topics'] : 1;
}
$sort_key = (isset($_POST['sort_key'])) ? $_POST['sort_key'] : $_GET['sort_key'];
$sort_dir = (isset($_POST['sort_dir'])) ? $_POST['sort_dir'] : $_GET['sort_dir'];
}
else
{
$topics_count = ($forum_data['forum_topics']) ? $forum_data['forum_topics'] : 1;
$limit_topics_time = '';
$sort_days = 0;
$sort_key = 't';
$sort_dir = 'd';
}
$sort_order = $sort_by[$sort_key] . ' ' . (($sort_dir == 'd') ? 'DESC' : 'ASC');
@ -269,7 +272,6 @@ if ($forum_data['forum_postable'])
'L_POSTS' => $user->lang['Posts'],
'L_LASTPOST' => $user->lang['Last_Post'],
'L_RATING' => $user->lang['Rating'],
'L_VIEW_MODERATORS' => $user->lang['View_moderators'],
'L_DISPLAY_TOPICS' => $user->lang['Display_topics'],
'L_SORT_BY' => $user->lang['Sort_by'],
'L_MARK_TOPICS_READ' => $user->lang['Mark_all_topics'],
@ -306,23 +308,20 @@ if ($forum_data['forum_postable'])
$result = $db->sql_query($sql);
$topic_icons = array();
if ($row = $db->sql_fetchrow($result))
while ($row = $db->sql_fetchrow($result))
{
do
{
$topic_icons[$row['icons_id']]['img'] = $row['icons_url'];
$topic_icons[$row['icons_id']]['width'] = $row['icons_width'];
$topic_icons[$row['icons_id']]['height'] = $row['icons_height'];
}
while ($row = $db->sql_fetchrow($result));
$topic_icons[$row['icons_id']]['img'] = $row['icons_url'];
$topic_icons[$row['icons_id']]['width'] = $row['icons_width'];
$topic_icons[$row['icons_id']]['height'] = $row['icons_height'];
}
// Grab all the basic data. If we're not on page 1 we also grab any
// announcements that may exist.
$total_topics = 0;
$topics_list = '';
$topic_rowset = array();
if ( $start )
if (empty($forum_data['topics_list']))
{
$sql = "SELECT t.*, u.username, u.user_id, u2.username as user2, u2.user_id as id2
FROM " . TOPICS_TABLE . " t, " . USERS_TABLE . " u, " . USERS_TABLE . " u2
@ -336,30 +335,57 @@ if ($forum_data['forum_postable'])
while( $row = $db->sql_fetchrow($result) )
{
$topics_list .= '.' . str_pad(base_convert($row['topic_id'], 10, 36), 5, '0', STR_PAD_LEFT);
$topic_rowset[] = $row;
$total_topics++;
}
$db->sql_freeresult($result);
$sql = "SELECT t.*, u.username, u.user_id, u2.username as user2, u2.user_id as id2
FROM " . TOPICS_TABLE . " t, " . USERS_TABLE . " u, " . USERS_TABLE . " u2
WHERE t.forum_id = $forum_id
AND t.topic_approved = 1
AND u.user_id = t.topic_poster
AND u2.user_id = t.topic_last_poster_id
$limit_topics_time
ORDER BY t.topic_type DESC, $sort_order
LIMIT $start, " . $config['topics_per_page'];
}
else
{
/*
$topic_ids = array();
preg_match_all('/.{5,5}/', $forum_data['topics_list'], $m);
foreach ($m[0] as $topic_id)
{
$topic_ids[] = base_convert($topic_id, 36, 10);
}
$sql = "SELECT t.*, u.username, u.user_id, u2.username as user2, u2.user_id as id2
FROM " . TOPICS_TABLE . " t, " . USERS_TABLE . " u, " . USERS_TABLE . " u2
WHERE t.topic_id IN (" . implode(', ', $topic_ids) . ")
AND u.user_id = t.topic_poster
AND u2.user_id = t.topic_last_poster_id
ORDER BY $sort_order";
*/
}
$sql = "SELECT t.*, u.username, u.user_id, u2.username as user2, u2.user_id as id2
FROM " . TOPICS_TABLE . " t, " . USERS_TABLE . " u, " . USERS_TABLE . " u2
WHERE t.forum_id = $forum_id
AND t.topic_approved = 1
AND u.user_id = t.topic_poster
AND u2.user_id = t.topic_last_poster_id
$limit_topics_time
ORDER BY t.topic_type DESC, $sort_order
LIMIT $start, " . $config['topics_per_page'];
$result = $db->sql_query($sql);
while( $row = $db->sql_fetchrow($result) )
{
$topics_list .= str_pad(base_convert($row['topic_id'], 10, 36), 5, '0', STR_PAD_LEFT);
$topic_rowset[] = $row;
$total_topics++;
}
$db->sql_freeresult($result);
if (empty($forum_data['topics_list']) && !empty($topics_list))
{
$sql = 'INSERT INTO ' . TOPICS_PREFETCH_TABLE . " (forum_id, start, sort_key, sort_dir, topics_list)
VALUES ($forum_id, $start, '$sort_key', '$sort_dir', '$topics_list')";
// $db->sql_query($sql);
}
// Okay, lets dump out the page ...
if ($total_topics)
{
@ -525,7 +551,7 @@ if ($forum_data['left_id'] != $forum_data['right_id'] - 1)
));
include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
display_forums($forum_data);
display_forums($forum_data, FALSE);
}
include($phpbb_root_path . 'includes/page_header.'.$phpEx);