コード例 #1
0
        public static string GetURL(HttpRequest Request, int ModuleID, string key, string Value, string RemoveKey)
        {
            if (Request != null && PortalSettings.Current != null)
            {
                NameValueCollection query = new NameValueCollection(Request.QueryString);

                if (!string.IsNullOrEmpty(key))
                {
                    query[key] = Value;
                }

                StringBuilder newQuery = new StringBuilder();
                foreach (string k in query.Keys)
                {
                    if (k != RemoveKey || RemoveKey == key)
                    {
                        newQuery.AppendFormat("&{0}={1}", k, query[k]);
                    }
                }

                string qPath = "?" + newQuery.ToString().TrimStart('&');
                string Path  = "~/Default.aspx" + qPath; //?TabId=" + PortalSettings.Current.ActiveTab.TabID;

                return(FriendlyUrlProvider.Instance().FriendlyUrl(PortalSettings.Current.ActiveTab, Path));
            }
            else
            {
                throw new Exception("HttpRequest & PortalSettings.Current must be Non-Nullable to generate a paging url");
            }
        }
コード例 #2
0
 /// <summary>
 /// Gets the standard URL without any specific page names.
 /// </summary>
 /// <param name="activeTab">The active tab.</param>
 /// <param name="url">The URL.</param>
 /// <param name="boardNameOrPageName">Name of the board name original page.</param>
 /// <param name="portalSettings">The portal settings.</param>
 /// <returns>Returns the Normal URL</returns>
 private string GetStandardUrl(
     TabInfo activeTab,
     string url,
     string boardNameOrPageName,
     PortalSettings portalSettings)
 {
     return(FriendlyUrlProvider.Instance()
            .FriendlyUrl(
                activeTab,
                "{0}&{1}".FormatWith(Globals.ApplicationURL(activeTab.TabID), url),
                boardNameOrPageName,
                portalSettings));
 }
コード例 #3
0
 /// <summary>
 /// Gets the standard URL without any specific page names.
 /// </summary>
 /// <param name="activeTab">The active tab.</param>
 /// <param name="url">The URL.</param>
 /// <param name="boardNameOrPageName">Name of the board name original page.</param>
 /// <param name="portalSettings">The portal settings.</param>
 /// <returns>Returns the Normal URL</returns>
 private static string GetStandardUrl(
     [NotNull] TabInfo activeTab,
     string url,
     string boardNameOrPageName,
     IPortalSettings portalSettings)
 {
     return(FriendlyUrlProvider.Instance()
            .FriendlyUrl(
                activeTab,
                $"{Globals.ApplicationURL(activeTab.TabID)}&{url}",
                boardNameOrPageName,
                portalSettings));
 }
コード例 #4
0
            public static string GetCurrentTabUrl(PortalSettings pS, string QueryParameters = null)
            {
                string Language = Thread.CurrentThread.CurrentCulture.ToString();

                if (pS != null && Thread.CurrentThread.CurrentCulture.ToString() == pS.DefaultLanguage)
                {
                    Language = null;
                }

                HttpContext Context = HttpContext.Current;

                string path = "~/Default.aspx";

                if (!string.IsNullOrEmpty(Language))
                {
                    pS.CultureCode = Language;
                }
                else
                {
                    pS.CultureCode = pS.DefaultLanguage;
                }

                if (string.IsNullOrEmpty(QueryParameters))
                {
                    QueryParameters = string.Empty;
                }

                if (Context.Request.QueryString.AllKeys.Count() > 0)
                {
                    string param = string.Empty;
                    foreach (string q in Context.Request.QueryString.AllKeys)
                    {
                        if (!string.IsNullOrEmpty(q) && q.ToLower() != "language" && q.ToLower() != "tabid")
                        {
                            param += ("&" + q + "=" + Context.Request.QueryString[q]);
                        }
                    }
                    QueryParameters = param + QueryParameters;
                }

                path = AppendQueryParameters(pS, pS.ActiveTab.TabID, path, QueryParameters, Language);
                return(FriendlyUrlProvider.Instance().FriendlyUrl(pS.ActiveTab, path));
            }
