コード例 #1
0
ファイル: CMSHelpers.cs プロジェクト: PowerserveIan/Meybohm
 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"]);
 }
コード例 #2
0
        public static CMMicrosite GetByID(int CMMicroSiteID, IEnumerable <string> includeList = null)
        {
            CMMicrosite obj = null;
            string      key = cacheKeyPrefix + CMMicroSiteID + GetCacheIncludeText(includeList);

            CMMicrosite tmpClass = null;

            if (Cache.IsEnabled)
            {
                if (Cache.IsEmptyCacheItem(key))
                {
                    return(null);
                }
                tmpClass = Cache[key] as CMMicrosite;
            }

            if (tmpClass != null)
            {
                obj = tmpClass;
            }
            else
            {
                using (Entities entity = new Entities())
                {
                    IQueryable <CMMicrosite> itemQuery = AddIncludes(entity.CMMicrosite, includeList);
                    obj = itemQuery.FirstOrDefault(n => n.CMMicroSiteID == CMMicroSiteID);
                }
                Cache.Store(key, obj);
            }

            return(obj);
        }
コード例 #3
0
 public CMMicrosite(CMMicrosite objectToCopy)
 {
     Active        = objectToCopy.Active;
     CMMicroSiteID = objectToCopy.CMMicroSiteID;
     Description   = objectToCopy.Description;
     Image         = objectToCopy.Image;
     Location      = objectToCopy.Location;
     Name          = objectToCopy.Name;
     Phone         = objectToCopy.Phone;
     Published     = objectToCopy.Published;
 }
コード例 #4
0
ファイル: CMSHelpers.cs プロジェクト: PowerserveIan/Meybohm
        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);
        }
コード例 #5
0
ファイル: CMSHelpers.cs プロジェクト: PowerserveIan/Meybohm
 public static void SetCurrentRequestCMSMicrosite(CMMicrosite micrositeEntity, HttpContext requestContext = null)
 {
     if (requestContext == null)
     {
         requestContext = HttpContext.Current;
     }
     if (requestContext == null)
     {
         return;
     }
     requestContext.Items["CMSMicrosite"] = micrositeEntity;
 }
コード例 #6
0
ファイル: CMSHelpers.cs プロジェクト: PowerserveIan/Meybohm
        public static int?GetCMMicrositeID(string inFilename, out string filename)
        {
            if (Cache[inFilename + "_outfilename"] != null)
            {
                filename = (string)Cache[inFilename + "_outfilename"];
                if (Cache[inFilename + "_micrositeID"] == null)
                {
                    return(null);
                }
                return(Convert.ToInt32(Cache[inFilename + "_micrositeID"]));
            }
            int?micrositeID = null;

            filename = inFilename;
            if (inFilename.Contains("/"))
            {
                List <CMMicrosite> microsites = CMMicrosite.CMMicrositeGetByName(inFilename.Split('/')[0].Replace("-", " "));
                if (microsites.Count == 1)
                {
                    micrositeID = microsites[0].CMMicroSiteID;
                }
                filename = inFilename.Split('/')[1];
            }
            else
            {
                if (Settings.EnableMicrosites && !GetCachedCMPages().Any(c => c.FileName.Equals(inFilename, StringComparison.OrdinalIgnoreCase) && (c.CMMicrositeID == null || c.CMMicrositeID == -1)))
                {
                    CMMicrosite micrositeEntity = CMMicrosite.CMMicrositeGetByName(inFilename.Replace("-", " ")).FirstOrDefault();
                    if (micrositeEntity != null)
                    {
                        micrositeID = micrositeEntity.CMMicroSiteID;
                        filename    = "Home.aspx";
                    }
                }
            }
            if (micrositeID.HasValue && String.IsNullOrEmpty(filename))
            {
                filename = "Home.aspx";
            }
            Cache[inFilename + "_outfilename"] = filename;
            if (micrositeID != null)
            {
                Cache[inFilename + "_micrositeID"] = micrositeID;
            }
            return(micrositeID);
        }
コード例 #7
0
ファイル: CMSHelpers.cs プロジェクト: PowerserveIan/Meybohm
        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);
        }
コード例 #8
0
ファイル: CMSHelpers.cs プロジェクト: PowerserveIan/Meybohm
 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"]);
 }
コード例 #9
0
ファイル: _BreadCrumbs.cs プロジェクト: PowerserveIan/Meybohm
        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);
        }
コード例 #10
0
ファイル: _Menu.cs プロジェクト: PowerserveIan/Meybohm
        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)));
        }
