返回   CHF站长论坛 > 特色讨论区 > vBulletin 交流专栏

vBulletin 交流专栏 vBulletin 是一个强大,灵活并可完全根据自己的需要定制的论坛程序。[官方]

双至强仅二千,企商在线,最早租用商 魔兽世界私服 魔兽世界私服 此文字广告位招租 天龙八部私服 传奇世界私服 新开传奇私服
传奇私服 热血江湖私服 全球最新的创意科技产品 魔域私服 魔域私服 新开传奇私服 魔域私服 传奇私服
发表新主题 回复
 
主题工具 主题评分 显示模式
旧 2006-11-29, 17:23   #1 (页面定位)
十方俱灭
 
十方俱灭 的头像
 
注册日期: 2006-04-22
帖子: 116
十方俱灭 是普普通通的会员
默认 【原创】壮举!修改模板实现vBB伪静态!

现在VBB的伪静态的解决方案大都是通过插件的形式来实现,这些软件可以有效减少使用者的工作量,维护也更加友好,适合流量不是很大,或者嫌麻烦的人使用。据我所知的这方面插件有4个:

vBSEO:功能最强大,维护最简单的插件,成熟大气,但是商业程序,价格也不菲

Zoints SEO:是开源且免费,但是功能和vBSEO相距甚远,又不能友好的设置改写规则(至少我没找到)

vRewrite:VBORG的Premium Modifications,也是纯hook实现的插件,同时又有了规则的选择支持,不过预设的规则很少,不修改这个规则的话,中文论坛虽然使用上没问题,但总给人感觉是有垃圾存在URL中。大概是以apache作基准平台吧,因为rewrite的语法不同,默认的规则只有手动修改才能在IIS下工作。

vB_Ranking:这款插件可以说是现在四个插件中最简单最简单的一个,纯hook实现,不需要修改模板,没有其他杂七杂八的功能,朴实无华但很实用,我个人很喜欢,缺点是rewrite的规则千篇一律,对于修改规则来说,我还没有进行尝试。由于开发于3.5.0 rc3阶段,兼容性也需要测试。

但是以插件的形式来实现的这4个插件,似乎存在一个共同的问题,就是性能问题。以vBSEO来说,他的rewrite规则是将页面改写到vbseo.php,再由vbseo.php根据设置的规则查找对应的页面并输出内容,因为他是加密不开源的,所以细节的东西无法知道,也不好多说。剩下的三个插件主要是是通过在hook的相应位置执行str_replace之类的语句,将输出的html内容进行替换,最终输出在浏览器上。要想知道细节方面的东西,就需要有丰富PHP开发经验的高手研究一下程序的工作机制,比如有没将某些东西进行缓存来减少程序的运算,还需要大量的用户测试和对比才能得到具体结论,我这里只是一种猜测。

所以简单来说,就是把输出的html中特定的连接url换了一下,而修改模板中输出的内容是最直接也最节能的办法。因为修改起来特别麻烦,所以这种办法不适合安装有大量模板的人使用,下面我就说下我的总结。

这个办法我用了两天两宿才基本完成了修改和测试等工作,在模板方面,可以通过搜索forumdisplay.php、showthread.php、showpost.php等文件名的方法获取哪些模板需要修改,这个静态化的程度也可以完全自己掌握,像“快速链接、上一主题、下一主题、转到首个未读回复”这样的地方要不要作完全可以自己选择,灵活度很高。但最好事先规划好要修改的地方,设计好URL规则和ISAPI_Rewrite的规则,不然很可能越搞头越大。同时我放弃了一些论坛上原有的不常用功能,比如搜索以后的highlightwords。

模板方面比较容易,值得一提的是,这里我用到了一个hook和三个分页的相关模板,不然在各种分页时候会混乱,为确保forumdisplay.php中各种排序的正常工作,也不得不用到这个hook。

PHP 代码:
<?xml version="1.0" encoding="UTF-8"?>

