public static CMMicrosite GetCurrentRequestCMSMicrosite(HttpContext requestContext = null) { if (requestContext == null) { requestContext = HttpContext.Current; } if (requestContext == null || requestContext.Items["CMSMicrosite"] == "null") { return(null); } if (requestContext.Items["CMSMicrosite"] == null) { string fileName = Helpers.GetFileName(requestContext); int? micrositeID = GetCMMicrositeID(fileName, out fileName); CMMicrosite microsite = micrositeID.HasValue ? CMMicrosite.GetByID(micrositeID.Value) : null; if (microsite != null) { CMSHelpers.SetCurrentRequestCMSMicrosite(microsite); } else { requestContext.Items["CMSMicrosite"] = "null"; } return(microsite); } return((CMMicrosite)requestContext.Items["CMSMicrosite"]); }
protected override void OnLoad(EventArgs e) { CMPage cmPage = CMSHelpers.GetCurrentRequestCMSPage(); if (cmPage != null) { CMPageTitle pageTitle; if (Settings.EnableMultipleLanguages) { pageTitle = CMPageTitle.CMPageTitleGetByCMPageIDAndLanguageID(cmPage.CMPageID, Helpers.GetCurrentLanguage().LanguageID).FirstOrDefault(); Controls.Add(new LiteralControl((pageTitle != null) ? pageTitle.Title : cmPage.Title)); } else { Controls.Add(new LiteralControl(cmPage.Title)); } } }
public static CMPage GetCurrentRequestCMSPage(HttpContext requestContext = null) { if (requestContext == null) { requestContext = HttpContext.Current; } if (requestContext == null || requestContext.Items["CMSPage"] == "null") { return(null); } if (requestContext.Items["CMSPage"] == null) { string fileName = Helpers.GetFileName(requestContext); CMMicrosite micrositeEntity = GetCurrentRequestCMSMicrosite(); CMPage cmPage = CMPage.CMPageGetByFileName(fileName).FirstOrDefault(c => micrositeEntity == null || c.CMMicrositeID == micrositeEntity.CMMicroSiteID); if (cmPage == null && fileName.ToLower().EndsWith(".aspx")) { cmPage = CMPage.CMPageGetByFileName(fileName.ToLower().Replace(".aspx", "")).FirstOrDefault(c => micrositeEntity == null || c.CMMicrositeID == micrositeEntity.CMMicroSiteID); } //TODO: Showcase fix, would love to make this not so stupid if (fileName.Equals("showcase.aspx", StringComparison.OrdinalIgnoreCase)) { SEOComponent.SEOData seoEntity = SEOComponent.SEOData.SEODataGetByPageURL("~/" + fileName + "?" + requestContext.Request.QueryString.ToString().Replace("?&", "?").TrimEnd('?').Split('&')[0]).FirstOrDefault(); if (seoEntity != null && !String.IsNullOrEmpty(seoEntity.FriendlyFilename) && seoEntity.FriendlyFilename.Split('/').Length > 1) { cmPage = CMPage.CMPageGetByFileName(seoEntity.FriendlyFilename.Split('/')[1]).FirstOrDefault(c => micrositeEntity == null || c.CMMicrositeID == micrositeEntity.CMMicroSiteID); } } if (cmPage != null) { CMSHelpers.SetCurrentRequestCMSPage(cmPage); } else { requestContext.Items["CMSPage"] = "null"; } return(cmPage); } return((CMPage)requestContext.Items["CMSPage"]); }
protected override void OnLoad(EventArgs e) { m_CurrentLanguageID = Settings.EnableMultipleLanguages ? Helpers.GetCurrentLanguage().LanguageID : Helpers.GetDefaultLanguageID(); BreadCrumbsL.Text = string.Empty; CMPage page = CMSHelpers.GetCurrentRequestCMSPage(); CMMicrosite micrositeEntity = CMSHelpers.GetCurrentRequestCMSMicrosite(); bool currentPageAdded = false; int? micrositeID = micrositeEntity != null ? (int?)micrositeEntity.CMMicroSiteID : null; if (page != null) { if (page.FileName.Equals("default.aspx", StringComparison.OrdinalIgnoreCase) || page.FileName.Equals("Home.aspx", StringComparison.OrdinalIgnoreCase)) { } else { List <SMItem> sms; if (Settings.EnableMultipleLanguages && Settings.MultilingualManageSiteMapsIndividually) { sms = CMSHelpers.GetCachedSMItems(micrositeID, Helpers.GetCurrentLanguage().LanguageID).Where(s => s.CMPageID == page.CMPageID && !s.OriginalSMItemID.HasValue && !s.NeedsApproval).ToList(); } else { sms = CMSHelpers.GetCachedSMItems(micrositeID).Where(s => s.CMPageID == page.CMPageID && !s.OriginalSMItemID.HasValue && !s.NeedsApproval && (s.LanguageID == null || s.LanguageID == Helpers.GetDefaultLanguageID())).ToList(); } sms = sms.Where(s => !s.NewHomes.HasValue || s.NewHomes.Value == NewHomes).ToList(); if (sms.Count > 0) { int mID; SMItem smi = (!String.IsNullOrEmpty(Request.QueryString["mID"]) && Int32.TryParse(Request.QueryString["mID"], out mID) ? sms.Find(s1 => s1.SMItemID == mID) : sms.Find(s1 => s1.CMPageID == page.CMPageID)) ?? sms[0]; int count = 0; Action <SMItem> addBreadCrumb = null; addBreadCrumb = smItem => { CMPage cmPage = CMSHelpers.GetCachedCMPages().Where(c => c.CMPageID == smItem.CMPageID).FirstOrDefault(); string itemDisplayName = smItem.Name; if (Settings.EnableMultipleLanguages && !Settings.MultilingualManageSiteMapsIndividually && smItem.LanguageID != m_CurrentLanguageID) { List <CMPageTitle> titles = CMPageTitle.CMPageTitleGetByCMPageIDAndLanguageID(smItem.CMPageID, m_CurrentLanguageID); if (titles.Count > 0) { itemDisplayName = titles.LastOrDefault().Title; } } if (cmPage != null && count != 0) { if (!cmPage.FileName.Equals("default.aspx", StringComparison.OrdinalIgnoreCase) && !cmPage.FileName.Equals("Home.aspx", StringComparison.OrdinalIgnoreCase)) { BreadCrumbsL.Text = @"<li><a title=""" + Server.HtmlEncode(itemDisplayName.Replace("<br />", "")) + @""" href=""" + Server.HtmlEncode(cmPage.FileName) + @""">" + Server.HtmlEncode(itemDisplayName.Replace("<br />", "")) + @"</a></li>" + BreadCrumbsL.Text; } } else { currentPageAdded = true; //This is where the current page gets added BreadCrumbsL.Text = @"<li" + (!String.IsNullOrEmpty(m_CurrentLIClass) ? " class='" + m_CurrentLIClass + "'" : "") + @">" + Server.HtmlEncode(itemDisplayName.Replace("<br />", "")) + @"</li>" + BreadCrumbsL.Text; } count++; if (smItem.SMItemParentID.HasValue) { addBreadCrumb(CMSHelpers.GetCachedSMItems(micrositeID).Where(s => s.SMItemID == smItem.SMItemParentID.Value).Single()); } }; addBreadCrumb(smi); } } } if (micrositeEntity != null) { BreadCrumbsL.Text = @"<li><a title=""" + Server.HtmlEncode(micrositeEntity.Name) + @""" href=""" + Helpers.RootPath + Server.HtmlEncode(micrositeEntity.Name.ToLower().Replace(" ", "-")) + (Globals.Settings.RequireASPXExtensions ? "/Home.aspx" : "/") + @""">" + Server.HtmlEncode(micrositeEntity.Name) + @"</a></li>" + BreadCrumbsL.Text; } BreadCrumbsL.Text = @"<ul class='" + m_ULClass + @"'><li" + (!String.IsNullOrEmpty(m_FirstLIClass) ? " class='" + m_FirstLIClass + "'" : "") + @"><a title=""Home"" href=""" + Helpers.RootPath + @""">Home</a></li>" + BreadCrumbsL.Text; if (!currentPageAdded && (!String.IsNullOrEmpty(PageTitle) || Page.Title != Globals.Settings.SiteTitle)) { BreadCrumbsL.Text += @"<li" + (!String.IsNullOrEmpty(m_CurrentLIClass) ? " class='" + m_CurrentLIClass + "'" : "") + @">" + (!String.IsNullOrEmpty(PageTitle) ? PageTitle : Page.Title.Replace(" - " + Globals.Settings.SiteTitle, "")) + @"</li>"; } BreadCrumbsL.Text += @"</ul>"; BreadCrumbsL.EnableViewState = false; Controls.Add(BreadCrumbsL); }
/// <summary> /// This method checks the Content Manager page for form fields. /// If it finds form fields it will submit them to the form recipient. /// </summary> public static void ParseRequestForFormFields(string regionName) { if (String.IsNullOrEmpty(HttpContext.Current.Request.Form[DynamicSubmitName])) { return; } int? micrositeID = null; bool globalContact = false; CMPage cmPage = CMSHelpers.GetCurrentRequestCMSPage(); // determine legit fields List <CMPageRegion> prs = new List <CMPageRegion>(); int?userID = Helpers.GetCurrentUserID(); if (userID == 0) { userID = null; } if (cmPage != null) { CMRegion cmRegion = CMRegion.CMRegionPage(0, 1, "", "", true, new CMRegion.Filters { FilterCMRegionName = regionName }).FirstOrDefault(); if (cmRegion != null) { CMPageRegion currentRegion = CMPageRegion.LoadContentRegion(new CMPageRegion.Filters { FilterCMPageRegionCMRegionID = cmRegion.CMRegionID.ToString(), FilterCMPageRegionUserID = userID.ToString(), FilterCMPageRegionCMPageID = cmPage.CMPageID.ToString(), FilterCMPageRegionNeedsApproval = false.ToString() }); if (currentRegion != null) { prs.Add(currentRegion); } } } //Also get Global areas that might contain forms List <CMPage> globalAreas = CMSHelpers.GetCachedCMPages().Where(c => !c.CMTemplateID.HasValue && c.FileName.Equals(regionName)).ToList(); List <CMPage> temp = new List <CMPage>(); temp.AddRange(globalAreas); foreach (CMPage globalPage in temp) { CMRegion cmRegion = CMRegion.CMRegionGetByName(regionName).FirstOrDefault(); if (cmRegion != null) { CMPageRegion region = CMPageRegion.LoadContentRegion(new CMPageRegion.Filters { FilterCMPageRegionCMRegionID = cmRegion.CMRegionID.ToString(), FilterCMPageRegionUserID = userID.ToString(), FilterCMPageRegionCMPageID = globalPage.CMPageID.ToString(), FilterCMPageRegionNeedsApproval = false.ToString() }); if (region != null) { prs.Clear(); prs.Add(region); } else { globalAreas.Remove(globalPage); } } else { globalAreas.Remove(globalPage); } } if (prs.Count > 0) { bool hasFields = false; List <string> validFields = new List <string>(); List <string> checkBoxes = new List <string>(); foreach (CMPageRegion pr in prs) { MatchCollection ms = Regex.Matches(pr.Content, @"<(input|textarea|select) (.|\n)*?name=""?((\w|\d|\s|\-|\(|\))+)""?(.|\n)*?/?>", RegexOptions.IgnoreCase | RegexOptions.Multiline); if (ms.Count > 0 && globalAreas.Exists(c => c.CMPageID == pr.CMPageID)) { cmPage = globalAreas.Find(c => c.CMPageID == pr.CMPageID); globalContact = true; } foreach (Match m in ms) { if (!m.ToString().Contains("type=\"radio\"") || !validFields.Contains(m.Groups[3].Value)) { validFields.Add(m.Groups[3].Value); } if (m.ToString().Contains("type=\"checkbox\"")) { checkBoxes.Add(m.Groups[3].Value); } } } validFields.Remove("dynamicsubmit"); CMSubmittedForm newForm = new CMSubmittedForm(); newForm.IsProcessed = false; newForm.DateSubmitted = DateTime.UtcNow; newForm.FormRecipient = cmPage.FormRecipient; newForm.ResponsePageID = cmPage.ResponsePageID; newForm.CMMicrositeID = cmPage.CMMicrositeID; if (HttpContext.Current.Request.Files.Count > 0) { if (Regex.IsMatch(HttpContext.Current.Request.Files[0].FileName, "(\\.(doc)|(docx)|(pdf)|(jpg)|(jpeg)|(bmp)|(png)|(gif)|(ppt)|(pptx)|(xls)|(xlsx))$")) { HttpContext.Current.Request.Files[0].SaveAs(HttpContext.Current.Server.MapPath(UploadedFilesLocation + HttpContext.Current.Request.Files[0].FileName)); newForm.UploadedFile = HttpContext.Current.Request.Files[0].FileName; } else { Page page = (Page)HttpContext.Current.Handler; page.ClientScript.RegisterStartupScript(page.GetType(), "InvalidFileExt", "alert('Invalid file extension. Valid extensions are: doc,docx,pdf,jpg,jpeg,bmp,png,gif,ppt,pptx,xls,xlsx');", true); return; } } if (validFields.Count > 0) { StringBuilder formData = new StringBuilder(); validFields.ForEach(s => { if (HttpContext.Current.Request.Form[s] != null) { formData.Append(string.Format("<tr><td>{0}</td><td>{1}</td></tr>", s, HttpContext.Current.Request.Form[s].ToString())); if (!hasFields) { hasFields = true; } } // if the item is not posted, no harm, just dont include it else if (checkBoxes.Contains(s)) { formData.Append(string.Format("<tr><td>{0}</td><td>{1}</td></tr>", s, "off")); if (!hasFields) { hasFields = true; } } }); if (hasFields) { string body = EmailTemplateService.HtmlMessageBody(EmailTemplates.CMSFormPost, new { PageName = cmPage.FileName, FormFields = formData.ToString() }); newForm.FormHTML = body; newForm.Save(); if (globalContact && !String.IsNullOrEmpty(Settings.GlobalContactEmailAddress)) { MailMessage message = new MailMessage(); message.To.Add(Settings.GlobalContactEmailAddress); message.IsBodyHtml = true; message.Body = body; message.Subject = Globals.Settings.SiteTitle + "- Form Submission From " + cmPage.FileName; if (!String.IsNullOrEmpty(newForm.UploadedFile)) { message.Attachments.Add(new Attachment(HttpContext.Current.Server.MapPath(UploadedFilesLocation + newForm.UploadedFile))); } SmtpClient client = new SmtpClient(); client.Send(message); } else if (!String.IsNullOrEmpty(cmPage.FormRecipient)) { cmPage.FormRecipient.Split(',').ToList().ForEach(recipient => { MailMessage message = new MailMessage(); message.To.Add(recipient); message.IsBodyHtml = true; message.Body = body; message.Subject = Globals.Settings.SiteTitle + "- Form Submission From " + cmPage.FileName; if (!String.IsNullOrEmpty(newForm.UploadedFile)) { message.Attachments.Add(new Attachment(HttpContext.Current.Server.MapPath(UploadedFilesLocation + newForm.UploadedFile))); } SmtpClient client = new SmtpClient(); client.Send(message); }); } } if (hasFields) { if (globalContact) { Page page = (Page)HttpContext.Current.Handler; page.ClientScript.RegisterStartupScript(page.GetType(), PopupScriptName, @"$(document).ready(function(){ if ($('a#contactDummyLink').length == 0) $('div.contactSuccess').parent().parent().prepend('<a href=""#contactSuccess"" style=""display:none;"" id=""contactDummyLink"">success</a>'); $('a#contactDummyLink').fancybox(); $('a#contactDummyLink').trigger('click'); setTimeout(function(){$.fancybox.close();}, 4000); });", true); } else if (cmPage.ResponsePageID != null) { HttpContext.Current.Response.Redirect(CMSHelpers.GetCachedCMPages().Where(p => p.CMPageID == cmPage.ResponsePageID.Value).Single().FileName); } else { Page page = (Page)HttpContext.Current.Handler; //If you change the key or type of the script below, //you must also change it on the _RadEditor.cs file or your page will not load correctly //in the if statement with Page.ClientScript.IsStartupScriptRegistered(Page.GetType(), "PopupScript") page.ClientScript.RegisterStartupScript(page.GetType(), PopupScriptName, "alert('Thank you. Your form has been submitted successfully.');", true); } } } } }
protected override void OnLoad(EventArgs e) { allSMItems = new List <SMItem>(); CMPage currentPage = CMSHelpers.GetCurrentRequestCMSPage(); FileName = String.IsNullOrEmpty(FileName) ? (currentPage != null ? currentPage.FileName : Helpers.GetFileName()) : FileName; string micrositeName = string.Empty; CMMicrosite micrositeEntity = CMSHelpers.GetCurrentRequestCMSMicrosite(); if (Settings.EnableMicrosites && MicrositeMenu) { if (micrositeEntity != null) { micrositeName = micrositeEntity.Name.ToLower().Replace(" ", "-"); } } allCMPages = CMSHelpers.GetCachedCMPages(); if (currentPage != null && currentPage.MicrositeDefault) { allSMItems = SMItem.SMItemGetByMicrositeDefault(true); } else { //Must AddRange here in order to eliminate updating the cache with "AdditionalSMItems" allSMItems.AddRange(CMSHelpers.GetCachedSMItems((micrositeEntity != null ? (int?)micrositeEntity.CMMicroSiteID : null)).Where(s => s.NewHomes == NewHomes)); } allSMItems.RemoveAll(s => s.NeedsApproval || s.OriginalSMItemID.HasValue); m_CurrentLanguageID = Settings.EnableMultipleLanguages ? Helpers.GetCurrentLanguage().LanguageID : Helpers.GetDefaultLanguageID(); if (Settings.EnableMultipleLanguages && Settings.MultilingualManageSiteMapsIndividually) { allSMItems.RemoveAll(s => s.LanguageID != m_CurrentLanguageID); } else { allSMItems.RemoveAll(s => s.LanguageID != null && s.LanguageID != Helpers.GetDefaultLanguageID()); } List <SMItem> additionalSMItems = MenuPlugin.GetAdditionalSMItems(allSMItems); allSMItems.AddRange(additionalSMItems); List <SMItem> rootItems = new List <SMItem>(); Func <int?, bool> shouldRenderSubs = null; Func <List <SMItem>, int?, List <int>, List <int> > getChildIDs = null; getChildIDs = (sms, parentID, ids) => { sms.ForEach(s => { if (s.ShowInMenu && s.SMItemID == parentID) { ids.Add(s.SMItemID); ids.AddRange(getChildIDs(sms, s.SMItemParentID, new List <int>())); } }); return(ids); }; Func <List <SMItem>, int?, List <int>, List <int> > getChildByParentIDs = null; getChildByParentIDs = (sms, parentID, ids) => { sms.ForEach(s => { if (s.ShowInMenu && s.SMItemParentID == parentID) { ids.Add(s.SMItemID); ids.AddRange(getChildByParentIDs(sms, s.SMItemID, new List <int>())); } }); return(ids); }; string fileNameAndQuery = (FileName + "?" + Request.QueryString.ToString().Replace("filename=" + FileName, "")).Replace("?&", "?").TrimEnd('?'); if (fileNameAndQuery.ToLower().StartsWith("showcase.aspx?showcaseid=2")) { fileNameAndQuery = fileNameAndQuery.ToLower().Replace("showcase.aspx?showcaseid=2", "search?").Replace("?&", "?").TrimEnd('?'); } else if (fileNameAndQuery.ToLower().StartsWith("showcase.aspx?showcaseid=4")) { fileNameAndQuery = fileNameAndQuery.ToLower().Replace("showcase.aspx?showcaseid=4", "search?").Replace("?&", "?").TrimEnd('?'); } Func <List <SMItem>, int?, string> renderMenu = null; renderMenu = (menus, Parent) => { var sub = menus; if (Parent.HasValue) { sub = menus.Where(m => m.ShowInMenu && m.SMItemParentID == Parent).OrderBy(s => s.Rank).ToList(); } if (sub.Count > 0) { StringBuilder sb = new StringBuilder(); if (Parent.HasValue) { sb.Append(String.Format("<ul{0}>", String.IsNullOrEmpty(UnorderedListClass) ? "" : String.Format(" class=\"{0}\"", UnorderedListClass))); } int index = 0; SMItem topLevelParentSMItem = null; if (!Parent.HasValue && !String.IsNullOrEmpty(CurrentSectionClass)) { CMPage currentCMPage = allCMPages.Find(c => c.FileName == FileName); if (currentCMPage != null) { topLevelParentSMItem = allSMItems.Find(s => s.CMPageID == currentCMPage.CMPageID); } //Don't want the top level of the menu to get this special class if its the currently selected page if (topLevelParentSMItem != null && menus.Exists(s => s.SMItemID == topLevelParentSMItem.SMItemID)) { topLevelParentSMItem = null; } while (topLevelParentSMItem != null && topLevelParentSMItem.SMItemParentID != null) { topLevelParentSMItem = allSMItems.Find(s => s.SMItemID == topLevelParentSMItem.SMItemParentID.Value); } } foreach (SMItem subMenuItem in sub) { bool hasSubItems; bool duplicatedMenuItem = allSMItems.Any(s => s.CMPageID == subMenuItem.CMPageID && s.SMItemID != subMenuItem.SMItemID && subMenuItem.CMPageID != 0); if (additionalSMItems.Exists(s => s.SMItemParentID == subMenuItem.SMItemID)) { hasSubItems = true; } else if (Settings.HideMembersAreaPagesInMenu && Settings.EnableCMPageRoles && !CMSHelpers.HasFullCMSPermission()) { hasSubItems = CMSHelpers.IsMenuItemParentByPageRoles(subMenuItem.SMItemID); } else { hasSubItems = (Parent.HasValue ? menus : allSMItems).Any(s => s.SMItemParentID == subMenuItem.SMItemID && s.ShowInMenu); } index++; string cmPageFileName = string.Empty; if (!String.IsNullOrEmpty(subMenuItem.LinkToPage)) { cmPageFileName = subMenuItem.LinkToPage; } else { CMPage itemCMPage = allCMPages.Where(c => c.CMPageID == subMenuItem.CMPageID).FirstOrDefault(); if (itemCMPage != null) { if (Settings.HideMembersAreaPagesInMenu && Settings.EnableCMPageRoles && !CMSHelpers.CanUserAccessPage(itemCMPage.CMPageID)) { continue; } cmPageFileName = itemCMPage.FileName; } } string itemDisplayName = subMenuItem.Name; if (Settings.EnableMultipleLanguages && !Settings.MultilingualManageSiteMapsIndividually && subMenuItem.LanguageID != m_CurrentLanguageID) { List <CMPageTitle> titles = CMPageTitle.CMPageTitleGetByCMPageIDAndLanguageID(subMenuItem.CMPageID, m_CurrentLanguageID); if (titles.Count > 0) { itemDisplayName = titles.LastOrDefault().Title; } } string className = Parent.HasValue ? SubListClass : MainListClass; if (className == null) { className = string.Empty; } if (cmPageFileName.Equals(fileNameAndQuery, StringComparison.OrdinalIgnoreCase) || cmPageFileName.Equals(fileNameAndQuery.ToLower().Replace(".aspx", ""), StringComparison.OrdinalIgnoreCase) || ((cmPageFileName.Equals(FileName, StringComparison.OrdinalIgnoreCase) || cmPageFileName.Equals(FileName.Replace("default.aspx", ""), StringComparison.OrdinalIgnoreCase)) && !allCMPages.Any(c => c.FileName.Equals(fileNameAndQuery, StringComparison.OrdinalIgnoreCase)))) { className += " current"; if (!Parent.HasValue) { MasterPage master = Page.Master; if (master != null) { while (master.Master != null) { master = master.Master; } ((System.Web.UI.HtmlControls.HtmlElement)master.FindControl("htmlEntity")).Attributes["class"] += " parent-" + cmPageFileName.ToLower().Replace(".aspx", ""); } } } if (index == sub.Count && !SuppressLast) { className += " lastLi"; } if (topLevelParentSMItem != null && subMenuItem.SMItemID == topLevelParentSMItem.SMItemID) { className += " " + CurrentSectionClass; } if (hasSubItems) { className += " parent"; } if (cmPageFileName.Equals("default.aspx", StringComparison.OrdinalIgnoreCase) || (micrositeEntity != null && (cmPageFileName.Equals("home", StringComparison.OrdinalIgnoreCase) || cmPageFileName.Equals("home.aspx", StringComparison.OrdinalIgnoreCase) || cmPageFileName.Equals("new-homes", StringComparison.OrdinalIgnoreCase)))) { className += " home"; } if (index - 1 == 0 && !String.IsNullOrEmpty(FirstLIClass)) { className += " " + FirstLIClass; } if (itemDisplayName.ToLower().Contains("<br />")) { className += " twoLines"; } className = className.Trim(); sb.Append("<li"); if (!String.IsNullOrEmpty(className)) { sb.AppendFormat(" class=\"{0}\"", className); } sb.AppendFormat("><a "); if (Parent.HasValue && !String.IsNullOrEmpty(SubAnchorClass)) { sb.AppendFormat("class=\"{0}\" ", SubAnchorClass); } else if (!Parent.HasValue && !String.IsNullOrEmpty(MainAnchorClass)) { sb.AppendFormat("class=\"{0}\" ", MainAnchorClass); } sb.AppendFormat("href=\"{0}{1}{2}{3}\"", cmPageFileName.Contains("://") ? "" : VirtualPathUtility.ToAbsolute("~/"), String.IsNullOrEmpty(micrositeName) || cmPageFileName.Contains("://") ? "" : Server.HtmlEncode(micrositeName) + "/", cmPageFileName.Equals("default.aspx", StringComparison.OrdinalIgnoreCase) ? "./" : (!Globals.Settings.RequireASPXExtensions && cmPageFileName.Equals("Home.aspx", StringComparison.OrdinalIgnoreCase) && !String.IsNullOrEmpty(micrositeName) ? "" : Server.HtmlEncode(cmPageFileName)), (duplicatedMenuItem ? (cmPageFileName.Contains("?") ? "&" : "?") + "mID=" + subMenuItem.SMItemID : "")); if (cmPageFileName.Contains("://")) { sb.Append(" target=\"_blank\""); } //end a start tag sb.AppendFormat(">{0}", Server.HtmlEncode(itemDisplayName)); if (Parent.HasValue && hasSubItems) { sb.Append(SubitemToken); } sb.Append("</a>"); if (hasSubItems && shouldRenderSubs(subMenuItem.SMItemID)) { sb.Append(renderMenu((Parent.HasValue ? menus : allSMItems), subMenuItem.SMItemID)); } sb.Append("</li>"); } if (Parent.HasValue) { sb.Append("</ul>"); } return(sb.ToString()); } return(string.Empty); }; if (!String.IsNullOrEmpty(RootFilenames)) { // Add items for the pages in the list to the root List <string> fileNames = new List <string>(RootFilenames.Split(',')); List <CMPage> rootPages = allCMPages.Where(c => fileNames.Contains(c.FileName.ToLower(), StringComparer.OrdinalIgnoreCase)).ToList(); rootItems.AddRange(allSMItems.Where(s => s.ShowInMenu).Where(s => rootPages.Select(p => p.CMPageID).ToList().Contains(s.CMPageID)).OrderBy(s => s.Rank).ToList()); } switch (Mode) { case MenuMode.CurrentSection: { // Add the parent to the current page as the root SMItem currentSMItem = null; if (String.IsNullOrEmpty(RootFilenames) && currentPage != null) { int mID; currentSMItem = (!String.IsNullOrEmpty(Request.QueryString["mID"]) && Int32.TryParse(Request.QueryString["mID"], out mID) ? allSMItems.Find(s1 => s1.SMItemID == mID) : allSMItems.Find(s1 => s1.CMPageID == currentPage.CMPageID)) ?? allSMItems.Find(s1 => s1.CMPageID == currentPage.CMPageID); if (currentSMItem != null) { if (AlwaysShowSecondLevelNav) { SMItem parentSMItem = allSMItems.Find(s2 => s2.SMItemID == currentSMItem.SMItemParentID); if (parentSMItem != null && parentSMItem.SMItemParentID.HasValue) { rootItems.Insert(0, allSMItems.Find(s3 => s3.SMItemID == parentSMItem.SMItemParentID)); } } if (rootItems.Count == 0) { if (currentSMItem.SMItemParentID != null && !CurrentSectionShowOnlyCurrentPageAndBelow) { rootItems.AddRange(allSMItems.Where(s2 => currentSMItem.SMItemParentID == s2.SMItemID).OrderBy(s => s.Rank).ToList()); } else { rootItems.Add(currentSMItem); } } } } shouldRenderSubs = ID => { return(rootItems.Select(s => s.SMItemID).ToList().Contains(ID ?? 0) ? true : (ShowSubPagesOfCurrentPage && currentSMItem != null && currentSMItem.SMItemID == ID ? true : (AlwaysShowSecondLevelNav ? currentSMItem.SMItemParentID == ID : BreakoutCurrentPage))); }; } break; case MenuMode.FullSiteMap: { if (String.IsNullOrEmpty(RootFilenames)) // Add all zero level items to the root { if (AlwaysShowSecondLevelNav) { if (currentPage != null) { int mID; SMItem currentSMItem = null; if (!String.IsNullOrEmpty(Request.QueryString["mID"]) && Int32.TryParse(Request.QueryString["mID"], out mID)) { currentSMItem = allSMItems.Find(s1 => s1.SMItemID == mID); } if (currentSMItem == null) { currentSMItem = allSMItems.Find(s1 => s1.CMPageID == currentPage.CMPageID); } if (currentSMItem != null) { SMItem parentSMItem = allSMItems.Find(s2 => s2.SMItemID == currentSMItem.SMItemParentID); while (parentSMItem != null && allSMItems.Any(s3 => s3.SMItemID == parentSMItem.SMItemParentID)) { parentSMItem = allSMItems.Find(s3 => s3.SMItemID == parentSMItem.SMItemParentID); } rootItems.Insert(0, parentSMItem ?? currentSMItem); } } } else { rootItems.AddRange(allSMItems.Where(s => s.ShowInMenu && !s.SMItemParentID.HasValue).OrderBy(s => s.Rank).ToList()); } } shouldRenderSubs = renderSubId => { if (!BreakoutCurrentPage) { return(true); } return(currentPage == null ? false : getChildByParentIDs(allSMItems, renderSubId, new List <int>()).Contains(allSMItems.Where(s => s.ShowInMenu && s.CMPageID == currentPage.CMPageID).Select(s => s.SMItemID).FirstOrDefault()) || allSMItems.Where(s => s.ShowInMenu && s.CMPageID == currentPage.CMPageID).Select(s => s.SMItemID).FirstOrDefault() == renderSubId); }; } break; case MenuMode.TopLevelOnly: { if (String.IsNullOrEmpty(RootFilenames)) // Add all zero level items to the root { rootItems.AddRange(allSMItems.Where(s => s.ShowInMenu && !s.SMItemParentID.HasValue).OrderBy(s => s.Rank).ToList()); } shouldRenderSubs = renderSubId => { return(false); }; } break; } Controls.Add(new LiteralControl(renderMenu(rootItems, null))); }