protected Url BuildPageUrl(ContentItem page, ref ContentItem current) { Url url = "/"; if (!host.IsStartPage(current)) { if (BuildingUrl != null) { // build path until a start page while (current != null && !host.IsStartPage(current)) { var args = new UrlEventArgs(current); BuildingUrl(this, args); if (!string.IsNullOrEmpty(args.Url)) { url = url.PrependSegment(Url.ToRelative(args.Url).TrimStart('~')); break; } url = url.PrependSegment(current.Name); current = current.Parent; } } else { while (current != null && !host.IsStartPage(current)) { url = url.PrependSegment(current.Name); current = current.Parent; } } url = url.SetExtension(page.Extension); } return(url); }
/// <summary>Calculates an item url by walking it's parent path.</summary> /// <param name="item">The item whose url to compute.</param> /// <returns>A friendly url to the supplied item.</returns> public override string BuildUrl(ContentItem item) { if (item == null) throw new ArgumentNullException("item"); ContentItem current = item; if (item.VersionOf.HasValue) { current = item.VersionOf; } // move up until first real page while(current != null && !current.IsPage) { current = current.Parent; } // no start page found, use rewritten url if (current == null) return item.FindPath(PathData.DefaultAction).GetRewrittenUrl(); Url url; if (host.IsStartPage(current)) { // we move right up to the start page url = "/"; } else { // at least one node before the start page url = new Url("/" + current.Name + current.Extension); current = current.Parent; // build path until a start page while (current != null && !host.IsStartPage(current)) { url = url.PrependSegment(current.Name); current = current.Parent; } } // no start page found, use rewritten url if (current == null) return item.FindPath(PathData.DefaultAction).GetRewrittenUrl(); if (item.IsPage && item.VersionOf.HasValue) // the item was a version, add this information as a query string url = url.AppendQuery(PathData.PageQueryKey, item.ID); else if(!item.IsPage) // the item was not a page, add this information as a query string url = url.AppendQuery(PathData.ItemQueryKey, item.ID); if (current.ID == host.CurrentSite.StartPageID) { // the start page belongs to the current site, use relative url return Url.ToAbsolute("~" + url.PathAndQuery); } var site = host.GetSite(current.ID) ?? host.DefaultSite; return GetHostedUrl(item, url, site); }
public string BuildUrl(ContentItem item) { Url url = new Url("/"); foreach (ContentItem parent in N2.Find.EnumerateParents(item, null, true)) { if (true == parent["IsStartPage"] as bool?) return url; url = url.PrependSegment(parent.Name); } return url; }
/// <summary>Calculates an item url by walking it's parent path.</summary> /// <param name="item">The item whose url to compute.</param> /// <returns>A friendly url to the supplied item.</returns> public virtual string BuildUrl(ContentItem item) { if (item == null) throw new ArgumentNullException("item"); ContentItem current = item; if (item.VersionOf != null) { current = item.VersionOf; } // move up until first real page while (current != null && !current.IsPage) { current = current.Parent; } // no page found, use rewritten url if (current == null) throw new N2Exception("Cannot build url to data item '{0}' with no containing page item.", item); Url url; if (host.IsStartPage(current)) { // we move right up to the start page url = "/"; } else { // at least one node before the start page url = new Url("/" + current.Name + current.Extension); current = current.Parent; // build path until a start page while (current != null && !host.IsStartPage(current)) { url = url.PrependSegment(current.Name); current = current.Parent; } } // no start page found, use rewritten url if (current == null) return item.FindPath(PathData.DefaultAction).RewrittenUrl; if (item.IsPage && item.VersionOf != null) // the item was a version, add this information as a query string url = url.AppendQuery(PathData.PageQueryKey, item.ID); else if (!item.IsPage) // the item was not a page, add this information as a query string url = url.AppendQuery(PathData.ItemQueryKey, item.ID); return Url.ToAbsolute("~" + url); }
/// <summary>Calculates an item url by walking it's parent path.</summary> /// <param name="item">The item whose url to compute.</param> /// <returns>A friendly url to the supplied item.</returns> public virtual string BuildUrl(ContentItem item) { if (item == null) { throw new ArgumentNullException("item"); } ContentItem current = item; if (item.VersionOf != null) { current = item.VersionOf; } // move up until first real page while (current != null && !current.IsPage) { current = current.Parent; } // no page found, use rewritten url if (current == null) { throw new N2Exception("Cannot build url to data item '{0}' with no containing page item.", item); } Url url; if (host.IsStartPage(current)) { // we move right up to the start page url = "/"; } else { // at least one node before the start page url = new Url("/" + current.Name + current.Extension); current = current.Parent; // build path until a start page while (current != null && !host.IsStartPage(current)) { url = url.PrependSegment(current.Name); current = current.Parent; } } // no start page found, use rewritten url if (current == null) { return(item.FindPath(PathData.DefaultAction).RewrittenUrl); } if (item.IsPage && item.VersionOf != null) { // the item was a version, add this information as a query string url = url.AppendQuery(PathData.PageQueryKey, item.ID); } else if (!item.IsPage) { // the item was not a page, add this information as a query string url = url.AppendQuery(PathData.ItemQueryKey, item.ID); } return(Url.ToAbsolute("~" + url)); }
/// <summary>Calculates an item url by walking it's parent path.</summary> /// <param name="item">The item whose url to compute.</param> /// <returns>A friendly url to the supplied item.</returns> public override string BuildUrl(ContentItem item) { if (item == null) { throw new ArgumentNullException("item"); } ContentItem current = item; if (item.VersionOf != null) { current = item.VersionOf; } // move up until first real page while (current != null && !current.IsPage) { current = current.Parent; } // no start page found, use rewritten url if (current == null) { return(item.FindPath(PathData.DefaultAction).RewrittenUrl); } Url url; if (host.IsStartPage(current)) { // we move right up to the start page url = "/"; } else { // at least one node before the start page url = new Url("/" + current.Name + current.Extension); current = current.Parent; // build path until a start page while (current != null && !host.IsStartPage(current)) { url = url.PrependSegment(current.Name); current = current.Parent; } } // no start page found, use rewritten url if (current == null) { return(item.FindPath(PathData.DefaultAction).RewrittenUrl); } if (item.IsPage && item.VersionOf != null) { // the item was a version, add this information as a query string url = url.AppendQuery(PathData.PageQueryKey, item.ID); } else if (!item.IsPage) { // the item was not a page, add this information as a query string url = url.AppendQuery(PathData.ItemQueryKey, item.ID); } if (current.ID == host.CurrentSite.StartPageID) { // the start page belongs to the current site, use relative url return(Url.ToAbsolute("~" + url.PathAndQuery)); } var site = host.GetSite(current.ID) ?? host.DefaultSite; return(GetHostedUrl(item, url, site)); }