forked from ventrian/News-Articles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ucAdminOptions.ascx.vb
executable file
·233 lines (162 loc) · 10.1 KB
/
ucAdminOptions.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
'
' News Articles for DotNetNuke - http://www.dotnetnuke.com
' Copyright (c) 2002-2007
' by Ventrian ( sales@ventrian.com ) ( http://www.ventrian.com )
'
Imports DotNetNuke.Common.Utilities
Imports DotNetNuke.Security
Imports DotNetNuke.Services.Exceptions
Imports System.Xml
Imports Ventrian.NewsArticles.Base
Namespace Ventrian.NewsArticles
Partial Public Class ucAdminOptions
Inherits NewsArticleModuleBase
#Region " Event Handlers "
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Try
trSiteTemplates.Visible = Me.UserInfo.IsSuperUser
If (Settings.Contains(ArticleConstants.PERMISSION_SITE_TEMPLATES_SETTING)) Then
If (Settings(ArticleConstants.PERMISSION_SITE_TEMPLATES_SETTING).ToString() <> "") Then
trSiteTemplates.Visible = PortalSecurity.IsInRoles(Settings(ArticleConstants.PERMISSION_SITE_TEMPLATES_SETTING).ToString())
End If
End If
Catch exc As Exception 'Module failed to load
ProcessModuleLoadException(Me, exc)
End Try
End Sub
#End Region
Protected Sub cmdImport_Click(ByVal sender As Object, ByVal e As EventArgs) Handles cmdImport.Click
Dim file As String = PortalSettings.HomeDirectoryMapPath & "import.xml"
Dim doc As New XmlDocument
doc.Load(file)
Dim nsMgr As New XmlNamespaceManager(doc.NameTable)
nsMgr.AddNamespace("wp", "http://wordpress.org/export/1.2/")
nsMgr.AddNamespace("content", "http://purl.org/rss/1.0/modules/content/")
Dim nodeRoot As XmlNode = doc.DocumentElement
Dim objCategoriesNodes As XmlNodeList = nodeRoot.SelectNodes("/rss/channel/wp:category", nsMgr)
Dim objCategoryController As New CategoryController()
For Each objCategoryNode As XmlNode In objCategoriesNodes
Dim objName As XmlNode = objCategoryNode.SelectSingleNode("wp:cat_name", nsMgr)
Dim objCategoryInfo As New CategoryInfo
objCategoryInfo.CategoryID = Null.NullInteger
objCategoryInfo.ModuleID = ModuleId
objCategoryInfo.ParentID = Null.NullInteger
objCategoryInfo.Name = objName.InnerText
objCategoryInfo.Description = ""
objCategoryInfo.InheritSecurity = True
objCategoryInfo.CategorySecurityType = 0
objCategoryInfo.MetaTitle = ""
objCategoryInfo.MetaDescription = ""
objCategoryInfo.MetaKeywords = ""
objCategoryController.AddCategory(objCategoryInfo)
Next
Dim objCategories As List(Of CategoryInfo) = objCategoryController.GetCategoriesAll(ModuleId, Null.NullInteger)
Dim objTagNodes As XmlNodeList = nodeRoot.SelectNodes("/rss/channel/wp:tag", nsMgr)
Dim objTagController As New TagController()
For Each objTagNode As XmlNode In objTagNodes
Dim objName As XmlNode = objTagNode.SelectSingleNode("wp:tag_name", nsMgr)
Dim objTag As New TagInfo
objTag.ModuleID = Me.ModuleId
objTag.Name = objName.InnerText
objTag.NameLowered = objName.InnerText.ToLower()
objTagController.Add(objTag)
Next
Dim objTags As ArrayList = objTagController.List(ModuleId, Null.NullInteger)
Dim objArticleNodes As XmlNodeList = nodeRoot.SelectNodes("/rss/channel/item", nsMgr)
Dim objArticleController As New ArticleController()
For Each objArticleNode As XmlNode In objArticleNodes
Dim objPostType As XmlNode = objArticleNode.SelectSingleNode("wp:post_type", nsMgr)
Dim objStatus As XmlNode = objArticleNode.SelectSingleNode("wp:status", nsMgr)
If (objPostType.InnerText = "post" And objStatus.InnerText <> "draft") Then
Dim objTitle As XmlNode = objArticleNode.SelectSingleNode("title", nsMgr)
Dim objContent As XmlNode = objArticleNode.SelectSingleNode("content:encoded", nsMgr)
Dim objPostID As XmlNode = objArticleNode.SelectSingleNode("wp:post_id", nsMgr)
Dim objPostDate As XmlNode = objArticleNode.SelectSingleNode("wp:post_date", nsMgr)
Dim dt As DateTime = DateTime.Parse(objPostDate.InnerText)
Dim objArticle As New ArticleInfo
objArticle.Title = objTitle.InnerText
objArticle.CreatedDate = dt
objArticle.StartDate = dt
objArticle.Status = StatusType.Published
objArticle.CommentCount = 0
objArticle.FileCount = 0
objArticle.RatingCount = 0
objArticle.Rating = 0
objArticle.ShortUrl = ""
objArticle.MetaTitle = ""
objArticle.MetaDescription = ""
objArticle.MetaKeywords = ""
objArticle.PageHeadText = ""
objArticle.IsFeatured = False
objArticle.IsSecure = False
objArticle.LastUpdate = DateTime.Now
objArticle.LastUpdateID = Me.UserId
objArticle.ModuleID = Me.ModuleId
objArticle.AuthorID = Me.UserId
objArticle.ArticleID = objArticleController.AddArticle(objArticle)
Dim objPageController As New PageController()
Dim objPage As New PageInfo
objPage.PageText = objContent.InnerText
objPage.ArticleID = objArticle.ArticleID
objPage.Title = objArticle.Title
objPageController.AddPage(objPage)
Dim objCategoryNodes As XmlNodeList = objArticleNode.SelectNodes("category", nsMgr)
For Each objCategoryNode As XmlNode In objCategoryNodes
Select Case objCategoryNode.Attributes("domain").InnerText
Case "post_tag"
For Each objTag As TagInfo In objTags
If (objTag.Name.ToLower() = objCategoryNode.InnerText.ToLower()) Then
objTagController.Add(objArticle.ArticleID, objTag.TagID)
Exit For
End If
Next
Exit Select
Case "category"
For Each objCategory As CategoryInfo In objCategories
If (objCategory.Name.ToLower() = objCategoryNode.InnerText.ToLower()) Then
objArticleController.AddArticleCategory(objArticle.ArticleID, objCategory.CategoryID)
Exit For
End If
Next
Exit Select
End Select
Next
Dim objCommentNodes As XmlNodeList = objArticleNode.SelectNodes("wp:comment", nsMgr)
For Each objCommentNode As XmlNode In objCommentNodes
Dim objAuthor As XmlNode = objCommentNode.SelectSingleNode("wp:comment_author", nsMgr)
Dim objAuthorEmail As XmlNode = objCommentNode.SelectSingleNode("wp:comment_author_email", nsMgr)
Dim objAuthorUrl As XmlNode = objCommentNode.SelectSingleNode("wp:comment_author_url", nsMgr)
Dim objAuthorIP As XmlNode = objCommentNode.SelectSingleNode("wp:comment_author_IP", nsMgr)
Dim objCommentContent As XmlNode = objCommentNode.SelectSingleNode("wp:comment_content", nsMgr)
Dim objCommentDate As XmlNode = objCommentNode.SelectSingleNode("wp:comment_date", nsMgr)
Dim dtComment As DateTime = DateTime.Parse(objCommentDate.InnerText)
Dim objComment As New CommentInfo
objComment.ArticleID = objArticle.ArticleID
objComment.UserID = Null.NullInteger
objComment.AnonymousName = objAuthor.InnerText
objComment.AnonymousEmail = objAuthorEmail.InnerText
objComment.AnonymousURL = objAuthorUrl.InnerText
objComment.Comment = FilterInput(objCommentContent.InnerText)
objComment.RemoteAddress = objAuthorIP.InnerText
objComment.NotifyMe = False
objComment.Type = 0
objComment.IsApproved = True
objComment.ApprovedBy = Me.UserId
objComment.CreatedDate = dtComment
Dim objCommentController As New CommentController
objComment.CommentID = objCommentController.AddComment(objComment)
objArticle.CommentCount = objArticle.CommentCount + 1
objArticleController.UpdateArticle(objArticle)
Next
End If
Next
End Sub
Private Function FilterInput(ByVal stringToFilter As String) As String
Dim objPortalSecurity As New PortalSecurity
stringToFilter = objPortalSecurity.InputFilter(stringToFilter, PortalSecurity.FilterFlag.NoScripting)
stringToFilter = Replace(stringToFilter, Chr(13), "")
stringToFilter = Replace(stringToFilter, ControlChars.Lf, "<br />")
Return stringToFilter
End Function
End Class
End Namespace