forked from DNNCommunity/DNN.Blog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BlogEdit.ascx.vb
235 lines (214 loc) · 9.22 KB
/
BlogEdit.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
'
' Bring2mind - http://www.bring2mind.net
' Copyright (c) 2013
' by Bring2mind
'
' 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 System.Linq
Imports DotNetNuke.Common
Imports DotNetNuke.Common.Utilities
Imports DotNetNuke.Services.Exceptions
Imports DotNetNuke.Modules.Blog.Entities.Blogs
Imports DotNetNuke.Modules.Blog.Common.Globals
Imports DotNetNuke.Framework
Public Class BlogEdit
Inherits BlogModuleBase
Private Sub Page_Init1(sender As Object, e As System.EventArgs) Handles Me.Init
jQuery.RequestDnnPluginsRegistration()
If Not BlogContext.Security.IsEditor Then
If Not BlogContext.Security.IsBlogger Then
Response.Redirect(NavigateURL("Access Denied"), True)
End If
If BlogContext.Blog IsNot Nothing AndAlso BlogContext.Blog.OwnerUserId <> UserId Then
Response.Redirect(NavigateURL("Access Denied"), True)
End If
End If
txtTitle.DefaultLanguage = PortalSettings.DefaultLanguage
txtDescription.DefaultLanguage = PortalSettings.DefaultLanguage
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not BlogContext.Security.IsBlogger Then
Throw New Exception("You do not have access to this resource. Please check your login status.")
End If
If Not Page.IsPostBack Then
If BlogContext.Blog Is Nothing Then BlogContext.Blog = New BlogInfo ' initialize fields
txtTitle.DefaultText = BlogContext.Blog.Title
txtTitle.LocalizedTexts = BlogContext.Blog.TitleLocalizations
txtTitle.InitialBind()
txtDescription.DefaultText = BlogContext.Blog.Description
txtDescription.LocalizedTexts = BlogContext.Blog.DescriptionLocalizations
txtDescription.InitialBind()
If BlogContext.IsMultiLingualSite Then
ddLocale.DataSource = DotNetNuke.Services.Localization.LocaleController.Instance.GetLocales(PortalId).Values.OrderBy(Function(t) t.NativeName)
ddLocale.DataValueField = "Code"
ddLocale.DataBind()
Try
ddLocale.Items.FindByValue(BlogContext.Blog.Locale).Selected = True
Catch ex As Exception
End Try
chkFullLocalization.Checked = BlogContext.Blog.FullLocalization
Else
rowLocale.Visible = False
rowFullLocalization.Visible = False
End If
chkPublic.Checked = BlogContext.Blog.Published
chkSyndicate.Checked = BlogContext.Blog.Syndicated
If BlogContext.Blog.SyndicationEmail Is Nothing Then
txtSyndicationEmail.Text = ModuleContext.PortalSettings.UserInfo.Email
Else
txtSyndicationEmail.Text = BlogContext.Blog.SyndicationEmail
End If
chkIncludeImagesInFeed.Checked = BlogContext.Blog.IncludeImagesInFeed
chkIncludeAuthorInFeed.Checked = BlogContext.Blog.IncludeAuthorInFeed
chkEnablePingBackReceive.Checked = BlogContext.Blog.EnablePingBackReceive
chkEnablePingBackSend.Checked = BlogContext.Blog.EnablePingBackSend
chkAutoApprovePingBack.Checked = BlogContext.Blog.AutoApprovePingBack
chkEnableTrackBackReceive.Checked = BlogContext.Blog.EnableTrackBackReceive
chkEnableTrackBackSend.Checked = BlogContext.Blog.EnableTrackBackSend
chkAutoApproveTrackBack.Checked = BlogContext.Blog.AutoApproveTrackBack
txtCopyright.Text = BlogContext.Blog.Copyright
cmdDelete.Visible = CBool(BlogContext.BlogId <> -1)
If Not String.IsNullOrEmpty(BlogContext.Blog.Image) Then
imgBlogImage.ImageUrl = ResolveUrl(glbImageHandlerPath) & String.Format("?TabId={0}&ModuleId={1}&Blog={2}&w=100&h=100&c=1&key={3}", TabId, Settings.ModuleId, BlogContext.BlogId, BlogContext.Blog.Image)
imgBlogImage.Visible = True
cmdImageRemove.Visible = True
Else
imgBlogImage.Visible = False
cmdImageRemove.Visible = False
End If
' ghost writing
chkMustApproveGhostPosts.Checked = BlogContext.Blog.MustApproveGhostPosts
chkPublishAsOwner.Checked = BlogContext.Blog.PublishAsOwner
ctlPermissions.Permissions = BlogContext.Blog.Permissions
ctlPermissions.TabId = TabId
ctlPermissions.CurrentUserId = UserId
ctlPermissions.UserIsAdmin = BlogContext.Security.UserIsAdmin
hlCancel.NavigateUrl = EditUrl("Manage")
End If
End Sub
Protected Sub cmdDelete_Click(ByVal sender As Object, ByVal e As EventArgs) Handles cmdDelete.Click
Try
If Not BlogContext.Blog Is Nothing Then
BlogsController.DeleteBlog(BlogContext.Blog.BlogID)
End If
Response.Redirect(EditUrl("Manage"), False)
Catch exc As Exception
ProcessModuleLoadException(Me, exc)
End Try
End Sub
Private Sub cmdUpdate_Click(sender As Object, e As System.EventArgs) Handles cmdUpdate.Click
Try
If Page.IsValid = True Then
If BlogContext.Blog Is Nothing Then
BlogContext.Blog = New BlogInfo
With BlogContext.Blog
.ModuleID = Settings.ModuleId
.OwnerUserId = Me.UserId
End With
End If
With BlogContext.Blog
.Title = txtTitle.DefaultText
.TitleLocalizations = txtTitle.GetLocalizedTexts
.Description = txtDescription.DefaultText
.DescriptionLocalizations = txtDescription.GetLocalizedTexts
If BlogContext.IsMultiLingualSite Then
.Locale = ddLocale.SelectedValue
.FullLocalization = chkFullLocalization.Checked
Else
.Locale = PortalSettings.DefaultLanguage
End If
.Published = chkPublic.Checked
.Syndicated = chkSyndicate.Checked
.SyndicationEmail = txtSyndicationEmail.Text
.IncludeImagesInFeed = chkIncludeImagesInFeed.Checked
.IncludeAuthorInFeed = chkIncludeAuthorInFeed.Checked
.EnablePingBackReceive = chkEnablePingBackReceive.Checked
.EnablePingBackSend = chkEnablePingBackSend.Checked
.AutoApprovePingBack = chkAutoApprovePingBack.Checked
.EnableTrackBackReceive = chkEnableTrackBackReceive.Checked
.EnableTrackBackSend = chkEnableTrackBackSend.Checked
.AutoApproveTrackBack = chkAutoApproveTrackBack.Checked
.Copyright = txtCopyright.Text.Trim
.MustApproveGhostPosts = chkMustApproveGhostPosts.Checked
.PublishAsOwner = chkPublishAsOwner.Checked
.Permissions = ctlPermissions.Permissions
If BlogContext.BlogId = -1 Then
.BlogID = BlogsController.AddBlog(BlogContext.Blog, UserId)
BlogContext.BlogId = .BlogID
Else
BlogsController.UpdateBlog(BlogContext.Blog, UserId)
End If
Modules.Blog.Security.Permissions.BlogPermissionsController.UpdateBlogPermissions(BlogContext.Blog)
End With
If fileImage.HasFile Then
Dim extension As String = IO.Path.GetExtension(fileImage.FileName).ToLower
If glbPermittedFileExtensions.IndexOf(extension & ",") > -1 Then
Dim saveDir As String = GetBlogDirectoryMapPath(BlogContext.BlogId)
If Not IO.Directory.Exists(saveDir) Then IO.Directory.CreateDirectory(saveDir)
If BlogContext.Blog.Image <> "" Then
' remove old images
Dim imagesToDelete As New List(Of String)
Dim d As New IO.DirectoryInfo(saveDir)
For Each f As IO.FileInfo In d.GetFiles
If f.Name.StartsWith(BlogContext.Blog.Image) Then
imagesToDelete.Add(f.FullName)
End If
Next
For Each f As String In imagesToDelete
Try
IO.File.Delete(f)
Catch ex As Exception
End Try
Next
End If
Dim newFileName As String = Guid.NewGuid.ToString("D")
fileImage.SaveAs(saveDir & newFileName & IO.Path.GetExtension(fileImage.FileName).ToLower)
BlogContext.Blog.Image = newFileName
BlogsController.UpdateBlog(BlogContext.Blog, UserId)
End If
End If
End If
Response.Redirect(EditUrl("Manage"), False)
Catch exc As Exception
ProcessModuleLoadException(Me, exc)
End Try
End Sub
Private Sub cmdImageRemove_Click(sender As Object, e As System.EventArgs) Handles cmdImageRemove.Click
If BlogContext.Blog IsNot Nothing Then
If BlogContext.Blog.Image <> "" Then
' remove old images
Dim saveDir As String = GetBlogDirectoryMapPath(BlogContext.BlogId)
Dim imagesToDelete As New List(Of String)
Dim d As New IO.DirectoryInfo(saveDir)
For Each f As IO.FileInfo In d.GetFiles
If f.Name.StartsWith(BlogContext.Blog.Image) Then
imagesToDelete.Add(f.FullName)
End If
Next
For Each f As String In imagesToDelete
Try
IO.File.Delete(f)
Catch ex As Exception
End Try
Next
End If
BlogContext.Blog.Image = ""
BlogsController.UpdateBlog(BlogContext.Blog, UserId)
End If
imgBlogImage.Visible = False
cmdImageRemove.Visible = False
End Sub
End Class