Skip to content

Commit

Permalink
Merge pull request #71 from DNNCommunity/development
Browse files Browse the repository at this point in the history
Merged development into master for v8.0.1 release
  • Loading branch information
valadas authored Feb 6, 2023
2 parents f962db6 + b249f5b commit 0e8c63a
Show file tree
Hide file tree
Showing 16 changed files with 2,343 additions and 2,189 deletions.
89 changes: 48 additions & 41 deletions Components/FeatureController.cs
Original file line number Diff line number Diff line change
@@ -1,25 +1,30 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using DotNetNuke.Common.Utilities;
using DotNetNuke.Entities.Modules;
using DotNetNuke.Security.Roles;
using DotNetNuke.Services.Search.Entities;

// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information

namespace DotNetNuke.Modules.Links.Components
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

using DotNetNuke.Common.Utilities;
using DotNetNuke.Entities.Modules;
using DotNetNuke.Security.Roles;
using DotNetNuke.Services.Search.Entities;

/// <summary>
/// Modules interface implementations
/// Modules interface implementations.
/// </summary>
public class FeatureController : ModuleSearchBase, IPortable
{
/// <summary>
/// Exports the module (Implements the IPortable interface)
/// Exports the module (Implements the IPortable interface).
/// </summary>
/// <param name="moduleID">The module ID</param>
/// <returns>XML String of the module data</returns>
/// <param name="moduleID">The module ID.</param>
/// <returns>XML String of the module data.</returns>
public string ExportModule(int moduleID)
{
StringBuilder xml = new StringBuilder();
Expand All @@ -28,7 +33,7 @@ public string ExportModule(int moduleID)
{
var module = ModuleController.Instance.GetModule(moduleID, DotNetNuke.Common.Utilities.Null.NullInteger, false);
var portalId = module?.PortalID ?? Null.NullInteger;
xml.Append("<links>");
xml.Append("<links>");
foreach (var link in links)
{
xml.Append("<link>");
Expand All @@ -40,23 +45,23 @@ public string ExportModule(int moduleID)
xml.AppendFormat("<trackclicks>{0}</trackclicks>", XmlUtils.XMLEncode(link.TrackClicks.ToString()));
xml.AppendFormat("<logactivity>{0}</logactivity>", XmlUtils.XMLEncode(link.LogActivity.ToString()));
xml.AppendFormat("<refreshinterval>{0}</refreshinterval>", XmlUtils.XMLEncode(link.RefreshInterval.ToString()));
xml.AppendFormat("<grantroles>{0}</grantroles>", XmlUtils.XMLEncode(ConvertToRoleNames(portalId, link.GrantRoles)));
xml.AppendFormat("<grantroles>{0}</grantroles>", XmlUtils.XMLEncode(this.ConvertToRoleNames(portalId, link.GrantRoles)));
xml.Append("</link>");
}

xml.Append("</links>");
}

return xml.ToString();
}
}