<plugins>
    <plugin active="1" executionorder="5" product="ad184">
        <title>伪静态_pagenav</title>
        <hookname>pagenav_page</hookname>
        <phpcode><![CDATA[global $foruminfo,$threadid;

$sort = $_GET[sort];
$page = $_GET[page];
$pp = $_GET[pp];
$order = $_GET[order];
//这里是为了识别,是伪静态的URL还是forumdisplay.php中的排序

if (!$sort and !$page and !$pp and !$order)
{
    $address3 = "forum$foruminfo[forumid]";
    $address4 = ".html";
    $address5 = "thread".$threadid;
    $prefix_temp = "-";
} else {
    $address3 = $address;
    $address4 = $address2;
    $address5 = $address;
    $prefix_temp = "&amp;page";
}]]></phpcode>
    </plugin>
</plugins>

有两个模板的修改要特别一提,分别是pagenav_pagelink、pagenav_pagelinkrel用来控制翻页的页数的。这里我主要修改的就是$address和$address2分别改为$address3、$address4、$address5,并且把连接符号换成了$prefix_temp,他们的值取决于上面的hook

PHP 代码:
<if condition="THIS_SCRIPT=='forumdisplay'">
<
td class="alt1"><class="smallfont" href="$address3<if condition="$curpage != 1">$prefix_temp$curpage</if>$address4" title="<phrase 1="$pagenumbers[first]" 2="$pagenumbers[last]" 3="$total">$vbphrase[show_results_x_to_y_of_z]</phrase>">$curpage</a></td>
</if>

<if 
condition="THIS_SCRIPT=='showthread' || THIS_SCRIPT=='showpost'">
<
td class="alt1"><class="smallfont" href="$address5<if condition="$curpage != 1">$prefix_temp$curpage</if>$address4" title="<phrase 1="$pagenumbers[first]" 2="$pagenumbers[last]" 3="$total">$vbphrase[show_results_x_to_y_of_z]</phrase>">$curpage</a></td>
</if>

<if 
condition="THIS_SCRIPT!='forumdisplay' AND THIS_SCRIPT!='showthread' AND THIS_SCRIPT!='showpost'">
<
td class="alt1"><class="smallfont" href="$address<if condition="$curpage != 1">&amp;page=$curpage</if>$address2" title="<phrase 1="$pagenumbers[first]" 2="$pagenumbers[last]" 3="$total">$vbphrase[show_results_x_to_y_of_z]</phrase>">$curpage</a></td>
</if> 
十方俱灭 当前离线   回复时引用此帖
旧 2006-11-29, 17:23   #2 (页面定位)
十方俱灭
 
十方俱灭 的头像
 
注册日期: 2006-04-22
帖子: 116
十方俱灭 是普普通通的会员
默认

还有控制上一页、下一页的pagenav,这里的修改也主要与pagenav_pagelink、pagenav_pagelinkrel相似

PHP 代码:
<if condition="THIS_SCRIPT=='forumdisplay'">
<
div class="pagenav" align="$stylevar[right]">
<
table class="tborder" cellpadding="3" cellspacing="$stylevar[cellspacing]" border="0">
<
tr>
    <
td class="vbmenu_control" style="font-weight:normal"><phrase 1="$pagenumber" 2="$totalpages">$vbphrase[page_x_of_y]</phrase></td>
    <if 
condition="$show['first']"><td class="alt1" nowrap="nowrap"><class="smallfont" href="$address3$address4" title="$vbphrase[first_page] - <phrase 1="$firstnumbers[first]" 2="$firstnumbers[last]" 3="$total">$vbphrase[results_x_to_y_of_z]</phrase>"><strong>&laquo;</strong$vbphrase[first]</a></td></if>
    <if 
