Exemplo n.º 1
0
        /// <summary>
        /// Creates the default settings file.
        /// </summary>
        internal static void CreateDefaultSettingsFile()
        {
            var newSettings = new EditorProviderSettings();

            var serializer = new XmlSerializer(typeof(EditorProviderSettings));

            var textWriter =
                new StreamWriter(
                    new FileStream(
                        Path.Combine(Globals.HostMapPath, SettingConstants.XmlDefaultFileName),
                        FileMode.OpenOrCreate,
                        FileAccess.ReadWrite,
                        FileShare.ReadWrite));

            serializer.Serialize(textWriter, newSettings);

            textWriter.Close();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Load Portal/Page/Module Settings
        /// </summary>
        private void LoadAllSettings()
        {
            var settingsDictionary = EditorController.GetEditorHostSettings();
            var portalRoles = RoleController.Instance.GetRoles(_portalSettings.PortalId);

            // Load Default Settings
            currentSettings = SettingsUtil.GetDefaultSettings(
                _portalSettings,
                _portalSettings.HomeDirectoryMapPath,
                _settings["configFolder"],
                portalRoles);

            // Set Current Mode to Default
            currentSettings.SettingMode = SettingsMode.Default;

            var portalKey = string.Format("DNNCKP#{0}#", _portalSettings.PortalId);
            var pageKey = string.Format("DNNCKT#{0}#", _portalSettings.ActiveTab.TabID);
            var moduleKey = string.Format("DNNCKMI#{0}#INS#{1}#", parentModulId, ID);

            // Load Portal Settings ?!
            if (SettingsUtil.CheckExistsPortalOrPageSettings(settingsDictionary, portalKey))
            {
                /* throw new ApplicationException(settingsDictionary.FirstOrDefault(
                             setting => setting.Name.Equals(string.Format("{0}{1}", portalKey, "StartupMode"))).Value);*/

                currentSettings = SettingsUtil.LoadPortalOrPageSettings(
                    _portalSettings, currentSettings, settingsDictionary, portalKey, portalRoles);

                // Set Current Mode to Portal
                currentSettings.SettingMode = SettingsMode.Portal;
            }

            // Load Page Settings ?!
            if (SettingsUtil.CheckExistsPortalOrPageSettings(settingsDictionary, pageKey))
            {
                currentSettings = SettingsUtil.LoadPortalOrPageSettings(
                    _portalSettings, currentSettings, settingsDictionary, pageKey, portalRoles);

                // Set Current Mode to Page
                currentSettings.SettingMode = SettingsMode.Page;
            }

            // Load Module Settings ?!
            if (!SettingsUtil.CheckExistsModuleInstanceSettings(moduleKey, parentModulId))
            {
                return;
            }

            currentSettings = SettingsUtil.LoadModuleSettings(
                _portalSettings, currentSettings, moduleKey, parentModulId, portalRoles);

            // Set Current Mode to Module Instance
            currentSettings.SettingMode = SettingsMode.ModuleInstance;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Loads the portal or page settings.
        /// </summary>
        /// <param name="portalSettings">The current portal settings.</param>
        /// <param name="currentSettings">The current settings.</param>
        /// <param name="editorHostSettings">The editor host settings.</param>
        /// <param name="key">The Portal or Page key.</param>
        /// <param name="portalRoles">The Portal Roles</param>
        /// <returns>
        /// Returns the Filled Settings
        /// </returns>
        internal static EditorProviderSettings LoadPortalOrPageSettings(
            PortalSettings portalSettings,
            EditorProviderSettings currentSettings,
            List<EditorHostSetting> editorHostSettings,
            string key,
            IList<RoleInfo> portalRoles)
        {
            var roles = new ArrayList();

            // Import all Editor config settings
            foreach (PropertyInfo info in GetEditorConfigProperties())
            {
                if (!editorHostSettings.Any(s => s.Name.Equals(string.Format("{0}{1}", key, info.Name))))
                {
                    continue;
                }

                /*if (!info.Name.Equals("CodeMirror") && !info.Name.Equals("WordCount"))
                {
                    continue;
                }*/

                var settingValue =
                    editorHostSettings.FirstOrDefault(
                        setting => setting.Name.Equals(string.Format("{0}{1}", key, info.Name))).Value;

                if (string.IsNullOrEmpty(settingValue))
                {
                    continue;
                }

                switch (info.PropertyType.Name)
                {
                    case "String":
                        info.SetValue(currentSettings.Config, settingValue, null);
                        break;
                    case "Int32":
                        info.SetValue(currentSettings.Config, int.Parse(settingValue), null);
                        break;
                    case "Decimal":
                        info.SetValue(currentSettings.Config, decimal.Parse(settingValue), null);
                        break;
                    case "Boolean":
                        info.SetValue(currentSettings.Config, bool.Parse(settingValue), null);
                        break;
                }

                switch (info.Name)
                {
                    case "ToolbarLocation":
                        info.SetValue(
                            currentSettings.Config,
                            (ToolBarLocation)Enum.Parse(typeof(ToolBarLocation), settingValue),
                            null);
                        break;
                    case "DefaultLinkType":
                        info.SetValue(
                            currentSettings.Config,
                            (LinkType)Enum.Parse(typeof(LinkType), settingValue),
                            null);
                        break;
                    case "EnterMode":
                    case "ShiftEnterMode":
                        info.SetValue(
                            currentSettings.Config,
                            (EnterModus)Enum.Parse(typeof(EnterModus), settingValue),
                            null);
                        break;
                    case "ContentsLangDirection":
                        info.SetValue(
                            currentSettings.Config,
                            (LanguageDirection)Enum.Parse(typeof(LanguageDirection), settingValue),
                            null);
                        break;
                    case "CodeMirror":
                        foreach (var codeMirrorInfo in
                            typeof(CodeMirror).GetProperties()
                                .Where(codeMirrorInfo => !codeMirrorInfo.Name.Equals("Theme")))
                        {
                            switch (codeMirrorInfo.PropertyType.Name)
                            {
                                case "String":
                                    if (
                                        editorHostSettings.Any(
                                            s => s.Name.Equals(string.Format("{0}{1}", key, codeMirrorInfo.Name))))
                                    {
                                        codeMirrorInfo.SetValue(currentSettings.Config.CodeMirror, settingValue, null);
                                    }

                                    break;
                                case "Boolean":
                                    if (
                                        editorHostSettings.Any(
                                            s => s.Name.Equals(string.Format("{0}{1}", key, codeMirrorInfo.Name))))
                                    {
                                        codeMirrorInfo.SetValue(
                                            currentSettings.Config.CodeMirror,
                                            bool.Parse(settingValue),
                                            null);
                                    }

                                    break;
                            }
                        }

                        break;
                    case "WordCount":
                        foreach (var wordCountInfo in typeof(WordCountConfig).GetProperties())
                        {
                            switch (wordCountInfo.PropertyType.Name)
                            {
                                case "String":
                                    if (
                                        editorHostSettings.Any(
                                            s => s.Name.Equals(string.Format("{0}{1}", key, wordCountInfo.Name))))
                                    {
                                        wordCountInfo.SetValue(currentSettings.Config.WordCount, settingValue, null);
                                    }

                                    break;
                                case "Boolean":
                                    if (
                                        editorHostSettings.Any(
                                            s => s.Name.Equals(string.Format("{0}{1}", key, wordCountInfo.Name))))
                                    {
                                        wordCountInfo.SetValue(
                                            currentSettings.Config.WordCount,
                                            bool.Parse(settingValue),
                                            null);
                                    }

                                    break;
                            }
                        }

                        break;
                }
            }

            /////////////////

            if (
                editorHostSettings.Any(
                    setting => setting.Name.Equals(string.Format("{0}{1}", key, SettingConstants.SKIN))))
            {
                var settingValue =
                    editorHostSettings.FirstOrDefault(
                        s => s.Name.Equals(string.Format("{0}{1}", key, SettingConstants.SKIN))).Value;

                if (!string.IsNullOrEmpty(settingValue))
                {
                    currentSettings.Config.Skin = settingValue;
                }
            }

            if (
                editorHostSettings.Any(
                    setting => setting.Name.Equals(string.Format("{0}{1}", key, SettingConstants.CODEMIRRORTHEME))))
            {
                var settingValue =
                    editorHostSettings.FirstOrDefault(
                        s => s.Name.Equals(string.Format("{0}{1}", key, SettingConstants.CODEMIRRORTHEME))).Value;

                if (!string.IsNullOrEmpty(settingValue))
                {
                    currentSettings.Config.CodeMirror.Theme = settingValue;
                }
            }

            List<ToolbarRoles> listToolbarRoles = (from RoleInfo objRole in portalRoles
                                                   where
                                                       editorHostSettings.Any(
                                                           setting =>
                                                           setting.Name.Equals(
                                                               string.Format(
                                                                   "{0}{2}#{1}",
                                                                   key,
                                                                   objRole.RoleID,
                                                                   SettingConstants.TOOLB)))
                                                   where
                                                       !string.IsNullOrEmpty(
                                                           editorHostSettings.FirstOrDefault(
                                                               s =>
                                                               s.Name.Equals(
                                                                   string.Format(
                                                                       "{0}{2}#{1}",
                                                                       key,
                                                                       objRole.RoleID,
                                                                       SettingConstants.TOOLB))).Value)
                                                   let sToolbar =
                                                       editorHostSettings.FirstOrDefault(
                                                           s =>
                                                           s.Name.Equals(
                                                               string.Format(
                                                                   "{0}{2}#{1}",
                                                                   key,
                                                                   objRole.RoleID,
                                                                   SettingConstants.TOOLB))).Value
                                                   select
                                                       new ToolbarRoles { RoleId = objRole.RoleID, Toolbar = sToolbar })
                .ToList();

            if (
                editorHostSettings.Any(
                    setting => setting.Name.Equals(string.Format("{0}{2}#{1}", key, "-1", SettingConstants.TOOLB))))
            {
                var settingValue =
                    editorHostSettings.FirstOrDefault(
                        s => s.Name.Equals(string.Format("{0}{2}#{1}", key, "-1", SettingConstants.TOOLB))).Value;

                if (!string.IsNullOrEmpty(settingValue))
                {
                    listToolbarRoles.Add(new ToolbarRoles { RoleId = -1, Toolbar = settingValue });
                }
            }

            currentSettings.ToolBarRoles = listToolbarRoles;

            var listUploadSizeRoles = (from RoleInfo objRole in portalRoles
                                       where
                                           editorHostSettings.Any(
                                               setting =>
                                               setting.Name.Equals(
                                                   string.Format(
                                                       "{0}{2}#{1}",
                                                       key,
                                                       objRole.RoleID,
                                                       SettingConstants.UPLOADFILELIMITS)))
                                       where
                                           !string.IsNullOrEmpty(
                                               editorHostSettings.FirstOrDefault(
                                                   s =>
                                                   s.Name.Equals(
                                                       string.Format(
                                                           "{0}{2}#{1}",
                                                           key,
                                                           objRole.RoleID,
                                                           SettingConstants.UPLOADFILELIMITS))).Value)
                                       let uploadFileLimit =
                                           editorHostSettings.FirstOrDefault(
                                               s =>
                                               s.Name.Equals(
                                                   string.Format(
                                                       "{0}{2}#{1}",
                                                       key,
                                                       objRole.RoleID,
                                                       SettingConstants.UPLOADFILELIMITS))).Value
                                       select
                                           new UploadSizeRoles { RoleId = objRole.RoleID, UploadFileLimit = Convert.ToInt32(uploadFileLimit) })
                .ToList();

            if (
                editorHostSettings.Any(
                    setting => setting.Name.Equals(string.Format("{0}{2}#{1}", key, "-1", SettingConstants.UPLOADFILELIMITS))))
            {
                var settingValue =
                    editorHostSettings.FirstOrDefault(
                        s => s.Name.Equals(string.Format("{0}{2}#{1}", key, "-1", SettingConstants.UPLOADFILELIMITS))).Value;

                if (!string.IsNullOrEmpty(settingValue))
                {
                    listUploadSizeRoles.Add(new UploadSizeRoles { RoleId = -1, UploadFileLimit = Convert.ToInt32(settingValue) });
                }
            }

            currentSettings.UploadSizeRoles = listUploadSizeRoles;

            if (
                editorHostSettings.Any(
                    setting => setting.Name.Equals(string.Format("{0}{1}", key, SettingConstants.ROLES))))
            {
                var settingValue =
                    editorHostSettings.FirstOrDefault(
                        s => s.Name.Equals(string.Format("{0}{1}", key, SettingConstants.ROLES))).Value;

                if (!string.IsNullOrEmpty(settingValue))
                {
                    string sRoles = settingValue;

                    currentSettings.BrowserRoles = sRoles;

                    string[] rolesA = sRoles.Split(';');

                    foreach (string sRoleName in rolesA)
                    {
                        if (Utility.IsNumeric(sRoleName))
                        {
                            RoleInfo roleInfo = RoleController.Instance.GetRoleById(int.Parse(sRoleName), portalSettings.PortalId);

                            if (roleInfo != null)
                            {
                                roles.Add(roleInfo.RoleName);
                            }
                        }
                        else
                        {
                            roles.Add(sRoleName);
                        }
                    }
                }
            }

            if (
                editorHostSettings.Any(
                    setting => setting.Name.Equals(string.Format("{0}{1}", key, SettingConstants.BROWSER))))
            {
                var settingValue =
                    editorHostSettings.FirstOrDefault(
                        s => s.Name.Equals(string.Format("{0}{1}", key, SettingConstants.BROWSER))).Value;

                if (!string.IsNullOrEmpty(settingValue))
                {
                    currentSettings.Browser = settingValue;

                    switch (currentSettings.Browser)
                    {
                        case "ckfinder":
                            foreach (string sRoleName in roles)
                            {
                                if (PortalSecurity.IsInRoles(sRoleName))
                                {
                                    currentSettings.BrowserMode = BrowserType.CKFinder;

                                    break;
                                }

                                currentSettings.BrowserMode = BrowserType.None;
                            }

                            break;
                        case "standard":
                            foreach (string sRoleName in roles)
                            {
                                if (PortalSecurity.IsInRoles(sRoleName))
                                {
                                    currentSettings.BrowserMode = BrowserType.StandardBrowser;

                                    break;
                                }

                                currentSettings.BrowserMode = BrowserType.None;
                            }

                            break;
                        case "none":
                            currentSettings.BrowserMode = BrowserType.None;
                            break;
                    }
                }
            }

            if (
                editorHostSettings.Any(
                    setting => setting.Name.Equals(string.Format("{0}{1}", key, SettingConstants.INJECTJS))))
            {
                var settingValue =
                    editorHostSettings.FirstOrDefault(
                        s => s.Name.Equals(string.Format("{0}{1}", key, SettingConstants.INJECTJS))).Value;

                if (!string.IsNullOrEmpty(settingValue))
                {
                    bool bResult;
                    if (bool.TryParse(settingValue, out bResult))
                    {
                        currentSettings.InjectSyntaxJs = bResult;
                    }
                }
            }

            if (
                editorHostSettings.Any(
                    setting => setting.Name.Equals(string.Format("{0}{1}", key, SettingConstants.WIDTH))))
            {
                var settingValue =
                    editorHostSettings.FirstOrDefault(
                        s => s.Name.Equals(string.Format("{0}{1}", key, SettingConstants.WIDTH))).Value;

                if (!string.IsNullOrEmpty(settingValue))
                {
                    currentSettings.Config.Width = settingValue;
                }
            }

            if (
                editorHostSettings.Any(
                    setting => setting.Name.Equals(string.Format("{0}{1}", key, SettingConstants.HEIGHT))))
            {
                var settingValue =
                    editorHostSettings.FirstOrDefault(
                        s => s.Name.Equals(string.Format("{0}{1}", key, SettingConstants.HEIGHT))).Value;

                if (!string.IsNullOrEmpty(settingValue))
                {
                    currentSettings.Config.Height = settingValue;
                }
            }

            if (
                editorHostSettings.Any(
                    setting => setting.Name.Equals(string.Format("{0}{1}", key, SettingConstants.BLANKTEXT))))
            {
                var settingValue =
                    editorHostSettings.FirstOrDefault(
                        s => s.Name.Equals(string.Format("{0}{1}", key, SettingConstants.BLANKTEXT))).Value;

                if (!string.IsNullOrEmpty(settingValue))
                {
                    currentSettings.BlankText = settingValue;
                }
            }

            if (
                editorHostSettings.Any(
                    setting => setting.Name.Equals(string.Format("{0}{1}", key, SettingConstants.CSS))))
            {
                var settingValue =
                    editorHostSettings.FirstOrDefault(
                        s => s.Name.Equals(string.Format("{0}{1}", key, SettingConstants.CSS))).Value;

                if (!string.IsNullOrEmpty(settingValue))
                {
                    currentSettings.Config.ContentsCss = settingValue;
                }
            }

            if (
                editorHostSettings.Any(
                    setting => setting.Name.Equals(string.Format("{0}{1}", key, SettingConstants.TEMPLATEFILES))))
            {
                var settingValue =
                    editorHostSettings.FirstOrDefault(
                        s => s.Name.Equals(string.Format("{0}{1}", key, SettingConstants.TEMPLATEFILES))).Value;

                if (!string.IsNullOrEmpty(settingValue))
                {
                    currentSettings.Config.Templates_Files = settingValue;
                }
            }

            if (
                editorHostSettings.Any(
                    setting => setting.Name.Equals(string.Format("{0}{1}", key, SettingConstants.CUSTOMJSFILE))))
            {
                var settingValue =
                    editorHostSettings.FirstOrDefault(
                        s => s.Name.Equals(string.Format("{0}{1}", key, SettingConstants.CUSTOMJSFILE))).Value;

                if (!string.IsNullOrEmpty(settingValue))
                {
                    currentSettings.CustomJsFile = settingValue;
                }
            }

            if (
                editorHostSettings.Any(
                    setting => setting.Name.Equals(string.Format("{0}{1}", key, SettingConstants.CONFIG))))
            {
                var settingValue =
                    editorHostSettings.FirstOrDefault(
                        s => s.Name.Equals(string.Format("{0}{1}", key, SettingConstants.CONFIG))).Value;

                if (!string.IsNullOrEmpty(settingValue))
                {
                    currentSettings.Config.CustomConfig = settingValue;
                }
            }

            if (
                editorHostSettings.Any(
                    setting => setting.Name.Equals(string.Format("{0}{1}", key, SettingConstants.FILELISTPAGESIZE))))
            {
                var settingValue =
                    editorHostSettings.FirstOrDefault(
                        s => s.Name.Equals(string.Format("{0}{1}", key, SettingConstants.FILELISTPAGESIZE))).Value;

                if (!string.IsNullOrEmpty(settingValue))
                {
                    currentSettings.FileListPageSize = int.Parse(settingValue);
                }
            }

            if (
                editorHostSettings.Any(
                    setting => setting.Name.Equals(string.Format("{0}{1}", key, SettingConstants.FILELISTVIEWMODE))))
            {
                var settingValue =
                    editorHostSettings.FirstOrDefault(
                        s => s.Name.Equals(string.Format("{0}{1}", key, SettingConstants.FILELISTVIEWMODE))).Value;

                if (!string.IsNullOrEmpty(settingValue))
                {
                    currentSettings.FileListViewMode = (FileListView)Enum.Parse(typeof(FileListView), settingValue);
                }
            }

            if (
                editorHostSettings.Any(
                    setting => setting.Name.Equals(string.Format("{0}{1}", key, SettingConstants.DEFAULTLINKMODE))))
            {
                var settingValue =
                    editorHostSettings.FirstOrDefault(
                        s => s.Name.Equals(string.Format("{0}{1}", key, SettingConstants.DEFAULTLINKMODE))).Value;

                if (!string.IsNullOrEmpty(settingValue))
                {
                    currentSettings.DefaultLinkMode = (LinkMode)Enum.Parse(typeof(LinkMode), settingValue);
                }
            }

            if (
                editorHostSettings.Any(
                    setting => setting.Name.Equals(string.Format("{0}{1}", key, SettingConstants.USEANCHORSELECTOR))))
            {
                var settingValue =
                    editorHostSettings.FirstOrDefault(
                        s => s.Name.Equals(string.Format("{0}{1}", key, SettingConstants.USEANCHORSELECTOR))).Value;

                if (!string.IsNullOrEmpty(settingValue))
                {
                    bool bResult;
                    if (bool.TryParse(settingValue, out bResult))
                    {
                        currentSettings.UseAnchorSelector = bResult;
                    }
                }
            }

            if (
                editorHostSettings.Any(
                    setting => setting.Name.Equals(string.Format("{0}{1}", key, SettingConstants.SHOWPAGELINKSTABFIRST))))
            {
                var settingValue =
                    editorHostSettings.FirstOrDefault(
                        s => s.Name.Equals(string.Format("{0}{1}", key, SettingConstants.SHOWPAGELINKSTABFIRST))).Value;

                if (!string.IsNullOrEmpty(settingValue))
                {
                    bool bResult;
                    if (bool.TryParse(settingValue, out bResult))
                    {
                        currentSettings.ShowPageLinksTabFirst = bResult;
                    }
                }
            }

            if (
                editorHostSettings.Any(
                    setting => setting.Name.Equals(string.Format("{0}{1}", key, SettingConstants.OVERRIDEFILEONUPLOAD))))
            {
                var settingValue =
                    editorHostSettings.FirstOrDefault(
                        s => s.Name.Equals(string.Format("{0}{1}", key, SettingConstants.OVERRIDEFILEONUPLOAD))).Value;

                if (!string.IsNullOrEmpty(settingValue))
                {
                    bool bResult;
                    if (bool.TryParse(settingValue, out bResult))
                    {
                        currentSettings.OverrideFileOnUpload = bResult;
                    }
                }
            }

            if (
                editorHostSettings.Any(
                    setting => setting.Name.Equals(string.Format("{0}{1}", key, SettingConstants.SUBDIRS))))
            {
                var settingValue =
                    editorHostSettings.FirstOrDefault(
                        s => s.Name.Equals(string.Format("{0}{1}", key, SettingConstants.SUBDIRS))).Value;

                if (!string.IsNullOrEmpty(settingValue))
                {
                    bool bResult;
                    if (bool.TryParse(settingValue, out bResult))
                    {
                        currentSettings.SubDirs = bResult;
                    }
                }
            }

            if (
                editorHostSettings.Any(
                    setting => setting.Name.Equals(string.Format("{0}{1}", key, SettingConstants.BROWSERROOTDIRID))))
            {
                var settingValue =
                    editorHostSettings.FirstOrDefault(
                        s => s.Name.Equals(string.Format("{0}{1}", key, SettingConstants.BROWSERROOTDIRID))).Value;

                if (!string.IsNullOrEmpty(settingValue))
                {
                    try
                    {
                        currentSettings.BrowserRootDirId = int.Parse(settingValue);
                    }
                    catch (Exception)
                    {
                        currentSettings.BrowserRootDirId = -1;
                    }
                }
            }

            if (
                editorHostSettings.Any(
                    setting => setting.Name.Equals(string.Format("{0}{1}", key, SettingConstants.UPLOADDIRID))))
            {
                var settingValue =
                    editorHostSettings.FirstOrDefault(
                        s => s.Name.Equals(string.Format("{0}{1}", key, SettingConstants.UPLOADDIRID))).Value;

                if (!string.IsNullOrEmpty(settingValue))
                {
                    try
                    {
                        currentSettings.UploadDirId = int.Parse(settingValue);
                    }
                    catch (Exception)
                    {
                        currentSettings.UploadDirId = -1;
                    }
                }
            }

            if (
                editorHostSettings.Any(
                    setting => setting.Name.Equals(string.Format("{0}{1}", key, SettingConstants.RESIZEWIDTH))))
            {
                var settingValue =
                    editorHostSettings.FirstOrDefault(
                        s => s.Name.Equals(string.Format("{0}{1}", key, SettingConstants.RESIZEWIDTH))).Value;

                if (!string.IsNullOrEmpty(settingValue))
                {
                    try
                    {
                        currentSettings.ResizeWidth = int.Parse(settingValue);
                    }
                    catch (Exception)
                    {
                        currentSettings.ResizeWidth = -1;
                    }
                }
            }

            if (
                editorHostSettings.Any(
                    setting => setting.Name.Equals(string.Format("{0}{1}", key, SettingConstants.RESIZEHEIGHT))))
            {
                var settingValue =
                    editorHostSettings.FirstOrDefault(
                        s => s.Name.Equals(string.Format("{0}{1}", key, SettingConstants.RESIZEHEIGHT))).Value;

                if (!string.IsNullOrEmpty(settingValue))
                {
                    try
                    {
                        currentSettings.ResizeHeight = int.Parse(settingValue);
                    }
                    catch (Exception)
                    {
                        currentSettings.ResizeHeight = -1;
                    }
                }
            }

            return currentSettings;
        }
Exemplo n.º 4
0
        /// <summary>
        /// Imports the old SettingsBase Xml File
        /// </summary>
        /// <param name="homeDirPath">The home folder path.</param>
        /// <param name="isDefaultXmlFile">if set to <c>true</c> [is default XML file].</param>
        internal static void ImportSettingBaseXml(string homeDirPath, bool isDefaultXmlFile = false)
        {
            var oldXmlPath = Path.Combine(homeDirPath, SettingConstants.XmlDefaultFileName);
            var oldSerializer = new XmlSerializer(typeof(SettingBase));
            var reader = new XmlTextReader(new FileStream(oldXmlPath, FileMode.Open, FileAccess.Read, FileShare.Read));

            if (!oldSerializer.CanDeserialize(reader))
            {
                reader.Close();

                return;
            }

            var oldDefaultSettings = (SettingBase)oldSerializer.Deserialize(reader);

            reader.Close();

            // Fix for old skins
            if (oldDefaultSettings.sSkin.Equals("office2003")
                            || oldDefaultSettings.sSkin.Equals("BootstrapCK-Skin")
                            || oldDefaultSettings.sSkin.Equals("chris")
                            || oldDefaultSettings.sSkin.Equals("v2"))
            {
                oldDefaultSettings.sSkin = "moono";
            }

            // Migrate Settings
            var importedSettings = new EditorProviderSettings
            {
                FileListPageSize = oldDefaultSettings.FileListPageSize,
                FileListViewMode = oldDefaultSettings.FileListViewMode,
                UseAnchorSelector = oldDefaultSettings.UseAnchorSelector,
                ShowPageLinksTabFirst = oldDefaultSettings.ShowPageLinksTabFirst,
                SubDirs = oldDefaultSettings.bSubDirs,
                InjectSyntaxJs = oldDefaultSettings.injectSyntaxJs,
                BrowserRootDirId = oldDefaultSettings.BrowserRootDirId,
                UploadDirId = oldDefaultSettings.UploadDirId,
                ResizeHeight = oldDefaultSettings.iResizeHeight,
                ResizeWidth = oldDefaultSettings.iResizeWidth,
                ToolBarRoles = oldDefaultSettings.listToolbRoles,
                BlankText = oldDefaultSettings.sBlankText,
                BrowserRoles = oldDefaultSettings.sBrowserRoles,
                Browser = oldDefaultSettings.sBrowser,
                Config =
                {
                    CustomConfig = oldDefaultSettings.sConfig,
                    ContentsCss = oldDefaultSettings.sCss,
                    Skin = oldDefaultSettings.sSkin,
                    Templates_Files = oldDefaultSettings.sTemplates,
                    Height = oldDefaultSettings.BrowserHeight,
                    Width = oldDefaultSettings.BrowserWidth,
                    AutoParagraph = true,
                    AutoUpdateElement = true,
                    BasicEntities = true,
                    BrowserContextMenuOnCtrl = true,
                    ColorButton_EnableMore = true,
                    DisableNativeSpellChecker = true,
                    DisableNativeTableHandles = true,
                    EnableTabKeyTools = true,
                    Entities = true,
                    Entities_Greek = true,
                    Entities_Latin = true,
                    FillEmptyBlocks = true,
                    IgnoreEmptyParagraph = true,
                    Image_RemoveLinkByEmptyURL = true,
                    PasteFromWordRemoveFontStyles = true,
                    PasteFromWordRemoveStyles = true,
                    Resize_Enabled = true,
                    StartupShowBorders = true,
                    ToolbarGroupCycling = true,
                    ToolbarStartupExpanded = true,
                    UseComputedState = true,
                    AutoGrow_BottomSpace = 0,
                    AutoGrow_MaxHeight = 0,
                    AutoGrow_MinHeight = 200,
                    BaseFloatZIndex = 10000,
                    Dialog_MagnetDistance = 20,
                    IndentOffset = 40,
                    Menu_SubMenuDelay = 400,
                    Resize_MaxHeight = 600,
                    Resize_MaxWidth = 3000,
                    Resize_MinHeight = 250,
                    Resize_MinWidth = 750,
                    Scayt_MaxSuggestions = 5,
                    Smiley_columns = 8,
                    SourceAreaTabSize = 20,
                    TabIndex = 0,
                    TabSpaces = 0,
                    UndoStackSize = 20
                }
            };

            // Delete Old File
            File.Delete(oldXmlPath);

            // Save new xml file
            var newSerializer = new XmlSerializer(typeof(EditorProviderSettings));

            using (
                var textWriter =
                    new StreamWriter(
                        new FileStream(
                            Path.Combine(
                                homeDirPath, isDefaultXmlFile ? SettingConstants.XmlDefaultFileName : SettingConstants.XmlSettingsFileName),
                            FileMode.OpenOrCreate,
                            FileAccess.ReadWrite,
                            FileShare.ReadWrite)))
            {
                newSerializer.Serialize(textWriter, importedSettings);

                textWriter.Close();
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Gets the size of the current user upload.
        /// </summary>
        /// <param name="settings">The settings.</param>
        /// <param name="portalSettings">The portal settings.</param>
        /// <param name="httpRequest">The HTTP request.</param>
        /// <returns>Returns the MAX. upload file size for the current user</returns>
        internal static int GetCurrentUserUploadSize(EditorProviderSettings settings, PortalSettings portalSettings, HttpRequest httpRequest)
        {
            var uploadFileLimitForPortal = Convert.ToInt32(Utility.GetMaxUploadSize());

            if (settings.ToolBarRoles.Count <= 0)
            {
                return uploadFileLimitForPortal;
            }

            var listUserUploadFileSizes = new List<ToolbarSet>();

            foreach (var roleUploadSize in settings.UploadSizeRoles)
            {
                if (roleUploadSize.RoleId.Equals(-1) && !httpRequest.IsAuthenticated)
                {
                    return roleUploadSize.UploadFileLimit;
                }

                if (roleUploadSize.RoleId.Equals(-1))
                {
                    continue;
                }

                // Role
                var role = RoleController.Instance.GetRoleById(roleUploadSize.RoleId, portalSettings.PortalId);

                if (role == null)
                {
                    continue;
                }

                if (!PortalSecurity.IsInRole(role.RoleName))
                {
                    continue;
                }

                var toolbar = new ToolbarSet(role.RoleName, roleUploadSize.UploadFileLimit);

                listUserUploadFileSizes.Add(toolbar);
            }

            if (listUserUploadFileSizes.Count <= 0)
            {
                return uploadFileLimitForPortal;
            }

            // Compare The User Toolbars if the User is more then One Role, and apply the Toolbar with the Highest Priority
            int iHighestPrio = listUserUploadFileSizes.Max(toolb => toolb.Priority);

            return listUserUploadFileSizes.Find(toolbarSel => toolbarSel.Priority.Equals(iHighestPrio)).Priority;
        }
        /// <summary>
        /// Exports the settings.
        /// </summary>
        /// <returns>Returns the exported EditorProviderSettings</returns>
        private EditorProviderSettings ExportSettings()
        {
            var exportSettings = new EditorProviderSettings { SettingMode = SettingsMode.Default };

            exportSettings.SettingMode = this.CurrentSettingsMode;

            // Export all Editor config settings
            foreach (PropertyInfo info in
                SettingsUtil.GetEditorConfigProperties())
            {
                switch (info.PropertyType.Name)
                {
                    case "String":
                        {
                            var textBox = Utility.FindControl<TextBox>(this.EditorConfigHolder, info.Name);

                            if (!string.IsNullOrEmpty(textBox.Text))
                            {
                                info.SetValue(exportSettings.Config, textBox.Text, null);
                            }
                        }

                        break;
                    case "Int32":
                        {
                            var textBox = Utility.FindControl<TextBox>(this.EditorConfigHolder, info.Name);

                            if (!string.IsNullOrEmpty(textBox.Text))
                            {
                                info.SetValue(exportSettings.Config, int.Parse(textBox.Text), null);
                            }
                        }

                        break;
                    case "Decimal":
                        {
                            var textBox = Utility.FindControl<TextBox>(this.EditorConfigHolder, info.Name);

                            if (!string.IsNullOrEmpty(textBox.Text))
                            {
                                info.SetValue(exportSettings.Config, decimal.Parse(textBox.Text), null);
                            }
                        }

                        break;
                    case "Boolean":
                        {
                            var checkBox = Utility.FindControl<CheckBox>(this.EditorConfigHolder, info.Name);

                            info.SetValue(exportSettings.Config, checkBox.Checked, null);
                        }

                        break;
                }

                switch (info.Name)
                {
                    case "ToolbarLocation":
                        {
                            var dropDownList = Utility.FindControl<DropDownList>(this.EditorConfigHolder, info.Name);

                            if (dropDownList.SelectedItem != null)
                            {
                                info.SetValue(
                                    exportSettings.Config,
                                    (ToolBarLocation)Enum.Parse(typeof(ToolBarLocation), dropDownList.SelectedValue),
                                    null);
                            }
                        }

                        break;
                    case "DefaultLinkType":
                        {
                            var dropDownList = Utility.FindControl<DropDownList>(this.EditorConfigHolder, info.Name);

                            if (dropDownList.SelectedItem != null)
                            {
                                info.SetValue(
                                    exportSettings.Config,
                                    (LinkType)Enum.Parse(typeof(LinkType), dropDownList.SelectedValue),
                                    null);
                            }
                        }

                        break;
                    case "EnterMode":
                    case "ShiftEnterMode":
                        {
                            var dropDownList = Utility.FindControl<DropDownList>(this.EditorConfigHolder, info.Name);

                            if (dropDownList.SelectedItem != null)
                            {
                                info.SetValue(
                                    exportSettings.Config,
                                    (EnterModus)Enum.Parse(typeof(EnterModus), dropDownList.SelectedValue),
                                    null);
                            }
                        }

                        break;
                    case "ContentsLangDirection":
                        {
                            var dropDownList = Utility.FindControl<DropDownList>(this.EditorConfigHolder, info.Name);

                            if (dropDownList.SelectedItem != null)
                            {
                                info.SetValue(
                                    exportSettings.Config,
                                    (LanguageDirection)Enum.Parse(typeof(LanguageDirection), dropDownList.SelectedValue),
                                    null);
                            }
                        }

                        break;
                    case "CodeMirror":
                        {
                            foreach (var codeMirrorInfo in
                                typeof(CodeMirror).GetProperties()
                                    .Where(codeMirrorInfo => !codeMirrorInfo.Name.Equals("Theme")))
                            {
                                switch (codeMirrorInfo.PropertyType.Name)
                                {
                                    case "String":
                                        {
                                            var textBox = Utility.FindControl<TextBox>(
                                                this.EditorConfigHolder,
                                                codeMirrorInfo.Name);

                                            if (!string.IsNullOrEmpty(textBox.Text))
                                            {
                                                codeMirrorInfo.SetValue(
                                                    exportSettings.Config.CodeMirror,
                                                    textBox.Text,
                                                    null);
                                            }
                                        }

                                        break;

                                    case "Boolean":
                                        {
                                            var checkBox = Utility.FindControl<CheckBox>(
                                                this.EditorConfigHolder,
                                                codeMirrorInfo.Name);

                                            codeMirrorInfo.SetValue(
                                                exportSettings.Config.CodeMirror,
                                                checkBox.Checked,
                                                null);
                                        }

                                        break;
                                }
                            }
                        }

                        break;
                    case "WordCount":
                        {
                            foreach (var wordCountInfo in typeof(WordCountConfig).GetProperties())
                            {
                                switch (wordCountInfo.PropertyType.Name)
                                {
                                    case "String":
                                        {
                                            var textBox = Utility.FindControl<TextBox>(
                                                this.EditorConfigHolder,
                                                wordCountInfo.Name);

                                            if (!string.IsNullOrEmpty(textBox.Text))
                                            {
                                                wordCountInfo.SetValue(
                                                    exportSettings.Config.WordCount,
                                                    textBox.Text,
                                                    null);
                                            }
                                        }

                                        break;

                                    case "Boolean":
                                        {
                                            var checkBox = Utility.FindControl<CheckBox>(
                                                this.EditorConfigHolder,
                                                wordCountInfo.Name);

                                            wordCountInfo.SetValue(
                                                exportSettings.Config.WordCount,
                                                checkBox.Checked,
                                                null);
                                        }

                                        break;
                                }
                            }
                        }

                        break;
                }
            }
            ///////////////////

            exportSettings.Config.Skin = this.ddlSkin.SelectedValue;
            exportSettings.Config.CodeMirror.Theme = this.CodeMirrorTheme.SelectedValue;
            exportSettings.Browser = this.ddlBrowser.SelectedValue;
            exportSettings.FileListViewMode =
                (FileListView)Enum.Parse(typeof(FileListView), this.FileListViewMode.SelectedValue);
            exportSettings.DefaultLinkMode = (LinkMode)Enum.Parse(typeof(LinkMode), this.DefaultLinkMode.SelectedValue);
            exportSettings.UseAnchorSelector = this.UseAnchorSelector.Checked;
            exportSettings.ShowPageLinksTabFirst = this.ShowPageLinksTabFirst.Checked;
            exportSettings.OverrideFileOnUpload = this.OverrideFileOnUpload.Checked;
            exportSettings.SubDirs = this.cbBrowserDirs.Checked;
            exportSettings.BrowserRootDirId = int.Parse(this.BrowserRootDir.SelectedValue);
            exportSettings.UploadDirId = int.Parse(this.UploadDir.SelectedValue);

            if (Utility.IsNumeric(this.FileListPageSize.Text))
            {
                exportSettings.FileListPageSize = int.Parse(this.FileListPageSize.Text);
            }

            if (Utility.IsNumeric(this.txtResizeWidth.Text))
            {
                exportSettings.ResizeWidth = int.Parse(this.txtResizeWidth.Text);
            }

            if (Utility.IsNumeric(this.txtResizeHeight.Text))
            {
                exportSettings.ResizeHeight = int.Parse(this.txtResizeHeight.Text);
            }

            exportSettings.InjectSyntaxJs = this.InjectSyntaxJs.Checked;

            if (Utility.IsUnit(this.txtWidth.Text))
            {
                exportSettings.EditorWidth = this.txtWidth.Text;
            }

            if (Utility.IsUnit(this.txtHeight.Text))
            {
                exportSettings.EditorHeight = this.txtHeight.Text;
            }

            exportSettings.BlankText = this.txtBlanktext.Text;
            exportSettings.Config.ContentsCss = this.CssUrl.Url;
            exportSettings.Config.Templates_Files = this.TemplUrl.Url;
            exportSettings.CustomJsFile = this.CustomJsFile.Url;
            exportSettings.Config.CustomConfig = this.ConfigUrl.Url;

            string sRoles = this.chblBrowsGr.Items.Cast<ListItem>()
                .Where(item => item.Selected)
                .Aggregate(string.Empty, (current, item) => current + (item.Value + ";"));

            if (sRoles != string.Empty)
            {
                exportSettings.BrowserRoles = sRoles;
            }

            var listToolbarRoles = new List<ToolbarRoles>();

            // Save Toolbar Setting for every Role
            for (int i = 0; i < this.gvToolbars.Rows.Count; i++)
            {
                Label label = (Label)this.gvToolbars.Rows[i].Cells[0].FindControl("lblRoleName");

                DropDownList ddLToolB = (DropDownList)this.gvToolbars.Rows[i].Cells[1].FindControl("ddlToolbars");

                if (label == null || ddLToolB == null)
                {
                    continue;
                }

                if (label.Text.Equals("Unauthenticated Users"))
                {
                    listToolbarRoles.Add(new ToolbarRoles { RoleId = -1, Toolbar = ddLToolB.SelectedValue });
                }
                else
                {
                    RoleInfo objRole = RoleController.Instance.GetRoleByName(this._portalSettings.PortalId, label.Text);

                    listToolbarRoles.Add(new ToolbarRoles { RoleId = objRole.RoleID, Toolbar = ddLToolB.SelectedValue });
                }
            }

            exportSettings.ToolBarRoles = listToolbarRoles;

            var listUploadSizeRoles = new List<UploadSizeRoles>();

            // Save Upload File Limit Setting for every Role
            for (int i = 0; i < this.UploadFileLimits.Rows.Count; i++)
            {
                var label = (Label)this.UploadFileLimits.Rows[i].Cells[0].FindControl("lblRoleName");

                var sizeLimit = (TextBox)this.UploadFileLimits.Rows[i].Cells[1].FindControl("SizeLimit");

                if (label == null || string.IsNullOrEmpty(sizeLimit.Text))
                {
                    continue;
                }

                if (label.Text.Equals("Unauthenticated Users"))
                {
                    listUploadSizeRoles.Add(
                        new UploadSizeRoles { RoleId = -1, UploadFileLimit = Convert.ToInt32(sizeLimit.Text) });
                }
                else
                {
                    RoleInfo objRole = RoleController.Instance.GetRoleByName(this._portalSettings.PortalId, label.Text);

                    listUploadSizeRoles.Add(
                        new UploadSizeRoles
                            {
                                RoleId = objRole.RoleID,
                                UploadFileLimit = Convert.ToInt32(sizeLimit.Text)
                            });
                }
            }

            exportSettings.UploadSizeRoles = listUploadSizeRoles;

            return exportSettings;
        }
        /// <summary>
        /// Load All Editor Settings
        /// </summary>
        /// <param name="currentMode">The current mode.</param>
        /// <param name="changeMode">if set to <c>true</c> [change mode].</param>
        private void LoadSettings(int currentMode, bool changeMode = true)
        {
            this.CurrentSettingsMode = (SettingsMode)Enum.Parse(typeof(SettingsMode), currentMode.ToString());

            this.lnkRemoveAll.Visible = !currentMode.Equals(0);
            this.lnkRemoveChild.Visible = !currentMode.Equals(0);
            this.CopyToAllChild.Visible = !currentMode.Equals(0);

            this.lnkRemove.Text = string.Format(
                Localization.GetString("Remove.Text", this.ResXFile, this.LangCode),
                this.rBlSetMode.Items[currentMode].Text);
            this.lnkRemoveAll.Text =
                string.Format(
                    Localization.GetString("RemoveAll.Text", this.ResXFile, this.LangCode),
                    this.rBlSetMode.Items[currentMode].Text);

            this.lnkRemove.ToolTip = string.Format(
                Localization.GetString("Remove.Help", this.ResXFile, this.LangCode),
                this.rBlSetMode.Items[currentMode].Text);
            this.lnkRemoveAll.ToolTip =
                string.Format(
                    Localization.GetString("RemoveAll.Help", this.ResXFile, this.LangCode),
                    this.rBlSetMode.Items[currentMode].Text);

            this.LoadDefaultSettings();

            var settingsDictionary = EditorController.GetEditorHostSettings();
            var portalRoles = RoleController.Instance.GetRoles(this._portalSettings.PortalId);

            var portalKey = string.Format("DNNCKP#{0}#", this._portalSettings.PortalId);
            var pageKey = string.Format("DNNCKT#{0}#", this.CurrentOrSelectedTabId);
            var moduleKey = string.Format("DNNCKMI#{0}#INS#{1}#", this.ModuleId, this.moduleInstanceName);

            var providerConfiguration = ProviderConfiguration.GetProviderConfiguration("htmlEditor");
            var objProvider = (Provider)providerConfiguration.Providers[providerConfiguration.DefaultProvider];

            var currentSettings = SettingsUtil.GetDefaultSettings(
                this._portalSettings,
                this._portalSettings.HomeDirectoryMapPath,
                objProvider.Attributes["ck_configFolder"],
                portalRoles);

            switch (this.CurrentSettingsMode)
            {
                case SettingsMode.Portal:
                    {
                        // Load Portal Settings ?!
                        if (SettingsUtil.CheckExistsPortalOrPageSettings(settingsDictionary, portalKey))
                        {
                            currentSettings = new EditorProviderSettings();

                            currentSettings = SettingsUtil.LoadPortalOrPageSettings(
                                this._portalSettings, currentSettings, settingsDictionary, portalKey, portalRoles);

                            // Set Current Mode to Portal
                            currentSettings.SettingMode = SettingsMode.Portal;

                            this.lnkRemove.Enabled = true;
                        }
                        else
                        {
                            this.lnkRemove.Enabled = false;
                        }
                    }

                    break;
                case SettingsMode.Page:
                    {
                        // Load Page Settings ?!
                        if (SettingsUtil.CheckExistsPortalOrPageSettings(settingsDictionary, pageKey))
                        {
                            currentSettings = new EditorProviderSettings();

                            currentSettings = SettingsUtil.LoadPortalOrPageSettings(
                                this._portalSettings, currentSettings, settingsDictionary, pageKey, portalRoles);

                            // Set Current Mode to Page
                            currentSettings.SettingMode = SettingsMode.Page;

                            this.lnkRemove.Enabled = true;
                        }
                        else
                        {
                            this.lnkRemove.Enabled = false;
                        }

                        var currentTab = new TabController().GetTab(
                            this.CurrentOrSelectedTabId, this._portalSettings.PortalId, false);

                        this.lnkRemoveChild.Enabled = currentTab.HasChildren;

                        this.lnkRemoveChild.Text = Localization.GetString(
                                "RemovePageChild.Text", this.ResXFile, this.LangCode);
                        this.lnkRemoveChild.ToolTip = Localization.GetString(
                            "RemovePageChild.Help", this.ResXFile, this.LangCode);

                        this.CopyToAllChild.Enabled = currentTab.HasChildren;

                        this.CopyToAllChild.Text = Localization.GetString(
                                "CopyPageChild.Text", this.ResXFile, this.LangCode);
                        this.CopyToAllChild.ToolTip = Localization.GetString(
                            "CopyPageChild.Help", this.ResXFile, this.LangCode);
                    }

                    break;
                case SettingsMode.ModuleInstance:
                    {
                        // Load Module Settings ?!
                        if (SettingsUtil.CheckExistsModuleInstanceSettings(moduleKey, this.ModuleId))
                        {
                            currentSettings = new EditorProviderSettings();

                            currentSettings = SettingsUtil.LoadModuleSettings(
                                this._portalSettings, currentSettings, moduleKey, this.ModuleId, portalRoles);

                            currentSettings.SettingMode = SettingsMode.ModuleInstance;

                            this.lnkRemove.Enabled = true;
                        }
                        else
                        {
                            this.lnkRemove.Enabled = false;
                        }

                        this.lnkRemoveChild.Enabled = true;

                        this.lnkRemoveChild.Text = Localization.GetString(
                            "RemoveModuleChild.Text", this.ResXFile, this.LangCode);
                        this.lnkRemoveChild.ToolTip = Localization.GetString(
                            "RemoveModuleChild.Help", this.ResXFile, this.LangCode);
                    }

                    break;
            }

            if (currentSettings != null)
            {
                this.FillSettings(currentSettings, changeMode);
            }
        }
        /// <summary>
        /// Fills the setting controls with the loaded Setting Values.
        /// </summary>
        /// <param name="importedSettings">The imported settings.</param>
        /// <param name="changeMode">if set to <c>true</c> [change mode].</param>
        private void FillSettings(EditorProviderSettings importedSettings, bool changeMode = true)
        {
            // Editor config settings
            foreach (
                PropertyInfo info in
                    SettingsUtil.GetEditorConfigProperties())
            {
                object value = null;

                if (!info.Name.Equals("CodeMirror") && !info.Name.Equals("WordCount"))
                {
                    value = info.GetValue(importedSettings.Config, null);

                    if (value == null)
                    {
                        continue;
                    }
                }

                switch (info.PropertyType.Name)
                {
                    case "Decimal":
                    case "Int32":
                    case "String":
                        {
                            var textBox = Utility.FindControl<TextBox>(this.EditorConfigHolder, info.Name);

                            if (textBox != null)
                            {
                                textBox.Text = value.ToString();
                            }
                        }

                        break;
                    case "Boolean":
                        {
                            var checkBox = Utility.FindControl<CheckBox>(this.EditorConfigHolder, info.Name);

                            if (checkBox != null)
                            {
                                checkBox.Checked = (bool)value;
                            }
                        }

                        break;
                }

                switch (info.Name)
                {
                    case "ContentsLangDirection":
                    case "EnterMode":
                    case "ShiftEnterMode":
                    case "ToolbarLocation":
                    case "DefaultLinkType":
                        {
                            var dropDownList = Utility.FindControl<DropDownList>(this.EditorConfigHolder, info.Name);

                            if (dropDownList != null)
                            {
                                if (dropDownList.Items.FindByValue(value.ToString()) != null)
                                {
                                    dropDownList.ClearSelection();
                                    dropDownList.Items.FindByValue(value.ToString()).Selected = true;
                                }
                            }
                        }

                        break;
                    case "CodeMirror":
                        {
                            foreach (
                           var codeMirrorInfo in
                               typeof(CodeMirror).GetProperties()
                                                 .Where(codeMirrorInfo => !codeMirrorInfo.Name.Equals("Theme")))
                            {
                                value = codeMirrorInfo.GetValue(importedSettings.Config.CodeMirror, null);

                                if (value == null)
                                {
                                    continue;
                                }

                                switch (codeMirrorInfo.PropertyType.Name)
                                {
                                    case "String":
                                        {
                                            var textBox = Utility.FindControl<TextBox>(this.EditorConfigHolder, codeMirrorInfo.Name);

                                            if (textBox != null)
                                            {
                                                textBox.Text = value.ToString();
                                            }
                                        }

                                        break;

                                    case "Boolean":
                                        {
                                            var checkBox = Utility.FindControl<CheckBox>(this.EditorConfigHolder, codeMirrorInfo.Name);

                                            if (checkBox != null)
                                            {
                                                checkBox.Checked = (bool)value;
                                            }
                                        }

                                        break;
                                }
                            }
                        }

                        break;
                    case "WordCount":
                        {
                            foreach (var wordCountInfo in typeof(WordCountConfig).GetProperties())
                            {
                                value = wordCountInfo.GetValue(importedSettings.Config.WordCount, null);

                                if (value == null)
                                {
                                    continue;
                                }

                                switch (wordCountInfo.PropertyType.Name)
                                {
                                    case "String":
                                        {
                                            var textBox = Utility.FindControl<TextBox>(this.EditorConfigHolder, wordCountInfo.Name);

                                            if (textBox != null)
                                            {
                                                textBox.Text = value.ToString();
                                            }
                                        }

                                        break;

                                    case "Boolean":
                                        {
                                            var checkBox = Utility.FindControl<CheckBox>(this.EditorConfigHolder, wordCountInfo.Name);

                                            if (checkBox != null)
                                            {
                                                checkBox.Checked = (bool)value;
                                            }
                                        }

                                        break;
                                }
                            }
                        }

                        break;
                }
            }
            ///////////////////

            if (!string.IsNullOrEmpty(importedSettings.Config.Skin)
                && this.ddlSkin.Items.FindByValue(importedSettings.Config.Skin) != null)
            {
                this.ddlSkin.ClearSelection();
                this.ddlSkin.SelectedValue = importedSettings.Config.Skin;
            }

            if (!string.IsNullOrEmpty(importedSettings.Config.CodeMirror.Theme)
                && this.CodeMirrorTheme.Items.FindByValue(importedSettings.Config.CodeMirror.Theme) != null)
            {
                this.CodeMirrorTheme.ClearSelection();
                this.CodeMirrorTheme.SelectedValue = importedSettings.Config.CodeMirror.Theme;
            }

            if (!string.IsNullOrEmpty(importedSettings.Browser)
                && this.ddlBrowser.Items.FindByValue(importedSettings.Browser) != null)
            {
                this.ddlBrowser.ClearSelection();
                this.ddlBrowser.SelectedValue = importedSettings.Browser;
            }

            this.FileListPageSize.Text = importedSettings.FileListPageSize.ToString();

            this.FileListViewMode.SelectedValue = importedSettings.FileListViewMode.ToString();
            this.DefaultLinkMode.SelectedValue = importedSettings.DefaultLinkMode.ToString();
            this.UseAnchorSelector.Checked = importedSettings.UseAnchorSelector;
            this.ShowPageLinksTabFirst.Checked = importedSettings.ShowPageLinksTabFirst;

            this.cbBrowserDirs.Checked = importedSettings.SubDirs;

            this.OverrideFileOnUpload.Checked = importedSettings.OverrideFileOnUpload;

            this.BrowserRootDir.SelectedValue =
                 this.BrowserRootDir.Items.FindByValue(importedSettings.BrowserRootDirId.ToString()) != null
                     ? importedSettings.BrowserRootDirId.ToString()
                     : "-1";

            this.UploadDir.SelectedValue = this.UploadDir.Items.FindByValue(importedSettings.UploadDirId.ToString())
                                           != null
                                               ? importedSettings.UploadDirId.ToString()
                                               : "-1";

            var configFolderInfo =
                Utility.ConvertFilePathToFolderInfo(
                    !string.IsNullOrEmpty(this.configFolder)
                        ? Path.Combine(this._portalSettings.HomeDirectoryMapPath, this.configFolder)
                        : this._portalSettings.HomeDirectoryMapPath,
                    this._portalSettings);

            this.ExportDir.SelectedValue = configFolderInfo != null
                                           &&
                                           this.ExportDir.Items.FindByValue(configFolderInfo.FolderID.ToString())
                                           != null
                                               ? configFolderInfo.FolderID.ToString()
                                               : "-1";

            this.ExportFileName.Text = string.Format("CKEditorSettings-{0}.xml", importedSettings.SettingMode);

            switch (importedSettings.SettingMode)
            {
                case SettingsMode.Portal:
                    this.ExportFileName.Text = string.Format(
                        "CKEditorSettings-{0}-{1}.xml", importedSettings.SettingMode, this._portalSettings.PortalId);
                    break;
                case SettingsMode.Page:
                    this.ExportFileName.Text = string.Format(
                        "CKEditorSettings-{0}-{1}.xml", importedSettings.SettingMode, this.CurrentOrSelectedTabId);
                    break;
                case SettingsMode.ModuleInstance:
                    this.ExportFileName.Text = string.Format(
                        "CKEditorSettings-{0}-{1}.xml", importedSettings.SettingMode, this.ModuleId);
                    break;
            }

            this.txtResizeHeight.Text = importedSettings.ResizeWidth.ToString();

            this.txtResizeHeight.Text = importedSettings.ResizeHeight.ToString();

            this.InjectSyntaxJs.Checked = importedSettings.InjectSyntaxJs;

            if (Utility.IsUnit(importedSettings.Config.Width))
            {
                this.txtWidth.Text = importedSettings.Config.Width;
            }

            if (Utility.IsUnit(importedSettings.Config.Height))
            {
                this.txtHeight.Text = importedSettings.Config.Height;
            }

            if (!string.IsNullOrEmpty(importedSettings.BlankText))
            {
                this.txtBlanktext.Text = importedSettings.BlankText;
            }

            List<ToolbarRoles> imporToolbarRoles = importedSettings.ToolBarRoles;

            // Load Toolbar Setting for Each Portal Role
            foreach (ToolbarRoles objToolbRoles in imporToolbarRoles)
            {
                if (objToolbRoles.RoleId.Equals(-1))
                {
                    for (int i = 0; i < this.gvToolbars.Rows.Count; i++)
                    {
                        Label label = (Label)this.gvToolbars.Rows[i].Cells[0].FindControl("lblRoleName");

                        if (label == null || !label.Text.Equals("Unauthenticated Users"))
                        {
                            continue;
                        }

                        DropDownList ddLToolB =
                            (DropDownList)this.gvToolbars.Rows[i].Cells[1].FindControl("ddlToolbars");

                        ddLToolB.ClearSelection();

                        if (ddLToolB.Items.FindByValue(objToolbRoles.Toolbar) != null)
                        {
                            ddLToolB.SelectedValue = objToolbRoles.Toolbar;
                        }
                    }
                }
                else
                {
                    RoleInfo objRole = RoleController.Instance.GetRoleById(objToolbRoles.RoleId, this._portalSettings.PortalId);

                    if (objRole == null)
                    {
                        continue;
                    }

                    for (int i = 0; i < this.gvToolbars.Rows.Count; i++)
                    {
                        Label label = (Label)this.gvToolbars.Rows[i].Cells[0].FindControl("lblRoleName");

                        if (label == null || !label.Text.Equals(objRole.RoleName))
                        {
                            continue;
                        }

                        DropDownList ddLToolB =
                            (DropDownList)this.gvToolbars.Rows[i].Cells[1].FindControl("ddlToolbars");

                        ddLToolB.ClearSelection();

                        if (ddLToolB.Items.FindByValue(objToolbRoles.Toolbar) != null)
                        {
                            ddLToolB.SelectedValue = objToolbRoles.Toolbar;
                        }
                    }
                }
            }

            var imporUploadSizeRoles = importedSettings.UploadSizeRoles;

            // Load Upload Size Setting for Each Portal Role
            foreach (var uploadSizeRole in imporUploadSizeRoles)
            {
                if (uploadSizeRole.RoleId.Equals(-1))
                {
                    for (int i = 0; i < this.UploadFileLimits.Rows.Count; i++)
                    {
                        Label label = (Label)this.UploadFileLimits.Rows[i].Cells[0].FindControl("lblRoleName");

                        if (label == null || !label.Text.Equals("Unauthenticated Users"))
                        {
                            continue;
                        }

                        var sizeLimit =
                            (TextBox)this.UploadFileLimits.Rows[i].Cells[1].FindControl("SizeLimit");

                        sizeLimit.Text = uploadSizeRole.UploadFileLimit.ToString();
                    }
                }
                else
                {
                    RoleInfo objRole = RoleController.Instance.GetRoleById(uploadSizeRole.RoleId, this._portalSettings.PortalId);

                    if (objRole == null)
                    {
                        continue;
                    }

                    for (int i = 0; i < this.UploadFileLimits.Rows.Count; i++)
                    {
                        Label label = (Label)this.UploadFileLimits.Rows[i].Cells[0].FindControl("lblRoleName");

                        if (label == null || !label.Text.Equals(objRole.RoleName))
                        {
                            continue;
                        }

                        var sizeLimit =
                            (TextBox)this.UploadFileLimits.Rows[i].Cells[1].FindControl("SizeLimit");

                        sizeLimit.Text = uploadSizeRole.UploadFileLimit.ToString();
                    }
                }
            }

            if (!string.IsNullOrEmpty(importedSettings.Config.ContentsCss))
            {
                this.CssUrl.Url = this.ReFormatURL(importedSettings.Config.ContentsCss);
            }

            if (!string.IsNullOrEmpty(importedSettings.Config.Templates_Files))
            {
                this.TemplUrl.Url = this.ReFormatURL(importedSettings.Config.Templates_Files);
            }

            if (!string.IsNullOrEmpty(importedSettings.CustomJsFile))
            {
                this.CustomJsFile.Url = this.ReFormatURL(importedSettings.CustomJsFile);
            }

            if (!string.IsNullOrEmpty(importedSettings.Config.CustomConfig))
            {
                this.ConfigUrl.Url = this.ReFormatURL(importedSettings.Config.CustomConfig);
            }

            if (!string.IsNullOrEmpty(importedSettings.BrowserRoles))
            {
                string sRoles = importedSettings.BrowserRoles;

                if (sRoles.Length >= 1 && sRoles.Contains(";"))
                {
                    string[] roles = sRoles.Split(';');

                    foreach (string sRoleName in roles)
                    {
                        if (Utility.IsNumeric(sRoleName))
                        {
                            if (this.chblBrowsGr.Items.FindByValue(sRoleName) != null)
                            {
                                this.chblBrowsGr.Items.FindByValue(sRoleName).Selected = true;
                            }
                        }
                        else
                        {
                            if (this.chblBrowsGr.Items.FindByText(sRoleName) != null)
                            {
                                this.chblBrowsGr.Items.FindByText(sRoleName).Selected = true;
                            }
                        }
                    }
                }
            }

            if (!changeMode)
            {
                return;
            }

            switch (importedSettings.SettingMode)
            {
                case SettingsMode.Portal:
                    this.rBlSetMode.SelectedIndex = 0;
                    break;
                case SettingsMode.Page:
                    this.rBlSetMode.SelectedIndex = 1;
                    break;
                case SettingsMode.ModuleInstance:
                    this.rBlSetMode.SelectedIndex = 2;
                    break;
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// Handles the Load event of the Page control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        protected void Page_Load(object sender, EventArgs e)
        {
            JavaScript.RequestRegistration(CommonJs.jQuery);

            this.SortAscending.CssClass = this.SortFilesDescending ? "ButtonNormal" : "ButtonSelected";
            this.SortDescending.CssClass = !this.SortFilesDescending ? "ButtonNormal" : "ButtonSelected";

            this.extensionWhiteList = HostController.Instance.GetString("FileExtensions").ToLower();

            if (!string.IsNullOrEmpty(this.request.QueryString["mode"]))
            {
                this.currentSettings.SettingMode =
                    (SettingsMode)Enum.Parse(typeof(SettingsMode), this.request.QueryString["mode"]);
            }

            ProviderConfiguration providerConfiguration = ProviderConfiguration.GetProviderConfiguration("htmlEditor");
            Provider objProvider = (Provider)providerConfiguration.Providers[providerConfiguration.DefaultProvider];

            var settingsDictionary = EditorController.GetEditorHostSettings();

            var portalRoles = RoleController.Instance.GetRoles(this._portalSettings.PortalId);

            switch (this.currentSettings.SettingMode)
            {
                case SettingsMode.Default:
                    // Load Default Settings
                    this.currentSettings = SettingsUtil.GetDefaultSettings(
                        this._portalSettings,
                        this._portalSettings.HomeDirectoryMapPath,
                        objProvider.Attributes["ck_configFolder"],
                        portalRoles);
                    break;
                case SettingsMode.Portal:
                    this.currentSettings = SettingsUtil.LoadPortalOrPageSettings(
                        this._portalSettings,
                        this.currentSettings,
                        settingsDictionary,
                        string.Format("DNNCKP#{0}#", this.request.QueryString["PortalID"]),
                        portalRoles);
                    break;
                case SettingsMode.Page:
                    this.currentSettings = SettingsUtil.LoadPortalOrPageSettings(
                        this._portalSettings,
                        this.currentSettings,
                        settingsDictionary,
                        string.Format("DNNCKT#{0}#", this.request.QueryString["tabid"]),
                        portalRoles);
                    break;
                case SettingsMode.ModuleInstance:
                    this.currentSettings = SettingsUtil.LoadModuleSettings(
                        this._portalSettings,
                        this.currentSettings,
                        string.Format(
                            "DNNCKMI#{0}#INS#{1}#", this.request.QueryString["mid"], this.request.QueryString["ckId"]),
                        int.Parse(this.request.QueryString["mid"]),
                        portalRoles);
                    break;
            }

            // set current Upload file size limit
            this.currentSettings.UploadFileSizeLimit = SettingsUtil.GetCurrentUserUploadSize(
                this.currentSettings,
                this._portalSettings,
                HttpContext.Current.Request);

            if (this.currentSettings.BrowserMode.Equals(Constants.BrowserType.StandardBrowser)
                && HttpContext.Current.Request.IsAuthenticated)
            {
                string command = null;

                try
                {
                    if (this.request.QueryString["Command"] != null)
                    {
                        command = this.request.QueryString["Command"];
                    }
                }
                catch (Exception)
                {
                    command = null;
                }

                try
                {
                    if (this.request.QueryString["Type"] != null)
                    {
                        this.browserModus = this.request.QueryString["Type"];
                        this.lblModus.Text = string.Format("Browser-Modus: {0}", this.browserModus);

                        if (!this.IsPostBack)
                        {
                            this.GetAcceptedFileTypes();

                            this.title.InnerText = string.Format("{0} - DNNConnect.CKEditorProvider.FileBrowser", this.lblModus.Text);

                            this.AnchorList.Visible = this.currentSettings.UseAnchorSelector;
                            this.LabelAnchor.Visible = this.currentSettings.UseAnchorSelector;

                            this.ListViewState.Value = this.currentSettings.FileListViewMode.ToString();

                            // Set default link mode
                            switch (this.currentSettings.DefaultLinkMode)
                            {
                                case LinkMode.RelativeURL:
                                    this.rblLinkType.SelectedValue = "relLink";
                                    break;
                                case LinkMode.AbsoluteURL:
                                    this.rblLinkType.SelectedValue = "absLnk";
                                    break;
                                case LinkMode.RelativeSecuredURL:
                                    this.rblLinkType.SelectedValue = "lnkClick";
                                    break;
                                case LinkMode.AbsoluteSecuredURL:
                                    this.rblLinkType.SelectedValue = "lnkAbsClick";
                                    break;
                            }

                            switch (this.browserModus)
                            {
                                case "Link":
                                    this.BrowserMode.Visible = true;

                                    if (this.currentSettings.ShowPageLinksTabFirst)
                                    {
                                        this.BrowserMode.SelectedValue = "page";
                                        this.panLinkMode.Visible = false;
                                        this.panPageMode.Visible = true;

                                        this.TrackClicks.Visible = false;
                                        this.lblModus.Text = string.Format(
                                            "Browser-Modus: {0}",
                                            string.Format("Page {0}", this.browserModus));
                                        this.title.InnerText = string.Format(
                                            "{0} - DNNConnect.CKEditorProvider.FileBrowser",
                                            this.lblModus.Text);

                                        this.RenderTabs();
                                    }
                                    else
                                    {
                                        this.BrowserMode.SelectedValue = "file";
                                        this.panPageMode.Visible = false;
                                    }

                                    break;
                                case "Image":
                                    this.BrowserMode.Visible = false;
                                    this.panPageMode.Visible = false;
                                    break;
                                case "Flash":
                                    this.BrowserMode.Visible = false;
                                    this.panPageMode.Visible = false;
                                    break;
                                default:
                                    this.BrowserMode.Visible = false;
                                    this.panPageMode.Visible = false;
                                    break;
                            }
                        }
                    }
                }
                catch (Exception)
                {
                    this.browserModus = null;
                }

                if (command != null)
                {
                    if (!command.Equals("FileUpload") && !command.Equals("FlashUpload")
                        && !command.Equals("ImageUpload"))
                    {
                        return;
                    }

                    var uploadedFile =
                        HttpContext.Current.Request.Files[HttpContext.Current.Request.Files.AllKeys[0]];

                    if (uploadedFile != null)
                    {
                        this.UploadFile(uploadedFile, command);
                    }
                }
                else
                {
                    if (!this.IsPostBack)
                    {
                        this.OverrideFile.Checked = this.currentSettings.OverrideFileOnUpload;

                        this.SetLanguage();

                        this.GetLanguageList();

                        var startFolder = this.StartingDir();

                        if (!Utility.IsInRoles(this._portalSettings.AdministratorRoleName, this._portalSettings))
                        {
                            // Hide physical file Path
                            this.lblCurrentDir.Visible = false;
                            this.lblCurrent.Visible = false;
                        }

                        this.FillFolderTree(startFolder);

                        bool folderSelected = false;

                        if (!string.IsNullOrEmpty(ckFileUrl))
                        {
                            try
                            {
                                folderSelected = this.SelectFolderFile(ckFileUrl);
                                ckFileUrl = null;
                            }
                            catch (Exception)
                            {
                                folderSelected = false;
                                ckFileUrl = null;
                            }
                        }

                        if (!folderSelected)
                        {
                            this.lblCurrentDir.Text = startFolder.PhysicalPath;

                            this.ShowFilesIn(startFolder);
                        }
                    }

                    this.FillQualityPrecentages();
                }
            }
            else
            {
                var errorScript = string.Format(
                    "javascript:alert('{0}');self.close();",
                    Localization.GetString("Error1.Text", this.ResXFile, this.LanguageCode));

                this.Response.Write("<script type=\"text/javascript\">");
                this.Response.Write(errorScript);
                this.Response.Write("</script>");

                this.Response.End();
            }
        }