-
Notifications
You must be signed in to change notification settings - Fork 1
/
LocalizationEditor.ascx.vb
318 lines (279 loc) · 13.3 KB
/
LocalizationEditor.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
'
' Copyright (c) 2004-2011 DNN-Europe, http://www.dnn-europe.net
'
' 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.
'
Imports DNNEurope.Modules.LocalizationEditor.Data
Imports DotNetNuke.Services.Exceptions
Imports DotNetNuke.Services.Localization.Localization
Imports DotNetNuke.Entities.Modules.Actions
Imports DNNEurope.Modules.LocalizationEditor.Entities.Permissions
Partial Public Class LocalizationEditor
Inherits ModuleBase
#Region " Private Members "
Private _userId As Integer = UserId
Private _userLocales As List(Of String)
Private _allLocales As List(Of String)
#End Region
#Region " Properties "
Public Property Locale As String = ""
Public Property IsEditorSpecificLocale As Boolean = False
Public Property IsEditorGenericLocale As Boolean = False
Public Property IsEditor As Boolean = False
Public ReadOnly Property UserPermissions As List(Of PermissionInfo)
Get
Return PermissionsController.GetPermissions(ModuleId).Where(Function(p) p.UserId = UserId).ToList()
End Get
End Property
Public Property UserLocales As List(Of String)
Get
If _userLocales Is Nothing Then
_userLocales = New List(Of String)
Using ir As IDataReader = DataProvider.Instance.GetLocalesForUser(UserId, PortalId, ModuleId)
Do While ir.Read
_userLocales.Add(CStr(ir.Item("Locale")))
Loop
End Using
End If
Return _userLocales
End Get
Set(value As List(Of String))
_userLocales = value
End Set
End Property
Public Property AllLocales As List(Of String)
Get
If _allLocales Is Nothing Then
_allLocales = Entities.Translations.TranslationsController.GetLocales(ModuleId)
For Each l As String In UserLocales
If Not _allLocales.Contains(l) Then
_allLocales.Add(l)
End If
Next
End If
Return _allLocales
End Get
Set(ByVal value As List(Of String))
_allLocales = value
End Set
End Property
#End Region
#Region " Event Handlers "
Private Sub Page_Init(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Init
Globals.ReadValue(Me.Request.Params, "Locale", Locale)
If UserInfo.IsSuperUser Then
_userId = PortalSettings.AdministratorId
End If
IsEditorSpecificLocale = UserLocales.Contains(Locale)
IsEditorGenericLocale = UserLocales.Contains(Left(Locale, 2))
IsEditor = CBool(UserLocales.Count > 0)
cmdUploadPack.ToolTip = LocalizeString("lbUploadPack")
cmdManageObjects.ToolTip = LocalizeString("lbManageObjects")
cmdManagePermissions.ToolTip = LocalizeString("lbManagePermissions")
cmdManagePartners.ToolTip = LocalizeString("lbManagePartners")
cmdClearCaches.ToolTip = LocalizeString("lbClearCaches")
cmdCube.ToolTip = LocalizeString("lbCube")
End Sub
Private Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
Try
' Show functions for authorized users
cmdManagePermissions.Visible = IsAdmin
cmdManageObjects.Visible = IsAdmin Or DotNetNuke.Security.Permissions.ModulePermissionController.HasModulePermission(ModuleConfiguration.ModulePermissions, Globals.glbObjectMgrPermission)
cmdManagePartners.Visible = IsAdmin
cmdClearCaches.Visible = IsAdmin And Me.Settings.CachePacks
cmdUploadPack.Visible = IsAdmin Or IsEditor
cmdCube.Visible = Settings.AllowDataExtract
cmdService.Visible = CBool(UserPermissions.Count > 0)
If Not Me.IsPostBack Then
Me.DataBind()
End If
Catch exc As Exception
ProcessModuleLoadException(Me, exc)
End Try
End Sub
Private Sub cmdCube_Click(sender As Object, e As System.EventArgs) Handles cmdCube.Click
Response.Redirect(ResolveUrl("~/DesktopModules/DNNEurope/LocalizationEditor/GetCube.ashx") & "?pid=" & PortalId.ToString & "&mid=" & ModuleId.ToString, False)
End Sub
Private Sub cmdUploadPack_Click(sender As Object, e As System.EventArgs) Handles cmdUploadPack.Click
Response.Redirect(EditUrl("UploadPack"), False)
End Sub
Protected Sub cmdManagePermissions_Click(ByVal sender As Object, ByVal e As EventArgs) Handles cmdManagePermissions.Click
Response.Redirect(EditUrl("Users"), False)
End Sub
Private Sub cmdManagePartners_Click(sender As Object, e As System.EventArgs) Handles cmdManagePartners.Click
Response.Redirect(EditUrl("Partners"), False)
End Sub
Protected Sub cmdManageObjects_Click(ByVal sender As Object, ByVal e As EventArgs) Handles cmdManageObjects.Click
Response.Redirect(EditUrl("ManageObjects"), False)
End Sub
Private Sub cmdClearCaches_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdClearCaches.Click
If Not IsEditor Then Exit Sub
Dim packPath As String = PortalSettings.HomeDirectoryMapPath & "\LocalizationEditor\Cache\" & ModuleId.ToString & "\"
If IO.Directory.Exists(packPath) Then
Dim zipFiles() As String = IO.Directory.GetFiles(packPath, "*.zip")
For Each f As String In zipFiles
Try
IO.File.Delete(f)
Catch
End Try
Next
End If
End Sub
Private Sub dlCorePackages_ItemCommand(source As Object, e As System.Web.UI.WebControls.DataListCommandEventArgs) Handles dlCorePackages.ItemCommand
If Not IsEditor Then Exit Sub
Dim command As String = e.CommandName.ToLower
Dim args() As String = CStr(e.CommandArgument).Split("|"c)
Dim objectId As Integer = CInt(args(0))
Dim version As String = args(1)
Dim obj As Entities.Objects.ObjectInfo = Entities.Objects.ObjectsController.GetObject(objectId)
Select Case command
Case "notify"
Dim packUrl As String = String.Format("{0}?ObjectId={1}&Locale={2}&Version={3}", Globals.PackUrl, objectId, Locale, version)
Dim url As String = String.Format("http://update.dotnetnuke.com/localization.aspx?type=Framework&name=DNNCORP.{0}&version={1}&culture={2}&url={3}", obj.ObjectName.Substring(3), version, Locale, HttpUtility.UrlEncode(packUrl))
Dim req As New Services.DataExchange.WebRequest
With req
.Url = url
.PostMode = Services.DataExchange.WebRequest.PostModeType.URLEncoded
End With
Dim res As Object = req.GetResponse
End Select
End Sub
#End Region
#Region " Public Methods "
Public Function GetObjectLocalePerctComplete(ByVal r As Object) As String
'Dim record As System.Data.Common.DbDataRecord = CType(CType(r, DataListItem).DataItem, System.Data.Common.DbDataRecord)
Dim record As DataRowView = CType(r, DataRowView)
Try
Dim perct As Double = CInt(record.Item("TextCount")) * 100
If CInt(record.Item("LastVersionTextCount")) = 0 Then Return ""
perct = perct / CInt(record.Item("LastVersionTextCount"))
Return String.Format("{0} %", Math.Round(perct))
Catch ex As Exception
End Try
Return ""
End Function
Public Function GetEditColumn(ByVal r As Object) As String
Dim record As DataRowView = CType(r, DataRowView)
Dim res As String = ""
If IsAdmin Or IsEditorSpecificLocale Then
res = String.Format("<a href=""{0}"" title=""{2}"" class=""iconLink""><span class=""entypoIcon icon16"" title=""{2}"">{1}</span></a>", EditUrl("ObjectId", CStr(record.Item("ObjectId")), "ObjectSummary", "Locale=" & Locale, "Version=" & CStr(record.Item("LastVersion"))), "✎", String.Format(GetString("Edit", LocalResourceFile), Locale))
End If
If IsAdmin Or IsEditorGenericLocale Then
res &= String.Format("<a href=""{0}"" title=""{2}""class=""iconLink""><span class=""entypoIcon icon16"" title=""{2}"">{1}</span></a>", EditUrl("ObjectId", CStr(record.Item("ObjectId")), "ObjectSummary", "Locale=" & Left(Locale, 2), "Version=" & CStr(record.Item("LastVersion"))), "✎", String.Format(GetString("Edit", LocalResourceFile), Left(Locale, 2)))
End If
Return res
End Function
Public Function GetObjectUrl(ByVal objectId As Integer) As String
Return EditUrl("ObjectId", objectId.ToString, "DownloadPack", "Locale=" & Locale)
End Function
#End Region
#Region " Private Methods "
Private Function ListCacheKey() As String
Return String.Format("LocList{0}", ModuleId)
End Function
#End Region
#Region " Overrides "
Public Overrides Sub DataBind()
If _Locale = "" Then
Dim locList As String = Nothing
If Not IsEditor Then
locList = CType(DotNetNuke.Common.Utilities.DataCache.GetCache(ListCacheKey), String)
End If
If locList Is Nothing Then
Dim llb As New StringBuilder
Dim ourUrl As String = DotNetNuke.Common.NavigateURL(TabId)
If ourUrl.Contains("?") Then
ourUrl &= "&"
Else
ourUrl &= "?"
End If
ourUrl &= "locale="
' top level of generic cultures
Dim gLocs As New List(Of String)
For Each l As String In AllLocales
If Not gLocs.Contains(Left(l, 2)) Then
gLocs.Add(Left(l, 2))
End If
Next
Dim genericLocales As New SortedDictionary(Of String, Globalization.CultureInfo)
For Each c As Globalization.CultureInfo In Globalization.CultureInfo.GetCultures(Globalization.CultureTypes.NeutralCultures)
If gLocs.Contains(c.Name) Then
genericLocales.Add(c.NativeName, c)
End If
Next
Dim handledLocales As New List(Of String)
For Each gl As String In genericLocales.Keys
handledLocales.Add(genericLocales(gl).Name)
llb.AppendFormat("<div class=""genericLocale"">{0} ({1})</div>", CultureTextInfo.ToTitleCase(gl), CultureTextInfo.ToTitleCase(genericLocales(gl).EnglishName))
If AllLocales.Contains(genericLocales(gl).Name) Then ' we have the generic variant in our system
For Each c As Globalization.CultureInfo In Globalization.CultureInfo.GetCultures(Globalization.CultureTypes.SpecificCultures)
If Left(c.Name, 2) = genericLocales(gl).Name Then
llb.AppendFormat("<div class=""specificLocale""><a href=""{0}{1}"">{2}</a></div>", ourUrl, c.Name, CultureTextInfo.ToTitleCase(c.NativeName))
handledLocales.Add(c.Name)
End If
Next
Else ' we just have a specific locale here
For Each l As String In AllLocales
If Left(l, 2) = genericLocales(gl).Name Then
Dim c As New Globalization.CultureInfo(l)
llb.AppendFormat("<div class=""specificLocale""><a href=""{0}{1}"">{2}</a></div>", ourUrl, c.Name, CultureTextInfo.ToTitleCase(c.NativeName))
handledLocales.Add(l)
End If
Next
End If
Next
' Now for any overlooked specific locales
Dim overlookedLocales As New List(Of String)
For Each l As String In AllLocales
If Not handledLocales.Contains(l) Then
overlookedLocales.Add(l)
End If
Next
If overlookedLocales.Count > 0 Then
llb.AppendFormat("<div class=""genericLocale"">{0}</div>", GetString("Other", LocalResourceFile))
For Each l As String In overlookedLocales
Dim c As New Globalization.CultureInfo(l)
llb.AppendFormat("<div class=""specificLocale""><a href=""{0}{1}"">{2}</a></div>", ourUrl, c.Name, c.NativeName)
Next
End If
locList = llb.ToString
End If
If Not IsEditor Then
DotNetNuke.Common.Utilities.DataCache.SetCache(ListCacheKey, locList)
End If
plhLocales.Controls.Add(New LiteralControl(locList))
pnlLocaleRequest.Visible = False
Else
pnlLocaleRequest.Visible = True
Dim oList As DataTable = DotNetNuke.Common.ConvertDataReaderToDataTable(DataProvider.Instance.GetObjectsWithStatus(ModuleId, Locale))
If IsEditorGenericLocale Or IsEditorSpecificLocale Then
dlObjects.DataSource = New DataView(oList, "PackageType<>'Pack'", "FriendlyName", DataViewRowState.CurrentRows)
Else
dlObjects.DataSource = New DataView(oList, "PackageType<>'Pack' And TextCount>0", "FriendlyName", DataViewRowState.CurrentRows)
End If
dlObjects.DataBind()
dlCorePackages.DataSource = New DataView(oList, "PackageType='Pack' And ChildCount>0 And PercentComplete>0 And (ObjectName='DNNCE' Or ObjectName='DNNPE' Or ObjectName='DNNEE')", "FriendlyName", DataViewRowState.CurrentRows)
dlCorePackages.DataBind()
If dlCorePackages.Items.Count < 1 Then pnlCorePackages.Visible = False
dlPackages.DataSource = New DataView(oList, "PackageType='Pack' And ChildCount>0 And PercentComplete>0 And Not (ObjectName='DNNCE' Or ObjectName='DNNPE' Or ObjectName='DNNEE')", "FriendlyName", DataViewRowState.CurrentRows)
dlPackages.DataBind()
If dlPackages.Items.Count < 1 Then pnlPackages.Visible = False
If dlObjects.Items.Count = 0 Then
pnlLocaleRequest.Visible = False
End If
End If
End Sub
#End Region
End Class