欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

pjblog的ubbcodeasp文件

程序员文章站 2022-07-02 20:39:22
复制代码 代码如下: <%'===========pblog2 ubb代码转换代码=========='     ...
复制代码 代码如下:

<%
'===========pblog2 ubb代码转换代码==========
'      author:puterjam
'         copryright pblog2
'         update: 2005-12-29
'===========================================
function ubbcode(byval strcontent,dissm,disubb,disimg,autourl,autokey)
 if isempty(strcontent) or isnull(strcontent) then
        exit function
 else
  dim re, strmatchs, strmatch, rndid,tmpstr1,tmpstr2,tmpstr3,tmpstr4
  set re=new regexp
  re.ignorecase =true
  re.global=true
  if autourl=1 then
   re.pattern="([^=\]][\s]*?|^)(http|https|rstp|ftp|mms|ed2k)://([a-za-z0-9\.\/=\?%\-_~`@':+!]*)"
   set strmatchs=re.execute(strcontent)
   for each strmatch in strmatchs
    tmpstr1=strmatch.submatches(0)
    tmpstr2=strmatch.submatches(1)
    tmpstr3=checkurl(strmatch.submatches(2))
    strcontent=replace(strcontent,strmatch.value,tmpstr1&"<a href="""&tmpstr2&"://"&tmpstr3&""" target=""_blank"">"&tmpstr2&"://"&tmpstr3&"</a>",1,-1,0)
   next
   're.pattern="(^|\s)(www\.\s+)"
   'strcontent=re.replace(strcontent,"$1<a href=""http://$2"" target=""_blank"">$2</a>")
  end if

  if not disubb=1 then
   if not disimg=1 then
             re.pattern="(\[img\])(.[^\]]*)\[\/img\]"
     set strmatchs=re.execute(strcontent)
     for each strmatch in strmatchs
      tmpstr1=(strmatch.submatches(1))
      strcontent=replace(strcontent,strmatch.value,"<img src="""&tmpstr1&""" border=""0"" alt=""""/>",1,-1,0)
     next

             re.pattern="\[img=(left|right|center|absmiddle|)\](.[^\]]*)(\[\/img\])"
     set strmatchs=re.execute(strcontent)
     for each strmatch in strmatchs
      tmpstr1=strmatch.submatches(0)
      tmpstr2=checkurl(strmatch.submatches(1))
      strcontent=replace(strcontent,strmatch.value,"<img align="""&tmpstr1&""" src="""&tmpstr2&""" border=""0"" alt=""""/>",1,-1,0)
     next

             re.pattern="\[img=(\d*|),(\d*|)\](.[^\]]*)\[\/img\]"
     set strmatchs=re.execute(strcontent)
     for each strmatch in strmatchs
      tmpstr1=strmatch.submatches(0)
      tmpstr2=strmatch.submatches(1)
      tmpstr3=checkurl(strmatch.submatches(2))
      strcontent=replace(strcontent,strmatch.value,"<img width="""&tmpstr1&""" height="""&tmpstr2&""" src="""&tmpstr3&""" border=""0"" alt=""""/>",1,-1,0)
     next

             re.pattern="\[img=(\d*|),(\d*|),(left|right|center|absmiddle|)\](.[^\]]*)(\[\/img\])"
     set strmatchs=re.execute(strcontent)
     for each strmatch in strmatchs
      tmpstr1=strmatch.submatches(0)
      tmpstr2=strmatch.submatches(1)
      tmpstr3=strmatch.submatches(2)
      tmpstr4=checkurl(strmatch.submatches(3))
      strcontent=replace(strcontent,strmatch.value,"<img width="""&tmpstr1&""" height="""&tmpstr2&""" align="""&tmpstr3&""" src="""&tmpstr4&""" border=""0"" alt=""""/>",1,-1,0)
     next
    else
             re.pattern="(\[img\])(.[^\]]*)\[\/img\]"
     set strmatchs=re.execute(strcontent)
     for each strmatch in strmatchs
      tmpstr1=checkurl(strmatch.submatches(1))
      strcontent=replace(strcontent,strmatch.value,"<a href="""&tmpstr1&""" target=""_blank"" title="""&tmpstr1&"""><img src=""images/image.gif"" alt="""" style=""margin:0px 2px -3px 0px"" border=""0""/>查看图片</a>",1,-1,0)
     next

             re.pattern="\[img=(left|right|center|absmiddle|)\](.[^\]]*)(\[\/img\])"
     set strmatchs=re.execute(strcontent)
     for each strmatch in strmatchs
      tmpstr1=strmatch.submatches(0)
      tmpstr2=checkurl(strmatch.submatches(1))
      strcontent=replace(strcontent,strmatch.value,"<a href="""&tmpstr2&""" target=""_blank"" title="""&tmpstr2&"""><img src=""images/image.gif"" alt="""" style=""margin:0px 2px -3px 0px"" border=""0""/>查看图片</a>",1,-1,0)
     next

             re.pattern="\[img=(\d*|),(\d*|)\](.[^\]]*)\[\/img\]"
     set strmatchs=re.execute(strcontent)
     for each strmatch in strmatchs
      tmpstr1=strmatch.submatches(0)
      tmpstr2=strmatch.submatches(1)
      tmpstr3=checkurl(strmatch.submatches(2))
      strcontent=replace(strcontent,strmatch.value,"<a href="""&tmpstr3&""" target=""_blank"" title="""&tmpstr3&"""><img src=""images/image.gif"" alt="""" style=""margin:0px 2px -3px 0px"" border=""0""/>查看图片</a>",1,-1,0)
     next

             re.pattern="\[img=(\d*|),(\d*|),(left|right|center|absmiddle|)\](.[^\]]*)(\[\/img\])"
     set strmatchs=re.execute(strcontent)
     for each strmatch in strmatchs
      tmpstr1=strmatch.submatches(0)
      tmpstr2=strmatch.submatches(1)
      tmpstr3=strmatch.submatches(2)
      tmpstr4=checkurl(strmatch.submatches(3))
      strcontent=replace(strcontent,strmatch.value,"<a href="""&tmpstr4&""" target=""_blank"" title="""&tmpstr4&"""><img src=""images/image.gif"" alt="""" style=""margin:0px 2px -3px 0px"" border=""0""/>查看图片</a>",1,-1,0)
     next    
   end if

