Skip to content

Commit 6682564

Browse files
authored
Merge pull request #1364 from johnhenley/issues/module-load-exceptions-1333
FIX: Refactor to avoid intermittant exceptions when replying
2 parents 7dd0c24 + ee6115f commit 6682564

File tree

1 file changed

+45
-55
lines changed

1 file changed

+45
-55
lines changed

Dnn.CommunityForums/controls/af_post.ascx.cs

+45-55
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ private void PrepareReply()
531531
this.ctlForm.EditorMode = Modules.ActiveForums.Controls.SubmitForm.EditorModes.Reply;
532532

533533
string template = TemplateCache.GetCachedTemplate(this.ForumModuleId, "ReplyEditor", this.ForumInfo.FeatureSettings.ReplyFormId);
534-
534+
535535
#region "Backward compatilbility -- remove in v10.00.00"
536536
template = DotNetNuke.Modules.ActiveForums.Services.Tokens.TokenReplacer.MapLegacyAuthorTokenSynonyms(new StringBuilder(template), this.PortalSettings, this.MainSettings, this.ForumUser.UserInfo?.Profile?.PreferredLocale).ToString();
537537
template = DotNetNuke.Modules.ActiveForums.Services.Tokens.TokenReplacer.MapLegacyPostTokenSynonyms(new StringBuilder(template), this.PortalSettings, this.ForumUser.UserInfo?.Profile?.PreferredLocale).ToString();
@@ -585,7 +585,6 @@ private void PrepareReply()
585585
// Setup form for Quote or Reply with body display
586586
var isQuote = false;
587587
var postId = 0;
588-
var sPostedBy = Utilities.GetSharedResource("[RESX:PostedBy]") + " {0} {1} {2}";
589588
if (this.Request.Params[ParamKeys.QuoteId] != null)
590589
{
591590
isQuote = true;
@@ -611,71 +610,62 @@ private void PrepareReply()
611610

612611
if (postId != 0)
613612
{
614-
var userDisplay = this.MainSettings.UserNameDisplay;
615-
if (this.editorType == EditorTypes.TEXTBOX)
616-
{
617-
userDisplay = "none";
618-
}
619-
620-
DotNetNuke.Modules.ActiveForums.Entities.ContentInfo ci;
621-
if (postId == TopicId)
622-
{
623-
ci = ti.Content;
624-
}
625-
else
626-
{
627-
var ri = new DotNetNuke.Modules.ActiveForums.Controllers.ReplyController(this.ForumModuleId).GetById(postId);
628-
ci = ri.Content;
629-
}
630-
631-
if (ci != null)
632-
{
633-
body = ci.Body;
634-
}
635-
636613
var post = postId == this.TopicId ? ti : (DotNetNuke.Modules.ActiveForums.Entities.IPostInfo)new DotNetNuke.Modules.ActiveForums.Controllers.ReplyController(this.ForumModuleId).GetById(postId);
637-
sPostedBy = string.Format(sPostedBy, DotNetNuke.Modules.ActiveForums.Controllers.ForumUserController.GetDisplayName(this.PortalSettings, this.MainSettings, false, false, post.Author.AuthorId, post.Author.Username, post.Author.FirstName, post.Author.LastName, post.Author.DisplayName), Utilities.GetSharedResource("On.Text"), Utilities.GetUserFormattedDateTime(post.Content.DateCreated, this.PortalId, this.UserId));
638-
}
639-
640-
if (this.allowHTML && this.editorType != EditorTypes.TEXTBOX)
641-
{
642-
if (body.ToUpper().Contains("<CODE") | body.ToUpper().Contains("[CODE]"))
614+
if (post != null)
643615
{
644-
var objCode = new CodeParser();
645-
body = CodeParser.ParseCode(System.Net.WebUtility.HtmlDecode(body));
646-
}
647-
}
648-
else
649-
{
650-
body = Utilities.PrepareForEdit(this.PortalId, this.ForumModuleId, this.ImagePath, body, this.allowHTML, this.editorType);
651-
}
652-
653-
if (isQuote)
654-
{
655-
this.ctlForm.EditorMode = SubmitForm.EditorModes.Quote;
656-
if (this.allowHTML && this.editorType != EditorTypes.TEXTBOX)
657-
{
658-
body = "<blockquote>" + System.Environment.NewLine + sPostedBy + System.Environment.NewLine + "<br />" + System.Environment.NewLine + body + System.Environment.NewLine + "</blockquote><br /><br />";
616+
var sPostedBy = Utilities.GetSharedResource("[RESX:PostedBy]") + " {0} {1} {2}";
617+
sPostedBy = string.Format(sPostedBy, DotNetNuke.Modules.ActiveForums.Controllers.ForumUserController.GetDisplayName(this.PortalSettings, this.MainSettings, false, false, post.Author.AuthorId, post.Author.Username, post.Author.FirstName, post.Author.LastName, post.Author.DisplayName), Utilities.GetSharedResource("On.Text"), Utilities.GetUserFormattedDateTime(post.Content.DateCreated, this.PortalId, this.UserId));
618+
body = post.Content.Body;
619+
if (this.allowHTML && this.editorType != EditorTypes.TEXTBOX)
620+
{
621+
if (body.ToUpperInvariant().Contains("<CODE") || body.ToUpperInvariant().Contains("[CODE]"))
622+
{
623+
body = CodeParser.ParseCode(System.Net.WebUtility.HtmlDecode(body));
624+
}
625+
}
626+
else
627+
{
628+
body = Utilities.PrepareForEdit(this.PortalId, this.ForumModuleId, this.ImagePath, body, this.allowHTML, this.editorType);
629+
}
630+
631+
if (isQuote)
632+
{
633+
this.ctlForm.EditorMode = SubmitForm.EditorModes.Quote;
634+
if (this.allowHTML && this.editorType != EditorTypes.TEXTBOX)
635+
{
636+
body = "<blockquote>" + System.Environment.NewLine + sPostedBy + System.Environment.NewLine + "<br />" + System.Environment.NewLine + body + System.Environment.NewLine + "</blockquote><br /><br />";
637+
}
638+
else
639+
{
640+
body = "[quote]" + System.Environment.NewLine + sPostedBy + System.Environment.NewLine + body + System.Environment.NewLine + "[/quote]" + System.Environment.NewLine;
641+
}
642+
}
643+
else
644+
{
645+
this.ctlForm.EditorMode = SubmitForm.EditorModes.ReplyWithBody;
646+
body = sPostedBy + "<br />" + body;
647+
}
648+
649+
this.ctlForm.Body = body;
650+
651+
if (this.ctlForm.EditorMode != SubmitForm.EditorModes.EditReply && this.canModApprove)
652+
{
653+
this.ctlForm.ShowModOptions = false;
654+
}
659655
}
660656
else
661657
{
662-
body = "[quote]" + System.Environment.NewLine + sPostedBy + System.Environment.NewLine + body + System.Environment.NewLine + "[/quote]" + System.Environment.NewLine;
658+
var im = new InfoMessage { Message = this.GetSharedResource("[RESX:Message:LoadTopicFailed]") };
659+
this.plhContent.Controls.Add(im);
663660
}
664661
}
665662
else
666663
{
667-
this.ctlForm.EditorMode = SubmitForm.EditorModes.ReplyWithBody;
668-
body = sPostedBy + "<br />" + body;
664+
var im = new InfoMessage { Message = this.GetSharedResource("[RESX:Message:LoadTopicFailed]") };
665+
this.plhContent.Controls.Add(im);
669666
}
670-
671-
this.ctlForm.Body = body;
672667
}
673668
}
674-
675-
if (this.ctlForm.EditorMode != SubmitForm.EditorModes.EditReply && this.canModApprove)
676-
{
677-
this.ctlForm.ShowModOptions = false;
678-
}
679669
}
680670

681671
private void SaveTopic()

0 commit comments

Comments
 (0)