condition="$show['prev']"><td class="alt1"><class="smallfont" href="$address3<if condition="$prevpage != 1">-$prevpage</if>$address4" title="$vbphrase[prev_page] - <phrase 1="$prevnumbers[first]" 2="$prevnumbers[last]" 3="$total">$vbphrase[results_x_to_y_of_z]</phrase>">&lt;</a></td></if>
    
$pagenav
    
<if condition="$show['next']"><td class="alt1"><class="smallfont" href="$address3-$nextpage$address4" title="$vbphrase[next_page] - <phrase 1="$nextnumbers[first]" 2="$nextnumbers[last]" 3="$total">$vbphrase[results_x_to_y_of_z]</phrase>">&gt;</a></td></if>
    <if 
condition="$show['last']"><td class="alt1" nowrap="nowrap"><class="smallfont" href="$address3-$totalpages$address4" title="$vbphrase[last_page] - <phrase 1="$lastnumbers[first]" 2="$lastnumbers[last]" 3="$total">$vbphrase[results_x_to_y_of_z]</phrase>">$vbphrase[last] <strong>&raquo;</strong></a></td></if>
    <if 
condition="$show['popups']"><td class="vbmenu_control" title="$address$address2"><a name="PageNav"></a></td></if>
</
tr>
</
table>
</
div>
</if>

<if 
condition="THIS_SCRIPT=='showthread' || THIS_SCRIPT=='showpost'">
<
div class="pagenav" align="$stylevar[right]">
<
table class="tborder" cellpadding="3" cellspacing="$stylevar[cellspacing]" border="0">
<
tr>
    <
td class="vbmenu_control" style="font-weight:normal"><phrase 1="$pagenumber" 2="$totalpages">$vbphrase[page_x_of_y]</phrase></td>
    <if 
condition="$show['first']"><td class="alt1" nowrap="nowrap"><class="smallfont" href="$address5$address4" title="$vbphrase[first_page] - <phrase 1="$firstnumbers[first]" 2="$firstnumbers[last]" 3="$total">$vbphrase[results_x_to_y_of_z]</phrase>"><strong>&laquo;</strong$vbphrase[first]</a></td></if>
    <if 
condition="$show['prev']"><td class="alt1"><class="smallfont" href="$address5<if condition="$prevpage != 1">-$prevpage</if>$address4" title="$vbphrase[prev_page] - <phrase 1="$prevnumbers[first]" 2="$prevnumbers[last]" 3="$total">$vbphrase[results_x_to_y_of_z]</phrase>">&lt;</a></td></if>
    
$pagenav
    
<if condition="$show['next']"><td class="alt1"><class="smallfont" href="$address5-$nextpage$address4" title="$vbphrase[next_page] - <phrase 1="$nextnumbers[first]" 2="$nextnumbers[last]" 3="$total">$vbphrase[results_x_to_y_of_z]</phrase>">&gt;</a></td></if>
    <if 
condition="$show['last']"><td class="alt1" nowrap="nowrap"><class="smallfont" href="$address5-$totalpages$address4" title="$vbphrase[last_page] - <phrase 1="$lastnumbers[first]" 2="$lastnumbers[last]" 3="$total">$vbphrase[results_x_to_y_of_z]</phrase>">$vbphrase[last] <strong>&raquo;</strong></a></td></if>
    <if 
condition="$show['popups']"><td class="vbmenu_control" title="$address$address2"><a name="PageNav"></a></td></if>
</
tr>
</
table>
</
div>
</if>

<if 
condition="THIS_SCRIPT!='forumdisplay' AND THIS_SCRIPT!='showthread' AND THIS_SCRIPT!='showpost'">
<
div class="pagenav" align="$stylevar[right]">
<
table class="tborder" cellpadding="3" cellspacing="$stylevar[cellspacing]" border="0">
<
tr>
    <
td class="vbmenu_control" style="font-weight:normal"><phrase 1="$pagenumber" 2="$totalpages">$vbphrase[page_x_of_y]</phrase></td>
    <if 
