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,4 +1,6 @@
1
- class CamaleonCms::Meta < ActiveRecord::Base
2
- self.table_name = "#{PluginRoutes.static_system_info["db_prefix"]}metas"
3
- # attr_accessible :objectid, :key, :value, :object_class
1
+ module CamaleonCms
2
+ class Meta < ActiveRecord::Base
3
+ self.table_name = "#{PluginRoutes.static_system_info["db_prefix"]}metas"
4
+ # attr_accessible :objectid, :key, :value, :object_class
5
+ end
4
6
  end
@@ -1,29 +1,32 @@
1
- class CamaleonCms::NavMenu < CamaleonCms::TermTaxonomy
2
- default_scope { where(taxonomy: :nav_menu).order(id: :asc) }
3
- alias_attribute :site_id, :parent_id
4
- cama_define_common_relationships('NavMenu')
5
- has_many :children, class_name: "CamaleonCms::NavMenuItem", foreign_key: :parent_id, dependent: :destroy, inverse_of: :parent
6
- belongs_to :site, :class_name => "CamaleonCms::Site", foreign_key: :parent_id, inverse_of: :nav_menus
1
+ module CamaleonCms
2
+ class NavMenu < CamaleonCms::TermTaxonomy
3
+ default_scope { where(taxonomy: :nav_menu).order(id: :asc) }
4
+ alias_attribute :site_id, :parent_id
7
5
 
8
- # add menu item for current menu
9
- # value: (Hash) is a hash object that contains label, type, link
10
- # options for type: post | category | post_type | post_tag | external
11
- # sample: {label: "my label", type: "external", link: "http://camaleon.tuzitio.com", target: '_blank'}
12
- # sample: {label: "my label", type: "post", link: 10}
13
- # sample: {label: "my label", type: "category", link: 12}
14
- # return item created
15
- def append_menu_item (value)
16
- item = children.create!({name: value[:label], url: value[:link], kind: value[:type], target: value[:target]})
17
- item
18
- end
6
+ cama_define_common_relationships('NavMenu')
7
+ has_many :children, class_name: "CamaleonCms::NavMenuItem", foreign_key: :parent_id, dependent: :destroy, inverse_of: :parent
8
+ belongs_to :site, foreign_key: :parent_id, inverse_of: :nav_menus
19
9
 
20
- # skip uniq slug validation
21
- def skip_slug_validation?
22
- true
23
- end
10
+ # add menu item for current menu
11
+ # value: (Hash) is a hash object that contains label, type, link
12
+ # options for type: post | category | post_type | post_tag | external
13
+ # sample: {label: "my label", type: "external", link: "http://camaleon.tuzitio.com", target: '_blank'}
14
+ # sample: {label: "my label", type: "post", link: 10}
15
+ # sample: {label: "my label", type: "category", link: 12}
16
+ # return item created
17
+ def append_menu_item (value)
18
+ item = children.create!({name: value[:label], url: value[:link], kind: value[:type], target: value[:target]})
19
+ item
20
+ end
21
+
22
+ # skip uniq slug validation
23
+ def skip_slug_validation?
24
+ true
25
+ end
24
26
 
25
- private
26
- # overwrite termtaxonomy method
27
- def destroy_dependencies
27
+ private
28
+ # overwrite termtaxonomy method
29
+ def destroy_dependencies
30
+ end
28
31
  end
29
32
  end
