public static string GetEditorToolbarMarkupForRazor(int moduleid, string uid, string BrowseUrl, string Profile)
        {
            if (HTMLEditor_Profile.Query("").Count() < 4)
            {
                GetHTMLEditorProfiles(-1);
            }

            string             result            = string.Empty;
            HTMLEditor_Profile HTMLEditorProfile = null;
            HTMLEditor         HTMLEditor        = null;

            if (!string.IsNullOrEmpty(uid))
            {
                uid        = uid = uid.ToLower().Trim();
                HTMLEditor = HTMLEditor.Query("where UID=@0", uid).SingleOrDefault();
                if (HTMLEditor != null)
                {
                    HTMLEditorProfile = HTMLEditor_Profile.Query("where ProfileID=@0", HTMLEditor.ProfileID).SingleOrDefault();
                }

                if (HTMLEditorProfile == null)
                {
                    string Preset = "Basic";
                    if (!string.IsNullOrEmpty(Profile))
                    {
                        Preset = Profile;
                    }

                    int ProfileID = 0;
                    if (HTMLEditor != null)
                    {
                        ProfileID = HTMLEditor.ProfileID;
                        if (ProfileID == 0)
                        {
                            Preset = "Basic";
                        }

                        if (ProfileID == -1)
                        {
                            Preset = "Standard";
                        }

                        if (ProfileID == -2)
                        {
                            Preset = "Full";
                        }

                        if (ProfileID == -3)
                        {
                            Preset = "Minimal";
                        }
                    }
                    else
                    {
                        switch (Preset)
                        {
                        case "Standard":
                            ProfileID = -1;
                            break;

                        case "Full":
                            ProfileID = -2;
                            break;

                        case "Minimal":
                            ProfileID = -3;
                            break;

                        default:
                            ProfileID = 0;
                            break;
                        }
                    }
                    EditorOptions EditorOptions = new EditorOptions
                    {
                        Plugins = GetPluginsKeyValueSaved(ProfileID)
                    };
                    HTMLEditorProfile = new HTMLEditor_Profile()
                    {
                        ProfileID = ProfileID, PortalID = -1, Name = Preset, Value = DotNetNuke.Common.Utilities.Json.Serialize(EditorOptions)
                    };
                }
            }
            if (HTMLEditorProfile != null)
            {
                EditorOptions editorOptions = DotNetNuke.Common.Utilities.Json.Deserialize <EditorOptions>(HTMLEditorProfile.Value);
                if (editorOptions != null)
                {
                    StringBuilder sb = new StringBuilder();
                    sb.Append("{");
                    if (!string.IsNullOrEmpty(editorOptions.Height))
                    {
                        sb.Append("\"height\": \"" + editorOptions.Height + "\",");
                    }

                    if (!string.IsNullOrEmpty(editorOptions.Width))
                    {
                        sb.Append("\"width\": \"" + editorOptions.Width + "\",");
                    }

                    if (!string.IsNullOrEmpty(editorOptions.UiColor))
                    {
                        sb.Append("\"uiColor\": \"" + editorOptions.UiColor + "\",");
                    }

                    if (editorOptions.FilebrowserBrowseUrl && PortalSettings.Current.UserInfo.UserID > 0)
                    {
                        sb.Append("\"filebrowserBrowseUrl\": \"" + BrowseUrl + "&type=filebrowserBrowseUrl#/common/controls/url/" + uid.Replace(moduleid.ToString(), "") + "\",");
                    }

                    if (editorOptions.FilebrowserImageBrowseUrl && PortalSettings.Current.UserInfo.UserID > 0)
                    {
                        sb.Append("\"filebrowserImageBrowseUrl\": \"" + BrowseUrl + "&type=filebrowserImageBrowseUrl#/common/controls/url/" + uid.Replace(moduleid.ToString(), "") + "\",");
                    }

                    if (HTMLEditorProfile.ProfileID == -3)
                    {
                        sb.Append("\"removeButtons\": \"Cut,Copy,Paste,Undo,Redo,Anchor,Underline,Strike,Subscript,Superscript,Outdent,Indent\",");
                    }
                    else
                    {
                        sb.Append("\"removeButtons\": \"\",");
                    }

                    sb.Append("\"disableNativeSpellChecker\": false,");
                    if (HTMLEditor != null && !string.IsNullOrEmpty(HTMLEditor.Settings))
                    {
                        HTMLEditorSetting HTMLEditorSetting = DotNetNuke.Common.Utilities.Json.Deserialize <HTMLEditorSetting>(HTMLEditor.Settings);
                        if (HTMLEditorSetting != null)
                        {
                            sb.Append("\"fullPage\": " + HTMLEditorSetting.FullPageMode.ToString().ToLower() + ",");
                        }
                    }
                    if (HTMLEditorProfile.ProfileID != -3)
                    {
                        sb.Append("\"allowedContent\": true,");
                    }

                    sb.Append("\"extraPlugins\": \"" + GetPlugins(editorOptions) + "\"");
                    sb.Append("}");
                    result = sb.ToString();
                }
            }
            return(result);
        }
        public bool SaveEditorProfile(string uid, int profileid, string applyto, HTMLEditorSetting settings)
        {
            if (!string.IsNullOrEmpty(uid) && !string.IsNullOrEmpty(applyto))
            {
                string uniqueUid = uid;
                try
                {
                    switch (applyto)
                    {
                    case "CurrentModule":
                    {
                        if (ActiveModule != null)
                        {
                            uid = uniqueUid.ToLower().Trim() + ActiveModule.ModuleID;
                        }
                        else
                        {
                            uid = uniqueUid.ToLower().Trim() + "0";
                        }

                        HTMLEditor HTMLEditor = HTMLEditor.Query("where UID=@0", uid).SingleOrDefault();
                        if (HTMLEditor != null)
                        {
                            HTMLEditor.ProfileID = profileid;
                            HTMLEditor.Settings  = DotNetNuke.Common.Utilities.Json.Serialize(settings);
                            HTMLEditor.Update();
                        }
                        else
                        {
                            HTMLEditor = new HTMLEditor
                            {
                                ProfileID = profileid,
                                UID       = uid,
                                Settings  = DotNetNuke.Common.Utilities.Json.Serialize(settings),
                                PortalID  = PortalSettings.ActiveTab.PortalID,
                                TabID     = PortalSettings.ActiveTab.TabID
                            };
                            HTMLEditor.Insert();
                        }
                        break;
                    }

                    case "PageModule":
                    {
                        foreach (ModuleInfo moduleinfo in EditorConfigFactory.GetTabModules(ActiveModule))
                        {
                            uid = uniqueUid.ToLower().Trim() + moduleinfo.ModuleID;
                            HTMLEditor HTMLEditor = HTMLEditor.Query("where UID=@0", uid).SingleOrDefault();
                            if (HTMLEditor != null)
                            {
                                HTMLEditor.ProfileID = profileid;
                                HTMLEditor.Settings  = DotNetNuke.Common.Utilities.Json.Serialize(settings);
                                HTMLEditor.Update();
                            }
                            else
                            {
                                HTMLEditor = new HTMLEditor
                                {
                                    ProfileID = profileid,
                                    UID       = uid,
                                    Settings  = DotNetNuke.Common.Utilities.Json.Serialize(settings)
                                };
                                HTMLEditor.Insert();
                            }
                        }
                        break;
                    }

                    case "PortalModule":
                    {
                        foreach (ModuleInfo moduleinfo in EditorConfigFactory.GetPortalModules(ActiveModule))
                        {
                            uid = uniqueUid.ToLower().Trim() + moduleinfo.ModuleID;
                            HTMLEditor HTMLEditor = HTMLEditor.Query("where UID=@0", uid).SingleOrDefault();
                            if (HTMLEditor != null)
                            {
                                HTMLEditor.ProfileID = profileid;
                                HTMLEditor.Settings  = DotNetNuke.Common.Utilities.Json.Serialize(settings);
                                HTMLEditor.Update();
                            }
                            else
                            {
                                HTMLEditor = new HTMLEditor
                                {
                                    ProfileID = profileid,
                                    UID       = uid,
                                    Settings  = DotNetNuke.Common.Utilities.Json.Serialize(settings)
                                };
                                HTMLEditor.Insert();
                            }
                        }
                        break;
                    }

                    default:
                        goto case "CurrentModule";
                    }
                    return(true);
                }
                catch (Exception ex)
                {
                    DotNetNuke.Services.Exceptions.Exceptions.LogException(ex);
                }
            }
            return(false);
        }
        internal static List <IUIData> GetData(PortalSettings portalSettings, ModuleInfo moduleInfo, Dictionary <string, string> parameters)
        {
            int PortalID = portalSettings.PortalId;
            int ModuleID = 0;

            if (moduleInfo != null)
            {
                ModuleID = moduleInfo.ModuleID;
            }

            string profile = string.Empty;

            if (HttpContext.Current != null && HttpContext.Current.Request != null && HttpContext.Current.Request.UrlReferrer != null && HttpContext.Current.Request.UrlReferrer.ToString().Contains("profile="))
            {
                profile = HttpContext.Current.Request.UrlReferrer.ToString().Split('=').Last();
            }
            else if (HttpContext.Current != null && HttpContext.Current.Request != null && HttpContext.Current.Request.UrlReferrer != null && HttpContext.Current.Request.UrlReferrer.ToString().Contains("profile/"))
            {
                profile = HttpContext.Current.Request.UrlReferrer.ToString().Split('/').Last();
                if (profile.Contains('?'))
                {
                    profile = profile.Split('?').First();
                }
            }
            Dictionary <string, IUIData> Settings           = new Dictionary <string, IUIData>();
            List <HTMLEditor_Profile>    HTMLEditorProfiles = GetHTMLEditorProfiles(PortalID);
            int ProfileID = 0;

            Settings.Add("UID", new UIData()
            {
                Name = "UID", Value = parameters.Where(p => p.Key == "uid").FirstOrDefault().Value
            });
            HTMLEditor Editor = HTMLEditor.Query("where UID=@0", Settings["UID"].Value + ModuleID).SingleOrDefault();

            if (Editor != null)
            {
                ProfileID = Editor.ProfileID;
                HTMLEditorSetting HTMLEditorSetting = DotNetNuke.Common.Utilities.Json.Deserialize <HTMLEditorSetting>(Editor.Settings);
                if (HTMLEditorSetting.UploadFilesRootFolder == 0)
                {
                    HTMLEditorSetting.UploadFilesRootFolder = BrowseUploadFactory.GetRootFolder(PortalID).FolderID;
                }

                if (HTMLEditorSetting.UploadImagesRootFolder == 0)
                {
                    HTMLEditorSetting.UploadImagesRootFolder = BrowseUploadFactory.GetRootFolder(PortalID).FolderID;
                }

                Settings.Add("Settings", new UIData()
                {
                    Name = "Settings", Options = HTMLEditorSetting
                });
            }
            else
            {
                if (!string.IsNullOrEmpty(profile) && HTMLEditorProfiles.Where(p => p.Name.ToLower() == profile.ToLower()).FirstOrDefault() != null)
                {
                    ProfileID = HTMLEditorProfiles.Where(p => p.Name.ToLower() == profile.ToLower()).FirstOrDefault().ProfileID;
                }

                HTMLEditorSetting HTMLEditorSetting = new HTMLEditorSetting();
                HTMLEditorSetting.UploadFilesRootFolder = HTMLEditorSetting.UploadImagesRootFolder = BrowseUploadFactory.GetRootFolder(PortalID).FolderID;
                Settings.Add("Settings", new UIData()
                {
                    Name = "Settings", Options = HTMLEditorSetting
                });
            }

            Settings.Add("Profiles", new UIData()
            {
                Name = "Profiles", Options = HTMLEditorProfiles, Value = ProfileID.ToString()
            });
            Settings.Add("EditorOptions", new UIData()
            {
                Name = "EditorOptions", Options = GetEditorOptions(HTMLEditorProfiles, int.Parse(Settings["Profiles"].Value))
            });
            Settings.Add("LocalizationKeyValue", new UIData()
            {
                Name = "LocalizationKeyValue", Options = getLocalizationKeyValue()
            });
            Settings.Add("Folders", new UIData()
            {
                Name = "Folders", Options = BrowseUploadFactory.GetFolders(PortalID)
            });
            Settings.Add("IsSuperUser", new UIData()
            {
                Name = "IsSuperUser", Value = PortalSettings.Current.UserInfo.IsSuperUser.ToString()
            });
            Settings.Add("ModuleID", new UIData()
            {
                Name = "ModuleID", Value = ModuleID.ToString()
            });
            return(Settings.Values.ToList());
        }