public virtual ActionResult ChangeHeaderBackground(string themeName)
 {
     var theme = new Theme(Site, themeName);
     ViewBag.VirtualPath = ServiceFactory.HeaderBackgroundManager.GetVirutalPath(theme);
     ViewBag.ContainerSize = ServiceFactory.HeaderBackgroundManager.GetContainerSize(Site);
     return View();
 }
Exemple #2
0
        /// <summary>
        /// Parses the object.
        /// </summary>
        /// <param name="relativePaths">The relative paths. <example>{"site1","themes","default","style1.css"}</example></param>
        /// <returns>
        /// the remaining paths.<example>{"site1"}</example>
        /// </returns>
        public override IEnumerable<string> ParseObject(IEnumerable<string> relativePaths)
        {
            //call base return {"site1","themes","default"}
            relativePaths = base.ParseObject(relativePaths);

            this.Theme = new Theme();

            // return {"site1"}
            return this.Theme.ParseObject(relativePaths);
        }
Exemple #3
0
        public void TestPhysicalPath()
        {
            string themeName = "theme1";
            var site = new Site("Site1");
            var theme = new Theme(site, themeName);

            string expected1 = Path.Combine(site.PhysicalPath, "themes", themeName);

            Assert.AreEqual(expected1, theme.PhysicalPath, true);
        }
Exemple #4
0
        public IEnumerable<StyleFile> AllStylesEnumerable(Site site, string themeName)
        {
            var theme = new Theme(site, themeName);

            var fileNames = EnumerateCssFilesWithPath(site, themeName);

            fileNames = FileOrderHelper.OrderFiles(GetOrderFile(site, themeName), fileNames);

            return fileNames.Select(it => new StyleFile(theme, it).LastVersion());
        }
Exemple #5
0
        public void TestVirtualPath()
        {
            string themeName = "theme1";
            var site = new Site("Site1");
            var theme = new Theme(site, themeName);

            string expected1 = Kooboo.Web.Url.UrlUtility.Combine(site.VirtualPath, "themes", themeName);

            Assert.AreEqual(expected1, theme.VirtualPath, true);
        }
Exemple #6
0
        public void TestParseFromPhysicalPath()
        {
            string siteName = "site1";
            string themeName = "theme1";
            string physicalPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "sites", siteName, "themes", themeName);

            var theme = new Theme(physicalPath);

            Assert.AreEqual(themeName, theme.Name);
            
            Assert.IsTrue(theme.Site.IsDummy);
            Assert.AreEqual(siteName, theme.Site.Name);
        }
        public override ActionResult Index(string directoryPath)
        {
            ViewData["Title"] = "Themes".Localize();

            var themeName = ControllerContext.RequestContext.GetRequestValue("ThemeName");

            if (!string.IsNullOrEmpty(themeName))
            {
                var theme = new Theme(Site, themeName);
                ViewBag.Theme = theme;
            }

            return base.Index(directoryPath);
        }
Exemple #8
0
        public static IEnumerable<ThemeFile> Parse(Theme theme, out string themeRuleBody, string baseUri=null)
        {
            theme = theme.LastVersion();
            IEnumerable<ThemeFile> themeFiles = ServiceFactory.ThemeManager.AllStyles(theme);
            ThemeRuleFile cssHackFile = ServiceFactory.ThemeManager.GetCssHack(theme);
            if (cssHackFile == null || !cssHackFile.Exists())
            {
                themeRuleBody = "";
                return themeFiles;
            }

            var themeRuleFiles = Parser.Parse(cssHackFile.Read(), (fileVirtualPath) => UrlUtility.ToHttpAbsolute(baseUri, new ThemeFile(theme, fileVirtualPath).LastVersion().VirtualPath), out themeRuleBody);

            return themeFiles.Where(it => !themeRuleFiles.Any(cf => cf.EqualsOrNullEmpty(it.FileName, StringComparison.CurrentCultureIgnoreCase)));
        }
