Revert "Temp8 tinymce"

This commit is contained in:
Warren Buckley
2018-11-22 14:05:51 +00:00
committed by GitHub
parent 2a0748fc1e
commit 54a2aa00a7
6677 changed files with 646351 additions and 410535 deletions

View File

@@ -0,0 +1,291 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using System.Xml;
using Umbraco.Core.IO;
namespace umbraco.editorControls.tinymce
{
[Obsolete("IDataType and all other references to the legacy property editors are no longer used this will be removed from the codebase in future versions")]
public class tinyMCEConfiguration
{
private static bool _init = false;
private static Hashtable _commands = new Hashtable(StringComparer.InvariantCultureIgnoreCase);
private static string _validElements;
private static Hashtable _configOptions = new Hashtable(StringComparer.InvariantCultureIgnoreCase);
public static Hashtable ConfigOptions
{
get
{
if (!_init)
init();
return _configOptions;
}
set
{
_configOptions = value;
}
}
public static string ValidElements
{
get
{
if (!_init)
init();
return _validElements;
}
set { _validElements = value; }
}
public static string PluginPath = IOHelper.ResolveUrl( SystemDirectories.Umbraco ) + "/plugins/tinymce3";
public static string JavascriptPath = IOHelper.ResolveUrl( SystemDirectories.UmbracoClient ) + "/tinymce3";
private static string _invalidElements;
public static string InvalidElements
{
get
{
if (!_init)
init();
return _invalidElements;
}
set { _invalidElements = value; }
}
private static Hashtable _plugins = new Hashtable(StringComparer.InvariantCultureIgnoreCase);
public static Hashtable Plugins
{
get
{
if (!_init)
init();
return _plugins;
}
set { _plugins = value; }
}
public static Hashtable Commands
{
get
{
if (!_init)
init();
return _commands;
}
}
public static SortedList SortedCommands
{
get
{
if (!_init)
init();
SortedList sc = new SortedList();
IDictionaryEnumerator ide = _commands.GetEnumerator();
while (ide.MoveNext())
sc.Add(((tinyMCECommand)ide.Value).Priority, (tinyMCECommand)ide.Value);
return sc;
}
}
private static void init()
{
// Load config
XmlDocument xd = new XmlDocument();
xd.Load(IOHelper.MapPath( SystemFiles.TinyMceConfig ));
foreach (XmlNode n in xd.DocumentElement.SelectNodes("//command"))
{
if (!_commands.ContainsKey(n.SelectSingleNode("./umbracoAlias").FirstChild.Value))
{
bool isStyle = false;
if (n.Attributes.GetNamedItem("isStyle") != null)
isStyle = bool.Parse(n.Attributes.GetNamedItem("isStyle").Value);
_commands.Add(
n.SelectSingleNode("./umbracoAlias").FirstChild.Value.ToLower(),
new tinyMCECommand(
isStyle,
n.SelectSingleNode("./icon").FirstChild.Value,
n.SelectSingleNode("./tinyMceCommand").FirstChild.Value,
n.SelectSingleNode("./umbracoAlias").FirstChild.Value.ToLower(),
n.SelectSingleNode("./tinyMceCommand").Attributes.GetNamedItem("userInterface").Value,
n.SelectSingleNode("./tinyMceCommand").Attributes.GetNamedItem("frontendCommand").Value,
n.SelectSingleNode("./tinyMceCommand").Attributes.GetNamedItem("value").Value,
int.Parse(n.SelectSingleNode("./priority").FirstChild.Value)
));
}
}
foreach (XmlNode n in xd.DocumentElement.SelectNodes("//plugin"))
{
if (!_plugins.ContainsKey(n.FirstChild.Value))
{
bool useOnFrontend = false;
if (n.Attributes.GetNamedItem("loadOnFrontend") != null)
useOnFrontend = bool.Parse(n.Attributes.GetNamedItem("loadOnFrontend").Value);
_plugins.Add(
n.FirstChild.Value.ToLower(),
new tinyMCEPlugin(
n.FirstChild.Value,
useOnFrontend));
}
}
foreach (XmlNode n in xd.DocumentElement.SelectNodes("//config"))
{
if (!_configOptions.ContainsKey(n.Attributes["key"].FirstChild.Value))
{
var value = "";
if (n.FirstChild != null)
value = n.FirstChild.Value;
_configOptions.Add(
n.Attributes["key"].FirstChild.Value.ToLower(),
value);
}
}
if (xd.DocumentElement.SelectSingleNode("./invalidElements") != null)
_invalidElements = xd.DocumentElement.SelectSingleNode("./invalidElements").FirstChild.Value;
if (xd.DocumentElement.SelectSingleNode("./validElements") != null)
{
string _val = xd.DocumentElement.SelectSingleNode("./validElements").FirstChild.Value.Replace("\r", "");
foreach (string s in _val.Split("\n".ToCharArray()))
_validElements += "'" + s + "' + \n";
_validElements = _validElements.Substring(0, _validElements.Length - 4);
}
_init = true;
}
}
public class tinyMCEPlugin
{
public tinyMCEPlugin(string Name, bool UseOnFrontEnd)
{
_name = Name;
_useOnFrontend = UseOnFrontEnd;
}
private string _name;
public string Name
{
get { return _name; }
set { _name = value; }
}
private bool _useOnFrontend;
public bool UseOnFrontend
{
get { return _useOnFrontend; }
set { _useOnFrontend = value; }
}
}
public class tinyMCECommand
{
public tinyMCECommand(bool isStylePicker, string Icon, string Command, string Alias, string UserInterface, string FrontEndCommand, string Value, int Priority)
{
_isStylePicker = isStylePicker;
_icon = Icon;
_command = Command;
_alias = Alias;
_userInterface = UserInterface;
_frontEndCommand = FrontEndCommand;
_value = Value;
_priority = Priority;
}
private bool _isStylePicker;
public bool IsStylePicker
{
get { return _isStylePicker; }
set { _isStylePicker = value; }
}
private string _icon;
public string Icon
{
get { return IOHelper.ResolveUrl( SystemDirectories.Umbraco ) + "/" + _icon; }
set { _icon = value; }
}
private string _command;
public string Command
{
get { return _command; }
set { _command = value; }
}
private string _alias;
public string Alias
{
get { return _alias; }
set { _alias = value; }
}
private string _userInterface;
public string UserInterface
{
get { return _userInterface; }
set { _userInterface = value; }
}
private string _frontEndCommand;
public string FrontEndCommand
{
get { return _frontEndCommand; }
set { _frontEndCommand = value; }
}
private string _value;
public string Value
{
get { return _value; }
set { _value = value; }
}
private int _priority;
public int Priority
{
get { return _priority; }
set { _priority = value; }
}
}
}

