This repository has been archived by the owner on Dec 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSettings.ascx.vb
317 lines (248 loc) · 12.3 KB
/
Settings.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
Imports DotNetNuke
Imports DotNetNuke.Common
Imports System.Configuration
Imports System.Text.RegularExpressions
Imports System.Xml
Imports System.Collections.Generic
Namespace DNNStuff.InjectAnything
Partial Class Settings
Inherits DotNetNuke.Entities.Modules.PortalModuleBase
Protected WithEvents ctlfile As DotNetNuke.UI.UserControls.UrlControl
Private _tokenList As Dictionary(Of String, DNNStuff.Utilities.RegularExpression.Token)
Private _script As StandardScript = Nothing
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
If Not Page.IsPostBack Then
Dim ms As New ModuleSettings(ModuleId, PortalSettings, Me)
LoadModuleSettings(ms)
_tokenList = InitTokenListFromModuleSettings(ms)
RenderTokensAsControls()
SetControlValuesFromTokens()
Else
_tokenList = DirectCast(Session("Tokens"), Dictionary(Of String, DNNStuff.Utilities.RegularExpression.Token))
RenderTokensAsControls()
End If
End Sub
Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
DNNUtilities.InjectCSS(Me.Page, ResolveUrl("Resources/Support/edit.css"))
Page.ClientScript.RegisterClientScriptInclude(Me.GetType, "yeti", ResolveUrl("resources/support/yetii-min.js"))
SetVisibilityBasedOnSource()
End Sub
#End Region
#Region "Base Method Implementations"
Public Sub UpdateSettings()
Dim ms As New ModuleSettings(ModuleId)
With ms
.InsertionPoint = ddlInsertionPoint.SelectedValue
.Source = ddlSource.SelectedValue
.StandardFile = ddlStandard.SelectedValue
.File = ctlfile.Url
.LinkFile = chkLinkFile.Checked And .Source = "File"
.Text = txtText.Text
.Debug = chkDebug.Checked
.Enable = chkEnable.Checked
End With
ms.UpdateSettings()
End Sub
Public Sub UpdateSettingsTokens()
Dim ms As New ModuleSettings(ModuleId)
ms.UpdateSettingsTokens(_tokenList)
End Sub
Private Sub SelectListItem(ByVal ctl As ListControl, ByVal value As String)
Dim li As ListItem
ctl.ClearSelection()
li = ctl.Items.FindByValue(value)
If li IsNot Nothing Then li.Selected = True
End Sub
Public Sub LoadModuleSettings(ByVal ms As ModuleSettings)
SelectListItem(ddlInsertionPoint, ms.InsertionPoint)
SelectListItem(ddlSource, ms.Source)
' bind standard scripts
BindStandard(ddlStandard)
Select Case ms.Source
Case "Standard"
SelectListItem(ddlStandard, ms.StandardFile)
Case "File"
ctlfile.Url = ms.File
End Select
chkLinkFile.Checked = ms.LinkFile
txtText.Text = ms.Text
chkDebug.Checked = ms.Debug
chkEnable.Checked = ms.Enable
End Sub
Public Sub SetControlValuesFromTokens()
' set control values based on token values
Dim ctrl As TextBox
For Each key As String In _tokenList.Keys
Dim t As DNNStuff.Utilities.RegularExpression.Token = _tokenList(key)
ctrl = DirectCast(pnlToken.FindControl("Token_" & t.Name), TextBox)
If Not ctrl Is Nothing Then
If t.Value IsNot Nothing Then
If t.Value.Length > 0 Then
ctrl.Text = t.Value
End If
End If
End If
Next
End Sub
#End Region
Private Sub SetVisibilityBasedOnSource()
Select Case ddlSource.SelectedValue
Case "File"
divStandard.Visible = False
divFile.Visible = True
divText.Visible = False
Case "Standard"
divStandard.Visible = True
divFile.Visible = False
divText.Visible = False
Case "Text"
divStandard.Visible = False
divFile.Visible = False
divText.Visible = True
End Select
End Sub
Private Sub cmdUpdate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdUpdate.Click
RetrieveTokenValuesFromControls()
UpdateSettings()
UpdateSettingsTokens()
' Redirect back to the portal home page
Response.Redirect(NavigateURL(), True)
End Sub
Private Sub cmdCancel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdCancel.Click
' Redirect back to the portal home page
Response.Redirect(NavigateURL(), True)
End Sub
Private Sub cmdRefresh_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdRefresh.Click
UpdateSettings()
UpdateSettingsTokens()
Response.Redirect(EditUrl())
End Sub
Private Sub BindStandard(ByVal o As ListControl)
Dim standardFolder As New IO.DirectoryInfo(Server.MapPath(ResolveUrl("Standard")))
o.Items.Clear()
For Each fi As IO.FileInfo In standardFolder.GetFiles("*.xml")
o.Items.Add(New ListItem(fi.Name.Replace(".xml", ""), fi.Name))
Next
End Sub
#Region " Token Support"
Private Function InitTokenListFromModuleSettings(ByVal ms As ModuleSettings) As System.Collections.Generic.Dictionary(Of String, DNNStuff.Utilities.RegularExpression.Token)
' build list of tokens based on current module settings
Return ms.LoadSettingsTokens(InitTokenListFromCurrentSettings(ms.Source, ms.StandardFile, ms.File, ms.Text))
End Function
Private Function InitTokenListFromCurrentSettings(ByVal source As String, ByVal standardFilename As String, ByVal portalFilename As String, ByVal text As String) As System.Collections.Generic.Dictionary(Of String, DNNStuff.Utilities.RegularExpression.Token)
' build list of tokens based on current module settings
Dim list As New System.Collections.Generic.Dictionary(Of String, DNNStuff.Utilities.RegularExpression.Token)
' clear standard script
_script = Nothing
Select Case source
Case "Standard"
' inject using file
If standardFilename.Length > 0 Then
Dim filename As String = HttpContext.Current.Server.MapPath(Me.ResolveUrl("Standard/" & standardFilename))
Dim fi As IO.FileInfo = New IO.FileInfo(filename)
Dim script As StandardScript = DNNUtilities.GetStandardScript(fi)
list = InitTokenListFromString(script.Items(0).Content)
' set script
_script = script
End If
Case "File"
' inject using file
list = InitTokenListFromString(Compatibility.GetFileContents(portalFilename, PortalSettings.HomeDirectoryMapPath, PortalId))
Case Else
' use the text
If text.Length > 0 Then list = InitTokenListFromString(Server.HtmlDecode(text))
End Select
Return list
End Function
Private Function InitTokenListFromString(ByVal s As String) As System.Collections.Generic.Dictionary(Of String, DNNStuff.Utilities.RegularExpression.Token)
' build list of tokens based on file or text
Dim replacer As New DNNStuff.Utilities.RegularExpression.TokenReplacement(New Hashtable)
Dim exclusions As New Generic.List(Of String)
exclusions.Add("STANDARDFOLDER")
exclusions.Add("ROLES")
exclusions.Add("ROLESARRAY")
' add exclusions for some simple array indexes ie. myArray[i]
exclusions.Add("I")
exclusions.Add("J")
exclusions.Add("K")
Dim tokens As System.Collections.Generic.Dictionary(Of String, DNNStuff.Utilities.RegularExpression.Token)
tokens = replacer.Tokens(s, exclusions)
' remove any tokens containing special characters (:) - this will catch all QS:, QUERYSTRING: and standard DNN tokens
Dim loopTokens As New List(Of String)
For Each key As String In tokens.Keys
If key.Contains(":") Then
loopTokens.Add(key)
End If
Next
For Each key As String In loopTokens
tokens.Remove(key)
Next
Return tokens
End Function
Private Sub RenderTokensAsControls()
' renders tokens as textboxes based on tokenList
pnlToken.Controls.Clear()
' render description and help
If _script IsNot Nothing Then
pnlToken.Controls.Add(New LiteralControl(String.Format("<span class=""SubHead"">Description</span>:<br />{0}<br />", _script.Description)))
pnlToken.Controls.Add(New LiteralControl(String.Format("<span class=""SubHead"">Help</span>:<br />{0}", _script.Help)))
End If
For Each key As String In _tokenList.Keys
Dim t As DNNStuff.Utilities.RegularExpression.Token = _tokenList(key)
Dim tb As New WebControls.TextBox
tb.ID = "Token_" & t.Name
' add label
Dim d As New HtmlControls.HtmlGenericControl("div")
d.Attributes.Add("class", "dnnFormItem")
Dim l As New DotNetNuke.UI.WebControls.PropertyLabelControl
l.ID = tb.ID & "_Help"
l.Caption = t.Name.Replace("_", " ") & " :"
If t.Parameters.ContainsKey("Caption") Then
l.Caption = t.Parameters("Caption")
End If
If t.Parameters.ContainsKey("Help") Then
l.HelpText = "<div class=""Help"">" & t.Parameters("Help") & "</div>"
End If
If t.Parameters.ContainsKey("Default") Then
tb.Text = t.Parameters("Default")
End If
tb.Columns = 40
If t.Parameters.ContainsKey("Columns") Then
Int32.TryParse(t.Parameters("Columns"), tb.Columns)
End If
l.EditControl = tb
d.Controls.Add(l)
' add textbox
d.Controls.Add(tb)
pnlToken.Controls.Add(d)
Next
Session("Tokens") = _tokenList
End Sub
Private Sub RetrieveTokenValuesFromControls()
' set tokenList values from token controls
Dim ctrl As TextBox
For Each key As String In _tokenList.Keys
Dim t As DNNStuff.Utilities.RegularExpression.Token = _tokenList(key)
ctrl = DirectCast(pnlToken.FindControl("Token_" & t.Name), TextBox)
If Not ctrl Is Nothing Then
t.Value = ctrl.Text
End If
Next
End Sub
#End Region
Private Sub SourceChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlSource.SelectedIndexChanged, ddlStandard.SelectedIndexChanged
' default link file to true
If ddlSource.SelectedValue = "File" Then chkLinkFile.Checked = True
_tokenList = InitTokenListFromCurrentSettings(ddlSource.SelectedValue, ddlStandard.SelectedValue, ctlfile.Url, txtText.Text)
RenderTokensAsControls()
SetVisibilityBasedOnSource()
End Sub
End Class
End Namespace