public void DisplayComments(Template template, Primitive owner, ICommentableItem item, List<User> commenters, long commentCount, DisplayCommentHookHandler hook) { int page = core.CommentPageNumber; DisplayComments(template, owner, item, commenters, page, commentCount, hook); }
public void DisplayComments(Template template, Primitive owner, ICommentableItem item, List<User> commenters, int page, long commentCount, DisplayCommentHookHandler hook) { Mysql db = core.Db; long c = core.Functions.RequestLong("c", 0); if (c > 0) { SelectQuery query = new SelectQuery("comments"); query.AddFields("COUNT(*) AS total"); query.AddCondition("comment_item_id", item.Id); query.AddCondition("comment_item_type_id", item.ItemKey.TypeId); query.AddCondition("comment_id", ConditionEquality.LessThanEqual, c); if (commenters != null) { if (commenters.Count == 2) { if (item.Namespace == "USER") { QueryCondition qc1 = query.AddCondition("c.comment_item_id", commenters[0].Id); qc1.AddCondition("user_id", commenters[1].Id); QueryCondition qc2 = query.AddCondition(ConditionRelations.Or, "c.comment_item_id", commenters[1].Id); qc2.AddCondition("user_id", commenters[0].Id); query.AddCondition("c.comment_item_type_id", item.ItemKey.TypeId); } else { query.AddCondition("comment_item_id", item.Id); query.AddCondition("comment_item_type_id", item.ItemKey.TypeId); } } else { query.AddCondition("comment_item_id", item.Id); query.AddCondition("comment_item_type_id", item.ItemKey.TypeId); } } else { query.AddCondition("comment_item_id", item.Id); query.AddCondition("comment_item_type_id", item.ItemKey.TypeId); } query.AddSort(SortOrder.Ascending, "comment_time_ut"); DataRow commentsRow = db.Query(query).Rows[0]; long before = (long)commentsRow["total"]; long after = item.Comments - before - 1; if (item.CommentSortOrder == SortOrder.Ascending) { page = (int)(before / item.CommentsPerPage + 1); } else { page = (int)(after / item.CommentsPerPage + 1); } } if (core.Session.IsLoggedIn && core.Session.LoggedInMember != null) { template.Parse("LOGGED_IN", "TRUE"); template.Parse("LOGGED_IN_USER_DISPLAY_NAME", core.Session.LoggedInMember.DisplayName); template.Parse("LOGGED_IN_USER_ICON", core.Session.LoggedInMember.Icon); template.Parse("LOGGED_IN_USER_TILE", core.Session.LoggedInMember.Tile); template.Parse("LOGGED_IN_USER_SQUARE", core.Session.LoggedInMember.Square); } List<Comment> comments = Comment.GetComments(core, item.ItemKey, item.CommentSortOrder, page, item.CommentsPerPage, commenters); Comment.LoadUserInfoCache(core, comments); if (commentCount >= 0) { template.Parse("COMMENTS", commentCount.ToString()); } else if (((NumberedItem)item).Info.Comments >= 0) { template.Parse("COMMENTS", ((NumberedItem)item).Info.Comments.ToString()); } else { template.Parse("COMMENTS", comments.Count.ToString()); } template.Parse("ITEM_ID", item.Id.ToString()); template.Parse("ITEM_TYPE", item.ItemKey.TypeId.ToString()); if (item.CommentSortOrder == SortOrder.Ascending) { template.Parse("COMMENTS_ASC", "TRUE"); template.Parse("COMMENT_SORT", "asc"); } else { template.Parse("COMMENTS_DESC", "TRUE"); template.Parse("COMMENT_SORT", "desc"); } foreach (Comment comment in comments) { core.PrimitiveCache.LoadUserProfile(comment.UserId); } long lastId = 0; foreach (Comment comment in comments) { VariableCollection commentsVariableCollection = template.CreateChild("comment-list"); //commentsVariableCollection.ParseRaw("COMMENT", Bbcode.Parse(HttpUtility.HtmlEncode(comment.Body), core.session.LoggedInMember)); /*if ((!core.IsMobile) && (!string.IsNullOrEmpty(comment.BodyCache))) { core.Display.ParseBbcodeCache(commentsVariableCollection, "COMMENT", comment.BodyCache); } else*/ { core.Display.ParseBbcode(commentsVariableCollection, "COMMENT", comment.Body, true, null, null); } try { User commentPoster = core.PrimitiveCache[comment.UserId]; lastId = comment.Id; commentsVariableCollection.Parse("ID", comment.Id.ToString()); commentsVariableCollection.Parse("TYPE_ID", ItemKey.GetTypeId(core, typeof(Comment))); commentsVariableCollection.Parse("USERNAME", commentPoster.DisplayName); commentsVariableCollection.Parse("USER_ID", commentPoster.Id.ToString()); commentsVariableCollection.Parse("USER_DISPLAY_NAME", commentPoster.DisplayName); commentsVariableCollection.Parse("U_PROFILE", commentPoster.ProfileUri); commentsVariableCollection.Parse("U_QUOTE", core.Hyperlink.BuildCommentQuoteUri(comment.Id)); commentsVariableCollection.Parse("U_REPORT", core.Hyperlink.BuildCommentReportUri(comment.Id)); commentsVariableCollection.Parse("U_DELETE", core.Hyperlink.BuildCommentDeleteUri(comment.Id)); commentsVariableCollection.Parse("U_LIKE", core.Hyperlink.BuildLikeItemUri(comment.ItemTypeId, comment.Id)); commentsVariableCollection.Parse("TIME", core.Tz.DateTimeToString(comment.GetTime(core.Tz))); commentsVariableCollection.Parse("USER_ICON", commentPoster.Icon); commentsVariableCollection.Parse("USER_TILE", commentPoster.Tile); commentsVariableCollection.Parse("USER_SQUARE", commentPoster.Square); if (comment.Info.Likes > 0) { commentsVariableCollection.Parse("LIKES", string.Format("{0:d} ", comment.Info.Likes)); } if (comment.Info.Dislikes > 0) { commentsVariableCollection.Parse("DISLIKES", string.Format(" {0:d}", comment.Info.Dislikes)); } if (comment.Info.SharedTimes > 0) { commentsVariableCollection.Parse("SHARES", string.Format(" ({0:d})", comment.Info.SharedTimes)); } if (hook != null) { hook(new DisplayCommentHookEventArgs(core, owner, commentPoster, commentsVariableCollection)); } if (core.Session.IsLoggedIn) { if (owner.CanModerateComments(core.Session.LoggedInMember)) { commentsVariableCollection.Parse("MODERATE", "TRUE"); } } if (owner.IsItemOwner(commentPoster)) { commentsVariableCollection.Parse("OWNER", "TRUE"); commentsVariableCollection.Parse("NORMAL", "FALSE"); } else { commentsVariableCollection.Parse("OWNER", "FALSE"); commentsVariableCollection.Parse("NORMAL", "TRUE"); } if (comment.SpamScore >= 10) { commentsVariableCollection.Parse("IS_SPAM", "TRUE"); } } catch { // if userid is 0, anonymous commentsVariableCollection.Parse("USERNAME", "Anonymous"); commentsVariableCollection.Parse("TIME", core.Tz.DateTimeToString(comment.GetTime(core.Tz))); commentsVariableCollection.Parse("OWNER", "FALSE"); commentsVariableCollection.Parse("NORMAL", "TRUE"); } } template.Parse("LAST_ID", "lastId"); }
public void DisplayComments(Template template, User profileOwner, ICommentableItem item, DisplayCommentHookHandler hook) { DisplayComments(template, (Primitive)profileOwner, item, null, -1, hook); }