欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

ubb js

程序员文章站 2022-03-10 22:24:57
stricons = "1"  //允许笑脸转换strsmile="1"   //同上imgname="em"picurl="/images/...

stricons = "1"  //允许笑脸转换
strsmile="1"   //同上
imgname="em"
picurl="/images/emot/"

function ubbcode(content,html){
    content=content.replace("\\r","");
    content=content.replace("\\n","");
    return (trans(content));
}


function trans(strcontent){
    var re;

 re=/\[img\](.+?)\[\/img\]/ig;
 strcontent=strcontent.replace(re,"<a href=$1 target=_blank><div><img src=$1 border=0 alt=按此在新窗口浏览图片 onload=\"javascript:if(this.width>screen.width*0.7)this.width=screen.width*0.7;\" galleryimg=no></div></a> ");
 re=/\[dir=*([0-9]*),*([0-9]*)\](.*?)\[\/dir]/ig
 strcontent=strcontent.replace(re,"<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>")
 re=/\[qt=*([0-9]*),*([0-9]*)\](.*?)\[\/qt]/ig
 strcontent=strcontent.replace(re,"<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=/\[mp=*([0-9]*),*([0-9]*)\](.*?)\[\/mp]/ig
 strcontent=strcontent.replace(re,"<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=/\[rm=*([0-9]*),*([0-9]*)\](.*?)\[\/rm]/ig
 strcontent=strcontent.replace(re,"<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=/(\[flash\])(.*?)(\[\/flash\])/ig
 strcontent= strcontent.replace(re,"<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=$2><param name=quality value=high><embed src=$2 quality=high pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' width=500 height=400>$2</embed></object>")
 re=/(\[flash=*([0-9]*),*([0-9]*)\])(.*?)(\[\/flash\])/ig
 strcontent= strcontent.replace(re,"<a href=$4 target=_blank><img src="+picurl+"swf.gif border=0 alt=点击开新窗口欣赏该flash动画!> [全屏欣赏]</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=$4><param name=quality value=high><param name=menu value=false><embed src=$4 quality=high menu=false pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' width=$2 height=$3>$4</embed></object>")

 re=/(\[upload=gif\])(.*?)(\[\/upload\])/ig
 strcontent= strcontent.replace(re,"<br><img src="+picurl+"gif.gif border=0>此主题相关图片如下:<br><a href=$2 target=_blank><img src=$2 border=0 alt=按此在新窗口浏览图片 onerror='if(this.src.indexof(\"219.239\") == -1)this.src=\"http://219.239.88.21$2\"' onload=\"javascript:if(this.width>screen.width-333)this.width=screen.width-333\"></a>")
 re=/(\[upload=jpg\])(.*?)(\[\/upload\])/ig
 strcontent= strcontent.replace(re,"<br><img src="+picurl+"jpg.gif border=0>此主题相关图片如下:<br><a href=$2 target=_blank><img src=$2 border=0 alt=按此在新窗口浏览图片 onerror='if(this.src.indexof(\"219.239\") == -1)this.src=\"http://219.239.88.21$2\"' onload=\"javascript:if(this.width>screen.width-333)this.width=screen.width-333\"></a>")
 re=/(\[upload=png\])(.*?)(\[\/upload\])/ig
 strcontent= strcontent.replace(re,"<br><img src="+picurl+"png.gif border=0>此主题相关图片如下:<br><a href=$2 target=_blank><img src=$2 border=0 alt=按此在新窗口浏览图片 onerror='if(this.src.indexof(\"219.239\") == -1)this.src=\"http://219.239.88.21$2\"' onload=\"javascript:if(this.width>screen.width-333)this.width=screen.width-333\"></a>")

 re=/(\[upload=swf\])(.*?)(\[\/upload\])/ig
 strcontent= strcontent.replace(re,"<br><a href=$2 target=_blank><img src="+picurl+"swf.gif border=0 alt=点击开新窗口欣赏该flash动画!> [全屏欣赏]</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=400 height=100><param name=movie value=$2><param name=quality value=high><param name=menu value=false><embed src=$2 quality=high menu=false pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' width=400 height=100>$2</embed></object>")

 re=/(\[upload=asf\])(.*?)(\[\/upload\])/ig
 strcontent= strcontent.replace(re,"<br><object align=middle classid=clsid:22d6f312-b0f6-11d0-94ab-0080c74c7e95 class=object id=mediaplayer width=400 height=300 ><param name=showstatusbar value=-1><param name=filename value=$2><embed type=application/x-oleobject codebase=http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#version=5,1,52,701 flename=mp src=$2  width=400 height=300></embed></object>")
 re=/(\[upload=avi\])(.*?)(\[\/upload\])/ig
 strcontent= strcontent.replace(re,"<br><object align=middle classid=clsid:22d6f312-b0f6-11d0-94ab-0080c74c7e95 class=object id=mediaplayer width=400 height=300 ><param name=showstatusbar value=-1><param name=filename value=$2><embed type=application/x-oleobject codebase=http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#version=5,1,52,701 flename=mp src=$2  width=400 height=300></embed></object>")
 re=/(\[upload=mpg\])(.*?)(\[\/upload\])/ig
 strcontent= strcontent.replace(re,"<br><object align=middle classid=clsid:22d6f312-b0f6-11d0-94ab-0080c74c7e95 class=object id=mediaplayer width=400 height=300 ><param name=showstatusbar value=-1><param name=filename value=$2><embed type=application/x-oleobject codebase=http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#version=5,1,52,701 flename=mp src=$2  width=400 height=300></embed></object>")
 re=/(\[upload=wmv\])(.*?)(\[\/upload\])/ig
 strcontent= strcontent.replace(re,"<br><object align=middle classid=clsid:22d6f312-b0f6-11d0-94ab-0080c74c7e95 class=object id=mediaplayer width=400 height=300 ><param name=showstatusbar value=-1><param name=filename value=$2><embed type=application/x-oleobject codebase=http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#version=5,1,52,701 flename=mp src=$2  width=400 height=300></embed></object>")

 re=/(\[upload=mp3\])(.*?)(\[\/upload\])/ig
 strcontent= strcontent.replace(re,"<br><object align=middle classid=clsid:22d6f312-b0f6-11d0-94ab-0080c74c7e95 class=object id=mediaplayer width=400 height=68 ><param name=showstatusbar value=-1><param name=filename value=$2><embed type=application/x-oleobject codebase=http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#version=5,1,52,701 flename=mp src=$2  width=400 height=68></embed></object>")
 re=/(\[upload=wav\])(.*?)(\[\/upload\])/ig
 strcontent= strcontent.replace(re,"<br><object align=middle classid=clsid:22d6f312-b0f6-11d0-94ab-0080c74c7e95 class=object id=mediaplayer width=400 height=68 ><param name=showstatusbar value=-1><param name=filename value=$2><embed type=application/x-oleobject codebase=http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#version=5,1,52,701 flename=mp src=$2  width=400 height=68></embed></object>")
 re=/(\[upload=mid\])(.*?)(\[\/upload\])/ig
 strcontent= strcontent.replace(re,"<br><object align=middle classid=clsid:22d6f312-b0f6-11d0-94ab-0080c74c7e95 class=object id=mediaplayer width=400 height=68 ><param name=showstatusbar value=-1><param name=filename value=$2><embed type=application/x-oleobject codebase=http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#version=5,1,52,701 flename=mp src=$2  width=400 height=68></embed></object>")

    re=/(\[upload=(.[^\[]*)\])(.*?)(\[\/upload\])/ig
    strcontent= strcontent.replace(re,"<br><img src="+picurl+"$2.gif border=0> <a href=$3 target=blank>点击浏览该文件</a>")

    re=/(\[refer=(\d{1,}),(.*?)\])(.*?)(\[\/refer\])/ig
    strcontent=strcontent.replace(re,"<table cellspacing=0 cellpadding=4 width=\"100%\" style=\"padding-top: 12px;\" border=0><tr><td background=\"/images/002.gif\" bgcolor=#f9f8fc  height=\"1\"></td></tr><tr><td style=\"padding-left: 16px\" bgcolor=#f9f8fc>回复$2楼<font color=\"#669900\">$3</font>发表:</td></tr><tr><td background=\"/images/002.gif\" bgcolor=#f9f8fc  height=\"1\"></td></tr><tr><td style=\"padding-left: 16px\" bgcolor=#f9f8fc> <font style=\"color:#a1a1a1\">$4</font> </td></tr><tr><td background=\"/images/002.gif\" bgcolor=#f9f8fc  height=\"1\"></td></tr></table>");

 re=/(\[url\])(.*?)(\[\/url\])/ig
 strcontent= strcontent.replace(re,"<a href=$2 target=_blank>$2</a>")
 re=/(\[url=(.[^\[]*)\])(.*?)(\[\/url\])/ig
 strcontent= strcontent.replace(re,"<a href=$2 target=_blank>$3</a>")

 re=/(\[email\])(.*?)(\[\/email\])/ig
 strcontent= strcontent.replace(re,"<img align=absmiddle src=/images/email.gif><a href=\"mailto:$2\">$2</a>")
 re=/(\[email=(.[^\[]*)\])(.*?)(\[\/email\])/ig
 strcontent= strcontent.replace(re,"<img align=absmiddle src=/images/email.gif><a href=\"mailto:$2\" target=_blank>$3</a>")

 re =/^(http:\/\/[a-za-z0-9\.\/=\?%\-&_~`@':+!]+)/ig
 strcontent = strcontent.replace(re,"<img align=absmiddle src=/images/url.gif><a target=_blank href=$1>$1</a>")
 re =/(http:\/\/[a-za-z0-9\.\/=\?%\-&_~`@':+!]+)$/ig
 strcontent = strcontent.replace(re,"<img align=absmiddle src=/images/url.gif><a target=_blank href=$1>$1</a>")
 re =/[^>=""](http:\/\/[a-za-z0-9\.\/=\?%\-&_~`@':+!]+)/ig
 strcontent = strcontent.replace(re,"<img align=absmiddle src=/images/url.gif><a target=_blank href=$1>$1</a>")
 re =/^(ftp:\/\/[a-za-z0-9\.\/=\?%\-&_~`@':+!]+)/ig
 strcontent = strcontent.replace(re,"<img align=absmiddle src=/images/url.gif><a target=_blank href=$1>$1</a>")
 re =/(ftp:\/\/[a-za-z0-9\.\/=\?%\-&_~`@':+!]+)$/ig
 strcontent = strcontent.replace(re,"<img align=absmiddle src=/images/url.gif><a target=_blank href=$1>$1</a>")
 re =/[^>=""](ftp:\/\/[a-za-z0-9\.\/=\?%\-&_~`@':+!]+)/ig
 strcontent = strcontent.replace(re,"<img align=absmiddle src=/images/url.gif><a target=_blank href=$1>$1</a>")
 re =/^(rtsp:\/\/[a-za-z0-9\.\/=\?%\-&_~`@':+!]+)/ig
 strcontent = strcontent.replace(re,"<img align=absmiddle src=/images/url.gif><a target=_blank href=$1>$1</a>")
 re =/(rtsp:\/\/[a-za-z0-9\.\/=\?%\-&_~`@':+!]+)$/ig
 strcontent = strcontent.replace(re,"<img align=absmiddle src=/images/url.gif><a target=_blank href=$1>$1</a>")
 re =/[^>=""](rtsp:\/\/[a-za-z0-9\.\/=\?%\-&_~`@':+!]+)/ig
 strcontent = strcontent.replace(re,"<img align=absmiddle src=/images/url.gif><a target=_blank href=$1>$1</a>")
 re =/^(mms:\/\/[a-za-z0-9\.\/=\?%\-&_~`@':+!]+)/ig
 strcontent = strcontent.replace(re,"<img align=absmiddle src=/images/url.gif><a target=_blank href=$1>$1</a>")
 re =/(mms:\/\/[a-za-z0-9\.\/=\?%\-&_~`@':+!]+)$/ig
 strcontent = strcontent.replace(re,"<img align=absmiddle src=/images/url.gif><a target=_blank href=$1>$1</a>")
 re =/[^>=""](mms:\/\/[a-za-z0-9\.\/=\?%\-&_~`@':+!]+)/ig
 strcontent = strcontent.replace(re,"<img align=absmiddle src=/images/url.gif><a target=_blank href=$1>$1</a>")

 if(stricons == "1"){                       //笑脸转换
 re=/(\[em(.*?)\])/ig
 strcontent=strcontent.replace(re,"<img src="+picurl+imgname+"$2.gif border=0 align=middle> ")
 }

 if(strsmile == "1"){                       //笑脸转换
 re=/(\[s(\d{1,2})\])/ig
 strcontent=strcontent.replace(re,"<img src=/images/smile/face$2.gif border=0 align=middle> ")
 }

 re=/(\[color=(.[^\[]*)\])(.*?)(\[\/color\])/ig
 strcontent=strcontent.replace(re,"<font color=$2>$3</font>")
 re=/(\[face=(.[^\[]*)\])(.*?)(\[\/face\])/ig
 strcontent=strcontent.replace(re,"<font face=$2>$3</font>")
 re=/(\[align=(.[^\[]*)\])(.*?)(\[\/align\])/ig
 strcontent=strcontent.replace(re,"<div align=$2>$3</div>")
//循环转换quote
 re=/(\[quote\])(.*?)(\[\/quote\])/ig
 while(strcontent.indexof("[quote]")>-1 && strcontent.indexof("[/quote]")>0){
 strcontent=strcontent.replace(re,"<blockquote>引用:<hr><span>$2</span><hr></blockquote>")
 }
 re=/(\[fly\])(.*?)(\[\/fly\])/ig
 strcontent=strcontent.replace(re,"<marquee width=90% behavior=alternate scrollamount=3>$2</marquee>")
 re=/(\[move\])(.*?)(\[\/move\])/ig
 strcontent=strcontent.replace(re,"<marquee scrollamount=3>$2</marquee>") 
 re=/\[glow=*([0-9]*),*(#*[a-z0-9]*),*([0-9]*)\](.*?)\[\/glow]/ig
 strcontent=strcontent.replace(re,"<table width=$1 style=\"filter:glow(color=$2, strength=$3)\">$4</table>")
 re=/\[shadow=*([0-9]*),*(#*[a-z0-9]*),*([0-9]*)\](.*?)\[\/shadow]/ig
 strcontent=strcontent.replace(re,"<table width=$1 style=\"filter:shadow(color=$2, strength=$3)\">$4</table>")

 re=/(\[i\])(.*?)(\[\/i\])/ig
 strcontent=strcontent.replace(re,"<i>$2</i>")
 re=/(\[u\])(.*?)(\[\/u\])/ig
 strcontent=strcontent.replace(re,"<u>$2</u>")
 re=/(\[b\])(.*?)(\[\/b\])/ig
 strcontent=strcontent.replace(re,"<b>$2</b>")

 re=/(\[size=1\])(.*?)(\[\/size\])/ig
 strcontent=strcontent.replace(re,"<font size=1>$2</font>")
 re=/(\[size=2\])(.*?)(\[\/size\])/ig
 strcontent=strcontent.replace(re,"<font size=2>$2</font>")
 re=/(\[size=3\])(.*?)(\[\/size\])/ig
 strcontent=strcontent.replace(re,"<font size=5>$2</font>")
 re=/(\[size=4\])(.*?)(\[\/size\])/ig
 strcontent=strcontent.replace(re,"<font size=6>$2</font>")

 re=/\[size=([+|-]?[0-7])\](.*?)(\[\/size\])/ig
 strcontent=strcontent.replace(re,"<font size=$1>$2</font>")

 re=/(\[list\])(.+?)(\[\/list\])/ig;
    strcontent=strcontent.replace(re,"<ul type=square>$2<\/ul>");
    re=/(\[list=)(a|1)(\])(.+?)(\[\/list\])/ig;
    strcontent=strcontent.replace(re,"<ol type=$2>$4<\/ol>");
    re=/(\[\*\])/ig;
    strcontent=strcontent.replace(re,"<li>");

 re=/(\[center\])(.*?)(\[\/center\])/ig
 strcontent=strcontent.replace(re,"<center>$2</center>")

return(strcontent);
}