您目前尚未登陆,请选择【登陆】或【注册
首页->博客论坛->SpaceBuilder v1.0正式版源码>>BlogControls/HttpHandler/BlogPostRssHandler.cs>>源码在线查看
温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:SpaceBuilder v1.0正式版源码
普通视图
		            
1//------------------------------------------------------------------------------ 2// <copyright company="Tunynet"> 3// Copyright (c) Tunynet Network Technology Co., Ltd. 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 public BlogPostRssHandler() 28 { } 29 30 private int sectionID = -1; 31 public int SectionID 32 { 33 get { return sectionID; } 34 set { sectionID = value; } 35 } 36 37 private string appkey = null; 38 public string ApplicationKey 39 { 40 get { return appkey; } 41 set { appkey = value; } 42 } 43 44 45 private string tagName = null; 46 public string TagName 47 { 48 get { return tagName; } 49 set { tagName = value; } 50 } 51 52 private Weblog currentBlog = null; 53 public Weblog CurrentBlog 54 { 55 get 56 { 57 if (currentBlog == null) 58 { 59 if (SectionID > 0) 60 currentBlog = Weblogs.GetWeblog(SectionID); 61 else if (!ValueHelper.IsNullOrEmpty(ApplicationKey)) 62 currentBlog = Weblogs.GetWeblog(ApplicationKey); 63 } 64 65 return currentBlog; 66 } 67 } 68 69 /// <summary> 70 /// Appends http://Host:Port to all blog urls 71 /// </summary> 72 protected override string BaseUrl 73 { 74 get { return WebUtils.HostPath(Context.Request.Url); } 75 } 76 77 protected override int CacheTime { get { return WeblogConfiguration.Instance().RssCacheWindowInSeconds; } } 78 79 protected override string CacheKey 80 { 81 get 82 { 83 if (!ValueHelper.IsNullOrEmpty(ApplicationKey)) 84 { 85 if (!ValueHelper.IsNullOrEmpty(TagName)) 86 return string.Format("Rss_BlogPosts:{0}:TagName:{1}", ApplicationKey, TagName); 87 else 88 return string.Format("Rss_BlogPosts:{0}:Individual", ApplicationKey); 89 } 90 else 91 { 92 if (!ValueHelper.IsNullOrEmpty(TagName)) 93 return string.Format("Rss_BlogPosts:{0}:TagName:{1}", SectionID, TagName); 94 else 95 return string.Format("Rss_BlogPosts:{0}:Individual", SectionID); 96 } 97 } 98 } 99 100 protected override void ProcessFeed() 101 { 102 SBContext sbContext = SBContext.Current; 103 if (sbContext.GetIntFromQueryString("SectionID", -1) > 0) 104 this.SectionID = sbContext.GetIntFromQueryString("SectionID", -1); 105 106 this.ApplicationKey = sbContext.ApplicationKey; 107 this.TagName = sbContext.GetStringFromQueryString("TagName", string.Empty); 108 109 base.ProcessFeed(); 110 } 111 112 protected override TunyNet.Rss.Components.CachedFeed BuildFeed() 113 { 114 if (CurrentBlog == null) 115 return new TunyNet.Rss.Components.CachedFeed(DateTime.Now, null, string.Empty); 116 117 BlogThreadQuery query = new BlogThreadQuery(); 118 query.SectionID = CurrentBlog.SectionID; 119 120 if (!ValueHelper.IsNullOrEmpty(TagName)) 121 query.TagName = TagName; 122 123 query.IncludeTags = false; 124 query.PageSize = WeblogConfiguration.Instance().RssDefaultThreadsPerFeed; 125 query.SortBy = BlogThreadSortBy.MostRecent; 126 query.SortOrder = SortOrder.Descending; 127 query.IsPublicFilter = true; 128 query.IgnorePaging = true; 129 query.PostConfig = BlogPostConfig.IsAggregated; 130 131 PagingDataSet<BlogThread> threads = BlogPosts.GetBlogThreads(query); 132 133 RssDocument rssDoc = new RssDocument(); 134 rssDoc.UseExternalNamespaces = true; 135 if (!ValueHelper.IsNullOrEmpty(StyleSheet)) 136 rssDoc.StyleSheet = FormatUrl(VirtualPathUtility.ToAbsolute(StyleSheet)); 137 138 RssChannel rssChannel = new RssChannel(); 139 rssChannel.Title = CurrentBlog.SectionName; 140 rssChannel.Link = FormatUrl(UserUrls.Instance().BlogHome(currentBlog.ApplicationKey)); 141 rssChannel.Description = CurrentBlog.Description; 142 rssChannel.Language = currentBlog.Langugage; 143 rssChannel.Generator = SBConfiguration.Instance().SpaceBuilderVersionInfo; 144 145 List<RssItem> rssItems = new List<RssItem>(); 146 147 foreach (BlogThread thread in threads.Records) 148 { 149 RssItem item = new RssItem(); 150 item.Title = WebUtils.HtmlDecode(thread.Subject); 151 item.Link = FormatUrl(BlogUrls.Instance().ShowPost(thread)); 152 item.Author = thread.Author; 153 item.PubDate = thread.PostDate; 154 155 RssGuid guid = new RssGuid(); 156 guid.IsPermaLink = false; 157 guid.Text = SiteSettingsManager.GetSiteSettings().SiteKey + ":Weblog:" + thread.PostID; 158 item.Guid = guid; 159 160 item.Comments = FormatUrl(BlogUrls.Instance().CommentsPage(CurrentBlog.ApplicationKey, thread.PostID)); 161 162 if (WeblogConfiguration.Instance().TruncateAggregatePost) 163 item.Description = HtmlUtils.TrimHtml(thread.Body, WeblogConfiguration.Instance().AggregatePostSize); 164 else 165 item.Description = thread.Body; 166 167 //是否启用rss阅读计数 168 if (CurrentBlog.EnableAggBugs) 169 { 170 item.Description = string.Format("{0}<img src=\"{1}\" width=\"1\" height=\"1\">", item.Description, FormatUrl(GlobalUrls.Instance().AggView(ViewObject.BlogThread, thread.PostID))); 171 } 172 173 item.ReplyCount = thread.ReplyCount; 174 175 rssItems.Add(item); 176 } 177 178 rssDoc.Channel = rssChannel; 179 rssChannel.Items = rssItems; 180 181 DateTime dt = threads.TotalRecords > 0 ? threads.Records[0].PostDate : DateTime.Now; 182 183 return new TunyNet.Rss.Components.CachedFeed(dt, null, rssDoc.ToXml()); 184 } 185 186 187 } 188} 189
还没有找到您心仪的内容?请用.net源码大搜捕
代码片断 打包下载该项目完整源码:SpaceBuilder v1.0正式版源码