Ejemplo n.º 1
0
        /// <summary>Finds items linked by the supplied item. This method only finds links in html text to items within the site.</summary>
        /// <param name="item">The item to examine for links.</param>
        /// <returns>A list of items referenced in html text by the supplied item.</returns>
        public virtual IList <ContentItem> FindLinkedItems(ContentItem item)
        {
            N2.Collections.ItemList items = new N2.Collections.ItemList();
            foreach (ContentDetail detail in item.Details)
            {
                if (detail.StringValue != null)
                {
                    foreach (string link in FindLinks(detail.StringValue))
                    {
                        if (string.IsNullOrEmpty(link))
                        {
                            continue;
                        }
                        else if (!(link.StartsWith("/") || link.StartsWith("~") || link.Contains("://")))
                        {
                            continue;
                        }

                        try
                        {
                            ContentItem referencedItem = urlParser.Parse(link);
                            if (referencedItem != null && referencedItem.ID != 0 && !items.Contains(referencedItem))
                            {
                                items.Add(referencedItem);
                            }
                        }
                        catch (Exception ex)
                        {
                            errorHandler.Notify(ex);
                        }
                    }
                }
            }
            return(items);
        }
Ejemplo n.º 2
0
        /// <summary>Finds items linked by the supplied item. This method only finds links in html text to items within the site.</summary>
        /// <param name="item">The item to examine for links.</param>
        /// <returns>A list of items referenced in html text by the supplied item.</returns>
        public virtual IEnumerable <ContentDetail> FindLinkedObjects(ContentItem item)
        {
            HashSet <object> existing = new HashSet <object>();

            foreach (ContentDetail detail in item.Details)
            {
                if (detail.StringValue != null)
                {
                    foreach (var d in FindLinks(detail.StringValue))
                    {
                        string link = d.StringValue;
                        if (string.IsNullOrEmpty(link))
                        {
                            continue;
                        }
                        if (!(link.StartsWith("/") || link.StartsWith("~") || link.Contains("://")))
                        {
                            continue;
                        }

                        d.Meta = detail.Name;

                        try
                        {
                            ContentItem referencedItem = urlParser.Parse(link);
                            if (referencedItem != null && referencedItem.ID != 0)
                            {
                                d.LinkedItem = referencedItem;
                            }
                        }
                        catch (Exception ex)
                        {
                            errorHandler.Notify(ex);
                        }

                        var reference = (object)d.LinkedItem ?? d.StringValue;
                        if (existing.Contains(reference))
                        {
                            d.BoolValue = true;
                        }
                        else
                        {
                            existing.Add(reference);
                        }

                        yield return(d);
                    }
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>Finds items linked by the supplied item. This method only finds links in html text to items within the site.</summary>
        /// <param name="item">The item to examine for links.</param>
        /// <returns>A list of items referenced in html text by the supplied item.</returns>
        public virtual IEnumerable <object> FindLinkedObjects(ContentItem item)
        {
            HashSet <object> existing = new HashSet <object>();

            foreach (ContentDetail detail in item.Details)
            {
                if (detail.StringValue != null)
                {
                    foreach (string link in FindLinks(detail.StringValue))
                    {
                        if (string.IsNullOrEmpty(link))
                        {
                            continue;
                        }
                        else if (!(link.StartsWith("/") || link.StartsWith("~") || link.Contains("://")))
                        {
                            continue;
                        }

                        object referencedItemOrLink = null;
                        try
                        {
                            ContentItem referencedItem = urlParser.Parse(link);
                            if (referencedItem != null && referencedItem.ID != 0)
                            {
                                referencedItemOrLink = referencedItem;
                            }
                        }
                        catch (Exception ex)
                        {
                            errorHandler.Notify(ex);
                        }

                        if (referencedItemOrLink == null)
                        {
                            referencedItemOrLink = link;
                        }

                        if (!existing.Contains(referencedItemOrLink))
                        {
                            existing.Add(referencedItemOrLink);
                            yield return(referencedItemOrLink);
                        }
                    }
                }
            }
        }