<%
Const MaxLoopcount=50
function ubb_htm(bod)h=2为转换帖,h=1为转换签名
Set re=new RegExp 声明正则表达式对象
re.IgnoreCase =true 设置是否区分字符大小写
re.Global=True 设置全区可用性
re.pattern 设置模式
bod = dvHTMLEncode(bod)
re.Pattern="(javascript)"
bod=re.Replace(bod,"<I>javascript</I>")
re.Pattern="(jscript:)"
bod=re.Replace(bod,"<I>jscript:</I>")
re.Pattern="(js:)"
bod=re.Replace(bod,"<I>js:</I>")
re.Pattern="(value)"
bod=re.Replace(bod,"<I>value</I>")
re.Pattern="(about:)"
bod=re.Replace(bod,"<I>about:</I>")
re.Pattern="(file:)"
bod=re.Replace(bod,"<I>file:</I>")
re.Pattern="(document.cookie)"
bod=re.Replace(bod,"<I>documents.cookie</I>")
re.Pattern="(vbscript:)"
bod=re.Replace(bod,"<I>vbscript:</I>")
re.Pattern="(vbs:)"
bod=re.Replace(bod,"<I>vbs:</I>")
re.Pattern="(on(mouse|exit|error|click|key))"
bod=re.Replace(bod,"<I>on$2</I>")
常用标签
re.Pattern="(\[humor)([\d]+)(\])"
bod=re.replace(bod,"<img src=""images/emot/$2.gif"" border=""0"">")
re.Pattern="\[QUOTE\](.*)\[\/QUOTE\]"
bod=re.Replace(bod,"<table style=""border-collapse:collapse;width:100%"" bordercolor=""#6595D6"" cellpadding=5 cellspacing=0 border=1><tr><td bgcolor=""#E4E8EF"" width=""100%"">$1</td></tr></table>")
re.Pattern="\[center\](.+)\[\/center\]"
bod=re.Replace(bod,"<center>$1</center>")
re.Pattern="\[i\](.+)\[\/i\]"
bod=re.Replace(bod,"<i>$1</i>")
re.Pattern="\[u\](.+)(\[\/u\])"
bod=re.Replace(bod,"<u>$1</u>")
re.Pattern="\[b\](.+)(\[\/b\])"
bod=re.Replace(bod,"<b>$1</b>")
re.Pattern="\[size=([1-8])\](.+)\[\/size\]"
bod=re.Replace(bod,"<font size=$1>$2</font>")
re.Pattern="\[face=(.[^\[]*)\](.+)\[\/face\]"
bod=re.Replace(bod,"<font face=$1>$2</font>")
re.Pattern="\[color=(.[^\[]*)\](.+)\[\/color\]"
bod=re.Replace(bod,"<font color=$1>$2</font>")
re.Pattern="\[align=(center|left|right)\](.+)\[\/align\]"
bod=re.Replace(bod,"<div align=$1>$2</div>")
re.Pattern = "\[url=(.[^\]]*)\](.[^\[]*)\[\/url]"
bod = re.Replace(bod,"<img align=absmiddle src=image/url.gif border=0><a target=_blank style=font-size:9pt href=$1>$2</a>")
re.Pattern = "\[url](.[^\[]*)\[\/url]"
bod = re.Replace(bod,"<img align=absmiddle src=image/url.gif border=0><a target=_blank style=font-size:9pt href=$1>$1</a>")
re.Pattern = "\[email=(.[^\]]*)\](.[^\[]*)\[\/email]"
bod = re.Replace(bod,"<img src=image\email.gif align=absmiddle border=0><a href=$1 style=font-size:9pt>$2</a>")
re.Pattern = "\[email](.[^\[]*)\[\/email]"
bod = re.Replace(bod,"<img src=image\email.gif align=absmiddle border=0><a href=mailto:$1 style=font-size:9pt>$1</a>")
re.Pattern="\[fly\](.*)\[\/fly\]"
bod=re.Replace(bod,"<marquee width=90% behavior=alternate scrollamount=3>$1</marquee>")
re.Pattern="\[move\](.*)\[\/move\]"
bod=re.Replace(bod,"<MARQUEE scrollamount=3>$1</marquee>")
re.Pattern="\[SHADOW=*([0-9]*),*(#*[a-z0-9]*),*([0-9]*)\](.[^\[]*)\[\/SHADOW]"
bod=re.Replace(bod,"<table width=$1 ><tr><td style=""filter:shadow(color=$2, strength=$3)"">$4</td></tr></table>")
re.Pattern="\[GLOW=*([0-9]*),*(#*[a-z0-9]*),*([0-9]*)\](.[^\[]*)\[\/GLOW]"
bod=re.Replace(bod,"<table width=$1 ><tr><td style=""filter:glow(color=$2, strength=$3)"">$4</td></tr></table>")
多媒体标签
re.Pattern="\[QT=*([0-9]*),*([0-9]*)\](.[^\[]*)\[\/QT]"
bod=re.Replace(bod,"<embed src=$3 width=$1 height=$2 autoplay=true loop=false controller=true playeveryframe=false cache=false scale=TOFIT bgcolor=#000000 kioskmode=false targetcache=false pluginspage=http://www.apple.com/quicktime/>")
re.Pattern="\[MP=*([0-9]*),*([0-9]*)\](.[^\[]*)\[\/MP]"
bod=re.Replace(bod,"<object align=middle classid=CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95 class=OBJECT id=MediaPlayer width=$1 height=$2 ><param name=ShowStatusBar value=-1><param name=Filename value=$3><embed type=application/x-oleobject codebase=http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701 flename=mp src=$3 width=$1 height=$2></embed></object>")
re.Pattern="\[RM=*([0-9]*),*([0-9]*)\](.[^\[]*)\[\/RM]"
bod=re.Replace(bod,"<OBJECT classid=clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA class=OBJECT id=RAOCX width=$1 height=$2><PARAM NAME=SRC VALUE=$3><PARAM NAME=CONSOLE VALUE=Clip1><PARAM NAME=CONTROLS VALUE=imagewindow><PARAM NAME=AUTOSTART VALUE=true></OBJECT><br><OBJECT classid=CLSID:CFCDAA03-8BE4-11CF-B84B-0020AFBBCCFA height=32 id=video2 width=$1><PARAM NAME=SRC VALUE=$3><PARAM NAME=AUTOSTART VALUE=-1><PARAM NAME=CONTROLS VALUE=controlpanel><PARAM NAME=CONSOLE VALUE=Clip1></OBJECT>")
re.Pattern="(\[FLASH\])(.[^\[]*)(\[\/FLASH\])"
bod= re.Replace(bod,"<a href=""$2"" TARGET=_blank style=font-size:9pt><IMG SRC=image/swf.gif border=0 alt=点击开新窗口欣赏该FLASH动画! height=16 width=16>[全屏欣赏]</a><br><OBJECT codeBase=http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=4,0,2,0 classid=clsid:D27CDB6E-AE6D-11cf-96B8-444553540000 width=500 height=400><PARAM NAME=movie VALUE=""$2""><PARAM NAME=quality VALUE=high><embed src=""$2"" quality=high pluginspage=http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash type=application/x-shockwave-flash width=500 height=400>$2</embed></OBJECT>")
re.Pattern="(\[sound\])(.[^\[]*)(\[\/sound\])"
bod=re.Replace(bod,"<a href=""$2"" target=_blank><IMG SRC=image/mid.gif border=0 alt=背景音乐></a><bgsound src=""$2"" loop=""-1"">")
图片标签
re.Pattern="\[IMG](.[^\[]*)\[\/IMG]"
bod=re.Replace(bod,"<a href=""$1"" target=blank><IMG SRC=""$1"" border=0></a>")
re.Pattern="\[UPLOAD=(gif|jpg|jpeg|bmp|png)\](.[^\[]*)(gif|jpg|jpeg|bmp|png)\[\/UPLOAD\]"
bod= re.Replace(bod,"<br>此主题相关图片如下:<br><A HREF=""$2$1"" TARGET=_blank><IMG SRC=""../$2$1"" border=0 alt=按此在新窗口浏览图片></A>")
re.Pattern="\[UPLOAD=(.[^\[]*)\](.[^\[]*)\[\/UPLOAD\]"
bod= re.Replace(bod,"<br><IMG SRC=""image/files/$1.gif"" border=0> <a href=""$2"" target=""_blank"" style=""font-size:9pt"">点击浏览该文件</a>")
自动识别www等开头的网址
re.Pattern = "^((http|https|ftp|rtsp|mms):(\/\/|\\\\)[A-Za-z0-9\./=\?%\-&_~`@[\]\:+!]+([^<>""])+)"
bod = re.Replace(bod,"<img align=absmiddle src=image/url.gif border=0><a target=_blank href=$1 style=font-size:10pt>$1</a>")
re.Pattern = "((http|https|ftp|rtsp|mms):(\/\/|\\\\)[A-Za-z0-9\./=\?%\-&_~`@[\]\:+!]+([^<>""])+)$([^\[]*)"
bod = re.Replace(bod,"<img align=absmiddle src=image/url.gif border=0><a target=_blank href=$1 style=font-size:10pt>$1</a>")
re.Pattern = "([^>=""])((http|https|ftp|rtsp|mms):(\/\/|\\\\)[A-Za-z0-9\./=\?%\-&_~`@[\]\:+!]+([^<>""])+)"
bod = re.Replace(bod,"$1<img align=absmiddle src=image/url.gif border=0><a target=_blank href=$2 style=font-size:10pt>$2</a>")
re.Pattern = "([^(http://|http:\\)])((www|cn)[.](\w)+[.]{1,}(net|com|cn|org|cc)(((\/[\~]*|\\[\~]*)(\w)+)|[.](\w)+)*(((([?](\w)+){1}[=]*))*((\w)+){1}([\&](\w)+[\=](\w)+)*)*)"
bod = re.Replace(bod,"$1<img align=absmiddle src=image/url.gif border=0><a target=_blank href=http://$2 style=font-size:10pt>$2</a>")
自动识别Email地址,如打开本功能在浏览内容很多的帖子会引起服务器停顿
re.Pattern = "([^(=)])((\w)+[@]{1}((\w)+[.]){1,3}(\w)+)"
bod = re.Replace(bod,"<img align=absmiddle src=image/url.gif border=0><a target=_blank href=""$2mailto:$2"">$2</a>")
bod=replace(bod,"<I></I>","")
bod=replace(bod,"‘","")
ubb_htm=bbimg(bod,500)
ubb_htm=checkquote(bod)
set re=Nothing
end function
function dvHTMLEncode(fString)
if not isnull(fString) then
fString = replace(fString, ">", ">")
fString = replace(fString, "<", "<")
fString = replace(fString, "&#", "<I>&#</I>")
fString = Replace(fString, CHR(32), "<I></I> ")
fString = Replace(fString, CHR(9), " ")
fString = Replace(fString, CHR(34), """)
fString = Replace(fString, CHR(39), "'")
fString = Replace(fString, CHR(13), "")
fString = Replace(fString, CHR(10) & CHR(10), "</P><P> ")
fString = Replace(fString, CHR(10), "<BR> ")
dvHTMLEncode = fString
end if
end function
function checkquote(strText)
Dim s
Dim Test
Dim LoopCount
LoopCount=0
Set re=new RegExp
re.IgnoreCase =true
re.Global=True
s=strText
re.Pattern="\[QUOTE\]"
Test=re.Test(s)
If Test Then
re.Pattern="\[\/QUOTE\]"
Test=re.Test(s)
If Test Then
do while test
re.Pattern="\[QUOTE\](.*)\[\/QUOTE\]"
s=re.Replace(s,"<table style=""border-collapse:collapse;width:90%"" align=""center"" bordercolor=""#6595D6"" cellpadding=5 cellspacing=0 border=1><tr><td bgcolor=""#E4E8EF"" width=""100%"">$1</td></tr></table>")
LoopCount=LoopCount+1
If LoopCount>MaxLoopCount Then Exit Do
loop
end if
end if
set re=Nothing
checkquote=s
end function
Function bbimg(strText,ssize)
Dim s
s=strText
Set re=new RegExp
re.IgnoreCase =true
re.Global=True
re.Pattern="<img(.[^>]*)>"
If ssize=500 Then
s=re.replace(s,"<img$1 onmousewheel=""return bbimg(this)"" onload=""javascript:if(this.width>screen.width-"&ssize&")this.style.width=screen.width-"&ssize&";"">")
Else
s=re.replace(s,"<img$1 onmousewheel=""return bbimg(this)"" onload=""javascript:if(this.width>screen.width-"&ssize&")this.style.width=screen.width-"&ssize&";if(this.height>250)this.style.width=(this.width*250)/this.height;"">")
End If
set re=nothing
bbimg=s
End Function
%>