camaleon_cms 2.5.3.1 → 2.6.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of camaleon_cms might be problematic. Click here for more details.

Files changed (118) hide show
  1. checksums.yaml +4 -4
  2. data/app/apps/plugins/front_cache/front_cache_helper.rb +1 -1
  3. data/app/assets/images/camaleon_cms/language/md.png +0 -0
  4. data/app/models/camaleon_cms/ability.rb +94 -92
  5. data/app/models/camaleon_cms/category.rb +45 -44
  6. data/app/models/camaleon_cms/custom_field.rb +26 -25
  7. data/app/models/camaleon_cms/custom_field_group.rb +115 -114
  8. data/app/models/camaleon_cms/custom_fields_relationship.rb +21 -19
  9. data/app/models/camaleon_cms/media.rb +48 -44
  10. data/app/models/camaleon_cms/meta.rb +5 -3
  11. data/app/models/camaleon_cms/nav_menu.rb +27 -24
  12. data/app/models/camaleon_cms/nav_menu_item.rb +58 -54
  13. data/app/models/camaleon_cms/plugin.rb +62 -60
  14. data/app/models/camaleon_cms/post.rb +205 -227
  15. data/app/models/camaleon_cms/post_comment.rb +44 -42
  16. data/app/models/camaleon_cms/post_default.rb +65 -62
  17. data/app/models/camaleon_cms/post_relationship.rb +1 -2
  18. data/app/models/camaleon_cms/post_tag.rb +9 -6
  19. data/app/models/camaleon_cms/post_type.rb +170 -163
  20. data/app/models/camaleon_cms/site.rb +211 -203
  21. data/app/models/camaleon_cms/term_relationship.rb +16 -14
  22. data/app/models/camaleon_cms/term_taxonomy.rb +49 -54
  23. data/app/models/camaleon_cms/theme.rb +24 -23
  24. data/app/models/camaleon_cms/user.rb +18 -13
  25. data/app/models/camaleon_cms/user_role.rb +130 -128
  26. data/app/models/camaleon_cms/widget/assigned.rb +25 -21
  27. data/app/models/camaleon_cms/widget/main.rb +40 -36
  28. data/app/models/camaleon_cms/widget/sidebar.rb +20 -16
  29. data/app/validators/camaleon_cms/post_uniq_validator.rb +28 -0
  30. data/app/validators/camaleon_cms/uniq_validator.rb +9 -0
  31. data/config/locales/camaleon_cms/admin/ar.yml +1 -0
  32. data/config/locales/camaleon_cms/admin/de.yml +1 -0
  33. data/config/locales/camaleon_cms/admin/en.yml +82 -21
  34. data/config/locales/camaleon_cms/admin/fr.yml +1 -0
  35. data/config/locales/camaleon_cms/admin/it.yml +1 -0
  36. data/config/locales/camaleon_cms/admin/js/de.yml +51 -0
  37. data/config/locales/camaleon_cms/admin/js/en.yml +51 -0
  38. data/config/locales/camaleon_cms/admin/js/es.yml +53 -0
  39. data/config/locales/camaleon_cms/admin/js/it.yml +44 -0
  40. data/config/locales/camaleon_cms/admin/js/nl.yml +42 -0
  41. data/config/locales/camaleon_cms/admin/js/pt-BR.yml +44 -0
  42. data/config/locales/camaleon_cms/admin/js/ru.yml +51 -0
  43. data/config/locales/camaleon_cms/admin/js/uk.yml +51 -0
  44. data/config/locales/camaleon_cms/admin/js/zh-CN.yml +51 -0
  45. data/config/locales/camaleon_cms/admin/nl.yml +1 -0
  46. data/config/locales/camaleon_cms/admin/ru.yml +1 -0
  47. data/config/locales/camaleon_cms/admin/uk.yml +2 -1
  48. data/config/locales/camaleon_cms/admin/zh-CH.yml +1 -0
  49. data/config/locales/camaleon_cms/common.md +3 -0
  50. data/config/locales/camaleon_cms/common/ar.yml +66 -0
  51. data/config/locales/camaleon_cms/common/de.yml +66 -0
  52. data/config/locales/camaleon_cms/common/en.yml +63 -0
  53. data/config/locales/camaleon_cms/common/es.yml +66 -0
  54. data/config/locales/camaleon_cms/common/fr.yml +66 -0
  55. data/config/locales/camaleon_cms/common/it.yml +63 -0
  56. data/config/locales/camaleon_cms/common/md.yml +60 -0
  57. data/config/locales/camaleon_cms/common/nl.yml +64 -0
  58. data/config/locales/camaleon_cms/common/pt-BR.yml +65 -0
  59. data/config/locales/camaleon_cms/common/pt.yml +65 -0
  60. data/config/locales/camaleon_cms/common/ru.yml +66 -0
  61. data/config/locales/camaleon_cms/common/uk.yml +64 -0
  62. data/config/locales/camaleon_cms/common/zh-CN.yml +66 -0
  63. data/config/locales/camaleon_cms/languages/ar.yml +16 -0
  64. data/config/locales/camaleon_cms/languages/de.yml +16 -0
  65. data/config/locales/camaleon_cms/languages/en.yml +16 -0
  66. data/config/locales/camaleon_cms/languages/es.yml +16 -0
  67. data/config/locales/camaleon_cms/languages/it.yml +16 -0
  68. data/config/locales/camaleon_cms/languages/md.yml +15 -0
  69. data/config/locales/camaleon_cms/languages/nl.yml +16 -0
  70. data/config/locales/camaleon_cms/languages/pt-BR.yml +16 -0
  71. data/config/locales/camaleon_cms/languages/pt.yml +16 -0
  72. data/config/locales/camaleon_cms/languages/ru.yml +16 -0
  73. data/config/locales/camaleon_cms/languages/uk.yml +16 -0
  74. data/config/locales/camaleon_cms/languages/zh-CN.yml +16 -0
  75. data/config/locales/camaleon_cms/routes/de.yml +8 -0
  76. data/config/locales/camaleon_cms/routes/es.yml +8 -0
  77. data/config/locales/camaleon_cms/routes/fr.yml +8 -0
  78. data/config/locales/camaleon_cms/routes/it.yml +8 -0
  79. data/config/locales/camaleon_cms/routes/md.yml +8 -0
  80. data/config/locales/camaleon_cms/routes/pt-BR.yml +8 -0
  81. data/config/locales/camaleon_cms/routes/pt.yml +8 -0
  82. data/config/locales/camaleon_cms/routes/ru.yml +8 -0
  83. data/config/locales/camaleon_cms/routes/uk.yml +8 -0
  84. data/config/locales/camaleon_cms/routes/zh-CN.yml +8 -0
  85. data/config/locales/md.yml +207 -0
  86. data/lib/camaleon_cms/version.rb +1 -1
  87. data/spec/dummy/config/application.rb +14 -2
  88. metadata +102 -109
  89. data/config/locales/camaleon_cms/admin/js.yml +0 -435
  90. data/config/locales/camaleon_cms/common.yml +0 -786
  91. data/config/locales/camaleon_cms/languages.yml +0 -167
  92. data/config/locales/camaleon_cms/routes.yml +0 -71
  93. data/spec/dummy/db/development.sqlite3 +0 -0
  94. data/spec/dummy/db/test.sqlite3 +0 -0
  95. data/spec/dummy/log/development.log +0 -254
  96. data/spec/dummy/log/test.log +0 -46384
  97. data/spec/dummy/public/media/1/rails_tmp.png +0 -0
  98. data/spec/dummy/public/media/1/rails_tmp_1.png +0 -0
  99. data/spec/dummy/public/media/1/rails_tmp_2.png +0 -0
  100. data/spec/dummy/public/media/1/rails_tmp_3.png +0 -0
  101. data/spec/dummy/public/media/1/sample/rails_tmp.png +0 -0
  102. data/spec/dummy/public/media/1/sample/thumb/rails_tmp-png.png +0 -0
  103. data/spec/dummy/public/media/1/slide33.jpg +0 -0
  104. data/spec/dummy/public/media/1/thumb/rails_tmp-png.png +0 -0
  105. data/spec/dummy/public/media/1/thumb/rails_tmp-png_20x.png +0 -0
  106. data/spec/dummy/public/media/1/thumb/rails_tmp-png_300x300.png +0 -0
  107. data/spec/dummy/public/media/1/thumb/rails_tmp-png_505x350.png +0 -0
  108. data/spec/dummy/public/media/1/thumb/rails_tmp_1-png.png +0 -0
  109. data/spec/dummy/public/media/1/thumb/rails_tmp_2-png.png +0 -0
  110. data/spec/dummy/public/media/1/thumb/rails_tmp_3-png.png +0 -0
  111. data/spec/dummy/public/media/1/thumb/slide33-jpg.jpg +0 -0
  112. data/spec/dummy/tmp/capybara/screenshot_2019-09-04-09-19-13.472.html +0 -457
  113. data/spec/dummy/tmp/capybara/screenshot_2019-09-04-09-19-13.472.png +0 -0
  114. data/spec/dummy/tmp/capybara/screenshot_2019-09-04-09-19-28.693.html +0 -428
  115. data/spec/dummy/tmp/capybara/screenshot_2019-09-04-09-19-28.693.png +0 -0
  116. data/spec/dummy/tmp/capybara/screenshot_2019-09-04-09-22-45.502.html +0 -337
  117. data/spec/dummy/tmp/capybara/screenshot_2019-09-04-09-22-45.502.png +0 -0
  118. data/spec/support/fixtures/rails_tmp.png +0 -0
