示例#1
0
        public ActionResult GetSimple(HttpPostedFileBase file)
        {
            if ((file == null) || (file.ContentLength <= 0))
            {
                // TODO Display an error
            }
            else
            {
                try
                {
                    using (var DB = new XenonCMSContext())
                    {
                        using (var Zip = new ZipArchive(file.InputStream))
                        {
                            HandleGetSimpleBootstrap3SettingsXml(Zip, DB);
                            HandleGetSimpleNewsManagerPosts(Zip, DB);
                            HandleGetSimplePages(Zip, DB);
                            HandleGetSimpleWebsiteXml(Zip, DB);
                        }
                    }
                }
                catch (Exception ex)
                {
                    // TODO Archive is likely invalid?
                }
            }

            return View();
        }
示例#2
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");
        }
示例#3
0
        public static 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);
        }
示例#4
0
        //
        // GET: /Cms/
        public ActionResult Index(string url)
        {
            // Clean up the url parameter
            if (string.IsNullOrWhiteSpace(url))
            {
                url = "home";
            }
            else
            {
                url = url.ToLower().Trim('/');
                if (url.EndsWith("/index")) url = url.Substring(0, url.LastIndexOf("/"));
            }

            // Check if we cached the page
            SitePage Page = DatabaseCache.GetSitePage(ControllerContext.RequestContext.HttpContext, url);
            if (Page == null)
            {
                string RequestDomain = Globals.GetRequestDomain(ControllerContext.RequestContext.HttpContext);
                using (XenonCMSContext DB = new XenonCMSContext())
                {
                    Page = DB.SitePages.SingleOrDefault(x => (x.Slug == url) && (x.Site.Domain == RequestDomain));
                }
                DatabaseCache.AddSitePage(ControllerContext.RequestContext.HttpContext, Page);
            }

            // Ensure retrieved page is valid
            if (Page == null)
            {
                if (Globals.IsNewSite(ControllerContext.RequestContext.HttpContext))
                {
                    return RedirectToAction("Install", "Cms");
                }
                else
                {
                    return HttpNotFound();
                }
            }
            else
            {
                ViewBag.Layout = Page.Layout;
                ViewBag.Title = Page.Title;
                ViewBag.ShowTitleOnPage = Page.ShowTitleOnPage;
                ViewBag.Html = Page.Html;
                ViewBag.DateLastUpdated = Page.DateLastUpdated;
                return View();
            }
        }
示例#5
0
        private void HandleGetSimpleBootstrap3SettingsXml(ZipArchive zip, XenonCMSContext DB)
        {
            string RequestDomain = Globals.GetRequestDomain(ControllerContext.RequestContext.HttpContext);

            // Handle the Bootstrap3Settings.xml file
            var Bootstrap3SettingsXmlFile = GetSimpleGetXmlDocuments(zip, "other/Bootstrap3Settings.xml");
            foreach (var KVP in Bootstrap3SettingsXmlFile)
            {
                var Site = DB.Sites.Single(x => x.Domain == RequestDomain);
                Site.ContactEmail = KVP.Value.DocumentElement.SelectSingleNode("ContactEmail").InnerText;
                // TODO GetSimple has DisplayOtherThemes
                Site.NavBarInverted = (KVP.Value.DocumentElement.SelectSingleNode("InvertNavigationBar").InnerText == "true");
                Site.Theme = KVP.Value.DocumentElement.SelectSingleNode("SelectedTheme").InnerText;
                // TODO GetSimple has TrackingId
                DB.SaveChanges();
                DatabaseCache.ResetSite(ControllerContext.RequestContext.HttpContext);
            }
        }
示例#6
0
        private void HandleGetSimpleWebsiteXml(ZipArchive zip, XenonCMSContext DB)
        {
            string RequestDomain = Globals.GetRequestDomain(ControllerContext.RequestContext.HttpContext);

            // Handle the Bootstrap3Settings.xml file
            var Bootstrap3SettingsXmlFile = GetSimpleGetXmlDocuments(zip, "other/website.xml");
            foreach (var KVP in Bootstrap3SettingsXmlFile)
            {
                var Site = DB.Sites.Single(x => x.Domain == RequestDomain);
                Site.Title = HttpUtility.HtmlDecode(KVP.Value.DocumentElement.SelectSingleNode("SITENAME").InnerText);
                DB.SaveChanges();
                DatabaseCache.ResetSite(ControllerContext.RequestContext.HttpContext);
            }
        }
