- <%
- ' Auto-generated Controller: Comments
- ' Generated on 5/2/2026 9:47:38 PM
- ' Generator: generateController.vbs v1.0
- '
- ' Remember to:
- ' 1. Add to app/controllers/autoload_controllers.asp
- ' 2. Register in core/lib.ControllerRegistry.asp
- ' 3. Add routes in public/Default.asp
-
-
- Class CommentsController_Class
- Private m_useLayout
- Private m_title
-
- Private Sub Class_Initialize()
- m_useLayout = True
- m_title = "Comments"
- End Sub
-
- Public Property Get useLayout
- useLayout = m_useLayout
- End Property
-
- Public Property Let useLayout(v)
- m_useLayout = v
- End Property
-
- Public Property Get Title
- Title = m_title
- End Property
-
- Public Property Let Title(v)
- m_title = v
- End Property
-
- '---------------------------------------------------------------
- ' Action: Create
- '---------------------------------------------------------------
- Public Sub Create()
- Dim comment
- Set comment = New POBO_Comments
-
- comment.PostID = FormNumberOrZero(Request.Form("PostID"))
- comment.AuthorName = Request.Form("AuthorName")
- comment.AuthorEmail = Request.Form("AuthorEmail")
- comment.Body = Request.Form("Body")
- comment.CreatedDate = Now()
- comment.IsApproved = 0
-
- CommentsRepository().AddNew comment
- Flash().Success = "Comment submitted for approval."
-
- Dim slug : slug = ResolvePostSlug(comment.PostID)
- If Len(slug) > 0 Then
- Response.Redirect PostUrl(slug)
- Else
- Response.Redirect "/posts"
- End If
- End Sub
-
- '---------------------------------------------------------------
- ' Action: Delete
- '---------------------------------------------------------------
- Public Sub Delete(ByVal id)
- CommentsRepository().Delete id
- Flash().Success = "Comment deleted."
-
- Dim returnUrl : returnUrl = Request.ServerVariables("HTTP_REFERER")
- If Len(returnUrl) = 0 Then returnUrl = "/posts"
- Response.Redirect returnUrl
- End Sub
-
- Private Function FormNumberOrZero(ByVal value)
- If IsNumeric(value) Then
- FormNumberOrZero = CLng(value)
- Else
- FormNumberOrZero = 0
- End If
- End Function
-
- Private Function ResolvePostSlug(ByVal postID)
- Dim slug : slug = Trim(Request.Form("Slug"))
- If Len(slug) = 0 Then slug = Trim(Request.Form("PostSlug"))
- slug = NormalizeSlug(slug)
-
- If Len(slug) = 0 And CLng(postID) > 0 Then
- Dim post
- On Error Resume Next
- Set post = PostsRepository().FindByID(postID)
- If Err.Number = 0 Then slug = NormalizeSlug(post.Slug)
- Err.Clear
- On Error GoTo 0
- End If
-
- ResolvePostSlug = slug
- End Function
-
- End Class
-
- ' Singleton instance
- Dim CommentsController_Class__Singleton
- Function CommentsController()
- If IsEmpty(CommentsController_Class__Singleton) Then
- Set CommentsController_Class__Singleton = New CommentsController_Class
- End If
- Set CommentsController = CommentsController_Class__Singleton
- End Function
- %>
|