If you want to display an RSS feed on the home page, here are the steps that I took.
1. Add attribute named "siteRssUrl" in "~/communityserver.config" (Line 79)
<Core
defaultLanguage="en-US"
....
siteRssUrl=http://www.yoursite.com/rss.xml
>
2. Modify "CSConfiguration.cs" file in "~/Configuration" of CommunityServerComponents project:
- add private member variable (Line 61):
private string siteRssUrl = String.Empty;
- add new attribute from attributeCollection (Line 155):
att = attributeCollection["siteRssUrl"];
if (att != null)
siteRssUrl = att.Value;
- add new public property (Line 434):
public string SiteRssUrl { get { return siteRssUrl; } }
3. Modify "~/Languages/en-US/ControlPanelResources.xml" and add the following new resource nodes (Line 164):
<resource name="CP_SiteRSS_Announcements">Current Site Features</resource>
<resource name="CP_SiteRSS_Announcements_More"><a href=http://www.yoursite.com/"> Read more at ... &raquo;</a></resource>
<resource name="CP_SiteRSS_NoAnnouncements">No feature stories are available.</resource>
4. Create new class libray file named "SiteRssFeed.cs" in "~/ControlPanel/Components" with the following code:
using System;
using CommunityServer.Reader.Components;
using CommunityServer.Components;
using CommunityServer.Configuration;
using Rss;
using System.Text.RegularExpressions;
using System.Net;
namespace CommunityServer.ControlPanel.Components
{
public class SiteRssFeed
{
static Regex stripHtml = new Regex("<[^>]*?>", RegexOptions.IgnoreCase | RegexOptions.Singleline);
private SiteRssFeed()
{
}
public static RssItemCollection GetAnnouncements()
{
RssItemCollection items;
items = (RssItemCollection)CSCache.Get("CP-SiteRss");
if (items != null)
return items;
items = new RssItemCollection();
if (Globals.IsNullorEmpty(CSConfiguration.GetConfig().SiteRssUrl))
return items;
Feed feed = new Feed();
feed.Url = CSConfiguration.GetConfig().SiteRssUrl;
feed.Title = "Current Site Features";
RssFeed rssFeed = null;
try
{
HttpWebRequest request = feed.CreateRequest();
request.Timeout = 10000; // timeout in ten seconds
rssFeed = RssFeed.Read(request);
}
catch (Exception)
{
return items;
}
if (rssFeed != null && rssFeed.Channels != null && rssFeed.Channels.Count >= 1)
{
RssItem newItem;
foreach (RssItem item in rssFeed.Channels[0].Items)
{
newItem = new RssItem();
newItem.Link = item.Link;
newItem.Title = stripHtml.Replace(item.Title, "");
newItem.Description = stripHtml.Replace(item.Description, "");
if (newItem.Description.Length > 250)
newItem.Description = newItem.Description.Substring(0, 250) + "...";
items.Add(newItem);
if (items.Count == 5)
break;
}
}
CSCache.Insert("CP-SiteRss", items, new System.Web.Caching.CacheDependency(null, new string[] { CommunityServer.Configuration.CSConfiguration.CacheKey }), 60 * 60 * 24);
return items;
}
}
}
5. Modify "~/Default.aspx" file as follows:
- Register the control
<%@ Register TagPrefix="CP" Namespace="CommunityServer.ControlPanel.Controls" Assembly="CommunityServer.Web" %>
- Add following two lines of code to Page_Load function (Line 16):
this.Announcements.DataSource = CommunityServer.ControlPanel.Components.SiteRssFeed.GetAnnouncements();
this.Announcements.DataBind();
- Add the following block of HTML below Featured Item content (Line 57):
<div class="CommonSidebarArea">
<h4 class="CommonSidebarHeader"><CP:ResourceControl runat="server" ResourceName="CP_SiteRSS_Announcements" ID="Resourcecontrol15"/></h4>
<div class="CommonSidebarContent">
<CS:RepeaterPlusNone runat="server" id="Announcements">
<ItemTemplate>
<div style="margin-bottom: 8px; margin-top: 8px;">
<a href="<%# DataBinder.Eval(Container.DataItem, "Link")%>"><%#DataBinder.Eval(Container.DataItem, "Title")%></a>
<div><%#DataBinder.Eval(Container.DataItem, "Description")%></div>
</div>
</ItemTemplate>
<NoneTemplate>
<div style="margin-bottom: 8px; margin-top: 8px;">
<CP:ResourceControl runat="server" ResourceName="CP_SiteRSS_NoAnnouncements" />
</div>
</NoneTemplate>
</CS:RepeaterPlusNone>
<CP:ResourceControl runat="server" ResourceName="CP_SiteRSS_Announcements_More" ID="Resourcecontrol16"/>
</div>
</div>