protected override void OnLoad(EventArgs e) { base.OnLoad(e); lblModuleProperties.CssClass = CssClass; if (ModuleControl != null && ModuleControl.ModuleContext.ModuleId > Null.NullInteger) { switch (ModuleControl.ModuleContext.Configuration.DesktopModule.ModuleName) { case "DNN_HTML": var workflowId = new HtmlTextController().GetWorkflow(ModuleControl.ModuleContext.ModuleId, ModuleControl.ModuleContext.TabId, ModuleControl.ModuleContext.PortalId).Value; var htmlTextInfo = new HtmlTextController().GetTopHtmlText(ModuleControl.ModuleContext.ModuleId, true, workflowId); string formatString = string.IsNullOrEmpty(FormatString) ? "{0}" : FormatString; string dateFormat = string.IsNullOrEmpty(DateFormat) ? "F" : DateFormat; lblModuleProperties.Text = string.Format(formatString, htmlTextInfo.LastModifiedOnDate.ToString(dateFormat)); break; default: // do nothing break; } } }
///// <summary> ///// ///// </summary> //private void LoadRenderModeList() //{ // var RenderModeList = new List<SelectListItem>(); // RenderModeList.Add(new SelectListItem { Text = Localization.GetString("RICH", LocalResourceFile), Value = "RICH", Selected = (RenderModeSelectedValue.Equals("RICH", StringComparison.InvariantCultureIgnoreCase)) }); // RenderModeList.Add(new SelectListItem { Text = Localization.GetString("BASIC", LocalResourceFile), Value = "BASIC", Selected = (RenderModeSelectedValue.Equals("BASIC", StringComparison.InvariantCultureIgnoreCase)) }); // ViewBag.RenderModeList = RenderModeList; //} ///// <summary> ///// ///// </summary> //private void LoadTextRenderModeRBList() //{ // var TextRenderModeRBList = new Dictionary<string, string>() // { // { "T", Localization.GetString("T",LocalResourceFile) }, // { "H", Localization.GetString("H",LocalResourceFile) }, // { "R", Localization.GetString("R",LocalResourceFile) } // }; // ViewBag.TextRenderModeRBList = TextRenderModeRBList; //} /// <summary> /// /// </summary> /// <param name="_html"></param> private string FormatToHtmlText(string _nText) { var repo = new HtmlModuleSettingsRepository(); var settings = repo.GetSettings(ModuleContext.Configuration); return(HtmlTextController.FormatHtmlText(ModuleContext.ModuleId, _nText, settings, ModuleContext.PortalSettings, (Page)HttpContext.CurrentHandler)); }
/// ----------------------------------------------------------------------------- /// <summary> /// LoadSettings loads the settings from the Database and displays them /// </summary> /// ----------------------------------------------------------------------------- public override void LoadSettings() { try { if (Page.IsPostBack == false) { chkReplaceTokens.Checked = ModuleSettings.ReplaceTokens; txtSearchDescLength.Text = ModuleSettings.SearchDescLength.ToString(); rblEnableFallback.SelectedValue = ModuleSettings.EnableFallback.ToString(); if (HasAdminRights()) { var htmlTextController = new HtmlTextController(); phAdvanceSettings.Visible = true; ddlMaxVersion.DataSource = Enumerable.Range(1, 15); ddlMaxVersion.DataBind(); int maxVersion = htmlTextController.GetMaximumVersionHistory(PortalId); if (ddlMaxVersion.Items.FindByValue(maxVersion.ToString()) != null) { ddlMaxVersion.Items.FindByValue(maxVersion.ToString()).Selected = true; } BindCleanableItems(); } } } catch (Exception exc) //Module failed to load { Exceptions.ProcessModuleLoadException(this, exc); } }
/// <summary> /// Formats the content to make it html safe. /// </summary> /// <param name = "htmlText">Content of the HTML.</param> /// <returns></returns> private string FormatContent(string htmlText) { var strContent = HttpUtility.HtmlDecode(htmlText); strContent = HtmlTextController.ManageRelativePaths(strContent, PortalSettings.HomeDirectory, "src", PortalId); strContent = HtmlTextController.ManageRelativePaths(strContent, PortalSettings.HomeDirectory, "background", PortalId); return(HttpUtility.HtmlEncode(strContent)); }
private void OnHtmlTextCleanAllClick(Object sender, EventArgs e) { HtmlTextController htc = new HtmlTextController(); foreach (var htmlText in GetCleanableHtmlTexts()) { htc.DeleteHtmlText(htmlText); } BindCleanableItems(); }
public static string GetHtmlText(int ModuleId) { HtmlTextController hc = new HtmlTextController(); var html = hc.GetTopHtmlText(ModuleId, true, Null.NullInteger); if (html != null) { return(html.Content); } return(""); }
private IEnumerable <HtmlTextInfo> GetCleanableHtmlTexts() { var htmlTextController = new HtmlTextController(); var allHtmlTexts = htmlTextController.GetAllHtmlText(); var allModules = ModuleController.Instance.GetModules(PortalId).Cast <ModuleInfo>().ToList(); var distinctHtmlTextModuleIDs = allHtmlTexts.Select(x => x.ModuleId).Distinct(); var distinctModulesModuleIDs = allModules.Select(x => x.ModuleID).Distinct(); var cleanableModuleIDs = distinctHtmlTextModuleIDs.Except(distinctModulesModuleIDs).ToList(); return(allHtmlTexts.Where(x => cleanableModuleIDs.Contains(x.ModuleId))); }
private void AddPictureToPage(int tabId, string imageUrl) { var moduleDef = ModuleDefinitionController.GetModuleDefinitionByFriendlyName("Text/HTML"); var tab = TabController.Instance.GetTab(tabId, 0); var objModule = new ModuleInfo(); objModule.Initialize(0); objModule.PortalID = 0; objModule.TabID = tab.TabID; objModule.ModuleOrder = 0; objModule.ModuleTitle = tab.Title; objModule.PaneName = "ContentPane"; objModule.ModuleDefID = moduleDef.ModuleDefID; // Text/HTML objModule.CacheTime = 1200; ModuleController.Instance.InitialModulePermission(objModule, objModule.TabID, 0); objModule.CultureCode = Null.NullString; objModule.AllTabs = false; objModule.Alignment = ""; var moduleId = ModuleController.Instance.AddModule(objModule); //creating the content object, and adding the content to the module var htmlTextController = new HtmlTextController(); var workflowStateController = new WorkflowStateController(); int workflowId = htmlTextController.GetWorkflow(moduleId, tabId, 0).Value; HtmlTextInfo htmlContent = htmlTextController.GetTopHtmlText(moduleId, false, workflowId); if (htmlContent == null) { htmlContent = new HtmlTextInfo(); htmlContent.ItemID = -1; htmlContent.StateID = workflowStateController.GetFirstWorkflowStateID(workflowId); htmlContent.WorkflowID = workflowId; htmlContent.ModuleID = moduleId; htmlContent.IsPublished = true; htmlContent.Approved = true; htmlContent.IsActive = true; } htmlContent.Content = $"<img src='/Portals/0/{imageUrl}' />"; int draftStateId = workflowStateController.GetFirstWorkflowStateID(workflowId); int nextWorkflowStateId = workflowStateController.GetNextWorkflowStateID(workflowId, htmlContent.StateID); int publishedStateId = workflowStateController.GetLastWorkflowStateID(workflowId); htmlTextController.UpdateHtmlText(htmlContent, htmlTextController.GetMaximumVersionHistory(0)); }
public static HtmlModel Html(int moduleId) { HtmlTextController hc = new HtmlTextController(); var html = hc.GetTopHtmlText(moduleId, true, Null.NullInteger); if (html != null) { return new HtmlModel { Content = HttpUtility.HtmlDecode(html.Content), Summary = html.Summary } } ; else { return(null); } }
private void OnHtmlTextCleanSelection(Object sender, EventArgs e) { HtmlTextController htc = new HtmlTextController(); var cleanableItems = GetCleanableHtmlTexts(); foreach (ListItem item in cleanableListBox.Items) { if (item.Selected) { var itemToDelete = cleanableItems.Where(x => x.ItemId == int.Parse(item.Value)).SingleOrDefault(); if (itemToDelete != null) { htc.DeleteHtmlText(itemToDelete); } } } BindCleanableItems(); }
/// <summary> /// lblContent_UpdateLabel allows for inline editing of content /// </summary> /// <param name="source"></param> /// <param name="e"></param> private void lblContent_UpdateLabel(object source, DNNLabelEditEventArgs e) { try { // verify security if ((!new PortalSecurity().InputFilter(e.Text, PortalSecurity.FilterFlag.NoScripting).Equals(e.Text))) { throw new SecurityException(); } else if (EditorEnabled && IsEditable && PortalSettings.UserMode == PortalSettings.Mode.Edit) { // get content var htmlTextController = new HtmlTextController(); HtmlTextInfo htmlText = htmlTextController.GetTopHtmlText(ModuleId, CurrentLocaleCode, true); if (htmlText == null) { htmlText = new HtmlTextInfo(); htmlText.ItemId = -1; // use current display title for new item only htmlText.ModuleTitle = ModuleContext.Configuration.ModuleTitle; } // set content attributes htmlText.ModuleId = ModuleId; htmlText.Locale = CurrentLocaleCode; htmlText.Content = Server.HtmlEncode(e.Text); htmlText.IsPublished = true; // save the content with new version htmlTextController.UpdateHtmlText(htmlText, true, htmlTextController.GetMaximumVersionHistory(PortalId)); //refresh module cache ModuleController.SynchronizeModule(ModuleId); } else { throw new SecurityException(); } } catch (Exception exc) { Exceptions.ProcessModuleLoadException(this, exc); } }
/// ----------------------------------------------------------------------------- /// <summary> /// UpdateSettings saves the modified settings to the Database /// </summary> /// ----------------------------------------------------------------------------- public override void UpdateSettings() { try { //update module settings ModuleSettings.ReplaceTokens = chkReplaceTokens.Checked; int searchLength = 0; if (int.TryParse(txtSearchDescLength.Text.Trim(), out searchLength)) { ModuleSettings.SearchDescLength = searchLength; } ModuleSettings.EnableFallback = bool.Parse(rblEnableFallback.SelectedValue); var repo = new HtmlModuleSettingsRepository(); repo.SaveSettings(this.ModuleConfiguration, ModuleSettings); // disable module caching if token replace is enabled if (chkReplaceTokens.Checked) { ModuleInfo module = ModuleController.Instance.GetModule(ModuleId, TabId, false); if (module.CacheTime > 0) { module.CacheTime = 0; ModuleController.Instance.UpdateModule(module); } } // advance global settings if (HasAdminRights()) { var htmlTextController = new HtmlTextController(); htmlTextController.UpdateMaximumVersionHistorySetting(PortalId, Convert.ToInt32(ddlMaxVersion.SelectedValue)); } } catch (Exception exc) //Module failed to load { Exceptions.ProcessModuleLoadException(this, exc); } }
private void DisplayPreview(HtmlTextInfo htmlText, bool historyPreview) { phLocale.Visible = false; if (historyPreview && htmlText.Version > 0) { phPreviewVersion.Visible = true; lblPreviewVersion.Text = htmlText.Version.ToString(); } else { phPreviewVersion.Visible = false; } litPreviewTitle.Text = htmlText.ModuleTitle; litPreviewBody.Text = HtmlTextController.FormatHtmlText(ModuleId, htmlText.Content, Settings, PortalSettings, Page); phEdit.Visible = false; phPreview.Visible = true; phHistory.Visible = false; btnSave.Enabled = false; btnEdit.Enabled = true; btnPreview.Enabled = false; btnHistory.Enabled = true; }
/// <summary> /// Page_Load runs when the control is loaded /// </summary> /// <param name="e"></param> protected override void OnLoad(EventArgs e) { base.OnLoad(e); try { // edit in place. EditorEnabled = (EditorEnabled && IsEditable && PortalSettings.UserMode == PortalSettings.Mode.Edit && !Settings.ReplaceTokens); // toolbar visibility if (!IsPostBack && EditorEnabled) { foreach (DNNToolBarButton button in editorDnnToobar.Buttons) { button.ToolTip = Localization.GetString(button.ToolTip + ".ToolTip", LocalResourceFile); } } else { editorDnnToobar.Visible = false; } // get content var htc = new HtmlTextController(); HtmlTextInfo htmlText = null; string contentString = ""; string contentTitle = ""; string localeCode = CurrentLocaleCode; bool useDefaultLanguage = true; // try get localize content if enabled if (CanLocalize(localeCode)) { htmlText = htc.GetTopHtmlText(ModuleId, localeCode, true); useDefaultLanguage = (htmlText != null || (htmlText == null && !Settings.EnableFallback)) ? false : true; } // default or fallback if (useDefaultLanguage) { htmlText = htc.GetTopHtmlText(ModuleId, PortalSettings.DefaultLanguage, true); } // set variables if (htmlText != null) { contentString = htmlText.Content; contentTitle = htmlText.ModuleTitle; } else { // add some help text when no content and in edit mode if (!IsPostBack && PortalSettings.UserMode == PortalSettings.Mode.Edit) { contentString = Localization.GetString(EditorEnabled ? "AddContentFromToolBar.Text" : "AddContentFromActionMenu.Text", LocalResourceFile); } else { ContainerControl.Visible = false; // hide the module if no content and in view mode } } // add content to module lblContent.Controls.Add(new LiteralControl(HtmlTextController.FormatHtmlText(ModuleId, contentString, Settings, PortalSettings, Page))); lblContent.EditEnabled = EditorEnabled; // override title to module if (!String.IsNullOrEmpty(contentTitle)) { ModuleConfiguration.ModuleTitle = contentTitle; } } catch (Exception exc) //Module failed to load { Exceptions.ProcessModuleLoadException(this, exc); } }