internal static bool MakeArchiveUrl(NewsArticlesFriendlyUrlProvider provider, Match archiveUrlMatch, Regex archiveUrlRegex, string friendlyUrlPath, DotNetNuke.Entities.Tabs.TabInfo tab, FriendlyUrlOptions options, TabUrlOptions urlOptions, string cultureCode, ref string endingPageName, ref bool useDnnPagePath, ref List <string> messages, out string archiveUrl) { archiveUrl = friendlyUrlPath; bool result = false; Group mthGrp = archiveUrlMatch.Groups["mth"]; Group yrGrp = archiveUrlMatch.Groups["yr"]; bool month = false, year = false; string mm = null, yyyy = null; string path = null; if (mthGrp != null && mthGrp.Success) { //contains a month month = true; mm = archiveUrlMatch.Groups["mm"].Value; } if (yrGrp != null && yrGrp.Success) { year = true; yyyy = archiveUrlMatch.Groups["yyyy"].Value; } if (year) { path = "/" + yyyy; } if (month) { path += "/" + mm; } if (path != null) //got a valid path { //have a valid url replacement for this url. So replace the matched part of the path with the friendly url if (archiveUrlMatch.Groups["l"].Success) //if the path had a leading /, then make sure to add that onto the replacement { path = provider.EnsureLeadingChar("/", path); } /* finish it all off */ messages.Add("Item Friendly Url Replacing Archive Url : " + friendlyUrlPath + " with Path : " + path); //this is the point where the Url is modified! //replace the path in the path - which leaves any other parts of a path intact. archiveUrl = archiveUrlRegex.Replace(friendlyUrlPath, path);//replace the part in the friendly Url path with it's replacement. //check if this tab is the one specified to not use a path if (provider.NoDnnPagePathTabId == tab.TabID) { useDnnPagePath = false;//make this Url relative from the site root } //set back to default.aspx so that Url Master removes it - just in case it wasn't standard endingPageName = DotNetNuke.Common.Globals.glbDefaultPage; //return success result = true; } return(result); }
internal static bool MakeCategoryUrl(NewsArticlesFriendlyUrlProvider provider, Match categoryUrlMatch, Regex categoryUrlRegex, string friendlyUrlPath, DotNetNuke.Entities.Tabs.TabInfo tab, FriendlyUrlOptions options, TabUrlOptions urlOptions, string cultureCode, ref string endingPageName, ref bool useDnnPagePath, ref List <string> messages, out string categoryUrl) { bool result = false; categoryUrl = null; //this is a url that looks like an category url. We want to modify it and create the new one. string rawId = categoryUrlMatch.Groups["catid"].Value; int categoryId = 0; if (int.TryParse(rawId, out categoryId)) { Hashtable friendlyUrlIndex = null; //the friendly url index is the lookup we use //we have obtained the item Id out of the Url //get the friendlyUrlIndex (it comes from the database via the cache) friendlyUrlIndex = UrlController.GetFriendlyUrlIndex(tab.TabID, tab.PortalID, provider, options, urlOptions); if (friendlyUrlIndex != null) { //item urls are indexed with a + category id ("c5") - this is so authors/articles/categories can be mixed and matched string furlkey = "c" + categoryId.ToString(); //create the lookup key for the friendly url index string path = (string)friendlyUrlIndex[furlkey]; //check if in the index if (path == null) { //don't normally expect to have a no-match with a friendly url path when an categoryId was in the Url. //could be a new item that has been created and isn't in the index //do a direct call and find out if it's there //path = UrlController.CheckForMissingNewscategoryItem(categoryId, "category", tab.TabID, tab.PortalID, provider, options, urlOptions, ref messages); } if (path != null) //got a valid path { //url found in the index for this entry. So replace the matched part of the path with the friendly url if (categoryUrlMatch.Groups["l"].Success) //if the path had a leading /, then make sure to add that onto the replacement { path = provider.EnsureLeadingChar("/", path); } /* finish it all off */ messages.Add("Item Friendly Url Replacing : " + friendlyUrlPath + " in Path : " + path); //this is the point where the Url is modified! //replace the path in the path - which leaves any other parts of a path intact. categoryUrl = categoryUrlRegex.Replace(friendlyUrlPath, path);//replace the part in the friendly Url path with it's replacement. //check if this tab is the one specified to not use a path if (provider.NoDnnPagePathTabId == tab.TabID) { useDnnPagePath = false;//make this Url relative from the site root } //set back to default.aspx so that Url Master removes it - just in case it wasn't standard endingPageName = DotNetNuke.Common.Globals.glbDefaultPage; result = true; } } } return(result); }
/// <summary> /// Creates a friendly article url, depending on the options /// </summary> /// <param name="provider"></param> /// <param name="articleUrlMatch"></param> /// <param name="articleUrlRegex"></param> /// <param name="friendlyUrlPath"></param> /// <param name="tab"></param> /// <param name="options"></param> /// <param name="urlOptions"></param> /// <param name="cultureCode"></param> /// <param name="endingPageName"></param> /// <param name="useDnnPagePath"></param> /// <param name="messages"></param> /// <param name="articleUrl"></param> /// <returns></returns> internal static bool MakeArticleUrl(NewsArticlesFriendlyUrlProvider provider, Match articleUrlMatch, Regex articleUrlRegex, string friendlyUrlPath, DotNetNuke.Entities.Tabs.TabInfo tab, FriendlyUrlOptions options, TabUrlOptions urlOptions, string cultureCode, ref string endingPageName, ref bool useDnnPagePath, ref List <string> messages, out string articleUrl) { bool result = false; articleUrl = null; //this is a url that looks like an article url. We want to modify it and create the new one. string rawId = articleUrlMatch.Groups["artid"].Value; int articleId = 0; if (int.TryParse(rawId, out articleId) && (provider.StartingArticleId <= articleId)) { Hashtable friendlyUrlIndex = null; //the friendly url index is the lookup we use //we have obtained the item Id out of the Url //get the friendlyUrlIndex (it comes from the database via the cache) friendlyUrlIndex = UrlController.GetFriendlyUrlIndex(tab.TabID, tab.PortalID, provider, options, urlOptions); if (friendlyUrlIndex != null) { string furlkey = null; int pageId = -1; //first check if we are seeking page or article if (articleUrlMatch.Groups["pageid"].Success) { //page item urls are index by p + page id. But we only use this if it is present //ie pages override articles when both are present string rawPageId = articleUrlMatch.Groups["pageid"].Value; if (int.TryParse(rawPageId, out pageId)) { furlkey = "p" + rawPageId; } } else { //item urls are indexed with a + articleId ("a5") - this is so we could mix and match entities if necessary furlkey = "a" + articleId.ToString(); //create the lookup key for the friendly url index } string path = (string)friendlyUrlIndex[furlkey]; //check if in the index if (path == null) { //don't normally expect to have a no-match with a friendly url path when an articleId was in the Url. //could be that the page id is bunk - in that case, just use the article Id if (furlkey.Contains("p")) { furlkey = "a" + articleId.ToString(); //create the lookup key for the friendly url index path = (string)friendlyUrlIndex[furlkey]; //check if in the index } if (path == null) { //could be a new item that has been created and isn't in the index //do a direct call and find out if it's there path = UrlController.CheckForMissingNewsArticleItem(articleId, "article", tab.TabID, tab.PortalID, provider, options, urlOptions, ref messages); } } if (path != null) //got a valid path { //url found in the index for this entry. So replace the matched part of the path with the friendly url if (articleUrlMatch.Groups["l"].Success) //if the path had a leading /, then make sure to add that onto the replacement { path = provider.EnsureLeadingChar("/", path); } /* finish it all off */ messages.Add("Item Friendly Url Replacing : " + friendlyUrlPath + " in Path : " + path); //this is the point where the Url is modified! //replace the path in the path - which leaves any other parts of a path intact. articleUrl = articleUrlRegex.Replace(friendlyUrlPath, path);//replace the part in the friendly Url path with it's replacement. //check if this tab is the one specified to not use a path if (provider.NoDnnPagePathTabId == tab.TabID) { useDnnPagePath = false;//make this Url relative from the site root } //set back to default.aspx so that Url Master removes it - just in case it wasn't standard endingPageName = DotNetNuke.Common.Globals.glbDefaultPage; result = true; } } } return(result); }