Skip to content

Commit de4b707

Browse files
authored
Merge pull request #1564 from johnhenley/issues/viewer-urls-1557
FIX: improves friendly URLs handling
2 parents 36e5888 + 6eac0ac commit de4b707

File tree

6 files changed

+218
-19
lines changed

6 files changed

+218
-19
lines changed

Dnn.CommunityForums/Entities/ForumInfo.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -222,15 +222,14 @@ internal DotNetNuke.Modules.ActiveForums.Entities.IPostInfo LoadLastPost()
222222

223223
return this.lastPostInfo;
224224

225-
// return this.lastPostInfo = this.LastReplyId == 0 ? (DotNetNuke.Modules.ActiveForums.Entities.IPostInfo)new DotNetNuke.Modules.ActiveForums.Controllers.TopicController(this.ModuleId).GetById(this.LastTopicId) : new DotNetNuke.Modules.ActiveForums.Controllers.ReplyController(this.ModuleId).GetById(this.LastReplyId);
226225
}
227-
226+
228227
[IgnoreColumn]
229228
public string LastPostUserName => this.LastPost != null && this.LastPost.Content != null ? this.LastPost.Content.AuthorName : string.Empty;
230-
229+
231230
[IgnoreColumn]
232231
public int LastPostUserID => this.LastPost != null && this.LastPost.Content != null ? this.LastPost.Content.AuthorId : DotNetNuke.Common.Utilities.Null.NullInteger;
233-
232+
234233
[IgnoreColumn]
235234
public DateTime? LastPostDateTime => this.LastPost != null && this.LastPost.Content != null ? (DateTime)this.LastPost.Content.DateUpdated : DotNetNuke.Common.Utilities.Null.NullDate;
236235

Dnn.CommunityForums/ReleaseNotes.txt

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,22 +67,25 @@
6767

