public static string GetContentLink(ContentHead head) { SiteService site = new SiteService(); if (!String.IsNullOrEmpty(head.ExternalLinkUrl)) return head.ExternalLinkUrl; if (site.IgnoreVirtualAppPath) return head.Location + head.CanonicalName; else return AppName + head.Location + head.CanonicalName; }
public ContentHead Post(string id, [FromBody] int selectedAlternative) { ContentHead contentHead = cms.GetContent(id); cms.ParseContentData(contentHead); if (selectedAlternative == 1) { contentHead.CONTENT.TotalVotes1 += 1; } if (selectedAlternative == 2) { contentHead.CONTENT.TotalVotes2 += 1; } if (selectedAlternative == 3) { contentHead.CONTENT.TotalVotes3 += 1; } if (selectedAlternative == 4) { contentHead.CONTENT.TotalVotes4 += 1; } if (selectedAlternative == 5) { contentHead.CONTENT.TotalVotes5 += 1; } decimal total = SumOfAlternatives(contentHead.CONTENT); //Calculates percent for all alternatives contentHead.CONTENT.Percent1 = (contentHead.CONTENT.TotalVotes1 / total) * 100; contentHead.CONTENT.Percent2 = (contentHead.CONTENT.TotalVotes2 / total) * 100; contentHead.CONTENT.Percent3 = (contentHead.CONTENT.TotalVotes3 / total) * 100; contentHead.CONTENT.Percent4 = (contentHead.CONTENT.TotalVotes4 / total) * 100; contentHead.CONTENT.Percent5 = (contentHead.CONTENT.TotalVotes5 / total) * 100; contentHead.Data.JSON = contentHead.CONTENT.ToString(); cms.SaveContent(contentHead); //PageviewCount means number of votes SiteService site = new Box.CMS.Services.SiteService(); site.LogPageView(id); return(contentHead); }
protected override void InitializePage() { base.InitializePage(); string id = this.TempData["id"] as string; SiteService site = new Box.CMS.Services.SiteService(); HEAD = site.GetContent(id); if (HEAD == null) throw new System.Web.HttpException(404, "page not found"); site.LogPageView(id); CONTENT_URL = Request.Url.Scheme + "://" + Request.Url.Host + (Request.Url.Port!=80?":" + Request.Url.Port:"") + HEAD.Location+HEAD.CanonicalName; CONTENT = HEAD.CONTENT; }
protected override void InitializePage() { base.InitializePage(); string id = UrlData[0]; SiteService site = new Box.CMS.Services.SiteService(); HEAD = site.GetContent(id); if (HEAD == null) { throw new System.Web.HttpException(404, "page not found"); } site.LogPageView(id); CONTENT_URL = Request.Url.Scheme + "://" + Request.Url.Host + (Request.Url.Port != 80?":" + Request.Url.Port:"") + HEAD.Location + HEAD.CanonicalName; CONTENT = HEAD.CONTENT; }
public ContentHead Post(string id, [FromBody] int selectedAlternative) { ContentHead contentHead = cms.GetContent(id); cms.ParseContentData(contentHead); if(selectedAlternative == 1) contentHead.CONTENT.TotalVotes1 += 1; if(selectedAlternative == 2) contentHead.CONTENT.TotalVotes2 += 1; if(selectedAlternative == 3) contentHead.CONTENT.TotalVotes3 += 1; if(selectedAlternative == 4) contentHead.CONTENT.TotalVotes4 += 1; if(selectedAlternative == 5) contentHead.CONTENT.TotalVotes5 += 1; decimal total = SumOfAlternatives(contentHead.CONTENT); //Calculates percent for all alternatives contentHead.CONTENT.Percent1 = (contentHead.CONTENT.TotalVotes1 / total) * 100; contentHead.CONTENT.Percent2 = (contentHead.CONTENT.TotalVotes2 / total) * 100; contentHead.CONTENT.Percent3 = (contentHead.CONTENT.TotalVotes3 / total) * 100; contentHead.CONTENT.Percent4 = (contentHead.CONTENT.TotalVotes4 / total) * 100; contentHead.CONTENT.Percent5 = (contentHead.CONTENT.TotalVotes5 / total) * 100; contentHead.Data.JSON = contentHead.CONTENT.ToString(); cms.SaveContent(contentHead); //PageviewCount means number of votes SiteService site = new Box.CMS.Services.SiteService(); site.LogPageView(id); return contentHead; }
public static IEnumerable<ContentHead> GetContents(string url, string order = "Date", string[] kinds = null, DateTime? createdFrom = null, DateTime? createdTo = null, bool parseContent = false, int skip = 0, int top = 0, string filter = null, System.Linq.Expressions.Expression<Func<ContentHead, bool>> queryFilter = null) { if (url != null && url.ToLower() == "$currenturl") { if (HttpContext.Current == null) return null; int qIndex = HttpContext.Current.Request.RawUrl.IndexOf("?", 0); if (qIndex > 0) url = HttpContext.Current.Request.RawUrl.Substring(0, qIndex); else url = HttpContext.Current.Request.RawUrl; url = RemoveAppNameFromUrl(url); int slashIndex = url.LastIndexOf("/", 1); if (slashIndex > 0) url = url.Substring(0, url.Length - slashIndex); } SiteService site = new SiteService(); return site.GetContents(url, order, kinds, createdFrom, createdTo, parseContent, skip, top, filter, queryFilter); }
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); }
public static IEnumerable<ContentHead> GetRelatedContents(string[] tags, string location = null, string[] kinds = null, bool parseContent = false, int top = 0) { SiteService site = new SiteService(); return site.GetRelatedContent(tags, top, location, kinds, parseContent); }
public static string GetFileUrl(string filePath, int width = 0, int height = 0, int maxWidth = 0, int maxHeight = 0, bool asThumb = false, string vAlign = "center", string hAlign = "center", string mode = "") { SiteService site = new SiteService(); string url = "/files/" + filePath + "/?height=" + height + "&maxHeight=" + maxHeight + "&asThumb=" + asThumb.ToString().ToLower() + "&width=" + width + "&maxWidth=" + maxWidth + "&vAlign=" + vAlign + "&hAlign=" + hAlign + "&mode=" + mode; if (site.IgnoreVirtualAppPath) url = AppName + url; return url; }
public static string GetFileName(string fileUId) { SiteService site = new SiteService(); return site.GetFileName(fileUId); }
public static IEnumerable<ContentHead> GetCrossLinksFrom(string pageArea, string order = "CrossLinkDisplayOrder", int top = 0, string[] kinds = null, bool parseContent = false, string[] pageAreaFallBacks = null) { SiteService site = new SiteService(); return site.GetCrossLinksFrom(pageArea, order, top, kinds, parseContent, pageAreaFallBacks); }
/// <summary> /// Gets Quiz FirstOrDefault() based on pageAREA /// </summary> /// <param name="pageArea"></param> /// <returns></returns> public static IHtmlString Quiz(string pageArea) { Func<ContentHead, HelperResult> template = (quiz) => { string templatePath = System.Web.HttpContext.Current.Request.MapPath("~/box_templates/QUIZ.cshtml"); string schemaTemplate = System.IO.File.ReadAllText(templatePath, Encoding.Default); bool alreadyVoted = true; if (HttpContext.Current.Request.Cookies["QUIZ_" + quiz.ContentUId] == null) alreadyVoted = false; quiz.CONTENT["alreadyVoted"] = alreadyVoted; string outputQuiz = RazorEngine.Razor.Parse(schemaTemplate, quiz); return new HelperResult(w => w.Write(outputQuiz)); }; string str = ""; SiteService site = new SiteService(); var quizContent = site.GetCrossLinksFrom(pageArea, null, 1, new string[] { "QUIZ" }, true).FirstOrDefault(); if (quizContent != null) str = template(quizContent).ToString(); return new HtmlString(str); }
public static IEnumerable<ContentHead> GetRelatedContents(string id = null, string location = null, string[] kinds = null, bool parseContent = false, int top = 0) { if (id == null) { Box.CMS.Web.ContentRenderView renderView = WebPageContext.Current.Page as Box.CMS.Web.ContentRenderView; if (renderView == null) return new List<ContentHead>(); id = renderView.HEAD.ContentUId; } SiteService site = new SiteService(); return site.GetRelatedContent(id, top, location, kinds, parseContent); }
public static ContentTagRank[] GetTagCloud(string location, string[] kinds) { SiteService site = new SiteService(); return site.GetTagCloud(location, kinds); }
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); }
public static void ResponseFile(string fileUId) { SiteService site = new SiteService(); site.ResponseFile(HttpContext.Current.Response, fileUId); }
public static string RemoveAppNameFromUrl(string url) { SiteService site = new SiteService(); if (site.IgnoreVirtualAppPath) return url; if (AppName != "" && url.StartsWith(AppName)) { url = url.Substring(AppName.Length); } return url; }
public static void LogPageShare(bool logShare = true, bool logComments = true) { Box.CMS.Web.ContentRenderView renderView = WebPageContext.Current.Page as Box.CMS.Web.ContentRenderView; if (renderView == null) return; string serverHost = HttpContext.Current.Request.Url.Scheme + "://" + HttpContext.Current.Request.Url.Authority; SiteService site = new SiteService(); site.LogPageShare(renderView.HEAD, serverHost, logShare, logComments); }