@@ -1,64 +1,68 @@
1
- class CamaleonCms::NavMenuItem < CamaleonCms::TermTaxonomy
2
- alias_attribute :site_id, :term_group
3
- alias_attribute :label, :name
4
- alias_attribute :url, :description
5
- alias_attribute :kind, :slug
6
- alias_attribute :target, :status
7
- # attr_accessible :label, :url, :kind
8
- default_scope { where(taxonomy: :nav_menu_item).order(id: :asc) }
9
- cama_define_common_relationships('NavMenuItem')
10
- belongs_to :parent, class_name: "CamaleonCms::NavMenu", inverse_of: :children
11
- belongs_to :parent_item, class_name: "CamaleonCms::NavMenuItem", foreign_key: :parent_id, inverse_of: :children
12
- has_many :children, class_name: "CamaleonCms::NavMenuItem", foreign_key: :parent_id, dependent: :destroy, inverse_of: :parent_item
1
+ module CamaleonCms
2
+ class NavMenuItem < CamaleonCms::TermTaxonomy
3
+ alias_attribute :site_id, :term_group
4
+ alias_attribute :label, :name
5
+ alias_attribute :url, :description
6
+ alias_attribute :kind, :slug
7
+ alias_attribute :target, :status
8
+ # attr_accessible :label, :url, :kind
9
+ #
10
+ default_scope { where(taxonomy: :nav_menu_item).order(id: :asc) }
13
11
 
14
- before_create :set_parent_site
15
- after_create :update_count
16
- #before_destroy :update_count
12
+ cama_define_common_relationships('NavMenuItem')
13
+ belongs_to :parent, class_name: "CamaleonCms::NavMenu", inverse_of: :children
14
+ belongs_to :parent_item, class_name: "CamaleonCms::NavMenuItem", foreign_key: :parent_id, inverse_of: :children
15
+ has_many :children, class_name: "CamaleonCms::NavMenuItem", foreign_key: :parent_id, dependent: :destroy, inverse_of: :parent_item
17
16
 
18
- # return the main menu
19
- def main_menu
20
- main_menu = self.parent
21
- return main_menu if main_menu.present?
22
- parent_menu = self.parent_item
23
- parent_menu.main_menu if parent_menu.present?
24
- end
17
+ before_create :set_parent_site
18
+ after_create :update_count
19
+ #before_destroy :update_count
25
20
 
26
- # check if this menu have children
27
- def have_children?
28
- self.children.count != 0
29
- end
21
+ # return the main menu
22
+ def main_menu
23
+ return parent if parent
30
24
 
31
- # add sub menu for a menu item
32
- # same values of NavMenu#append_menu_item
33
- # return item created
34
- def append_menu_item(value)
35
- children.create({name: value[:label], url: value[:link], kind: value[:type], target: value[:target]})
36
- end
25
+ parent_item.main_menu if parent_item
26
+ end
37
27
 
38
- # update current menu
39
- # value: same as append_menu_item (label, link, target)
40
- def update_menu_item(value)
41
- self.update({name: value[:label], url: value[:link], target: value[:target]})
42
- end
28
+ # check if this menu have children
29
+ def have_children?
30
+ self.children.count != 0
31
+ end
43
32
 
44
- # overwrite skip uniq slug validation
45
- def skip_slug_validation?; true end
46
- def before_validating; end
33
+ # add sub menu for a menu item
34
+ # same values of NavMenu#append_menu_item
35
+ # return item created
36
+ def append_menu_item(value)
37
+ children.create({name: value[:label], url: value[:link], kind: value[:type], target: value[:target]})
38
+ end
47
39
 
48
- private
49
- def update_count
50
- self.parent.update_column('count', self.parent.children.size) if self.parent.present?
51
- self.parent_item.update_column('count', self.parent_item.children.size) if self.parent_item.present?
52
- self.update_column(:term_group, main_menu.parent_id)
53
- self.update_column(:term_order, CamaleonCms::NavMenuItem.where(parent_id: self.parent_id).count) # update position
54
- end
40
+ # update current menu
41
+ # value: same as append_menu_item (label, link, target)
42
+ def update_menu_item(value)
43
+ self.update({name: value[:label], url: value[:link], target: value[:target]})
44
+ end
55
45
 
56
- # fast access from site to menu items
57
- def set_parent_site
58
- self.site_id = self.parent_item.site_id if self.parent_item.present?
59
- self.site_id = self.parent.site_id if self.parent.present?
60
- end
46
+ # overwrite skip uniq slug validation
47
+ def skip_slug_validation?; true end
48
+ def before_validating; end
49
+
50
+ private
51
+
52
+ def update_count
53
+ self.parent.update_column('count', parent.children.size) if parent
54
+ self.parent_item.update_column('count', parent_item.children.size) if parent_item
55
+ self.update_column(:term_group, main_menu.parent_id)
56
+ self.update_column(:term_order, CamaleonCms::NavMenuItem.where(parent_id: parent_id).count) # update position
57
+ end
61
58
 
