protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            // add ids to controls
            _width.ID  = "width";
            _height.ID = "height";


            // initialize validators
            _widthValidator.ValidationExpression = "0*[1-9][0-9]*";
            _widthValidator.ErrorMessage         = ui.Text("errorHandling", "errorIntegerWithoutTab", ui.Text("width"), new BasePages.BasePage().getUser());
            _widthValidator.Display                      = ValidatorDisplay.Dynamic;
            _widthValidator.ControlToValidate            = _width.ID;
            _heightValidator.ValidationExpression        = "0*[1-9][0-9]*";
            _heightValidator.ErrorMessage                = ui.Text("errorHandling", "errorIntegerWithoutTab", ui.Text("height"), new BasePages.BasePage().getUser());
            _heightValidator.ControlToValidate           = _height.ID;
            _heightValidator.Display                     = ValidatorDisplay.Dynamic;
            _maxImageWidthValidator.ValidationExpression = "0*[1-9][0-9]*";
            _maxImageWidthValidator.ErrorMessage         = ui.Text("errorHandling", "errorIntegerWithoutTab", "'" + ui.Text("rteMaximumDefaultImgSize") + "'", new BasePages.BasePage().getUser());
            _maxImageWidthValidator.ControlToValidate    = _maxImageWidth.ID;
            _maxImageWidthValidator.Display              = ValidatorDisplay.Dynamic;

            if (!Page.IsPostBack)
            {
                if (Configuration != null)
                {
                    string[] config = Configuration.Split("|".ToCharArray());
                    if (config.Length > 0)
                    {
                        _selectedButtons = config[0];

                        if (config.Length > 1)
                        {
                            if (config[1] == "1")
                            {
                                _enableRightClick.Checked = true;
                            }
                        }

                        if (config.Length > 2)
                        {
                            _advancedUsers = config[2];
                        }

                        if (config.Length > 4 && config[4].Split(',').Length > 1)
                        {
                            //                        if (config[3] == "1")
                            //                            _fullWidth.Checked = true;
                            //                        else
                            //                        {
                            _width.Text  = config[4].Split(',')[0];
                            _height.Text = config[4].Split(',')[1];
                            //                        }
                        }

                        // if width and height are empty or lower than 0 then set default sizes:
                        int tempWidth, tempHeight;
                        int.TryParse(_width.Text, out tempWidth);
                        int.TryParse(_height.Text, out tempHeight);
                        if (_width.Text.Trim() == "" || tempWidth < 1)
                        {
                            _width.Text = "500";
                        }
                        if (_height.Text.Trim() == "" || tempHeight < 1)
                        {
                            _height.Text = "400";
                        }

                        if (config.Length > 5)
                        {
                            _stylesheets = config[5];
                        }
                        if (config.Length > 6 && config[6] != "")
                        {
                            _showLabel.Checked = bool.Parse(config[6]);
                        }

                        if (config.Length > 7 && config[7] != "")
                        {
                            _maxImageWidth.Text = config[7];
                        }
                        else
                        {
                            _maxImageWidth.Text = "500";
                        }
                    }

                    // add editor buttons
                    IDictionaryEnumerator ide = tinyMCEConfiguration.SortedCommands.GetEnumerator();
                    while (ide.MoveNext())
                    {
                        tinyMCECommand cmd = (tinyMCECommand)ide.Value;
                        ListItem       li  =
                            new ListItem(
                                string.Format("<img src=\"{0}\" class=\"tinymceIcon\" alt=\"{1}\" />&nbsp;", cmd.Icon,
                                              cmd.Alias), cmd.Alias);
                        if (_selectedButtons.IndexOf(cmd.Alias) > -1)
                        {
                            li.Selected = true;
                        }

                        _editorButtons.Items.Add(li);
                    }

                    // add users
                    var userService = ApplicationContext.Current.Services.UserService;
                    foreach (var ug in userService.GetAllUserGroups())
                    {
                        ListItem li = new ListItem(ug.Name, ug.Id.ToString());
                        if (("," + _advancedUsers + ",").IndexOf("," + ug.Id + ",") > -1)
                        {
                            li.Selected = true;
                        }

                        _advancedUsersList.Items.Add(li);
                    }

                    // add stylesheets
                    foreach (cms.businesslogic.web.StyleSheet st in cms.businesslogic.web.StyleSheet.GetAll())
                    {
                        ListItem li = new ListItem(st.Text, st.Id.ToString());
                        if (("," + _stylesheets + ",").IndexOf("," + st.Id.ToString() + ",") > -1)
                        {
                            li.Selected = true;
                        }

                        _stylesheetList.Items.Add(li);
                    }
                }

                // Mark the current db type
                _dropdownlist.SelectedValue = _datatype.DBType.ToString();
            }
        }
