Refactor of niceurl (and parts of requesthandler)
[TFS Changeset #78370]
This commit is contained in:
@@ -421,10 +421,62 @@ namespace umbraco
|
||||
return niceUrlCache[nodeID];
|
||||
}
|
||||
|
||||
internal static string niceUrlJuno(int nodeId, int startNodeDepth, string currentDomain)
|
||||
{
|
||||
string parentUrl = String.Empty;
|
||||
XmlElement node = UmbracoContext.Current.GetXml().GetElementById(nodeId.ToString());
|
||||
if (node.ParentNode.Name.ToLower() != "root" || UmbracoSettings.UseDomainPrefixes)
|
||||
{
|
||||
if (UmbracoSettings.UseDomainPrefixes)
|
||||
{
|
||||
Domain[] domains =
|
||||
Domain.GetDomainsById(nodeId);
|
||||
// when there's a domain on a url we'll just return the domain rather than the parent path
|
||||
if (domains.Length > 0)
|
||||
{
|
||||
if (currentDomain != String.Empty)
|
||||
{
|
||||
foreach (Domain d in domains)
|
||||
{
|
||||
// if there's multiple domains we'll prefer to use the same domain as the current request
|
||||
if (currentDomain == d.Name.ToLower())
|
||||
parentUrl = "http://" + d.Name;
|
||||
}
|
||||
}
|
||||
|
||||
if (parentUrl == String.Empty)
|
||||
{
|
||||
parentUrl = "http://" + domains[0].Name;
|
||||
}
|
||||
|
||||
return parentUrl;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (parentUrl == String.Empty && (int.Parse(node.Attributes.GetNamedItem("level").Value) > startNodeDepth || UmbracoSettings.UseDomainPrefixes))
|
||||
{
|
||||
if (node.ParentNode.Name != "root")
|
||||
{
|
||||
parentUrl = niceUrlJuno(int.Parse(node.ParentNode.Attributes.GetNamedItem("id").Value), startNodeDepth, currentDomain);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// only return the current node url if we're at the startnodedepth or higher
|
||||
if (int.Parse(node.Attributes.GetNamedItem("level").Value) >= startNodeDepth)
|
||||
return parentUrl + "/" + node.Attributes.GetNamedItem("urlName").Value;
|
||||
else
|
||||
return "/";
|
||||
}
|
||||
|
||||
internal static string NiceUrlFetch(int nodeID, int startNodeDepth)
|
||||
{
|
||||
bool directoryUrls = GlobalSettings.UseDirectoryUrls;
|
||||
string baseUrl = SystemDirectories.Root; // SystemDirectories.Umbraco;
|
||||
string junoUrl = niceUrlJuno(nodeID, startNodeDepth, HttpContext.Current.Request.ServerVariables["SERVER_NAME"].ToLower());
|
||||
return appendUrlExtension(baseUrl, directoryUrls, junoUrl);
|
||||
|
||||
//baseUrl = baseUrl.Substring(0, baseUrl.LastIndexOf("/"));
|
||||
|
||||
bool atDomain = false;
|
||||
|
||||
@@ -10,6 +10,7 @@ using umbraco.cms.businesslogic.template;
|
||||
using umbraco.cms.businesslogic.web;
|
||||
using umbraco.interfaces;
|
||||
using umbraco.IO;
|
||||
using umbraco.presentation.nodeFactory;
|
||||
|
||||
namespace umbraco {
|
||||
/// <summary>
|
||||
@@ -99,11 +100,22 @@ namespace umbraco {
|
||||
|
||||
// Check for Domain prefix
|
||||
string domainUrl = "";
|
||||
if (checkDomain && Domain.Exists(HttpContext.Current.Request.ServerVariables["SERVER_NAME"])) {
|
||||
domainUrl =
|
||||
library.NiceUrlFetch(
|
||||
Domain.GetRootFromDomain(HttpContext.Current.Request.ServerVariables["SERVER_NAME"]), 1); // we use niceUrlFetch because we have to bypass caching
|
||||
// If at domain root
|
||||
if (checkDomain && Domain.Exists(HttpContext.Current.Request.ServerVariables["SERVER_NAME"]))
|
||||
{
|
||||
// we need to get the node based on domain
|
||||
Node n = new Node(Domain.GetRootFromDomain(HttpContext.Current.Request.ServerVariables["SERVER_NAME"]));
|
||||
domainUrl = n.UrlName; // we don't use niceUrlFetch as we need more control
|
||||
if (n.Parent != null)
|
||||
{
|
||||
while (n.Parent != null)
|
||||
{
|
||||
n = n.Parent;
|
||||
domainUrl = n.UrlName + "/" + domainUrl;
|
||||
}
|
||||
}
|
||||
domainUrl = "/" + domainUrl;
|
||||
|
||||
// If at domain root
|
||||
if (url == "") {
|
||||
_tempQuery = "";
|
||||
requestRawUrl = domainUrl.Split("/".ToCharArray());
|
||||
|
||||
Reference in New Issue
Block a user