Пример #1
0
Файл: Pager.cs Проект: vzrus/VZF
        /// <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;
        }
Пример #2
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 (url.IsNotSet())
            {
                 return newUrl;
            }

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

                var parser = new SimpleURLParameterParser(url);

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

                string useKey = 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(); 
                            //// pageName += "pg";
                           /* if (parser[useKey].ToType<int>() == YafRssFeeds.Active.ToInt())
                            {
                                description = "active";
                            }
                            else if (parser[useKey].ToType<int>() == YafRssFeeds.Favorite.ToInt())
                            {
                                description = "favorite";
                            }
                            else if (parser[useKey].ToType<int>() == YafRssFeeds.Forum.ToInt())
                            {
                                description = "forum";
                            }
                            else if (parser[useKey].ToType<int>() == YafRssFeeds.LatestAnnouncements.ToInt())
                            {
                                description = "latestannouncements";
                            }
                            else if (parser[useKey].ToType<int>() == YafRssFeeds.LatestPosts.ToInt())
                            {
                                description = "latestposts";
                            }
                            else if (parser[useKey].ToType<int>() == YafRssFeeds.Posts.ToInt())
                            {
                                description = "posts";
                            }
                            else if (parser[useKey].ToType<int>() == YafRssFeeds.Topics.ToInt())
                            {
                                description = "topics";
                            } */
                        }

                        string useKey2;
                        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)),
                            "{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;
        }