コード例 #11
0
ファイル: CMSHelpers.cs プロジェクト: PowerserveIan/Meybohm
        public static void SendSiteMapApprovalEmailAlerts(int userID, int?micrositeID, int?languageID, bool isAdmin, bool?approval)
        {
            if (Settings.EnableApprovals && Settings.SendApprovalEmails)
            {
                MailMessage email  = new MailMessage();
                SmtpClient  client = new SmtpClient();
                if (!approval.HasValue)
                {
                    string key = "ContentManager_SiteMapApprovalEmails_" + userID + "_" + micrositeID + "_" + languageID;
                    if (!Settings.EnableCaching || HttpContext.Current == null || HttpContext.Current.Cache == null || HttpContext.Current.Cache[key] == null)
                    {
                        User     userEntity     = User.GetByID(userID);
                        Language languageEntity = null;
                        if (languageID.HasValue)
                        {
                            languageEntity = Language.GetByID(languageID.Value);
                        }
                        //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 : "") + (micrositeID.HasValue ? micrositeID == -1 ? " Microsite Default" : " " + CMMicrosite.GetByID(micrositeID.Value).Name : "") + " <a href=\"" + Helpers.RootPath + "admin/content-manager/sitemap.aspx" + (micrositeID.HasValue ? "?micrositeid=" + micrositeID.Value : "") + (languageEntity != null ? (micrositeID.HasValue ? "&" : "?") + "language=" + languageEntity.CultureName : "") + "\">Sitemap</a>";
                            email.Subject    = Globals.Settings.SiteTitle + " - Sitemap Approval Required";

                            client.Send(email);
                        }

                        //Send Editor Email
                        email      = new MailMessage();
                        email.From = new MailAddress(Globals.Settings.FromEmail);

                        List <SMItemUser> allEditors;
                        if (micrositeID.HasValue && micrositeID > 0)
                        {
                            allEditors = SMItemUser.SMItemUserGetByCMMicrositeID(micrositeID);
                        }
                        else if (micrositeID.HasValue && micrositeID == -1)
                        {
                            allEditors = SMItemUser.SMItemUserGetByMicrositeDefault(true);
                        }
                        else
                        {
                            allEditors = SMItemUser.GetAll().Where(s => s.CMMicrositeID == null && !s.MicrositeDefault).ToList();
                        }

                        if (languageID.HasValue)
                        {
                            allEditors = allEditors.Where(s => s.LanguageID == languageID.Value).ToList();
                        }

                        foreach (SMItemUser id in allEditors)
                        {
                            if (id.UserID != userID)
                            {
                                User editor = User.GetByID(id.UserID);
                                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 : "") + (micrositeID.HasValue ? micrositeID == -1 ? " Microsite Default" : " " + CMMicrosite.GetByID(micrositeID.Value).Name : "") + " <a href=\"" + Helpers.RootPath + "admin/content-manager/sitemap.aspx" + (micrositeID.HasValue ? "?micrositeid=" + micrositeID.Value : "") + (languageEntity != null ? (micrositeID.HasValue ? "&" : "?") + "language=" + languageEntity.CultureName : "") + "\">Sitemap</a>, which you have also edited.  The Sitemap is still awaiting approval from an Admin.";
                            email.Subject    = Globals.Settings.SiteTitle + " - Sitemap Edited";

                            client = new SmtpClient();
                            client.Send(email);
                        }
                        //Only send email alerts every 10 minutes per user that changes sitemap
                        if (Settings.EnableCaching && HttpContext.Current != null && HttpContext.Current.Cache != null)
                        {
                            HttpContext.Current.Cache.Insert(key, true, null, DateTime.Now.AddMinutes(10), TimeSpan.Zero);
                        }
                    }
                }
                else                 //Approve/Denied
                {
                    //Send Editors Email
                    email      = new MailMessage();
                    email.From = new MailAddress(Globals.Settings.FromEmail);

                    List <SMItemUser> allEditors;
                    if (micrositeID.HasValue && micrositeID > 0)
                    {
                        allEditors = SMItemUser.SMItemUserGetByCMMicrositeID(micrositeID);
                    }
                    else if (micrositeID.HasValue && micrositeID == -1)
                    {
                        allEditors = SMItemUser.SMItemUserGetByMicrositeDefault(true);
                    }
                    else
                    {
                        allEditors = SMItemUser.GetAll().Where(s => s.CMMicrositeID == null && !s.MicrositeDefault).ToList();
                    }

                    if (languageID.HasValue)
                    {
                        allEditors = allEditors.Where(s => s.LanguageID == languageID.Value).ToList();
                    }

                    foreach (SMItemUser id in allEditors)
                    {
                        if (id.UserID != userID)
                        {
                            User editor = User.GetByID(id.UserID);
                            email.To.Add(new MailAddress(editor.Email, editor.Name));
                        }
                    }

                    SMItemUser.DeleteAll(micrositeID, languageID);

                    if (email.To.Count > 0)
                    {
                        Language languageEntity = null;
                        if (languageID.HasValue)
                        {
                            languageEntity = Language.GetByID(languageID.Value);
                        }

                        email.IsBodyHtml = true;
                        email.Body       = "An Admin has " + (approval.Value ? "approved" : "denied") + " the changes to the" + (languageEntity != null ? " " + languageEntity.Culture : "") + (micrositeID.HasValue ? micrositeID == -1 ? " Microsite Default" : " " + CMMicrosite.GetByID(micrositeID.Value).Name : "") + " <a href=\"" + Helpers.RootPath + "admin/content-manager/sitemap.aspx" + (micrositeID.HasValue ? "?micrositeid=" + micrositeID.Value : "") + (languageEntity != null ? (micrositeID.HasValue ? "&" : "?") + "language=" + languageEntity.CultureName : "") + "\">Sitemap</a> that you made.";
                        email.Subject    = Globals.Settings.SiteTitle + " - Sitemap " + (approval.Value ? "Approved" : "Denied");

                        client = new SmtpClient();
                        client.Send(email);
                    }
                }
            }
        }
コード例 #12
0
ファイル: CMSHelpers.cs プロジェクト: PowerserveIan/Meybohm
        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);
                    }
                }
            }
        }