Cleaning up folder structure (U4-56)
This commit is contained in:
506
OLD/umbraco.Legacy/editorControls/tinymce/TinyMCE.cs
Normal file
506
OLD/umbraco.Legacy/editorControls/tinymce/TinyMCE.cs
Normal file
@@ -0,0 +1,506 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Web;
|
||||
using System.Web.UI;
|
||||
using umbraco.BasePages;
|
||||
using umbraco.BusinessLogic;
|
||||
using umbraco.cms.businesslogic.web;
|
||||
using umbraco.editorControls.wysiwyg;
|
||||
using umbraco.interfaces;
|
||||
using umbraco.uicontrols;
|
||||
|
||||
namespace umbraco.editorControls.tinymce {
|
||||
public class TinyMCE : webcontrol.TinyMCE, IDataEditor, IMenuElement {
|
||||
private IData _data;
|
||||
private bool _enableContextMenu = false;
|
||||
private string _editorButtons = "";
|
||||
private string _advancedUsers = "";
|
||||
private bool _fullWidth = false;
|
||||
private int _width = 0;
|
||||
private int _height = 0;
|
||||
private bool _showLabel = false;
|
||||
private string _plugins = "";
|
||||
private ArrayList _stylesheets = new ArrayList();
|
||||
|
||||
private ArrayList _menuIcons = new ArrayList();
|
||||
private SortedList _buttons = new SortedList();
|
||||
private SortedList _mceButtons = new SortedList();
|
||||
private bool _isInitialized = false;
|
||||
private string _activateButtons = "";
|
||||
private string _disableButtons = "help,visualaid,";
|
||||
private int m_maxImageWidth = 500;
|
||||
|
||||
public virtual string Plugins {
|
||||
get { return _plugins; }
|
||||
set { _plugins = value; }
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
if (configSettings.Length > 6 && configSettings[6] != "")
|
||||
_showLabel = bool.Parse(configSettings[6]);
|
||||
|
||||
if (configSettings.Length > 7 && configSettings[7] != "")
|
||||
m_maxImageWidth = int.Parse(configSettings[7].ToString());
|
||||
|
||||
// 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.ToLower().IndexOf(GlobalSettings.Path.ToLower()) > -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");
|
||||
|
||||
// Check maximum image width
|
||||
config.Add("umbracoMaximumDefaultImageWidth", m_maxImageWidth.ToString());
|
||||
|
||||
// Styles
|
||||
string cssFiles = String.Empty;
|
||||
string styles = string.Empty;
|
||||
foreach (string styleSheetId in _stylesheets) {
|
||||
if (styleSheetId.Trim() != "")
|
||||
try {
|
||||
StyleSheet s = StyleSheet.GetStyleSheet(int.Parse(styleSheetId), false, false);
|
||||
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");
|
||||
|
||||
|
||||
if (HttpContext.Current.Request.Path.IndexOf(GlobalSettings.Path) > -1)
|
||||
config.Add("language", User.GetUser(BasePage.GetUserId(BasePage.umbracoUserContextID)).Language);
|
||||
else
|
||||
config.Add("language", System.Threading.Thread.CurrentThread.CurrentCulture.TwoLetterISOLanguageName);
|
||||
|
||||
if (_fullWidth) {
|
||||
config.Add("auto_resize", "true");
|
||||
base.Cols = 30;
|
||||
base.Rows = 30;
|
||||
} else {
|
||||
base.Cols = 0;
|
||||
base.Rows = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#region IDataEditor Members
|
||||
|
||||
#region TreatAsRichTextEditor
|
||||
|
||||
public virtual bool TreatAsRichTextEditor {
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region ShowLabel
|
||||
|
||||
public virtual bool ShowLabel {
|
||||
get { return _showLabel; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Editor
|
||||
|
||||
public Control Editor {
|
||||
get { return this; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Save()
|
||||
|
||||
public virtual void Save() {
|
||||
string parsedString = base.Text.Trim();
|
||||
if (parsedString != string.Empty) {
|
||||
parsedString = replaceMacroTags(parsedString).Trim();
|
||||
|
||||
// clean macros and add paragraph element for tidy
|
||||
bool removeParagraphs = false;
|
||||
if (parsedString.Length > 16 && parsedString.ToLower().Substring(0, 17) == "|||?umbraco_macro") {
|
||||
removeParagraphs = true;
|
||||
parsedString = "<p>" + parsedString + "</p>";
|
||||
}
|
||||
|
||||
// tidy html
|
||||
|
||||
if (UmbracoSettings.TidyEditorContent) {
|
||||
string tidyTxt = library.Tidy(parsedString, false);
|
||||
if (tidyTxt != "[error]") {
|
||||
// compensate for breaking macro tags by tidy
|
||||
parsedString = tidyTxt.Replace("/?>", "/>");
|
||||
if (removeParagraphs) {
|
||||
if (parsedString.Length - parsedString.Replace("<", "").Length == 2)
|
||||
parsedString = parsedString.Replace("<p>", "").Replace("</p>", "");
|
||||
}
|
||||
} else {
|
||||
// TODO
|
||||
// How to log errors? _data.NodeId does not exist?
|
||||
//BusinessLogic.Log.Add(BusinessLogic.LogTypes.Error, BusinessLogic.User.GetUser(0), _data.NodeId, "Error tidying txt from property: " + _data.PropertyId.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
// rescue umbraco tags
|
||||
parsedString = parsedString.Replace("|||?", "<?").Replace("/|||", "/>").Replace("|*|", "\"");
|
||||
|
||||
// fix images
|
||||
parsedString = tinyMCEImageHelper.cleanImages(parsedString);
|
||||
|
||||
// parse current domain and instances of slash before anchor (to fix anchor bug)
|
||||
// NH 31-08-2007
|
||||
if (HttpContext.Current.Request.ServerVariables != null) {
|
||||
parsedString = parsedString.Replace(helper.GetBaseUrl(HttpContext.Current) + "/#", "#");
|
||||
parsedString = parsedString.Replace(helper.GetBaseUrl(HttpContext.Current), "");
|
||||
}
|
||||
|
||||
// if text is an empty parargraph, make it all empty
|
||||
if (parsedString.ToLower() == "<p></p>")
|
||||
parsedString = "";
|
||||
}
|
||||
_data.Value = parsedString;
|
||||
|
||||
// update internal webcontrol value with parsed result
|
||||
base.Text = parsedString;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
protected override void OnLoad(EventArgs e) {
|
||||
base.OnLoad(e);
|
||||
try {
|
||||
base.NodeId = ((cms.businesslogic.datatype.DefaultData)_data).NodeId;
|
||||
base.VersionId = ((cms.businesslogic.datatype.DefaultData)_data).Version;
|
||||
config.Add("umbraco_toolbar_id",
|
||||
ElementIdPreFix + ((cms.businesslogic.datatype.DefaultData)_data).PropertyId.ToString());
|
||||
} catch {
|
||||
// Empty catch as this is caused by the document doesn't exists yet,
|
||||
// like when using this on an autoform
|
||||
}
|
||||
Page.ClientScript.RegisterClientScriptBlock(GetType(), "tinymce",
|
||||
"<script language=\"javascript\" type=\"text/javascript\" src=\"" +
|
||||
JavascriptLocation + CoreFile + "\"></script>");
|
||||
Page.ClientScript.RegisterClientScriptBlock(GetType(), "tinymceUmbPasteCheck",
|
||||
"<script language=\"javascript\" type=\"text/javascript\" src=\"" +
|
||||
JavascriptLocation +
|
||||
"/plugins/umbracoAdditions/umbPasteCheck.js\"></script>");
|
||||
}
|
||||
|
||||
protected override void Render(HtmlTextWriter output) {
|
||||
base.JavascriptLocation = GlobalSettings.ClientPath + "/tinymce/tiny_mce.js";
|
||||
base.Render(output);
|
||||
}
|
||||
|
||||
protected override void OnInit(EventArgs e) {
|
||||
base.OnInit(e);
|
||||
if (!Page.IsPostBack) {
|
||||
if (_data != null && _data.Value != null)
|
||||
base.Text = _data.Value.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
private string replaceMacroTags(string text) {
|
||||
while (findStartTag(text) > -1) {
|
||||
string result = text.Substring(findStartTag(text), findEndTag(text) - findStartTag(text));
|
||||
text = text.Replace(result, generateMacroTag(result));
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
||||
private string generateMacroTag(string macroContent) {
|
||||
string macroAttr = macroContent.Substring(5, macroContent.IndexOf(">") - 5);
|
||||
string macroTag = "|||?UMBRACO_MACRO ";
|
||||
Hashtable attributes = ReturnAttributes(macroAttr);
|
||||
IDictionaryEnumerator ide = attributes.GetEnumerator();
|
||||
while (ide.MoveNext()) {
|
||||
if (ide.Key.ToString().IndexOf("umb_") != -1) {
|
||||
// Hack to compensate for Firefox adding all attributes as lowercase
|
||||
string orgKey = ide.Key.ToString();
|
||||
if (orgKey == "umb_macroalias")
|
||||
orgKey = "umb_macroAlias";
|
||||
|
||||
macroTag += orgKey.Substring(4, orgKey.ToString().Length - 4) + "=|*|" +
|
||||
ide.Value.ToString() + "|*| ";
|
||||
}
|
||||
}
|
||||
macroTag += "/|||";
|
||||
|
||||
return macroTag;
|
||||
}
|
||||
|
||||
public static Hashtable ReturnAttributes(String tag) {
|
||||
Hashtable ht = new Hashtable();
|
||||
MatchCollection m =
|
||||
Regex.Matches(tag, "(?<attributeName>\\S*)=\"(?<attributeValue>[^\"]*)\"",
|
||||
RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace);
|
||||
foreach (Match attributeSet in m)
|
||||
ht.Add(attributeSet.Groups["attributeName"].Value.ToString(),
|
||||
attributeSet.Groups["attributeValue"].Value.ToString());
|
||||
|
||||
return ht;
|
||||
}
|
||||
|
||||
private int findStartTag(string text) {
|
||||
string temp = "";
|
||||
text = text.ToLower();
|
||||
if (text.IndexOf("ismacro=\"true\"") > -1) {
|
||||
temp = text.Substring(0, text.IndexOf("ismacro=\"true\""));
|
||||
return temp.LastIndexOf("<");
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
private int findEndTag(string text) {
|
||||
string find = "<!-- endumbmacro -->";
|
||||
|
||||
int endMacroIndex = text.ToLower().IndexOf(find);
|
||||
string tempText = text.ToLower().Substring(endMacroIndex + find.Length, text.Length - endMacroIndex - find.Length);
|
||||
int finalEndPos = 0;
|
||||
while (tempText.Length > 5)
|
||||
if (tempText.Substring(finalEndPos, 6) == "</div>")
|
||||
break;
|
||||
else
|
||||
finalEndPos++;
|
||||
|
||||
return endMacroIndex + find.Length + finalEndPos + 6;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IDataFieldWithButtons Members
|
||||
|
||||
public object[] MenuIcons {
|
||||
get {
|
||||
initButtons();
|
||||
|
||||
object[] tempIcons = new object[_menuIcons.Count];
|
||||
for (int i = 0; i < _menuIcons.Count; i++)
|
||||
tempIcons[i] = _menuIcons[i];
|
||||
return tempIcons;
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IMenuElement Members
|
||||
|
||||
public string ElementName {
|
||||
get { return "div"; }
|
||||
}
|
||||
|
||||
public string ElementIdPreFix {
|
||||
get { return "umbTinymceMenu"; }
|
||||
}
|
||||
|
||||
public string ElementClass {
|
||||
get { return "tinymceMenuBar"; }
|
||||
}
|
||||
|
||||
public int ExtraMenuWidth {
|
||||
get {
|
||||
initButtons();
|
||||
return _buttons.Count * 40 + 300;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
205
OLD/umbraco.Legacy/editorControls/tinymce/tinyMCEImageHelper.cs
Normal file
205
OLD/umbraco.Legacy/editorControls/tinymce/tinyMCEImageHelper.cs
Normal file
@@ -0,0 +1,205 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Drawing.Imaging;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Web;
|
||||
using umbraco.BusinessLogic;
|
||||
using umbraco.IO;
|
||||
|
||||
namespace umbraco.editorControls.tinymce
|
||||
{
|
||||
internal class tinyMCEImageHelper
|
||||
{
|
||||
public static string cleanImages(string html)
|
||||
{
|
||||
string[] allowedAttributes = UmbracoSettings.ImageAllowedAttributes.ToLower().Split(',');
|
||||
string pattern = @"<img [^>]*>";
|
||||
MatchCollection tags =
|
||||
Regex.Matches(html + " ", pattern, RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace);
|
||||
foreach (Match tag in tags)
|
||||
{
|
||||
if (tag.Value.ToLower().IndexOf("umbraco_macro") == -1)
|
||||
{
|
||||
string cleanTag = "<img";
|
||||
int orgWidth = 0, orgHeight = 0;
|
||||
// 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
|
||||
Hashtable ht = new Hashtable();
|
||||
MatchCollection m =
|
||||
Regex.Matches(tag.Value.Replace(">", " >"),
|
||||
"(?<attributeName>\\S*)=\"(?<attributeValue>[^\"]*)\"|(?<attributeName>\\S*)=(?<attributeValue>[^\"|\\s]*)\\s",
|
||||
RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace);
|
||||
foreach (Match attributeSet in m)
|
||||
{
|
||||
ht.Add(attributeSet.Groups["attributeName"].Value.ToString().ToLower(),
|
||||
attributeSet.Groups["attributeValue"].Value.ToString());
|
||||
if (attributeSet.Groups["attributeName"].Value.ToString().ToLower() == "width")
|
||||
orgWidth = int.Parse(attributeSet.Groups["attributeValue"].Value.ToString());
|
||||
else if (attributeSet.Groups["attributeName"].Value.ToString().ToLower() == "height")
|
||||
orgHeight = int.Parse(attributeSet.Groups["attributeValue"].Value.ToString());
|
||||
}
|
||||
|
||||
// If rel attribute exists and if it's different from current sizing we should resize the image!
|
||||
if (helper.FindAttribute(ht, "rel") != "")
|
||||
{
|
||||
int newWidth = 0, newHeight = 0;
|
||||
|
||||
// if size has changed resize image serverside
|
||||
string[] newDims = helper.FindAttribute(ht, "rel").Split(",".ToCharArray());
|
||||
if (newDims.Length > 0 &&
|
||||
(newDims[0] != helper.FindAttribute(ht, "width") ||
|
||||
newDims[1] != helper.FindAttribute(ht, "height")))
|
||||
{
|
||||
try
|
||||
{
|
||||
cleanTag += doResize(ht, out newWidth, out newHeight);
|
||||
}
|
||||
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") + "\"";
|
||||
}
|
||||
Log.Add(LogTypes.Error, User.GetUser(0), -1,
|
||||
"Error resizing image in editor: " + err.ToString());
|
||||
}
|
||||
} else
|
||||
{
|
||||
cleanTag = StripSrc(cleanTag, ht);
|
||||
|
||||
if (helper.FindAttribute(ht, "width") != "")
|
||||
{
|
||||
cleanTag += " width=\"" + helper.FindAttribute(ht, "width") + "\"";
|
||||
cleanTag += " height=\"" + helper.FindAttribute(ht, "height") + "\"";
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Add src, width and height properties
|
||||
cleanTag = StripSrc(cleanTag, ht);
|
||||
|
||||
|
||||
if (helper.FindAttribute(ht, "width") != "")
|
||||
{
|
||||
cleanTag += " width=\"" + helper.FindAttribute(ht, "width") + "\"";
|
||||
cleanTag += " height=\"" + helper.FindAttribute(ht, "height") + "\"";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
// Build image tag
|
||||
foreach (string attr in allowedAttributes)
|
||||
{
|
||||
if (helper.FindAttribute(ht, attr) != "")
|
||||
{
|
||||
string 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 StripSrc(string cleanTag, Hashtable ht)
|
||||
{
|
||||
string src = helper.FindAttribute(ht, "src");
|
||||
// update orgSrc to remove umbraco reference
|
||||
if (src.IndexOf("/media/") > -1)
|
||||
src = src.Substring(src.IndexOf("/media/"), src.Length - src.IndexOf("/media/"));
|
||||
|
||||
cleanTag += " src=\"" + src + "\"";
|
||||
return cleanTag;
|
||||
}
|
||||
|
||||
private static string doResize(Hashtable attributes, out int finalWidth, out int finalHeight)
|
||||
{
|
||||
string resizeDim = helper.FindAttribute(attributes, "width") + "," +
|
||||
helper.FindAttribute(attributes, "height");
|
||||
string[] resizeDimSplit = resizeDim.Split(',');
|
||||
string orgSrc = HttpContext.Current.Server.HtmlDecode(helper.FindAttribute(attributes, "src").Replace("%20", " "));
|
||||
string[] orgDim = helper.FindAttribute(attributes, "rel").Split(",".ToCharArray());
|
||||
float orgWidth = float.Parse(orgDim[0]);
|
||||
float orgHeight = float.Parse(orgDim[1]);
|
||||
string newSrc = "";
|
||||
int newWidth = int.Parse(resizeDimSplit[0]);
|
||||
int newHeight = int.Parse(resizeDimSplit[1]);
|
||||
|
||||
if (orgHeight > 0 && orgWidth > 0 && resizeDim != "" && orgSrc != "")
|
||||
{
|
||||
// Check dimensions
|
||||
if (Math.Abs(orgWidth/newWidth) > Math.Abs(orgHeight/newHeight))
|
||||
{
|
||||
newHeight = (int) Math.Round((float) newWidth*(orgHeight/orgWidth));
|
||||
}
|
||||
else
|
||||
{
|
||||
newWidth = (int) Math.Round((float) newHeight*(orgWidth/orgHeight));
|
||||
}
|
||||
|
||||
// update orgSrc to remove umbraco reference
|
||||
if (orgSrc.IndexOf("/media/") > -1)
|
||||
orgSrc = orgSrc.Substring(orgSrc.IndexOf("/media/"), orgSrc.Length - orgSrc.IndexOf("/media/"));
|
||||
|
||||
string ext = orgSrc.Substring(orgSrc.LastIndexOf(".") + 1, orgSrc.Length - orgSrc.LastIndexOf(".") - 1);
|
||||
newSrc = orgSrc.Replace("." + ext, "_" + newWidth.ToString() + "x" + newHeight.ToString() + ".jpg");
|
||||
|
||||
string fullSrc = IOHelper.MapPath(orgSrc);
|
||||
string fullSrcNew = IOHelper.MapPath(newSrc);
|
||||
|
||||
// Load original image
|
||||
Image image = Image.FromFile(fullSrc);
|
||||
|
||||
|
||||
// Create new image with best quality settings
|
||||
Bitmap bp = new Bitmap(newWidth, newHeight);
|
||||
Graphics g = Graphics.FromImage(bp);
|
||||
g.SmoothingMode = SmoothingMode.HighQuality;
|
||||
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
|
||||
g.PixelOffsetMode = PixelOffsetMode.HighQuality;
|
||||
|
||||
// Copy the old image to the new and resized
|
||||
Rectangle rect = new Rectangle(0, 0, newWidth, newHeight);
|
||||
g.DrawImage(image, rect, 0, 0, image.Width, image.Height, GraphicsUnit.Pixel);
|
||||
|
||||
// Copy metadata
|
||||
ImageCodecInfo[] codecs = ImageCodecInfo.GetImageEncoders();
|
||||
ImageCodecInfo codec = null;
|
||||
for (int i = 0; i < codecs.Length; i++)
|
||||
{
|
||||
if (codecs[i].MimeType.Equals("image/jpeg"))
|
||||
codec = codecs[i];
|
||||
}
|
||||
|
||||
// Set compresion ratio to 90%
|
||||
EncoderParameters ep = new EncoderParameters();
|
||||
ep.Param[0] = new EncoderParameter(Encoder.Quality, 90L);
|
||||
|
||||
// Save the new image
|
||||
bp.Save(fullSrcNew, codec, ep);
|
||||
}
|
||||
|
||||
// return the new width and height
|
||||
finalWidth = newWidth;
|
||||
finalHeight = newHeight;
|
||||
|
||||
return
|
||||
" src=\"" + newSrc + "\" width=\"" + newWidth.ToString() + "\" height=\"" + newHeight.ToString() +
|
||||
"\"";
|
||||
}
|
||||
}
|
||||
}
|
||||
403
OLD/umbraco.Legacy/editorControls/tinymce/webcontrol/TinyMCE.cs
Normal file
403
OLD/umbraco.Legacy/editorControls/tinymce/webcontrol/TinyMCE.cs
Normal file
@@ -0,0 +1,403 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Specialized;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Web;
|
||||
using System.Web.UI;
|
||||
using System.Web.UI.WebControls;
|
||||
using umbraco.BusinessLogic;
|
||||
using umbraco.cms.businesslogic.macro;
|
||||
using umbraco.cms.businesslogic.media;
|
||||
using umbraco.cms.businesslogic.property;
|
||||
using Content = umbraco.cms.businesslogic.Content;
|
||||
|
||||
namespace umbraco.editorControls.tinymce.webcontrol {
|
||||
public class TinyMCE : WebControl, IPostBackDataHandler {
|
||||
private string _javascriptLocation = GlobalSettings.ClientPath + "/tinymce";
|
||||
private string _coreFile = "/tiny_mce.js";
|
||||
private int _rows = 13;
|
||||
private int _cols = 60;
|
||||
public NameValueCollection config;
|
||||
private string temp;
|
||||
|
||||
private int _nodeId = -1;
|
||||
private Guid _versionId;
|
||||
|
||||
public int NodeId {
|
||||
set { _nodeId = value; }
|
||||
}
|
||||
|
||||
public Guid VersionId {
|
||||
set { _versionId = value; }
|
||||
}
|
||||
|
||||
public string CoreFile {
|
||||
get { return _coreFile; }
|
||||
}
|
||||
|
||||
|
||||
public TinyMCE() {
|
||||
config = new NameValueCollection();
|
||||
config.Add("mode", "exact");
|
||||
config.Add("theme", "advanced");
|
||||
|
||||
//content_css : "/mycontent.css"
|
||||
temp = string.Empty;
|
||||
|
||||
|
||||
//this._config.SetStringParam(TinyMCEConfig.StringParameter.mode, "exact");
|
||||
//this._config.SetStringParam(TinyMCEConfig.StringParameter.theme, "advanced");
|
||||
//this._config.SetStringParam(TinyMCEConfig.StringParameter.plugins, "advlink,noneditable,advimage,flash");
|
||||
//this._config.SetStringParam(TinyMCEConfig.StringParameter.theme_advanced_buttons3_add, "flash");
|
||||
}
|
||||
|
||||
// <summary>
|
||||
/// The text of the editor
|
||||
/// </summary>
|
||||
public string Text {
|
||||
get { return (string)ViewState["text"]; }
|
||||
set { ViewState["text"] = value; }
|
||||
}
|
||||
|
||||
// <summary>
|
||||
/// The number of rows in the textarea that gets converted to the editor.
|
||||
/// This affects the size of the editor. Default is 10
|
||||
/// </summary>
|
||||
public int Rows {
|
||||
get { return _rows; }
|
||||
set { _rows = value; }
|
||||
}
|
||||
|
||||
// <summary>
|
||||
/// The number of columns in the textarea that gets converted to the editor.
|
||||
/// This affects the size of the editor. Default is 40.
|
||||
/// </summary>
|
||||
public int Cols {
|
||||
get { return _cols; }
|
||||
set { _cols = value; }
|
||||
}
|
||||
|
||||
// <summary>
|
||||
/// Path to the TinyMCE javascript, default is "jscripts/tiny_mce/tiny_mce.js"
|
||||
/// </summary>
|
||||
public string JavascriptLocation {
|
||||
get { return _javascriptLocation; }
|
||||
set { _javascriptLocation = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Draws the editor
|
||||
/// </summary>
|
||||
/// <param name="outWriter">The writer to draw the editor to</param>
|
||||
protected override void Render(HtmlTextWriter writer) {
|
||||
writer.WriteLine("<!-- tinyMCE -->\n");
|
||||
|
||||
writer.WriteLine("<script language=\"javascript\" type=\"text/javascript\">");
|
||||
writer.WriteLine("tinyMCE.init({");
|
||||
|
||||
for (int i = 0; i < config.Count; i++) {
|
||||
writer.WriteLine(config.GetKey(i) + " : \"" + config.Get(i) + "\",");
|
||||
}
|
||||
writer.WriteLine("theme_advanced_resizing : true,");
|
||||
writer.WriteLine("theme_advanced_resize_horizontal : false,");
|
||||
writer.WriteLine("apply_source_formatting : true,");
|
||||
writer.WriteLine("relative_urls : false,");
|
||||
writer.WriteLine("valid_elements : {0},", tinyMCEConfiguration.ValidElements);
|
||||
writer.WriteLine("invalid_elements : \"{0}\",", tinyMCEConfiguration.InvalidElements);
|
||||
|
||||
writer.WriteLine("elements : \"" + UniqueID + "\",");
|
||||
writer.WriteLine("umbracoPath: \"" + GlobalSettings.Path + "\"");
|
||||
|
||||
|
||||
writer.WriteLine("});");
|
||||
|
||||
// write a message that this is deprecated
|
||||
writer.WriteLine("alert('This page use an old version of the Richtext Editor (TinyMCE2), which is deprecated and no longer supported in Umbraco 4. \\n\\nPlease upgrade by going to\\n- Developer\\n- Data Types\\n- Richtext editor\\n- And choose \\'TinyMCE3 wysiwyg\\' as the rendercontrol\\n\\nIf you don\\'t have administrative priviledges in umbraco, you should contact your administrator');");
|
||||
|
||||
writer.WriteLine("</script>\n");
|
||||
writer.WriteLine("<!-- /tinyMCE -->\n");
|
||||
|
||||
if (Cols > 0)
|
||||
writer.Write("<textarea class=\"tinymce" + UniqueID + "\" id=\"" + UniqueID + "\" name=\"" + UniqueID + "\" cols=\"" + Cols + "\" rows=\"" +
|
||||
Rows + "\" style=\"width: 100%\">\n");
|
||||
else
|
||||
writer.Write("<textarea class=\"tinymce" + UniqueID + "\" id=\"" + UniqueID + "\" name=\"" + UniqueID + "\">\n");
|
||||
|
||||
|
||||
// if the document exists, parse it for macros
|
||||
if (_nodeId != -1)
|
||||
writer.Write(parseMacrosToHtml(formatMedia(Text)));
|
||||
else
|
||||
writer.Write(Text);
|
||||
writer.WriteLine("</textarea>");
|
||||
}
|
||||
|
||||
private string formatMedia(string html) {
|
||||
// Local media path
|
||||
string localMediaPath = getLocalMediaPath();
|
||||
|
||||
// Find all media images
|
||||
string pattern = "<img [^>]*src=\"(?<mediaString>/media[^\"]*)\" [^>]*>";
|
||||
|
||||
MatchCollection tags =
|
||||
Regex.Matches(html, pattern, RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace);
|
||||
foreach (Match tag in tags)
|
||||
if (tag.Groups.Count > 0) {
|
||||
// Replace /> to ensure we're in old-school html mode
|
||||
string tempTag = "<img";
|
||||
string orgSrc = tag.Groups["mediaString"].Value;
|
||||
|
||||
// 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
|
||||
Hashtable ht = new Hashtable();
|
||||
MatchCollection m =
|
||||
Regex.Matches(tag.Value.Replace(">", " >"),
|
||||
"(?<attributeName>\\S*)=\"(?<attributeValue>[^\"]*)\"|(?<attributeName>\\S*)=(?<attributeValue>[^\"|\\s]*)\\s",
|
||||
RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace);
|
||||
foreach (Match attributeSet in m) {
|
||||
if (attributeSet.Groups["attributeName"].Value.ToString().ToLower() != "src")
|
||||
ht.Add(attributeSet.Groups["attributeName"].Value.ToString(),
|
||||
attributeSet.Groups["attributeValue"].Value.ToString());
|
||||
}
|
||||
|
||||
// build the element
|
||||
// Build image tag
|
||||
IDictionaryEnumerator ide = ht.GetEnumerator();
|
||||
while (ide.MoveNext())
|
||||
tempTag += " " + ide.Key.ToString() + "=\"" + ide.Value.ToString() + "\"";
|
||||
|
||||
// Find the original filename, by removing the might added width and height
|
||||
orgSrc =
|
||||
orgSrc.Replace(
|
||||
"_" + helper.FindAttribute(ht, "width") + "x" + helper.FindAttribute(ht, "height"), "").
|
||||
Replace("%20", " ");
|
||||
|
||||
// Check for either id or guid from media
|
||||
string mediaId = getIdFromSource(orgSrc, localMediaPath);
|
||||
|
||||
Media imageMedia = null;
|
||||
|
||||
try {
|
||||
int mId = int.Parse(mediaId);
|
||||
Property p = new Property(mId);
|
||||
imageMedia = new Media(Content.GetContentFromVersion(p.VersionId).Id);
|
||||
} catch {
|
||||
try {
|
||||
imageMedia = new Media(Content.GetContentFromVersion(new Guid(mediaId)).Id);
|
||||
} catch {
|
||||
}
|
||||
}
|
||||
|
||||
// Check with the database if any media matches this url
|
||||
if (imageMedia != null) {
|
||||
try {
|
||||
// Check extention
|
||||
if (imageMedia.getProperty("umbracoExtension").Value.ToString() != orgSrc.Substring(orgSrc.LastIndexOf(".") + 1, orgSrc.Length - orgSrc.LastIndexOf(".") - 1))
|
||||
orgSrc = orgSrc.Substring(0, orgSrc.LastIndexOf(".") + 1) +
|
||||
imageMedia.getProperty("umbracoExtension").Value.ToString();
|
||||
|
||||
// Format the tag
|
||||
tempTag = tempTag + " rel=\"" +
|
||||
imageMedia.getProperty("umbracoWidth").Value.ToString() + "," +
|
||||
imageMedia.getProperty("umbracoHeight").Value.ToString() + "\" src=\"" + orgSrc +
|
||||
"\"";
|
||||
tempTag += "/>";
|
||||
|
||||
// Replace the tag
|
||||
html = html.Replace(tag.Value, tempTag);
|
||||
} catch (Exception ee) {
|
||||
Log.Add(LogTypes.Error, User.GetUser(0), -1,
|
||||
"Error reading size data from media: " + imageMedia.Id.ToString() + ", " +
|
||||
ee.ToString());
|
||||
}
|
||||
} else
|
||||
Log.Add(LogTypes.Error, User.GetUser(0), -1,
|
||||
"Error reading size data from media (not found): " + orgSrc);
|
||||
}
|
||||
return html;
|
||||
}
|
||||
|
||||
private string getIdFromSource(string src, string localMediaPath) {
|
||||
// important - remove out the umbraco path + media!
|
||||
src = src.Replace(localMediaPath, "");
|
||||
|
||||
string _id = "";
|
||||
|
||||
// Check for directory id naming
|
||||
if (src.Length - src.Replace("/", "").Length > 0) {
|
||||
string[] dirSplit = src.Split("/".ToCharArray());
|
||||
string tempId = dirSplit[0];
|
||||
try {
|
||||
// id
|
||||
_id = int.Parse(tempId).ToString();
|
||||
} catch {
|
||||
// guid
|
||||
_id = tempId;
|
||||
}
|
||||
} else {
|
||||
string[] fileSplit = src.Replace("/media/", "").Split("-".ToCharArray());
|
||||
|
||||
// guid or id
|
||||
if (fileSplit.Length > 3) {
|
||||
for (int i = 0; i < 5; i++)
|
||||
_id += fileSplit[i] + "-";
|
||||
_id = _id.Substring(0, _id.Length - 1);
|
||||
} else
|
||||
_id = fileSplit[0];
|
||||
}
|
||||
|
||||
return _id;
|
||||
}
|
||||
|
||||
private string getLocalMediaPath() {
|
||||
string[] umbracoPathSplit = GlobalSettings.Path.Split("/".ToCharArray());
|
||||
string umbracoPath = "";
|
||||
for (int i = 0; i < umbracoPathSplit.Length - 1; i++)
|
||||
umbracoPath += umbracoPathSplit[i] + "/";
|
||||
return umbracoPath + "media/";
|
||||
}
|
||||
|
||||
|
||||
private string parseMacrosToHtml(string input) {
|
||||
int nodeId = _nodeId;
|
||||
Guid versionId = _versionId;
|
||||
string content = input;
|
||||
|
||||
|
||||
string pattern = @"(<\?UMBRACO_MACRO\W*[^>]*/>)";
|
||||
MatchCollection tags =
|
||||
Regex.Matches(content, pattern, RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace);
|
||||
|
||||
// Page for macro rendering
|
||||
page p = new page(nodeId, versionId);
|
||||
HttpContext.Current.Items["macrosAdded"] = 0;
|
||||
HttpContext.Current.Items["pageID"] = nodeId.ToString();
|
||||
|
||||
foreach (Match tag in tags) {
|
||||
try {
|
||||
// Create div
|
||||
Hashtable attributes = helper.ReturnAttributes(tag.Groups[1].Value);
|
||||
string div = macro.renderMacroStartTag(attributes, nodeId, versionId).Replace(""", "&quot;");
|
||||
|
||||
// Insert macro contents here...
|
||||
macro m;
|
||||
if (helper.FindAttribute(attributes, "macroID") != "")
|
||||
m = new macro(int.Parse(helper.FindAttribute(attributes, "macroID")));
|
||||
else {
|
||||
// legacy: Check if the macroAlias is typed in lowercasing
|
||||
string macroAlias = helper.FindAttribute(attributes, "macroAlias");
|
||||
if (macroAlias == "") {
|
||||
macroAlias = helper.FindAttribute(attributes, "macroalias");
|
||||
attributes.Remove("macroalias");
|
||||
attributes.Add("macroAlias", macroAlias);
|
||||
}
|
||||
|
||||
if (macroAlias != "")
|
||||
m = new macro(Macro.GetByAlias(macroAlias).Id);
|
||||
else
|
||||
throw new ArgumentException("umbraco is unable to identify the macro. No id or macroalias was provided for the macro in the macro tag.", tag.Groups[1].Value);
|
||||
}
|
||||
|
||||
if (helper.FindAttribute(attributes, "macroAlias") == "")
|
||||
attributes.Add("macroAlias", m.Alias);
|
||||
|
||||
|
||||
try {
|
||||
div += macro.MacroContentByHttp(nodeId, versionId, attributes);
|
||||
} catch {
|
||||
div += "<span style=\"color: green\">No macro content available for WYSIWYG editing</span>";
|
||||
}
|
||||
|
||||
|
||||
div += macro.renderMacroEndTag();
|
||||
content = content.Replace(tag.Groups[1].Value, div);
|
||||
} catch (Exception ee) {
|
||||
Log.Add(LogTypes.Error, this._nodeId, "Macro Parsing Error: " + ee.ToString());
|
||||
string div = "<div class=\"umbMacroHolder mceNonEditable\"><p style=\"color: red\"><strong>umbraco was unable to parse a macro tag, which means that parts of this content might be corrupt.</strong> <br /><br />Best solution is to rollback to a previous version by right clicking the node in the tree and then try to insert the macro again. <br/><br/>Please report this to your system administrator as well - this error has been logged.</p></div>";
|
||||
content = content.Replace(tag.Groups[1].Value, div);
|
||||
}
|
||||
|
||||
}
|
||||
return content;
|
||||
}
|
||||
|
||||
private static readonly object TextChangedEvent = new object();
|
||||
|
||||
/// <summary>
|
||||
/// Raises an event when the text in the editor changes.
|
||||
/// </summary>
|
||||
public event EventHandler TextChanged {
|
||||
add { Events.AddHandler(TextChangedEvent, value); }
|
||||
remove { Events.RemoveHandler(TextChangedEvent, value); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Event for text change.
|
||||
/// </summary>
|
||||
/// <param name="e"></param>
|
||||
protected virtual void OnTextChanged(EventArgs e) {
|
||||
if (Events != null) {
|
||||
EventHandler oEventHandler = (EventHandler)Events[TextChangedEvent];
|
||||
if (oEventHandler != null) {
|
||||
oEventHandler(this, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called when a postback occurs on the page the control is placed at
|
||||
/// </summary>
|
||||
/// <param name="postDataKey">The key of the editor data</param>
|
||||
/// <param name="postCollection">All the posted data</param>
|
||||
/// <returns></returns>
|
||||
bool IPostBackDataHandler.LoadPostData(string postDataKey, NameValueCollection postCollection) {
|
||||
string newText = postCollection[postDataKey];
|
||||
|
||||
if (newText != Text) {
|
||||
Text = newText;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Raises an event when postback occurs
|
||||
/// </summary>
|
||||
void IPostBackDataHandler.RaisePostDataChangedEvent() {
|
||||
OnTextChanged(EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
public enum TinyMceButtons {
|
||||
code,
|
||||
bold,
|
||||
italic,
|
||||
underline,
|
||||
strikethrough,
|
||||
justifyleft,
|
||||
justifycenter,
|
||||
justifyright,
|
||||
justifyfull,
|
||||
bullist,
|
||||
numlist,
|
||||
outdent,
|
||||
indent,
|
||||
cut,
|
||||
copy,
|
||||
pasteword,
|
||||
undo,
|
||||
redo,
|
||||
link,
|
||||
unlink,
|
||||
image,
|
||||
table,
|
||||
hr,
|
||||
removeformat,
|
||||
sub,
|
||||
sup,
|
||||
charmap,
|
||||
anchor,
|
||||
umbracomacro
|
||||
}
|
||||
}
|
||||
56
OLD/umbraco.Legacy/editorControls/wysiwyg/WysiwygDataType.cs
Normal file
56
OLD/umbraco.Legacy/editorControls/wysiwyg/WysiwygDataType.cs
Normal file
@@ -0,0 +1,56 @@
|
||||
using System;
|
||||
|
||||
namespace umbraco.editorControls.wysiwyg
|
||||
{
|
||||
/// <summary>
|
||||
/// Summary description for WysiwygDataType.
|
||||
/// </summary>
|
||||
public class WysiwygDataType : cms.businesslogic.datatype.BaseDataType,interfaces.IDataType
|
||||
{
|
||||
private editor _Editor;
|
||||
private cms.businesslogic.datatype.DefaultData _baseData;
|
||||
private interfaces.IDataPrevalue _prevalueeditor;
|
||||
|
||||
public override interfaces.IDataEditor DataEditor
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_Editor == null)
|
||||
{
|
||||
_Editor = new editor((cms.businesslogic.datatype.DefaultData)Data);
|
||||
|
||||
}
|
||||
return _Editor;
|
||||
}
|
||||
}
|
||||
|
||||
public override interfaces.IData Data
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_baseData == null)
|
||||
_baseData = new cms.businesslogic.datatype.DefaultData(this);
|
||||
return _baseData;
|
||||
}
|
||||
}
|
||||
public override Guid Id
|
||||
{
|
||||
get {return new Guid("a3776494-0574-4d93-b7de-efdfdec6f2d1");}
|
||||
}
|
||||
|
||||
public override string DataTypeName
|
||||
{
|
||||
get {return "Editor";}
|
||||
}
|
||||
|
||||
public override interfaces.IDataPrevalue PrevalueEditor
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_prevalueeditor == null)
|
||||
_prevalueeditor = new DefaultPrevalueEditor(this,false);
|
||||
return _prevalueeditor;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
563
OLD/umbraco.Legacy/editorControls/wysiwyg/editor.cs
Normal file
563
OLD/umbraco.Legacy/editorControls/wysiwyg/editor.cs
Normal file
@@ -0,0 +1,563 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Drawing.Imaging;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Web;
|
||||
using System.Web.UI;
|
||||
using System.Web.UI.WebControls;
|
||||
using umbraco.BusinessLogic;
|
||||
using umbraco.interfaces;
|
||||
using umbraco.uicontrols;
|
||||
|
||||
namespace umbraco.editorControls.wysiwyg
|
||||
{
|
||||
/// <summary>
|
||||
/// Generates a field for typing numeric data
|
||||
/// </summary>
|
||||
public class editor : HiddenField, IDataFieldWithButtons
|
||||
{
|
||||
private ArrayList _buttons = new ArrayList();
|
||||
private bool _isInitialized = false;
|
||||
private String _text;
|
||||
private ArrayList _menuIcons = new ArrayList();
|
||||
|
||||
private bool _browserIsCompatible = false;
|
||||
|
||||
private cms.businesslogic.datatype.DefaultData _data;
|
||||
|
||||
public editor(cms.businesslogic.datatype.DefaultData Data)
|
||||
{
|
||||
_data = Data;
|
||||
|
||||
if (HttpContext.Current.Request.Browser.Win32 &&
|
||||
HttpContext.Current.Request.Browser.Browser == "IE")
|
||||
_browserIsCompatible = true;
|
||||
}
|
||||
|
||||
public virtual bool TreatAsRichTextEditor
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
|
||||
public bool ShowLabel
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public Control Editor
|
||||
{
|
||||
get { return this; }
|
||||
}
|
||||
|
||||
public String Text
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_text == null) return "";
|
||||
HttpContext.Current.Trace.Warn("return text", _text);
|
||||
return _text;
|
||||
}
|
||||
set
|
||||
{
|
||||
_text = " " + value + " ";
|
||||
if (_text.Trim() != "")
|
||||
{
|
||||
// Check for umbraco tags
|
||||
string pattern = @"[^'](<\?UMBRACO_MACRO\W*[^>]*/>)[^']";
|
||||
MatchCollection tags =
|
||||
Regex.Matches(_text, pattern, RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace);
|
||||
foreach (Match tag in tags)
|
||||
{
|
||||
_text =
|
||||
_text.Replace(tag.Groups[1].Value,
|
||||
"<IMG alt='" + tag.Groups[1].Value + "' src=\"/imagesmacroo.gif\">");
|
||||
}
|
||||
|
||||
// Clean urls
|
||||
// _text = _text.Replace("http://" + System.Web.HttpContext.Current.Request.ServerVariables["SERVER_NAME"], "").Replace("HTTP://" + System.Web.HttpContext.Current.Request.ServerVariables["SERVER_NAME"], "");
|
||||
}
|
||||
base.Value = _text.Trim();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public virtual object[] MenuIcons
|
||||
{
|
||||
get
|
||||
{
|
||||
initButtons();
|
||||
|
||||
object[] tempIcons = new object[_menuIcons.Count];
|
||||
for (int i = 0; i < _menuIcons.Count; i++)
|
||||
tempIcons[i] = _menuIcons[i];
|
||||
return tempIcons;
|
||||
}
|
||||
}
|
||||
|
||||
public override string Value
|
||||
{
|
||||
get { return base.Value; }
|
||||
set
|
||||
{
|
||||
base.Value = " " + value + " ";
|
||||
// Check for umbraco tags
|
||||
string pattern = @"[^'](<\?UMBRACO_MACRO\W*[^>]*/>)[^']";
|
||||
MatchCollection tags =
|
||||
Regex.Matches(base.Value + " ", pattern,
|
||||
RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace);
|
||||
foreach (Match tag in tags)
|
||||
{
|
||||
base.Value =
|
||||
base.Value.Replace(tag.Groups[1].Value,
|
||||
"<IMG alt='" + tag.Groups[1].Value + "' src=\"/imagesmacroo.gif\">");
|
||||
}
|
||||
|
||||
Text = base.Value.Trim();
|
||||
}
|
||||
}
|
||||
|
||||
private string cleanImages(string html)
|
||||
{
|
||||
string[] allowedAttributes = UmbracoSettings.ImageAllowedAttributes.ToLower().Split(',');
|
||||
string pattern = @"<img [^>]*>";
|
||||
MatchCollection tags =
|
||||
Regex.Matches(html + " ", pattern, RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace);
|
||||
foreach (Match tag in tags)
|
||||
{
|
||||
if (tag.Value.ToLower().IndexOf("umbraco_macro") == -1)
|
||||
{
|
||||
string 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
|
||||
Hashtable ht = new Hashtable();
|
||||
MatchCollection m =
|
||||
Regex.Matches(tag.Value.Replace(">", " >"),
|
||||
"(?<attributeName>\\S*)=\"(?<attributeValue>[^\"]*)\"|(?<attributeName>\\S*)=(?<attributeValue>[^\"|\\s]*)\\s",
|
||||
RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace);
|
||||
foreach (Match attributeSet in m)
|
||||
ht.Add(attributeSet.Groups["attributeName"].Value.ToString().ToLower(),
|
||||
attributeSet.Groups["attributeValue"].Value.ToString());
|
||||
|
||||
// Build image tag
|
||||
foreach (string attr in allowedAttributes)
|
||||
{
|
||||
if (helper.FindAttribute(ht, attr) != "")
|
||||
cleanTag += " " + attr + "=\"" + helper.FindAttribute(ht, attr) + "\"";
|
||||
}
|
||||
|
||||
// If umbracoResizeImage attribute exists we should resize the image!
|
||||
if (helper.FindAttribute(ht, "umbracoresizeimage") != "")
|
||||
{
|
||||
try
|
||||
{
|
||||
cleanTag += doResize(ht);
|
||||
}
|
||||
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") + "\"";
|
||||
}
|
||||
Log.Add(LogTypes.Error, User.GetUser(0), -1,
|
||||
"Error resizing image in editor: " + err.ToString());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Add src, width and height properties
|
||||
cleanTag += " src=\"" + helper.FindAttribute(ht, "src") + "\"";
|
||||
|
||||
if (helper.FindAttribute(ht, "width") != "")
|
||||
{
|
||||
cleanTag += " width=\"" + helper.FindAttribute(ht, "width") + "\"";
|
||||
cleanTag += " height=\"" + helper.FindAttribute(ht, "height") + "\"";
|
||||
}
|
||||
}
|
||||
|
||||
if (bool.Parse(GlobalSettings.EditXhtmlMode))
|
||||
cleanTag += "/";
|
||||
cleanTag += ">";
|
||||
html = html.Replace(tag.Value, cleanTag);
|
||||
}
|
||||
}
|
||||
|
||||
return html;
|
||||
}
|
||||
|
||||
private string doResize(Hashtable attributes)
|
||||
{
|
||||
string resizeDim = helper.FindAttribute(attributes, "umbracoresizeimage");
|
||||
string[] resizeDimSplit = resizeDim.Split(',');
|
||||
string orgSrc = helper.FindAttribute(attributes, "src").Replace("%20", " ");
|
||||
int orgHeight = int.Parse(helper.FindAttribute(attributes, "umbracoorgheight"));
|
||||
int orgWidth = int.Parse(helper.FindAttribute(attributes, "umbracoorgwidth"));
|
||||
string beforeWidth = helper.FindAttribute(attributes, "umbracobeforeresizewidth");
|
||||
string beforeHeight = helper.FindAttribute(attributes, "umbracobeforeresizeheight");
|
||||
string newSrc = "";
|
||||
|
||||
if (orgHeight > 0 && orgWidth > 0 && resizeDim != "" && orgSrc != "")
|
||||
{
|
||||
// Check filename
|
||||
if (beforeHeight != "" && beforeWidth != "")
|
||||
{
|
||||
orgSrc = orgSrc.Replace("_" + beforeWidth + "x" + beforeHeight, "");
|
||||
}
|
||||
string ext = orgSrc.Substring(orgSrc.LastIndexOf(".") + 1, orgSrc.Length - orgSrc.LastIndexOf(".") - 1);
|
||||
newSrc = orgSrc.Replace("." + ext, "_" + resizeDimSplit[0] + "x" + resizeDimSplit[1] + ".jpg");
|
||||
|
||||
string fullSrc = HttpContext.Current.Server.MapPath(orgSrc);
|
||||
string fullSrcNew = HttpContext.Current.Server.MapPath(newSrc);
|
||||
|
||||
// Load original image
|
||||
System.Drawing.Image image = System.Drawing.Image.FromFile(fullSrc);
|
||||
|
||||
// Create new image with best quality settings
|
||||
Bitmap bp = new Bitmap(int.Parse(resizeDimSplit[0]), int.Parse(resizeDimSplit[1]));
|
||||
Graphics g = Graphics.FromImage(bp);
|
||||
g.SmoothingMode = SmoothingMode.HighQuality;
|
||||
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
|
||||
g.PixelOffsetMode = PixelOffsetMode.HighQuality;
|
||||
|
||||
// Copy the old image to the new and resized
|
||||
Rectangle rect = new Rectangle(0, 0, int.Parse(resizeDimSplit[0]), int.Parse(resizeDimSplit[1]));
|
||||
g.DrawImage(image, rect, 0, 0, image.Width, image.Height, GraphicsUnit.Pixel);
|
||||
|
||||
// Copy metadata
|
||||
ImageCodecInfo[] codecs = ImageCodecInfo.GetImageEncoders();
|
||||
ImageCodecInfo codec = null;
|
||||
for (int i = 0; i < codecs.Length; i++)
|
||||
{
|
||||
if (codecs[i].MimeType.Equals("image/jpeg"))
|
||||
codec = codecs[i];
|
||||
}
|
||||
|
||||
// Set compresion ratio to 90%
|
||||
EncoderParameters ep = new EncoderParameters();
|
||||
ep.Param[0] = new EncoderParameter(Encoder.Quality, 90L);
|
||||
|
||||
// Save the new image
|
||||
bp.Save(fullSrcNew, codec, ep);
|
||||
orgSrc = newSrc;
|
||||
}
|
||||
|
||||
return " src=\"" + newSrc + "\" width=\"" + resizeDimSplit[0] + "\" height=\"" + resizeDimSplit[1] + "\"";
|
||||
}
|
||||
|
||||
public void Save()
|
||||
{
|
||||
if (Text.Trim() != "")
|
||||
{
|
||||
// Parse for servername
|
||||
if (HttpContext.Current.Request.ServerVariables != null)
|
||||
{
|
||||
_text = _text.Replace(helper.GetBaseUrl(HttpContext.Current) + GlobalSettings.Path + "/", "");
|
||||
_text = _text.Replace(helper.GetBaseUrl(HttpContext.Current), "");
|
||||
}
|
||||
|
||||
// Parse for editing scriptname
|
||||
string pattern2 = GlobalSettings.Path + "/richTextHolder.aspx?[^#]*#";
|
||||
MatchCollection tags2 =
|
||||
Regex.Matches(_text, pattern2, RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace);
|
||||
foreach (Match tag in tags2)
|
||||
{
|
||||
_text = _text.Replace(tag.Value, "");
|
||||
HttpContext.Current.Trace.Warn("editor-match", tag.Value);
|
||||
}
|
||||
|
||||
// Parse for macros inside images
|
||||
string pattern = @"<IMG\W*alt='(<?[^>]*>)'[^>]*>";
|
||||
MatchCollection tags =
|
||||
Regex.Matches(_text, pattern, RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace);
|
||||
foreach (Match tag in tags)
|
||||
if (tag.Groups.Count > 0)
|
||||
{
|
||||
string umbTag = tag.Groups[1].Value;
|
||||
// Check for backwards compliance with old macro-tag format (<?UMBRACO_MACRO xxxx> vs. new format with closed tags: <?UMBRACO_MACRO xxxx/>)
|
||||
if (umbTag.IndexOf("/>") < 0)
|
||||
umbTag = umbTag.Substring(0, umbTag.Length - 1) + "/>";
|
||||
|
||||
_text = _text.Replace(tag.Value, umbTag);
|
||||
}
|
||||
|
||||
|
||||
// check for image tags
|
||||
_text = cleanImages(_text);
|
||||
|
||||
_text = replaceMacroTags(_text).Trim();
|
||||
|
||||
// clean macros and add paragraph element for tidy
|
||||
bool removeParagraphs = false;
|
||||
if (_text.Length > 15 && _text.ToLower().Substring(0, 17) == "|||?umbraco_macro")
|
||||
{
|
||||
removeParagraphs = true;
|
||||
_text = "<p>" + _text + "</p>";
|
||||
}
|
||||
|
||||
// tidy html
|
||||
|
||||
if (UmbracoSettings.TidyEditorContent)
|
||||
{
|
||||
string tidyTxt = library.Tidy(_text, false);
|
||||
if (tidyTxt != "[error]")
|
||||
{
|
||||
// compensate for breaking macro tags by tidy
|
||||
_text = tidyTxt.Replace("/?>", "/>");
|
||||
if (removeParagraphs)
|
||||
{
|
||||
if (_text.Length - _text.Replace("<", "").Length == 2)
|
||||
_text = _text.Replace("<p>", "").Replace("</p>", "");
|
||||
}
|
||||
}
|
||||
else
|
||||
Log.Add(LogTypes.Error, User.GetUser(0), _data.NodeId,
|
||||
"Error tidying txt from property: " + _data.PropertyId.ToString());
|
||||
}
|
||||
|
||||
// rescue umbraco tags
|
||||
_text = _text.Replace("|||?", "<?").Replace("/|||", "/>").Replace("|*|", "\"");
|
||||
|
||||
// if text is an empty parargraph, make it all empty
|
||||
if (_text.ToLower() == "<p></p>")
|
||||
_text = "";
|
||||
}
|
||||
|
||||
// cms.businesslogic.Content.GetContentFromVersion(_version).getProperty(_alias).Value = Text;
|
||||
|
||||
_data.Value = Text;
|
||||
}
|
||||
|
||||
private string replaceMacroTags(string text)
|
||||
{
|
||||
while (findStartTag(text) > -1)
|
||||
{
|
||||
string result = text.Substring(findStartTag(text), findEndTag(text) - findStartTag(text));
|
||||
text = text.Replace(result, generateMacroTag(result));
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
||||
private string generateMacroTag(string macroContent)
|
||||
{
|
||||
string macroAttr = macroContent.Substring(5, macroContent.IndexOf(">") - 5);
|
||||
string macroTag = "|||?UMBRACO_MACRO ";
|
||||
Hashtable attributes = ReturnAttributes(macroAttr);
|
||||
IDictionaryEnumerator ide = attributes.GetEnumerator();
|
||||
while (ide.MoveNext())
|
||||
{
|
||||
if (ide.Key.ToString().IndexOf("umb_") != -1)
|
||||
macroTag += ide.Key.ToString().Substring(4, ide.Key.ToString().Length - 4) + "=|*|" +
|
||||
ide.Value.ToString() + "|*| ";
|
||||
}
|
||||
macroTag += "/|||";
|
||||
|
||||
return macroTag;
|
||||
}
|
||||
|
||||
public static Hashtable ReturnAttributes(String tag)
|
||||
{
|
||||
Hashtable ht = new Hashtable();
|
||||
MatchCollection m =
|
||||
Regex.Matches(tag, "(?<attributeName>\\S*)=\"(?<attributeValue>[^\"]*)\"",
|
||||
RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace);
|
||||
foreach (Match attributeSet in m)
|
||||
ht.Add(attributeSet.Groups["attributeName"].Value.ToString(),
|
||||
attributeSet.Groups["attributeValue"].Value.ToString());
|
||||
|
||||
return ht;
|
||||
}
|
||||
|
||||
private int findStartTag(string text)
|
||||
{
|
||||
string temp = "";
|
||||
text = text.ToLower();
|
||||
if (text.IndexOf("ismacro=\"true\"") > -1)
|
||||
{
|
||||
temp = text.Substring(0, text.IndexOf("ismacro=\"true\""));
|
||||
return temp.LastIndexOf("<");
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
private int findEndTag(string text)
|
||||
{
|
||||
string find = "<!-- endumbmacro --></div>";
|
||||
return text.ToLower().IndexOf("<!-- endumbmacro --></div>") + find.Length;
|
||||
}
|
||||
|
||||
private void initButtons()
|
||||
{
|
||||
if (!_isInitialized)
|
||||
{
|
||||
_isInitialized = true;
|
||||
|
||||
// Test for browser compliance
|
||||
if (_browserIsCompatible)
|
||||
{
|
||||
// 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
|
||||
_buttons.Add(
|
||||
new editorButton("html", ui.Text("buttons", "htmlEdit", null),
|
||||
GlobalSettings.Path + "/images/editor/html.gif", "viewHTML('" + ClientID + "')"));
|
||||
_buttons.Add("split");
|
||||
_buttons.Add(
|
||||
new editorButton("showstyles", ui.Text("buttons", "styleShow", null) + " (CTRL+SHIFT+V)",
|
||||
GlobalSettings.Path + "/images/editor/showStyles.gif",
|
||||
"umbracoShowStyles('" + ClientID + "')"));
|
||||
_buttons.Add("split");
|
||||
_buttons.Add(
|
||||
new editorButton("bold", ui.Text("buttons", "bold", null) + " (CTRL+B)",
|
||||
GlobalSettings.Path + "/images/editor/bold.gif",
|
||||
"umbracoEditorCommand('" + ClientID + "', 'bold', '')"));
|
||||
_buttons.Add(
|
||||
new editorButton("italic", ui.Text("buttons", "italic", null) + " (CTRL+I)",
|
||||
GlobalSettings.Path + "/images/editor/italic.gif",
|
||||
"umbracoEditorCommand('" + ClientID + "', 'italic', '')"));
|
||||
_buttons.Add(
|
||||
new editorButton("graphicheadline", ui.Text("buttons", "graphicHeadline", null) + "(CTRL+B)",
|
||||
GlobalSettings.Path + "/images/editor/umbracoTextGen.gif",
|
||||
"umbracoTextGen('" + ClientID + "')"));
|
||||
_buttons.Add("split");
|
||||
_buttons.Add(
|
||||
new editorButton("justifyleft", ui.Text("buttons", "justifyLeft", null),
|
||||
GlobalSettings.Path + "/images/editor/left.gif",
|
||||
"umbracoEditorCommand('" + ClientID + "', 'justifyleft', '')"));
|
||||
_buttons.Add(
|
||||
new editorButton("justifycenter", ui.Text("buttons", "justifyCenter", null),
|
||||
GlobalSettings.Path + "/images/editor/center.gif",
|
||||
"umbracoEditorCommand('" + ClientID + "', 'justifycenter', '')"));
|
||||
_buttons.Add(
|
||||
new editorButton("justifyright", ui.Text("buttons", "justifyRight", null),
|
||||
GlobalSettings.Path + "/images/editor/right.gif",
|
||||
"umbracoEditorCommand('" + ClientID + "', 'justifyright', '')"));
|
||||
_buttons.Add("split");
|
||||
_buttons.Add(
|
||||
new editorButton("listBullet", ui.Text("buttons", "listBullet", null),
|
||||
GlobalSettings.Path + "/images/editor/bullist.gif",
|
||||
"umbracoEditorCommand('" + ClientID + "', 'insertUnorderedList', '')"));
|
||||
_buttons.Add(
|
||||
new editorButton("listNumeric", ui.Text("buttons", "listNumeric", null),
|
||||
GlobalSettings.Path + "/images/editor/numlist.gif",
|
||||
"umbracoEditorCommand('" + ClientID + "', 'insertOrderedList', '')"));
|
||||
_buttons.Add(
|
||||
new editorButton("deindent", ui.Text("buttons", "deindent", null),
|
||||
GlobalSettings.Path + "/images/editor/deindent.gif",
|
||||
"umbracoEditorCommand('" + ClientID + "', 'Outdent', '')"));
|
||||
_buttons.Add(
|
||||
new editorButton("indent", ui.Text("buttons", "indent", null),
|
||||
GlobalSettings.Path + "/images/editor/inindent.gif",
|
||||
"umbracoEditorCommand('" + ClientID + "', 'Indent', '')"));
|
||||
_buttons.Add("split");
|
||||
_buttons.Add(
|
||||
new editorButton("linkInsert", ui.Text("buttons", "linkInsert", null),
|
||||
GlobalSettings.Path + "/images/editor/link.gif",
|
||||
"umbracoLink('" + ClientID + "')"));
|
||||
_buttons.Add(
|
||||
new editorButton("linkLocal", ui.Text("buttons", "linkLocal", null),
|
||||
GlobalSettings.Path + "/images/editor/anchor.gif",
|
||||
"umbracoAnchor('" + ClientID + "')"));
|
||||
_buttons.Add("split");
|
||||
_buttons.Add(
|
||||
new editorButton("pictureInsert", ui.Text("buttons", "pictureInsert", null),
|
||||
GlobalSettings.Path + "/images/editor/image.gif",
|
||||
"umbracoImage('" + ClientID + "')"));
|
||||
_buttons.Add(
|
||||
new editorButton("macroInsert", ui.Text("buttons", "macroInsert", null),
|
||||
GlobalSettings.Path + "/images/editor/insMacro.gif",
|
||||
"umbracoInsertMacro('" + ClientID + "', '" + GlobalSettings.Path + "')"));
|
||||
_buttons.Add(
|
||||
new editorButton("tableInsert", ui.Text("buttons", "tableInsert", null),
|
||||
GlobalSettings.Path + "/images/editor/instable.gif",
|
||||
"umbracoInsertTable('" + ClientID + "', '" + GlobalSettings.Path + "')"));
|
||||
_buttons.Add(
|
||||
new editorButton("formFieldInsert", ui.Text("buttons", "formFieldInsert", null),
|
||||
GlobalSettings.Path + "/images/editor/form.gif",
|
||||
"umbracoInsertForm('" + ClientID + "', '" + GlobalSettings.Path + "')"));
|
||||
|
||||
// add save icon
|
||||
foreach (object o in _buttons)
|
||||
{
|
||||
try
|
||||
{
|
||||
MenuIconI menuItem = new MenuIconClass();
|
||||
|
||||
editorButton e = (editorButton)o;
|
||||
menuItem.OnClickCommand = e.onClickCommand;
|
||||
menuItem.ImageURL = e.imageUrl;
|
||||
menuItem.AltText = e.alttag;
|
||||
menuItem.ID = e.id;
|
||||
_menuIcons.Add(menuItem);
|
||||
}
|
||||
catch
|
||||
{
|
||||
_menuIcons.Add("|");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnLoad(EventArgs e)
|
||||
{
|
||||
base.OnLoad(e);
|
||||
Page.ClientScript.RegisterClientScriptInclude(Page.GetType(), "UMBRACO_EDITOR", GlobalSettings.Path + "/js/editorBarFunctions.js");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Render this control to the output parameter specified.
|
||||
/// </summary>
|
||||
/// <param name="output"> The HTML writer to write out to </param>
|
||||
protected override void Render(HtmlTextWriter output)
|
||||
{
|
||||
if (_browserIsCompatible)
|
||||
{
|
||||
base.Render(output);
|
||||
output.Write("<iframe name=\"" + ClientID + "_holder\" id=\"" + ClientID +
|
||||
"_holder\" style=\"border: 0px; width: 100%; height: 100%\" frameborder=\"0\" src=\"" +
|
||||
GlobalSettings.Path + "/richTextHolder.aspx?nodeId=" + _data.NodeId.ToString() +
|
||||
"&versionId=" + _data.Version.ToString() + "&propertyId=" + _data.PropertyId.ToString() +
|
||||
"\"></iframe>");
|
||||
output.Write("<input type=\"hidden\" name=\"" + ClientID + "_source\" value=\"\">");
|
||||
|
||||
string strScript = "function umbracoRichTextSave" + ClientID + "() {\nif (document.frames[\"" +
|
||||
ClientID + "_holder\"].document.getElementById(\"holder\")) document.getElementById(\"" +
|
||||
ClientID + "\").value = document.frames[\"" + ClientID +
|
||||
"_holder\"].document.getElementById(\"holder\").innerHTML;\n}" +
|
||||
|
||||
"addSaveHandler('umbracoRichTextSave" + ClientID + "();');";
|
||||
try
|
||||
{
|
||||
if (ScriptManager.GetCurrent(Page).IsInAsyncPostBack)
|
||||
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "umbracoRichTextSave" + this.ClientID, strScript, true);
|
||||
else
|
||||
Page.ClientScript.RegisterStartupScript(this.GetType(), "umbracoRichTextSave" + this.ClientID, strScript, true);
|
||||
}
|
||||
catch
|
||||
{
|
||||
Page.ClientScript.RegisterStartupScript(this.GetType(), "umbracoRichTextSave" + this.ClientID, strScript, true);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
output.WriteLine("<textarea name=\"" + ClientID + "\" style=\"width: 100%; height: 95%\">" +
|
||||
HttpContext.Current.Server.HtmlEncode(base.Value.Trim()) +
|
||||
"</textarea>");
|
||||
output.WriteLine(
|
||||
"<p class=\"guiDialogTiny\"><i>(Unfortunately WYSIWYG editing is only useLiveEditing in Internet Explorer on Windows. <a href=\"http://umbraco.org/various/cross-platform.aspx\" target=\"_blank\">More info</a>)</i></p>");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user