发帖明星在首页“排排坐”
技术与开发
代代在很多论坛上看到,论坛自动把当天发帖最多的三位用户放到论坛首页。这个功能非常实用,能激励用户多发帖,为论坛带来活力。但是代代非常好奇,这个功能是怎么实现的?

要实现这个功能,论坛要安装“发帖明星”插件(插件下载地址:http://www.shudoo.com/bzsoft,ASP版)。这个插件是这样设计的,先在论坛首页模板中新增一个发帖明星板块,然后新建一个ASP页面作为插件页面。
在页面中添加检索功能——找出发帖最多的三位用户,再通过用户ID从数据库的用户表中提取详细的用户信息,最后输出到“发帖明星”板块里即可。根据相似原理,我们还可以制作在线明星插件等。
第一步 新增发帖明星板块
进入论坛管理后台(以动网为例),点击“风格管理”按钮,找到“分页面模板(page_index)”选项,点击右边的“界面风格”按钮进入编辑界面,在模板“template.html(0)”部分找到“〈div class="mainbox"〉〈div class="Menubox"〉”这段代码,在代码后面加入下面代码:
〈div class="mainbox"〉发帖明星〈/div〉
第二步 新建插件页面并功能化
接下来,新建一个ASP插件页面,在页面上添加检索功能以及从数据库提取数据的功能。输入相关代码实现该功能,其中关键代码如下所示(完整代码下载地址:http://www.shudoo.com/bzsoft):
If IsNull(Application(mxcache & "_naid")) Or CStr(Application(mxcache & "_ndate"))〈〉CStr(Date()) Then
'查找当日第一个帖子的ID号
If IsSqlDataBase = 1 Then
Set rs=conn.execute("select top 1 AnnounceID from "& Dvbbs.NowUseBBS &" where DateAndTime>='"& Date() &"' order by AnnounceID asc",0,1)
Else
Set rs=conn.execute("select top 1 AnnounceID from "& Dvbbs.NowUseBBS &" where datediff('d',Date(),DateAndTime)〉=0 order by AnnounceID asc",0,1)
mxstr = "〈div class=""menu""〉〈strong〉发帖明星〈/strong〉〈/div〉"
mxstr=mxstr & "〈div class=""mainbar3"" style=""height:180px;""〉"
'通过当日第一个帖子的ID号检索出当日所有的帖子和发帖最多的用户ID
If IsSqlDataBase = 1 Then
Set rs=conn.execute("select top 3 count(AnnounceID) as total,PostUserID from "& Dvbbs.NowUseBBS &" where AnnounceID〉="& naid &" and DateAndTime〉='"& Date() &"' group by PostUserID order by total desc",0,1)
Else
Set rs=conn.execute("select top 3 count(AnnounceID),PostUserID from "& Dvbbs.NowUseBBS &" where AnnounceID〉="& naid &" and datediff('d',Date(),DateAndTime)〉=0 group by PostUserID order by count(AnnounceID) desc",0,1)
'利用用户ID从用户表中提取用户信息
Set rs=conn.execute("select UserID,UserName,UserPost,UserSex,UserFace,UserWidth,UserHeight,UserClass,UserMoney,userWealth,userEP,userCP from [Dv_User] where UserID in("& inid &")",0,1)
If rs.eof Or rs.bof Then
ReDim ushu(11,0)
ushu(0,0)=0
ushu(1,0)="无"
ushu(2,0)=0
ushu(3,0)=0
ushu(4,0)="Images/userface/image1.gif"
ushu(5,0)=32
ushu(6,0)=32
ushu(7,0)="无"
ushu(8,0)=0
ushu(9,0)=0
ushu(10,0)=0
ushu(11,0)=0
Else
ushu=rs.getrows(-1)
End If
Set rs=Nothing
'将用户信息保存到变量mxstr中,以备输出
For iii=0 To UBound(tshu,2)
For jjj=0 To UBound(ushu,2)
If tshu(1,iii)=ushu(0,jjj) Then
If iii=0 Then
mxstr=mxstr & "〈div style=""float:left;width:4%;text-align:center;height:180px;"" id=""tdleft""〉〈img style=""margin:80px 0px;"" src="""& tosex(ushu(3,jjj)) &""" /〉〈/div〉"
Else
第三步 在首页显示发帖明星
将第二步中制作的插件页面放到论坛根目录下,并修改论坛根目录下面的index.asp页面,在其页面代码“〈!——#include file="Dv_plus/IndivGroup/Dv_IndivGroup_Config.asp"——〉”的下面加入插件调用代码“〈!——#include file="插件文件名"——〉”。
最后找到index.asp页面中的TPL_Scan Template.Html(0)并修改为TPL_Scan Replace(Template.Html(0),"发帖明星",tomx()),这样便可以将插件的“发帖明星” 信息输出到第一步新建的“发帖明星”板块中了。
编后
本文的发帖明星插件是按照当天论坛所有用户发帖量来选取明星用户的,如果当天论坛管理员发布的帖数较多,就可能将管理员提取到首页,显得很不合适,大家可以在提取用户的SQL语句中添加过滤掉某些特定用户的条件来防止提取到一些不必要的信息。