コード例 #5
0
        internal static void GetPageName(ref string PageName, int TabID, PortalSettings pS)
        {
            //Find pagename
            TabInfo tab;
            string  PageNameURL = string.Empty;

            if (TabID > -1)
            {
                tab         = new TabController().GetTab(TabID, pS.PortalId);
                PageNameURL = FriendlyUrlProvider.Instance().FriendlyUrl(tab, "~/Default.aspx?TabId=" + tab.TabID, " ", pS.PortalAlias.HTTPAlias).ToLower();
                int Index = PageNameURL.IndexOf(pS.PortalAlias.HTTPAlias) + pS.PortalAlias.HTTPAlias.Length;

                if (Index < PageNameURL.Length)
                {
                    PageName = PageNameURL.Substring(Index).Trim().TrimStart('/').TrimEnd('/');
                }
            }
            else
            {
                tab         = new TabController().GetTab(pS.HomeTabId, pS.PortalId);
                PageNameURL = FriendlyUrlProvider.Instance().FriendlyUrl(tab, "~/Default.aspx", tab.TabName, pS.PortalAlias.HTTPAlias).ToLower();
                PageName    = PageNameURL.TrimStart('~', '/').Trim();
            }
        }
コード例 #6
0
        /// <summary>
        /// Processes the item.
        /// </summary>
        /// <param name="e">
        /// The <see cref="RepeaterItemEventArgs"/> instance containing the event data.
        /// </param>
        /// <returns>
        /// Returns the Item as string
        /// </returns>
        private string ProcessItem(RepeaterItemEventArgs e)
        {
            var currentRow = (DataRowView)e.Item.DataItem;

            var currentItem = this.itemTemplate;

            var messageUrl = FriendlyUrlProvider.Instance().FriendlyUrl(
                this.yafTabInfo,
                "{0}&g=posts&m={1}".FormatWith(
                    Globals.ApplicationURL(this.yafTabInfo.TabID),
                    currentRow["LastMessageID"]),
                UrlRewriteHelper.CleanStringForURL(
                    YafContext.Current.Get <IBadWordReplace>().Replace(currentRow["Topic"].ToString())),
                this.PortalSettings);

            try
            {
                // Render [LASTPOSTICON]
                var lastPostedImage = new ThemeImage
                {
                    LocalizedTitlePage = "DEFAULT",
                    LocalizedTitleTag  = "GO_LAST_POST",
                    LocalizedTitle     =
                        Localization.GetString(
                            "LastPost.Text",
                            this.LocalResourceFile),
                    ThemeTag = "TOPIC_NEW",
                    Style    = "width:16px;height:16px"
                };

                currentItem = currentItem.Replace("[LASTPOSTICON]", lastPostedImage.RenderToString());
            }
            catch (Exception)
            {
                currentItem = currentItem.Replace("[LASTPOSTICON]", string.Empty);
            }

            // Render [TOPICLINK]
            var textMessageLink = new HyperLink
            {
                Text =
                    YafContext.Current.Get <IBadWordReplace>()
                    .Replace(currentRow["Topic"].ToString()),
                NavigateUrl = messageUrl
            };

            currentItem = currentItem.Replace("[TOPICLINK]", textMessageLink.RenderToString());

            // Render [FORUMLINK]
            var forumLink = new HyperLink
            {
                Text        = currentRow["Forum"].ToString(),
                NavigateUrl = FriendlyUrlProvider.Instance().FriendlyUrl(
                    this.yafTabInfo,
                    "{0}&g=topics&f={1}".FormatWith(
                        Globals.ApplicationURL(this.yafTabInfo.TabID),
                        currentRow["ForumID"]),
                    UrlRewriteHelper.CleanStringForURL(
                        YafContext.Current.Get <IBadWordReplace>()
                        .Replace(currentRow["Forum"].ToString())),
                    this.PortalSettings)
            };

            currentItem = currentItem.Replace("[FORUMLINK]", forumLink.RenderToString());

            // Render [BYTEXT]
            currentItem = currentItem.Replace(
                "[BYTEXT]",
                YafContext.Current.Get <IHaveLocalization>().GetText("SEARCH", "BY"));

            // Render [LASTUSERLINK]
            // Just in case...
            if (currentRow["LastUserID"] != DBNull.Value)
            {
                var userName = YafContext.Current.Get <YafBoardSettings>().EnableDisplayName
                                   ? currentRow["LastUserDisplayName"].ToString()
                                   : currentRow["LastUserName"].ToString();

                userName = new UnicodeEncoder().XSSEncode(userName);

                var lastUserLink = new HyperLink
                {
                    Text        = userName,
                    ToolTip     = userName,
                    NavigateUrl = FriendlyUrlProvider.Instance().FriendlyUrl(
                        this.yafTabInfo,
                        "{0}&g=profile&u={1}".FormatWith(
                            Globals.ApplicationURL(this.yafTabInfo.TabID),
                            currentRow["LastUserID"]),
                        userName,
                        this.PortalSettings)
                };

                currentItem = currentItem.Replace("[LASTUSERLINK]", lastUserLink.RenderToString());
            }

            // Render [LASTMESSAGE]
            var lastMessage =
                BBCodeHelper.StripBBCode(
                    HtmlHelper.StripHtml(HtmlHelper.CleanHtmlString(currentRow["LastMessage"].ToType <string>())))
                .RemoveMultipleWhitespace();

            try
            {
                var match = Regex.Match(currentItem, @"\[LASTMESSAGE\:(?<count>[0-9]*)\]", RegexOptions.Compiled);

                if (match.Success)
                {
                    var messageLimit = match.Groups["count"].Value.ToType <int>();

                    currentItem = currentItem.Replace(
                        "[LASTMESSAGE:{0}]".FormatWith(match.Groups["count"].Value),
                        lastMessage.Truncate(messageLimit));
                }
                else
                {
                    currentItem = currentItem.Replace("[LASTMESSAGE]", lastMessage);
                }
            }
            catch (Exception)
            {
                currentItem = currentItem.Replace("[LASTMESSAGE]", lastMessage);
            }

            // Render [LASTPOSTEDDATETIME]
            var displayDateTime = new DisplayDateTime {
                DateTime = currentRow["LastPosted"].ToType <DateTime>()
            };

            currentItem = currentItem.Replace("[LASTPOSTEDDATETIME]", displayDateTime.RenderToString());

            return(currentItem);
        }
