Skip to content

Commit

Permalink
FIX: correct behavior when Friendly URLs are disabled but still insta…
Browse files Browse the repository at this point in the history
  • Loading branch information
johnhenley committed Jun 16, 2023
1 parent 6ecb9af commit 0e015c9
Show file tree
Hide file tree
Showing 10 changed files with 20 additions and 42 deletions.
8 changes: 0 additions & 8 deletions CustomControls/HTML/CategoryTreeView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -208,14 +208,6 @@ public string Render()
{
ParentForumId = ForumId;
}
string groupTemplate = TemplateUtils.GetTemplateSection(ItemTemplate, "[AF:DIR:FORUMGROUP]", "[/AF:DIR:FORUMGROUP]");
string forumTemplate = TemplateUtils.GetTemplateSection(ItemTemplate, "[AF:DIR:FORUM]", "[/AF:DIR:FORUM]");
string subForumTemplate = TemplateUtils.GetTemplateSection(ItemTemplate, "[AF:DIR:SUBFORUM]", "[/AF:DIR:SUBFORUM]");
bool useFriendlyUrl = Utilities.IsRewriteLoaded();
int currGroup = -1;
string gtmp = string.Empty;
string ftmp = string.Empty;
string subtmp = string.Empty;
using (IDataReader dr = db.ForumContent_List(PortalId, ModuleId, ForumGroupId, ForumId, ParentForumId))
{
//ParentForum Section
Expand Down
8 changes: 0 additions & 8 deletions CustomControls/HTML/ForumContentView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -208,14 +208,6 @@ public string Render()
{
ParentForumId = ForumId;
}
string groupTemplate = TemplateUtils.GetTemplateSection(ItemTemplate, "[AF:DIR:FORUMGROUP]", "[/AF:DIR:FORUMGROUP]");
string forumTemplate = TemplateUtils.GetTemplateSection(ItemTemplate, "[AF:DIR:FORUM]", "[/AF:DIR:FORUM]");
string subForumTemplate = TemplateUtils.GetTemplateSection(ItemTemplate, "[AF:DIR:SUBFORUM]", "[/AF:DIR:SUBFORUM]");
bool useFriendlyUrl = Utilities.IsRewriteLoaded();
int currGroup = -1;
string gtmp = string.Empty;
string ftmp = string.Empty;
string subtmp = string.Empty;
using (IDataReader dr = db.ForumContent_List(PortalId, ModuleId, ForumGroupId, ForumId, ParentForumId))
{
//ParentForum Section
Expand Down
7 changes: 2 additions & 5 deletions CustomControls/ServerControls/WhatsNewControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -192,12 +192,9 @@ protected override void OnLoad(EventArgs e)
dr = DataProvider.Instance().GetPosts(PortalId, ForumIds, TopicsOnly, RandomOrder, Rows, Tags, FilterByUserId);
}

var useFriendly = Utilities.IsRewriteLoaded();
var sHost = Utilities.GetHost();
try
try
{
var sTempTemplate = sTemplate;
string lastPostDate;
while (dr.Read())
{
var groupName = Convert.ToString(dr["GroupName"]);
Expand Down Expand Up @@ -253,7 +250,7 @@ protected override void OnLoad(EventArgs e)
if (TabId == -1)
TabId = Convert.ToInt32(topicTabId);

if (useFriendly && !(string.IsNullOrEmpty(sForumUrl)) && !(string.IsNullOrEmpty(sTopicURL)))
if (Utilities.UseFriendlyURLs( Utilities.SafeConvertInt(topicModuleId)) && !(string.IsNullOrEmpty(sForumUrl)) && !(string.IsNullOrEmpty(sTopicURL)))
{
var ctlUtils = new ControlUtils();
sTopicURL = ctlUtils.BuildUrl(Convert.ToInt32(topicTabId), Convert.ToInt32(topicModuleId), sGroupPrefixURL, sForumUrl, Convert.ToInt32(groupId), Convert.ToInt32(forumId), Convert.ToInt32(topicId), sTopicURL, -1, -1, string.Empty, 1, Convert.ToInt32(replyId), -1);
Expand Down
3 changes: 1 addition & 2 deletions CustomControls/UserControls/WhatsNewRSS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,6 @@ private string BuildRSS()

var forumids = Settings.RSSIgnoreSecurity ? Settings.Forums : AuthorizedForums;

var useFriendly = Utilities.IsRewriteLoaded();
var dr = DataProvider.Instance().GetPosts(RequestPortalID, forumids, true, false, Settings.Rows, Settings.Tags);
var sHost = Utilities.GetHost();

Expand Down Expand Up @@ -297,7 +296,7 @@ private string BuildRSS()
var ts = DataCache.MainSettings(topicModuleId);

string url;
if (string.IsNullOrEmpty(sTopicUrl) || !useFriendly)
if (string.IsNullOrEmpty(sTopicUrl) || !Utilities.UseFriendlyURLs(topicModuleId))
{
string[] Params = { ParamKeys.ViewType + "=" + Views.Topic, ParamKeys.ForumId + "=" + forumId, ParamKeys.TopicId + "=" + topicId };
url = Common.Globals.NavigateURL(topicTabId, "", Params);
Expand Down
1 change: 0 additions & 1 deletion Services/AdminServiceController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ public class ToggleUrlHandlerDTO
public HttpResponseMessage ToggleURLHandler(ToggleUrlHandlerDTO dto)
{
var cfg = new ConfigUtils();
bool success;
if (Utilities.IsRewriteLoaded())
{
cfg.DisableRewriter(HttpContext.Current.Server.MapPath("~/web.config"));
Expand Down
14 changes: 1 addition & 13 deletions WhatsNew.ascx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ protected override void OnLoad(EventArgs e)

var sb = new StringBuilder(Settings.Header);

var useFriendly = Utilities.IsRewriteLoaded();
var sHost = Utilities.GetHost();

try
Expand Down Expand Up @@ -136,17 +135,6 @@ protected override void OnLoad(EventArgs e)

var ts = DataCache.MainSettings(topicModuleId);

// The Module Stores the PostDate in the Current Time Zone format of the Server, not in UTC.
// So we need to calculate the difference between the Site UTC Offset and the Server UTC Offset and Users UTC Offset and the Server offset and add that to the displayed time.
//AF now stores in UTC;
//var dtNow = DateTime.UtcNow;
//var timeOffsetServer = (int)TimeZoneInfo.Local.GetUtcOffset(dtNow).TotalMinutes;
//var timeOffsetSite = (int)PortalSettings.TimeZone.GetUtcOffset(dtNow).TotalMinutes;
//var timeOffsetUser = (int)UserInfo.Profile.PreferredTimeZone.GetUtcOffset(postDate).TotalMinutes;

//var timeOffset = (timeOffsetSite - timeOffsetServer) + (timeOffsetUser- timeOffsetServer);

// Use a stringBuilder for better performance;
var sbTemplate = new StringBuilder(Settings.Format ?? string.Empty);

sbTemplate = sbTemplate.Replace("[FORUMGROUPNAME]", groupName);
Expand All @@ -166,7 +154,7 @@ protected override void OnLoad(EventArgs e)
sbTemplate = sbTemplate.Replace("[REPLYID]", replyId.ToString());
sbTemplate = sbTemplate.Replace("[REPLYCOUNT]", replyCount.ToString());

if (useFriendly && !(string.IsNullOrEmpty(sForumUrl) && string.IsNullOrEmpty(sTopicUrl)))
if (Utilities.UseFriendlyURLs(topicModuleId) && !(string.IsNullOrEmpty(sForumUrl) && string.IsNullOrEmpty(sTopicUrl)))
{
var ctlUtils = new ControlUtils();

Expand Down
2 changes: 1 addition & 1 deletion class/TemplateUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ public static string ParseEmailTemplate(string template, string templateName, in

// Build the link
string link;
if (string.IsNullOrEmpty(fi.PrefixURL) || !Utilities.IsRewriteLoaded())
if (string.IsNullOrEmpty(fi.PrefixURL) || !Utilities.UseFriendlyURLs(moduleID))
{
if (replyId == 0)
link = ms.UseShortUrls ? Common.Globals.NavigateURL(tabID, string.Empty, new[] { string.Concat(ParamKeys.TopicId, "=", topicId) })
Expand Down
4 changes: 4 additions & 0 deletions class/Utilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -934,6 +934,10 @@ internal static bool IsRewriteLoaded()
return false;
}
}
internal static bool UseFriendlyURLs(int ModuleId)
{
return IsRewriteLoaded() && SettingsBase.GetModuleSettings(ModuleId).URLRewriteEnabled;
}

/// <summary>
/// Get the template as a string from the specified path
Expand Down
11 changes: 9 additions & 2 deletions components/Helpers/URL.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
// DEALINGS IN THE SOFTWARE.
//

using System;

namespace DotNetNuke.Modules.ActiveForums
{
public class URL
Expand Down Expand Up @@ -85,12 +87,17 @@ public static string TopicLink(int tabId, int moduleId, TopicInfo ti)

return sURL;
}
[Obsolete("Deprecated in Community Forums. Scheduled for removal in 09.00.00. ReplyLink(int tabId, int moduleId, TopicInfo ti, int userId, int replyId)")]

public static string ReplyLink(int tabId, TopicInfo ti, int userId, int replyId)
public static string ReplyLink(int tabId, TopicInfo ti, int userId, int replyId)
{
return ReplyLink(tabId, DotNetNuke.Common.Utilities.Null.NullInteger, ti, userId, replyId);
}
public static string ReplyLink(int tabId, int moduleId, TopicInfo ti, int userId, int replyId)
{
var sURL = Utilities.NavigateUrl(tabId, string.Empty, new [] { ParamKeys.TopicId + "=" + ti.TopicId, ParamKeys.ContentJumpId + "=" + replyId });

if (string.IsNullOrEmpty(ti.URL) || ! Utilities.IsRewriteLoaded())
if (string.IsNullOrEmpty(ti.URL) || ! Utilities.UseFriendlyURLs(moduleId))
return sURL;

var db = new Data.Common();
Expand Down
4 changes: 2 additions & 2 deletions components/Topics/TopicsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ public override IList<SearchDocument> GetModifiedSearchDocuments(ModuleInfo modu

/* since this code runs without HttpContext, get https:// by looking at page settings */
bool isHttps = new DotNetNuke.Entities.Tabs.TabController().GetTab(moduleInfo.TabID, moduleInfo.PortalID).IsSecure;
bool isRewriteLoaded = Utilities.IsRewriteLoaded();
bool useFriendlyURLs = Utilities.UseFriendlyURLs(moduleInfo.ModuleID);
string primaryPortalAlias = new DotNetNuke.Entities.Portals.PortalAliasController().GetPortalAliasesByPortalId(moduleInfo.PortalID).FirstOrDefault(x => x.IsPrimary).HTTPAlias;

ForumController fc = new ForumController();
Expand Down Expand Up @@ -459,7 +459,7 @@ public override IList<SearchDocument> GetModifiedSearchDocuments(ModuleInfo modu
ForumUrlPrefixes.Add(forumid, forumPrefixUrl);
}
string link = string.Empty;
if (!string.IsNullOrEmpty(forumPrefixUrl) && isRewriteLoaded)
if (!string.IsNullOrEmpty(forumPrefixUrl) && useFriendlyURLs)
{
link = new Data.Common().GetUrl(moduleInfo.ModuleID, -1, forumid, topicid, -1, contentid);
}
Expand Down

0 comments on commit 0e015c9

Please sign in to comment.