ubbcode.aspx
上传用户:scene123
上传日期:2010-02-19
资源大小:3311k
文件大小:10k
源码类别:

.net编程

开发平台:

C#

  1. <SCRIPT RUNAT=SERVER LANGUAGE=VBSCRIPT>
  2.     strIMGInPosts = "1" '顯示圖片 1=顯示 0=連結
  3.     strAllowHTML = "0" 'HTML功能 1=啟動 0=關閉
  4.     strIcons = "1" '顯示icon 1=顯示 0=關閉
  5.     strflash = "1" '顯示Flash 1=顯示 0=連結
  6.     picurl = "pic"
  7.     function UBBCode(strContent)
  8.     if strAllowHTML <> 1 then
  9.     strContent = Server.HTMLEncode(strContent)
  10.     strContent = replace(strContent,VBCrlf,"<br> ")
  11.     else
  12.     strContent = Server.HTMLcode(strContent)
  13.     end if
  14.     
  15.     dim re
  16.     Set re=new RegExp
  17.     re.IgnoreCase =true
  18.     re.Global=True
  19.     re.Pattern="(script)"
  20.     strContent=re.Replace(strContent,"s cript")
  21. re.Pattern="([i])(.[^[]*)([/i])"
  22.     strContent=re.Replace(strContent,"<i>$2</i>")
  23.     re.Pattern="([u])(.[^[]*)([/u])"
  24.     strContent=re.Replace(strContent,"<u>$2</u>")
  25.     re.Pattern="([b])(.[^[]*)([/b])"
  26.     strContent=re.Replace(strContent,"<b>$2</b>")
  27.     re.Pattern="([fly])(.*)([/fly])"
  28.     strContent=re.Replace(strContent,"<marquee>$2</marquee>")
  29.     re.Pattern="([size=1])(.[^[]*)([/size])"
  30.     strContent=re.Replace(strContent,"<font size=1>$2</font>")
  31.     re.Pattern="([size=2])(.[^[]*)([/size])"
  32.     strContent=re.Replace(strContent,"<font size=2>$2</font>")
  33.     re.Pattern="([size=3])(.[^[]*)([/size])"
  34.     strContent=re.Replace(strContent,"<font size=3>$2</font>")
  35.     re.Pattern="([size=4])(.[^[]*)([/size])"
  36.     strContent=re.Replace(strContent,"<font size=4>$2</font>")
  37.     re.Pattern="([center])(.[^[]*)([/center])"
  38.     strContent=re.Replace(strContent,"<center>$2</center>")
  39.     if strIMGInPosts = "1" then
  40.     re.Pattern="([IMG])(.[^[]*)([/IMG])"
  41.     strContent=re.Replace(strContent,"<IMG SRC=""$2"" border=0 alt=按此在新窗口浏览图片 onload=""javascript:if(this.width>screen.width-333)this.width=screen.width-333"">")
  42.     end if
  43.     re.Pattern="[DIR=*([0-9]*),*([0-9]*)](.[^[]*)[/DIR]"
  44.     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>")
  45.     re.Pattern="[QT=*([0-9]*),*([0-9]*)](.[^[]*)[/QT]"
  46.     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/>")
  47.     re.Pattern="[MP=*([0-9]*),*([0-9]*)](.[^[]*)[/MP]"
  48.     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>")
  49.     re.Pattern="[RM=*([0-9]*),*([0-9]*)](.[^[]*)[/RM]"
  50.     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>")
  51.     if strflash= "1" then
  52.     re.Pattern="([FLASH])(.[^[]*)([/FLASH])"
  53.     strContent= re.Replace(strContent,"<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>")
  54.     end if
  55.     re.Pattern="([UPLOAD=gif])(.[^[]*)([/UPLOAD])"
  56.     strContent= re.Replace(strContent,"<br><IMG SRC="""&picurl&"gif.gif"" border=0>此主题相关图片如下:<br><A HREF=""$2"" TARGET=_blank><IMG SRC=""$2"" border=0 alt=按此在新窗口浏览图片 onload=""javascript:if(this.width>screen.width-333)this.width=screen.width-333""></A>")
  57.     re.Pattern="([UPLOAD=jpg])(.[^[]*)([/UPLOAD])"
  58.     strContent= re.Replace(strContent,"<br><IMG SRC="""&picurl&"jpg.gif"" border=0>此主题相关图片如下:<br><A HREF=""$2"" TARGET=_blank><IMG SRC=""$2"" border=0 alt=按此在新窗口浏览图片 onload=""javascript:if(this.width>screen.width-333)this.width=screen.width-333""></A>")
  59.     re.Pattern="([UPLOAD=bmp])(.[^[]*)([/UPLOAD])"
  60.     strContent= re.Replace(strContent,"<br><IMG SRC="""&picurl&"bmp.gif"" border=0>此主题相关图片如下:<br><A HREF=""$2"" TARGET=_blank><IMG SRC=""$2"" border=0 alt=按此在新窗口浏览图片 onload=""javascript:if(this.width>screen.width-333)this.width=screen.width-333""></A>")
  61.     re.Pattern="([UPLOAD=(.[^[]*)])(.[^[]*)([/UPLOAD])"
  62.     strContent= re.Replace(strContent,"<br><IMG SRC="""&picurl&"$2.gif"" border=0> <a href=""$3"">点击浏览该文件</a>")
  63.     re.Pattern="([URL])(.[^[]*)([/URL])"
  64.     strContent= re.Replace(strContent,"<A HREF=""$2"" TARGET=_blank>$2</A>")
  65.     re.Pattern="([URL=(.[^[]*)])(.[^[]*)([/URL])"
  66.     strContent= re.Replace(strContent,"<A HREF=""$2"" TARGET=_blank>$3</A>")
  67.     re.Pattern="([EMAIL])(.[^[]*)([/EMAIL])"
  68.     strContent= re.Replace(strContent,"<img align=absmiddle src="&picurl&"email1.gif><A HREF=""mailto:$2"">$2</A>")
  69.     re.Pattern="([EMAIL=(.[^[]*)])(.[^[]*)([/EMAIL])"
  70.     strContent= re.Replace(strContent,"<img align=absmiddle src="&picurl&"email1.gif><A HREF=""mailto:$2"" TARGET=_blank>$3</A>")
  71. re.Pattern = "^(http://[A-Za-z0-9./=?%-&_~`@':+!]+)"
  72. strContent = re.Replace(strContent,"<img align=absmiddle src="&picurl&"url.gif><a target=_blank href=$1>$1</a>")
  73. re.Pattern = "(http://[A-Za-z0-9./=?%-&_~`@':+!]+)$"
  74. strContent = re.Replace(strContent,"<img align=absmiddle src="&picurl&"url.gif><a target=_blank href=$1>$1</a>")
  75. re.Pattern = "[^>=""](http://[A-Za-z0-9./=?%-&_~`@':+!]+)"
  76. strContent = re.Replace(strContent,"<img align=absmiddle src="&picurl&"url.gif><a target=_blank href=$1>$1</a>")
  77. re.Pattern = "^(ftp://[A-Za-z0-9./=?%-&_~`@':+!]+)"
  78. strContent = re.Replace(strContent,"<img align=absmiddle src="&picurl&"url.gif><a target=_blank href=$1>$1</a>")
  79. re.Pattern = "(ftp://[A-Za-z0-9./=?%-&_~`@':+!]+)$"
  80. strContent = re.Replace(strContent,"<img align=absmiddle src="&picurl&"url.gif><a target=_blank href=$1>$1</a>")
  81. re.Pattern = "[^>=""](ftp://[A-Za-z0-9./=?%-&_~`@':+!]+)"
  82. strContent = re.Replace(strContent,"<img align=absmiddle src="&picurl&"url.gif><a target=_blank href=$1>$1</a>")
  83. re.Pattern = "^(rtsp://[A-Za-z0-9./=?%-&_~`@':+!]+)"
  84. strContent = re.Replace(strContent,"<img align=absmiddle src="&picurl&"url.gif><a target=_blank href=$1>$1</a>")
  85. re.Pattern = "(rtsp://[A-Za-z0-9./=?%-&_~`@':+!]+)$"
  86. strContent = re.Replace(strContent,"<img align=absmiddle src="&picurl&"url.gif><a target=_blank href=$1>$1</a>")
  87. re.Pattern = "[^>=""](rtsp://[A-Za-z0-9./=?%-&_~`@':+!]+)"
  88. strContent = re.Replace(strContent,"<img align=absmiddle src="&picurl&"url.gif><a target=_blank href=$1>$1</a>")
  89. re.Pattern = "^(mms://[A-Za-z0-9./=?%-&_~`@':+!]+)"
  90. strContent = re.Replace(strContent,"<img align=absmiddle src="&picurl&"url.gif><a target=_blank href=$1>$1</a>")
  91. re.Pattern = "(mms://[A-Za-z0-9./=?%-&_~`@':+!]+)$"
  92. strContent = re.Replace(strContent,"<img align=absmiddle src="&picurl&"url.gif><a target=_blank href=$1>$1</a>")
  93. re.Pattern = "[^>=""](mms://[A-Za-z0-9./=?%-&_~`@':+!]+)"
  94. strContent = re.Replace(strContent,"<img align=absmiddle src="&picurl&"url.gif><a target=_blank href=$1>$1</a>")
  95.     re.Pattern="([HTML])(.[^[]*)([/HTML])"
  96.     strContent=re.Replace(strContent,"<table width='100%' border='0' cellspacing='0' cellpadding='6' bgcolor='"&abgcolor&"'><td><b>以下内容为程序代码:</b><br>$2</td></table>")
  97.     re.Pattern="([code])(.[^[]*)([/code])"
  98.     strContent=re.Replace(strContent,"<table width='100%' border='0' cellspacing='0' cellpadding='6' bgcolor='"&abgcolor&"'><td><b>以下内容为程序代码:</b><br>$2</td></table>")
  99.     re.Pattern="([color=(.[^[]*)])(.[^[]*)([/color])"
  100.     strContent=re.Replace(strContent,"<font color=$2>$3</font>")
  101.     re.Pattern="([face=(.[^[]*)])(.[^[]*)([/face])"
  102.     strContent=re.Replace(strContent,"<font face=$2>$3</font>")
  103.     re.Pattern="([align=(.[^[]*)])(.[^[]*)([/align])"
  104.     strContent=re.Replace(strContent,"<div align=$2>$3</div>")
  105.     re.Pattern="([QUOTE])(.*)([/QUOTE])"
  106.     strContent=re.Replace(strContent,"<table cellpadding=0 cellspacing=0 border=1 WIDTH=94% bordercolor=#000000 bgcolor=#F2F8FF align=center  ><tr><td  ><table width=100% cellpadding=5 cellspacing=1 border=0><TR><TD BGCOLOR='"&abgcolor&"'>$2</table></table><br>")
  107.     re.Pattern="([move])(.*)([/move])"
  108.     strContent=re.Replace(strContent,"<MARQUEE scrollamount=3>$2</marquee>")
  109.     re.Pattern="[GLOW=*([0-9]*),*(#*[a-z0-9]*),*([0-9]*)](.[^[]*)[/GLOW]"
  110.     strContent=re.Replace(strContent,"<table width=$1 style=""filter:glow(color=$2, strength=$3)"">$4</table>")
  111.     re.Pattern="[SHADOW=*([0-9]*),*(#*[a-z0-9]*),*([0-9]*)](.[^[]*)[/SHADOW]"
  112.     strContent=re.Replace(strContent,"<table width=$1 style=""filter:shadow(color=$2, strength=$3)"">$4</table>")
  113. if strIcons = "1" then
  114.     re.Pattern="([em(.[^[]*)])"
  115.     strContent=re.Replace(strContent,"<img src="&picurl&"em$2.gif border=0 align=middle>")
  116.     end if
  117.     set re=Nothing
  118.     UBBCode=strContent
  119. end function
  120. function reUBBCode(strContent)
  121.     strContent = htmlencode(strContent)
  122.     dim re
  123.     Set re=new RegExp
  124.     re.IgnoreCase =true
  125.     re.Global=True
  126.     re.Pattern="([QUOTE])(.*)([/QUOTE])"
  127.     strContent=re.Replace(strContent,"")
  128.     set re=Nothing
  129.     reUBBCode=strContent
  130. end function
  131. </SCRIPT>