zen 0.2.5 → 0.2.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (178) hide show
  1. data/.gems +34 -0
  2. data/.travis.yml +7 -0
  3. data/AUTHORS +5 -0
  4. data/CHANGELOG +14 -0
  5. data/{license.txt → LICENSE} +0 -0
  6. data/MANIFEST +67 -51
  7. data/README.md +18 -25
  8. data/Rakefile +2 -3
  9. data/bin/zen +2 -2
  10. data/lib/zen.rb +93 -57
  11. data/lib/zen/asset.rb +7 -8
  12. data/lib/zen/bin/app.rb +0 -2
  13. data/lib/zen/controller/admin_controller.rb +4 -9
  14. data/lib/zen/controller/base_controller.rb +0 -25
  15. data/lib/zen/controller/main_controller.rb +5 -5
  16. data/lib/zen/controller/preview.rb +50 -0
  17. data/lib/zen/helper/common.rb +4 -68
  18. data/lib/zen/helper/message.rb +82 -0
  19. data/lib/zen/helper/theme.rb +2 -2
  20. data/lib/zen/language.rb +68 -38
  21. data/lib/zen/language/en/zen_general.yml +1 -4
  22. data/lib/zen/language/nl/zen_general.yml +28 -0
  23. data/lib/zen/language/nl/zen_models.yml +13 -0
  24. data/lib/zen/layout/admin.xhtml +1 -1
  25. data/lib/zen/layout/login.xhtml +1 -1
  26. data/lib/zen/model/settings.rb +2 -0
  27. data/lib/zen/package.rb +29 -25
  28. data/lib/zen/package/all.rb +1 -1
  29. data/lib/zen/package/categories/lib/categories/controller/categories.rb +51 -63
  30. data/lib/zen/package/categories/lib/categories/controller/category_groups.rb +45 -52
  31. data/lib/zen/package/categories/lib/categories/language/en/categories.yml +2 -2
  32. data/lib/zen/package/categories/lib/categories/language/nl/categories.yml +39 -0
  33. data/lib/zen/package/categories/lib/categories/language/nl/category_groups.yml +33 -0
  34. data/lib/zen/package/categories/lib/categories/plugin/categories.rb +2 -2
  35. data/lib/zen/package/comments/lib/comments.rb +31 -2
  36. data/lib/zen/package/comments/lib/comments/controller/comments.rb +42 -57
  37. data/lib/zen/package/comments/lib/comments/controller/comments_form.rb +36 -51
  38. data/lib/zen/package/comments/lib/comments/language/en/comments.yml +7 -3
  39. data/lib/zen/package/comments/lib/comments/language/nl/comments.yml +48 -0
  40. data/lib/zen/package/comments/lib/comments/model/comment.rb +45 -4
  41. data/lib/zen/package/comments/lib/comments/plugin/anti_spam.rb +152 -0
  42. data/lib/zen/package/comments/lib/comments/plugin/comments.rb +5 -6
  43. data/lib/zen/package/comments/lib/comments/view/admin/comments/index.xhtml +2 -2
  44. data/lib/zen/package/custom_fields/lib/custom_fields/controller/custom_field_groups.rb +43 -52
  45. data/lib/zen/package/custom_fields/lib/custom_fields/controller/custom_fields.rb +68 -67
  46. data/lib/zen/package/custom_fields/lib/custom_fields/language/en/custom_fields.yml +1 -1
  47. data/lib/zen/package/custom_fields/lib/custom_fields/language/nl/custom_field_groups.yml +32 -0
  48. data/lib/zen/package/custom_fields/lib/custom_fields/language/nl/custom_fields.yml +52 -0
  49. data/lib/zen/package/custom_fields/lib/custom_fields/model/custom_field.rb +3 -3
  50. data/lib/zen/package/custom_fields/lib/custom_fields/model/custom_field_group.rb +4 -7
  51. data/lib/zen/package/custom_fields/lib/custom_fields/model/custom_field_value.rb +3 -3
  52. data/lib/zen/package/menus/lib/menus/controller/menu_items.rb +37 -44
  53. data/lib/zen/package/menus/lib/menus/controller/menus.rb +33 -43
  54. data/lib/zen/package/menus/lib/menus/helper/menu_item.rb +5 -10
  55. data/lib/zen/package/menus/lib/menus/language/nl/menu_items.yml +41 -0
  56. data/lib/zen/package/menus/lib/menus/language/nl/menus.yml +39 -0
  57. data/lib/zen/package/menus/lib/menus/model/menu.rb +3 -3
  58. data/lib/zen/package/menus/lib/menus/model/menu_item.rb +3 -3
  59. data/lib/zen/package/menus/lib/menus/plugin/menus.rb +5 -6
  60. data/lib/zen/package/menus/migrations/1297184342_create_schema.rb +1 -1
  61. data/lib/zen/package/sections/lib/sections.rb +20 -0
  62. data/lib/zen/package/sections/lib/sections/controller/section_entries.rb +85 -79
  63. data/lib/zen/package/sections/lib/sections/controller/sections.rb +58 -66
  64. data/lib/zen/package/sections/lib/sections/language/en/sections.yml +0 -1
  65. data/lib/zen/package/sections/lib/sections/language/nl/section_entries.yml +43 -0
  66. data/lib/zen/package/sections/lib/sections/language/nl/sections.yml +47 -0
  67. data/lib/zen/package/sections/lib/sections/model/section.rb +11 -15
  68. data/lib/zen/package/sections/lib/sections/model/section_entry.rb +9 -5
  69. data/lib/zen/package/sections/lib/sections/plugin/section_entries.rb +7 -8
  70. data/lib/zen/package/sections/lib/sections/plugin/sections.rb +3 -4
  71. data/lib/zen/package/sections/lib/sections/view/admin/section-entries/form.xhtml +0 -4
  72. data/lib/zen/package/sections/lib/sections/view/admin/section-entries/index.xhtml +8 -2
  73. data/lib/zen/package/sections/migrations/1306772479_remove_unique_slug.rb +28 -0
  74. data/lib/zen/package/settings/lib/settings.rb +21 -34
  75. data/lib/zen/package/settings/lib/settings/controller/settings.rb +29 -22
  76. data/lib/zen/package/settings/lib/settings/language/en/settings.yml +7 -5
  77. data/lib/zen/package/settings/lib/settings/language/nl/settings.yml +39 -0
  78. data/lib/zen/package/settings/lib/settings/model/setting.rb +3 -5
  79. data/lib/zen/package/settings/lib/settings/plugin/group_base.rb +3 -4
  80. data/lib/zen/package/settings/lib/settings/plugin/setting_base.rb +3 -5
  81. data/lib/zen/package/settings/lib/settings/plugin/settings.rb +11 -4
  82. data/lib/zen/package/settings/lib/settings/view/admin/settings/index.xhtml +5 -5
  83. data/lib/zen/package/settings/migrations/1299538742_add_language_key.rb +8 -8
  84. data/lib/zen/package/settings/migrations/1303196915_settings_plugin.rb +2 -5
  85. data/lib/zen/package/users/lib/users/controller/access_rules.rb +54 -61
  86. data/lib/zen/package/users/lib/users/controller/user_groups.rb +49 -57
  87. data/lib/zen/package/users/lib/users/controller/users.rb +58 -73
  88. data/lib/zen/package/users/lib/users/language/en/users.yml +6 -0
  89. data/lib/zen/package/users/lib/users/language/nl/access_rules.yml +37 -0
  90. data/lib/zen/package/users/lib/users/language/nl/user_groups.yml +31 -0
  91. data/lib/zen/package/users/lib/users/language/nl/users.yml +56 -0
  92. data/lib/zen/package/users/lib/users/model/user.rb +16 -1
  93. data/lib/zen/package/users/lib/users/view/admin/users/form.xhtml +27 -2
  94. data/lib/zen/package/users/lib/users/view/admin/users/index.xhtml +15 -3
  95. data/lib/zen/package/users/migrations/1304939855_user_settings.rb +15 -0
  96. data/lib/zen/plugin.rb +7 -9
  97. data/lib/zen/public/admin/css/{buttons.css → zen/buttons.css} +11 -7
  98. data/lib/zen/public/admin/css/{datepicker.css → zen/datepicker.css} +0 -0
  99. data/lib/zen/public/admin/css/{editor.css → zen/editor.css} +10 -5
  100. data/lib/zen/public/admin/css/{forms.css → zen/forms.css} +1 -1
  101. data/lib/zen/public/admin/css/{general.css → zen/general.css} +7 -7
  102. data/lib/zen/public/admin/css/{grid.css → zen/grid.css} +0 -0
  103. data/lib/zen/public/admin/css/{layout.css → zen/layout.css} +4 -5
  104. data/lib/zen/public/admin/css/zen/messages.css +61 -0
  105. data/lib/zen/public/admin/css/{notifications.css → zen/notifications.css} +4 -4
  106. data/lib/zen/public/admin/css/{reset.css → zen/reset.css} +0 -0
  107. data/lib/zen/public/admin/css/{tables.css → zen/tables.css} +3 -3
  108. data/lib/zen/public/admin/css/{tabs.css → zen/tabs.css} +5 -5
  109. data/lib/zen/public/admin/css/zen/window.css +79 -0
  110. data/lib/zen/public/admin/images/{icons → zen/icons}/accept.png +0 -0
  111. data/lib/zen/public/admin/images/{icons → zen/icons}/add.png +0 -0
  112. data/lib/zen/public/admin/images/{icons → zen/icons}/back.png +0 -0
  113. data/lib/zen/public/admin/images/{icons → zen/icons}/bold.png +0 -0
  114. data/lib/zen/public/admin/images/zen/icons/close.png +0 -0
  115. data/lib/zen/public/admin/images/{icons → zen/icons}/delete.png +0 -0
  116. data/lib/zen/public/admin/images/{icons → zen/icons}/edit.png +0 -0
  117. data/lib/zen/public/admin/images/{icons → zen/icons}/error.png +0 -0
  118. data/lib/zen/public/admin/images/{icons → zen/icons}/help.png +0 -0
  119. data/lib/zen/public/admin/images/{icons → zen/icons}/info.png +0 -0
  120. data/lib/zen/public/admin/images/{icons → zen/icons}/italic.png +0 -0
  121. data/lib/zen/public/admin/images/{icons → zen/icons}/large/error.png +0 -0
  122. data/lib/zen/public/admin/images/{icons → zen/icons}/large/notice.png +0 -0
  123. data/lib/zen/public/admin/images/{icons → zen/icons}/large/success.png +0 -0
  124. data/lib/zen/public/admin/images/{icons → zen/icons}/link.png +0 -0
  125. data/lib/zen/public/admin/images/{icons → zen/icons}/logout.png +0 -0
  126. data/lib/zen/public/admin/images/{icons → zen/icons}/ol.png +0 -0
  127. data/lib/zen/public/admin/images/{icons → zen/icons}/pdf.png +0 -0
  128. data/lib/zen/public/admin/images/zen/icons/preview.png +0 -0
  129. data/lib/zen/public/admin/images/{icons → zen/icons}/ul.png +0 -0
  130. data/lib/zen/public/admin/images/{icons → zen/icons}/user.png +0 -0
  131. data/lib/zen/public/admin/images/{icons → zen/icons}/view.png +0 -0
  132. data/lib/zen/public/admin/js/zen/core.js +73 -0
  133. data/lib/zen/public/admin/js/zen/editor.js +527 -0
  134. data/lib/zen/public/admin/js/zen/editor/markdown.js +84 -0
  135. data/lib/zen/public/admin/js/zen/editor/textile.js +84 -0
  136. data/lib/zen/public/admin/js/zen/init.js +12 -66
  137. data/lib/zen/public/admin/js/zen/tabs.js +5 -0
  138. data/lib/zen/public/admin/js/zen/window.js +206 -0
  139. data/lib/zen/task/build.rake +23 -6
  140. data/lib/zen/task/clean.rake +6 -7
  141. data/lib/zen/task/db.rake +7 -9
  142. data/lib/zen/task/package.rake +6 -6
  143. data/lib/zen/task/test.rake +6 -0
  144. data/lib/zen/task/theme.rake +3 -3
  145. data/lib/zen/theme.rb +3 -4
  146. data/lib/zen/validation.rb +7 -9
  147. data/lib/zen/version.rb +3 -4
  148. data/lib/zen/view/bottom.xhtml +0 -5
  149. data/lib/zen/view/main.xhtml +2 -0
  150. data/proto/app/app.rb +6 -4
  151. data/proto/app/config/config.rb +1 -7
  152. data/proto/app/config/database.rb +47 -43
  153. data/proto/app/config/middlewares.rb +0 -40
  154. data/proto/app/start.rb +1 -6
  155. data/proto/app/{vendor → theme}/.gitkeep +0 -0
  156. data/proto/migration.rb +3 -3
  157. data/proto/package/lib/package.rb +0 -1
  158. data/proto/package/lib/package/controller/controllers.rb +7 -40
  159. data/proto/package/lib/package/model/model.rb +3 -3
  160. metadata +106 -79
  161. data/CHANGELOG.md +0 -27
  162. data/ROADMAP.md +0 -53
  163. data/lib/zen/database.rb +0 -112
  164. data/lib/zen/logger.rb +0 -56
  165. data/lib/zen/public/admin/css/modals.css +0 -63
  166. data/lib/zen/public/admin/images/icons/close.png +0 -0
  167. data/lib/zen/public/admin/js/vendor/yepnope.js +0 -1
  168. data/lib/zen/public/admin/js/zen/editor/base.js +0 -262
  169. data/lib/zen/public/admin/js/zen/editor/drivers/html.js +0 -89
  170. data/lib/zen/public/admin/js/zen/editor/drivers/markdown.js +0 -87
  171. data/lib/zen/public/admin/js/zen/editor/drivers/textile.js +0 -87
  172. data/lib/zen/public/admin/js/zen/modal.js +0 -146
  173. data/lib/zen/public/admin/js/zen/notification.js +0 -211
  174. data/proto/app/config/requires.rb +0 -10
  175. data/proto/app/vendor/theme/.gitkeep +0 -0
  176. data/proto/package/lib/package/view/admin/package/edit.xhtml +0 -0
  177. data/proto/package/lib/package/view/admin/package/form.xhtml +0 -0
  178. data/proto/package/lib/package/view/admin/package/new.xhtml +0 -0
