public static CMPage GetByCMPageIDAndLanguageID(int cmPageId, int languageId) { CMPage obj; string key = cacheKeyPrefix + "GetByCMPageIDAndLanguageID_" + cmPageId + "_" + languageId; CMPage tmpClass = null; if (Cache.IsEnabled) { tmpClass = Cache[key] as CMPage; } if (tmpClass != null) { obj = tmpClass; } else { using (Entities entity = new Entities()) { obj = entity.CMPage.Include("CMPageTitle").FirstOrDefault(p => p.CMPageID == cmPageId && p.CMPageTitle.Any(t => t.LanguageID == languageId)); } } return(obj); }
/// <summary> /// Takes in the ID of the current CMPage and returns whether or not /// the currently logged in user may access that page (determined by entries in CMPageRole /// </summary> /// <param name="cmPageID"></param> /// <returns></returns> public static bool CanUserAccessPage(int cmPageID) { bool authorized = true; if (HasFullCMSPermission()) { return(true); } CMPageRole.Filters filterList = new CMPageRole.Filters(); filterList.FilterCMPageRoleCMPageID = cmPageID.ToString(); filterList.FilterCMPageRoleEditor = false.ToString(); List <CMPageRole> pageRoles = CMPageRole.CMPageRolePage(0, 0, "", "", true, filterList); CMPage thePage = CMPage.GetByID(cmPageID); if (thePage.NeedsApproval && pageRoles.Count == 0) { return(false); } if (pageRoles.Count > 0) { authorized = false; if (HttpContext.Current.User.Identity.IsAuthenticated) { List <UserRole> userRoles = UserRole.UserRoleGetByUserID(Helpers.GetCurrentUserID()); if (pageRoles.Any(pageRole => userRoles.Exists(r => r.RoleID == pageRole.RoleID && (!thePage.NeedsApproval || (thePage.NeedsApproval && pageRole.Editor))))) { authorized = true; } } } return(authorized); }
public static CMPage GetByID(int CMPageID, IEnumerable <string> includeList = null) { CMPage obj = null; string key = cacheKeyPrefix + CMPageID + GetCacheIncludeText(includeList); CMPage tmpClass = null; if (Cache.IsEnabled) { if (Cache.IsEmptyCacheItem(key)) { return(null); } tmpClass = Cache[key] as CMPage; } if (tmpClass != null) { obj = tmpClass; } else { using (Entities entity = new Entities()) { IQueryable <CMPage> itemQuery = AddIncludes(entity.CMPage, includeList); obj = itemQuery.FirstOrDefault(n => n.CMPageID == CMPageID); } Cache.Store(key, obj); } return(obj); }
public static string GetCurrentRequestCMSPagePathWithMicrosite(HttpContext requestContext = null) { CMMicrosite microsite = GetCurrentRequestCMSMicrosite(requestContext); CMPage cmPage = GetCurrentRequestCMSPage(requestContext); if (cmPage == null) { return(string.Empty); } return((microsite != null ? microsite.Name.ToLower().Replace(" ", "-") + "/" : string.Empty) + cmPage.FileName); }
public static void SetCurrentRequestCMSPage(CMPage cmsPage, HttpContext requestContext = null) { if (requestContext == null) { requestContext = HttpContext.Current; } if (requestContext == null) { return; } requestContext.Items["CMSPage"] = cmsPage; }
public static List <CMPage> GetCachedCMPages() { int languageID = Helpers.GetCurrentLanguage().LanguageID; string cacheKeyCMPages = "ContentManager_CMPage_AllCMPages_" + languageID; List <CMPage> allCMPages = Cache[cacheKeyCMPages] as List <CMPage>; if (allCMPages == null) { allCMPages = Settings.EnableMultipleLanguages ? CMPage.CMPagesGetAllWithCMPageTitle(languageID) : CMPage.GetAll(); Cache.Store(cacheKeyCMPages, allCMPages); } return(allCMPages); }
public static List <CMPage> CMPageGetByCMTemplateIDAndLanguageID(int?templateId, int?languageID) { List <CMPage> objects; string key = cacheKeyPrefix + "GetByCMTemplateIDAndLanguageID" + (templateId.HasValue ? "_" + templateId.Value : "") + (languageID.HasValue ? "_" + languageID.Value : ""); List <CMPage> tmpList = null; if (Cache.IsEnabled) { tmpList = Cache[key] as List <CMPage>; } if (tmpList != null) { objects = tmpList; } else { objects = new List <CMPage>(); using (Entities entity = new Entities()) { var query = from page in entity.CMPage where page.CMTemplateID == templateId select new { CMSPage = page, CMSTitle = (from title in page.CMPageTitle where title.LanguageID == languageID select title.Title).FirstOrDefault() }; foreach (var page in query) { CMPage pageEntity = page.CMSPage; if (pageEntity.OriginalCMPageID.HasValue && String.IsNullOrEmpty(page.CMSTitle)) { pageEntity.CMPageTitleTitle = query.FirstOrDefault(p => p.CMSPage.CMPageID == pageEntity.OriginalCMPageID.Value).CMSTitle; } else { pageEntity.CMPageTitleTitle = page.CMSTitle; } objects.Add(pageEntity); } } Cache.Store(key, objects); } return(objects); }
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 bool CanUserManagePage() { CMPage currentPage = GetCurrentRequestCMSPage(); CMMicrosite micrositeEntity = GetCurrentRequestCMSMicrosite(); bool canManage = (HttpContext.Current.User.IsInRole("Microsite Admin") && (micrositeEntity != null && CMMicrositeUser.CMMicrositeUserGetByCMMicrositeID(micrositeEntity.CMMicroSiteID).Exists(m => m.UserID == Helpers.GetCurrentUserID()))); if (HttpContext.Current.User.IsInRole("CMS Page Manager") && !canManage) { if (currentPage != null) { List <CMPageRole> pageRoles = CMPageRole.CMPageRolePage(0, 0, "", "", true, new CMPageRole.Filters { FilterCMPageRoleCMPageID = currentPage.CMPageID.ToString(), FilterCMPageRoleEditor = true.ToString() }); if (pageRoles.Any(role => HttpContext.Current.User.IsInRole(Role.GetByID(role.RoleID).Name))) { canManage = true; } } } return(canManage); }
public CMPage(CMPage objectToCopy) { CanDelete = objectToCopy.CanDelete; CMMicrositeID = objectToCopy.CMMicrositeID; CMPageID = objectToCopy.CMPageID; CMTemplateID = objectToCopy.CMTemplateID; Created = objectToCopy.Created; Deleted = objectToCopy.Deleted; DynamicCollectionID = objectToCopy.DynamicCollectionID; EditorDeleted = objectToCopy.EditorDeleted; EditorUserIDs = objectToCopy.EditorUserIDs; FeaturedPage = objectToCopy.FeaturedPage; FileName = objectToCopy.FileName; FormRecipient = objectToCopy.FormRecipient; MicrositeDefault = objectToCopy.MicrositeDefault; NeedsApproval = objectToCopy.NeedsApproval; OriginalCMPageID = objectToCopy.OriginalCMPageID; ResponsePageID = objectToCopy.ResponsePageID; Title = objectToCopy.Title; UserID = objectToCopy.UserID; }
public static List <CMPage> CMPagesGetAllWithCMPageTitle(int languageID) { List <CMPage> objects; string key = cacheKeyPrefix + "GetAllWithTitleByLanguageID" + languageID; List <CMPage> tmpList = null; if (Cache.IsEnabled) { tmpList = Cache[key] as List <CMPage>; } if (tmpList != null) { objects = tmpList; } else { objects = new List <CMPage>(); using (Entities entity = new Entities()) { var query = from page in entity.CMPage select new { CMSPage = page, CMSTitle = (from title in page.CMPageTitle where title.LanguageID == languageID select title.Title).FirstOrDefault() }; foreach (var page in query) { CMPage pageEntity = page.CMSPage; pageEntity.CMPageTitleTitle = page.CMSTitle; objects.Add(pageEntity); } } Cache.Store(key, objects); } return(objects); }
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"]); }
/// <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))); }
public static void SendApprovalEmailAlerts(CMPage editedPage, CMPageRegion region, int userID, bool content, bool isAdmin) { SendApprovalEmailAlerts(editedPage, region, userID, content, isAdmin, null, null); }
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); }
public static void SendApprovalEmailAlerts(CMPage editedPage, CMPageRegion region, int userID, bool content, bool isAdmin, bool?approval, int?languageID) { if (Settings.EnableApprovals && Settings.SendApprovalEmails) { MailMessage email = new MailMessage(); SmtpClient client = new SmtpClient(); CMPage originalPage = editedPage.OriginalCMPageID.HasValue ? CMPage.GetByID(editedPage.OriginalCMPageID.Value) : null; string pageName = string.Empty; if (languageID.HasValue) { CMPageTitle titleEntity = null; //If Denied, take the original page title if (originalPage != null && approval.HasValue && !approval.Value) { titleEntity = CMPageTitle.CMPageTitleGetByCMPageIDAndLanguageID(originalPage.CMPageID, languageID.Value).FirstOrDefault(); } //If not approve/deny, take the current displayed unapproved page title if (titleEntity == null) { titleEntity = CMPageTitle.CMPageTitleGetByCMPageIDAndLanguageID(editedPage.CMPageID, languageID.Value).FirstOrDefault(); } if (titleEntity != null) { pageName = titleEntity.Title; } } if (String.IsNullOrEmpty(pageName)) { if (originalPage != null && approval.HasValue && !approval.Value) { pageName = originalPage.Title; } else { pageName = editedPage.Title; } } Language languageEntity = null; if (languageID.HasValue) { languageEntity = Language.GetByID(languageID.Value); } if (!approval.HasValue) { User userEntity = User.GetByID(userID); //Don't send Admin Email if Admin is the one who edited if (!isAdmin) { //Send Admin Email email.From = new MailAddress(Globals.Settings.FromEmail); if (!String.IsNullOrEmpty(Settings.ApprovalAdminEmailAddresses)) { foreach (string s in Settings.ApprovalAdminEmailAddresses.Split(';')) { email.To.Add(new MailAddress(s)); } } else //Send to all Admins { foreach (UserRole admin in UserRole.UserRoleGetWithUserByRoleName("Admin")) { email.To.Add(new MailAddress(admin.User.Email, admin.User.Name)); } } email.IsBodyHtml = true; email.Body = userEntity.Name + " has updated the " + (languageEntity != null ? languageEntity.Culture + " " : "") + (content ? "content" : "properties") + " of <a href=\"" + Helpers.RootPath + (content ? (editedPage.CMMicrositeID.HasValue ? CMMicrosite.GetByID(editedPage.CMMicrositeID.Value).Name + "/" : "") + editedPage.FileName + (languageEntity != null ? "?language=" + languageEntity.CultureName : "") : "admin/content-manager/content-manager-page.aspx?id=" + editedPage.CMPageID + (languageEntity != null ? "&language=" + languageEntity.CultureName : "")) + "\">" + pageName + "</a>"; email.Subject = Globals.Settings.SiteTitle + " - " + (content ? "Content" : "Page Properties") + " Approval Required"; client.Send(email); } //Send Editor Email email = new MailMessage(); email.From = new MailAddress(Globals.Settings.FromEmail); if (content && region != null && !String.IsNullOrEmpty(region.EditorUserIDs)) { foreach (string id in region.EditorUserIDs.Split(',')) { if (!id.Equals(userID.ToString())) { User editor = User.GetByID(Convert.ToInt32(id)); email.To.Add(new MailAddress(editor.Email, editor.Name)); } } } else if (!String.IsNullOrEmpty(editedPage.EditorUserIDs)) { foreach (string id in editedPage.EditorUserIDs.Split(',')) { if (!id.Equals(userID.ToString())) { User editor = User.GetByID(Convert.ToInt32(id)); email.To.Add(new MailAddress(editor.Email, editor.Name)); } } } if (email.To.Count > 0) { email.IsBodyHtml = true; email.Body = userEntity.Name + " has updated the " + (languageEntity != null ? languageEntity.Culture + " " : "") + (content ? "content" : "properties") + " of <a href=\"" + Helpers.RootPath + (content ? (editedPage.CMMicrositeID.HasValue ? CMMicrosite.GetByID(editedPage.CMMicrositeID.Value).Name + "/" : "") + editedPage.FileName + (languageEntity != null ? "?language=" + languageEntity.CultureName : "") : "admin/content-manager/content-manager-page.aspx?id=" + editedPage.CMPageID + (languageEntity != null ? "&language=" + languageEntity.CultureName : "")) + "\">" + pageName + "</a>, which you have also edited. The page is still awaiting approval from an Admin."; email.Subject = Globals.Settings.SiteTitle + " - " + (content ? "Content" : "Page Properties") + " Edited"; client = new SmtpClient(); client.Send(email); } } else //Approve/Denied { //Send Editors Email email = new MailMessage(); email.From = new MailAddress(Globals.Settings.FromEmail); if (content && region != null && !String.IsNullOrEmpty(region.EditorUserIDs)) { foreach (string id in region.EditorUserIDs.Split(',')) { if (!id.Equals(userID.ToString())) { User editor = User.GetByID(Convert.ToInt32(id)); email.To.Add(new MailAddress(editor.Email, editor.Name)); } } } else if (!String.IsNullOrEmpty(editedPage.EditorUserIDs)) { foreach (string id in editedPage.EditorUserIDs.Split(',')) { if (!id.Equals(userID.ToString())) { User editor = User.GetByID(Convert.ToInt32(id)); email.To.Add(new MailAddress(editor.Email, editor.Name)); } } } if (email.To.Count > 0) { email.IsBodyHtml = true; email.Body = "An Admin has " + (approval.Value ? "approved" : "denied") + " the " + (languageEntity != null ? languageEntity.Culture + " " : "") + (content ? "content" : "properties") + " changes to <a href=\"" + Helpers.RootPath + (content ? (editedPage.CMMicrositeID.HasValue ? CMMicrosite.GetByID(editedPage.CMMicrositeID.Value).Name + "/" : "") + editedPage.FileName + (languageEntity != null ? "?language=" + languageEntity.CultureName : "") : "admin/content-manager/content-manager-page.aspx?id=" + editedPage.CMPageID + (languageEntity != null ? "&language=" + languageEntity.CultureName : "")) + "\">" + pageName + "</a> that you made."; email.Subject = Globals.Settings.SiteTitle + " - " + (content ? "Content" : "Page Properties") + " " + (approval.Value ? "Approved" : "Denied"); client = new SmtpClient(); client.Send(email); } } } }