-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathRespondPage.aspx.cs
258 lines (234 loc) · 10.9 KB
/
RespondPage.aspx.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
// <copyright file="RespondPage.aspx.cs" company="Engage Software">
// Engage: Events - http://www.EngageSoftware.com
// Copyright (c) 2004-2011
// by Engage Software ( http://www.engagesoftware.com )
// </copyright>
// 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.
namespace Engage.Dnn.Events
{
using System;
using System.Collections;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.IO;
using System.Web.Hosting;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using DotNetNuke.Entities.Modules;
using DotNetNuke.Framework;
using DotNetNuke.Services.Exceptions;
using DotNetNuke.UI.Utilities;
using Globals = DotNetNuke.Common.Globals;
/// <summary>
/// Code behind for a page that loads the <see cref="Respond"/> control.
/// </summary>
public partial class RespondPage : PageBase
{
/// <summary>
/// Gets the tab ID of the module calling this page.
/// </summary>
/// <value>The tab ID of the calling module.</value>
private int TabId
{
get
{
int tabId;
if (int.TryParse(this.Request.QueryString["TabId"], NumberStyles.Integer, CultureInfo.InvariantCulture, out tabId))
{
return tabId;
}
return new ModuleController().GetModuleByDefinition(this.PortalSettings.PortalId, Utility.DesktopModuleName).TabID;
}
}
/// <summary>
/// Gets the module ID of the module calling this page.
/// </summary>
/// <value>The module ID of the calling module.</value>
private int ModuleId
{
get
{
int moduleId;
if (int.TryParse(this.Request.QueryString["ModuleId"], NumberStyles.Integer, CultureInfo.InvariantCulture, out moduleId))
{
return moduleId;
}
return new ModuleController().GetModuleByDefinition(this.PortalSettings.PortalId, Utility.DesktopModuleName).ModuleID;
}
}
/// <summary>
/// Raises the <see cref="Control.Init"/> event.
/// </summary>
/// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
protected override void OnInit(EventArgs e)
{
try
{
AJAX.AddScriptManager(this.Page);
base.OnInit(e);
this.Load += this.Page_Load;
}
catch (Exception exc)
{
Exceptions.ProcessModuleLoadException(this, exc);
}
}
/// <summary>
/// Handles the Load event of the Page control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
private void Page_Load(object sender, EventArgs e)
{
try
{
this.RespondControl.ModuleConfiguration = new ModuleController().GetModule(this.ModuleId, this.TabId);
this.LoadStylesheets();
}
catch (Exception exc)
{
Exceptions.ProcessModuleLoadException(this, exc);
}
}
/// <summary>
/// Loads the CSS stylesheets for this page
/// </summary>
/// <remarks>
/// Based on the method of the same name in <see cref="DotNetNuke.Framework.CDefault"/> (version 4.8.2),
/// combined with similar code in InjectSkin,
/// translated through <see href="http://www.codechanger.com/"/>.
/// </remarks>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Globalization", "CA1307:SpecifyStringComparison", MessageId = "System.String.LastIndexOf(System.String)", Justification = "Mimicking the behavior of DNN core"),
System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Globalization", "CA1307:SpecifyStringComparison", MessageId = "System.String.EndsWith(System.String)", Justification = "Mimicking the behavior of DNN core"),
System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Globalization", "CA1304:SpecifyCultureInfo", MessageId = "System.String.ToLower", Justification = "Mimicking the behavior of DNN core")]
private void LoadStylesheets()
{
string id;
Hashtable stylesheetCache = DataCache.GetCache("CSS") as Hashtable ?? new Hashtable();
// module stylesheet
bool saveCache = false;
ModuleInfo moduleConfiguration = this.RespondControl.ModuleConfiguration;
if (moduleConfiguration.ControlSrc.ToLower().EndsWith(".ascx"))
{
// Get module.css from Path to control
id = Globals.CreateValidID(Globals.ApplicationPath + "/" + moduleConfiguration.ControlSrc.Substring(0, moduleConfiguration.ControlSrc.LastIndexOf("/")));
if (!stylesheetCache.ContainsKey(id))
{
string moduleControlStylesheetPath = Globals.ApplicationPath + "/" + moduleConfiguration.ControlSrc.Substring(0, moduleConfiguration.ControlSrc.LastIndexOf("/") + 1);
if (File.Exists(HostingEnvironment.MapPath(moduleControlStylesheetPath) + "module.css"))
{
stylesheetCache[id] = moduleControlStylesheetPath + "module.css";
}
else
{
stylesheetCache[id] = string.Empty;
}
saveCache = true;
}
}
else
{
// Get module.css from Folder
id = Globals.CreateValidID(Globals.ApplicationPath + "/" + moduleConfiguration.FolderName);
if (!stylesheetCache.ContainsKey(id))
{
string moduleStylesheetPath = Globals.ApplicationPath + "/" + moduleConfiguration.FolderName + "/module.css";
if (File.Exists(HostingEnvironment.MapPath(moduleStylesheetPath)))
{
stylesheetCache[id] = moduleStylesheetPath;
}
else
{
stylesheetCache[id] = string.Empty;
}
saveCache = true;
}
}
if (saveCache && Globals.PerformanceSetting != Globals.PerformanceSettings.NoCaching)
{
DataCache.SetCache("CSS", stylesheetCache);
}
if (!string.IsNullOrEmpty(stylesheetCache[id].ToString()))
{
// Add it to beginning of style list
this.AddStylesheet(id, stylesheetCache[id].ToString());
}
// default style sheet ( required )
id = Globals.CreateValidID(Globals.HostPath);
this.AddStylesheet(id, Globals.HostPath + "default.css");
// skin package style sheet
id = Globals.CreateValidID(this.PortalSettings.ActiveTab.SkinPath);
if (!stylesheetCache.ContainsKey(id))
{
if (File.Exists(HostingEnvironment.MapPath(this.PortalSettings.ActiveTab.SkinPath) + "skin.css"))
{
stylesheetCache[id] = this.PortalSettings.ActiveTab.SkinPath + "skin.css";
}
else
{
stylesheetCache[id] = string.Empty;
}
if (Globals.PerformanceSetting != Globals.PerformanceSettings.NoCaching)
{
DataCache.SetCache("CSS", stylesheetCache);
}
}
if (!string.IsNullOrEmpty(stylesheetCache[id].ToString()))
{
this.AddStylesheet(id, stylesheetCache[id].ToString());
}
// skin file style sheet
string skinFileStylesheetPath = this.PortalSettings.ActiveTab.SkinSrc.Replace(".ascx", ".css");
id = Globals.CreateValidID(skinFileStylesheetPath);
if (!stylesheetCache.ContainsKey(id))
{
if (File.Exists(HostingEnvironment.MapPath(skinFileStylesheetPath)))
{
stylesheetCache[id] = skinFileStylesheetPath;
}
else
{
stylesheetCache[id] = string.Empty;
}
if (Globals.PerformanceSetting != Globals.PerformanceSettings.NoCaching)
{
DataCache.SetCache("CSS", stylesheetCache);
}
}
if (!string.IsNullOrEmpty(stylesheetCache[id].ToString()))
{
this.AddStylesheet(id, stylesheetCache[id].ToString());
}
// portal style sheet
id = Globals.CreateValidID(this.PortalSettings.HomeDirectory);
this.AddStylesheet(id, this.PortalSettings.HomeDirectory + "portal.css");
}
/// <summary>
/// Adds the style-sheet to the page header.
/// </summary>
/// <remarks>
/// Based on the method of the same name in <see cref="DotNetNuke.Framework.CDefault"/> (version 4.8.2),
/// translated through <see href="http://www.codechanger.com/"/>.
/// </remarks>
/// <param name="id">The id to use for the style-sheet link.</param>
/// <param name="path">The path to the style-sheet.</param>
[SuppressMessage("Microsoft.Reliability", "CA2000", Justification = "stylesheetLink is passed to the Page Controls collection and does not need to be manually disposed")]
private void AddStylesheet(string id, string path)
{
// First see if we have already added the <LINK> control
if (this.Page.Header.FindControl(id) == null)
{
HtmlLink stylesheetLink = new HtmlLink();
stylesheetLink.ID = id;
stylesheetLink.Attributes["rel"] = "stylesheet";
stylesheetLink.Attributes["type"] = "text/css";
stylesheetLink.Href = path;
this.Page.Header.Controls.Add(stylesheetLink);
}
}
}
}