Example #1
0
        public override ItemList GetItemsInZone(ContentItem parentItem, string zoneName)
        {
            if(zoneName.EndsWith("None"))
                return new ItemList();
            if (zoneName.EndsWith("All"))
                return parentItem.GetChildren(new DelegateFilter(ci => ci.ZoneName != null));

            return parentItem.GetChildren(zoneName);
        }
Example #2
0
        public override System.Collections.Generic.IEnumerable<ContentItem> GetParts(ContentItem belowParentItem, string inZoneNamed, string filteredForInterface)
        {
            if(inZoneNamed.EndsWith("None"))
                return new ItemList();
            if (inZoneNamed.EndsWith("All"))
                return belowParentItem.GetChildren(new DelegateFilter(ci => ci.ZoneName != null));

            return belowParentItem.GetChildren(inZoneNamed);
        }
Example #3
0
        public override ItemList GetItemsInZone(ContentItem parentItem, string zoneName)
        {
            if (zoneName.EndsWith("None"))
            {
                return(new ItemList());
            }
            if (zoneName.EndsWith("All"))
            {
                return(parentItem.GetChildren(new DelegateFilter(ci => ci.ZoneName != null)));
            }

            return(parentItem.GetChildren(zoneName));
        }
Example #4
0
        public override System.Collections.Generic.IEnumerable <ContentItem> GetParts(ContentItem belowParentItem, string inZoneNamed, string filteredForInterface)
        {
            if (inZoneNamed.EndsWith("None"))
            {
                return(new ItemList());
            }
            if (inZoneNamed.EndsWith("All"))
            {
                return(belowParentItem.GetChildren(new DelegateFilter(ci => ci.ZoneName != null)));
            }

            return(belowParentItem.GetChildren(inZoneNamed));
        }
Example #5
0
 protected virtual IEnumerable<ContentItem> GetChildren(ContentItem currentItem)
 {
     IEnumerable<ContentItem> children = currentItem.GetChildren();
     if (Filter != null)
         children = Filter(children);
     return children;
 }
Example #6
0
        private void BuildControlHierarchy(ContentItem currentItem, ContentItem startPage)
        {
            if (currentItem == null)
            {
                currentItem = startPage;
            }

            ItemList children = currentItem.GetChildren();

            if (children.Count > 0)
            {
                currentItem = children[0];
            }
            IEnumerable <ContentItem> ancestors = GetAncestors(currentItem, startPage);
            ContentItem startingPoint           = GetStartingPoint();

            if (startingPoint != null)
            {
                ItemHierarchyNavigator navigator;
                if (BranchMode)
                {
                    navigator = new ItemHierarchyNavigator(new BranchHierarchyBuilder(currentItem, startingPoint), Filters);
                }
                else
                {
                    navigator = new ItemHierarchyNavigator(new TreeHierarchyBuilder(startingPoint, MaxLevels), Filters);
                }
                if (navigator.Current != null)
                {
                    AddControlsRecursive(this, navigator, CurrentPage, ancestors);
                }
            }
        }
Example #7
0
        public IEnumerable <ContentItem> GetChildren(string path)
        {
            foreach (var pair in UploadFolderPaths)
            {
                if (pair.ParentPath.Equals(path, StringComparison.InvariantCultureIgnoreCase))
                {
                    yield return(CreateDirectory(pair));
                }
                else if (path.StartsWith(pair.Path, StringComparison.InvariantCultureIgnoreCase))
                {
                    ContentItem dir = CreateDirectory(pair);

                    var subdirPath = path.Substring(pair.Path.Length);
                    if (subdirPath != "")
                    {
                        dir = dir.GetChild(subdirPath);
                    }

                    if (dir != null)
                    {
                        foreach (var child in dir.GetChildren(new NullFilter()))
                        {
                            yield return(child);
                        }
                    }
                }
            }
        }
Example #8
0
        public bool HasChildren(string path)
        {
            foreach (var pair in UploadFolderPaths)
            {
                if (pair.ParentPath.Equals(path, StringComparison.InvariantCultureIgnoreCase))
                {
                    return(true);
                }

                if (pair.Path.Equals(path, StringComparison.InvariantCultureIgnoreCase))
                {
                    return(true);
                }

                if (path.StartsWith(pair.Path, StringComparison.InvariantCultureIgnoreCase))
                {
                    ContentItem dir = CreateDirectory(pair);

                    var remaining = path.Substring(pair.Path.Length);
                    if (!string.IsNullOrEmpty(remaining))
                    {
                        dir = dir.GetChild(remaining);
                    }

                    if (dir != null)
                    {
                        return(dir.GetChildren().Any());
                    }
                }
            }
            return(false);
        }
Example #9
0
 protected void AddReferencesRecursive(ContentItem current, ItemList referrers)
 {
     referrers.AddRange(Find.Items.Where.Detail().Eq(Item).Select());
     foreach (ContentItem child in current.GetChildren())
     {
         AddReferencesRecursive(child, referrers);
     }
 }
Example #10
0
 private void ApplyRolesRecursive(ContentItem item)
 {
     ApplyRoles(item);
     foreach (ContentItem child in item.GetChildren())
     {
         ApplyRolesRecursive(child);
     }
 }
    private static N2.Collections.ItemList GetChildren(ContentItem parentItem)
    {
        N2.Collections.ItemFilter trashFilter = new N2.Collections.TypeFilter(true, typeof(N2.Edit.Trash.TrashContainerItem));
        N2.Collections.ItemFilter folderFilter = new N2.Collections.TypeFilter(true, typeof(FolderItem));
        N2.Collections.ItemFilter imageFilter = new N2.Collections.TypeFilter(true, typeof(ImageItem));

        return parentItem.GetChildren(trashFilter, folderFilter, imageFilter);
    }
 private Collections.ItemList GetAllItems()
 {
     if (allItems == null && parentItem != null)
     {
         allItems = parentItem.GetChildren();
     }
     return(allItems);
 }
Example #13
0
 protected void AddReferencesRecursive(ContentItem current, ItemList referrers)
 {
     referrers.AddRange(Find.Items.Where.Detail().Eq(Item).Select());
     foreach (ContentItem child in current.GetChildren())
     {
         AddReferencesRecursive(child, referrers);
     }
 }
Example #14
0
        public IEnumerable <ContentItem> Children(ContentItem item, ItemFilter filter = null)
        {
            if (item == null)
            {
                return(Enumerable.Empty <ContentItem>());
            }

            return(item.GetChildren(filter ?? DefaultFilter()));
        }
        public static IList <T> GetCrossLinks <T>(this ContentItem contentItem, string childZoneName) where T : ContentItem
        {
            var children = contentItem.GetChildren(
                new ZoneFilter(childZoneName),
                new AccessFilter(),
                new CrossLinkFilter <T>());

            return(children.Select(c => (T)c.GetDetail("ContentItem")).ToList());
        }
Example #16
0
 protected void AddReferencesRecursive(ContentItem current, ItemList referrers)
 {
     referrers.AddRange(Content.Search.Repository.Find(Parameter.Equal(null, Item).Detail()));
     //Find.Items.Where.Detail().Eq(Item).Select());
     foreach (ContentItem child in current.GetChildren())
     {
         AddReferencesRecursive(child, referrers);
     }
 }
		protected void AddReferencesRecursive(ContentItem current, ItemList referrers)
		{
			referrers.AddRange(Content.Search.Repository.Find(Parameter.Equal(null, Item).Detail()));
				//Find.Items.Where.Detail().Eq(Item).Select());
			foreach (ContentItem child in current.GetChildren())
			{
				AddReferencesRecursive(child, referrers);
			}
		}
Example #18
0
        /// <summary>Retrieves content items added to a zone of the parnet item.</summary>
        /// <param name="parentItem">The item whose items to get.</param>
        /// <param name="zoneName">The zone in which the items should be contained.</param>
        /// <returns>A list of items in the zone.</returns>
        public virtual ItemList GetItemsInZone(ContentItem parentItem, string zoneName)
        {
            if (parentItem == null)
            {
                return(new ItemList());
            }

            return(parentItem.GetChildren(zoneName));
        }
		public override void UpdateEditor(ContentItem item, Control editor)
		{
			TextBox tb = (TextBox)editor;
			tb.Text = string.Empty;
			foreach (ContentItem child in item.GetChildren())
			{
				tb.Text += child.Title + Environment.NewLine;
			}
		}
        /// <summary>Children of a given item.</summary>
        /// <param name="parent"></param>
        /// <param name="filter"></param>
        /// <returns></returns>
        public IEnumerable <ContentItem> Children(ContentItem parent, ItemFilter filter = null)
        {
            if (parent == null)
            {
                return(Enumerable.Empty <ContentItem>());
            }
            TryMasterVersion(ref parent);

            return(parent.GetChildren(filter ?? DefaultFilter));
        }
        public override void UpdateEditor(ContentItem item, Control editor)
        {
            TextBox tb = (TextBox)editor;

            tb.Text = string.Empty;
            foreach (ContentItem child in item.GetChildren())
            {
                tb.Text += child.Title + Environment.NewLine;
            }
        }
