您的位置: 网站首页 > 编程乐园, 网站网页 > 阅读文章

Pjblog教程-防止出错,全手工来为我们的Pjblog添加相关日志

pjblog  PJBlog的相关日志插件很早就出来了,但是是一个插件,使用此插件会自动修改几个PJ文件里的内容。而我的PJBLOG本身已经被我修改了多处,使用此插件后会不会出错呢?有点小小地担心,于是我决定把插件代码读懂,这样就知道如何手工进行修改了,呵呵~~哈哈

      先下载相关日志插件,我下载的是WBC相关日志插件的优化版,比最早出来的那个代码有些不一样。

手工修改方法如下:

1、编辑文件article.asp:
找到最后一行代码:
<!–#include file=”footer.asp” –>
在其之前插入如下代码:

<script language=”javascript” type=”text/javascript” src=”ajaxJS.js”></script>
<script language=”javascript” type=”text/javascript”>
getdata(‘wbc_getarticle.asp?id=<%=id%>’,'wbc_tag’,'wbc_tag’);
</script>
2、编辑class文件夹下的cls_article.asp,
找到
<img src=”images/tag.gif” style=”margin:4px 2px -4px 0px” alt=”"/><strong>Tags:</strong> <%=getTag.filterHTML(log_ViewArr(19,0))%><br/>

在这一句下面添加:
<img src=”images/tag.gif” style=”margin:4px 2px -4px 0px” alt=”"/><strong>相关日志:</strong><br/>
<div id=”wbc_tag”></div><br/>
3、静态日志模式下,编辑Template文件夹下的Article.asp
找到如下代码:
<img src=”images/icon_trackback.gif” style=”margin:0px 2px -4px 0px” alt=”"/><strong>引用通告地址:</strong> <a href=”<$trackback$>”
target=”_blank”><$trackback$></a><br/>
<img src=”images/tag.gif” style=”margin:4px 2px -4px 0px” alt=”"/><strong>Tags:</strong> <$log_tag$><br/>

在其下面加入:
<img src=”images/tag.gif” style=”margin:4px 2px -4px 0px” alt=”"/><strong>相关日志:</strong><br/>
<div id=”wbc_tag”></div><br/>

4、将如下代码保存为ajaxJS.js文件,放到PJBLOG根目录下:
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);
                       
                    }
                }
           
        }
}
5、将以下代码保存为wbc_getarticle.asp文件,放到PJBLOG根目录下:
<%@ 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” ‘<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<+================//这里要特别注意,必须改成你PJBLOG的数据库路径。
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,tagstr,tagname
    Set Rs=conn.execute(“Select log_tag from blog_Content where log_ID=”&id&”")
    if not Rs.eof then
        tagname=rs(“log_tag”)
    else
        tagname=”"
    end if
    Rs.close
    set rs=nothing
    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 tagname<>”" then
        wbc_tag=tagname
    if wbc_tag<>”" then
        wbc_tag=split(wbc_tag,”}”)
    i=0
    i2=0
    ‘find total
    tagstr=”"
    for i=0 to ubound(wbc_tag)-1
        set rsT=conn.execute(“select tag_name from blog_tag where tag_id=”&replace(wbc_tag(i),”{“,”"))
        tagstr=tagstr+”log_Title like ‘%”&rsT(0)&”%’ or ”
    next
    if tagstr<>”" then
        tagstr=”where “&left(tagstr,len(tagstr)-3)
    end if
    Set RsT=server.CreateObject(“adodb.recordset”)
    RsT.open “Select log_ID from blog_Content “&tagstr& ” and log_ID<>”&id,conn,1,1
    if not RsT.eof then
        total_rela=Rst.recordcount
    End if
   
    Set RsT=nothing
    ‘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
            Set RsT=conn.execute(“Select log_Title,log_id,log_ViewNums from blog_Content “&tagstr& ” 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
        End if
    End if
    output=output&pagestr
    If Ifmore or thispage<>1 then
        OutPut=OutPut&”<br/><strong>模式:</strong> <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>模式:</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
end if
%>
在此文件里我已经把繁体中文修改成了简体中文。

如果你懒得复制代码, 点击这里下载ajaxJS.js和wbc_getarticle.asp。
最后还可以把这个插件进行优化修改,现在这样的修改是以本文TAG标签关联其他文章标题的。

我不喜欢这样,我把它修改成以本文TAG标签关联其他文章TAG的。
修改文件:打开wbc_getarticle.asp,找到以下代码
  tagstr=tagstr+”log_Title like ‘%”&rsT(0)&”%’ or ”
替换为
  tagstr=tagstr+”log_tag like ‘%”+wbc_tag(i)+”}”+”%’ or ”

附件里的wbc_getarticle.asp为后一种修改法。

修改完成了,效果见本站!

  • 属于分类: 编程乐园, 网站网页
  • 本文标签:
  • 人气指数: 3,846
  • 文章作者: 野球小子
  • 生产日期: 2007年12月29日 - 11时16分12秒
看看还有没有您感兴趣的:

  • 您的大名(必填)
  • E-Mail (必填)
  • 您的网站(有的话就写一下吧~)
  • 评论内容:(必填)