forked from ventrian/Simple-Gallery
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TagCloud.ascx.vb
executable file
·146 lines (97 loc) · 5.39 KB
/
TagCloud.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
'
' Simple Gallery for DotNetNuke - http://www.dotnetnuke.com
' Copyright (c) 2002-2007
' by Ventrian ( sales@ventrian.com ) ( http://www.ventrian.com )
'
Imports System.Text.RegularExpressions
Imports DotNetNuke.Common
Imports DotNetNuke.Common.Utilities
Imports DotNetNuke.Services.Exceptions
Imports DotNetNuke.Services.Localization
Imports Ventrian.SimpleGallery.Common
Imports Ventrian.SimpleGallery.Entities
Namespace Ventrian.SimpleGallery
Partial Public Class TagCloud
Inherits SimpleGalleryBase
#Region " Private Members "
#End Region
#Region " Private Methods "
Private Sub BindTags()
Dim galleryTabID As Integer = Null.NullInteger
If (Settings.Contains(Constants.SETTING_TAG_CLOUD_PHOTO_TAB_ID)) Then
galleryTabID = Convert.ToInt32(Settings(Constants.SETTING_TAG_CLOUD_PHOTO_TAB_ID).ToString())
End If
Dim galleryModuleID As Integer = Null.NullInteger
If (Settings.Contains(Constants.SETTING_TAG_CLOUD_PHOTO_MODULE_ID)) Then
galleryModuleID = Convert.ToInt32(Settings(Constants.SETTING_TAG_CLOUD_PHOTO_MODULE_ID).ToString())
End If
Dim galleryTabModuleID As Integer = Null.NullInteger
If (Settings.Contains(Constants.SETTING_TAG_CLOUD_PHOTO_TAB_MODULE_ID)) Then
galleryTabModuleID = Convert.ToInt32(Settings(Constants.SETTING_TAG_CLOUD_PHOTO_TAB_MODULE_ID).ToString())
End If
Dim galleryAlbumID As Integer = Null.NullInteger
If (Settings.Contains(Constants.SETTING_TAG_CLOUD_PHOTO_ALBUM_ID)) Then
galleryAlbumID = Convert.ToInt32(Settings(Constants.SETTING_TAG_CLOUD_PHOTO_ALBUM_ID).ToString())
End If
Dim galleryMaxCount As Integer = Constants.DEFAULT_TAG_CLOUD_MAX_COUNT
If (Settings.Contains(Constants.SETTING_TAG_CLOUD_MAX_COUNT)) Then
galleryMaxCount = Convert.ToInt32(Settings(Constants.SETTING_TAG_CLOUD_MAX_COUNT).ToString())
End If
If (galleryModuleID <> Null.NullInteger) Then
Dim objTagController As New TagController
Dim objTags As ArrayList = objTagController.List(galleryModuleID, galleryAlbumID, galleryMaxCount, True)
objTags.Sort()
If (objTags.Count > 0) Then
Dim minWeight As Decimal = Decimal.MaxValue, maxWeight As Decimal = Decimal.MinValue
Dim FontScale() As String = {"weight5", "weight4", "weight3", "weight2", "weight1"}
Const SpacerMarkup As String = " " 'The markup injected between each item in the cloud
For Each objTag As TagInfo In objTags
Dim numProductsDec As Decimal = Convert.ToDecimal(objTag.Usages)
If numProductsDec < minWeight Then minWeight = numProductsDec
If numProductsDec > maxWeight Then maxWeight = numProductsDec
Next
Dim scaleUnitLength As Decimal = (maxWeight - minWeight + 1) / Convert.ToDecimal(FontScale.Length)
litCloudMarkup.Text &= "<div id=""tagCloud"" class=""tagCloud"">"
For Each objTag As TagInfo In objTags
Dim numProductsDec As Decimal = Convert.ToDecimal(objTag.Usages)
Dim scaleValue As Integer = CType(Decimal.Truncate((numProductsDec - minWeight) / scaleUnitLength), Int32)
litCloudMarkup.Text &= String.Format("<a class=""{1}"" href=""{0}"">{2}</a>{3}", _
GetTagUrl(objTag, galleryTabID, galleryTabModuleID), FontScale(scaleValue), objTag.Name, SpacerMarkup)
Next
litCloudMarkup.Text &= "</div>"
Else
litCloudMarkup.Text = "<div class=""normal"">" & Localization.GetString("NoTags", Me.LocalResourceFile) & "</div>"
End If
Else
litCloudMarkup.Text = "<div class=""normal"">" & Localization.GetString("Configure", Me.LocalResourceFile) & "</div>"
End If
End Sub
Private Function GetTagUrl(ByVal objTag As TagInfo, ByVal tabID As Integer, ByVal moduleID As Integer) As String
If (AllLetters(objTag.Name) = True) Then
Return NavigateURL(tabID, "", "Tag=" & objTag.Name, "Tags=" & moduleID.ToString())
Else
Return NavigateURL(tabID, "", "TagID=" & objTag.TagID.ToString(), "Tags=" & moduleID.ToString())
End If
End Function
Private Function AllLetters(ByVal txt As String) As Boolean
Dim reg As New Regex("^[A-Za-z]+$")
Dim ok As Boolean = True
If Not (reg.IsMatch(txt)) Then
ok = False
Else
ok = True
End If
Return ok
End Function
#End Region
#Region " Event Handlers "
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Try
BindTags()
Catch exc As Exception
ProcessModuleLoadException(Me, exc)
End Try
End Sub
#End Region
End Class
End Namespace