/// <summary>
/// Imports xml to fill the module data
/// Imports xml to fill the module data.
/// </summary>
/// <param name="moduleID">The module ID importing</param>
/// <param name="content">The data representation to import in an XML string</param>
/// <param name="version">The version of the export</param>
/// <param name="userId">The user ID of the user importing the data</param>
/// <param name="moduleID">The module ID importing.</param>
/// <param name="content">The data representation to import in an XML string.</param>
/// <param name="version">The version of the export.</param>
/// <param name="userId">The user ID of the user importing the data.</param>
public void ImportModule(int moduleID, string content, string version, int userId)
{
var module = ModuleController.Instance.GetModule(moduleID, DotNetNuke.Common.Utilities.Null.NullInteger, false);
Expand All @@ -67,30 +72,31 @@ public void ImportModule(int moduleID, string content, string version, int userI
var xmlLinks = xmlDoc.SelectNodes("links/link");
foreach (XmlNode xmlLink in xmlLinks)
{
int viewOrder = int.TryParse(GetXmlNodeValue(xmlLink ,"vieworder"), out viewOrder) ? viewOrder : 0;
bool newWindow = bool.TryParse(GetXmlNodeValue(xmlLink, "newwindow"), out newWindow) ? newWindow : false;
int viewOrder = int.TryParse(this.GetXmlNodeValue(xmlLink, "vieworder"), out viewOrder) ? viewOrder : 0;
bool newWindow = bool.TryParse(this.GetXmlNodeValue(xmlLink, "newwindow"), out newWindow) ? newWindow : false;
Link link = new Link
{
ModuleId = moduleID,
Title = GetXmlNodeValue(xmlLink, "title"),
Url = DotNetNuke.Common.Globals.ImportUrl(moduleID, GetXmlNodeValue(xmlLink, "url")),
Title = this.GetXmlNodeValue(xmlLink, "title"),
Url = DotNetNuke.Common.Globals.ImportUrl(moduleID, this.GetXmlNodeValue(xmlLink, "url")),
ViewOrder = viewOrder,
Description = GetXmlNodeValue(xmlLink, "description"),
GrantRoles = ConvertToRoleIds(portalId, GetXmlNodeValue(xmlLink, "grantroles")),
Description = this.GetXmlNodeValue(xmlLink, "description"),
GrantRoles = this.ConvertToRoleIds(portalId, this.GetXmlNodeValue(xmlLink, "grantroles")),
};

link.NewWindow = newWindow;

if (bool.TryParse(GetXmlNodeValue(xmlLink, "trackclicks"), out bool trackClicks))
if (bool.TryParse(this.GetXmlNodeValue(xmlLink, "trackclicks"), out bool trackClicks))
{
link.TrackClicks = trackClicks;
}
if (bool.TryParse(GetXmlNodeValue(xmlLink, "logactivity"), out bool logActivity))

if (bool.TryParse(this.GetXmlNodeValue(xmlLink, "logactivity"), out bool logActivity))
{
link.LogActivity = logActivity;
}

if (int.TryParse(GetXmlNodeValue(xmlLink, "refreshinterval"), out int refreshInterval))
if (int.TryParse(this.GetXmlNodeValue(xmlLink, "refreshinterval"), out int refreshInterval))
{
link.RefreshInterval = refreshInterval;
}
Expand All @@ -104,20 +110,21 @@ public void ImportModule(int moduleID, string content, string version, int userI
UrlController objUrls = new UrlController();
var moduleInfo = ModuleController.Instance.GetModule(moduleID, Null.NullInteger, false);
objUrls.UpdateUrl(
moduleInfo.PortalID,
moduleInfo.PortalID,
link.Url,
LinkController.ConvertUrlType(DotNetNuke.Common.Globals.GetURLType(link.Url)),
LinkController.ConvertUrlType(DotNetNuke.Common.Globals.GetURLType(link.Url)),
link.LogActivity,
link.TrackClicks,
moduleID,
link.TrackClicks,
moduleID,
link.NewWindow);
}
}

}

/// <inheritdoc/>
public override IList<SearchDocument> GetModifiedSearchDocuments(ModuleInfo moduleInfo, DateTime beginDateUtc)
{
// TODO: Would be better performing if we had a last modified date and soft deletes
DotNetNuke.Services.Search.Internals.InternalSearchController.Instance.DeleteSearchDocumentsByModule(moduleInfo.PortalID, moduleInfo.ModuleID, moduleInfo.ModuleDefID);
Services.Search.Internals.InternalSearchController.Instance.DeleteSearchDocumentsByModule(moduleInfo.PortalID, moduleInfo.ModuleID, moduleInfo.ModuleDefID);
List<SearchDocument> searchDocuments = new List<SearchDocument>();
var links = LinkController.GetLinks(moduleInfo.ModuleID);
foreach (var link in links)
Expand All @@ -129,7 +136,7 @@ public override IList<SearchDocument> GetModifiedSearchDocuments(ModuleInfo modu
Title = link.Title,
Description = link.Description,
Body = link.Description,
ModifiedTimeUtc = link.CreatedDate
ModifiedTimeUtc = link.CreatedDate,
};
searchDocuments.Add(searchDoc);
}
Expand All @@ -156,7 +163,7 @@ private string ConvertToRoleNames(int portalId, string grantRoles)
}

var roles = string.Empty;
foreach (var roleId in grantRoles.Split(new []{';'}, StringSplitOptions.RemoveEmptyEntries).Select(i => Convert.ToInt32(i)))
foreach (var roleId in grantRoles.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries).Select(i => Convert.ToInt32(i)))
{
var role = RoleController.Instance.GetRoleById(portalId, roleId);
if (role != null)
Expand Down
172 changes: 108 additions & 64 deletions Components/Link.cs
Original file line number Diff line number Diff line change
@@ -1,64 +1,108 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DotNetNuke.Common.Utilities;
using DotNetNuke.ComponentModel.DataAnnotations;
using DotNetNuke.Entities.Modules;

namespace DotNetNuke.Modules.Links.Components
{
/// <summary>
/// Represents a link
/// </summary>
[TableName("Links")]
[Serializable]
[PrimaryKey("ItemId")]
[Cacheable("Dnn_Links", System.Web.Caching.CacheItemPriority.Normal, 20)]
public class Link
{
[ColumnName("ItemID")]
public int ItemId { get; set; }

[ColumnName("ModuleID")]
public int ModuleId { get; set; }

public string Title { get; set; }

public string Url { get; set; }

public int ViewOrder { get; set; }

public string Description { get; set; }

public int CreatedByUser { get; set; }

public DateTime CreatedDate { get; set; }

public int RefreshInterval { get; set; }

public string GrantRoles { get; set; }

[IgnoreColumn]
public string ImageURL { get; set; }

[ReadOnlyColumn]
public bool TrackClicks { get; set; }

[ReadOnlyColumn]
public bool LogActivity { get; set; }

[ReadOnlyColumn]
public bool NewWindow { get; set; }

[IgnoreColumn]
public bool RefreshContent
{
get
{
return RefreshInterval > 0;
}
}
}
}
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information

namespace DotNetNuke.Modules.Links.Components
{
using System;

using DotNetNuke.ComponentModel.DataAnnotations;

/// <summary>
/// Represents a link.
/// </summary>
[TableName("Links")]
[Serializable]
[PrimaryKey("ItemId")]
[Cacheable("Dnn_Links", System.Web.Caching.CacheItemPriority.Normal, 20)]
public class Link
{
/// <summary>
/// Gets or sets the item id.
/// </summary>
[ColumnName("ItemID")]
public int ItemId { get; set; }

/// <summary>
/// Gets or sets the module id.
/// </summary>
[ColumnName("ModuleID")]
public int ModuleId { get; set; }

/// <summary>
/// Gets or sets the title.
/// </summary>
public string Title { get; set; }

/// <summary>
/// Gets or sets the URL.
/// </summary>
public string Url { get; set; }

/// <summary>
/// Gets or sets the view order.
/// </summary>
public int ViewOrder { get; set; }

/// <summary>
/// Gets or sets the description.
/// </summary>
public string Description { get; set; }

/// <summary>
/// Gets or sets the id of the user that created the link.
/// </summary>
public int CreatedByUser { get; set; }

/// <summary>
/// Gets or sets the created date.
/// </summary>
public DateTime CreatedDate { get; set; }

/// <summary>
/// Gets or sets the refresh interval.
/// </summary>
public int RefreshInterval { get; set; }

/// <summary>
/// Gets or sets the grant roles.
/// </summary>
public string GrantRoles { get; set; }

/// <summary>
/// Gets or sets the image URL.
/// </summary>
[IgnoreColumn]
public string ImageURL { get; set; }

/// <summary>
/// Gets or sets a value indicating whether to track clicks.
/// </summary>
[ReadOnlyColumn]
public bool TrackClicks { get; set; }

/// <summary>
/// Gets or sets a value indicating whether to log the activity.
/// </summary>
[ReadOnlyColumn]
public bool LogActivity { get; set; }

/// <summary>
/// Gets or sets a value indicating whether to open the link in a new window.
/// </summary>
[ReadOnlyColumn]
public bool NewWindow { get; set; }

/// <summary>
/// Gets a value indicating whether to refresh the content.
/// </summary>
[IgnoreColumn]
public bool RefreshContent
{
get
{
return this.RefreshInterval > 0;
}
}
}
}
Loading

0 comments on commit 0e8c63a

Please sign in to comment.