示例#1
0
        /// <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);
        }
示例#2
0
        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);
        }
示例#3
0
        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;
        }
示例#4
0
        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;
        }
示例#5
0
        public ActionResult GetPosts(string contextPath, int skip, int pageSize, string rnd)
        {
            SetCurrentWorkspace(contextPath);
            var posts       = DataLayer.GetPostsForWorkspace(contextPath).Skip(skip).Take(pageSize).ToList();
            var postsMarkup = WallHelper.GetWallPostsMarkup(contextPath, posts);

            return(Json(postsMarkup, JsonRequestBehavior.AllowGet));
        }
示例#6
0
        public ActionResult CreateComment(string postId, string contextPath, string text, string rnd)
        {
            if (string.IsNullOrEmpty(text))
            {
                return(null);
            }

            AssertPermission();

            SetCurrentWorkspace(contextPath);
            var comment = DataLayer.CreateComment(postId, contextPath, text);

            var commentMarkup = WallHelper.GetCommentMarkup(comment.CreationDate, ContentRepository.User.Current as User, text, comment.Id, new LikeInfo(), comment);

            return(Json(commentMarkup, JsonRequestBehavior.AllowGet));
        }
示例#7
0
        public ActionResult CreatePost(string contextPath, string text, string rnd)
        {
            if (string.IsNullOrEmpty(text))
            {
                return(null);
            }

            AssertPermission();

            SetCurrentWorkspace(contextPath);
            var post       = DataLayer.CreateManualPost(contextPath, text);
            var postInfo   = new PostInfo(post);
            var postMarkup = WallHelper.GetPostMarkup(postInfo, contextPath);

            return(Json(postMarkup, JsonRequestBehavior.AllowGet));
        }
示例#8
0
        public static string GetContentCardMarkup(Node sharedContent, string contextPath)
        {
            var markupStr = WallHelper.GetMarkupString("$skin/renderers/Wall/ContentCard.html");

            if (markupStr == null)
            {
                return(null);
            }

            markupStr = ReplaceResources(markupStr);

            var shareContent = Content.Create(sharedContent);
            var sharedGc     = sharedContent as GenericContent;

            markupStr = markupStr.Replace("{{shareicon}}", IconHelper.ResolveIconPath(sharedGc.Icon, 32));
            markupStr = markupStr.Replace("{{sharedisplayname}}", shareContent.DisplayName);
            markupStr = markupStr.Replace("{{sharecontenttype}}", sharedGc.NodeType.Name);

            var user = sharedContent as User;

            if (user == null)
            {
                markupStr = markupStr.Replace("{{sharepath}}", sharedGc.Path);

                var wsRelPath = sharedGc.Path;
                if (sharedGc.Path.StartsWith(contextPath) && sharedGc.Path != contextPath)
                {
                    wsRelPath = sharedGc.Path.Substring(contextPath.Length);
                }

                markupStr = markupStr.Replace("{{shareworkspacerelativepath}}", wsRelPath);
            }
            else
            {
                var path = Actions.ActionUrl(Content.Create(user), "Profile");

                markupStr = markupStr.Replace("{{sharepath}}", path);
                markupStr = markupStr.Replace("{{shareworkspacerelativepath}}", path);
            }

            return(markupStr);
        }
示例#9
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);
        }
示例#10
0
        public ActionResult Share(int itemId, string contextPath, string text, string rnd)
        {
            if (!WallHelper.HasWallPermission(contextPath))
            {
                return(Json("403", JsonRequestBehavior.AllowGet));
            }

            AssertPermission();

            SetCurrentWorkspace(contextPath);
            try
            {
                DataLayer.CreateSharePost(contextPath, text, itemId);
            }
            catch (SecurityException)
            {
                return(Json("403", JsonRequestBehavior.AllowGet));
            }

            return(null);
        }
示例#11
0
        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));
        }
示例#12
0
        /// <summary>
        /// Returns markup in a long format - for posts
        /// </summary>
        /// <returns></returns>
        public string GetLongMarkup()
        {
            if (Count == 0)
            {
                return(string.Empty);
            }

            string markup = string.Empty;

            if (iLike && Count == 1)
            {
                markup = SNSR.GetString(SNSR.Wall.YouLikeThis);
            }

            if (iLike && Count == 2)
            {
                markup = string.Format(WallHelper.GetXmlDecodedString(SNSR.GetString(SNSR.Wall.YouAndAnotherLikesThis)), _likeListLinkParams);
            }

            if (iLike && Count > 2)
            {
                markup = string.Format(WallHelper.GetXmlDecodedString(SNSR.GetString(SNSR.Wall.YouAndOthersLikesThis)), Count - 1, _likeListLinkParams);
            }

            if (!iLike && Count == 1)
            {
                markup = string.Format(WallHelper.GetXmlDecodedString(SNSR.GetString(SNSR.Wall.OnePersonLikesThis)), _likeListLinkParams);
            }

            if (!iLike && Count > 1)
            {
                markup = string.Format(WallHelper.GetXmlDecodedString(SNSR.GetString(SNSR.Wall.MorePersonLikeThis)), Count, _likeListLinkParams);
            }

            return(markup);
        }
示例#13
0
 /// <summary>
 /// Gets markup for a new post, when there are no comments and likes yet.
 /// </summary>
 /// <returns></returns>
 public static string GetPostMarkup(PostInfo postInfo, string contextPath)
 {
     return(WallHelper.GetPostMarkup(postInfo, contextPath, string.Empty, string.Empty, 0, new LikeInfo(), false));
 }
示例#14
0
        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);
        }
示例#15
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();
            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());
        }
示例#16
0
        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);
        }