/// <summary> /// Renders the specified output. /// </summary> /// <param name="writer">The output.</param> protected override void Render([NotNull] HtmlTextWriter writer) { if (!this.Visible) { return; } if (!this.PageBoardContext.BoardSettings.ShowAtomLink) { return; } writer.BeginRender(); string url; if (this.PageBoardContext.CurrentForumPage.PageType is ForumPages.Topics or ForumPages.Posts) { url = this.PageBoardContext.CurrentForumPage.PageType is ForumPages.Topics ? this.Get <LinkBuilder>().GetLink( ForumPages.Feed, new { feed = RssFeeds.Topics.ToInt(), f = this.PageBoardContext.PageForumID, name = UrlRewriteHelper.CleanStringForURL(this.PageBoardContext.PageForum.Name) }) : this.Get <LinkBuilder>().GetLink( ForumPages.Feed, new { feed = RssFeeds.Posts.ToInt(), t = this.PageBoardContext.PageTopicID, name = UrlRewriteHelper.CleanStringForURL(this.PageBoardContext.PageTopic.TopicName) }); }
/// <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 = this.ResolveUrl( "~/Default.aspx?tabid={1}&g=posts&m={0}#post{0}".FormatWith( currentRow["LastMessageID"], this.yafTabId)); // make message url... if (Classes.Config.EnableURLRewriting) { messageUrl = Globals.ResolveUrl( "~/tabid/{0}/g/posts/m/{1}/{2}.aspx#post{1}".FormatWith( this.yafTabId, currentRow["LastMessageID"], UrlRewriteHelper.CleanStringForURL(YafContext.Current.Get <IBadWordReplace>().Replace(currentRow["Topic"].ToString())))); } // 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()); // 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 = Classes.Config.EnableURLRewriting ? Globals.ResolveUrl( "~/tabid/{0}/g/topics/f/{1}/{2}.aspx".FormatWith( this.yafTabId, currentRow["ForumID"], currentRow["Forum"])) : this.ResolveUrl( "~/Default.aspx?tabid={1}&g=topics&f={0}".FormatWith( currentRow["ForumID"], this.yafTabId)) }; 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 = this.HtmlEncode(userName); var lastUserLink = new HyperLink { Text = userName, ToolTip = userName, NavigateUrl = Classes.Config.EnableURLRewriting ? Globals.ResolveUrl( "~/tabid/{0}/g/profile/u/{1}/{2}.aspx".FormatWith( this.yafTabId, currentRow["LastUserID"], userName)) : this.ResolveUrl( "~/Default.aspx?tabid={1}&g=profile&u={0}".FormatWith( currentRow["LastUserID"], this.yafTabId)) }; 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); }
/// <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); }
/// <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 & ... newUrl = newUrl.Replace("&", "&").Replace("&", "&"); return(newUrl); }
/// <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 & ... newUrl = newUrl.Replace("&", "&").Replace("&", "&"); return(newUrl); }
/// <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); }
/// <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 & ... newUrl = newUrl.Replace("&", "&").Replace("&", "&"); 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()); }
/// <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); }