-
Notifications
You must be signed in to change notification settings - Fork 5
/
EditRss.ascx.vb
339 lines (317 loc) · 10.8 KB
/
EditRss.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
'
' DotNetNuke® - http://www.dotnetnuke.com
' Copyright (c) 2002-2012
' by DotNetNuke Corporation
'
' Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
' documentation files (the "Software"), to deal in the Software without restriction, including without limitation
' the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
' to permit persons to whom the Software is furnished to do so, subject to the following conditions:
'
' The above copyright notice and this permission notice shall be included in all copies or substantial portions
' of the Software.
'
' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
' TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
' THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
' CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
' DEALINGS IN THE SOFTWARE.
'
Imports System.Web.UI.WebControls
Imports DotNetNuke.Common
Imports DotNetNuke.Services.Exceptions
Imports DotNetNuke.Services.Localization.Localization
Imports DotNetNuke.Modules.News.Entities.Feeds
''' <summary>
''' Control to edit the definition of an aggregated feed.
''' </summary>
''' <remarks>
''' </remarks>
''' <history>
''' [pdonker] 03/01/2008 Created
''' </history>
Partial Public Class EditRss
Inherits Modulebase
#Region " Private Members "
Private _opml As String = ""
#End Region
#Region " Public Members "
#End Region
#Region " Controls "
Protected WithEvents ctlXsl As UI.UserControls.UrlControl
#End Region
#Region " Event Handlers "
''' <summary>
''' Called upon Page Load
''' </summary>
''' <param name="sender"></param>
''' <param name="e"></param>
''' <remarks>
''' </remarks>
''' <history>
''' [pdonker] 03/01/2008 Created
''' [pdonker] 24/03/2010 Changed custom transformation to full mapped path
''' </history>
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Try
If Not Page.IsPostBack Then
DotNetNuke.UI.Utilities.ClientAPI.AddButtonConfirm(cmdDelete, DotNetNuke.Services.Localization.Localization.GetString("Delete.Confirm", Me.LocalResourceFile))
With ddOverrideTransform
.Items.Add(New ListItem(GetString("UseDefault.Option", Me.LocalResourceFile), ""))
.Items.Add(New ListItem(GetString("Atom.Option", Me.LocalResourceFile), "atom"))
.Items.Add(New ListItem(GetString("Rdf.Option", Me.LocalResourceFile), "rdf"))
.Items.Add(New ListItem(GetString("Rss091.Option", Me.LocalResourceFile), "rss091"))
.Items.Add(New ListItem(GetString("Twitter.Option", Me.LocalResourceFile), "DotNetNuke.Modules.News.Services.PreProcessing.TwitterPreProcessor, DotNetNuke.Modules.News"))
End With
If Not IO.Directory.Exists(PortalSettings.HomeDirectoryMapPath & Common.LocalTransformationPath) Then
IO.Directory.CreateDirectory(PortalSettings.HomeDirectoryMapPath & Common.LocalTransformationPath)
End If
For Each f As String In IO.Directory.GetFiles(PortalSettings.HomeDirectoryMapPath & Common.LocalTransformationPath, "*.xsl?")
Dim fName As String = Mid(f, f.LastIndexOf("\") + 2)
ddOverrideTransform.Items.Add(New ListItem(fName & " [Portal]", PortalSettings.HomeDirectoryMapPath & Common.LocalTransformationPath & "\" & fName))
Next
pnlEdit.Visible = False
BindList()
End If
Catch exc As Exception 'Module failed to load
ProcessModuleLoadException(Me, exc)
End Try
End Sub
''' <summary>
''' Update all settings and go back to page.
''' </summary>
''' <param name="sender"></param>
''' <param name="e"></param>
''' <remarks>
''' </remarks>
''' <history>
''' [pdonker] 03/01/2008 Created
''' </history>
Private Sub cmdUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdUpdate.Click
Try
If Page.IsValid Then
Dim feedId As Integer = CInt(hidFeedId.Value)
Dim f As FeedInfo = Nothing
If feedId = -1 Then
f = New FeedInfo
With f
.ModuleID = ModuleId
End With
Else
f = FeedController.GetFeed(feedId, ModuleId)
End If
With f
.CacheTime = Integer.Parse(txtCacheTime.Text)
.FeedUrl = txtFeedUrl.Text
Dim Password As String = txtPassword.Text
If Not String.IsNullOrEmpty(Password) Then
Dim encKey As String = Common.GetEncryptionKey
If Not String.IsNullOrEmpty(encKey) Then
Dim ps As New DotNetNuke.Security.PortalSecurity
Password = ps.Encrypt(encKey, Password)
End If
.Password = Password
Else
.Password = ""
End If
.User = txtUser.Text
If optStandard.Checked Then
.OverrideTransform = ddOverrideTransform.Text
ElseIf optType.Checked Then
.OverrideTransform = txtOverrideTransform.Text
Else
.OverrideTransform = ctlXsl.Url
End If
End With
If feedId = -1 Then
FeedController.AddFeed(f)
Else
FeedController.UpdateFeed(f)
End If
CloseEdit()
End If
Catch exc As Exception 'Module failed to load
ProcessModuleLoadException(Me, exc)
End Try
End Sub
''' <summary>
''' Cancel edits and go back to page.
''' </summary>
''' <param name="sender"></param>
''' <param name="e"></param>
''' <remarks>
''' </remarks>
''' <history>
''' [pdonker] 03/01/2008 Created
''' </history>
Private Sub cmdCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdCancel.Click
Try
CloseEdit()
Catch exc As Exception 'Module failed to load
ProcessModuleLoadException(Me, exc)
End Try
End Sub
''' <summary>
''' Show add new RSS feed panel
''' </summary>
''' <param name="sender"></param>
''' <param name="e"></param>
''' <remarks>
''' </remarks>
''' <history>
''' [pdonker] 03/01/2008 Created
''' </history>
Private Sub cmdAdd_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdAdd.Click
showEdit(-1)
End Sub
''' <summary>
''' Delete the selected news feed
''' </summary>
''' <param name="sender"></param>
''' <param name="e"></param>
''' <remarks>
''' </remarks>
''' <history>
''' [pdonker] 03/01/2008 Created
''' </history>
Private Sub cmdDelete_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdDelete.Click
Dim feedId As Integer = CInt(hidFeedId.Value)
FeedController.DeleteFeed(feedId)
CloseEdit()
End Sub
''' <summary>
''' Return to RSS feed view
''' </summary>
''' <param name="sender"></param>
''' <param name="e"></param>
''' <remarks>
''' </remarks>
''' <history>
''' [tstensitzki] 07/25/2010 Force a cache refresh to reflect recent config changes
''' [pdonker] 03/01/2008 Created
''' </history>
Private Sub cmdReturn_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdReturn.Click
Response.Redirect(NavigateURL(Me.TabId, "", "ClearCache=1"), False)
End Sub
''' <summary>
''' Edit feed in list
''' </summary>
''' <param name="source"></param>
''' <param name="e"></param>
''' <remarks>
''' </remarks>
''' <history>
''' [pdonker] 03/01/2008 Created
''' </history>
Private Sub dlFeeds_EditCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataListCommandEventArgs) Handles dlFeeds.EditCommand
dlFeeds.EditItemIndex = e.Item.ItemIndex
Dim feedId As Integer = CInt(dlFeeds.DataKeys(e.Item.ItemIndex))
showEdit(feedId)
End Sub
''' <summary>
''' User decided to change type of preprocessing
''' </summary>
''' <param name="sender"></param>
''' <param name="e"></param>
''' <remarks></remarks>
Private Sub optOverrideTransform_Changed(ByVal sender As Object, ByVal e As System.EventArgs) Handles optStandard.CheckedChanged, optType.CheckedChanged, optUrl.CheckedChanged
If optUrl.Checked Then
ddOverrideTransform.Enabled = False
ctlXsl.Visible = True
txtOverrideTransform.Enabled = False
ElseIf optType.Checked Then
ddOverrideTransform.Enabled = False
ctlXsl.Visible = False
txtOverrideTransform.Enabled = True
Else 'standard
ddOverrideTransform.Enabled = True
ctlXsl.Visible = False
txtOverrideTransform.Enabled = False
End If
End Sub
#End Region
#Region " Private Methods "
Private Sub showEdit(ByVal FeedId As Integer)
If FeedId = -1 Then
txtCacheTime.Text = "-1"
txtFeedUrl.Text = ""
txtPassword.Text = ""
txtUser.Text = ""
ddOverrideTransform.ClearSelection()
txtOverrideTransform.Text = ""
txtOverrideTransform.Enabled = False
ctlXsl.Visible = False
optStandard.Checked = True
txtCache.Text = ""
txtCache.Enabled = False
Else
Dim f As FeedInfo = FeedController.GetFeed(FeedId, ModuleId)
txtCacheTime.Text = "-1"
txtFeedUrl.Text = f.FeedUrl
If f.User <> "" Then
txtUser.Text = f.User
txtPassword.Text = GetString("PasswordEncoded", Me.LocalResourceFile)
txtPassword.Attributes.Add("onclick", "Javascript:this.value='';")
Else
txtPassword.Text = ""
txtUser.Text = ""
End If
ddOverrideTransform.ClearSelection()
If f.OverrideTransform = "" Then 'no transformation
ddOverrideTransform.Enabled = True
ctlXsl.Visible = False
txtOverrideTransform.Enabled = False
optStandard.Checked = True
ElseIf ddOverrideTransform.Items.FindByValue(f.OverrideTransform) IsNot Nothing Then ' standard
ddOverrideTransform.Items.FindByValue(f.OverrideTransform).Selected = True
ddOverrideTransform.Enabled = True
ctlXsl.Visible = False
txtOverrideTransform.Enabled = False
txtOverrideTransform.Text = ""
optStandard.Checked = True
ElseIf Text.RegularExpressions.Regex.Match(f.OverrideTransform.Replace(" ", ""), "[a-zA-Z0-9\.]*,[a-zA-Z0-9\.]*").Success Then
txtOverrideTransform.Text = f.OverrideTransform
ddOverrideTransform.Enabled = False
ctlXsl.Visible = False
txtOverrideTransform.Enabled = True
optType.Checked = True
Else ' url
ctlXsl.Url = f.OverrideTransform
ddOverrideTransform.Enabled = False
ctlXsl.Visible = True
txtOverrideTransform.Enabled = False
txtOverrideTransform.Text = ""
optUrl.Checked = True
End If
txtCache.Text = f.Cache
txtCache.Enabled = True
End If
hidFeedId.Value = FeedId.ToString
pnlEdit.Visible = True
pnlList.Visible = False
End Sub
Private Sub CloseEdit()
pnlEdit.Visible = False
pnlList.Visible = True
BindList()
End Sub
''' <summary>
''' Make the datalist with feeds.
''' </summary>
''' <remarks>
''' </remarks>
''' <history>
''' [pdonker] 03/01/2008 Created
''' [pdonker] 24/03/2010 DL invisible on no items
''' </history>
Private Sub BindList()
dlFeeds.DataSource = DotNetNuke.Common.ConvertDataReaderToDataTable(Data.DataProvider.Instance().GetFeedsByModule(ModuleId))
dlFeeds.DataBind()
If dlFeeds.Items.Count = 0 Then
dlFeeds.Visible = False
Else
dlFeeds.Visible = True
End If
End Sub
#End Region
End Class