📄 weblogatomwriter.cs
字号:
//------------------------------------------------------------------------------
// <copyright company="Telligent Systems">
// Copyright (c) Telligent Systems Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
using System;
using System.Collections;
using CommunityServer.Components;
namespace CommunityServer.Blogs.Components
{
/// <summary>
/// Creates the XML for an Atom feed based on a single weblog
/// </summary>
public class WeblogAtomWriter : BaseAtomWriter
{
public WeblogAtomWriter(ArrayList posts, Section s, string baseUrl) : base(posts,s, baseUrl)
{
}
/// <summary>
/// Helper to cast the CurrenSection a Welbog
/// </summary>
protected Weblog CurrentWeblog
{
get{ return this.CurrentSection as Weblog;}
}
/// <summary>
/// Returns the time of the last modified post. Might be able to move this to the base
/// </summary>
protected override DateTime Modified
{
get
{
if(posts != null && posts.Count > 0)
{
return ((WeblogPost) (posts[posts.Count -1])).BloggerTime;
}
else
return new DateTime(2004,1,1);
}
}
/// <summary>
/// Return a link to the weblog home page
/// </summary>
protected override string HomeLink
{
get { return FormatUrl(BlogUrls.Instance().HomePage(CurrentWeblog.ApplicationKey)); }
}
/// <summary>
/// Writes the channel. This is an abstract member and must be implemented
/// </summary>
protected override void WriteChannel()
{
BuildChannel(CurrentWeblog.Name,HomeLink,CurrentWeblog.Description);
}
/// <summary>
/// Blog store a preferred language, so lets use it
/// </summary>
protected override string Language
{
get
{
return CurrentWeblog.Langugage;
}
}
/// <summary>
/// Writes the commentRss element
/// </summary>
/// <param name="p"></param>
protected override void ExtendendElements(Post p)
{
if(CurrentWeblog.EnableComments)
{
this.WriteElementString("wfw:commentRss", FormatUrl(BlogUrls.Instance().CommentRss(CurrentWeblog.ApplicationKey,p.PostID)));
}
}
/// <summary>
/// Enables Excerpt only syndiation as well as AggBugs
/// </summary>
/// <param name="p"></param>
/// <returns></returns>
protected override string PostBody(Post p)
{
WeblogPost wp = p as WeblogPost;
if(wp == null)
return p.FormattedBody;
else
{
string desc = null;
if(wp.SyndicateExcerpt)
{
if(wp.HasExcerpt)
{
desc = wp.Excerpt;
}
else
{
desc = Formatter.RemoveHtml(p.FormattedBody,500) ;
}
desc = string.Format("{0}...(<a href=\"{1}\">read more</a>)",desc,FormatUrl(BuildLink(p)));
}
else
{
desc = wp.FormattedBody;
}
if(CurrentWeblog.EnableAggBugs)
desc = string.Format("{0}<img src=\"{1}\" width=\"1\" height=\"1\">",desc,FormatUrl(Globals.GetSiteUrls().AggView(wp.PostID)));
return desc;
}
}
//ScottW: Need to include the bloggers timzezone for other Atom date elements
protected override void DateElements(Post p)
{
base.DateElements (p);
//this.WriteElementString("issued", W3UTC(p.PostDate.AddHours((-1) * CurrentWeblog.t), TimeZone(p.User.Profile.Timezone)));
}
/// <summary>
/// Builds a link to the post. This item is abstract and must be implemented
/// </summary>
/// <param name="p"></param>
/// <returns></returns>
protected override string BuildLink(Post p)
{
return FormatUrl(BlogUrls.Instance().Post(p as WeblogPost, CurrentWeblog));
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -