コード例 #1
0
            public static List <ThemeFont> GetFonts(int PortalID, string CategoryGuid)
            {
                List <ThemeFont> Fonts = new List <ThemeFont>();

                if (!string.IsNullOrEmpty(CategoryGuid))
                {
                    if (CategoryGuid.ToLower() == "all")
                    {
                        foreach (IThemeEditor te in GetCategories())
                        {
                            ThemeEditorWrapper ThemeEditorWrapper = GetThemeEditors(PortalID, te.Guid);
                            if (ThemeEditorWrapper != null && ThemeEditorWrapper.Fonts != null)
                            {
                                Fonts.AddRange(ThemeEditorWrapper.Fonts);
                            }
                        }
                    }
                    else
                    {
                        ThemeEditorWrapper ThemeEditorWrapper = GetThemeEditors(PortalID, CategoryGuid);
                        if (ThemeEditorWrapper != null && ThemeEditorWrapper.Fonts != null)
                        {
                            Fonts.AddRange(ThemeEditorWrapper.Fonts);
                        }
                    }
                }
                return(Fonts);
            }
コード例 #2
0
            public static void UpdateFonts(string CategoryGuid, dynamic data)
            {
                ThemeEditorWrapper ThemeEditorWrapper = GetThemeEditors(PortalSettings.Current.PortalId, CategoryGuid);

                if (ThemeEditorWrapper == null)
                {
                    ThemeEditorWrapper = new ThemeEditorWrapper();
                }

                if (ThemeEditorWrapper.Fonts == null)
                {
                    ThemeEditorWrapper.Fonts = new List <ThemeFont>();
                }

                string GUID = !string.IsNullOrEmpty(data.Guid.ToString()) ? data.Guid.ToString() : Guid.NewGuid().ToString();

                if (ThemeEditorWrapper.Fonts.Where(a => a.Guid.ToLower() == GUID.ToLower()).FirstOrDefault() != null)
                {
                    ThemeFont ThemeFont = ThemeEditorWrapper.Fonts.Where(a => a.Guid.ToLower() == GUID.ToLower()).FirstOrDefault();
                    if (ThemeFont != null)
                    {
                        ThemeFont.Name   = data.Name;
                        ThemeFont.Family = data.Family;
                        ThemeFont.Css    = data.Css;
                    }
                }
                else
                {
                    ThemeEditorWrapper.Fonts.Add(new ThemeFont {
                        Guid = GUID, Name = data.Name.ToString(), Family = data.Family.ToString(), Css = data.Css.ToString()
                    });
                }

                UpdateThemeEditorJson(CategoryGuid, ThemeEditorWrapper);
            }
コード例 #3
0
            public static bool Delete(string CategoryGuid, string Category, string SubCategory)
            {
                try
                {
                    ThemeEditorWrapper ThemeEditorWrapper = GetThemeEditors(PortalSettings.Current.PortalId, CategoryGuid);
                    if (ThemeEditorWrapper != null && ThemeEditorWrapper.ThemeEditors != null)
                    {
                        if (!string.IsNullOrEmpty(Category) && !string.IsNullOrEmpty(SubCategory))
                        {
                            List <string> FilteredGuids = ThemeEditorWrapper.ThemeEditors.Where(t => t.Category.ToLower() == Category.ToLower() && !string.IsNullOrEmpty(t.Title) && t.Title.ToLower() == SubCategory.ToLower()).Select(s => s.Guid).ToList();
                            if (FilteredGuids != null && FilteredGuids.Count > 0)
                            {
                                ThemeEditorWrapper.ThemeEditors = ThemeEditorWrapper.ThemeEditors.Where(t => !FilteredGuids.Contains(t.Guid)).ToList();
                            }
                        }
                        else
                        {
                            ThemeEditorWrapper.ThemeEditors = ThemeEditorWrapper.ThemeEditors.Where(t => t.Category.ToLower() != Category.ToLower()).ToList();
                        }

                        UpdateThemeEditorJson(CategoryGuid, ThemeEditorWrapper);
                    }
                    return(true);
                }
                catch (Exception ex) { DotNetNuke.Services.Exceptions.Exceptions.LogException(ex); return(false); }
            }
コード例 #4
0
        internal static List <IUIData> GetAllData(string identifier, Dictionary <string, string> parameters)
        {
            Dictionary <string, IUIData> Settings = new Dictionary <string, IUIData>();
            string ThemeName = string.Empty;
            string Category  = string.Empty;
            string Guid      = string.Empty;

            if (parameters.Count > 0)
            {
                if (parameters.ContainsKey("themename"))
                {
                    ThemeName = parameters["themename"];
                }

                if (parameters.ContainsKey("cat"))
                {
                    Category = parameters["cat"];
                }

                if (parameters.ContainsKey("guid"))
                {
                    Guid = parameters["guid"];
                }
            }
            Settings.Add("MarkUp", new UIData {
                Name = "MarkUp", Value = Core.Managers.ThemeManager.GetMarkUp(identifier, Guid)
            });
            Settings.Add("Category", new UIData {
                Name = "Category", Value = Category
            });
            Settings.Add("Guid", new UIData {
                Name = "Guid", Value = Guid
            });
            Settings.Add("ThemeName", new UIData {
                Name = "ThemeName", Value = ThemeName
            });
            if (identifier.ToLower() == "setting_manage")
            {
                bool DeveloperMode = true;
                ThemeEditorWrapper themeEditorWrapper = Core.Managers.ThemeManager.GetThemeEditors(PortalSettings.Current.PortalId, Guid);
                if (themeEditorWrapper != null)
                {
                    DeveloperMode = themeEditorWrapper.DeveloperMode;
                }

                Settings.Add("DeveloperMode", new UIData {
                    Name = "DeveloperMode", Value = DeveloperMode.ToString().ToLower()
                });
                Settings.Add("Fonts", new UIData {
                    Name = "Fonts", Options = Core.Managers.ThemeManager.GetFonts(PortalSettings.Current.PortalId, Guid)
                });
                Settings.Add("Font", new UIData {
                    Name = "Font", Options = new ThemeFont()
                });
            }
            return(Settings.Values.ToList());
        }
コード例 #5
0
            public static ThemeEditor GetThemeEditor(string categoryguid, string guid)
            {
                int index = 0;
                ThemeEditorWrapper ThemeEditorWrapper = GetThemeEditors(PortalSettings.Current.PortalId, categoryguid);

                if (ThemeEditorWrapper != null)
                {
                    return(GetThemeEditor(ThemeEditorWrapper.ThemeEditors, guid, ref index));
                }
                else
                {
                    return(null);
                }
            }
コード例 #6
0
            private static void UpdateThemeEditorJson(string CategoryGuid, ThemeEditorWrapper ThemeEditorWrapper)
            {
                string ThemeEditorJsonPath = GetThemeEditorJsonPath(PortalSettings.Current.PortalId, CategoryGuid);

                if (ThemeEditorJsonPath.EndsWith("theme.editor.custom.json"))
                {
                    ThemeEditorWrapper.DeveloperMode = true;
                }

                string Content = JsonConvert.SerializeObject(ThemeEditorWrapper);

                File.WriteAllText(ThemeEditorJsonPath, Content);
                CacheFactory.Clear(CacheFactory.Keys.ThemeManager);
            }
コード例 #7
0
            public static string GetMarkUp(string identifier, string Guid)
            {
                StringBuilder      sb      = new StringBuilder();
                ThemeEditorWrapper editors = GetThemeEditors(PortalSettings.Current.PortalId, Guid);

                if (editors != null && editors.ThemeEditors != null)
                {
                    List <ThemeEditorValue> themeEditorValues = GetThemeEditorValues(PortalSettings.Current.PortalId, Guid);
                    foreach (IGrouping <string, ThemeEditor> item in GetThemeEditors(PortalSettings.Current.PortalId, Guid).ThemeEditors.GroupBy(g => g.Category).OrderBy(a => a.Key).ToList())
                    {
                        sb.Append(GetMarkUp(identifier, item, themeEditorValues, editors.DeveloperMode, Guid));
                    }
                }
                return(sb.ToString());
            }
コード例 #8
0
            public static ThemeEditorWrapper GetThemeEditors(int PortalID, string CategoryGuid)
            {
                string ThemeEditorJsonPath = GetThemeEditorJsonPath(PortalID, CategoryGuid);

                if (!File.Exists(ThemeEditorJsonPath))
                {
                    File.Create(ThemeEditorJsonPath).Dispose();
                }

                string             CacheKey = CacheFactory.GetCacheKey(CacheFactory.Keys.ThemeManager, PortalID, CategoryGuid);
                ThemeEditorWrapper result   = CacheFactory.Get(CacheKey);

                if (result == null)
                {
                    result = JsonConvert.DeserializeObject <ThemeEditorWrapper>(File.ReadAllText(ThemeEditorJsonPath));
                    CacheFactory.Set(CacheKey, result);
                }
                return(result);
            }
コード例 #9
0
            public static bool Update(string categoryGuid, ThemeEditor themeEditor)
            {
                try
                {
                    if (string.IsNullOrEmpty(themeEditor.Guid))
                    {
                        themeEditor.Guid = Guid.NewGuid().ToString();
                    }
                    ThemeEditorWrapper ThemeEditorWrapper = GetThemeEditors(PortalSettings.Current.PortalId, categoryGuid);
                    if (ThemeEditorWrapper != null && ThemeEditorWrapper.ThemeEditors != null)
                    {
                        int         index = -1;
                        ThemeEditor existingThemeEditor = GetThemeEditor(ThemeEditorWrapper.ThemeEditors, themeEditor.Guid, ref index);
                        if (existingThemeEditor != null && index >= 0)
                        {
                            ThemeEditorWrapper.ThemeEditors[index] = themeEditor;
                        }
                        else
                        {
                            ThemeEditorWrapper.ThemeEditors.Add(themeEditor);
                        }
                    }
                    else
                    {
                        if (ThemeEditorWrapper == null)
                        {
                            ThemeEditorWrapper = new ThemeEditorWrapper();
                        }

                        ThemeEditorWrapper.ThemeEditors = new List <ThemeEditor>
                        {
                            themeEditor
                        };
                    }
                    UpdateThemeEditorJson(categoryGuid, ThemeEditorWrapper);
                    return(true);
                }
                catch (Exception ex) { DotNetNuke.Services.Exceptions.Exceptions.LogException(ex); return(false); }
            }
コード例 #10
0
            public static void DeleteFonts(string CategoryGuid, ThemeFont data)
            {
                ThemeEditorWrapper ThemeEditorWrapper = GetThemeEditors(PortalSettings.Current.PortalId, CategoryGuid);

                if (ThemeEditorWrapper == null)
                {
                    ThemeEditorWrapper = new ThemeEditorWrapper();
                }

                if (ThemeEditorWrapper.Fonts == null)
                {
                    ThemeEditorWrapper.Fonts = new List <ThemeFont>();
                }

                string GUID = !string.IsNullOrEmpty(data.Guid.ToString()) ? data.Guid.ToString() : Guid.NewGuid().ToString();

                if (ThemeEditorWrapper.Fonts.Where(a => a.Guid.ToLower() == GUID.ToLower()).FirstOrDefault() != null)
                {
                    ThemeFont ThemeFont = ThemeEditorWrapper.Fonts.Where(a => a.Guid.ToLower() == GUID.ToLower()).FirstOrDefault();
                    ThemeEditorWrapper.Fonts.Remove(ThemeFont);
                    UpdateThemeEditorJson(CategoryGuid, ThemeEditorWrapper);
                }
            }
コード例 #11
0
        internal static List <IUIData> GetData(Dictionary <string, string> parameters)
        {
            Dictionary <string, IUIData> Settings = new Dictionary <string, IUIData>();

            string CatGuid  = string.Empty;
            string Guid     = string.Empty;
            string Category = string.Empty;
            string Type     = string.Empty;

            if (parameters.Count > 0)
            {
                if (parameters.ContainsKey("catguid"))
                {
                    CatGuid = parameters["catguid"];
                }

                if (parameters.ContainsKey("guid"))
                {
                    Guid = parameters["guid"];
                }

                if (parameters.ContainsKey("cat"))
                {
                    Category = parameters["cat"];
                }

                if (parameters.ContainsKey("type"))
                {
                    Type = parameters["type"];
                }
            }

            ThemeEditor te = Core.Managers.ThemeManager.GetThemeEditor(CatGuid, Guid);

            Settings.Add("ThemeEditor", new UIData {
                Name = "ThemeEditor", Options = te ?? new ThemeEditor()
            });
            Settings.Add("ControlTypes", new UIData {
                Name = "ControlTypes", Options = Core.Managers.ThemeManager.GetControlTypes()
            });
            Settings.Add("IsNew", new UIData {
                Name = "IsNew", Value = string.IsNullOrEmpty(Guid) ? "true" : "false"
            });
            Settings.Add("Fonts", new UIData {
                Name = "Fonts", OptionsText = "Name", OptionsValue = "Value", Options = Core.Managers.ThemeManager.GetDDLFonts(CatGuid), Value = "0"
            });
            Settings.Add("Category", new UIData {
                Name = "Category", Value = Category
            });
            Settings.Add("Type", new UIData {
                Name = "Type", Value = Type
            });

            bool DeveloperMode = true;
            ThemeEditorWrapper themeEditorWrapper = Core.Managers.ThemeManager.GetThemeEditors(PortalSettings.Current.PortalId, CatGuid);

            if (themeEditorWrapper != null)
            {
                DeveloperMode = themeEditorWrapper.DeveloperMode;
            }

            Settings.Add("DeveloperMode", new UIData {
                Name = "DeveloperMode", Value = DeveloperMode.ToString().ToLower()
            });
            Settings.Add("CatGuid", new UIData {
                Name = "CatGuid", Value = CatGuid
            });
            return(Settings.Values.ToList());
        }
コード例 #12
0
            public static void ProcessScss(int PortalID)
            {
                StringBuilder sb            = new StringBuilder();
                string        ThemeName     = GetCurrentThemeName(PortalID);
                string        BootstrapPath = HttpContext.Current.Server.MapPath("~/Portals/_default/vThemes/" + ThemeName + "/scss/Bootstrap/bootstrap.scss");
                string        BeforePath    = HttpContext.Current.Server.MapPath("~/Portals/_default/vThemes/" + ThemeName + "/scss/Before.scss");
                string        AfterPath     = HttpContext.Current.Server.MapPath("~/Portals/_default/vThemes/" + ThemeName + "/scss/After.scss");

                foreach (ThemeFont font in GetFonts(PortalID, "all"))
                {
                    if (!string.IsNullOrEmpty(font.Css))
                    {
                        sb.Append(font.Css);
                    }
                }

                if (File.Exists(BeforePath))
                {
                    sb.Append(File.ReadAllText(BeforePath));
                }

                List <string> Css = new List <string>();

                foreach (IThemeEditor category in GetCategories())
                {
                    List <ThemeEditorValue> themeEditorValues = GetThemeEditorValues(PortalID, category.Guid);
                    ThemeEditorWrapper      editors           = GetThemeEditors(PortalID, category.Guid);
                    if (editors != null && editors.ThemeEditors != null)
                    {
                        foreach (IGrouping <string, ThemeEditor> themeEditorGroup in GetThemeEditors(PortalID, category.Guid).ThemeEditors.GroupBy(g => g.Category).OrderBy(a => a.Key).ToList())
                        {
                            foreach (ThemeEditor item in themeEditorGroup.OrderBy(a => a.Title).ToList())
                            {
                                string sass = item.Sass;
                                foreach (dynamic ctl in item.Controls)
                                {
                                    string id           = ctl.Guid.ToString();
                                    string css          = ctl.CustomCSS.ToString();
                                    string variable     = ctl.LessVariable.ToString();
                                    string DefaultValue = ctl.DefaultValue.ToString();

                                    ThemeEditorValue editorValue = themeEditorValues?.Where(t => t.Guid.ToLower() == id.ToLower()).FirstOrDefault();
                                    if (editorValue != null)
                                    {
                                        DefaultValue = editorValue.Value;
                                    }

                                    if (!string.IsNullOrEmpty(DefaultValue) && !string.IsNullOrEmpty(css))
                                    {
                                        string[] strings = new string[] { variable };
                                        strings = css.Split(strings, StringSplitOptions.None);
                                        css     = string.Join(DefaultValue, strings);
                                        Css.Add(css + ';');
                                    }
                                    else if (!string.IsNullOrEmpty(DefaultValue) && !string.IsNullOrEmpty(variable) && variable.StartsWith("$"))
                                    {
                                        Css.Add(variable + ":" + DefaultValue + " !default;");
                                    }

                                    if (!string.IsNullOrEmpty(sass))
                                    {
                                        Css.Add(sass + ';');
                                    }
                                }
                            }
                        }
                    }
                }

                if (Css != null && Css.Count > 0)
                {
                    Css = Css.Distinct().ToList();
                    foreach (string str in Css)
                    {
                        sb.Append(str);
                    }
                }

                if (File.Exists(BootstrapPath))
                {
                    sb.Append(File.ReadAllText(BootstrapPath));
                }

                if (File.Exists(AfterPath))
                {
                    sb.Append(File.ReadAllText(AfterPath));
                }

                if (sb.Length > 0)
                {
                    string ThemeCss = HttpContext.Current.Server.MapPath("~/Portals/" + PortalID + "/vThemes/" + ThemeName + "/Theme.css");
                    if (!File.Exists(ThemeCss))
                    {
                        File.Create(ThemeCss).Dispose();
                    }
                    else
                    {
                        File.Copy(ThemeCss, ThemeCss.Replace("Theme.css", "Theme.backup.css"), true);
                    }

                    CompilationResult result = SassCompiler.Compile(sb.ToString(), HttpContext.Current.Server.MapPath("~/Portals/_default/vThemes/" + ThemeName + "/scss/Bootstrap/"));
                    File.WriteAllText(ThemeCss, result.CompiledContent);
                    PortalController.IncrementCrmVersion(PortalID);

                    UnloadSassCompiler();
                }
            }