コード例 #7
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 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);
        }
コード例 #8
0
        public static string GetFriendlyURL(int?ModuleID, PortalSettings pS, string QueryParameters, URLEntity u)
        {
            string strLanguage = string.IsNullOrEmpty(u.Language) ? URLManager.GetCurrentLanguage() : u.Language;

            string path = "~/Default.aspx";

            if (!string.IsNullOrEmpty(strLanguage))
            {
                pS.CultureCode = strLanguage;
            }
            else
            {
                pS.CultureCode = pS.DefaultLanguage;
            }

            TabInfo tab = null;

            if (u.PageName)
            {
                if (ModuleID.HasValue)
                {
                    int?ModuleTabID = null;

                    var Index = GetModuleTabIndex();

                    if (Index.ContainsKey(ModuleID.Value))
                    {
                        ModuleTabID = Index[ModuleID.Value];
                    }
                    else
                    {
                        ModuleInfo minfo = new ModuleController().GetModule(ModuleID.Value, Null.NullInteger, false);
                        ModuleTabID = minfo.TabID;
                    }
                    if (ModuleTabID.HasValue)
                    {
                        tab = new TabController().GetTab(ModuleTabID.Value, pS.PortalId);
                    }
                }
                else if (pS.HomeTabId != pS.ActiveTab.TabID)
                {
                    tab = pS.ActiveTab;
                }
            }


            if (tab == null)
            {
                tab = new TabController().GetTab(pS.HomeTabId, pS.PortalId);
            }


            path = AppendQueryParameters(pS, tab.TabID, path, QueryParameters, strLanguage, u);
            if (pS != null && pS.PortalAlias != null)
            {
                return(FriendlyUrlProvider.Instance().FriendlyUrl(tab, path, u.Slug, pS as IPortalSettings));
            }
            else
            {
                return(path.TrimStart('~', '/') + "&" + u.Slug);
            }
        }
コード例 #9
0
        /// <summary>
        /// Processes the item.
        /// </summary>
        /// <param name="e">
        /// The <see cref="RepeaterItemEventArgs"/> instance containing the event data.
        /// </param>
        /// <returns>
        /// Returns the Item as string
        /// </returns>
        private string ProcessItem(RepeaterItemEventArgs e)
        {
            var dataItem = (LatestTopic)e.Item.DataItem;

            var currentItem = this.itemTemplate;

            var messageUrl = FriendlyUrlProvider.Instance().FriendlyUrl(
                this.yafTabInfo,
                $"{Globals.ApplicationURL(this.yafTabInfo.TabID)}&g=posts&m={dataItem.LastMessageID}",
                UrlRewriteHelper.CleanStringForURL(
                    BoardContext.Current.Get <IBadWordReplace>().Replace(dataItem.Topic)));

            currentItem = currentItem.Replace("[LASTPOSTICON]", string.Empty);

            // Render TOPICLINK
            var textMessageLink = new HyperLink
            {
                Text =
                    BoardContext.Current.Get <IBadWordReplace>()
                    .Replace(dataItem.Topic),
                NavigateUrl = messageUrl
            };

            currentItem = currentItem.Replace("[TOPICLINK]", textMessageLink.RenderToString());

            // Render FORUMLINK
            var forumLink = new HyperLink
            {
                Text        = dataItem.Forum,
                NavigateUrl = FriendlyUrlProvider.Instance().FriendlyUrl(
                    this.yafTabInfo,
                    $"{Globals.ApplicationURL(this.yafTabInfo.TabID)}&g=topics&f={dataItem.ForumID}",
                    UrlRewriteHelper.CleanStringForURL(
                        BoardContext.Current.Get <IBadWordReplace>()
                        .Replace(dataItem.Forum)))
            };

            currentItem = currentItem.Replace("[FORUMLINK]", forumLink.RenderToString());

            // Render BYTEXT
            currentItem = currentItem.Replace(
                "[BYTEXT]",
                BoardContext.Current.Get <IHaveLocalization>().GetText("SEARCH", "BY"));

            // Render LASTUSERLINK
            // Just in case...
            if (dataItem.LastUserID.HasValue)
            {
                var userName = BoardContext.Current.Get <BoardSettings>().EnableDisplayName
                                   ? dataItem.LastUserDisplayName
                                   : dataItem.LastUserName;

                userName = new UnicodeEncoder().XSSEncode(userName);

                var lastUserLink = new HyperLink
                {
                    Text        = userName,
                    ToolTip     = userName,
                    NavigateUrl = FriendlyUrlProvider.Instance().FriendlyUrl(
                        this.yafTabInfo,
                        $"{Globals.ApplicationURL(this.yafTabInfo.TabID)}&g=profile&u={dataItem.LastUserID}",
                        userName)
                };

                currentItem = currentItem.Replace("[LASTUSERLINK]", lastUserLink.RenderToString());
            }

            // Render LASTMESSAGE
            var lastMessage =
                BBCodeHelper.StripBBCode(
                    HtmlHelper.StripHtml(HtmlHelper.CleanHtmlString(dataItem.LastMessage)))
                .RemoveMultipleWhitespace();

            try
            {
                var match = Regex.Match(currentItem, @"\[LASTMESSAGE\:(?<count>[0-9]*)\]", RegexOptions.Compiled);

                if (match.Success)
                {
                    var messageLimit = match.Groups["count"].Value.ToType <int>();

                    currentItem = currentItem.Replace(
                        $"[LASTMESSAGE:{match.Groups["count"].Value}]",
                        lastMessage.Truncate(messageLimit));
                }
                else
                {
                    currentItem = currentItem.Replace("[LASTMESSAGE]", lastMessage);
                }
            }
            catch (Exception)
            {
                currentItem = currentItem.Replace("[LASTMESSAGE]", lastMessage);
            }

            // Render LASTPOSTEDDATETIME
            var displayDateTime = new DisplayDateTime {
                DateTime = (DateTime)dataItem.LastPosted
            };

            currentItem = currentItem.Replace("[LASTPOSTEDDATETIME]", displayDateTime.RenderToString());

            return(currentItem);
        }
コード例 #10
0
        /// <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());
        }
コード例 #11
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);
        }