public static void SetupStyle( List <MarkupCss> markupCss, ModuleConfiguration config, SuperFlexiDisplaySettings displaySettings, string clientID, int moduleID, int pageID, Page page, Control control) { string styleLinkFormat = "\n<link rel=\"stylesheet\" href=\"{0}\" media=\"{2}\" data-name=\"{1}\">"; string rawCSSFormat = "\n<style type=\"text/css\" data-name=\"{1}\" media=\"{2}\">\n{0}\n</style>"; foreach (MarkupCss style in markupCss) { StringBuilder sbStyleText = new StringBuilder(); StringBuilder sbStyleName = new StringBuilder(); sbStyleName.Append(String.IsNullOrWhiteSpace(style.Name) ? clientID + "flexiStyle_" + markupCss.IndexOf(style) : "flexiStyle_" + style.Name); SuperFlexiHelpers.ReplaceStaticTokens(sbStyleName, config, false, displaySettings, moduleID, pageID, out sbStyleName); string scriptName = sbStyleName.ToString(); if (!String.IsNullOrWhiteSpace(style.Url)) { sbStyleText.Append(string.Format(styleLinkFormat, style.Url.Replace("$_SitePath_$", "/Data/Sites/" + CacheHelper.GetCurrentSiteSettings().SiteId.ToString() + "/"), scriptName, style.Media)); } else if (!String.IsNullOrWhiteSpace(style.CSS)) { sbStyleText.Append(string.Format(rawCSSFormat, style.CSS, scriptName, style.Media)); } SuperFlexiHelpers.ReplaceStaticTokens(sbStyleText, config, false, displaySettings, moduleID, pageID, out sbStyleText); LiteralControl theLiteral = new LiteralControl(); theLiteral.Text = sbStyleText.ToString(); StyleSheetCombiner ssc = (StyleSheetCombiner)page.Header.FindControl("StyleSheetCombiner"); if (ssc != null) { int sscIndex = page.Header.Controls.IndexOf(ssc); if (style.RenderAboveSSC) { page.Header.Controls.AddAt(sscIndex, theLiteral); } else { page.Header.Controls.AddAt(sscIndex + 1, theLiteral); } } else { page.Header.Controls.AddAt(0, theLiteral); } } }
public static void SetupStyle( List <MarkupCss> markupCss, ModuleConfiguration config, SuperFlexiDisplaySettings displaySettings, string clientID, int moduleID, int pageID, Page page, Control control) { string styleLinkFormat = "\n<link rel=\"stylesheet\" href=\"{0}\" media=\"{2}\" data-name=\"{1}\">"; string rawCSSFormat = "\n<style type=\"text/css\" data-name=\"{1}\" media=\"{2}\">\n{0}\n</style>"; foreach (MarkupCss style in markupCss) { StringBuilder sbStyleText = new StringBuilder(); StringBuilder sbStyleName = new StringBuilder(); sbStyleName.Append(String.IsNullOrWhiteSpace(style.Name) ? clientID + "flexiStyle_" + markupCss.IndexOf(style) : "flexiStyle_" + style.Name); SuperFlexiHelpers.ReplaceStaticTokens(sbStyleName, config, false, displaySettings, moduleID, pageID, out sbStyleName); string styleName = sbStyleName.ToString(); if (!String.IsNullOrWhiteSpace(style.Url)) { string styleUrl = string.Empty; if (style.Url.StartsWith("/") || style.Url.StartsWith("http://") || style.Url.StartsWith("https://")) { styleUrl = style.Url; } else if (style.Url.StartsWith("~/")) { styleUrl = WebUtils.ResolveServerUrl(style.Url); } else if (style.Url.StartsWith("$_SitePath_$")) { styleUrl = style.Url.Replace("$_SitePath_$", "/Data/Sites/" + CacheHelper.GetCurrentSiteSettings().SiteId.ToString() + "/"); } else { styleUrl = new Uri(config.SolutionLocationUrl, style.Url).ToString(); } //else if (File.Exists(System.Web.Hosting.HostingEnvironment.MapPath(config.MarkupDefinitionFile))) //{ // FileInfo fileInfo = new FileInfo(System.Web.Hosting.HostingEnvironment.MapPath(config.MarkupDefinitionFile)); // styleUrl = WebUtils.ResolveServerUrl(Path.Combine(fileInfo.DirectoryName.Replace(System.Web.Hosting.HostingEnvironment.MapPath("~"), "~/"), style.Url)); //} sbStyleText.Append(string.Format(styleLinkFormat, styleUrl, styleName, style.Media)); } else if (!String.IsNullOrWhiteSpace(style.CSS)) { sbStyleText.Append(string.Format(rawCSSFormat, style.CSS, styleName, style.Media)); } SuperFlexiHelpers.ReplaceStaticTokens(sbStyleText, config, false, displaySettings, moduleID, pageID, out sbStyleText); LiteralControl theLiteral = new LiteralControl(); theLiteral.Text = sbStyleText.ToString(); StyleSheetCombiner ssc = (StyleSheetCombiner)page.Header.FindControl("StyleSheetCombiner"); if (ssc != null) { int sscIndex = page.Header.Controls.IndexOf(ssc); if (style.RenderAboveSSC) { page.Header.Controls.AddAt(sscIndex, theLiteral); } else { page.Header.Controls.AddAt(sscIndex + 1, theLiteral); } } else { page.Header.Controls.AddAt(0, theLiteral); } } }
public static void SetupScripts( List <MarkupScript> markupScripts, ModuleConfiguration config, SuperFlexiDisplaySettings displaySettings, bool isEditable, bool isPostBack, string clientID, int moduleID, int pageID, Page page, Control control) { string scriptRefFormat = "\n<script type=\"text/javascript\" src=\"{0}\" data-name=\"{1}\"></script>"; string rawScriptFormat = "\n<script type=\"text/javascript\" data-name=\"{1}\">\n{0}\n</script>"; foreach (MarkupScript script in markupScripts) { StringBuilder sbScriptText = new StringBuilder(); StringBuilder sbScriptName = new StringBuilder(); sbScriptName.Append(String.IsNullOrWhiteSpace(script.ScriptName) ? clientID + "flexiScript_" + markupScripts.IndexOf(script) : "flexiScript_" + script.ScriptName); SuperFlexiHelpers.ReplaceStaticTokens(sbScriptName, config, isEditable, displaySettings, moduleID, pageID, out sbScriptName); string scriptName = sbScriptName.ToString(); if (!String.IsNullOrWhiteSpace(script.Url)) { //string scriptUrl = string.Empty; //if (script.Url.StartsWith("/") || // script.Url.StartsWith("http://") || // script.Url.StartsWith("https://")) //{ // scriptUrl = script.Url; //} //else if (script.Url.StartsWith("~/")) //{ // scriptUrl = WebUtils.ResolveServerUrl(script.Url); //} //else if (script.Url.StartsWith("$_SitePath_$")) //{ // scriptUrl = script.Url.Replace("$_SitePath_$", "/Data/Sites/" + CacheHelper.GetCurrentSiteSettings().SiteId.ToString() + "/"); //} //else //{ // scriptUrl = new Uri(config.SolutionLocationUrl, script.Url).ToString(); //} //else if (File.Exists(System.Web.Hosting.HostingEnvironment.MapPath(config.MarkupDefinitionFile))) //{ // FileInfo fileInfo = new FileInfo(System.Web.Hosting.HostingEnvironment.MapPath(config.MarkupDefinitionFile)); // scriptUrl = WebUtils.ResolveServerUrl(Path.Combine(fileInfo.DirectoryName.Replace(System.Web.Hosting.HostingEnvironment.MapPath("~"), "~/"), script.Url)); //} string scriptUrl = GetPathToFile(config, script.Url); sbScriptText.Append(string.Format(scriptRefFormat, scriptUrl, scriptName)); } else if (!String.IsNullOrWhiteSpace(script.RawScript)) { sbScriptText.Append(string.Format(rawScriptFormat, script.RawScript, scriptName)); } SuperFlexiHelpers.ReplaceStaticTokens(sbScriptText, config, isEditable, displaySettings, moduleID, pageID, out sbScriptText); // script position options // inHead // inBody (register script) (default) // aboveMarkupDefinition // belowMarkupDefinition // bottomStartup (register startup script) switch (script.Position) { case "inHead": if (!isPostBack && !page.IsCallback) { if (page.Header.FindControl(scriptName) == null) { LiteralControl headLit = new LiteralControl(); headLit.ID = scriptName; headLit.Text = sbScriptText.ToString(); headLit.ClientIDMode = System.Web.UI.ClientIDMode.Static; headLit.EnableViewState = false; page.Header.Controls.Add(headLit); } } break; case "aboveMarkupDefinition": if (control == null) { goto case "bottomStartup"; } if (control.FindControlRecursive(scriptName) == null) { Control aboveMarkupDefinitionScripts = control.FindControlRecursive("aboveMarkupDefinitionScripts"); if (aboveMarkupDefinitionScripts != null) { LiteralControl aboveLit = new LiteralControl(); aboveLit.ID = scriptName; aboveLit.Text = sbScriptText.ToString(); aboveMarkupDefinitionScripts.Controls.Add(aboveLit); } else { goto case "bottomStartup"; } } break; case "belowMarkupDefinition": if (control == null) { goto case "bottomStartup"; } if (control.FindControlRecursive(scriptName) == null) { Control belowMarkupDefinitionScripts = control.FindControlRecursive("belowMarkupDefinitionScripts"); if (belowMarkupDefinitionScripts != null) { LiteralControl belowLit = new LiteralControl(); belowLit.ID = scriptName; belowLit.Text = sbScriptText.ToString(); belowMarkupDefinitionScripts.Controls.Add(belowLit); } else { goto case "bottomStartup"; } } //strBelowMarkupScripts.AppendLine(scriptText); break; case "bottomStartup": if (!page.ClientScript.IsStartupScriptRegistered(scriptName)) { ScriptManager.RegisterStartupScript( page, typeof(Page), scriptName, sbScriptText.ToString(), false); } break; case "inBody": default: if (!page.ClientScript.IsClientScriptBlockRegistered(scriptName)) { ScriptManager.RegisterClientScriptBlock( page, typeof(Page), scriptName, sbScriptText.ToString(), false); } break; } } }
private IndexItem GetIndexItem(PageSettings pageSettings, int moduleID, Item item) { Module module = new Module(moduleID); log.Debug($"moduleid: {moduleID} for module {module.ModuleTitle}"); ModuleConfiguration config = new ModuleConfiguration(module); if (!config.IncludeInSearch) { return(null); } SuperFlexiDisplaySettings displaySettings = new SuperFlexiDisplaySettings(); ModuleDefinition flexiFeature = new ModuleDefinition(config.FeatureGuid); IndexItem indexItem = new IndexItem(); indexItem.SiteId = pageSettings.SiteId; indexItem.PageId = pageSettings.PageId; indexItem.PageName = pageSettings.PageName; indexItem.ViewRoles = pageSettings.AuthorizedRoles; indexItem.FeatureId = flexiFeature.FeatureGuid.ToString(); indexItem.FeatureName = String.IsNullOrWhiteSpace(config.ModuleFriendlyName) ? module.ModuleTitle : config.ModuleFriendlyName; indexItem.FeatureResourceFile = flexiFeature.ResourceFile; indexItem.ItemId = item.ItemID; indexItem.CreatedUtc = item.CreatedUtc; indexItem.LastModUtc = item.LastModUtc; if (pageSettings.UseUrl) { if (pageSettings.UrlHasBeenAdjustedForFolderSites) { indexItem.ViewPage = pageSettings.UnmodifiedUrl.Replace("~/", string.Empty); } else { indexItem.ViewPage = pageSettings.Url.Replace("~/", string.Empty); } indexItem.UseQueryStringParams = false; } SearchDef searchDef = SearchDef.GetByFieldDefinition(item.DefinitionGuid); bool hasSearchDef = true; if (searchDef == null) { searchDef = new SearchDef(); hasSearchDef = false; } System.Text.StringBuilder sbTitle = new System.Text.StringBuilder(searchDef.Title); System.Text.StringBuilder sbKeywords = new System.Text.StringBuilder(searchDef.Keywords); System.Text.StringBuilder sbDescription = new System.Text.StringBuilder(searchDef.Description); System.Text.StringBuilder sbLink = new System.Text.StringBuilder(searchDef.Link); System.Text.StringBuilder sbLinkQueryAddendum = new System.Text.StringBuilder(searchDef.LinkQueryAddendum); SiteSettings siteSettings = new SiteSettings(pageSettings.SiteGuid); SuperFlexiHelpers.ReplaceStaticTokens(sbTitle, config, false, displaySettings, module, pageSettings, siteSettings, out sbTitle); SuperFlexiHelpers.ReplaceStaticTokens(sbKeywords, config, false, displaySettings, module, pageSettings, siteSettings, out sbKeywords); SuperFlexiHelpers.ReplaceStaticTokens(sbDescription, config, false, displaySettings, module, pageSettings, siteSettings, out sbDescription); SuperFlexiHelpers.ReplaceStaticTokens(sbLink, config, false, displaySettings, module, pageSettings, siteSettings, out sbLink); SuperFlexiHelpers.ReplaceStaticTokens(sbLinkQueryAddendum, config, false, displaySettings, module, pageSettings, siteSettings, out sbLinkQueryAddendum); var fieldValues = ItemFieldValue.GetItemValues(item.ItemGuid); log.Debug($"SuperFlexi Index: total field value count for ItemGuid ({item.ItemGuid}) is {fieldValues.Count}"); foreach (ItemFieldValue fieldValue in fieldValues) { Field field = new Field(fieldValue.FieldGuid); if (field == null || !field.Searchable) { continue; } if (hasSearchDef) { sbTitle.Replace(field.Token, fieldValue.FieldValue); sbKeywords.Replace(field.Token, fieldValue.FieldValue); sbDescription.Replace(field.Token, fieldValue.FieldValue); sbLink.Replace(field.Token, fieldValue.FieldValue); sbLinkQueryAddendum.Replace(field.Token, fieldValue.FieldValue); } else { sbKeywords.Append(fieldValue.FieldValue); } if (debugLog) { log.DebugFormat("RebuildIndex indexing item [{0} = {1}]", field.Name, fieldValue.FieldValue); } } if (hasSearchDef) { sbTitle.Replace("$_ItemID_$", item.ItemID.ToString()); sbKeywords.Replace("$_ItemID_$", item.ItemID.ToString()); sbDescription.Replace("$_ItemID_$", item.ItemID.ToString()); sbLink.Replace("$_ItemID_$", item.ItemID.ToString()); sbLinkQueryAddendum.Replace("$_ItemID_$", item.ItemID.ToString()); indexItem.Content = sbDescription.ToString(); indexItem.Title = sbTitle.ToString(); if (sbLink.Length > 0) { indexItem.ViewPage = sbLink.ToString(); } if (sbLinkQueryAddendum.Length > 0) { indexItem.QueryStringAddendum = sbLinkQueryAddendum.ToString(); indexItem.UseQueryStringParams = false; } } else { indexItem.ModuleTitle = pageSettings.PageName; indexItem.Title = String.IsNullOrWhiteSpace(config.ModuleFriendlyName) ? module.ModuleTitle : config.ModuleFriendlyName; } indexItem.PageMetaKeywords = sbKeywords.ToString(); indexItem.Categories = sbKeywords.ToString(); return(indexItem); }
private void PopulateControls() { string featuredImageUrl = string.Empty; string markupTop = string.Empty; string markupBottom = string.Empty; featuredImageUrl = String.IsNullOrWhiteSpace(config.InstanceFeaturedImage) ? featuredImageUrl : WebUtils.GetRelativeSiteRoot() + config.InstanceFeaturedImage; markupTop = displaySettings.ModuleInstanceMarkupTop; markupBottom = displaySettings.ModuleInstanceMarkupBottom; strOutput.Append(markupTop); if (config.UseHeader && config.HeaderLocation == "InnerBodyPanel" && !String.IsNullOrWhiteSpace(config.HeaderContent) && !String.Equals(config.HeaderContent, "<p> </p>")) { try { strOutput.Append(string.Format(displaySettings.HeaderContentFormat, config.HeaderContent)); } catch (FormatException ex) { log.ErrorFormat(markupErrorFormat, "HeaderContentFormat", moduleTitle, ex); } } StringBuilder jsonString = new StringBuilder(); StringWriter stringWriter = new StringWriter(jsonString); JsonTextWriter jsonWriter = new JsonTextWriter(stringWriter); // http://www.newtonsoft.com/json/help/html/T_Newtonsoft_Json_DateTimeZoneHandling.htm jsonWriter.DateTimeZoneHandling = DateTimeZoneHandling.Utc; // http://www.newtonsoft.com/json/help/html/T_Newtonsoft_Json_DateFormatHandling.htm jsonWriter.DateFormatHandling = DateFormatHandling.IsoDateFormat; string jsonObjName = "sflexi" + module.ModuleId.ToString() + (config.IsGlobalView ? "Modules" : "Items"); if (config.RenderJSONOfData) { jsonWriter.WriteRaw("var " + jsonObjName + " = "); if (config.JsonLabelObjects || config.IsGlobalView) { jsonWriter.WriteStartObject(); } else { jsonWriter.WriteStartArray(); } } List <IndexedStringBuilder> itemsMarkup = new List <IndexedStringBuilder>(); //List<Item> categorizedItems = new List<Item>(); bool usingGlobalViewMarkup = !String.IsNullOrWhiteSpace(displaySettings.GlobalViewMarkup); int currentModuleID = -1; foreach (Item item in items) { bool itemIsEditable = isEditable || WebUser.IsInRoles(item.EditRoles); bool itemIsViewable = WebUser.IsInRoles(item.ViewRoles) || itemIsEditable; if (!itemIsViewable) { continue; } //int itemCount = 0; //StringBuilder content = new StringBuilder(); IndexedStringBuilder content = new IndexedStringBuilder(); ModuleConfiguration itemModuleConfig = new ModuleConfiguration(module); item.ModuleFriendlyName = itemModuleConfig.ModuleFriendlyName; if (String.IsNullOrWhiteSpace(itemModuleConfig.ModuleFriendlyName)) { Module itemModule = new Module(item.ModuleGuid); if (itemModule != null) { item.ModuleFriendlyName = itemModule.ModuleTitle; } } if (config.IsGlobalView) { content.SortOrder1 = itemModuleConfig.GlobalViewSortOrder; content.SortOrder2 = item.SortOrder; } else { content.SortOrder1 = item.SortOrder; } List <ItemFieldValue> fieldValues = ItemFieldValue.GetItemValues(item.ItemGuid); //using item.ModuleID here because if we are using a 'global view' we need to be sure the item edit link uses the correct module id. string itemEditUrl = WebUtils.GetSiteRoot() + "/SuperFlexi/Edit.aspx?pageid=" + pageId + "&mid=" + item.ModuleID + "&itemid=" + item.ItemID; string itemEditLink = itemIsEditable ? String.Format(displaySettings.ItemEditLinkFormat, itemEditUrl) : string.Empty; if (config.RenderJSONOfData) { if (config.IsGlobalView) { if (currentModuleID != item.ModuleID) { if (currentModuleID != -1) { jsonWriter.WriteEndObject(); jsonWriter.WriteEndObject(); } currentModuleID = item.ModuleID; //always label objects in globalview jsonWriter.WritePropertyName("m" + currentModuleID.ToString()); jsonWriter.WriteStartObject(); jsonWriter.WritePropertyName("Module"); jsonWriter.WriteValue(item.ModuleFriendlyName); jsonWriter.WritePropertyName("Items"); jsonWriter.WriteStartObject(); } } if (config.JsonLabelObjects || config.IsGlobalView) { jsonWriter.WritePropertyName("i" + item.ItemID.ToString()); } jsonWriter.WriteStartObject(); jsonWriter.WritePropertyName("ItemId"); jsonWriter.WriteValue(item.ItemID.ToString()); jsonWriter.WritePropertyName("SortOrder"); jsonWriter.WriteValue(item.SortOrder.ToString()); if (IsEditable) { jsonWriter.WritePropertyName("EditUrl"); jsonWriter.WriteValue(itemEditUrl); } } content.Append(displaySettings.ItemMarkup); foreach (Field field in fields) { if (String.IsNullOrWhiteSpace(field.Token)) { field.Token = "$_NONE_$"; //just in case someone has loaded the database with fields without using a source file. } bool fieldValueFound = false; foreach (ItemFieldValue fieldValue in fieldValues) { if (field.FieldGuid == fieldValue.FieldGuid) { fieldValueFound = true; if (String.IsNullOrWhiteSpace(fieldValue.FieldValue) || fieldValue.FieldValue.StartsWith("&deleted&") || fieldValue.FieldValue.StartsWith("&deleted&") || fieldValue.FieldValue.StartsWith("<p>&deleted&</p>") || fieldValue.FieldValue.StartsWith("<p>&deleted&</p>")) { content.Replace("^" + field.Token + "^", string.Empty); content.Replace("^" + field.Token, string.Empty); content.Replace(field.Token + "^", string.Empty); content.Replace(field.Token, string.Empty); } else { if (IsDateField(field)) { DateTime dateTime = new DateTime(); if (DateTime.TryParse(fieldValue.FieldValue, out dateTime)) { /// ^field.Token is used when we don't want the preTokenString and postTokenString to be used content.Replace("^" + field.Token + "^", dateTime.ToString(field.DateFormat)); content.Replace("^" + field.Token, dateTime.ToString(field.DateFormat) + field.PostTokenString); content.Replace(field.Token + "^", field.PreTokenString + dateTime.ToString(field.DateFormat)); content.Replace(field.Token, field.PreTokenString + dateTime.ToString(field.DateFormat) + field.PostTokenString); } } if (IsCheckBoxListField(field) || IsRadioButtonListField(field)) { foreach (CheckBoxListMarkup cblm in config.CheckBoxListMarkups) { if (cblm.Field == field.Name) { StringBuilder cblmContent = new StringBuilder(); List <string> values = fieldValue.FieldValue.SplitOnCharAndTrim(';'); if (values.Count > 0) { foreach (string value in values) { //why did we use _ValueItemID_ here instead of _ItemID_? cblmContent.Append(cblm.Markup.Replace(field.Token, value).Replace("$_ValueItemID_$", item.ItemID.ToString()) + cblm.Separator); cblm.SelectedValues.Add(new CheckBoxListMarkup.SelectedValue { Value = value, ItemID = item.ItemID }); //cblm.SelectedValues.Add(fieldValue); } } cblmContent.Length -= cblm.Separator.Length; content.Replace(cblm.Token, cblmContent.ToString()); } } } //else //{ /// ^field.Token is used when we don't want the preTokenString and postTokenString to be used content.Replace("^" + field.Token + "^", fieldValue.FieldValue); content.Replace("^" + field.Token, fieldValue.FieldValue + field.PostTokenString); content.Replace(field.Token + "^", field.PreTokenString + fieldValue.FieldValue); content.Replace(field.Token, field.PreTokenString + fieldValue.FieldValue + field.PostTokenString); //} } //if (!String.IsNullOrWhiteSpace(field.LinkedField)) //{ // Field linkedField = fields.Find(delegate(Field f) { return f.Name == field.LinkedField; }); // if (linkedField != null) // { // ItemFieldValue linkedValue = fieldValues.Find(delegate(ItemFieldValue fv) { return fv.FieldGuid == linkedField.FieldGuid; }); // content.Replace(linkedField.Token, linkedValue.FieldValue); // } //} if (config.RenderJSONOfData) { jsonWriter.WritePropertyName(field.Name); //if (IsDateField(field)) //{ // DateTime dateTime = new DateTime(); // if (DateTime.TryParse(fieldValue.FieldValue, out dateTime)) // { // jsonWriter.WriteValue(dateTime); // } //} //else //{ jsonWriter.WriteValue(fieldValue.FieldValue); //} } } } if (!fieldValueFound) { content.Replace(field.Token, field.DefaultValue); } } if (config.RenderJSONOfData) { //if (config.IsGlobalView) //{ // jsonWriter.WriteEndObject(); //} jsonWriter.WriteEndObject(); } content.Replace("$_EditLink_$", itemEditLink); content.Replace("$_ItemID_$", item.ItemID.ToString()); content.Replace("$_SortOrder_$", item.SortOrder.ToString()); if (!String.IsNullOrWhiteSpace(content)) { itemsMarkup.Add(content); } } if (config.DescendingSort) { itemsMarkup.Sort(delegate(IndexedStringBuilder a, IndexedStringBuilder b) { int xdiff = b.SortOrder1.CompareTo(a.SortOrder1); if (xdiff != 0) { return(xdiff); } else { return(b.SortOrder2.CompareTo(a.SortOrder2)); } }); } else { itemsMarkup.Sort(delegate(IndexedStringBuilder a, IndexedStringBuilder b) { int xdiff = a.SortOrder1.CompareTo(b.SortOrder1); if (xdiff != 0) { return(xdiff); } else { return(a.SortOrder2.CompareTo(b.SortOrder2)); } }); } StringBuilder allItems = new StringBuilder(); if (displaySettings.ItemsPerGroup == -1) { foreach (IndexedStringBuilder sb in itemsMarkup) { //allItems.Append(displaySettings.GlobalViewModuleGroupMarkup.Replace("$_ModuleGroupName_$", sb.GroupName)); allItems.Append(sb.ToString()); } if (usingGlobalViewMarkup) { strOutput.AppendFormat(displaySettings.ItemsWrapperFormat, displaySettings.GlobalViewMarkup.Replace("$_ModuleGroups_$", allItems.ToString())); } else { strOutput.AppendFormat(displaySettings.ItemsWrapperFormat, allItems.ToString()); } } else { int itemIndex = 0; decimal totalGroupCount = Math.Ceiling(itemsMarkup.Count / Convert.ToDecimal(displaySettings.ItemsPerGroup)); if (totalGroupCount < 1 && itemsMarkup.Count > 0) { totalGroupCount = 1; } int currentGroup = 1; List <StringBuilder> groups = new List <StringBuilder>(); while (currentGroup <= totalGroupCount && itemIndex < itemsMarkup.Count) { StringBuilder group = new StringBuilder(); group.Append(displaySettings.ItemsRepeaterMarkup); //group.SortOrder1 = itemsMarkup[itemIndex].SortOrder1; //group.SortOrder2 = itemsMarkup[itemIndex].SortOrder2; //group.GroupName = itemsMarkup[itemIndex].GroupName; for (int i = 0; i < displaySettings.ItemsPerGroup; i++) { if (itemIndex < itemsMarkup.Count) { group.Replace("$_Items[" + i.ToString() + "]_$", itemsMarkup[itemIndex].ToString()); itemIndex++; } else { break; } } groups.Add(group); currentGroup++; } //groups.Sort(delegate (IndexedStringBuilder a, IndexedStringBuilder b) { // int xdiff = a.SortOrder1.CompareTo(b.SortOrder1); // if (xdiff != 0) return xdiff; // else return a.SortOrder2.CompareTo(b.SortOrder2); //}); foreach (StringBuilder group in groups) { allItems.Append(group.ToString()); } strOutput.AppendFormat(displaySettings.ItemsWrapperFormat, Regex.Replace(allItems.ToString(), @"(\$_Items\[[0-9]+\]_\$)", string.Empty, RegexOptions.Multiline)); } //strOutput.Append(displaySettings.ItemListMarkupBottom); if (config.RenderJSONOfData) { if (config.JsonLabelObjects || config.IsGlobalView) { jsonWriter.WriteEndObject(); if (config.IsGlobalView) { jsonWriter.WriteEndObject(); jsonWriter.WriteEnd(); } } else { jsonWriter.WriteEndArray(); } MarkupScript jsonScript = new MarkupScript(); jsonWriter.Close(); stringWriter.Close(); jsonScript.RawScript = stringWriter.ToString(); jsonScript.Position = config.JsonRenderLocation; jsonScript.ScriptName = "sflexi" + module.ModuleId.ToString() + config.MarkupDefinitionName.ToCleanFileName() + "-JSON"; List <MarkupScript> scripts = new List <MarkupScript>(); scripts.Add(jsonScript); SuperFlexiHelpers.SetupScripts(scripts, config, displaySettings, IsEditable, IsPostBack, ClientID, ModuleId, PageId, Page, this); } if (config.UseFooter && config.FooterLocation == "InnerBodyPanel" && !String.IsNullOrWhiteSpace(config.FooterContent) && !String.Equals(config.FooterContent, "<p> </p>")) { try { strOutput.AppendFormat(displaySettings.FooterContentFormat, config.FooterContent); } catch (System.FormatException ex) { log.ErrorFormat(markupErrorFormat, "FooterContentFormat", moduleTitle, ex); } } strOutput.Append(markupBottom); SuperFlexiHelpers.ReplaceStaticTokens(strOutput, config, isEditable, displaySettings, module.ModuleId, pageSettings, siteSettings, out strOutput); //this is for displaying all of the selected values from the items outside of the items themselves foreach (CheckBoxListMarkup cblm in config.CheckBoxListMarkups) { StringBuilder cblmContent = new StringBuilder(); if (fields.Count > 0 && cblm.SelectedValues.Count > 0) { Field theField = fields.Where(field => field.Name == cblm.Field).Single(); if (theField != null) { List <CheckBoxListMarkup.SelectedValue> distinctSelectedValues = new List <CheckBoxListMarkup.SelectedValue>(); foreach (CheckBoxListMarkup.SelectedValue selectedValue in cblm.SelectedValues) { CheckBoxListMarkup.SelectedValue match = distinctSelectedValues.Find(i => i.Value == selectedValue.Value); if (match == null) { distinctSelectedValues.Add(selectedValue); } else { match.Count++; } } //var selectedValues = cblm.SelectedValues.GroupBy(selectedValue => selectedValue.Value) // .Select(distinctSelectedValue => new { Value = distinctSelectedValue.Key, Count = distinctSelectedValue.Count(), ItemID = distinctSelectedValue.ItemID }) // .OrderBy(x => x.Value); foreach (CheckBoxListMarkup.SelectedValue value in distinctSelectedValues) { cblmContent.Append(cblm.Markup.Replace(theField.Token, value.Value).Replace("$_ValueItemID_$", value.ItemID.ToString()) + cblm.Separator); cblmContent.Replace("$_CBLValueCount_$", value.Count.ToString()); } } if (cblmContent.Length >= cblm.Separator.Length) { cblmContent.Length -= cblm.Separator.Length; } strOutput.Replace(cblm.Token, cblmContent.ToString()); } strOutput.Replace(cblm.Token, string.Empty); } theLit.Text = strOutput.ToString(); }
private void LoadSettings() { Module module = new Module(ModuleGuid); config = new ModuleConfiguration(module); //PageSettings currentPage = CacheHelper.GetCurrentPage(); if (config.MarkupDefinition != null) { displaySettings = config.MarkupDefinition; } if (ModuleConfiguration != null) { Title = ModuleConfiguration.ModuleTitle; Description = ModuleConfiguration.FeatureName; } StringBuilder moduleTitle = new StringBuilder(); moduleTitle.Append(displaySettings.ModuleTitleMarkup); SuperFlexiHelpers.ReplaceStaticTokens(moduleTitle, config, IsEditable, displaySettings, module, currentPage, siteSettings, out moduleTitle); litModuleTitle.Text = moduleTitle.ToString(); if (config.InstanceCssClass.Length > 0 && !config.HideOuterWrapperPanel) { pnlOuterWrap.SetOrAppendCss(config.InstanceCssClass.Replace("$_ModuleID_$", ModuleId.ToString())); } if (SiteUtils.IsMobileDevice() && config.MobileInstanceCssClass.Length > 0 && !config.HideOuterWrapperPanel) { pnlOuterWrap.SetOrAppendCss(config.MobileInstanceCssClass.Replace("$_ModuleID_$", ModuleId.ToString())); } theWidget.Config = config; if (currentPage != null) { theWidget.PageId = currentPage.PageId; theWidget.CurrentPage = currentPage; } theWidget.ModuleId = ModuleId; theWidget.IsEditable = IsEditable; theWidget.SiteRoot = SiteRoot; theWidget.ImageSiteRoot = ImageSiteRoot; //theWidgetRazor.Config = config; //theWidgetRazor.PageId = PageId; //theWidgetRazor.ModuleId = ModuleId; //theWidgetRazor.IsEditable = IsEditable; //theWidgetRazor.SiteRoot = SiteRoot; //theWidgetRazor.ImageSiteRoot = ImageSiteRoot; theWidget.Visible = true; //theWidgetRazor.Visible = config.UseRazor; if (config.UseHeader && config.HeaderLocation != "InnerBodyPanel" && !String.IsNullOrWhiteSpace(config.HeaderContent) && !String.Equals(config.HeaderContent, "<p> </p>")) { StringBuilder headerContent = new StringBuilder(); headerContent.AppendFormat(displaySettings.HeaderContentFormat, config.HeaderContent); SuperFlexiHelpers.ReplaceStaticTokens(headerContent, config, IsEditable, displaySettings, module, currentPage, siteSettings, out headerContent); LiteralControl litHeaderContent = new LiteralControl(headerContent.ToString()); //if HeaderLocation is set to a hidden panel the header will be added to the Outside. switch (config.HeaderLocation) { default: break; case "OuterBodyPanel": if (config.HideOuterBodyPanel) { goto case "Outside"; } pnlOuterBody.Controls.AddAt(0, litHeaderContent); break; case "InnerWrapperPanel": if (config.HideInnerWrapperPanel) { goto case "Outside"; } pnlInnerWrap.Controls.AddAt(0, litHeaderContent); break; case "OuterWrapperPanel": if (config.HideOuterWrapperPanel) { goto case "Outside"; } pnlOuterWrap.Controls.AddAt(0, litHeaderContent); break; case "Outside": litHead.Text = headerContent.ToString(); break; } } if (config.UseFooter && config.FooterLocation != "InnerBodyPanel" && !String.IsNullOrWhiteSpace(config.FooterContent) && !String.Equals(config.FooterContent, "<p> </p>")) { StringBuilder footerContent = new StringBuilder(); footerContent.AppendFormat(displaySettings.FooterContentFormat, config.FooterContent); SuperFlexiHelpers.ReplaceStaticTokens(footerContent, config, IsEditable, displaySettings, module, currentPage, siteSettings, out footerContent); LiteralControl litFooterContent = new LiteralControl(footerContent.ToString()); //if FooterLocation is set to a hidden panel the footer will be added to the Outside. switch (config.FooterLocation) { default: break; case "OuterBodyPanel": if (config.HideOuterBodyPanel) { goto case "Outside"; } pnlOuterBody.Controls.Add(litFooterContent); break; case "InnerWrapperPanel": if (config.HideInnerWrapperPanel) { goto case "Outside"; } pnlInnerWrap.Controls.Add(litFooterContent); break; case "OuterWrapperPanel": if (config.HideOuterWrapperPanel) { goto case "Outside"; } pnlOuterWrap.Controls.Add(litFooterContent); break; case "Outside": litFoot.Text = footerContent.ToString(); break; } } pnlOuterWrap.RenderContentsOnly = config.HideOuterWrapperPanel; pnlInnerWrap.RenderContentsOnly = config.HideInnerWrapperPanel; pnlOuterBody.RenderContentsOnly = config.HideOuterBodyPanel; pnlInnerBody.RenderContentsOnly = config.HideInnerBodyPanel; }
public static void SetupScripts( List <MarkupScript> markupScripts, ModuleConfiguration config, SuperFlexiDisplaySettings displaySettings, bool forceHttps, bool isEditable, bool isPostBack, string clientID, int moduleID, int pageID, Page page, Control control) { string scriptRefFormat = "\n<script type=\"text/javascript\" src=\"{0}\" data-name=\"{1}\"></script>"; string rawScriptFormat = "\n<script type=\"text/javascript\" data-name=\"{1}\">\n{0}\n</script>"; foreach (MarkupScript script in markupScripts) { StringBuilder sbScriptText = new StringBuilder(); StringBuilder sbScriptName = new StringBuilder(); sbScriptName.Append(String.IsNullOrWhiteSpace(script.ScriptName) ? clientID + "flexiScript_" + markupScripts.IndexOf(script) : "flexiScript_" + script.ScriptName); SuperFlexiHelpers.ReplaceStaticTokens(sbScriptName, config, isEditable, displaySettings, moduleID, pageID, out sbScriptName); string scriptName = sbScriptName.ToString(); if (!String.IsNullOrWhiteSpace(script.Url)) { string scriptUrl = GetPathToFile(config, script.Url, forceHttps); sbScriptText.Append(string.Format(scriptRefFormat, scriptUrl, scriptName)); } else if (!String.IsNullOrWhiteSpace(script.RawScript)) { sbScriptText.Append(string.Format(rawScriptFormat, script.RawScript, scriptName)); } SuperFlexiHelpers.ReplaceStaticTokens(sbScriptText, config, isEditable, displaySettings, moduleID, pageID, out sbScriptText); // script position options // inHead // inBody (register script) (default) // aboveMarkupDefinition // belowMarkupDefinition // bottomStartup (register startup script) switch (script.Position) { case "inHead": if (!isPostBack && !page.IsCallback) { if (page.Header.FindControl(scriptName) == null) { LiteralControl headLit = new LiteralControl(); headLit.ID = scriptName; headLit.Text = sbScriptText.ToString(); headLit.ClientIDMode = System.Web.UI.ClientIDMode.Static; headLit.EnableViewState = false; page.Header.Controls.Add(headLit); } } break; case "aboveMarkupDefinition": if (control == null) { goto case "bottomStartup"; } if (control.FindControlRecursive(scriptName) == null) { Control aboveMarkupDefinitionScripts = control.FindControlRecursive("aboveMarkupDefinitionScripts"); if (aboveMarkupDefinitionScripts != null) { LiteralControl aboveLit = new LiteralControl(); aboveLit.ID = scriptName; aboveLit.Text = sbScriptText.ToString(); aboveMarkupDefinitionScripts.Controls.Add(aboveLit); } else { goto case "bottomStartup"; } } break; case "belowMarkupDefinition": if (control == null) { goto case "bottomStartup"; } if (control.FindControlRecursive(scriptName) == null) { Control belowMarkupDefinitionScripts = control.FindControlRecursive("belowMarkupDefinitionScripts"); if (belowMarkupDefinitionScripts != null) { LiteralControl belowLit = new LiteralControl(); belowLit.ID = scriptName; belowLit.Text = sbScriptText.ToString(); belowMarkupDefinitionScripts.Controls.Add(belowLit); } else { goto case "bottomStartup"; } } //strBelowMarkupScripts.AppendLine(scriptText); break; case "bottomStartup": if (!page.ClientScript.IsStartupScriptRegistered(scriptName)) { ScriptManager.RegisterStartupScript( page, typeof(Page), scriptName, sbScriptText.ToString(), false); } break; case "inBody": default: if (!page.ClientScript.IsClientScriptBlockRegistered(scriptName)) { ScriptManager.RegisterClientScriptBlock( page, typeof(Page), scriptName, sbScriptText.ToString(), false); } break; } } }