Skip to content

Commit

Permalink
Created SubmitPostResult as a result when posting post to database, i…
Browse files Browse the repository at this point in the history
…ssue #11
  • Loading branch information
Ilpo Juvander committed Mar 24, 2017
1 parent 6aeed6a commit 6dbd1a1
Show file tree
Hide file tree
Showing 7 changed files with 230 additions and 142 deletions.
23 changes: 0 additions & 23 deletions branches/DNN_5/Components/Configuration/Enums.vb
Original file line number Diff line number Diff line change
Expand Up @@ -775,27 +775,4 @@ Namespace DotNetNuke.Modules.Forum
Inline = 8
End Enum

''' <summary>
''' Provides the status of an attempted post.
''' </summary>
''' <remarks></remarks>
Public Enum PostMessage
ForumClosed = 0
ForumDoesntExist = 1
ForumIsParent = 2
ForumNoAttachments = 3
PostApproved = 4
PostEditExpired = 5
PostInvalidBody = 6
PostInvalidSubject = 7
PostModerated = 8
ThreadLocked = 9
UserAttachmentPerms = 10
UserBanned = 11
UserCannotEditPost = 12
UserCannotPostReply = 13
UserCannotStartThread = 14
UserCannotViewForum = 15
End Enum

End Namespace
130 changes: 96 additions & 34 deletions branches/DNN_5/Components/Content/PostConnector.vb

Large diffs are not rendered by default.

147 changes: 74 additions & 73 deletions branches/DNN_5/Components/UI/Posts.vb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Option Explicit On
Imports DotNetNuke.Entities.Users
Imports DotNetNuke.Services.FileSystem
Imports DotNetNuke.Forum.Library
Imports DotNetNuke.Forum.Library.Data

Namespace DotNetNuke.Modules.Forum

Expand Down Expand Up @@ -347,7 +348,7 @@ Namespace DotNetNuke.Modules.Forum
End If

Dim cntPostConnect As New PostConnector
Dim PostMessage As PostMessage
Dim PostMessage As SubmitPostResult

Dim textReply As String = txtQuickReply.Text

Expand All @@ -359,8 +360,8 @@ Namespace DotNetNuke.Modules.Forum

PostMessage = cntPostConnect.SubmitInternalPost(TabID, ModuleID, PortalID, CurrentForumUser.UserID, strSubject, textReply, ForumID, objThread.ThreadID, -1, objThread.IsPinned, False, False, objThread.ThreadStatus, "", RemoteAddress, objThread.PollID, False, objThread.ThreadID, objThread.Terms)

Select Case PostMessage
Case PostMessage.PostApproved
Select Case PostMessage.Result
Case DotNetNuke.Forum.Library.Data.PostMessage.PostApproved
' Dim ReturnURL As String = NavigateURL()

' If objModSecurity.IsModerator Then
Expand All @@ -374,7 +375,7 @@ Namespace DotNetNuke.Modules.Forum
' End If

' Response.Redirect(ReturnURL, False)
Case PostMessage.PostModerated
Case DotNetNuke.Forum.Library.Data.PostMessage.PostModerated
'tblNewPost.Visible = False
'tblOldPost.Visible = False
'tblPreview.Visible = False
Expand Down Expand Up @@ -519,106 +520,106 @@ Namespace DotNetNuke.Modules.Forum
End If
End If

' If the thread info is nothing, it is probably a deleted thread
If objThread Is Nothing Then
' we should consider setting type of redirect here?
' If the thread info is nothing, it is probably a deleted thread
If objThread Is Nothing Then
' we should consider setting type of redirect here?

MyBase.BasePage.Response.Redirect(Utilities.Links.NoContentLink(TabID, ModuleID), True)
End If
MyBase.BasePage.Response.Redirect(Utilities.Links.NoContentLink(TabID, ModuleID), True)
End If

' Make sure the forum is active
If Not objThread.ContainingForum.IsActive Then
' we should consider setting type of redirect here?

