Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Evoq 8 #11

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ _ReSharper.*
*.user
Resources.zip.manifest
package/
.vs/
*.GhostDoc.xml
82 changes: 72 additions & 10 deletions HtmlTextModuleController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ namespace Engage.Dnn.F3
using System;
using System.Collections.Generic;
using System.Reflection;

using DotNetNuke.Entities.Modules;
using DotNetNuke.Framework;

/// <summary>
Expand Down Expand Up @@ -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)
Expand All @@ -72,25 +74,85 @@ public int GetWorkflowId(int moduleId, int tabId, int portalId)
}

// DNN 5.4
var workflowPair = (KeyValuePair<string, int>)HtmlTextControllerType.InvokeMember(
"GetWorkflow",
var getWorkflow = HtmlTextControllerType.GetMethod("GetWorkflow");
if (getWorkflow != null)
{
var workflowPair = (KeyValuePair<string, int>)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)
Expand Down
10 changes: 2 additions & 8 deletions IHtmlTextModuleController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,10 @@ namespace Engage.Dnn.F3
/// </summary>
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);
}
}
14 changes: 2 additions & 12 deletions ViewLinks.ascx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/// <summary>
Expand Down