示例#1
0
        public void Simple_URL_Parameter_Parser_Test()
        {
            var parser = new SimpleURLParameterParser("g=forum&t=1&url=&pg=43#cool");

            Assert.AreEqual(true, parser.HasAnchor, "Url should have an Anchor");
            Assert.AreEqual("cool", parser.Anchor, "The Url should be called : cool");
            Assert.AreEqual("forum", parser.Parameters["g"], "The Parameter g should equals forum");
            Assert.AreEqual(
                "url=&pg=43",
                parser.CreateQueryString(new[] { "g", "t" }),
                "The Parameter g should equals forum");
            Assert.AreEqual("43", parser.Parameters[3], "The Parameter Index 3 should be 43");
        }
示例#2
0
        /// <summary>
        /// Gets the page URL.
        /// </summary>
        /// <param name="page">The page.</param>
        /// <returns>
        /// The get page url.
        /// </returns>
        protected string GetPageURL(int page)
        {
            string url;

            // create proper query string...
            var parser = new SimpleURLParameterParser(this.Get <HttpRequestBase>().QueryString.ToString());

            // get the current page
            var currentPage = (ForumPages)Enum.Parse(typeof(ForumPages), parser["g"], true);

            if (parser["m"] != null)
            {
                // must be converted to by topic...
                parser.Parameters.Remove("m");
                parser.Parameters.Add("t", YafContext.Current.PageTopicID.ToString());
            }

            if (page > 1)
            {
                string tmp = parser.CreateQueryString(new[] { "g", "p", "tabid", "find" });
                if (tmp.Length > 0)
                {
                    tmp += "&";
                }

                tmp += "p={0}";

                url = YafBuildLink.GetLink(currentPage, tmp, page);
            }
            else
            {
                url = YafBuildLink.GetLink(currentPage, parser.CreateQueryString(new[] { "g", "p", "tabid", "find" }));
            }

            return(url);
        }
        /// <summary>
        /// Build the url.
        /// </summary>
        /// <param name="url">
        /// The url.
        /// </param>
        /// <returns>
        /// Returns the URL.
        /// </returns>
        public override string BuildUrl(string url)
        {
            var newUrl = $"{AppPath}{Config.ForceScriptName ?? ScriptName}?{url}";

            // create scriptName
            var scriptName = $"{AppPath}{Config.ForceScriptName ?? ScriptName}";

            // get the base script file from the config -- defaults to, well, default.aspx :)
            var scriptFile = Config.BaseScriptFile;

            if (url.IsNotSet())
            {
                return(newUrl);
            }

            const string gsr = "getsearchresults";

            scriptName = scriptName.Replace(gsr, scriptFile);
            newUrl     = newUrl.Replace(gsr, scriptFile);

            if (scriptName.EndsWith(scriptFile))
            {
                var before = scriptName.Remove(scriptName.LastIndexOf(scriptFile, StringComparison.Ordinal));

                var parser = new SimpleURLParameterParser(url);

                // create "rewritten" url...
                newUrl = before;

                var useKey         = string.Empty;
                var description    = string.Empty;
                var pageName       = parser["g"];
                var forumPage      = ForumPages.forum;
                var getDescription = false;

                var isFeed     = false;
                var handlePage = false;

                if (pageName.IsSet())
                {
                    try
                    {
                        forumPage      = pageName.ToEnum <ForumPages>();
                        getDescription = true;
                    }
                    catch (Exception)
                    {
                        getDescription = false;
                    }
                }

                if (getDescription)
                {
                    switch (forumPage)
                    {
                    case ForumPages.topics:
                        useKey    = "f";
                        pageName += "/";

                        // description = UrlRewriteHelper.GetForumName(parser[useKey].ToType<int>());
                        description =
                            UrlRewriteHelper.CleanStringForURL(
                                parser["name"].IsSet()
                                        ? parser["name"]
                                        : UrlRewriteHelper.GetForumName(parser[useKey].ToType <int>()));
                        handlePage = true;
                        break;

                    case ForumPages.Posts:
                        pageName += "/";
                        if (parser["t"].IsSet())
                        {
                            useKey      = "t";
                            pageName   += "t";
                            description = UrlRewriteHelper.GetTopicName(parser[useKey].ToType <int>());
                        }
                        else if (parser["m"].IsSet())
                        {
                            useKey    = "m";
                            pageName += "m";

                            try
                            {
                                description = UrlRewriteHelper.GetTopicNameFromMessage(parser[useKey].ToType <int>());
                            }
                            catch (Exception)
                            {
                                description = "posts";
                            }
                        }

                        handlePage = true;
                        break;

                    case ForumPages.Profile:
                        useKey      = "u";
                        pageName   += "/";
                        description =
                            UrlRewriteHelper.CleanStringForURL(
                                parser["name"].IsSet()
                                        ? parser["name"]
                                        : UrlRewriteHelper.GetProfileName(parser[useKey].ToType <int>()));

                        parser.Parameters.Remove("name");
                        break;

                    case ForumPages.forum:
                        pageName = "category/";
                        if (parser["c"].IsSet())
                        {
                            useKey      = "c";
                            description = UrlRewriteHelper.GetCategoryName(parser[useKey].ToType <int>());
                        }
                        else
                        {
                            pageName = string.Empty;
                        }

                        break;

                    case ForumPages.RssTopic:
                        pageName += "/";

                        if (parser["pg"].IsSet())
                        {
                            description = parser["pg"].ToEnum <YafRssFeeds>().ToString().ToLower();
                        }

                        if (parser["f"].IsSet())
                        {
                            description += $"_{UrlRewriteHelper.GetForumName(parser["f"].ToType<int>())}";
                        }

                        if (parser["t"].IsSet())
                        {
                            description += $"_{UrlRewriteHelper.GetTopicName(parser["t"].ToType<int>())}";
                        }

                        if (parser["c"].IsSet())
                        {
                            description += $"_{UrlRewriteHelper.GetCategoryName(parser["c"].ToType<int>())}";
                        }

                        if (parser["ft"].IsSet())
                        {
                            description += parser["ft"].ToType <int>() == YafSyndicationFormats.Atom.ToInt()
                                                   ? "-atom"
                                                   : "-rss";
                        }

                        handlePage = true;
                        isFeed     = true;
                        break;
                    }
                }

                // special handling for admin pages
                if (parser["g"].StartsWith("admin_"))
                {
                    pageName = parser["g"].Replace("_", "/");
                }

                newUrl += pageName;

                if (useKey.Length > 0)
                {
                    newUrl += parser[useKey];
                }

                // handle pager links
                if (handlePage && parser["p"] != null && !isFeed)
                {
                    var page = parser["p"].ToType <int>();

                    if (page != 1)
                    {
                        description += $"/page{page}";
                    }

                    parser.Parameters.Remove("p");
                }

                if (isFeed)
                {
                    if (parser["ft"] != null)
                    {
                        var page = parser["ft"].ToType <int>();
                        newUrl += $"ft{page}";
                        parser.Parameters.Remove("ft");
                    }

                    if (parser["f"] != null)
                    {
                        var page = parser["f"].ToType <int>();
                        newUrl += $"f{page}";
                        parser.Parameters.Remove("f");
                    }

                    if (parser["t"] != null)
                    {
                        var page = parser["t"].ToType <int>();
                        newUrl += $"t{page}";
                        parser.Parameters.Remove("t");
                    }
                }

                if (parser["find"] != null)
                {
                    newUrl += $"find{parser["find"].Trim()}";
                    parser.Parameters.Remove("find");
                }

                if (description.Length > 0)
                {
                    if (description.EndsWith("-"))
                    {
                        description = description.Remove(description.Length - 1, 1);
                    }

                    newUrl += $"-{description}";
                }

                var restUrl = parser.CreateQueryString(new[] { "g", useKey, "name" });

                // append to the url if there are additional (unsupported) parameters
                if (restUrl.Length > 0)
                {
                    newUrl += $"?{restUrl}";
                }

                if (newUrl.EndsWith("/forum"))
                {
                    // remove in favor of just slash...
                    newUrl = newUrl.Remove(newUrl.LastIndexOf("/forum", StringComparison.Ordinal), "/forum".Length);
                }

                // add anchor
                if (parser.HasAnchor)
                {
                    newUrl += $"#{parser.Anchor}";
                }
            }

            // just make sure & is &amp; ...
            newUrl = newUrl.Replace("&amp;", "&").Replace("&", "&amp;");

            return(newUrl);
        }
