📄 ftb3htmleditorprovider.cs
字号:
using System;
using System.Collections;
using System.IO;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DotNetNuke.Common;
using DotNetNuke.Entities.Portals;
using DotNetNuke.Framework.Providers;
using DotNetNuke.Modules.HTMLEditorProvider;
using FreeTextBoxControls;
//
// DotNetNuke - http://www.dotnetnuke.com
// Copyright (c) 2002-2005
// by Shaun Walker ( sales@perpetualmotion.ca ) of Perpetual Motion Interactive Systems Inc. ( http://www.perpetualmotion.ca )
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
// documentation files (the "Software"), to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
// to permit persons to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or substantial portions
// of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
// TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
// CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
namespace DotNetNuke.HtmlEditor
{
/// -----------------------------------------------------------------------------
/// Class: TextEditor
/// Project: Provider.FtbHtmlEditorProvider
/// -----------------------------------------------------------------------------
/// <summary>
/// Ftb3HtmlEditorProvider implements an Html Editor Provider for FTB (FreeTextBox) 3
/// </summary>
/// <remarks>
/// </remarks>
/// <history>
/// [cnurse] 12/13/2004 Documented
/// </history>
/// -----------------------------------------------------------------------------
public class Ftb3HtmlEditorProvider : HtmlEditorProvider
{
FreeTextBoxControls.FreeTextBox cntlFtb;
private const string ProviderType = "htmlEditor";
private ArrayList additionalToolbars;
private string rootImageDirectory;
private string controlID;
private ProviderConfiguration providerConfiguration;
private string providerPath;
private ArrayList styles;
private bool enableProFeatures;
private string spellCheck;
private string toolbarStyle;
#region " Provider "
public Ftb3HtmlEditorProvider()
{
cntlFtb = new FreeTextBoxControls.FreeTextBox();
additionalToolbars = new ArrayList();
providerConfiguration = ProviderConfiguration.GetProviderConfiguration(ProviderType);
PortalSettings portalSettings = PortalController.GetCurrentPortalSettings();
//Dim objMyPortalModuleControl As PortalModuleControl = CType(HttpContext.Current.Items("PortalModuleControl"), PortalModuleControl)
// Read the configuration specific information for this provider
Provider provider = ((Provider) providerConfiguration.Providers[providerConfiguration.DefaultProvider]);
providerPath = provider.Attributes["providerPath"];
spellCheck = provider.Attributes["spellCheck"];
enableProFeatures = bool.Parse(provider.Attributes["enableProFeatures"]);
toolbarStyle = provider.Attributes["toolbarStyle"];
}
public string ProviderPath
{
get { return this.providerPath; }
}
#endregion
#region "Properties "
public override Control HtmlEditorControl
{
get { return this.cntlFtb; }
}
public override string Text
{
get { return this.cntlFtb.Text; }
set { this.cntlFtb.Text = value; }
}
public override string ControlID
{
get { return this.controlID; }
set { this.controlID = value; }
}
public override ArrayList AdditionalToolbars
{
get { return this.additionalToolbars; }
set { this.additionalToolbars = value; }
}
public override string RootImageDirectory
{
get
{
if (this.rootImageDirectory == null || this.rootImageDirectory.Length == 0)
{
PortalSettings portalSettings = PortalController.GetCurrentPortalSettings();
return portalSettings.HomeDirectory.Substring(portalSettings.HomeDirectory.IndexOf("/Portals/"));
}
else
{
return this.rootImageDirectory;
}
}
set { this.rootImageDirectory = value; }
}
public override Unit Width
{
get { return cntlFtb.Width; }
set { cntlFtb.Width = value; }
}
public override Unit Height
{
get { return cntlFtb.Height; }
set { cntlFtb.Height = value; }
}
#endregion
#region "Private Helper Methods"
/// -----------------------------------------------------------------------------
/// <summary>
/// Creates the Color ToolBar
/// </summary>
/// <remarks>
/// </remarks>
/// <returns>A FreeTextBox ToolBar</returns>
/// <history>
/// [cnurse] 12/13/2004 Documented
/// </history>
/// -----------------------------------------------------------------------------
private FreeTextBoxControls.Toolbar AddColorToolBar()
{
FreeTextBoxControls.Toolbar tb = new FreeTextBoxControls.Toolbar();
tb.Items.Add(new FontForeColorsMenu());
tb.Items.Add(new FontForeColorPicker());
tb.Items.Add(new FontBackColorsMenu());
tb.Items.Add(new FontBackColorPicker());
return tb;
}
/// -----------------------------------------------------------------------------
/// <summary>
/// Creates the Edit ToolBar
/// </summary>
/// <remarks>
/// </remarks>
/// <returns>A FreeTextBox ToolBar</returns>
/// <history>
/// [cnurse] 12/13/2004 Documented
/// </history>
/// -----------------------------------------------------------------------------
private FreeTextBoxControls.Toolbar AddEditToolBar()
{
FreeTextBoxControls.Toolbar tb = new FreeTextBoxControls.Toolbar();
tb.Items.Add(new Cut());
tb.Items.Add(new Copy());
tb.Items.Add(new Paste());
tb.Items.Add(new Delete());
tb.Items.Add(new ToolbarSeparator());
tb.Items.Add(new Undo());
tb.Items.Add(new Redo());
return tb;
}
/// -----------------------------------------------------------------------------
/// <summary>
/// Creates the Format ToolBar
/// </summary>
/// <remarks>
/// </remarks>
/// <returns>A FreeTextBox ToolBar</returns>
/// <history>
/// [cnurse] 12/13/2004 Documented
/// </history>
/// -----------------------------------------------------------------------------
private FreeTextBoxControls.Toolbar AddFormatToolBar()
{
FreeTextBoxControls.Toolbar tb = new FreeTextBoxControls.Toolbar();
tb.Items.Add(new JustifyLeft());
tb.Items.Add(new JustifyCenter());
tb.Items.Add(new JustifyRight());
tb.Items.Add(new JustifyFull());
tb.Items.Add(new ToolbarSeparator());
tb.Items.Add(new BulletedList());
tb.Items.Add(new NumberedList());
tb.Items.Add(new Indent());
tb.Items.Add(new Outdent());
return tb;
}
/// -----------------------------------------------------------------------------
/// <summary>
/// Creates the Insert ToolBar
/// </summary>
/// <remarks>
/// </remarks>
/// <returns>A FreeTextBox ToolBar</returns>
/// <history>
/// [cnurse] 12/13/2004 Documented
/// </history>
/// -----------------------------------------------------------------------------
private FreeTextBoxControls.Toolbar AddInsertToolBar()
{
FreeTextBoxControls.Toolbar tb = new FreeTextBoxControls.Toolbar();
tb.Items.Add(new SymbolsMenu());
tb.Items.Add(new InsertRule());
tb.Items.Add(new InsertDate());
tb.Items.Add(new InsertTime());
tb.Items.Add(new ToolbarSeparator());
tb.Items.Add(new CreateLink());
tb.Items.Add(new Unlink());
tb.Items.Add(new InsertImageFromGallery());
return tb;
}
/// -----------------------------------------------------------------------------
/// <summary>
/// Creates the Insert ToolBar
/// </summary>
/// <remarks>
/// </remarks>
/// <returns>A FreeTextBox ToolBar</returns>
/// <history>
/// [cnurse] 12/13/2004 Documented
/// [JWhite] 2/25/2005 Added SpellCheck
/// </history>
/// -----------------------------------------------------------------------------
private FreeTextBoxControls.Toolbar AddSpecialToolBar()
{
FreeTextBoxControls.Toolbar tb = new FreeTextBoxControls.Toolbar();
tb.Items.Add(new Preview());
tb.Items.Add(new SelectAll());
switch (spellCheck)
{
case "NetSpell":
tb.Items.Add(new NetSpell()); //requires NetSpell library
break;
case "IeSpellCheck":
tb.Items.Add(new IeSpellCheck());
break;
}
if (enableProFeatures)
{
tb.Items.Add(new WordClean()); //pro only
}
else
{
StringBuilder wordCleanScript = new StringBuilder();
wordCleanScript.Append("wordContent = this.ftb.designEditor.document.body.innerHTML; ");
wordCleanScript.Append("wordContent = String(wordContent).replace(/ class=[^\\s|>]*/gi,\'\'); ");
wordCleanScript.Append("wordContent = String(wordContent).replace(/ style=\\\'[^>]*\\\'/gi,\'\'); ");
wordCleanScript.Append("wordContent = String(wordContent).replace(/ align=[^\\s|>]*/gi,\'\'); ");
wordCleanScript.Append("wordContent = String(wordContent).replace(/<p [^>]*>/gi,\'<p>\'); ");
wordCleanScript.Append("wordContent = String(wordContent).replace(/<b [^>]*>/gi,\'<b>\'); ");
wordCleanScript.Append("wordContent = String(wordContent).replace(/<i [^>]*>/gi,\'<i>\'); ");
wordCleanScript.Append("wordContent = String(wordContent).replace(/<ul [^>]*>/gi,\'<ul>\'); ");
wordCleanScript.Append("wordContent = String(wordContent).replace(/<li [^>]*>/gi,\'<li>\'); ");
wordCleanScript.Append("wordContent = String(wordContent).replace(/<b>/gi,\'<strong>\'); ");
wordCleanScript.Append("wordContent = String(wordContent).replace(/<\\/b>/gi,\'</strong>\'); ");
wordCleanScript.Append("wordContent = String(wordContent).replace(/<em>/gi,\'<i>\'); ");
wordCleanScript.Append("wordContent = String(wordContent).replace(/<\\/em>/gi,\'</i>\'); ");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -