public MenuNode(DNNNode dnnNode, MenuNode parent) { TabId = Convert.ToInt32(dnnNode.ID); Text = dnnNode.Text; Url = (dnnNode.ClickAction == eClickAction.PostBack) ? "postback:" + dnnNode.ID : String.IsNullOrEmpty(dnnNode.JSFunction) ? dnnNode.NavigateURL : "javascript:" + dnnNode.JSFunction; Enabled = dnnNode.Enabled; Selected = dnnNode.Selected; Breadcrumb = dnnNode.BreadCrumb; Separator = dnnNode.IsBreak; Icon = dnnNode.Image; Target = dnnNode.Target; Title = null; Keywords = null; Description = null; Parent = parent; CommandName = dnnNode.get_CustomAttribute("CommandName"); CommandArgument = dnnNode.get_CustomAttribute("CommandArgument"); DNNAbstract.DNNNodeToMenuNode(dnnNode, this); if ((dnnNode.DNNNodes != null) && (dnnNode.DNNNodes.Count > 0)) { Children = ConvertDNNNodeCollection(dnnNode.DNNNodes, this); } }
private void ApplyNodeManipulator() { RootNode = new MenuNode( ((INodeManipulator)Activator.CreateInstance(BuildManager.GetType(menuSettings.NodeManipulator, true, true))). ManipulateNodes(RootNode.Children, HostPortalSettings)); }
protected override void OnPreRender(EventArgs e) { using (new DNNContext(this)) { try { base.OnPreRender(e); var menuStyle = GetStringSetting("MenuStyle"); if (String.IsNullOrEmpty(menuStyle)) { menu = null; return; } var menuSettings = new Settings { MenuStyle = GetStringSetting("MenuStyle"), NodeXmlPath = GetStringSetting("NodeXmlPath"), NodeSelector = GetStringSetting("NodeSelector"), IncludeContext = GetBoolSetting("IncludeContext"), IncludeHidden = GetBoolSetting("IncludeHidden"), IncludeNodes = GetStringSetting("IncludeNodes"), ExcludeNodes = GetStringSetting("ExcludeNodes"), NodeManipulator = GetStringSetting("NodeManipulator"), TemplateArguments = DDRMenu.Settings.TemplateArgumentsFromSettingString(GetStringSetting("TemplateArguments")), ClientOptions = DDRMenu.Settings.ClientOptionsFromSettingString(GetStringSetting("ClientOptions")) }; MenuNode rootNode = null; if (String.IsNullOrEmpty(menuSettings.NodeXmlPath)) { rootNode = new MenuNode( Localiser.LocaliseDNNNodeCollection( Navigation.GetNavigationNodes( ClientID, Navigation.ToolTipSource.None, -1, -1, DNNAbstract.GetNavNodeOptions(menuSettings.IncludeHidden)))); } menu = MenuBase.Instantiate(menuStyle); menu.RootNode = rootNode; menu.ApplySettings(menuSettings); menu.PreRender(); } catch (Exception exc) { Exceptions.ProcessModuleLoadException(this, exc); } } }
protected override void OnPreRender(EventArgs e) { using (new DNNContext(this)) { try { base.OnPreRender(e); var menuStyle = GetStringSetting("MenuStyle"); if (String.IsNullOrEmpty(menuStyle)) { menu = null; return; } var menuSettings = new Settings { MenuStyle = GetStringSetting("MenuStyle"), NodeXmlPath = GetStringSetting("NodeXmlPath"), NodeSelector = GetStringSetting("NodeSelector"), IncludeContext = GetBoolSetting("IncludeContext"), IncludeHidden = GetBoolSetting("IncludeHidden"), IncludeNodes = GetStringSetting("IncludeNodes"), ExcludeNodes = GetStringSetting("ExcludeNodes"), NodeManipulator = GetStringSetting("NodeManipulator"), TemplateArguments = DDRMenu.Settings.TemplateArgumentsFromSettingString(GetStringSetting("TemplateArguments")), ClientOptions = DDRMenu.Settings.ClientOptionsFromSettingString(GetStringSetting("ClientOptions")) }; MenuNode rootNode = null; if (String.IsNullOrEmpty(menuSettings.NodeXmlPath)) { rootNode = new MenuNode( Localiser.LocaliseDNNNodeCollection( Navigation.GetNavigationNodes( ClientID, Navigation.ToolTipSource.None, -1, -1, DNNAbstract.GetNavNodeOptions(true)))); } menu = MenuBase.Instantiate(menuStyle); menu.RootNode = rootNode; menu.ApplySettings(menuSettings); menu.PreRender(); } catch (Exception exc) { Exceptions.ProcessModuleLoadException(this, exc); } } }
private void FilterHiddenNodes(MenuNode parentNode) { var portalSettings = PortalController.Instance.GetCurrentPortalSettings(); var filteredNodes = new List <MenuNode>(); filteredNodes.AddRange( parentNode.Children.FindAll( n => { var tab = TabController.Instance.GetTab(n.TabId, portalSettings.PortalId); return(tab == null || !tab.IsVisible); })); parentNode.Children.RemoveAll(n => filteredNodes.Contains(n)); parentNode.Children.ForEach(this.FilterHiddenNodes); }
public List <MenuNode> FlattenChildren(MenuNode root) { var flattened = new List <MenuNode>(); if (root.TabId != 0) { flattened.Add(root); } var children = root.Children; if (children != null) { foreach (var child in children) { flattened.AddRange(FlattenChildren(child)); } } return(flattened); }
private List<MenuNode> GetCatNodeXml(string currentTabId, int parentItemId = 0, bool recursive = true, int depth = 0, MenuNode pnode = null, string defaultListPage = "") { var nodes = new List<MenuNode>(); //[TODO: Add images onto DDRMenu] //var objS = objCtrl.GetByGuidKey(PortalSettings.Current.PortalId, -1, "SETTINGS", "NBrightBuySettings"); //var imgFolder = objS.GetXmlProperty("genxml/textbox/txtuploadfolder"); //var defimgsize = objS.GetXmlProperty("genxml/textbox/txtsmallimgsize"); //var l = objCtrl.GetList(PortalSettings.Current.PortalId, -1, "CATEGORY", strFilter, strOrderBy, 0, 0, 0, 0, "CATEGORYLANG", Utils.GetCurrentCulture()); var grpCatCtrl = new GrpCatController(Utils.GetCurrentCulture()); var l = grpCatCtrl.GetCategories(parentItemId); foreach (var obj in l) { if (!obj.ishidden) { var n = new MenuNode(); n.Parent = pnode; n.TabId = obj.categoryid; n.Text = obj.categoryname; n.Title = obj.categorydesc; var tabid = ""; if (Utils.IsNumeric(defaultListPage)) tabid = defaultListPage; if (tabid == "") tabid = currentTabId; if (Utils.IsNumeric(tabid)) n.Url = grpCatCtrl.GetCategoryUrl(obj, Convert.ToInt32((tabid))); n.Enabled = true; if (obj.disabled) n.Enabled = false; n.Selected = false; if (_catid == obj.categoryid.ToString("")) n.Selected = true; n.Breadcrumb = false; if (_catid == obj.categoryid.ToString("")) n.Breadcrumb = true; n.Separator = false; n.LargeImage = ""; n.Icon = ""; var img = obj.imageurl; if (img != "") { n.LargeImage = img; n.Icon = StoreSettings.NBrightBuyPath() + "/NBrightThumb.ashx?w=50&h=50&src=/" + img; } n.Keywords = obj.metakeywords; n.Description = obj.metadescription; n.CommandName = ""; //n.CommandArgument = string.Format("entrycount={0}|moduleid={1}", obj.GetXmlProperty("genxml/hidden/entrycount"), obj.ModuleId.ToString("")); n.CommandArgument = obj.entrycount.ToString(""); // not used, so we use it to store the entry count if (recursive && depth < 50) //stop infinate loop, only allow 50 sub levels { depth += 1; var childrenNodes = GetCatNodeXml(tabid, obj.categoryid, true, depth, n, defaultListPage); if (childrenNodes.Count > 0) { n.Children = childrenNodes; } } nodes.Add(n); } } return nodes; }
public static void DNNNodeToMenuNode(DNNNode dnnNode, MenuNode menuNode) { menuNode.LargeImage = dnnNode.LargeImage; }
public void ReadXml(XmlReader reader) { var empty = reader.IsEmptyElement; if (reader.MoveToFirstAttribute()) { do { switch (reader.Name.ToLowerInvariant()) { case "id": TabId = Convert.ToInt32(reader.Value); break; case "text": Text = reader.Value; break; case "title": Title = reader.Value; break; case "url": Url = reader.Value; break; case "enabled": Enabled = (reader.Value == "1"); break; case "selected": Selected = (reader.Value == "1"); break; case "breadcrumb": Breadcrumb = (reader.Value == "1"); break; case "separator": Separator = (reader.Value == "1"); break; case "icon": Icon = reader.Value; break; case "largeimage": LargeImage = reader.Value; break; case "commandname": CommandName = reader.Value; break; case "commandargument": CommandArgument = reader.Value; break; case "target": Target = reader.Value; break; //default: // throw new XmlException(String.Format("Unexpected attribute '{0}'", reader.Name)); } }while (reader.MoveToNextAttribute()); } if (empty) { return; } while (reader.Read()) { switch (reader.NodeType) { case XmlNodeType.Element: switch (reader.Name.ToLowerInvariant()) { case "node": var child = new MenuNode { Parent = this }; child.ReadXml(reader); Children.Add(child); break; case "keywords": Keywords = reader.ReadElementContentAsString().Trim(); break; case "description": Description = reader.ReadElementContentAsString().Trim(); break; case "root": break; default: throw new XmlException(String.Format("Unexpected element '{0}'", reader.Name)); } break; case XmlNodeType.EndElement: reader.ReadEndElement(); return; } } }
public static List <MenuNode> ConvertDNNNodeCollection(DNNNodeCollection dnnNodes, MenuNode parent) { var result = new List <MenuNode>(); foreach (DNNNode node in dnnNodes) { result.Add(new MenuNode(node, parent)); } return(result); }
private void FilterNodes(string nodeString, bool exclude) { var nodeTextStrings = SplitAndTrim(nodeString); var filteredNodes = new List <MenuNode>(); var tc = new TabController(); var flattenedNodes = new MenuNode(); foreach (var nodeText in nodeTextStrings) { if (nodeText.StartsWith("[")) { var roleName = nodeText.Substring(1, nodeText.Length - 2); filteredNodes.AddRange( this.RootNode.Children.FindAll( n => { var tab = TabController.Instance.GetTab(n.TabId, Null.NullInteger, false); foreach (TabPermissionInfo perm in tab.TabPermissions) { if (perm.AllowAccess && (perm.PermissionKey == "VIEW") && ((perm.RoleID == -1) || (perm.RoleName.ToLowerInvariant() == roleName))) { return(true); } } return(false); })); } else if (nodeText.StartsWith("#")) { var tagName = nodeText.Substring(1, nodeText.Length - 1); if (!string.IsNullOrEmpty(tagName)) { // flatten nodes first. tagged pages should be flattened and not heirarchical if (flattenedNodes != new MenuNode()) { flattenedNodes.Children = this.RootNode.FlattenChildren(this.RootNode); } filteredNodes.AddRange( flattenedNodes.Children.FindAll( n => { var tab = tc.GetTab(n.TabId, Null.NullInteger, false); return(tab.Terms.Any(x => x.Name.ToLowerInvariant() == tagName)); })); } } else { filteredNodes.Add(this.RootNode.FindByNameOrId(nodeText)); } } // if filtered for foksonomy tags, use flat tree to get all related pages in nodeselection if (flattenedNodes.HasChildren()) { this.RootNode = flattenedNodes; } if (exclude) { this.RootNode.RemoveAll(filteredNodes); } else { this.RootNode.Children.RemoveAll(n => filteredNodes.Contains(n) == exclude); } }
private void ApplyNodeSelector() { string selector; if (!nodeSelectorAliases.TryGetValue(menuSettings.NodeSelector.ToLowerInvariant(), out selector)) { selector = menuSettings.NodeSelector; } var selectorSplit = SplitAndTrim(selector); var currentTabId = HostPortalSettings.ActiveTab.TabID; var newRoot = RootNode; var rootSelector = selectorSplit[0]; if (rootSelector != "*") { if (rootSelector.StartsWith("+")) { var depth = Convert.ToInt32(rootSelector); newRoot = RootNode; for (var i = 0; i <= depth; i++) { newRoot = newRoot.Children.Find(n => n.Breadcrumb); if (newRoot == null) { RootNode = new MenuNode(); return; } } } else if (rootSelector.StartsWith("-") || rootSelector == "0" || rootSelector == ".") { newRoot = RootNode.FindById(currentTabId); if (newRoot == null) { RootNode = new MenuNode(); return; } if (rootSelector.StartsWith("-")) { for (var n = Convert.ToInt32(rootSelector); n < 0; n++) { if (newRoot.Parent != null) { newRoot = newRoot.Parent; } } } } else { newRoot = RootNode.FindByNameOrId(rootSelector); if (newRoot == null) { RootNode = new MenuNode(); return; } } } // ReSharper disable PossibleNullReferenceException RootNode = new MenuNode(newRoot.Children); // ReSharper restore PossibleNullReferenceException if (selectorSplit.Count > 1) { for (var n = Convert.ToInt32(selectorSplit[1]); n > 0; n--) { var newChildren = new List <MenuNode>(); foreach (var child in RootNode.Children) { newChildren.AddRange(child.Children); } RootNode = new MenuNode(newChildren); } } if (selectorSplit.Count > 2) { var newChildren = RootNode.Children; for (var n = Convert.ToInt32(selectorSplit[2]); n > 0; n--) { var nextChildren = new List <MenuNode>(); foreach (var child in newChildren) { nextChildren.AddRange(child.Children); } newChildren = nextChildren; } foreach (var node in newChildren) { node.Children = null; } } }
private void ApplyNodeSelector() { string selector; if (!nodeSelectorAliases.TryGetValue(menuSettings.NodeSelector.ToLowerInvariant(), out selector)) { selector = menuSettings.NodeSelector; } var selectorSplit = SplitAndTrim(selector); var currentTabId = HostPortalSettings.ActiveTab.TabID; var newRoot = RootNode; var rootSelector = selectorSplit[0]; if (rootSelector != "*") { if (rootSelector.StartsWith("+")) { var depth = Convert.ToInt32(rootSelector); newRoot = RootNode; for (var i = 0; i <= depth; i++) { newRoot = newRoot.Children.Find(n => n.Breadcrumb); if (newRoot == null) { RootNode = new MenuNode(); return; } } } else if (rootSelector.StartsWith("-") || rootSelector == "0" || rootSelector == ".") { newRoot = RootNode.FindById(currentTabId); if (newRoot == null) { RootNode = new MenuNode(); return; } if (rootSelector.StartsWith("-")) { for (var n = Convert.ToInt32(rootSelector); n < 0; n++) { if (newRoot.Parent != null) { newRoot = newRoot.Parent; } } } } else { newRoot = RootNode.FindByNameOrId(rootSelector); if (newRoot == null) { RootNode = new MenuNode(); return; } } } // ReSharper disable PossibleNullReferenceException RootNode = new MenuNode(newRoot.Children); // ReSharper restore PossibleNullReferenceException if (selectorSplit.Count > 1) { for (var n = Convert.ToInt32(selectorSplit[1]); n > 0; n--) { var newChildren = new List<MenuNode>(); foreach (var child in RootNode.Children) { newChildren.AddRange(child.Children); } RootNode = new MenuNode(newChildren); } } if (selectorSplit.Count > 2) { var newChildren = RootNode.Children; for (var n = Convert.ToInt32(selectorSplit[2]); n > 0; n--) { var nextChildren = new List<MenuNode>(); foreach (var child in newChildren) { nextChildren.AddRange(child.Children); } newChildren = nextChildren; } foreach (var node in newChildren) { node.Children = null; } } }
private void FilterNodes(string nodeString, bool exclude) { var nodeTextStrings = SplitAndTrim(nodeString); var filteredNodes = new List<MenuNode>(); var tc = new TabController(); var flattenedNodes = new MenuNode(); foreach (var nodeText in nodeTextStrings) { if (nodeText.StartsWith("[")) { var roleName = nodeText.Substring(1, nodeText.Length - 2); filteredNodes.AddRange( RootNode.Children.FindAll( n => { var tab = TabController.Instance.GetTab(n.TabId, Null.NullInteger, false); foreach (TabPermissionInfo perm in tab.TabPermissions) { if (perm.AllowAccess && (perm.PermissionKey == "VIEW") && ((perm.RoleID == -1) || (perm.RoleName.ToLowerInvariant() == roleName))) { return true; } } return false; })); } else if (nodeText.StartsWith("#")) { var tagName = nodeText.Substring(1, nodeText.Length - 1); if (!string.IsNullOrEmpty(tagName)) { //flatten nodes first. tagged pages should be flattened and not heirarchical if (flattenedNodes != new MenuNode()) flattenedNodes.Children = RootNode.FlattenChildren(RootNode); filteredNodes.AddRange( flattenedNodes.Children.FindAll( n => { var tab = tc.GetTab(n.TabId, Null.NullInteger, false); return (tab.Terms.Any(x => x.Name.ToLower() == tagName)); })); } } else { var nodeText2 = nodeText; filteredNodes.AddRange( RootNode.Children.FindAll( n => { var nodeName = n.Text.ToLowerInvariant(); var nodeId = n.TabId.ToString(); return (nodeText2 == nodeName || nodeText2 == nodeId); })); } } // if filtered for foksonomy tags, use flat tree to get all related pages in nodeselection if (flattenedNodes.HasChildren()) RootNode = flattenedNodes; RootNode.Children.RemoveAll(n => filteredNodes.Contains(n) == exclude); }