- public class UBB
- {
- #region 公共静态方法
- /// <summary>
- /// UBB代码处理函数
- /// </summary>
- /// <param name="_Str">输入字符串</param>
- /// <returns>输出字符串</returns>
- static public string u(string _Str)
- {
- Regex r;
- Match m;
- #region 处理符号
- 处理空格
- //_Str = _Str.Replace(" ", " ");
- 处理单引号
- //_Str = _Str.Replace("'", "’");
- 处理双引号
- _Str = _Str.Replace("/"", """);
- html标记符
- //_Str = _Str.Replace("<", "<");
- //_Str = _Str.Replace(">", ">");
- #endregion
- #region 处理换行
- //r = new Regex(@"(/r/n(( )| )+)(?<正文> +)", RegexOptions.IgnoreCase);
- //for (m = r.Match(_Str); m.Success; m = m.NextMatch())
- //{
- // _Str = _Str.Replace(m.Groups[0].ToString(), "<br />" + m.Groups["正文"].ToString());
- //}
- //_Str = _Str.Replace("/r/n", "<br />");
- #endregion
- #region 处[url=xxx][/url]标记
- r = new Regex(@"(/[url=(.[^/[]*)/])(.*?)(/[//url/])", RegexOptions.IgnoreCase);
- for (m = r.Match(_Str); m.Success; m = m.NextMatch())
- {
- _Str = _Str.Replace(m.Groups[0].ToString(), "<A href=/"" + m.Groups[2].ToString() + "/" target=/"_blank/">" + m.Groups[3].ToString() + "</A>");
- }
- #endregion
- #region url [ = ]
- r = new Regex(@"[^/]/[=](http://[A-Za-z0-9/./=/?%/-&_~`@':+!]+)", RegexOptions.IgnoreCase);
- for (m = r.Match(_Str); m.Success; m = m.NextMatch())
- {
- _Str = _Str.Replace(m.Groups[1].ToString(), "<a href=" + m.Groups[1].ToString() + " target=_blank>" + m.Groups[1].ToString() + "</a>");
- }
- #endregion
- #region 处[/email]标记
- r = new Regex(@"/[email/](.[^/[]*)/[//email/]", RegexOptions.IgnoreCase);
- for (m = r.Match(_Str); m.Success; m = m.NextMatch())
- {
- _Str = _Str.Replace(m.Groups[0].ToString(), "<A href=/"mailto:" + m.Groups[1].ToString() + "/" target=/"_blank/">" + m.Groups[1].ToString() + "</A>");
- }
- #endregion
- #region 处[IMG][/IMG]标记
- r = new Regex(@"/[img/](http|https|ftp):(.[^/[]*)/[//img/]", RegexOptions.IgnoreCase);
- for (m = r.Match(_Str); m.Success; m = m.NextMatch())
- {
- _Str = _Str.Replace(m.Groups[0].ToString(),
- "<br /><center><a οnfοcus=this.blur() href=" + m.Groups[1].ToString() + "://" + m.Groups[2].ToString() +
- " target=_blank><IMG SRC=" + m.Groups[1].ToString() + "://" + m.Groups[2].ToString() +
- " border=0 alt=按此在新窗口浏览图片 οnlοad=/"javascript:if(this.width>500) this.width=500/"></a></center><br />");
- }
- #endregion
- #region 处[em]标记
- r = new Regex(@"(/[em(.[^/[]*)/])", RegexOptions.IgnoreCase);
- for (m = r.Match(_Str); m.Success; m = m.NextMatch())
- {
- _Str = _Str.Replace(m.Groups[0].ToString(), "<img src=pic/em" + m.Groups[1].ToString() + ".gif border=0 align=middle>");
- }
- #endregion
- #region 处[flash=x,x][/flash]标记
- r = new Regex(@"(/[falsh=*([0-9]*),*([0-9]*)/])(.*?)(/[//falsh/])", RegexOptions.IgnoreCase);
- for (m = r.Match(_Str); m.Success; m = m.NextMatch())
- {
- _Str = _Str.Replace(m.Groups[0].ToString(),
- "<br /><center><a href=" + m.Groups[3].ToString() +
- " TARGET=_blank>[全屏欣赏]</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=" + m.Groups[1].ToString() +
- " height=" + m.Groups[2].ToString() + "><PARAM NAME=movie VALUE=" + m.Groups[3].ToString() +
- "><PARAM NAME=quality VALUE=high><param name=menu value=false><embed src=" + m.Groups[3].ToString() +
- " quality=high menu=false pluginspage=http://www.macromedia.com/go/getflashplayer type=application/x-shockwave-flash width=" + m.Groups[1].ToString() +
- " height=" + m.Groups[2].ToString() + ">" + m.Groups[3].ToString() + "</embed></OBJECT></center><br />");
- }
- #endregion
- #region 处[swf=x,x][/swf]标记
- r = new Regex(@"(/[swf=*([0-9]*),*([0-9]*)/])(.*?)(/[//swf/])", RegexOptions.IgnoreCase);
- for (m = r.Match(_Str); m.Success; m = m.NextMatch())
- {
- _Str = _Str.Replace(m.Groups[0].ToString(),
- "<center><a href=" + m.Groups[4].ToString() +
- " TARGET=_blank>[全屏欣赏]</a><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=" + m.Groups[2].ToString() +
- " height=" + m.Groups[3].ToString() + "><PARAM NAME=movie VALUE=" + m.Groups[4].ToString() +
- "><PARAM NAME=quality VALUE=high><param name=menu value=false><embed src=" + m.Groups[4].ToString() +
- " quality=high menu=false pluginspage=http://www.macromedia.com/go/getflashplayer type=application/x-shockwave-flash width=" + m.Groups[2].ToString() +
- " height=" + m.Groups[3].ToString() + ">" + m.Groups[4].ToString() + "</embed></OBJECT></center>");
- }
- #endregion
- #region 处[dir=x][/dir]标记
- r = new Regex(@"(/[dir=)(/d*?),(/d*?)/]([ /t]*?)(/[//dir/])", RegexOptions.IgnoreCase);
- for (m = r.Match(_Str); m.Success; m = m.NextMatch())
- {
- _Str = _Str.Replace(m.Groups[0].ToString(),
- "<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=" + m.Groups[2].ToString() + " height=" + m.Groups[3].ToString() + "><param name=src value=" + m.Groups[4].ToString() + "><embed src=" + m.Groups[4].ToString() + " pluginspage=http://www.macromedia.com/shockwave/download/ width=" + m.Groups[2].ToString() + " height=" + m.Groups[3].ToString() + "></embed></object>");
- }
- #endregion
- #region 处[rm=x][/rm]标记
- r = new Regex(@"/[rm=*([0-9]*),*([0-9]*)/](.[^/[]*)/[//rm]", RegexOptions.IgnoreCase);
- for (m = r.Match(_Str); m.Success; m = m.NextMatch())
- {
- _Str = _Str.Replace(m.Groups[0].ToString(),
- "<br /><OBJECT classid=clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA class=OBJECT id=RAOCX width=" + m.Groups[1].ToString() +
- " height=" + m.Groups[2].ToString() + "><PARAM NAME=SRC VALUE=" + m.Groups[3].ToString() +
- "><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=" + m.Groups[1].ToString() +
- "><PARAM NAME=SRC VALUE=" + m.Groups[3].ToString() +
- "><PARAM NAME=AUTOSTART VALUE=-1><PARAM NAME=CONTROLS VALUE=controlpanel><PARAM NAME=CONSOLE VALUE=Clip1></OBJECT><br />");
- }
- #endregion
- #region 处[mp=x,x][/mp]标记
- r = new Regex(@"/[mp=*([0-9]*),*([0-9]*)/](.[^/[]*)/[//mp]", RegexOptions.IgnoreCase);
- for (m = r.Match(_Str); m.Success; m = m.NextMatch())
- {
- _Str = _Str.Replace(m.Groups[0].ToString(),
- "<object align=middle classid=CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95 class=OBJECT id=MediaPlayer width=" + m.Groups[1].ToString() +
- " height=" + m.Groups[2].ToString() + "><param name=ShowStatusBar value=-1><param name=Filename value=" + m.Groups[3].ToString() +
- "><embed type=application/x-oleobject codebase=http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701 flename=mp src=" + m.Groups[3].ToString() +
- " width=" + m.Groups[1].ToString() +
- " height=" + m.Groups[2].ToString() + "></embed></object>");
- }
- #endregion
- #region 处[qt=x][/qt]标记
- r = new Regex(@"(/[qt=)(/d*?),(/d*?)/]([ /t]*?)(/[//qt/])", RegexOptions.IgnoreCase);
- for (m = r.Match(_Str); m.Success; m = m.NextMatch())
- {
- _Str = _Str.Replace(m.Groups[0].ToString(),
- "<embed src=" + m.Groups[4].ToString() + " width=" + m.Groups[2].ToString() + " height=" + m.Groups[3].ToString() + " autoplay=true loop=false controller=true playeveryframe=false cache=false scale=TOFIT bgcolor=#000000 kioskmode=false targetcache=false pluginspage=http://www.apple.com/quicktime/>");
- }
- #endregion
- #region 处<div class="UBBPanel"><div class="UBBTitle"><img src="images/quote.gif" style="margin:0px 2px -3px 0px" alt="引用内容"/> 引用内容</div><div class="UBBContent"></div></div>标记
- r = new Regex(@"(/[QUOTE/])([ /t]*?)(/[//QUOTE/])", RegexOptions.IgnoreCase);
- for (m = r.Match(_Str); m.Success; m = m.NextMatch())
- {
- _Str = _Str.Replace(m.Groups[0].ToString(), "<table cellpadding=0 cellspacing=0 border=1 WIDTH=94% bordercolor=#000000 bgcolor=#F2F8FF align=center style=FONT-SIZE: 9pt><tr><td ><table width=100% cellpadding=5 cellspacing=1 border=0><TR><TD >" + m.Groups[2].ToString() + "</table></table><br>");
- }
- #endregion
- #region 处[move][/move]标记
- r = new Regex(@"(/[move/])([ /t]*?)(/[//move/])", RegexOptions.IgnoreCase);
- for (m = r.Match(_Str); m.Success; m = m.NextMatch())
- {
- _Str = _Str.Replace(m.Groups[0].ToString(), "<MARQUEE scrollamount=3>" + m.Groups[2].ToString() + "</MARQUEE>");
- }
- #endregion
- #region 处<marquee width="90%" behavior="alternate" scrollamount="3"></marquee>标记
- r = new Regex(@"(/[FLY/])([ /t]*?)(/[//FLY/])", RegexOptions.IgnoreCase);
- for (m = r.Match(_Str); m.Success; m = m.NextMatch())
- {
- _Str = _Str.Replace(m.Groups[0].ToString(), "<MARQUEE width=80% behavior=alternate scrollamount=3>" + m.Groups[2].ToString() + "</MARQUEE>");
- }
- #endregion
- #region 处[image][/image]标记
- //处[image][/image]标记
- r = new Regex(@"(/[image/])([ /t]*?)(/[//image/])", RegexOptions.IgnoreCase);
- for (m = r.Match(_Str); m.Success; m = m.NextMatch())
- {
- _Str = _Str.Replace(m.Groups[0].ToString(),
- "<center><img src=/"" + m.Groups[2].ToString() + "/" border=0 align=middle></center><br>");
- }
- #endregion
- return _Str;
- }
- #endregion
- }
UBB转换函数
最新推荐文章于 2024-08-13 16:15:07 发布