您目前尚未登陆,请选择【登陆】或【注册
首页->博客论坛->SpaceBuilder v1.1源代码>>BlogControls/HttpHandler/BlogCommentRssHandler.cs>>源码在线查看
温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:SpaceBuilder v1.1源代码
普通视图
		            
1//------------------------------------------------------------------------------ 2// <copyright company="Tunynet"> 3// Copyright (c) Tunynet Inc. All rights reserved. 4// </copyright> 5//------------------------------------------------------------------------------ 6 7using System; 8using System.Collections.Generic; 9using System.Text; 10using SpaceBuilder.Rss.Controls; 11using SpaceBuilder.Blogs.Components; 12using TunyNet.Utils; 13using SpaceBuilder.Components; 14using SpaceBuilder.Blogs.Configuration; 15using TunyNet.Data.Utils; 16using TunyNet.Rss.Components; 17using SpaceBuilder.Configuration; 18using System.Web; 19 20namespace SpaceBuilder.Blogs.Controls 21{ 22 /// <summary> 23 /// 用于生成博客评论RSS 24 /// </summary> 25 /// <remarks> 26 /// 例如:生成博客最新评论,获取某篇文章的评论 27 /// </remarks> 28 public class BlogCommentRssHandler : BaseRssHandler 29 { 30 private int sectionID = -1; 31 /// <summary> 32 /// 博客SectionID 33 /// </summary> 34 public int SectionID 35 { 36 get { return sectionID; } 37 set { sectionID = value; } 38 } 39 40 private string appkey = null; 41 /// <summary> 42 /// ApplicationKey 43 /// </summary> 44 public string ApplicationKey 45 { 46 get { return appkey; } 47 set { appkey = value; } 48 } 49 50 private int threadID = -1; 51 /// <summary> 52 /// 博客主题ID 53 /// </summary> 54 public int ThreadID 55 { 56 get { return threadID; } 57 set { threadID = value; } 58 } 59 60 private Weblog currentBlog = null; 61 /// <summary> 62 /// 当前博客 63 /// </summary> 64 public Weblog CurrentBlog 65 { 66 get 67 { 68 if (currentBlog == null) 69 { 70 if (SectionID > 0) 71 currentBlog = Weblogs.GetWeblog(SectionID); 72 else if (!ValueHelper.IsNullOrEmpty(ApplicationKey)) 73 currentBlog = Weblogs.GetWeblog(ApplicationKey); 74 } 75 76 return currentBlog; 77 } 78 } 79 80 /// <summary> 81 /// 获取完整的URL(例如: http://www.spacebuilder.cn/a/b.aspx 82 /// </summary> 83 protected override string BaseUrl 84 { 85 get { return WebUtils.HostPath(Context.Request.Url); } 86 } 87 88 /// <summary> 89 /// 缓存时间 90 /// </summary> 91 protected override int CacheTime 92 { 93 get { return WeblogConfiguration.Instance().RssCacheWindowInSeconds; } 94 } 95 96 /// <summary> 97 /// 缓存标识 98 /// </summary> 99 protected override string CacheKey 100 { 101 get 102 { 103 if (!ValueHelper.IsNullOrEmpty(ApplicationKey)) 104 { 105 if (ThreadID > 0) 106 return string.Format("Rss_BlogComments:{0}:ThreadID:{1}", ApplicationKey, ThreadID); 107 else 108 return string.Format("Rss_BlogComments:{0}:MostRecent", ApplicationKey); 109 } 110 else 111 { 112 if (ThreadID > 0) 113 return string.Format("Rss_BlogComments:{0}:ThreadID:{1}", SectionID, ThreadID); 114 else 115 return string.Format("Rss_BlogComments:{0}:MostRecent", SectionID); 116 } 117 } 118 } 119 120 /// <summary> 121 /// 处理Feed 122 /// </summary> 123 protected override void ProcessFeed() 124 { 125 SBContext sbContext = SBContext.Current; 126 if (sbContext.GetIntFromQueryString("SectionID", -1) > 0) 127 this.SectionID = sbContext.GetIntFromQueryString("SectionID", -1); 128 129 this.ApplicationKey = sbContext.ApplicationKey; 130 this.ThreadID = sbContext.ThreadID; 131 132 base.ProcessFeed(); 133 } 134 135 /// <summary> 136 /// 创建Feed 137 /// </summary> 138 protected override TunyNet.Rss.Components.CachedFeed BuildFeed() 139 { 140 if (CurrentBlog == null) 141 return new TunyNet.Rss.Components.CachedFeed(DateTime.Now, null, string.Empty); 142 143 BlogCommentQuery query = new BlogCommentQuery(); 144 if (this.ThreadID > 0) 145 query.ThreadID = this.ThreadID; 146 else 147 query.SectionID = CurrentBlog.SectionID; 148 149 query.CommentApprovalStatus = ApprovalStatus.IsApproved; 150 query.PageSize = WeblogConfiguration.Instance().RssDefaultThreadsPerFeed; 151 query.SortBy = BlogCommentSortBy.PostDate; 152 query.SortOrder = SortOrder.Descending; 153 query.IgnorePaging = true; 154 155 PagingDataSet<BlogPost> threads = BlogPosts.GetComments(query); 156 157 RssDocument rssDoc = new RssDocument(); 158 rssDoc.UseExternalNamespaces = true; 159 160 if (!ValueHelper.IsNullOrEmpty(StyleSheet)) 161 rssDoc.StyleSheet = FormatUrl(VirtualPathUtility.ToAbsolute(StyleSheet)); 162 163 RssChannel rssChannel = new RssChannel(); 164 rssChannel.Title = CurrentBlog.SectionName; 165 rssChannel.Link = FormatUrl(UserUrls.Instance().BlogHome(currentBlog.ApplicationKey)); 166 rssChannel.Description = CurrentBlog.Description; 167 rssChannel.Language = currentBlog.Langugage; 168 rssChannel.Generator = SBConfiguration.Instance().SpaceBuilderVersionInfo; 169 170 List<RssItem> rssItems = new List<RssItem>(); 171 172 foreach (BlogPost comment in threads.Records) 173 { 174 RssItem item = new RssItem(); 175 item.Title = WebUtils.HtmlDecode(comment.Subject); 176 177 item.Author = comment.Author; 178 item.PubDate = comment.PostDate; 179 180 RssGuid guid = new RssGuid(); 181 guid.IsPermaLink = false; 182 guid.Text = SiteSettingsManager.GetSiteSettings().SiteKey + ":Weblog:" + comment.PostID; 183 item.Guid = guid; 184 185 BlogThread thread = BlogPosts.GetThread(comment.ParentID, true); 186 if (thread != null) 187 { 188 item.Link = FormatUrl(BlogUrls.Instance().ShowPost(thread, CurrentBlog, comment)); 189 item.Comments = FormatUrl(BlogUrls.Instance().CommentsPage(CurrentBlog.ApplicationKey, comment.ParentID)); 190 } 191 192 item.Description = comment.Body; 193 //item.ReplyCount = comment.ReplyCount; 194 rssItems.Add(item); 195 } 196 197 rssDoc.Channel = rssChannel; 198 rssChannel.Items = rssItems; 199 200 DateTime dt = threads.TotalRecords > 0 ? threads.Records[0].PostDate : DateTime.Now; 201 202 return new TunyNet.Rss.Components.CachedFeed(dt, null, rssDoc.ToXml()); 203 } 204 205 206 } 207} 208
还没有找到您心仪的内容?请用.net源码大搜捕
代码片断 打包下载该项目完整源码:SpaceBuilder v1.1源代码