コード例 #1
0
ファイル: SiteHelpers.cs プロジェクト: foster-hub/box-cms
        public static IHtmlString ContentsRelatedWithHotestThread(Func<ContentHead, HelperResult> itemTemplate = null, string location = null, string[] kinds = null, ContentRanks rankBy = ContentRanks.PageViews, Periods period = Periods.LastDay, int top = 5, string navigationId = null)
        {
            SiteService site = new SiteService();

            DateTime? lastPublished = DateTime.Now;
            if (period != Periods.AnyTime)
                lastPublished = site.GetLastPublishDate(location, kinds);

            ContentHead hotContent = site.GetHotestContent(kinds, location, rankBy, period.StartDate(lastPublished), null);
            if (hotContent == null)
                return new HtmlString("");
            return ContentsRelated(hotContent.TagsToArray(), itemTemplate, null, null, null, false, top, navigationId);
        }
コード例 #2
0
ファイル: SiteHelpers.cs プロジェクト: foster-hub/box-cms
        public static IHtmlString Contents(string[] kinds = null, Func<ContentHead, HelperResult> itemTemplate = null, string order = "Date", Periods period = Periods.AnyTime, DateTime? createdFrom = null, DateTime? createdTo = null, bool parseContent = false, int top = 0, string navigationId = null, string location = null, string filter = null, IHtmlString noItemMessage = null, System.Linq.Expressions.Expression<Func<ContentHead, bool>> queryFilter = null)
        {
            if (itemTemplate == null)
                itemTemplate = (head) => { return new HelperResult(w => w.Write("<li>" + ContentLink(head) + "</li>")); };
            string str = "";

            int skip = 0;
            if (navigationId != null)
            {
                top = BoxLib.GetListPageSize(navigationId);
                skip = BoxLib.GetPageSkipForList(navigationId) * top;
            }

            SiteService site = new SiteService();

            DateTime? startDate = createdFrom;
            if (period != Periods.AnyTime)
            {
                DateTime? lastPublished = DateTime.Now;
                lastPublished = site.GetLastPublishDate(location, kinds);
                startDate = period.StartDate(lastPublished);
            }

            var contents = BoxLib.GetContents(location, order, kinds, startDate, createdTo, parseContent, skip, top + 1, filter, queryFilter);
            int i = 0;
            foreach (ContentHead head in contents) {
                if (i < top) {
                    head.OrderIndex = i;
                    str = str + itemTemplate(head).ToString();
                    i++;
                }
            }

            if (navigationId != null) {

                bool hasMorePage = contents.Count() == top + 1;
                int realCount = contents.Count();
                if (realCount > top)
                    realCount = top;

                BoxLib.SetListIsOver(navigationId, !hasMorePage);
                BoxLib.SetListCount(navigationId, realCount);
            }

            if (contents.Count() == 0)
            {
                if (noItemMessage != null)
                    return noItemMessage;
                else
                    return new HtmlString("<li>No items.</li>");
            }

            return new HtmlString(str);
        }