示例#4
0
        /// <summary>
        /// Build the url.
        /// </summary>
        /// <param name="url">The url.</param>
        /// <returns>
        /// The build url.
        /// </returns>
        public override string BuildUrl(string url)
        {
            string newUrl = "{0}{1}?{2}".FormatWith(AppPath, Config.ForceScriptName ?? ScriptName, url);

            // create scriptName
            string scriptName = "{0}{1}".FormatWith(AppPath, Config.ForceScriptName ?? ScriptName);

            // get the base script file from the config -- defaults to, well, default.aspx :)
            string scriptFile = Config.BaseScriptFile;

            if (scriptName.EndsWith(scriptFile))
            {
                string before = scriptName.Remove(scriptName.LastIndexOf(scriptFile, StringComparison.Ordinal));

                var parser = new SimpleURLParameterParser(url);

                // create "rewritten" url...
                newUrl = before + Config.UrlRewritingPrefix;

                string useKey      = string.Empty;
                string useKey2     = string.Empty;
                string description = string.Empty;
                string pageName    = parser["g"];
                bool   isFeed      = false;
                //// const bool showKey = false;
                bool handlePage = false;

                switch (parser["g"])
                {
                case "topics":
                    useKey      = "f";
                    description = this.GetForumName(parser[useKey].ToType <int>());
                    handlePage  = true;
                    break;

                case "posts":
                    if (parser["t"].IsSet())
                    {
                        useKey      = "t";
                        pageName   += "t";
                        description = this.GetTopicName(parser[useKey].ToType <int>());
                    }
                    else if (parser["m"].IsSet())
                    {
                        useKey    = "m";
                        pageName += "m";

                        try
                        {
                            description = this.GetTopicNameFromMessage(parser[useKey].ToType <int>());
                        }
                        catch (Exception)
                        {
                            description = "posts";
                        }
                    }

                    handlePage = true;
                    break;

                case "profile":
                    useKey = "u";

                    // description = GetProfileName( Convert.ToInt32( parser [useKey] ) );
                    break;

                case "forum":
                    if (parser["c"].IsSet())
                    {
                        useKey      = "c";
                        description = this.GetCategoryName(parser[useKey].ToType <int>());
                    }

                    break;

                case "rsstopic":
                    if (parser["pg"].IsSet())
                    {
                        useKey      = "pg";
                        description = parser[useKey].ToEnum <YafRssFeeds>().ToString().ToLower();
                    }

                    if (parser["f"].IsSet())
                    {
                        useKey2      = "f";
                        description += this.GetForumName(parser[useKey2].ToType <int>());
                    }

                    if (parser["t"].IsSet())
                    {
                        useKey2      = "t";
                        description += this.GetTopicName(parser[useKey2].ToType <int>());
                    }

                    if (parser["ft"].IsSet())
                    {
                        useKey2 = "ft";

                        if (parser[useKey2].ToType <int>() == YafSyndicationFormats.Atom.ToInt())
                        {
                            description += "-atom";
                        }
                        else
                        {
                            description += "-rss";
                        }
                    }

                    handlePage = true;
                    isFeed     = true;
                    break;
                }

                newUrl += pageName;

                if (useKey.Length > 0)
                {
                    newUrl += parser[useKey];
                }

                if (handlePage && parser["p"] != null && !isFeed)
                {
                    int page = parser["p"].ToType <int>();
                    if (page != 1)
                    {
                        newUrl += "p{0}".FormatWith(page);
                    }

                    parser.Parameters.Remove("p");
                }

                if (isFeed)
                {
                    if (parser["ft"] != null)
                    {
                        int page = parser["ft"].ToType <int>();
                        newUrl += "ft{0}".FormatWith(page);
                        parser.Parameters.Remove("ft");
                    }

                    if (parser["f"] != null)
                    {
                        int page = parser["f"].ToType <int>();
                        newUrl += "f{0}".FormatWith(page);
                        parser.Parameters.Remove("f");
                    }

                    if (parser["t"] != null)
                    {
                        int page = parser["t"].ToType <int>();
                        newUrl += "t{0}".FormatWith(page);
                        parser.Parameters.Remove("t");
                    }
                }

                if (parser["find"] != null)
                {
                    newUrl += "find{0}".FormatWith(parser["find"].Trim());
                    parser.Parameters.Remove("find");
                }

                if (description.Length > 0)
                {
                    if (description.EndsWith("-"))
                    {
                        description = description.Remove(description.Length - 1, 1);
                    }

                    newUrl += "_{0}".FormatWith(description);
                }

                newUrl += ".aspx";

                /*  if (!isFeed)
                 * {
                 *   newUrl += ".aspx";
                 * }
                 * else
                 * {
                 *   newUrl += ".xml";
                 * } */

                string restURL = parser.CreateQueryString(new[] { "g", useKey });

                // append to the url if there are additional (unsupported) parameters
                if (restURL.Length > 0)
                {
                    newUrl += "?{0}".FormatWith(restURL);
                }

                // see if we can just use the default (/)
                if (newUrl.EndsWith("{0}forum.aspx".FormatWith(Config.UrlRewritingPrefix)))
                {
                    // remove in favor of just slash...
                    newUrl =
                        newUrl.Remove(
                            newUrl.LastIndexOf(
                                "{0}forum.aspx".FormatWith(Config.UrlRewritingPrefix), StringComparison.Ordinal),
                            "{0}forum.aspx".FormatWith(Config.UrlRewritingPrefix).Length);
                }

                // add anchor
                if (parser.HasAnchor)
                {
                    newUrl += "#{0}".FormatWith(parser.Anchor);
                }
            }

            // just make sure & is &amp; ...
            newUrl = newUrl.Replace("&amp;", "&").Replace("&", "&amp;");

            return(newUrl);
        }
