« ax-upload使用介绍(带进度条的文件上传)让你的windows XP可以自动登陆 »

解决Z-blog中的tag含有空格的问题

z-blog占据了国内中文个人博客的半壁江山,它的易用性以及友好的模板设置和对SEO的优化吸引了大量的博客爱好者,对于普通的个人博客来说,Zblog已经很完美了,如果要打造个性化的个人博客,也许还有一些地方值得改进,特别是在做英文站时,发现了zblog一个很大的弊端,那就是zblog不能设置含有空格的tag(因为Zblog是用空格来区分多个tag的),起初我用"-"应付了一下,后来发现这样的tag越来越多,对SEO和用户的视觉会有很大影响,因此,痛下决心,花了一个小时,将这个问题解决了。分享一下经验.

大部分博客程序都是用";"来区分多个tag的,我也采取了这种分割的方式,需要对zblog中几个源文件进行修改,由于危险性比较大,在您修改之前请一定先做备份,否则,后果自负哦!

第一处修改:

文件名:c_function.asp

在Function TransferHTML(source,para)
增加如下的一段代码:

If Instr(para,"[normaltag]")>0  Then
  source=Replace(source,"$","")
  source=Replace(source,"(","")
  source=Replace(source,")","")
  source=Replace(source,"*","")
  source=Replace(source,"+","")
  source=Replace(source,",","")
  source=Replace(source,"[","")
  source=Replace(source,"]","")
  source=Replace(source,"{","")
  source=Replace(source,"}","")
  source=Replace(source,"?","")
  source=Replace(source,"\","")
  source=Replace(source,"^","")
  source=Replace(source,"|","")
  source=Replace(source,":","")
  source=Replace(source,"""","")
 End If

 该代码是将用户输入的tag中含有的特殊符号替换成空格,注意,这里没有对";"进行处理。

第二处修改:这里是比较关键的修改,将原来使用空格分割tag的处理变为

文件名:c_function.asp

将Function ParseTag(strTag)修改为

 Dim s
 Dim t
 Dim i
 Dim Tag
 Dim b
 Dim objTag

 strTag=Trim(strTag)
 strTag=TransferHTML(strTag,"[normaltag]")
 t=Split(strTag,",")

 GetTags()
 For i=LBound(t) To UBound(t)
  t(i) = Trim(t(i))'下面几行都是去掉多余的空格 by http://www.ajaxstu.com
  t(i) = replace(t(i),"    "," ")
  t(i) = replace(t(i),"   "," ")
  t(i) = replace(t(i),"  "," ")
  b=False

  For Each Tag in Tags
   If IsObject(Tag) Then
    If UCase(Tag.Name)=UCase(t(i)) Then
     b=True
    End If
   End If
  Next

  If b=False Then
   Set objTag=New TTag
   objTag.ID=0
   objTag.Name=t(i)
   objTag.Order=0
   objTag.Intro=""
   objTag.Post
   Set objTag=Nothing
  End If

 Next

 GetTags()
 For i=LBound(t) To UBound(t)
  For Each Tag in Tags
   If IsObject(Tag) Then
    If UCase(Tag.Name)=UCase(t(i)) Then
     t(i)="{"&Tag.ID&"}"
    End If
   End If
  Next
 Next

 s=Join(t)
 s=Replace(s," ","")

 ParseTag=s

第三处修改:

文件名:c_system_lib.asp

Public Property Get TagToName

  Dim t,i,s

  If Tag<>"" Then
   s=Tag
   s=Replace(s,"}","")
   t=Split(s,"{")

   For i=LBound(t) To UBound(t)
    If t(i)<>"" Then
     If IsEmpty(FirstTagIntro) Then FirstTagIntro=Tags(t(i)).Intro
     t(i)=Tags(t(i)).Name
    End If
   Next

   s=Trim(Join(t,","))
   
   If(instr(s,",")=1)Then  '去掉第一个,
    s=right(s,len(s)-1)
   End If
   
   If s=" " Then s=""
   TagToName=s
  End If

 End Property

第四处修改:

文件名:edit_fckeditor.asp

将最后的javascript改为:

function AddKey(i) {
  var strKey=document.getElementById("edtTag").value;
  var strNow;
  if (strKey.length < 1)
  {
    strNow=i
  }
  else strNow=","+i

 

  if(strKey.indexOf(strNow)==-1){
   strKey=strKey+strNow;
  }
  document.getElementById("edtTag").value=strKey;
 }

 

该处修改是实现在编辑文章时如果选择多个已有的tag,自动将tag之间用";"分开。

程序中的几个文件下载地址:

code.rar

可能这几个文件中我不止修改了上面描述的几处,请尽量自己根据需要修改,不要盲目的覆盖,如果升级的话可能会影响功能。

原创文章如转载,请注明:转载自悠悠博客 [ http://www.ajaxstu.com/ ]

相关文章:

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。