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