예제 #1
0
        public static string NavBarStyle(HttpContextBase httpContext)
        {
            Site Site = DatabaseCache.GetSite(httpContext);

            if (Site == null)
            {
                string RequestDomain = Globals.GetRequestDomain(httpContext);

                using (XenonCMSContext DB = new XenonCMSContext())
                {
                    // Get site title
                    Site = DB.Sites.SingleOrDefault(x => x.Domain == RequestDomain);
                }

                if (Site == null)
                {
                    return("default");
                }
                else
                {
                    DatabaseCache.AddSite(httpContext, Site);
                }
            }

            return(Site.NavBarInverted ? "inverse" : "default");
        }
예제 #2
0
        public static string Theme(HttpContextBase httpContext)
        {
            Site Site = DatabaseCache.GetSite(httpContext);

            if (Site == null)
            {
                string RequestDomain = Globals.GetRequestDomain(httpContext);

                using (XenonCMSContext DB = new XenonCMSContext())
                {
                    // Get site title
                    Site = DB.Sites.SingleOrDefault(x => x.Domain == RequestDomain);
                }

                if (Site == null)
                {
                    return("Cerulean");
                }
                else
                {
                    DatabaseCache.AddSite(httpContext, Site);
                }
            }

            return(Site.Theme);
        }
예제 #3
0
        public static string Sidebar(HttpContextBase httpContext)
        {
            string Result = DatabaseCache.GetSidebars(httpContext);

            if (Result == null)
            {
                string RequestDomain = Globals.GetRequestDomain(httpContext);

                using (XenonCMSContext DB = new XenonCMSContext())
                {
                    // Get site side bar
                    var Site = DB.Sites.SingleOrDefault(x => x.Domain == RequestDomain);
                    if (Site != null)
                    {
                        Result += Site.Sidebar;
                    }

                    // Get global side bar(s)
                    var GlobalSidebars = DB.SiteGlobalSidebars.Where(x => x.Site.Domain == RequestDomain).OrderBy(x => x.GlobalSidebar.DisplayOrder);
                    foreach (var Sidebar in GlobalSidebars)
                    {
                        Result += Sidebar.GlobalSidebar.Html;
                    }
                }

                if (Result == null)
                {
                    Result = "";
                }
                DatabaseCache.AddSidebars(httpContext, Result);
            }

            return(Result);
        }
예제 #4
0
        static private List <string> GetAdminIPs(HttpContextBase httpContext, bool globalOnly)
        {
            List <string> Result = DatabaseCache.GetAdminIPs(httpContext, globalOnly);

            if (Result == null)
            {
                Result = new List <string>();
                string RequestDomain = Globals.GetRequestDomain(httpContext);

                try
                {
                    using (XenonCMSContext DB = new XenonCMSContext())
                    {
                        // Global admin ips
                        foreach (var Row in DB.GlobalAdminIPs)
                        {
                            Result.Add(Row.Address);
                        }

                        if (!globalOnly)
                        {
                            // Site admin ips
                            foreach (var Row in DB.SiteAdminIPs.Where(x => x.Site.Domain == RequestDomain))
                            {
                                Result.Add(Row.Address);
                            }
                        }
                    }

                    // Cache what we have so far, so if the dns lookup is necessary, and takes awhile, we won't have multiple requests doing it
                    DatabaseCache.AddAdminIPs(httpContext, Result, globalOnly);

                    // Lookup any hostnames and convert to ip address
                    for (int i = 0; i < Result.Count; i++)
                    {
                        if (!Regex.IsMatch(Result[i], @"\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}", RegexOptions.Compiled))
                        {
                            // Not in the format of an IP, so convert hostname to IP
                            try
                            {
                                Result[i] = Dns.GetHostAddresses(Result[i])[0].ToString();
                            }
                            catch (Exception)
                            {
                                // Lookup failed, just ignore
                            }
                        }
                    }

                    // Re-cache, now that we have dns lookups completed
                    DatabaseCache.AddAdminIPs(httpContext, Result, globalOnly);
                }
                catch (Exception)
                {
                    // Something failed, just ignore
                }
            }

            return(Result);
        }