@@ -13,13 +13,13 @@ module Categories
13
13
  include ::Categories::Model
14
14
 
15
15
  map('/admin/category-groups')
16
-
16
+
17
17
  before_all do
18
18
  csrf_protection(:save, :delete) do
19
19
  respond(lang('zen_general.errors.csrf'), 403)
20
20
  end
21
21
  end
22
-
22
+
23
23
  ##
24
24
  # The constructor is used to set various options such as the form URLs and load
25
25
  # the language pack for the categories module.
@@ -33,19 +33,19 @@ module Categories
33
33
  #
34
34
  def initialize
35
35
  super
36
-
36
+
37
37
  @form_save_url = CategoryGroups.r(:save)
38
38
  @form_delete_url = CategoryGroups.r(:delete)
39
-
39
+
40
40
  Zen::Language.load('category_groups')
41
-
41
+
42
42
  # Set the page title
43
43
  if !action.method.nil?
44
44
  method = action.method.to_s
45
45
  @page_title = lang("category_groups.titles.#{method}") rescue nil
46
46
  end
47
47
  end
48
-
48
+
49
49
  ##
50
50
  # Show an overview of all existing category groups and allow the user
51
51
  # to create new category groups or manage individual categories.
@@ -61,12 +61,12 @@ module Categories
61
61
  if !user_authorized?([:read])
