This repository has been archived by the owner on Feb 12, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathView.ascx.vb
220 lines (146 loc) · 7.57 KB
/
View.ascx.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
Imports DotNetNuke
Imports DotNetNuke.Entities.Modules.Actions
Imports DotNetNuke.Entities.Modules
Imports DotNetNuke.Services.Exceptions
Imports DotNetNuke.Services.Localization
Imports System.IO
Imports DotNetNuke.Framework
Public Class View
Inherits PortalModuleBase
#Region "Private Members"
Private _TokenKey As String = ""
Private _TokenSecret As String = ""
Private _ConsumerKey As String = ""
Private _ConsumerSecret As String = ""
Private _Displaymode As String = ""
Private _Template As String = Me.TemplateSourceDirectory & "\templates\_default.html"
Private _SearchFor As String = ""
Private _PostCount As String = "10"
Private _RefreshInterval As String = "30"
Private _RenderingMode As String = "S"
Private _processor As TemplateProcessor = Nothing
#End Region
#Region "Event Handlers"
Protected Sub Page_Init(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Init
Try
ServicesFramework.Instance.RequestAjaxAntiForgerySupport()
LoadSettings()
If ValidateSettings() Then
pnlSettingsIncomplete.Visible = False
RegisterCss()
If _RenderingMode = "C" Then
RegisterScripts()
rptFeed.Visible = False
pnlClientSideTweets.Visible = True
Else
_processor = New TemplateProcessor(Settings)
rptFeed.Visible = True
BindData()
pnlClientSideTweets.Visible = False
End If
Else
rptFeed.Visible = False
pnlSettingsIncomplete.Visible = True
lblSettingsIncomplete.Text = Localization.GetString("lblSettingsIncomplete", LocalResourceFile)
End If
Catch exc As Exception
Exceptions.ProcessModuleLoadException(Me, exc)
End Try
End Sub
Private Sub rptFeed_ItemDataBound(sender As Object, e As RepeaterItemEventArgs) Handles rptFeed.ItemDataBound
Dim strTemplate As String = Server.MapPath(_Template)
If (e.Item.ItemType = ListItemType.Header) Then
strTemplate += "\Header.htm"
strTemplate = strTemplate.Replace("\\", "\")
_processor.ProcessSurroundingTemplate(e.Item.Controls, Helpers.ReadTemplate(strTemplate))
End If
If e.Item.ItemType = ListItemType.Item Then
Dim objPost As TwitterPost = CType(e.Item.DataItem, TwitterPost)
strTemplate += "\Item.htm"
strTemplate = strTemplate.Replace("\\", "\")
_processor.ProcessItemTemplate(e.Item.Controls, Helpers.ReadTemplate(strTemplate), objPost)
End If
If e.Item.ItemType = ListItemType.AlternatingItem Then
Dim objPost As TwitterPost = CType(e.Item.DataItem, TwitterPost)
strTemplate += "\ItemAlternate.htm"
strTemplate = strTemplate.Replace("\\", "\")
_processor.ProcessItemTemplate(e.Item.Controls, Helpers.ReadTemplate(strTemplate), objPost)
End If
If (e.Item.ItemType = ListItemType.Footer) Then
strTemplate += "\Footer.htm"
strTemplate = strTemplate.Replace("\\", "\")
_processor.ProcessSurroundingTemplate(e.Item.Controls, Helpers.ReadTemplate(strTemplate))
End If
End Sub
#End Region
#Region "Private Methods"
Private Sub RegisterCss()
Dim strCssUrl As String = _Template & "/template.css"
Dim blnAlreadyRegistered As Boolean = False
For Each ctrl As Control In Me.Page.Header.Controls
If TypeOf (ctrl) Is HtmlLink Then
Dim ctrlCss As HtmlLink = CType(ctrl, HtmlLink)
If ctrlCss.Href.ToLower = strCssUrl.ToLower Then
blnAlreadyRegistered = True
Exit For
End If
End If
Next
If Not blnAlreadyRegistered Then
Dim ctrlLink As New HtmlLink
ctrlLink.Href = strCssUrl
ctrlLink.Attributes.Add("rel", "stylesheet")
ctrlLink.Attributes.Add("type", "text/css")
ctrlLink.Attributes.Add("media", "screen")
Me.Page.Header.Controls.Add(ctrlLink)
End If
End Sub
Private Sub RegisterScripts()
Dim strScript As String = vbCrLf & "<script type=""text/javascript"">" & vbCrLf & vbCrLf
strScript += " (function ($, Sys) {" & vbCrLf
strScript += " $(document).ready(function () {" & vbCrLf
strScript += " setupTweets(" & ModuleId.ToString & ");" & vbCrLf
strScript += " setInterval(function() { setupTweets(" & ModuleId.ToString & ") }, " & (_RefreshInterval * 1000) & ");" & vbCrLf
strScript += " Sys.WebForms.PageRequestManager.getInstance().add_endRequest(function () {" & vbCrLf
strScript += " setupTweets(" & ModuleId.ToString & ");" & vbCrLf
strScript += " setInterval(function() { setupTweets(" & ModuleId.ToString & ") }, " & (_RefreshInterval * 1000) & ");" & vbCrLf
strScript += " });" & vbCrLf
strScript += " });" & vbCrLf & vbCrLf
strScript += " }(jQuery, window.Sys));" & vbCrLf
strScript += "</script>" & vbCrLf
Me.Page.ClientScript.RegisterClientScriptInclude("ConnectTwitterFeed", ResolveClientUrl(Me.TemplateSourceDirectory & "/js/TwitterFeed.js"))
Page.ClientScript.RegisterStartupScript(Me.[GetType](), "ConnectTwitterFeedScriptBlock", strScript)
End Sub
Private Sub BindData()
Dim feed As New List(Of TwitterPost)
Dim ctrl As New FeedController(_TokenKey, _TokenSecret, _ConsumerKey, _ConsumerSecret)
Select Case _Displaymode.ToLower
Case "u"
feed = ctrl.GetUserTimeLine(_SearchFor, _PostCount)
Case "s"
feed = ctrl.SearchTweets(_SearchFor, _PostCount)
End Select
rptFeed.DataSource = feed
rptFeed.DataBind()
End Sub
Private Sub LoadSettings()
If (Settings.Contains("Twitter_SelectedTemplate")) Then _Template = Settings("Twitter_SelectedTemplate").ToString()
If (Settings.Contains("Twitter_DisplayMode")) Then _Displaymode = Settings("Twitter_DisplayMode").ToString()
If (Settings.Contains("Twitter_ConsumerKey")) Then _ConsumerKey = Settings("Twitter_ConsumerKey").ToString()
If (Settings.Contains("Twitter_ConsumerSecret")) Then _ConsumerSecret = Settings("Twitter_ConsumerSecret").ToString()
If (Settings.Contains("Twitter_TokenKey")) Then _TokenKey = Settings("Twitter_TokenKey").ToString()
If (Settings.Contains("Twitter_TokenSecret")) Then _TokenSecret = Settings("Twitter_TokenSecret").ToString()
If (Settings.Contains("Twitter_SearchFor")) Then _SearchFor = Settings("Twitter_SearchFor").ToString()
If (Settings.Contains("Twitter_PostCount")) Then _PostCount = Settings("Twitter_PostCount").ToString()
If (Settings.Contains("Twitter_RefreshInterval")) Then _RefreshInterval = Settings("Twitter_RefreshInterval").ToString()
If (Settings.Contains("Twitter_RenderingMode")) Then _RenderingMode = Settings("Twitter_RenderingMode").ToString()
End Sub
Private Function ValidateSettings() As Boolean
If String.IsNullOrEmpty(_TokenKey) Or String.IsNullOrEmpty(_TokenSecret) Or String.IsNullOrEmpty(_ConsumerKey) Or String.IsNullOrEmpty(_ConsumerSecret) Or String.IsNullOrEmpty(_SearchFor) Then
Return False
End If
Return True
End Function
#End Region
End Class