condition="$show['first']"><td class="alt1" nowrap="nowrap"><class="smallfont" href="$address$address2" title="$vbphrase[first_page] - <phrase 1="$firstnumbers[first]" 2="$firstnumbers[last]" 3="$total">$vbphrase[results_x_to_y_of_z]</phrase>"><strong>&laquo;</strong$vbphrase[first]</a></td></if>
    <if 
condition="$show['prev']"><td class="alt1"><class="smallfont" href="$address<if condition="$prevpage != 1">-$prevpage</if>$address2" title="$vbphrase[prev_page] - <phrase 1="$prevnumbers[first]" 2="$prevnumbers[last]" 3="$total">$vbphrase[results_x_to_y_of_z]</phrase>">&lt;</a></td></if>
    
$pagenav
    
<if condition="$show['next']"><td class="alt1"><class="smallfont" href="$address-$nextpage$address2" title="$vbphrase[next_page] - <phrase 1="$nextnumbers[first]" 2="$nextnumbers[last]" 3="$total">$vbphrase[results_x_to_y_of_z]</phrase>">&gt;</a></td></if>
    <if 
condition="$show['last']"><td class="alt1" nowrap="nowrap"><class="smallfont" href="$address-$totalpages$address2" title="$vbphrase[last_page] - <phrase 1="$lastnumbers[first]" 2="$lastnumbers[last]" 3="$total">$vbphrase[results_x_to_y_of_z]</phrase>">$vbphrase[last] <strong>&raquo;</strong></a></td></if>
    <if 
condition="$show['popups']"><td class="vbmenu_control" title="$address$address2"><a name="PageNav"></a></td></if>
</
tr>
</
table>
</
div>
</if> 
因为是自己测试着用的,所以代码方面都不是很规范,最后我就发一下我的两个规则,这个规则也同样是以测试为目的来整理的,所以我不会把大家看晕,哈哈!

引用:
[ISAPI_Rewrite]

#######################三联论坛伪静态规则开始#######################

##############################存档部分##############################

RewriteRule ^(.*)/archive/forum([0-9]+).html $1/archive/index.php?f-$2.html
RewriteRule ^(.*)/archive/thread([0-9]+).html $1/archive/index.php?t-$2.html

##############################论坛列表##############################

#forum$forum[forumid].html
RewriteRule ^(.*)/forum([0-9]+).html $1/forumdisplay.php?f=$2

#pagenav_pagelink、pagenav_pagelinkrel
RewriteRule ^(.*)/forum([0-9]+)-([0-9]+).html $1/forumdisplay.php?f=$2&page=$3

#forum$foruminfo[forumid]-viewgoodnees.html
RewriteRule ^(.*)/forum([0-9]+)-viewgoodnees.html $1/forumdisplay.php?f=$2&viewgoodnees=1

#forum$foruminfo[forumid]-tcatid$tcatid.html
RewriteRule ^(.*)/forum([0-9]+)-tcatid([0-9]+).html $1/forumdisplay.php?f=$2&tcatid=$3

#forum$foruminfo[forumid]-viewgoodnees-tcatid$tcatid.html
RewriteRule ^(.*)/forum([0-9]+)-viewgoodnees-tcatid([0-9]+).html $1/forumdisplay.php?f=$2&tcatid=$3&viewgoodnees=1

#forum$foruminfo[forumid]-viewgoodnees-tcatid.html
RewriteRule ^(.*)/forum([0-9]+)-viewgoodnees-tcatid.html $1/forumdisplay.php?f=$2&tcatid=$3

##############################主题部分##############################

#thread$threadid.html
#thread$threadinfo[threadid].html
RewriteRule ^(.*)/thread([0-9]+).html $1/showthread.php?t=$2

#threadbit_pagelink、pagenav_pagelinkrel
RewriteRule ^(.*)/thread([0-9]+)-([0-9]+).html $1/showthread.php?t=$2&page=$3

