-
Notifications
You must be signed in to change notification settings - Fork 24
/
LatestComments.ascx.vb
executable file
·243 lines (175 loc) · 9.62 KB
/
LatestComments.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
Imports DotNetNuke.Common.Utilities
Imports DotNetNuke.Entities.Modules
Imports DotNetNuke.Services.Exceptions
Imports Ventrian.NewsArticles.Base
Namespace Ventrian.NewsArticles
Partial Public Class LatestComments
Inherits NewsArticleModuleBase
#Region " Private Members "
Private _objLayoutController As LayoutController
Private _objLayoutHeader As LayoutInfo
Private _objLayoutItem As LayoutInfo
Private _objLayoutFooter As LayoutInfo
Private _articleTabID As Integer = Null.NullInteger
Private _articleTabInfo As DotNetNuke.Entities.Tabs.TabInfo
Private _articleModuleID As Integer = Null.NullInteger
Private _articleSettings As ArticleSettings
#End Region
#Region " Private Properties "
Public Shadows ReadOnly Property ArticleSettings() As ArticleSettings
Get
If (_articleSettings Is Nothing) Then
Dim _settings As Hashtable = Common.GetModuleSettings(_articleModuleID)
Dim objModuleController As New ModuleController
Dim objModule As ModuleInfo = objModuleController.GetModule(_articleModuleID, _articleTabID)
If Not (objModule Is Nothing) Then
Dim objSettings As Hashtable = objModule.TabModuleSettings
For Each key As String In objSettings.Keys
If (_settings.ContainsKey(key) = False) Then
_settings.Add(key, objSettings(key))
End If
Next
End If
_articleSettings = New ArticleSettings(_settings, Me.PortalSettings, Me.ModuleConfiguration)
End If
Return _articleSettings
End Get
End Property
Private ReadOnly Property ArticleTabInfo() As DotNetNuke.Entities.Tabs.TabInfo
Get
If (_articleTabInfo Is Nothing) Then
Dim objTabController As New DotNetNuke.Entities.Tabs.TabController
_articleTabInfo = objTabController.GetTab(_articleTabID, Me.PortalId, False)
End If
Return _articleTabInfo
End Get
End Property
Private Sub BindComments()
Dim objModuleController As New ModuleController()
Dim objModule As ModuleInfo = objModuleController.GetModule(_articleModuleID, _articleTabID)
_objLayoutController = New LayoutController(PortalSettings, ArticleSettings, objModule, Page)
Dim layoutHeader As String
If (Settings.Contains(ArticleConstants.LATEST_COMMENTS_HTML_HEADER)) Then
layoutHeader = Settings(ArticleConstants.LATEST_COMMENTS_HTML_HEADER).ToString()
Else
layoutHeader = ArticleConstants.DEFAULT_LATEST_COMMENTS_HTML_HEADER
End If
_objLayoutHeader = _objLayoutController.GetLayoutObject(layoutHeader)
Dim layoutItem As String
If (Settings.Contains(ArticleConstants.LATEST_COMMENTS_HTML_BODY)) Then
layoutItem = Settings(ArticleConstants.LATEST_COMMENTS_HTML_BODY).ToString()
Else
layoutItem = ArticleConstants.DEFAULT_LATEST_COMMENTS_HTML_BODY
End If
_objLayoutItem = _objLayoutController.GetLayoutObject(layoutItem)
Dim layoutFooter As String
If (Settings.Contains(ArticleConstants.LATEST_COMMENTS_HTML_FOOTER)) Then
layoutFooter = Settings(ArticleConstants.LATEST_COMMENTS_HTML_FOOTER).ToString()
Else
layoutFooter = ArticleConstants.DEFAULT_LATEST_COMMENTS_HTML_FOOTER
End If
_objLayoutFooter = _objLayoutController.GetLayoutObject(layoutFooter)
Dim count As Integer = 10
If (Settings.Contains(ArticleConstants.LATEST_COMMENTS_COUNT)) Then
count = Convert.ToInt32(Settings(ArticleConstants.LATEST_COMMENTS_COUNT).ToString())
End If
Dim objCommentController As New CommentController
rptLatestComments.DataSource = objCommentController.GetCommentList(_articleModuleID, Null.NullInteger, True, SortDirection.Descending, count)
rptLatestComments.DataBind()
If (rptLatestComments.Items.Count = 0) Then
phNoComments.Visible = True
rptLatestComments.Visible = False
Dim noComments As String = ArticleConstants.DEFAULT_LATEST_COMMENTS_HTML_NO_COMMENTS
If (Settings.Contains(ArticleConstants.LATEST_COMMENTS_HTML_NO_COMMENTS)) Then
noComments = Settings(ArticleConstants.LATEST_COMMENTS_HTML_NO_COMMENTS).ToString()
End If
noComments = "<div id=""NoRecords"" class=""Normal"">" & noComments & "</div>"
Dim objNoComments As LayoutInfo = _objLayoutController.GetLayoutObject(noComments)
ProcessHeaderFooter(phNoComments.Controls, objNoComments.Tokens)
End If
End Sub
Private Sub ProcessBody(ByRef controls As ControlCollection, ByVal objComment As CommentInfo, ByVal layoutArray As String())
If (ArticleTabInfo Is Nothing) Then
Return
End If
Dim objArticleController As New ArticleController
Dim objArticle As ArticleInfo = objArticleController.GetArticle(objComment.ArticleID)
_objLayoutController.ProcessComment(controls, objArticle, objComment, _objLayoutItem.Tokens)
End Sub
Private Sub ProcessHeaderFooter(ByRef controls As ControlCollection, ByVal layoutArray As String())
For iPtr As Integer = 0 To layoutArray.Length - 1 Step 2
controls.Add(New LiteralControl(layoutArray(iPtr).ToString()))
If iPtr < layoutArray.Length - 1 Then
Select Case layoutArray(iPtr + 1)
Case Else
Dim objLiteralOther As New Literal
objLiteralOther.Text = "[" & layoutArray(iPtr + 1) & "]"
objLiteralOther.EnableViewState = False
controls.Add(objLiteralOther)
End Select
End If
Next
End Sub
#End Region
#Region " Private Methods "
Private Function FindSettings() As Boolean
If (Settings.Contains(ArticleConstants.LATEST_COMMENTS_TAB_ID)) Then
If (IsNumeric(Settings(ArticleConstants.LATEST_COMMENTS_TAB_ID).ToString())) Then
_articleTabID = Convert.ToInt32(Settings(ArticleConstants.LATEST_COMMENTS_TAB_ID).ToString())
End If
End If
If (Settings.Contains(ArticleConstants.LATEST_COMMENTS_MODULE_ID)) Then
If (IsNumeric(Settings(ArticleConstants.LATEST_COMMENTS_MODULE_ID).ToString())) Then
_articleModuleID = Convert.ToInt32(Settings(ArticleConstants.LATEST_COMMENTS_MODULE_ID).ToString())
If (_articleModuleID <> Null.NullInteger) Then
Return True
End If
End If
End If
Return False
End Function
#End Region
#Region " Event Handlers "
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Try
If (FindSettings()) Then
BindComments()
Else
lblNotConfigured.Visible = True
rptLatestComments.Visible = False
End If
Catch exc As Exception 'Module failed to load
ProcessModuleLoadException(Me, exc)
End Try
End Sub
Private Sub Page_PreRender(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.PreRender
Try
If (_articleTabID <> Null.NullInteger) Then
If (Settings.Contains(ArticleConstants.LATEST_COMMENTS_INCLUDE_STYLESHEET)) Then
If (Convert.ToBoolean(Settings(ArticleConstants.LATEST_COMMENTS_INCLUDE_STYLESHEET).ToString())) Then
LoadStyleSheet()
End If
End If
End If
Catch exc As Exception 'Module failed to load
ProcessModuleLoadException(Me, exc)
End Try
End Sub
Private Sub rptLatestComments_OnItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles rptLatestComments.ItemDataBound
Try
If (e.Item.ItemType = ListItemType.Header) Then
ProcessHeaderFooter(e.Item.Controls, _objLayoutHeader.Tokens())
End If
If (e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem) Then
ProcessBody(e.Item.Controls, CType(e.Item.DataItem, CommentInfo), _objLayoutItem.Tokens)
End If
If (e.Item.ItemType = ListItemType.Footer) Then
ProcessHeaderFooter(e.Item.Controls, _objLayoutFooter.Tokens())
End If
Catch exc As Exception 'Module failed to load
ProcessModuleLoadException(Me, exc)
End Try
End Sub
#End Region
End Class
End Namespace