ubbcode.asp
Upload User: ahxunteng
Upload Date: 2022-05-16
Package Size: 1606k
Code Size: 10k
Development Platform:

VBScript

  1. <%
  2. const ImagePath="images/"
  3. function UBBCode(strContent)
  4. strContent= FilterJS(strContent)
  5. dim re
  6. dim po,ii
  7. dim reContent
  8. Set re=new RegExp
  9. re.IgnoreCase =true
  10. re.Global=True
  11. po=0
  12. ii=0
  13. re.Pattern="[IMG](http|https|ftp)://(.[^[]*)[/IMG]"
  14. strContent=re.Replace(strContent,"<a onfocus=this.blur() href=""$1://$2"" target=_blank><IMG SRC=""$1://$2"" border=0 alt=按此在新窗口浏览图片 onload=""javascript:if(this.width>screen.width-333)this.width=screen.width-333""></a>")
  15. re.Pattern="[UPLOAD=(gif|jpg|jpeg|bmp|png)](.[^[]*)(gif|jpg|jpeg|bmp|png)[/UPLOAD]"
  16. strContent= re.Replace(strContent,"<br><IMG SRC="""&ImagePath&"$1.gif"" border=0>此主题相关图片如下:<br><A HREF=""$2$1"" TARGET=_blank><IMG SRC=""$2$1"" border=0 alt=按此在新窗口浏览图片 onload=""javascript:if(this.width>screen.width-333)this.width=screen.width-333""></A>")
  17. re.Pattern="[UPLOAD=(.[^[]*)](.[^[]*)[/UPLOAD]"
  18. strContent= re.Replace(strContent,"<br><IMG SRC="""&ImagePath&"$1.gif"" border=0> <a href=""$2"">点击浏览该文件</a>")
  19. re.Pattern="[DIR=*([0-9]*),*([0-9]*)](.[^[]*)[/DIR]"
  20. strContent=re.Replace(strContent,"<object classid=clsid:166B1BCA-3F9C-11CF-8075-444553540000 codebase=http://download.macromedia.com/pub/shockwave/cabs/director/sw.cab#version=7,0,2,0 width=$1 height=$2><param name=src value=$3><embed src=$3 pluginspage=http://www.macromedia.com/shockwave/download/ width=$1 height=$2></embed></object>")
  21. re.Pattern="[QT=*([0-9]*),*([0-9]*)](.[^[]*)[/QT]"
  22. strContent=re.Replace(strContent,"<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/>")
  23. re.Pattern="[MP=*([0-9]*),*([0-9]*)](.[^[]*)[/MP]"
  24. strContent=re.Replace(strContent,"<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>")
  25. re.Pattern="[RM=*([0-9]*),*([0-9]*)](.[^[]*)[/RM]"
  26. strContent=re.Replace(strContent,"<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>")
  27. re.Pattern="([FLASH])(.[^[]*)([/FLASH])"
  28. strContent= re.Replace(strContent,"<a href=""$2"" TARGET=_blank><IMG SRC=" & ImagePath & "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=5,0,0,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>")
  29. re.Pattern="([FLASH=*([0-9]*),*([0-9]*)])(.[^[]*)([/FLASH])"
  30. strContent= re.Replace(strContent,"<a href=""$4"" TARGET=_blank><IMG SRC=" & ImagePath & "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=5,0,0,0 classid=clsid:D27CDB6E-AE6D-11cf-96B8-444553540000 width=$2 height=$3><PARAM NAME=movie VALUE=""$4""><PARAM NAME=quality VALUE=high><embed src=""$4"" quality=high pluginspage='http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash'type='application/x-shockwave-flash' width=$2 height=$3>$4</embed></OBJECT>")
  31. re.Pattern="([URL])(.[^[]*)([/URL])"
  32. strContent= re.Replace(strContent,"<A HREF=""$2"" TARGET=_blank>$2</A>")
  33. re.Pattern="([URL=(.[^[]*)])(.[^[]*)([/URL])"
  34. strContent= re.Replace(strContent,"<A HREF=""$2"" TARGET=_blank>$3</A>")
  35. re.Pattern="([EMAIL])(S+@.[^[]*)([/EMAIL])"
  36. strContent= re.Replace(strContent,"<img align=absmiddle src=" & ImagePath & "email1.gif><A HREF=""mailto:$2"">$2</A>")
  37. re.Pattern="([EMAIL=(S+@.[^[]*)])(.[^[]*)([/EMAIL])"
  38. strContent= re.Replace(strContent,"<img align=absmiddle src=" & ImagePath & "email1.gif><A HREF=""mailto:$2"" TARGET=_blank>$3</A>")
  39. '自动识别网址
  40. 're.Pattern = "^((http|https|ftp|rtsp|mms):(//|\\)[A-Za-z0-9./=?%-&_~`@':+!]+)"
  41. 'strContent = re.Replace(strContent,"<img align=absmiddle src=pic/url.gif border=0><a target=_blank href=$1>$1</a>")
  42. 're.Pattern = "((http|https|ftp|rtsp|mms):(//|\\)[A-Za-z0-9./=?%-&_~`@':+!]+)$"
  43. 'strContent = re.Replace(strContent,"<img align=absmiddle src=pic/url.gif border=0><a target=_blank href=$1>$1</a>")
  44. 're.Pattern = "([^>=""])((http|https|ftp|rtsp|mms):(//|\\)[A-Za-z0-9./=?%-&_~`@':+!]+)"
  45. 'strContent = re.Replace(strContent,"$1<img align=absmiddle src=pic/url.gif border=0><a target=_blank href=$2>$2</a>")
  46. '自动识别www等开头的网址
  47. 're.Pattern = "([^(http://|http:\)])((www|cn)[.](w)+[.]{1,}(net|com|cn|org|cc)(((/[~]*|\[~]*)(w)+)|[.](w)+)*(((([?](w)+){1}[=]*))*((w)+){1}([&](w)+[=](w)+)*)*)"
  48. 'strContent = re.Replace(strContent,"<img align=absmiddle src=pic/url.gif border=0><a target=_blank href=http://$2>$2</a>")
  49. '自动识别Email地址,如打开本功能在浏览内容很多的帖子会引起服务器停顿
  50. 're.Pattern = "([^(=)])((w)+[@]{1}((w)+[.]){1,3}(w)+)"
  51. 'strContent = re.Replace(strContent,"<img align=absmiddle src=pic/url.gif border=0><a target=_blank href=""mailto:$2"">$2</a>")
  52. re.Pattern="[em(.[^[]*)]"
  53. strContent=re.Replace(strContent,"<img src="&ImagePath&"em$1.gif border=0 align=middle>")
  54. re.Pattern="[HTML](.[^[]*)[/HTML]"
  55. strContent=re.Replace(strContent,"<table width='100%'border='0'cellspacing='0'cellpadding='6' class=tableborder1><td><b>以下内容为程序代码:</b><br>$1</td></table>")
  56. re.Pattern="[code](.[^[]*)[/code]"
  57. strContent=re.Replace(strContent,"<table width='100%'border='0'cellspacing='0'cellpadding='6' class=tableborder1><td><b>以下内容为程序代码:</b><br>$1</td></table>")
  58. re.Pattern="[color=(.[^[]*)](.[^[]*)[/color]"
  59. strContent=re.Replace(strContent,"<font color=$1>$2</font>")
  60. re.Pattern="[face=(.[^[]*)](.[^[]*)[/face]"
  61. strContent=re.Replace(strContent,"<font face=$1>$2</font>")
  62. re.Pattern="[align=(center|left|right)](.*)[/align]"
  63. strContent=re.Replace(strContent,"<div align=$1>$2</div>")
  64. re.Pattern="[QUOTE](.*)[/QUOTE]"
  65. strContent=re.Replace(strContent,"<table style=""width:80%"" cellpadding=5 cellspacing=1 class=tableborder1><TR><TD class=tableborder1>$1</td></tr></table><br>")
  66. re.Pattern="[fly](.*)[/fly]"
  67. strContent=re.Replace(strContent,"<marquee width=90% behavior=alternate scrollamount=3>$1</marquee>")
  68. re.Pattern="[move](.*)[/move]"
  69. strContent=re.Replace(strContent,"<MARQUEE scrollamount=3>$1</marquee>")
  70. re.Pattern="[GLOW=*([0-9]*),*(#*[a-z0-9]*),*([0-9]*)](.[^[]*)[/GLOW]"
  71. strContent=re.Replace(strContent,"<table width=$1 style=""filter:glow(color=$2, strength=$3)"">$4</table>")
  72. re.Pattern="[SHADOW=*([0-9]*),*(#*[a-z0-9]*),*([0-9]*)](.[^[]*)[/SHADOW]"
  73. strContent=re.Replace(strContent,"<table width=$1 style=""filter:shadow(color=$2, strength=$3)"">$4</table>")
  74. re.Pattern="[i](.[^[]*)[/i]"
  75. strContent=re.Replace(strContent,"<i>$1</i>")
  76. re.Pattern="[u](.[^[]*)([/u])"
  77. strContent=re.Replace(strContent,"<u>$1</u>")
  78. re.Pattern="[b](.[^[]*)([/b])"
  79. strContent=re.Replace(strContent,"<b>$1</b>")
  80. re.Pattern="[size=([1-4])](.[^[]*)[/size]"
  81. strContent=re.Replace(strContent,"<font size=$1>$2</font>")
  82. strContent=replace(strContent,"<I></I>","")
  83. set re=Nothing
  84. strContent=replace(strContent,vbCrLf&vbCrlf,"</P><P> ")
  85. strContent=replace(strContent,vbCrlf,"<BR> ")
  86. strContent=replace(strContent,"  ","&nbsp;&nbsp;")
  87. UBBCode=strContent
  88. end function
  89. Function FilterJS(v)
  90. if not isnull(v) then
  91. dim t
  92. dim re
  93. dim reContent
  94. Set re=new RegExp
  95. re.IgnoreCase =true
  96. re.Global=True
  97. re.Pattern="(javascript)"
  98. t=re.Replace(v,"&#106avascript")
  99. re.Pattern="(jscript:)"
  100. t=re.Replace(t,"&#106script:")
  101. re.Pattern="(js:)"
  102. t=re.Replace(t,"&#106s:")
  103. re.Pattern="(value)"
  104. t=re.Replace(t,"value")
  105. re.Pattern="(about:)"
  106. t=re.Replace(t,"about&#58")
  107. re.Pattern="(file:)"
  108. t=re.Replace(t,"file&#58")
  109. re.Pattern="(document.cookie)"
  110. t=re.Replace(t,"documents&#46cookie")
  111. re.Pattern="(vbscript:)"
  112. t=re.Replace(t,"&#118bscript:")
  113. re.Pattern="(vbs:)"
  114. t=re.Replace(t,"&#118bs:")
  115. re.Pattern="(on(mouse|exit|error|click|key))"
  116. t=re.Replace(t,"&#111n$2")
  117. re.Pattern="(&#)"
  118. t=re.Replace(t,"&#")
  119. FilterJS=t
  120. set re=nothing
  121. end if
  122. End Function
  123. function dvHTMLEncode(fString)
  124. if not isnull(fString) then
  125.     fString = replace(fString, ">", "&gt;")
  126.     fString = replace(fString, "<", "&lt;")
  127.     fString = Replace(fString, CHR(32), "&nbsp;")
  128.     fString = Replace(fString, CHR(9), "&nbsp;")
  129.     fString = Replace(fString, CHR(34), "&quot;")
  130.     fString = Replace(fString, CHR(39), "&#39;")
  131.     fString = Replace(fString, CHR(13), "")
  132.     fString = Replace(fString, vbCrLf&vbCrlf, "</P><P> ")
  133.     fString = Replace(fString, vbCrLf, "<BR> ")
  134.     dvHTMLEncode = fString
  135. end if
  136. end function
  137. function nohtml(str)
  138.     dim re
  139.     Set re=new RegExp
  140.     re.IgnoreCase =true
  141.     re.Global=True
  142.     re.Pattern="(<.[^<]*>)"
  143.     str=re.replace(str," ")
  144.     re.Pattern="(</[^<]*>)"
  145.     str=re.replace(str," ")
  146.     nohtml=str
  147.     set re=nothing
  148. end function
  149. %>