62
- # overwrite inherit method
63
- def destroy_dependencies; end
59
+ # fast access from site to menu items
60
+ def set_parent_site
61
+ self.site_id = parent_item.site_id if parent_item
62
+ self.site_id = parent.site_id if parent
63
+ end
64
+
65
+ # overwrite inherit method
66
+ def destroy_dependencies; end
67
+ end
64
68
  end
@@ -1,76 +1,78 @@
1
- class CamaleonCms::Plugin < CamaleonCms::TermTaxonomy
2
- # attrs:
3
- # term_group => status active (1, nil)
4
- # slug => plugin key
5
- # name => plugin name
1
+ module CamaleonCms
2
+ class Plugin < CamaleonCms::TermTaxonomy
3
+ # attrs:
4
+ # term_group => status active (1, nil)
5
+ # slug => plugin key
6
+ # name => plugin name
6
7
 
7
- attr_accessor :error
8
- cama_define_common_relationships('Plugin')
9
- belongs_to :site, class_name: "CamaleonCms::Site", foreign_key: :parent_id
8
+ attr_accessor :error
9
+ cama_define_common_relationships('Plugin')
10
+ belongs_to :site, foreign_key: :parent_id
10
11
 
11
- default_scope { where(taxonomy: :plugin) }
12
- scope :active, -> { where(term_group: 1) }
12
+ default_scope { where(taxonomy: :plugin) }
13
+ scope :active, -> { where(term_group: 1) }
13
14
 
14
- before_validation :set_default
15
- before_destroy :destroy_custom_fields
15
+ before_validation :set_default
16
+ before_destroy :destroy_custom_fields
16
17
 
17
- # active the plugin
18
- def active
19
- self.term_group = 1
20
- self.save
21
- end
18
+ # active the plugin
19
+ def active
20
+ self.term_group = 1
21
+ self.save
22
+ end
22
23
 
23
- # inactive the plugin
24
- def inactive
25
- self.term_group = nil
26
- self.save
27
- end
24
+ # inactive the plugin
25
+ def inactive
26
+ self.term_group = nil
27
+ self.save
28
+ end
28
29
 
29
- # check if plugin is active
30
- def active?
31
- self.term_group.to_s == "1"
32
- end
30
+ # check if plugin is active
31
+ def active?
32
+ self.term_group.to_s == "1"
33
+ end
33
34
 
34
- # return theme settings configured in config.json
35
- def settings
36
- PluginRoutes.plugin_info(self.slug)
37
- end
35
+ # return theme settings configured in config.json
36
+ def settings
37
+ PluginRoutes.plugin_info(slug)
38
+ end
38
39
 
39
- # check if current installation version is older
40
- # return boolean
41
- def old_version?
42
- # self.installed_version.to_s != self.settings["version"].to_s
43
- false
44
- end
40
+ # check if current installation version is older
41
+ # return boolean
42
+ def old_version?
43
+ # self.installed_version.to_s != self.settings["version"].to_s
44
+ false
45
+ end
45
46
 
46
- # set a new installation version for this plugin
47
- def installed_version=(version)
48
- self.set_option("version_installed", version)
49
- end
47
+ # set a new installation version for this plugin
48
+ def installed_version=(version)
49
+ self.set_option("version_installed", version)
50
+ end
51
+
52
+ # return gem installed version
53
+ def installed_version
54
+ return ""
50
55
 
51
- # return gem installed version
52
- def installed_version
53
- return ""
54
- res = self.get_option("version_installed")
55
- unless res.present? # fix for old installations
56
- res = self.settings["version"]
57
- self.installed_version= res
56
+ res = get_option("version_installed")
57
+ unless res.present? # fix for old installations
58
+ res = self.settings["version"]
59
+ self.installed_version = res
60
+ end
61
+ res
58
62
  end
59
- res
60
- end
61
63
 