View File

@@ -0,0 +1,161 @@
using System;
using System.Collections;
using System.Linq;
using System.Text.RegularExpressions;
using System.Web;
using Umbraco.Core.Configuration;
using Umbraco.Core.IO;
using Umbraco.Core.Logging;
using umbraco.cms.businesslogic.Files;
namespace umbraco.editorControls.tinymce
{
[Obsolete("IDataType and all other references to the legacy property editors are no longer used this will be removed from the codebase in future versions")]
internal class tinyMCEImageHelper
{
public static string cleanImages(string html)
{
var allowedAttributes = UmbracoConfig.For.UmbracoSettings().Content.ImageTagAllowedAttributes.Select(x => x.ToLower()).ToList();
//Always add src as it's essential to output any image at all
if (allowedAttributes.Contains("src") == false)
allowedAttributes.Add("src");
const string pattern = @"<img [^>]*>";
var tags = Regex.Matches(html + " ", pattern, RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace);
foreach (Match tag in tags)
{
if (tag.Value.ToLower().IndexOf("umbraco_macro", StringComparison.Ordinal) == -1)
{
var cleanTag = "<img";
// gather all attributes
// TODO: This should be replaced with a general helper method - but for now we'll wanna leave umbraco.dll alone for this patch
var ht = new Hashtable();
var matches = Regex.Matches(tag.Value.Replace(">", " >"), "(?<attributeName>\\S*?)=\"(?<attributeValue>[^\"]*)\"|(?<attributeName>\\S*?)=(?<attributeValue>[^\"|\\s]*)\\s", RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace);
foreach (Match attributeSet in matches)
{
ht.Add(attributeSet.Groups["attributeName"].Value.ToLower(),
attributeSet.Groups["attributeValue"].Value);
}
// If rel attribute exists and if it's different from current sizing we should resize the image!
if (helper.FindAttribute(ht, "rel") != "")
{
// if size has changed resize image serverside
var newDims = helper.FindAttribute(ht, "rel").Split(",".ToCharArray());
if (newDims.Length > 0 && (newDims[0] != helper.FindAttribute(ht, "width") || newDims[1] != helper.FindAttribute(ht, "height")))
{
try
{
int newWidth;
int newHeight;
string newSrc;
cleanTag += DoResize(ht, out newWidth, out newHeight, out newSrc);
ht["src"] = newSrc;
}
catch (Exception err)
{
cleanTag += " src=\"" + helper.FindAttribute(ht, "src") + "\"";
if (helper.FindAttribute(ht, "width") != "")
{
cleanTag += " width=\"" + helper.FindAttribute(ht, "width") + "\"";
cleanTag += " height=\"" + helper.FindAttribute(ht, "height") + "\"";
}
LogHelper.Error<tinyMCEImageHelper>("Error resizing image in editor", err);
}
}
else
{
if (helper.FindAttribute(ht, "width") != "")
{
cleanTag += " width=\"" + helper.FindAttribute(ht, "width") + "\"";
cleanTag += " height=\"" + helper.FindAttribute(ht, "height") + "\"";
}
}
}
else
{
if (helper.FindAttribute(ht, "width") != "")
{
cleanTag += " width=\"" + helper.FindAttribute(ht, "width") + "\"";
cleanTag += " height=\"" + helper.FindAttribute(ht, "height") + "\"";
}
}
// Build image tag
foreach (var attr in allowedAttributes)
{
if (helper.FindAttribute(ht, attr) != "")
{
var attrValue = helper.FindAttribute(ht, attr);
cleanTag += " " + attr + "=\"" + attrValue + "\"";
}
}
if (bool.Parse(GlobalSettings.EditXhtmlMode))
cleanTag += "/";
cleanTag += ">";
html = html.Replace(tag.Value, cleanTag);
}
}
return html;
}
private static string DoResize(IDictionary attributes, out int finalWidth, out int finalHeight, out string newSrc)
{
var fs = FileSystemProviderManager.Current.GetFileSystemProvider<MediaFileSystem>();
var orgSrc = HttpContext.Current.Server.HtmlDecode(helper.FindAttribute(attributes, "src").Replace("%20", " "));
var orgDim = helper.FindAttribute(attributes, "rel").Split(",".ToCharArray());
var orgWidth = float.Parse(orgDim[0]);
var orgHeight = float.Parse(orgDim[1]);
var newWidth = int.Parse(helper.FindAttribute(attributes, "width"));
var newHeight = int.Parse(helper.FindAttribute(attributes, "height"));
newSrc = "";
if (orgHeight > 0 && orgWidth > 0 && orgSrc != "")
{
// Check dimensions
if (Math.Abs(orgWidth / newWidth) > Math.Abs(orgHeight / newHeight))
{
newHeight = (int)Math.Round(newWidth * (orgHeight / orgWidth));
}
else
{
newWidth = (int)Math.Round(newHeight * (orgWidth / orgHeight));
}
var orgPath = fs.GetRelativePath(orgSrc);
if (fs.FileExists(orgPath))
{
var uf = new UmbracoFile(orgPath);
try
{
newSrc = uf.Resize(newWidth, newHeight);
}
catch (Exception ex)
{
LogHelper.Error<tinyMCEImageHelper>(string.Format("The file {0} could not be resized, reverting the image src attribute to the original source: {1}", orgPath, orgSrc), ex);
newSrc = orgSrc;
}
}
else
{
LogHelper.Warn<tinyMCEImageHelper>(string.Format("The file {0} does not exist, reverting the image src attribute to the original source: {1}", orgPath, orgSrc));
newSrc = orgSrc;
}
}
finalWidth = newWidth;
finalHeight = newHeight;
return " width=\"" + newWidth + "\" height=\"" + newHeight + "\"";
}
}
}

