Digg的实现原理
Digg概念源自美国Digg公司。它完全是依靠真实的网民的自己力量。网站上所有内容都是由网民自己发布,并且内容的位置也是由网民自己来决定。当内容的顶数,评论等达到一定的数字,这些内容就有可能从众多的信息中脱颖而出。
Digg自诞生之日起就以一种崭新的“新闻过滤器”模式和独立的新闻立场给互联网世界带来了强烈的影响。它是依靠网友的力量对资讯进行筛选、推荐、投票,进而生成用户自己的内容。
目前国内就有不少网站采用了开源程序进行Digg网站的建设,用以吸引“顶客”人群,如知名的IT媒体社区Donews的Dig频道;另外还有一些自行开发或者基于开源程序后期开发的Digg网站,较为知名的有我顶网(wodingg.com)等。
这段时间我也开发了相关功能插件,下面把该Digg功能的关键代码贴出来:
stype = NoSqlHack(request("post")) '得到提交类型,分Digg和bury
spanid = NoSqlHack(request("id"))'得到新闻ID
if stype="" or spanid="" then
response.Write("r")'类型或者新闻ID为空时返回错误字符R
response.End()
end if
select case stype
case "show"'类型为显示Digg数
set Digg_RS=Conn.execute("select Digg from FS_NS_News where ID="&spanid&"")
if not Digg_RS.eof then TmpStr = cstr(Digg_RS(0))
response.Write("document.write('"&TmpStr&"')")
RsClose()
case "digg"'类型为Digg提交
Deltime = DateDiff("D",2,GetTime)'删除一天后的Digg用户记录
'Response.write(Deltime)
Conn.execute("DELETE from FS_NS_Digg where DiggTime<"&Deltime)
set Digg_RS=Conn.execute("select * from FS_NS_Digg where ip = '"&ip&"' and NewsID = "&spanid&"")'判断是否有相同IP用户在同一天内对同一新闻进行Digg操作,有则返回错误字符R
if not Digg_RS.eof then
response.Write("r")
else
Conn.execute("insert into FS_NS_Digg(IP,NewsID,DiggTime) values('"&ip&"',"&spanid&",'"&GetTime&"')")'向数据库插入Digg日志
Conn.execute("Update FS_NS_News set Digg=Digg+1 where ID="&spanid&"")'更新Digg数
set Digg_RS=Conn.execute("select Digg from FS_NS_News where ID="&spanid&"")
if not Digg_RS.eof then TmpStr = cstr(Digg_RS(0))
response.Write(TmpStr)
end if
RsClose()
case else
response.Write("r")
end select
完了前台用ajax取得数据!