MyBase.BasePage.Response.Redirect(Utilities.Links.NoContentLink(TabID, ModuleID), True)
End If

' Make sure the forum is active
If Not objThread.ContainingForum.IsActive Then
' User might access this page by typing url so better check permission on parent forum
If Not (objThread.ContainingForum.PublicView) Then
If Not objSecurity.IsAllowedToViewPrivateForum Then
' we should consider setting type of redirect here?

MyBase.BasePage.Response.Redirect(Utilities.Links.NoContentLink(TabID, ModuleID), True)
MyBase.BasePage.Response.Redirect(Utilities.Links.UnAuthorizedLink(), True)
End If
End If

' User might access this page by typing url so better check permission on parent forum
If Not (objThread.ContainingForum.PublicView) Then
If Not objSecurity.IsAllowedToViewPrivateForum Then
' we should consider setting type of redirect here?
If objConfig.OverrideTitle Then
Dim Title As String
Dim Subject As String

MyBase.BasePage.Response.Redirect(Utilities.Links.UnAuthorizedLink(), True)
End If
If objThread.Subject.Length > Constants.SEO_TITLE_LIMIT Then
Subject = objThread.Subject.Substring(0, Constants.SEO_TITLE_LIMIT)
Else
Subject = objThread.Subject
End If

If objConfig.OverrideTitle Then
Dim Title As String
Dim Subject As String

If objThread.Subject.Length > Constants.SEO_TITLE_LIMIT Then
Subject = objThread.Subject.Substring(0, Constants.SEO_TITLE_LIMIT)
Else
Subject = objThread.Subject
End If
If Not Subject.Length > Constants.SEO_TITLE_LIMIT Then
Title = Subject

Subject += " - " & objThread.ContainingForum.Name
If Not Subject.Length > Constants.SEO_TITLE_LIMIT Then
Title = Subject

Subject += " - " & objThread.ContainingForum.Name
Subject += " - " & Me.BaseControl.PortalName
If Not Subject.Length > Constants.SEO_TITLE_LIMIT Then
Title = Subject

Subject += " - " & Me.BaseControl.PortalName
If Not Subject.Length > Constants.SEO_TITLE_LIMIT Then
Title = Subject
End If
End If
Else
Title = Subject
End If

MyBase.BasePage.Title = Title
Else
Title = Subject
End If

If objConfig.OverrideDescription Then
Dim Description As String
MyBase.BasePage.Title = Title
End If

If objThread.Subject.Length < Constants.SEO_DESCRIPTION_LIMIT Then
Description = objThread.Subject
Else
Description = objThread.Subject.Substring(0, Constants.SEO_DESCRIPTION_LIMIT)
End If
If objConfig.OverrideDescription Then
Dim Description As String

MyBase.BasePage.Description = Description
If objThread.Subject.Length < Constants.SEO_DESCRIPTION_LIMIT Then
Description = objThread.Subject
Else
Description = objThread.Subject.Substring(0, Constants.SEO_DESCRIPTION_LIMIT)
End If

If objConfig.OverrideKeyWords Then
Dim KeyWords As String = ""
Dim keyCount As Integer = 0
MyBase.BasePage.Description = Description
End If

If objThread.ContainingForum.ParentID = 0 Then
KeyWords = objThread.ContainingForum.Name
keyCount = 1
Else
KeyWords = objThread.ContainingForum.ParentForum.Name + "," + objThread.ContainingForum.Name
keyCount = 2
End If
If objConfig.OverrideKeyWords Then
Dim KeyWords As String = ""
Dim keyCount As Integer = 0

If objConfig.EnableTagging Then
For Each Term As Entities.Content.Taxonomy.Term In objThread.Terms
If keyCount < Constants.SEO_KEYWORDS_LIMIT Then
KeyWords += "," + Term.Name
keyCount += 1
Else
Exit For
End If
Next
If objThread.ContainingForum.ParentID = 0 Then
KeyWords = objThread.ContainingForum.Name
keyCount = 1
Else
KeyWords = objThread.ContainingForum.ParentForum.Name + "," + objThread.ContainingForum.Name
keyCount = 2
End If