Example #22
0
 /// <summary>
 /// Builds up the entire site tree recursively, adding items to the list
 /// </summary>
 /// <param name="list">This should be an empty list</param>
 /// <param name="parent">This should be called using the root item</param>
 private void RecurseTree(IList <ContentItem> list, ContentItem parent)
 {
     // TODO: add caching?
     foreach (var item in parent.GetChildren())
     {
         if (item.Visible && item.IsPage)                 // TODO make this a setting
         {
             list.Add(item);
             RecurseTree(list, item);
         }
     }
 }
Example #23
0
 /// <summary>Gets the children of the given item for the given user interface.</summary>
 /// <param name="parent">The item whose children to get.</param>
 /// <param name="userInterface">The interface where the children are displayed.</param>
 /// <returns>An enumeration of the children.</returns>
 public virtual IEnumerable<ContentItem> GetChildren(ContentItem parent, string userInterface)
 {
     foreach (var child in parent.GetChildren(new AccessFilter(WebContext.User, Security)))
     {
         yield return child;
     }
     if (Interfaces.Managing == userInterface)
     {
         foreach (var child in NodeFactory.GetChildren(parent.Path))
         {
             yield return child;
         }
     }
 }
Example #24
0
 /// <summary>Gets the children of the given item for the given user interface.</summary>
 /// <param name="parent">The item whose children to get.</param>
 /// <param name="userInterface">The interface where the children are displayed.</param>
 /// <returns>An enumeration of the children.</returns>
 public virtual IEnumerable <ContentItem> GetChildren(ContentItem parent, string userInterface)
 {
     foreach (var child in parent.GetChildren(new AccessFilter(WebContext.User, Security)))
     {
         yield return(child);
     }
     if (Interfaces.Managing == userInterface)
     {
         foreach (var child in NodeFactory.GetChildren(parent.Path))
         {
             yield return(child);
         }
     }
 }
        public override SiteMapNodeCollection GetChildNodes(SiteMapNode node)
        {
            SiteMapNodeCollection nodes = new SiteMapNodeCollection();
            ContentItem           item  = (node != null) ? Context.Persister.Get(int.Parse(node.Key)) : null;

            // Add published nodes that are pages
            if (item != null)
            {
                foreach (ContentItem child in item.GetChildren(GetFilter()))
                {
                    nodes.Add(Convert(child));
                }
            }

            return(nodes);
        }
 private static IEnumerable GetFiles(ContentItem contentItem, FileType fileType)
 {
     IEnumerable<ContentItem> files = contentItem.GetChildren().Pages().Published().Authorized(Operations.Read);
     switch (fileType)
     {
         case FileType.Image :
             files = files.Where(f => f is FileSystem.Images.Image);
             break;
     }
     return files.Select(ci => new
         {
             name = ci.Title,
             url = GetUrl(fileType, ci),
             imageUrl = GetImageUrl(ci)
         });
 }
Example #27
0
        private void BuildControlHierarchy(ContentItem currentItem, ContentItem startPage)
        {
            if (currentItem == null)
            {
                currentItem = startPage;
            }

            ItemList children = currentItem.GetChildren();

            if (children.Count > 0)
            {
                currentItem = children[0];
            }
            IEnumerable <ContentItem> ancestors = GetAncestors(currentItem, startPage);
            ContentItem startingPoint           = GetStartingPoint();

            if (startingPoint != null)
            {
                HierarchyBuilder builder = null;

                if (BranchMode)
                {
                    builder = new BranchHierarchyBuilder(currentItem, startingPoint);
                }
                else
                {
                    builder = new TreeHierarchyBuilder(startingPoint, MaxLevels);
                }

                HierarchyNode <ContentItem> node = builder.Children(Filters).Build();
                if (node.Current != null)
                {
                    AddControlsRecursive(this, node, CurrentItem, ancestors);
                }
            }
        }
Example #28
0
 protected void AddReferencesRecursive(ContentItem current, List<ContentItem> referrers)
 {
     referrers.AddRange(Context.Finder.QueryItems().Where(ci => ci.Details.OfType<LinkProperty>().Any(ld => ld.LinkedItem == current)));
     foreach (ContentItem child in current.GetChildren())
         AddReferencesRecursive(child, referrers);
 }
Example #29
0
		private IEnumerable<ContentItem> GetChildren(ContentItem ancestorItem)
		{
			return (from x in ancestorItem.GetChildren()
					where x.IsPage && (menuPart.MenuShowInvisible || x.Visible) && x.IsPublished() && x.ID != Content.Current.Page.ID
					select x).ToArray();
		}