Esempio n. 2
0
        public TinyMCE(IData Data, string Configuration)
        {
            _data = Data;
            string[] configSettings = Configuration.Split("|".ToCharArray());

            if (configSettings.Length > 0)
            {
                _editorButtons = configSettings[0];

                if (configSettings.Length > 1)
                {
                    if (configSettings[1] == "1")
                    {
                        _enableContextMenu = true;
                    }
                }

                if (configSettings.Length > 2)
                {
                    _advancedUsers = configSettings[2];
                }

                if (configSettings.Length > 3)
                {
                    if (configSettings[3] == "1")
                    {
                        _fullWidth = true;
                    }
                    else if (configSettings[4].Split(',').Length > 1)
                    {
                        _width  = int.Parse(configSettings[4].Split(',')[0]);
                        _height = int.Parse(configSettings[4].Split(',')[1]);
                    }
                }

                // default width/height
                if (_width < 1)
                {
                    _width = 500;
                }
                if (_height < 1)
                {
                    _height = 400;
                }

                // add stylesheets
                if (configSettings.Length > 4)
                {
                    foreach (string s in configSettings[5].Split(",".ToCharArray()))
                    {
                        _stylesheets.Add(s);
                    }
                }

                // sizing
                if (!_fullWidth)
                {
                    config.Add("width", _width.ToString());
                    config.Add("height", _height.ToString());
                }

                if (_enableContextMenu)
                {
                    _plugins += ",contextmenu";
                }


//                config.Add("theme_advanced_statusbar_location", "none");

                // If the editor is used in Umbraco, use Umbraco's own toolbar
                bool onFront = false;
                if (HttpContext.Current.Request.Path.IndexOf(GlobalSettings.Path) > -1)
                {
                    config.Add("theme_advanced_toolbar_location", "external");
                }
                else
                {
                    onFront = true;
                    config.Add("theme_advanced_toolbar_location", "top");
                }

                // load plugins
                IDictionaryEnumerator pluginEnum = tinyMCEConfiguration.Plugins.GetEnumerator();
                while (pluginEnum.MoveNext())
                {
                    tinyMCEPlugin plugin = (tinyMCEPlugin)pluginEnum.Value;
                    if (plugin.UseOnFrontend || (!onFront && !plugin.UseOnFrontend))
                    {
                        _plugins += "," + plugin.Name;
                    }
                }
                if (_plugins.StartsWith(","))
                {
                    _plugins = _plugins.Substring(1, _plugins.Length - 1);
                }
                if (_plugins.EndsWith(","))
                {
                    _plugins = _plugins.Substring(0, _plugins.Length - 1);
                }

                config.Add("plugins", _plugins);

                // Check advanced settings
                if (("," + _advancedUsers + ",").IndexOf("," + UmbracoEnsuredPage.CurrentUser.UserType.Id + ",") > -1)
                {
                    config.Add("umbracoAdvancedMode", "true");
                }
                else
                {
                    config.Add("umbracoAdvancedMode", "false");
                }

                // Styles
                string cssFiles = String.Empty;
                string styles   = string.Empty;
                foreach (string styleSheetId in _stylesheets)
                {
                    if (styleSheetId.Trim() != "")
                    {
                        try
                        {
                            StyleSheet s = new StyleSheet(int.Parse(styleSheetId));
                            cssFiles += GlobalSettings.Path + "/../css/" + s.Text + ".css";

                            foreach (StylesheetProperty p in s.Properties)
                            {
                                if (styles != string.Empty)
                                {
                                    styles += ";";
                                }
                                if (p.Alias.StartsWith("."))
                                {
                                    styles += p.Text + "=" + p.Alias;
                                }
                                else
                                {
                                    styles += p.Text + "=" + p.Alias;
                                }
                            }

                            cssFiles += ",";
                        }
                        catch (Exception ee)
                        {
                            Log.Add(LogTypes.Error, -1,
                                    string.Format(
                                        string.Format("Error adding stylesheet to tinymce (id: {{0}}). {0}", ee),
                                        styleSheetId));
                        }
                    }
                }

                config.Add("content_css", cssFiles);
                config.Add("theme_advanced_styles", styles);

                // Add buttons
                IDictionaryEnumerator ide = tinyMCEConfiguration.Commands.GetEnumerator();
                while (ide.MoveNext())
                {
                    tinyMCECommand cmd = (tinyMCECommand)ide.Value;
                    if (_editorButtons.IndexOf("," + cmd.Alias + ",") > -1)
                    {
                        _activateButtons += cmd.Alias + ",";
                    }
                    else
                    {
                        _disableButtons += cmd.Alias + ",";
                    }
                }

                if (_activateButtons.Length > 0)
                {
                    _activateButtons = _activateButtons.Substring(0, _activateButtons.Length - 1);
                }
                if (_disableButtons.Length > 0)
                {
                    _disableButtons = _disableButtons.Substring(0, _disableButtons.Length - 1);
                }

                // Add buttons
                initButtons();
                _activateButtons = "";

                int separatorPriority = 0;
                ide = _mceButtons.GetEnumerator();
                while (ide.MoveNext())
                {
                    string mceCommand  = ide.Value.ToString();
                    int    curPriority = (int)ide.Key;

                    // Check priority
                    if (separatorPriority > 0 &&
                        Math.Floor(decimal.Parse(curPriority.ToString()) / 10) >
                        Math.Floor(decimal.Parse(separatorPriority.ToString()) / 10))
                    {
                        _activateButtons += "separator,";
                    }

                    _activateButtons += mceCommand + ",";

                    separatorPriority = curPriority;
                }


                config.Add("theme_advanced_buttons1", _activateButtons);
                config.Add("theme_advanced_buttons2", "");
                config.Add("theme_advanced_buttons3", "");
                config.Add("theme_advanced_toolbar_align", "left");
                config.Add("theme_advanced_disable", _disableButtons);

                config.Add("theme_advanced_path ", "true");
                config.Add("extended_valid_elements", "div[*]");
                config.Add("document_base_url", "/");
                config.Add("event_elements", "div");
                config.Add("language", User.GetUser(BasePage.GetUserId(BasePage.umbracoUserContextID)).Language);

                if (_fullWidth)
                {
                    config.Add("auto_resize", "true");
                    base.Cols = 30;
                    base.Rows = 30;
                }
                else
                {
                    base.Cols = 0;
                    base.Rows = 0;
                }
            }
        }
