PHPBB论坛伪静态规则写法

不知道使用PHPbb的人多否,前几天折腾一个论坛,用了BB,于是找了下bb的伪静态,发现不是很多~ 仅有的几个看了下生产日期,发现过期了……

为此iFans收集了强人的杰作~

只需要改这四个文件:

1、viewtopic.php
2、viewtopic.php
3、includes/functions_display.php
4、includes/functions.php

分页规则:viewforum-1-0.html -> viewform.php?f=1&start=1 版面两个参数版面id 和分页参数
viewtopic-1-1-1.html -> viewtopic?f=1&t=1&start=1 版面id 帖子id 分页参数
按照规则,在.htaccess里加上下面的代码:

RewriteEngine on

#phpbb重写规则
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^viewtopic-(.+)-(.+)-(.+).html$ viewtopic.php?f=$1&t=$2&start=$3 [L,NC]
RewriteRule ^viewforum-(.+)-(.+).html$ viewforum.php?f=$1&start=$2 [L,NC]

打开viewtopic.php

649行:’U_VIEW_FORUM’ => append_sid(“{$phpbb_root_path}viewforum.$phpEx”, ‘f=’ . $forum_id),
改为:
//’U_VIEW_FORUM’ => append_sid(“{$phpbb_root_path}viewforum.$phpEx”, ‘f=’ . $forum_id),
‘U_VIEW_FORUM’ => “./viewforum”. ‘-‘ . $forum_id.’-‘.’0.html’,
567行:$pagination = generate_pagination(append_sid(“{$phpbb_root_path}viewtopic.$phpEx”, “f=$forum_id&t=$topic_id” . ((strlen($u_sort_param)) ? “&$u_sort_param” : ”) . (($highlight_match) ? “&hilit=$highlight” : ”)), $total_posts, $config[‘posts_per_page’], $start);

修改为

//$pagination = generate_pagination(append_sid(“{$phpbb_root_path}viewtopic.$phpEx”, “f=$forum_id&t=$topic_id” . ((strlen($u_sort_param)) ? “&$u_sort_param” : ”) . (($highlight_match) ? “&hilit=$highlight” : ”)), $total_posts, $config[‘posts_per_page’], $start);
$pagination = generate_pagination1(append_sid(“{$phpbb_root_path}viewtopic.$phpEx”, “f=$forum_id&t=$topic_id” . ((strlen($u_sort_param)) ? “&$u_sort_param” : ”) . (($highlight_match) ? “&hilit=$highlight” : ”)),”./viewtopic”. ‘-‘ . $forum_id.’-‘. $topic_id.’-‘, $total_posts, $config[‘posts_per_page’], $start);

打开includes/functions.php

在最后加上这个函数

