当前文件路径:DNN/Library/Controls/TextEditor.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 DotNetNuke.Services.Personalization
21
Imports DotNetNuke.Entities.Modules
22
Imports DotNetNuke.Modules.HTMLEditorProvider
23
24
Namespace DotNetNukeNamespace DotNetNuke.UI.UserControls
25
26
/**/''' -----------------------------------------------------------------------------
27
''' Class: TextEditor
28
''' Project: DotNetNuke
29
''' -----------------------------------------------------------------------------
30
''' <summary>
31
''' TextEditor is a user control that provides a wrapper for the HtmlEditor providers
32
''' </summary>
33
''' <remarks>
34
''' </remarks>
35
''' <history>
36
''' [cnurse] 12/13/2004 Documented
37
''' </history>
38
''' -----------------------------------------------------------------------------
39
<ValidationPropertyAttribute("Text")> Public Class TextEditorClass TextEditor
40
Inherits System.Web.UI.UserControl
41
42
Controls#Region "Controls"
43
44
Protected WithEvents tblTextEditor As System.Web.UI.HtmlControls.HtmlTable
45
Protected WithEvents celTextEditor As System.Web.UI.HtmlControls.HtmlTableCell
46
Protected WithEvents optView As System.Web.UI.WebControls.RadioButtonList
47
Protected WithEvents txtDesktopHTML As System.Web.UI.WebControls.TextBox
48
Protected WithEvents optRender As System.Web.UI.WebControls.RadioButtonList
49
Protected WithEvents pnlBasicTextBox As System.Web.UI.WebControls.Panel
50
Protected WithEvents pnlBasicRender As System.Web.UI.WebControls.Panel
51
Protected WithEvents plcEditor As System.Web.UI.WebControls.PlaceHolder
52
Protected WithEvents pnlRichTextBox As System.Web.UI.WebControls.Panel
53
Protected WithEvents pnlOption As System.Web.UI.WebControls.Panel
54
#End Region
55
56
Private Members#Region "Private Members"
57
58
Private _ChooseMode As Boolean = True
59
Private _ChooseRender As Boolean = True
60
Private _HtmlEncode As Boolean = True
61
Private _Width As System.Web.UI.WebControls.Unit
62
Private _Height As System.Web.UI.WebControls.Unit
63
Private RichTextEditor As Modules.HTMLEditorProvider.HtmlEditorProvider
64
65
Private MyFileName As String = "TextEditor.ascx"
66
67
#End Region
68
69
Properties#Region "Properties"
70
71
'Enables/Disables the option to allow the user to select between Rich/Basic Mode
72
'Default is true.
73
Public Property ChooseMode()Property ChooseMode() As Boolean
74
Get
75
ChooseMode = _ChooseMode
76
End Get
77
Set(ByVal Value As Boolean)
78
_ChooseMode = Value
79
End Set
80
End Property
81
82
'Determines wether or not the Text/Html button is rendered for Basic mode
83
'Default is True
84
Public Property ChooseRender()Property ChooseRender() As Boolean
85
Get
86
ChooseRender = _ChooseRender
87
End Get
88
Set(ByVal Value As Boolean)
89
_ChooseRender = Value
90
End Set
91
End Property
92
93
'Gets/Sets the Default mode of the control, either "RICH" or "BASIC"
94
'Defaults to Rich
95
Public Property DefaultMode()Property DefaultMode() As String
96
Get
97
If CType(Me.ViewState.Item("DefaultMode"), String) = "" Then
98
Return "RICH" ' default to rich
99
Else
100
Return CType(Me.ViewState.Item("DefaultMode"), String)
101
End If
102
End Get
103
Set(ByVal Value As String)
104
If Value.ToUpper <> "BASIC" Then
105
Me.ViewState.Item("DefaultMode") = "RICH"
106
Else
107
Me.ViewState.Item("DefaultMode") = "BASIC"
108
End If
109
End Set
110
End Property
111
112
'Gets/Sets the Height of the control
113
Public Property Height()Property Height() As System.Web.UI.WebControls.Unit
114
Get
115
Return _Height
116
End Get
117
Set(ByVal Value As System.Web.UI.WebControls.Unit)
118
_Height = Value
119
End Set
120
End Property
121
122
'Turns on HtmlEncoding of text. If this option is on the control will assume
123
'it is being passed encoded text and will decode.
124
Public Property HtmlEncode()Property HtmlEncode() As Boolean
125
Get
126
HtmlEncode = _HtmlEncode
127
End Get
128
Set(ByVal Value As Boolean)
129
_HtmlEncode = Value
130
End Set
131
End Property
132
133
'The current mode of the control "RICH", "BASIC"
134
Public Property Mode()Property Mode() As String
135
Get
136
Dim strMode As String = ""
137
Dim objUserInfo As UserInfo = UserController.GetCurrentUserInfo
138
139
'Check if Personal Preference is set
140
If objUserInfo.UserID >= 0 Then
141
If Not Personalization.GetProfile("DotNetNuke.TextEditor", "PreferredTextEditor") Is Nothing Then
142
strMode = CType(Personalization.GetProfile("DotNetNuke.TextEditor", "PreferredTextEditor"), String)
143
End If
144
End If
145
146
'If no Preference Check if Viewstate has been saved
147
If strMode Is Nothing Or strMode = "" Then
148
If CType(Me.ViewState.Item("DesktopMode"), String) <> "" Then
149
strMode = CType(Me.ViewState.Item("DesktopMode"), String)
150
End If
151
End If
152
153
'Finally if still no value Use default
154
If strMode Is Nothing Or strMode = "" Then
155
strMode = DefaultMode
156
End If
157
158
Return strMode
159
End Get
160
Set(ByVal Value As String)
161
Dim objUserInfo As UserInfo = UserController.GetCurrentUserInfo
162
163
If Value.ToUpper <> "BASIC" Then
164
Me.ViewState.Item("DesktopMode") = "RICH"
165
166
If objUserInfo.UserID >= 0 Then
167
Personalization.SetProfile("DotNetNuke.TextEditor", "PreferredTextEditor", "RICH")
168
End If
169
Else
170
Me.ViewState.Item("DesktopMode") = "BASIC"
171
172
If objUserInfo.UserID >= 0 Then
173
Personalization.SetProfile("DotNetNuke.TextEditor", "PreferredTextEditor", "BASIC")
174
End If
175
End If
176
End Set
177
End Property
178
179
'Gets/Sets the Text of the control
180
Public Property Text()Property Text() As String
181
Get
182
If optView.SelectedItem.Value = "BASIC" Then
183
Select Case optRender.SelectedItem.Value
184
Case "T"
185
Text = Encode(FormatHtml(txtDesktopHTML.Text))
186
Case "R"
187
Text = txtDesktopHTML.Text
188
Case Else
189
Text = Encode(txtDesktopHTML.Text)
190
End Select
191
Else
192
Text = Encode(RichTextEditor.Text)
193
End If
194
End Get
195
Set(ByVal Value As String)
196
If Value <> "" Then
197
txtDesktopHTML.Text = Decode(FormatText(Value))
198
RichTextEditor.Text = Decode(Value)
199
End If
200
End Set
201
End Property
202
203
'Sets the render mode for Basic mode. {Raw | HTML | Text}
204
Public Property TextRenderMode()Property TextRenderMode() As String
205
Get
206
TextRenderMode = CType(Me.ViewState.Item("textrender"), String)
207
End Get
208
Set(ByVal Value As String)
209
Dim strMode As String
210
211
strMode = Value.ToUpper.Substring(0, 1)
212
If strMode <> "R" And strMode <> "H" And strMode <> "T" Then
213
strMode = "H"
214
End If
215
216
Me.ViewState.Item("textrender") = strMode
217
End Set
218
End Property
219
220
'Gets/Sets the Width of the control
221
Public Property Width()Property Width() As System.Web.UI.WebControls.Unit
222
Get
223
Return _Width
224
End Get
225
Set(ByVal Value As System.Web.UI.WebControls.Unit)
226
_Width = Value
227
End Set
228
End Property
229
230
'Allows public access ot the HtmlEditorProvider
231
Public ReadOnly Property RichText()Property RichText() As HtmlEditorProvider
232
Get
233
Return RichTextEditor
234
End Get
235
End Property
236
237
#End Region
238
239
Private Methods#Region "Private Methods"
240
241
/**/''' -----------------------------------------------------------------------------
242
''' <summary>
243
''' Decodes the html
244
''' </summary>
245
''' <remarks>
246
''' </remarks>
247
''' <param name="strHtml">Html to decode</param>
248
''' <returns>The decoded html</returns>
249
''' <history>
250
''' [cnurse] 12/13/2004 Documented
251
''' </history>
252
''' -----------------------------------------------------------------------------
253
Private Function Decode()Function Decode(ByVal strHtml As String) As String
254
If Me.HtmlEncode Then
255
Decode = Server.HtmlDecode(strHtml)
256
Else
257
Decode = strHtml
258
End If
259
End Function
260
261
/**/''' -----------------------------------------------------------------------------
262
''' <summary>
263
''' Encodes the html
264
''' </summary>
265
''' <remarks>
266
''' </remarks>
267
''' <param name="strHtml">Html to encode</param>
268
''' <returns>The encoded html</returns>
269
''' <history>
270
''' [cnurse] 12/13/2004 Documented
271
''' </history>
272
''' -----------------------------------------------------------------------------
273
Private Function Encode()Function Encode(ByVal strHtml As String) As String
274
If Me.HtmlEncode Then
275
Encode = Server.HtmlEncode(strHtml)
276
Else
277
Encode = strHtml
278
End If
279
End Function
280
281
/**/''' -----------------------------------------------------------------------------
282
''' <summary>
283
''' Formats String as Html by replacing linefeeds by <br/>
284
''' </summary>
285
''' <remarks>
286
''' </remarks>
287
''' <param name="strText">Text to format</param>
288
''' <returns>The formatted html</returns>
289
''' <history>
290
''' [cnurse] 12/13/2004 Documented
291
''' </history>
292
''' -----------------------------------------------------------------------------
293
Private Function FormatHtml()Function FormatHtml(ByVal strText As String) As String
294
295
Dim strHtml As String = strText
296
Try
297
If strHtml <> "" Then
298
strHtml = Replace(strHtml, Chr(13), "")
299
strHtml = Replace(strHtml, ControlChars.Lf, "<br />")
300
End If
301
302