Пример #1
0
    private string GeneratePageComments()
    {
        member = (Member)HttpContext.Current.Session["Member"];

        if (member != null)
        {
            IsLoggedIn = true;
        }

        AjaxComment[] comments = new AjaxComment[0];

        comments = AjaxComment.GetCommentByObjectIDWithJoin(ObjectId, (int)CommentType);
        DefaultNewCommentParams = "'" + CommentType.ToString() + "','" + ObjectWebId + "'";


        NumberOfComments = comments.Length;

        for (int i = 0; i < comments.Length; i++)
        {
            PageComments += comments[i].HTML;
        }

        if (NumberOfComments <= 0)
        {
            return("<p id='pBeFirst'>Be the first to post a comment</p>");
        }

        StringBuilder sbCommentHTML = new StringBuilder();
        StringBuilder sbPartialHTML = null;

        object[] parameters = new object[12];

        string HTMLItem = (@"<li class='clearfix' id='li{5}' depth='{7}'><a href='javascript:dmp(""{8}"");'><img src='{0}' alt='' width='50' height='50' class='commenter_avatar' /></a>
							<div class='comment_entry' id='{5}'>
								<p class='reply'>"                                );


        string HTMLItem2 = (@"</p>
								<p class='commenter'> <cite><a href='/users/{1}'>{1}</a></cite><br />
								<small>{2}</small></p>
								<p id='commentBody{5}'>{4}.{11}</p>
                                <p id='commentBodyHidden{5}' style='visibility:hidden;display:none'>{9}.</p>
							</div>
						</li>"                        );

        int lastReplytoID = -1;

        for (int i = 0; i < comments.Length; i++)
        {
            AjaxComment comment = comments[i];

            int CurrentCommentDepth = comment.Depth;
            int PrevCommentDepth    = 0;
            int NextCommentDepth    = 0;

            try
            {
                PrevCommentDepth = comments[i - 1].Depth;
            }
            catch { }

            try
            {
                NextCommentDepth = comments[i + 1].Depth;
            }
            catch { }

            sbPartialHTML = new StringBuilder();
            sbPartialHTML.Append(HTMLItem);

            if (member != null && comment.WebMemberID == member.WebMemberID && !comment.IsDeleted)
            {
                sbPartialHTML.Append(@"<small><a id=""edit{5}"" href=""javascript:editComment('{6}','{5}','{10}');void(0);"">Edit</a>");
                sbPartialHTML.Append(@"<a id=""delete{5}"" href=""javascript:deleteComment('{6}','{5}','{10}');"">Delete</a></small>");
            }

            if (!comment.IsDeleted)
            {
                if (IsLoggedIn)
                {
                    sbPartialHTML.Append(@"<a id=""reply{5}"" href=""javascript:replyToComment('{6}','{5}','{10}');void(0);"">Reply</a>");
                }
                else
                {
                    sbPartialHTML.Append(@"<a href=""" + LoginUrl + @""">Reply</a>");
                }
            }

            sbPartialHTML.Append(HTMLItem2);

            parameters[0]  = comment.PhotoUrl;
            parameters[1]  = comment.NickName;
            parameters[2]  = TimeDistance.TimeAgo(comment.DTCreated);
            parameters[11] = "";

            if (!comment.IsDeleted)
            {
                parameters[4] = HTMLUtility.AutoLink(comment.Text);
                parameters[9] = HTMLUtility.FormatForText(comment.Text);

                if (comment.SentFromMobile)
                {
                    parameters[11] = "<p><i>Sent from my mobile</i></p>";
                }
            }
            else
            {
                parameters[4] = @"<i style=""font-weight:lighter;color:gray"">Comment Deleted</i>";
            }

            parameters[5]  = comment.WebCommentID;
            parameters[6]  = (int)CommentType;
            parameters[7]  = comment.Depth;
            parameters[8]  = comment.WebMemberID;
            parameters[10] = ObjectWebId;


            if (PrevCommentDepth <= 1 && comment.Depth > 1)
            {
                sbCommentHTML.Append("<ol class=\"jqCmtOl\" id=\"jqCmtOl\">");
            }

            sbCommentHTML.AppendFormat(sbPartialHTML.ToString(), parameters);

            if (NextCommentDepth <= 1 && comment.Depth > 1)
            {
                sbCommentHTML.Append("</ol>");
            }

            lastReplytoID = comment.InReplyToCommentID;
        }

        //string FinalComments = "<ul id='ulCommentList' class='profile_commentlist'>" + sbCommentHTML.ToString() + "</ul>";

        return(sbCommentHTML.ToString());
    }