Example #1
0
        public static IHtmlContent ContentsRelated(string[] tags, Func<ContentHead, HelperResult> itemTemplate = null, string headerText = null, string location = null, string[] kinds = null, bool parseContent = false, int top = 0, string navigationId = null)
        {
            if (itemTemplate == null) {
                itemTemplate = (head) => { return new HelperResult(w => {
                        return w.WriteAsync("<li>" + ContentLink(head) + "</li>");
                    });
                };
            }

            string str = "";
            var heads = BoxLib.GetRelatedContents(tags, location, kinds, parseContent, top);
            var sb = new StringBuilder();            
            using (TextWriter tw = new StringWriter(sb))
            {               
                foreach (ContentHead head in heads)
                    itemTemplate(head).WriteTo(tw, System.Text.Encodings.Web.HtmlEncoder.Default);
            }
            str = sb.ToString();
            if (headerText != null && !String.IsNullOrEmpty(str))
                str = headerText + str;

            if (navigationId != null) {
                BoxLib.SetListIsOver(navigationId, heads.Count() < top);
                BoxLib.SetListCount(navigationId, heads.Count());
            }

            HtmlString html = new HtmlString(str);
            return html;
        }
Example #2
0
        public static IHtmlString ContentsRelated(string[] tags, Func <ContentHead, HelperResult> itemTemplate = null, string headerText = null, string location = null, string[] kinds = null, bool parseContent = false, int top = 0, string navigationId = null)
        {
            if (itemTemplate == null)
            {
                itemTemplate = (head) => { return(new HelperResult(w => w.Write("<li>" + ContentLink(head) + "</li>"))); }
            }
            ;

            string str   = "";
            var    heads = BoxLib.GetRelatedContents(tags, location, kinds, parseContent, top);

            foreach (ContentHead head in heads)
            {
                str = str + itemTemplate(head).ToString();
            }
            if (headerText != null && !String.IsNullOrEmpty(str))
            {
                str = headerText + str;
            }

            if (navigationId != null)
            {
                BoxLib.SetListIsOver(navigationId, heads.Count() < top);
                BoxLib.SetListCount(navigationId, heads.Count());
            }

            HtmlString html = new HtmlString(str);

            return(html);
        }
Example #3
0
        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, filter, queryFilter);
            int i        = 0;

            foreach (ContentHead head in contents)
            {
                head.OrderIndex = i;
                str             = str + itemTemplate(head).ToString();
                i++;
            }

            if (navigationId != null)
            {
                BoxLib.SetListIsOver(navigationId, contents.Count() < top);
                BoxLib.SetListCount(navigationId, contents.Count());
            }

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

            return(new HtmlString(str));
        }
Example #4
0
        public static IHtmlString PageMoreContentButton(string text = "More content...", string cssClass = null, string listId = null)
        {
            if (listId != null && BoxLib.GetListIsOver(listId))
            {
                return(new HtmlString(""));
            }

            string html = "<a " + (cssClass == null?"":"class=\"" + cssClass + "\"") + " src=\"#\" data-bind=\"click: function(d,e) { d._getData(); }, visible: nextContentButtonVisible()\" class=\"listNextButton\">" + text + "</a>";

            return(new HtmlString(html));
        }
Example #5
0
        public static IHtmlContent 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)
        {
            DateTime? lastPublished = DateTime.Now;
            if (period != Periods.AnyTime)
                lastPublished = BoxLib.GetLastPublishDate(location, kinds);

            ContentHead hotContent = BoxLib.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);
        }
Example #6
0
        public static IHtmlString TagCloud(string tagLink, string location = null, string[] kinds = null)
        {
            string cloud = "<ul class=\"tagCloud\">";

            ContentTagRank[] tags = BoxLib.GetTagCloud(location, kinds);
            foreach (ContentTagRank t in tags.OrderBy(t => t.Tag))
            {
                cloud = cloud + "<li value=\"" + t.Rank + "\"><a href=\"" + tagLink + "\\" + EncodeTag(t.Tag) + "\">" + t.Tag + "</a></li>";
            }
            cloud = cloud + "</ul>";
            return(new HtmlString(cloud));
        }