function generate_pagination1($base_url1,$base_url, $num_items, $per_page, $start_item, $add_prevnext_text = false, $tpl_prefix = ”)
{
global $template, $user;

// Make sure $per_page is a valid value
$per_page = ($per_page <= 0) ? 1 : $per_page; $seperator = '‘ . $user->lang[‘COMMA_SEPARATOR’] . ‘‘;
$total_pages = ceil($num_items / $per_page);

if ($total_pages == 1 || !$num_items)
{
return false;
}

$on_page = floor($start_item / $per_page) + 1;
$url_delim = (strpos($base_url, ‘?’) === false) ? ‘?’ : ((strpos($base_url, ‘?’) === strlen($base_url) – 1) ? ” : ‘&’);

$page_string = ($on_page == 1) ? ‘1‘ : ‘1‘;

if ($total_pages > 5)
{
$start_cnt = min(max(1, $on_page – 4), $total_pages – 5);
$end_cnt = max(min($total_pages, $on_page + 4), 6);

$page_string .= ($start_cnt > 1) ? ‘ … ‘ : $seperator;

for ($i = $start_cnt + 1; $i < $end_cnt; $i++) { $page_string .= ($i == $on_page) ? '‘ . $i . ‘‘ : ‘‘ . $i . ‘‘;
if ($i < $end_cnt - 1) { $page_string .= $seperator; } } $page_string .= ($end_cnt < $total_pages) ? ' ... ' : $seperator; } else { $page_string .= $seperator; for ($i = 2; $i < $total_pages; $i++) { $page_string .= ($i == $on_page) ? '‘ . $i . ‘‘ : ‘‘ . $i . ‘‘;
if ($i < $total_pages) { $page_string .= $seperator; } } } $page_string .= ($on_page == $total_pages) ? '‘ . $total_pages . ‘‘ : ‘‘ . $total_pages . ‘‘;

if ($add_prevnext_text)
{
if ($on_page != 1)
{
$page_string = ‘‘ . $user->lang[‘PREVIOUS’] . ‘  ‘ . $page_string;
}

if ($on_page != $total_pages)
{
$page_string .= ‘  ‘ . $user->lang[‘NEXT’] . ‘‘;
}
}

$template->assign_vars(array(
$tpl_prefix . ‘BASE_URL’ => $base_url,
‘A_’ . $tpl_prefix . ‘BASE_URL’ => addslashes($base_url1),
$tpl_prefix . ‘PER_PAGE’ => $per_page,

$tpl_prefix . ‘PREVIOUS_PAGE’ => ($on_page == 1) ? ” : $base_url . “” . (($on_page – 2) * $per_page.”.html”),
$tpl_prefix . ‘NEXT_PAGE’ => ($on_page == $total_pages) ? ” : $base_url . “” . ($on_page * $per_page).”.html”,
$tpl_prefix . ‘TOTAL_PAGES’ => $total_pages,
));

return $page_string;
}

之所以不改原来的函数,是为了留着原始版本,如果将来出问题,可以很简单的恢复,下面同上
打开includes/functions_display.php
加下面的函数:

function topic_generate_pagination1($replies, $url)
{
global $config, $user;

// Make sure $per_page is a valid value
$per_page = ($config[‘posts_per_page’] <= 0) ? 1 : $config['posts_per_page']; if (($replies + 1) > $per_page)
{
$total_pages = ceil(($replies + 1) / $per_page);
$pagination = ”;

$times = 1;
for ($j = 0; $j < $replies + 1; $j += $per_page) { $pagination .= '‘ . $times . ‘‘;
if ($times == 1 && $total_pages > 5)
{
$pagination .= ‘ … ‘;

// Display the last three pages
$times = $total_pages – 3;
$j += ($total_pages – 4) * $per_page;
}
else if ($times < $total_pages) { $pagination .= '‘ . $user->lang[‘COMMA_SEPARATOR’] . ‘‘;
}
$times++;
}
}
else
{
$pagination = ”;
}

return $pagination;
}

314行:

‘U_VIEWFORUM’ => append_sid(“{$phpbb_root_path}viewforum.$phpEx”, ‘f=’ . $row[‘forum_id’]))

改为:

‘U_VIEWFORUM’ => “./viewforum”. ‘-‘ . $row[‘forum_id’].”-0.html”)

358行:

‘link’ => append_sid(“{$phpbb_root_path}viewforum.$phpEx”, ‘f=’ . $subforum_id),

改为:

//’link’ => append_sid(“{$phpbb_root_path}viewforum.$phpEx”, ‘f=’ . $subforum_id),
‘link’ => “./viewforum”. ‘-‘ . $subforum_id.’-0.html’,

438行:

$u_viewforum = append_sid(“{$phpbb_root_path}viewforum.$phpEx”, ‘f=’ . $row[‘forum_id’]);

改为:

//$u_viewforum = append_sid(“{$phpbb_root_path}viewforum.$phpEx”, ‘f=’ . $row[‘forum_id’]);
$u_viewforum = “./viewforum”. ‘-‘ . $row[‘forum_id’].’-‘.$start.’.html’;

450行:

$u_viewforum = append_sid(“{$phpbb_root_path}viewforum.$phpEx”, ‘f=’ . $row[‘forum_id’]);

改为:

$u_viewforum = “./viewforum”. ‘-‘ . $row[‘forum_id’].’-‘.$start.’.html’;

