/// <summary> /// Output just the scripts for the Agility preview and development bar. /// </summary> /// <param name="helper"></param> public static HtmlString RenderAgilityPreviewBarScripts(this IHtmlHelper helper) { Agility.Web.Objects.AgilityPage p = AgilityContext.Page; if (p != null) { StringBuilder sb = new StringBuilder(); //inject the status panel scripts if (AgilityContext.IsPreview || Current.Settings.DevelopmentMode) { string script = StatusPanelEmitter.GetStatusPanelScriptNoJQuery(); sb.Append(script); } //handle dependencies on ouput cache... if (AgilityContext.OutputCacheKeys.Count > 0) { AgilityCache.AddResponseCacheDependancy(AgilityContext.OutputCacheKeys); } return(new HtmlString(sb.ToString())); } else if (AgilityContext.IsTemplatePreview) { //template preview... string script = StatusPanelEmitter.GetStatusPanelScriptNoJQuery(); return(new HtmlString(script)); } else { return(new HtmlString("")); } }
private List <AgilitySiteMapNode> GetDynamicChildNodes(AgilitySiteMapNode anode, AgilitySiteMapNode parentNode, List <AgilitySiteMapNode> collection) { string dynamicPageContentReferenceName = anode.DynamicPageContentReferenceName; string dynamicPageParentFieldName = anode.DynamicPageParentFieldName; if (string.IsNullOrEmpty(dynamicPageContentReferenceName) && string.IsNullOrEmpty(dynamicPageParentFieldName)) { return(collection); } //the child pages are dynamic pages... AgilityPage page = anode.AgilityPage; int parentContentID = 0; if (page != null) { string contentReferenceName = dynamicPageContentReferenceName; if (string.IsNullOrEmpty(contentReferenceName)) { AgilityDynamicSiteMapNode dpNode = anode.ParentNode as AgilityDynamicSiteMapNode; if (dpNode == null) { AgilitySiteMapNode pnode = parentNode; while (pnode != null) { dpNode = pnode.ParentNode as AgilityDynamicSiteMapNode; if (dpNode != null) { break; } pnode = pnode.ParentNode; } } if (!string.IsNullOrEmpty(dynamicPageParentFieldName) && dpNode != null && !string.IsNullOrEmpty(dpNode.ReferenceName)) { //get the content reference name from the parent page... AgilityContent parentContent = BaseCache.GetContent(dpNode.ReferenceName, AgilityContext.LanguageCode, AgilityContext.WebsiteName); if (parentContent != null && parentContent.DataSet != null && parentContent.DataSet.Tables["ContentItems"] != null && parentContent.DataSet.Tables["ContentItems"].Columns.Contains(dynamicPageParentFieldName)) { DataRow row = parentContent.GetItemByContentID(dpNode.ContentID); if (row != null) { //the contentReferenceName is stored in the field value... contentReferenceName = row[dynamicPageParentFieldName] as string; } } } } else if (!string.IsNullOrEmpty(dynamicPageParentFieldName)) { //filter the dynamic page list by the parent field... AgilityDynamicSiteMapNode dpNode = anode.ParentNode as AgilityDynamicSiteMapNode; if (dpNode == null) { AgilitySiteMapNode pnode = parentNode; while (pnode != null) { dpNode = pnode.ParentNode as AgilityDynamicSiteMapNode; if (dpNode != null) { break; } pnode = pnode.ParentNode; } } parentContentID = -1; if (!string.IsNullOrEmpty(dynamicPageParentFieldName) && dpNode != null && !string.IsNullOrEmpty(dpNode.ReferenceName)) { parentContentID = dpNode.ContentID; } } if (!string.IsNullOrEmpty(contentReferenceName)) { //add this page and reference name to the page/dynamic content index BaseCache.UpdateDynamicPageIndex(page.ID, contentReferenceName); //get the content first DataView dv = Data.GetContentView(contentReferenceName); //get the dynamic page formula index Dictionary <string, DynamicPageFormulaItem> dpIndex = BaseCache.GetDynamicPageFormulaIndex(page.ID, contentReferenceName, AgilityContext.LanguageCode, page.ServerPage, true); if (dpIndex != null && dv != null) { //make an ID based index Dictionary <int, DynamicPageFormulaItem> idIndex = new Dictionary <int, DynamicPageFormulaItem>(); foreach (var item in dpIndex.Values) { idIndex[item.ContentID] = item; } //loop all of the dynamic pages.... foreach (DataRowView dvr in dv) { DynamicPageFormulaItem item = null; int contentID = -1; if (!int.TryParse($"{dvr["ContentID"]}", out contentID)) { contentID = -1; } if (!idIndex.TryGetValue(contentID, out item)) { continue; } if (parentContentID != 0) { //do a lookup to ensure the parent id condition is met if necessary object testParentContentIDObj = item.GetContentItemValue(dynamicPageParentFieldName); if (testParentContentIDObj != null) { int testParentContentID = -1; string testParentContentIDStr = string.Format("{0}", testParentContentIDObj); if (int.TryParse(testParentContentIDStr, out testParentContentID)) { //if the value is an int, test for equality... if (parentContentID != testParentContentID) { continue; } } else { //value is NOT an int, test for "in" '[id],' or ',[id],' or ',[id]' if (!testParentContentIDStr.StartsWith(string.Format("{0},", parentContentID)) && !testParentContentIDStr.EndsWith(string.Format(",{0}", parentContentID)) && !testParentContentIDStr.Contains(string.Format(",{0},", parentContentID))) { continue; } } } else { continue; } } AgilityDynamicSiteMapNode thisDNode = AgilityDynamicSiteMapNode.GetDynamicNode(anode, item, page); collection.Add(thisDNode); } } } } return(collection); }
public async Task <HtmlString> InvokeAsync() { AgilityContext.HttpContext = HttpContext; StringBuilder sb = new StringBuilder(); Agility.Web.Objects.AgilityPage p = AgilityContext.Page; if (p != null) { //inject the status panel scripts if (AgilityContext.IsPreview || Current.Settings.DevelopmentMode) { string script = StatusPanelEmitter.GetStatusPanelScriptNoJQuery(); sb.AppendLine(script); } if (!string.IsNullOrEmpty(p.CustomAnalyticsScript)) { string script = p.CustomAnalyticsScript; if (script.IndexOf(AgilityHelpers.GLOBAL_SCRIPT_SEPARATOR) != -1) { string scriptBottomPage = script.Substring(script.IndexOf(AgilityHelpers.GLOBAL_SCRIPT_SEPARATOR) + AgilityHelpers.GLOBAL_SCRIPT_SEPARATOR.Length); if (!string.IsNullOrEmpty(scriptBottomPage)) { sb.AppendLine(scriptBottomPage); } } } //add the Javascript tracking stuff if (p.IncludeInStatsTracking) { //global script if (!string.IsNullOrEmpty(AgilityContext.Domain.StatsTrackingScript)) { string scriptTopGlobal = AgilityContext.Domain.StatsTrackingScript; if (scriptTopGlobal.IndexOf(AgilityHelpers.GLOBAL_SCRIPT_SEPARATOR) != -1) { string scriptBottomGlobal = scriptTopGlobal.Substring(scriptTopGlobal.IndexOf(AgilityHelpers.GLOBAL_SCRIPT_SEPARATOR) + AgilityHelpers.GLOBAL_SCRIPT_SEPARATOR.Length); if (!string.IsNullOrEmpty(scriptBottomGlobal)) { sb.AppendLine(scriptBottomGlobal); } } } } //handle dependencies on ouput cache... if (AgilityContext.OutputCacheKeys.Count > 0) { AgilityCache.AddResponseCacheDependancy(AgilityContext.OutputCacheKeys); } } else if (AgilityContext.IsTemplatePreview) { //template preview... string script = StatusPanelEmitter.GetStatusPanelScriptNoJQuery(); sb.AppendLine(script); } return(new HtmlString(sb.ToString())); }
internal static AgilityDynamicSiteMapNode GetDynamicNode(AgilitySiteMapNode parentNode, Agility.Web.AgilityContentServer.DynamicPageFormulaItem pageFormulaItem, AgilityPage page) { string nodeID = string.Format("{0}_{1}", parentNode.Key, pageFormulaItem.ContentID); string menuText = pageFormulaItem.MenuText; string pageName = pageFormulaItem.Name; string url = parentNode.ParentNode.PagePath; if (string.IsNullOrEmpty(url)) { url = parentNode.ParentNode.Url; } int index = url.LastIndexOf(".aspx", StringComparison.CurrentCultureIgnoreCase); if (index > 0) { url = url.Substring(0, index); } bool addAspx = true; if (AgilityContext.Domain != null && AgilityContext.Domain.ExtensionlessUrls) { addAspx = false; } string urlPath = string.Format("{0}/{1}", url, pageName); url = string.Format("{0}/{1}", url, pageName); if (addAspx) { url = string.Format("{0}.aspx", url); } if (url.StartsWith("/")) { url = string.Format("~{0}", url); } AgilityDynamicSiteMapNode node = new AgilityDynamicSiteMapNode(nodeID, url, menuText); node.ReferenceName = pageFormulaItem.ContentReferenceName; node.ContentID = pageFormulaItem.ContentID; //override the visibility attributes... node.SitemapVisible = pageFormulaItem.VisibleOnSitemap; node.MenuVisible = pageFormulaItem.VisibleOnMenu; node.ParentNode = parentNode.ParentNode; node.PageItemID = parentNode.PageItemID; node.ChildNodes = new List <AgilitySiteMapNode>(); foreach (AgilitySiteMapNode parentChildNode in parentNode.ChildNodes) { AgilitySiteMapNode childNode = parentChildNode.Copy(urlPath, node); node.ChildNodes.Add(childNode); } return(node); }