示例#5
0
        /// <summary>
        /// Build the url.
        /// </summary>
        /// <param name="url">The url.</param>
        /// <returns>
        /// Returns the URL.
        /// </returns>
        public override string BuildUrl(string url)
        {
            string newUrl = "{0}{1}?{2}".FormatWith(AppPath, Config.ForceScriptName ?? ScriptName, url);

            // create scriptName
            string scriptName = "{0}{1}".FormatWith(AppPath, Config.ForceScriptName ?? ScriptName);

            // get the base script file from the config -- defaults to, well, default.aspx :)
            string scriptFile = Config.BaseScriptFile;

            if (url.IsNotSet())
            {
                return(newUrl);
            }

            if (scriptName.EndsWith(scriptFile))
            {
                string before = scriptName.Remove(scriptName.LastIndexOf(scriptFile, StringComparison.Ordinal));

                var parser = new SimpleURLParameterParser(url);

                // create "rewritten" url...
                newUrl = before;

                var useKey      = string.Empty;
                var description = string.Empty;
                var pageName    = parser["g"];

                bool isFeed     = false;
                bool handlePage = false;

                switch (pageName)
                {
                case "topics":
                    useKey      = "f";
                    pageName   += "/";
                    description = UrlRewriteHelper.GetForumName(parser[useKey].ToType <int>());
                    handlePage  = true;
                    break;

                case "posts":
                    pageName += "/";
                    if (parser["t"].IsSet())
                    {
                        useKey      = "t";
                        pageName   += "t";
                        description = UrlRewriteHelper.GetTopicName(parser[useKey].ToType <int>());
                    }
                    else if (parser["m"].IsSet())
                    {
                        useKey    = "m";
                        pageName += "m";

                        try
                        {
                            description = UrlRewriteHelper.GetTopicNameFromMessage(parser[useKey].ToType <int>());
                        }
                        catch (Exception)
                        {
                            description = "posts";
                        }
                    }

                    handlePage = true;
                    break;

                case "profile":
                    useKey      = "u";
                    pageName   += "/";
                    description = UrlRewriteHelper.GetProfileName(parser[useKey].ToType <int>());
                    break;

                case "forum":
                    pageName = "category/";
                    if (parser["c"].IsSet())
                    {
                        useKey      = "c";
                        description = UrlRewriteHelper.GetCategoryName(parser[useKey].ToType <int>());
                    }
                    else
                    {
                        pageName = string.Empty;
                    }

                    break;

                case "rsstopic":
                    pageName += "/";

                    if (parser["pg"].IsSet())
                    {
                        description = parser["pg"].ToEnum <YafRssFeeds>().ToString().ToLower();
                    }

                    if (parser["f"].IsSet())
                    {
                        description += "_{0}".FormatWith(UrlRewriteHelper.GetForumName(parser["f"].ToType <int>()));
                    }

                    if (parser["t"].IsSet())
                    {
                        description += "_{0}".FormatWith(UrlRewriteHelper.GetTopicName(parser["t"].ToType <int>()));
                    }

                    if (parser["c"].IsSet())
                    {
                        description += "_{0}".FormatWith(UrlRewriteHelper.GetCategoryName(parser["c"].ToType <int>()));
                    }

                    if (parser["ft"].IsSet())
                    {
                        description += parser["ft"].ToType <int>() == YafSyndicationFormats.Atom.ToInt()
                                               ? "-atom"
                                               : "-rss";
                    }

                    handlePage = true;
                    isFeed     = true;
                    break;
                }

                // special handling for admin pages
                if (parser["g"].StartsWith("admin_"))
                {
                    pageName = parser["g"].Replace("_", "/");
                }

                newUrl += pageName;

                if (useKey.Length > 0)
                {
                    newUrl += parser[useKey];
                }

                // handle pager linkse
                if (handlePage && parser["p"] != null && !isFeed)
                {
                    var page = parser["p"].ToType <int>();

                    if (page != 1)
                    {
                        description += "/page{0}".FormatWith(page);
                    }

                    parser.Parameters.Remove("p");
                }

                if (isFeed)
                {
                    if (parser["ft"] != null)
                    {
                        int page = parser["ft"].ToType <int>();
                        newUrl += "ft{0}".FormatWith(page);
                        parser.Parameters.Remove("ft");
                    }

                    if (parser["f"] != null)
                    {
                        int page = parser["f"].ToType <int>();
                        newUrl += "f{0}".FormatWith(page);
                        parser.Parameters.Remove("f");
                    }

                    if (parser["t"] != null)
                    {
                        int page = parser["t"].ToType <int>();
                        newUrl += "t{0}".FormatWith(page);
                        parser.Parameters.Remove("t");
                    }
                }

                if (parser["find"] != null)
                {
                    newUrl += "find{0}".FormatWith(parser["find"].Trim());
                    parser.Parameters.Remove("find");
                }

                if (description.Length > 0)
                {
                    if (description.EndsWith("-"))
                    {
                        description = description.Remove(description.Length - 1, 1);
                    }

                    newUrl += "-{0}".FormatWith(description);
                }

                var restURL = parser.CreateQueryString(new[] { "g", useKey });

                // append to the url if there are additional (unsupported) parameters
                if (restURL.Length > 0)
                {
                    newUrl += "?{0}".FormatWith(restURL);
                }

                if (newUrl.EndsWith("/forum"))
                {
                    // remove in favor of just slash...
                    newUrl =
                        newUrl.Remove(
                            newUrl.LastIndexOf(
                                "/forum", StringComparison.Ordinal),
                            "/forum".Length);
                }

                // add anchor
                if (parser.HasAnchor)
                {
                    newUrl += "#{0}".FormatWith(parser.Anchor);
                }
            }

            // just make sure & is &amp; ...
            newUrl = newUrl.Replace("&amp;", "&").Replace("&", "&amp;");

            return(newUrl);
        }
        /// <summary>
        /// Builds the URL complete.
        /// </summary>
        /// <param name="boardSettings">The board settings.</param>
        /// <param name="url">The URL.</param>
        /// <param name="fullUrl">if set to <c>true</c> [full URL].</param>
        /// <returns>
        /// The new URL.
        /// </returns>
        private string BuildUrlComplete(object boardSettings, string url, bool fullUrl)
        {
            var yafBoardSettings = boardSettings.ToType <YafBoardSettings>();

            var yafTab = new TabController().GetTab(yafBoardSettings.DNNPageTab, yafBoardSettings.DNNPortalId, true);

            var domainName = TestableGlobals.Instance.GetDomainName(HttpContext.Current.Request.Url);
            var aliasUrl   = PortalAliasController.GetPortalAliasByTab(yafBoardSettings.DNNPageTab, domainName);
            var alias      = PortalAliasController.Instance.GetPortalAlias(aliasUrl);

            var portalSettings = new PortalSettings(yafTab.PortalID, alias);

            if (portalSettings.ContentLocalizationEnabled)
            {
                yafTab = new TabController().GetTabByCulture(
                    yafBoardSettings.DNNPageTab,
                    yafBoardSettings.DNNPortalId,
                    new LocaleController().GetCurrentLocale(yafBoardSettings.DNNPortalId));
            }

            if (url.IsNotSet())
            {
                return(this.GetBaseUrl(yafBoardSettings, yafTab));
            }

            if (!global::YAF.Classes.Config.EnableURLRewriting)
            {
                if (!fullUrl)
                {
                    return(Globals.ResolveUrl("{0}&{1}".FormatWith(Globals.ApplicationURL(yafTab.TabID), url)));
                }

                var baseUrlMask = yafBoardSettings.BaseUrlMask;

                if (baseUrlMask.EndsWith("/"))
                {
                    baseUrlMask = baseUrlMask.Remove(baseUrlMask.Length - 1);
                }

                return("{0}{1}".FormatWith(
                           baseUrlMask,
                           Globals.ResolveUrl("{0}&{1}".FormatWith(Globals.ApplicationURL(yafTab.TabID), url))));
            }

            var newUrl = new StringBuilder();

            var boardNameOrPageName = UrlRewriteHelper.CleanStringForURL(yafTab.TabName);

            var parser = new SimpleURLParameterParser(url);

            var pageName       = parser["g"];
            var forumPage      = ForumPages.forum;
            var getDescription = false;

            if (pageName.IsSet())
            {
                try
                {
                    forumPage      = pageName.ToEnum <ForumPages>();
                    getDescription = true;
                }
                catch (Exception)
                {
                    getDescription = false;
                }
            }

            if (getDescription)
            {
                string useKey;
                switch (forumPage)
                {
                case ForumPages.topics:
                {
                    useKey = "f";

                    boardNameOrPageName =
                        UrlRewriteHelper.CleanStringForURL(
                            parser["name"].IsSet()
                                        ? parser["name"]
                                        : UrlRewriteHelper.GetForumName(parser[useKey].ToType <int>()));
                }

                break;

                case ForumPages.posts:
                {
                    if (parser["t"].IsSet())
                    {
                        useKey = "t";

                        var topicName = UrlRewriteHelper.GetTopicName(parser[useKey].ToType <int>());

                        if (topicName.EndsWith("-"))
                        {
                            topicName = topicName.Remove(topicName.Length - 1, 1);
                        }

                        boardNameOrPageName = topicName;
                    }
                    else if (parser["m"].IsSet())
                    {
                        useKey = "m";

                        string topicName;

                        try
                        {
                            topicName = UrlRewriteHelper.GetTopicNameFromMessage(parser[useKey].ToType <int>());

                            if (topicName.EndsWith("-"))
                            {
                                topicName = topicName.Remove(topicName.Length - 1, 1);
                            }
                        }
                        catch (Exception)
                        {
                            topicName = parser["g"];
                        }

                        boardNameOrPageName = topicName;
                    }
                }

                break;

                case ForumPages.profile:
                {
                    useKey = "u";

                    boardNameOrPageName =
                        UrlRewriteHelper.CleanStringForURL(
                            parser["name"].IsSet()
                                        ? parser["name"]
                                        : UrlRewriteHelper.GetProfileName(parser[useKey].ToType <int>()));

                    // Redirect the user to the Dnn profile page.

                    /*return
                     *  Globals.UserProfileURL(
                     *      UserController.GetUserByName(yafPortalId, boardNameOrPageName).UserID);*/
                }

                break;

                case ForumPages.forum:
                {
                    if (parser["c"].IsSet())
                    {
                        useKey = "c";
                        boardNameOrPageName = UrlRewriteHelper.GetCategoryName(parser[useKey].ToType <int>());
                    }
                    else if (parser["g"].IsSet())
                    {
                        return("{0}{1}".FormatWith(this.GetBaseUrl(yafBoardSettings, yafTab), boardNameOrPageName));
                    }
                }

                break;
                }
            }

            if (boardNameOrPageName.Equals(yafTab.TabName))
            {
                boardNameOrPageName = string.Empty;
            }

            newUrl.Append(
                FriendlyUrlProvider.Instance()
                .FriendlyUrl(
                    yafTab,
                    "{0}&{1}".FormatWith(Globals.ApplicationURL(yafTab.TabID), parser.CreateQueryString(new[] { "name" })),
                    "{0}.aspx".FormatWith(boardNameOrPageName),
                    portalSettings));

            // add anchor

            /*if (parser.HasAnchor)
             * {
             * newUrl.AppendFormat("#{0}", parser.Anchor);
             * }*/

            var finalUrl = newUrl.ToString();

            if (finalUrl.EndsWith("/"))
            {
                finalUrl = finalUrl.Remove(finalUrl.Length - 1);
            }

            return(finalUrl.Length >= 260
                       ? this.GetStandardUrl(yafTab, url, boardNameOrPageName, portalSettings)
                       : finalUrl);
        }