6868
<h4>New Features &amp; Enhancements</h4>
6969
<ul>
70-
<li>NEW: Adds Recycle Bin to be able to restore (soft-)deleted topics and replies (<a href="https://github.com/DNNCommunity/Dnn.CommunityForums/pull/1531">PR# 1531</a>)</li>
71-
<li>NEW: Adds an avatar injection service to populate avatars (currently using Gravatar) for forums users who haven't set up their own DNN profile picture/avatar. (<a href="https://github.com/DNNCommunity/Dnn.CommunityForums/pull/1446">PR# 1446</a>)</li>
70+
<li>NEW: Adds Recycle Bin to be able to restore (soft-)deleted topics and replies (<a href="https://github.com/DNNCommunity/Dnn.CommunityForums/pull/1531">PR# 1531</a>)</li>
71+
<li>NEW: Adds an avatar injection service to populate avatars (currently using Gravatar) for forums users who haven't set up their own DNN profile picture/avatar. (<a href="https://github.com/DNNCommunity/Dnn.CommunityForums/pull/1446">PR# 1446</a>)</li>
72+
<!--
73+
<li>NEW: (<a href="https://github.com/DNNCommunity/Dnn.CommunityForums/pull/TBD">PR# TBD</a>)</li>
7274

73-
<!--
7475
<li>UPDATE: (<a href="https://github.com/DNNCommunity/Dnn.CommunityForums/issues/">Issue </a>)</li>
76+
-->
7577
<li>None at this time.</li>
76-
-->
7778
</ul>
7879

7980
<h4>Bug Fixes</h4>
8081
<ul>
8182
<li>FIX: Update indexes on forum/topic tracking tables for uniqueness; upgrade script to detect and remove duplicates, keeping the latest entries (<a href="https://github.com/DNNCommunity/Dnn.CommunityForums/issues/1434">Issue 1434</a>)</li>
83+
<li>FIX: Forum Viewer updated to working correctly with friendly URLs and localized sites (<a href="https://github.com/DNNCommunity/Dnn.CommunityForums/issues/1557">Issue 1557</a>)</li>
84+
<li>FIX: Permissions preventing viewing of attachments (<a href="https://github.com/DNNCommunity/Dnn.CommunityForums/issues/1559">Issue 1559</a>)</li>
8285

83-
<!--
86+
<!--
8487
<li>None at this time.</li>
85-
-->
88+
-->
8689
</ul>
8790

8891
<h4>Tasks / Development Updates (and Technical Debt)</h4>

Dnn.CommunityForums/class/ForumBase.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,21 @@ public DotNetNuke.Modules.ActiveForums.Entities.ForumInfo ForumInfo
369369
{
370370
get
371371
{
372-
return this.foruminfo ?? (this.foruminfo = DotNetNuke.Modules.ActiveForums.Controllers.ForumController.Forums_Get(this.PortalId, this.ForumModuleId, this.ForumId, true, this.TopicId));
372+
if (this.foruminfo == null)
373+
{
374+
this.foruminfo = DotNetNuke.Modules.ActiveForums.Controllers.ForumController.Forums_Get(this.PortalId, this.ForumModuleId, this.ForumId, true, this.TopicId);
375+
}
376+
377+
if (this.foruminfo != null)
378+
{
379+
this.foruminfo.PortalSettings = this.PortalSettings;
380+
if (this.foruminfo.ForumGroup != null)
381+
{
382+
this.foruminfo.ForumGroup.PortalSettings = this.PortalSettings;
383+
}
384+
}
385+
386+
return this.foruminfo;
373387
}
374388

375389
set

Dnn.CommunityForums/components/Controls/ControlUtils.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,10 @@ public string BuildUrl(int portalId, int tabId, int moduleId, string groupPrefix
165165

166166
var sURL = Utilities.NavigateURL(tabId, portalSettings, string.Empty, @params.ToArray());
167167
var tabInfo = DotNetNuke.Entities.Tabs.TabController.Instance.GetTab(tabId, portalId);
168-
if (!string.IsNullOrEmpty(mainSettings.PrefixURLBase) && !mainSettings.PrefixURLBase.Trim().Equals(tabInfo.TabName.Trim(), StringComparison.InvariantCultureIgnoreCase))
168+
var moduleInfo = DotNetNuke.Entities.Modules.ModuleController.Instance.GetModule(moduleId, DotNetNuke.Common.Utilities.Null.NullInteger, true);
169+
170+
/* ONLY include prefix if main forum module, prefix isn't same as tab name, and prefix is filled, e.g. don't include running in viewer module */
171+
if (moduleInfo.TabID.Equals(tabId) && !mainSettings.PrefixURLBase.Trim().Equals(tabInfo.TabName.Trim(), StringComparison.InvariantCultureIgnoreCase) && !string.IsNullOrEmpty(mainSettings.PrefixURLBase) )
169172
{
170173
sURL += "/" + mainSettings.PrefixURLBase;
171174
}

Dnn.CommunityForums/components/Extensions/ReWriter.cs

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ namespace DotNetNuke.Modules.ActiveForums
2222
{
2323
using System;
2424
using System.Data;
25+
using System.Linq;
2526
using System.Text.RegularExpressions;
2627
using System.Web;
2728

@@ -218,10 +219,16 @@ public void OnBeginRequest(object s, EventArgs e)
218219
return;
219220
}
220221

222+
var urlToSearch = newSearchURL;
223+
if (HttpContext.Current.Request.UserLanguages != null && HttpContext.Current.Request.UserLanguages.Length > 0 && urlToSearch.ToLowerInvariant().Contains(HttpContext.Current.Request.UserLanguages[0].ToLowerInvariant()))
224+
{
225+
urlToSearch = urlToSearch.Replace(HttpContext.Current.Request.UserLanguages[0].ToLowerInvariant() + "/", string.Empty);
226+
}
227+
221228
Data.Common db = new Data.Common();
222229
try
223230
{
224-
using (IDataReader dr = db.URLSearch(portalId, newSearchURL))
231+
using (IDataReader dr = db.URLSearch(portalId, urlToSearch))
225232
{
226233
while (dr.Read())
227234
{
@@ -300,7 +307,7 @@ public void OnBeginRequest(object s, EventArgs e)
300307

301308
if (this.moduleId > 0)
302309
{
303-
this.mainSettings = new SettingsInfo { ModuleId = this.moduleId, MainSettings = DotNetNuke.Entities.Modules.ModuleController.Instance.GetModule(moduleId: this.moduleId, tabId: this.tabId, ignoreCache: false).ModuleSettings };
310+
this.mainSettings = new SettingsInfo { ModuleId = this.moduleId, MainSettings = DotNetNuke.Entities.Modules.ModuleController.Instance.GetModule(moduleId: this.moduleId, tabId: DotNetNuke.Common.Utilities.Null.NullInteger, ignoreCache: false).ModuleSettings };
304311
}
305312

306313
if (this.mainSettings == null)
@@ -411,16 +418,29 @@ public void OnBeginRequest(object s, EventArgs e)
411418
if (canContinue)
412419
{
413420
// avoid redirect, e.g. "/Forums" == "forums/"
414-
if ((searchURL.StartsWith("/") || searchURL.EndsWith("/")) && searchURL.IndexOf("/") == searchURL.LastIndexOf("/") &&
415-
(newSearchURL.StartsWith("/") || newSearchURL.EndsWith("/")) && newSearchURL.IndexOf("/") == newSearchURL.LastIndexOf("/") &&
416-
searchURL.Replace("/", string.Empty).ToLowerInvariant() == newSearchURL.Replace("/", string.Empty).ToLowerInvariant())
421+
var searchURL2 = searchURL;
422+
if (HttpContext.Current.Request.UserLanguages != null && HttpContext.Current.Request.UserLanguages.Length > 0 && searchURL2.ToLowerInvariant().Contains(HttpContext.Current.Request.UserLanguages[0].ToLowerInvariant()))
423+
{
424+
searchURL2 = searchURL2.Replace(HttpContext.Current.Request.UserLanguages[0].ToLowerInvariant() + "/", string.Empty);
425+
}
426+
427+
var newSearchURL2 = newSearchURL;
428+
if (HttpContext.Current.Request.UserLanguages != null && HttpContext.Current.Request.UserLanguages.Length > 0 && newSearchURL2.ToLowerInvariant().Contains(HttpContext.Current.Request.UserLanguages[0].ToLowerInvariant()))
429+
{
430+
newSearchURL2 = newSearchURL2.Replace(HttpContext.Current.Request.UserLanguages[0].ToLowerInvariant() + "/", string.Empty);
431+
}
432+
433+
// avoid redirect, e.g. "/Forums" == "forums/"
434+
if (((searchURL2.StartsWith("/") && searchURL2.IndexOf("/") == searchURL2.LastIndexOf("/")) || (searchURL2.EndsWith("/") && searchURL2.IndexOf("/") == searchURL2.LastIndexOf("/"))) &&
435+
((newSearchURL2.StartsWith("/") && newSearchURL2.IndexOf("/") == newSearchURL2.LastIndexOf("/")) || (newSearchURL2.EndsWith("/") && newSearchURL2.IndexOf("/") == newSearchURL2.LastIndexOf("/"))) &&
436+
(searchURL2.Replace("/", string.Empty).ToLowerInvariant() == newSearchURL2.Replace("/", string.Empty).ToLowerInvariant()))
417437
{
418438
return;
419439
}
420440

421-
if (searchURL != newSearchURL)
441+
if (searchURL2 != newSearchURL2)
422442
{
423-
string urlTail = searchURL.Replace(newSearchURL, string.Empty);
443+
string urlTail = searchURL2.Replace(newSearchURL2, string.Empty);
424444
if (urlTail.StartsWith("/"))
425445
{
426446
urlTail = urlTail.Substring(1);

0 commit comments

Comments
 (0)