Exemplo n.º 1
0
        /// <summary>
        /// Checks for, and adds to the indexes, a missing item.
        /// </summary>
        /// <param name="itemId"></param>
        /// <param name="tabId"></param>
        /// <param name="portalId"></param>
        /// <param name="provider"></param>
        /// <param name="options"></param>
        /// <param name="messages"></param>
        /// <returns>Valid path if found</returns>
        internal static string CheckForMissingItemId(int itemId, string itemType, int portalId, SocialUrlProvider provider, FriendlyUrlOptions options, ref List <string> messages)
        {
            string          path        = null;
            FriendlyUrlInfo friendlyUrl = null;

            messages.Add("Item not found Id : " + itemId.ToString() + ", Type : " + itemType + " Checking Item directly");
            Data.DataProvider.Instance().GetSocialUrl(portalId, itemId, itemType, out friendlyUrl);
            if (friendlyUrl != null)
            {
                messages.Add("itemId found : " + itemId.ToString() + " , Type : " + itemType + " - Rebuilding indexes");
                //call and get the path
                path = UrlController.MakeItemFriendlyUrl(friendlyUrl, provider, options);
                //so this entry did exist but wasn't in the index.  Rebuild the index
                UrlController.RebuildIndexes(portalId, provider, options);
            }
            return(path);
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
        public override string TransformFriendlyUrlToQueryString(string[] urlParms, int tabId, int portalId, FriendlyUrlOptions options, string cultureCode,
                                                                 PortalAliasInfo portalAlias, ref List <string> messages, out int status, out string location)
        {
            //initialise results and output variables
            string result = ""; status = 200; //OK

            location = null;                  //no redirect location
            if (messages == null)
            {
                messages = new List <string>();
            }

            Hashtable queryStringIndex = null;
            string    path             = string.Join("/", urlParms);
            bool      found            = false;
            bool      siteRootMatch    = false;

            if (string.IsNullOrEmpty(path) == false && Regex.IsMatch(path, @"(^|/)(mid|moduleId)/\d+/?", RegexOptions.IgnoreCase) == false)
            {
                if (urlParms.Length > 0)
                {
                    //tabid == -1 when no dnn page path is in the Url.  This means the DNN url rewriter can't determine the DNN page based on the Url.
                    //In this case, it is up to this provider to identify the correct tabId that matches the Url.  Failure to do so will result in the incorrect tab being loaded when the page is rendered.
                    if (tabId == -1)
                    {
                        siteRootMatch = true;
                    }
                    queryStringIndex = UrlController.GetQueryStringIndex(portalId, this, options, false);
                    List <string> keepParms = new List <string>();
                    //iterate backwards through the collection of params
                    string lookupPath = path;
                    if (string.IsNullOrEmpty(UrlPath) == false && lookupPath.StartsWith(UrlPath))
                    {
                        lookupPath = lookupPath.Substring(UrlPath.Length);
                    }

                    for (int i = urlParms.GetUpperBound(0); i >= 0; i--)
                    {
                        //check for existence of this value in the querystring index
                        string urlParm = urlParms[i];
                        string qsKey   = lookupPath.ToLower();
                        string qs      = (string)queryStringIndex[qsKey];
                        if (qs != null)
                        {
                            //found a querystring match
                            found = true;
                            messages.Add("Item Matched in Friendly Url Provider.  Url : " + lookupPath + " Path : " + path);
                            result += qs;
                            break;
                        }
                        else
                        {
                            if (string.IsNullOrEmpty(urlParm) == false)
                            {
                                //not found - remove last url parm from lookup path
                                if (lookupPath.Length <= urlParm.Length)
                                {
                                    lookupPath = "";
                                }
                                else
                                {
                                    lookupPath = lookupPath.Remove(lookupPath.Length - (urlParm.Length + 1));
                                }
                                keepParms.Insert(0, urlParm);//add from front always
                            }
                        }
                    }
                    if (found)
                    {
                        //put on any remainder of the path that wasn't to do with the friendly Url
                        string remainder = base.CreateQueryStringFromParameters(keepParms.ToArray(), -1);
                        //put it all together for the final rewrite string
                        result += remainder;
                    }
                }
            }
            return(result);
        }