62
62
  respond(lang('zen_general.errors.not_authorized'), 403)
63
63
  end
64
-
64
+
65
65
  set_breadcrumbs(lang('category_groups.titles.index'))
66
-
66
+
67
67
  @category_groups = CategoryGroup.all
68
68
  end
69
-
69
+
70
70
  ##
71
71
  # Edit an existing category group based on the ID specified in the URL.
72
72
  # This method requires the following permissions:
@@ -81,19 +81,19 @@ module Categories
81
81
  if !user_authorized?([:read, :update])
82
82
  respond(lang('zen_general.errors.not_authorized'), 403)
83
83
  end
84
-
84
+
85
85
  set_breadcrumbs(
86
86
  anchor_to(lang('category_groups.titles.index'), CategoryGroups.r(:index)),
87
87
  lang('category_groups.titles.edit')
88
88
  )
89
-
89
+
90
90
  if flash[:form_data]
91
91
  @category_group = flash[:form_data]
92
92
  else
93
93
  @category_group = CategoryGroup[id]
94
94
  end
95
95
  end
96
-
96
+
97
97
  ##
98
98
  # Create a new category group. This method requires the following permissions:
99
99
  #
@@ -107,12 +107,12 @@ module Categories
107
107
  if !user_authorized?([:create, :read])
