您目前尚未登陆,请选择【登陆】或【注册
首页->博客论坛->SpaceBuilder v1.0正式版源码>>BlogControls/HttpHandler/BlogCommentRssHandler.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 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 /// 用于生成博客评论 24 /// </summary> 25 /// <remarks> 26 /// 例如:生成博客最新评论,获取某篇文章的评论 27 /// </remarks> 28 public class BlogCommentRssHandler : BaseRssHandler 29 { 30 public BlogCommentRssHandler() 31 { } 32 33 private int sectionID = -1; 34 public int SectionID 35 { 36 get { return sectionID; } 37 set { sectionID = value; } 38 } 39 40 private string appkey = null; 41 public string ApplicationKey 42 { 43 get { return appkey; } 44 set { appkey = value; } 45 } 46 47 private int threadID = -1; 48 public int ThreadID 49 { 50 get { return threadID; } 51 set { threadID = value; } 52 } 53 54 private Weblog currentBlog = null; 55 public Weblog CurrentBlog 56 { 57 get 58 { 59 if (currentBlog == null) 60 { 61 if (SectionID > 0) 62 currentBlog = Weblogs.GetWeblog(SectionID); 63 else if (!ValueHelper.IsNullOrEmpty(ApplicationKey)) 64 currentBlog = Weblogs.GetWeblog(ApplicationKey); 65 } 66 67 return currentBlog; 68 } 69 } 70 71 /// <summary> 72 /// Appends http://Host:Port to all blog urls 73 /// </summary> 74 protected override string BaseUrl 75 { 76 get { return WebUtils.HostPath(Context.Request.Url); } 77 } 78 79 protected override int CacheTime { get { return WeblogConfiguration.Instance().RssCacheWindowInSeconds; } } 80 81 protected override string CacheKey 82 { 83 get 84 { 85 if (!ValueHelper.IsNullOrEmpty(ApplicationKey)) 86 { 87 if (ThreadID > 0) 88 return string.Format("Rss_BlogComments:{0}:ThreadID:{1}", ApplicationKey, ThreadID); 89 else 90 return string.Format("Rss_BlogComments:{0}:MostRecent", ApplicationKey); 91 } 92 else 93 { 94 if (ThreadID > 0) 95 return string.Format("Rss_BlogComments:{0}:ThreadID:{1}", SectionID, ThreadID); 96 else 97 return string.Format("Rss_BlogComments:{0}:MostRecent", SectionID); 98 } 99 } 100 } 101 102 protected override void ProcessFeed() 103 { 104 SBContext wlContext = SBContext.Current; 105 if (wlContext.GetIntFromQueryString("SectionID", -1) > 0) 106 this.SectionID = wlContext.GetIntFromQueryString("SectionID", -1); 107 108 this.ApplicationKey = wlContext.ApplicationKey; 109 this.ThreadID = wlContext.ThreadID; 110 111 base.ProcessFeed(); 112 } 113 114 protected override TunyNet.Rss.Components.CachedFeed BuildFeed() 115 { 116 if (CurrentBlog == null) 117 return new TunyNet.Rss.Components.CachedFeed(DateTime.Now, null, string.Empty); 118 119 BlogCommentQuery query = new BlogCommentQuery(); 120 if (this.ThreadID > 0) 121 query.ThreadID = this.ThreadID; 122 else 123 query.SectionID = CurrentBlog.SectionID; 124 125 query.ApproveStatus = ApproveStatus.IsApproved; 126 query.PageSize = WeblogConfiguration.Instance().RssDefaultThreadsPerFeed; 127 query.SortBy = BlogCommentSortBy.PostDate; 128 query.SortOrder = SortOrder.Descending; 129 query.IgnorePaging = true; 130 131 PagingDataSet<BlogPost> threads = BlogPosts.GetComments(query); 132 133 RssDocument rssDoc = new RssDocument(); 134 rssDoc.UseExternalNamespaces = true; 135 136 if (!ValueHelper.IsNullOrEmpty(StyleSheet)) 137 rssDoc.StyleSheet = FormatUrl(VirtualPathUtility.ToAbsolute(StyleSheet)); 138 139 RssChannel rssChannel = new RssChannel(); 140 rssChannel.Title = CurrentBlog.SectionName; 141 rssChannel.Link = FormatUrl(UserUrls.Instance().BlogHome(currentBlog.ApplicationKey)); 142 rssChannel.Description = CurrentBlog.Description; 143 rssChannel.Language = currentBlog.Langugage; 144 rssChannel.Generator = SBConfiguration.Instance().SpaceBuilderVersionInfo; 145 146 List<RssItem> rssItems = new List<RssItem>(); 147 148 foreach (BlogPost comment in threads.Records) 149 { 150 RssItem item = new RssItem(); 151 item.Title = WebUtils.HtmlDecode(comment.Subject); 152 153 item.Author = comment.Author; 154 item.PubDate = comment.PostDate; 155 156 RssGuid guid = new RssGuid(); 157 guid.IsPermaLink = false; 158 guid.Text = SiteSettingsManager.GetSiteSettings().SiteKey + ":Weblog:" + comment.PostID; 159 item.Guid = guid; 160 161 BlogThread thread = BlogPosts.GetThread(comment.ParentID, true); 162 if (thread != null) 163 { 164 item.Link = FormatUrl(BlogUrls.Instance().ShowPost(thread, CurrentBlog, comment)); 165 item.Comments = FormatUrl(BlogUrls.Instance().CommentsPage(CurrentBlog.ApplicationKey, comment.ParentID)); 166 } 167 168 item.Description = comment.Body; 169 //item.ReplyCount = comment.ReplyCount; 170 rssItems.Add(item); 171 } 172 173 rssDoc.Channel = rssChannel; 174 rssChannel.Items = rssItems; 175 176 DateTime dt = threads.TotalRecords > 0 ? threads.Records[0].PostDate : DateTime.Now; 177 178 return new TunyNet.Rss.Components.CachedFeed(dt, null, rssDoc.ToXml()); 179 } 180 181 182 } 183} 184
还没有找到您心仪的内容?请用.net源码大搜捕
代码片断 打包下载该项目完整源码:SpaceBuilder v1.0正式版源码