给PJBlog文章添加相关日志的显示功能,之前已经有很多人研究过了。像在PJBlog官方论坛就有WBC相关日志和静¢脉提供的插件:相关日志插件 FOR PJBLOG 2.7 080110修正。在这里介绍一个全自动安装的方法:
日志插件进行总结大致可以分两种:
一、以本文TAG标签关联其他文章标题的。
二、以本文TAG标签关联其他文章TAG的。
安装方法:
1.新建文件命名为:ajaxJS.js,添加如下代码:
function $(id)
{
return document.getElementById(id);
}
function echo(obj,html)
{
$(obj).innerHTML=html;
}
function fopen(obj)
{
$(obj).style.display="";
}
function fclose(obj)
{
$(obj).style.display="none";
}
function createxmlhttp()
{
var xmlhttp=false;
try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e) {
xmlhttp = false;
}
}
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
xmlhttp = new XMLHttpRequest();
if (xmlhttp.overrideMimeType) {//设置MiME类别
xmlhttp.overrideMimeType('text/xml');
}
}
return xmlhttp;
}
function getdata(url,obj1,obj2)
{
var xmlhttp=createxmlhttp();
if(!xmlhttp)
{
alert("你的浏览器不支持XMLHTTP!!");
return;
}
xmlhttp.onreadystatechange=requestdata;
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
function requestdata()
{
fopen(obj1);
echo(obj1,"正在加载数据,请稍等……");
if(xmlhttp.readyState==4)
{
if(xmlhttp.status==200)
{
if(obj1!=obj2){fclose(obj1);};
echo(obj2,xmlhttp.responseText);
}
}
}
}
2.新建文件命名为:wbc_getarticle.asp,添加如下代码:
<%@ LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<%
Response.expires=-1
Response.AddHeader"pragma","no-cache"
Response.AddHeader"cache-control","no-store"
Session.CodePage=65001
Const AccessFile="blogDB/wbc.mdb" '<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<+================
Set Conn= Server.CreateObject("ADODB.Connection")
Conn.ConnectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath(AccessFile)
Conn.Open
If Err Then
err.Clear
Set Conn = Nothing
Response.Write("<meta http-equiv=""Content-Type"" content=""text/html; charset=UTF-8"" /><div style='font-size:12px;font-weight:bold;border:1px solid #006;padding:6px;background:#fcc'>数据库连接出错,请检查连接字串!</div>")
Response.End
end if
id=request("id")
if id<>"" and isnumeric(id) then
Dim wbc_tag,Rs,i,RsT,OutPut,i2,i3,i4,str,ifMore,i2_2,total_rela,page,pagestr,thispage
Set Rs=conn.execute("Select * from blog_Content where log_ID="&id&"")
if request("page")<>"" and isnumeric(request("page")) then
page=Cint(request("page"))
if page<1 then page=1
Else
page=1
End if
thispage=page
OutPut=""
total_rela=0
i2_2=10 '每頁顯示No.
i3=(page-1)*i2_2
if request("act")="more" then i2_2=-1
ifMore=false
if not rs.eof then
wbc_tag=rs("log_tag")
if wbc_tag<>"" then
wbc_tag=split(wbc_tag,"}")
i=0
i2=0
'find total
DO until i>Ubound(wbc_tag)
Set RsT=conn.execute("Select log_Title,log_id,log_ViewNums from blog_Content where log_tag like '%"&wbc_tag(i)&"}%' and log_ID<>"&id&" order by log_PostTime desc")
if not RsT.eof then
Do until Rst.eof
str=split(RsT(0),"(*##*)")(0)
If instr(OutPut,str)=0 and wbc_tag(i)<>"" then
total_rela=total_rela+1
End if
Rst.movenext
Loop
End if
Set RsT=nothing
i=i+1
Loop
'pages
if int((total_rela/i2_2))< total_rela/i2_2 then
page=(total_rela/i2_2)+1
Else
page=int(total_rela/i2_2)
end if
pagestr=""
i=1
do until i>page
if thispage=i then
pagestr=pagestr&"<strong style='text-decoration:none' title='当前页'>["&i&"]</strong>"
Elseif abs(thispage-i)<5 then
pagestr=pagestr&"<a style='cursor:pointer' title='转到第"&i&"页' onclick=getdata('wbc_getarticle.asp?id="&id&"&page="&i&"','wbc_tag','wbc_tag') >["&i&"]</a>"
end if
i=i+1
Loop
if page>1 then pagestr=" <div style='margin-top:10px;width:350px;'><strong>分页:</strong> "&pagestr&""
'show results
i=0
i4=0
DO until i>Ubound(wbc_tag)
Set RsT=conn.execute("Select log_Title,log_id,log_ViewNums from blog_Content where log_tag like '%"&wbc_tag(i)&"}%' and log_ID<>"&id&" order by log_PostTime desc")
if not RsT.eof then
Do until Rst.eof or i4=i2_2
str=split(RsT(0),"(*##*)")(0)
If instr(OutPut,str)=0 and wbc_tag(i)<>"" then
if i2>(i3-1) then
i4=i4+1
OutPut=OutPut&" <li><a href='article.asp?id="&RsT(1)&"'>"&str&"["&RsT(2)&"]</a></li>"
end if
i2=i2+1
End if
Rst.movenext
Loop
if not RsT.eof then Ifmore=true
End if
Set RsT=nothing
i=i+1
Loop
End if
End if
output=output&pagestr
If Ifmore or thispage<>1 then
OutPut=OutPut&"<br/><font color=red><strong>模式:</strong></font> <a style='cursor:pointer' onclick=getdata('wbc_getarticle.asp?id="&id&"&act=more','wbc_tag','wbc_tag') >全部显示[共"&total_rela&"個相关文章]</a></div>"
elseif i2>(i2_2-1) then
OutPut=OutPut&"<div style='margin-top:10px;width:350px;'><strong><font color=red>模式:</font></strong> <a style='cursor:pointer' onclick=getdata('wbc_getarticle.asp?id="&id&"','wbc_tag','wbc_tag') >分页显示[共"&total_rela&"個相关文章]</a></div>"
end if
OutPut=replace(OutPut,chr(39),chr(34))
response.Write OutPut
Set rs=nothing
end if
%>
3.新建文件:WBC_Update.asp,添加如下代码:
<!–#include file="BlogCommon.asp" –>
<!–#include file="header.asp" –>
<!–#include file="common/ModSet.asp" –>
<!–#include file="plugins.asp" –>
<!–#include file="class/cls_default.asp" –>
<!–#include file="class/cls_logAction.asp" –>
<form id="form1" name="form1" method="post" action="?act=go">
<label>
<input type="submit" name="Submit" value="點擊開始更新!" />
</label>
</form>
<%
'========================
'By WBC
'On 2006-05-22
'版權所有 不得轉載
'This Page For WBC相关日志
'========================
'on error resume next
if err then err.clear
session.codepage=65001
Private function LoadFile(ByVal File)
Dim cacheStream
Set cacheStream = Server.CreateObject("ADODB.Stream")
With cacheStream
.Type = 2
.Mode = 3
.Open
.Charset = "utf-8"
.Position =cacheStream.Size
.LoadFromFile Server.MapPath(File)
LoadFile=.ReadText
.Close
End With
End function
Private Function SaveFile(ByVal strBody,ByVal File)
Dim objStream
Dim RText
RText=""
Set objStream = Server.CreateObject("ADODB.Stream")
If Err Then
RText=array(Err.Number,Err.Description)
Err.Clear
exit function
End If
With objStream
.Type = 2
.Open
.Charset = "utf-8"
.Position = objStream.Size
.WriteText = strBody
.SaveToFile Server.MapPath(File),2
.Close
End With
RText="ok"
SaveFile=RText
Set objStream = Nothing
End Function
Private Function replaceStr(FileName,IntStr,FinStr)
Dim loadStr
loadStr=LoadFile(FileName)
if instr(loadStr,IntStr)<>0 then
SaveFile loadStr,FileName&".wbc_backup" 'backup!
loadStr=replace(loadStr,IntStr,FinStr)
SaveFile loadStr,FileName
replaceStr=true
Else
replaceStr=false
End if
loadStr=""
End Function
Private Function DeleteFile(FilePath)
Dim FSO
Set FSO=Server.CreateObject("Scripting.FileSystemObject")
IF FSO.FileExists(server.mapPath(FilePath)) Then
FSO.DeleteFile server.mapPath(FilePath),True
DeleteFile = True
Else
DeleteFile = false
End IF
Set FSO = Nothing
End Function
Function ReBulid()
Dim LoadArticle,LogLen
LogLen=0
Set LoadArticle=conn.Execute("Select log_ID FROM blog_Content")
Do Until LoadArticle.eof
PostArticle LoadArticle("log_ID")
LogLen=LogLen+1
LoadArticle.movenext
Loop
response.write "共转换 "&LogLen&" 篇日志到文件!<br> "
End Function
If request("act")="go" then
'=====Start============
Dim TempStr,result,aspOpen,aspClz,Er
Er=""
result=""
aspOpen=chr(60)&chr(37)
aspClz=chr(37)&chr(62)
if not replaceStr ("wbc_getarticle.asp","blogDB/wbc.mdb",AccessFile) then Er="更改數據庫地址錯誤!<br>"
if Er="" then
result=replaceStr("article.asp","<!–#include file=""footer.asp"" –>","<script language=""javascript"" type=""text/javascript"" src=""ajaxJS.js""></script>"&vbcrlf&_
"<script language=""javascript"" type=""text/javascript"">"&vbcrlf&_
" getdata('wbc_getarticle.asp?id="&aspOpen&"=id"&aspClz&"','wbc_tag','wbc_tag');"&vbcrlf&_
"</script>"&vbcrlf&"<!–#include file=""footer.asp"" –>")
if not result then Er=Er&"更改article.asp錯誤!<br>"
End if
If Er="" then
result=replaceStr("Template/Article.asp","<$log_tag$><br/>","<$log_tag$><br/>"&vbcrlf&_
"<!–Add By WBC –>"&vbcrlf&_
"<img src=""images/tag.gif"" style=""margin:4px 2px -4px 0px"" alt=""""/><strong>相关日志:</strong><br/>"&vbcrlf&_
"<div class=""Content-body"" id=""wbc_tag""></div><br/>"&vbcrlf&_
"<!–End By WBC –>")
if not result then Er=Er&"更改Template/Article.asp錯誤!<br>"
End if
If Er="" then
result=replaceStr("class/cls_article.asp",aspOpen&"=getTag.filterHTML(log_ViewArr(19,0))"&aspClz&"<br/>",aspOpen&"=getTag.filterHTML(log_ViewArr(19,0))"&aspClz&"<br/>"&vbcrlf&_
"<!–Add By WBC –>"&vbcrlf&_
"<img src=""images/tag.gif"" style=""margin:4px 2px -4px 0px"" alt=""""/><font color=red><strong>您可能还对下面的文章感兴趣:</strong></font><br/>"&vbcrlf&_
"<div class=""Content-body"" id=""wbc_tag""></div><br/>"&vbcrlf&_
"<!–End By WBC –>")
if not result then Er=Er&"更改Template/Article.asp錯誤!<br>"
End if
If Er<>"" then
response.write Er&"<br>如果未能解決請到<a href='HTTP://lzw.me' target='_blank'>HTTP://wbc.bkkss.com</a>留言。"
Else
if blog_postFile then ReBulid()
if not DeleteFile("wbc_update.asp") then
response.write "請手動刪除wbc_update.asp文件!!!<br>"
Else
response.write "wbc_update.asp文件已自動刪除!!!<br>"
End if
Response.write "更新完成!!!!<br>所有更新文件都有備份!名為:原文件名.wbc_backup<br>本文件已自動刪除!"
End if
End if
if err<>0 then
response.Write err & Err.Description & Err.Source
End if
%>
<!–#include file="footer.asp" –>
以上三个文件保存在根目录内,然后运行:
你的域名/WBC_Update.asp 这个文件,会自动安装到你的博客中,同时所有修改了的文件都进行了备份,备份名为你的文件名+.wbc_backup。如果发生冲突可以还原。
以上提供的是第一种方式的(以本文TAG标签关联其他文章标题),提供了自动安装功能,只需将包内的文件解压放在PJBLOG的目录。如果大家想用第二种方式,那么先按照上面方法进行安装,然后进行如下操作:
修改文件:打开pjblog根目录下的wbc_getarticle.asp,找到以下代码
tagstr=tagstr+"log_Title like '%"&rsT(0)&"%' or "
替换为
tagstr=tagstr+"log_tag like '%"+wbc_tag(i)+"}"+"%' or "
即可改为第二种方式。