UBB (vb.net full version)

Source: Internet
Author: User
Tags filter chr html tags
UBB recently I used vb.net to do a forum, looking for a bit on the internet, although there are about UBB (vb.net) conversion code, but not comprehensive, I added here, take out and share.
What is the problem to my personal forum www.hushiyu.com to communicate, always welcome.


Public Class Ubbs
function Ubb (vstr as String)

' Replace HTML tags and wrap processing
VSTR = replace (Vstr, ">", ">")
VSTR = replace (Vstr, "<", "<")
Vstr = Replace (Vstr, CHR (32), "")
Vstr = Replace (Vstr, CHR (9), "")
Vstr = Replace (Vstr, CHR (34), "" ")
Vstr = Replace (Vstr, CHR (39), "'")
Vstr = Replace (Vstr, CHR (13), "")
Vstr = Replace (Vstr, CHR (), "<BR>")
Vstr = Replace (Vstr, "[Enter]", "<BR>")

Dim xface As Integer
If Xface=1 Then
' Expression conversion, numeric variable xface=1, allow conversion
VSTR = replace (vstr, ":)", "VSTR = replace (VSTR, ":(", "VSTR = replace (Vstr, ": O", "VSTR = replace (vstr, ":D", "VSTR = replace (vstr, ";)", "VSTR = replace (vstr, ":p", "VSTR = replace (Vstr, ": Cool:", "VSTR = replace (Vstr, ": Mad:", "VSTR = replace (Vstr, ": Eek:", "VSTR = replace (Vstr, ":?:", "End If

Dim Objregex As RegEx

' Shielding JS and so on
Objregex = new Regex ("JavaScript")
Vstr = Objregex.replace (Vstr, "JavaScript")
Objregex = new Regex ("JScript:")
Vstr = Objregex.replace (vstr, "JScript:")
Objregex = new Regex ("JS:")
Vstr = Objregex.replace (Vstr, "JS:")
Objregex = new Regex ("value")
Vstr = Objregex.replace (Vstr, "value")
Objregex = new Regex ("About:")
Vstr = Objregex.replace (Vstr, "about:")
Objregex = new Regex ("File:")
Vstr = Objregex.replace (vstr, "File:")
Objregex = new Regex ("Document.cookie")
Vstr = Objregex.replace (Vstr, "Documents.cookie")
Objregex = new Regex ("VBScript:")
Vstr = Objregex.replace (Vstr, "VBScript:")
Objregex = new Regex ("VBS:")
Vstr = Objregex.replace (VSTR, "VBS:")
Objregex = new Regex (On (Mouse|exit|error|click|key))
Vstr = Objregex.replace (Vstr, "on$2")
Objregex = new Regex ("script")
Vstr = Objregex.replace (vstr, "script")

' Ubb Conversion
' URL
Objregex = new Regex (\[url= (. [ ^\[]*)\])(.*?) (\[\/url\]) ")
Vstr = Objregex.replace (Vstr, "<a href=" "$" "target=_blank>$3</a>")
' EMAIL
Objregex = new Regex ("\[email\] (. [ ^\[]*) \[\/email\] "")
Vstr = Objregex.replace (vstr, <a href= "mailto:$1" "target=" "_blank" ">$1</a>")
' IMG
Objregex = new Regex ("\[img\] (http|https|ftp): \/\/(. [ ^\[]*) \[\/img\] "")
Vstr = Objregex.replace (Vstr, <br><a Onfocus=this.blur () href= "$1://$2" "Target=_blank>screen.width-333) this.width=screen.width-333 "></a>")
' Automatically identify URLs
Objregex = new Regex ("\[url=" (http:\/\/.[ ^\[]*)\](. [^\[]*) (\[\/url\]) ")
Vstr = Objregex.replace (Vstr, "<a href=" "$" "target=" "_blank" ">$2</a>")
Objregex = new Regex ("^" (http://[a-za-z0-9\./=\?%\ -&_~ ' @ ': +!] +)")
Vstr = Objregex.replace (Vstr, "<a href=" "$" "target=" "_blank" ">$1</a>")
Objregex = new Regex ("http://[a-za-z0-9\./=\?%\ -&_~ ' @ ': +!] +)$")
Vstr = Objregex.replace (Vstr, "<a target=_blank href=$1>$1</a>")
Objregex = new Regex ("[^>="] (http://[a-za-z0-9\./=\?%\ -&_~ ' @ ': +!] +)")
Vstr = Objregex.replace (Vstr, "<a target=_blank href=$1>$1</a>")
' COLOR
Objregex = new Regex ("\[color=" (. [ ^\[]*)\](. [^\[]*) \[\/color\] ")
Vstr = Objregex.replace (Vstr, "<font color=" ">$2</font>")
' U
Objregex = new Regex ("\[u\] (. *) \[\/u\]")
Vstr = Objregex.replace (Vstr, "<U>$1</U>")
' B
Objregex = new Regex ("\[b\] (. *) \[\/b\]")
Vstr = Objregex.replace (Vstr, "<B>$1</B>")
' I
Objregex = new Regex ("\[i\] (. *) \[\/i\]")
Vstr = Objregex.replace (Vstr, "<I>$1</I>")
' FLY
Objregex = new Regex ("\[fly\] (. *) \[\/fly\]")
Vstr = Objregex.replace (Vstr, "<marquee width=" "80%" "behavior=" "Alternate" "Scrollamount=" "3" ">$1</marquee > ")
' SHADOW
Objregex = new Regex ("\[shadow=*" ([0-9]*), * (#*[a-z0-9]*), * ([0-9]*) \] (. [ ^\[]*) \[\/shadow] "")
Vstr = Objregex.replace (Vstr, "<table width=$1 style=" "Filter:shadow (color=$2, strength=$3)" ">$4</table> ")
' GLOW
Objregex = new Regex ("\[glow=*" ([0-9]*), * (#*[a-z0-9]*), * ([0-9]*) \] (. [ ^\[]*) \[\/glow] "")
Vstr = Objregex.replace (Vstr, "<table width=$1 style=" "Filter:glow (color=$2, strength=$3)" ">$4</table>")
' Center
Objregex = new Regex ((\[center\)) (. *?) (\[\/center\]) ")
Vstr = Objregex.replace (Vstr, "<center>$2</center>")

' CODE
Objregex = new Regex ("\[code\] (. *) \[\/code\]")
Vstr = Objregex.replace (vstr, <table width= "80%" "border=" "0" "cellpadding=" "2" "cellspacing=" "0" "Bgcolor=" "# 99FFCC "style=" "border:1px solid #000000; Font-size:9pt;font-family:tahoma" "><tr><td>$1</td> </tr></table> ")

' FLASH
Objregex = new Regex ((\[falsh\)) (. *?) (\[\/falsh\]) ")
Vstr = Objregex.replace (Vstr, "<object codebase=http://download.macromedia.com/pub/shockwave/cabs/flash/ swflash.cab#version=6,0,29,0 classid=clsid:d27cdb6e-ae6d-11cf-96b8-444553540000 width=500 Height=400><PARAM Name=movie value= "$" "><param name=quality value=high><embed src=" "$" "Quality=high pluginspage= ' http ://www.macromedia.com/go/getflashplayer ' type= ' Application/x-shockwave-flash ' width=500 height=400>$2</ Embed></object> ")
Objregex = new Regex (\[falsh=* ([0-9]*), * ([0-9]*) \]) (. *?) (\[\/falsh\]) ")
Vstr = Objregex.replace (Vstr, "<a href=" "$" "Target=_blank> [Full screen to enjoy]</a><br><br><object codebase=http://download.macromedia.com/pub /shockwave/cabs/flash/swflash.cab#version=6,0,29,0 classid=clsid:d27cdb6e-ae6d-11cf-96b8-444553540000 width=$2 Height=$3><param Name=movie value= "" $ "" ><param name=quality value=high><param Name=menu False><embed src= "" $ "" Quality=high menu=false pluginspage= ' Http://www.macromedia.com/go/getflashplayer ' Type= ' Application/x-shockwave-flash ' width=$2 height=$3>$4</embed></object> ")

' Dir
Objregex = new Regex ("\[dir=*" ([0-9]*), * ([0-9]*) \] (. [ ^\[]*) \[\/dir] "")
Vstr = Objregex.replace (Vstr, "<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> ")

' RM
Objregex = new Regex ("\[rm=*" ([0-9]*), * ([0-9]*) \] (. [ ^\[]*) \[\/rm] "")
Vstr = Objregex.replace (Vstr, "<object CLASSID=CLSID:CFCDAA03-8BE4-11CF-B84B-0020AFBBCCFA Class=OBJECT width=$1 height=$2><param name=src Value=$3><param name=console Value=clip1><param 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 AUTOSTART value=-1><param name=controls Value=controlpanel><param name=console VALUE=Clip1></ Object> ")

' MP
Objregex = new Regex ("\[mp=*" ([0-9]*), * ([0-9]*) \] (. [ ^\[]*) \[\/MP] "")
Vstr = Objregex.replace (Vstr, "<object align=middle classid=clsid:22d6f312-b0f6-11d0-94ab-0080c74c7e95 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> ")

' QT
Objregex = new Regex ("\[qt=*" ([0-9]*), * ([0-9]*) \] (. [ ^\[]*) \[\/QT] "")
Vstr = Objregex.replace vstr, <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/> ")

' QUOTE
Objregex = new Regex ((\[quote\)) (. *) (\[\/quote\])
Vstr = Objregex.replace (Vstr, "<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>& Lt TD >$2</table></table><br> ")

' Move
Objregex = new Regex ((\[move\)) (. *) (\[\/move\])
Vstr = Objregex.replace (Vstr, "<marquee scrollamount=3>$2</marquee>")

' Size
Objregex = new Regex ("(\[size=1\]) (. [ ^\[]*) (\[\/size\]) ")
Vstr = Objregex.replace (Vstr, "<font size=1>$2</font>")
Objregex = new Regex ("(\[size=2\]) (. [ ^\[]*) (\[\/size\]) ")
Vstr = Objregex.replace (Vstr, "<font size=2>$2</font>")
Objregex = new Regex ("(\[size=3\]) (. [ ^\[]*) (\[\/size\]) ")
Vstr = Objregex.replace (Vstr, "<font size=3>$2</font>")
Objregex = new Regex ("(\[size=4\]) (. [ ^\[]*) (\[\/size\]) ")
Vstr = Objregex.replace (Vstr, "<font size=4>$2</font>")

' Face
Objregex = new Regex (\[face= (. [ ^\[]*)\])(. [^\[]*) (\[\/face\]) ")
Vstr = Objregex.replace (Vstr, "<font face=$2>$3</font>")

' em

Objregex = new Regex (\[em (. [ ^\[]*)\])")
Vstr = Objregex.replace (Vstr, "' Done, and you can expand yourself
UBB = Vstr
End Function

End Class



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.