/// <summary> /// Get the URL of the blog entry a comment was made against /// </summary> /// <param name="comment">The comment to find the blog entry URL for</param> /// <returns>The URL if found, otherwise an empty string</returns> public virtual string GetEntryUrlForComment(CommentItem comment) { if (comment != null) return LinkManager.GetItemUrl(ManagerFactory.EntryManagerInstance.GetBlogEntryByComment(comment).InnerItem); else return string.Empty; }
/// <summary> /// Get the name of the blog entry a comment was made against /// </summary> /// <param name="comment">The comment to find the blog entry title for</param> /// <returns>The title if found, otherwise an empty string</returns> public virtual string GetEntryTitleForComment(CommentItem comment) { if (comment != null) return ManagerFactory.EntryManagerInstance.GetBlogEntryByComment(comment).Title.Text; else return string.Empty; }
public virtual CommentItem[] LoadComments(CommentItem addedComment = null) { var comments = ManagerFactory.CommentManagerInstance.GetEntryComments(CurrentEntry); //if a comment has been added but is not coming back yet (i.e. being indexed), fake it if (addedComment != null && comments.Count(comment => comment.ID == addedComment.ID) == 0) { List<CommentItem> newList = new List<CommentItem> { addedComment }; newList.AddRange(comments); comments = newList.ToArray(); } return comments; }
protected virtual void LoadComments(CommentItem addedComment = null) { // Comments enabled and exist? var showCommentsList = CurrentBlog.EnableComments.Checked && !CurrentEntry.DisableComments.Checked; if (!showCommentsList || ManagerFactory.CommentManagerInstance.GetCommentsCount(CurrentEntry) == 0) { if (CommentList != null) { CommentList.Visible = false; } } else { if (ListViewComments != null) { ListViewComments.DataSource = CommentsListCore.LoadComments(addedComment); ListViewComments.DataBind(); } } }
/// <summary> /// Populates the velocity template context. Only the objects that were /// added in this method will be accessible in the mail template. /// </summary> /// <remarks>Override this to add your own data to the context</remarks> protected virtual void PopulateContext(WorkflowPipelineArgs args) { velocityContext.Put("args", args); velocityContext.Put("item", args.DataItem); velocityContext.Put("processor", args.ProcessorItem); velocityContext.Put("user", Sitecore.Context.User); velocityContext.Put("history", args.DataItem.State.GetWorkflow().GetHistory(args.DataItem)); velocityContext.Put("state", args.DataItem.State.GetWorkflowState()); velocityContext.Put("nextState", GetNextState(args)); velocityContext.Put("site", Sitecore.Context.Site); velocityContext.Put("time", DateTime.Now); EntryItem entryItem = null; if (args.DataItem.TemplateIsOrBasedOn(Settings.EntryTemplateID)) { entryItem = new EntryItem(args.DataItem); } else if (args.DataItem.TemplateIsOrBasedOn(Settings.CommentTemplateID)) { CommentItem commentItem = new CommentItem(args.DataItem); entryItem = ManagerFactory.EntryManagerInstance.GetBlogEntryByComment(commentItem); velocityContext.Put("comment", commentItem); } if (entryItem != null) { velocityContext.Put("entry", entryItem); if (!string.IsNullOrEmpty(entryItem.InnerItem.Statistics.CreatedBy)) { UserProfile createdBy = User.FromName(entryItem.InnerItem.Statistics.CreatedBy, false).Profile; velocityContext.Put("entryCreatedBy", createdBy); } if (!string.IsNullOrEmpty(entryItem.InnerItem.Statistics.UpdatedBy)) { UserProfile updatedBy = User.FromName(entryItem.InnerItem.Statistics.UpdatedBy, false).Profile; velocityContext.Put("entryUpdatedBy", updatedBy); } BlogHomeItem blog = ManagerFactory.BlogManagerInstance.GetCurrentBlog(entryItem); velocityContext.Put("blog", blog); } }
public CommentsList(ICommentsListCore commentsListCore) { CommentsListCore = commentsListCore ?? new CommentsListCore(CurrentBlog, CurrentEntry); Comments = new CommentItem[0]; }
/// <summary> /// Gets the entry item for the current comment. /// </summary> /// <param name="commentItem">The comment item.</param> /// <returns></returns> public virtual EntryItem GetBlogEntryByComment(CommentItem commentItem) { if (commentItem == null) return null; return commentItem.InnerItem.FindAncestorByAnyTemplate(Settings.EntryTemplateIds); }
public void Process(CreateCommentArgs args) { Assert.ArgumentNotNull(args, "args cannot be null"); Assert.IsNotNull(args.Database, "Database cannot be null"); Assert.IsNotNull(args.Comment, "Comment cannot be null"); Assert.IsNotNull(args.EntryID, "Entry ID cannot be null"); Assert.IsNotNull(args.Language, "Language cannot be null"); var entryItem = args.Database.GetItem(args.EntryID, args.Language); if (entryItem != null) { var blogItem = BlogManager.GetCurrentBlog(entryItem); if (blogItem != null) { var template = args.Database.GetTemplate(blogItem.BlogSettings.CommentTemplateID); var itemName = ItemUtil.ProposeValidItemName(string.Format("Comment at {0} by {1}", GetDateTime().ToString("yyyyMMdd HHmmss"), args.Comment.AuthorName)); if (itemName.Length > 100) { itemName = itemName.Substring(0, 100); } // verify the comment item name is unique for this entry var query = BuildFastQuery(entryItem, itemName); var num = 1; var nondupItemName = itemName; while (entryItem.Database.SelectSingleItem(query) != null) { nondupItemName = itemName + " " + num; num++; query = BuildFastQuery(entryItem, nondupItemName); } // need to create the comment within the shell site to ensure workflow is applied to comment var shellSite = SiteContextFactory.GetSiteContext(Sitecore.Constants.ShellSiteName); SiteContextSwitcher siteSwitcher = null; try { if (shellSite != null) { siteSwitcher = new SiteContextSwitcher(shellSite); } using (new SecurityDisabler()) { var newItem = entryItem.Add(nondupItemName, template); var newComment = new CommentItem(newItem); newComment.BeginEdit(); newComment.Name.Field.Value = args.Comment.AuthorName; newComment.Email.Field.Value = args.Comment.AuthorEmail; newComment.Comment.Field.Value = args.Comment.Text; foreach (var entry in args.Comment.Fields) { newComment.InnerItem[entry.Key] = entry.Value; } newComment.EndEdit(); args.CommentItem = newComment; } } finally { siteSwitcher?.Dispose(); } } else { var message = "Failed to find blog for entry {0}\r\nIgnoring comment: name='{1}', email='{2}', commentText='{3}'"; Logger.Error(string.Format(message, args.EntryID, args.Comment.AuthorName, args.Comment.AuthorEmail, args.Comment.Text), typeof(CreateCommentItem)); } } else { var message = "Failed to find blog entry {0}\r\nIgnoring comment: name='{1}', email='{2}', commentText='{3}'"; Logger.Error(string.Format(message, args.EntryID, args.Comment.AuthorName, args.Comment.AuthorEmail, args.Comment.Text), typeof(CreateCommentItem)); } }