#post$postid.html
RewriteRule ^(.*)/post([0-9]+).html $1/showthread.php?p=$2

#thread$thread[threadid]-last-post.html
RewriteRule ^(.*)/thread([0-9]+)-last-post.html $1/showthread.php?goto=lastpost&t=$2

#thread$thread[threadid]-new-post.html
#thread$lastpostinfo[lastthreadid]-new-post.html
RewriteRule ^(.*)/thread([0-9]+)-new-post.html $1/showthread.php?goto=newpost&t=$2

#thread$threadid-prev-thread.html
RewriteRule ^(.*)/thread([0-9]+)-prev-thread.html $1/showthread.php?t=$2&goto=nextoldest

#thread$threadid-next-thread.html
RewriteRule ^(.*)/thread([0-9]+)-next-thread.html $1/showthread.php?t=$2&goto=nextnewest

#thread$threadid-print.html
RewriteRule ^(.*)/thread([0-9]+)-print.html $1/printthread.php?t=$2

#thread$threadid-$maxperpage-print.html
RewriteRule ^(.*)/thread([0-9]+)-([0-9]+)-print.html $1/printthread.php?t=$2&pp=$3

##############################帖子部分##############################

#post-p$postid.html post$watch[postid].html
RewriteRule ^(.*)/post-([0-9]+).html $1/showpost.php?p=$2

#post$post[postid]-p$post[postcount].html
RewriteRule ^(.*)/post([0-9]+)-p([0-9]+).html $1/showpost.php?p=$2&postcount=$3

#RewriteRule ^(.*)/post([0-9]+)-p([0-9]+)-([0-9]+).html $1/showpost.php?p=$3&page=$4

##############################其他部分##############################

RewriteRule ^(.*)/forum.html $1/index.php
RewriteRule ^(.*)/thread.html $1/index.php
#RewriteRule ^(.*)/user([0-9]+).html $1/member.php?u=$2
#RewriteRule ^(.*)/memberlist.html $1/memberlist.php
#RewriteRule ^(.*)/(?:forum|thread|post|user|archive)/(.*\.(?:gif|jpg|png|css|xml|js))(.*) $1/$2$3 [I,L]

#######################三联论坛伪静态规则结束#######################

虽然自称壮举,不过没有专门看过ISAPI_Rewrite的规则手册,也没有专门学过正则表达式,都是依葫芦画瓢,各位兄弟门多指教,哈哈:)

关于静态化后的论坛演示,可以到我的测试论坛:
http://chinae3.skycom.cn/bbs/
十方俱灭 当前离线   回复时引用此帖
旧 2006-11-29, 17:33   #3 (页面定位)
十方俱灭
 
十方俱灭 的头像
 
注册日期: 2006-04-22
帖子: 116
十方俱灭 是普普通通的会员
默认

现在已知的2个问题,一是风格的切换问题,二是跳转页码的问题,这2个都不得不修改文件,而且即便如此,也没有很完美的解决问题...
十方俱灭 当前离线   回复时引用此帖
旧 2006-11-29, 23:28   #4 (页面定位)
梦龙
 
梦龙 的头像
 
注册日期: 2006-07-29
帖子: 11
梦龙 是普普通通的会员
默认

崇拜
梦龙 当前离线   回复时引用此帖
旧 2006-11-30, 00:21   #5 (页面定位)
hjb1©
管 理 员 &lt;--还是写上来了 ^_^
 
hjb1 的头像
 
注册日期: 2005-09-04
住址: 我家床上
帖子: 1329
hjb1 是一个将要出名的人hjb1 是一个将要出名的人hjb1 是一个将要出名的人hjb1 是一个将要出名的人hjb1 是一个将要出名的人hjb1 是一个将要出名的人
默认

强啊~~~
hjb1 当前离线   回复时引用此帖
回复

书签

标签

主题工具
显示模式 对此主题评分
对此主题评分:



所有时间均为北京时间。现在的时间是 09:15