-
Notifications
You must be signed in to change notification settings - Fork 13
/
IFrame.ascx.cs
371 lines (333 loc) · 12.7 KB
/
IFrame.ascx.cs
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
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
/*
* DNN Corp. - http://www.dnnsoftware.com
* Copyright (c) 2016
* by DNN Corp.
*
* 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.
*/
using DotNetNuke.Modules.IFrame.Components;
using DotNetNuke.Common;
using DotNetNuke.Entities.Modules;
using DotNetNuke.Entities.Modules.Actions;
using DotNetNuke.Framework.JavaScriptLibraries;
using DotNetNuke.Security;
using DotNetNuke.Services.Exceptions;
using DotNetNuke.Services.Localization;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DotNetNuke.Modules.IFrame.UI
{
public partial class IFrame : PortalModuleBase, IActionable
{
#region Settings
private string Source
{
get
{
object source = ViewState["Source"];
if (source == null)
{
StringBuilder sourceBuilder = new StringBuilder();
object o = Settings["Source"];
if (o != null)
{
if ((!(string.IsNullOrEmpty(UrlType))) && (UrlType == "T"))
sourceBuilder.Append(Globals.NavigateURL(Convert.ToInt32(o)));
else
{
sourceBuilder.Append(Convert.ToString(o));
if ((sourceBuilder.ToString().IndexOf("://") < 0) && (!(sourceBuilder.ToString().StartsWith("/"))))
sourceBuilder.Insert(0, PortalSettings.HomeDirectory);
}
string hashString = string.Empty;
List<ParametersInfo> parameters = (List<ParametersInfo>)ParametersController.GetParameters(ModuleId);
if ((parameters != null) && (parameters.Count() > 0))
{
bool queryStringOpen = false;
foreach (ParametersInfo p in parameters)
{
if (p.UseAsHash)
hashString = string.Format("#{0}", p.Name);
else
{
sourceBuilder.Append(queryStringOpen ? "&" : "?");
sourceBuilder.Append(p.ToString());
queryStringOpen = true;
}
}
}
if (!(string.IsNullOrEmpty(hashString)))
sourceBuilder.Append(hashString);
}
ViewState["Source"] = sourceBuilder.ToString();
return sourceBuilder.ToString();
}
else
{
return Convert.ToString(source);
}
}
}
private string UrlType
{
get { return Convert.ToString(Settings["UrlType"]); }
}
private string Width
{
get { return Convert.ToString(Settings["Width"]); }
}
private string Height
{
get { return Convert.ToString(Settings["Height"]); }
}
private bool AutoHeight
{
get
{
bool autoHeight;
try
{
object o = Settings["AutoHeight"];
if (o == null)
autoHeight = false;
else
autoHeight = Convert.ToBoolean(o);
}
catch (Exception ex)
{
Exception ex1 = new Exception(string.Format("Invalid AutoHeight value: {0}", Settings["AutoHeight"]), ex);
Exceptions.LogException(ex1);
autoHeight = false;
}
return autoHeight;
}
}
private Scrolling Scrolling
{
get
{
Scrolling scrolling;
try
{
object o = Settings["Scrolling"];
if (o == null)
scrolling = Scrolling.Auto;
else
scrolling = (Scrolling)Convert.ToInt32(o);
}
catch (Exception ex)
{
Exception ex1 = new Exception(string.Format("Invalid Scrolling value: {0}", Settings["Scrolling"]), ex);
Exceptions.LogException(ex1);
scrolling = Scrolling.Auto;
}
return scrolling;
}
}
private bool Border
{
get
{
bool border;
try
{
border = Convert.ToBoolean(Settings["Border"]);
}
catch (Exception ex)
{
Exception ex1 = new Exception(string.Format("Invalid Border value: {0}", Settings["Border"]), ex);
Exceptions.LogException(ex1);
border = false;
}
return border;
}
}
private bool AllowTransparency
{
get
{
bool allowTransparency;
try
{
allowTransparency = Convert.ToBoolean(Settings["AllowTransparency"]);
}
catch (Exception ex)
{
Exception ex1 = new Exception(string.Format("Invalid Border value: {0}", Settings["AllowTransparency"]), ex);
Exceptions.LogException(ex1);
allowTransparency = false;
}
return allowTransparency;
}
}
private string Name
{
get { return Convert.ToString(Settings["Name"]); }
}
private string ToolTip
{
get { return Convert.ToString(Settings["ToolTip"]); }
}
private string CssStyle
{
get { return Convert.ToString(Settings["CssStyle"]); }
}
private string OnLoadJavaScript
{
get { return Convert.ToString(Settings["OnLoadJavaScript"]); }
}
#endregion
#region Private Properties
private ParametersController _parametersController;
protected ParametersController ParametersController
{
get
{
if (_parametersController == null)
_parametersController = new ParametersController();
return _parametersController;
}
}
#endregion
#region Event Handlers
/// <summary>
/// Handles the <see cref="Control.Init" /> event.
/// </summary>
protected void Page_Init(object sender, EventArgs e)
{
JavaScript.RequestRegistration(CommonJs.jQuery);
}
/// <summary>
/// Handles the <see cref="Control.Load" /> event.
/// </summary>
protected void Page_Load(object sender, EventArgs e)
{
try
{
if (!(string.IsNullOrEmpty(Source)))
{
HtmlIFrame.Visible = true;
MessageContainer.Visible = false;
}
else
{
HtmlIFrame.Visible = false;
MessageLabel.Text = Localization.GetString("NoSource", LocalResourceFile);
MessageContainer.Visible = true;
}
}
catch (Exception ex)
{
// Module falied to load
Exceptions.ProcessModuleLoadException(this, ex);
}
}
/// <summary>
/// Handles the <see cref="Control.PreRender"/> event.
/// </summary>
protected void Page_PreRender(object sender, EventArgs e)
{
// Add source and parameters
HtmlIFrame.Attributes.Add("src", Source);
// Add "Unsupported" text
HtmlIFrame.InnerHtml = string.Format(Localization.GetString("Unsupported", LocalResourceFile), Source);
// Add width
if (!(string.IsNullOrEmpty(Width)))
HtmlIFrame.Attributes.Add("width", Width);
// Add height
if (!(string.IsNullOrEmpty(Height)))
HtmlIFrame.Attributes.Add("height", Height);
// Auto Height
if (AutoHeight)
{
int additionalHeight = 0;
if (Border) additionalHeight += 4;
if (Scrolling != Scrolling.No) additionalHeight += 14;
StringBuilder scriptBuilder = new StringBuilder();
scriptBuilder.Append("function autoIFrame(frameId, moreSpace){\r\n");
scriptBuilder.Append(" try{\r\n");
scriptBuilder.Append(" frame = document.getElementById(frameId);\r\n");
scriptBuilder.Append(" innerDoc = (frame.contentDocument) ? frame.contentDocument : frame.contentWindow.document;\r\n");
scriptBuilder.Append(" frame.height = innerDoc.body.scrollHeight + moreSpace;\r\n");
scriptBuilder.Append(" }\r\n");
scriptBuilder.Append(" catch(err){\r\n");
scriptBuilder.Append(" window.status = err.message;\r\n");
scriptBuilder.Append(" }\r\n");
scriptBuilder.Append("}\r\n");
if (!(Page.ClientScript.IsClientScriptBlockRegistered("IFrameAutoResize")))
Page.ClientScript.RegisterClientScriptBlock(GetType(), "IFrameAutoResize", scriptBuilder.ToString(), true);
scriptBuilder.Clear();
scriptBuilder.Append("function resize_");
scriptBuilder.Append(ModuleId);
scriptBuilder.Append("() {\r\n");
scriptBuilder.Append(" if (window.parent && window.parent.autoIFrame) {\r\n");
scriptBuilder.Append(" window.parent.autoIFrame(\"");
scriptBuilder.Append(HtmlIFrame.ClientID);
scriptBuilder.Append("\", ");
scriptBuilder.Append(additionalHeight.ToString("g"));
scriptBuilder.Append(");\r\n");
scriptBuilder.Append(" }\r\n");
scriptBuilder.Append("}\r\n");
if (!(Page.ClientScript.IsClientScriptBlockRegistered(string.Format("AutoResize-{0}", ModuleId))))
Page.ClientScript.RegisterClientScriptBlock(GetType(), string.Format("AutoResize-{0}", ModuleId), scriptBuilder.ToString(), true);
HtmlIFrame.Attributes.Add("onload", string.Format("javascript:resize_{0}()", ModuleId));
}
// Scrolling
if (Scrolling != Scrolling.Auto)
HtmlIFrame.Attributes.Add("scrolling", Enum.GetName(typeof(Scrolling), Scrolling));
// Border
if (!(Border))
HtmlIFrame.Attributes.Add("frameborder", "0");
// AllowTransparency
if (AllowTransparency)
HtmlIFrame.Attributes.Add("allowtransparency", "true");
// Name
if (!(string.IsNullOrEmpty(Name)))
HtmlIFrame.Attributes.Add("name", Name);
// Tooltip
if (!(string.IsNullOrEmpty(ToolTip)))
HtmlIFrame.Attributes.Add("title", ToolTip);
// CssStyle
if (!(string.IsNullOrEmpty(CssStyle)))
HtmlIFrame.Attributes.Add("style", CssStyle);
// OnLoadJavaScript
if ((!(string.IsNullOrEmpty(OnLoadJavaScript))) && (!(AutoHeight)))
HtmlIFrame.Attributes.Add("onload", OnLoadJavaScript);
}
#endregion
#region IActionable
public ModuleActionCollection ModuleActions
{
get
{
ModuleActionCollection actions = new ModuleActionCollection();
actions.Add(GetNextActionID(),
Localization.GetString("EditOptions.Action", LocalResourceFile),
ModuleActionType.ContentOptions,
string.Empty,
string.Empty,
EditUrl(),
false,
SecurityAccessLevel.Edit,
true,
false);
return actions;
}
}
#endregion
}
}