camaleon_cms 2.5.0 → 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 (144) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/app/apps/plugins/front_cache/front_cache_helper.rb +1 -1
  4. data/app/assets/config/camaleon-cms.js +0 -1
  5. data/app/assets/images/camaleon_cms/language/md.png +0 -0
  6. data/app/assets/javascripts/camaleon_cms/bootstrap.min.js +4 -5
  7. data/app/assets/stylesheets/camaleon_cms/bootstrap.min.css +6 -0
  8. data/app/assets/{fonts/camaleon_cms → stylesheets/camaleon_cms/fonts}/glyphicons-halflings-regular.eot +0 -0
  9. data/app/assets/{fonts/camaleon_cms → stylesheets/camaleon_cms/fonts}/glyphicons-halflings-regular.svg +0 -0
  10. data/app/assets/{fonts/camaleon_cms → stylesheets/camaleon_cms/fonts}/glyphicons-halflings-regular.ttf +0 -0
  11. data/app/assets/{fonts/camaleon_cms → stylesheets/camaleon_cms/fonts}/glyphicons-halflings-regular.woff +0 -0
  12. data/app/assets/{fonts/camaleon_cms → stylesheets/camaleon_cms/fonts}/glyphicons-halflings-regular.woff2 +0 -0
  13. data/app/controllers/camaleon_cms/admin/sessions_controller.rb +1 -1
  14. data/app/controllers/camaleon_cms/frontend_controller.rb +4 -1
  15. data/app/helpers/camaleon_cms/admin/breadcrumb_helper.rb +1 -1
  16. data/app/helpers/camaleon_cms/camaleon_helper.rb +4 -4
  17. data/app/helpers/camaleon_cms/frontend/seo_helper.rb +2 -1
  18. data/app/helpers/camaleon_cms/frontend/site_helper.rb +1 -6
  19. data/app/helpers/camaleon_cms/short_code_helper.rb +3 -3
  20. data/app/helpers/camaleon_cms/uploader_helper.rb +3 -2
  21. data/app/models/camaleon_cms/ability.rb +94 -92
  22. data/app/models/camaleon_cms/category.rb +45 -44
  23. data/app/models/camaleon_cms/custom_field.rb +26 -25
  24. data/app/models/camaleon_cms/custom_field_group.rb +115 -114
  25. data/app/models/camaleon_cms/custom_fields_relationship.rb +21 -19
  26. data/app/models/camaleon_cms/media.rb +48 -44
  27. data/app/models/camaleon_cms/meta.rb +5 -3
  28. data/app/models/camaleon_cms/nav_menu.rb +27 -24
  29. data/app/models/camaleon_cms/nav_menu_item.rb +58 -54
  30. data/app/models/camaleon_cms/plugin.rb +62 -60
  31. data/app/models/camaleon_cms/post.rb +205 -226
  32. data/app/models/camaleon_cms/post_comment.rb +44 -42
  33. data/app/models/camaleon_cms/post_default.rb +65 -62
  34. data/app/models/camaleon_cms/post_relationship.rb +1 -2
  35. data/app/models/camaleon_cms/post_tag.rb +9 -6
  36. data/app/models/camaleon_cms/post_type.rb +170 -163
  37. data/app/models/camaleon_cms/site.rb +211 -203
  38. data/app/models/camaleon_cms/term_relationship.rb +16 -14
  39. data/app/models/camaleon_cms/term_taxonomy.rb +49 -54
  40. data/app/models/camaleon_cms/theme.rb +24 -23
  41. data/app/models/camaleon_cms/user.rb +18 -13
  42. data/app/models/camaleon_cms/user_role.rb +130 -128
  43. data/app/models/camaleon_cms/widget/assigned.rb +25 -21
  44. data/app/models/camaleon_cms/widget/main.rb +40 -36
  45. data/app/models/camaleon_cms/widget/sidebar.rb +20 -16
  46. data/app/models/concerns/camaleon_cms/user_methods.rb +1 -1
  47. data/app/validators/camaleon_cms/post_uniq_validator.rb +28 -0
  48. data/app/validators/camaleon_cms/uniq_validator.rb +9 -0
  49. data/app/views/camaleon_cms/shortcode_templates/widget.html.erb +1 -1
  50. data/config/initializers/assets.rb +1 -1
  51. data/config/initializers/non_digest_assets.rb +3 -0
  52. data/config/locales/camaleon_cms/admin/ar.yml +1 -0
  53. data/config/locales/camaleon_cms/admin/de.yml +1 -0
  54. data/config/locales/camaleon_cms/admin/en.yml +82 -21
  55. data/config/locales/camaleon_cms/admin/fr.yml +1 -0
  56. data/config/locales/camaleon_cms/admin/it.yml +1 -0
  57. data/config/locales/camaleon_cms/admin/js/de.yml +51 -0
  58. data/config/locales/camaleon_cms/admin/js/en.yml +51 -0
  59. data/config/locales/camaleon_cms/admin/js/es.yml +53 -0
  60. data/config/locales/camaleon_cms/admin/js/it.yml +44 -0
  61. data/config/locales/camaleon_cms/admin/js/nl.yml +42 -0
  62. data/config/locales/camaleon_cms/admin/js/pt-BR.yml +44 -0
  63. data/config/locales/camaleon_cms/admin/js/ru.yml +51 -0
  64. data/config/locales/camaleon_cms/admin/js/uk.yml +51 -0
  65. data/config/locales/camaleon_cms/admin/js/zh-CN.yml +51 -0
  66. data/config/locales/camaleon_cms/admin/nl.yml +1 -0
  67. data/config/locales/camaleon_cms/admin/ru.yml +1 -0
  68. data/config/locales/camaleon_cms/admin/uk.yml +2 -1
  69. data/config/locales/camaleon_cms/admin/zh-CH.yml +1 -0
  70. data/config/locales/camaleon_cms/common.md +3 -0
  71. data/config/locales/camaleon_cms/common/ar.yml +66 -0
  72. data/config/locales/camaleon_cms/common/de.yml +66 -0
  73. data/config/locales/camaleon_cms/common/en.yml +63 -0
  74. data/config/locales/camaleon_cms/common/es.yml +66 -0
  75. data/config/locales/camaleon_cms/common/fr.yml +66 -0
  76. data/config/locales/camaleon_cms/common/it.yml +63 -0
  77. data/config/locales/camaleon_cms/common/md.yml +60 -0
  78. data/config/locales/camaleon_cms/common/nl.yml +64 -0
  79. data/config/locales/camaleon_cms/common/pt-BR.yml +65 -0
  80. data/config/locales/camaleon_cms/common/pt.yml +65 -0
  81. data/config/locales/camaleon_cms/common/ru.yml +66 -0
  82. data/config/locales/camaleon_cms/common/uk.yml +64 -0
  83. data/config/locales/camaleon_cms/common/zh-CN.yml +66 -0
  84. data/config/locales/camaleon_cms/languages/ar.yml +16 -0
  85. data/config/locales/camaleon_cms/languages/de.yml +16 -0
  86. data/config/locales/camaleon_cms/languages/en.yml +16 -0
  87. data/config/locales/camaleon_cms/languages/es.yml +16 -0
  88. data/config/locales/camaleon_cms/languages/it.yml +16 -0
  89. data/config/locales/camaleon_cms/languages/md.yml +15 -0
  90. data/config/locales/camaleon_cms/languages/nl.yml +16 -0
  91. data/config/locales/camaleon_cms/languages/pt-BR.yml +16 -0
  92. data/config/locales/camaleon_cms/languages/pt.yml +16 -0
  93. data/config/locales/camaleon_cms/languages/ru.yml +16 -0
  94. data/config/locales/camaleon_cms/languages/uk.yml +16 -0
  95. data/config/locales/camaleon_cms/languages/zh-CN.yml +16 -0
  96. data/config/locales/camaleon_cms/routes/de.yml +8 -0
  97. data/config/locales/camaleon_cms/routes/es.yml +8 -0
  98. data/config/locales/camaleon_cms/routes/fr.yml +8 -0
  99. data/config/locales/camaleon_cms/routes/it.yml +8 -0
  100. data/config/locales/camaleon_cms/routes/md.yml +8 -0
  101. data/config/locales/camaleon_cms/routes/pt-BR.yml +8 -0
  102. data/config/locales/camaleon_cms/routes/pt.yml +8 -0
  103. data/config/locales/camaleon_cms/routes/ru.yml +8 -0
  104. data/config/locales/camaleon_cms/routes/uk.yml +8 -0
  105. data/config/locales/camaleon_cms/routes/zh-CN.yml +8 -0
  106. data/config/locales/md.yml +207 -0
  107. data/config/routes/admin.rb +1 -1
  108. data/lib/camaleon_cms/version.rb +1 -1
  109. data/lib/generators/camaleon_cms/theme_template/views/layouts/index.html.erb +19 -16
  110. data/lib/plugin_routes.rb +1 -26
  111. data/spec/dummy/config/application.rb +15 -3
  112. data/spec/features/admin/not_found_spec.rb +10 -0
  113. metadata +132 -123
  114. data/app/assets/stylesheets/camaleon_cms/bootstrap.min.css.scss +0 -6799
  115. data/config/locales/camaleon_cms/admin/js.yml +0 -435
  116. data/config/locales/camaleon_cms/common.yml +0 -784
  117. data/config/locales/camaleon_cms/languages.yml +0 -167
  118. data/config/locales/camaleon_cms/routes.yml +0 -71
  119. data/spec/dummy/db/development.sqlite3 +0 -0
  120. data/spec/dummy/db/test.sqlite3 +0 -0
  121. data/spec/dummy/log/development.log +0 -233
  122. data/spec/dummy/log/test.log +0 -46368
  123. data/spec/dummy/public/media/1/rails_tmp.png +0 -0
  124. data/spec/dummy/public/media/1/rails_tmp_1.png +0 -0
  125. data/spec/dummy/public/media/1/rails_tmp_2.png +0 -0
  126. data/spec/dummy/public/media/1/rails_tmp_3.png +0 -0
  127. data/spec/dummy/public/media/1/sample/rails_tmp.png +0 -0
  128. data/spec/dummy/public/media/1/sample/thumb/rails_tmp-png.png +0 -0
  129. data/spec/dummy/public/media/1/slide33.jpg +0 -0
  130. data/spec/dummy/public/media/1/thumb/rails_tmp-png.png +0 -0
  131. data/spec/dummy/public/media/1/thumb/rails_tmp-png_20x.png +0 -0
  132. data/spec/dummy/public/media/1/thumb/rails_tmp-png_300x300.png +0 -0
  133. data/spec/dummy/public/media/1/thumb/rails_tmp-png_505x350.png +0 -0
  134. data/spec/dummy/public/media/1/thumb/rails_tmp_1-png.png +0 -0
  135. data/spec/dummy/public/media/1/thumb/rails_tmp_2-png.png +0 -0
  136. data/spec/dummy/public/media/1/thumb/rails_tmp_3-png.png +0 -0
  137. data/spec/dummy/public/media/1/thumb/slide33-jpg.jpg +0 -0
  138. data/spec/dummy/tmp/capybara/screenshot_2019-09-04-09-19-13.472.html +0 -457
  139. data/spec/dummy/tmp/capybara/screenshot_2019-09-04-09-19-13.472.png +0 -0
  140. data/spec/dummy/tmp/capybara/screenshot_2019-09-04-09-19-28.693.html +0 -428
  141. data/spec/dummy/tmp/capybara/screenshot_2019-09-04-09-19-28.693.png +0 -0
  142. data/spec/dummy/tmp/capybara/screenshot_2019-09-04-09-22-45.502.html +0 -337
  143. data/spec/dummy/tmp/capybara/screenshot_2019-09-04-09-22-45.502.png +0 -0
  144. data/spec/support/fixtures/rails_tmp.png +0 -0
