Subforums part 3: "the one that actually works"

git-svn-id: file:///svn/phpbb/trunk@2916 89ea8834-ac86-4346-8a33-228a782c2dd0
This commit is contained in:
Ludovic Arnaud 2002-10-03 19:44:58 +00:00
parent 4c82531712
commit 743460bd80
3 changed files with 64 additions and 32 deletions

View file

@ -96,10 +96,11 @@ get_moderators($forum_moderators);
$cat_id = (!empty($_GET['c'])) ? intval($_GET['c']) : 0;
$root_id = $branch_root_id = $cat_id;
$forum_rows = $subforums = array();
$forum_rows = $subforums = $parent_forums = array();
if ($cat_id == 0)
{
$is_child = TRUE;
$total_posts = 0;
switch (SQL_LAYER)
{
@ -119,6 +120,8 @@ if ($cat_id == 0)
}
else
{
$is_child = FALSE;
if (!$acl->get_acl($cat_id, 'forum', 'list'))
{
//
@ -127,17 +130,16 @@ else
message_die(ERROR, $lang['Category_not_exist']);
}
//
// NOTE: make sure that categories post count is set to 0
//
$sql = 'SELECT SUM(forum_posts) AS total
FROM ' . FORUMS_TABLE . '
WHERE post_count_inc = 1
AND forum_status <> ' . ITEM_CATEGORY;
WHERE post_count_inc = 1';
$result = $db->sql_query($sql);
$total_posts = $db->sql_fetchfield('total', 0, $result);
//
// TODO: change this to get both parents and children
//
$result = $db->sql_query('SELECT left_id, right_id, parent_id FROM ' . FORUMS_TABLE . ' WHERE forum_id = ' . $cat_id);
$catrow = $db->sql_fetchrow($result);
@ -147,6 +149,7 @@ else
$sql = 'SELECT f.*, u.username
FROM ' . FORUMS_TABLE . ' f, ' . USERS_TABLE . 'u
WHERE (f.left_id BETWEEN ' . $catrow['left_id'] . ' AND ' . $catrow['right_id'] . '
OR ' . $catrow['left_id'] . ' BETWEEN f.left_id AND f.right_id)
AND f.forum_last_poster_id = u.user_id(+)
ORDER BY left_id';
break;
@ -156,6 +159,7 @@ else
FROM ' . FORUMS_TABLE . ' f
LEFT JOIN ' . USERS_TABLE . ' u ON f.forum_last_poster_id = u.user_id
WHERE f.left_id BETWEEN ' . $catrow['left_id'] . ' AND ' . $catrow['right_id'] . '
OR ' . $catrow['left_id'] . ' BETWEEN f.left_id AND f.right_id
ORDER BY f.left_id';
}
}
@ -170,9 +174,17 @@ while ($row = $db->sql_fetchrow($result))
if ($row['forum_id'] == $cat_id)
{
$parent_forums[] = $row;
$forum_rows[] = $row;
$is_child = TRUE;
}
elseif ($row['parent_id'] == $cat_id)
elseif (!$is_child)
{
$parent_forums[] = $row;
}
else
{
if ($row['parent_id'] == $cat_id)
{
//
// Root-level forum
@ -195,12 +207,16 @@ while ($row = $db->sql_fetchrow($result))
}
elseif ($row['display_on_index'] && $row['forum_status'] != ITEM_CATEGORY)
{
//
// Subforum, store it for direct linking
//
if ($acl->get_acl($row['forum_id'], 'forum', 'list'))
{
$subforums[$parent_id][] = $row;
}
}
}
}
$root_id = ($cat_id) ? $catrow['parent_id'] : 0;
include($phpbb_root_path . 'includes/forums_display.' . $phpEx);
@ -249,6 +265,23 @@ $template->assign_vars(array(
'U_MARK_READ' => "index.$phpEx$SID&amp;mark=forums")
);
foreach ($parent_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
//

View file

@ -4,7 +4,7 @@
<!-- INCLUDE viewforum_subforum.html -->
<!-- ENDIF -->
<form method="post" action="{S_FORUM_ACTION}"><table width="100%" cellspacing="2" cellpadding="2" border="0" align="center">
<table width="100%" cellspacing="2" cellpadding="2" border="0" align="center">
<tr>
<td colspan="2" align="left" valign="bottom"><a class="maintitle" href="{U_VIEW_FORUM}">{FORUM_NAME}</a><br /><span class="gensmall"> [ <a href="{U_VIEW_MODERATORS}">{L_VIEW_MODERATORS}</a> ]<br /><br /><b>{LOGGED_IN_USER_LIST}</b></span></td>
<td align="right" valign="bottom" nowrap="nowrap"><span class="gensmall"><b>{PAGINATION}</b></span></td>
@ -46,7 +46,7 @@
</tr>
<!-- END topicrow -->
<tr>
<td class="catBottom" colspan="8" height="28" align="center" valign="middle"><span class="genmed">{L_DISPLAY_TOPICS}:&nbsp;{S_SELECT_SORT_DAYS}&nbsp;{L_SORT_BY} {S_SELECT_SORT_KEY} {S_SELECT_SORT_DIR}&nbsp;<input type="submit" class="liteoption" value="{L_GO}" name="sort" /></span></td>
<form method="post" action="{S_FORUM_ACTION}"><td class="catBottom" colspan="8" height="28" align="center" valign="middle"><span class="genmed">{L_DISPLAY_TOPICS}:&nbsp;{S_SELECT_SORT_DAYS}&nbsp;{L_SORT_BY} {S_SELECT_SORT_KEY} {S_SELECT_SORT_DIR}&nbsp;<input type="submit" class="liteoption" value="{L_GO}" name="sort" /></span></td></form>
</tr>
</table>
@ -67,7 +67,6 @@
<td colspan="3"><span class="gensmall">{S_WATCH_FORUM}</span></td>
</tr>
</table>
</form>
<table width="100%" cellspacing="0" cellpadding="0" border="0">
<tr>