当前文件路径:DNN/Library/Controls/SkinControl.vb 
1
'
2
' DotNetNuke?- http://www.dotnetnuke.com
3
' Copyright (c) 2002-2008
4
' by DotNetNuke Corporation
5
'
6
' Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
7
' documentation files (the "Software"), to deal in the Software without restriction, including without limitation
8
' the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
9
' to permit persons to whom the Software is furnished to do so, subject to the following conditions:
10
'
11
' The above copyright notice and this permission notice shall be included in all copies or substantial portions
12
' of the Software.
13
'
14
' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
15
' TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
16
' THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
17
' CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
18
' DEALINGS IN THE SOFTWARE.
19
'
20
Imports System.IO
21
Imports DotNetNuke.UI.WebControls
22
23
Namespace DotNetNukeNamespace DotNetNuke.UI.Skins
24
25
Public Class SkinControlClass SkinControl
26
Inherits Framework.UserControlBase
27
28
Controls#Region "Controls"
29
Protected WithEvents optHost As System.Web.UI.WebControls.RadioButton
30
Protected WithEvents optSite As System.Web.UI.WebControls.RadioButton
31
Protected WithEvents cboSkin As System.Web.UI.WebControls.DropDownList
32
Protected WithEvents cmdPreview As CommandButton
33
#End Region
34
35
Private Members#Region "Private Members"
36
Private _Width As String = ""
37
Private _SkinRoot As String
38
Private _SkinSrc As String
39
Private _localResourceFile As String
40
Private _objPortal As PortalInfo
41
#End Region
42
43
Public Properties#Region "Public Properties"
44
Public Property Width()Property Width() As String
45
Get
46
Width = Convert.ToString(ViewState("SkinControlWidth"))
47
End Get
48
Set(ByVal Value As String)
49
_Width = Value
50
End Set
51
End Property
52
53
Public Property SkinRoot()Property SkinRoot() As String
54
Get
55
SkinRoot = Convert.ToString(ViewState("SkinRoot"))
56
End Get
57
Set(ByVal Value As String)
58
_SkinRoot = Value
59
End Set
60
End Property
61
62
Public Property SkinSrc()Property SkinSrc() As String
63
Get
64
If Not cboSkin.SelectedItem Is Nothing Then
65
SkinSrc = cboSkin.SelectedItem.Value
66
Else
67
SkinSrc = ""
68
End If
69
End Get
70
Set(ByVal Value As String)
71
_SkinSrc = Value
72
End Set
73
End Property
74
75
Public Property LocalResourceFile()Property LocalResourceFile() As String
76
Get
77
Dim fileRoot As String
78
79
If _localResourceFile = "" Then
80
fileRoot = Me.TemplateSourceDirectory & "/" & Services.Localization.Localization.LocalResourceDirectory & "/SkinControl.ascx"
81
Else
82
fileRoot = _localResourceFile
83
End If
84
Return fileRoot
85
End Get
86
Set(ByVal Value As String)
87
_localResourceFile = Value
88
End Set
89
End Property
90
#End Region
91
92
Private Methods#Region "Private Methods"
93
94
Private Sub LoadSkins()Sub LoadSkins()
95
96
Dim strRoot As String
97
Dim strFolder As String
98
Dim arrFolders As String()
99
Dim strFile As String
100
Dim arrFiles As String()
101
Dim strLastFolder As String
102
Dim strSeparator As String = "----------------------------------------"
103
104
cboSkin.Items.Clear()
105
106
If optHost.Checked Then
107
' load host skins
108
strLastFolder = ""
109
strRoot = Common.Globals.HostMapPath & SkinRoot
110
If Directory.Exists(strRoot) Then
111
arrFolders = Directory.GetDirectories(strRoot)
112
For Each strFolder In arrFolders
113
If Not strFolder.EndsWith(glbHostSkinFolder) Then
114
arrFiles = Directory.GetFiles(strFolder, "*.ascx")
115
For Each strFile In arrFiles
116
strFolder = Mid(strFolder, InStrRev(strFolder, "\") + 1)
117
If strLastFolder <> strFolder Then
118
If strLastFolder <> "" Then
119
cboSkin.Items.Add(New ListItem(strSeparator, ""))
120
End If
121
strLastFolder = strFolder
122
End If
123
cboSkin.Items.Add(New ListItem(FormatSkinName(strFolder, Path.GetFileNameWithoutExtension(strFile)), "[G]" & SkinRoot & "/" & strFolder & "/" & Path.GetFileName(strFile)))
124
Next
125
End If
126
Next
127
End If
128
End If
129
130
If optSite.Checked Then
131
' load portal skins
132
strLastFolder = ""
133
strRoot = _objPortal.HomeDirectoryMapPath & SkinRoot
134
If Directory.Exists(strRoot) Then
135
arrFolders = Directory.GetDirectories(strRoot)
136
For Each strFolder In arrFolders
137
arrFiles = Directory.GetFiles(strFolder, "*.ascx")
138
For Each strFile In arrFiles
139
strFolder = Mid(strFolder, InStrRev(strFolder, "\") + 1)
140
If strLastFolder <> strFolder Then
141
If strLastFolder <> "" Then
142
cboSkin.Items.Add(New ListItem(strSeparator, ""))
143
End If
144
strLastFolder = strFolder
145
End If
146
cboSkin.Items.Add(New ListItem(FormatSkinName(strFolder, Path.GetFileNameWithoutExtension(strFile)), "[L]" & SkinRoot & "/" & strFolder & "/" & Path.GetFileName(strFile)))
147
Next
148
Next
149
End If
150
End If
151
152
' default value
153
If cboSkin.Items.Count > 0 Then
154
cboSkin.Items.Insert(0, New ListItem(strSeparator, ""))
155
End If
156
cboSkin.Items.Insert(0, New ListItem("<" + Services.Localization.Localization.GetString("Not_Specified") + ">", ""))
157
158
' select current skin
159
Dim intIndex As Integer
160
For intIndex = 0 To cboSkin.Items.Count - 1
161
If cboSkin.Items(intIndex).Value.ToLower = Convert.ToString(ViewState("SkinSrc")).ToLower Then
162
cboSkin.Items(intIndex).Selected = True
163
Exit For
164
End If
165
Next
166
167
End Sub
168
169
/**/''' -----------------------------------------------------------------------------
170
''' <summary>
171
''' format skin name
172
''' </summary>
173
''' <remarks>
174
''' </remarks>
175
''' <param name="strSkinFolder">The Folder Name</param>
176
''' <param name="strSkinFile">The File Name without extension</param>
177
''' <history>
178
''' </history>
179
''' -----------------------------------------------------------------------------
180
Private Function FormatSkinName()Function FormatSkinName(ByVal strSkinFolder As String, ByVal strSkinFile As String) As String
181
If strSkinFolder.ToLower = "_default" Then
182
' host folder
183
Return strSkinFile
184
Else ' portal folder
185
Select Case strSkinFile.ToLower
186
Case "skin", "container", "default"
187
Return strSkinFolder
188
Case Else
189
Return strSkinFolder & " - " & strSkinFile
190
End Select
191
End If
192
End Function
193
194
#End Region
195
196
Event Handlers#Region "Event Handlers"
197
/**/''' -----------------------------------------------------------------------------
198
''' <summary>
199
''' Page_Init runs when the control is initialised
200
''' </summary>
201
''' <remarks>
202
''' </remarks>
203
''' <history>
204
''' [cnurse] 11/30/2007 created
205
''' </history>
206
''' -----------------------------------------------------------------------------
207
Private Sub Page_Init()Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
208
209
'Make sure the Preview command buttons postback rather than use AJAX
210
Framework.AJAX.RegisterPostBackControl(cmdPreview)
211
212
End Sub
213
214
'*******************************************************
215
'
216
' The Page_Load server event handler on this page is used
217
' to populate the role information for the page
218
'
219
'*******************************************************
220
Private Sub Page_Load()Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
221
Try
222
Dim objPortals As New PortalController
223
If Not (Request.QueryString("pid") Is Nothing) And (PortalSettings.ActiveTab.ParentId = PortalSettings.SuperTabId Or UserController.GetCurrentUserInfo.IsSuperUser) Then
224
_objPortal = objPortals.GetPortal(Int32.Parse(Request.QueryString("pid")))
225
Else
226
_objPortal = objPortals.GetPortal(PortalSettings.PortalId)
227
End If
228
229
If Not Page.IsPostBack Then
230
231
' save persistent values
232
ViewState("SkinControlWidth") = _Width
233
ViewState("SkinRoot") = _SkinRoot
234
ViewState("SkinSrc") = _SkinSrc
235
236
' set width of control
237
If _Width <> "" Then
238
cboSkin.Width = System.Web.UI.WebControls.Unit.Parse(_Width)
239
End If
240
241
' set selected skin
242
If _SkinSrc <> "" Then
243
Select Case _SkinSrc.Substring(0, 3)
244
Case "[L]"
245
optHost.Checked = False
246
optSite.Checked = True
247
Case "[G]"
248
optSite.Checked = False
249
optHost.Checked = True
250
End Select
251
Else
252
' no skin selected, initialized to site skin if any exists
253
Dim strRoot As String = _objPortal.HomeDirectoryMapPath & SkinRoot
254
If Directory.Exists(strRoot) AndAlso Directory.GetDirectories(strRoot).Length > 0 Then
255
optHost.Checked = False
256
optSite.Checked = True
257
End If
258
End If
259
260
LoadSkins()
261
262
End If
263
264
Catch exc As Exception 'Module failed to load
265
ProcessModuleLoadException(Me, exc)
266
End Try
267
End Sub
268
269
Private Sub optHost_CheckedChanged()Sub optHost_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles optHost.CheckedChanged
270
271
LoadSkins()
272
273
End Sub
274
275
Private Sub optSite_CheckedChanged()Sub optSite_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles optSite.CheckedChanged
276
277
LoadSkins()
278
279
End Sub
280
281
Private Sub cmdPreview_Click()Sub cmdPreview_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdPreview.Click
282
283
If SkinSrc <> "" Then
284
285
Dim strType As String = SkinRoot.Substring(0, SkinRoot.Length - 1)
286
287
Dim strURL As String = ApplicationURL() & "&" & strType & "Src=" & QueryStringEncode(SkinSrc.Replace(".ascx", ""))
288
289
If SkinRoot = SkinInfo.RootContainer Then
290
If Not Request.QueryString("ModuleId") Is Nothing Then
291
strURL += "&ModuleId=" & Request.QueryString("ModuleId").ToString
292
End If
293
End If
294
295
Response.Redirect(strURL, True)
296
End If
297
298
End Sub
299
#End Region
300
301
End Class
302
303
End Namespace
304