62
- # return the title of this plugin
63
- def title
64
- PluginRoutes.plugin_info(self.slug)["title"]
65
- end
64
+ # return the title of this plugin
65
+ def title
66
+ PluginRoutes.plugin_info(slug)["title"]
67
+ end
66
68
 
67
- private
68
- def set_default
69
- self.name = self.slug unless self.name.present?
70
- end
69
+ private
70
+ def set_default
71
+ self.name = slug unless name.present?
72
+ end
71
73
 
72
- def destroy_custom_fields
73
- self.get_field_groups.destroy_all
74
+ def destroy_custom_fields
75
+ self.get_field_groups.destroy_all
76
+ end
74
77
  end
75
-
76
78
  end
@@ -1,265 +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, status: [:draft, :draft_child, :trash])
10
- if posts.size > 0
11
- if slug_array.size > 1
12
- 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(", ")} "
13
- else
14
- record.errors[:base] << "#{I18n.t('camaleon_cms.admin.post.message.requires_different_slug')}: #{record.slug.to_s} "
15
- 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
16
49
  end
17
-
18
- # avoid recursive page parent
19
- 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)
20
- else
21
- # validation for other classes
50
+ res
22
51
  end
23
52
  end
24
- end
25
- end
26
53
 
27
- class CamaleonCms::Post < CamaleonCms::PostDefault
28
- include CamaleonCms::CategoriesTagsForPosts
29
- alias_attribute :post_type_id, :taxonomy_id
30
- default_scope ->{ where(post_class: "Post").order(post_order: :asc, created_at: :desc) }
31
- cama_define_common_relationships('Post')
32
-
33
- # DEPRECATED
34
- has_many :post_relationships, class_name: "CamaleonCms::PostRelationship", foreign_key: :objectid, dependent: :destroy, inverse_of: :posts
35
- has_many :post_types, class_name: "CamaleonCms::PostType", through: :post_relationships, :source => :post_type
36
- # END DEPRECATED
37
-
38
- has_many :term_relationships, class_name: "CamaleonCms::TermRelationship", foreign_key: :objectid, dependent: :destroy, inverse_of: :objects
39
- has_many :categories, class_name: "CamaleonCms::Category", through: :term_relationships, :source => :term_taxonomies
40
- has_many :post_tags, class_name: "CamaleonCms::PostTag", through: :term_relationships, :source => :term_taxonomies
41
- has_many :comments, class_name: "CamaleonCms::PostComment", foreign_key: :post_id, dependent: :destroy
42
- has_many :drafts, ->{where(status: 'draft_child')}, class_name: "CamaleonCms::Post", foreign_key: :post_parent, dependent: :destroy
43
- has_many :children, class_name: "CamaleonCms::Post", foreign_key: :post_parent, dependent: :destroy, primary_key: :id
44
-
45
- belongs_to :owner, class_name: CamaManager.get_user_class_name, foreign_key: :user_id
46
- belongs_to :parent, class_name: "CamaleonCms::Post", foreign_key: :post_parent
47
- belongs_to :post_type, class_name: "CamaleonCms::PostType", foreign_key: :taxonomy_id, inverse_of: :posts
48
-
49
- scope :visible_frontend, -> {where(status: 'published')}
50
- scope :public_posts, -> {visible_frontend.where(visibility: ['public', ""]) } #public posts (not passwords, not privates)
51
- scope :private_posts, -> {where(visibility: 'private') } #public posts (not passwords, not privates)
52
-
53
- scope :trash, -> {where(status: 'trash')}
54
- scope :no_trash, -> {where.not(status: 'trash')}
55
- scope :published, -> {where(status: 'published')}
56
- scope :root_posts, -> {where(post_parent: [nil, ''])}
57
- scope :drafts, -> {where(status: %w(draft draft_child))}
58
- scope :pending, -> {where(status: 'pending')}
59
- scope :latest, -> {reorder(created_at: :desc)}
60
-
61
- validates_with CamaleonCms::PostUniqValidator
62
- attr_accessor :show_title_with_parent
63
- before_create :fix_post_order, if: lambda{|p| !p.post_order.present? || p.post_order == 0 }
64
-
65
- # return all parents for current page hierarchy ordered bottom to top
66
- def parents
67
- cama_fetch_cache("parents_#{self.id}") do
68
- res = []
69
- p = self.parent
70
- while p.present?
71
- res << p
72
- 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
73
60
  end