586行:

‘U_VIEW_FORUM’=> append_sid(“{$phpbb_root_path}viewforum.$phpEx”, ‘f=’ . $parent_forum_id))

改为:

‘U_VIEW_FORUM’ => “./viewforum”. ‘-‘ . $parent_forum_id.’-0.html’)

598行:

‘U_VIEW_FORUM’=> append_sid(“{$phpbb_root_path}viewforum.$phpEx”, ‘f=’ . $forum_data[‘forum_id’]))

改为:

//’U_VIEW_FORUM’ => append_sid(“{$phpbb_root_path}viewforum.$phpEx”, ‘f=’ . $forum_data[‘forum_id’]))
‘U_VIEW_FORUM’ => “./viewforum”. ‘-‘ . $forum_data[‘forum_id’].’-0.html’)

1095行:

‘U_ACTIVE_FORUM’ => append_sid(“{$phpbb_root_path}viewforum.$phpEx”, ‘f=’ . $active_f_id),

改为:

//’U_ACTIVE_FORUM’ => append_sid(“{$phpbb_root_path}viewforum.$phpEx”, ‘f=’ . $active_f_id),
‘U_ACTIVE_TOPIC’=> append_sid(“{$phpbb_root_path}viewtopic.$phpEx”, ‘t=’ . $active_t_id),

打开viewforum.php
621行:

$view_topic_url = append_sid(“{$phpbb_root_path}viewtopic.$phpEx”, $view_topic_url_params);

改为:

//$view_topic_url = append_sid(“{$phpbb_root_path}viewtopic.$phpEx”, $view_topic_url_params);
$view_topic_url = “./viewtopic”.’-‘ . (($row[‘forum_id’]) ? $row[‘forum_id’] : $forum_id) . ‘-‘ . $topic_id.’-‘.$start.’.html’;

154行:

‘U_VIEW_FORUM’ => append_sid(“{$phpbb_root_path}viewforum.$phpEx”, “f=$forum_id&start=$start”),

改为:

//’U_VIEW_FORUM’=> append_sid(“{$phpbb_root_path}viewforum.$phpEx”, “f=$forum_id&start=$start”),
‘U_VIEW_FORUM’ => “./viewforum”. ‘-‘ . $forum_id.’-‘.$start.’.html’,

306行:

‘S_FORUM_ACTION’ => append_sid(“{$phpbb_root_path}viewforum.$phpEx”, “f=$forum_id&start=$start”),

改为:

//’S_FORUM_ACTION’=> append_sid(“{$phpbb_root_path}viewforum.$phpEx”, “f=$forum_id&start=$start”),
‘S_FORUM_ACTION’=> “./viewforum”. ‘-‘ . $forum_id.’-‘.$start.’.html’,

531行:

‘PAGINATION’=> generate_pagination(append_sid(“{$phpbb_root_path}viewforum.$phpEx”, “f=$forum_id” . ((strlen($u_sort_param)) ? “&$u_sort_param” : ”)), $topics_count, $config[‘topics_per_page’], $start),

改为:

//’PAGINATION’=> generate_pagination(append_sid(“{$phpbb_root_path}viewforum.$phpEx”, “f=$forum_id” . ((strlen($u_sort_param)) ? “&$u_sort_param” : ”)), $topics_count, $config[‘topics_per_page’], $start),
‘PAGINATION’=> generate_pagination1(append_sid(“{$phpbb_root_path}viewforum.$phpEx”, “f=$forum_id” . ((strlen($u_sort_param)) ? “&$u_sort_param” : ”)),”./viewforum”. ‘-‘ . $forum_id.’-‘, $topics_count, $config[‘topics_per_page’], $start),

645行:

‘PAGINATION’=> topic_generate_pagination($replies, $view_topic_url),

改为:

‘PAGINATION’ => topic_generate_pagination1($replies, $view_topic_url1),

2 篇回应 (访客:0 篇, 博主:0 篇, 其它:2 篇)

Leave a Reply

You must be logged in to post a comment.

RSS feed for comments on this post. TrackBack URL