Example #30
0
 private static IEnumerable <StartPage> GetTranslations(ContentItem currentPage)
 {
     return(currentPage.GetChildren().OfType <StartPage>());
 }
Example #31
0
 /// <summary>
 /// Builds up the entire site tree recursively, adding items to the list
 /// </summary>
 /// <param name="list">This should be an empty list</param>
 /// <param name="parent">This should be called using the root item</param>
 private static void RecurseTree(IList<ContentItem> list, ContentItem parent)
 {
     // TODO: add caching?
     foreach (var item in parent.GetChildren().Visible().Pages())
     {
         list.Add(item);
         RecurseTree(list, item);
     }
 }
Example #32
0
 /// <summary>Returns true when an item has children.</summary>
 /// <param name="filter">The filter to apply.</param>
 /// <param name="parent">The item whose childrens existence is to be determined.</param>
 /// <returns>True when there are children.</returns>
 public virtual bool HasChildren(ContentItem parent, ItemFilter filter)
 {
     return parent.GetChildren(filter).Count > 0;
 }
Example #33
0
 IHierarchicalEnumerable IHierarchyData.GetChildren()
 {
     return(item.GetChildren());
 }
Example #34
0
 public override IHierarchicalEnumerable Select()
 {
     return(parentItem != null?parentItem.GetChildren() : null);
 }
Example #35
0
        public IEnumerable<ContentItem> Children(ContentItem item, ItemFilter filter = null)
        {
            if (item == null) return Enumerable.Empty<ContentItem>();

            return item.GetChildren(filter ?? DefaultFilter());
        }
Example #36
0
        /// <summary>Retrieves content items added to a zone of the parnet item.</summary>
        /// <param name="parentItem">The item whose items to get.</param>
        /// <param name="zoneName">The zone in which the items should be contained.</param>
        /// <returns>A list of items in the zone.</returns>
        public virtual ItemList GetItemsInZone(ContentItem parentItem, string zoneName)
        {
            if(parentItem == null)
                return new ItemList();

            return parentItem.GetChildren(zoneName);
        }
Example #37
0
 private void ApplyRolesRecursive(ContentItem item)
 {
     ApplyRoles(item);
     foreach (ContentItem child in item.GetChildren())
     {
         ApplyRolesRecursive(child);
     }
 }
 /// <summary>
 /// Builds up the entire site tree recursively, adding items to the list
 /// </summary>
 /// <param name="list">This should be an empty list</param>
 /// <param name="parent">This should be called using the root item</param>
 private void RecurseTree(IList<ContentItem> list, ContentItem parent)
 {
     // TODO: add caching?
     foreach (var item in parent.GetChildren())
     {
         if (item.Visible && item.IsPage) // TODO make this a setting
         {
             list.Add(item);
             RecurseTree(list, item);
         }
     }
 }
Example #39
0
        private static bool SitemapRecursive(ContentItem contentItem, StringBuilder sb)
        {
            var childItems = contentItem.GetChildren().Visible();

            bool foundSomething = false;

            StringBuilder sbInner = new StringBuilder();

            if (childItems.Any())
            {
                sbInner.Append("<ul>");
                foreach (ContentItem childItem in childItems)
                {
                    ISitemapAppearance appearance = childItem as ISitemapAppearance;
                    //the appearance != null bit means that by default items won't show as links
                    bool visible = childItem.Visible && (childItem.IsPage || (appearance != null && appearance.VisibleInSitemap));

                    if (visible)
                    {
                        sbInner.Append("<li>");

                        sbInner.AppendFormat("<a href=\"{0}\">{1}</a>", childItem.Url, childItem.Title);
                        foundSomething = true;

                        //something has been found on this tree path, but still possibility of dead ends, so start again!
                        StringBuilder sbInnerFurther = new StringBuilder();
                        SitemapRecursive(childItem, sbInnerFurther);
                        sbInner.Append(sbInnerFurther.ToString());

                        sbInner.Append("</li>");
                    }
                    else
                    {
                        //nothing found yet, so don't add anything but keep checking - progress so far needs to be saved to the new stringbuilder
                        StringBuilder sbInnerFurther = new StringBuilder();
                        sbInnerFurther.Append("<li>");
                        sbInnerFurther.Append(childItem.Title);

                        //this will return if something is found further down the tree
                        foundSomething = SitemapRecursive(childItem, sbInnerFurther);

                        //only add this level if something was found!
                        if (foundSomething)
                            sbInner.Append(sbInnerFurther.ToString() + "</li>");
                    }
                }
                sbInner.Append("</ul>");
            }

            //only append to the final string, if at somepoint a link has been hit, otherwise, you'll end up with loads of titles for no reason
            if (foundSomething)
                sb.Append(sbInner.ToString());

            return foundSomething;
        }
Example #40
0
        /// <summary>Children of a given item.</summary>
        /// <param name="parent"></param>
        /// <param name="filter"></param>
        /// <returns></returns>
        public IEnumerable<ContentItem> Children(ContentItem parent, ItemFilter filter = null)
        {
            if (parent == null) return Enumerable.Empty<ContentItem>();
            UseMasterVersion(ref parent);

            return parent.GetChildren(filter ?? DefaultFilter);
        }
Example #41
0
		protected virtual void UpdateParts(ContentItem target, ContentItem source)
		{

			List<string> keysTarget = new List<string>(target.GetChildren(new Collections.PartFilter()).Keys);
			List<string> keysSource = new List<string>(source.GetChildren(new Collections.PartFilter()).Keys);
			System.Collections.Generic.Dictionary<int, ContentItem> toCopy = new System.Collections.Generic.Dictionary<int, ContentItem>();

			bool bDelete = true;
			bool bAdd = true;


			foreach (string keyTarget in keysTarget)
			{
				ContentItem childTarget = target.Children[keyTarget];


				foreach (string keySource in keysSource)
				{
					ContentItem childSource = source.Children[keySource];

					if (childSource.TranslationKey == childTarget.TranslationKey)
					{
						UpdateContentItem(childTarget, childSource);
						childTarget.SortOrder = childSource.SortOrder;
						bDelete = false;
					}

				}

				if (bDelete)
				{
					_persister.Delete(childTarget);
					//N2.Context.Current.Resolve<N2.Edit.Trash.ITrashHandler>().Purge(childTarget);
				}
				else
					bDelete = true;
			}


			keysTarget = new List<string>(target.GetChildren(new Collections.PartFilter()).Keys);

			foreach (string keySource in keysSource)
			{
				ContentItem childSource = source.Children[keySource];

				foreach (string keyTarget in keysTarget)
				{
					ContentItem childTarget = target.Children[keyTarget];

					if (childSource.TranslationKey == childTarget.TranslationKey)
					{
						bAdd = false;
					}
				}

				if (bAdd)
				{
					childSource.ID = 0;
					childSource.Parent = null;
					toCopy.Add(source.Children.IndexOf(childSource), childSource);
				}
				else
					bAdd = true;

			}

			ContentItem copyChild;
			foreach (int key in toCopy.Keys)
			{
				if (toCopy.TryGetValue(key, out copyChild))
				{
					copyChild.InsertAt(target, key);
				}
			}

		}
Example #42
0
 private IEnumerable <ContentItem> GetChildren(ContentItem ancestorItem)
 {
     return((from x in ancestorItem.GetChildren()
             where x.IsPage && (menuPart.MenuShowInvisible || x.Visible) && x.IsPublished() && x.ID != Content.Current.Page.ID
             select x).ToArray());
 }
Example #43
0
 /// <summary>Returns true when an item has children.</summary>
 /// <param name="filter">The filter to apply.</param>
 /// <param name="parent">The item whose childrens existence is to be determined.</param>
 /// <returns>True when there are children.</returns>
 public virtual bool HasChildren(ContentItem parent, ItemFilter filter)
 {
     return(parent.GetChildren(filter).Count > 0);
 }
Example #44
0
		private static IEnumerable<StartPage> GetTranslations(ContentItem currentPage)
		{
			return currentPage.GetChildren().OfType<StartPage>();
		}
Example #45
0
        private void ApplyRulesRecursive(ContentItem item, IEnumerable<string> allowedOperations)
        {
            // Only apply the rules if the current user has permission to administer this item.
            if (Engine.SecurityManager.IsAuthorized(item, User, Operations.Administer))
                ApplyRules(item, allowedOperations);

            // Apply recursively.
            ContentItem[] children = item.GetChildren().ToArray();
            foreach (ContentItem child in children)
                ApplyRulesRecursive(child, allowedOperations);
        }
Example #46
0
 public IEnumerable<ContentItem> Children(ContentItem item, ItemFilter filter = null)
 {
     return item.GetChildren(filter ?? new NavigationFilter());
 }
Example #47
0
 private static IEnumerable<WidgetContentItem> GetWidgets(ContentItem item)
 {
     return item.GetChildren<WidgetContentItem>().Authorized(Operations.Read);
 }