108
108
  respond(lang('zen_general.errors.not_authorized'), 403)
109
109
  end
110
-
110
+
111
111
  set_breadcrumbs(
112
112
  anchor_to(lang('category_groups.titles.index'), CategoryGroups.r(:index)),
113
113
  lang('category_groups.titles.new')
114
114
  )
115
-
115
+
116
116
  @category_group = CategoryGroup.new
117
117
  end
118
118
 
@@ -125,42 +125,47 @@ module Categories
125
125
  #
126
126
  # @author Yorick Peterse
127
127
  # @since 0.1
128
- #
128
+ #
129
129
  def save
130
130
  if !user_authorized?([:create, :update])
131
131
  respond(lang('zen_general.errors.not_authorized'), 403)
132
132
  end
133
-
134
- post = request.params.dup
135
-
133
+
134
+ post = request.subset(:id, :name, :description)
135
+
136
136
  if post['id'] and !post['id'].empty?
137
- @category_group = CategoryGroup[post['id'].to_i]
137
+ @category_group = CategoryGroup[post['id']]
138
138
  save_action = :save
139
139
  else
140
140
  @category_group = CategoryGroup.new
141
141
  save_action = :new
142
142
  end
143
-
143
+
144
+ # Set the messages
144
145
  flash_success = lang("category_groups.success.#{save_action}")
