public CommentInfo(List <Node> comments, List <Node> likesForComments, string markupStr) { var commentsMarkup = new StringBuilder(); var hiddenComments = new StringBuilder(); var index = 0; foreach (var comment in comments) { var likesForComment = likesForComments.Where(l => RepositoryPath.GetParentPath(RepositoryPath.GetParentPath(l.Path)) == comment.Path).ToList(); var commentGc = comment as GenericContent; var commentLikeInfo = new LikeInfo(likesForComment, commentGc.Id); var commentMarkup = WallHelper.GetCommentMarkup(markupStr, commentGc.CreationDate, commentGc.CreatedBy as User, commentGc.Description, commentGc.Id, commentLikeInfo, comment); // if it is one of the last two comments, add it to visible comments list, otherwise to hidden comments list if (index < comments.Count - 2) { hiddenComments.Append(commentMarkup); } else { commentsMarkup.Append(commentMarkup); } index++; } CommentsMarkup = commentsMarkup.ToString(); HiddenCommentsMarkup = hiddenComments.ToString(); CommentCount = comments.Count; }
public CommentInfo(int itemId) { var comments = new StringBuilder(); var hiddenComments = new StringBuilder(); var commentsResult = DataLayer.GetComments(itemId); if (commentsResult == null) { return; } var index = 0; foreach (var comment in commentsResult.Nodes) { var commentGc = comment as GenericContent; var commentLikeInfo = new LikeInfo(commentGc.Id); var commentMarkup = WallHelper.GetCommentMarkup(commentGc.CreationDate, commentGc.CreatedBy as User, commentGc.Description, commentGc.Id, commentLikeInfo, comment); // if it is one of the last two comments, add it to visible comments list, otherwise to hidden comments list if (index < commentsResult.Count - 2) { hiddenComments.Append(commentMarkup); } else { comments.Append(commentMarkup); } index++; } CommentsMarkup = comments.ToString(); HiddenCommentsMarkup = hiddenComments.ToString(); CommentCount = commentsResult.Count; }
public ActionResult Like(string itemId, string contextPath, bool fullMarkup, string rnd) { AssertPermission(); SetCurrentWorkspace(contextPath); var parentId = 0; DataLayer.CreateLike(itemId, contextPath, out parentId); var likeInfo = new LikeInfo(parentId); return(Json(fullMarkup ? likeInfo.GetLongMarkup() : likeInfo.GetShortMarkup(), JsonRequestBehavior.AllowGet)); }
/// <summary> /// Gets markup for a Comment control /// </summary> /// <returns></returns> public static string GetCommentControlMarkup(Node contextNode, out int commentCount, out int likeCount) { // get comments for this content var contentCommentInfo = new CommentInfo(contextNode.Id); // get likes for this content var contentLikeInfo = new LikeInfo(contextNode.Id); var markupStr = WallHelper.GetCommentControlMarkup( contextNode, contentCommentInfo.HiddenCommentsMarkup, contentCommentInfo.CommentsMarkup, contentCommentInfo.CommentCount, contentLikeInfo); commentCount = contentCommentInfo.CommentCount; likeCount = contentLikeInfo.Count; return(markupStr); }
public ActionResult GetLikeList(string itemId, string contextPath, string rnd) { if (!HasPermission()) { return(Json(SNSR.GetString(SNSR.Wall.PleaseLogIn), JsonRequestBehavior.AllowGet)); } SetCurrentWorkspace(contextPath); var id = PostInfo.GetIdFromClientId(itemId); // create like markup var likeInfo = new LikeInfo(id); var likelist = new StringBuilder(); foreach (var likeitem in likeInfo.LikeUsers) { var likeuser = likeitem as User; likelist.Append(WallHelper.GetLikeListItemMarkup(likeuser)); } return(Json(likelist.ToString(), JsonRequestBehavior.AllowGet)); }
/// <summary> /// Gets markup for a Post. /// </summary> /// <returns></returns> public static string GetPostMarkup(PostInfo postInfo, string contextPath, string hiddenCommentsMarkup, string commentsMarkup, int commentCount, LikeInfo likeInfo, bool drawBoundary) { var markupStr = postInfo.Type == PostType.BigPost ? GetBigPostMarkupStr() : GetSmallPostMarkupStr(); var commentSectionStr = GetCommentSectionMarkupStr(); return(GetPostMarkup(markupStr, commentSectionStr, postInfo, contextPath, hiddenCommentsMarkup, commentsMarkup, commentCount, likeInfo, drawBoundary)); }
public static string GetCommentMarkup(string markupStr, DateTime creationDate, User user, string text, int commentId, LikeInfo likeInfo, Node commentNode) { if (markupStr == null) { return(null); } markupStr = ReplaceResources(markupStr); markupStr = markupStr.Replace("{{commentid}}", commentId.ToString()); markupStr = markupStr.Replace("{{avatar}}", UITools.GetAvatarUrl(user)); markupStr = markupStr.Replace("{{username}}", user.FullName); markupStr = markupStr.Replace("{{userlink}}", Actions.ActionUrl(Content.Create(user), "Profile")); markupStr = markupStr.Replace("{{text}}", text); markupStr = markupStr.Replace("{{date}}", creationDate.ToString()); markupStr = markupStr.Replace("{{friendlydate}}", UITools.GetFriendlyDate(creationDate)); markupStr = markupStr.Replace("{{likeboxdisplay}}", likeInfo.Count > 0 ? "inline" : "none"); markupStr = markupStr.Replace("{{likes}}", likeInfo.GetShortMarkup()); markupStr = markupStr.Replace("{{ilikedisplay}}", !likeInfo.iLike ? "inline" : "none"); markupStr = markupStr.Replace("{{iunlikedisplay}}", likeInfo.iLike ? "inline" : "none"); // user interaction allowed var haspermission = WallHelper.HasLikePermission(commentNode); markupStr = markupStr.Replace("{{interactdisplay}}", haspermission ? "inline" : "none"); // show 'like' icon for comment likes if user does not have permission -> in this case like icon would not appear since like link is hidden markupStr = markupStr.Replace("{{interactclass}}", haspermission ? string.Empty : "sn-commentlike"); return(markupStr); }
/// <summary> /// Gets markup for a comment. /// </summary> /// <param name="creationDate">Date when the comment was created</param> /// <param name="user">User who created the comment.</param> /// <param name="text">Text of the comment.</param> /// <returns></returns> public static string GetCommentMarkup(DateTime creationDate, User user, string text, int commentId, LikeInfo likeInfo, Node commentNode) { var markupStr = GetCommentMarkupStr(); return(GetCommentMarkup(markupStr, creationDate, user, text, commentId, likeInfo, commentNode)); }
public static string GetContentWallMarkup(string markupStr, Node contextNode, string hiddenCommentsMarkup, string commentsMarkup, int commentCount, LikeInfo likeInfo, string postsMarkup) { if (markupStr == null) { return(null); } markupStr = ReplaceResources(markupStr); markupStr = markupStr.Replace("{{postid}}", contextNode.Id.ToString()); markupStr = markupStr.Replace("{{hiddencomments}}", hiddenCommentsMarkup); markupStr = markupStr.Replace("{{comments}}", commentsMarkup); markupStr = markupStr.Replace("{{hiddencommentboxdisplay}}", commentCount > 2 ? "block" : "none"); markupStr = markupStr.Replace("{{commentcount}}", commentCount.ToString()); markupStr = markupStr.Replace("{{likeboxdisplay}}", likeInfo.Count > 0 ? "block" : "none"); markupStr = markupStr.Replace("{{likes}}", likeInfo.GetLongMarkup()); markupStr = markupStr.Replace("{{ilikedisplay}}", !likeInfo.iLike ? "inline" : "none"); markupStr = markupStr.Replace("{{iunlikedisplay}}", likeInfo.iLike ? "inline" : "none"); var content = Content.Create(contextNode); var contextGc = contextNode as GenericContent; markupStr = markupStr.Replace("{{shareicon}}", IconHelper.ResolveIconPath(contextGc.Icon, 32)); markupStr = markupStr.Replace("{{sharedisplayname}}", content.DisplayName); markupStr = markupStr.Replace("{{sharecontenttype}}", contextGc.NodeType.Name); markupStr = markupStr.Replace("{{sharepath}}", contextGc.Path); var ws = Workspace.GetWorkspaceWithWallForNode(contextNode); if (ws == null) { ws = Workspace.GetWorkspaceForNode(contextNode); } if (ws != null) { var wsContent = Content.Create(ws); markupStr = markupStr.Replace("{{sharetargetdefaultpath}}", ws.Path); markupStr = markupStr.Replace("{{sharetargetdefaultname}}", wsContent.DisplayName); markupStr = markupStr.Replace("{{workspacepath}}", ws.Path); markupStr = markupStr.Replace("{{workspacename}}", wsContent.DisplayName); } else { markupStr = markupStr.Replace("{{sharetargetdefaultpath}}", string.Empty); markupStr = markupStr.Replace("{{sharetargetdefaultname}}", string.Empty); } // always include profile link - it will be created if not yet exists var currentUser = User.Current as User; markupStr = markupStr.Replace("{{mywallpath}}", Actions.ActionUrl(Content.Create(currentUser), "Profile")); markupStr = markupStr.Replace("{{mywallname}}", "My wall"); markupStr = markupStr.Replace("{{mywalldisplay}}", "inline"); markupStr = markupStr.Replace("{{workspacedisplay}}", ws != null ? "inline" : "none"); markupStr = markupStr.Replace("{{posts}}", postsMarkup); // user interaction allowed markupStr = markupStr.Replace("{{interactdisplay}}", WallHelper.HasWallPermission(contextNode.Path, contextNode) ? "block" : "none"); return(markupStr); }
/// <summary> /// Gets markup for a Content Wall /// </summary> /// <param name="contextId"></param> /// <param name="hiddenCommentsMarkup"></param> /// <param name="commentsMarkup"></param> /// <param name="commentCount"></param> /// <returns></returns> public static string GetContentWallMarkup(Node contextNode, string hiddenCommentsMarkup, string commentsMarkup, int commentCount, LikeInfo likeInfo, string postsMarkup) { var markupStr = GetContentWallMarkupStr(); return(GetContentWallMarkup(markupStr, contextNode, hiddenCommentsMarkup, commentsMarkup, commentCount, likeInfo, postsMarkup)); }
/// <summary> /// Gets markup for a Comment control /// </summary> /// <returns></returns> public static string GetCommentControlMarkup(Node contextNode, string hiddenCommentsMarkup, string commentsMarkup, int commentCount, LikeInfo likeInfo) { var markupStr = WallHelper.GetMarkupString("$skin/renderers/Wall/CommentControl.html"); if (markupStr == null) { return(null); } markupStr = ReplaceResources(markupStr); markupStr = markupStr.Replace("{{postid}}", contextNode.Id.ToString()); markupStr = markupStr.Replace("{{hiddencomments}}", hiddenCommentsMarkup); markupStr = markupStr.Replace("{{comments}}", commentsMarkup); markupStr = markupStr.Replace("{{hiddencommentboxdisplay}}", commentCount > 2 ? "block" : "none"); markupStr = markupStr.Replace("{{commentcount}}", commentCount.ToString()); markupStr = markupStr.Replace("{{likeboxdisplay}}", likeInfo.Count > 0 ? "block" : "none"); markupStr = markupStr.Replace("{{likes}}", likeInfo.GetLongMarkup()); markupStr = markupStr.Replace("{{ilikedisplay}}", !likeInfo.iLike ? "inline" : "none"); markupStr = markupStr.Replace("{{iunlikedisplay}}", likeInfo.iLike ? "inline" : "none"); // user interaction allowed markupStr = markupStr.Replace("{{interactdisplay}}", WallHelper.HasWallPermission(contextNode.Path, contextNode) ? "block" : "none"); return(markupStr); }
public static string GetWallPostsMarkup(string contextPath, List <PostInfo> posts) { if (posts.Count == 0) { return(string.Empty); } // create query for comments and likes var csb = new StringBuilder(); var paths = new List <string>(); foreach (var postInfo in posts) { if (postInfo.IsJournal) { continue; } paths.Add(postInfo.Path); } List <Node> allComments; List <Node> allLikes; if (paths.Count == 0) // only non-persisted journal posts are there to show (no comments or likes) { allComments = new List <Node>(); allLikes = new List <Node>(); } else { var settings = new QuerySettings() { EnableAutofilters = FilterStatus.Disabled }; var allCommentsAndLikes = ContentQuery.Query(ContentRepository.SafeQueries.InTreeAndTypeIs, settings, paths, new[] { "Comment", "Like" }).Nodes.ToList(); var commentNodeTypeId = NodeType.GetByName("Comment").Id; var likeTypeId = NodeType.GetByName("Like").Id; allComments = allCommentsAndLikes.Where(c => c.NodeTypeId == commentNodeTypeId).ToList(); allLikes = allCommentsAndLikes.Where(l => l.NodeTypeId == likeTypeId).ToList(); } var bigPostMarkupStr = GetBigPostMarkupStr(); var smallPostMarkupStr = GetSmallPostMarkupStr(); var commentMarkupStr = GetCommentMarkupStr(); var commentSectionStr = GetCommentSectionMarkupStr(); PostInfo prevPost = null; var sb = new StringBuilder(); foreach (var postInfo in posts) { // get comments and likes for post CommentInfo commentInfo; LikeInfo likeInfo; if (postInfo.IsJournal) { commentInfo = new CommentInfo(); likeInfo = new LikeInfo(); } else { var commentsForPost = allComments.Where(c => RepositoryPath.GetParentPath(RepositoryPath.GetParentPath(c.Path)) == postInfo.Path).ToList(); var likesForPostAndComments = allLikes.Where(l => l.Path.StartsWith(postInfo.Path)).ToList(); var likesForPost = likesForPostAndComments.Where(l => RepositoryPath.GetParentPath(RepositoryPath.GetParentPath(l.Path)) == postInfo.Path).ToList(); commentInfo = new CommentInfo(commentsForPost, likesForPostAndComments, commentMarkupStr); likeInfo = new LikeInfo(likesForPost, postInfo.Id); } var drawBoundary = (prevPost != null) && (prevPost.Type != PostType.BigPost) && (postInfo.Type == PostType.BigPost); var markup = WallHelper.GetPostMarkup( postInfo.Type == PostType.BigPost ? bigPostMarkupStr : smallPostMarkupStr, commentSectionStr, postInfo, contextPath, commentInfo.HiddenCommentsMarkup, commentInfo.CommentsMarkup, commentInfo.CommentCount, likeInfo, drawBoundary); prevPost = postInfo; sb.Append(markup); } return(sb.ToString()); }
public static string GetPostMarkup(string markupStr, string commentSectionStr, PostInfo postInfo, string contextPath, string hiddenCommentsMarkup, string commentsMarkup, int commentCount, LikeInfo likeInfo, bool drawBoundary) { if (markupStr == null) { return(null); } if (commentSectionStr == null) { return(null); } markupStr = ReplaceResources(markupStr); markupStr = markupStr.Replace("{{commentsection}}", commentSectionStr); markupStr = markupStr.Replace("{{postid}}", postInfo.ClientId.ToString()); markupStr = markupStr.Replace("{{avatar}}", UITools.GetAvatarUrl(postInfo.CreatedBy)); markupStr = markupStr.Replace("{{username}}", postInfo.CreatedBy.FullName); markupStr = markupStr.Replace("{{userlink}}", Actions.ActionUrl(Content.Create(postInfo.CreatedBy), "Profile")); var text = postInfo.Text; if (text != null) { text = text.Replace("{{path}}", postInfo.LastPath ?? string.Empty); } var haspermission = WallHelper.HasWallPermission(contextPath); markupStr = markupStr.Replace("{{text}}", text); markupStr = markupStr.Replace("{{date}}", postInfo.CreationDate.ToString()); markupStr = markupStr.Replace("{{friendlydate}}", UITools.GetFriendlyDate(postInfo.CreationDate)); markupStr = markupStr.Replace("{{hiddencomments}}", hiddenCommentsMarkup); markupStr = markupStr.Replace("{{comments}}", commentsMarkup); markupStr = markupStr.Replace("{{commentboxdisplay}}", (commentCount > 0) && haspermission ? "block" : "none"); markupStr = markupStr.Replace("{{hiddencommentboxdisplay}}", commentCount > 2 ? "block" : "none"); markupStr = markupStr.Replace("{{commentcount}}", commentCount.ToString()); markupStr = markupStr.Replace("{{likeboxdisplay}}", likeInfo.Count > 0 ? "block" : "none"); markupStr = markupStr.Replace("{{likes}}", likeInfo.GetLongMarkup()); markupStr = markupStr.Replace("{{ilikedisplay}}", !likeInfo.iLike ? "inline" : "none"); markupStr = markupStr.Replace("{{iunlikedisplay}}", likeInfo.iLike ? "inline" : "none"); // content card - only manualposts count here, journals don't have this markup if (postInfo.Type == PostType.BigPost && postInfo.SharedContent != null) { markupStr = markupStr.Replace("{{contentcard}}", WallHelper.GetContentCardMarkup(postInfo.SharedContent, contextPath)); } else { markupStr = markupStr.Replace("{{contentcard}}", string.Empty); } // small post icon var smallposticon = "/Root/Global/images/icons/16/add.png"; if (postInfo.Type == PostType.JournalModified) { smallposticon = "/Root/Global/images/icons/16/edit.png"; } if (postInfo.Type == PostType.JournalDeletedPhysically) { smallposticon = "/Root/Global/images/icons/16/delete.png"; } if (postInfo.Type == PostType.JournalMoved) { smallposticon = "/Root/Global/images/icons/16/move.png"; } if (postInfo.Type == PostType.JournalCopied) { smallposticon = "/Root/Global/images/icons/16/copy.png"; } markupStr = markupStr.Replace("{{smallposticon}}", smallposticon); markupStr = markupStr.Replace("{{postboundaryclass}}", drawBoundary ? "sn-post-boundary" : string.Empty); markupStr = markupStr.Replace("{{action}}", postInfo.Action); // small post details markupStr = markupStr.Replace("{{detailsdisplay}}", string.IsNullOrEmpty(postInfo.Details) ? "none" : "inline"); markupStr = markupStr.Replace("{{detailssection}}", ReplaceResources(postInfo.Details)); // user interaction allowed markupStr = markupStr.Replace("{{interactdisplay}}", haspermission ? "inline" : "none"); return(markupStr); }