public override string ChangeFriendlyUrl(TabInfo tab, string friendlyUrlPath, FriendlyUrlOptions options, string cultureCode, ref string endingPageName, out bool useDnnPagePath, ref List <string> messages) { //set default values for out parameters useDnnPagePath = true; if (messages == null) { messages = new List <string>(); } //check if we want to try and modify this Url //first check to see if this Url is an 'edit' Url - something that loads a module-specific page. //we don't want to mess with these, because they're always permissions based Urls and thus //no need to be friendly if (string.IsNullOrEmpty(friendlyUrlPath) == false && Regex.IsMatch(friendlyUrlPath, @"(^|/)(mid|moduleId)/\d+/?", RegexOptions.IgnoreCase) == false) { Hashtable friendlyUrlIndex = null; //the friendly url index is the lookup we use //try and match incoming friendly url path to what we would expect from the module Regex groupUrlRegex = new Regex(@"(?<l>/)?groupid/(?<groupid>\d+)", RegexOptions.IgnoreCase); Match groupUrlMatch = groupUrlRegex.Match(friendlyUrlPath); if (groupUrlMatch.Success) { //this is a group Url we want to try and modify string rawId = groupUrlMatch.Groups["groupid"].Value; int groupId = 0; if (int.TryParse(rawId, out groupId)) { //we have obtained the groupId out of the Url //get the friendlyUrlIndex (it comes from the database via the cache) friendlyUrlIndex = UrlController.GetFriendlyUrlIndex(tab.PortalID, this, options); if (friendlyUrlIndex != null) { //item urls are indexed with i + itemId ("i5") - this is so we could mix and match entities if necessary string furlkey = FriendlyUrlInfo.MakeKey("group", groupId); //create the lookup key for the friendly url index string path = null; //check for a child pages / group ID in the index first if (GroupPagePathTabId > -1 && tab.ParentId == GroupPagePathTabId) { string cpFurlKey = "t" + tab.TabID.ToString() + furlkey; path = (string)friendlyUrlIndex[cpFurlKey]; //check if in the index for a child page } if (path == null) //now check for a match in the index { 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 itemId 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.CheckForMissingItemId(groupId, "group", tab.PortalID, this, options, 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 (groupUrlMatch.Groups["l"].Success) //if the path had a leading /, then make sure to add that onto the replacement { path = base.EnsureLeadingChar("/", path); } /* finish it all off */ messages.Add("Group 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. friendlyUrlPath = groupUrlRegex.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 ((GroupPagePathTabId == tab.TabID || GroupPagePathTabId == tab.ParentId) && HideGroupPagePath) { useDnnPagePath = false;//make this Url relative from the site root } //set back to default.aspx so that DNN Url Rewriter removes it - just in case it wasn't standard endingPageName = DotNetNuke.Common.Globals.glbDefaultPage; } } } } } return(friendlyUrlPath); }
public override bool CheckForRedirect(int tabId, int portalid, string httpAlias, Uri requestUri, NameValueCollection queryStringCol, FriendlyUrlOptions options, out string redirectLocation, ref List <string> messages) { bool doRedirect = false; redirectLocation = "";//set blank location //compare to known pattern of old Urls string path = requestUri.AbsoluteUri; if (string.IsNullOrEmpty(path) == false && Regex.IsMatch(path, @"(^|/)(mid|moduleId)/\d+/?", RegexOptions.IgnoreCase) == false) { //could be in old /groupId/xx format - if so, we want to redirect it Regex pathRegex = new Regex(@"/groupid/(?<groupid>\d+)", RegexOptions.IgnoreCase); Match pathMatch = pathRegex.Match(path); if (pathMatch.Success) { string groupIdRaw = pathMatch.Groups["groupid"].Value; int groupId; if (int.TryParse(groupIdRaw, out groupId)) { //ok, valid item Id found //get the valid Url for this item Hashtable friendlyUrlIndex = UrlController.GetFriendlyUrlIndex(portalid, this, options); //look up the friendly url index using the item key string furlKey = FriendlyUrlInfo.MakeKey("group", groupId); if (friendlyUrlIndex != null) { string friendlyUrl = null; TabController tc = new TabController(); TabInfo tab = tc.GetTab(tabId, portalid, false); if (tab != null && tab.ParentId == GroupPagePathTabId) { //this is the child tab of the group tab string cpFurlKey = "t" + tabId.ToString() + furlKey; friendlyUrl = (string)friendlyUrlIndex[cpFurlKey]; } if (friendlyUrl == null) { friendlyUrl = (string)friendlyUrlIndex[furlKey]; } if (friendlyUrl != null) { //ok, we're going to replace this in the Url if (HideGroupPagePath == false) { friendlyUrl = base.EnsureLeadingChar("/", friendlyUrl); string result = pathRegex.Replace(path, friendlyUrl); doRedirect = true; redirectLocation = result; } else { DotNetNuke.Entities.Portals.PortalAliasInfo pa = DotNetNuke.Entities.Portals.PortalAliasController.GetPortalAliasInfo(httpAlias); if (pa != null) { DotNetNuke.Entities.Portals.PortalSettings ps = new DotNetNuke.Entities.Portals.PortalSettings(tabId, pa); redirectLocation = DotNetNuke.Common.Globals.NavigateURL(tabId, ps, "", "groupid=" + groupId); doRedirect = true; } } } } } } } return(doRedirect); }