当前文件路径:DNN/Library/Controls/SkinThumbNailControl.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
22
Namespace DotNetNukeNamespace DotNetNuke.UI.Skins
23
24
/**/''' -----------------------------------------------------------------------------
25
''' <summary>
26
''' SkinThumbNailControl is a user control that provides that displays the skins
27
''' as a Radio ButtonList with Thumbnail Images where available
28
''' </summary>
29
''' <remarks>
30
''' </remarks>
31
''' <history>
32
''' [cnurse] 10/12/2004 Created
33
''' </history>
34
''' -----------------------------------------------------------------------------
35
Public MustInherit Class SkinThumbNailControlClass SkinThumbNailControl
36
Inherits Framework.UserControlBase
37
38
Controls#Region "Controls"
39
40
Protected WithEvents optSkin As System.Web.UI.WebControls.RadioButtonList
41
Protected WithEvents ControlContainer As System.Web.UI.HtmlControls.HtmlGenericControl
42
43
#End Region
44
45
Private Members#Region "Private Members"
46
47
Private _Columns As Integer = -1
48
49
#End Region
50
51
Properties#Region "Properties"
52
53
Public Property Border()Property Border() As String
54
Get
55
Return Convert.ToString(ViewState("SkinControlBorder"))
56
End Get
57
Set(ByVal Value As String)
58
ViewState("SkinControlBorder") = Value
59
If Value <> "" Then
60
ControlContainer.Style.Add("border-top", Value)
61
ControlContainer.Style.Add("border-bottom", Value)
62
ControlContainer.Style.Add("border-left", Value)
63
ControlContainer.Style.Add("border-right", Value)
64
End If
65
End Set
66
End Property
67
68
Public Property Columns()Property Columns() As Integer
69
Get
70
Return Convert.ToInt32(ViewState("SkinControlColumns"))
71
End Get
72
Set(ByVal Value As Integer)
73
ViewState("SkinControlColumns") = Value
74
If Value > 0 Then
75
optSkin.RepeatColumns = Value
76
End If
77
End Set
78
End Property
79
80
Public Property Height()Property Height() As String
81
Get
82
Return Convert.ToString(ViewState("SkinControlHeight"))
83
End Get
84
Set(ByVal Value As String)
85
ViewState("SkinControlHeight") = Value
86
If Value <> "" Then
87
ControlContainer.Style.Add("height", Value)
88
End If
89
End Set
90
End Property
91
92
Public Property SkinRoot()Property SkinRoot() As String
93
Get
94
Return Convert.ToString(ViewState("SkinRoot"))
95
End Get
96
Set(ByVal Value As String)
97
ViewState("SkinRoot") = Value
98
End Set
99
End Property
100
101
Public Property SkinSrc()Property SkinSrc() As String
102
Get
103
If Not optSkin.SelectedItem Is Nothing Then
104
Return optSkin.SelectedItem.Value
105
Else
106
Return ""
107
End If
108
End Get
109
Set(ByVal Value As String)
110
' select current skin
111
Dim intIndex As Integer
112
For intIndex = 0 To optSkin.Items.Count - 1
113
If optSkin.Items(intIndex).Value = Value Then
114
optSkin.Items(intIndex).Selected = True
115
Exit For
116
End If
117
Next
118
119
End Set
120
End Property
121
122
Public Property Width()Property Width() As String
123
Get
124
Return Convert.ToString(ViewState("SkinControlWidth"))
125
End Get
126
Set(ByVal Value As String)
127
ViewState("SkinControlWidth") = Value
128
If Value <> "" Then
129
ControlContainer.Style.Add("width", Value)
130
End If
131
End Set
132
End Property
133
134
#End Region
135
136
Private Methods#Region "Private Methods"
137
138
/**/''' -----------------------------------------------------------------------------
139
''' <summary>
140
''' AddDefaultSkin adds the not-specified skin to the radio button list
141
''' </summary>
142
''' <remarks>
143
''' </remarks>
144
''' <history>
145
''' [cnurse] 12/15/2004 Created
146
''' </history>
147
''' -----------------------------------------------------------------------------
148
Private Sub AddDefaultSkin()Sub AddDefaultSkin()
149
Dim strDefault As String = Services.Localization.Localization.GetString("Not_Specified") & "<br>"
150
strDefault += "<img src=""" & Common.Globals.ApplicationPath & "/images/spacer.gif"" width=""140"" height=""135"" border=""0"">"
151
optSkin.Items.Insert(0, New ListItem(strDefault, ""))
152
End Sub
153
154
/**/''' -----------------------------------------------------------------------------
155
''' <summary>
156
''' AddSkin adds the skin to the radio button list
157
''' </summary>
158
''' <remarks>
159
''' </remarks>
160
''' <param name="strFolder">The Skin Folder</param>
161
''' <param name="strFile">The Skin File</param>
162
''' <history>
163
''' [cnurse] 9/8/2004 Created
164
''' </history>
165
''' -----------------------------------------------------------------------------
166
Private Sub AddSkin()Sub AddSkin(ByVal root As String, ByVal strFolder As String, ByVal strFile As String)
167
168
Dim strImage As String = ""
169
170
If File.Exists(strFile.Replace(".ascx", ".jpg")) Then
171
strImage += "<a href=""" & CreateThumbnail(strFile.Replace(".ascx", ".jpg")).Replace("thumbnail_", "") & """ target=""_new""><img src=""" & CreateThumbnail(strFile.Replace(".ascx", ".jpg")) & """ border=""1""></a>"
172
Else
173
strImage += "<img src=""" & Common.Globals.ApplicationPath & "/images/thumbnail.jpg"" border=""1"">"
174
End If
175
176
optSkin.Items.Add(New ListItem(FormatSkinName(strFolder, Path.GetFileNameWithoutExtension(strFile)) & "<br>" & strImage, root & "/" & strFolder & "/" & Path.GetFileName(strFile)))
177
178
End Sub
179
180
/**/''' -----------------------------------------------------------------------------
181
''' <summary>
182
''' format skin name
183
''' </summary>
184
''' <remarks>
185
''' </remarks>
186
''' <param name="strSkinFolder">The Folder Name</param>
187
''' <param name="strSkinFile">The File Name without extension</param>
188
''' <history>
189
''' </history>
190
''' -----------------------------------------------------------------------------
191
Private Function FormatSkinName()Function FormatSkinName(ByVal strSkinFolder As String, ByVal strSkinFile As String) As String
192
If strSkinFolder.ToLower = "_default" Then
193
' host folder
194
Return strSkinFile
195
Else ' portal folder
196
Select Case strSkinFile.ToLower
197
Case "skin", "container", "default"
198
Return strSkinFolder
199
Case Else
200
Return strSkinFolder & " - " & strSkinFile
201
End Select
202
End If
203
End Function
204
205
/**/''' -----------------------------------------------------------------------------
206
''' <summary>
207
''' CreateThumbnail creates a thumbnail of the Preview Image
208
''' </summary>
209
''' <remarks>
210
''' </remarks>
211
''' <param name="strImage">The Image File Name</param>
212
''' <history>
213
''' [cnurse] 9/8/2004 Created
214
''' </history>
215
''' -----------------------------------------------------------------------------
216
Private Function CreateThumbnail()Function CreateThumbnail(ByVal strImage As String) As String
217
218
Dim blnCreate As Boolean = True
219
220
Dim strThumbnail As String = strImage.Replace(Path.GetFileName(strImage), "thumbnail_" & Path.GetFileName(strImage))
221
222
' check if image has changed
223
If File.Exists(strThumbnail) Then
224
Dim d1 As Date = File.GetLastWriteTime(strThumbnail)
225
Dim d2 As Date = File.GetLastWriteTime(strImage)
226
If File.GetLastWriteTime(strThumbnail) = File.GetLastWriteTime(strImage) Then
227
blnCreate = False
228
End If
229
End If
230
231
If blnCreate Then
232
233
Dim dblScale As Double
234
Dim intHeight As Integer
235
Dim intWidth As Integer
236
237
Dim intSize As Integer = 140 ' size of the thumbnail
238
239
Dim objImage As System.Drawing.Image
240
Try
241
objImage = Drawing.Image.FromFile(strImage)
242
243
' scale the image to prevent distortion
244
If objImage.Height > objImage.Width Then
245
'The height was larger, so scale the width
246
dblScale = intSize / objImage.Height
247
intHeight = intSize
248
intWidth = CInt(objImage.Width * dblScale)
249
Else
250
'The width was larger, so scale the height
251
dblScale = intSize / objImage.Width
252
intWidth = intSize
253
intHeight = CInt(objImage.Height * dblScale)
254
End If
255
256
' create the thumbnail image
257
Dim objThumbnail As System.Drawing.Image
258
objThumbnail = objImage.GetThumbnailImage(intWidth, intHeight, Nothing, IntPtr.Zero)
259
260
' delete the old file ( if it exists )
261
If File.Exists(strThumbnail) Then
262
File.Delete(strThumbnail)
263
End If
264
265
' save the thumbnail image
266
objThumbnail.Save(strThumbnail, objImage.RawFormat)
267
268
' set the file attributes
269
File.SetAttributes(strThumbnail, FileAttributes.Normal)
270
File.SetLastWriteTime(strThumbnail, File.GetLastWriteTime(strImage))
271
272
' tidy up
273
objImage.Dispose()
274
objThumbnail.Dispose()
275
276
Catch
277
278
' problem creating thumbnail
279
280
End Try
281
282
End If
283
284
strThumbnail = Common.Globals.ApplicationPath & "\" & strThumbnail.Substring(strThumbnail.ToLower.IndexOf("portals\"))
285
286
' return thumbnail filename
287
Return strThumbnail
288
289
End Function
290
291
#End Region
292
293
Public Methods#Region "Public Methods"
294
295
/**/''' -----------------------------------------------------------------------------
296
''' <summary>
297
''' Clear clears the radio button list
298
''' </summary>
299
''' <remarks>
300
''' </remarks>
301
''' <history>
302
''' [cnurse] 12/15/2004 Created
303
''' </history>
304
''' -----------------------------------------------------------------------------
305
Public Sub Clear()Sub Clear()
306
optSkin.Items.Clear()
307
End Sub
308
309