'-----------多媒体标签----------------
   re.pattern="\[(swf|wma|wmv|rm|ra|qt)(=\d*?|)(,\d*?|)\]([^<>]*?)\[\/(swf|wma|wmv|rm|ra|qt)\]"
      set strmatchs=re.execute(strcontent)
      dim strtype,strwidth,strheight,strsrc,titletext
  for each strmatch in strmatchs
   randomize
     strtype=strmatch.submatches(0)
     if strtype="swf" then
      titletext="<img src=""images/flash.gif"" alt="""" style=""margin:0px 2px -3px 0px"" border=""0""/>flash动画"
     elseif strtype="wma" then
      titletext="<img src=""images/music.gif"" alt="""" style=""margin:0px 2px -3px 0px"" border=""0""/>播放音频文件"
     elseif strtype="wmv" then
      titletext="<img src=""images/mediaplayer.gif"" alt="""" style=""margin:0px 2px -3px 0px"" border=""0""/>播放视频文件"  
     elseif strtype="rm" then
      titletext="<img src=""images/realplayer.gif"" alt="""" style=""margin:0px 2px -3px 0px"" border=""0""/>播放real视频流文件"  
     elseif strtype="ra" then
      titletext="<img src=""images/realplayer.gif"" alt="""" style=""margin:0px 2px -3px 0px"" border=""0""/>播放real音频流文件"  
     elseif strtype="qt" then
      titletext="<img src=""images/mediaplayer.gif"" alt="""" style=""margin:0px 2px -3px 0px"" border=""0""/>播放mov视频文件"  
     end if
              strwidth=strmatch.submatches(1)
              strheight=strmatch.submatches(2)
              if (len(strwidth)=0) then
                strwidth="400"
                else
               strwidth=right(strwidth,(len(strwidth)-1))
              end if
              if (len(strheight)=0) then
               strheight="300"
                else
              strheight=right(strheight,(len(strheight)-1))
              end if
              strsrc=checkurl(strmatch.submatches(3))
   rndid="temp"&int(100000 * rnd)
   strcontent= replace(strcontent,strmatch.value,"<div class=""ubbpanel""><div class=""ubbtitle"">"&titletext&"</div><div class=""ubbcontent""><a id="""+rndid+"_href"" href=""javascript:mediashow('"+strtype+"','"+rndid+"','"+strsrc+"','"+strwidth+"','"+strheight+"')""><img name="""+rndid+"_img"" src=""images/mm_snd.gif"" style=""margin:0px 3px -2px 0px"" border=""0"" alt=""""/><span id="""+rndid+"_text"">在线播放</span></a><div id="""+rndid+"""></div></div></div>")
  next
  set strmatchs=nothing
  re.pattern="(\[mid\])(.[^\]]*)\[\/mid\]"
  strcontent= re.replace(strcontent,"<embed src=""$2"" height=""45"" width=""314"" autostart=""0""></embed>") 
'-----------常规标签----------------
   re.pattern = "\[url=(.[^\]]*)\](.[^\[]*)\[\/url]"
   set strmatchs=re.execute(strcontent)
   for each strmatch in strmatchs
    tmpstr1=checkurl(strmatch.submatches(0))
    tmpstr2=strmatch.submatches(1)
    strcontent=replace(strcontent,strmatch.value,"<a target=""_blank"" href="""&tmpstr1&""">"&tmpstr2&"</a>",1,-1,0)
   next

   re.pattern = "\[url](.[^\[]*)\[\/url]"
   set strmatchs=re.execute(strcontent)
   for each strmatch in strmatchs
    tmpstr1=checkurl(strmatch.submatches(0))
    strcontent=replace(strcontent,strmatch.value,"<a target=""_blank"" href="""&tmpstr1&""">"&tmpstr1&"</a>",1,-1,0)
   next

   re.pattern = "\[ed2k=([^\r]*?)\]([^\r]*?)\[\/ed2k]"
   set strmatchs=re.execute(strcontent)
   for each strmatch in strmatchs
    tmpstr1=checkurl(strmatch.submatches(0))
    tmpstr2=strmatch.submatches(1)
    strcontent=replace(strcontent,strmatch.value,"<img border="""" src=""images/ed2k.gif"" alt=""""/><a target=""_blank"" href="""&tmpstr1&""">"&tmpstr2&"</a>",1,-1,0)
   next

   re.pattern = "\[ed2k]([^\r]*?)\[\/ed2k]"
   set strmatchs=re.execute(strcontent)
   for each strmatch in strmatchs
    tmpstr1=checkurl(strmatch.submatches(0))
    strcontent=replace(strcontent,strmatch.value,"<img border="""" src=""images/ed2k.gif"" alt=""""/><a target=""_blank"" href="""&tmpstr1&""">"&tmpstr1&"</a>",1,-1,0)
   next

   re.pattern = "\[email=(.[^\]]*)\](.[^\[]*)\[\/email]"
   set strmatchs=re.execute(strcontent)
   for each strmatch in strmatchs
    tmpstr1=checkurl(strmatch.submatches(0))
    tmpstr2=strmatch.submatches(1)
    strcontent=replace(strcontent,strmatch.value,"<a href=""mailto:"&tmpstr1&""">"&tmpstr2&"</a>",1,-1,0)
   next

   
   re.pattern = "\[email](.[^\[]*)\[\/email]"
   set strmatchs=re.execute(strcontent)
   for each strmatch in strmatchs
    tmpstr1=checkurl(strmatch.submatches(0))
    strcontent=replace(strcontent,strmatch.value,"<a href=""mailto:"&tmpstr1&""">"&tmpstr1&"</a>",1,-1,0)
   next

'-----------字体格式----------------
      re.pattern="\[align=(\w{4,6})\]([^\r]*?)\[\/align\]"
   strcontent=re.replace(strcontent,"<div align=""$1"">$2</div>")
        re.pattern="\[color=(#\w{3,10}|\w{3,10})\]([^\r]*?)\[\/color\]"
   strcontent=re.replace(strcontent,"<span style=""color:$1"">$2</span>")
      re.pattern="\[size=(\d{1,2})\]([^\r]*?)\[\/size\]"
   strcontent=re.replace(strcontent,"<span style=""font-size:$1pt"">$2</span>")
      re.pattern="\[font=([^\r]*?)\]([^\r]*?)\[\/font\]"
   strcontent=re.replace(strcontent,"<span style=""font-family:$1"">$2</span>")
   re.pattern="\[b\]([^\r]*?)\[\/b\]"
   strcontent=re.replace(strcontent,"<strong>$1</strong>")
      re.pattern="\[i\]([^\r]*?)\[\/i\]"
   strcontent=re.replace(strcontent,"<i>$1</i>")
      re.pattern="\[u\]([^\r]*?)\[\/u\]"
   strcontent=re.replace(strcontent,"<u>$1</u>")
      re.pattern="\[s\]([^\r]*?)\[\/s\]"
   strcontent=re.replace(strcontent,"<s>$1</s>")
      re.pattern="\[sup\]([^\r]*?)\[\/sup\]"
   strcontent=re.replace(strcontent,"<sup>$1</sup>")
      re.pattern="\[sub\]([^\r]*?)\[\/sub\]"
   strcontent=re.replace(strcontent,"<sub>$1</sub>")
      re.pattern="\[fly\]([^\r]*?)\[\/fly\]"
   strcontent=re.replace(strcontent,"<marquee width=""90%"" behavior=""alternate"" scrollamount=""3"">$1</marquee>")

  end if

'-----------特殊标签----------------
  re.pattern = "\[down=(.[^\]]*)\](.[^\[]*)\[\/down]"
  set strmatchs=re.execute(strcontent)
  for each strmatch in strmatchs
   tmpstr1=checkurl(strmatch.submatches(0))
   tmpstr2=strmatch.submatches(1)
   strcontent=replace(strcontent,strmatch.value,"<img src=""images/download.gif"" alt=""下载文件"" style=""margin:0px 2px -4px 0px""/> <a href="""&tmpstr1&""" target=""_blank"">"&tmpstr2&"</a>",1,-1,0)
  next  

  re.pattern = "\[down\](.[^\[]*)\[\/down]"
  set strmatchs=re.execute(strcontent)
  for each strmatch in strmatchs
   tmpstr1=checkurl(strmatch.submatches(0))
   strcontent=replace(strcontent,strmatch.value,"<img src=""images/download.gif"" alt=""下载文件"" style=""margin:0px 2px -4px 0px""/> <a href="""&tmpstr1&""" target=""_blank"">下载此文件</a>",1,-1,0)
  next

  re.pattern = "\[mdown=(.[^\]]*)\](.[^\[]*)\[\/mdown]"
  set strmatchs=re.execute(strcontent)
  for each strmatch in strmatchs
   tmpstr1=checkurl(strmatch.submatches(0))
   tmpstr2=strmatch.submatches(1)
   if len(memname)>0 then
    strcontent=replace(strcontent,strmatch.value,"<img src=""images/download.gif"" alt=""下载文件"" style=""margin:0px 2px -4px 0px""/> <a href="""&tmpstr1&""" target=""_blank"">"&tmpstr2&"</a>",1,-1,0)
    else
    strcontent=replace(strcontent,strmatch.value,"<img src=""images/download.gif"" alt=""只允许会员下载"" style=""margin:0px 2px -4px 0px""/> 该文件只允许会员下载! <a href=""login.asp"">登录</a> | <a href=""register.asp"">注册</a>",1,-1,0)
   end if
  next

  re.pattern = "\[mdown\](.[^\[]*)\[\/mdown]"
  set strmatchs=re.execute(strcontent)
  for each strmatch in strmatchs
   tmpstr1=checkurl(strmatch.submatches(0))
   if len(memname)>0 then
    strcontent=replace(strcontent,strmatch.value,"<img src=""images/download.gif"" alt=""下载文件"" style=""margin:0px 2px -4px 0px""/> <a href="""&tmpstr1&""" target=""_blank"">下载此文件</a>",1,-1,0)
    else
    strcontent=replace(strcontent,strmatch.value,"<img src=""images/download.gif"" alt=""只允许会员下载"" style=""margin:0px 2px -4px 0px""/> 该文件只允许会员下载! <a href=""login.asp"">登录</a> | <a href=""register.asp"">注册</a>",1,-1,0)
   end if
  next

 


  re.pattern="\[code\](.*?)\[\/code\]"
  strcontent= re.replace(strcontent,"<div class=""ubbpanel""><div class=""ubbtitle""><img src=""images/code.gif"" style=""margin:0px 2px -3px 0px"" alt=""程序代码""/> 程序代码</div><div class=""ubbcontent"">$1</div></div>")

  re.pattern="\[quote\](.*?)\[\/quote\]"
  strcontent= re.replace(strcontent,"<div class=""ubbpanel""><div class=""ubbtitle""><img src=""images/quote.gif"" style=""margin:0px 2px -3px 0px"" alt=""引用内容""/> 引用内容</div><div class=""ubbcontent"">$1</div></div>")
  re.pattern="\[quote=(.[^\]]*)\](.*?)\[\/quote\]"
  strcontent= re.replace(strcontent,"<div class=""ubbpanel""><div class=""ubbtitle""><img src=""images/quote.gif"" style=""margin:0px 2px -3px 0px"" alt=""引用来自 $1""/> 引用来自 $1</div><div class=""ubbcontent"">$2</div></div>")

  re.pattern="\[hidden\](.*?)\[\/hidden\]"
  if len(memname)>0 then  
   strcontent= re.replace(strcontent,"<div class=""ubbpanel""><div class=""ubbtitle""><img src=""images/quote.gif"" style=""margin:0px 2px -3px 0px"" alt=""显示被隐藏内容""/> 显示被隐藏内容</div><div class=""ubbcontent"">$1</div></div>")
   else
   strcontent= re.replace(strcontent,"<div class=""ubbpanel""><div class=""ubbtitle""><img src=""images/quote.gif"" style=""margin:0px 2px -3px 0px"" alt=""隐藏内容""/> 隐藏内容</div><div class=""ubbcontent"">该内容已经被作者隐藏,只有会员才允许查阅 <a href=""login.asp"">登录</a> | <a href=""register.asp"">注册</a></div></div>")
  end if

  re.pattern="\[hidden=(.[^\]]*)\](.*?)\[\/hidden\]"
  if len(memname)>0 then  
   strcontent= re.replace(strcontent,"<div class=""ubbpanel""><div class=""ubbtitle""><img src=""images/quote.gif"" style=""margin:0px 2px -3px 0px"" alt=""显示被隐藏内容 $1""/> 显示被隐藏内容来自 $1</div><div class=""ubbcontent"">$2</div></div>")
   else
   strcontent= re.replace(strcontent,"<div class=""ubbpanel""><div class=""ubbtitle""><img src=""images/quote.gif"" style=""margin:0px 2px -3px 0px"" alt=""隐藏内容 $1""/> 隐藏内容</div><div class=""ubbcontent"">该内容已经被作者隐藏,只有会员才允许查阅 <a href=""login.asp"">登录</a> | <a href=""register.asp"">注册</a></div></div>")
  end if

  re.pattern="\[html\](.*?)\[\/html\]"
  set strmatchs=re.execute(strcontent)
  for each strmatch in strmatchs
   randomize
   rndid="temp"&int(100000 * rnd)
   strcontent=replace(strcontent,strmatch.value,"<div class=""ubbpanel""><div class=""ubbtitle""><img src=""images/html.gif"" style=""margin:0px 2px -3px 0px""> html代码</div><div class=""ubbcontent""><textarea rows=""8"" id="""&rndid&""">"&ubbfilter(htmldecode(strmatch.submatches(0)))& "</textarea><br/><input onclick=""runex('"&rndid&"')""  type=""button"" value=""运行此代码""/> <input onclick=""docopy('"&rndid&"')""  type=""button"" value=""复制此代码""/><br/> [ctrl+a 全部选择 提示:你可先修改部分代码,再按运行]</div></div>",1,-1,0)
  next
  set strmatchs=nothing
'-----------list标签----------------
   strcontent = replace(strcontent,"[list]","<ul>")
   re.pattern = "\[list=(.[^\]]*)\]"
   strcontent = re.replace(strcontent,"<ul style=""list-style-type:$1"">")
   re.pattern = "\[\*\](.[^\[]*)(\n|)"
   strcontent = re.replace(strcontent,"<li>$1</li>")
   strcontent = replace(strcontent,"[/list]","</ul>")

'-----------表情图标----------------
  if not dissm=1 then
   dim log_smilies,log_smiliescontent
   for each log_smilies in arr_smilies
    log_smiliescontent=split(log_smilies,"|")
    strcontent=replace(strcontent,log_smiliescontent(2)," <img src=""images/smilies/"&log_smiliescontent(1)&""" border=""0"" style=""margin:0px 0px -2px 0px"" alt=""""/>")
   next
  end if

'-----------关键词识别----------------
  if autokey=1 then
   dim log_keywords,log_keywordscontent
   for each log_keywords in arr_keywords
    log_keywordscontent=split(log_keywords,"$|$")
    if log_keywordscontent(3)<>"none" then
     strcontent=replace(strcontent,log_keywordscontent(1),"<a href="""&log_keywordscontent(2)&""" target=""_blank""><img src=""images/keywords/"&log_keywordscontent(3)&""" border=""0"" alt=""""/> "&log_keywordscontent(1)&"</a>")
    else
     strcontent=replace(strcontent,log_keywordscontent(1),"<a href="""&log_keywordscontent(2)&""" target=""_blank"">"&log_keywordscontent(1)&"</a>")
    end if
   next
  end if

  set re=nothing

  ubbcode=strcontent
 end if
end function
%>