protected override void OnPreRender(EventArgs e) { if (Visible) { if (pnlEdit.Visible) { // Register other scripts which are necessary in edit mode if (UseProgressScript) { ScriptHelper.RegisterLoader(Page); } // Register script StringBuilder sb = new StringBuilder(); sb.AppendLine("function Delete_" + menuElem.ClientID + "(NodeID) { " + Page.ClientScript.GetPostBackEventReference(btnDelete, null) + "; } \n"); sb.AppendLine("function " + formElem.ClientID + "_RefreshForm(){" + Page.ClientScript.GetPostBackEventReference(btnRefresh, "") + " }"); // Register the scripts AddScript(sb.ToString()); ScriptHelper.RegisterBootstrapScripts(Page); if (formElem.FieldControls != null) { // Disable maximize plugin on HTML editors var htmlControls = formElem.FormInformation.GetFields(FormFieldControlTypeEnum.HtmlAreaControl); foreach (FormFieldInfo field in htmlControls) { Control control = formElem.FieldControls[field.Name]; CMSHtmlEditor htmlEditor = ControlsHelper.GetChildControl(control, typeof(CMSHtmlEditor)) as CMSHtmlEditor; if (htmlEditor != null) { var parameters = new LiveSiteWidgetsParameters(CurrentDocument.NodeAliasPath, PortalContext.ViewMode) { IsInlineWidget = true }; htmlEditor.Node = CurrentDocument; htmlEditor.RemovePlugins.Add("maximize"); htmlEditor.Config["CurrentHash"] = parameters.GetHashString(); htmlEditor.Config["CurrentViewMode"] = PortalContext.ViewMode.ToStringRepresentation(); } } } if (!NewDocument && !NewCulture) { formElem.Enabled = AllowSave; } } } base.OnPreRender(e); }
protected override void OnPreRender(EventArgs e) { if (Visible) { if (pnlEdit.Visible) { // Register other scripts which are necessary in edit mode if (UseProgressScript) { ScriptHelper.RegisterLoader(Page); } // Register script StringBuilder sb = new StringBuilder(); sb.AppendLine("function Delete_" + menuElem.ClientID + "(NodeID) { " + Page.ClientScript.GetPostBackEventReference(btnDelete, null) + "; } \n"); sb.AppendLine("function " + formElem.ClientID + "_RefreshForm(){" + Page.ClientScript.GetPostBackEventReference(btnRefresh, "") + " }"); // Register the scripts AddScript(sb.ToString()); ScriptHelper.RegisterBootstrapScripts(Page); if (formElem.FieldControls != null) { // Disable maximize plugin on HTML editors var htmlControls = formElem.FormInformation.GetFieldsWithControl(FormFieldControlName.HTMLAREA); foreach (FormFieldInfo field in htmlControls) { Control control = formElem.FieldControls[field.Name]; CMSHtmlEditor htmlEditor = ControlsHelper.GetChildControl(control, typeof(CMSHtmlEditor)) as CMSHtmlEditor; if (htmlEditor != null) { htmlEditor.Node = DocumentContext.CurrentDocument; htmlEditor.RemovePlugins.Add("maximize"); } } } if (!NewDocument && !NewCulture) { formElem.Enabled = AllowSave; } } } base.OnPreRender(e); }
/// <summary> /// Loads content from specific newsletter template. /// </summary> private void LoadContent() { EmailTemplateInfo emailTemplate = EmailTemplateInfoProvider.GetEmailTemplateInfo(mTemplateID); if ((emailTemplate == null) || string.IsNullOrEmpty(emailTemplate.TemplateBody)) { return; } // Remove security parameters from macros string templateText = MacroResolver.RemoveSecurityParameters(emailTemplate.TemplateBody, true, null); if (!RequestHelper.IsPostBack() && (issue != null)) { // Load content of editable regions IssueHelper.LoadRegionsContents(ref regionsContents, issue.IssueText); } CMSEditableRegion editableRegion = null; LiteralControl before = null; int count = 0; int textStart = 0; string region = null; string[] parts = null; string name = null; int width = 0; int height = 0; string toolbarLocation = "Out:CKEditorToolbar"; string toolbarSetName = "Newsletter"; int editRegStart = templateText.IndexOfCSafe("$$", textStart); int editRegEnd = 0; // Apply CSS e-mail template style HTMLHelper.AddToHeader(Page, CSSHelper.GetCSSFileLink(EmailTemplateInfoProvider.GetStylesheetUrl(emailTemplate.TemplateName))); while (editRegStart >= 0) { count++; before = new LiteralControl(); // Get template text surrounding editable regions - make links absolute before.Text = URLHelper.MakeLinksAbsolute(templateText.Substring(textStart, (editRegStart - textStart))); plcContent.Controls.Add(before); // End of region editRegStart += 2; textStart = editRegStart; if (editRegStart < templateText.Length - 1) { editRegEnd = templateText.IndexOfCSafe("$$", editRegStart); if (editRegEnd >= 0) { region = templateText.Substring(editRegStart, editRegEnd - editRegStart); parts = (region + ":" + ":").Split(':'); try { name = parts[0]; if (!string.IsNullOrEmpty(name.Trim())) { width = ValidationHelper.GetInteger(parts[1], 0); height = ValidationHelper.GetInteger(parts[2], 0); editableRegion = new CMSEditableRegion(); editableRegion.ID = name; editableRegion.RegionType = CMSEditableRegionTypeEnum.HtmlEditor; editableRegion.ViewMode = ViewModeEnum.Edit; editableRegion.DialogHeight = height; editableRegion.DialogWidth = width; editableRegion.WordWrap = false; editableRegion.HtmlAreaToolbarLocation = toolbarLocation; editableRegion.RegionTitle = name; editableRegion.UseStylesheet = false; editableRegion.HTMLEditorCssStylesheet = EmailTemplateInfoProvider.GetStylesheetUrl(emailTemplate.TemplateName); if (!mReadOnly) { editableRegion.HtmlAreaToolbar = toolbarSetName; } else { editableRegion.HtmlAreaToolbar = "Disabled"; } CMSHtmlEditor editor = editableRegion.HtmlEditor; editor.AddExtraPlugin("CMSPlugins"); editor.AddExtraPlugin("autogrow"); editor.AutoGrowMinHeight = height; editor.LinkDialogConfig.UseFullURL = true; editor.QuickInsertConfig.UseFullURL = true; editor.ResolverName = "NewsletterResolver"; DialogConfiguration dialogConfig = editor.MediaDialogConfig; dialogConfig.UseFullURL = true; dialogConfig.MetaFileObjectID = (issue != null) ? issue.IssueID : 0; dialogConfig.MetaFileObjectType = (issue != null) && issue.IssueIsVariant ? NewsletterObjectType.NEWSLETTERISSUEVARIANT : NewsletterObjectType.NEWSLETTERISSUE; dialogConfig.MetaFileCategory = MetaFileInfoProvider.OBJECT_CATEGORY_ISSUE; dialogConfig.HideAttachments = false; editableRegion.LoadContent(ValidationHelper.GetString(regionsContents[name.ToLowerCSafe()], string.Empty)); plcContent.Controls.Add(editableRegion); textStart = editRegEnd + 2; } } catch { } } } editRegStart = templateText.IndexOfCSafe("$$", textStart); } before = new LiteralControl(); before.Text = URLHelper.MakeLinksAbsolute(templateText.Substring(textStart)); plcContent.Controls.Add(before); }
/// <summary> /// Overridden CreateChildControls method. /// </summary> protected override void CreateChildControls() { SetupControl(); Controls.Clear(); base.CreateChildControls(); if (!StopProcessing) { if (!CMSAbstractEditableControl.RequestEditViewMode(ViewMode, ContentID)) { ViewMode = ViewModeEnum.Preview; } // Create controls by actual page mode switch (ViewMode) { case ViewModeEnum.Edit: case ViewModeEnum.EditDisabled: // Main editor panel pnlEditor = new Panel(); pnlEditor.ID = "pnlEditor"; pnlEditor.CssClass = "EditableTextEdit EditableText_" + ContentID; pnlEditor.Attributes.Add("data-tracksavechanges", "true"); Controls.Add(pnlEditor); // Title label lblTitle = new Label(); lblTitle.EnableViewState = false; lblTitle.CssClass = "EditableTextTitle"; pnlEditor.Controls.Add(lblTitle); // Error label lblError = new Label(); lblError.EnableViewState = false; lblError.CssClass = "EditableTextError"; pnlEditor.Controls.Add(lblError); // Display the region control based on the region type switch (RegionType) { case CMSEditableRegionTypeEnum.HtmlEditor: // HTML Editor Editor = new CMSHtmlEditor(); Editor.IsLiveSite = false; Editor.ID = "htmlValue"; Editor.AutoDetectLanguage = false; Editor.DefaultLanguage = Thread.CurrentThread.CurrentCulture.TwoLetterISOLanguageName; Editor.Title = Title; Editor.UseInlineMode = UseInlineMode; Editor.ContentsLangDirection = CultureHelper.IsPreferredCultureRTL() ? LanguageDirection.RightToLeft : LanguageDirection.LeftToRight; // Set the language try { CultureInfo ci = CultureHelper.GetCultureInfo(DataHelper.GetNotEmpty(MembershipContext.AuthenticatedUser.PreferredUICultureCode, LocalizationContext.PreferredCultureCode)); Editor.DefaultLanguage = ci.TwoLetterISOLanguageName; } catch (ArgumentNullException) { } catch (CultureNotFoundException) { } Editor.AutoDetectLanguage = false; Editor.Enabled = IsEnabled(ViewMode); if (ViewMode == ViewModeEnum.EditDisabled) { pnlEditor.Controls.Add(new LiteralControl("<div style=\"width: 98%\">")); pnlEditor.Controls.Add(Editor); pnlEditor.Controls.Add(new LiteralControl("</div>")); } else { pnlEditor.Controls.Add(Editor); } break; case CMSEditableRegionTypeEnum.TextArea: case CMSEditableRegionTypeEnum.TextBox: // TextBox txtValue = new CMSTextBox(); txtValue.ID = "txtValue"; txtValue.CssClass = "EditableTextTextBox"; txtValue.Enabled = IsEnabled(ViewMode); pnlEditor.Controls.Add(txtValue); break; } break; default: // Display content in non editing modes ltlContent = new Literal(); ltlContent.ID = "ltlContent"; ltlContent.EnableViewState = false; Controls.Add(ltlContent); break; } } }
/// <summary> /// Overridden CreateChildControls method. /// </summary> protected override void CreateChildControls() { SetupControl(); Controls.Clear(); base.CreateChildControls(); if (!StopProcessing) { if (!CMSAbstractEditableControl.RequestEditViewMode(ViewMode, ContentID)) { ViewMode = ViewModeEnum.Preview; } // Create controls by actual page mode switch (ViewMode) { case ViewModeEnum.Edit: case ViewModeEnum.EditDisabled: // Main editor panel pnlEditor = new Panel(); pnlEditor.ID = "pnlEditor"; pnlEditor.CssClass = "EditableTextEdit EditableText_" + ContentID; pnlEditor.Attributes.Add("data-tracksavechanges", "true"); Controls.Add(pnlEditor); // Title label lblTitle = new Label(); lblTitle.EnableViewState = false; lblTitle.CssClass = "EditableTextTitle"; pnlEditor.Controls.Add(lblTitle); // Error label lblError = new Label(); lblError.EnableViewState = false; lblError.CssClass = "EditableTextError"; pnlEditor.Controls.Add(lblError); // Display the region control based on the region type switch (RegionType) { case CMSEditableRegionTypeEnum.HtmlEditor: // HTML Editor Editor = new CMSHtmlEditor(); Editor.IsLiveSite = false; Editor.ID = "htmlValue"; Editor.AutoDetectLanguage = false; Editor.DefaultLanguage = Thread.CurrentThread.CurrentCulture.TwoLetterISOLanguageName; Editor.Title = Title; Editor.UseInlineMode = UseInlineMode; Editor.ContentsLangDirection = CultureHelper.IsPreferredCultureRTL() ? LanguageDirection.RightToLeft : LanguageDirection.LeftToRight; // Set the language try { CultureInfo ci = CultureHelper.GetCultureInfo(DataHelper.GetNotEmpty(MembershipContext.AuthenticatedUser.PreferredUICultureCode, LocalizationContext.PreferredCultureCode)); Editor.DefaultLanguage = ci.TwoLetterISOLanguageName; } catch (ArgumentNullException) { } catch (CultureNotFoundException) { } Editor.AutoDetectLanguage = false; Editor.Enabled = IsEnabled(ViewMode); if (ViewMode == ViewModeEnum.EditDisabled) { pnlEditor.Controls.Add(new LiteralControl("<div style=\"width: 98%\">")); pnlEditor.Controls.Add(Editor); pnlEditor.Controls.Add(new LiteralControl("</div>")); } else { pnlEditor.Controls.Add(Editor); } break; case CMSEditableRegionTypeEnum.TextArea: case CMSEditableRegionTypeEnum.TextBox: // TextBox txtValue = new CMSTextBox(); txtValue.ID = "txtValue"; txtValue.CssClass = "EditableTextTextBox"; // Do not append macro hash. Macro security is being applied in the CMSAbstractWebPart txtValue.ProcessMacroSecurity = false; txtValue.Enabled = IsEnabled(ViewMode); pnlEditor.Controls.Add(txtValue); break; } break; default: // Display content in non editing modes ltlContent = new Literal(); ltlContent.ID = "ltlContent"; ltlContent.EnableViewState = false; Controls.Add(ltlContent); break; } } }
/// <summary> /// Loads content from specific newsletter template. /// </summary> private void LoadContent() { var urlHelper = new URLHelper(); EmailTemplateInfo emailTemplate = EmailTemplateInfoProvider.GetEmailTemplateInfo(mTemplateID); if ((emailTemplate == null) || string.IsNullOrEmpty(emailTemplate.TemplateBody)) { return; } // Remove security parameters from macros string templateText = MacroSecurityProcessor.RemoveSecurityParameters(emailTemplate.TemplateBody, true, null); if (!RequestHelper.IsPostBack() && (issue != null)) { // Load content of editable regions IssueHelper.LoadRegionsContents(ref regionsContents, issue.IssueText); } LiteralControl before; int count = 0; int textStart = 0; string toolbarLocation = "Out:CKToolbar"; string toolbarSetName = "Newsletter"; int editRegStart = templateText.IndexOfCSafe("$$", textStart); // Apply CSS e-mail template style Page.AddToHeader(CssLinkHelper.GetCssFileLink(EmailTemplateInfoProvider.GetStylesheetUrl(emailTemplate.TemplateName))); string domainName = SiteContext.CurrentSite.SiteIsContentOnly ? SiteContext.CurrentSite.SitePresentationURL : SiteContext.CurrentSite.DomainName; while (editRegStart >= 0) { count++; before = new LiteralControl(); // Get template text surrounding editable regions - make links absolute before.Text = urlHelper.MakeLinksAbsolute(templateText.Substring(textStart, (editRegStart - textStart)), domainName); plcContent.Controls.Add(before); // End of region editRegStart += 2; textStart = editRegStart; if (editRegStart < templateText.Length - 1) { int editRegEnd = templateText.IndexOfCSafe("$$", editRegStart); if (editRegEnd >= 0) { string region = templateText.Substring(editRegStart, editRegEnd - editRegStart); string[] parts = (region + ":" + ":").Split(':'); try { string name = parts[0]; if (!string.IsNullOrEmpty(name.Trim())) { Regex intNumber = RegexHelper.GetRegex("^[0-9]+"); int width = ValidationHelper.GetInteger(intNumber.Match(parts[1]).Value, 0); int height = ValidationHelper.GetInteger(intNumber.Match(parts[2]).Value, 0); CMSEditableRegion editableRegion = new CMSEditableRegion(); editableRegion.ID = name; editableRegion.RegionType = CMSEditableRegionTypeEnum.HtmlEditor; editableRegion.ViewMode = ViewModeEnum.Edit; editableRegion.DialogHeight = height; editableRegion.DialogWidth = width; editableRegion.WordWrap = false; editableRegion.HtmlAreaToolbarLocation = toolbarLocation; editableRegion.RegionTitle = name; editableRegion.UseStylesheet = false; editableRegion.HTMLEditorCssStylesheet = EmailTemplateInfoProvider.GetStylesheetUrl(emailTemplate.TemplateName); if (!mReadOnly) { editableRegion.HtmlAreaToolbar = toolbarSetName; } else { editableRegion.HtmlAreaToolbar = "Disabled"; } CMSHtmlEditor editor = editableRegion.HtmlEditor; editor.ExtraPlugins.Add("autogrow"); editor.AutoGrowMinHeight = height; editor.ResolverName = "NewsletterResolver"; DialogConfiguration dialogConfig = editor.MediaDialogConfig; dialogConfig.MetaFileObjectID = (issue != null) ? issue.IssueID : 0; dialogConfig.MetaFileObjectType = (issue != null) && issue.IssueIsVariant ? IssueInfo.OBJECT_TYPE_VARIANT : IssueInfo.OBJECT_TYPE; dialogConfig.MetaFileCategory = ObjectAttachmentsCategories.ISSUE; dialogConfig.HideAttachments = false; editableRegion.LoadContent(ValidationHelper.GetString(regionsContents[name.ToLowerCSafe()], string.Empty)); plcContent.Controls.Add(editableRegion); textStart = editRegEnd + 2; } } catch { } } } editRegStart = templateText.IndexOfCSafe("$$", textStart); } before = new LiteralControl(); before.Text = urlHelper.MakeLinksAbsolute(templateText.Substring(textStart), domainName); plcContent.Controls.Add(before); }