您目前尚未登陆,请选择【登陆】或【注册
首页->博客论坛->SpaceBuilder v1.0正式版源码>>BlogControls/Views/EntryComments.cs>>源码在线查看
温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:SpaceBuilder v1.0正式版源码
当前文件:文件类型 SpaceBuiderV10Source/BlogControls/Views/EntryComments.cs打开代码结构图
普通视图
		            
1//------------------------------------------------------------------------------ 2// <copyright company="Tunynet"> 3// Copyright (c) Tunynet Network Technology Co., Ltd. All rights reserved. 4// </copyright> 5//------------------------------------------------------------------------------ 6 7using System; 8using System.ComponentModel; 9using System.Web.UI.WebControls; 10 11using SpaceBuilder.Blogs.Components; 12using SpaceBuilder.Components; 13using SpaceBuilder.Utils; 14using SpaceBuilder.Security; 15using SpaceBuilder.Posts.Permissions; 16using System.Collections.Generic; 17using SpaceBuilder.Controls; 18using SpaceBuilder.Controls.Utils; 19using TunyNet.Data.Utils; 20 21namespace SpaceBuilder.Blogs.Controls 22{ 23 /// <summary> 24 /// Summary description for EntryComments. 25 /// </summary> 26 public class EntryComments : WeblogThemedControl 27 { 28 Public Properties 44 45 private Repeater Comments = null; 46 private BlogThread parent = null; 47 //private Pager pager; 48 private PostBackPager pager; 49 //private RssButton rssButton; 50 private BlogPostSetQuery query = new BlogPostSetQuery(); 51 public EntryComments() 52 { } 53 54 private PostSet _dataSource; 55 56 /// <summary> 57 /// Property DataSource (object) 58 /// </summary> 59 public PostSet DataSource 60 { 61 get { return this._dataSource; } 62 set { this._dataSource = value; } 63 } 64 65 public override void DataBind() 66 { 67 this.EnsureChildControls(); 68 query.PostID = this.PostID; 69 query.IncludeTags = true; 70 query.ReturnFullThread = false; 71 query.PageSize = this.DisplayItemCount; 72 query.PageIndex = pager.PageIndex; 73 74 PostSet postset1 = BlogPosts.GetPostSet(query); 75 this.ps = postset1; 76 this.DataSource = postset1; 77 78 79 if (DataSource != null && DataSource.Replies != null && Comments != null) 80 { 81 parent = DataSource.Thread; 82 Comments.DataSource = DataSource.Replies; 83 Comments.DataBind(); 84 85 if (DataSource.Replies.Count == 0 && HideOnNoComments) 86 this.Visible = false; 87 88 if (DataSource.Replies.Count == 0) 89 FindControl("CommentTitle").Visible = false; 90 } 91 else if (HideOnNoComments) 92 this.Visible = false; 93 94 if (pager != null && Comments != null) 95 { 96 pager.PageSize = this.DisplayItemCount; 97 pager.TotalRecords = DataSource.TotalRecords; 98 } 99 } 100 101 protected override void AttachChildControls() 102 { 103 //pager = FindControl("Pager") as Pager; 104 pager = FindControl("Pager") as PostBackPager; 105 if (pager != null) 106 { 107 pager.PageIndexChanged += new PagerEventHandler(pager_PageIndexChanged); 108 } 109 Comments = FindControl("Comments") as Repeater; 110 if (Comments == null) 111 { 112 this.Controls.Clear(); 113 this.Visible = false; 114 return; 115 } 116 //rssButton = (RssButton)FindControl("RssButton"); 117 //if(rssButton!=null) 118 //{ 119 // //没有订阅blog评论的blogUrl! 120 // //rssButton.NavigateUrl=BlogUrls.Instance().rs 121 //} 122 //query.PageIndex = pager.PageIndex; 123 124 Comments.ItemDataBound += new RepeaterItemEventHandler(Comments_ItemDataBound); 125 Comments.ItemCommand += new RepeaterCommandEventHandler(Comments_ItemCommand); 126 DataBind(); 127 } 128 129 void pager_PageIndexChanged(object sender, PagerEventArgs e) 130 { 131 DataBind(); 132 } 133 134 const string anchortag = "<a name=\"{0}\"></a>"; 135 private string Anchor(int ID) 136 { 137 return string.Format(anchortag, ID); 138 } 139 140 private int _anonymousUserID = -1; 141 private bool IsAnonymousUserID(int userID) 142 { 143 if (_anonymousUserID == -1) 144 _anonymousUserID = Users.GetAnonymousUser().UserID; 145 146 return _anonymousUserID == userID; 147 } 148 149 private void Comments_ItemDataBound(object sender, RepeaterItemEventArgs e) 150 { 151 if (parent == null) 152 return; 153 154 if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) 155 { 156 BlogPost comment = e.Item.DataItem as BlogPost; 157 if (comment != null) 158 { 159 UserAvatar avatar = e.Item.FindControl("Avatar") as UserAvatar; 160 if (avatar != null) 161 avatar.User = comment.User; 162 163 //Literal title = (Literal)(e.Item.FindControl("Title")); 164 //if (title != null) 165 // title.Text = String.Format("{0}{1}", comment.Subject, Anchor(comment.PostID)); 166 167 HyperLink perma = (HyperLink)e.Item.FindControl("PermaLink"); 168 perma.NavigateUrl = BlogUrls.Instance().ShowPost(parent, CurrentWeblog, comment); 169 170 HyperLink author = (HyperLink)e.Item.FindControl("Author"); 171 if (author != null) 172 { 173 if (comment.HasTitleUrl) 174 { 175 author.NavigateUrl = TunyNet.Utils.HtmlUtils.UnHtmlEncode(GlobalUrls.Instance().Redirect(comment.TitleUrl)); 176 if (IsAnonymousUserID(comment.UserID)) 177 author.Attributes.Add("rel", "nofollow"); 178 } 179 else 180 { 181 if (!IsAnonymousUserID(comment.UserID)) 182 author.NavigateUrl = UserUrls.Instance().UserChannelHome(comment.UserID, UserDomainMenuType.Profile); 183 } 184 if (comment.BlogPostType == BlogPostType.Comment) 185 { 186 author.Text = comment.Author; 187 author.ToolTip = author.Text; 188 } 189 else if (comment.BlogPostType == BlogPostType.Trackback) 190 { 191 author.Text = comment.TrackBackName != null ? comment.TrackBackName : "TrackBack"; 192 author.Attributes.Add("title", "TrackBack"); 193 } 194 } 195 196 Literal PostDate = (Literal)(e.Item.FindControl("PostDate")); 197 if (PostDate != null) 198 { 199 //PostDate.Text = comment.PostDate.ToString("f"); 200 PostDate.Text = string.Format("{0}{1}", comment.PostDate.ToString("f"), Anchor(comment.PostID)); 201 } 202 203 Literal Post = (Literal)(e.Item.FindControl("PostText")); 204 if (Post != null) 205 { 206 Post.Text = comment.Body; 207 } 208 209 LinkButton editlink = e.Item.FindControl("EditLink") as LinkButton; 210 if (editlink != null) 211 { 212 if (Permissions.ValidatePermissions(this.CurrentWeblog, Permission.Post, this.CurrentUser)) 213 { 214 editlink.Text = "删除评论"; 215 editlink.CommandName = comment.PostID.ToString(); 216 editlink.Attributes.Add("onclick", "return confirm(\"确认要删除此评论吗?\");"); 217 editlink.Visible = true; 218 editlink.CommandArgument = comment.PostID.ToString(); 219 } 220 else 221 { 222 editlink.Visible = false; 223 } 224 225 } 226 } 227 } 228 } 229 230 private void Comments_ItemCommand(object source, RepeaterCommandEventArgs e) 231 { 232 int entryID = Int32.Parse(e.CommandArgument as string); 233 BlogPosts.DeletePost(entryID); 234 235 //Need to do this a bit cleaner. 236 if (this.DataSource != null) 237 { 238 //this.DataBind(); 239 IList<BlogPost> items = DataSource.Replies; 240 if (items != null && items.Count > 0) 241 { 242 for (int i = 0; i < items.Count; i++) 243 { 244 if (items[i].PostID == entryID) 245 { 246 items.RemoveAt(i); 247 break; 248 } 249 } 250 251 this.Comments.DataSource = items; 252 this.Comments.DataBind(); 253 } 254 } 255 } 256 ...