Implements 29219, Fixes 29265

[TFS Changeset #78962]
This commit is contained in:
hartvig
2010-10-26 09:40:03 +00:00
parent 33b7ade10d
commit 1bad5aeafe
6 changed files with 96 additions and 149 deletions

View File

@@ -1532,6 +1532,14 @@ namespace umbraco.cms.businesslogic.web
return GetPreviewXml(xd, Version);
}
/// <summary>
/// Method to remove an assigned template from a document
/// </summary>
public void RemoveTemplate()
{
Template = 0;
}
#endregion
#region Protected Methods

View File

@@ -24,7 +24,11 @@
<!-- the id of the page that should be shown if the page is not found -->
<!-- <errorPage culture="default">1</errorPage>-->
<!-- <errorPage culture="en-US">200</errorPage>-->
<error404>1</error404>
<error404>
<errorPage culture="default">1134</errorPage>
<errorPage culture="en-US">1135</errorPage>
<errorPage culture="en-UK">1135</errorPage>
</error404>
</errors>
<notifications>
<!-- the email that should be used as from mail when umbraco sends a notification -->
@@ -70,6 +74,8 @@
<requestHandler>
<!-- this will ensure that urls are unique when running with multiple root nodes -->
<useDomainPrefixes>false</useDomainPrefixes>
<!-- this will add a trailing slash (/) to urls when in directory url mode -->
<addTrailingSlash>false</addTrailingSlash>
<urlReplacing removeDoubleDashes="true">
<char org=" ">-</char>
<char org="&quot;"></char>
@@ -102,7 +108,7 @@
<cleaningMiliseconds>86400</cleaningMiliseconds>
<maxLogAge>1440</maxLogAge>
</logging>
<scheduledTasks>
<!-- add tasks that should be called with an interval (seconds) -->
<!-- <task log="true" alias="test60" interval="60" url="http://localhost/umbraco/test.aspx"/>-->
@@ -130,7 +136,7 @@
<memberServiceUsers>umbraco</memberServiceUsers>
<templateServiceUsers>umbraco</templateServiceUsers>
</webservices>
<!-- Configuration for repositories -->
<!-- Add or remove repositories here. You will need the repository's unique key to be able to connect to it.-->
<repositories>
@@ -148,7 +154,7 @@
<!-- Maps language, usertype, application and application_url to help pages -->
<help defaultUrl="http://our.umbraco.org/wiki/umbraco-help/{0}/{1}">
<!-- Add links that should open custom help pages -->
<!--<link application="content" applicationUrl="dashboard.aspx" language="en" userType="Administrators" helpUrl="http://www.xyz.no?{0}/{1}/{2}/{3}" /> -->
<!--<link application="content" applicationUrl="dashboard.aspx" language="en" userType="Administrators" helpUrl="http://www.xyz.no?{0}/{1}/{2}/{3}" /> -->
</help>
</settings>

View File

@@ -145,7 +145,30 @@ namespace umbraco
HttpContext.Current.Trace.Write("umbracoPage", "Looking up skin information");
if (m_umbPage != null)
this.MasterPageFile = template.GetMasterPageName(m_umbPage.Template);
{
if (m_umbPage.Template == 0)
{
string custom404 = umbraco.library.GetCurrentNotFoundPageId();
if (!String.IsNullOrEmpty(custom404))
{
XmlNode xmlNodeNotFound = content.Instance.XmlContent.GetElementById(custom404);
if (xmlNodeNotFound != null)
{
m_umbPage = new page(xmlNodeNotFound);
}
}
}
if (m_umbPage.Template != 0)
{
this.MasterPageFile = template.GetMasterPageName(m_umbPage.Template);
}
else
{
GenerateNotFoundContent();
Response.End();
}
}
initUmbracoPage();
}
@@ -247,17 +270,7 @@ namespace umbraco
else
{
Response.StatusCode = 404;
Response.Write("<html><body><h1>Page not found</h1>");
if (m_umbRequest != null)
HttpContext.Current.Response.Write("<h3>No umbraco document matches the url '" + HttpUtility.HtmlEncode(Request.Url.ToString()) + "'</h3><p>umbraco tried this to match it using this xpath query'" + m_umbRequest.PageXPathQuery + "')");
else
HttpContext.Current.Response.Write("<h3>No umbraco document matches the url '" + HttpUtility.HtmlEncode(Request.Url.ToString()) + "'</h3>");
Response.Write("</p>");
Response.Write("<p>This page can be replaced with a custom 404 page by adding the id of the umbraco document to show as 404 page in the /config/umbracoSettings.config file. Just add the id to the '/settings/content/errors/error404' element.</p>");
Response.Write("<p>For more information, visit <a href=\"http://umbraco.org/redir/custom-404\">information about custom 404</a> on the umbraco website.</p>");
Response.Write("<p style=\"border-top: 1px solid #ccc; padding-top: 10px\"><small>This page is intentionally left ugly ;-)</small></p>");
Response.Write("</body></html>");
GenerateNotFoundContent();
}
}
}
@@ -270,6 +283,21 @@ namespace umbraco
}
}
private void GenerateNotFoundContent()
{
Response.StatusCode = 404;
Response.Write("<html><body><h1>Page not found</h1>");
if (m_umbRequest != null)
HttpContext.Current.Response.Write("<h3>No umbraco document matches the url '" + HttpUtility.HtmlEncode(Request.Url.ToString()) + "'</h3><p>umbraco tried this to match it using this xpath query'" + m_umbRequest.PageXPathQuery + "')");
else
HttpContext.Current.Response.Write("<h3>No umbraco document matches the url '" + HttpUtility.HtmlEncode(Request.Url.ToString()) + "'</h3>");
Response.Write("</p>");
Response.Write("<p>This page can be replaced with a custom 404 page by adding the id of the umbraco document to show as 404 page in the /config/umbracoSettings.config file. Just add the id to the '/settings/content/errors/error404' element.</p>");
Response.Write("<p>For more information, visit <a href=\"http://umbraco.org/redir/custom-404\">information about custom 404</a> on the umbraco website.</p>");
Response.Write("<p style=\"border-top: 1px solid #ccc; padding-top: 10px\"><small>This page is intentionally left ugly ;-)</small></p>");
Response.Write("</body></html>");
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.

View File

@@ -477,79 +477,6 @@ namespace 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;
string currentDomain = HttpContext.Current.Request.ServerVariables["SERVER_NAME"].ToLower();
if (UmbracoSettings.UseDomainPrefixes && Domain.Exists(currentDomain))
atDomain = true;
// Find path from nodeID
String tempUrl = "";
XmlElement node = UmbracoContext.Current.GetXml().GetElementById(nodeID.ToString());
String[] splitpath = null;
if (node != null)
{
try
{
splitpath =
node.Attributes.GetNamedItem("path").Value.ToString().
Split(",".ToCharArray());
int startNode = startNodeDepth;
// check root nodes for domains
if (UmbracoSettings.UseDomainPrefixes && startNode > 1)
{
if (node.ParentNode.Name.ToLower() != "root")
{
Domain[] domains =
Domain.GetDomainsById(int.Parse(node.ParentNode.Attributes.GetNamedItem("id").Value));
if (
domains.Length > 0)
{
tempUrl =
getUrlByDomain(int.Parse(node.ParentNode.Attributes.GetNamedItem("id").Value), "",
atDomain, currentDomain, true);
}
// test for domains on root nodes, then make the url domain only
}
else if (Domain.GetDomainsById(nodeID).Length > 0)
{
tempUrl = getUrlByDomain(nodeID, "",
false, currentDomain, false);
return tempUrl;
}
}
if (splitpath.Length > startNode)
{
for (int i = startNode; i < splitpath.Length; i++)
{
tempUrl = getUrlByDomain(int.Parse(splitpath[i]), tempUrl, atDomain, currentDomain, false);
}
}
else
{
// check the root node for language
tempUrl += getUrlByDomain(nodeID, "", atDomain, currentDomain, false);
}
}
catch (Exception e)
{
HttpContext.Current.Trace.Warn("library.NiceUrl",
string.Format("Error generating nice url for id '{0}'", nodeID), e);
tempUrl = "/" + nodeID;
}
tempUrl = appendUrlExtension(baseUrl, directoryUrls, tempUrl);
}
else
HttpContext.Current.Trace.Warn("niceurl", string.Format("No node found at '{0}'", nodeID));
return tempUrl;
}
private static string appendUrlExtension(string baseUrl, bool directoryUrls, string tempUrl)
@@ -570,48 +497,6 @@ namespace umbraco
return tempUrl;
}
private static string getUrlByDomain(int DocumentId, string tempUrl, bool atDomain, string currentDomain,
bool emptyOnSameDomain)
{
Domain[] domains = Domain.GetDomainsById(DocumentId);
if (!UmbracoSettings.UseDomainPrefixes || domains.Length == 0)
tempUrl += "/" +
url.FormatUrl(
UmbracoContext.Current.GetXml().GetElementById(DocumentId.ToString()).Attributes.GetNamedItem
("urlName").Value);
else
{
// check if one of the domains are the same as the current one
if (atDomain)
{
bool inDomainRange = false;
foreach (Domain d in domains)
if (d.Name.ToLower() == currentDomain)
{
inDomainRange = true;
break;
}
if (inDomainRange)
{
if (emptyOnSameDomain)
return tempUrl;
else
tempUrl = "/" +
url.FormatUrl(
UmbracoContext.Current.GetXml().GetElementById(DocumentId.ToString()).Attributes.
GetNamedItem("urlName").Value);
}
else
tempUrl = "http://" + domains[0].Name;
}
else
tempUrl = "http://" + domains[0].Name;
}
return tempUrl;
}
/// <summary>
/// Returns a string with the data from the given element of a node. Both elements (data-fields)
/// and properties can be used - ie:
@@ -2287,6 +2172,36 @@ namespace umbraco
return cms.helpers.xhtml.TidyHtml(StringToTidy);
}
internal static string GetCurrentNotFoundPageId()
{
string error404 = "";
XmlNode error404Node = UmbracoSettings.GetKeyAsNode("/settings/content/errors/error404");
if (error404Node.ChildNodes.Count > 0 && error404Node.ChildNodes[0].HasChildNodes)
{
// try to get the 404 based on current culture (via domain)
XmlNode cultureErrorNode;
if (Domain.Exists(HttpContext.Current.Request.ServerVariables["SERVER_NAME"]))
{
Domain d = Domain.GetDomain(HttpContext.Current.Request.ServerVariables["SERVER_NAME"]);
// test if a 404 page exists with current culture
cultureErrorNode = error404Node.SelectSingleNode(String.Format("errorPage [@culture = '{0}']", d.Language.CultureAlias));
if (cultureErrorNode != null && cultureErrorNode.FirstChild != null)
error404 = cultureErrorNode.FirstChild.Value;
}
else
{
cultureErrorNode = error404Node.SelectSingleNode("errorPage [@culture = 'default']");
if (cultureErrorNode != null && cultureErrorNode.FirstChild != null)
error404 = cultureErrorNode.FirstChild.Value;
}
}
else
error404 = UmbracoSettings.GetKey("/settings/content/errors/error404");
return error404;
}
#endregion
#region Template Control Mapping Functions