145
146
  flash_error = lang("category_groups.errors.#{save_action}")
146
-
147
+
148
+ post.delete('id')
149
+
150
+ # Try to run the query
147
151
  begin
148
152
  @category_group.update(post)
149
- notification(:success, lang('category_groups.titles.index'), flash_success)
150
- rescue
151
- notification(:error, lang('category_groups.titles.index'), flash_error)
153
+ message(:success, flash_success)
154
+ rescue => e
155
+ message(:error, flash_error)
156
+ Ramaze::Log.error(e.inspect)
152
157
 
153
158
  flash[:form_data] = @category_group
154
159
  flash[:form_errors] = @category_group.errors
155
160
  end
156
-
161
+
157
162
  if !@category_group.nil? and @category_group.id
158
163
  redirect(CategoryGroups.r(:edit, @category_group.id))
159
- else
164
+ else
160
165
  redirect(CategoryGroups.r(:new))
161
166
  end
162
167
  end
163
-
168
+
164
169
  ##
165
170
  # Delete all specified category groups and their categories. In
166
171
  # order to delete a number of groups an array of fields, named "category_group_ids"
@@ -179,37 +184,25 @@ module Categories
179
184
  respond(lang('zen_general.errors.not_authorized'), 403)
180
185
  end
181
186
 
182
- post = request.params.dup
183
-
184
- if !post['category_group_ids'] or post['category_group_ids'].empty?
185
- notification(
186
- :error,
187
- lang('category_groups.titles.index'),
188
- lang('category_groups.errors.no_delete')
189
- )
187
+ post = request.subset(:category_group_ids)
190
188
 
189
+ if !post['category_group_ids'] or post['category_group_ids'].empty?
190
+ message(:error, lang('category_groups.errors.no_delete'))
191
191
  redirect(CategoryGroups.r(:index))
192
192
  end
193
-
193
+
194
194
  post['category_group_ids'].each do |id|
195
195
  begin
196
- CategoryGroup[id.to_i].destroy
197
- notification(
198
- :success,
199
- lang('category_groups.titles.index'),
200
- lang('category_groups.success.delete')
201
- )
202
- rescue
203
- notification(
204
- :error,
205
- lang('category_groups.titles.index'),
206
- lang('category_groups.errors.delete') % id
207
- )
196
+ CategoryGroup[id].destroy
197
+ message(:success, lang('category_groups.success.delete'))
198
+ rescue => e
199
+ Ramaze::Log.error(e.inspect)
200
+ message(:error, lang('category_groups.errors.delete') % id)
208
201
  end
209
202
  end
210
-
203
+
211
204
  redirect(CategoryGroups.r(:index))
212
205
  end
213
- end
214
- end
215
- end
206
+ end # CategoryGroups
207
+ end # Controller
208
+ end # Categories
@@ -12,8 +12,8 @@ labels:
12
12
  slug : 'Slug'
13
13
 
14
14
  placeholders:
15
- name : 'The name of the category'
16
- slug : 'A URL friendly name of the category'
15
+ name : 'The name of the category.'
16
+ slug : 'A URL friendly name of the category.'
17
17
 
18
18
  messages:
19
19
  no_categories : 'No categories have been created yet.'
@@ -0,0 +1,39 @@
1
+ ---
2
+ titles:
3
+ index: 'Categoriën'
4
+ edit : 'Categorie aanpassen'
5
+ new : 'Categorie aanmaken'
6
+
7
+ labels:
8
+ id : '#'
9
+ name : 'Naam'
10
+ description: 'Beschrijving'
11
+
12
+ # TODO: "Ouder" is a rather uncommon translation of the word "parent" when dealing with
13
+ # a hierarchy. It should be replaced with a better word once I find out which one to
14
+ # use.
15
+ parent: 'Ouder'
16
+ slug : 'Slug'
17
+
18
+ placeholders:
19
+ name: 'De naam van de categorie.'
20
+ slug: 'Een URL vriendelijke versie van de naam van de categorie.'
21
+
22
+ messages:
23
+ no_categories: 'Er zijn nog geen categoriën aangemaakt.'
24
+
25
+ success:
26
+ new : 'De categorie is aangemaakt.'
27
+ save : 'De categorie is aangepast.'
28
+ delete: 'De categorie is verwijderd.'
29
+
30
+ errors:
31
+ new : 'De categorie kon niet worden aangemaakt.'
32
+ save : 'De categorie kon niet worden aangepast.'
33
+ delete : 'De categorie met ID #%s kon niet worden verwijderd.'
34
+ no_delete: 'U moet ten minste 1 categorie specificeren om te verwijderen.'
35
+
36
+ buttons:
37
+ new : 'Categorie aanmaken'
38
+ save : 'Categorie opslaan'
39
+ delete: 'Geselecteerde categoriën verwijderen'
@@ -0,0 +1,33 @@
1
+ ---
2
+ titles:
3
+ index: 'Categorie groepen'
4
+ edit : 'Categorie groep aanpassen'
5
+ new : 'Categorie groep aanmaken'
6
+
7
+ labels:
8
+ id : '#'
9
+ name : 'Naam'
10
+ description: 'Beschrijving'
11
+ manage : 'Categoriën beheren'
12
+
13
+ placeholders:
14
+ name: 'De naam van de groep.'
15
+
16
+ messages:
17
+ no_groups: 'Er zijn nog geen groepen aangemaakt.'
18
+
19
+ success:
20
+ new : 'De categorie groep is aangemaakt.'
21
+ save : 'De categorie groep is aangepast.'
22
+ delete: 'De categorie groep is verwijderd.'
23
+
24
+ errors:
25
+ new : 'De categorie groep kon niet worden aangemaakt.'
26
+ save : 'De categorie groep kon niet worden aangepast.'
27
+ delete : 'De categorie groep met ID #%s kon niet worden verwijderd.'
28
+ no_delete: 'U moet ten minste 1 groep specificeren om te verwijderen.'
29
+
30
+ buttons:
31
+ new : 'Groep aanmaken'
32
+ save : 'Groep opslaan'
33
+ delete: 'Geselecteerde groepen verwijderen'
@@ -100,8 +100,8 @@ module Categories
100
100
 
101
101
  # Get all the categories according to our specified configuration options
102
102
  # and the category group that was retrieved earlier on.
103
- categories = Category.filter(:category_group_id => category_group.id)
104
- .limit(@options[:limit], @options[:offset])
103
+ categories = Category.filter(:category_group_id => category_group.id) \
104
+ .limit(@options[:limit], @options[:offset]) \
105
105
  .all
106
106
 
107
107
  # Retrieve the category for the specified ID or slug
@@ -2,6 +2,7 @@ require __DIR__('comments/model/comment.rb')
2
2
  require __DIR__('comments/controller/comments')
3
3
  require __DIR__('comments/controller/comments_form')
4
4
  require __DIR__('comments/plugin/comments')
5
+ require __DIR__('comments/plugin/anti_spam')
5
6
 
6
7
  Zen::Language.options.paths.push(__DIR__('comments'))
7
8
  Zen::Language.load('comments')
@@ -10,12 +11,12 @@ Zen::Package.add do |p|
10
11
  p.name = 'comments'
11
12
  p.author = 'Yorick Peterse'
12
13
  p.url = 'http://yorickpeterse.com/'
13
- p.about = "Allow users to post comments on any given section entry (as long as
14
+ p.about = "Allow users to post comments on any given section entry (as long as
14
15
  the section allows it)."
15
16
 
16
17
  p.directory = __DIR__('comments')
17
18
  p.migration_dir = __DIR__('../migrations')
18
-
19
+
19
20
  p.menu = [{
20
21
  :title => lang('comments.titles.index'),
21
22
  :url => "admin/comments"
@@ -33,3 +34,31 @@ Zen::Plugin.add do |p|
33
34
  p.about = 'Plugin that can be used to retrieve comments.'
34
35
  p.plugin = Comments::Plugin::Comments
35
36
  end
37
+
38
+ Zen::Plugin.add do |p|
39
+ p.name = 'anti_spam'
40
+ p.author = 'Yorick Peterse'
41
+ p.url = 'http://yorickpeterse.com/'
42
+ p.about = 'Plugin used for checking if a comment is spam or ham.'
43
+ p.plugin = Comments::Plugin::AntiSpam
44
+ end
45
+
46
+ plugin(:settings, :register) do |setting|
47
+ setting.title = lang('comments.labels.anti_spam_system')
48
+ setting.description = lang('comments.placeholders.anti_spam_system')
49
+ setting.name = 'anti_spam_system'
50
+ setting.group = 'security'
51
+ setting.type = 'select'
52
+ setting.default = 'defensio'
53
+ setting.values = {
54
+ 'defensio' => lang('comments.labels.defensio')
55
+ }
56
+ end
57
+
58
+ plugin(:settings, :register) do |setting|
59
+ setting.title = lang('comments.labels.defensio_key')
60
+ setting.description = lang('comments.placeholders.defensio_key')
61
+ setting.name = 'defensio_key'
62
+ setting.group = 'security'
63
+ setting.type = 'textbox'
64
+ end
@@ -17,37 +17,37 @@ module Comments
17
17
  include ::Comments::Model
18
18
 
19
19
  map('/admin/comments')
20
-
20
+
21
21
  before_all do
22
22
  csrf_protection(:save, :delete) do
23
23
  respond(lang('zen_general.errors.csrf'), 403)
24
24
  end
25
25
  end
26
-
26
+
27
27
  ##
28
28
  # Constructor method that pre-loads several variables and language files.
29
29
  # The following language files are loaded:
30
30
  #
31
31
  # * comments
32
- #
32
+ #
33
33
  # @author Yorick Peterse
34
34
  # @since 0.1
35
35
  #
36
36
  def initialize
37
37
  super
38
-
38
+
39
39
  @form_save_url = Comments.r(:save)
40
40
  @form_delete_url = Comments.r(:delete)
41
-
41
+
42
42
  Zen::Language.load('comments')
43
-
43
+
44
44
  # Set the page title
45
45
  if !action.method.nil?
46
46
  method = action.method.to_s
47
47
  @page_title = lang("comments.titles.#{method}") rescue nil
48
48
  end
49
49
  end
50
-
50
+
51
51
  ##
52
52
  # Shows an overview of all posted comments along with their status,
53
53
  # author and so on.
@@ -55,7 +55,7 @@ module Comments
55
55
  # This method requires the following permissions:
56
56
  #
57
57
  # * read
58
- #
58
+ #
59
59
  # @author Yorick Peterse
60
60
  # @since 0.1
61
61
  #
@@ -63,12 +63,12 @@ module Comments
63
63
  if !user_authorized?([:read])
64
64
  respond(lang('zen_general.errors.not_authorized'), 403)
65
65
  end
66
-
66
+
67
67
  set_breadcrumbs(lang('comments.titles.index'))
68
-
68
+
69
69
  @comments = Comment.all
70
70
  end
71
-
71
+
72
72
  ##
73
73
  # Edits an existing comment based on the ID.
74
74
  #
@@ -81,14 +81,13 @@ module Comments
81
81
  # @param [Integer] id The ID of the comment to retrieve so that we can edit it.
82
82
  # @since 0.1
83
83
  #
84
- def edit id
84
+ def edit(id)
85
85
  if !user_authorized?([:read, :update])
86
86
  respond(lang('zen_general.errors.not_authorized'), 403)
87
87
  end
88
-
88
+
89
89
  set_breadcrumbs(
90
- anchor_to(lang('comments.titles.index'), Comments.r(:index)),
91
- @page_title
90
+ anchor_to(lang('comments.titles.index'), Comments.r(:index)), @page_title
92
91
  )
93
92
 
94
93
  if flash[:form_data]
@@ -97,7 +96,7 @@ module Comments
97
96
  @comment = Comment[id.to_i]
98
97
  end
99
98
  end
100
-
99
+
101
100
  ##
102
101
  # Saves a comment based on the current POST data. Note that this
103
102
  # method won't create a new comment as this can't be done using the backend.
@@ -113,29 +112,27 @@ module Comments
113
112
  if !user_authorized?([:update])
114
113
  respond(lang('zen_general.errors.not_authorized'), 403)
115
114
  end
116
-
115
+
117
116
  # Copy the POST data so we can work with it without messing things up
118
- post = request.params.dup
119
- @comment = Comment[post['id'].to_i]
117
+ post = request.subset(
118
+ :user_id, :name, :website, :email, :comment, :status, :section_entry_id, :id
119
+ )
120
+
121
+ @comment = Comment[post['id']]
122
+
123
+ post.delete('id')
120
124
 
121
125
  begin
122
126
  @comment.update(post)
123
- notification(
124
- :success,
125
- lang('comments.titles.index'),
126
- lang('comments.success.save')
127
- )
128
- rescue
129
- notification(
130
- :error,
131
- lang('comments.titles.index'),
132
- lang('comments.errors.save')
133
- )
134
-
127
+ message(:success, lang('comments.success.save'))
128
+ rescue => e
129
+ Ramaze::Log.error(e.inspect)
130
+ message(:error, lang('comments.errors.save'))
131
+
135
132
  flash[:form_errors] = @comment.errors
136
133
  flash[:form_data] = @comment
137
134
  end
138
-
135
+
139
136
  # Redirect the user to the proper page.
140
137
  if @comment.id
141
138
  redirect(Comments.r(:edit, @comment.id))
@@ -143,7 +140,7 @@ module Comments
143
140
  redirect_referrer
144
141
  end
145
142
  end
146
-
143
+
147
144
  ##
148
145
  # Deletes a number of comments based on the comment IDs specified
149
146
  # in the POST array "comment_ids".
@@ -159,38 +156,26 @@ module Comments
159
156
  if !user_authorized?([:delete])
160
157
  respond(lang('zen_general.errors.not_authorized'), 403)
161
158
  end
162
-
159
+
163
160
  # Obviously we'll require some IDs
164
161
  if !request.params['comment_ids'] or request.params['comment_ids'].empty?
165
- notification(
166
- :error,
167
- lang('comments.titles.index'),
168
- lang('comments.errors.no_delete')
169
- )
170
-
162
+ message(:error, lang('comments.errors.no_delete'))
171
163
  redirect_referrer
172
164
  end
173
-
165
+
174
166
  # Delete each section
175
167
  request.params['comment_ids'].each do |id|
176
168
  begin
177
- Comment[id.to_i].destroy
178
- notification(
179
- :success,
180
- lang('comments.titles.index'),
181
- lang('comments.success.delete')
182
- )
183
- rescue
184
- notification(
185
- :error,
186
- lang('comments.titles.index'),
187
- lang('comments.errors.delete') % id
188
- )
169
+ Comment[id].destroy
170
+ message(:success, lang('comments.success.delete'))
171
+ rescue => e
172
+ Ramaze::Log.error(e.inspect)
173
+ message(:error, lang('comments.errors.delete') % id)
189
174
  end
190
175
  end
191
-
176
+
192
177
  redirect_referrer
193
178
  end
194
- end
195
- end
196
- end
179
+ end # Comments
180
+ end # Controller
181
+ end # Comments