' If we haven't hit the keyword limit, let's add portal name to the list.
If objConfig.EnableTagging Then
For Each Term As Entities.Content.Taxonomy.Term In objThread.Terms
If keyCount < Constants.SEO_KEYWORDS_LIMIT Then
KeyWords += "," + Me.BaseControl.PortalName
KeyWords += "," + Term.Name
keyCount += 1
Else
Exit For
End If
End If
Next

MyBase.BasePage.KeyWords = KeyWords
' If we haven't hit the keyword limit, let's add portal name to the list.
If keyCount < Constants.SEO_KEYWORDS_LIMIT Then
KeyWords += "," + Me.BaseControl.PortalName
End If
End If

If PostPage > 0 Then
PostPage = PostPage - 1
Else
PostPage = 0
End If
MyBase.BasePage.KeyWords = KeyWords
End If

If PostPage > 0 Then
PostPage = PostPage - 1
Else
PostPage = 0
End If
End Sub

''' <summary>
Expand Down
22 changes: 11 additions & 11 deletions branches/DNN_5/Forum_PostEdit.ascx.vb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
Option Strict On
Option Explicit On
'
' DotNetNuke® - http://www.dotnetnuke.com
' Copyright (c) 2002-2011
Expand All @@ -17,9 +19,7 @@
' CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
' DEALINGS IN THE SOFTWARE.
'
Option Strict On
Option Explicit On

Imports DotNetNuke.Forum.Library.Data
Imports DotNetNuke.Modules.Forum.Utilities

Namespace DotNetNuke.Modules.Forum
Expand Down Expand Up @@ -450,7 +450,7 @@ Namespace DotNetNuke.Modules.Forum
If ViewState("PostContent") IsNot Nothing Then
teContent.Text = ViewState("PostContent").ToString()
Else
DotNetNuke.UI.Skins.Skin.AddModuleMessage(Me, Localization.GetString(Forum.PostMessage.PostInvalidBody.ToString() + ".Text", LocalResourceFile), Skins.Controls.ModuleMessage.ModuleMessageType.RedError)
DotNetNuke.UI.Skins.Skin.AddModuleMessage(Me, Localization.GetString(DotNetNuke.Forum.Library.Data.PostMessage.PostInvalidBody.ToString() + ".Text", LocalResourceFile), Skins.Controls.ModuleMessage.ModuleMessageType.RedError)
Exit Sub
End If
End If
Expand All @@ -475,15 +475,15 @@ Namespace DotNetNuke.Modules.Forum

' Validation (from UI)
If Len(teContent.Text) = 0 Then
DotNetNuke.UI.Skins.Skin.AddModuleMessage(Me, Localization.GetString(Forum.PostMessage.PostInvalidBody.ToString() + ".Text", LocalResourceFile), Skins.Controls.ModuleMessage.ModuleMessageType.RedError)
DotNetNuke.UI.Skins.Skin.AddModuleMessage(Me, Localization.GetString(DotNetNuke.Forum.Library.Data.PostMessage.PostInvalidBody.ToString() + ".Text", LocalResourceFile), Skins.Controls.ModuleMessage.ModuleMessageType.RedError)
Exit Sub
End If
If Len(txtSubject.Text) = 0 Then
DotNetNuke.UI.Skins.Skin.AddModuleMessage(Me, Localization.GetString(Forum.PostMessage.PostInvalidSubject.ToString() + ".Text", LocalResourceFile), Skins.Controls.ModuleMessage.ModuleMessageType.RedError)
DotNetNuke.UI.Skins.Skin.AddModuleMessage(Me, Localization.GetString(DotNetNuke.Forum.Library.Data.PostMessage.PostInvalidSubject.ToString() + ".Text", LocalResourceFile), Skins.Controls.ModuleMessage.ModuleMessageType.RedError)
Exit Sub
End If
If ddlForum.SelectedItem Is Nothing Or ddlForum.SelectedItem.Value = "-1" Then
DotNetNuke.UI.Skins.Skin.AddModuleMessage(Me, Localization.GetString(Forum.PostMessage.ForumDoesntExist.ToString() + ".Text", LocalResourceFile), Skins.Controls.ModuleMessage.ModuleMessageType.RedError)
DotNetNuke.UI.Skins.Skin.AddModuleMessage(Me, Localization.GetString(DotNetNuke.Forum.Library.Data.PostMessage.ForumDoesntExist.ToString() + ".Text", LocalResourceFile), Skins.Controls.ModuleMessage.ModuleMessageType.RedError)
Exit Sub
End If

Expand Down Expand Up @@ -578,12 +578,12 @@ Namespace DotNetNuke.Modules.Forum
End If

Dim cntPostConnect As New PostConnector
Dim PostMessage As PostMessage
Dim PostMessage As SubmitPostResult

PostMessage = cntPostConnect.SubmitInternalPost(TabId, ModuleId, PortalId, CurrentForumUser.UserID, txtSubject.Text, teContent.Text, objForum.ForumID, ParentPostID, PostID, chkIsPinned.Checked, chkIsClosed.Checked, chkNotify.Checked, ThreadStatus, ctlAttachment.lstAttachmentIDs, RemoteAddress, PollID, IsQuote, ThreadID, Terms)

Select Case PostMessage
Case PostMessage.PostApproved
Select Case PostMessage.Result
Case DotNetNuke.Forum.Library.Data.PostMessage.PostApproved
Dim ReturnURL As String = NavigateURL()

If objModSecurity.IsModerator Then
Expand All @@ -601,7 +601,7 @@ Namespace DotNetNuke.Modules.Forum
End If

Response.Redirect(ReturnURL, False)
Case PostMessage.PostModerated
Case DotNetNuke.Forum.Library.Data.PostMessage.PostModerated
divNewPost.Visible = False
tblOldPost.Visible = False
tblPreview.Visible = False
Expand Down
5 changes: 4 additions & 1 deletion branches/DNN_5/ReleaseNotes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
</p>
<ul>
<li>Support for Journal with general setting to enable/disable journal entries from being created</li>
<li>Issue #8 fixed</li>
<li>Issue #8 fixed</li>
<li>Marked one of the SubmitExternalPost as Obsole and this will be removed totally in next release (Issue #9)</li>
<li>Added another SubmitExternalPost to allow IsPinned (Issue #11)</li>
<li>Returning SubmitPostResult from post to database which includes postid and result (Issue #11)</li>
</ul>
<br />
<p class="Owner">
Expand Down
44 changes: 44 additions & 0 deletions branches/DotNetNuke.Forum.Library/Data/SubmitPostResult.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DotNetNuke.Forum.Library.Data
{
public enum PostMessage
{
ForumClosed = 0,
ForumDoesntExist = 1,
ForumIsParent = 2,
ForumNoAttachments = 3,
PostApproved = 4,
PostEditExpired = 5,
PostInvalidBody = 6,
PostInvalidSubject = 7,
PostModerated = 8,
ThreadLocked = 9,
UserAttachmentPerms = 10,
UserBanned = 11,
UserCannotEditPost = 12,
UserCannotPostReply = 13,
UserCannotStartThread = 14,
UserCannotViewForum = 15
};

/// <summary>
/// Struct to return result after post is submitted to db
/// </summary>
public class SubmitPostResult
{
/// <summary>
/// PostId of either existing or new post that was submitted.
/// Note that depending on the Result returned this value may or may not be actual PostId found in database.
/// </summary>
public int PostId;
/// <summary>
/// Post result
/// </summary>
public PostMessage Result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Data\SubmitPostResult.cs" />
<Compile Include="FileUtilityClass.cs" />
<Compile Include="JournalUtilityClass.cs" />
<Compile Include="PortalUtilityClass.cs" />
Expand Down

0 comments on commit 6dbd1a1

Please sign in to comment.