@@ -1,44 +1,46 @@
1
- class CamaleonCms::PostComment < ActiveRecord::Base
2
- include CamaleonCms::Metas
3
- self.table_name = "#{PluginRoutes.static_system_info["db_prefix"]}comments"
4
- # attr_accessible :user_id, :post_id, :content, :author, :author_email, :author_url, :author_IP, :approved, :agent, :agent, :typee, :comment_parent, :is_anonymous
5
- attr_accessor :is_anonymous
6
-
7
- #default_scope order('comments.created_at ASC')
8
- #approved: approved | pending | spam
9
-
10
- cama_define_common_relationships('PostComment')
11
- has_many :children, class_name: "CamaleonCms::PostComment", foreign_key: :comment_parent, dependent: :destroy
12
- belongs_to :post, class_name: "CamaleonCms::Post", foreign_key: :post_id
13
- belongs_to :parent, class_name: "CamaleonCms::PostComment", foreign_key: :comment_parent
14
- belongs_to :user, class_name: CamaManager.get_user_class_name, foreign_key: :user_id
15
-
16
- default_scope {order("#{CamaleonCms::PostComment.table_name}.created_at DESC")}
17
-
18
- scope :main, -> { where(:comment_parent => nil) }
19
- scope :comment_parent, -> { where(:comment_parent => 'is not null') }
20
- scope :approveds, -> { where(:approved => 'approved') }
21
-
22
- validates :content, :presence => true
23
- validates_presence_of :author, :author_email, if: Proc.new { |c| c.is_anonymous.present? }
24
- after_create :update_counter
25
- after_destroy :update_counter
26
-
27
- # return the owner of this comment
28
- def comment_user
29
- self.user
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
- class CamaleonCms::PostDefault < ActiveRecord::Base
2
- include CamaleonCms::Metas
3
- include CamaleonCms::CustomFieldsRead
4
- self.table_name = "#{PluginRoutes.static_system_info["db_prefix"]}posts"
1
+ module CamaleonCms
2
+ class PostDefault < ActiveRecord::Base
3
+ include CamaleonCms::Metas
4
+ include CamaleonCms::CustomFieldsRead
5
5
 
