将BBCODE转换为HTML代码[未完稿]

将BBCODE转换为HTML代码[未完稿]
#########################
sub code
{
my $text = shift(); ##文本

$text =~ s!&(.+?);!&$1;!ig;
$text =~ s!>!>!g;
$text =~ s!<!<!g;
$text =~ s!\n!<br>!ig;
$text =~ s!\t!&nbsp;&nbsp;!g;

$text =~ s/(\[URL|(^|\s)(http|ftp|https):\/\/|(^|\s)(www|ftp)\.)(\S*?)".*?(\]|\[\/URL\]|\s|$)/$1$6$7/isg;
$text =~ s/(^|\s)((http|ftp|https):\/\/\S+)/ <A HREF="$2" TARGET=_blank>$2<\/A> /isg;
$text =~ s/(^|\s)(www\.\S+)/ <A HREF="http:\/\/$2" TARGET=_blank>$2<\/A> /isg;
$text =~ s/(^|\s)(ftp\.\S+)/ <A HREF="ftp:\/\/$2" TARGET=_blank>$2<\/A> /isg;
$text =~ s/(\[URL\])(http|https|ftp)(:\/\/\S+?)(\[\/URL\])/<A HREF="$2$3" TARGET=_blank>$2$3<\/A>/isg;
$text =~ s/(\[URL\])(\S+?)(\[\/URL\])/<A HREF="http:\/\/$2" TARGET=_blank>$2<\/A>/isg;
$text =~ s/(\[URL=)(http|https|ftp)(:\/\/\S+?)(\])(.+?)(\[\/URL\])/<A HREF="$2$3" TARGET=_blank>$5<\/A>/isg;
$text =~ s/(\[URL=)(\S+?)(\])(.+?)(\[\/URL\])/<A HREF="http:\/\/$2" TARGET=_blank>$4<\/A>/isg;
$text =~ s/\[email=([\w\.\-]+\@[\w\.\-]+)\](.+?)\[\/email\]/<A HREF='mailto:$1' TITLE='发邮件到:$1'>$2<\/A>/g;
$text =~ s/\[email\]([\w\.\-]+\@[\w\.\-]+)\[\/email\]/<A HREF='mailto:$1'>$1<\/A>/g;
$text =~ s!\[b\](.+?)\[/b\]!<B>$1</B>!ig;
$text =~ s!\[i\](.+?)\[/i\]!<I>$1</I>!ig;
$text =~ s!\[u\](.+?)\[/u\]!<U>$1</U>!ig;
$text =~ s!\[sup\](.+?)\[/sup\]!<SUP>$1</SUP>!ig;
$text =~ s!\[sub\](.+?)\[/sub\]!<SUB>$1</SUB>!ig;
$text =~ s!\[center\](.+?)\[/center\]!<CENTER>$1</CENTER>!ig;
$text =~ s/(\[COLOR=)(.+?)(\])(.+?)(\[\/COLOR\])/<FONT COLOR="$2">$4<\/FONT>/isg;
$text =~ s/(\[size=)(.+?)(\])(.+?)(\[\/size\])/<FONT size="$2">$4<\/FONT>/isg;
$text =~ s/(\[font=)(.+?)(\])(.+?)(\[\/font\])/<FONT face="$2">$4<\/FONT>/isg;
$text =~ s/\[img\s+([^\s]+)\s+([^\]]+)\](https?:\/\/[\w\-\.%\~\_\/]+?)\[\/img\]/<a href='$3' target=_blank><IMG SRC='$3' WIDTH=$1 HEIGHT=$2 BORDER=0 onload=\"javascript\:if(this\.width>800-250)this\.width=800-250\" alt='在新窗口中浏览'><\/a>/ig ;
$text =~ s/\[img\](.+?)\[\/img\]/<a href='$1' target=_blank><IMG SRC='$1' BORDER=0 onload=\"javascript\:if(this\.width>800-250)this\.width=800-250\" alt='在新窗口中浏览'><\/a>/ig;
$text =~ s!\[quote\](.+?)\[\/quote\]!<table width=100% border=0 cellspacing=0 cellpadding=0 class=bbs-text><tr><td><font color=#FF0000 size=2><b>引用<\/b><\/font>:<\/td><\/tr> <tr><td><table width="90%" border="0" cellspacing="0" cellpadding="0" align="center" bgcolor="#000000" height="1"><tr><td><div align="left"><\/div><\/td><\/tr><\/table><table width="90%" border="1" cellspacing="0" cellpadding="0" align="center" class="bbs-text" bordercolor="#000000" bgcolor="#F6F6F6"><tr><td><font size=2>$1</font><\/td><\/tr><\/table><\/td><\/tr><\/table>!isg;
$text =~ s/(\[marquee\])(.+?)(\[\/marquee\])/<marquee>$2<\/marquee>/isg;
$text =~ s/(\[strike\])(.+?)(\[\/strike\])/<strike>$2<\/strike>/isg;
$text =~ s/(\[swf\])\s*(http|https|ftp):\/\/(\S+?\.swf)\s*(\[\/swf\])/<PARAM NAME=PLAY VALUE=TRUE><PARAM NAME=LOOP VALUE=TRUE><PARAM NAME=QUALITY VALUE=HIGH><embed src=$2:\/\/$3 quality=high pluginspage="http:\/\/www.macromedia.com\/shockwave\/download\/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application\/x-shockwave-flash" WIDTH=410 height=280><\/embed>/isg;
$text =~ s/(\[FLASH=)(\S+?)(\,)(\S+?)(\])\s*(http|https|ftp):\/\/(\S+?\.swf)\s*(\[\/FLASH\])/<OBJECT CLASSID="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" WIDTH=$2 HEIGHT=$4><PARAM NAME=MOVIE VALUE=$6:\/\/$7><PARAM NAME=PLAY VALUE=TRUE><PARAM NAME=LOOP VALUE=TRUE><PARAM NAME=QUALITY VALUE=HIGH><EMBED SRC=$6:\/\/$7 WIDTH=$2 HEIGHT=$4 PLAY=TRUE LOOP=TRUE QUALITY=HIGH><\/EMBED><\/OBJECT>/isg;
$text =~ s/(\[ra\])(.+?\.)(ram|rmm|mp3|mp2|mpa|ra)(\[\/ra\])/<b>这个是 RealPlayer 音乐:<\/b><br><object classid="clsid:CFCDAA03-8BE4-11CF-B84B-0020AFBBCCFA" id="RAOCX" width="480" height="70"><param name="_ExtentX" value="6694"><param name="_ExtentY" value="1588"><param name="AUTOSTART" value="0"><param name="SHUFFLE" value="0"><param name="PREFETCH" value="0"><param name="NOLABELS" value="0"><param name="SRC" value="$2$3"><param name="CONTROLS" value="StatusBar,ControlPanel"><param name="LOOP" value="0"><param name="NUMLOOP" value="0"><param name="CENTER" value="0"><param name="MAINTAINASPECT" value="0"><param name="BACKGROUNDCOLOR" value="#000000"><embed src="$2$3" width="320" autostart="true" height="70"><\/object><BR>/isg;
$text =~ s/(\[rm\])(.+?\.)(ram|rmm|rm|mpg|mpv|mpeg|dat|avi)(\[\/rm\])/<b>这个是 RealPlayer 影片:<\/b><br><object classid="clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA" HEIGHT=300 ID=Player WIDTH=480 VIEWASTEXT><param NAME="_ExtentX" VALUE="12726"><param NAME="_ExtentY" VALUE="8520"><param NAME="AUTOSTART" VALUE="0"><param NAME="SHUFFLE" VALUE="0"><param NAME="PREFETCH" VALUE="0"><param NAME="NOLABELS" VALUE="0"><param NAME="CONTROLS" VALUE="ImageWindow"><param NAME="CONSOLE" VALUE="_master"><param NAME="LOOP" VALUE="0"><param NAME="NUMLOOP" VALUE="0"><param NAME="CENTER" VALUE="0"><param NAME="MAINTAINASPECT" VALUE="$2$3"><param NAME="BACKGROUNDCOLOR" VALUE="#000000"><\/object><br><object CLASSID=clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA HEIGHT=32 ID=Player WIDTH=480 VIEWASTEXT><param NAME="_ExtentX" VALUE="18256"><param NAME="_ExtentY" VALUE="794"><param NAME="AUTOSTART" VALUE="0"><param NAME="SHUFFLE" VALUE="0"><param NAME="PREFETCH" VALUE="0"><param NAME="NOLABELS" VALUE="0"><param NAME="CONTROLS" VALUE="controlpanel"><param NAME="CONSOLE" VALUE="_master"><param NAME="LOOP" VALUE="0"><param NAME="NUMLOOP" VALUE="0"><param NAME="CENTER" VALUE="0"><param NAME="MAINTAINASPECT" VALUE="0"><param NAME="BACKGROUNDCOLOR" VALUE="#000000"><param NAME="SRC" VALUE="$2$3"><\/object><BR>/isg;
$text =~ s/(\[wma\])(.+?\.)(ram|wma|mp3|mp2|ra|mpa)(\[\/wma\])/<b>这个是 Windows Media Player 音乐:<\/b><br><embed type="application\/x-mplayer2" pluginspage="http:\/\/www.microsoft.com\/Windows\/Downloads\/Contents\/Products\/MediaPlayer\/" src="$2$3" name="realradio" showcontrols=1 ShowDisplay=0 ShowStatusBar=1 width=480 height=70 autostart=0><\/embed><BR>/isg;
$text =~ s/(\[wmv\])(.+?\.)(ram|asf|asx|avi|wmv|mpg|mpeg|dat)(\[\/wmv\])/<b> 这个是 Windows Media Player 影片:<\/b><br><EMBED id="videowindow1" name="videowindow1" src="$2$3" width="480" height="330" AutoStart=0 ><\/EMBED><BR>/isg;
$text =~ s/(\[em\])(.+?)(\[\/em\])/<img src=$cfg{bbstemplateurl}\/..\/image\/em\/$2>/isg;

####

$text =~ s!( {2,})!"&nbsp;" x length($1)!meg;

return $text;
}
###################################