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());
        }
Example #2
0
        /// <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;
        }
Example #3
0
        protected override void CreateChildControls()
        {
            if (this.ContextNode == null)
                return;

            if (ShowExecutionTime)
                Timer.Start();

            // gather posts for this content
            List<PostInfo> posts;
            using (new OperationTrace("Wall - Gather posts"))
            {
                posts = DataLayer.GetPostsForContent(this.ContextNode).ToList();
            }
            string postsMarkup;
            using (new OperationTrace("Wall - Posts markup"))
            {
                postsMarkup = WallHelper.GetWallPostsMarkup(this.ContextNode.Path, posts);
            }

            CommentInfo contentCommentInfo;
            LikeInfo contentLikeInfo;
            using (new OperationTrace("Wall - Gather content comments"))
            {
                var commentsAndLikesQuery = "+TypeIs:(Comment Like) +InTree:\"" + this.ContextNode.Path + "\"";
                var settings = new QuerySettings() { EnableAutofilters = false };
                var allCommentsAndLikes = ContentQuery.Query(commentsAndLikesQuery, settings).Nodes.ToList();

                var commentNodeTypeId = NodeType.GetByName("Comment").Id;
                var likeTypeId = NodeType.GetByName("Like").Id;

                var commentsForPost = allCommentsAndLikes.Where(c => c.NodeTypeId == commentNodeTypeId).ToList();
                var likesForPostAndComments = allCommentsAndLikes.Where(l => l.NodeTypeId == likeTypeId).ToList();
                var likesForPost = likesForPostAndComments.Where(l => RepositoryPath.GetParentPath(RepositoryPath.GetParentPath(l.Path)) == this.ContextNode.Path).ToList();

                var commentMarkupStr = WallHelper.GetCommentMarkupStr();

                // get comments for this content
                contentCommentInfo = new CommentInfo(commentsForPost, likesForPostAndComments, commentMarkupStr);

                // get likes for this content
                contentLikeInfo = new LikeInfo(likesForPost, this.ContextNode.Id);
            }

            using (new OperationTrace("Wall - Content comments markup"))
            {
                var markupStr = WallHelper.GetContentWallMarkup(
                    this.ContextNode,
                    contentCommentInfo.HiddenCommentsMarkup,
                    contentCommentInfo.CommentsMarkup,
                    contentCommentInfo.CommentCount,
                    contentLikeInfo,
                    postsMarkup);

                this.Controls.Add(new Literal { Text = markupStr });
            }

            if (ShowExecutionTime)
                Timer.Stop();

            base.CreateChildControls();
            this.ChildControlsCreated = true;
        }
Example #4
0
        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();
            foreach (var postInfo in posts)
            {
                if (postInfo.IsJournal)
                    continue;

                csb.Append("\"" + postInfo.Path + "\" ");
            }

            var paths = csb.ToString().Trim();

            List<Node> allComments;
            List<Node> allLikes;

            if (string.IsNullOrEmpty(paths))    // only non-persisted journal posts are there to show (no comments or likes)
            {
                allComments = new List<Node>();
                allLikes = new List<Node>();
            } 
            else 
            {
                var commentsAndLikesQuery = "+TypeIs:(Comment Like) +InTree:(" + paths + ")";
                var settings = new QuerySettings() { EnableAutofilters = false };
                var allCommentsAndLikes = ContentQuery.Query(commentsAndLikesQuery, settings).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();
        }