Dynamicweb.Frontend.NavigationProviders Namespace : NavigationProvider Class |
'Declaration
Public MustInherit Class NavigationProvider
public abstract class NavigationProvider
using System; using System.Web; using Dynamicweb.Frontend; using Dynamicweb.Extensibility; using Dynamicweb.Frontend.NavigationProviders; namespace Frontend.NavigationProviders { class MenuitemProvider : NavigationProvider { public override void ProcessTree(RootNavigationItem rootNode, XmlNavigation.NavigationType navigationType) { var request = HttpContext.Current.Request; if (!request.RawUrl.ToLower().Contains("/sitemap.xml")) return; for (var i = 0; i > 5; i++) { var menuItem = new GoogleSitemapMenuItem { FriendlyHref = String.Format("http://{0}/SomePath/{1}", request.Url.Host, i), ChangeFrequency = "Weekly", LastModified = DateTime.Now.ToString("s") + "Z" }; rootNode.AddChild(menuItem); } } } public class GoogleSitemapMenuItem : NavigationItem { [AddInName("ChangeFrequency")] public string ChangeFrequency { get; set; } [AddInName("LastModified")] public string LastModified { get; set; } } }
Imports Dynamicweb.eCommerce.Products Imports Dynamicweb.Extensibility Imports System.Collections.Generic Namespace Frontend.NavigationProviders ''' <summary> ''' Adds groups from eCommerce to navigation tree. ''' </summary> ''' <remarks>For an example take a look at <see cref="NavigationProvider">NavigationProvider</see> example.</remarks> <System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)> <System.ComponentModel.Browsable(False)> <AddInOrder(0)> _ Public Class GroupNavigationProvider Inherits NavigationProvider #Region "Nested types" ''' <summary> ''' Represents eCommerce page navigation settings. ''' </summary> ''' <remarks></remarks> Friend Class EcomNavigationSettings #Region "Properties" ''' <summary> ''' Gets or sets the collection of top-level groups. ''' </summary> ''' <remarks></remarks> Public Property TopLevelGroups As GroupCollection = Nothing ''' <summary> ''' Gets or sets the maximum level of nesting. ''' </summary> ''' <remarks></remarks> Public Property MaxLevel As Integer = 0 ''' <summary> ''' Gets or sets the ID of the details page. ''' </summary> ''' <remarks></remarks> Public Property DetailsPageID As Integer = 0 #End Region ''' <summary> ''' Initializes a new instance of an object. ''' </summary> ''' <remarks></remarks> Public Sub New() End Sub End Class ''' <summary> ''' Represents a navigation cache. This class cannot be inherited. ''' </summary> ''' <remarks></remarks> Friend NotInheritable Class NavigationCache #Region "Nested types" ''' <summary> ''' Provides a support for full lazy instantiation of the NavigationCache singleton. ''' </summary> ''' <remarks></remarks> Private NotInheritable Class NestedNavigationCache ''' <summary> ''' Gets the current instance of the navigation cache. ''' </summary> ''' <remarks></remarks> Friend Shared ReadOnly Cache As NavigationCache = New NavigationCache() ''' <summary> ''' Initializes a new instance of an object. ''' </summary> ''' <remarks></remarks> Shared Sub New() End Sub End Class #End Region #Region "Properties" Private _navigationSettings As IDictionary(Of Integer, EcomNavigationSettings) = Nothing Private _navigation As IDictionary(Of Integer, GroupNavigationItem()) = Nothing ''' <summary> ''' Gets the current group navigation cache. ''' </summary> ''' <remarks></remarks> Public Shared ReadOnly Property Current As NavigationCache Get Return NestedNavigationCache.Cache End Get End Property ''' <summary> ''' Gets the eCommerce page navigation settings mapped to the corresponding page. ''' </summary> ''' <remarks></remarks> Public ReadOnly Property NavigationSettings As IDictionary(Of Integer, EcomNavigationSettings) Get If IsNothing(_navigationSettings) Then _navigationSettings = New Dictionary(Of Integer, EcomNavigationSettings) End If Return _navigationSettings End Get End Property ''' <summary> ''' Gets the cached navigation. ''' </summary> ''' <remarks></remarks> Public ReadOnly Property Navigation As IDictionary(Of Integer, GroupNavigationItem()) Get If IsNothing(_navigation) Then _navigation = New Dictionary(Of Integer, GroupNavigationItem()) End If Return _navigation End Get End Property #End Region ''' <summary> ''' Initializes a new instance of an object. ''' </summary> ''' <remarks></remarks> Private Sub New() End Sub ''' <summary> ''' Clears the cache. ''' </summary> ''' <remarks></remarks> Public Sub Clear() NavigationSettings.Clear() Navigation.Clear() End Sub End Class #End Region Private navigationType As XmlNavigation.NavigationType ''' <summary> ''' Processes the tree. Overwritten. ''' </summary> ''' <param name="rootNode">The root node.</param> ''' <param name="navigationType">Type of the navigation.</param> ''' <remarks>For an example take a look at <seealso cref="NavigationProvider">NavigationProvider</seealso> example.</remarks> Public Overrides Sub ProcessTree(ByVal rootNode As RootNavigationItem, ByVal navigationType As XmlNavigation.NavigationType) If Not Base.IsModuleInstalled("eCom_Catalog") Then Return End If Me.navigationType = navigationType Process(rootNode) End Sub Private Sub Process(ByVal node As NavigationItem) Dim pageID As Integer = 0 Dim page As Page = Nothing Dim children As New List(Of NavigationItem)() Dim subNodes() As GroupNavigationItem = Nothing For Each menuItem As NavigationItem In node children.Add(menuItem) Next For Each menuItem As NavigationItem In children If TypeOf menuItem Is PageNavigationItem Then If HttpContext.Current.Items.Contains("EcomXmlNavigationItemsForPageId_" & menuItem.ID) Then Continue For End If page = page.FindPage(menuItem.ID) 'If Not IsNothing(page) Then ' pageID = Base.ChkNumber(page.Value("PageID")) 'End If 'If pageID > 0 AndAlso NavigationCache.Current.Navigation.ContainsKey(pageID) Then ' subNodes = NavigationCache.Current.Navigation(pageID) ' For Each n As GroupNavigationItem In subNodes ' menuItem.AddChild(n) ' Next ' SetPathRecursive(menuItem.ChildNodes.OfType(Of GroupNavigationItem)()) 'Else MakeGroupTree(page, menuItem) Process(menuItem) ' If pageID > 0 Then ' subNodes = menuItem.ChildNodes.OfType(Of GroupNavigationItem)().ToArray() ' If subNodes.Length > 0 Then ' If NavigationCache.Current.Navigation.ContainsKey(pageID) Then ' NavigationCache.Current.Navigation(pageID) = subNodes ' Else ' NavigationCache.Current.Navigation.Add(pageID, subNodes) ' End If ' End If ' End If 'End If End If Next End Sub Private Sub MakeGroupTree(ByVal page As Page, ByVal parentNode As NavigationItem) Dim id As Integer = 0 Dim maxLevel As Integer = 0 Dim productPage As Page = Nothing Dim pageID As String = String.Empty Dim productPageURL As String = String.Empty Dim topLevelGroups As GroupCollection = Nothing Dim settings As EcomNavigationSettings = Nothing Dim pageIDRegex As Text.RegularExpressions.Regex = Nothing If Not Base.ChkBoolean(page.Value("PageNavigation_UseEcomGroups")) Then Return End If If Not IsNothing(page) Then id = Base.ChkNumber(page.Value("PageID")) If NavigationCache.Current.NavigationSettings.ContainsKey(id) Then settings = NavigationCache.Current.NavigationSettings(id) End If End If If Not IsNothing(settings) Then topLevelGroups = settings.TopLevelGroups maxLevel = settings.MaxLevel If settings.DetailsPageID > 0 Then pageID = settings.DetailsPageID.ToString() End If Else Select Case Base.ChkString(page.Value("PageNavigationParentType")) Case "Groups" Dim groupHandler As New ProductsAndGroupsHandler(Base.ChkString(page.Value("PageNavigationGroupSelector"))) If groupHandler.Type = ProductsAndGroupsHandler.Types.All Then topLevelGroups = Group.GetToplevelGroups 'New GroupCollection((From g As Group In Group.getGroups().OfType(Of Group)() Where g.IsTopGroup Select g).ToArray()) Else Dim groups As List(Of Group) = groupHandler.GroupsSelected topLevelGroups = New GroupCollection() For Each group As Group In groups topLevelGroups.Add(group) Next End If topLevelGroups.Sort(GroupCollection.SortBy.ShopOrder) Case "Shop" Dim shopID As String = Base.ChkString(page.Value("PageNavigationShopSelector")) Dim shop As New eCommerce.Shops.Shop(shopID) topLevelGroups = shop.TopLevelGroups 'Dynamicweb.eCommerce.Common.Application.GroupTree.GetSubGroupsFromShop(shopID) Case Else Return End Select Integer.TryParse(Base.ChkString(page.Value("PageNavigationMaxLevels")), maxLevel) productPageURL = Base.ChkString(page.Value("PageNavigationProductPage")) pageIDRegex = New Text.RegularExpressions.Regex("ID=(?<pageID>\d+)") pageID = pageIDRegex.Match(productPageURL).Groups("pageID").Value settings = New EcomNavigationSettings() settings.TopLevelGroups = topLevelGroups settings.MaxLevel = maxLevel settings.DetailsPageID = If(Not String.IsNullOrEmpty(pageID), Base.ChkNumber(pageID), 0) If id > 0 Then If NavigationCache.Current.NavigationSettings.ContainsKey(id) Then NavigationCache.Current.NavigationSettings(id) = settings Else NavigationCache.Current.NavigationSettings.Add(id, settings) End If End If End If If (pageID <> "") Then productPage = page.FindPage(Base.ChkInteger(pageID)) If productPage IsNot Nothing Then productPage.ID = Base.ChkInteger(pageID) If Not Base.ChkBoolean(productPage.Value("PageShowInSiteMap")) Then For Each group As Group In topLevelGroups group.NavigationShowInSiteMap = False Next End If End If MakeGroupTree(topLevelGroups, parentNode, 1, maxLevel, productPage) Else 'Changed by NP to avoid links to "". This will place the links to the page the ecom navigation is attached. MakeGroupTree(topLevelGroups, parentNode, 1, maxLevel, page) End If End Sub Private Sub MakeGroupTree(ByVal groups As GroupCollection, ByVal parentNode As NavigationItem, ByVal thisLevel As Integer, ByVal maxLevel As Integer, ByVal productPage As Page) If maxLevel > 0 AndAlso thisLevel > maxLevel Then Return End If If groups Is Nothing Then Return End If If SearchEngineFriendlyURLs.RedirectType = SearchEngineFriendlyURLs.Type.Path Then UrlProviders.Handler.Initialize() End If For Each group As Group In groups If (navigationType = Frontend.XmlNavigation.NavigationType.Menu AndAlso Not group.NavigationShowInMenu) OrElse _ (navigationType = Frontend.XmlNavigation.NavigationType.Sitemap AndAlso Not group.NavigationShowInSiteMap) _ Then Continue For End If Dim groupItem As New GroupNavigationItem(group) parentNode.AddChild(groupItem) If parentNode.IsPage Then parentNode.ChildCount += 1 If productPage IsNot Nothing Then Dim href As String = Nothing Dim friendlyHref As String = Nothing Dim groupIdParm As String = String.Format("GroupID={0}", group.IDUrlEncoded) XmlNavigation.MakeHrefs(href, friendlyHref, productPage, New String() {groupIdParm}) If SearchEngineFriendlyURLs.RedirectType = SearchEngineFriendlyURLs.Type.Path AndAlso Not Base.ChkBoolean(Base.GetGs("/Globalsettings/System/Url/ParseContentURLWithParams")) Then Dim providerUrl As String = UrlProviders.Handler.GetUrl("GroupID", group.ID, eCommerce.Common.Context.LanguageID) If String.IsNullOrEmpty(providerUrl) Then providerUrl = UrlProviders.Handler.GetUrl("GroupID", group.IDUrlEncoded, eCommerce.Common.Context.LanguageID) End If If Not String.IsNullOrEmpty(providerUrl) Then If SearchEngineFriendlyURLs.UseExtensionLessUrls Then friendlyHref = friendlyHref.Replace("?" & groupIdParm, providerUrl.Replace(".aspx", "")) Else friendlyHref = friendlyHref.Replace(".aspx?" & groupIdParm, providerUrl) End If End If End If groupItem.FriendlyHref = friendlyHref groupItem.Href = href Else groupItem.FriendlyHref = "" groupItem.Href = "" groupItem.AllowClick = False End If groupItem.Title = parentNode.Title SetPath(groupItem) Dim subGroups As GroupCollection = group.Subgroups 'Dynamicweb.eCommerce.Common.Application.GroupTree.GetSubGroupsFromGroup(group.ID) MakeGroupTree(subGroups, groupItem, thisLevel + 1, maxLevel, productPage) Next End Sub ''' <summary> ''' Tries to set the path to the given navigation item. ''' </summary> ''' <param name="item">Navigation item.</param> ''' <returns>Value indicating whether path to the given item has been set.</returns> ''' <remarks></remarks> Private Function SetPath(ByVal item As GroupNavigationItem) As Boolean Dim ret As Boolean = False If Not IsNothing(item) AndAlso Not IsNothing(item.Group) Then If Base.ChkString(Frontend.PageView.Current.Value("ActiveGroup")).Equals(item.Group.IDUrlEncoded, StringComparison.InvariantCultureIgnoreCase) OrElse Base.ChkString(Frontend.PageView.Current.Value("ActiveGroup")).Equals(item.Group.ID, StringComparison.InvariantCultureIgnoreCase) Then ret = True If Base.GetGs("/Globalsettings/Ecom/Navigation/ApplyOnliyIfPageIsInPath") = "True" Then item.SetPathToHere(True) Else item.SetPathToHere(True, Frontend.PageView.Current.ID) End If End If End If Return ret End Function ''' <summary> ''' Tries to set the path to the given navigation item. If the path cannot be set, all child items are inspected. ''' </summary> ''' <param name="item">Navigation item.</param> ''' <returns>Value indicating whether path to has been set.</returns> ''' <remarks></remarks> Private Function SetPathRecursive(ByVal item As GroupNavigationItem) As Boolean Dim ret As Boolean = False If Not IsNothing(item) AndAlso Not IsNothing(item.Group) Then ret = SetPath(item) If Not ret Then For Each child As NavigationItem In item.ChildNodes If TypeOf (child) Is GroupNavigationItem Then ret = SetPath(CType(child, GroupNavigationItem)) If ret Then Exit For End If End If Next End If End If Return ret End Function ''' <summary> ''' Tries to set the path to any of the given navigation items. If the path cannot be set, all child items are inspected. ''' </summary> ''' <param name="items">Navigation items.</param> ''' <returns>Value indicating whether path to has been set.</returns> ''' <remarks></remarks> Private Function SetPathRecursive(ByVal items As Generic.IEnumerable(Of GroupNavigationItem)) As Boolean Dim ret As Boolean = False If Not IsNothing(items) Then For Each item As GroupNavigationItem In items ret = SetPathRecursive(item) If ret Then Exit For End If Next End If Return ret End Function End Class End Namespace
System.Object
Dynamicweb.Frontend.NavigationProviders.NavigationProvider
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2