示例#7
0
        private void HandleGetSimplePages(ZipArchive zip, XenonCMSContext DB)
        {
            string RequestDomain = Globals.GetRequestDomain(ControllerContext.RequestContext.HttpContext);
            int SiteId = DB.Sites.Single(x => x.Domain == RequestDomain).Id;

            // Handle the pages files
            var PagesFiles = GetSimpleGetXmlDocuments(zip, "pages/");
            foreach (var KVP in PagesFiles)
            {
                // Get slug so we can skip built-in pages
                string Parent = KVP.Value.DocumentElement.SelectSingleNode("parent").InnerText;
                string Url = KVP.Value.DocumentElement.SelectSingleNode("url").InnerText;
                string Slug = string.IsNullOrWhiteSpace(Parent) ? Url : Parent + "/" + Url;
                if (Slug == "index") Slug = "home";
                if ((Slug == "blog") || (Slug == "contact") || (Slug == "news"))
                {
                    // TODO Skipping these built-ins
                }
                else
                {
                    // Update existing or add new page
                    // TODO GetSimple has a "meta" tag,
                    var SP = DB.SitePages.SingleOrDefault(x => (x.Site.Domain == RequestDomain) && (x.Slug == Slug)) ?? new SitePage();
                    SP.DateAdded = Convert.ToDateTime(KVP.Value.DocumentElement.SelectSingleNode("pubDate").InnerText);
                    SP.DateLastUpdated = Convert.ToDateTime(KVP.Value.DocumentElement.SelectSingleNode("pubDate").InnerText);
                    SP.DisplayOrder = Convert.ToInt32(KVP.Value.DocumentElement.SelectSingleNode("menuOrder").InnerText);
                    SP.Html = HttpUtility.HtmlDecode(KVP.Value.DocumentElement.SelectSingleNode("content").InnerText);
                    SP.Layout = "NormalNoSidebar"; // TODO there is a "template" tag
                    SP.ParentId = 0; // TODO there is a "parent" tag
                    SP.RequireAdmin = false; // TODO "private" tag
                    SP.RightAlign = false;
                    SP.ShowInMenu = (KVP.Value.DocumentElement.SelectSingleNode("menuStatus").InnerText == "Y");
                    SP.ShowTitleOnPage = true;
                    SP.SiteId = SiteId;
                    SP.Slug = Slug;
                    SP.Text = HttpUtility.HtmlDecode(KVP.Value.DocumentElement.SelectSingleNode("menu").InnerText); // TODO Rename text to something more intuitive
                    SP.Title = HttpUtility.HtmlDecode(KVP.Value.DocumentElement.SelectSingleNode("title").InnerText);
                    if (SP.Id <= 0) DB.SitePages.Add(SP);
                    DB.SaveChanges();
                    DatabaseCache.ResetNavMenuItems(ControllerContext.RequestContext.HttpContext);
                    DatabaseCache.RemoveSitePage(ControllerContext.RequestContext.HttpContext, Slug);
                }
            }
        }
示例#8
0
        private void HandleGetSimpleNewsManagerPosts(ZipArchive zip, XenonCMSContext DB)
        {
            string RequestDomain = Globals.GetRequestDomain(ControllerContext.RequestContext.HttpContext);
            int SiteId = DB.Sites.Single(x => x.Domain == RequestDomain).Id;

            // Handle the NewsManager posts files
            var PostsFiles = GetSimpleGetXmlDocuments(zip, "posts/");
            foreach (var KVP in PostsFiles)
            {
                // Update existing or add new post
                // TODO GetSimple has a "tags" tag
                string Slug = Path.GetFileNameWithoutExtension(KVP.Key);
                var SBP = DB.SiteBlogPosts.SingleOrDefault(x => (x.Site.Domain == RequestDomain) && (x.Slug == Slug)) ?? new SiteBlogPost();
                SBP.DateLastUpdated = Convert.ToDateTime(KVP.Value.DocumentElement.SelectSingleNode("date").InnerText);
                SBP.DatePosted = Convert.ToDateTime(KVP.Value.DocumentElement.SelectSingleNode("date").InnerText);
                SBP.FullPostText = HttpUtility.HtmlDecode(KVP.Value.DocumentElement.SelectSingleNode("content").InnerText);
                SBP.SiteId = SiteId;
                SBP.Slug = Slug;
                SBP.Title = HttpUtility.HtmlDecode(KVP.Value.DocumentElement.SelectSingleNode("title").InnerText);
                if (SBP.Id <= 0) DB.SiteBlogPosts.Add(SBP);
                DB.SaveChanges();
                DatabaseCache.ResetBlogIndex(ControllerContext.RequestContext.HttpContext);
            }
        }
示例#9
0
        public ActionResult Install(Install model)
        {
            if (Globals.IsNewSite(ControllerContext.RequestContext.HttpContext))
            {
                if (ModelState.IsValid)
                {
                    using (XenonCMSContext DB = new XenonCMSContext())
                    {
                        string RequestDomain = Globals.GetRequestDomain(ControllerContext.RequestContext.HttpContext);
                        Site Site = new Site();
                        Site.AdminIPs = new List<SiteAdminIP>();
                        Site.BlogPosts = new List<SiteBlogPost>();
                        Site.Pages = new List<SitePage>();

                        SiteAdminIP NewAdminIP = new SiteAdminIP();
                        NewAdminIP.Address = ControllerContext.RequestContext.HttpContext.Request.UserHostAddress;
                        Site.AdminIPs.Add(NewAdminIP);

                        SiteBlogPost NewBlogPost = new SiteBlogPost();
                        NewBlogPost.DateLastUpdated = DateTime.Now;
                        NewBlogPost.DatePosted = DateTime.Now;
                        NewBlogPost.FullPostText = "XenonCMS has been successfully installed and is ready for use on " + RequestDomain + "!";
                        NewBlogPost.Slug = "xenoncms-installed";
                        NewBlogPost.Title = "XenonCMS Installed";
                        Site.BlogPosts.Add(NewBlogPost);

                        Site.ContactEmail = "contact@" + RequestDomain;
                        Site.Domain = RequestDomain;
                        Site.NavBarInverted = false;

                        SitePage NewPageHome = new SitePage();
                        NewPageHome.DateAdded = DateTime.Now;
                        NewPageHome.DateLastUpdated = DateTime.Now;
                        NewPageHome.DisplayOrder = 1;
                        NewPageHome.Html = "XenonCMS has been successfully installed and is ready for use on " + RequestDomain + "!";
                        NewPageHome.Layout = "JumbotronNoSidebar";
                        NewPageHome.Text = "Home";
                        NewPageHome.Slug = "home";
                        NewPageHome.ParentId = 0;
                        NewPageHome.RequireAdmin = false;
                        NewPageHome.RightAlign = false;
                        NewPageHome.ShowInMenu = true;
                        NewPageHome.ShowTitleOnPage = true;
                        NewPageHome.Title = "XenonCMS Installed";
                        Site.Pages.Add(NewPageHome);

                        SitePage NewPageBlog = new SitePage();
                        NewPageBlog.DateAdded = DateTime.Now;
                        NewPageBlog.DateLastUpdated = DateTime.Now;
                        NewPageBlog.DisplayOrder = 2;
                        NewPageBlog.Html = "N/A";
                        NewPageBlog.Layout = "NormalSidebar";
                        NewPageBlog.Text = "Blog";
                        NewPageBlog.Slug = "blog";
                        NewPageBlog.ParentId = 0;
                        NewPageBlog.RequireAdmin = false;
                        NewPageBlog.RightAlign = false;
                        NewPageBlog.ShowInMenu = true;
                        NewPageBlog.ShowTitleOnPage = true;
                        NewPageBlog.Title = "Blog";
                        Site.Pages.Add(NewPageBlog);

                        SitePage NewPageContact = new SitePage();
                        NewPageContact.DateAdded = DateTime.Now;
                        NewPageContact.DateLastUpdated = DateTime.Now;
                        NewPageContact.DisplayOrder = 3;
                        NewPageContact.Html = "N/A";
                        NewPageContact.Layout = "NormalSidebar";
                        NewPageContact.Text = "Contact";
                        NewPageContact.Slug = "contact";
                        NewPageContact.ParentId = 0;
                        NewPageContact.RequireAdmin = false;
                        NewPageContact.RightAlign = false;
                        NewPageContact.ShowInMenu = true;
                        NewPageContact.ShowTitleOnPage = true;
                        NewPageContact.Title = "Contact";
                        Site.Pages.Add(NewPageContact);

                        Site.Sidebar = "<div class=\"panel panel-default\"><div class=\"panel-heading\"><h3 class=\"panel-title\">XenonCMS Installed</h3></div><div class=\"panel-body\">XenonCMS has been successfully installed and is ready for use on " + RequestDomain + "!</div></div>";
                        Site.Theme = "Cerulean";
                        Site.Title = RequestDomain;

                        DB.Sites.Add(Site);
                        DB.SaveChanges();

                        DatabaseCache.AddSite(ControllerContext.RequestContext.HttpContext, Site);
                        DatabaseCache.ResetAdminIPs(ControllerContext.RequestContext.HttpContext);
                        DatabaseCache.ResetBlogPosts(ControllerContext.RequestContext.HttpContext);
                        DatabaseCache.ResetNavMenuItems(ControllerContext.RequestContext.HttpContext);
                        DatabaseCache.ResetSidebars(ControllerContext.RequestContext.HttpContext);
                    }

                    return RedirectToAction("Index");
                }
                else
                {
                    return View(model);
                }
            }
            else
            {
                return RedirectToAction("Index");
            }
        }
示例#10
0
        private static 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;
        }
示例#11
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;
        }
示例#12
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;
        }
示例#13
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;
        }