Exemple #9
0
 public IEnumerable<ThemeImageFile> AllImagesEnumerable(Theme theme)
 {
     List<ThemeImageFile> list = new List<ThemeImageFile>();
     theme = theme.LastVersion();
     if (theme.Exists())
     {
         ThemeImageFile dummy = new ThemeImageFile(theme, "dummy");
         var baseDir = dummy.BasePhysicalPath;
         if (Directory.Exists(baseDir))
         {
             foreach (var file in Directory.EnumerateFiles(baseDir))
             {
                 list.Add(new ThemeImageFile(theme, Path.GetFileName(file)));
             }
         }
     }
     return list;
 }
Exemple #10
0
 public virtual bool IsEanbled(Theme theme)
 {
     return false;
 }
Exemple #11
0
 public virtual string GetVirutalPath(Theme theme)
 {
     return "";
 }
Exemple #12
0
 public virtual void Change(Theme theme, string originalFile, int x, int y)
 {
 }
Exemple #13
0
 public StyleFile(Theme theme, string fileName)
     : base(theme, fileName)
 {
 }
Exemple #14
0
 public void Add(Theme item)
 {
     IOUtility.EnsureDirectoryExists(item.PhysicalPath);
 }
        /// <summary>
        /// The appointed theme file url of site
        /// </summary>
        /// <param name="frontUrlHelper">The front url helper</param>
        /// <param name="themeName">the theme</param>
        /// <param name="relativeUrl">The relative theme file path of site</param>
        /// <returns></returns>
        public static IHtmlString ThemeFileUrl(this FrontUrlHelper frontUrlHelper, string baseUri, string themeName, string relativeUrl)
        {
            var site = Site.Current;
            string resourceDomain = site.ResourceDomain;
            IHtmlString url = new HtmlString("");
            if (!string.IsNullOrEmpty(themeName))
            {
                var fileExists = false;
                var themeFileUrl = "";
                do
                {
                    site = site.AsActual();
                    Theme theme = new Theme(site, themeName).LastVersion();
                    themeFileUrl = Kooboo.Web.Url.UrlUtility.Combine(theme.VirtualPath, relativeUrl);
                    var physicalPath = HttpContext.Current.Server.MapPath(themeFileUrl);
                    fileExists = File.Exists(physicalPath);

                    site = theme.Site.Parent;
                } while (site != null && !fileExists);
                if (!string.IsNullOrEmpty(resourceDomain))
                {
                    baseUri = resourceDomain;
                }
                return new HtmlString(UrlUtility.ToHttpAbsolute(baseUri, themeFileUrl));
            }
            return frontUrlHelper.ThemeFileUrl(baseUri, relativeUrl);
        }
        /// <summary>
        /// The theme file url of site
        /// </summary>
        /// <param name="frontUrlHelper">The front url helper</param>
        /// <param name="site">The site</param>
        /// <param name="baseUri">Base uri</param>
        /// <param name="relativeThemeFilePath">The relative theme file path of site</param>
        /// <returns></returns>
        public static IHtmlString ThemeFileUrl(this FrontUrlHelper frontUrlHelper, Site site, string baseUri, string relativeThemeFilePath)
        {
            string resourceDomain = site.ResourceDomain;

            bool themeFileExists = false;
            string themeFileUrl = String.Empty;
            string themeFilePhysicalPath = String.Empty;

            do
            {
                site = site.AsActual();

                Theme theme = new Theme(site, site.Theme).LastVersion();
                themeFileUrl = UrlUtility.Combine(theme.VirtualPath, relativeThemeFilePath);
                themeFilePhysicalPath = HttpContext.Current.Server.MapPath(themeFileUrl);
                themeFileExists = File.Exists(themeFilePhysicalPath);

                site = theme.Site.Parent;
            } while (site != null && !themeFileExists);

            if (!String.IsNullOrEmpty(resourceDomain))
            {
                baseUri = resourceDomain; // CDN have high priority
            }
            return new HtmlString(UrlUtility.ToHttpAbsolute(baseUri, themeFileUrl));
        }
