@using BlogEngine.Core
@using BlogEngine.NET.Custom.Widgets
@{
    var title = Model.Title;
    var dic = CategoryList.SortCategories();

    var categoryUrl = Utils.RelativeWebRoot + "category";

    var settings = Common.GetSettings(Model.Id);
    bool showRssIcon = true;
    bool showPostCnt = true;
    if (settings.ContainsKey("showrssicon"))
    {
        showRssIcon = bool.Parse(settings["showrssicon"]);
    }
    if (settings.ContainsKey("showpostcount"))
    {
        showPostCnt = bool.Parse(settings["showpostcount"]);
    }
}
<div class="Widget widget categorylist">
    <h4 class="WidgetHeader widget-header">@title</h4>
    <div class="WidgetContent widget-content">
        <ul id="categorylist">
            @foreach (var cat in dic.Values)
            {
                int i = cat.CompleteTitle().Count(c => c == '-');
                string spaces = string.Empty;
                for (int j = 0; j < i; j++)
                {
                    spaces += "&nbsp;&nbsp;&nbsp;";
                }
                var posts = Post.GetPostsByCategory(cat).FindAll(p => p.IsVisible).Count;
                <li>
                    @if (i > 0)
                    {
                    <a>@Html.Raw(spaces)</a>
                    }
                    @if (showRssIcon == true)
                    {
                    <a rel="nofollow" href="@categoryUrl/feed/@Utils.RemoveIllegalCharacters(cat.Title)">
                        <img class="rssButton" alt="RSS feed for SubBlog" src="~/Content/images/blog/rssButton.png">
                    </a>
                    }
                    <a title="Category: @cat.Title" href="@categoryUrl/@Utils.RemoveIllegalCharacters(cat.Title)">
                        @cat.Title 
                        @if (showPostCnt)
                        {
                            <span>(@posts)</span>
                        }
                    </a>
                </li>
            }
        </ul>
    </div>
</div>