6
- # 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
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
- has_many :term_relationships, class_name: "CamaleonCms::TermRelationship", foreign_key: :objectid, dependent: :destroy, primary_key: :id
14
- has_many :children, ->{ where(post_class: "PostDefault") }, class_name: "CamaleonCms::PostDefault", foreign_key: :post_parent, dependent: :destroy, primary_key: :id
15
- scope :featured, ->{ where(is_feature: true) }
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
- validates :title, :slug, presence: true
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
- # callbacks
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
- # return the parent of a post (support for sub contents or tree of posts)
36
- def parent
37
- CamaleonCms::Post.where(id: self.post_parent).first
38
- end
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
- # return the author of this Content
41
- def author
42
- begin
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
- # return all menu items in which this post was assigned
50
- def in_nav_menu_items
51
- CamaleonCms::NavMenuItem.where(url: self.id, kind: 'post')
52
- end
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
- # Set the meta, field values and the post keywords here
55
- def set_params(meta, custom_fields, options)
56
- self.set_metas(meta)
57
- self.set_field_values(custom_fields)
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
- private
62
- def before_validating
63
- #self.slug = self.title if self.slug.blank?
64
- #self.slug = self.slug.to_s.parameterize
65
- end
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
- # do all before actions to save the content
68
- def before_saved
69
- self.title = "Untitled" unless self.title.present?
70
- 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
71
- end
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
- # destroy all dependencies of this content
74
- # unassign this items from menus
75
- def destroy_dependencies
76
- in_nav_menu_items.destroy_all
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 :posts, ->{ order("#{CamaleonCms::Post.table_name}.id DESC") }, :class_name => "CamaleonCms::Post", foreign_key: :objectid, inverse_of: :post_relationships, dependent: :destroy
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
- class CamaleonCms::PostTag < CamaleonCms::TermTaxonomy
2
- default_scope { where(taxonomy: :post_tag) }
3
- cama_define_common_relationships('PostTag')
4
- has_many :posts, foreign_key: :objectid, through: :term_relationships, :source => :objects
5
- belongs_to :post_type, class_name: "CamaleonCms::PostType", foreign_key: :parent_id, inverse_of: :post_tags
6
- belongs_to :owner, class_name: CamaManager.get_user_class_name, foreign_key: :user_id
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
- class CamaleonCms::PostType < CamaleonCms::TermTaxonomy
2
- alias_attribute :site_id, :parent_id
3
- default_scope { where(taxonomy: :post_type) }
4
- cama_define_common_relationships('PostType')
5
- has_many :categories, :class_name => "CamaleonCms::Category", foreign_key: :parent_id, dependent: :destroy, inverse_of: :post_type_parent
6
- has_many :post_tags, :class_name => "CamaleonCms::PostTag", foreign_key: :parent_id, dependent: :destroy, inverse_of: :post_type
7
- has_many :posts, class_name: "CamaleonCms::Post", foreign_key: :taxonomy_id, dependent: :destroy, inverse_of: :post_type
8
- has_many :comments, through: :posts
9
- has_many :posts_through_categories, foreign_key: :objectid, through: :term_relationships, :source => :objects
10
- has_many :posts_draft, class_name: "CamaleonCms::Post", foreign_key: :taxonomy_id, dependent: :destroy, source: :drafts, inverse_of: :post_type
11
- has_many :field_group_taxonomy, -> {where("object_class LIKE ?","PostType_%")}, :class_name => "CamaleonCms::CustomField", foreign_key: :objectid, dependent: :destroy
12
-
13
- belongs_to :owner, class_name: CamaManager.get_user_class_name, foreign_key: :user_id
14
- belongs_to :site, :class_name => "CamaleonCms::Site", foreign_key: :parent_id
15
-
16
- scope :visible_menu, -> {where(term_group: nil)}
17
- scope :hidden_menu, -> {where(term_group: -1)}
18
- before_destroy :destroy_field_groups
19
- after_create :set_default_site_user_roles
20
- after_create :refresh_routes
21
- after_destroy :refresh_routes
22
- after_update :check_refresh_routes
23
- before_update :default_category
24
-
25
- # check if current post type manage categories
26
- def manage_categories?
27
- options[:has_category] || options[:has_single_category]
28
- end
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
- # hide or show this post type on admin -> contents -> menu
31
- # true => enable, false => disable
32
- def toggle_show_for_admin_menu(flag)
33
- self.update(term_group: flag == true ? nil : -1)
34
- end
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
- # check if this post type is shown on admin -> contents -> menu
37
- def show_for_admin_menu?
38
- self.term_group == nil
39
- end
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
- # check if this post type manage post tags
42
- def manage_tags?
43
- options[:has_tags]
44
- end
43
+ # check if this post type manage post tags
44
+ def manage_tags?
45
+ options[:has_tags]
46
+ end
45
47
 
