Ejemplo n.º 1
0
        /// <summary>
        /// 内容处理
        /// </summary>
        /// <param name="body">待处理内容</param>
        /// <param name="associateId">待处理相关项Id</param>
        /// <param name="userId">相关项作者</param>
        /// <param name="ownerId">拥有者Id</param>
        /// <returns></returns>
        public string Process(string body, string ownerTenantTypeId, long associateId, long userId, long ownerId)
        {
            string tenantTypeId = TenantTypeIds.Instance().Microblog();
            AtUserService atUserService = new AtUserService(tenantTypeId);
            body = atUserService.ResolveBodyForDetail(body, associateId, userId, AtUserTagGenerate);

            TagService tagService = new TagService(tenantTypeId);

            Func<KeyValuePair<string, long>, long, string> topicTagGenerate = delegate(KeyValuePair<string, long> _tagNameWithId, long _ownerId)
            {
                return string.Format("<a href=\"{1}\">#{0}#</a>", _tagNameWithId.Key, MicroblogUrlGetterFactory.Get(ownerTenantTypeId).TopicDetail(_tagNameWithId.Key.Trim(), _ownerId));
            };

            body = tagService.ResolveBodyForDetail(body, associateId, ownerId, topicTagGenerate);

            body = body.Replace("\n", "<br/>");

            EmotionService emotionService = DIContainer.Resolve<EmotionService>();
            body = emotionService.EmoticonTransforms(body);

            ParsedMediaService parsedMediaService = DIContainer.Resolve<ParsedMediaService>();
            body = parsedMediaService.ResolveBodyForDetail(body, associateId, userId, UrlTagGenerate);

            return body;
        }
Ejemplo n.º 2
0
        /// <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(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 = "<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;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 内容处理
        /// </summary>
        /// <param name="body">待处理内容</param>
        /// <param name="associateId">待处理相关项Id</param>
        /// <param name="userId">相关项作者</param>
        /// <param name="tenantTypeId">租户类型Id</param>
        /// <returns></returns>
        public string Process(string body, string tenantTypeId, long associateId, long userId)
        {
            tenantTypeId = TenantTypeIds.Instance().Comment();

            AtUserService atUserService = new AtUserService(tenantTypeId);
            atUserService.ResolveBodyForEdit(body, userId, associateId);
            body = atUserService.ResolveBodyForDetail(body, associateId, userId, AtUserTagGenerate);

            EmotionService emotionService = DIContainer.Resolve<EmotionService>();
            body = emotionService.EmoticonTransforms(body);

            return body;
        }
Ejemplo n.º 4
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;
        }