forked from ventrian/News-Articles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathucApproveComments.ascx.vb
executable file
·386 lines (288 loc) · 21.3 KB
/
ucApproveComments.ascx.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
Imports DotNetNuke.Common.Utilities
Imports DotNetNuke.Services.Exceptions
Imports Ventrian.NewsArticles.Components.Social
Imports Ventrian.NewsArticles.Base
Namespace Ventrian.NewsArticles
Partial Public Class ucApproveComments
Inherits NewsArticleModuleBase
#Region " Private Methods "
Private Sub BindComments()
Dim objCommentController As New CommentController
rptApproveComments.DataSource = objCommentController.GetCommentList(Me.ModuleId, Null.NullInteger, False, SortDirection.Ascending, Null.NullInteger)
rptApproveComments.DataBind()
If (rptApproveComments.Items.Count = 0) Then
rptApproveComments.Visible = False
lblNoComments.Visible = True
End If
End Sub
Private Sub CheckSecurity()
If (Request.IsAuthenticated = False) Then
Response.Redirect(Common.GetModuleLink(Me.TabId, Me.ModuleId, "NotAuthenticated", ArticleSettings), True)
End If
If (ArticleSettings.IsApprover) Then
Return
End If
Response.Redirect(Common.GetModuleLink(Me.TabId, Me.ModuleId, "NotAuthorized", ArticleSettings), True)
End Sub
Private Sub NotifyAuthor(ByVal objComment As CommentInfo)
Dim objArticleController As New ArticleController
Dim objArticle As ArticleInfo = objArticleController.GetArticle(objComment.ArticleID)
If Not (objArticle Is Nothing) Then
Dim objEmailTemplateController As New EmailTemplateController
Try
' Don't send it to the author if it's their own comment.
If (objArticle.AuthorID <> objComment.UserID) Then
objEmailTemplateController.SendFormattedEmail(Me.ModuleId, Common.GetArticleLink(objArticle, PortalSettings.ActiveTab, ArticleSettings, False), objArticle, objComment, EmailTemplateType.CommentNotification, ArticleSettings)
End If
Catch ex As Exception
Dim objEventLog As New DotNetNuke.Services.Log.EventLog.EventLogController
Dim objUserController As New DotNetNuke.Entities.Users.UserController
Dim objUser As DotNetNuke.Entities.Users.UserInfo = objUserController.GetUser(Me.PortalId, objArticle.AuthorID)
Dim sendTo As String = ""
If Not (objUser Is Nothing) Then
sendTo = objUser.Email
End If
objEventLog.AddLog("News Articles Email Failure", "Failure to send [Author Comment] to '" & sendTo & "' from '" & Me.PortalSettings.Email, PortalSettings, -1, DotNetNuke.Services.Log.EventLog.EventLogController.EventLogType.ADMIN_ALERT)
End Try
End If
End Sub
#End Region
#Region " Protected Methods "
Protected Function GetAuthor(ByVal obj As Object) As String
Dim objComment As CommentInfo = CType(obj, CommentInfo)
If Not (objComment Is Nothing) Then
If (objComment.UserID <> Null.NullInteger) Then
Return objComment.AuthorUserName
Else
Return objComment.AnonymousName
End If
Else
Return ""
End If
End Function
Protected Function GetArticleUrl(ByVal obj As Object) As String
Dim objComment As CommentInfo = CType(obj, CommentInfo)
If Not (objComment Is Nothing) Then
Dim objArticleController As New ArticleController
Dim objArticle As ArticleInfo = objArticleController.GetArticle(objComment.ArticleID)
If (objArticle IsNot Nothing) Then
Return Common.GetArticleLink(objArticle, Me.PortalSettings.ActiveTab, Me.ArticleSettings, False)
End If
End If
Return ""
End Function
Protected Function GetEditCommentUrl(ByVal commentID As String) As String
Return Common.GetModuleLink(TabId, ModuleId, "EditComment", ArticleSettings, "CommentID=" & commentID, "ReturnUrl=" & Server.UrlEncode(Request.RawUrl))
End Function
Protected Function GetTitle(ByVal obj As Object) As String
Dim objComment As CommentInfo = CType(obj, CommentInfo)
If Not (objComment Is Nothing) Then
Dim objArticleController As New ArticleController
Dim objArticle As ArticleInfo = objArticleController.GetArticle(objComment.ArticleID)
If (objArticle IsNot Nothing) Then
Return objArticle.Title
End If
End If
Return ""
End Function
Protected Function GetWebsite(ByVal obj As Object) As String
Dim objComment As CommentInfo = CType(obj, CommentInfo)
If Not (objComment Is Nothing) Then
If (objComment.AnonymousURL <> "") Then
Return "<a href='" & DotNetNuke.Common.AddHTTP(objComment.AnonymousURL) & "' target='_blank'>" & objComment.AnonymousURL & "</a>"
End If
End If
Return ""
End Function
#End Region
#Region " Event Handlers "
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Try
CheckSecurity()
If (Page.IsPostBack = False) Then
BindComments()
End If
Catch exc As Exception 'Module failed to load
ProcessModuleLoadException(Me, exc)
End Try
End Sub
Private Sub rptApproveComments_OnItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles rptApproveComments.ItemDataBound
If (e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem) Then
Dim objComment As CommentInfo = CType(e.Item.DataItem, CommentInfo)
If (objComment IsNot Nothing) Then
Dim chkSelected As CheckBox = CType(e.Item.FindControl("chkSelected"), CheckBox)
chkSelected.Attributes.Add("CommentID", objComment.CommentID.ToString())
End If
End If
End Sub
Protected Sub cmdApprove_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdApprove.Click
For Each item As RepeaterItem In rptApproveComments.Items
If (item.ItemType = ListItemType.Item Or item.ItemType = ListItemType.AlternatingItem) Then
Dim chkSelected As CheckBox = CType(item.FindControl("chkSelected"), CheckBox)
If Not (chkSelected Is Nothing) Then
If (chkSelected.Checked) Then
Dim commentID As Integer = Convert.ToInt32(chkSelected.Attributes("CommentID").ToString())
Dim objCommentController As New CommentController()
Dim objComment As CommentInfo = objCommentController.GetComment(commentID)
If Not (objComment Is Nothing) Then
objComment.IsApproved = True
objComment.ApprovedBy = Me.UserId
objCommentController.UpdateComment(objComment)
Dim objEmailTemplateController As New EmailTemplateController()
If (ArticleSettings.NotifyAuthorOnApproval) Then
NotifyAuthor(objComment)
End If
Dim objArticleController As New ArticleController
Dim objArticle As ArticleInfo = objArticleController.GetArticle(objComment.ArticleID)
If Not (objArticle Is Nothing) Then
If (ArticleSettings.EnableActiveSocialFeed And objComment.UserID <> Null.NullInteger) Then
If (ArticleSettings.ActiveSocialCommentKey <> "") Then
If IO.File.Exists(HttpContext.Current.Server.MapPath("~/bin/active.modules.social.dll")) Then
Dim ai As Object = Nothing
Dim asm As System.Reflection.Assembly
Dim ac As Object = Nothing
Try
asm = System.Reflection.Assembly.Load("Active.Modules.Social")
ac = asm.CreateInstance("Active.Modules.Social.API.Journal")
If Not ac Is Nothing Then
ac.AddProfileItem(New Guid(ArticleSettings.ActiveSocialCommentKey), objComment.UserID, Common.GetArticleLink(objArticle, PortalSettings.ActiveTab, ArticleSettings, False), objArticle.Title, objComment.Comment, objComment.Comment, 1, "")
End If
Catch ex As Exception
End Try
End If
End If
End If
If (Request.IsAuthenticated) Then
If (ArticleSettings.JournalIntegration) Then
Dim objJournal As New Journal
objJournal.AddCommentToJournal(objArticle, objComment, PortalId, TabId, UserId, Common.GetArticleLink(objArticle, PortalSettings.ActiveTab, ArticleSettings, False))
End If
End If
If (ArticleSettings.EnableSmartThinkerStoryFeed And objComment.UserID <> Null.NullInteger) Then
Dim objStoryFeed As New wsStoryFeed.StoryFeedWS
objStoryFeed.Url = DotNetNuke.Common.Globals.AddHTTP(Request.ServerVariables("HTTP_HOST") & Me.ResolveUrl("~/DesktopModules/Smart-Thinker%20-%20UserProfile/StoryFeed.asmx"))
Dim val As String = GetSharedResource("StoryFeed-AddComment")
Dim delimStr As String = "[]"
Dim delimiter As Char() = delimStr.ToCharArray()
Dim layoutArray As String() = val.Split(delimiter)
Dim valResult As String = ""
For iPtr As Integer = 0 To layoutArray.Length - 1 Step 2
valResult = valResult & layoutArray(iPtr)
If iPtr < layoutArray.Length - 1 Then
Select Case layoutArray(iPtr + 1)
Case "ARTICLEID"
valResult = valResult & objComment.ArticleID.ToString()
Case "AUTHORID"
valResult = valResult & objComment.UserID.ToString()
Case "AUTHOR"
If (objComment.UserID = Null.NullInteger) Then
valResult = valResult & objComment.AnonymousName
Else
valResult = valResult & objComment.AuthorDisplayName
End If
Case "ARTICLELINK"
valResult = valResult & Common.GetArticleLink(objArticle, PortalSettings.ActiveTab, ArticleSettings, False)
Case "ARTICLETITLE"
valResult = valResult & objArticle.Title
Case "ISANONYMOUS"
If (objComment.UserID <> Null.NullInteger) Then
While (iPtr < layoutArray.Length - 1)
If (layoutArray(iPtr + 1) = "/ISANONYMOUS") Then
Exit While
End If
iPtr = iPtr + 1
End While
End If
Case "/ISANONYMOUS"
' Do Nothing
Case "ISNOTANONYMOUS"
If (objComment.UserID <> Null.NullInteger) Then
While (iPtr < layoutArray.Length - 1)
If (layoutArray(iPtr + 1) = "/ISNOTANONYMOUS") Then
Exit While
End If
iPtr = iPtr + 1
End While
End If
Case "/ISNOTANONYMOUS"
' Do Nothing
End Select
End If
Next
Try
objStoryFeed.AddAction(81, objComment.CommentID, valResult, objComment.UserID, "VE6457624576460436531768")
Catch
End Try
End If
If (ArticleSettings.NotifyEmailOnComment <> "") Then
For Each email As String In ArticleSettings.NotifyEmailOnComment.Split(Convert.ToChar(";"))
If (email <> "") Then
objEmailTemplateController.SendFormattedEmail(Me.ModuleId, Common.GetArticleLink(objArticle, PortalSettings.ActiveTab, ArticleSettings, False), objArticle, objComment, EmailTemplateType.CommentNotification, ArticleSettings, email)
End If
Next
End If
If (ArticleSettings.NotifyAuthorOnApproval) Then
objEmailTemplateController.SendFormattedEmail(Me.ModuleId, Common.GetArticleLink(objArticle, PortalSettings.ActiveTab, ArticleSettings, False), objArticle, objComment, EmailTemplateType.CommentApproved, ArticleSettings)
End If
Dim objMailList As New Hashtable
Dim objComments As List(Of CommentInfo) = objCommentController.GetCommentList(Me.ModuleId, objComment.ArticleID, True, SortDirection.Ascending, Null.NullInteger)
For Each objNotifyComment As CommentInfo In objComments
If (objNotifyComment.CommentID <> objComment.CommentID And objNotifyComment.NotifyMe) Then
If (objNotifyComment.UserID = Null.NullInteger) Then
If (objNotifyComment.AnonymousEmail <> "") Then
Try
If (objMailList.Contains(objNotifyComment.AnonymousEmail) = False) Then
objEmailTemplateController.SendFormattedEmail(Me.ModuleId, Common.GetArticleLink(objArticle, PortalSettings.ActiveTab, ArticleSettings, False), objArticle, objComment, EmailTemplateType.CommentNotification, ArticleSettings, objNotifyComment.AnonymousEmail)
objMailList.Add(objNotifyComment.AnonymousEmail, objNotifyComment.AnonymousEmail)
End If
Catch ex As Exception
Dim objEventLog As New DotNetNuke.Services.Log.EventLog.EventLogController
objEventLog.AddLog("News Articles Email Failure", "Failure to send [Anon Comment] to '" & objNotifyComment.AnonymousEmail & "' from '" & Me.PortalSettings.Email, PortalSettings, -1, DotNetNuke.Services.Log.EventLog.EventLogController.EventLogType.ADMIN_ALERT)
End Try
End If
Else
If (objNotifyComment.AuthorEmail <> "") Then
Try
If (objNotifyComment.UserID <> objComment.UserID) Then
If (objMailList.Contains(objNotifyComment.UserID.ToString()) = False) Then
objEmailTemplateController.SendFormattedEmail(Me.ModuleId, Common.GetArticleLink(objArticle, PortalSettings.ActiveTab, ArticleSettings, False), objArticle, objComment, EmailTemplateType.CommentNotification, ArticleSettings, objNotifyComment.AuthorEmail)
objMailList.Add(objNotifyComment.UserID.ToString(), objNotifyComment.UserID.ToString())
End If
End If
Catch ex As Exception
Dim objEventLog As New DotNetNuke.Services.Log.EventLog.EventLogController
objEventLog.AddLog("News Articles Email Failure", "Failure to send [Author Comment] to '" & objNotifyComment.AuthorEmail & "' from '" & Me.PortalSettings.Email, PortalSettings, -1, DotNetNuke.Services.Log.EventLog.EventLogController.EventLogType.ADMIN_ALERT)
End Try
End If
End If
End If
Next
End If
End If
End If
End If
End If
Next
Response.Redirect(Request.RawUrl, True)
End Sub
Protected Sub cmdReject_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdReject.Click
For Each item As RepeaterItem In rptApproveComments.Items
If (item.ItemType = ListItemType.Item Or item.ItemType = ListItemType.AlternatingItem) Then
Dim chkSelected As CheckBox = CType(item.FindControl("chkSelected"), CheckBox)
If Not (chkSelected Is Nothing) Then
If (chkSelected.Checked) Then
Dim commentID As Integer = Convert.ToInt32(chkSelected.Attributes("CommentID").ToString())
Dim objCommentController As New CommentController()
Dim objComment As CommentInfo = objCommentController.GetComment(commentID)
If Not (objComment Is Nothing) Then
objCommentController.DeleteComment(objComment.CommentID, objComment.ArticleID)
End If
End If
End If
End If
Next
Response.Redirect(Request.RawUrl, True)
End Sub
#End Region
End Class
End Namespace