camaleon_cms 2.5.3.1 → 2.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of camaleon_cms might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/app/apps/plugins/front_cache/front_cache_helper.rb +1 -1
- data/app/assets/images/camaleon_cms/language/md.png +0 -0
- data/app/models/camaleon_cms/ability.rb +94 -92
- data/app/models/camaleon_cms/category.rb +45 -44
- data/app/models/camaleon_cms/custom_field.rb +26 -25
- data/app/models/camaleon_cms/custom_field_group.rb +115 -114
- data/app/models/camaleon_cms/custom_fields_relationship.rb +21 -19
- data/app/models/camaleon_cms/media.rb +48 -44
- data/app/models/camaleon_cms/meta.rb +5 -3
- data/app/models/camaleon_cms/nav_menu.rb +27 -24
- data/app/models/camaleon_cms/nav_menu_item.rb +58 -54
- data/app/models/camaleon_cms/plugin.rb +62 -60
- data/app/models/camaleon_cms/post.rb +205 -227
- data/app/models/camaleon_cms/post_comment.rb +44 -42
- data/app/models/camaleon_cms/post_default.rb +65 -62
- data/app/models/camaleon_cms/post_relationship.rb +1 -2
- data/app/models/camaleon_cms/post_tag.rb +9 -6
- data/app/models/camaleon_cms/post_type.rb +170 -163
- data/app/models/camaleon_cms/site.rb +211 -203
- data/app/models/camaleon_cms/term_relationship.rb +16 -14
- data/app/models/camaleon_cms/term_taxonomy.rb +49 -54
- data/app/models/camaleon_cms/theme.rb +24 -23
- data/app/models/camaleon_cms/user.rb +18 -13
- data/app/models/camaleon_cms/user_role.rb +130 -128
- data/app/models/camaleon_cms/widget/assigned.rb +25 -21
- data/app/models/camaleon_cms/widget/main.rb +40 -36
- data/app/models/camaleon_cms/widget/sidebar.rb +20 -16
- data/app/validators/camaleon_cms/post_uniq_validator.rb +28 -0
- data/app/validators/camaleon_cms/uniq_validator.rb +9 -0
- data/config/locales/camaleon_cms/admin/ar.yml +1 -0
- data/config/locales/camaleon_cms/admin/de.yml +1 -0
- data/config/locales/camaleon_cms/admin/en.yml +82 -21
- data/config/locales/camaleon_cms/admin/fr.yml +1 -0
- data/config/locales/camaleon_cms/admin/it.yml +1 -0
- data/config/locales/camaleon_cms/admin/js/de.yml +51 -0
- data/config/locales/camaleon_cms/admin/js/en.yml +51 -0
- data/config/locales/camaleon_cms/admin/js/es.yml +53 -0
- data/config/locales/camaleon_cms/admin/js/it.yml +44 -0
- data/config/locales/camaleon_cms/admin/js/nl.yml +42 -0
- data/config/locales/camaleon_cms/admin/js/pt-BR.yml +44 -0
- data/config/locales/camaleon_cms/admin/js/ru.yml +51 -0
- data/config/locales/camaleon_cms/admin/js/uk.yml +51 -0
- data/config/locales/camaleon_cms/admin/js/zh-CN.yml +51 -0
- data/config/locales/camaleon_cms/admin/nl.yml +1 -0
- data/config/locales/camaleon_cms/admin/ru.yml +1 -0
- data/config/locales/camaleon_cms/admin/uk.yml +2 -1
- data/config/locales/camaleon_cms/admin/zh-CH.yml +1 -0
- data/config/locales/camaleon_cms/common.md +3 -0
- data/config/locales/camaleon_cms/common/ar.yml +66 -0
- data/config/locales/camaleon_cms/common/de.yml +66 -0
- data/config/locales/camaleon_cms/common/en.yml +63 -0
- data/config/locales/camaleon_cms/common/es.yml +66 -0
- data/config/locales/camaleon_cms/common/fr.yml +66 -0
- data/config/locales/camaleon_cms/common/it.yml +63 -0
- data/config/locales/camaleon_cms/common/md.yml +60 -0
- data/config/locales/camaleon_cms/common/nl.yml +64 -0
- data/config/locales/camaleon_cms/common/pt-BR.yml +65 -0
- data/config/locales/camaleon_cms/common/pt.yml +65 -0
- data/config/locales/camaleon_cms/common/ru.yml +66 -0
- data/config/locales/camaleon_cms/common/uk.yml +64 -0
- data/config/locales/camaleon_cms/common/zh-CN.yml +66 -0
- data/config/locales/camaleon_cms/languages/ar.yml +16 -0
- data/config/locales/camaleon_cms/languages/de.yml +16 -0
- data/config/locales/camaleon_cms/languages/en.yml +16 -0
- data/config/locales/camaleon_cms/languages/es.yml +16 -0
- data/config/locales/camaleon_cms/languages/it.yml +16 -0
- data/config/locales/camaleon_cms/languages/md.yml +15 -0
- data/config/locales/camaleon_cms/languages/nl.yml +16 -0
- data/config/locales/camaleon_cms/languages/pt-BR.yml +16 -0
- data/config/locales/camaleon_cms/languages/pt.yml +16 -0
- data/config/locales/camaleon_cms/languages/ru.yml +16 -0
- data/config/locales/camaleon_cms/languages/uk.yml +16 -0
- data/config/locales/camaleon_cms/languages/zh-CN.yml +16 -0
- data/config/locales/camaleon_cms/routes/de.yml +8 -0
- data/config/locales/camaleon_cms/routes/es.yml +8 -0
- data/config/locales/camaleon_cms/routes/fr.yml +8 -0
- data/config/locales/camaleon_cms/routes/it.yml +8 -0
- data/config/locales/camaleon_cms/routes/md.yml +8 -0
- data/config/locales/camaleon_cms/routes/pt-BR.yml +8 -0
- data/config/locales/camaleon_cms/routes/pt.yml +8 -0
- data/config/locales/camaleon_cms/routes/ru.yml +8 -0
- data/config/locales/camaleon_cms/routes/uk.yml +8 -0
- data/config/locales/camaleon_cms/routes/zh-CN.yml +8 -0
- data/config/locales/md.yml +207 -0
- data/lib/camaleon_cms/version.rb +1 -1
- data/spec/dummy/config/application.rb +14 -2
- metadata +102 -109
- data/config/locales/camaleon_cms/admin/js.yml +0 -435
- data/config/locales/camaleon_cms/common.yml +0 -786
- data/config/locales/camaleon_cms/languages.yml +0 -167
- data/config/locales/camaleon_cms/routes.yml +0 -71
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/development.log +0 -254
- data/spec/dummy/log/test.log +0 -46384
- data/spec/dummy/public/media/1/rails_tmp.png +0 -0
- data/spec/dummy/public/media/1/rails_tmp_1.png +0 -0
- data/spec/dummy/public/media/1/rails_tmp_2.png +0 -0
- data/spec/dummy/public/media/1/rails_tmp_3.png +0 -0
- data/spec/dummy/public/media/1/sample/rails_tmp.png +0 -0
- data/spec/dummy/public/media/1/sample/thumb/rails_tmp-png.png +0 -0
- data/spec/dummy/public/media/1/slide33.jpg +0 -0
- data/spec/dummy/public/media/1/thumb/rails_tmp-png.png +0 -0
- data/spec/dummy/public/media/1/thumb/rails_tmp-png_20x.png +0 -0
- data/spec/dummy/public/media/1/thumb/rails_tmp-png_300x300.png +0 -0
- data/spec/dummy/public/media/1/thumb/rails_tmp-png_505x350.png +0 -0
- data/spec/dummy/public/media/1/thumb/rails_tmp_1-png.png +0 -0
- data/spec/dummy/public/media/1/thumb/rails_tmp_2-png.png +0 -0
- data/spec/dummy/public/media/1/thumb/rails_tmp_3-png.png +0 -0
- data/spec/dummy/public/media/1/thumb/slide33-jpg.jpg +0 -0
- data/spec/dummy/tmp/capybara/screenshot_2019-09-04-09-19-13.472.html +0 -457
- data/spec/dummy/tmp/capybara/screenshot_2019-09-04-09-19-13.472.png +0 -0
- data/spec/dummy/tmp/capybara/screenshot_2019-09-04-09-19-28.693.html +0 -428
- data/spec/dummy/tmp/capybara/screenshot_2019-09-04-09-19-28.693.png +0 -0
- data/spec/dummy/tmp/capybara/screenshot_2019-09-04-09-22-45.502.html +0 -337
- data/spec/dummy/tmp/capybara/screenshot_2019-09-04-09-22-45.502.png +0 -0
- data/spec/support/fixtures/rails_tmp.png +0 -0
@@ -1,266 +1,244 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
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
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
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
|
-
|
80
|
-
|
81
|
-
|
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
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
68
|
+
# check if this post was published
|
69
|
+
def published?
|
70
|
+
status == 'published'
|
71
|
+
end
|
92
72
|
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
73
|
+
# check if this is in pending status
|
74
|
+
def pending?
|
75
|
+
status == 'pending'
|
76
|
+
end
|
97
77
|
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
78
|
+
# check if this is in draft status
|
79
|
+
def draft?
|
80
|
+
status == 'draft' || status == 'draft_child'
|
81
|
+
end
|
102
82
|
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
end
|
83
|
+
def draft_child?
|
84
|
+
status == 'draft_child'
|
85
|
+
end
|
107
86
|
|
108
|
-
|
109
|
-
|
110
|
-
|
87
|
+
# check if this is in trash status
|
88
|
+
def trash?
|
89
|
+
status == 'trash'
|
90
|
+
end
|
111
91
|
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
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
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
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
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
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
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
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
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
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
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
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
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
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
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
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
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
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
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
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
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
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
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
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
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
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
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
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
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
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
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
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
|
-
|
223
|
-
|
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
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
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
|
-
|
238
|
-
|
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
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
214
|
+
# increment the counter of visitors
|
215
|
+
def increment_visits!
|
216
|
+
set_meta('visits', total_visits+1)
|
217
|
+
end
|
246
218
|
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
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
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
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
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
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
|