示例#1
0
        /// <summary>
        /// Creates the user interface.
        /// </summary>
        /// <param name="writer"></param>
        protected override void Render(HtmlTextWriter writer)
        {
            // <div> -- entire area
            writer.RenderBeginTag(HtmlTextWriterTag.Div);
            // <ul>
            writer.AddAttribute(HtmlTextWriterAttribute.Class, "qaComments");
            writer.RenderBeginTag(HtmlTextWriterTag.Ul);
            // get data
            var postComments = Controller.GetPostComments(ObjPost.PostId);

            if (postComments != null)
            {
                foreach (var comment in postComments)
                {
                    // <li>
                    writer.RenderBeginTag(HtmlTextWriterTag.Li);

                    var matches = new Regex("(?<![\">])((http|https|ftp)\\://.+?)(?=\\s|$)").Matches(comment.Comment);

                    foreach (Match m in matches)
                    {
                        comment.Comment = comment.Comment.Replace(m.Value, "<a rel=\"nofollow\" href=\"" + m.Value + "\">" + m.Value + "</a>");
                    }

                    writer.Write("<p>" + comment.Comment + " - ");

                    // <a />
                    var objUser = Entities.Users.UserController.GetUserById(ModContext.PortalId, comment.UserId);
                    writer.AddAttribute(HtmlTextWriterAttribute.Href, Common.Globals.UserProfileURL(objUser.UserID));
                    writer.RenderBeginTag(HtmlTextWriterTag.A);
                    writer.Write(objUser.DisplayName);
                    writer.RenderEndTag();

                    // comment date
                    writer.Write(" " + Utils.CalculateDateForDisplay(comment.CreatedOnDate));
                    writer.Write("</p>");

                    // </li>
                    writer.RenderEndTag();
                }
            }

            // </ul>
            writer.RenderEndTag();

            var objCommentE   = Privileges.Single(s => s.Key == Constants.Privileges.CommentEverywhere.ToString());
            var objRemoveUser = Privileges.Single(s => s.Key == Constants.Privileges.RemoveNewUser.ToString());

            if (CurrentUserScore >= objCommentE.Value || ModContext.IsEditable || ((ObjPost.CreatedUserId == ModContext.PortalSettings.UserId) && (CurrentUserScore >= objRemoveUser.Value)) || ((Question.CreatedUserId == ModContext.PortalSettings.UserId) && (CurrentUserScore >= objRemoveUser.Value)))
            {
                // <div> - comment expand/collapse and fieldset container
                writer.AddAttribute(HtmlTextWriterAttribute.Class, "qaCommentArea");
                writer.RenderBeginTag(HtmlTextWriterTag.Div);
                // <h2>
                writer.AddAttribute(HtmlTextWriterAttribute.Class, "dnnFormSectionHead");
                writer.RenderBeginTag(HtmlTextWriterTag.H2);
                // <a />
                writer.AddAttribute(HtmlTextWriterAttribute.Id, "comment-postid-" + ObjPost.PostId);
                writer.AddAttribute(HtmlTextWriterAttribute.Href, "#");
                writer.RenderBeginTag(HtmlTextWriterTag.A);
                writer.Write(Localization.GetString("CommentHeader.Text", SharedResourceFile));
                writer.RenderEndTag();
                // </h2>
                writer.RenderEndTag();

                // <fieldset>
                writer.RenderBeginTag(HtmlTextWriterTag.Fieldset);

                // <div> - dnnFormItem
                writer.AddAttribute(HtmlTextWriterAttribute.Class, "dnnFormItem");
                writer.RenderBeginTag(HtmlTextWriterTag.Div);
                // <input />
                _txtComment.RenderControl(writer);
                // </div> - dnnFormItem
                writer.RenderEndTag();

                // add comment link button
                _cmdAddComment.RenderControl(writer);

                // </fieldset>
                writer.RenderEndTag();
                // </div> - comment expand/collapse and fieldset container
                writer.RenderEndTag();
            }
            // </div> -- entire area
            writer.RenderEndTag();
        }