示例#7
0
        /// <summary>
        /// Build the url.
        /// </summary>
        /// <param name="url">The url.</param>
        /// <returns>
        /// Returns the URL.
        /// </returns>
        public override string BuildUrl(string url)
        {
            string newUrl = "{0}{1}?{2}".FormatWith(AppPath, Config.ForceScriptName ?? ScriptName, url);

            // create scriptName
            string scriptName = "{0}{1}".FormatWith(AppPath, Config.ForceScriptName ?? ScriptName);

            // get the base script file from the config -- defaults to, well, default.aspx :)
            string scriptFile = Config.BaseScriptFile;

            if (url.IsNotSet())
            {
                return(newUrl);
            }

            if (scriptName.EndsWith(scriptFile))
            {
                var before = scriptName.Remove(scriptName.LastIndexOf(scriptFile, StringComparison.Ordinal));

                var parser = new SimpleURLParameterParser(url);

                // create "rewritten" url...
                newUrl = "{0}{1}".FormatWith(before, Config.UrlRewritingPrefix);

                var        useKey         = string.Empty;
                var        description    = string.Empty;
                var        pageName       = parser["g"];
                ForumPages forumPage      = ForumPages.forum;
                var        getDescription = false;
                var        isFeed         = false;
                var        handlePage     = false;

                if (pageName.IsSet())
                {
                    try
                    {
                        forumPage      = pageName.ToEnum <ForumPages>();
                        getDescription = true;
                    }
                    catch (Exception)
                    {
                        getDescription = false;
                    }
                }

                if (getDescription)
                {
                    switch (forumPage)
                    {
                    case ForumPages.topics:
                        useKey      = "f";
                        description = UrlRewriteHelper.GetForumName(parser[useKey].ToType <int>());
                        handlePage  = true;
                        break;

                    case ForumPages.posts:
                        if (parser["t"].IsSet())
                        {
                            useKey      = "t";
                            pageName   += "t";
                            description = UrlRewriteHelper.GetTopicName(parser[useKey].ToType <int>());
                        }
                        else if (parser["m"].IsSet())
                        {
                            useKey    = "m";
                            pageName += "m";

                            try
                            {
                                description = UrlRewriteHelper.GetTopicNameFromMessage(parser[useKey].ToType <int>());
                            }
                            catch (Exception)
                            {
                                description = "posts";
                            }
                        }

                        handlePage = true;
                        break;

                    case ForumPages.profile:
                        useKey = "u";

                        description =
                            UrlRewriteHelper.CleanStringForURL(
                                parser["name"].IsSet()
                                        ? parser["name"]
                                        : UrlRewriteHelper.GetProfileName(parser[useKey].ToType <int>()));

                        parser.Parameters.Remove("name");
                        break;

                    case ForumPages.forum:
                        if (parser["c"].IsSet())
                        {
                            useKey      = "c";
                            description = UrlRewriteHelper.GetCategoryName(parser[useKey].ToType <int>());
                        }

                        break;

                    case ForumPages.rsstopic:
                        if (parser["pg"].IsSet())
                        {
                            description = parser["pg"].ToEnum <YafRssFeeds>().ToString().ToLower();
                        }

                        if (parser["f"].IsSet())
                        {
                            description +=
                                "_{0}".FormatWith(UrlRewriteHelper.GetForumName(parser["f"].ToType <int>()));
                        }

                        if (parser["t"].IsSet())
                        {
                            description +=
                                "_{0}".FormatWith(UrlRewriteHelper.GetTopicName(parser["t"].ToType <int>()));
                        }

                        if (parser["c"].IsSet())
                        {
                            description +=
                                "_{0}".FormatWith(UrlRewriteHelper.GetCategoryName(parser["c"].ToType <int>()));
                        }

                        if (parser["ft"].IsSet())
                        {
                            description += parser["ft"].ToType <int>() == YafSyndicationFormats.Atom.ToInt()
                                                   ? "-atom"
                                                   : "-rss";
                        }

                        handlePage = true;
                        isFeed     = true;
                        break;
                    }
                }

                newUrl += pageName;

                if (useKey.Length > 0)
                {
                    newUrl += parser[useKey];
                }

                if (handlePage && parser["p"] != null && !isFeed)
                {
                    int page = parser["p"].ToType <int>();
                    if (page != 1)
                    {
                        newUrl += "p{0}".FormatWith(page);
                    }

                    parser.Parameters.Remove("p");
                }

                if (isFeed)
                {
                    if (parser["ft"] != null)
                    {
                        int page = parser["ft"].ToType <int>();
                        newUrl += "ft{0}".FormatWith(page);
                        parser.Parameters.Remove("ft");
                    }

                    if (parser["f"] != null)
                    {
                        int page = parser["f"].ToType <int>();
                        newUrl += "f{0}".FormatWith(page);
                        parser.Parameters.Remove("f");
                    }

                    if (parser["t"] != null)
                    {
                        int page = parser["t"].ToType <int>();
                        newUrl += "t{0}".FormatWith(page);
                        parser.Parameters.Remove("t");
                    }
                }

                if (parser["find"] != null)
                {
                    newUrl += "find{0}".FormatWith(parser["find"].Trim());
                    parser.Parameters.Remove("find");
                }

                if (description.Length > 0)
                {
                    if (description.EndsWith("-"))
                    {
                        description = description.Remove(description.Length - 1, 1);
                    }

                    newUrl += "_{0}".FormatWith(description);
                }

                newUrl += ".aspx";

                var restURL = parser.CreateQueryString(new[] { "g", useKey });

                // append to the url if there are additional (unsupported) parameters
                if (restURL.Length > 0)
                {
                    newUrl += "?{0}".FormatWith(restURL);
                }

                // see if we can just use the default (/)
                if (newUrl.EndsWith("{0}forum.aspx".FormatWith(Config.UrlRewritingPrefix)))
                {
                    // remove in favor of just slash...
                    newUrl =
                        newUrl.Remove(
                            newUrl.LastIndexOf(
                                "{0}forum.aspx".FormatWith(Config.UrlRewritingPrefix), StringComparison.Ordinal),
                            "{0}forum.aspx".FormatWith(Config.UrlRewritingPrefix).Length);
                }

                // add anchor
                if (parser.HasAnchor)
                {
                    newUrl += "#{0}".FormatWith(parser.Anchor);
                }
            }

            // just make sure & is &amp; ...
            newUrl = newUrl.Replace("&amp;", "&").Replace("&", "&amp;");

            return(newUrl);
        }
示例#8
0
        /// <summary>
        /// Build the url.
        /// </summary>
        /// <param name="url">
        /// The url.
        /// </param>
        /// <returns>
        /// Returns the URL.
        /// </returns>
        public override string BuildUrl(string url)
        {
            var newUrl = new StringBuilder();

            newUrl.Append($"{AppPath}{Config.ForceScriptName ?? ScriptName}?{url}");

            // create scriptName
            var scriptName = $"{AppPath}{Config.ForceScriptName ?? ScriptName}";

            // get the base script file from the config -- defaults to, well, default.aspx :)
            var scriptFile = Config.BaseScriptFile;

            if (url.IsNotSet())
            {
                return(newUrl.ToString());
            }

            // TODO : is this needed?!

            /*const string gsr = "getsearchresults";
             * scriptName = scriptName.Replace(gsr, scriptFile);
             * newUrl = newUrl.Replace(gsr, scriptFile);*/

            if (scriptName.EndsWith(scriptFile))
            {
                var before = scriptName.Remove(scriptName.LastIndexOf(scriptFile, StringComparison.Ordinal));

                var parser = new SimpleURLParameterParser(url);

                // create "rewritten" url...
                newUrl.Clear();
                newUrl.Append(before);

                var useKey         = string.Empty;
                var description    = string.Empty;
                var pageName       = parser["g"];
                var forumPage      = ForumPages.Board;
                var getDescription = false;

                var isFeed     = false;
                var handlePage = false;

                if (pageName.IsSet())
                {
                    try
                    {
                        forumPage      = pageName.ToEnum <ForumPages>();
                        getDescription = true;
                    }
                    catch (Exception)
                    {
                        getDescription = false;
                    }
                }

                if (getDescription)
                {
                    switch (forumPage)
                    {
                    case ForumPages.Topics:
                        useKey      = "f";
                        pageName   += "/";
                        description = parser["name"];
                        handlePage  = true;
                        break;

                    case ForumPages.Posts:
                        pageName += "/";
                        if (parser["t"].IsSet())
                        {
                            useKey      = "t";
                            pageName   += "t";
                            description = UrlRewriteHelper.CleanStringForURL(parser["name"]);
                        }
                        else if (parser["m"].IsSet())
                        {
                            useKey      = "m";
                            pageName   += "m";
                            description = UrlRewriteHelper.CleanStringForURL(parser["name"]);
                        }

                        handlePage = true;
                        break;

                    case ForumPages.UserProfile:
                        useKey      = "u";
                        pageName   += "/";
                        description = UrlRewriteHelper.CleanStringForURL(parser["name"]);

                        parser.Parameters.Remove("name");
                        break;

                    case ForumPages.Board:
                        pageName = "category/";
                        if (parser["c"].IsSet())
                        {
                            useKey      = "c";
                            description = UrlRewriteHelper.CleanStringForURL(parser["name"]);
                        }
                        else
                        {
                            pageName = string.Empty;
                        }

                        break;

                    case ForumPages.Feed:
                        pageName += "/";

                        if (parser["feed"].IsSet())
                        {
                            description = parser["feed"].ToEnum <RssFeeds>().ToString().ToLower();
                        }

                        if (parser["f"].IsSet())
                        {
                            description = parser["name"];
                        }

                        if (parser["t"].IsSet())
                        {
                            description = parser["name"];
                        }

                        if (parser["c"].IsSet())
                        {
                            description = parser["name"];
                        }

                        handlePage = true;
                        isFeed     = true;
                        break;
                    }
                }

                if (parser["g"].StartsWith("Admin_"))
                {
                    // special handling for admin pages
                    pageName = parser["g"].Replace("Admin_", "Admin/");
                }
                else if (parser["g"].StartsWith("Moderate_"))
                {
                    // special handling for moderate pages
                    pageName = parser["g"].Replace("Moderate_", "Moderate/");
                }
                else if (parser["g"].StartsWith("Profile_"))
                {
                    // special handling for Profile pages
                    pageName = parser["g"].Replace("Profile_", "Profile/");
                }
                else if (parser["g"].StartsWith("Account_"))
                {
                    // special handling for Account pages
                    pageName = parser["g"].Replace("Account_", "Account/");
                }

                newUrl.Append(pageName);

                if (useKey.Length > 0)
                {
                    newUrl.Append(parser[useKey]);
                }

                // handle pager links
                if (handlePage && parser["p"] != null && !isFeed)
                {
                    var page = parser["p"].ToType <int>();

                    /*if (page != 1)
                     * {
                     *  description += $"/page{page}";
                     * }*/

                    description += $"/page{page}";

                    parser.Parameters.Remove("p");
                }

                if (isFeed)
                {
                    if (parser["feed"] != null)
                    {
                        var page = parser["feed"].ToType <int>();
                        newUrl.Append(page);
                        parser.Parameters.Remove("feed");
                    }

                    if (parser["f"] != null)
                    {
                        var page = parser["f"].ToType <int>();
                        newUrl.AppendFormat("-f{0}", page);
                        parser.Parameters.Remove("f");
                    }

                    if (parser["t"] != null)
                    {
                        var page = parser["t"].ToType <int>();
                        newUrl.AppendFormat("-t{0}", page);
                        parser.Parameters.Remove("t");
                    }

                    if (parser["c"] != null)
                    {
                        var page = parser["c"].ToType <int>();
                        newUrl.AppendFormat("-c{0}", page);
                        parser.Parameters.Remove("c");
                    }
                }

                if (description.Length > 0)
                {
                    if (description.EndsWith("-"))
                    {
                        description = description.Remove(description.Length - 1, 1);
                    }

                    newUrl.AppendFormat("-{0}", description);
                }

                var restUrl = parser.CreateQueryString(new[] { "g", useKey, "name" });

                // append to the url if there are additional (unsupported) parameters
                if (restUrl.Length > 0)
                {
                    newUrl.AppendFormat("?{0}", restUrl);
                }

                if (newUrl.ToString().EndsWith("/forum"))
                {
                    // remove in favor of just slash...
                    newUrl.Remove(newUrl.LastIndexOf("/forum", StringComparison.Ordinal), "/forum".Length);
                }

                // add anchor
                if (parser.HasAnchor)
                {
                    newUrl.AppendFormat("#{0}", parser.Anchor);
                }
            }

            // just make sure & is &amp; ...
            newUrl = newUrl.Replace("&amp;", "&").Replace("&", "&amp;");

            return(newUrl.ToString());
        }
        /// <summary>
        /// The build url.
        /// </summary>
        /// <param name="boardSettings">The board settings.</param>
        /// <param name="url">The url.</param>
        /// <returns>
        /// The new Url.
        /// </returns>
        public override string BuildUrl(object boardSettings, string url)
        {
            var yafBoardSettings = boardSettings.ToType <YafBoardSettings>();

            var yafTab = new TabController().GetTab(yafBoardSettings.DNNPageTab);

            if (url.IsNotSet())
            {
                // return BaseURL
                var baseUrl = Globals.NavigateURL();

                if (baseUrl.EndsWith(yafTab.TabName))
                {
                    baseUrl = baseUrl.Replace(yafTab.TabName, string.Empty);
                }

                if (baseUrl.EndsWith("{0}.aspx".FormatWith(yafTab.TabName)))
                {
                    baseUrl = baseUrl.Replace("{0}.aspx".FormatWith(yafTab.TabName), string.Empty);
                }

                if (baseUrl.EndsWith("{0}.aspx".FormatWith(yafTab.TabName.ToLower())))
                {
                    baseUrl = baseUrl.Replace("{0}.aspx".FormatWith(yafTab.TabName.ToLower()), string.Empty);
                }

                return(baseUrl);
            }

            if (!Config.EnableURLRewriting)
            {
                return(Globals.ResolveUrl("{0}&{1}".FormatWith(Globals.ApplicationURL(yafTab.TabID), url)));
            }

            var newUrl = new StringBuilder();

            var portalSettings = new PortalSettings(yafTab.PortalID);

            /*var portalSettings = PortalController.GetCurrentPortalSettings();
             *
             * var yafTab = new TabController().GetTab(
             *  yafBoardSettings.DNNPageTab,
             *  portalSettings.PortalId,
             *  false);*/

            var boardNameOrPageName = UrlRewriteHelper.CleanStringForURL(yafBoardSettings.Name);

            var parser = new SimpleURLParameterParser(url);

            var        pageName       = parser["g"];
            ForumPages forumPage      = ForumPages.forum;
            var        getDescription = false;

            if (pageName.IsSet())
            {
                try
                {
                    forumPage      = pageName.ToEnum <ForumPages>();
                    getDescription = true;
                }
                catch (Exception)
                {
                    getDescription = false;
                }
            }

            if (getDescription)
            {
                switch (forumPage)
                {
                case ForumPages.topics:
                {
                    boardNameOrPageName = UrlRewriteHelper.GetForumName(parser["f"].ToType <int>());
                }

                break;

                case ForumPages.posts:
                {
                    if (parser["t"].IsSet())
                    {
                        var topicName = UrlRewriteHelper.GetTopicName(parser["t"].ToType <int>());

                        if (topicName.EndsWith("-"))
                        {
                            topicName = topicName.Remove(topicName.Length - 1, 1);
                        }

                        boardNameOrPageName = topicName;
                    }
                    else if (parser["m"].IsSet())
                    {
                        string topicName;

                        try
                        {
                            topicName = UrlRewriteHelper.GetTopicNameFromMessage(parser["m"].ToType <int>());

                            if (topicName.EndsWith("-"))
                            {
                                topicName = topicName.Remove(topicName.Length - 1, 1);
                            }
                        }
                        catch (Exception)
                        {
                            topicName = parser["g"];
                        }

                        boardNameOrPageName = topicName;
                    }
                }

                break;

                case ForumPages.profile:
                {
                    boardNameOrPageName =
                        UrlRewriteHelper.CleanStringForURL(
                            parser["name"].IsSet()
                                        ? parser["name"]
                                        : UrlRewriteHelper.GetProfileName(parser["u"].ToType <int>()));
                }

                break;

                case ForumPages.forum:
                {
                    if (parser["c"].IsSet())
                    {
                        boardNameOrPageName = UrlRewriteHelper.GetCategoryName(parser["c"].ToType <int>());
                    }
                }

                break;
                }
            }

            newUrl.Append(
                FriendlyUrlProvider.Instance()
                .FriendlyUrl(
                    yafTab,
                    "{0}&{1}".FormatWith(Globals.ApplicationURL(yafTab.TabID), url),
                    boardNameOrPageName,
                    portalSettings.DefaultPortalAlias));

            // add anchor

            /*if (parser.HasAnchor)
             * {
             * newUrl.AppendFormat("#{0}", parser.Anchor);
             * }*/

            return(newUrl.Length >= 260
                       ? this.GetStandardUrl(yafTab, url, boardNameOrPageName, portalSettings)
                       : newUrl.ToString());
        }
