您目前尚未登陆,请选择【登陆】或【注册
首页->博客论坛->SpaceBuilder v1.0正式版源码>>BlogControls/Views/EntryList.cs>>源码在线查看
温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:SpaceBuilder v1.0正式版源码
当前文件:文件类型 SpaceBuiderV10Source/BlogControls/Views/EntryList.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.Web.UI.WebControls; 9using SpaceBuilder.Components; 10using SpaceBuilder.Blogs.Components; 11using SpaceBuilder.Controls; 12using SpaceBuilder.Utils; 13using SpaceBuilder.Controls.Utils; 14using SpaceBuilder.Security; 15using SpaceBuilder.Posts.Permissions; 16using TunyNet.Utils; 17using TunyNet.Data.Utils; 18using System.Web.UI.HtmlControls; 19 20namespace SpaceBuilder.Blogs.Controls 21{ 22 /// <summary> 23 /// Summary description for EntryList. 24 /// </summary> 25 public class EntryList : WeblogThemedControl 26 { 27 private SBContext wlContext = SBContext.Current; 28 29 private Literal listTitle = null; 30 private HtmlGenericControl titleWrapper = null; 31 private Repeater entryItems = null; 32 private PostBackPager pager = null; 33 34 private Literal tagName; 35 private Literal tagDescription; 36 37 protected override void AttachChildControls() 38 { 39 listTitle = FindControl("listTitle") as Literal; 40 titleWrapper = FindControl("titleWrapper") as HtmlGenericControl; 41 42 entryItems = FindControl("EntryItems") as Repeater; 43 pager = FindControl("Pager") as PostBackPager; 44 pager.PageIndexChanged += new PagerEventHandler(Pager_PageIndexChanged); 45 46 entryItems.ItemDataBound += new RepeaterItemEventHandler(entryItems_ItemDataBound); 47 48 tagName = FindControl("TagName") as Literal; 49 tagDescription = FindControl("TagDescription") as Literal; 50 51 string strTagName = SBContext.Current.GetStringFromQueryString("TagName", string.Empty); 52 53 if (!ValueHelper.IsNullOrEmpty(strTagName)) 54 { 55 UserTag tag = SpaceBuilder.Components.Tags.GetUserTag(strTagName, TagType.Blog, CurrentDomainUser.UserID); 56 if (tag == null) 57 { 58 throw new SBException(SBExceptionType.ResourceNotFound,string.Format("Tag {0} could not be found!",strTagName)); 59 } 60 if (tagName != null) 61 { 62 tagName.Text = tag.TagName; 63 this.SetPageTitle(tag.TagName); 64 } 65 66 if (tagDescription != null) 67 { 68 string strFormat = "该标签内有&nbsp;{0}&nbsp;篇文章,站内还有&nbsp;{1}&nbsp;个用户定义了相同的标签,共有<a href='{2}'>{3}</a>篇文章"; 69 tagDescription.Text = string.Format(strFormat, tag.ItemCount, tag.UserCount - 1, ChannelUrls.Instance().ListWebLogPostsByTag(tag.TagName), tag.ItemCountOfSite); 70 } 71 } 72 } 73 74 protected override void OnLoad(EventArgs e) 75 { 76 base.OnLoad(e); 77 EnsureChildControls(); 78 //if (!Page.IsPostBack) 79 Bind(); 80 } 81 82 public void Bind() 83 { 84 BlogThreadQuery query = new BlogThreadQuery(); 85 query.SectionID = CurrentWeblog.SectionID; 86 query.BlogThreadType = this.BlogThreadType; 87 88 //如果当前用户是blog所有者或者blog管理员则显示所有文章 89 if (IsUserDomainOwner || wlContext.User.IsBlogAdministrator) 90 query.IsPublicFilter = false; 91 92 query.SortOrder = SortOrder; 93 94 switch (query.BlogThreadType) 95 { 96 case BlogThreadType.Tag: 97 query.TagName = wlContext.GetStringFromQueryString("TagName", string.Empty); 98 break; 99 100 case BlogThreadType.Day: 101 case BlogThreadType.Month: 102 case BlogThreadType.Year: 103 query.DateFilter = GetDate(); 104 break; 105 106 case BlogThreadType.Recent: 107 break; 108 } 109 query.PageSize = DisplayItemCount; 110 query.PageIndex = pager.PageIndex; 111 if (IgnorePaging) 112 query.IgnorePaging = true; 113 114 PagingDataSet<BlogThread> ts = BlogPosts.GetBlogThreads(query, false); 115 pager.PageSize = query.PageSize; 116 pager.TotalRecords = ts.TotalRecords; 117 entryItems.DataSource = ts.Records; 118 entryItems.DataBind(); 119 120 pager.Visible = (!IgnorePaging && (pager.TotalRecords > pager.PageSize)); 121 122 switch (query.BlogThreadType) 123 { 124 125 case BlogThreadType.Tag: 126 tagName.Text = query.TagName; 127 break; 128 case BlogThreadType.Day: 129 listTitle.Text = query.DateFilter.ToLongDateString() + " - 文章"; 130 break; 131 case BlogThreadType.Month: 132 listTitle.Text = query.DateFilter.ToString("MMMM yyyy") + " - 文章"; 133 break; 134 default: 135 titleWrapper.Visible = false; 136 break; 137 } 138 139 if (!ValueHelper.IsNullOrEmpty(listTitle.Text)) 140 this.SetPageTitle(listTitle.Text); 141 else 142 this.SetPageTitle(string.Empty); 143 144 } 145 146 147 private void entryItems_ItemDataBound(object sender, RepeaterItemEventArgs e) 148 { 149 if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) 150 { 151 BlogThread entry = e.Item.DataItem as BlogThread; 152 if (entry != null) 153 { 154 HyperLink link = e.Item.FindControl("PermaLink") as HyperLink; 155 if (link != null) 156 { 157 link.Text = entry.PostDate.ToString("f"); 158 link.NavigateUrl = BlogUrls.Instance().ShowBlogPostByDay(this.CurrentWeblog.ApplicationKey, entry.PostDate); 159 } 160 161 if (!entry.IsPublic) 162 { 163 Image notPublicImage = e.Item.FindControl("NotPublicImage") as Image; 164 if (notPublicImage != null) 165 { 166 notPublicImage.Visible = true; 167 notPublicImage.ToolTip = "此文章未公开"; 168 } 169 } 170 171 link = e.Item.FindControl("PostTitle") as HyperLink; 172 if (link != null) 173 { 174 link.NavigateUrl = BlogUrls.Instance().ShowPost(entry, CurrentWeblog); 175 link.Text = StringUtils.Trim(entry.Subject, 25); 176 link.ToolTip = entry.Subject; 177 } 178 179 Literal blogPostType = e.Item.FindControl("BlogPostType") as Literal; 180 if (blogPostType != null) 181 { 182 switch (entry.BlogPostType) 183 { 184 case BlogPostType.Post: 185 blogPostType.Text += "[原创]"; 186 break; 187 case BlogPostType.Article: 188 blogPostType.Text += "[转帖]"; 189 break; 190 } 191 } 192 Literal tags = e.Item.FindControl("Tags") as Literal; 193 if (tags != null) 194 { 195 if (entry.Tags.Count > 0) 196 { 197 foreach (UserTag tag in entry.Tags) 198 { 199 tags.Text += string.Format("<a href='{0}' title='该用户在此标签下还有{1}篇文章'>{2}</a>&nbsp;&nbsp;", GlobalUrls.Instance().ShowBlogPostsByTag(CurrentDomainUser.UserName, tag.TagName), tag.ItemCount, tag.TagName); 200 } 201 } 202 } 203 204 205 Literal Body = e.Item.FindControl("Body") as Literal; 206 HyperLink readMore = e.Item.FindControl("ReadMoreLink") as HyperLink; 207 if (Body != null) 208 { 209 if (DisplayExcerpts) 210 { 211 if (entry.HasExcerpt) 212 Body.Text = entry.Excerpt; 213 else 214 Body.Text = HtmlUtils.TrimHtml(entry.Body, 250); 215 216 if (readMore != null) 217 { 218 readMore.Visible = true; 219 readMore.NavigateUrl = BlogUrls.Instance().ShowPost(entry, CurrentWeblog); 220 readMore.Text = "[阅读全文]"; 221 } 222 } 223 else 224 { 225 if (readMore != null) 226 readMore.Visible = false; 227 228 Body.Text = entry.Body; 229 } 230 } 231 232 link = e.Item.FindControl("CommentsLink") as HyperLink; 233 Literal commentDesc = e.Item.FindControl("CommentDesc") as Literal; 234 if (link != null) 235 { 236 if ((CurrentWeblog.EnableComments && !entry.IsLocked) || entry.ReplyCount > 0) 237 { 238 link.Text = string.Format("评论({0})", entry.ReplyCount); 239 link.NavigateUrl = BlogUrls.Instance().ShowPost(entry, CurrentWeblog) + "#comments"; 240 commentDesc.Text = ""; 241 } 242 else 243 { 244 commentDesc.Text = "(关闭评论)"; 245 link.Visible = false; 246 } 247 } 248 249 Literal totalViews = e.Item.FindControl("TotalViews") as Literal; 250 if (totalViews != null) 251 totalViews.Text = string.Format("点击({0})", entry.HitTimes); 252 253 254 link = e.Item.FindControl("EditLink") as HyperLink; 255 if (link != null) 256 { 257 if (Permissions.ValidatePermissions(CurrentWeblog, Permission.Post, CurrentUser)) 258 { 259 link.Visible = true; 260 link.NavigateUrl = BlogUrls.Instance().PostEditor(CurrentWeblog.ApplicationKey, entry.PostID); 261 link.Text = string.Format("[{0}]", ResourceManager.GetString("Edit")); 262 link.ToolTip = "修改该文章"; 263 } 264 else 265 link.Visible = false; 266 } 267 268 RatingButton ratingButton = e.Item.FindControl("RatingButton") as RatingButton; 269 if (ratingButton != null) 270 { 271 if (entry.EnableRatings) 272 { 273 ratingButton.Visible = true; 274 ratingButton.TotalRatings = entry.TotalRatings; 275 ratingButton.RatingSum = entry.RatingSum; 276 ratingButton.ThreadID = entry.ThreadID; 277 ratingButton.ApplicationType = ApplicationType.Blog; 278 } 279 else 280 ratingButton.Visible = false; 281 } 282 283 link = e.Item.FindControl("AuthorLink") as HyperLink; 284 if (link != null) 285 { 286 link.Text = entry.Author; 287 link.NavigateUrl = UserUrls.Instance().UserChannelHome(entry.UserID, UserDomainMenuType.Profile); 288 } 289 290 } 291 } 292 } 293 294 295 void Pager_PageIndexChanged(object sender, PagerEventArgs e) 296 { 297 Bind(); 298 } 299 300 301 Public Properties