Esempio n. 3
0
        private void initButtons()
        {
            if (!_isInitialized)
            {
                _isInitialized = true;

                // Add icons for the editor control:
                // Html
                // Preview
                // Style picker, showstyles
                // Bold, italic, Text Gen
                // Align: left, center, right
                // Lists: Bullet, Ordered, indent, undo indent
                // Link, Anchor
                // Insert: Image, macro, table, formular

                foreach (string button in _activateButtons.Split(','))
                {
                    if (button.Trim() != "")
                    {
                        try
                        {
                            tinyMCECommand cmd = (tinyMCECommand)tinyMCEConfiguration.Commands[button];

                            string appendValue = "";
                            if (cmd.Value != "")
                            {
                                appendValue = ", '" + cmd.Value + "'";
                            }
                            _mceButtons.Add(cmd.Priority, cmd.Command);
                            _buttons.Add(cmd.Priority,
                                         new editorButton(cmd.Alias, UI.Text("buttons", cmd.Alias, null), cmd.Icon,
                                                          "tinyMCE.execInstanceCommand('" + ClientID + "', '" +
                                                          cmd.Command + "', " + cmd.UserInterface + appendValue + ")"));
                        }
                        catch (Exception ee)
                        {
                            Log.Add(LogTypes.Error, User.GetUser(0), -1,
                                    string.Format("TinyMCE: Error initializing button '{0}': {1}", button, ee.ToString()));
                        }
                    }
                }

                // add save icon
                int separatorPriority     = 0;
                IDictionaryEnumerator ide = _buttons.GetEnumerator();
                while (ide.MoveNext())
                {
                    object buttonObj   = ide.Value;
                    int    curPriority = (int)ide.Key;

                    // Check priority
                    if (separatorPriority > 0 &&
                        Math.Floor(decimal.Parse(curPriority.ToString()) / 10) >
                        Math.Floor(decimal.Parse(separatorPriority.ToString()) / 10))
                    {
                        _menuIcons.Add("|");
                    }

                    try
                    {
                        editorButton e = (editorButton)buttonObj;

                        MenuIconI menuItem = new MenuIconClass();

                        menuItem.OnClickCommand = e.onClickCommand;
                        menuItem.ImageURL       = e.imageUrl;
                        menuItem.AltText        = e.alttag;
                        menuItem.ID             = e.id;
                        _menuIcons.Add(menuItem);
                    }
                    catch
                    {
                    }

                    separatorPriority = curPriority;
                }
            }
        }
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            // add ids to controls
            _width.ID  = "width";
            _height.ID = "height";


            // initialize validators
            _widthValidator.ValidationExpression = "0*[1-9][0-9]*";
            _widthValidator.ErrorMessage         = "Width must be an integer";
            _widthValidator.Display               = ValidatorDisplay.Dynamic;
            _widthValidator.ControlToValidate     = _width.ID;
            _heightValidator.ValidationExpression = "0*[1-9][0-9]*";
            _heightValidator.ErrorMessage         = "Height must be an integer";
            _heightValidator.ControlToValidate    = _height.ID;
            _heightValidator.Display              = ValidatorDisplay.Dynamic;

            if (!Page.IsPostBack)
            {
                string[] config = Configuration.Split("|".ToCharArray());
                if (config.Length > 0)
                {
                    _selectedButtons = config[0];

                    if (config.Length > 1)
                    {
                        if (config[1] == "1")
                        {
                            _enableRightClick.Checked = true;
                        }
                    }

                    if (config.Length > 2)
                    {
                        _advancedUsers = config[2];
                    }

                    if (config.Length > 4 && config[4].Split(',').Length > 1)
                    {
//                        if (config[3] == "1")
//                            _fullWidth.Checked = true;
//                        else
//                        {
                        _width.Text  = config[4].Split(',')[0];
                        _height.Text = config[4].Split(',')[1];
//                        }
                    }

                    // if width and height are empty or lower than 0 then set default sizes:
                    int tempWidth, tempHeight;
                    int.TryParse(_width.Text, out tempWidth);
                    int.TryParse(_height.Text, out tempHeight);
                    if (_width.Text.Trim() == "" || tempWidth < 1)
                    {
                        _width.Text = "500";
                    }
                    if (_height.Text.Trim() == "" || tempHeight < 1)
                    {
                        _height.Text = "400";
                    }

                    if (config.Length > 4)
                    {
                        _stylesheets = config[5];
                    }
                }

                // add editor buttons
                IDictionaryEnumerator ide = tinyMCEConfiguration.SortedCommands.GetEnumerator();
                while (ide.MoveNext())
                {
                    tinyMCECommand cmd = (tinyMCECommand)ide.Value;
                    ListItem       li  = new ListItem(string.Format("<img src=\"{0}\" class=\"tinymceIcon\" alt=\"{1}\" />&nbsp;", cmd.Icon, cmd.Alias), cmd.Alias);
                    if (_selectedButtons.IndexOf(cmd.Alias) > -1)
                    {
                        li.Selected = true;
                    }

                    _editorButtons.Items.Add(li);
                }

                // add users
                foreach (BusinessLogic.UserType ut in BusinessLogic.UserType.getAll)
                {
                    ListItem li = new ListItem(ut.Name, ut.Id.ToString());
                    if (("," + _advancedUsers + ",").IndexOf("," + ut.Id.ToString() + ",") > -1)
                    {
                        li.Selected = true;
                    }

                    _advancedUsersList.Items.Add(li);
                }

                // add stylesheets
                foreach (Cms.BusinessLogic.web.StyleSheet st in Cms.BusinessLogic.web.StyleSheet.GetAll())
                {
                    ListItem li = new ListItem(st.Text, st.Id.ToString());
                    if (("," + _stylesheets + ",").IndexOf("," + st.Id.ToString() + ",") > -1)
                    {
                        li.Selected = true;
                    }

                    _stylesheetList.Items.Add(li);
                }


                // Mark the current db type
                _dropdownlist.SelectedValue = _datatype.DBType.ToString();
            }
        }