Esempio n. 1
0
        public void LocaliseNode(MenuNode node)
        {
            TabInfo tab = (node.TabId > 0) ? TabController.Instance.GetTab(node.TabId, Null.NullInteger, false) : null;

            if (tab != null)
            {
                List <Core.Data.Entities.Localization> Localization = Core.Managers.LocalizationManager.GetLocaleProperties(PortalSettings.Current.CultureCode, "Page", tab.TabID, null);
                TabInfo localised = LocaliseTab(tab);
                tab = localised ?? tab;

                if (localised != null)
                {
                    node.TabId   = tab.TabID;
                    node.Enabled = !tab.DisableLink;
                    if (!tab.IsVisible)
                    {
                        node.TabId = -1;
                    }
                }

                node.Text        = (Localization.Count > 0 && Localization.Where(x => x.Name == "Name").FirstOrDefault() != null && !string.IsNullOrEmpty(Localization.Where(x => x.Name == "Name").FirstOrDefault().Value)) ? Localization.Where(x => x.Name == "Name").FirstOrDefault().Value : tab.TabName;
                node.Title       = (Localization.Count > 0 && Localization.Where(x => x.Name == "Title").FirstOrDefault() != null && !string.IsNullOrEmpty(Localization.Where(x => x.Name == "Title").FirstOrDefault().Value)) ? Localization.Where(x => x.Name == "Title").FirstOrDefault().Value : tab.Title;
                node.Description = (Localization.Count > 0 && Localization.Where(x => x.Name == "Description").FirstOrDefault() != null && !string.IsNullOrEmpty(Localization.Where(x => x.Name == "Description").FirstOrDefault().Value)) ? Localization.Where(x => x.Name == "Description").FirstOrDefault().Value : tab.Description;
                node.Keywords    = tab.KeyWords;
            }
            else
            {
                node.TabId = -1;
            }

            node.Children.ForEach(LocaliseNode);
        }
        private void FilterHiddenNodes(MenuNode parentNode)
        {
            PortalSettings  portalSettings = PortalController.Instance.GetCurrentSettings() as PortalSettings;
            List <MenuNode> filteredNodes  = new List <MenuNode>();

            filteredNodes.AddRange(
                parentNode.Children.FindAll(
                    n =>
            {
                TabInfo tab = TabController.Instance.GetTab(n.TabId, portalSettings.PortalId);
                return(tab == null || !tab.IsVisible);
            }));

            parentNode.Children.RemoveAll(n => filteredNodes.Contains(n));

            parentNode.Children.ForEach(FilterHiddenNodes);
        }
        public static List <MenuNode> ConvertDNNNodeCollection(DNNNodeCollection dnnNodes, MenuNode parent)
        {
            List <MenuNode> result = new List <MenuNode>();

            foreach (DNNNode node in dnnNodes)
            {
                result.Add(new MenuNode(node, parent));
            }

            return(result);
        }
        private void ApplyNodeSelector()
        {
            if (!nodeSelectorAliases.TryGetValue(menuSetting.NodeSelector.ToLowerInvariant(), out string selector))
            {
                selector = menuSetting.NodeSelector;
            }

            List <string> selectorSplit = SplitAndTrim(selector);

            int currentTabId = HostPortalSettings.ActiveTab.TabID;

            MenuNode newRoot = RootNode;

            string rootSelector = selectorSplit[0];

            if (rootSelector != "*")
            {
                if (rootSelector.StartsWith("+"))
                {
                    int depth = Convert.ToInt32(rootSelector);
                    newRoot = RootNode;
                    for (int 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 (int 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 (int n = Convert.ToInt32(selectorSplit[1]); n > 0; n--)
                {
                    List <MenuNode> newChildren = new List <MenuNode>();
                    foreach (MenuNode child in RootNode.Children)
                    {
                        newChildren.AddRange(child.Children);
                    }
                    RootNode = new MenuNode(newChildren);
                }
            }

            if (selectorSplit.Count > 2)
            {
                List <MenuNode> newChildren = RootNode.Children;
                for (int n = Convert.ToInt32(selectorSplit[2]); n > 0; n--)
                {
                    List <MenuNode> nextChildren = new List <MenuNode>();
                    foreach (MenuNode child in newChildren)
                    {
                        nextChildren.AddRange(child.Children);
                    }
                    newChildren = nextChildren;
                }
                foreach (MenuNode node in newChildren)
                {
                    node.Children = null;
                }
            }
        }