74
- res
75
61
  end
76
- end
77
62
 
78
- # return all children elements for current post (page hierarchy)
79
- def full_children
80
- cama_fetch_cache("full_children_#{self.id}") do
81
- res = self.children.to_a
82
- res.each{|c| res += c.full_children }
83
- res
63
+ # return the post type of this post (DEPRECATED)
64
+ def get_post_type_depre
65
+ post_types.reorder(nil).first
84
66
  end
85
- end
86
67
 
87
- # return the post type of this post (DEPRECATED)
88
- def get_post_type_depre
89
- post_types.reorder(nil).first
90
- end
68
+ # check if this post was published
69
+ def published?
70
+ status == 'published'
71
+ end
91
72
 
92
- # check if this post was published
93
- def published?
94
- status == 'published'
95
- end
73
+ # check if this is in pending status
74
+ def pending?
75
+ status == 'pending'
76
+ end
96
77
 
97
- # check if this is in pending status
98
- def pending?
99
- status == 'pending'
100
- end
78
+ # check if this is in draft status
79
+ def draft?
80
+ status == 'draft' || status == 'draft_child'
81
+ end
101
82
 
102
- # check if this is in draft status
103
- def draft?
104
- status == 'draft' || status == 'draft_child'
105
- end
83
+ def draft_child?
84
+ status == 'draft_child'
85
+ end
106
86
 
107
- def draft_child?
108
- status == 'draft_child'
109
- end
87
+ # check if this is in trash status
88
+ def trash?
89
+ status == 'trash'
90
+ end
110
91
 
111
- # check if this is in trash status
112
- def trash?
113
- status == 'trash'
114
- 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
115
97
 
116
- # check if current post can manage content
117
- # return boolean
118
- def manage_content?(posttype = nil)
119
- get_option('has_content', (posttype || post_type).get_option('has_content', true))
120
- 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
121
102
 
122
- # return boolean
123
- def manage_layout?(posttype = nil)
124
- get_option('has_layout', (posttype || post_type).get_option('has_layout', false))
125
- 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
126
108
 
127
- # check if current post can manage template
128
- # return boolean
129
- def manage_template?(posttype = nil)
130
- get_option('has_template', (posttype || post_type).get_option('has_template', true))
131
- 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
132
114
 
133
- # check if current post can manage summary
134
- # return boolean
135
- def manage_summary?(posttype = nil)
136
- get_option('has_summary', (posttype || post_type).get_option('has_summary', true))
137
- 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
138
120
 
139
- # check if current post can manage picture
140
- # return boolean
141
- def manage_picture?(posttype = nil)
142
- get_option('has_picture', (posttype || post_type).get_option('has_picture', true))
143
- 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
144
126
 
145
- # check if current post can manage comments
146
- # return boolean
147
- def manage_comments?(posttype = nil)
148
- get_option('has_comments', (posttype || post_type).get_option('has_comments', false))
149
- 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
150
134
 
151
- # check if the post can be commented
152
- # sample: @post.can_commented?
153
- # return Boolean (true/false)
154
- # 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)
155
- def can_commented?
156
- manage_comments? && get_meta('has_comments').to_s == "1"
157
- 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
158
139
 
159
- # check if is required picture for current post
160
- def is_required_picture?
161
- post_type.get_option('is_required_picture', false)
162
- 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
163
156
 
