public M_Blog_Msg FillMsg(string msg, int pid = 0, int rid = 0) { M_User_Plat upMod = B_User_Plat.GetLogin(); M_Blog_Msg model = new M_Blog_Msg(); model.MsgType = 1; model.Status = 1; model.CUser = upMod.UserID; model.CUName = upMod.TrueName; #region 信息内容处理 msg = Server.HtmlEncode(msg); //避免写入js,后面可插入Html //------处理@功能 //@功能 { MatchCollection mc = regHelper.GetValuesBySE(msg, "@", "]"); int id = 0; string atuser = "", atgroup = "", name = ""; string uTlp = "<a href='javascript:;' onclick='ShowUser({0});'>{1}</a>"; string gTlp = "<a href='javascript:;' onclick='ShowGroup({0});'>{1}</a>"; foreach (Match m in mc) { if (string.IsNullOrEmpty(m.Value)) { continue; } if (m.Value.Contains("uid:")) { id = DataConvert.CLng(regHelper.GetValueBySE(m.Value, "uid:", "]", false)); name = regHelper.GetValueBySE(m.Value, "@", @"\[").Replace("[", ""); atuser += id + ","; msg = msg.Replace(m.Value, string.Format(uTlp, id, name)); } else if (m.Value.Contains("gid:")) { id = DataConvert.CLng(regHelper.GetValueBySE(m.Value, "gid:", "]", false)); name = regHelper.GetValueBySE(m.Value, "@", @"\[").Replace("[", ""); atgroup += id + ","; msg = msg.Replace(m.Value, string.Format(gTlp, id, name)); } msg = msg.Replace(m.Value, ""); } if (!string.IsNullOrEmpty(atuser) || !string.IsNullOrEmpty(atgroup)) { atuser += upBll.SelByGIDS(atgroup); if (!string.IsNullOrEmpty(atuser.Replace(",", ""))) { model.ATUser = StrHelper.IdsFormat(atuser); //model.ATUser = model.ATUser.Replace("," + upMod.UserID, "");//过滤自己 //提示被@人 M_Notify notifyMod = new M_Notify(); notifyMod.CUName = upMod.UserName; notifyMod.Title = "Hi,有人@你了,点击查看详情"; notifyMod.Content = msg.Length > 30 ? msg.Substring(0, 30) : msg; notifyMod.ReceUsers = model.ATUser; B_Notify.NotifyList.Add(notifyMod); } } } #endregion model.MsgContent = msg; model.pid = pid; model.ReplyID = rid; if (rid > 0) { M_Blog_Msg msgMod = msgBll.SelReturnModel(model.ReplyID); model.ReplyUserID = msgMod.CUser; model.ReplyUName = msgMod.CUName; } if (!string.IsNullOrEmpty(Request.Form["Attach_Hid"]))//为安全,不允许全路径,必须后台对路径处理 { string uppath = B_Plat_Common.GetDirPath(B_Plat_Common.SaveType.Blog); M_UserInfo bus = buser.GetLogin(); string files = SafeSC.PathDeal(Request.Form["Attach_Hid"].Trim()); foreach (string file in files.Split('|')) { if (string.IsNullOrEmpty(file)) { continue; } model.Attach += uppath + file + "|"; } } model.GroupIDS = Request.Form["GroupIDS_Chk"];//后期需加入检测,避免前台伪造 model.ColledIDS = ""; //model.CompID = upMod.CompID; return(model); }
private M_Blog_Msg FillMsg(string msg, out string puremsg, int pid = 0, int rid = 0, string files = "") { puremsg = msg; M_Blog_Msg model = new M_Blog_Msg(); model.MsgType = 1; model.Status = 1; model.CUser = upMod.UserID; model.CUName = upMod.TrueName; model.ProID = CurProID; model.CompID = upMod.CompID; model.pid = pid; model.ReplyID = rid; #region 信息内容处理 //#话题(转码后会带有#符号,所以需要转码前处理完成) if (msg.Contains("#")) { string deftopic = "#插入话题#"; msg = msg.Replace(deftopic, ""); string tlp = "<a href='/Plat/Blog?Skey={0}' title='话题浏览'>{1}</a>"; Dictionary <string, string> itemDic = new Dictionary <string, string>(); for (int i = 0; !string.IsNullOrEmpty(regHelper.GetValueBySE(msg, "#", "#", false)) && i < 5; i++)//最多不能超过5个话题 { string topic = "#" + regHelper.GetValueBySE(msg, "#", "#", false) + "#"; msg = msg.Replace(topic, "{" + i + "}"); topic = topic.Replace(" ", "").Replace(",", ""); itemDic.Add("{" + i + "}", string.Format(tlp, HttpUtility.UrlEncode(topic), topic)); model.Topic += topic + ","; } msg = HttpUtility.HtmlEncode(msg); foreach (var item in itemDic) { msg = msg.Replace(item.Key, item.Value); } } else { msg = HttpUtility.HtmlEncode(msg); } //URL转链接 { string tlp = "<a href='{0}' target='_blank'>{0}</a>"; MatchCollection mcs = regHelper.GetUrlsByStr(msg); foreach (Match m in mcs) { //同网址,信息替换多次会产生Bug,如多个www.baidu.com string url = m.Value.IndexOf("://") < 0 ? "http://" + m.Value : m.Value; msg = msg.Replace(m.Value, string.Format(tlp, url)); } } //表情 { if (!string.IsNullOrEmpty(GetParam("ImgFace_Hid"))) { string imgHtml = "<img src='/Plugins/Ueditor/dialogs/emotion/{0}' class='imgface_img' />"; DataTable imgDT = JsonHelper.JsonToDT(GetParam("ImgFace_Hid")); foreach (DataRow dr in imgDT.Rows) { msg = msg.Replace(dr["title"].ToString(), string.Format(imgHtml, dr["realurl"].ToString())); puremsg = puremsg.Replace(dr["title"].ToString(), ""); } } } //@功能 { MatchCollection mc = regHelper.GetValuesBySE(msg, "@", "]"); int id = 0; string atuser = "", atgroup = "", name = ""; string uTlp = "<a href='javascript:;' onclick='ShowUser({0});'>{1}</a>"; string gTlp = "<a href='javascript:;' onclick='ShowGroup({0});'>{1}</a>"; foreach (Match m in mc) { //@what130[uid:19],名字替换为超链接,之后的取值取入数据库 if (string.IsNullOrEmpty(m.Value)) { continue; } if (m.Value.Contains("uid:")) { id = DataConvert.CLng(regHelper.GetValueBySE(m.Value, "uid:", "]", false)); name = regHelper.GetValueBySE(m.Value, "@", @"\[").Replace("[", ""); atuser += id + ","; msg = msg.Replace(m.Value, string.Format(uTlp, id, name)); } else if (m.Value.Contains("gid:")) { id = DataConvert.CLng(regHelper.GetValueBySE(m.Value, "gid:", "]", false)); name = regHelper.GetValueBySE(m.Value, "@", @"\[").Replace("[", ""); atgroup += id + ","; msg = msg.Replace(m.Value, string.Format(gTlp, id, name)); } puremsg = puremsg.Replace(m.Value, ""); } if (!string.IsNullOrEmpty(atuser) || !string.IsNullOrEmpty(atgroup)) { atuser += upBll.SelByGIDS(atgroup); if (!string.IsNullOrEmpty(atuser.Replace(",", ""))) { model.ATUser = StrHelper.IdsFormat(atuser); //model.ATUser = model.ATUser.Replace("," + upMod.UserID, "");//过滤自己 //提示被@人 //M_Notify notifyMod = new M_Notify(); //notifyMod.CUName = upMod.UserName; //notifyMod.Title = "Hi,[" + B_User.GetUserName(upMod.TrueName, upMod.UserName) + "]@你了,点击查看详情"; //notifyMod.Content = puremsg.Length > 30 ? puremsg.Substring(0, 30) : puremsg; //notifyMod.ReceUsers = model.ATUser; //B_Notify.NotifyList.Add(notifyMod); } } } //-------------------------------- msg = msg.Replace("\r", "").Replace("\n", "<br/>");//替换换行标识 #endregion //msg = msg.Replace("'", "\'"); model.MsgContent = msg; if (rid > 0) { M_Blog_Msg msgMod = msgBll.SelReturnModel(model.ReplyID); model.ReplyUserID = msgMod.CUser; model.ReplyUName = msgMod.CUName; } if (string.IsNullOrEmpty(files) && !string.IsNullOrEmpty(Request.Form["Attach_Hid"])) { files = SafeSC.PathDeal(GetParam("Attach_Hid")); } if (!string.IsNullOrEmpty(files))//为安全,不允许全路径,必须后台对路径处理 { string uppath = B_Plat_Common.GetDirPath(upMod, B_Plat_Common.SaveType.Blog); foreach (string file in files.Split('|')) { if (string.IsNullOrEmpty(file)) { continue; } model.Attach += uppath + file + "|"; } } if (!string.IsNullOrEmpty(Request.Form["GOnlyMe_Chk"])) { model.GroupIDS = "0"; } else { model.GroupIDS = GetParam("GroupIDS_Chk"); } model.ColledIDS = ""; return(model); }
public ContentResult Blog_API() { //正数为plat,负数为bar string action = GetParam("action"); string result = ""; int id = DataConvert.CLng(Regex.Split(GetParam("value"), ":::")[0]); //思路,信息都存在贴吧中,ID为负数 switch (action) { case "add": { string puremsg = ""; msgMod = FillMsg(Request.Form["MsgContent_T"], out puremsg); result = msgBll.Insert(msgMod).ToString(); #region 步至微博 if (!string.IsNullOrWhiteSpace(Request.Form["sync_chk"])) { puremsg = StringHelper.SubStr(puremsg, 140, ""); string sync = Request.Form["sync_chk"]; M_User_Token tokenMod = tokenBll.SelModelByUid(mu.UserID); if (tokenMod != null) { try { if (sync.Contains("sina") && !string.IsNullOrWhiteSpace(tokenMod.SinaToken)) { //sinaBll = new SinaHelper(tokenMod.SinaToken); //string err = sinaBll.PostStatus(puremsg, (msgMod.Attach ?? "").Split('|')[0]); //ZLLog.L(err); } } catch (Exception ex) { ZLLog.L("[" + sync + "]同步失败,用户[" + mu.UserName + "]原因:" + ex.Message); } } } #endregion } break; case "addvote": { msgMod = FillMsg(Request.Form["MsgContent_T"]); msgMod.MsgType = 2; msgMod.Title = HttpUtility.HtmlEncode(GetParam("VoteTitle_T")); msgMod.VoteOP = Request.Form["VoteOption_T1"] + "," + Request.Form["VoteOption_T"]; //为Jquery验证 msgMod.VoteOP = HttpUtility.HtmlEncode(msgMod.VoteOP); msgMod.VoteResult = ""; msgMod.EndTime = DateTime.Parse(GetParam("EndDate_T")); result = msgBll.Insert(msgMod).ToString(); } break; case "addarticle": //里面包含html|图片|附件,暂不同步微博 { string msg = GetParam("msg"); UEHelper ueHelper = new UEHelper(); msgMod = FillMsg(""); msgMod.MsgContent = msg; msgMod.MsgType = 3; msgMod.Title = ueHelper.GetSubTitle(msgMod.MsgContent); result = msgBll.Insert(msgMod).ToString(); } break; case "AddReply": case "AddReply2": if (id == 0) { throw new Exception("传入的ID不正确"); } result = PlatAJAX(); break; case "UserVote": result = PlatAJAX(); break; default: if (id == 0) { throw new Exception("信息ID不正确"); } if (id > 0) { result = PlatAJAX(); } else { result = BarAJAX(); } break; } return(Content(result)); }
public void Content_Add() { M_Node nodeMod = nodeBll.SelReturnModel(NodeID); M_CommonData CData = new M_CommonData(); if (Mid > 0) { CData = conBll.GetCommonData(Mid); if (!CData.Inputer.Equals(mu.UserName)) { function.WriteErrMsg("你无权修改该内容"); } } else { CData.NodeID = NodeID; CData.ModelID = ModelID; CData.TableName = modBll.GetModelById(CData.ModelID).TableName; } DataTable dt = fieldBll.SelByModelID(CData.ModelID, false); Call commonCall = new Call(); DataTable table = commonCall.GetDTFromMVC(dt, Request); CData.Title = Request.Form["title"]; CData.Subtitle = Request["Subtitle"]; CData.PYtitle = Request["PYtitle"]; CData.TagKey = Request.Form["tagkey"]; CData.Status = nodeMod.SiteContentAudit; string parentTree = ""; CData.FirstNodeID = nodeBll.SelFirstNodeID(CData.NodeID, ref parentTree); CData.ParentTree = parentTree; CData.TitleStyle = Request.Form["TitleStyle"]; //CData.TopImg = Request.Form["selectpic"];//首页图片 if (Mid > 0)//修改内容 { conBll.UpdateContent(table, CData); } else { CData.DefaultSkins = 0; CData.EliteLevel = 0; CData.UpDateType = 2; CData.InfoID = ""; CData.RelatedIDS = ""; CData.Inputer = mu.UserName; CData.GeneralID = conBll.AddContent(table, CData); //插入信息给两个表,主表和从表:CData-主表的模型,table-从表 } if (Mid <= 0) //添加时增加积分 { //积分 if (SiteConfig.UserConfig.InfoRule > 0) { buser.ChangeVirtualMoney(mu.UserID, new M_UserExpHis() { UserID = mu.UserID, detail = "添加内容:" + CData.Title + "增加积分", score = SiteConfig.UserConfig.InfoRule, ScoreType = (int)M_UserExpHis.SType.Point }); } } string url = "MyContent?NodeID=" + CData.NodeID; if (nodeMod.CUName == "能力中心")//nodeMod.CUName.Equals("能力中心") { M_Blog_Msg msgMod = new M_Blog_Msg(); M_User_Plat upMod = B_User_Plat.GetLogin(); //M_Common_Notify comMod = new M_Common_Notify(); B_Blog_Msg msgBll = new B_Blog_Msg(); //B_Common_Notify comBll = new B_Common_Notify(); RegexHelper regHelper = new RegexHelper(); string msg = "#" + nodeMod.NodeName + "#[" + upMod.TrueName + "]发布了[<a href='/Item/" + CData.GeneralID + ".aspx' title='点击访问'>" + CData.Title + "</a>]"; string deftopic = "#插入话题#"; if (msg.Contains("#")) { msg = msg.Replace(deftopic, ""); string tlp = "<a href='/Plat/Blog?Skey={0}' title='话题浏览'>{1}</a>"; Dictionary <string, string> itemDic = new Dictionary <string, string>(); for (int i = 0; !string.IsNullOrEmpty(regHelper.GetValueBySE(msg, "#", "#", false)) && i < 5; i++)//最多不能超过5个话题 { string topic = "#" + regHelper.GetValueBySE(msg, "#", "#", false) + "#"; msg = msg.Replace(topic, "{" + i + "}"); topic = topic.Replace(" ", "").Replace(",", ""); itemDic.Add("{" + i + "}", string.Format(tlp, Server.UrlEncode(topic), topic)); msgMod.Topic += topic + ","; } foreach (var item in itemDic) { msg = msg.Replace(item.Key, item.Value); } } msgMod.MsgType = 1; msgMod.Status = 1; msgMod.CUser = upMod.UserID; msgMod.CUName = upMod.TrueName; msgMod.CompID = upMod.CompID; msgMod.ProID = 0; msgMod.pid = 0; msgMod.ReplyID = 0; msgMod.GroupIDS = ""; msgMod.ColledIDS = ""; msgMod.MsgContent = msg; msgMod.Title = CData.Title; msgMod.ID = msgBll.Insert(msgMod); url = "/Plat/Blog/"; } function.WriteSuccessMsg("操作成功!", url); }