View File

@@ -0,0 +1,331 @@
using System;
using System.Collections;
using System.Web.UI;
using System.Web.UI.WebControls;
using umbraco.BusinessLogic;
using umbraco.DataLayer;
using Umbraco.Core;
namespace umbraco.editorControls.tinymce
{
[Obsolete("IDataType and all other references to the legacy property editors are no longer used this will be removed from the codebase in future versions")]
public class tinyMCEPreValueConfigurator : System.Web.UI.WebControls.PlaceHolder, interfaces.IDataPrevalue
{
// UI controls
private CheckBoxList _editorButtons;
private CheckBox _enableRightClick;
private DropDownList _dropdownlist;
private CheckBoxList _advancedUsersList;
private CheckBoxList _stylesheetList;
private TextBox _width = new TextBox();
private TextBox _height = new TextBox();
private TextBox _maxImageWidth = new TextBox();
private CheckBox _fullWidth = new CheckBox();
private CheckBox _showLabel = new CheckBox();
private RegularExpressionValidator _widthValidator = new RegularExpressionValidator();
private RegularExpressionValidator _heightValidator = new RegularExpressionValidator();
private RegularExpressionValidator _maxImageWidthValidator = new RegularExpressionValidator();
// referenced datatype
private cms.businesslogic.datatype.BaseDataType _datatype;
private string _selectedButtons = "";
private string _advancedUsers = "";
private string _stylesheets = "";
/// <summary>
/// Unused, please do not use
/// </summary>
[Obsolete("Obsolete, For querying the database use the new UmbracoDatabase object ApplicationContext.Current.DatabaseContext.Database", false)]
public static ISqlHelper SqlHelper
{
get { return Application.SqlHelper; }
}
public tinyMCEPreValueConfigurator(cms.businesslogic.datatype.BaseDataType DataType)
{
// state it knows its datatypedefinitionid
_datatype = DataType;
setupChildControls();
}
private void setupChildControls()
{
_dropdownlist = new DropDownList();
_dropdownlist.ID = "dbtype";
_dropdownlist.Items.Add(DBTypes.Date.ToString());
_dropdownlist.Items.Add(DBTypes.Integer.ToString());
_dropdownlist.Items.Add(DBTypes.Ntext.ToString());
_dropdownlist.Items.Add(DBTypes.Nvarchar.ToString());
_editorButtons = new CheckBoxList();
_editorButtons.ID = "editorButtons";
_editorButtons.RepeatColumns = 4;
_editorButtons.CellPadding = 3;
_enableRightClick = new CheckBox();
_enableRightClick.ID = "enableRightClick";
_advancedUsersList = new CheckBoxList();
_advancedUsersList.ID = "advancedUsersList";
_stylesheetList = new CheckBoxList();
_stylesheetList.ID = "stylesheetList";
_showLabel = new CheckBox();
_showLabel.ID = "showLabel";
_maxImageWidth = new TextBox();
_maxImageWidth.ID = "maxImageWidth";
// put the childcontrols in context - ensuring that
// the viewstate is persisted etc.
Controls.Add(_dropdownlist);
Controls.Add(_enableRightClick);
Controls.Add(_editorButtons);
Controls.Add(_advancedUsersList);
Controls.Add(_stylesheetList);
Controls.Add(_width);
Controls.Add(_widthValidator);
Controls.Add(_height);
Controls.Add(_heightValidator);
Controls.Add(_showLabel);
Controls.Add(_maxImageWidth);
Controls.Add(_maxImageWidthValidator);
// Controls.Add(_fullWidth);
}
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();
}
}
public Control Editor
{
get
{
return this;
}
}
public virtual void Save()
{
_datatype.DBType = (cms.businesslogic.datatype.DBTypes)Enum.Parse(typeof(cms.businesslogic.datatype.DBTypes), _dropdownlist.SelectedValue, true);
// Generate data-string
string data = ",";
foreach (ListItem li in _editorButtons.Items)
if (li.Selected)
data += li.Value + ",";
data += "|";
if (_enableRightClick.Checked)
data += "1";
else
data += "0";
data += "|";
foreach (ListItem li in _advancedUsersList.Items)
if (li.Selected)
data += li.Value + ",";
data += "|";
data += "0|";
data += _width.Text + "," + _height.Text + "|";
foreach (ListItem li in _stylesheetList.Items)
if (li.Selected)
data += li.Value + ",";
data += "|";
data += _showLabel.Checked.ToString() + "|";
data += _maxImageWidth.Text + "|";
using (var sqlHelper = Application.SqlHelper)
{
// If the add new prevalue textbox is filled out - add the value to the collection.
IParameter[] SqlParams = new IParameter[] {
sqlHelper.CreateParameter("@value",data),
sqlHelper.CreateParameter("@dtdefid",_datatype.DataTypeDefinitionId)};
sqlHelper.ExecuteNonQuery("delete from cmsDataTypePreValues where datatypenodeid = @dtdefid", SqlParams);
// we need to populate the parameters again due to an issue with SQL CE
SqlParams = new IParameter[] {
sqlHelper.CreateParameter("@value",data),
sqlHelper.CreateParameter("@dtdefid",_datatype.DataTypeDefinitionId)};
sqlHelper.ExecuteNonQuery("insert into cmsDataTypePreValues (datatypenodeid,[value],sortorder,alias) values (@dtdefid,@value,0,'')", SqlParams);
}
}
protected override void Render(HtmlTextWriter writer)
{
writer.WriteLine("<table>");
writer.WriteLine("<tr><th>" + ui.Text("editdatatype", "dataBaseDatatype") + ":</th><td>");
_dropdownlist.RenderControl(writer);
writer.Write("</td></tr>");
writer.Write("<tr><th>" + ui.Text("editdatatype", "rteButtons") + ":</th><td>");
_editorButtons.RenderControl(writer);
writer.Write("</td></tr>");
writer.Write("<tr><th>" + ui.Text("editdatatype", "rteRelatedStylesheets") + ":</th><td>");
_stylesheetList.RenderControl(writer);
writer.Write("</td></tr>");
writer.Write("<tr><th>" + ui.Text("editdatatype", "rteEnableContextMenu") + ":</th><td>");
_enableRightClick.RenderControl(writer);
writer.Write("</td></tr>");
writer.Write("<tr><th>" + ui.Text("editdatatype", "rteEnableAdvancedSettings") + ":</th><td>");
_advancedUsersList.RenderControl(writer);
writer.Write("</td></tr>");
writer.Write("<tr><th>");
//"Size:</th><td>Maximum width and height: ");
// _fullWidth.RenderControl(writer);
writer.Write(ui.Text("editdatatype", "rteWidthAndHeight") + ":</th><td>");
_width.RenderControl(writer);
_widthValidator.RenderControl(writer);
writer.Write(" x ");
_height.RenderControl(writer);
_heightValidator.RenderControl(writer);
writer.Write("</td></tr>");
writer.Write("<tr><th>");
writer.Write(ui.Text("editdatatype", "rteMaximumDefaultImgSize") + ":</th><td>");
_maxImageWidth.RenderControl(writer);
_maxImageWidthValidator.RenderControl(writer);
writer.Write("</td></tr>");
writer.Write("<tr><th>" + ui.Text("editdatatype", "rteShowLabel") + ":</th><td>");
_showLabel.RenderControl(writer);
writer.Write("</td></tr>");
writer.Write("</table>");
}
public string Configuration
{
get
{
try
{
using (var sqlHelper = Application.SqlHelper)
return sqlHelper.ExecuteScalar<string>("select value from cmsDataTypePreValues where datatypenodeid = @datatypenodeid", sqlHelper.CreateParameter("@datatypenodeid", _datatype.DataTypeDefinitionId));
}
catch
{
return "";
}
}
}
}
}