164
- # define post configuration for current post
165
- # possible key values (String):
166
- # has_content, boolean (default true)
167
- # has_summary, boolean (default true)
168
- # has_seo, boolean (default true)
169
- # has_picture, boolean (default true)
170
- # has_template, boolean (default false)
171
- # has_comments, boolean (default false)
172
- # default_layout: (string) (default layout) # this is still used if post type was inactivated layout and overwritten by dropdown in post view
173
- # default_template: (string) (default template) # this is still used if post type was inactivated template and overwritten by dropdown in post view
174
- # has_layout: (boolean) (default false)
175
- # skip_fields: (array) (default empty) array of custom field keys to avoid for this post, sample: ["subtitle", "icon"]
176
- # val: value for the setting
177
- def set_setting(key, val)
178
- set_option(key, val)
179
- 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
180
163
 
181
- # assign multiple settings
182
- def set_settings(settings = {})
183
- settings.each do |key, val|
184
- 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)
185
169
  end
186
- end
187
170
 
188
- # put a new order position for this post
189
- # new_order_position: (Integer) position number
190
- # return nil
191
- def set_position(new_order_position)
192
- self.update_column("post_order", new_order_position)
193
- 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
194
176
 
195
- # save the summary for current post
196
- # summary: Text String without html
197
- def set_summary(summary)
198
- set_meta("summary", summary)
199
- 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?
200
184
 
201
- # check if current post permit manage seo attrs
202
- # has_keywords: used until next version (deprecated to use has_seo)
203
- # return boolean
204
- def manage_seo?(posttype = nil)
205
- get_option('has_seo', get_option('has_keywords', false)) || (posttype || post_type).manage_seo?
206
- end
207
- 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
208
190
 
209
- # save the thumbnail url for current post
210
- # thumb_url: String url
211
- def set_thumb(thumb_url)
212
- set_meta("thumb", thumb_url)
213
- 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
214
196
 
215
- # save the layout name to be used on render this post
216
- # layout_name: String layout name: my_layout.html.erb => 'my_layout'
217
- def set_layout(layout_name)
218
- set_meta("layout", layout_name)
219
- 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)
220
201
 
221
- # return the layout assigned to this post
222
- # post_type: post type owner of this post
223
- def get_layout(posttype = nil)
224
- return get_option("default_layout") if !manage_layout?(posttype)
225
- get_meta('layout', get_option("default_layout") || (posttype || self.post_type).get_option('default_layout', nil))
226
- end
202
+ get_meta('layout', get_option('default_layout') || (posttype || post_type).get_option('default_layout', nil))
203
+ end
227
204
 
228
- # return the template assigned to this post
229
- # verify default template defined in post type
230
- # post_type: post type owner of this post
231
- def get_template(posttype = nil)
232
- return get_option("default_template") if !manage_template?(posttype)
233
- get_meta('template', get_option("default_template") || (posttype || self.post_type).get_option('default_template', nil))
234
- 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)
235
210
 
236
- # increment the counter of visitors
237
- def increment_visits!
238
- set_meta("visits", total_visits+1)
239
- end
211
+ get_meta('template', get_option('default_template') || (posttype || post_type).get_option('default_template', nil))
212
+ end
240
213
 
241
- # return the quantity of visits for this post
242
- def total_visits
243
- get_meta("visits", 0).to_i
244
- end
214
+ # increment the counter of visitors
215
+ def increment_visits!
216
+ set_meta('visits', total_visits+1)
217
+ end
245
218
 
246
- # return the quantity of comments for this post
247
- # TODO comments count to move into cache counter
248
- def total_comments
249
- self.get_meta("comments_count", 0).to_i
250
- end
219
+ # return the quantity of visits for this post
220
+ def total_visits
221
+ get_meta('visits', 0).to_i
222
+ end
251
223
 
252
- # manage the custom decorators for posts
253
- # sample: my_post_type.set_option('cama_post_decorator_class', 'ProductDecorator')
254
- # Sample: https://github.com/owen2345/camaleon-ecommerce/tree/master/app/decorators/
255
- def decorator_class
256
- (post_type.get_option('cama_post_decorator_class', 'CamaleonCms::PostDecorator') rescue 'CamaleonCms::PostDecorator').constantize
257
- 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
258
229
 
259
- private
260
- # calculate a post order when it is empty
261
- def fix_post_order
262
- last_post = post_type.posts.where.not(id: nil).last
263
- 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
264
243
  end
265
244
  end