46
- # check if this post type permit to manage seo attrs in posts
47
- def manage_seo?
48
- get_option('has_seo', get_option('has_keywords', true))
49
- end
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
- # assign settings for this post type
52
- # default values: {
53
- # has_category: false,
54
- # has_tags: false,
55
- # has_summary: true,
56
- # has_content: true,
57
- # has_comments: false,
58
- # has_picture: true,
59
- # has_template: true,
60
- # has_seo: true,
61
- # not_deleted: false,
62
- # has_layout: false,
63
- # default_layout: '',
64
- # contents_route_format: 'post'
65
- # }
66
- def set_settings(settings = {})
67
- settings.each do |key, val|
68
- self.set_option(key, val)
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
- # set or update a setting for this post type
73
- def set_setting(key, value)
74
- self.set_option(key, value)
75
- end
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
- # select full_categories for the post type, include all children categories
78
- def full_categories
79
- CamaleonCms::Category.where(site_id: site_id, post_type_id: id)
80
- end
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
- # return default category for this post type
83
- # only return a category for post types that manage categories
84
- def default_category
85
- if manage_categories?
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
- # add a post for current model
96
- # title: title for post, => required
97
- # content: html text content, => required
98
- # thumb: image url, => default (empty). check http://camaleon.tuzitio.com/api-methods.html#section_fileuploads
99
- # categories: [1,3,4,5], => default (empty)
100
- # tags: String comma separated, => default (empty)
101
- # slug: string key for post, => default (empty)
102
- # summary: String resume (optional) => default (empty)
103
- # post_order: Integer to define the order position in the list (optional)
104
- # fields: Hash of values for custom fields, sample => fields: {subtitle: 'abc', icon: 'test' } (optional)
105
- # settings: Hash of post settings, sample => settings:
106
- # {has_content: false, has_summary: true, default_layout: 'my_layout', default_template: 'my_template' } (optional, see more in post.set_setting(...))
107
- # data_metas: {template: "", layout: ""}
108
- # 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'})
109
- # More samples here: https://gist.github.com/owen2345/eba9691585ed78ad6f7b52e9591357bf
110
- # return created post if it was created, else return errors
111
- def add_post(args)
112
- _fields = args.delete(:fields)
113
- _settings = args.delete(:settings)
114
- _summary = args.delete(:summary)
115
- _order_position = args.delete(:order_position)
116
- args[:data_categories] = _categories = args.delete(:categories)
117
- args[:data_tags] = args.delete(:tags)
118
- _thumb = args.delete(:thumb)
119
- p = self.posts.new(args)
120
- p.slug = self.site.get_valid_post_slug(p.title.parameterize) unless p.slug.present?
121
- if p.save!
122
- _settings.each{ |k, v| p.set_setting(k, v) } if _settings.present?
123
- p.set_position(_order_position) if _order_position.present?
124
- p.set_summary(_summary) if _summary.present?
125
- p.set_thumb(_thumb) if _thumb.present?
126
- _fields.each{ |k, v| p.save_field_value(k, v) } if _fields.present?
127
- return p.decorate
128
- else
129
- p.errors
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
- # return all available route formats of this post type for content posts
134
- def contents_route_formats
135
- {
136
- "post_of_post_type" => "<code>/group/:post_type_id-:title/:slug</code><br> (Sample: http://localhost.com/group/17-services/myservice.html)",
137
- "post_of_category" => "<code>/category/:category_id-:title/:slug</code><br> (Sample: http://localhost.com/category/17-services/myservice.html)",
138
- "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)",
139
- "post_of_posttype" => "<code>/:post_type_title/:slug</code><br> (Sample: http://localhost.com/services/myservice.html)",
140
- "post" => "<code>/:slug</code><br> (Sample: http://localhost.com/myservice.html)",
141
- "hierarchy_post" => "<code>/:parent1_slug/:parent2_slug/.../:slug</code><br> (Sample: http://localhost.com/item-1/item-1-1/item-111.html)"
142
- }
143
- end
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
- # return the configuration of routes for post contents
146
- def contents_route_format
147
- get_option("contents_route_format", "post")
148
- end
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
- # verify if this post_type support for page hierarchy (parents)
151
- def manage_hierarchy?
152
- get_option('has_parent_structure', false)
153
- end
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
- private
156
- # skip save_metas_options callback after save changes (inherit from taxonomy) to call from here manually
157
- def save_metas_options_skip
158
- true
159
- end
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
- # assign default roles for this post type
162
- # define default settings for this post type
163
- def set_default_site_user_roles
164
- self.set_multiple_options({has_category: false, has_tags: false, has_summary: true, has_content: true, has_comments: false, has_picture: true, has_template: true, has_seo: true, not_deleted: false, has_layout: false, default_layout: ""}.merge(PluginRoutes.fixActionParameter(data_options||{}).to_sym))
165
- self.site.set_default_user_roles(self)
166
- default_category
167
- end
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
- # destroy all custom field groups assigned to this post type
170
- def destroy_field_groups
171
- unless self.destroyed_by_association.present?
172
- if self.slug == "post" || self.slug == "page"
173
- errors.add(:base, "This post type can not be deleted.")
174
- return false
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
- # reload routes to enable this post type url, like: http://localhost/my-slug
181
- def refresh_routes
182
- PluginRoutes.reload unless self.destroyed_by_association.present?
183
- end
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
- # check if slug was changed
186
- def check_refresh_routes
187
- refresh_routes if cama_attr_changed?(:slug)
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