Example #7
0
        public static IHtmlString PageNextButton(string listId, string text = "next", string formId = null)
        {
            if (BoxLib.GetListIsOver(listId))
            {
                return(new HtmlString(""));
            }

            string html = "<a href=\"{0}\" class=\"listNextButton\">{1}</a>";

            html = String.Format(html, BoxLib.ListNavigatonNextLink(listId, formId), text);

            return(new HtmlString(html));
        }
Example #8
0
        public static IHtmlString PageFirstButton(string listId, string text = "first", string formId = null)
        {
            int page = BoxLib.GetPageSkipForList(listId);

            if (page == 0)
            {
                return(new HtmlString(""));
            }

            string html = "<a href=\"{0}\" class=\"listFirstButton\">{1}</a>";

            html = String.Format(html, BoxLib.ListNavigationLink(listId, 0, formId), text);
            return(new HtmlString(html));
        }
Example #9
0
        public static IHtmlString CrossLinksFrom(string pageArea, Func <ContentHead, HelperResult> itemTemplate = null, string order = "CrossLinkDisplayOrder", int top = 0, string[] kinds = null, IHtmlString noItemMessage = null, bool parseContent = false, string navigationId = null, string[] pageAreaFallBacks = null)
        {
            if (itemTemplate == null)
            {
                itemTemplate = (head) => { return(new HelperResult(w => w.Write("<div style=\"background-image: url(" + BoxLib.GetFileUrl(head.ThumbFilePath, asThumb: true) + ")\">" + ContentLink(head) + "</div>"))); }
            }
            ;


            var    heads = BoxLib.GetCrossLinksFrom(pageArea, order, top, kinds, parseContent, pageAreaFallBacks);
            string str   = "";
            int    i     = 0;

            foreach (ContentHead head in heads)
            {
                head.OrderIndex = i;
                str             = str + itemTemplate(head);
                i++;
            }

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

            if (navigationId != null)
            {
                BoxLib.SetListIsOver(navigationId, heads.Count() < top);
                BoxLib.SetListCount(navigationId, heads.Count());
            }

            return(new HtmlString(str));
        }
Example #10
0
        public static IHtmlContent CrossLinksFrom(string pageArea, Func<ContentHead, HelperResult> itemTemplate = null, Orders order = Orders.CrossLinkDisplayOrder, int top = 0, string[] kinds = null, IHtmlContent noItemMessage = null, bool parseContent = false, string navigationId = null, string[] pageAreaFallBacks = null)
        {            
            if (itemTemplate == null) {
                itemTemplate = (head) => { return new HelperResult(w =>
                    {
                        return w.WriteAsync("<div style=\"background-image: url(" + BoxLib.GetFileUrl(head.ThumbFilePath, asThumb: true) + "); width: 150px; height: 150px;\">" + ContentLink(head) + "</div>");
                    });
                };
            }

            var heads = BoxLib.GetCrossLinksFrom(pageArea, order, top, kinds, parseContent, pageAreaFallBacks);
            string str = "";            
            var sb = new StringBuilder();            
            using (TextWriter tw = new StringWriter(sb))
            {               
                int i = 0;                
                foreach (ContentHead head in heads)
                {
                    head.OrderIndex = i;
                    itemTemplate(head).WriteTo(tw, System.Text.Encodings.Web.HtmlEncoder.Default);
                    i++;
                }                
            }

            str = sb.ToString();
            if (heads.Count() == 0)
            {
                if (noItemMessage != null)
                    return noItemMessage;
                else
                    return new HtmlString("<div>No items.</div>");
            }

            if (navigationId != null) {
                BoxLib.SetListIsOver(navigationId, heads.Count() < top);
                BoxLib.SetListCount(navigationId, heads.Count());
            }

            return new HtmlString(str);
        }
