예제 #1
0
        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;
        }
예제 #2
0
        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;
        }
        public ActionResult EditPost(long threadId, long? postId = null)
        {
            BarThread thread = barThreadService.Get(threadId);

            if (thread == null)
            {
                return Redirect(SiteUrls.Instance().SystemMessage(TempData, new SystemMessageViewModel
                {
                    Body = "没有找到你要编辑的回帖",
                    Title = "没有找到回帖",
                    StatusMessageType = StatusMessageType.Hint
                }));
            }

            BarPost post = null;
            if (postId.HasValue)
            {
                post = barPostService.Get(postId ?? 0);
                if (!authorizer.BarPost_Edit(post))
                {
                    return Redirect(SiteUrls.Instance().SystemMessage(TempData, new SystemMessageViewModel
                    {
                        Body = "您没有权限编辑此回帖",
                        Title = "没有权限",
                        StatusMessageType = StatusMessageType.Hint
                    }));
                }
            }
            else
            {


                string errorMessage = string.Empty;
                if (!authorizer.BarPost_Create(thread.SectionId, out errorMessage))
                {


                    if (UserContext.CurrentUser == null)
                        return Redirect(SiteUrls.Instance().Login(true));

                    return Redirect(SiteUrls.Instance().SystemMessage(TempData, new SystemMessageViewModel
                    {
                        Body = errorMessage,
                        Title = "没有权限",
                        StatusMessageType = StatusMessageType.Hint
                    }));
                }
            }
            if (postId.HasValue && post == null)
            {
                return Redirect(SiteUrls.Instance().SystemMessage(TempData, new SystemMessageViewModel
                {
                    Body = "没有找到你要编辑的回帖",
                    Title = "没有找到回帖",
                    StatusMessageType = StatusMessageType.Hint
                }));
            }





            BarPostEditModel postModel = null;
            if (post != null)
                postModel = post.AsEditModel();
            else
            {
                postModel = new BarPostEditModel
                {
                    ThreadId = threadId,
                    PostId = postId,
                    Subject = thread.Subject
                };

                string body = Request.QueryString.Get<string>("MultilineBody", null);

                if (!string.IsNullOrEmpty(body))
                    postModel.Body = body = new EmotionService().EmoticonTransforms(body);
            }
            ViewData["PostBodyMaxLength"] = barSettings.PostBodyMaxLength;

            postModel.SectionId = thread.SectionId;
            return View(postModel);
        }