Copied to clipboard

Flag this post as spam?

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


  • Garret 69 posts 309 karma points
    Dec 16, 2012 @ 15:45
    Garret
    0

    Made some changes to get truncatedFolderUrl working in 4.11.1

    Probably could use a lot of improvement:) But started working with Autofolders for a blog-type kind of functionality and found out that the current version of Autofolders isn't working as expected any more:( Besides that i really like the idea and approach.

    But I started working on the 2.0.3 source code from http://autofolders.codeplex.com/

    Challenge 1: NiceUrl()

    The Niceurl() of autofolders function looks if truncatedFolderUrl is provided on FolderProvider Level, but the Autofoldersettings looks for it at AutoFolder Level. Nice would be if FolderProvider knew what AutoFolders invoked the call. But for now quick fix, pass along a boolean doTruncateFolders to the NiceUrl function in XsltExtensionLibrary

    Changes in BaseFolderProvider.cs:

           public virtual string NiceUrl(string realUrl)
            {
                return NiceUrl(realUrl, false);
            }
    
            public virtual string NiceUrl(string realUrl, bool doTruncatedFolder)
            {
    
                if (doTruncatedFolder)
                {
                    int additionFolders = this.CreatedFolderDepth;
                    List<string> urlParts = new List<string>(realUrl.Split('/'));
                    if (urlParts.Count > (additionFolders + 1))
                    {
                        while (additionFolders > 0)
                        {
                            urlParts.RemoveAt(urlParts.Count - 2);
                            additionFolders--;
                        }
                    }
                    string truncatedUrl = "";
    
                    foreach (string part in urlParts)
                    {
                        if (truncatedUrl.Length > 0)
                            truncatedUrl += "/";
    
                        truncatedUrl += part;
                    }
    
                    return "/" + truncatedUrl;
                }
                else
                {
                    return realUrl;
                }
            }

    change to IFolderProvider

            string NiceUrl(string url);
            string NiceUrl(string url, bool truncatedFolderUrl);

    change to XsltExtensionLibrary.cs

                if (autoFolderSetting != null)
                {
                    //property TruncatedFolderUrl of FolderProvider isn't set anywhere, but isn't used either so call to function with a boolean to truncate url
                    if(!String.IsNullOrEmpty(autoFolderSetting.TruncatedFolderUrl))
                        return autoFolderSetting.FolderProvider.NiceUrl(umbraco.library.NiceUrl(pageId), true);
                    else
                        return autoFolderSetting.FolderProvider.NiceUrl(umbraco.library.NiceUrl(pageId), false);
                }

    Challenge 2 : NotFoundHandler for the internal redirect

    This is in no way backwards compatible and can only be used for 4.11.1.

    Changes in NotFoundHandler.cs

    1. Get the type of the node
    2. Add functionality to tell NiceUrl() to truncate the url

            public static string NiceUrl(int pageId)
            {
                AutoFolderSetting autoFolderSetting = null;
    
                XPathNodeIterator pageNode = umbraco.library.GetXmlNodeById(pageId.ToString());
                if (pageNode != null)
                {
                    //string docType = pageNode.Current.GetAttribute("nodeTypeAlias", "");
                    //changed becasue .GetAttribute("nodeTypeAlias", ""); returns null
                    string docType = pageNode.Current.LocalName;
    
                    autoFolderSetting = AutoFolderSettings.Instance.GetSettings(docType);
                }
    
                if (autoFolderSetting != null)
                {
                    //property TruncatedFolderUrl of FolderProvider isn't set anywhere, but isn't used either so call to function with a boolean to truncate url
                    if(!String.IsNullOrEmpty(autoFolderSetting.TruncatedFolderUrl))
                        return autoFolderSetting.FolderProvider.NiceUrl(umbraco.library.NiceUrl(pageId), true);
                    else
                        return autoFolderSetting.FolderProvider.NiceUrl(umbraco.library.NiceUrl(pageId), false);
                }
                else
                {
                    return umbraco.library.NiceUrl(pageId);
                }
            }
  • Garret 69 posts 309 karma points
    Dec 16, 2012 @ 15:59
    Garret
    0

    Challenge 1: NiceUrl()

    The Niceurl() of autofolders function looks if truncatedFolderUrl is provided on FolderProvider Level, but the Autofoldersettings looks for it at AutoFolder Level. Nice would be if FolderProvider knew what AutoFolders invoked the call. But for now quick fix, pass along a boolean doTruncateFolders to the NiceUrl function in XsltExtensionLibrary

    Changes in BaseFolderProvider.cs:

           public virtual string NiceUrl(string realUrl)
            {
                return NiceUrl(realUrl, false);
            }
    
            public virtual string NiceUrl(string realUrl, bool doTruncatedFolder)
            {
    
                if (doTruncatedFolder)
                {
                    int additionFolders = this.CreatedFolderDepth;
                    List<string> urlParts = new List<string>(realUrl.Split('/'));
                    if (urlParts.Count > (additionFolders + 1))
                    {
                        while (additionFolders > 0)
                        {
                            urlParts.RemoveAt(urlParts.Count - 2);
                            additionFolders--;
                        }
                    }
                    string truncatedUrl = "";
    
                    foreach (string part in urlParts)
                    {
                        if (truncatedUrl.Length > 0)
                            truncatedUrl += "/";
    
                        truncatedUrl += part;
                    }
    
                    return "/" + truncatedUrl;
                }
                else
                {
                    return realUrl;
                }
            }

    change to IFolderProvider.cs

            string NiceUrl(string url);
            string NiceUrl(string url, bool truncatedFolderUrl);

    change to XsltExtensionLibrary.cs

    1. Get the type of the node
    2. Add functionality to tell NiceUrl() to truncate the url

            public static string NiceUrl(int pageId)
            {
                AutoFolderSetting autoFolderSetting = null;
    
                XPathNodeIterator pageNode = umbraco.library.GetXmlNodeById(pageId.ToString());
                if (pageNode != null)
                {
                    //string docType = pageNode.Current.GetAttribute("nodeTypeAlias", "");
                    //changed becasue .GetAttribute("nodeTypeAlias", ""); returns null
                    string docType = pageNode.Current.LocalName;
    
                    autoFolderSetting = AutoFolderSettings.Instance.GetSettings(docType);
                }
    
                if (autoFolderSetting != null)
                {
                    //property TruncatedFolderUrl of FolderProvider isn't set anywhere, but isn't used either so call to function with a boolean to truncate url
                    if(!String.IsNullOrEmpty(autoFolderSetting.TruncatedFolderUrl))
                        return autoFolderSetting.FolderProvider.NiceUrl(umbraco.library.NiceUrl(pageId), true);
                    else
                        return autoFolderSetting.FolderProvider.NiceUrl(umbraco.library.NiceUrl(pageId), false);
                }
                else
                {
                    return umbraco.library.NiceUrl(pageId);
                }
            }

    Challenge 2 : NotFoundHandler for the internal redirect

    This is in no way backwards compatible and can only be used for 4.11.1.

    Changes in NotFoundHandler.cs. Mainly the way of getting getting the correct node

    if (folderProvider != null)
    {
    
        //old
        //string parentUrlXPath = requestHandler.CreateXPathQuery(theParentUrl, true);
        //XmlNode parentNode = content.Instance.XmlContent.SelectSingleNode(parentUrlXPath);
        //new
        Node parentNode = uQuery.GetNodeByUrl(theParentUrl);
    
        if (parentNode != null)
        {
            //old
            //XmlNode redir = content.Instance.XmlContent.SelectSingleNode("//node[@id='" + parentNode.Attributes.GetNamedItem("id").Value + "']//node [@urlName = '" + pageUrl.Replace(".aspx", string.Empty).ToLower() + "']");
            //new
            Node redir = parentNode.GetDescendantNodes().First(n => n.UrlName == pageUrl);
    
            if (redir != null)
            {
                //old
                //m_redirectID = int.Parse(redir.Attributes.GetNamedItem("id").Value);
                //new
                m_redirectID = redir.Id;
    
                m_success = true;
            }
        }
    }

     

    Maybe this can be of help!

     

     

     

     

Please Sign in or register to post replies

Write your reply to:

Draft