forked from ventrian/News-Articles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Print.aspx.vb
executable file
·312 lines (241 loc) · 13.4 KB
/
Print.aspx.vb
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
'
' News Articles for DotNetNuke - http://www.dotnetnuke.com
' Copyright (c) 2005-2012
' by Ventrian ( sales@ventrian.com ) ( http://www.ventrian.com )
'
Imports System.IO
Imports DotNetNuke.Common
Imports DotNetNuke.Common.Utilities
Imports DotNetNuke.Entities.Modules
Imports DotNetNuke.Framework
Namespace Ventrian.NewsArticles
Partial Public Class Print
Inherits PageBase
#Region " Private Members "
Private _articleID As Integer = Null.NullInteger
Private _moduleID As Integer = Null.NullInteger
Private _tabModuleID As Integer = Null.NullInteger
Private _tabID As Integer = Null.NullInteger
Private _pageID As Integer = Null.NullInteger
Private _portalID As Integer = Null.NullInteger
Private _template As String = Null.NullString
Private _articleSettings As ArticleSettings
#End Region
#Region " Private Methods "
Private Sub ReadQueryString()
If Not (Request("ArticleID") Is Nothing) Then
_articleID = Convert.ToInt32(Request("ArticleID"))
End If
If Not (Request("ModuleID") Is Nothing) Then
_moduleID = Convert.ToInt32(Request("ModuleID"))
End If
If Not (Request("TabID") Is Nothing) Then
_tabID = Convert.ToInt32(Request("TabID"))
End If
If Not (Request("TabModuleID") Is Nothing) Then
_tabModuleID = Convert.ToInt32(Request("TabModuleID"))
End If
If Not (Request("PageID") Is Nothing) Then
_pageID = Convert.ToInt32(Request("PageID"))
End If
If Not (Request("PortalID") Is Nothing) Then
_portalID = Convert.ToInt32(Request("PortalID"))
End If
End Sub
Private Sub ManageStyleSheets(ByVal PortalCSS As Boolean)
' initialize reference paths to load the cascading style sheets
Dim objCSS As Control = Me.FindControl("CSS")
Dim objLink As HtmlGenericControl
Dim ID As String
Dim objCSSCache As Hashtable = CType(DataCache.GetCache("CSS"), Hashtable)
If objCSSCache Is Nothing Then
objCSSCache = New Hashtable
End If
If Not objCSS Is Nothing Then
If PortalCSS = False Then
' module style sheet
ID = CreateValidID("PropertyAgent")
objLink = New HtmlGenericControl("link")
objLink.ID = ID
objLink.Attributes("rel") = "stylesheet"
objLink.Attributes("type") = "text/css"
objLink.Attributes("href") = Me.ResolveUrl("module.css")
objCSS.Controls.Add(objLink)
' default style sheet ( required )
ID = CreateValidID(DotNetNuke.Common.Globals.HostPath)
objLink = New HtmlGenericControl("link")
objLink.ID = ID
objLink.Attributes("rel") = "stylesheet"
objLink.Attributes("type") = "text/css"
objLink.Attributes("href") = DotNetNuke.Common.Globals.HostPath & "default.css"
objCSS.Controls.Add(objLink)
' skin package style sheet
ID = CreateValidID(PortalSettings.ActiveTab.SkinPath)
If objCSSCache.ContainsKey(ID) = False Then
If File.Exists(Server.MapPath(PortalSettings.ActiveTab.SkinPath) & "skin.css") Then
objCSSCache(ID) = PortalSettings.ActiveTab.SkinPath & "skin.css"
Else
objCSSCache(ID) = ""
End If
If Not DotNetNuke.Common.Globals.PerformanceSetting = DotNetNuke.Common.Globals.PerformanceSettings.NoCaching Then
DataCache.SetCache("CSS", objCSSCache)
End If
End If
If objCSSCache(ID).ToString <> "" Then
objLink = New HtmlGenericControl("link")
objLink.ID = ID
objLink.Attributes("rel") = "stylesheet"
objLink.Attributes("type") = "text/css"
objLink.Attributes("href") = objCSSCache(ID).ToString
objCSS.Controls.Add(objLink)
End If
' skin file style sheet
ID = CreateValidID(Replace(PortalSettings.ActiveTab.SkinSrc, ".ascx", ".css"))
If objCSSCache.ContainsKey(ID) = False Then
If File.Exists(Server.MapPath(Replace(PortalSettings.ActiveTab.SkinSrc, ".ascx", ".css"))) Then
objCSSCache(ID) = Replace(PortalSettings.ActiveTab.SkinSrc, ".ascx", ".css")
Else
objCSSCache(ID) = ""
End If
If Not DotNetNuke.Common.Globals.PerformanceSetting = DotNetNuke.Common.Globals.PerformanceSettings.NoCaching Then
DataCache.SetCache("CSS", objCSSCache)
End If
End If
If objCSSCache(ID).ToString <> "" Then
objLink = New HtmlGenericControl("link")
objLink.ID = ID
objLink.Attributes("rel") = "stylesheet"
objLink.Attributes("type") = "text/css"
objLink.Attributes("href") = objCSSCache(ID).ToString
objCSS.Controls.Add(objLink)
End If
Else
' portal style sheet
ID = CreateValidID(PortalSettings.HomeDirectory)
objLink = New HtmlGenericControl("link")
objLink.ID = ID
objLink.Attributes("rel") = "stylesheet"
objLink.Attributes("type") = "text/css"
objLink.Attributes("href") = PortalSettings.HomeDirectory & "portal.css"
objCSS.Controls.Add(objLink)
End If
End If
End Sub
Private Sub BindArticle()
If (_articleID = Null.NullInteger) Then
Response.Redirect(NavigateURL(_tabID), True)
End If
Dim objArticleController As New ArticleController
Dim objArticle As ArticleInfo = objArticleController.GetArticle(_articleID)
If Not (objArticle Is Nothing) Then
' Check Article Security
If (objArticle.IsSecure) Then
If (ArticleSettings.IsSecureEnabled = False) Then
If (ArticleSettings.SecureUrl <> "") Then
Dim url As String = Request.Url.ToString().Replace(AddHTTP(Request.Url.Host), "")
If (ArticleSettings.SecureUrl.IndexOf("?") <> -1) Then
Response.Redirect(ArticleSettings.SecureUrl & "&returnurl=" & Server.UrlEncode(url), True)
Else
Response.Redirect(ArticleSettings.SecureUrl & "?returnurl=" & Server.UrlEncode(url), True)
End If
Else
Response.Redirect(NavigateURL(_tabID), True)
End If
End If
End If
Dim objModuleController As New ModuleController
Dim objModule As ModuleInfo = objModuleController.GetModule(objArticle.ModuleID, _tabID)
If Not (objModule Is Nothing) Then
If (DotNetNuke.Security.PortalSecurity.IsInRoles(objModule.AuthorizedViewRoles) = False) Then
Response.Redirect(NavigateURL(_tabID), True)
End If
If (objModule.PortalID <> PortalSettings.PortalId) Then
Response.Redirect(NavigateURL(_tabID), True)
End If
End If
Dim objLayoutController As New LayoutController(PortalSettings, ArticleSettings, objModule, Page)
'Dim objLayoutController As New LayoutController(PortalSettings, ArticleSettings, Page, False, _tabID, _moduleID, _tabModuleID, _portalID, _pageID, Null.NullInteger, "Articles-Print-" & _moduleID.ToString())
Dim objLayoutItem As LayoutInfo = LayoutController.GetLayout(ArticleSettings, objModule, Page, LayoutType.Print_Item_Html)
objLayoutController.ProcessArticleItem(phArticle.Controls, objLayoutItem.Tokens, objArticle)
objLayoutController.LoadStyleSheet(ArticleSettings.Template)
Dim objLayoutTitle As LayoutInfo = LayoutController.GetLayout(ArticleSettings, objModule, Page, LayoutType.View_Title_Html)
If (objLayoutTitle.Template <> "") Then
Dim phPageTitle As New PlaceHolder()
objLayoutController.ProcessArticleItem(phPageTitle.Controls, objLayoutTitle.Tokens, objArticle)
Me.Title = RenderControlToString(phPageTitle)
End If
Dim objLayoutDescription As LayoutInfo = LayoutController.GetLayout(ArticleSettings, objModule, Page, LayoutType.View_Description_Html)
If (objLayoutDescription.Template <> "") Then
Dim phPageDescription As New PlaceHolder()
objLayoutController.ProcessArticleItem(phPageDescription.Controls, objLayoutDescription.Tokens, objArticle)
Dim meta As New HtmlMeta
meta.Name = "MetaDescription"
meta.Content = RenderControlToString(phPageDescription)
If (meta.Content <> "") Then
Me.Header.Controls.Add(meta)
End If
End If
Dim objLayoutKeyword As LayoutInfo = LayoutController.GetLayout(ArticleSettings, objModule, Page, LayoutType.View_Keyword_Html)
If (objLayoutKeyword.Template <> "") Then
Dim phPageKeyword As New PlaceHolder()
objLayoutController.ProcessArticleItem(phPageKeyword.Controls, objLayoutKeyword.Tokens, objArticle)
Dim meta As New HtmlMeta
meta.Name = "MetaKeywords"
meta.Content = RenderControlToString(phPageKeyword)
If (meta.Content <> "") Then
Me.Header.Controls.Add(meta)
End If
End If
Else
Response.Redirect(NavigateURL(), True)
End If
End Sub
Protected Function GetSharedResource(ByVal key As String) As String
Dim path As String = Me.TemplateSourceDirectory & "/" & DotNetNuke.Services.Localization.Localization.LocalResourceDirectory & "/" & DotNetNuke.Services.Localization.Localization.LocalSharedResourceFile
path = "~" & path.Substring(path.IndexOf("/DesktopModules/"), path.Length - path.IndexOf("/DesktopModules/"))
Return DotNetNuke.Services.Localization.Localization.GetString(key, path)
End Function
Private Function RenderControlToString(ByVal ctrl As Control) As String
Dim sb As New StringBuilder()
Dim tw As New IO.StringWriter(sb)
Dim hw As New HtmlTextWriter(tw)
ctrl.RenderControl(hw)
Return sb.ToString()
End Function
Protected Function StripHtml(ByVal html As String) As String
Dim pattern As String = "<(.|\n)*?>"
Return Regex.Replace(html, pattern, String.Empty)
End Function
#End Region
#Region " Private Properties "
Public ReadOnly Property BasePage() As DotNetNuke.Framework.CDefault
Get
Return CType(Me.Page, DotNetNuke.Framework.CDefault)
End Get
End Property
Public ReadOnly Property ArticleSettings() As ArticleSettings
Get
If (_articleSettings Is Nothing) Then
Dim objModuleController As New ModuleController
Dim settings As Hashtable = objModuleController.GetModuleSettings(_moduleID)
'Add TabModule Settings
settings = DotNetNuke.Entities.Portals.PortalSettings.GetTabModuleSettings(_tabModuleID, settings)
Dim objModule As ModuleInfo = objModuleController.GetModule(_moduleID, _tabID)
_articleSettings = New ArticleSettings(settings, Me.PortalSettings, objModule)
End If
Return _articleSettings
End Get
End Property
#End Region
#Region " Event Handlers "
Private Sub Page_Initialization(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
ManageStyleSheets(False)
ManageStyleSheets(True)
ReadQueryString()
BindArticle()
End Sub
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
#End Region
End Class
End Namespace