/// <summary> /// UBB代码处理函数 /// </summary> /// <param name="_postpramsinfo">UBB转换参数表</param> /// <returns>输出字符串</returns> public static string UBBToHTML(PostpramsInfo _postpramsinfo) { Match m; string sDetail = _postpramsinfo.Sdetail; StringBuilder sb = new StringBuilder(); int pcodecount = -1; string sbStr = ""; string prefix = _postpramsinfo.Pid.ToString(); if (_postpramsinfo.Bbcodeoff == 0) { for (m = r[0].Match(sDetail); m.Success; m = m.NextMatch()) { sbStr = Parsecode(m.Groups[1].ToString(), prefix, ref pcodecount, _postpramsinfo.Allowhtml, ref sb); sDetail = sDetail.Replace(m.Groups[0].ToString(), sbStr); } } if (_postpramsinfo.Bbcodeoff == 0) { sDetail = HideDetail(sDetail, _postpramsinfo.Hide, _postpramsinfo.Usercredits); } //清除无效的smilie标签 sDetail = Regex.Replace(sDetail, @"\[smilie\](.+?)\[\/smilie\]", "$1", options); #region 建立smile表情标签 if (_postpramsinfo.Smileyoff == 0 && _postpramsinfo.Smiliesinfo != null) { sDetail = ParseSmilies(sDetail, _postpramsinfo.Smiliesinfo, _postpramsinfo.Smiliesmax); } #endregion // [smilie]处标记 sDetail = Regex.Replace(sDetail, @"\[smilie\](.+?)\[\/smilie\]", "<img src=\"$1\" />", options); if (_postpramsinfo.Bbcodeoff == 0) { if (sDetail.ToLower().Contains("[free]") || sDetail.ToLower().Contains("[/free]")) { for (m = r[15].Match(sDetail); m.Success; m = m.NextMatch()) { sDetail = sDetail.Replace(m.Groups[0].ToString(), "<br /><div class=\"msgheader\">免费内容:</div><div class=\"msgborder\">" + m.Groups[1].ToString() + "</div><br />"); } } // Bold, Italic, Underline sDetail = Regex.Replace(sDetail, @"\[b(?:\s*)\]", "<b>", options); sDetail = Regex.Replace(sDetail, @"\[i(?:\s*)\]", "<i>", options); sDetail = Regex.Replace(sDetail, @"\[u(?:\s*)\]", "<u>", options); sDetail = Regex.Replace(sDetail, @"\[/b(?:\s*)\]", "</b>", options); sDetail = Regex.Replace(sDetail, @"\[/i(?:\s*)\]", "</i>", options); sDetail = Regex.Replace(sDetail, @"\[/u(?:\s*)\]", "</u>", options); // Sub/Sup sDetail = Regex.Replace(sDetail, @"\[sup(?:\s*)\]", "<sup>", options); sDetail = Regex.Replace(sDetail, @"\[sub(?:\s*)\]", "<sub>", options); sDetail = Regex.Replace(sDetail, @"\[/sup(?:\s*)\]", "</sup>", options); sDetail = Regex.Replace(sDetail, @"\[/sub(?:\s*)\]", "</sub>", options); // P sDetail = Regex.Replace(sDetail, @"((\r\n)*\[p\])(.*?)((\r\n)*\[\/p\])", "<p>$3</p>", RegexOptions.IgnoreCase | RegexOptions.Singleline); // Anchors sDetail = ParseUrl(sDetail); // Email sDetail = Regex.Replace(sDetail, @"\[email(?:\s*)\](.*?)\[\/email\]", "<a href=\"mailto:$1\" target=\"_blank\">$1</a>", options); sDetail = Regex.Replace(sDetail, @"\[email=(.[^\[]*)(?:\s*)\](.*?)\[\/email(?:\s*)\]", "<a href=\"mailto:$1\" target=\"_blank\">$2</a>", options); #region // Font sDetail = Regex.Replace(sDetail, @"\[color=([^\[\<]+?)\]", "<font color=\"$1\">", options); sDetail = Regex.Replace(sDetail, @"\[size=(\d+?)\]", "<font size=\"$1\">", options); sDetail = Regex.Replace(sDetail, @"\[size=(\d+(\.\d+)?(px|pt|in|cm|mm|pc|em|ex|%)+?)\]", "<font style=\"font-size: $1\">", options); sDetail = Regex.Replace(sDetail, @"\[font=([^\[\<]+?)\]", "<font face=\"$1\">", options); sDetail = Regex.Replace(sDetail, @"\[align=([^\[\<]+?)\]", "<p align=\"$1\">", options); sDetail = Regex.Replace(sDetail, @"\[float=(left|right)\]", "<br style=\"clear: both\"><span style=\"float: $1;\">", options); sDetail = Regex.Replace(sDetail, @"\[/color(?:\s*)\]", "</font>", options); sDetail = Regex.Replace(sDetail, @"\[/size(?:\s*)\]", "</font>", options); sDetail = Regex.Replace(sDetail, @"\[/font(?:\s*)\]", "</font>", options); sDetail = Regex.Replace(sDetail, @"\[/align(?:\s*)\]", "</p>", options); sDetail = Regex.Replace(sDetail, @"\[/float(?:\s*)\]", "</span>", options); // BlockQuote sDetail = Regex.Replace(sDetail, @"\[indent(?:\s*)\]", "<blockquote>", options); sDetail = Regex.Replace(sDetail, @"\[/indent(?:\s*)\]", "</blockquote>", options); sDetail = Regex.Replace(sDetail, @"\[simpletag(?:\s*)\]", "<blockquote>", options); sDetail = Regex.Replace(sDetail, @"\[/simpletag(?:\s*)\]", "</blockquote>", options); // List sDetail = Regex.Replace(sDetail, @"\[list\]", "<ul>", options); sDetail = Regex.Replace(sDetail, @"\[list=1\]", "<ul type=1 class=\"litype_1\">", options); sDetail = Regex.Replace(sDetail, @"\[list=a\]", "<ul type=1 class=\"litype_2\">", options); sDetail = Regex.Replace(sDetail, @"\[list=A\]", "<ul type=1 class=\"litype_3\">", options); sDetail = Regex.Replace(sDetail, @"\[\*\]", "<li>", options); sDetail = Regex.Replace(sDetail, @"\[/list\]", "</ul>", options); #endregion #region 循环转换table sDetail = ParseTable(sDetail); #endregion // shadow sDetail = Regex.Replace(sDetail, @"(\[SHADOW=)(\d*?),(#*\w*?),(\d*?)\]([\s]||[\s\S]+?)(\[\/SHADOW\])", "<table width='$2' style='filter:SHADOW(COLOR=$3, STRENGTH=$4)'>$5</table>", options); // glow sDetail = Regex.Replace(sDetail, @"(\[glow=)(\d*?),(#*\w*?),(\d*?)\]([\s]||[\s\S]+?)(\[\/glow\])", "<table width='$2' style='filter:GLOW(COLOR=$3, STRENGTH=$4)'>$5</table>", options); // center sDetail = Regex.Replace(sDetail, @"\[center\]([\s]||[\s\S]+?)\[\/center\]", "<center>$1</center>", options); // Media MatchCollection mc = r[12].Matches(sDetail); foreach (Match match in mc) { sDetail = sDetail.Replace(match.Groups[0].Value, ParseMedia(match.Groups[1].Value, Utils.StrToInt(match.Groups[2].Value, 64), Utils.StrToInt(match.Groups[3].Value, 48), match.Groups[4].Value == "1" ? true : false, match.Groups[6].Value)); } #region 自定义标签 if (_postpramsinfo.Customeditorbuttoninfo != null) { sDetail = ReplaceCustomTag(sDetail, _postpramsinfo.Customeditorbuttoninfo); } #endregion #region 处理[quote][/quote]标记 int intQuoteIndexOf = sDetail.ToLower().IndexOf("[quote]"); int quotecount = 0; while (intQuoteIndexOf >= 0 && sDetail.ToLower().IndexOf("[/quote]") >= 0 && quotecount < 3) { quotecount++; sDetail = Regex.Replace(sDetail, @"\[quote\]([\s\S]+?)\[/quote\]", "<table style=\"width: auto;\"><tr><td style=\"border:none;\"><div class=\"quote\"><blockquote>$1</blockquote></div></td></tr></table>", options); intQuoteIndexOf = sDetail.ToLower().IndexOf("[quote]", intQuoteIndexOf + 7); } #endregion //处理[area]标签 sDetail = Regex.Replace(sDetail, @"\[area=([\s\S]+?)\]([\s\S]+?)\[/area\]", "<div class=\"msgheader\">$1</div><div class=\"msgborder\">$2</div>", options); sDetail = Regex.Replace(sDetail, @"\[area\]([\s\S]+?)\[/area\]", "<br /><br /><div class=\"msgheader\"></div><div class=\"msgborder\">$1</div>", options); #region 动网兼容模式ubb if (_postpramsinfo.Bbcodemode == 1) { ///[upload=jpg].jpg[/upload] string attachCode = "<p><img alt=\"\" src=\"{0}\" border=\"0\" /><span class=\"bold\">附件</span>: <a href=\"{1}\" target=\"_blank\">{2}</a> </p>"; string replacement = ""; string attachIcon = "images/attachicons/attachment.gif"; for (m = r[1].Match(sDetail); m.Success; m = m.NextMatch()) { Match m1 = r[2].Match(m.Groups[4].ToString().ToLower()); if (m1.Success) { sDetail = sDetail.Replace(m.Groups[0].ToString(), "[attach]" + m1.Groups[1] + "[/attach]"); continue; } string attachPath = m.Groups[4].ToString().ToLower().Replace("viewfile.asp?id", "attachment.aspx?attachmentid"); if (attachPath.IndexOf("attachment.aspx?attachmentid") == -1) { attachPath = BaseConfigs.GetSitePath + "upload/" + attachPath; } else { attachPath = BaseConfigs.GetSitePath + attachPath; } if ("rar,zip".IndexOf(m.Groups[2].ToString().ToLower()) != -1) { attachIcon = "images/attachicons/rar.gif"; } if ("jpg,jpeg,gif,bmp,png".IndexOf(m.Groups[2].ToString().ToLower()) != -1) { if (_postpramsinfo.Showimages == 1) { sDetail = sDetail.Replace(m.Groups[0].ToString(), "<img src=\"" + attachPath + "\" border=\"0\" onload=\"if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.alt=\'点击在新窗口浏览图片\\nCTRL+Mouse 滚轮可放大/缩小\';}\" onmouseover=\"if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.style.cursor=\'hand\'; this.alt=\'点击在新窗口浏览图片\\nCTRL+Mouse 滚轮可放大/缩小\';}\" onclick=\"if(!this.resized) {return true;} else {window.open(this.src);}\" onmousewheel=\"return imgzoom(this);\" />"); } else { replacement = attachPath; if (replacement.LastIndexOf("/") > 0) { replacement = Utils.CutString(replacement, replacement.LastIndexOf("/")); } replacement = string.Format(attachCode, attachIcon, attachPath); sDetail = sDetail.Replace(m.Groups[0].ToString(), replacement); } } else { replacement = attachPath; if (replacement.LastIndexOf("/") > 0) { replacement = Utils.CutString(replacement, replacement.LastIndexOf("/")); } replacement = string.Format(attachCode, attachIcon, attachPath, replacement); sDetail = sDetail.Replace(m.Groups[0].ToString(), replacement); } } sDetail = Regex.Replace(sDetail, @"\[uploadimage\](\d{1,})\[/uploadimage\]", "[attach]$1[/attach]", options); replacement = ""; for (m = r[3].Match(sDetail); m.Success; m = m.NextMatch()) { Match m1 = r[4].Match(m.Groups[2].ToString().ToLower()); if (m1.Success) { sDetail = sDetail.Replace(m.Groups[0].ToString(), "[attach]" + m1.Groups[1] + "[/attach]"); continue; } string attachPath = m.Groups[2].ToString().ToLower().Replace("viewfile.asp?id", "attachment.aspx?attachmentid"); if (attachPath.IndexOf("attachment.aspx?attachmentid") == -1) { attachPath = BaseConfigs.GetSitePath + "upload/" + attachPath; } else { attachPath = BaseConfigs.GetSitePath + attachPath; } if (_postpramsinfo.Showimages == 1) { sDetail = sDetail.Replace(m.Groups[0].ToString(), "<img src=\"" + attachPath + "\" border=\"0\" onload=\"if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.alt=\'点击在新窗口浏览图片\\nCTRL+Mouse 滚轮可放大/缩小\';}\" onmouseover=\"if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.style.cursor=\'hand\'; this.alt=\'点击在新窗口浏览图片\\nCTRL+Mouse 滚轮可放大/缩小\';}\" onclick=\"if(!this.resized) {return true;} else {window.open(this.src);}\" onmousewheel=\"return imgzoom(this);\" />"); } else { replacement = attachPath; if (replacement.LastIndexOf("/") > 0) { replacement = Utils.CutString(replacement, replacement.LastIndexOf("/")); } replacement = string.Format(attachCode, attachIcon, attachPath, replacement); sDetail = sDetail.Replace(m.Groups[0].ToString(), replacement); } } sDetail = Regex.Replace(sDetail, @"\[uploadfile\](\d{1,})\[/uploadfile\]", "[attach]$1[/attach]", options); replacement = ""; for (m = r[5].Match(sDetail); m.Success; m = m.NextMatch()) { Match m1 = r[6].Match(m.Groups[2].ToString().ToLower()); if (m1.Success) { sDetail = sDetail.Replace(m.Groups[0].ToString(), "[attach]" + m1.Groups[1] + "[/attach]"); continue; } replacement = m.Groups[2].ToString().ToLower().Replace("viewfile.asp?id", "attachment.aspx?attachmentid"); if (replacement.IndexOf("attachment.aspx?attachmentid") == -1) { replacement = BaseConfigs.GetSitePath + "upload/" + replacement; } else { replacement = BaseConfigs.GetSitePath + replacement; } if (replacement.LastIndexOf("/") > 0) { replacement = Utils.CutString(replacement, replacement.LastIndexOf("/")); } replacement = string.Format(attachCode, attachIcon, BaseConfigs.GetSitePath + m.Groups[2].ToString().ToLower().Replace("viewfile.asp?id", "attachment.aspx?attachmentid"), replacement); sDetail = sDetail.Replace(m.Groups[0].ToString(), replacement); } sDetail = Regex.Replace(sDetail, @"\[upload\](\d{1,})\[/upload\]", "[attach]$1[/attach]", options); //[upload].*[/upload] replacement = ""; for (m = r[7].Match(sDetail); m.Success; m = m.NextMatch()) { Match m1 = r[8].Match(m.Groups[2].ToString().ToLower()); if (m1.Success) { sDetail = sDetail.Replace(m.Groups[0].ToString(), "[attach]" + m1.Groups[1] + "[/attach]"); continue; } replacement = BaseConfigs.GetSitePath + m.Groups[2].ToString().ToLower().Replace("viewfile.asp?id", "attachment.aspx?attachmentid"); if (replacement.IndexOf("attachment.aspx?attachmentid") == -1) { replacement = BaseConfigs.GetSitePath + "upload/" + replacement; } else { replacement = BaseConfigs.GetSitePath + replacement; } if (replacement.LastIndexOf("/") > 0) { replacement = Utils.CutString(replacement, replacement.LastIndexOf("/")); } replacement = string.Format(attachCode, attachIcon, BaseConfigs.GetSitePath + m.Groups[2].ToString().ToLower().Replace("viewfile.asp?id", "attachment.aspx?attachmentid"), replacement); sDetail = sDetail.Replace(m.Groups[0].ToString(), replacement); } } #endregion } #region 将网址字符串转换为链接 if (_postpramsinfo.Parseurloff == 0) { sDetail = sDetail.Replace("&", "&"); // p2p link sDetail = Regex.Replace(sDetail, @"^((tencent|ed2k|thunder|vagaa):\/\/[\[\]\|A-Za-z0-9\.\/=\?%\-&_~`@':+!]+)", "<a target=\"_blank\" href=\"$1\">$1</a>", options); sDetail = Regex.Replace(sDetail, @"((tencent|ed2k|thunder|vagaa):\/\/[\[\]\|A-Za-z0-9\.\/=\?%\-&_~`@':+!]+)$", "<a target=\"_blank\" href=\"$1\">$1</a>", options); sDetail = Regex.Replace(sDetail, @"[^>=\]""]((tencent|ed2k|thunder|vagaa):\/\/[\[\]\|A-Za-z0-9\.\/=\?%\-&_~`@':+!]+)", "<a target=\"_blank\" href=\"$1\">$1</a>", options); } #endregion #region 处理[img][/img]标记 if (_postpramsinfo.Showimages == 1) { //控制签名html长度 if (_postpramsinfo.Signature == 1) { sDetail = Regex.Replace(sDetail, @"\[img\]\s*(http://[^\[\<\r\n]+?)\s*\[\/img\]", "<img src=\"$1\" border=\"0\" />", options); sDetail = Regex.Replace(sDetail, @"\[img=(\d{1,4})[x|\,](\d{1,4})\]\s*(http://[^\[\<\r\n]+?)\s*\[\/img\]", "<img src=\"$3\" width=\"$1\" height=\"$2\" border=\"0\" />", options); sDetail = Regex.Replace(sDetail, @"\[image\](http://[\s\S]+?)\[/image\]", "<img src=\"$1\" border=\"0\" />", options); } else { sDetail = Regex.Replace(sDetail, @"\[img\]\s*(http://[^\[\<\r\n]+?)\s*\[\/img\]", "<img src=\"$1\" border=\"0\" onload=\"thumbImg(this)\" />", options); sDetail = Regex.Replace(sDetail, @"\[img=(\d{1,4})[x|\,](\d{1,4})\]\s*(http://[^\[\<\r\n]+?)\s*\[\/img\]", "<img src=\"$3\" width=\"$1\" height=\"$2\" border=\"0\" onload=\"thumbImg(this)\" />", options); sDetail = Regex.Replace(sDetail, @"\[image\](http://[\s\S]+?)\[/image\]", "<img src=\"$1\" border=\"0\" />", options); } } #endregion pcodecount = 0; foreach (string str in Utils.SplitString(sb.ToString(), "<>")) { sDetail = sDetail.Replace("[\tDISCUZ_CODE_" + prefix + "_" + pcodecount.ToString() + "\t]", str); pcodecount++; } #region 处理空格 sDetail = sDetail.Replace("\t", " "); sDetail = sDetail.Replace(" ", " "); #endregion // [r/] sDetail = Regex.Replace(sDetail, @"\[r/\]", "\r", options); // [n/] sDetail = Regex.Replace(sDetail, @"\[n/\]", "\n", options); #region 处理换行 //处理换行,在每个新行的前面添加两个全角空格 for (m = r[9].Match(sDetail); m.Success; m = m.NextMatch()) { sDetail = sDetail.Replace(m.Groups[0].ToString(), "<br /> " + m.Groups["正文"].ToString()); } ////处理换行,在每个新行的前面添加两个全角空格 if (_postpramsinfo.Allowhtml == 0) { sDetail = sDetail.Replace("\r\n", "<br />"); sDetail = sDetail.Replace("\r", ""); sDetail = sDetail.Replace("\n\n", "<br /><br />"); sDetail = sDetail.Replace("\n", "<br />"); sDetail = sDetail.Replace("{rn}", "\r\n"); sDetail = sDetail.Replace("{nn}", "\n\n"); sDetail = sDetail.Replace("{r}", "\r"); sDetail = sDetail.Replace("{n}", "\n"); } #endregion return sDetail; }
protected override void ShowPage() { pagetitle = "用户控制面板"; if (!IsLogin()) return; if (SASRequest.IsPost()) { if (LogicUtils.IsCrossSitePost()) { AddErrLine("您的请求来路不正确,无法提交。如果您安装了某种默认屏蔽来路信息的个人防火墙软件(如 Norton Internet Security),请设置其不要禁止来路信息后再试。"); return; } ValidateInfo(); if (IsErr()) return; if (page_err == 0) { UserInfo userInfo = new UserInfo(); userInfo.Ps_id = userid; userInfo.Ps_name = Utils.HtmlEncode(LogicUtils.BanWordFilter(SASRequest.GetString("nickname"))); userInfo.Ps_gender = SASRequest.GetInt("gender", 0); userInfo.Pd_name = SASRequest.GetString("realname"); userInfo.Pd_idcard = SASRequest.GetString("idcard"); userInfo.Pd_mobile = SASRequest.GetString("mobile"); userInfo.Pd_phone = SASRequest.GetString("phone"); userInfo.Ps_email = SASRequest.GetString("email").Trim().ToLower(); userInfo.Pd_birthday = Utils.HtmlEncode(SASRequest.GetString("bday")); userInfo.Ps_isEmail = SASRequest.GetInt("showemail", 1); if (SASRequest.GetString("website").IndexOf(".") > -1 && !SASRequest.GetString("website").ToLower().StartsWith("http")) userInfo.Pd_website = Utils.HtmlEncode("http://" + SASRequest.GetString("website")); else userInfo.Pd_website = Utils.HtmlEncode(SASRequest.GetString("website")); //userInfo.Icq = Utils.HtmlEncode(SASRequest.GetString("icq")); userInfo.Pd_QQ = Utils.HtmlEncode(SASRequest.GetString("qq")); userInfo.Pd_Yahoo = Utils.HtmlEncode(SASRequest.GetString("yahoo")); userInfo.Pd_MSN = Utils.HtmlEncode(SASRequest.GetString("msn")); userInfo.Pd_Skype = Utils.HtmlEncode(SASRequest.GetString("skype")); userInfo.Tm_location = Utils.HtmlEncode(SASRequest.GetString("location")); userInfo.Pd_bio = Utils.HtmlEncode(LogicUtils.BanWordFilter(SASRequest.GetString("bio"))); PostpramsInfo postPramsInfo = new PostpramsInfo(); postPramsInfo.Usergroupid = usergroupid; postPramsInfo.Attachimgpost = config.Attachimgpost; postPramsInfo.Showattachmentpath = config.Showattachmentpath; postPramsInfo.Hide = 0; postPramsInfo.Price = 0; //获取提交的内容并进行脏字和Html处理 postPramsInfo.Sdetail = Utils.HtmlEncode(LogicUtils.BanWordFilter(SASRequest.GetString("signature"))); ; postPramsInfo.Smileyoff = 1; //postPramsInfo.Bbcodeoff = 1 - usergroupinfo.Allowsigbbcode; postPramsInfo.Parseurloff = 1; //postPramsInfo.Showimages = usergroupinfo.Allowsigimgcode; postPramsInfo.Allowhtml = 0; postPramsInfo.Signature = 1; postPramsInfo.Smiliesinfo = Smilies.GetSmiliesListWithInfo(); postPramsInfo.Customeditorbuttoninfo = null; postPramsInfo.Smiliesmax = config.Smiliesmax; postPramsInfo.Signature = 1; userInfo.Pd_sign = UBB.UBBToHTML(postPramsInfo); if (userInfo.Pd_sign.Length >= 1000) { AddErrLine("您的签名转换后超出系统最大长度, 请返回修改"); return; } userInfo.Pd_sign = postPramsInfo.Sdetail; userInfo.Ps_issign = SASRequest.GetInt("sigstatus", 0) != 0 ? 1 : 0; Users.UpdateUserProfile(userInfo); OnlineUsers.DeleteUserByUid(userid); //删除在线表中的信息,使之重建该用户在线表信息 SetUrl("usercpprofile.aspx"); SetMetaRefresh(); SetShowBackLink(true); AddMsgLine("修改个人档案完毕"); } } else { UserInfo userInfo = Users.GetUserInfo(userid);//olid avatarFlashParam = Utils.GetRootUrl(BaseConfigs.GetSitePath) + "images/common/camera.swf?nt=1&inajax=1&appid=" + Utils.MD5(userInfo.Ps_name + userInfo.Ps_password + userInfo.Ps_id + olid) + "&input=" + DES.Encode(userid + "," + olid, config.Passwordkey) + "&ucapi=" + Utils.UrlEncode(Utils.GetRootUrl(BaseConfigs.GetSitePath) + "tools/ajax.aspx"); avatarImage = Avatars.GetAvatarUrl(userid); } }