Example #11
0
        void context_AuthorizeRequest(object sender, EventArgs e)
        {
            System.Web.HttpApplication app = sender as System.Web.HttpApplication;
            if (app == null)
            {
                return;
            }

            string fullUrl     = BoxLib.RemoveAppNameFromUrl(app.Context.Request.RawUrl);
            string redirectUrl = null;

            if (fullUrl.StartsWith("/where-is-my-db.htm"))
            {
                return;
            }

            // if true, can see not published contents
            bool canSeeOnlyPublished = GetShowOnlyPublished(app, fullUrl);

            string url = BoxLib.RemoveAppNameFromUrl(app.Request.FilePath);

            redirectCache.TryGetValue(url, out redirectUrl);

            if (redirectUrl == null)
            {
                Services.CMSService cms = new Services.CMSService();

                ContentHead c = null;
                try
                {
                    c = cms.GetContentHeadByUrlAndKind(url, null, canSeeOnlyPublished);
                }
                catch (Exception ex)
                {
                    var SQLexception = Box.Core.Services.SecurityService.GetSqlException(ex);
                    if (SQLexception != null && !Box.Core.Services.SecurityService.IsDebug)
                    {
                        app.Context.Response.Redirect("~/where-is-my-db.htm#" + SQLexception.Number);
                    }
                    else
                    {
                        throw ex;
                    }
                }

                if (c == null)
                {
                    return;
                }

                redirectUrl = "~/box_templates/" + c.Kind + "/" + c.ContentUId;

                // only add at cache published urls
                if (canSeeOnlyPublished)
                {
                    redirectCache.TryAdd(url, redirectUrl);
                }
            }

            app.Context.RewritePath(redirectUrl + "?" + app.Context.Request.QueryString);
        }
Example #12
0
 public static IHtmlString ContentLink(ContentHead content)
 {
     return(new HtmlString("<a href=\"" + BoxLib.GetContentLink(content) + "\" title=\"" + content.Name + "\">" + content.Name + "</a>"));
 }
Example #13
0
 public static IHtmlString Image(dynamic file, int width = 0, int height = 0, int maxWidth = 0, int maxHeight = 0, string cssClass = "", string vAlign = "center", string hAlign = "center", string mode = "")
 {
     return(new HtmlString("<img src=\"" + BoxLib.GetFileUrl((string)file.Folder, (string)file.FileUId, width, height, maxWidth, maxHeight, false, vAlign, hAlign, mode) + "\" alt=\"" + file.Caption + "\" title=\"" + file.Caption + "\" class=\"" + cssClass + "\" />"));
 }
Example #14
0
        public static IHtmlContent Contents(string[] kinds = null, Func<ContentHead, HelperResult> itemTemplate = null, Orders order = Orders.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, IHtmlContent noItemMessage = null, System.Linq.Expressions.Expression<Func<ContentHead, bool>> queryFilter = null, int manualSkip = 0)
        {
            if (itemTemplate == null) {
                itemTemplate = (head) => { return new HelperResult(w =>
                    {
                        return w.WriteAsync("<li>" + ContentLink(head) + "</li>");
                    });
                };
            }
            string str = "";

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

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


            var contents = BoxLib.GetContents(location, order, kinds, startDate, createdTo, parseContent, skip, top + 1, filter, queryFilter);
            var sb = new StringBuilder();            
            using (TextWriter tw = new StringWriter(sb))
            {                               
                int i = 0;            
                foreach (ContentHead head in contents) {
                    if (i < top) {
                        head.OrderIndex = i;
                        itemTemplate(head).WriteTo(tw, System.Text.Encodings.Web.HtmlEncoder.Default);
                        i++;
                    }
                }
                str = sb.ToString();
            }
            
            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);
        }