<%@ Control %>
<%@ Import Namespace="CommunityServer.Reader.Components" %>
<%@ Import Namespace="CommunityServer.Components" %>
<%@ Register TagPrefix="CS" Namespace="CommunityServer.Controls" Assembly="CommunityServer.Controls" %>
<%@ Register TagPrefix="CSR" Namespace="CommunityServer.Reader.Controls" Assembly="CommunityServer.Reader" %>
<script runat="server">

string GetCommentCount(object item)
{
	FeedPost feedPost = (FeedPost) item;
	
	if (feedPost.CommentCount < 0) return "";
	else return feedPost.CommentCount.ToString();
}

string GetPubDate(object item)
{
	FeedPost feedPost = (FeedPost) item;
	
	
	return Formatter.FormatAgoDate(feedPost.PubDate);
}

string GetCreator(object item)
{
	FeedPost feedPost	= (FeedPost) item;
	
	if (feedPost.Creator == null || feedPost.Creator.Trim() == "")
	{ 
		if (feedPost.FeedTitle != null || feedPost.FeedTitle.Trim() != "")
		{
			return " by <a href=\"" + feedPost.FeedLink + "\" target=\"_blank\">" + Formatter.RemoveHtml(feedPost.FeedTitle, 0) + "</a>";
		}
	}
	else
	{
		return " by " + feedPost.Creator;
	}
	return "";
}

string GetTitle(object item)
{
	FeedPost feedPost	= (FeedPost) item;
	string title		= feedPost.Title;
	if ((title != null) && (title.Trim().Length > 0))
		return title;

	return ResourceManager.GetString("roller_feed_no_title", "FeedReader.xml");
}

string GetDescription(object item)
{
	FeedPost feedPost	= (FeedPost) item;
	string description	= feedPost.Description;
	int length			= ReaderConfiguration.Instance().TruncationLength;
	
	if (length != 0)
	{
		if (Formatter.RemoveHtml(description, 0).Length > length)
		{
			description = Formatter.RemoveHtml(description, 0).Substring(0, length) + "... [<a href=\"" + feedPost.Link + "\" target=\"_blank\">read more</a>]";
		}
		else
		{
			description = Formatter.RemoveHtml(description, 0);
		}
	}
	return description;
}

</script>
<div class="RollerPostListingContainer">

	<ul class="BlogPostList">
	
	<CS:RepeaterPlusNone ID="rPosts" Runat="server">
		<ItemTemplate>
		<li class="BlogPostArea">
		<table width="100%">
		<tr>
			<td valign="top" width="1">
				<div class="BlogRating">
					<a href='<%# DataBinder.Eval(Container.DataItem, "CommentsUrl") %>' target="_blank"><span class="BlogCommentCount"><%# GetCommentCount(Container.DataItem) %></span><br/>
					<CSR:ResourceControl ResourceName="roller_comments_label" runat="server" /></a>
				</div>
			</td>
			<td class="ShowBorder">
				<h4 class="BlogPostHeader"><a href="<%# DataBinder.Eval(Container.DataItem, "Link") %>" target="_blank"><%# GetTitle(Container.DataItem) %></a></h4>
				<div class="BlogPostContent"><%# GetDescription(Container.DataItem) %></div>
				<div class="BlogPostFooter"><%# GetPubDate(Container.DataItem) %><%# GetCreator(Container.DataItem) %></div>
			</td>
		</tr>
		</table>
		</li>
		</ItemTemplate>
		<NoneTemplate>
		<li class="BlogPostArea">
		<table width="100%">
		<tr>
			<td align="center">
				<CSR:ResourceControl ResourceName="roller_no_posts" runat="server" />
			</td>
		</tr>
		</table>
		</li>
		</NoneTemplate>
	</CS:RepeaterPlusNone>
	<CS:SinglePager runat = "Server" id = "Pager" />
	
	</ul>
	
</div>
