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.
- 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,44 +1,46 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
1
|
+
module CamaleonCms
|
2
|
+
class PostComment < ActiveRecord::Base
|
3
|
+
include CamaleonCms::Metas
|
4
|
+
|
5
|
+
self.table_name = "#{PluginRoutes.static_system_info['db_prefix']}comments"
|
6
|
+
# attr_accessible :user_id, :post_id, :content, :author, :author_email, :author_url, :author_IP, :approved, :agent, :agent, :typee, :comment_parent, :is_anonymous
|
7
|
+
attr_accessor :is_anonymous
|
8
|
+
|
9
|
+
#default_scope order('comments.created_at ASC')
|
10
|
+
#approved: approved | pending | spam
|
11
|
+
|
12
|
+
cama_define_common_relationships('PostComment')
|
13
|
+
has_many :children, class_name: 'CamaleonCms::PostComment', foreign_key: :comment_parent, dependent: :destroy
|
14
|
+
belongs_to :post
|
15
|
+
belongs_to :parent, class_name: 'CamaleonCms::PostComment', foreign_key: :comment_parent
|
16
|
+
belongs_to :user, class_name: CamaManager.get_user_class_name, foreign_key: :user_id
|
17
|
+
|
18
|
+
default_scope {order("#{CamaleonCms::PostComment.table_name}.created_at DESC")}
|
19
|
+
|
20
|
+
scope :main, -> { where(comment_parent: nil) }
|
21
|
+
scope :comment_parent, -> { where(comment_parent: 'is not null') }
|
22
|
+
scope :approveds, -> { where(approved: 'approved') }
|
23
|
+
|
24
|
+
validates :content, presence: true
|
25
|
+
validates_presence_of :author, :author_email, if: Proc.new { |c| c.is_anonymous.present? }
|
26
|
+
after_create :update_counter
|
27
|
+
after_destroy :update_counter
|
28
|
+
|
29
|
+
# return the owner of this comment
|
30
|
+
def comment_user
|
31
|
+
user
|
32
|
+
end
|
33
|
+
|
34
|
+
# check if this comments is already approved
|
35
|
+
def is_approved?
|
36
|
+
self.approved == 'approved'
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
# update comment counter
|
42
|
+
def update_counter
|
43
|
+
post&.set_meta('comments_count', post.comments.count)
|
44
|
+
end
|
30
45
|
end
|
31
|
-
|
32
|
-
# check if this comments is already approved
|
33
|
-
def is_approved?
|
34
|
-
self.approved == 'approved'
|
35
|
-
end
|
36
|
-
|
37
|
-
private
|
38
|
-
# update comment counter
|
39
|
-
def update_counter
|
40
|
-
p = self.post
|
41
|
-
p.set_meta("comments_count", p.comments.count) if p.present?
|
42
|
-
end
|
43
|
-
|
44
46
|
end
|
@@ -1,78 +1,81 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
module CamaleonCms
|
2
|
+
class PostDefault < ActiveRecord::Base
|
3
|
+
include CamaleonCms::Metas
|
4
|
+
include CamaleonCms::CustomFieldsRead
|
5
5
|
|
6
|
-
|
7
|
-
attr_accessor :draft_id
|
8
|
-
# attr_accessible :data_options
|
9
|
-
# attr_accessible :data_metas
|
10
|
-
cattr_accessor :current_user
|
11
|
-
cattr_accessor :current_site
|
6
|
+
self.table_name = "#{PluginRoutes.static_system_info["db_prefix"]}posts"
|
12
7
|
|
13
|
-
|
14
|
-
|
15
|
-
|
8
|
+
# attr_accessible :user_id, :title, :slug, :content, :content_filtered, :status, :visibility, :visibility_value, :post_order, :post_type_key, :taxonomy_id, :published_at, :post_parent, :post_order, :is_feature
|
9
|
+
attr_accessor :draft_id
|
10
|
+
# attr_accessible :data_options
|
11
|
+
# attr_accessible :data_metas
|
12
|
+
cattr_accessor :current_user
|
13
|
+
cattr_accessor :current_site
|
16
14
|
|
17
|
-
|
15
|
+
has_many :term_relationships, foreign_key: :objectid, dependent: :destroy, primary_key: :id
|
16
|
+
has_many :children, ->{ where(post_class: "PostDefault") }, class_name: "CamaleonCms::PostDefault", foreign_key: :post_parent, dependent: :destroy, primary_key: :id
|
17
|
+
scope :featured, ->{ where(is_feature: true) }
|
18
18
|
|
19
|
-
|
20
|
-
before_validation :before_validating
|
21
|
-
before_save :before_saved
|
22
|
-
before_destroy :destroy_dependencies
|
19
|
+
validates :title, :slug, presence: true
|
23
20
|
|
21
|
+
# callbacks
|
22
|
+
before_validation :before_validating
|
23
|
+
before_save :before_saved
|
24
|
+
before_destroy :destroy_dependencies
|
24
25
|
|
25
|
-
# find a content by slug (support multi language)
|
26
|
-
def self.find_by_slug(slug)
|
27
|
-
#if current_site.present? && current_site.get_meta("languages_site", []).count <= 1
|
28
|
-
# res = self.where(slug: slug)
|
29
|
-
#else
|
30
|
-
res = self.where("#{CamaleonCms::Post.table_name}.slug = ? OR #{CamaleonCms::Post.table_name}.slug LIKE ? ", slug, "%-->#{slug}<!--%")
|
31
|
-
#end
|
32
|
-
res.reorder("").first
|
33
|
-
end
|
34
26
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
27
|
+
# find a content by slug (support multi language)
|
28
|
+
def self.find_by_slug(slug)
|
29
|
+
#if current_site.present? && current_site.get_meta("languages_site", []).count <= 1
|
30
|
+
# res = self.where(slug: slug)
|
31
|
+
#else
|
32
|
+
res = self.where("#{CamaleonCms::Post.table_name}.slug = ? OR #{CamaleonCms::Post.table_name}.slug LIKE ? ", slug, "%-->#{slug}<!--%")
|
33
|
+
#end
|
34
|
+
res.reorder("").first
|
35
|
+
end
|
39
36
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
CamaleonCms::User.find(self.user_id)
|
44
|
-
rescue
|
45
|
-
CamaleonCms::User.admin_scope.first
|
37
|
+
# return the parent of a post (support for sub contents or tree of posts)
|
38
|
+
def parent
|
39
|
+
CamaleonCms::Post.where(id: post_parent).first
|
46
40
|
end
|
47
|
-
end
|
48
41
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
42
|
+
# return the author of this Content
|
43
|
+
def author
|
44
|
+
begin
|
45
|
+
CamaleonCms::User.find(user_id)
|
46
|
+
rescue
|
47
|
+
CamaleonCms::User.admin_scope.first
|
48
|
+
end
|
49
|
+
end
|
53
50
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
self.set_options(options)
|
59
|
-
end
|
51
|
+
# return all menu items in which this post was assigned
|
52
|
+
def in_nav_menu_items
|
53
|
+
CamaleonCms::NavMenuItem.where(url: id, kind: 'post')
|
54
|
+
end
|
60
55
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
56
|
+
# Set the meta, field values and the post keywords here
|
57
|
+
def set_params(meta, custom_fields, options)
|
58
|
+
self.set_metas(meta)
|
59
|
+
self.set_field_values(custom_fields)
|
60
|
+
self.set_options(options)
|
61
|
+
end
|
66
62
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
63
|
+
private
|
64
|
+
def before_validating
|
65
|
+
#self.slug = self.title if self.slug.blank?
|
66
|
+
#self.slug = self.slug.to_s.parameterize
|
67
|
+
end
|
72
68
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
69
|
+
# do all before actions to save the content
|
70
|
+
def before_saved
|
71
|
+
self.title = "Untitled" unless title.present?
|
72
|
+
self.content_filtered = content.to_s.include?('<!--:-->') ? content.translations.inject({}) { |h, (key, value)| h[key] = value.squish.strip_tags; h }.to_translate : content.to_s.squish.strip_tags
|
73
|
+
end
|
74
|
+
|
75
|
+
# destroy all dependencies of this content
|
76
|
+
# unassign this items from menus
|
77
|
+
def destroy_dependencies
|
78
|
+
in_nav_menu_items.destroy_all
|
79
|
+
end
|
77
80
|
end
|
78
81
|
end
|
@@ -6,7 +6,7 @@ class CamaleonCms::PostRelationship < ActiveRecord::Base
|
|
6
6
|
default_scope ->{ order(term_order: :asc) }
|
7
7
|
|
8
8
|
belongs_to :post_type, :class_name => "CamaleonCms::PostType", foreign_key: :term_taxonomy_id, inverse_of: :post_relationships
|
9
|
-
belongs_to :
|
9
|
+
belongs_to :post, ->{ order("#{CamaleonCms::Post.table_name}.id DESC") }, foreign_key: :objectid, inverse_of: :post_relationships, dependent: :destroy
|
10
10
|
|
11
11
|
# callbacks
|
12
12
|
after_create :update_count
|
@@ -16,5 +16,4 @@ class CamaleonCms::PostRelationship < ActiveRecord::Base
|
|
16
16
|
def update_count
|
17
17
|
self.post_type.update_column('count', self.post_type.posts.size) if self.post_type.present?
|
18
18
|
end
|
19
|
-
|
20
19
|
end
|
@@ -1,7 +1,10 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
1
|
+
module CamaleonCms
|
2
|
+
class PostTag < CamaleonCms::TermTaxonomy
|
3
|
+
default_scope { where(taxonomy: :post_tag) }
|
4
|
+
|
5
|
+
cama_define_common_relationships('PostTag')
|
6
|
+
has_many :posts, foreign_key: :objectid, through: :term_relationships, source: :object
|
7
|
+
belongs_to :post_type, foreign_key: :parent_id, inverse_of: :post_tags
|
8
|
+
belongs_to :owner, class_name: CamaManager.get_user_class_name, foreign_key: :user_id
|
9
|
+
end
|
7
10
|
end
|
@@ -1,189 +1,196 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
1
|
+
module CamaleonCms
|
2
|
+
class PostType < CamaleonCms::TermTaxonomy
|
3
|
+
alias_attribute :site_id, :parent_id
|
4
|
+
default_scope { where(taxonomy: :post_type) }
|
5
|
+
cama_define_common_relationships('PostType')
|
6
|
+
has_many :categories, foreign_key: :parent_id, dependent: :destroy, inverse_of: :post_type_parent
|
7
|
+
has_many :post_tags, foreign_key: :parent_id, dependent: :destroy, inverse_of: :post_type
|
8
|
+
has_many :posts, foreign_key: :taxonomy_id, dependent: :destroy, inverse_of: :post_type
|
9
|
+
has_many :comments, through: :posts
|
10
|
+
has_many :posts_through_categories, foreign_key: :objectid, through: :term_relationships, source: :object
|
11
|
+
has_many :posts_draft, class_name: 'CamaleonCms::Post', foreign_key: :taxonomy_id, dependent: :destroy, inverse_of: :post_type
|
12
|
+
has_many :field_group_taxonomy, -> {where('object_class LIKE ?', 'PostType_%')}, class_name: 'CamaleonCms::CustomField', foreign_key: :objectid, dependent: :destroy
|
13
|
+
|
14
|
+
belongs_to :owner, class_name: CamaManager.get_user_class_name, foreign_key: :user_id
|
15
|
+
belongs_to :site, foreign_key: :parent_id
|
16
|
+
|
17
|
+
scope :visible_menu, -> {where(term_group: nil)}
|
18
|
+
scope :hidden_menu, -> {where(term_group: -1)}
|
19
|
+
|
20
|
+
before_destroy :destroy_field_groups
|
21
|
+
after_create :set_default_site_user_roles
|
22
|
+
after_create :refresh_routes
|
23
|
+
after_destroy :refresh_routes
|
24
|
+
after_update :check_refresh_routes
|
25
|
+
before_update :default_category
|
26
|
+
|
27
|
+
# check if current post type manage categories
|
28
|
+
def manage_categories?
|
29
|
+
options[:has_category] || options[:has_single_category]
|
30
|
+
end
|
29
31
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
32
|
+
# hide or show this post type on admin -> contents -> menu
|
33
|
+
# true => enable, false => disable
|
34
|
+
def toggle_show_for_admin_menu(flag)
|
35
|
+
self.update(term_group: flag == true ? nil : -1)
|
36
|
+
end
|
35
37
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
38
|
+
# check if this post type is shown on admin -> contents -> menu
|
39
|
+
def show_for_admin_menu?
|
40
|
+
self.term_group == nil
|
41
|
+
end
|
40
42
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
43
|
+
# check if this post type manage post tags
|
44
|
+
def manage_tags?
|
45
|
+
options[:has_tags]
|
46
|
+
end
|
45
47
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
48
|
+
# check if this post type permit to manage seo attrs in posts
|
49
|
+
def manage_seo?
|
50
|
+
get_option('has_seo', get_option('has_keywords', true))
|
51
|
+
end
|
50
52
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
53
|
+
# assign settings for this post type
|
54
|
+
# default values: {
|
55
|
+
# has_category: false,
|
56
|
+
# has_tags: false,
|
57
|
+
# has_summary: true,
|
58
|
+
# has_content: true,
|
59
|
+
# has_comments: false,
|
60
|
+
# has_picture: true,
|
61
|
+
# has_template: true,
|
62
|
+
# has_seo: true,
|
63
|
+
# not_deleted: false,
|
64
|
+
# has_layout: false,
|
65
|
+
# default_layout: '',
|
66
|
+
# contents_route_format: 'post'
|
67
|
+
# }
|
68
|
+
def set_settings(settings = {})
|
69
|
+
settings.each do |key, val|
|
70
|
+
self.set_option(key, val)
|
71
|
+
end
|
69
72
|
end
|
70
|
-
end
|
71
73
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
74
|
+
# set or update a setting for this post type
|
75
|
+
def set_setting(key, value)
|
76
|
+
self.set_option(key, value)
|
77
|
+
end
|
76
78
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
79
|
+
# select full_categories for the post type, include all children categories
|
80
|
+
def full_categories
|
81
|
+
CamaleonCms::Category.where(site_id: site_id, post_type_id: id)
|
82
|
+
end
|
83
|
+
|
84
|
+
# return default category for this post type
|
85
|
+
# only return a category for post types that manage categories
|
86
|
+
def default_category
|
87
|
+
return unless manage_categories?
|
81
88
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
cat = self.categories.find_by_slug("uncategorized")
|
87
|
-
unless cat.present?
|
88
|
-
cat = self.categories.create({name: 'Uncategorized', slug: 'uncategorized', parent_id: self.id})
|
89
|
-
cat.set_option("not_deleted", true)
|
89
|
+
cat = categories.find_by_slug('uncategorized')
|
90
|
+
unless cat
|
91
|
+
cat = categories.create({name: 'Uncategorized', slug: 'uncategorized', parent_id: id})
|
92
|
+
cat.set_option('not_deleted', true)
|
90
93
|
end
|
91
94
|
cat
|
92
95
|
end
|
93
|
-
end
|
94
96
|
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
97
|
+
# add a post for current model
|
98
|
+
# title: title for post, => required
|
99
|
+
# content: html text content, => required
|
100
|
+
# thumb: image url, => default (empty). check http://camaleon.tuzitio.com/api-methods.html#section_fileuploads
|
101
|
+
# categories: [1,3,4,5], => default (empty)
|
102
|
+
# tags: String comma separated, => default (empty)
|
103
|
+
# slug: string key for post, => default (empty)
|
104
|
+
# summary: String resume (optional) => default (empty)
|
105
|
+
# post_order: Integer to define the order position in the list (optional)
|
106
|
+
# fields: Hash of values for custom fields, sample => fields: {subtitle: 'abc', icon: 'test' } (optional)
|
107
|
+
# settings: Hash of post settings, sample => settings:
|
108
|
+
# {has_content: false, has_summary: true, default_layout: 'my_layout', default_template: 'my_template' } (optional, see more in post.set_setting(...))
|
109
|
+
# data_metas: {template: "", layout: ""}
|
110
|
+
# sample: my_posttype.add_post(title: "My Title", post_order: 5, content: 'lorem_ipsum', settings: {default_template: "home/counters", has_content: false, has_seo: false, skip_fields: ["sub_tite", 'banner']}, fields: {pattern: true, bg: 'http://www.reallusion.com/de/images/3dx5/whatsnew/3dx5_features_banner_bg_02.jpg'})
|
111
|
+
# More samples here: https://gist.github.com/owen2345/eba9691585ed78ad6f7b52e9591357bf
|
112
|
+
# return created post if it was created, else return errors
|
113
|
+
def add_post(args)
|
114
|
+
_fields = args.delete(:fields)
|
115
|
+
_settings = args.delete(:settings)
|
116
|
+
_summary = args.delete(:summary)
|
117
|
+
_order_position = args.delete(:order_position)
|
118
|
+
args[:data_categories] = _categories = args.delete(:categories)
|
119
|
+
args[:data_tags] = args.delete(:tags)
|
120
|
+
_thumb = args.delete(:thumb)
|
121
|
+
p = posts.new(args)
|
122
|
+
p.slug = site.get_valid_post_slug(p.title.parameterize) unless p.slug.present?
|
123
|
+
if p.save!
|
124
|
+
_settings.each{ |k, v| p.set_setting(k, v) } if _settings.present?
|
125
|
+
p.set_position(_order_position) if _order_position.present?
|
126
|
+
p.set_summary(_summary) if _summary.present?
|
127
|
+
p.set_thumb(_thumb) if _thumb.present?
|
128
|
+
_fields.each{ |k, v| p.save_field_value(k, v) } if _fields.present?
|
129
|
+
p.decorate
|
130
|
+
else
|
131
|
+
p.errors
|
132
|
+
end
|
130
133
|
end
|
131
|
-
end
|
132
134
|
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
135
|
+
# return all available route formats of this post type for content posts
|
136
|
+
def contents_route_formats
|
137
|
+
{
|
138
|
+
'post_of_post_type' => '<code>/group/:post_type_id-:title/:slug</code><br> (Sample: http://localhost.com/group/17-services/myservice.html)',
|
139
|
+
'post_of_category' => '<code>/category/:category_id-:title/:slug</code><br> (Sample: http://localhost.com/category/17-services/myservice.html)',
|
140
|
+
'post_of_category_post_type' => '<code>/:post_type_title/category/:category_id-:title/:slug</code><br> (Sample: http://localhost.com/services/category/17-services/myservice.html)',
|
141
|
+
'post_of_posttype' => '<code>/:post_type_title/:slug</code><br> (Sample: http://localhost.com/services/myservice.html)',
|
142
|
+
'post' => '<code>/:slug</code><br> (Sample: http://localhost.com/myservice.html)',
|
143
|
+
'hierarchy_post' => '<code>/:parent1_slug/:parent2_slug/.../:slug</code><br> (Sample: http://localhost.com/item-1/item-1-1/item-111.html)'
|
144
|
+
}
|
145
|
+
end
|
144
146
|
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
147
|
+
# return the configuration of routes for post contents
|
148
|
+
def contents_route_format
|
149
|
+
get_option('contents_route_format', 'post')
|
150
|
+
end
|
149
151
|
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
152
|
+
# verify if this post_type support for page hierarchy (parents)
|
153
|
+
def manage_hierarchy?
|
154
|
+
get_option('has_parent_structure', false)
|
155
|
+
end
|
154
156
|
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
157
|
+
private
|
158
|
+
# skip save_metas_options callback after save changes (inherit from taxonomy) to call from here manually
|
159
|
+
def save_metas_options_skip
|
160
|
+
true
|
161
|
+
end
|
160
162
|
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
163
|
+
# assign default roles for this post type
|
164
|
+
# define default settings for this post type
|
165
|
+
def set_default_site_user_roles
|
166
|
+
self.set_multiple_options(
|
167
|
+
{ has_category: false, has_tags: false, has_summary: true, has_content: true, has_comments: false,
|
168
|
+
has_picture: true, has_template: true, has_seo: true, not_deleted: false, has_layout: false,
|
169
|
+
default_layout: '' }.merge(PluginRoutes.fixActionParameter(data_options || {}).to_sym)
|
170
|
+
)
|
171
|
+
self.site.set_default_user_roles(self)
|
172
|
+
default_category
|
173
|
+
end
|
168
174
|
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
+
# destroy all custom field groups assigned to this post type
|
176
|
+
def destroy_field_groups
|
177
|
+
unless self.destroyed_by_association.present?
|
178
|
+
if slug == 'post' || slug == 'page'
|
179
|
+
errors.add(:base, 'This post type can not be deleted.')
|
180
|
+
return false
|
181
|
+
end
|
175
182
|
end
|
183
|
+
self.get_field_groups.destroy_all
|
176
184
|
end
|
177
|
-
self.get_field_groups.destroy_all
|
178
|
-
end
|
179
185
|
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
186
|
+
# reload routes to enable this post type url, like: http://localhost/my-slug
|
187
|
+
def refresh_routes
|
188
|
+
PluginRoutes.reload unless self.destroyed_by_association.present?
|
189
|
+
end
|
184
190
|
|
185
|
-
|
186
|
-
|
187
|
-
|
191
|
+
# check if slug was changed
|
192
|
+
def check_refresh_routes
|
193
|
+
refresh_routes if cama_attr_changed?(:slug)
|
194
|
+
end
|
188
195
|
end
|
189
196
|
end
|