From 3074b8240cee35efe4b9305f99c8e2ef5ad05580 Mon Sep 17 00:00:00 2001 From: Brian Dukes Date: Thu, 17 Sep 2015 17:06:12 -0500 Subject: [PATCH] Add support for Evoq 8 The APIs for the HTML Pro module changed in Evoq 8, this reflects this changes Fixes #10 --- HtmlTextModuleController.cs | 82 +++++++++++++++++++++++++++++++----- IHtmlTextModuleController.cs | 10 +---- ViewLinks.ascx.cs | 14 +----- 3 files changed, 76 insertions(+), 30 deletions(-) diff --git a/HtmlTextModuleController.cs b/HtmlTextModuleController.cs index f560bbc..7213e66 100644 --- a/HtmlTextModuleController.cs +++ b/HtmlTextModuleController.cs @@ -14,6 +14,8 @@ namespace Engage.Dnn.F3 using System; using System.Collections.Generic; using System.Reflection; + + using DotNetNuke.Entities.Modules; using DotNetNuke.Framework; /// @@ -57,7 +59,7 @@ public HtmlTextModuleController() this.workflowStateController = Reflection.CreateInstance(WorkflowStateControllerType); } - public int GetWorkflowId(int moduleId, int tabId, int portalId) + private int? GetWorkflowId(int moduleId, int tabId, int portalId) { var getWorkflowId = HtmlTextControllerType.GetMethod("GetWorkflowID"); if (getWorkflowId != null) @@ -72,25 +74,85 @@ public int GetWorkflowId(int moduleId, int tabId, int portalId) } // DNN 5.4 - var workflowPair = (KeyValuePair)HtmlTextControllerType.InvokeMember( - "GetWorkflow", + var getWorkflow = HtmlTextControllerType.GetMethod("GetWorkflow"); + if (getWorkflow != null) + { + var workflowPair = (KeyValuePair)HtmlTextControllerType.InvokeMember( + "GetWorkflow", + BindingFlags.InvokeMethod, + null, + this.htmlTextController, + new object[] { moduleId, tabId, portalId }, + null); + + return workflowPair.Value; + } + + return null; + } + + public IHtmlTextInfo GetTopHtmlText(int moduleId, int tabId, int portalId) + { + var workflowId = this.GetWorkflowId(moduleId, tabId, portalId); + if (workflowId != null) + { + return + new HtmlTextInfo( + HtmlTextControllerType.InvokeMember( + "GetTopHtmlText", + BindingFlags.InvokeMethod, + null, + this.htmlTextController, + new object[] { moduleId, false, workflowId.Value }, + null)); + } + + var serviceLocatorType = Reflection.CreateType("DotNetNuke.Framework.ServiceLocator`2"); + var versionControllerInterface = Reflection.CreateType("DotNetNuke.Professional.HtmlPro.Components.IVersionController"); + var versionControllerClass = Reflection.CreateType("DotNetNuke.Professional.HtmlPro.Components.VersionController"); + var versionControllerLocatorType = serviceLocatorType.MakeGenericType(versionControllerInterface, versionControllerClass); + var versionControllerInstance = versionControllerLocatorType.InvokeMember( + "Instance", + BindingFlags.Static | BindingFlags.Public | BindingFlags.GetProperty, + null, + null, + new object[0], + null); + + var htmlInfo = versionControllerInterface.InvokeMember( + "GetLatestVersion", BindingFlags.InvokeMethod, null, - this.htmlTextController, - new object[] { moduleId, tabId, portalId }, + versionControllerInstance, + new object[] { moduleId }, null); - return workflowPair.Value; + return htmlInfo == null ? null : new HtmlTextInfo(htmlInfo); } - public IHtmlTextInfo GetTopHtmlText(int moduleId, bool isPublished, int workflowId) + public IHtmlTextInfo CreateNewHtmlTextInfo() { - return new HtmlTextInfo(HtmlTextControllerType.InvokeMember("GetTopHtmlText", BindingFlags.InvokeMethod, null, this.htmlTextController, new object[] { moduleId, isPublished, workflowId }, null)); + return new HtmlTextInfo(); } - public IHtmlTextInfo CreateNewHtmlTextInfo() + public void SaveHtmlContent(IHtmlTextInfo htmlTextInfo, int moduleId, int tabId, int portalId) { - return new HtmlTextInfo(); + if (htmlTextInfo == null) + { + throw new ArgumentNullException("htmlTextInfo"); + } + + var workflowId = this.GetWorkflowId(moduleId, tabId, portalId); + if (workflowId != null) + { + htmlTextInfo.WorkflowId = workflowId.Value; + htmlTextInfo.StateId = this.GetFirstWorkflowStateId(workflowId.Value); + this.UpdateHtmlText(htmlTextInfo, this.GetMaximumVersionHistory(portalId)); + return; + } + + var module = new ModuleController().GetModule(moduleId, tabId, true); + Reflection.InvokeMethod(HtmlTextControllerType, "SaveHtmlContent", this.htmlTextController, new object[] { htmlTextInfo.HtmlTextInfoInstance, module, }); } public void UpdateHtmlText(IHtmlTextInfo htmlTextInfo, int maximumVersionHistory) diff --git a/IHtmlTextModuleController.cs b/IHtmlTextModuleController.cs index b9008fd..1b790a7 100644 --- a/IHtmlTextModuleController.cs +++ b/IHtmlTextModuleController.cs @@ -16,16 +16,10 @@ namespace Engage.Dnn.F3 /// public interface IHtmlTextModuleController { - int GetWorkflowId(int moduleId, int tabId, int portalId); - - IHtmlTextInfo GetTopHtmlText(int moduleId, bool isPublished, int workflowId); + IHtmlTextInfo GetTopHtmlText(int moduleId, int tabId, int portalId); IHtmlTextInfo CreateNewHtmlTextInfo(); - int GetFirstWorkflowStateId(int workflowId); - - void UpdateHtmlText(IHtmlTextInfo htmlTextInfo, int maximumVersionHistory); - - int GetMaximumVersionHistory(int portalId); + void SaveHtmlContent(IHtmlTextInfo htmlTextInfo, int moduleId, int tabId, int portalId); } } \ No newline at end of file diff --git a/ViewLinks.ascx.cs b/ViewLinks.ascx.cs index 24fb3ce..3a5ffd2 100644 --- a/ViewLinks.ascx.cs +++ b/ViewLinks.ascx.cs @@ -183,20 +183,10 @@ protected override void OnInit(EventArgs e) private static void CreateNewTextHtmlVersion(string searchValue, string replacementValue, int moduleId, int tabId, int portalId, string content) { var htmlTextController = CreateHtmlTextController(); - var workflowId = htmlTextController.GetWorkflowId(moduleId, tabId, portalId); - var htmlInfo = htmlTextController.GetTopHtmlText(moduleId, false, workflowId) ?? htmlTextController.CreateNewHtmlTextInfo(); + var htmlInfo = htmlTextController.GetTopHtmlText(moduleId, tabId, portalId) ?? htmlTextController.CreateNewHtmlTextInfo(); htmlInfo.ModuleId = moduleId; htmlInfo.Content = content.Replace(HttpUtility.HtmlEncode(searchValue), HttpUtility.HtmlEncode(replacementValue)); - htmlInfo.WorkflowId = workflowId; - htmlInfo.StateId = htmlTextController.GetFirstWorkflowStateId(workflowId); - - // TODO: allow direct publish - ////if (canDirectlyPublish) - ////{ - //// htmlInfo.StateID = workflowStateController.GetNextWorkflowStateID(workflowId, htmlInfo.StateID); - ////} - - htmlTextController.UpdateHtmlText(htmlInfo, htmlTextController.GetMaximumVersionHistory(portalId)); + htmlTextController.SaveHtmlContent(htmlInfo, moduleId, tabId, portalId); } ///