View File

@@ -557,24 +557,7 @@ namespace umbraco {
url + " (from '" + HttpContext.Current.Request.UrlReferrer + "')");
// Test if the error404 not child elements
string error404 = "";
XmlNode error404Node = UmbracoSettings.GetKeyAsNode("/settings/content/errors/error404");
if (error404Node.ChildNodes.Count > 0 && error404Node.ChildNodes[0].HasChildNodes) {
// try to get the 404 based on current culture (via domain)
XmlNode cultureErrorNode;
if (Domain.Exists(HttpContext.Current.Request.ServerVariables["SERVER_NAME"])) {
Domain d = Domain.GetDomain(HttpContext.Current.Request.ServerVariables["SERVER_NAME"]);
// test if a 404 page exists with current culture
cultureErrorNode = error404Node.SelectSingleNode(String.Format("errorPage [@culture = '{0}']", d.Language.CultureAlias));
if (cultureErrorNode != null && cultureErrorNode.FirstChild != null)
error404 = cultureErrorNode.FirstChild.Value;
} else {
cultureErrorNode = error404Node.SelectSingleNode("errorPage [@culture = 'default']");
if (cultureErrorNode != null && cultureErrorNode.FirstChild != null)
error404 = cultureErrorNode.FirstChild.Value;
}
} else
error404 = UmbracoSettings.GetKey("/settings/content/errors/error404");
string error404 = umbraco.library.GetCurrentNotFoundPageId();
_redirectID = int.Parse(error404);

View File

@@ -273,6 +273,13 @@ namespace umbraco.cms.presentation
{
_document.Template = int.Parse(ddlDefaultTemplate.SelectedValue);
}
else
{
if (new DocumentType(_document.ContentType.Id).allowedTemplates.Length == 0)
{
_document.RemoveTemplate();
}
}