@@ -1,266 +1,244 @@
1
- class CamaleonCms::PostUniqValidator < ActiveModel::Validator
2
- def validate(record)
3
- unless record.draft?
4
- slug_array = record.slug.to_s.translations_array
5
- ptype = record.post_type
6
- if ptype.present? # only for posts that belongs to a post type model
7
- posts = ptype.site.posts
8
- .where("(#{slug_array.map {|s| "#{CamaleonCms::Post.table_name}.slug LIKE '%-->#{s}<!--%'"}.join(" OR ")} ) OR #{CamaleonCms::Post.table_name}.slug = ?", record.slug)
9
- .where.not(id: record.id)
10
- .where.not(status: [:draft, :draft_child, :trash])
11
- if posts.size > 0
12
- if slug_array.size > 1
13
- record.errors[:base] << "#{I18n.t('camaleon_cms.admin.post.message.requires_different_slug')}: #{posts.pluck(:slug).map{|slug| record.slug.to_s.translations.map{|lng, r_slug| "#{r_slug} (#{lng})" if slug.translations_array.include?(r_slug) }.join(",") }.join(",").split(",").uniq.clean_empty.join(", ")} "
14
- else
15
- record.errors[:base] << "#{I18n.t('camaleon_cms.admin.post.message.requires_different_slug')}: #{record.slug.to_s} "
16
- end
1
+ module CamaleonCms
2
+ class Post < CamaleonCms::PostDefault
3
+ include CamaleonCms::CategoriesTagsForPosts
4
+
5
+ alias_attribute :post_type_id, :taxonomy_id
6
+ default_scope ->{ where(post_class: 'Post').order(post_order: :asc, created_at: :desc) }
7
+ cama_define_common_relationships('Post')
8
+
9
+ # DEPRECATED
10
+ has_many :post_relationships, class_name: "CamaleonCms::PostRelationship", foreign_key: :objectid, dependent: :destroy, inverse_of: :post
11
+ has_many :post_types, class_name: "CamaleonCms::PostType", through: :post_relationships, source: :post_type
12
+ # END DEPRECATED
13
+
14
+ has_many :term_relationships, foreign_key: :objectid, dependent: :destroy, inverse_of: :object
15
+ has_many :categories, class_name: "CamaleonCms::Category", through: :term_relationships, source: :term_taxonomy
16
+ has_many :post_tags, class_name: "CamaleonCms::PostTag", through: :term_relationships, source: :term_taxonomy
17
+ has_many :comments, class_name: 'CamaleonCms::PostComment', foreign_key: :post_id, dependent: :destroy
18
+ has_many :drafts, ->{where(status: 'draft_child')}, class_name: 'CamaleonCms::Post', foreign_key: :post_parent, dependent: :destroy
19
+ has_many :children, class_name: 'CamaleonCms::Post', foreign_key: :post_parent, dependent: :destroy, primary_key: :id
20
+
21
+ belongs_to :owner, class_name: CamaManager.get_user_class_name, foreign_key: :user_id
22
+ belongs_to :parent, class_name: 'CamaleonCms::Post', foreign_key: :post_parent
23
+ belongs_to :post_type, foreign_key: :taxonomy_id, inverse_of: :posts
24
+
25
+ scope :visible_frontend, -> {where(status: 'published')}
26
+ scope :public_posts, -> {visible_frontend.where(visibility: ['public', '']) } #public posts (not passwords, not privates)
27
+ scope :private_posts, -> {where(visibility: 'private') } #public posts (not passwords, not privates)
28
+
29
+ scope :trash, -> {where(status: 'trash')}
30
+ scope :no_trash, -> {where.not(status: 'trash')}
31
+ scope :published, -> {where(status: 'published')}
32
+ scope :root_posts, -> {where(post_parent: [nil, ''])}
33
+ scope :drafts, -> {where(status: %w(draft draft_child))}
34
+ scope :pending, -> {where(status: 'pending')}
35
+ scope :latest, -> {reorder(created_at: :desc)}
36
+
37
+ validates_with CamaleonCms::PostUniqValidator
38
+ attr_accessor :show_title_with_parent
39
+ before_create :fix_post_order, if: lambda{|p| !p.post_order.present? || p.post_order == 0 }
40
+
41
+ # return all parents for current page hierarchy ordered bottom to top
42
+ def parents
43
+ cama_fetch_cache("parents_#{id}") do
44
+ res = []
45
+ p = parent
46
+ while p
47
+ res << p
48
+ p = p.parent
17
49
  end
18
-
19
- # avoid recursive page parent
20
- record.errors[:base] << I18n.t('camaleon_cms.admin.post.message.recursive_hierarchy', default: 'Parent Post Recursive') if record.post_parent.present? && ptype.manage_hierarchy? && record.parents.cama_pluck(:id).include?(record.id)
21
- else
22
- # validation for other classes
50
+ res
23
51
  end
24
52
  end
25
- end
26
- end
27
53
 
28
- class CamaleonCms::Post < CamaleonCms::PostDefault
29
- include CamaleonCms::CategoriesTagsForPosts
30
- alias_attribute :post_type_id, :taxonomy_id
31
- default_scope ->{ where(post_class: "Post").order(post_order: :asc, created_at: :desc) }
32
- cama_define_common_relationships('Post')
33
-
34
- # DEPRECATED
35
- has_many :post_relationships, class_name: "CamaleonCms::PostRelationship", foreign_key: :objectid, dependent: :destroy, inverse_of: :posts
36
- has_many :post_types, class_name: "CamaleonCms::PostType", through: :post_relationships, :source => :post_type
37
- # END DEPRECATED
38
-
39
- has_many :term_relationships, class_name: "CamaleonCms::TermRelationship", foreign_key: :objectid, dependent: :destroy, inverse_of: :objects
40
- has_many :categories, class_name: "CamaleonCms::Category", through: :term_relationships, :source => :term_taxonomies
41
- has_many :post_tags, class_name: "CamaleonCms::PostTag", through: :term_relationships, :source => :term_taxonomies
42
- has_many :comments, class_name: "CamaleonCms::PostComment", foreign_key: :post_id, dependent: :destroy
43
- has_many :drafts, ->{where(status: 'draft_child')}, class_name: "CamaleonCms::Post", foreign_key: :post_parent, dependent: :destroy
44
- has_many :children, class_name: "CamaleonCms::Post", foreign_key: :post_parent, dependent: :destroy, primary_key: :id
45
-
46
- belongs_to :owner, class_name: CamaManager.get_user_class_name, foreign_key: :user_id
47
- belongs_to :parent, class_name: "CamaleonCms::Post", foreign_key: :post_parent
48
- belongs_to :post_type, class_name: "CamaleonCms::PostType", foreign_key: :taxonomy_id, inverse_of: :posts
49
-
50
- scope :visible_frontend, -> {where(status: 'published')}
51
- scope :public_posts, -> {visible_frontend.where(visibility: ['public', ""]) } #public posts (not passwords, not privates)
52
- scope :private_posts, -> {where(visibility: 'private') } #public posts (not passwords, not privates)
53
-
54
- scope :trash, -> {where(status: 'trash')}
55
- scope :no_trash, -> {where.not(status: 'trash')}
56
- scope :published, -> {where(status: 'published')}
57
- scope :root_posts, -> {where(post_parent: [nil, ''])}
58
- scope :drafts, -> {where(status: %w(draft draft_child))}
59
- scope :pending, -> {where(status: 'pending')}
60
- scope :latest, -> {reorder(created_at: :desc)}
61
-
62
- validates_with CamaleonCms::PostUniqValidator
63
- attr_accessor :show_title_with_parent
64
- before_create :fix_post_order, if: lambda{|p| !p.post_order.present? || p.post_order == 0 }
65
-
66
- # return all parents for current page hierarchy ordered bottom to top
67
- def parents
68
- cama_fetch_cache("parents_#{self.id}") do
69
- res = []
70
- p = self.parent
71
- while p.present?
72
- res << p
73
- p = p.parent
54
+ # return all children elements for current post (page hierarchy)
55
+ def full_children
56
+ cama_fetch_cache("full_children_#{self.id}") do
57
+ res = children.to_a
58
+ res.each{|c| res += c.full_children }
59
+ res
74
60
  end
75
- res
76
61
  end
77
- end
78
62
 
79
- # return all children elements for current post (page hierarchy)
80
- def full_children
81
- cama_fetch_cache("full_children_#{self.id}") do
82
- res = self.children.to_a
83
- res.each{|c| res += c.full_children }
84
- res
63
+ # return the post type of this post (DEPRECATED)
64
+ def get_post_type_depre
65
+ post_types.reorder(nil).first
85
66
  end
86
- end
87
67
 
88
- # return the post type of this post (DEPRECATED)
89
- def get_post_type_depre
90
- post_types.reorder(nil).first
91
- end
68
+ # check if this post was published
69
+ def published?
70
+ status == 'published'
71
+ end
92
72
 
93
- # check if this post was published
94
- def published?
95
- status == 'published'
96
- end
73
+ # check if this is in pending status
74
+ def pending?
75
+ status == 'pending'
76
+ end
97
77
 
98
- # check if this is in pending status
99
- def pending?
100
- status == 'pending'
101
- end
78
+ # check if this is in draft status
79
+ def draft?
80
+ status == 'draft' || status == 'draft_child'
81
+ end
102
82
 
103
- # check if this is in draft status
104
- def draft?
105
- status == 'draft' || status == 'draft_child'
106
- end
83
+ def draft_child?
84
+ status == 'draft_child'
85
+ end
107
86
 
108
- def draft_child?
109
- status == 'draft_child'
110
- end
87
+ # check if this is in trash status
88
+ def trash?
89
+ status == 'trash'
90
+ end
111
91
 
112
- # check if this is in trash status
113
- def trash?
114
- status == 'trash'
115
- end
92
+ # check if current post can manage content
93
+ # return boolean
94
+ def manage_content?(posttype = nil)
95
+ get_option('has_content', (posttype || post_type).get_option('has_content', true))
96
+ end
116
97
 
117
- # check if current post can manage content
118
- # return boolean
119
- def manage_content?(posttype = nil)
120
- get_option('has_content', (posttype || post_type).get_option('has_content', true))
121
- end
98
+ # return boolean
99
+ def manage_layout?(posttype = nil)
100
+ get_option('has_layout', (posttype || post_type).get_option('has_layout', false))
101
+ end
122
102
 
123
- # return boolean
124
- def manage_layout?(posttype = nil)
125
- get_option('has_layout', (posttype || post_type).get_option('has_layout', false))
126
- end
103
+ # check if current post can manage template
104
+ # return boolean
105
+ def manage_template?(posttype = nil)
106
+ get_option('has_template', (posttype || post_type).get_option('has_template', true))
107
+ end
127
108
 
128
- # check if current post can manage template
129
- # return boolean
130
- def manage_template?(posttype = nil)
131
- get_option('has_template', (posttype || post_type).get_option('has_template', true))
132
- end
109
+ # check if current post can manage summary
110
+ # return boolean
111
+ def manage_summary?(posttype = nil)
112
+ get_option('has_summary', (posttype || post_type).get_option('has_summary', true))
113
+ end
133
114
 
134
- # check if current post can manage summary
135
- # return boolean
136
- def manage_summary?(posttype = nil)
137
- get_option('has_summary', (posttype || post_type).get_option('has_summary', true))
138
- end
115
+ # check if current post can manage picture
116
+ # return boolean
117
+ def manage_picture?(posttype = nil)
118
+ get_option('has_picture', (posttype || post_type).get_option('has_picture', true))
119
+ end
139
120
 
140
- # check if current post can manage picture
141
- # return boolean
142
- def manage_picture?(posttype = nil)
143
- get_option('has_picture', (posttype || post_type).get_option('has_picture', true))
144
- end
121
+ # check if current post can manage comments
122
+ # return boolean
123
+ def manage_comments?(posttype = nil)
124
+ get_option('has_comments', (posttype || post_type).get_option('has_comments', false))
125
+ end
145
126
 
146
- # check if current post can manage comments
147
- # return boolean
148
- def manage_comments?(posttype = nil)
149
- get_option('has_comments', (posttype || post_type).get_option('has_comments', false))
150
- end
127
+ # check if the post can be commented
128
+ # sample: @post.can_commented?
129
+ # return Boolean (true/false)
130
+ # to enable comments for current post, use this: post.set_meta('has_comments', '1'). Note: Parent PostType should be enabled for comments too: post_type.set_option('has_comments', true)
131
+ def can_commented?
132
+ manage_comments? && get_meta('has_comments').to_s == '1'
133
+ end
151
134
 
152
- # check if the post can be commented
153
- # sample: @post.can_commented?
154
- # return Boolean (true/false)
155
- # to enable comments for current post, use this: post.set_meta('has_comments', '1'). Note: Parent PostType should be enabled for comments too: post_type.set_option('has_comments', true)
156
- def can_commented?
157
- manage_comments? && get_meta('has_comments').to_s == "1"
158
- end
135
+ # check if is required picture for current post
136
+ def is_required_picture?
137
+ post_type.get_option('is_required_picture', false)
138
+ end
159
139
 
160
- # check if is required picture for current post
161
- def is_required_picture?
162
- post_type.get_option('is_required_picture', false)
163
- end
140
+ # define post configuration for current post
141
+ # possible key values (String):
142
+ # has_content, boolean (default true)
143
+ # has_summary, boolean (default true)
144
+ # has_seo, boolean (default true)
145
+ # has_picture, boolean (default true)
146
+ # has_template, boolean (default false)
147
+ # has_comments, boolean (default false)
148
+ # default_layout: (string) (default layout) # this is still used if post type was inactivated layout and overwritten by dropdown in post view
149
+ # default_template: (string) (default template) # this is still used if post type was inactivated template and overwritten by dropdown in post view
150
+ # has_layout: (boolean) (default false)
151
+ # skip_fields: (array) (default empty) array of custom field keys to avoid for this post, sample: ["subtitle", "icon"]
152
+ # val: value for the setting
153
+ def set_setting(key, val)
154
+ set_option(key, val)
155
+ end
164
156
 
165
- # define post configuration for current post
166
- # possible key values (String):
167
- # has_content, boolean (default true)
168
- # has_summary, boolean (default true)
169
- # has_seo, boolean (default true)
170
- # has_picture, boolean (default true)
171
- # has_template, boolean (default false)
172
- # has_comments, boolean (default false)
173
- # default_layout: (string) (default layout) # this is still used if post type was inactivated layout and overwritten by dropdown in post view
174
- # default_template: (string) (default template) # this is still used if post type was inactivated template and overwritten by dropdown in post view
175
- # has_layout: (boolean) (default false)
176
- # skip_fields: (array) (default empty) array of custom field keys to avoid for this post, sample: ["subtitle", "icon"]
177
- # val: value for the setting
178
- def set_setting(key, val)
179
- set_option(key, val)
180
- end
157
+ # assign multiple settings
158
+ def set_settings(settings = {})
159
+ settings.each do |key, val|
160
+ set_setting(key, val)
161
+ end
162
+ end
181
163
 
182
- # assign multiple settings
183
- def set_settings(settings = {})
184
- settings.each do |key, val|
185
- set_setting(key, val)
164
+ # put a new order position for this post
165
+ # new_order_position: (Integer) position number
166
+ # return nil
167
+ def set_position(new_order_position)
168
+ self.update_column('post_order', new_order_position)
186
169
  end
187
- end
188
170
 
189
- # put a new order position for this post
190
- # new_order_position: (Integer) position number
191
- # return nil
192
- def set_position(new_order_position)
193
- self.update_column("post_order", new_order_position)
194
- end
171
+ # save the summary for current post
172
+ # summary: Text String without html
173
+ def set_summary(summary)
174
+ set_meta('summary', summary)
175
+ end
195
176
 
196
- # save the summary for current post
197
- # summary: Text String without html
198
- def set_summary(summary)
199
- set_meta("summary", summary)
200
- end
177
+ # check if current post permit manage seo attrs
178
+ # has_keywords: used until next version (deprecated to use has_seo)
179
+ # return boolean
180
+ def manage_seo?(posttype = nil)
181
+ get_option('has_seo', get_option('has_keywords', false)) || (posttype || post_type).manage_seo?
182
+ end
183
+ alias_method :manage_keywords?, :manage_seo? # method name deprecated to use manage_seo?
201
184
 
202
- # check if current post permit manage seo attrs
203
- # has_keywords: used until next version (deprecated to use has_seo)
204
- # return boolean
205
- def manage_seo?(posttype = nil)
206
- get_option('has_seo', get_option('has_keywords', false)) || (posttype || post_type).manage_seo?
207
- end
208
- alias_method :manage_keywords?, :manage_seo? # method name deprecated to use manage_seo?
185
+ # save the thumbnail url for current post
186
+ # thumb_url: String url
187
+ def set_thumb(thumb_url)
188
+ set_meta('thumb', thumb_url)
189
+ end
209
190
 
210
- # save the thumbnail url for current post
211
- # thumb_url: String url
212
- def set_thumb(thumb_url)
213
- set_meta("thumb", thumb_url)
214
- end
191
+ # save the layout name to be used on render this post
192
+ # layout_name: String layout name: my_layout.html.erb => 'my_layout'
193
+ def set_layout(layout_name)
194
+ set_meta('layout', layout_name)
195
+ end
215
196
 
216
- # save the layout name to be used on render this post
217
- # layout_name: String layout name: my_layout.html.erb => 'my_layout'
218
- def set_layout(layout_name)
219
- set_meta("layout", layout_name)
220
- end
197
+ # return the layout assigned to this post
198
+ # post_type: post type owner of this post
199
+ def get_layout(posttype = nil)
200
+ return get_option('default_layout') unless manage_layout?(posttype)
221
201
 
222
- # return the layout assigned to this post
223
- # post_type: post type owner of this post
224
- def get_layout(posttype = nil)
225
- return get_option("default_layout") if !manage_layout?(posttype)
226
- get_meta('layout', get_option("default_layout") || (posttype || self.post_type).get_option('default_layout', nil))
227
- end
202
+ get_meta('layout', get_option('default_layout') || (posttype || post_type).get_option('default_layout', nil))
203
+ end
228
204
 
229
- # return the template assigned to this post
230
- # verify default template defined in post type
231
- # post_type: post type owner of this post
232
- def get_template(posttype = nil)
233
- return get_option("default_template") if !manage_template?(posttype)
234
- get_meta('template', get_option("default_template") || (posttype || self.post_type).get_option('default_template', nil))
235
- end
205
+ # return the template assigned to this post
206
+ # verify default template defined in post type
207
+ # post_type: post type owner of this post
208
+ def get_template(posttype = nil)
209
+ return get_option('default_template') unless manage_template?(posttype)
236
210
 
237
- # increment the counter of visitors
238
- def increment_visits!
239
- set_meta("visits", total_visits+1)
240
- end
211
+ get_meta('template', get_option('default_template') || (posttype || post_type).get_option('default_template', nil))
212
+ end
241
213
 
242
- # return the quantity of visits for this post
243
- def total_visits
244
- get_meta("visits", 0).to_i
245
- end
214
+ # increment the counter of visitors
215
+ def increment_visits!
216
+ set_meta('visits', total_visits+1)
217
+ end
246
218
 
247
- # return the quantity of comments for this post
248
- # TODO comments count to move into cache counter
249
- def total_comments
250
- self.get_meta("comments_count", 0).to_i
251
- end
219
+ # return the quantity of visits for this post
220
+ def total_visits
221
+ get_meta('visits', 0).to_i
222
+ end
252
223
 
253
- # manage the custom decorators for posts
254
- # sample: my_post_type.set_option('cama_post_decorator_class', 'ProductDecorator')
255
- # Sample: https://github.com/owen2345/camaleon-ecommerce/tree/master/app/decorators/
256
- def decorator_class
257
- (post_type.get_option('cama_post_decorator_class', 'CamaleonCms::PostDecorator') rescue 'CamaleonCms::PostDecorator').constantize
258
- end
224
+ # return the quantity of comments for this post
225
+ # TODO comments count to move into cache counter
226
+ def total_comments
227
+ get_meta('comments_count', 0).to_i
228
+ end
259
229
 
260
- private
261
- # calculate a post order when it is empty
262
- def fix_post_order
263
- last_post = post_type.posts.where.not(id: nil).last
264
- self.post_order = last_post.present? ? last_post.post_order + 1 : 1
230
+ # manage the custom decorators for posts
231
+ # sample: my_post_type.set_option('cama_post_decorator_class', 'ProductDecorator')
232
+ # Sample: https://github.com/owen2345/camaleon-ecommerce/tree/master/app/decorators/
233
+ def decorator_class
234
+ (post_type.get_option('cama_post_decorator_class', 'CamaleonCms::PostDecorator') rescue 'CamaleonCms::PostDecorator').constantize
235
+ end
236
+
237
+ private
238
+ # calculate a post order when it is empty
239
+ def fix_post_order
240
+ last_post = post_type.posts.where.not(id: nil).last
241
+ self.post_order = last_post.present? ? last_post.post_order + 1 : 1
242
+ end
265
243
  end
266
244
  end