public string Process(string body, string tenantTypeId, long associateId, long userId) { //解析at用户 AtUserService atUserService = new AtUserService(TenantTypeIds.Instance().BlogThread()); body = atUserService.ResolveBodyForDetail(body, associateId, userId, AtUserTagGenerate); AttachmentService attachmentService = new AttachmentService(tenantTypeId); IEnumerable <Attachment> attachments = attachmentService.GetsByAssociateId(associateId); if (attachments != null && attachments.Count() > 0) { IList <BBTag> bbTags = new List <BBTag>(); string htmlTemplate = "<div class=\"tn-annexinlaid\"><a href=\"javascript:;\" target=\"_blank\" menu=\"#attachement-artdialog-{4}\">{0}</a>(<em>{1}</em>{2},<em>下载次数:{3}</em>)</div>"; //解析文本中附件 IEnumerable <Attachment> attachmentsFiles = attachments.Where(n => n.MediaType != MediaType.Image); foreach (var attachment in attachmentsFiles) { bbTags.Add(AddBBTag(htmlTemplate, attachment)); } body = HtmlUtility.BBCodeToHtml(body, bbTags); } body = new EmotionService().EmoticonTransforms(body); body = DIContainer.Resolve <ParsedMediaService>().ResolveBodyForHtmlDetail(body, ParsedMediaTagGenerate); return(body); }
/// <summary> /// 手机端帖子正文解析器 /// </summary> /// <param name="body"></param> /// <param name="tenantTypeId"></param> /// <param name="associateId"></param> /// <param name="userId"></param> /// <returns></returns> public string ProcessForMobile(string body, string tenantTypeId, long associateId, long userId) { //解析at用户 AtUserService atUserService = new AtUserService(tenantTypeId); body = atUserService.ResolveBodyForDetail(body, associateId, userId, AtUserTagGenerate); AttachmentService attachmentService = new AttachmentService(tenantTypeId); IEnumerable <Attachment> attachments = attachmentService.GetsByAssociateId(associateId); if (attachments != null && attachments.Count() > 0) { IList <BBTag> bbTags = new List <BBTag>(); string htmlTemplate = "<a href=\"{1}\" target=\"_blank\" menu=\"#attachement-artdialog-{2}\">{0}</a>"; //解析文本中附件 IEnumerable <Attachment> attachmentsFiles = attachments.Where(n => n.MediaType != MediaType.Image); foreach (var attachment in attachmentsFiles) { bbTags.Add(AddBBTagForMobile(htmlTemplate, attachment)); } body = HtmlUtility.BBCodeToHtml(body, bbTags); } body = new EmotionService().EmoticonTransforms(body); body = DIContainer.Resolve <ParsedMediaService>().ResolveBodyForHtmlDetail(body, ParsedMediaTagGenerateForMobile); return(body); }
public string Process(string body, string tenantTypeId, long associateId, long userId) { if (string.IsNullOrEmpty(body) || !body.Contains("[attach:")) { return(body); } List <long> attachmentIds = new List <long>(); Regex rg = new Regex(@"\[attach:(?<id>[\d]+)\]", RegexOptions.Multiline | RegexOptions.Singleline); MatchCollection matches = rg.Matches(body); if (matches != null) { foreach (Match m in matches) { if (m.Groups["id"] == null || string.IsNullOrEmpty(m.Groups["id"].Value)) { continue; } long attachmentId = 0; long.TryParse(m.Groups["id"].Value, out attachmentId); if (attachmentId > 0 && !attachmentIds.Contains(attachmentId)) { attachmentIds.Add(attachmentId); } } } IEnumerable <ContentAttachment> attachments = new ContentAttachmentService().Gets(attachmentIds); if (attachments != null && attachments.Count() > 0) { IList <BBTag> bbTags = new List <BBTag>(); string htmlTemplate = "<div class=\"tn-annexinlaid\"><a href=\"{3}\" rel=\"nofollow\">{0}</a>(<em>{1}</em>,<em>下载次数:{2}</em>)<a href=\"{3}\" rel=\"nofollow\">下载</a> </div>"; //解析文本中附件 foreach (var attachment in attachments) { bbTags.Add(AddBBTag(htmlTemplate, attachment)); } body = HtmlUtility.BBCodeToHtml(body, bbTags); } return(body); }
public string Process(string body, string tenantTypeId, long associateId, long userId) { //if (string.IsNullOrEmpty(body) || !body.Contains("[attach:")) // return body; //List<long> attachmentIds = new List<long>(); //Regex rg = new Regex(@"\[attach:(?<id>[\d]+)\]", RegexOptions.Multiline | RegexOptions.Singleline); //MatchCollection matches = rg.Matches(body); //if (matches != null) //{ // foreach (Match m in matches) // { // if (m.Groups["id"] == null || string.IsNullOrEmpty(m.Groups["id"].Value)) // continue; // long attachmentId = 0; // long.TryParse(m.Groups["id"].Value, out attachmentId); // if (attachmentId > 0 && !attachmentIds.Contains(attachmentId)) // attachmentIds.Add(attachmentId); // } //} //IEnumerable<ContentAttachment> attachments = new ContentAttachmentService().Gets(attachmentIds); //if (attachments != null && attachments.Count() > 0) //{ // IList<BBTag> bbTags = new List<BBTag>(); // string htmlTemplate = "<div class=\"tn-annexinlaid\"><a href=\"{3}\" rel=\"nofollow\">{0}</a>(<em>{1}</em>,<em>下载次数:{2}</em>)<a href=\"{3}\" rel=\"nofollow\">下载</a> </div>"; // //解析文本中附件 // foreach (var attachment in attachments) // { // bbTags.Add(AddBBTag(htmlTemplate, attachment)); // } // body = HtmlUtility.BBCodeToHtml(body, bbTags); //} //解析at用户 AtUserService atUserService = new AtUserService(tenantTypeId); body = atUserService.ResolveBodyForDetail(body, associateId, userId, AtUserTagGenerate); AttachmentService attachmentService = new AttachmentService(tenantTypeId); IEnumerable <Attachment> attachments = attachmentService.GetsByAssociateId(associateId); if (attachments != null && attachments.Count() > 0) { IList <BBTag> bbTags = new List <BBTag>(); string htmlTemplate = "<div class=\"tn-annexinlaid\"><a href=\"{3}\" rel=\"nofollow\">{0}</a>(<em>{1}</em>,<em>下载次数:{2}</em>)<a href=\"{3}\" rel=\"nofollow\">下载</a> </div>"; //解析文本中附件 IEnumerable <Attachment> attachmentsFiles = attachments.Where(n => n.MediaType != MediaType.Image); foreach (var attachment in attachmentsFiles) { bbTags.Add(AddBBTag(htmlTemplate, attachment)); } body = HtmlUtility.BBCodeToHtml(body, bbTags); } body = new EmotionService().EmoticonTransforms(body); body = DIContainer.Resolve <ParsedMediaService>().ResolveBodyForHtmlDetail(body, ParsedMediaTagGenerate); return(body); }