/// <summary> /// 动态处理程序 /// </summary> /// <param name="blogThread"></param> /// <param name="eventArgs"></param> private void BlogThreadActivityModule_After(BlogThread blogThread, AuditEventArgs eventArgs) { //生成动态 ActivityService activityService = new ActivityService(); AuditService auditService = new AuditService(); bool?auditDirection = auditService.ResolveAuditDirection(eventArgs.OldAuditStatus, eventArgs.NewAuditStatus); if (auditDirection == true) { //初始化Owner为用户的动态 Activity activityOfUser = Activity.New(); activityOfUser.ActivityItemKey = ActivityItemKeys.Instance().CreateBlogThread(); activityOfUser.ApplicationId = BlogConfig.Instance().ApplicationId; //判断是否有图片、音频、视频 AttachmentService attachmentService = new AttachmentService(TenantTypeIds.Instance().BlogThread()); IEnumerable <Attachment> attachments = attachmentService.GetsByAssociateId(blogThread.ThreadId); if (attachments != null && attachments.Any(n => n.MediaType == MediaType.Image)) { activityOfUser.HasImage = true; } activityOfUser.HasMusic = false; activityOfUser.HasVideo = false; activityOfUser.IsOriginalThread = !blogThread.IsReproduced; activityOfUser.IsPrivate = blogThread.PrivacyStatus == PrivacyStatus.Private ? true : false; activityOfUser.UserId = blogThread.UserId; activityOfUser.ReferenceId = 0; activityOfUser.ReferenceTenantTypeId = string.Empty; activityOfUser.SourceId = blogThread.ThreadId; activityOfUser.TenantTypeId = TenantTypeIds.Instance().BlogThread(); activityOfUser.OwnerId = blogThread.UserId; activityOfUser.OwnerName = blogThread.Author; activityOfUser.OwnerType = ActivityOwnerTypes.Instance().User(); //是否是公开的(用于是否推送站点动态) bool isPublic = blogThread.PrivacyStatus == PrivacyStatus.Public ? true : false; //生成动态 activityService.Generate(activityOfUser, true, isPublic); } //删除动态 else if (auditDirection == false) { activityService.DeleteSource(TenantTypeIds.Instance().BlogThread(), blogThread.ThreadId); } }
public JsonResult _Delete(string spaceKey, IEnumerable <long> threadIds) { foreach (var threadId in threadIds) { BlogThread blogThread = blogService.Get(threadId); if (authorizer.BlogThread_Delete(blogThread)) { blogService.Delete(blogThread); } else { return(Json(new StatusMessageData(StatusMessageType.Error, "无权操作!"))); } } return(Json(new StatusMessageData(StatusMessageType.Success, "删除日志成功!"))); }
/// <summary> /// BlogThread转换成<see cref="Lucene.Net.Documents.Document"/> /// </summary> /// <param name="blogThread">日志实体</param> /// <returns>Lucene.Net.Documents.Document</returns> public static Document Convert(BlogThread blogThread) { Document doc = new Document(); //索引日志基本信息 doc.Add(new Field(BlogIndexDocument.ThreadId, blogThread.ThreadId.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED)); doc.Add(new Field(BlogIndexDocument.TenantTypeId, blogThread.TenantTypeId, Field.Store.YES, Field.Index.NOT_ANALYZED)); doc.Add(new Field(BlogIndexDocument.OwnerId, blogThread.OwnerId.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED)); doc.Add(new Field(BlogIndexDocument.IsEssential, blogThread.IsEssential ? "1" : "0", Field.Store.YES, Field.Index.NOT_ANALYZED)); doc.Add(new Field(BlogIndexDocument.Keywords, blogThread.Keywords ?? "", Field.Store.NO, Field.Index.ANALYZED)); doc.Add(new Field(BlogIndexDocument.Summary, blogThread.Summary ?? "", Field.Store.NO, Field.Index.ANALYZED)); doc.Add(new Field(BlogIndexDocument.UserId, blogThread.UserId.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED)); doc.Add(new Field(BlogIndexDocument.Subject, blogThread.Subject.ToLower(), Field.Store.YES, Field.Index.ANALYZED)); doc.Add(new Field(BlogIndexDocument.Body, HtmlUtility.StripHtml(blogThread.GetBody(), true, false).ToLower(), Field.Store.NO, Field.Index.ANALYZED)); doc.Add(new Field(BlogIndexDocument.Author, blogThread.Author, Field.Store.YES, Field.Index.ANALYZED)); doc.Add(new Field(BlogIndexDocument.DateCreated, DateTools.DateToString(blogThread.DateCreated, DateTools.Resolution.DAY), Field.Store.YES, Field.Index.NOT_ANALYZED)); doc.Add(new Field(BlogIndexDocument.AuditStatus, ((int)blogThread.AuditStatus).ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED)); doc.Add(new Field(BlogIndexDocument.PrivacyStatus, ((int)blogThread.PrivacyStatus).ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED)); //索引日志tag foreach (string tagName in blogThread.TagNames) { doc.Add(new Field(BlogIndexDocument.Tag, tagName.ToLower(), Field.Store.YES, Field.Index.ANALYZED)); } //索引日志用户分类名称 IEnumerable<string> ownerCategoryNames = blogThread.OwnerCategoryNames; if (ownerCategoryNames != null) { foreach (string ownerCategoryName in ownerCategoryNames) { doc.Add(new Field(BlogIndexDocument.OwnerCategoryName, ownerCategoryName.ToLower(), Field.Store.YES, Field.Index.ANALYZED)); } } //索引日志站点分类ID long? siteCategoryId = blogThread.SiteCategoryId; if (siteCategoryId.HasValue) { doc.Add(new Field(BlogIndexDocument.SiteCategoryId, siteCategoryId.Value.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED)); } return doc; }
/// <summary> /// 置顶/取消置顶 /// </summary> /// <param name="isSticky">置顶为true;取消置顶为false</param> public JsonResult _BlogSetSticky(string spaceKey, long threadId, bool isSticky) { BlogThread blogThread = blogService.Get(threadId); if (blogThread == null) { return Json(new StatusMessageData(StatusMessageType.Error, "无效操作!")); } if (!DIContainer.Resolve<Authorizer>().BlogThread_Edit(blogThread)) { return Json(new StatusMessageData(StatusMessageType.Error, "没有权限!")); } blogService.SetSticky(threadId, isSticky); string message = isSticky ? "置顶成功!" : "取消置顶成功!"; return Json(new StatusMessageData(StatusMessageType.Success, message)); }
/// <summary> /// 隐私状态发生变化时,同时更新动态的私有状态 /// </summary> /// <param name="blogThread">日志</param> /// <param name="eventArgs">事件</param> private void BlogThreadAcitivityPrivicyChangeEventModule_After(BlogThread blogThread, CommonEventArgs eventArgs) { if (eventArgs.EventOperationType == EventOperationType.Instance().Create() || eventArgs.EventOperationType == EventOperationType.Instance().Update()) { ActivityService activityService = new ActivityService(); Activity activity = activityService.Get(TenantTypeIds.Instance().BlogThread(), blogThread.ThreadId); if (activity == null) { return; } bool newIsPrivate = blogThread.PrivacyStatus != PrivacyStatus.Public; if (activity.IsPrivate != newIsPrivate) { activityService.UpdatePrivateStatus(activity.ActivityId, newIsPrivate); } } }
/// <summary> /// 审核状态发生变化时处理积分 /// </summary> /// <param name="blogThread">日志</param> /// <param name="eventArgs">事件</param> private void BlogThreadPointModule_After(BlogThread blogThread, AuditEventArgs eventArgs) { AuditService auditService = new AuditService(); string pointItemKey = string.Empty; string eventOperationType = string.Empty; bool?auditDirection = auditService.ResolveAuditDirection(eventArgs.OldAuditStatus, eventArgs.NewAuditStatus); if (auditDirection == true) //加积分 { pointItemKey = PointItemKeys.Instance().Blog_CreateThread(); if (eventArgs.OldAuditStatus == null) { eventOperationType = EventOperationType.Instance().Create(); } else { eventOperationType = EventOperationType.Instance().Approved(); } } else if (auditDirection == false) //减积分 { pointItemKey = PointItemKeys.Instance().Blog_DeleteThread(); if (eventArgs.NewAuditStatus == null) { eventOperationType = EventOperationType.Instance().Delete(); } else { eventOperationType = EventOperationType.Instance().Disapproved(); } } if (!string.IsNullOrEmpty(pointItemKey)) { PointService pointService = new PointService(); string description = string.Format(ResourceAccessor.GetString("PointRecord_Pattern_" + eventOperationType), "日志", blogThread.Subject); pointService.GenerateByRole(blogThread.UserId, pointItemKey, description, eventOperationType == EventOperationType.Instance().Create() || eventOperationType == EventOperationType.Instance().Delete() && eventArgs.OperatorInfo.OperatorUserId == blogThread.UserId); } }
public ActionResult _CreateBlogComment(long ActivityId) { Activity activity = activityService.Get(ActivityId); if (activity == null) { return(Content(string.Empty)); } BlogThread thread = blogService.Get(activity.ReferenceId); if (thread == null) { return(Content(string.Empty)); } IEnumerable <Attachment> attachments = attachementService.GetsByAssociateId(thread.ThreadId); if (attachments != null && attachments.Count() > 0) { IEnumerable <Attachment> attachmentImages = attachments.Where(n => n.MediaType == MediaType.Image); if (attachmentImages != null && attachmentImages.Count() > 0) { ViewData["Attachments"] = attachmentImages.FirstOrDefault(); } } Comment comment = commentService.Get(activity.SourceId); if (comment == null) { return(Content(string.Empty)); } ViewData["BlogThread"] = thread; ViewData["ActivityId"] = ActivityId; IUserService userService = DIContainer.Resolve <IUserService>(); ViewData["UserService"] = userService; return(View(comment)); }
/// <summary> /// 文章操作文章事件处理 /// </summary> private void BlogOperationLogEventModule_After(BlogThread senders, CommonEventArgs eventArgs) { if (eventArgs.EventOperationType == EventOperationType.Instance().Delete() || eventArgs.EventOperationType == EventOperationType.Instance().Approved() || eventArgs.EventOperationType == EventOperationType.Instance().Disapproved() || eventArgs.EventOperationType == EventOperationType.Instance().SetEssential() || eventArgs.EventOperationType == EventOperationType.Instance().CancelEssential()) { OperationLogEntry entry = new OperationLogEntry(eventArgs.OperatorInfo); entry.ApplicationId = entry.ApplicationId; entry.Source = BlogConfig.Instance().ApplicationName; entry.OperationType = eventArgs.EventOperationType; entry.OperationObjectName = senders.Subject; entry.OperationObjectId = senders.ThreadId; entry.Description = string.Format(ResourceAccessor.GetString("OperationLog_Pattern_" + eventArgs.EventOperationType, entry.ApplicationId), "文章", entry.OperationObjectName); OperationLogService logService = Tunynet.DIContainer.Resolve <OperationLogService>(); logService.Create(entry); } }
/// <summary> /// 文章操作文章事件处理 /// </summary> private void BlogOperationLogEventModule_After(BlogThread senders, CommonEventArgs eventArgs) { if (eventArgs.EventOperationType == EventOperationType.Instance().Delete() || eventArgs.EventOperationType == EventOperationType.Instance().Approved() || eventArgs.EventOperationType == EventOperationType.Instance().Disapproved() || eventArgs.EventOperationType == EventOperationType.Instance().SetEssential() || eventArgs.EventOperationType == EventOperationType.Instance().CancelEssential()) { OperationLogEntry entry = new OperationLogEntry(eventArgs.OperatorInfo); entry.ApplicationId = entry.ApplicationId; entry.Source = BlogConfig.Instance().ApplicationName; entry.OperationType = eventArgs.EventOperationType; entry.OperationObjectName = senders.Subject; entry.OperationObjectId = senders.ThreadId; entry.Description = string.Format(ResourceAccessor.GetString("OperationLog_Pattern_" + eventArgs.EventOperationType, entry.ApplicationId), "文章", entry.OperationObjectName); OperationLogService logService = Tunynet.DIContainer.Resolve<OperationLogService>(); logService.Create(entry); } }
/// <summary> /// 评论文章 /// 1.锁定的文章不允许评论; /// 2.对于匿名用户,根据站点匿名用户; /// </summary> public static bool BlogComment_Create(this Authorizer authorizer, BlogThread blogThread) { //锁定的文章不允许评论 if (blogThread.IsLocked) { return false; } //允许登录用户 if (UserContext.CurrentUser != null) { return true; } //判断是否允许匿名用户评论 ISettingsManager<SiteSettings> siteSettingsManager = DIContainer.Resolve<ISettingsManager<SiteSettings>>(); SiteSettings siteSettings = siteSettingsManager.Get(); return siteSettings.EnableAnonymousPosting; }
public ActionResult Create(BlogThread BlogThread, int BlogId) { if (ModelState.IsValid) { //Save Blog Thread BlogThread.DateTime = System.DateTime.Now; BlogThread.UserId = 1; BlogThread.UserName = User.Identity.Name; BlogThread.BlogId = BlogId; shopDB.AddToBlogThreads(BlogThread); shopDB.SaveChanges(); return(RedirectToAction("Blog", "Category", new { id = BlogThread.BlogId })); } // Invalid – redisplay with errors var viewModel = new BlogThreadManagerViewModel { BlogThread = new BlogThread() }; return(View(viewModel)); }
/// <summary> /// 日志增量索引 /// </summary> private void BlogThread_After(BlogThread blog, CommonEventArgs eventArgs) { if (blog == null) { return; } if (blogSearcher == null) { blogSearcher = (BlogSearcher)SearcherFactory.GetSearcher(BlogSearcher.CODE); } //添加索引 if (eventArgs.EventOperationType == EventOperationType.Instance().Create()) { if (!blog.IsDraft) { blogSearcher.Insert(blog); } } //删除索引 if (eventArgs.EventOperationType == EventOperationType.Instance().Delete()) { blogSearcher.Delete(blog.ThreadId); } //更新索引 if (eventArgs.EventOperationType == EventOperationType.Instance().Update()) { if (!blog.IsDraft) { blogSearcher.Update(blog); } } }
public ActionResult Edit(string spaceKey, BlogThreadEditModel model) { string errorMessage = string.Empty; if (ModelState.HasBannedWord(out errorMessage)) { return(Redirect(SiteUrls.Instance().SystemMessage(TempData, new SystemMessageViewModel { Title = "发布失败", Body = errorMessage, StatusMessageType = StatusMessageType.Error }))); } BlogThread blogThread = null; //写日志 if (model.ThreadId == 0) { if (!authorizer.BlogThread_Create(spaceKey, out errorMessage)) { if (model.IsDraft) { return(Json(new StatusMessageData(StatusMessageType.Error, "没有权限创建新的日志!"))); } else { return(Redirect(SiteUrls.Instance().SystemMessage(TempData, new SystemMessageViewModel { Title = "没有权限", Body = errorMessage, StatusMessageType = StatusMessageType.Error }))); } } blogThread = model.AsBlogThread(); bool isCreated = blogService.Create(blogThread); if (!isCreated) { if (model.IsDraft) { return(Json(new StatusMessageData(StatusMessageType.Error, "发布失败,请稍后再试!"))); } else { return(Redirect(SiteUrls.Instance().SystemMessage(TempData, new SystemMessageViewModel { Title = "发布失败", Body = "发布失败,请稍后再试!", StatusMessageType = StatusMessageType.Error }))); } } } //编辑日志 else { blogThread = model.AsBlogThread(); if (!authorizer.BlogThread_Edit(blogThread)) { if (model.IsDraft) { return(Json(new StatusMessageData(StatusMessageType.Error, "没有权限编辑" + blogThread.Subject + "!"))); } else { return(Redirect(SiteUrls.Instance().SystemMessage(TempData, new SystemMessageViewModel { Title = "没有权限", Body = "没有权限编辑" + blogThread.Subject + "!", StatusMessageType = StatusMessageType.Error }))); } } //如果之前是草稿,现在正式发布,那么需要先删除草稿,然后创建新的日志 BlogThread oldBlogThread = blogService.Get(blogThread.ThreadId); if (oldBlogThread.IsDraft && !blogThread.IsDraft) { blogService.Delete(oldBlogThread); bool isCreated = blogService.Create(blogThread); } else { blogService.Update(blogThread); //清除用户分类 categoryService.ClearCategoriesFromItem(blogThread.ThreadId, blogThread.OwnerId, TenantTypeIds.Instance().BlogThread()); if (blogSettings.AllowSetSiteCategory) { //清除站点分类(投稿到) categoryService.ClearCategoriesFromItem(blogThread.ThreadId, 0, TenantTypeIds.Instance().BlogThread()); } //清除标签 tagService.ClearTagsFromItem(blogThread.ThreadId, blogThread.UserId); } } //设置隐私状态 UpdatePrivacySettings(blogThread, model.PrivacyStatus1, model.PrivacyStatus2); //设置用户分类 if (!string.IsNullOrEmpty(model.OwnerCategoryIds)) { string[] ownerCategoryIds = model.OwnerCategoryIds.TrimEnd(',').Split(','); categoryService.AddCategoriesToItem(ownerCategoryIds.Select(n => long.Parse(n)), blogThread.ThreadId, blogThread.OwnerId); } if (blogSettings.AllowSetSiteCategory) { //设置站点分类(投稿到) if (model.SiteCategoryId.HasValue) { categoryService.AddCategoriesToItem(new List <long> { model.SiteCategoryId.Value }, blogThread.ThreadId, 0); } } string tags = string.Join(",", model.TagNames); if (!string.IsNullOrEmpty(tags)) { tagService.AddTagsToItem(tags, blogThread.UserId, blogThread.ThreadId); } //如果是保存草稿,则返回Json if (blogThread.IsDraft) { return(Json(new { MessageType = StatusMessageType.Success, MessageContent = "保存成功!", ThreadId = blogThread.ThreadId })); } else { return(Redirect(SiteUrls.Instance().BlogDetail(spaceKey, blogThread.ThreadId))); //return Json(new { MessageType = StatusMessageType.Success, MessageContent = SiteUrls.Instance().BlogDetail(spaceKey, blogThread.ThreadId), ThreadId = blogThread.ThreadId }); } }
/// <summary> /// 更新索引 /// </summary> /// <param name="blogThread">待更新的日志</param> public void Update(BlogThread blogThread) { Document doc = BlogIndexDocument.Convert(blogThread); searchEngine.Update(doc, blogThread.ThreadId.ToString(), BlogIndexDocument.ThreadId); }
/// <summary> /// 审核状态发生变化时处理积分 /// </summary> /// <param name="blogThread">日志</param> /// <param name="eventArgs">事件</param> private void BlogThreadPointModule_After(BlogThread blogThread, AuditEventArgs eventArgs) { AuditService auditService = new AuditService(); string pointItemKey = string.Empty; string eventOperationType = string.Empty; bool? auditDirection = auditService.ResolveAuditDirection(eventArgs.OldAuditStatus, eventArgs.NewAuditStatus); if (auditDirection == true) //加积分 { pointItemKey = PointItemKeys.Instance().Blog_CreateThread(); if (eventArgs.OldAuditStatus == null) eventOperationType = EventOperationType.Instance().Create(); else eventOperationType = EventOperationType.Instance().Approved(); } else if (auditDirection == false) //减积分 { pointItemKey = PointItemKeys.Instance().Blog_DeleteThread(); if (eventArgs.NewAuditStatus == null) eventOperationType = EventOperationType.Instance().Delete(); else eventOperationType = EventOperationType.Instance().Disapproved(); } if (!string.IsNullOrEmpty(pointItemKey)) { PointService pointService = new PointService(); string description = string.Format(ResourceAccessor.GetString("PointRecord_Pattern_" + eventOperationType), "日志", blogThread.Subject); pointService.GenerateByRole(blogThread.UserId, pointItemKey, description, eventOperationType == EventOperationType.Instance().Create() || eventOperationType == EventOperationType.Instance().Delete() && eventArgs.OperatorInfo.OperatorUserId == blogThread.UserId); } }
/// <summary> /// 处理加精操作加积分 /// </summary> /// <param name="blogThread">日志</param> /// <param name="eventArgs">事件</param> private void BlogThreadPointModuleForManagerOperation_After(BlogThread blogThread, CommonEventArgs eventArgs) { NoticeService noticeService = new NoticeService(); string pointItemKey = string.Empty; if (eventArgs.EventOperationType == EventOperationType.Instance().SetEssential()) { pointItemKey = PointItemKeys.Instance().EssentialContent(); PointService pointService = new PointService(); string description = string.Format(ResourceAccessor.GetString("PointRecord_Pattern_" + eventArgs.EventOperationType), "日志", blogThread.ResolvedSubject); pointService.GenerateByRole(blogThread.UserId, pointItemKey, description); if (blogThread.UserId > 0) { Notice notice = Notice.New(); notice.UserId = blogThread.UserId; notice.ApplicationId = BlogConfig.Instance().ApplicationId; notice.TypeId = NoticeTypeIds.Instance().Hint(); notice.LeadingActor = blogThread.Author; notice.LeadingActorUrl = SiteUrls.FullUrl(SiteUrls.FullUrl(SiteUrls.Instance().SpaceHome(blogThread.UserId))); notice.RelativeObjectName = HtmlUtility.TrimHtml(blogThread.Subject, 64); notice.RelativeObjectUrl = SiteUrls.FullUrl(SiteUrls.Instance().BlogDetail(blogThread.User.UserName, blogThread.ThreadId)); notice.TemplateName = NoticeTemplateNames.Instance().ManagerSetEssential(); noticeService.Create(notice); } } }
/// <summary> /// 编辑文章 /// 空间主人或管理员可以编辑空间用户的文章(置顶也使用该规则) /// </summary> public static bool BlogThread_Edit(this Authorizer authorizer, BlogThread blogThread) { IUser currentUser = UserContext.CurrentUser; if (currentUser == null) { return false; } if (blogThread.UserId == currentUser.UserId || authorizer.IsAdministrator(BlogConfig.Instance().ApplicationId)) { return true; } return false; }
/// <summary> /// 日志详细页 /// </summary> public ActionResult Detail(string spaceKey, long threadId) { BlogThread blogThread = blogService.Get(threadId); if (blogThread == null) { return(HttpNotFound()); } if (!authorizer.BlogThread_View(blogThread)) { return(Redirect(SiteUrls.Instance().SystemMessage(TempData, new SystemMessageViewModel { Title = "没有权限", Body = "由于空间主人的权限设置,您无法浏览当前内容。", StatusMessageType = StatusMessageType.Hint }))); } long currentSpaceUserId = UserIdToUserNameDictionary.GetUserId(spaceKey); if (!authorizer.IsAdministrator(BlogConfig.Instance().ApplicationId) && blogThread.UserId != currentSpaceUserId && (int)blogThread.AuditStatus < (int)(new AuditService().GetPubliclyAuditStatus(BlogConfig.Instance().ApplicationId))) { return(Redirect(SiteUrls.Instance().SystemMessage(TempData, new SystemMessageViewModel { Title = "尚未通过审核", Body = "由于当前日志尚未通过审核,您无法浏览当前内容。", StatusMessageType = StatusMessageType.Hint }))); } //附件信息 IEnumerable <Attachment> attachments = attachmentService.GetsByAssociateId(threadId); if (attachments != null && attachments.Count() > 0) { ViewData["attachments"] = attachments.Where(n => n.MediaType == MediaType.Other); } //更新浏览计数 CountService countService = new CountService(TenantTypeIds.Instance().BlogThread()); countService.ChangeCount(CountTypes.Instance().HitTimes(), blogThread.ThreadId, blogThread.UserId, 1, false); //设置SEO信息 pageResourceManager.InsertTitlePart(blogThread.Author); pageResourceManager.InsertTitlePart(blogThread.ResolvedSubject); List <string> keywords = new List <string>(); keywords.AddRange(blogThread.TagNames); keywords.AddRange(blogThread.OwnerCategoryNames); string keyword = string.Join(" ", keywords.Distinct()); if (!string.IsNullOrEmpty(blogThread.Keywords)) { keyword += " " + blogThread.Keywords; } pageResourceManager.SetMetaOfKeywords(keyword); if (!string.IsNullOrEmpty(blogThread.Summary)) { pageResourceManager.SetMetaOfDescription(HtmlUtility.StripHtml(blogThread.Summary, true, false)); } return(View(blogThread)); }
/// <summary> /// 评论日志动态处理程序 /// </summary> /// <param name="comment"></param> /// <param name="eventArgs"></param> private void BlogCommentActivityEventModule_After(Comment comment, AuditEventArgs eventArgs) { NoticeService noticeService = new NoticeService(); BlogThread blogThread = null; if (comment.TenantTypeId == TenantTypeIds.Instance().BlogThread()) { //生成动态 ActivityService activityService = new ActivityService(); AuditService auditService = new AuditService(); bool? auditDirection = auditService.ResolveAuditDirection(eventArgs.OldAuditStatus, eventArgs.NewAuditStatus); if (auditDirection == true) { //创建评论的动态[关注评论者的粉丝可以看到该评论] Activity activity = Activity.New(); activity.ActivityItemKey = ActivityItemKeys.Instance().CreateBlogComment(); activity.ApplicationId = BlogConfig.Instance().ApplicationId; BlogService blogService = new BlogService(); blogThread = blogService.Get(comment.CommentedObjectId); if (blogThread == null || blogThread.UserId == comment.UserId) { return; } activity.IsOriginalThread = true; activity.IsPrivate = false; activity.OwnerId = comment.UserId; activity.OwnerName = comment.Author; activity.OwnerType = ActivityOwnerTypes.Instance().User(); activity.ReferenceId = blogThread.ThreadId; activity.ReferenceTenantTypeId = TenantTypeIds.Instance().BlogThread(); activity.SourceId = comment.Id; activity.TenantTypeId = TenantTypeIds.Instance().Comment(); activity.UserId = comment.UserId; //是否是公开的(用于是否推送站点动态) bool isPublic = blogThread.PrivacyStatus == PrivacyStatus.Public ? true : false; activityService.Generate(activity, false, isPublic); //创建评论的动态[关注该日志的用户可以看到该评论] Activity activityOfBlogComment = Activity.New(); activityOfBlogComment.ActivityItemKey = activity.ActivityItemKey; activityOfBlogComment.ApplicationId = activity.ApplicationId; activityOfBlogComment.IsOriginalThread = activity.IsOriginalThread; activityOfBlogComment.IsPrivate = activity.IsPrivate; activityOfBlogComment.ReferenceId = activity.ReferenceId; activityOfBlogComment.ReferenceTenantTypeId = activity.ReferenceTenantTypeId; activityOfBlogComment.SourceId = activity.SourceId; activityOfBlogComment.TenantTypeId = activity.TenantTypeId; activityOfBlogComment.UserId = activity.UserId; activityOfBlogComment.OwnerId = blogThread.ThreadId; activityOfBlogComment.OwnerName = blogThread.ResolvedSubject; activityOfBlogComment.OwnerType = ActivityOwnerTypes.Instance().Blog(); activityService.Generate(activityOfBlogComment, false, isPublic); } else if (auditDirection == false) { activityService.DeleteSource(TenantTypeIds.Instance().Comment(), comment.Id); } } }
/// <summary> /// 查看文章 /// 仅自己可见的只能是文章作者或管理员可以查看 /// 部分可见的只能是文章作者、指定可见的用户或管理员可以查看 /// </summary> public static bool BlogThread_View(this Authorizer authorizer, BlogThread blogThread) { if (blogThread.PrivacyStatus == PrivacyStatus.Public) { return true; } IUser currentUser = UserContext.CurrentUser; if (currentUser == null) { return false; } if (blogThread.UserId == currentUser.UserId || authorizer.IsAdministrator(BlogConfig.Instance().ApplicationId)) { return true; } if (blogThread.PrivacyStatus == PrivacyStatus.Private) { return false; } ContentPrivacyService contentPrivacyService = new ContentPrivacyService(); if (contentPrivacyService.Validate(blogThread, currentUser.UserId)) { return true; } return false; }
public ActionResult _Reproduce(string spaceKey, BlogThreadEditModel model) { IUser currentUser = UserContext.CurrentUser; BlogThread blogThread = blogService.Get(model.ThreadId); if (blogThread == null) { return(HttpNotFound()); } BlogThread reproducedBlogThread = BlogThread.New(); reproducedBlogThread.IsDraft = false; reproducedBlogThread.IsReproduced = true; reproducedBlogThread.Keywords = blogThread.Keywords; reproducedBlogThread.Subject = blogThread.Subject; reproducedBlogThread.Body = blogThread.GetBody(); reproducedBlogThread.Summary = blogThread.Summary; reproducedBlogThread.UserId = currentUser.UserId; reproducedBlogThread.OwnerId = currentUser.UserId; reproducedBlogThread.TenantTypeId = TenantTypeIds.Instance().User(); reproducedBlogThread.Author = currentUser.DisplayName; reproducedBlogThread.OriginalAuthorId = blogThread.OriginalAuthorId; reproducedBlogThread.PrivacyStatus = model.PrivacyStatus; reproducedBlogThread.FeaturedImage = blogThread.FeaturedImage; reproducedBlogThread.FeaturedImageAttachmentId = blogThread.FeaturedImageAttachmentId; reproducedBlogThread.OriginalThreadId = blogThread.ThreadId; //替换附件 IEnumerable <Attachment> attachments = attachmentService.GetsByAssociateId(blogThread.ThreadId); if (attachments != null && attachments.Count() > 0) { foreach (var attachment in attachments) { Attachment newAttachment = null; //如果该附件有售价并且该用户没有购买过(下载过)该附件则不转载附件 if (attachment.Price > 0 && !attachmentDownloadService.IsDownloaded(currentUser.UserId, attachment.AttachmentId)) { string oldAttach = "[attach:" + attachment.AttachmentId + "]"; reproducedBlogThread.Body = reproducedBlogThread.Body.Replace(oldAttach, ""); } else { newAttachment = attachmentService.CloneForUser(attachment, currentUser.UserId); string oldAttach = "[attach:" + attachment.AttachmentId + "]"; string newAttach = "[attach:" + newAttachment.AttachmentId + "]"; reproducedBlogThread.Body = reproducedBlogThread.Body.Replace(oldAttach, newAttach); //替换标题图 if (blogThread.FeaturedImageAttachmentId > 0 && blogThread.FeaturedImageAttachmentId == attachment.AttachmentId) { reproducedBlogThread.FeaturedImage = newAttachment.GetRelativePath() + "\\" + newAttachment.FileName; reproducedBlogThread.FeaturedImageAttachmentId = newAttachment.AttachmentId; } } } } bool isCreated = blogService.Create(reproducedBlogThread); if (!isCreated) { return(Redirect(SiteUrls.Instance().SystemMessage(TempData, new SystemMessageViewModel { Title = "发布失败", Body = "发布失败,请稍后再试!", StatusMessageType = StatusMessageType.Error }))); } //设置隐私状态 UpdatePrivacySettings(reproducedBlogThread, model.PrivacyStatus1, model.PrivacyStatus2); //设置用户分类 if (!string.IsNullOrEmpty(model.OwnerCategoryIds)) { string[] ownerCategoryIds = model.OwnerCategoryIds.TrimEnd(',').Split(','); categoryService.AddCategoriesToItem(ownerCategoryIds.Select(n => long.Parse(n)), reproducedBlogThread.ThreadId, reproducedBlogThread.OwnerId); } //设置标签(如此处理是因为标签选择器会输出两个同名的hidden input) if (model.TagNames != null && model.TagNames.Count() == 2 && !string.IsNullOrEmpty(model.TagNames.ElementAt(1))) { tagService.AddTagsToItem(model.TagNames.ElementAt(1), reproducedBlogThread.UserId, reproducedBlogThread.ThreadId); } return(Redirect(SiteUrls.Instance().BlogDetail(currentUser.UserName, reproducedBlogThread.ThreadId))); }
/// <summary> /// 隐私状态发生变化时,同时更新动态的私有状态 /// </summary> /// <param name="blogThread">日志</param> /// <param name="eventArgs">事件</param> private void BlogThreadAcitivityPrivicyChangeEventModule_After(BlogThread blogThread, CommonEventArgs eventArgs) { if (eventArgs.EventOperationType == EventOperationType.Instance().Create() || eventArgs.EventOperationType == EventOperationType.Instance().Update()) { ActivityService activityService = new ActivityService(); Activity activity = activityService.Get(TenantTypeIds.Instance().BlogThread(), blogThread.ThreadId); if (activity == null) { return; } bool newIsPrivate = blogThread.PrivacyStatus == PrivacyStatus.Private ? true : false; //是否是公开的(用于是否推送站点动态) bool isPublic = blogThread.PrivacyStatus == PrivacyStatus.Public ? true : false; if (activity.IsPrivate != newIsPrivate) { activityService.UpdatePrivateStatus(activity.ActivityId, newIsPrivate,isPublic); } } }
/// <summary> /// 添加索引 /// </summary> /// <param name="blogThread">待添加的日志</param> public void Insert(BlogThread blogThread) { Insert(new BlogThread[] { blogThread }); }
/// <summary> /// 动态处理程序 /// </summary> /// <param name="blogThread"></param> /// <param name="eventArgs"></param> private void BlogThreadActivityModule_After(BlogThread blogThread, AuditEventArgs eventArgs) { //生成动态 ActivityService activityService = new ActivityService(); AuditService auditService = new AuditService(); bool? auditDirection = auditService.ResolveAuditDirection(eventArgs.OldAuditStatus, eventArgs.NewAuditStatus); if (auditDirection == true) { //初始化Owner为用户的动态 Activity activityOfUser = Activity.New(); activityOfUser.ActivityItemKey = ActivityItemKeys.Instance().CreateBlogThread(); activityOfUser.ApplicationId = BlogConfig.Instance().ApplicationId; //判断是否有图片、音频、视频 AttachmentService attachmentService = new AttachmentService(TenantTypeIds.Instance().BlogThread()); IEnumerable<Attachment> attachments = attachmentService.GetsByAssociateId(blogThread.ThreadId); if (attachments != null && attachments.Any(n => n.MediaType == MediaType.Image)) { activityOfUser.HasImage = true; } activityOfUser.HasMusic = false; activityOfUser.HasVideo = false; activityOfUser.IsOriginalThread = !blogThread.IsReproduced; activityOfUser.IsPrivate = blogThread.PrivacyStatus == PrivacyStatus.Private ? true : false; activityOfUser.UserId = blogThread.UserId; activityOfUser.ReferenceId = 0; activityOfUser.ReferenceTenantTypeId = string.Empty; activityOfUser.SourceId = blogThread.ThreadId; activityOfUser.TenantTypeId = TenantTypeIds.Instance().BlogThread(); activityOfUser.OwnerId = blogThread.UserId; activityOfUser.OwnerName = blogThread.Author; activityOfUser.OwnerType = ActivityOwnerTypes.Instance().User(); //是否是公开的(用于是否推送站点动态) bool isPublic = blogThread.PrivacyStatus == PrivacyStatus.Public ? true : false; //生成动态 activityService.Generate(activityOfUser, true, isPublic); } //删除动态 else if (auditDirection == false) { activityService.DeleteSource(TenantTypeIds.Instance().BlogThread(), blogThread.ThreadId); } }
public ActionResult Edit(string spaceKey, long?threadId, long?ownerId) { BlogThreadEditModel model = null; BlogThread blogThread = null; //日志用户分类下拉列表 IEnumerable <Category> ownerCategories = null; //写日志 if (!threadId.HasValue) { string errorMessage = string.Empty; if (!authorizer.BlogThread_Create(spaceKey, out errorMessage)) { return(Redirect(SiteUrls.Instance().SystemMessage(TempData, new SystemMessageViewModel { Title = "没有权限", Body = errorMessage, StatusMessageType = StatusMessageType.Error }))); } model = new BlogThreadEditModel() { PrivacyStatus = PrivacyStatus.Public }; if (ownerId.HasValue) { model.OwnerId = ownerId; } //获取所有者分类 if (ownerId.HasValue) { ownerCategories = categoryService.GetOwnerCategories(ownerId.Value, TenantTypeIds.Instance().BlogThread()); } else { ownerCategories = categoryService.GetOwnerCategories(UserContext.CurrentUser.UserId, TenantTypeIds.Instance().BlogThread()); } pageResourceManager.InsertTitlePart("写日志"); } //编辑日志 else { blogThread = blogService.Get(threadId.Value); if (blogThread == null) { return(HttpNotFound()); } if (!authorizer.BlogThread_Edit(blogThread)) { return(Redirect(SiteUrls.Instance().SystemMessage(TempData, new SystemMessageViewModel { Title = "没有权限", Body = "没有权限编辑" + blogThread.Subject + "!", StatusMessageType = StatusMessageType.Error }))); } Dictionary <int, IEnumerable <ContentPrivacySpecifyObject> > privacySpecifyObjects = contentPrivacyService.GetPrivacySpecifyObjects(TenantTypeIds.Instance().BlogThread(), blogThread.ThreadId); if (privacySpecifyObjects.ContainsKey(SpecifyObjectTypeIds.Instance().User())) { IEnumerable <ContentPrivacySpecifyObject> userPrivacySpecifyObjects = privacySpecifyObjects[SpecifyObjectTypeIds.Instance().User()]; ViewData["userPrivacySpecifyObjects"] = string.Join(",", userPrivacySpecifyObjects.Select(n => n.SpecifyObjectId)); } if (privacySpecifyObjects.ContainsKey(SpecifyObjectTypeIds.Instance().UserGroup())) { IEnumerable <ContentPrivacySpecifyObject> userGroupPrivacySpecifyObjects = privacySpecifyObjects[SpecifyObjectTypeIds.Instance().UserGroup()]; ViewData["userGroupPrivacySpecifyObjects"] = string.Join(",", userGroupPrivacySpecifyObjects.Select(n => n.SpecifyObjectId)); } model = blogThread.AsEditModel(); //获取所有者分类 ownerCategories = categoryService.GetOwnerCategories(blogThread.OwnerId, TenantTypeIds.Instance().BlogThread()); IEnumerable <Category> selectedOwnerCategories = blogThread.OwnerCategories; Dictionary <long, Category> ownerCategoryDic = new Dictionary <long, Category>(); if (selectedOwnerCategories != null && selectedOwnerCategories.Count() > 0) { ownerCategoryDic = selectedOwnerCategories.ToDictionary(n => n.CategoryId, n => n); } ViewData["ownerCategoryDic"] = ownerCategoryDic; pageResourceManager.InsertTitlePart("编辑日志"); } ViewData["ownerCategories"] = ownerCategories; //日志站点分类下拉列表(投稿到) if (blogSettings.AllowSetSiteCategory) { IEnumerable <Category> siteCategories = categoryService.GetOwnerCategories(0, TenantTypeIds.Instance().BlogThread()); ViewData["siteCategories"] = new SelectList(siteCategories, "CategoryId", "CategoryName", blogThread == null ? null : blogThread.SiteCategoryId); } return(View(model)); }
/// <summary> /// 日志增量索引 /// </summary> private void BlogThread_After(BlogThread blog, CommonEventArgs eventArgs) { if (blog == null) { return; } if (blogSearcher == null) { blogSearcher = (BlogSearcher)SearcherFactory.GetSearcher(BlogSearcher.CODE); } //添加索引 if (eventArgs.EventOperationType == EventOperationType.Instance().Create()) { if (!blog.IsDraft) { blogSearcher.Insert(blog); } } //删除索引 if (eventArgs.EventOperationType == EventOperationType.Instance().Delete()) { blogSearcher.Delete(blog.ThreadId); } //更新索引 if (eventArgs.EventOperationType == EventOperationType.Instance().Update() || eventArgs.EventOperationType == EventOperationType.Instance().Approved() || eventArgs.EventOperationType == EventOperationType.Instance().Disapproved()) { if (!blog.IsDraft) { blogSearcher.Update(blog); } } }