private HtmlGenericControl BindCategories()
{
var dic = SortCategories();
if (dic.Keys.Count == 0)
{
var none = new HtmlGenericControl("p") { InnerText = "None" };
return none;
}
var ul = new HtmlGenericControl("ul") { ID = "categorylist" };
foreach (var id in dic.Values)
{
// Find full category
var cat = Category.GetCategory(id);
var key = cat.CompleteTitle();
var li = new HtmlGenericControl("li");
int i = cat.CompleteTitle().Count(c => c == '-');
string spaces = string.Empty;
for (int j = 0; j < i; j++)
{
spaces += "   ";
}
if (i > 0)
{
var textArea = new HtmlAnchor();
textArea.InnerHtml = spaces;
li.Controls.Add(textArea);
}
if (this.ShowRssIcon)
{
var img = new HtmlImage
{
Src = string.Format("{0}pics/rssButton.png", Utils.RelativeWebRoot),
Alt =
string.Format(
"{0} feed for {1}", BlogSettings.Instance.SyndicationFormat.ToUpperInvariant(), key)
};
img.Attributes["class"] = "rssButton";
var feedAnchor = new HtmlAnchor { HRef = cat.FeedRelativeLink };
feedAnchor.Attributes["rel"] = "nofollow";
feedAnchor.Controls.Add(img);
li.Controls.Add(feedAnchor);
}
var posts = Post.GetPostsByCategory(dic[key]).FindAll(p => p.IsVisible).Count;
var postCount = string.Format(" ({0})", posts);
if (!this.ShowPostCount)
{
postCount = null;
}
var anc = new HtmlAnchor
{
HRef = cat.RelativeLink,
InnerHtml = HttpUtility.HtmlEncode(cat.Title) + postCount,
Title = string.Format("Categorie: {0}", key)
};
li.Controls.Add(anc);
ul.Controls.Add(li);
}
return ul;
}