Skip to content

Commit d1b18a7

Browse files
authored
Merge pull request DNNCommunity#327 from johnhenley/issues/326
FIX: Correct behavior when Friendly URLs are disabled but still installed
2 parents ece4699 + 58ab798 commit d1b18a7

File tree

12 files changed

+23
-46
lines changed

12 files changed

+23
-46
lines changed

CustomControls/HTML/CategoryTreeView.cs

-8
Original file line numberDiff line numberDiff line change
@@ -208,14 +208,6 @@ public string Render()
208208
{
209209
ParentForumId = ForumId;
210210
}
211-
string groupTemplate = TemplateUtils.GetTemplateSection(ItemTemplate, "[AF:DIR:FORUMGROUP]", "[/AF:DIR:FORUMGROUP]");
212-
string forumTemplate = TemplateUtils.GetTemplateSection(ItemTemplate, "[AF:DIR:FORUM]", "[/AF:DIR:FORUM]");
213-
string subForumTemplate = TemplateUtils.GetTemplateSection(ItemTemplate, "[AF:DIR:SUBFORUM]", "[/AF:DIR:SUBFORUM]");
214-
bool useFriendlyUrl = Utilities.IsRewriteLoaded();
215-
int currGroup = -1;
216-
string gtmp = string.Empty;
217-
string ftmp = string.Empty;
218-
string subtmp = string.Empty;
219211
using (IDataReader dr = db.ForumContent_List(PortalId, ModuleId, ForumGroupId, ForumId, ParentForumId))
220212
{
221213
//ParentForum Section

CustomControls/HTML/ForumContentView.cs

-8
Original file line numberDiff line numberDiff line change
@@ -208,14 +208,6 @@ public string Render()
208208
{
209209
ParentForumId = ForumId;
210210
}
211-
string groupTemplate = TemplateUtils.GetTemplateSection(ItemTemplate, "[AF:DIR:FORUMGROUP]", "[/AF:DIR:FORUMGROUP]");
212-
string forumTemplate = TemplateUtils.GetTemplateSection(ItemTemplate, "[AF:DIR:FORUM]", "[/AF:DIR:FORUM]");
213-
string subForumTemplate = TemplateUtils.GetTemplateSection(ItemTemplate, "[AF:DIR:SUBFORUM]", "[/AF:DIR:SUBFORUM]");
214-
bool useFriendlyUrl = Utilities.IsRewriteLoaded();
215-
int currGroup = -1;
216-
string gtmp = string.Empty;
217-
string ftmp = string.Empty;
218-
string subtmp = string.Empty;
219211
using (IDataReader dr = db.ForumContent_List(PortalId, ModuleId, ForumGroupId, ForumId, ParentForumId))
220212
{
221213
//ParentForum Section

CustomControls/ServerControls/WhatsNewControl.cs

+2-5
Original file line numberDiff line numberDiff line change
@@ -192,12 +192,9 @@ protected override void OnLoad(EventArgs e)
192192
dr = DataProvider.Instance().GetPosts(PortalId, ForumIds, TopicsOnly, RandomOrder, Rows, Tags, FilterByUserId);
193193
}
194194

195-
var useFriendly = Utilities.IsRewriteLoaded();
196-
var sHost = Utilities.GetHost();
197-
try
195+
try
198196
{
199197
var sTempTemplate = sTemplate;
200-
string lastPostDate;
201198
while (dr.Read())
202199
{
203200
var groupName = Convert.ToString(dr["GroupName"]);
@@ -253,7 +250,7 @@ protected override void OnLoad(EventArgs e)
253250
if (TabId == -1)
254251
TabId = Convert.ToInt32(topicTabId);
255252

256-
if (useFriendly && !(string.IsNullOrEmpty(sForumUrl)) && !(string.IsNullOrEmpty(sTopicURL)))
253+
if (Utilities.UseFriendlyURLs( Utilities.SafeConvertInt(topicModuleId)) && !(string.IsNullOrEmpty(sForumUrl)) && !(string.IsNullOrEmpty(sTopicURL)))
257254
{
258255
var ctlUtils = new ControlUtils();
259256
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);

CustomControls/UserControls/WhatsNewRSS.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,6 @@ private string BuildRSS()
256256

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

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

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

299298
string url;
300-
if (string.IsNullOrEmpty(sTopicUrl) || !useFriendly)
299+
if (string.IsNullOrEmpty(sTopicUrl) || !Utilities.UseFriendlyURLs(topicModuleId))
301300
{
302301
string[] Params = { ParamKeys.ViewType + "=" + Views.Topic, ParamKeys.ForumId + "=" + forumId, ParamKeys.TopicId + "=" + topicId };
303302
url = Common.Globals.NavigateURL(topicTabId, "", Params);

Services/AdminServiceController.cs

-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ public class ToggleUrlHandlerDTO
4343
public HttpResponseMessage ToggleURLHandler(ToggleUrlHandlerDTO dto)
4444
{
4545
var cfg = new ConfigUtils();
46-
bool success;
4746
if (Utilities.IsRewriteLoaded())
4847
{
4948
cfg.DisableRewriter(HttpContext.Current.Server.MapPath("~/web.config"));

WhatsNew.ascx.cs

+1-13
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ protected override void OnLoad(EventArgs e)
104104

105105
var sb = new StringBuilder(Settings.Header);
106106

107-
var useFriendly = Utilities.IsRewriteLoaded();
108107
var sHost = Utilities.GetHost();
109108

110109
try
@@ -136,17 +135,6 @@ protected override void OnLoad(EventArgs e)
136135

137136
var ts = DataCache.MainSettings(topicModuleId);
138137

139-
// The Module Stores the PostDate in the Current Time Zone format of the Server, not in UTC.
140-
// 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.
141-
//AF now stores in UTC;
142-
//var dtNow = DateTime.UtcNow;
143-
//var timeOffsetServer = (int)TimeZoneInfo.Local.GetUtcOffset(dtNow).TotalMinutes;
144-
//var timeOffsetSite = (int)PortalSettings.TimeZone.GetUtcOffset(dtNow).TotalMinutes;
145-
//var timeOffsetUser = (int)UserInfo.Profile.PreferredTimeZone.GetUtcOffset(postDate).TotalMinutes;
146-
147-
//var timeOffset = (timeOffsetSite - timeOffsetServer) + (timeOffsetUser- timeOffsetServer);
148-
149-
// Use a stringBuilder for better performance;
150138
var sbTemplate = new StringBuilder(Settings.Format ?? string.Empty);
151139

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

169-
if (useFriendly && !(string.IsNullOrEmpty(sForumUrl) && string.IsNullOrEmpty(sTopicUrl)))
157+
if (Utilities.UseFriendlyURLs(topicModuleId) && !(string.IsNullOrEmpty(sForumUrl) && string.IsNullOrEmpty(sTopicUrl)))
170158
{
171159
var ctlUtils = new ControlUtils();
172160

class/TemplateUtils.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ public static string ParseEmailTemplate(string template, string templateName, in
232232

233233
// Build the link
234234
string link;
235-
if (string.IsNullOrEmpty(fi.PrefixURL) || !Utilities.IsRewriteLoaded())
235+
if (string.IsNullOrEmpty(fi.PrefixURL) || !Utilities.UseFriendlyURLs(moduleID))
236236
{
237237
if (replyId == 0)
238238
link = ms.UseShortUrls ? Common.Globals.NavigateURL(tabID, string.Empty, new[] { string.Concat(ParamKeys.TopicId, "=", topicId) })

class/Utilities.cs

+4
Original file line numberDiff line numberDiff line change
@@ -932,6 +932,10 @@ internal static bool IsRewriteLoaded()
932932
return false;
933933
}
934934
}
935+
internal static bool UseFriendlyURLs(int ModuleId)
936+
{
937+
return IsRewriteLoaded() && SettingsBase.GetModuleSettings(ModuleId).URLRewriteEnabled;
938+
}
935939

936940
/// <summary>
937941
/// Get the template as a string from the specified path

components/Helpers/URL.cs

+9-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
// DEALINGS IN THE SOFTWARE.
1919
//
2020

21+
using System;
22+
2123
namespace DotNetNuke.Modules.ActiveForums
2224
{
2325
public class URL
@@ -85,12 +87,17 @@ public static string TopicLink(int tabId, int moduleId, TopicInfo ti)
8587

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

89-
public static string ReplyLink(int tabId, TopicInfo ti, int userId, int replyId)
92+
public static string ReplyLink(int tabId, TopicInfo ti, int userId, int replyId)
93+
{
94+
return ReplyLink(tabId, DotNetNuke.Common.Utilities.Null.NullInteger, ti, userId, replyId);
95+
}
96+
public static string ReplyLink(int tabId, int moduleId, TopicInfo ti, int userId, int replyId)
9097
{
9198
var sURL = Utilities.NavigateUrl(tabId, string.Empty, new [] { ParamKeys.TopicId + "=" + ti.TopicId, ParamKeys.ContentJumpId + "=" + replyId });
9299

93-
if (string.IsNullOrEmpty(ti.URL) || ! Utilities.IsRewriteLoaded())
100+
if (string.IsNullOrEmpty(ti.URL) || ! Utilities.UseFriendlyURLs(moduleId))
94101
return sURL;
95102

96103
var db = new Data.Common();

components/Replies/Replies.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,8 @@ public ReplyInfo ApproveReply(int PortalId, int TabId, int ModuleId, int ForumId
281281
}
282282
if (fullURL.EndsWith("/"))
283283
{
284-
fullURL += Utilities.IsRewriteLoaded() ? String.Concat("#", ReplyId) : String.Concat("?", ParamKeys.ContentJumpId, "=", ReplyId);
285-
}
284+
fullURL += Utilities.UseFriendlyURLs(ModuleId) ? String.Concat("#", ReplyId) : String.Concat("?", ParamKeys.ContentJumpId, "=", ReplyId);
285+
}
286286
Social amas = new Social();
287287
amas.AddReplyToJournal(PortalId, ModuleId, ForumId, TopicId, ReplyId, reply.Author.AuthorId, fullURL, reply.Content.Subject, string.Empty, reply.Content.Body,fi.Security.Read, fi.SocialGroupId);
288288
}

components/Topics/TopicsController.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ and also is used by the Community Links module (https://github.com/DNNCommunity/
406406

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

412412
ForumController fc = new ForumController();
@@ -459,7 +459,7 @@ and also is used by the Community Links module (https://github.com/DNNCommunity/
459459
ForumUrlPrefixes.Add(forumid, forumPrefixUrl);
460460
}
461461
string link = string.Empty;
462-
if (!string.IsNullOrEmpty(forumPrefixUrl) && isRewriteLoaded)
462+
if (!string.IsNullOrEmpty(forumPrefixUrl) && useFriendlyURLs)
463463
{
464464
link = new Data.Common().GetUrl(moduleInfo.ModuleID, -1, forumid, topicid, -1, contentid);
465465
}

controls/af_quickreply.ascx.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -431,8 +431,7 @@ private void SaveQuickReply()
431431
}
432432
if (fullURL.EndsWith("/"))
433433
{
434-
fullURL += Utilities.IsRewriteLoaded() ? String.Concat("#", ReplyId) : String.Concat("?", ParamKeys.ContentJumpId, "=", ReplyId);
435-
}
434+
fullURL += Utilities.UseFriendlyURLs(ForumModuleId) ? String.Concat("#", ReplyId) : String.Concat("?", ParamKeys.ContentJumpId, "=", ReplyId); }
436435
if (isApproved)
437436
{
438437

0 commit comments

Comments
 (0)