This repository was archived by the owner on Dec 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathAggregator.ascx.vb
1166 lines (951 loc) · 50.4 KB
/
Aggregator.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
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
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
Option Strict On
Option Explicit On
Imports System
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Text
Imports System.IO
Imports System.Text.RegularExpressions
Imports System.Xml
Imports System.Net
Imports DotNetNuke
Imports DotNetNuke.Entities.Modules
Imports DotNetNuke.Entities.Portals
Imports DotNetNuke.Security
Imports DotNetNuke.Services.Localization
Imports DotNetNuke.Common
Imports DotNetNuke.Common.Utilities
Imports DotNetNuke.Services.Exceptions
Imports RssToolkit.Rss
Namespace DNNStuff.Aggregator
Partial Class Aggregator
Inherits Entities.Modules.PortalModuleBase
Implements Entities.Modules.Communications.IModuleListener
Implements Entities.Modules.IActionable
' currently selected tab
Private _selectedTabNumber As Integer = 1
' object graph for tabs and contained modules
Private _aggregator As AggregatorInfo = New AggregatorInfo
' module settings
Private _ms As ModuleSettings
' token settings
Private _aggregatorTokens As Hashtable
#Region " Properties"
Private ReadOnly Property SettingsFilename() As String
Get
Return IO.Path.Combine(MapPath(SkinFolder), "settings.xml")
End Get
End Property
Private ReadOnly Property SkinFilename() As String
Get
Return ResolveUrl(SkinFolder & "/styles.css")
End Get
End Property
Private ReadOnly Property SkinFolder() As String
Get
Return ResolveUrl(String.Format("Skins/{0}/{1}", _ms.TabSkin, _ms.TabTemplate))
End Get
End Property
Private ReadOnly Property ResourceFolder() As String
Get
Return ResolveUrl(String.Format("Resources"))
End Get
End Property
Private ReadOnly Property SkinBaseFolder() As String
Get
Return ResolveUrl(String.Format("Skins/{0}", _ms.TabSkin))
End Get
End Property
Private ReadOnly Property Unique(ByVal s As String, Optional ByVal scope As String = "module") As String
' make string unique for this module instance
Get
Select Case scope.ToLower
Case "template"
Return "Agg" & _ms.TabSkin & "_" & _ms.TabTemplate & "_" & s
Case "skin"
Return "Agg" & _ms.TabSkin & "_" & s
Case "resource"
Return "Agg" & "_" & s
Case Else
Return "Agg" & Me.ModuleId.ToString & "_" & s
End Select
End Get
End Property
#End Region
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
'NOTE: The following placeholder declaration is required by the Web Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
' settings
_ms = New ModuleSettings(ModuleId)
' inject css
DNNUtilities.InjectCSS(Page, SkinFilename)
' inject js libraries appearing on every page
Page.ClientScript.RegisterClientScriptInclude("dnnstuff", ResolveUrl("Resources/Support/dnnstuff-min.js"))
' render tabs
RenderTabs()
' inject partial rendering modules here so they work
' module menus are still slighly affected but are still usuable
InjectIntoTabsPartialRendering()
End Sub
Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
' register the client api
DotNetNuke.UI.Utilities.ClientAPI.RegisterClientReference(Me.Page, DotNetNuke.UI.Utilities.ClientAPI.ClientNamespaceReferences.dnn)
' load jQuery and UI
DotNetNuke.Framework.jQuery.RequestRegistration()
DotNetNuke.Framework.jQuery.RequestUIRegistration()
' inject non partial rendering modules here so that databinding works properly in the injected modules
' and the menus act normal
InjectIntoTabsNonPartialRendering()
End Sub
Private Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender
' inject inline javascript - moved here to ensure it comes after the DNN5 jquery include
If Not (_aggregator.SingleTab And _ms.HideSingleTab) Then
Dim t As New Template(_ms, MapPath(SkinFolder), MapPath(ResourceFolder()))
InjectScript(t, "script", "body", "template", True)
InjectScript(t, "head", "head", "resource", False)
InjectScript(t, "head", "head", "skin", False)
InjectScript(t, "head", "head", "template", False)
End If
End Sub
#End Region
#Region " Optional Interfaces"
Public ReadOnly Property ModuleActions() As Entities.Modules.Actions.ModuleActionCollection Implements Entities.Modules.IActionable.ModuleActions
Get
Dim Actions As New Entities.Modules.Actions.ModuleActionCollection
Actions.Add(GetNextActionID, Localization.GetString(Entities.Modules.Actions.ModuleActionType.ContentOptions, LocalResourceFile), Entities.Modules.Actions.ModuleActionType.ContentOptions, "", "", EditUrl(), False, SecurityAccessLevel.Edit, True, False)
Actions.Add(GetNextActionID, Localization.GetString("CopyAggregator", LocalResourceFile), Entities.Modules.Actions.ModuleActionType.ExportModule, "", "", EditUrl("CopyAggregator"), False, SecurityAccessLevel.Admin, True, False)
Actions.Add(GetNextActionID, Localization.GetString("ManageSkin", LocalResourceFile), Entities.Modules.Actions.ModuleActionType.ImportModule, "", "", EditUrl("ManageSkin"), False, SecurityAccessLevel.Admin, True, False)
Actions.Add(GetNextActionID, Localization.GetString("UploadSkin", LocalResourceFile), Entities.Modules.Actions.ModuleActionType.ImportModule, "", "", EditUrl("UploadSkin"), False, SecurityAccessLevel.Host, True, False)
Return Actions
End Get
End Property
#End Region
#Region " Main Rendering"
Private Sub LoadAggregator()
' Load ModuleInfo objects for all tabs we will be Aggregating
Dim ctrl As New AggregatorController
_aggregator = ctrl.GetAggregatorObjectGraph(ModuleId, _ms.TabSkin, _ms.TabTemplate)
' process tabs hidden by querystring
RemoveQueryStringModules()
' process locale settings
RemoveLocaleSpecificModules()
RemoveLocaleSpecificTabs()
' remove additional modules based on security
RemoveInvisibleModules()
' update captions
UpdateTabCaptions()
' remove tabs if no modules inside, or no text to show
RemoveEmptyTabs()
' add tabs based on rss
AddRSSTabs()
' get selected module
_selectedTabNumber = GetSelectedTab()
End Sub
Private Sub AddRSSTabs()
If _ms.RSSUrl.Length = 0 Then Exit Sub
' grab feed
Dim feed As RssToolkit.Rss.RssDocument = DownloadFeed()
If feed Is Nothing Then Exit Sub
' determine max items
Dim maxItems As Integer = _ms.RSSMaxItems
If maxItems = 0 Then maxItems = feed.Channel.Items.Count
' template
Dim t As New Template(_ms, MapPath(SkinFolder), MapPath(ResourceFolder))
Dim item As RssItem
For itemIndex As Integer = 0 To Math.Min(maxItems - 1, feed.Channel.Items.Count - 1)
item = feed.Channel.Items(itemIndex)
Dim ati As New AggregatorTabInfo
With ati
.Caption = GetRSSTabCaptionTemplate(_ms.RSSTabCaption, item)
.HtmlText = GetRSSContentTemplate(t, item)
.ModuleId = Me.ModuleId
.AggregatorTabId = -1
.Modules = New ArrayList
.Properties = New ArrayList
.RSS = RSSItemSettings(item)
End With
_aggregator.Tabs.Add(ati)
Next
End Sub
Private Sub UpdateTabCaptions()
' process tabs
Dim tabNumber As Integer = 1
For Each ai As AggregatorTabInfo In _aggregator.Tabs
' update caption
If ai.Caption.Contains("[") And ai.Caption.Contains("]") Then
ai.Caption = ReplaceAggregatorTabInfoTokens(ai.Caption, ai, tabNumber)
tabNumber += 1
End If
Next
End Sub
Private Sub RemoveInvisibleModules()
Dim includeModule As Boolean
' process tabs
For Each ai As AggregatorTabInfo In _aggregator.Tabs
For Each ami As AggregatorModuleInfo In New ArrayList(ai.Modules)
includeModule = False
If Not ami.ModuleInfo Is Nothing Then
includeModule = Compatibility.IncludeModule(ami.ModuleInfo, PortalSettings)
End If
' update or remove depending on outcome
If Not includeModule Then
' remove it
ai.Modules.Remove(ami)
End If
Next
Next
End Sub
Private Sub RemoveLocaleSpecificTabs()
' remove any tabs from data that don't match the current locale
Dim currentLocale As String = System.Threading.Thread.CurrentThread.CurrentCulture.ToString.ToLower
Dim fallbackCount As Integer = 0
' first pass, remove anything not matching current locale exactly
For Each ai As AggregatorTabInfo In New ArrayList(_aggregator.Tabs)
' check for locale
If ai.Locale <> "All" And ai.Locale <> "Fallback" Then
If ai.Locale.ToLower <> currentLocale Then
_aggregator.Tabs.Remove(ai)
End If
End If
If ai.Locale = "Fallback" Then fallbackCount += 1
Next
' second pass, remove the fallback locale only if another tab is present that isn't a fallback also
If _aggregator.Tabs.Count > fallbackCount Then
For Each ai As AggregatorTabInfo In New ArrayList(_aggregator.Tabs)
' check for locale
If ai.Locale = "Fallback" Then
If _aggregator.Tabs.Count > 1 Then
_aggregator.Tabs.Remove(ai)
End If
End If
Next
End If
End Sub
Private Sub RemoveEmptyTabs()
' remove any empty tabs
Dim currentLocale As String = System.Threading.Thread.CurrentThread.CurrentCulture.ToString.ToLower
For Each ai As AggregatorTabInfo In New ArrayList(_aggregator.Tabs)
' remove if no modules inside, or no text to show
If ai.Modules.Count = 0 And ai.HtmlText.Length = 0 Then
_aggregator.Tabs.Remove(ai)
End If
Next
End Sub
Private Sub RemoveLocaleSpecificModules()
' remove any modules from data that don't match the current locale
Dim currentLocale As String = System.Threading.Thread.CurrentThread.CurrentCulture.ToString.ToLower
For Each ai As AggregatorTabInfo In New ArrayList(_aggregator.Tabs)
For Each ami As AggregatorModuleInfo In New ArrayList(ai.Modules)
If ami.Locale <> "All" And ami.Locale <> "Fallback" Then
If ami.Locale.ToLower <> currentLocale Then
ai.Modules.Remove(ami)
End If
End If
Next
Next
' second pass, remove the default locale only if another module is present
For Each ai As AggregatorTabInfo In New ArrayList(_aggregator.Tabs)
For Each ami As AggregatorModuleInfo In New ArrayList(ai.Modules)
If ami.Locale = "Fallback" Then
If ai.Modules.Count > 1 Then
ai.Modules.Remove(ami)
End If
End If
Next
Next
End Sub
Private Sub RenderTabs()
' hide any aggregated modules on this page before DNN shows them
HidePageLevelAggregations()
LoadAggregator()
If _aggregator.TabsToShow Then
Dim t As New Template(_ms, MapPath(SkinFolder), MapPath(ResourceFolder()))
' render
RenderLayout(t)
HideAggregatedModules()
End If
End Sub
Private Sub HideAggregatedModules()
' setup to hide modules so that DNN doesn't render them outside our tabs .. we'll render them later in page load
For Each ai As AggregatorTabInfo In _aggregator.Tabs
For Each ami As AggregatorModuleInfo In ai.Modules
If _ms.HideTitles Then
ami.ModuleInfo.ContainerSrc = ResolveUrl("no container.ascx")
End If
ami.ModuleInfo.IsDeleted = True
Next
Next
End Sub
Private Sub InjectIntoTabsPartialRendering()
InjectIntoTabs(Me, LoadEventType.PageInit, _aggregator, _selectedTabNumber)
End Sub
Private Sub InjectIntoTabsNonPartialRendering()
InjectIntoTabs(Me, LoadEventType.PageLoad, _aggregator, _selectedTabNumber)
End Sub
Private Sub HidePageLevelAggregations()
' hide any modules that will eventually be aggregated on this page, !necessary for nesting
Dim dr As IDataReader = Nothing
Try
Dim ctrl As New AggregatorController
dr = ctrl.GetPageModules(TabId)
Dim innerModuleId As Integer
While dr.Read
innerModuleId = Convert.ToInt32(dr("ModuleId"))
For Each mi As ModuleInfo In PortalSettings.ActiveTab.Modules
If mi.ModuleID = innerModuleId Then
' it's aggregated somewhere, hide before DNN gets to show it
mi.IsDeleted = True
End If
Next
End While
Catch ex As Exception
Finally
If dr IsNot Nothing Then dr.Close()
End Try
End Sub
Private Function FindControlRecursive(ByVal root As Control, ByVal id As String) As Control
' 10/Feb/2006 - Currently not used in the injection routine but left here in case it becomes necessary to use it at a later date
If root.ID = id Then
Return root
End If
For Each c As Control In root.Controls
Dim t As Control = FindControlRecursive(c, id)
If Not (t Is Nothing) Then
Return t
End If
Next
Return Nothing
End Function
#End Region
#Region " Template Rendering"
Private Sub RenderLayout(ByVal t As Template)
Dim tabStrip As String = ""
Dim tabNumber As Integer = 1
If Not (_aggregator.SingleTab And _ms.HideSingleTab) Then
' render tabs
tabNumber = 1
Dim tabs As New StringBuilder
For Each ai As AggregatorTabInfo In _aggregator.Tabs
tabs.Append(GetTabTemplate(t, ai, tabNumber))
tabNumber += 1
Next
' render tabstrip
tabStrip = t.TabStripTemplate _
.Replace("[TABS]", tabs.ToString)
End If
' tab pages - only if not already rendered within tab template
Dim tabPages As New StringBuilder
If Not t.TabTemplate.Contains("[TABPAGE]") Then
' render tab pages
tabNumber = 1
For Each ai As AggregatorTabInfo In _aggregator.Tabs
tabPages.Append(GetTabPageTemplate(t, ai, tabNumber))
tabNumber += 1
Next
End If
' make replacements in layout template
Dim LayoutTemplate As String = t.LayoutTemplate _
.Replace("[TABSTRIP]", tabStrip) _
.Replace("[TABPAGES]", tabPages.ToString)
' paging
Dim pagingTemplate As String = ""
If Not (_aggregator.SingleTab And _ms.HideSingleTab) Then
If _ms.ShowPrevNext Then
' build paging controls
pagingTemplate = GetPagingTemplate(t, Nothing, 0)
If Not t.PagingInTemplates Then
' add to layouttemplate
LayoutTemplate = LayoutTemplate & "[PAGING]"
End If
End If
End If
' make one last replacements for paging - either replaces with controls or clears if paging is not activated in settings
' and any other global replacements
LayoutTemplate = LayoutTemplate _
.Replace("[PAGING]", pagingTemplate)
' aggregator tokens
LayoutTemplate = ReplaceAggregatorInfoTokens(LayoutTemplate)
' parse and add to page
Controls.Add(ParseControl(LayoutTemplate))
End Sub
Private Function GetRSSContentTemplate(ByVal t As Template, ByVal item As RssItem) As String
' returns all of the code that makes up an rss item
Return ReplaceRSSItemTokens(t.RSSContentTemplate, item)
End Function
Private Function GetRSSTabCaptionTemplate(ByVal s As String, ByVal item As RssItem) As String
' returns all of the code that makes up an rss tab caption
Return ReplaceRSSItemTokens(s, item)
End Function
Private Function GetTabTemplate(ByVal t As Template, ByVal ati As AggregatorTabInfo, ByVal tabNumber As Integer) As String
' returns all of the code that makes up a tab
' events
Dim events As New StringBuilder
If _ms.ActiveHover Then
events.Append("onmouseover=""javascript:setTimeout('" & Unique("SelectTab") & "([TABNUMBER],[MODULEID])'," & _ms.ActiveHoverDelay.ToString & ");"" ")
Else
events.Append("onclick=""javascript:" & Unique("SelectTab") & "([TABNUMBER],[MODULEID]);"" ")
events.Append("onmouseover=""javascript:" & Unique("MouseOverTab") & "(this);"" ")
events.Append("onmouseout=""javascript:" & Unique("MouseOutTab") & "(this);"" ")
End If
' tab
Dim tab As String = t.TabTemplate _
.Replace("[TABACTION]", events.ToString)
' check for tabpage token, used for inline tabs
If tab.Contains("[TABPAGE]") Then
tab = tab.Replace("[TABPAGE]", GetTabPageTemplate(t, ati, tabNumber))
End If
' tab tokens
If ati IsNot Nothing Then
tab = ReplaceAggregatorTabInfoTokens(tab, ati, tabNumber)
End If
Return tab
End Function
Private Function GetTabPageTemplate(ByVal t As Template, ByVal ati As AggregatorTabInfo, ByVal tabNumber As Integer) As String
' build tab page content
Dim tabPage As New StringBuilder
Dim wrappedModuleCount As Integer = 0
' see if there is html text first and add that
If ati.HtmlText.Length > 0 Then
Dim text As String = ati.HtmlText
For Each ami As AggregatorModuleInfo In ati.Modules
Dim token As String = "[MOD" & ami.ModuleId & "]"
If ati.HtmlText.Contains(token) Then
ami.ModuleInfo.PaneName = "wrap" & tabNumber.ToString & "_" & ami.AggregatorModuleId.ToString
text = text.Replace(token, String.Format("<div runat=""server"" id=""{0}"" valign=""top""></div>", ami.ModuleInfo.PaneName))
wrappedModuleCount += 1
End If
Next
' remove any remaining [MODxxxx] tokens for modules the user doesn't have rights to that were skipped
text = RegularExpressions.Regex.Replace(text, "\[MOD\d+\]", "")
' append
tabPage.Append(text)
End If
If wrappedModuleCount < ati.Modules.Count Then
' not all modules are using wrapping, we need to add injection spots
If (ati.Modules.Count - wrappedModuleCount) > 1 Then
' use a table so we can get the breaking correct
tabPage.Append("<table cellspacing=""0"" cellpadding=""0"" border=""0"" width=""100%"">")
tabPage.Append("<tr>")
' start table
Dim moduleNumber As Integer = 1
For Each ami As AggregatorModuleInfo In ati.Modules
If Not ami.ModuleInfo.PaneName.StartsWith("wrap") Then
' inject below text area if not wrapped in html/text area above
ami.ModuleInfo.PaneName = "cell" & tabNumber.ToString & "_" & moduleNumber.ToString
tabPage.AppendFormat("<td runat=""server"" id=""{0}"" valign=""top""></td>", ami.ModuleInfo.PaneName)
If ami.InsertBreak And moduleNumber < ati.Modules.Count Then
' finish table and start a new one
tabPage.Append("</tr>")
tabPage.Append("</table>")
tabPage.Append("<table cellspacing=""0"" cellpadding=""0"" border=""0"" width=""100%"">")
tabPage.Append("<tr>")
End If
moduleNumber += 1
End If
Next
' finish row and start a new one
tabPage.Append("</tr>")
tabPage.Append("</table>")
Else
If (ati.Modules.Count - wrappedModuleCount) > 0 Then
' if only one module then don't put inside table, unnecessary
Dim ami As AggregatorModuleInfo = DirectCast(ati.Modules(0), AggregatorModuleInfo)
If Not ami.ModuleInfo.PaneName.StartsWith("wrap") Then
ami.ModuleInfo.PaneName = "div" & tabNumber.ToString & "_1"
tabPage.AppendFormat("<div runat=""server"" id=""{0}"" />", ami.ModuleInfo.PaneName)
End If
End If
End If
End If
' grab empty tab page template
Dim emptyTabPage As String = GetEmptyTabPageTemplate(t, ati, tabNumber)
emptyTabPage = emptyTabPage.Replace("[TABPAGECONTENT]", tabPage.ToString)
' tab tokens
If ati IsNot Nothing Then
emptyTabPage = ReplaceAggregatorTabInfoTokens(emptyTabPage, ati, tabNumber)
End If
Return emptyTabPage
End Function
Private Function GetEmptyTabPageTemplate(ByVal t As Template, ByVal ati As AggregatorTabInfo, ByVal tabNumber As Integer) As String
' return a hidden div for injecting module into
' events
Dim events As New StringBuilder
If Not (_aggregator.SingleTab And _ms.HideSingleTab) Then
events.Append("style=""display:none""")
End If
' tabpage
Dim tabpage As String = t.TabPageTemplate
' check for paging
Dim pagingTemplate As String = ""
If tabpage.Contains("[PAGING]") Then
pagingTemplate = GetPagingTemplate(t, ati, tabNumber)
End If
' do replacements
tabpage = tabpage _
.Replace("[PAGING]", pagingTemplate) _
.Replace("[TABPAGEACTION]", events.ToString)
Return tabpage
End Function
Private Function GetPagingTemplate(ByVal t As Template, ByVal ati As AggregatorTabInfo, ByVal tabNumber As Integer) As String
Dim prevnext As String = t.PagingTemplate _
.Replace("[PAGINGITEMLIST]", GetPagingItemListTemplate(t))
' tab tokens
If ati IsNot Nothing Then
prevnext = ReplaceAggregatorTabInfoTokens(prevnext, ati, tabNumber)
End If
Return prevnext
End Function
Private Function GetPagingItemListTemplate(ByVal t As Template) As String
' render tabs
Dim tabNumber As Integer = 1
Dim pagingItemList As New StringBuilder
For Each ati As AggregatorTabInfo In _aggregator.Tabs
pagingItemList.Append(GetPagingItemTemplate(t, ati, tabNumber))
tabNumber += 1
Next
Return pagingItemList.ToString
End Function
Private Function GetPagingItemTemplate(ByVal t As Template, ByVal ai As AggregatorTabInfo, ByVal tabNumber As Integer) As String
Return ReplaceAggregatorTabInfoTokens(t.PagingItemTemplate, ai, tabNumber)
End Function
#End Region
#Region " Javascript Injection"
Private Sub InjectScript(ByVal t As Template, ByVal ScriptName As String, ByVal Location As String, ByVal Scope As String, ByVal UseFallback As Boolean)
Dim js As String = t.GetScript(ScriptName, Scope, UseFallback)
' do replacements
js = ReplaceAggregatorInfoTokens(js)
If Not String.IsNullOrEmpty(js) Then
Select Case Location.ToLower
Case "head"
Dim scriptKey As String = Unique(ScriptName.ToLower, Scope) & "_" & Scope
If Not Page.ClientScript.IsClientScriptBlockRegistered(Me.GetType, scriptKey) Then
Page.Header.Controls.Add(New LiteralControl(js))
' dummy script block so we can track if it's already in header
Page.ClientScript.RegisterClientScriptBlock(Me.GetType, scriptKey, "")
End If
Case Else
Page.ClientScript.RegisterClientScriptBlock(Me.GetType(), Unique(ScriptName.ToLower), js)
End Select
End If
End Sub
#End Region
#Region " Programatic Tab Selected"
Private Sub RemoveQueryStringModules()
If Not Request.QueryString("Agg" & ModuleId.ToString & "_HideTabs") Is Nothing And Not Page.IsPostBack Then
Dim delimTabNumbers As String = Request.QueryString("Agg" & ModuleId.ToString & "_HideTabs")
Dim tabNumbers() As String = delimTabNumbers.Split(","c)
Array.Reverse(tabNumbers) ' start backwards
For Each tabToken As String In tabNumbers
Dim tabNumber As Integer
If Int32.TryParse(tabToken, tabNumber) Then
If _aggregator.Tabs.Count >= tabNumber Then
' remove it
_aggregator.Tabs.RemoveAt(tabNumber - 1)
End If
End If
Next
End If
End Sub
Private Function GetSelectedTab() As Integer
' determine selected tab
Dim selectedTab As Integer = _ms.DefaultTab
If Not Request.QueryString("Agg" & ModuleId.ToString & "_SelectTab") Is Nothing And Not Page.IsPostBack Then
' check for selection by tab number
selectedTab = Convert.ToInt32(Request.QueryString("Agg" & ModuleId.ToString & "_SelectTab"))
Else
If Not Request.QueryString("Agg" & ModuleId.ToString & "_SelectByNum") Is Nothing And Not Page.IsPostBack Then
' check for selection by tab number
selectedTab = Convert.ToInt32(Request.QueryString("Agg" & ModuleId.ToString & "_SelectByNum"))
Else
If Not Request.QueryString("Agg" & ModuleId.ToString & "_SelectByTitle") Is Nothing And Not Page.IsPostBack Then
' check for selection by title
Dim matchTitle As String = ReplaceGenericTokens(Me, Request.QueryString("Agg" & ModuleId.ToString & "_SelectByTitle"))
Dim tabNumber As Integer = 1
For Each ai As AggregatorTabInfo In New ArrayList(_aggregator.Tabs)
If ai.Caption.ToUpper = matchTitle.ToUpper Then
selectedTab = tabNumber
Exit For
End If
tabNumber += 1
Next
Else
' get selected module by checking cookie, this allows us to maintain state
' not only between post back but also calls to other pages such as edit pages
' v5.6.3 - added the remember option, only applicable in view mode or non postback
If _ms.RememberLastOpenTab Or Page.IsPostBack Or Me.IsEditable Then
If Not Request.Cookies("DNNSTUFF_Aggregator") Is Nothing Then
' new consolidated cookie handling
selectedTab = Convert.ToInt32(Request.Cookies("DNNSTUFF_Aggregator")(ModuleId.ToString))
Else
If Not Request.Cookies(Unique("SelectedElementId")) Is Nothing Then
' old single cookie handling for backward compatibility
selectedTab = Convert.ToInt32(Replace(Request.Cookies(Unique("SelectedElementId")).Value, Unique("Tab"), ""))
Else
' lets check hidden field, just in case cookies disabled, then at least
' we get postback
If Request.Form(Unique("SelectedElementId")) IsNot Nothing Then
selectedTab = Convert.ToInt32(Replace(Request.Form(Unique("SelectedElementId")), Unique("Tab"), ""))
End If
End If
End If
Else
' lets check hidden field, just in case cookies disabled, then at least
' we get postback
If Request.Form(Unique("SelectedElementId")) IsNot Nothing Then
selectedTab = Convert.ToInt32(Replace(Request.Form(Unique("SelectedElementId")), Unique("Tab"), ""))
End If
End If
End If
End If
End If
If selectedTab < 1 Or selectedTab > _aggregator.Tabs.Count Then
selectedTab = _ms.DefaultTab
If selectedTab < 1 Or selectedTab > _aggregator.Tabs.Count Then
selectedTab = 1
End If
End If
Return selectedTab
End Function
Public Sub OnModuleCommunication(ByVal s As Object, ByVal e As Entities.Modules.Communications.ModuleCommunicationEventArgs) Implements Entities.Modules.Communications.IModuleListener.OnModuleCommunication
If e Is Nothing Then Exit Sub
If e.Target = "Aggregator" Then
Select Case e.Type
Case "SelectByNum", "SelectTab"
_selectedTabNumber = Convert.ToInt32(e.Value.ToString())
Case "SelectByTitle", "SelectTitle"
Dim tabNumber As Integer = 1
For Each ai As AggregatorTabInfo In New ArrayList(_aggregator.Tabs)
If ai.Caption.ToUpper = e.Value.ToString.ToUpper Then
_selectedTabNumber = tabNumber
Exit For
End If
tabNumber += 1
Next
End Select
End If
End Sub
#End Region
#Region " Token Replacement"
Public Function MakeReplacements_Backward(ByVal s As String) As String
' RDE - removed need for moduleSettings after the multiple modules per tab change
' replace system settings
s = Regex.Replace(s, "\[DNN:PORTAL.PORTALID\]", PortalId.ToString, RegexOptions.IgnoreCase)
s = Regex.Replace(s, "\[DNN:PORTAL.PORTALNAME\]", PortalSettings.PortalName, RegexOptions.IgnoreCase)
s = Regex.Replace(s, "\[DNN:MODULE.MODULEID\]", ModuleId.ToString, RegexOptions.IgnoreCase)
s = Regex.Replace(s, "\[DNN:TAB.TABID\]", TabId.ToString, RegexOptions.IgnoreCase)
s = Regex.Replace(s, "\[DNN:TAB.TABNAME\]", PortalSettings.ActiveTab.TabName, RegexOptions.IgnoreCase)
s = Regex.Replace(s, "\[DNN:USER.USERID\]", UserId.ToString, RegexOptions.IgnoreCase)
If Not UserInfo.Username Is Nothing Then
If Not UserInfo.DisplayName Is Nothing Then
s = Regex.Replace(s, "\[DNN:USER.FULLNAME\]", UserInfo.DisplayName, RegexOptions.IgnoreCase)
End If
s = Regex.Replace(s, "\[DNN:USER.USERNAME\]", UserInfo.Username, RegexOptions.IgnoreCase)
Else
s = Regex.Replace(s, "\[DNN:USER.FULLNAME\]", "Anonymous", RegexOptions.IgnoreCase)
s = Regex.Replace(s, "\[DNN:USER.USERNAME\]", "Anonymous", RegexOptions.IgnoreCase)
End If
s = Regex.Replace(s, "\[DNN:IMAGEURL\]", ResolveUrl("~/images"), RegexOptions.IgnoreCase)
' now do query strings
For Each key As String In Request.QueryString.Keys
s = Regex.Replace(s, "\[QUERYSTRING:" & UCase(key) & "\]", Request.QueryString(key).ToString, RegexOptions.IgnoreCase)
Next
Return s
End Function
Private Function ReplaceAggregatorTabInfoTokens(ByVal text As String, ByVal ati As AggregatorTabInfo, ByVal tabNumber As Integer) As String
' do generic replacements
text = Compatibility.ReplaceGenericTokens(Me, text)
' do aggregator tab specific replacements
Dim logicReplacer As New DNNStuff.Utilities.RegularExpression.IfDefinedTokenReplacement(AggregatorTabSettings(ati, tabNumber, text))
logicReplacer.ReplaceIfNotFound = False
text = logicReplacer.Replace(text)
Dim replacer As New DNNStuff.Utilities.RegularExpression.TokenReplacement(AggregatorTabSettings(ati, tabNumber, text))
replacer.ReplaceIfNotFound = False
Return replacer.Replace(text)
End Function
Private Function ReplaceAggregatorInfoTokens(ByVal text As String) As String
' do generic replacements
text = ReplaceGenericTokens(Me, text)
' do aggregator tab specific replacements
Dim logicReplacer As New DNNStuff.Utilities.RegularExpression.IfDefinedTokenReplacement(AggregatorSettings())
text = logicReplacer.Replace(text)
Dim replacer As New DNNStuff.Utilities.RegularExpression.TokenReplacement(AggregatorSettings())
replacer.ReplaceIfNotFound = False
Return replacer.Replace(text)
End Function
Private Function ReplaceRSSItemTokens(ByVal text As String, ByVal item As RssItem) As String
' do generic replacements
text = ReplaceGenericTokens(Me, text)
' rss content
Dim logicReplacer As New DNNStuff.Utilities.RegularExpression.IfDefinedTokenReplacement(RSSItemSettings(item))
text = logicReplacer.Replace(text)
Dim tokenReplacer As New DNNStuff.Utilities.RegularExpression.TokenReplacement(RSSItemSettings(item))
tokenReplacer.ReplaceIfNotFound = False
text = tokenReplacer.Replace(text)
Return text
End Function
Private Function AggregatorSettings() As Hashtable
If _aggregatorTokens IsNot Nothing Then Return _aggregatorTokens
Dim tokens As New Hashtable
tokens.Add("UNIQUE", Unique(""))
tokens.Add("PARENTID", Me.Parent.ClientID)
tokens.Add("MODULEID", Me.ModuleId.ToString)
tokens.Add("MODULEFOLDER", Me.ControlPath.Remove(Me.ControlPath.Length - 1)) ' remove last / character to be consistent with resolveurl
tokens.Add("TABMODULEID", Me.TabModuleId.ToString)
tokens.Add("SKIN", _ms.TabTheme)
tokens.Add("SKINFOLDER", ResolveUrl(SkinFolder))
tokens.Add("SKINBASEFOLDER", ResolveUrl(SkinBaseFolder))
tokens.Add("SELECTEDTABNUMBER", _selectedTabNumber.ToString)
tokens.Add("TABCOUNT", _aggregator.Tabs.Count.ToString)
tokens.Add("IMAGEURL", ResolveUrl("~/images"))
' SELECTTARGET
Dim selectTarget As New StringBuilder
If _aggregator.Targets.Count > 0 Then
For Each at As AggregatorTargetInfo In _aggregator.Targets
selectTarget.AppendLine("if (typeof " & "Agg" & at.TargetModuleId.ToString & "_SelectTab!=""undefined"" && source!=" & at.TargetModuleId.ToString & ") {")
selectTarget.AppendLine("Agg" & at.TargetModuleId.ToString & "_SelectTab(tabNumber,source);}")
Next
End If
tokens.Add("SELECTTARGET", selectTarget.ToString)
tokens.Add("PAGEFIRSTACTION", "onClick=""javascript:" & Unique("SelectTab") & "(1);"" ")
tokens.Add("PAGEPREVACTION", "onClick=""javascript:" & Unique("SelectPrevTab") & "();"" ")
tokens.Add("PAGENEXTACTION", "onClick=""javascript:" & Unique("SelectNextTab") & "();"" ")
tokens.Add("PAGELASTACTION", "onClick=""javascript:" & Unique("SelectTab") & "(" & _aggregator.Tabs.Count & ");"" ")
tokens.Add("FIRSTCAPTION", Localization.GetString("First.Text", LocalResourceFile))
tokens.Add("PREVCAPTION", Localization.GetString("Prev.Text", LocalResourceFile))
tokens.Add("NEXTCAPTION", Localization.GetString("Next.Text", LocalResourceFile))
tokens.Add("LASTCAPTION", Localization.GetString("Last.Text", LocalResourceFile))
tokens.Add("HIDETABS", _ms.HideTabs.ToString)
tokens.Add("ACTIVEHOVER", _ms.ActiveHover.ToString)
tokens.Add("ACTIVEHOVERDELAY", _ms.ActiveHoverDelay.ToString)
tokens.Add("HIDESINGLETAB", _ms.HideSingleTab.ToString)
tokens.Add("HIDETITLES", _ms.HideTitles.ToString)
tokens.Add("SHOWPAGER", _ms.ShowPrevNext.ToString)
tokens.Add("DEFAULTTABNUMBER", _ms.DefaultTab.ToString)
tokens.Add("REMEMBERLASTOPENTAB", _ms.RememberLastOpenTab.ToString)
tokens.Add("HEIGHT", _ms.Height)
tokens.Add("WIDTH", _ms.Width)
tokens.Add("LOCALE", System.Threading.Thread.CurrentThread.CurrentCulture.ToString.ToLower)
Dim overflow_style As String = ""
Dim height_style As String = ""
If _ms.Height <> "" Then
Dim height As Integer
If Int32.TryParse(_ms.Height, height) Then
height_style = "height:" & height.ToString & "px;"
Else
height_style = "height:" & _ms.Height & ";"
End If
overflow_style = "overflow:auto;"
End If
Dim width_style As String = ""
If _ms.Width <> "" Then
Dim width As Integer
If Int32.TryParse(_ms.Width, width) Then
width_style = "width:" & width.ToString & "px;"
Else
width_style = "width:" & _ms.Width & ";"
End If
overflow_style = "overflow:auto;"
End If
tokens.Add("HEIGHT_STYLE", height_style)
tokens.Add("WIDTH_STYLE", width_style)
tokens.Add("OVERFLOW_STYLE", "position:relative;" & overflow_style)
tokens.Add("SAVEACTIVETAB", String.Format("subcookiejar.bake('DNNSTUFF_Aggregator',{{{0}:tabNumber.toString()}});", ModuleId))
' replace our special [REQUIRES] tokens with something inoccuous like a comment
tokens.Add("REQUIRESJQUERY", "<!-- requires jquery -->")
tokens.Add("REQUIRESJQUERYUI", "<!-- requires jquery ui -->")
tokens.Add("CDATASTART", "<![CDATA[")
tokens.Add("CDATAEND", "]]>")
' grab settings if available
If _aggregator.Properties IsNot Nothing Then
For Each prop As CustomSettingsInfo In _aggregator.Properties
tokens.Add(prop.Name.ToUpper, prop.Value)
Next
End If
' add querystring values
Dim qs As New Specialized.NameValueCollection(Request.QueryString) ' create a copy, some weird errors happening with url rewriters
Dim keyval As Object
For Each key As String In qs.Keys
keyval = qs(key)
If key IsNot Nothing And keyval IsNot Nothing Then
tokens.Add("QS_" & key.ToUpper(), keyval.ToString())
End If
Next
_aggregatorTokens = tokens
Return _aggregatorTokens
End Function
Private Function ParseLocalizedString(ByVal s As String) As String
Dim currentLocale As String = System.Threading.Thread.CurrentThread.CurrentCulture.ToString.ToLower
Dim reg As Regex = New Regex(String.Format("{0}:(.*?)(\||$)", currentLocale), RegexOptions.IgnoreCase)
If reg.IsMatch(s) Then
Dim match As RegularExpressions.Match = reg.Match(s)
If match.Groups.Count > 1 Then
s = match.Groups(1).Value
End If
End If
Return s
End Function
Private Function AggregatorTabSettings(ByVal ati As AggregatorTabInfo, ByVal tabNumber As Integer, ByVal text As String) As Hashtable
' build hashtable of tokens relative to an individual tab
Dim tokens As New Hashtable
Dim ami As AggregatorModuleInfo = Nothing
If ati.Modules.Count > 0 Then
ami = CType(ati.Modules(0), AggregatorModuleInfo)
End If
' MODULETITLE
If ami IsNot Nothing Then
tokens.Add("MODULETITLE", ami.ModuleInfo.ModuleTitle)
Else
tokens.Add("MODULETITLE", ati.Caption)
End If
' MMLINKS
If text.Contains("[MMLINKSTITLE]") Then