示例#10
0
        /// <summary>
        /// Builds the URL complete.
        /// </summary>
        /// <param name="boardSettings">The board settings.</param>
        /// <param name="url">The URL.</param>
        /// <param name="fullUrl">if set to <c>true</c> [full URL].</param>
        /// <returns>
        /// The new URL.
        /// </returns>
        private static string BuildUrlComplete([NotNull] object boardSettings, [CanBeNull] string url, bool fullUrl)
        {
            CodeContracts.VerifyNotNull(boardSettings);

            var yafBoardSettings = boardSettings.ToType <BoardSettings>();

            var yafTab = new TabController().GetTab(yafBoardSettings.DNNPageTab, yafBoardSettings.DNNPortalId, true);

            var domainName = TestableGlobals.Instance.GetDomainName(HttpContext.Current.Request.Url);
            var aliasUrl   = PortalAliasController.GetPortalAliasByTab(yafBoardSettings.DNNPageTab, domainName);
            var alias      = PortalAliasController.Instance.GetPortalAlias(aliasUrl);

            IPortalSettings portalSettings = new PortalSettings(yafTab.PortalID, alias);

            if (portalSettings.ContentLocalizationEnabled)
            {
                yafTab = new TabController().GetTabByCulture(
                    yafBoardSettings.DNNPageTab,
                    yafBoardSettings.DNNPortalId,
                    new LocaleController().GetCurrentLocale(yafBoardSettings.DNNPortalId));
            }

            if (url.IsNotSet())
            {
                return(GetBaseUrl(yafBoardSettings, yafTab));
            }

            if (!Configuration.Config.EnableURLRewriting)
            {
                if (!fullUrl)
                {
                    return(Globals.ResolveUrl($"{Globals.ApplicationURL(yafTab.TabID)}&{url}"));
                }

                var baseUrlMask = yafBoardSettings.BaseUrlMask;

                if (baseUrlMask.EndsWith("/"))
                {
                    baseUrlMask = baseUrlMask.Remove(baseUrlMask.Length - 1);
                }

                return
                    ($"{baseUrlMask}{Globals.ResolveUrl($"{Globals.ApplicationURL(yafTab.TabID)}&{url}")}");
            }

            var newUrl = new StringBuilder();

            var boardNameOrPageName = UrlRewriteHelper.CleanStringForURL(yafTab.TabName);

            var parser = new SimpleURLParameterParser(url);

            var pageName       = parser["g"];
            var forumPage      = ForumPages.Board;
            var getDescription = false;

            if (pageName.IsSet())
            {
                try
                {
                    forumPage      = pageName.ToEnum <ForumPages>();
                    getDescription = true;
                }
                catch (Exception)
                {
                    getDescription = false;
                }
            }

            if (getDescription)
            {
                switch (forumPage)
                {
                case ForumPages.Topics:
                {
                    boardNameOrPageName = UrlRewriteHelper.CleanStringForURL(parser["name"]);
                }

                break;

                case ForumPages.Posts:
                {
                    if (parser["t"].IsSet())
                    {
                        var topicName = UrlRewriteHelper.CleanStringForURL(parser["name"]);

                        if (topicName.EndsWith("-"))
                        {
                            topicName = topicName.Remove(topicName.Length - 1, 1);
                        }

                        boardNameOrPageName = topicName;
                    }
                    else if (parser["m"].IsSet())
                    {
                        string topicName;

                        try
                        {
                            topicName = UrlRewriteHelper.CleanStringForURL(parser["name"]);

                            if (topicName.EndsWith("-"))
                            {
                                topicName = topicName.Remove(topicName.Length - 1, 1);
                            }
                        }
                        catch (Exception)
                        {
                            topicName = parser["g"];
                        }

                        boardNameOrPageName = topicName;
                    }
                }

                break;

                case ForumPages.UserProfile:
                {
                    var userInfo = UserController.GetUserByName(parser["name"]);

                    if (userInfo != null)
                    {
                        return(Globals.UserProfileURL(userInfo.UserID));
                    }

                    var userId = BoardContext.Current.Get <IAspNetUsersHelper>()
                                 .GetUserProviderKeyFromUserID(parser["u"].ToType <int>()).ToType <int>();

                    return(Globals.UserProfileURL(userId));
                }

                case ForumPages.Board:
                {
                    if (parser["c"].IsSet())
                    {
                        boardNameOrPageName = UrlRewriteHelper.CleanStringForURL(parser["name"]);
                    }
                    else if (parser["g"].IsSet())
                    {
                        return(yafTab.FullUrl);
                    }
                }

                break;
                }
            }

            if (boardNameOrPageName.Equals(yafTab.TabName))
            {
                boardNameOrPageName = string.Empty;
            }

            newUrl.Append(
                FriendlyUrlProvider.Instance()
                .FriendlyUrl(
                    yafTab,
                    $"{Globals.ApplicationURL(yafTab.TabID)}&{parser.CreateQueryString(new[] { "name" })}",
                    $"{boardNameOrPageName}.aspx",
                    portalSettings));

            // add anchor

            /*if (parser.HasAnchor)
             * {
             * newUrl.AppendFormat("#{0}", parser.Anchor);
             * }*/

            var finalUrl = newUrl.ToString();

            if (finalUrl.EndsWith("/"))
            {
                finalUrl = finalUrl.Remove(finalUrl.Length - 1);
            }

            finalUrl = finalUrl.Replace("/%20/", "-");

            return(finalUrl.Length >= 260
                       ? GetStandardUrl(yafTab, url, boardNameOrPageName, portalSettings)
                       : finalUrl);
        }
示例#11
0
文件: Pager.cs 项目: habeebtc/Spam
        protected string GetPageURL(int page)
        {
            string url = "";

            // create proper query string...
            SimpleURLParameterParser parser = new SimpleURLParameterParser( System.Web.HttpContext.Current.Request.QueryString.ToString() );

            // get the current page
            Pages currentPage = (Pages) Enum.Parse(typeof(Pages),parser["g"],true);

            if ( parser ["m"] != null )
            {
                // must be converted to by topic...
                parser.Parameters.Remove( "m" );
                parser.Parameters.Add( "t", ForumPage.PageTopicID.ToString() );
            }

            if ( page > 1 )
            {
            string tmp = parser.CreateQueryString( new string [] { "g", "p", "tabid" } );
                if (tmp.Length > 0) tmp += "&";

                tmp += "p={0}";

                url = Forum.GetLink( currentPage, tmp, page );
            }
            else
            {
            url = Forum.GetLink( currentPage, parser.CreateQueryString( new string [] { "g", "p", "tabid" } ) );
            }

            return url;
        }