Exemple #17
0
 public void Update(Theme @new, Theme old)
 {
 }
Exemple #18
0
 public ThemeImageFile(Theme theme, string fileName)
     : base(theme, fileName)
 {
 }
Exemple #19
0
 private ThemeRuleFile GetCssHack(Site site, string themeName)
 {
     while (site != null)
     {
         var theme = new Theme(site, themeName);
         var themeRuleFile = new ThemeRuleFile(theme);
         if (themeRuleFile.Exists())
         {
             return themeRuleFile;
         }
         site = site.Parent;
     }
     return null;
 }
Exemple #20
0
 public virtual ThemeRuleFile GetCssHack(Theme theme)
 {
     return GetCssHack(theme.Site, theme.Name);
 }
Exemple #21
0
 public IQueryable<ThemeImageFile> AllImages(Theme theme)
 {
     return AllImagesEnumerable(theme).AsQueryable();
 }
Exemple #22
0
 public void Remove(Theme item)
 {
     System.IO.DirectoryInfo di = new DirectoryInfo(item.PhysicalPath);
     di.Delete(true);
 }
Exemple #23
0
 public Theme Get(Theme dummy)
 {
     throw new NotImplementedException();
 }
Exemple #24
0
        private IEnumerable<string> EnumerateCssFilesWithPath(Site site, string themeName)
        {
            List<string> results = new List<string>();

            while (site != null)
            {
                Theme theme = new Theme(site, themeName);
                var baseDir = theme.PhysicalPath;
                if (Directory.Exists(baseDir))
                {
                    var tempResults = EnumerateCssFiles(baseDir);
                    if (results.Count == 0)
                    {
                        results.AddRange(tempResults);
                    }
                    else
                    {
                        foreach (var item in tempResults)
                        {
                            if (!results.Any(it => Path.GetFileName(it).Equals(Path.GetFileName(item), StringComparison.InvariantCultureIgnoreCase)))
                            {
                                results.Add(item);
                            }
                        }
                    }
                }
                site = site.Parent;
            }
            return results;
        }
Exemple #25
0
 public ThemeFile(Theme theme, string fileName)
     : base(theme.Site, fileName)
 {
     this.Theme = theme;
 }
Exemple #26
0
 public virtual IEnumerable<StyleFile> AllStyles(Theme theme)
 {
     return AllStylesEnumerable(theme.Site, theme.Name).AsQueryable();
 }
Exemple #27
0
 public ThemeRuleFile(Theme theme)
     : base(theme, "Theme.rule")
 {
 }
Exemple #28
0
        /// <summary>
        /// the file URL under the theme of current site.
        /// </summary>
        /// <param name="relativeUrl">The relative URL.<example>images/logo.png</example></param>
        /// <returns></returns>
        public virtual IHtmlString ThemeFileUrl(string relativeUrl)
        {
            var site = this.Site;
            IHtmlString url = new HtmlString("");
            if (!string.IsNullOrEmpty(site.Name))
            {
                var fileExists = false;
                var themeFileUrl = "";
                do
                {
                    site = site.AsActual();

                    Theme theme = new Theme(site, site.Theme).LastVersion();
                    themeFileUrl = Kooboo.Web.Url.UrlUtility.Combine(theme.VirtualPath, relativeUrl);
                    var physicalPath = UrlUtility.MapPath(themeFileUrl);
                    fileExists = File.Exists(physicalPath);

                    site = theme.Site.Parent;
                } while (site != null && !fileExists);

                url = ResourceCDNUrl(themeFileUrl);
            }

            return url;
        }
 public virtual ActionResult SaveBackground(string themeName, string Url, int Width, int Height, int x, int y)
 {
     var theme = new Theme(Site, themeName);
     ServiceFactory.HeaderBackgroundManager.Change(theme, Url, x, y);
     var filePath = Server.MapPath(Url);
     if (System.IO.File.Exists(filePath))
     {
         System.IO.File.Delete(filePath);
     }
     return Json(true);
 }