-
Notifications
You must be signed in to change notification settings - Fork 0
/
Helpers.vbhtml
131 lines (124 loc) · 6.37 KB
/
Helpers.vbhtml
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
@Helper Copyright()
' Razor Portfolio VB.NET Version 1.0.0.0
' WWWeb Concepts Copyright 2017 (wwwebconcepts.com )
' James W. Threadgill [email protected]
'=========================================================================================================================================================
' MIT License
' Copyright(c) 2017 James Threadgill
' 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.
'=============================================================================================================================================================
End Helper
@Helper SetTheme()
' Get template according to device or request
Dim strTheme As String = HttpContext.Current.Application("Theme")
Dim mTheme As String = HttpContext.Current.Application("MobileTheme")
Dim SessionTheme As String = HttpContext.Current.Session.Item("SessionTheme")
Dim ThemeCookie As String = ""
If Not HttpContext.Current.Request.Cookies("ThemeCookie") Is Nothing Then
ThemeCookie = HttpContext.Current.Request.Cookies("ThemeCookie").ToString
End If
If String.IsNullOrEmpty(SessionTheme) And String.IsNullOrEmpty(ThemeCookie) Then InitializeApplication.InitializeTheme()
If ThemeCookie = "Mobile" Or SessionTheme = "Mobile" And Not String.IsNullOrEmpty(mTheme) Then
strTheme = "~/" & mTheme
Else
strTheme = "~/" & strTheme
End If
@strTheme
End Helper
@Helper Canonical()
' Get page as desktop for use in desktop template
Dim strProtocol As String = Request.Url.Scheme & "://"
Dim qString As String = Request.ServerVariables("QUERY_STRING")
Dim strCanonical As String = HttpContext.Current.Application("CanonicalDomain") & Strings.Replace(Request.ServerVariables("SCRIPT_NAME"), ".vbhtml", "")
Try
If Not String.IsNullOrEmpty(qString) Then
If InStr(qString, "&Theme=d") Then
qString = Strings.Replace(qString, "&Theme=d", "")
ElseIf InStr(qString, "Theme=d") Then
qString = Strings.Replace(qString, "Theme=d", "")
ElseIf InStr(qString, "&Theme=m") Then
qString = Strings.Replace(qString, "&Theme=m", "")
ElseIf InStr(qString, "Theme=m") Then
qString = Strings.Replace(qString, "Theme=m", "")
End If
End If
If Not String.IsNullOrEmpty(qString) Then
strCanonical = strProtocol & strCanonical & "?" & qString
Else
strCanonical = strProtocol & strCanonical
End If
strCanonical = URL.Rewrite(Server.HtmlEncode(strCanonical))
@Html.Raw(strCanonical)
Catch e As Exception
'Dont show the error.
End Try
End Helper
@Helper GetBasePath()
' Get application base path
Dim strPath As String = ""
Dim strProtocol As String = Request.Url.Scheme & "://"
Dim port As String = Request.Url.Port
If port <> 80 And port <> 433 Then port = ":" & port Else port = ""
Dim strAppInstallFolder As String = InitializeApplication.AppInstallFolder()
If Not String.IsNullOrEmpty(strAppInstallFolder) Then strAppInstallFolder &= "/"
strPath = strProtocol & Request.ServerVariables("SERVER_NAME") & port & "/" & strAppInstallFolder
@strPath
End Helper
@Helper PageAsMobile()
' Get page link as mobile for use in desktop template
Dim strPageM As String = Strings.Replace(Request.ServerVariables("SCRIPT_NAME"), ".vbhtml", "")
Dim qString As String = Request.ServerVariables("QUERY_STRING")
Dim mTheme As String = HttpContext.Current.Application("MobileTheme")
Try
If Not String.IsNullOrEmpty(mTheme) Then
If Not String.IsNullOrEmpty(qString) Then
strPageM = Strings.Replace(strPageM, ".vbhtml", "") & "?" & qString
If InStr(qString, "Theme=d") Then
strPageM = Strings.Replace(strPageM, "Theme=d", "Theme=m")
Else
strPageM &= "&Theme=m"
End If
Else
strPageM &= "?Theme=m"
End If
Else
strPageM = ""
End If
strPageM = URL.Rewrite(Server.HtmlEncode(strPageM))
If InStr(strPageM, "?N=") Then strPageM = Replace(strPageM, "?Theme=", "&Theme=")
@Html.Raw(strPageM)
Catch e As Exception
'Dont show the error.
End Try
End Helper
@Helper PageAsDesktop()
' Get page link as desktop for use in mobile template
Dim strPageD As String = Strings.Replace(Request.ServerVariables("SCRIPT_NAME"), ".vbhtml", "")
Dim qString As String = Request.ServerVariables("QUERY_STRING")
Try
If Not String.IsNullOrEmpty(qString) Then
strPageD = Strings.Replace(strPageD, ".vbhtml", "") & "?" & qString
If InStr(qString, "Theme=m") Then
strPageD = Strings.Replace(strPageD, "Theme=m", "Theme=d")
Else
strPageD &= "&Theme=d"
End If
Else
strPageD &= "?Theme=d"
End If
strPageD = URL.Rewrite(Server.HtmlEncode(strPageD))
If InStr(strPageD, "?N=") Then strPageD = Replace(strPageD, "?Theme=", "&Theme=")
@Html.Raw(strPageD)
Catch e As Exception
'Dont show the error.
End Try
End Helper