예제 #5
0
        static public bool IsNewSite(HttpContextBase httpContext)
        {
            Site Site = DatabaseCache.GetSite(httpContext);

            if (Site == null)
            {
                string RequestDomain = GetRequestDomain(httpContext);
                using (XenonCMSContext DB = new XenonCMSContext())
                {
                    Site = DB.Sites.SingleOrDefault(x => x.Domain == RequestDomain);
                }
                DatabaseCache.AddSite(httpContext, Site);
            }

            return(Site == null);
        }
예제 #6
0
        private static List <NavMenuItem> GetNavMenuItems(HttpContextBase httpContext, bool isAdmin, bool rightAlign)
        {
            List <NavMenuItem> Result = DatabaseCache.GetNavMenuItems(httpContext, isAdmin, rightAlign);

            if (Result == null)
            {
                Result = new List <NavMenuItem>();
                string RequestDomain = Globals.GetRequestDomain(httpContext);

                using (XenonCMSContext DB = new XenonCMSContext())
                {
                    // Get nav menu
                    var NavMenuItems = DB.SitePages.Where(x => (x.Site.Domain == RequestDomain) && x.ShowInMenu && (x.ParentId == 0) && (isAdmin || !x.RequireAdmin) && (x.RightAlign == rightAlign)).OrderBy(x => x.DisplayOrder).ThenBy(x => x.Text).ToArray();
                    foreach (var NMI in NavMenuItems)
                    {
                        // Build the menu item
                        NavMenuItem NewMenuItem = new NavMenuItem(NMI.Text, NMI.Slug);

                        // Determine if we have children
                        var Children = DB.SitePages.Where(x => x.ShowInMenu && (x.ParentId == NMI.Id) && (isAdmin || !x.RequireAdmin) && (x.RightAlign == rightAlign)).OrderBy(x => x.DisplayOrder).ThenBy(x => x.Text);
                        if (Children.Count() > 0)
                        {
                            NewMenuItem.Children = new List <NavMenuItem>();
                            foreach (var C in Children)
                            {
                                NewMenuItem.Children.Add(new NavMenuItem(C.Text, C.Slug));
                            }
                        }

                        Result.Add(NewMenuItem);
                    }
                }

                DatabaseCache.AddNavMenuItems(httpContext, Result, isAdmin, rightAlign);
            }

            return(Result);
        }
예제 #7
0
        internal static List <ViewModels.Blog.Index> GetBlogIndex(XenonCMSContext db, HttpContextBase httpContext)
        {
            // Pull from cache
            string RequestDomain = Globals.GetRequestDomain(httpContext);
            string CacheKey      = _BlogIndexKey + RequestDomain;
            var    Result        = (List <ViewModels.Blog.Index>)httpContext.Cache[CacheKey];

            if (Result == null)
            {
                // Pull from database
                var BlogPosts = db.SiteBlogPosts.Where(x => x.Site.Domain == RequestDomain).OrderByDescending(x => x.DatePosted).ToArray();
                if (BlogPosts != null)
                {
                    // Database model to view model
                    Result = ModelConverter.Convert <ViewModels.Blog.Index>(BlogPosts);

                    // Add to cache
                    DatabaseCache.AddBlogIndex(Result, httpContext);
                }
            }

            return(Result);
        }
예제 #8
0
        internal static ViewModels.Blog.Details GetBlogDetails(int id, XenonCMSContext db, HttpContextBase httpContext)
        {
            // Pull from cache
            string RequestDomain = Globals.GetRequestDomain(httpContext);
            string CacheKey      = _BlogDetailsKey + RequestDomain + "-" + id.ToString();
            var    Result        = (ViewModels.Blog.Details)httpContext.Cache[CacheKey];

            if (Result == null)
            {
                // Pull from database
                var BlogPost = db.SiteBlogPosts.SingleOrDefault(x => (x.Id == id) && (x.Site.Domain == RequestDomain));
                if (BlogPost != null)
                {
                    // Database model to view model
                    Result = ModelConverter.Convert <ViewModels.Blog.Details>(BlogPost);

                    // Add to cache
                    DatabaseCache.AddBlogDetails(Result, httpContext);
                }
            }

            return(Result);
        }