Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • alexei 21 posts 40 karma points
    Nov 23, 2009 @ 20:12
    alexei
    0

    niceurl > 3rd level

    Hi,

    I have a list of articles which includes items from several sub-domain sites. I used niceUrl and get the same problem as here http://our.umbraco.org/forum/using/ui-questions/3502-Problem-with-useDomainPrefixes---no-unique-URL-starting-with-3rd-level?p=0 ;

    Links to articles under the 3d level works only for current domain others are't reachible

    (umbraco tried this to match it using this xpath query'/domainprefixes-are-used-so-i-do-not-work')

    I tried use NiceUrlFullPath: the situation changed vice versa all domains exept current begin working. On curent domain I get top level folder inside url (  <add key="umbracoHideTopLevelNodeFromPath" value="true" />)

    Help me please to solve one of this problems or better both

    May be I can use Alternative Links? How?

    it is very important for my site, SOS!

  • alexei 21 posts 40 karma points
    Nov 23, 2009 @ 20:44
    alexei
    0

    upd

    I forget to say that I implemented the solution form this discussion  our.umbraco.org/.../3502-Problem-with-useDomainPrefixes---no-unique-URL-starting-with-3rd-level but it's to much additional coding. 

  • alexei 21 posts 40 karma points
    Nov 24, 2009 @ 22:32
    alexei
    0

    ok, no choice :(

    to minimize coding and errors we build modified NiceUrl which works exactly like NiceUrlFullPath but without a bug with toplevel folder. You may test following code if you  have same problem

    Any comments from umbraco gurus will be appriciated

    using

     

    System;

    using

     

    System.Data;

    using

     

    System.Globalization;

    using

     

    System.Configuration;

    using

     

    System.IO;

    using

     

    System.Net;

    using

     

    System.Net.Mail;

    using

     

    System.Text;

    using

     

    System.Text.RegularExpressions;

    using

     

    System.Web;

    using

     

    System.Web.UI;

    using

     

    System.Xml;

    using

     

    System.Xml.XPath;

     

    using

     

    umbraco.BusinessLogic;

    using

     

    umbraco.cms.businesslogic;

    using

     

    umbraco.cms.businesslogic.media;

    using

     

    umbraco.cms.businesslogic.member;

    using

     

    umbraco.cms.businesslogic.propertytype;

    using

     

    umbraco.cms.businesslogic.relation;

    using

     

    umbraco.cms.businesslogic.web;

    using

     

    umbraco.cms.helpers;

    using

     

    umbraco.presentation.cache;

    using

     

    umbraco.scripting;

    using

     

    umbraco.DataLayer;

    using

     

    umbraco.presentation.templateControls;

    using

     

    System.Web.Security;

    using

     

    umbraco.cms.businesslogic.language;

    using

     

    umbraco.presentation.nodeFactory;

    using

     

    umbraco.interfaces;

    using

     

    umbraco;

    namespace

     

    myUrl

    {

     

    /// <summary>

     

    /// Function library for umbraco. Includes various helper-methods and methods to

     

    /// save and load data from umbraco.

     

    ///

     

    /// Especially usefull in XSLT where any of these methods can be accesed using the umbraco.library name-space. Example:

     

    /// &lt;xsl:value-of select="umbraco.library:NiceUrl(@id)"/&gt;

     

    /// </summary>

     

    public class url

    {

    #region

     

    Xslt Helper functions

     

    /// <summary>

     

    /// Returns a string with a friendly url from a node.

     

    /// IE.: Instead of having /482 (id) as an url, you can have

     

    /// /screenshots/developer/macros (spoken url)

     

    /// </summary>

     

    /// <param name="nodeID">Identifier for the node that should be returned</param>

     

    /// <returns>String with a friendly url from a node</returns>

     

    public static string NiceUrl(int nodeID)

    {

     

    try

    {

     

    int startNode = 2;

     

     

    return niceUrlDo(nodeID, startNode);

    }

     

    catch

    {

     

    return "#";

    }

    }

     

    /// <summary>

     

    /// This method will always add the root node to the path. You should always use NiceUrl, as that is the

     

    /// only one who checks for toplevel node settings in the web.config

     

    /// </summary>

     

    /// <param name="nodeID">Identifier for the node that should be returned</param>

     

    /// <returns>String with a friendly url from a node</returns>

     

    public static string NiceUrlFullPath(int nodeID)

    {

     

    return niceUrlDo(nodeID, 1);

    }

     

    private static string niceUrlDo(int nodeID, int startNodeDepth)

    {

     

    XmlDocument umbracoXML = content.Instance.XmlContent;

     

    bool directoryUrls = GlobalSettings.UseDirectoryUrls;

     

    string baseUrl = GlobalSettings.Path;

    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 = umbracoXML.GetElementById(nodeID.ToString());

     

    String[] splitpath = null;

     

    if (node != null)

    {

     

    try

    {

    splitpath =

    umbracoXML.GetElementById(nodeID.ToString()).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() == "node")

    {

     

    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));

    tempUrl =

    "http://" + GetDomains(nodeID) + tempUrl;

     

    return tempUrl;

    }

     

    /// <summary>

     

    /// Gets the path to umbraco's root directory (/umbraco by default).

     

    /// </summary>

     

    /// <value>The path.</value>

     

    public static string Path

    {

     

    get

    {

     

    try

    {

     

    return ConfigurationManager.AppSettings["umbracoPath"];

    }

     

    catch

    {

     

    return String.Empty;

    }

    }

    }

     

    /// <summary>

     

    /// Gets a value indicating whether umbraco uses directory urls.

     

    /// </summary>

     

    /// <value><c>true</c> if umbraco uses directory urls; otherwise, <c>false</c>.</value>

     

    public static bool UseDirectoryUrls

    {

     

    get

    {

     

    try

    {

     

    return bool.Parse(ConfigurationManager.AppSettings["umbracoUseDirectoryUrls"]);

    }

     

    catch

    {

     

    return false;

    }

    }

    }

     

    private static string appendUrlExtension(string baseUrl, bool directoryUrls, string tempUrl)

    {

     

    if (!directoryUrls)

     

    // append .aspx extension if the url includes other than just the domain name

     

    if (tempUrl.ToString() != "" &&

    (!tempUrl.StartsWith(

    "http://") || tempUrl.Replace("http://", "").IndexOf("/") > -1))

    tempUrl = baseUrl + tempUrl +

    ".aspx";

     

    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(

     

    content.Instance.XmlContent.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(

     

    content.Instance.XmlContent.GetElementById(DocumentId.ToString()).Attributes.

    GetNamedItem(

    "urlName").Value);

    }

     

    else

     

    //tempUrl = "http://" + domains[0].Name;

    tempUrl = tempUrl;

    }

     

    else

     

    //tempUrl = "http://" + domains[0].Name;

    tempUrl = tempUrl;

    }

     

    return tempUrl;

    }

     

    /// <summary>

     

    /// Checks with the Assigned domains settings and retuns an array the the Domains matching the node

     

    /// </summary>

     

    /// <param name="NodeId">Identifier for the node that should be returned</param>

     

    /// <returns>A Domain array with all the Domains that matches the nodeId</returns>

     

    public static Domain[] GetCurrentDomains(int NodeId)

    {

     

    string[] pathIds = GetItem(NodeId, "path").Split(',');

     

    for (int i = pathIds.Length - 1; i > 0; i--)

    {

     

    Domain[] retVal = Domain.GetDomainsById(int.Parse(pathIds[i]));

     

    if (retVal.Length > 0)

    {

     

    return retVal;

    }

    }

     

    return null;

    }

     

    public static String GetDomains(int nodeid)

    {

     

    /*Domain[] doms = library.GetCurrentDomains(nodeid);

    StringBuilder sb = new StringBuilder();

    sb.Append("<domains>");

    foreach (Domain dom in doms)

    {

    sb.Append(string.Format("<domain id=\"{0}\" name=\"{1}\" language=\"{2}\" />", dom.Id, dom.Name, dom.Language.CultureAlias));

    }

    sb.Append("</domains>");

    XmlDocument xd = new XmlDocument();

    xd.LoadXml(sb.ToString());

    XPathNavigator xp = xd.CreateNavigator();

    return xp.Select("/domains");*/

     

    Domain[] doms = library.GetCurrentDomains(nodeid);

     

    return doms[0].Name;

    }

     

    public static string FormatUrl(string url)

    {

     

    string _newUrl = url;

     

    XmlNode replaceChars = UmbracoSettings.UrlReplaceCharacters;

     

    foreach (XmlNode n in replaceChars.SelectNodes("char"))

    {

     

    if (n.Attributes.GetNamedItem("org") != null && n.Attributes.GetNamedItem("org").Value != "")

    _newUrl = _newUrl.Replace(n.Attributes.GetNamedItem(

    "org").Value, xmlHelper.GetNodeValue(n));

    }

     

    return _newUrl;

    }

     

    /// <summary>

     

    /// Returns a string with the data from the given element of a node. Both elements (data-fields)

     

    /// and properties can be used - ie:

     

    /// getItem(1, nodeName) will return a string with the name of the node with id=1 even though

     

    /// nodeName is a property and not an element (data-field).

     

    /// </summary>

     

    /// <param name="nodeID">Identifier for the node that should be returned</param>

     

    /// <param name="alias">The element that should be returned</param>

     

    /// <returns>Returns a string with the data from the given element of a node</returns>

     

    public static string GetItem(int nodeID, String alias)

    {

     

    XmlDocument umbracoXML = content.Instance.XmlContent;

     

    if (umbracoXML.GetElementById(nodeID.ToString()) != null)

     

    if (

     

    ",id,version,parentID,level,writerID,editDataType,template,sortOrder,createDate,updateDate,nodeName,writerName,path,"

    .

    IndexOf(

    "," + alias + ",") > -1)

     

    return umbracoXML.GetElementById(nodeID.ToString()).Attributes.GetNamedItem(alias).Value;

     

    else if (

    umbracoXML.GetElementById(nodeID.ToString()).SelectSingleNode(

    "./data [@alias='" + alias + "']") !=

     

    null)

     

    return

    umbracoXML.GetElementById(nodeID.ToString()).SelectSingleNode(

    "./data [@alias = '" + alias +

     

    "']").ChildNodes[0].

    Value;

    //.Value + "*";

     

    else

     

    return string.Empty;

     

    else

     

    return string.Empty;

    }

    #endregion

    }

    }

     
  • alexei 21 posts 40 karma points
    Nov 24, 2009 @ 22:33
    alexei
    0

    O! sorry for formating

  • Tizer 170 posts 201 karma points
    Mar 27, 2012 @ 07:38
    Tizer
    0

    Which file is this supposed to replace? (if any :))

    If I knew that I may be able to reformat it, but at the moment I am clueless

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies