ASP Classic blog framework - BrainOrdure
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

222 wiersze
6.5KB

  1. <%
  2. ' Auto-generated Controller: Posts
  3. ' Generated on 5/2/2026 9:47:38 PM
  4. ' Generator: generateController.vbs v1.0
  5. '
  6. ' Remember to:
  7. ' 1. Add to app/controllers/autoload_controllers.asp
  8. ' 2. Register in core/lib.ControllerRegistry.asp
  9. ' 3. Add routes in public/Default.asp
  10. Class PostsController_Class
  11. Private m_useLayout
  12. Private m_title
  13. Private Sub Class_Initialize()
  14. m_useLayout = True
  15. m_title = "Posts"
  16. End Sub
  17. Public Property Get useLayout
  18. useLayout = m_useLayout
  19. End Property
  20. Public Property Let useLayout(v)
  21. m_useLayout = v
  22. End Property
  23. Public Property Get Title
  24. Title = m_title
  25. End Property
  26. Public Property Let Title(v)
  27. m_title = v
  28. End Property
  29. '---------------------------------------------------------------
  30. ' Action: Index
  31. '---------------------------------------------------------------
  32. Public Sub Index()
  33. Dim posts
  34. Set posts = PostsRepository().FindAllWhere("IsPublished = 1", "PublishedDate DESC", 0, 20)
  35. %>
  36. <!--#include file="../views/Posts/index.asp" -->
  37. <%
  38. End Sub
  39. '---------------------------------------------------------------
  40. ' Action: Show
  41. '---------------------------------------------------------------
  42. Public Sub Show(ByVal slug)
  43. Dim matches
  44. Set matches = PostsRepository().Find(Array("Slug", slug, "IsPublished", 1), Empty)
  45. If matches.Count = 0 Then
  46. Response.Status = "404 Not Found"
  47. %>
  48. <!--#include file="../views/Error/NotFound.asp" -->
  49. <%
  50. Exit Sub
  51. End If
  52. Dim post
  53. Set post = matches.Front()
  54. Dim comments
  55. Set comments = CommentsRepository().Find(Array("PostID", post.PostID, "IsApproved", 1), "CreatedDate")
  56. %>
  57. <!--#include file="../views/Posts/show.asp" -->
  58. <%
  59. End Sub
  60. '---------------------------------------------------------------
  61. ' Action: New
  62. '---------------------------------------------------------------
  63. Public Sub NewForm()
  64. %>
  65. <!--#include file="../views/Posts/new.asp" -->
  66. <%
  67. End Sub
  68. '---------------------------------------------------------------
  69. ' Action: Create
  70. '---------------------------------------------------------------
  71. Public Sub Create()
  72. Dim title : title = Trim(Request.Form("Title"))
  73. If Len(title) = 0 Then
  74. Flash().AddError "Title is required."
  75. Response.Redirect "/posts/new"
  76. Exit Sub
  77. End If
  78. Dim post
  79. Set post = New POBO_Posts
  80. post.Title = title
  81. post.Summary = Request.Form("Summary")
  82. post.Body = Request.Form("Body")
  83. post.CategoryID = FormNumberOrZero(Request.Form("CategoryID"))
  84. post.Slug = BuildSlug(title)
  85. post.CreatedDate = Now()
  86. post.UpdatedDate = Now()
  87. post.IsPublished = 0
  88. PostsRepository().AddNew post
  89. Flash().Success = "Post created."
  90. Response.Redirect "/posts"
  91. End Sub
  92. '---------------------------------------------------------------
  93. ' Action: Edit
  94. '---------------------------------------------------------------
  95. Public Sub Edit(ByVal id)
  96. Dim post
  97. On Error Resume Next
  98. Set post = PostsRepository().FindByID(id)
  99. If Err.Number <> 0 Then
  100. Err.Clear
  101. On Error GoTo 0
  102. Response.Status = "404 Not Found"
  103. %>
  104. <!--#include file="../views/Error/NotFound.asp" -->
  105. <%
  106. Exit Sub
  107. End If
  108. On Error GoTo 0
  109. %>
  110. <!--#include file="../views/Posts/edit.asp" -->
  111. <%
  112. End Sub
  113. '---------------------------------------------------------------
  114. ' Action: Update
  115. '---------------------------------------------------------------
  116. Public Sub Update(ByVal id)
  117. Dim post
  118. On Error Resume Next
  119. Set post = PostsRepository().FindByID(id)
  120. If Err.Number <> 0 Then
  121. Err.Clear
  122. On Error GoTo 0
  123. Response.Status = "404 Not Found"
  124. %>
  125. <!--#include file="../views/Error/NotFound.asp" -->
  126. <%
  127. Exit Sub
  128. End If
  129. On Error GoTo 0
  130. Dim title : title = Trim(Request.Form("Title"))
  131. If Len(title) = 0 Then
  132. Flash().AddError "Title is required."
  133. Response.Redirect "/posts/" & Server.URLEncode(CStr(id)) & "/edit"
  134. Exit Sub
  135. End If
  136. post.Title = title
  137. post.Summary = Request.Form("Summary")
  138. post.Body = Request.Form("Body")
  139. post.CategoryID = FormNumberOrZero(Request.Form("CategoryID"))
  140. post.Slug = BuildSlug(title)
  141. post.UpdatedDate = Now()
  142. PostsRepository().Update post
  143. Flash().Success = "Post updated."
  144. Response.Redirect "/posts"
  145. End Sub
  146. '---------------------------------------------------------------
  147. ' Action: Delete
  148. '---------------------------------------------------------------
  149. Public Sub Delete(ByVal id)
  150. PostsRepository().Delete id
  151. Flash().Success = "Post deleted."
  152. Response.Redirect "/posts"
  153. End Sub
  154. Private Function FormNumberOrZero(ByVal value)
  155. If IsNumeric(value) Then
  156. FormNumberOrZero = CLng(value)
  157. Else
  158. FormNumberOrZero = 0
  159. End If
  160. End Function
  161. Private Function BuildSlug(ByVal value)
  162. Dim raw : raw = LCase(Trim(CStr(value)))
  163. Dim i, ch, slug, previousDash
  164. slug = ""
  165. previousDash = False
  166. For i = 1 To Len(raw)
  167. ch = Mid(raw, i, 1)
  168. If (ch >= "a" And ch <= "z") Or (ch >= "0" And ch <= "9") Then
  169. slug = slug & ch
  170. previousDash = False
  171. ElseIf Not previousDash And Len(slug) > 0 Then
  172. slug = slug & "-"
  173. previousDash = True
  174. End If
  175. Next
  176. Do While Right(slug, 1) = "-"
  177. slug = Left(slug, Len(slug) - 1)
  178. Loop
  179. If Len(slug) = 0 Then slug = "post"
  180. BuildSlug = slug
  181. End Function
  182. End Class
  183. ' Singleton instance
  184. Dim PostsController_Class__Singleton
  185. Function PostsController()
  186. If IsEmpty(PostsController_Class__Singleton) Then
  187. Set PostsController_Class__Singleton = New PostsController_Class
  188. End If
  189. Set PostsController = PostsController_Class__Singleton
  190. End Function
  191. %>

Powered by TurnKey Linux.