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.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/app/apps/plugins/front_cache/front_cache_helper.rb +1 -1
- data/app/assets/config/camaleon-cms.js +0 -1
- data/app/assets/images/camaleon_cms/language/md.png +0 -0
- data/app/assets/javascripts/camaleon_cms/bootstrap.min.js +4 -5
- data/app/assets/stylesheets/camaleon_cms/bootstrap.min.css +6 -0
- data/app/assets/{fonts/camaleon_cms → stylesheets/camaleon_cms/fonts}/glyphicons-halflings-regular.eot +0 -0
- data/app/assets/{fonts/camaleon_cms → stylesheets/camaleon_cms/fonts}/glyphicons-halflings-regular.svg +0 -0
- data/app/assets/{fonts/camaleon_cms → stylesheets/camaleon_cms/fonts}/glyphicons-halflings-regular.ttf +0 -0
- data/app/assets/{fonts/camaleon_cms → stylesheets/camaleon_cms/fonts}/glyphicons-halflings-regular.woff +0 -0
- data/app/assets/{fonts/camaleon_cms → stylesheets/camaleon_cms/fonts}/glyphicons-halflings-regular.woff2 +0 -0
- data/app/controllers/camaleon_cms/admin/sessions_controller.rb +1 -1
- data/app/controllers/camaleon_cms/frontend_controller.rb +4 -1
- data/app/helpers/camaleon_cms/admin/breadcrumb_helper.rb +1 -1
- data/app/helpers/camaleon_cms/camaleon_helper.rb +4 -4
- data/app/helpers/camaleon_cms/frontend/seo_helper.rb +2 -1
- data/app/helpers/camaleon_cms/frontend/site_helper.rb +1 -6
- data/app/helpers/camaleon_cms/short_code_helper.rb +3 -3
- data/app/helpers/camaleon_cms/uploader_helper.rb +3 -2
- 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 -226
- 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/models/concerns/camaleon_cms/user_methods.rb +1 -1
- data/app/validators/camaleon_cms/post_uniq_validator.rb +28 -0
- data/app/validators/camaleon_cms/uniq_validator.rb +9 -0
- data/app/views/camaleon_cms/shortcode_templates/widget.html.erb +1 -1
- data/config/initializers/assets.rb +1 -1
- data/config/initializers/non_digest_assets.rb +3 -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/config/routes/admin.rb +1 -1
- data/lib/camaleon_cms/version.rb +1 -1
- data/lib/generators/camaleon_cms/theme_template/views/layouts/index.html.erb +19 -16
- data/lib/plugin_routes.rb +1 -26
- data/spec/dummy/config/application.rb +15 -3
- data/spec/features/admin/not_found_spec.rb +10 -0
- metadata +132 -123
- data/app/assets/stylesheets/camaleon_cms/bootstrap.min.css.scss +0 -6799
- data/config/locales/camaleon_cms/admin/js.yml +0 -435
- data/config/locales/camaleon_cms/common.yml +0 -784
- 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 -233
- data/spec/dummy/log/test.log +0 -46368
- 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,4 +1,6 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
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
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
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
|
-
|
9
|
-
|
10
|
-
|
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
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
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
|
-
|
26
|
-
|
27
|
-
|
27
|
+
private
|
28
|
+
# overwrite termtaxonomy method
|
29
|
+
def destroy_dependencies
|
30
|
+
end
|
28
31
|
end
|
29
32
|
end
|
@@ -1,64 +1,68 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
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
|
-
|
15
|
-
|
16
|
-
|
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
|
-
|
19
|
-
|
20
|
-
|
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
|
-
|
27
|
-
|
28
|
-
|
29
|
-
end
|
21
|
+
# return the main menu
|
22
|
+
def main_menu
|
23
|
+
return parent if parent
|
30
24
|
|
31
|
-
|
32
|
-
|
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
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
end
|
28
|
+
# check if this menu have children
|
29
|
+
def have_children?
|
30
|
+
self.children.count != 0
|
31
|
+
end
|
43
32
|
|
44
|
-
|
45
|
-
|
46
|
-
|
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
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
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
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
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
|
-
|
63
|
-
|
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
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
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
|
-
|
8
|
-
|
9
|
-
|
8
|
+
attr_accessor :error
|
9
|
+
cama_define_common_relationships('Plugin')
|
10
|
+
belongs_to :site, foreign_key: :parent_id
|
10
11
|
|
11
|
-
|
12
|
-
|
12
|
+
default_scope { where(taxonomy: :plugin) }
|
13
|
+
scope :active, -> { where(term_group: 1) }
|
13
14
|
|
14
|
-
|
15
|
-
|
15
|
+
before_validation :set_default
|
16
|
+
before_destroy :destroy_custom_fields
|
16
17
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
18
|
+
# active the plugin
|
19
|
+
def active
|
20
|
+
self.term_group = 1
|
21
|
+
self.save
|
22
|
+
end
|
22
23
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
24
|
+
# inactive the plugin
|
25
|
+
def inactive
|
26
|
+
self.term_group = nil
|
27
|
+
self.save
|
28
|
+
end
|
28
29
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
30
|
+
# check if plugin is active
|
31
|
+
def active?
|
32
|
+
self.term_group.to_s == "1"
|
33
|
+
end
|
33
34
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
35
|
+
# return theme settings configured in config.json
|
36
|
+
def settings
|
37
|
+
PluginRoutes.plugin_info(slug)
|
38
|
+
end
|
38
39
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
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
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
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
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
res
|
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
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
64
|
+
# return the title of this plugin
|
65
|
+
def title
|
66
|
+
PluginRoutes.plugin_info(slug)["title"]
|
67
|
+
end
|
66
68
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
69
|
+
private
|
70
|
+
def set_default
|
71
|
+
self.name = slug unless name.present?
|
72
|
+
end
|
71
73
|
|
72
|
-
|
73
|
-
|
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
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
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
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
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
|
-
|
79
|
-
|
80
|
-
|
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
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
68
|
+
# check if this post was published
|
69
|
+
def published?
|
70
|
+
status == 'published'
|
71
|
+
end
|
91
72
|
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
73
|
+
# check if this is in pending status
|
74
|
+
def pending?
|
75
|
+
status == 'pending'
|
76
|
+
end
|
96
77
|
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
78
|
+
# check if this is in draft status
|
79
|
+
def draft?
|
80
|
+
status == 'draft' || status == 'draft_child'
|
81
|
+
end
|
101
82
|
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
end
|
83
|
+
def draft_child?
|
84
|
+
status == 'draft_child'
|
85
|
+
end
|
106
86
|
|
107
|
-
|
108
|
-
|
109
|
-
|
87
|
+
# check if this is in trash status
|
88
|
+
def trash?
|
89
|
+
status == 'trash'
|
90
|
+
end
|
110
91
|
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
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
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
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
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
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
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
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
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
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
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
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
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
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
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
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
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
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
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
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
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
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
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
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
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
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
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
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
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
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
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
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
|
-
|
222
|
-
|
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
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
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
|
-
|
237
|
-
|
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
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
214
|
+
# increment the counter of visitors
|
215
|
+
def increment_visits!
|
216
|
+
set_meta('visits', total_visits+1)
|
217
|
+
end
|
245
218
|
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
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
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
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
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
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
|