camaleon_cms 2.1.2.0 → 2.1.2.1
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/assets/javascripts/camaleon_cms/admin/_custom_fields.js +5 -3
- data/app/assets/javascripts/camaleon_cms/admin/_libraries.js +2 -0
- data/app/assets/javascripts/camaleon_cms/admin/_post.js +4 -14
- data/app/assets/javascripts/camaleon_cms/admin/jquery.validate.js +1 -1
- data/app/assets/javascripts/camaleon_cms/admin/nav_menu.js.coffee +1 -1
- data/app/assets/javascripts/camaleon_cms/admin/uploader/_media_manager.js.coffee +5 -5
- data/app/controllers/camaleon_cms/admin/appearances/nav_menus_controller.rb +1 -1
- data/app/controllers/camaleon_cms/admin/categories_controller.rb +2 -2
- data/app/controllers/camaleon_cms/admin/media_controller.rb +4 -2
- data/app/controllers/camaleon_cms/admin/plugins_controller.rb +4 -0
- data/app/controllers/camaleon_cms/admin/post_tags_controller.rb +2 -2
- data/app/controllers/camaleon_cms/admin/posts_controller.rb +2 -2
- data/app/controllers/camaleon_cms/admin/sessions_controller.rb +0 -5
- data/app/controllers/camaleon_cms/admin/settings_controller.rb +3 -1
- data/app/controllers/camaleon_cms/admin/users_controller.rb +2 -2
- data/app/controllers/camaleon_cms/apps/plugins_front_controller.rb +3 -1
- data/app/controllers/camaleon_cms/apps/themes_front_controller.rb +4 -1
- data/app/controllers/camaleon_cms/frontend_controller.rb +11 -3
- data/app/decorators/camaleon_cms/custom_fields_concern.rb +24 -0
- data/app/decorators/camaleon_cms/post_decorator.rb +11 -0
- data/app/helpers/camaleon_cms/admin/custom_fields_helper.rb +1 -1
- data/app/helpers/camaleon_cms/frontend/nav_menu_helper.rb +45 -2
- data/app/helpers/camaleon_cms/session_helper.rb +3 -6
- data/app/helpers/camaleon_cms/uploader_helper.rb +23 -7
- data/app/models/camaleon_cms/category.rb +5 -5
- data/app/models/camaleon_cms/custom_field_group.rb +2 -1
- data/app/models/camaleon_cms/nav_menu.rb +3 -2
- data/app/models/camaleon_cms/nav_menu_item.rb +10 -3
- data/app/models/camaleon_cms/post.rb +10 -2
- data/app/models/camaleon_cms/post_default.rb +4 -9
- data/app/models/camaleon_cms/post_tag.rb +1 -1
- data/app/models/camaleon_cms/post_type.rb +6 -5
- data/app/models/camaleon_cms/site.rb +2 -2
- data/app/models/camaleon_cms/term_taxonomy.rb +0 -10
- data/app/models/camaleon_cms/user.rb +2 -10
- data/app/models/concerns/camaleon_cms/custom_fields_read.rb +17 -9
- data/app/models/concerns/camaleon_cms/metas.rb +8 -0
- data/app/uploaders/camaleon_cms_uploader.rb +6 -4
- data/app/views/camaleon_cms/_flash_messages.html.erb +9 -5
- data/app/views/camaleon_cms/admin/appearances/nav_menus/_menu_items.html.erb +1 -1
- data/app/views/camaleon_cms/admin/appearances/nav_menus/_menu_items_list.html.erb +1 -1
- data/app/views/camaleon_cms/admin/categories/_form.html.erb +1 -9
- data/app/views/camaleon_cms/admin/media/index.html.erb +1 -1
- data/app/views/camaleon_cms/admin/posts/_sidebar.html.erb +8 -2
- data/app/views/camaleon_cms/admin/sessions/register.html.erb +2 -2
- data/app/views/camaleon_cms/admin/settings/custom_fields/fields/_field_attrs.html.erb +2 -2
- data/app/views/camaleon_cms/admin/settings/custom_fields/fields/_image.html.erb +2 -2
- data/app/views/camaleon_cms/admin/settings/custom_fields/index.html.erb +1 -1
- data/app/views/camaleon_cms/admin/settings/post_types/_form.html.erb +4 -0
- data/app/views/camaleon_cms/admin/settings/site.html.erb +2 -2
- data/app/views/camaleon_cms/admin/users/form.html.erb +3 -16
- data/app/views/camaleon_cms/default_theme/partials/_categories_list.html.erb +1 -1
- data/app/views/camaleon_cms/default_theme/partials/_comments.html.erb +2 -2
- data/app/views/camaleon_cms/default_theme/partials/_comments_list2.html.erb +24 -0
- data/app/views/camaleon_cms/default_theme/partials/_sidebar.html.erb +40 -20
- data/app/views/camaleon_cms/default_theme/post_type.html.erb +1 -2
- data/config/initializers/active_record_extension.rb +5 -5
- data/config/locales/camaleon_cms/admin/es.yml +2 -0
- data/config/locales/camaleon_cms/common.yml +1 -0
- data/db/migrate/20160504155652_add_feature_to_posts.rb +5 -0
- data/db/migrate/20160504155653_move_first_name_of_users.rb +9 -0
- data/lib/camaleon_cms/version.rb +1 -1
- data/lib/ext/string.rb +11 -1
- data/lib/generators/camaleon_cms/theme_template/app/apps/themes/my_theme/main_helper.rb +10 -7
- metadata +6 -2
@@ -275,7 +275,7 @@ module CamaleonCms::Admin::CustomFieldsHelper
|
|
275
275
|
]
|
276
276
|
}
|
277
277
|
# evaluate the content of command value on listing
|
278
|
-
# sample:
|
278
|
+
# sample command: options_from_collection_for_select(current_site.the_posts("commerce").decorate, :id, :the_title)
|
279
279
|
items[:select_eval] = {
|
280
280
|
key: 'select_eval',
|
281
281
|
label: t('camaleon_cms.admin.custom_field.fields.select_eval'),
|
@@ -59,7 +59,7 @@ module CamaleonCms::Frontend::NavMenuHelper
|
|
59
59
|
nav_menu = current_site.nav_menus.first unless nav_menu.present?
|
60
60
|
html = "<#{args[:container]} class='#{args[:container_class]}' id='#{args[:container_id]}'>#{args[:container_prepend]}{__}#{args[:container_append]}</#{args[:container]}>"
|
61
61
|
if nav_menu.present?
|
62
|
-
html = html.sub("{__}", cama_menu_draw_items(args, nav_menu.children))
|
62
|
+
html = html.sub("{__}", cama_menu_draw_items(args, nav_menu.children.reorder(:term_order)))
|
63
63
|
else
|
64
64
|
html = html.sub("{__}", "")
|
65
65
|
end
|
@@ -91,7 +91,7 @@ module CamaleonCms::Frontend::NavMenuHelper
|
|
91
91
|
_args = r[:settings]
|
92
92
|
|
93
93
|
if has_children
|
94
|
-
html_children, current_children = cama_menu_draw_items(args, nav_menu_item.children, level + 1)
|
94
|
+
html_children, current_children = cama_menu_draw_items(args, nav_menu_item.children.reorder(:term_order), level + 1)
|
95
95
|
else
|
96
96
|
html_children, current_children = "", false
|
97
97
|
end
|
@@ -112,6 +112,49 @@ module CamaleonCms::Frontend::NavMenuHelper
|
|
112
112
|
end
|
113
113
|
end
|
114
114
|
|
115
|
+
# filter and parse all menu items visible for current user and adding the flag for current_parent or current_item
|
116
|
+
# max_levels: max levels to iterate
|
117
|
+
# return an multidimensional array with all items until level 'max_levels'
|
118
|
+
# internal_level: ingnore (managed by internal recursion)
|
119
|
+
def cama_menu_parse_items(items, max_levels=-1, internal_level=0)
|
120
|
+
res, is_current_parent, levels = [], false, [0]
|
121
|
+
items.each_with_index do |nav_menu_item, index|
|
122
|
+
data_nav_item = _get_link_nav_menu(nav_menu_item)
|
123
|
+
next if data_nav_item == false
|
124
|
+
_is_current = data_nav_item[:current] || site_current_path == data_nav_item[:link] || site_current_path == data_nav_item[:link].sub(".html", "")
|
125
|
+
has_children = nav_menu_item.have_children?
|
126
|
+
has_children = false if max_levels > 0 && max_levels == internal_level
|
127
|
+
data_nav_item[:label] = data_nav_item[:name]
|
128
|
+
data_nav_item[:url] = data_nav_item[:link]
|
129
|
+
r = {
|
130
|
+
menu_item: nav_menu_item.decorate,
|
131
|
+
level: internal_level,
|
132
|
+
has_children: has_children,
|
133
|
+
index: index,
|
134
|
+
current_item: _is_current,
|
135
|
+
current_parent: false,
|
136
|
+
levels: 0
|
137
|
+
}.merge(data_nav_item.except(:current, :name, :link))
|
138
|
+
|
139
|
+
if has_children
|
140
|
+
r[:children], _is_current_parent, r[:levels] = cama_menu_parse_items(nav_menu_item.children.reorder(:term_order), max_levels, internal_level + 1)
|
141
|
+
if _is_current_parent
|
142
|
+
is_current_parent = true
|
143
|
+
r[:current_parent] = true
|
144
|
+
end
|
145
|
+
r[:levels] = r[:levels] + 1
|
146
|
+
end
|
147
|
+
levels << r[:levels]
|
148
|
+
res << r
|
149
|
+
end
|
150
|
+
|
151
|
+
if internal_level == 0
|
152
|
+
res
|
153
|
+
else
|
154
|
+
[res, is_current_parent, levels.max]
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
115
158
|
#******************* BREADCRUMBS *******************
|
116
159
|
# draw the breadcrumb as html list
|
117
160
|
def breadcrumb_draw
|
@@ -41,15 +41,12 @@ module CamaleonCms::SessionHelper
|
|
41
41
|
# User registration.
|
42
42
|
#
|
43
43
|
# user_data must contain:
|
44
|
+
# - first_name
|
44
45
|
# - email
|
45
46
|
# - username
|
46
47
|
# - password
|
47
48
|
# - password_confirmation
|
48
|
-
|
49
|
-
# meta must contain:
|
50
|
-
# - first_name
|
51
|
-
# - last_name
|
52
|
-
#
|
49
|
+
|
53
50
|
def cama_register_user(user_data, meta)
|
54
51
|
@user = current_site.users.new(user_data)
|
55
52
|
r = {user: @user, params: params}; hook_run('user_before_register', r)
|
@@ -58,7 +55,7 @@ module CamaleonCms::SessionHelper
|
|
58
55
|
{:result => false, :type => :captcha_error, :message => t('camaleon_cms.admin.users.message.error_captcha')}
|
59
56
|
else
|
60
57
|
if @user.save
|
61
|
-
@user.
|
58
|
+
@user.set_metas(meta)
|
62
59
|
message = current_site.need_validate_email? ? t('camaleon_cms.admin.users.message.created_pending_validate_email') : t('camaleon_cms.admin.users.message.created')
|
63
60
|
r = {user: @user, message: message, redirect_url: cama_admin_login_path}; hooks_run('user_after_register', r)
|
64
61
|
{:result => true, :message => r[:message], :redirect_url => r[:redirect_url]}
|
@@ -14,10 +14,12 @@ module CamaleonCms::UploaderHelper
|
|
14
14
|
# sample: temporal => will save in /rails_path/public/temporal
|
15
15
|
# generate_thumb: true, # generate thumb image if this is image format (default true)
|
16
16
|
# maximum: maximum bytes permitted to upload (default: 1000MG)
|
17
|
-
# dimension: dimension for the image (sample: 30x30 | x30 | 30x)
|
17
|
+
# dimension: dimension for the image (sample: 30x30 | x30 | 30x | 300x300?)
|
18
18
|
# formats: extensions permitted, sample: jpg,png,... or generic: images | videos | audios | documents (default *)
|
19
19
|
# remove_source: Boolean (delete source file after saved if this is true, default false)
|
20
20
|
# same_name: Boolean (save the file with the same name if defined true, else search for a non used name)
|
21
|
+
# versions: String (Create multiple versions of the image uploaded), sample: '300x300,505x350' ==> Will create two extra file with this dimensions
|
22
|
+
# thumb_size: String (redefine the dimensions of the thumbnail, sample: '100x100' ==> only for images)
|
21
23
|
# temporal_time: if great than 0 seconds, then this file will expire (removed) in that time (default: 0)
|
22
24
|
# To manage jobs, please check http://edgeguides.rubyonrails.org/active_job_basics.html
|
23
25
|
# Note: if you are using temporal_time, you will need to copy the file to another directory later
|
@@ -38,7 +40,9 @@ module CamaleonCms::UploaderHelper
|
|
38
40
|
filename: (uploaded_io.original_filename rescue uploaded_io.path.split("/").last).parameterize(".").downcase.gsub(" ", "-"),
|
39
41
|
file_size: File.size(uploaded_io.to_io),
|
40
42
|
remove_source: false,
|
41
|
-
same_name: false
|
43
|
+
same_name: false,
|
44
|
+
versions: '',
|
45
|
+
thumb_size: nil
|
42
46
|
}.merge(settings)
|
43
47
|
hooks_run("before_upload", settings)
|
44
48
|
res = {error: nil}
|
@@ -57,8 +61,18 @@ module CamaleonCms::UploaderHelper
|
|
57
61
|
res = cama_uploader.add_file(uploaded_io, key, {same_name: settings[:same_name]})
|
58
62
|
{} if settings[:temporal_time] > 0 # temporal file upload (always put as local for temporal files) (TODO: use delayjob)
|
59
63
|
|
64
|
+
# generate image versions
|
65
|
+
if res['format'] == 'image'
|
66
|
+
settings[:versions].to_s.gsub(' ', '').split(',').each do |v|
|
67
|
+
version_path = cama_resize_upload(uploaded_io.path, v, {replace: false})
|
68
|
+
cama_uploader.add_file(version_path, cama_uploader.version_path(res['key'], v), is_thumb: true, same_name: true)
|
69
|
+
FileUtils.rm_f(version_path)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
60
73
|
# generate thumb
|
61
|
-
cama_uploader_generate_thumbnail(uploaded_io.path, res['key']) if settings[:generate_thumb] && res['thumb'].present?
|
74
|
+
cama_uploader_generate_thumbnail(uploaded_io.path, res['key'], settings[:thumb_size]) if settings[:generate_thumb] && res['thumb'].present?
|
75
|
+
|
62
76
|
FileUtils.rm_f(uploaded_io.path) if settings[:remove_source]
|
63
77
|
res
|
64
78
|
end
|
@@ -66,9 +80,11 @@ module CamaleonCms::UploaderHelper
|
|
66
80
|
# generate thumbnail of a existent image
|
67
81
|
# key: key of the current file
|
68
82
|
# the thumbnail will be saved in my_images/my_img.png => my_images/thumb/my_img.png
|
69
|
-
def cama_uploader_generate_thumbnail(uploaded_io, key)
|
83
|
+
def cama_uploader_generate_thumbnail(uploaded_io, key, thumb_size = nil)
|
84
|
+
w, h = cama_uploader.thumb[:w], cama_uploader.thumb[:h]
|
85
|
+
w, h = thumb_size.split('x') if thumb_size.present?
|
70
86
|
uploaded_io = File.open(uploaded_io) if uploaded_io.is_a?(String)
|
71
|
-
path_thumb = cama_resize_and_crop(uploaded_io.path,
|
87
|
+
path_thumb = cama_resize_and_crop(uploaded_io.path, w, h)
|
72
88
|
thumb = cama_uploader.add_file(path_thumb, cama_uploader.version_path(key), is_thumb: true, same_name: true)
|
73
89
|
FileUtils.rm_f(path_thumb)
|
74
90
|
thumb
|
@@ -215,9 +231,9 @@ module CamaleonCms::UploaderHelper
|
|
215
231
|
|
216
232
|
# resize image if the format is correct
|
217
233
|
# return resized file path
|
218
|
-
def cama_resize_upload(image_path, dimesion)
|
234
|
+
def cama_resize_upload(image_path, dimesion, args = {})
|
219
235
|
if cama_uploader.class.validate_file_format(image_path, 'image') && dimesion.present?
|
220
|
-
r={file: image_path, w: dimesion.split('x')[0], h: dimesion.split('x')[1], w_offset: 0, h_offset: 0, resize: !dimesion.split('x')[2] || dimesion.split('x')[2] == "resize", replace: true, gravity: :north_east}; hooks_run("on_uploader_resize", r)
|
236
|
+
r= {file: image_path, w: dimesion.split('x')[0], h: dimesion.split('x')[1], w_offset: 0, h_offset: 0, resize: !dimesion.split('x')[2] || dimesion.split('x')[2] == "resize", replace: true, gravity: :north_east}.merge(args); hooks_run("on_uploader_resize", r)
|
221
237
|
if r[:w].present? && r[:h].present?
|
222
238
|
image_path = cama_resize_and_crop(r[:file], r[:w], r[:h], {overwrite: r[:replace], gravity: r[:gravity] })
|
223
239
|
else
|
@@ -7,15 +7,15 @@
|
|
7
7
|
See the GNU Affero General Public License (GPLv3) for more details.
|
8
8
|
=end
|
9
9
|
class CamaleonCms::Category < CamaleonCms::TermTaxonomy
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
alias_attribute :site_id, :term_group
|
11
|
+
alias_attribute :post_type_id, :status
|
13
12
|
default_scope { where(taxonomy: :category) }
|
14
13
|
has_many :metas, ->{ where(object_class: 'Category')}, :class_name => "CamaleonCms::Meta", foreign_key: :objectid, dependent: :destroy
|
15
14
|
has_many :posts, foreign_key: :objectid, through: :term_relationships, :source => :objects
|
16
15
|
has_many :children, class_name: "CamaleonCms::Category", foreign_key: :parent_id, dependent: :destroy
|
17
16
|
belongs_to :parent, class_name: "CamaleonCms::Category", foreign_key: :parent_id
|
18
|
-
belongs_to :post_type_parent, class_name: "CamaleonCms::PostType", foreign_key: :parent_id
|
17
|
+
belongs_to :post_type_parent, class_name: "CamaleonCms::PostType", foreign_key: :parent_id, inverse_of: :categories
|
18
|
+
belongs_to :site, class_name: 'CamaleonCms::Site', foreign_key: :site_id
|
19
19
|
|
20
20
|
scope :no_empty, ->{ where("count > 0") } # return all categories that contains at least one post
|
21
21
|
scope :empty, ->{ where(count: [0,nil]) } # return all categories that does not contain any post
|
@@ -40,7 +40,7 @@ class CamaleonCms::Category < CamaleonCms::TermTaxonomy
|
|
40
40
|
private
|
41
41
|
def set_site
|
42
42
|
pt = self.post_type
|
43
|
-
self.
|
43
|
+
self.site_id = pt.site_id unless self.site_id.present?
|
44
44
|
self.status = pt.id unless self.status.present?
|
45
45
|
end
|
46
46
|
|
@@ -9,6 +9,7 @@
|
|
9
9
|
class CamaleonCms::CustomFieldGroup < CamaleonCms::CustomField
|
10
10
|
self.primary_key = :id
|
11
11
|
# attrs required: name, slug, description
|
12
|
+
alias_attribute :site_id, :parent_id
|
12
13
|
default_scope { where.not(object_class: '_fields').reorder("#{CamaleonCms::CustomField.table_name}.field_order ASC") }
|
13
14
|
|
14
15
|
has_many :metas, ->{ where(object_class: 'CustomFieldGroup')}, :class_name => "CamaleonCms::Meta", foreign_key: :objectid, dependent: :destroy
|
@@ -34,7 +35,7 @@ class CamaleonCms::CustomFieldGroup < CamaleonCms::CustomField
|
|
34
35
|
return c if c.present?
|
35
36
|
|
36
37
|
field_item = self.fields.create!(item)
|
37
|
-
field_item.
|
38
|
+
field_item.set_options(options)
|
38
39
|
auto_save_default_values(field_item, options)
|
39
40
|
field_item
|
40
41
|
end
|
@@ -8,9 +8,10 @@
|
|
8
8
|
=end
|
9
9
|
class CamaleonCms::NavMenu < CamaleonCms::TermTaxonomy
|
10
10
|
default_scope { where(taxonomy: :nav_menu).order(id: :asc) }
|
11
|
+
alias_attribute :site_id, :parent_id
|
11
12
|
has_many :metas, ->{ where(object_class: 'NavMenu')}, :class_name => "CamaleonCms::Meta", foreign_key: :objectid, dependent: :destroy
|
12
|
-
has_many :children, class_name: "CamaleonCms::NavMenuItem", foreign_key: :parent_id, dependent: :destroy
|
13
|
-
belongs_to :site, :class_name => "CamaleonCms::Site", foreign_key: :parent_id
|
13
|
+
has_many :children, class_name: "CamaleonCms::NavMenuItem", foreign_key: :parent_id, dependent: :destroy, inverse_of: :parent
|
14
|
+
belongs_to :site, :class_name => "CamaleonCms::Site", foreign_key: :parent_id, inverse_of: :nav_menus
|
14
15
|
|
15
16
|
# add menu item for current menu
|
16
17
|
# value: (Hash) is a hash object that contains label, type, link
|
@@ -9,10 +9,11 @@
|
|
9
9
|
class CamaleonCms::NavMenuItem < CamaleonCms::TermTaxonomy
|
10
10
|
default_scope { where(taxonomy: :nav_menu_item).order(id: :asc) }
|
11
11
|
has_many :metas, ->{ where(object_class: 'NavMenuItem')}, :class_name => "CamaleonCms::Meta", foreign_key: :objectid, dependent: :destroy
|
12
|
-
belongs_to :parent, class_name: "CamaleonCms::NavMenu"
|
13
|
-
belongs_to :parent_item, class_name: "CamaleonCms::NavMenuItem", foreign_key: :parent_id
|
14
|
-
has_many :children, class_name: "CamaleonCms::NavMenuItem", foreign_key: :parent_id, dependent: :destroy
|
12
|
+
belongs_to :parent, class_name: "CamaleonCms::NavMenu", inverse_of: :children
|
13
|
+
belongs_to :parent_item, class_name: "CamaleonCms::NavMenuItem", foreign_key: :parent_id, inverse_of: :children
|
14
|
+
has_many :children, class_name: "CamaleonCms::NavMenuItem", foreign_key: :parent_id, dependent: :destroy, inverse_of: :parent_item
|
15
15
|
|
16
|
+
before_create :set_parent_site
|
16
17
|
after_create :update_count
|
17
18
|
#before_destroy :update_count
|
18
19
|
alias_attribute :site_id, :term_group
|
@@ -66,4 +67,10 @@ class CamaleonCms::NavMenuItem < CamaleonCms::TermTaxonomy
|
|
66
67
|
self.parent_item.update_column('count', self.parent_item.children.size) if self.parent_item.present?
|
67
68
|
self.update_column(:term_group, main_menu.parent_id)
|
68
69
|
end
|
70
|
+
|
71
|
+
# fast access from site to menu items
|
72
|
+
def set_parent_site
|
73
|
+
self.site_id = self.parent_item.site_id if self.parent_item.present?
|
74
|
+
self.site_id = self.parent.site_id if self.parent.present?
|
75
|
+
end
|
69
76
|
end
|
@@ -32,6 +32,7 @@ end
|
|
32
32
|
|
33
33
|
class CamaleonCms::Post < CamaleonCms::PostDefault
|
34
34
|
include CamaleonCms::CategoriesTagsForPosts
|
35
|
+
alias_attribute :post_type_id, :taxonomy_id
|
35
36
|
default_scope ->{ where(post_class: "Post").order(post_order: :asc, created_at: :desc) }
|
36
37
|
has_many :metas, ->{ where(object_class: 'Post')}, :class_name => "CamaleonCms::Meta", foreign_key: :objectid, dependent: :delete_all
|
37
38
|
|
@@ -49,7 +50,7 @@ class CamaleonCms::Post < CamaleonCms::PostDefault
|
|
49
50
|
|
50
51
|
belongs_to :owner, class_name: "CamaleonCms::User", foreign_key: :user_id
|
51
52
|
belongs_to :parent, class_name: "CamaleonCms::Post", foreign_key: :post_parent
|
52
|
-
belongs_to :post_type, class_name: "CamaleonCms::PostType", foreign_key: :taxonomy_id
|
53
|
+
belongs_to :post_type, class_name: "CamaleonCms::PostType", foreign_key: :taxonomy_id, inverse_of: :posts
|
53
54
|
|
54
55
|
scope :visible_frontend, -> {where(status: 'published')}
|
55
56
|
scope :public_posts, -> {visible_frontend.where(visibility: ['public', ""]) } #public posts (not passwords, not privates)
|
@@ -239,4 +240,11 @@ class CamaleonCms::Post < CamaleonCms::PostDefault
|
|
239
240
|
def total_comments
|
240
241
|
self.get_meta("comments_count", 0).to_i
|
241
242
|
end
|
242
|
-
|
243
|
+
|
244
|
+
# manage the custom decorators for posts
|
245
|
+
# sample: my_post_type.set_option('cama_post_decorator_class', 'ProductDecorator')
|
246
|
+
# Sample: https://github.com/owen2345/camaleon-ecommerce/tree/master/app/decorators/
|
247
|
+
def decorator_class
|
248
|
+
(self.post_type.get_option('cama_post_decorator_class', 'CamaleonCms::PostDecorator') rescue 'CamaleonCms::PostDecorator').constantize
|
249
|
+
end
|
250
|
+
end
|
@@ -11,7 +11,7 @@ class CamaleonCms::PostDefault < ActiveRecord::Base
|
|
11
11
|
include CamaleonCms::CustomFieldsRead
|
12
12
|
self.table_name = "#{PluginRoutes.static_system_info["db_prefix"]}posts"
|
13
13
|
|
14
|
-
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
|
14
|
+
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
|
15
15
|
attr_accessor :draft_id
|
16
16
|
attr_accessible :data_options
|
17
17
|
attr_accessible :data_metas
|
@@ -20,6 +20,7 @@ class CamaleonCms::PostDefault < ActiveRecord::Base
|
|
20
20
|
|
21
21
|
has_many :term_relationships, class_name: "CamaleonCms::TermRelationship", foreign_key: :objectid, dependent: :destroy, primary_key: :id
|
22
22
|
has_many :children, ->{ where(post_class: "PostDefault") }, class_name: "CamaleonCms::PostDefault", foreign_key: :post_parent, dependent: :destroy, primary_key: :id
|
23
|
+
scope :featured, ->{ where(is_feature: true) }
|
23
24
|
|
24
25
|
validates :title, :slug, presence: true
|
25
26
|
|
@@ -28,6 +29,7 @@ class CamaleonCms::PostDefault < ActiveRecord::Base
|
|
28
29
|
before_save :before_saved
|
29
30
|
before_destroy :destroy_dependencies
|
30
31
|
|
32
|
+
|
31
33
|
# find a content by slug (support multi language)
|
32
34
|
def self.find_by_slug(slug)
|
33
35
|
if current_site.present? && current_site.get_meta("languages_site", []).count <= 1
|
@@ -52,13 +54,6 @@ class CamaleonCms::PostDefault < ActiveRecord::Base
|
|
52
54
|
end
|
53
55
|
end
|
54
56
|
|
55
|
-
# save meta values passed from form
|
56
|
-
def set_meta_from_form(data_metas)
|
57
|
-
data_metas.each do |key, value|
|
58
|
-
self.set_meta(key, value)
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
57
|
# return all menu items in which this post was assigned
|
63
58
|
def in_nav_menu_items
|
64
59
|
CamaleonCms::NavMenuItem.joins(:metas).where("value LIKE ?","%\"object_id\":\"#{self.id}\"%").where("value LIKE ?","%\"type\":\"post\"%").readonly(false)
|
@@ -66,7 +61,7 @@ class CamaleonCms::PostDefault < ActiveRecord::Base
|
|
66
61
|
|
67
62
|
# Set the meta, field values and the post keywords here
|
68
63
|
def set_params(meta, field_options, post_data_keywords)
|
69
|
-
self.
|
64
|
+
self.set_metas(meta)
|
70
65
|
self.set_field_values(field_options)
|
71
66
|
self.set_option("keywords", post_data_keywords)
|
72
67
|
end
|
@@ -10,6 +10,6 @@ class CamaleonCms::PostTag < CamaleonCms::TermTaxonomy
|
|
10
10
|
default_scope { where(taxonomy: :post_tag) }
|
11
11
|
has_many :metas, ->{ where(object_class: 'PostTag')}, :class_name => "CamaleonCms::Meta", foreign_key: :objectid, dependent: :destroy
|
12
12
|
has_many :posts, foreign_key: :objectid, through: :term_relationships, :source => :objects
|
13
|
-
belongs_to :post_type, class_name: "CamaleonCms::PostType", foreign_key: :parent_id
|
13
|
+
belongs_to :post_type, class_name: "CamaleonCms::PostType", foreign_key: :parent_id, inverse_of: :post_tags
|
14
14
|
belongs_to :owner, class_name: "CamaleonCms::User", foreign_key: :user_id
|
15
15
|
end
|
@@ -7,12 +7,14 @@
|
|
7
7
|
See the GNU Affero General Public License (GPLv3) for more details.
|
8
8
|
=end
|
9
9
|
class CamaleonCms::PostType < CamaleonCms::TermTaxonomy
|
10
|
+
alias_attribute :site_id, :parent_id
|
10
11
|
default_scope { where(taxonomy: :post_type) }
|
11
12
|
has_many :metas, ->{ where(object_class: 'PostType')}, :class_name => "CamaleonCms::Meta", foreign_key: :objectid, dependent: :delete_all
|
12
|
-
has_many :categories, :class_name => "CamaleonCms::Category", foreign_key: :parent_id, dependent: :destroy
|
13
|
-
has_many :post_tags, :class_name => "CamaleonCms::PostTag", foreign_key: :parent_id, dependent: :destroy
|
14
|
-
has_many :posts, class_name: "CamaleonCms::Post", foreign_key: :taxonomy_id, dependent: :destroy
|
15
|
-
has_many :
|
13
|
+
has_many :categories, :class_name => "CamaleonCms::Category", foreign_key: :parent_id, dependent: :destroy, inverse_of: :post_type_parent
|
14
|
+
has_many :post_tags, :class_name => "CamaleonCms::PostTag", foreign_key: :parent_id, dependent: :destroy, inverse_of: :post_type
|
15
|
+
has_many :posts, class_name: "CamaleonCms::Post", foreign_key: :taxonomy_id, dependent: :destroy, inverse_of: :post_type
|
16
|
+
has_many :posts_through_categories, foreign_key: :objectid, through: :term_relationships, :source => :objects
|
17
|
+
has_many :posts_draft, class_name: "CamaleonCms::Post", foreign_key: :taxonomy_id, dependent: :destroy, source: :drafts, inverse_of: :post_type
|
16
18
|
has_many :field_group_taxonomy, -> {where("object_class LIKE ?","PostType_%")}, :class_name => "CamaleonCms::CustomField", foreign_key: :objectid, dependent: :destroy
|
17
19
|
|
18
20
|
belongs_to :owner, class_name: "CamaleonCms::User", foreign_key: :user_id
|
@@ -187,5 +189,4 @@ class CamaleonCms::PostType < CamaleonCms::TermTaxonomy
|
|
187
189
|
def check_refresh_routes
|
188
190
|
refresh_routes if self.slug_changed?
|
189
191
|
end
|
190
|
-
|
191
192
|
end
|
@@ -11,7 +11,7 @@ class CamaleonCms::Site < CamaleonCms::TermTaxonomy
|
|
11
11
|
default_scope { where(taxonomy: :site).reorder(term_group: :desc) }
|
12
12
|
has_many :metas, -> { where(object_class: 'Site') }, :class_name => "CamaleonCms::Meta", foreign_key: :objectid, dependent: :delete_all
|
13
13
|
has_many :post_types, :class_name => "CamaleonCms::PostType", foreign_key: :parent_id, dependent: :destroy
|
14
|
-
has_many :nav_menus, :class_name => "CamaleonCms::NavMenu", foreign_key: :parent_id, dependent: :destroy
|
14
|
+
has_many :nav_menus, :class_name => "CamaleonCms::NavMenu", foreign_key: :parent_id, dependent: :destroy, inverse_of: :site
|
15
15
|
has_many :nav_menu_items, :class_name => "CamaleonCms::NavMenuItem", foreign_key: :term_group
|
16
16
|
has_many :widgets, :class_name => "CamaleonCms::Widget::Main", foreign_key: :parent_id, dependent: :destroy
|
17
17
|
has_many :sidebars, :class_name => "CamaleonCms::Widget::Sidebar", foreign_key: :parent_id, dependent: :destroy
|
@@ -286,7 +286,7 @@ class CamaleonCms::Site < CamaleonCms::TermTaxonomy
|
|
286
286
|
content = "<p style='text-align: center;'><img width='155' height='155' src='http://camaleon.tuzitio.com/media/132/logo2.png' alt='logo' /></p><p><strong>Camaleon CMS</strong> is a free and open-source tool and a fexible content management system (CMS) based on <a href='rubyonrails.org'>Ruby on Rails 4</a> and MySQL. </p> <p>With Camaleon you can do the following:</p> <ul> <li>Create instantly a lot of sites in the same installation</li> <li>Manage your content information in several languages</li> <li>Extend current functionality by plugins (MVC structure and no more echo or prints anywhere)</li> <li>Create or install different themes for each site</li> <li>Create your own structure without coding anything (adapt Camaleon as you want and not you for Camaleon)</li> <li>Create your store and start to sell your products using our plugins</li> <li>Avoid web attacks</li> <li>Compare the speed and enjoy the speed of your new Camaleon site</li> <li>Customize or create your themes for mobile support</li> <li>Support more visitors at the same time</li> <li>Manage your information with a panel like wordpress </li> <li>All urls are oriented for SEO</li> <li>Multiples roles of users</li> </ul>"
|
287
287
|
end
|
288
288
|
user = self.users.admin_scope.first
|
289
|
-
user = self.users.admin_scope.create({email: 'admin@local.com', username: 'admin', password: 'admin', password_confirmation: 'admin'}) unless user.present?
|
289
|
+
user = self.users.admin_scope.create({email: 'admin@local.com', username: 'admin', password: 'admin', password_confirmation: 'admin', first_name: 'Administrator'}) unless user.present?
|
290
290
|
post = pt.add_post({title: title, slug: slug, content: content, user_id: user.id, status: 'published'})
|
291
291
|
@nav_menu.append_menu_item({label: title, type: 'post', link: post.id})
|
292
292
|
end
|
@@ -41,16 +41,6 @@ class CamaleonCms::TermTaxonomy < ActiveRecord::Base
|
|
41
41
|
CamaleonCms::TermTaxonomy.where("#{CamaleonCms::TermTaxonomy.table_name}.parent_id = ?", self.id)
|
42
42
|
end
|
43
43
|
|
44
|
-
# save multiple option at once
|
45
|
-
# sample: set_options_from_form({option1: 1, option2: 'b', ..})
|
46
|
-
def set_options_from_form(metas = [])
|
47
|
-
if metas.present?
|
48
|
-
metas.each do |key, value|
|
49
|
-
self.set_option(key, value)
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
44
|
# return all menu items in which this taxonomy was assigned
|
55
45
|
def in_nav_menu_items
|
56
46
|
CamaleonCms::NavMenuItem.joins(:metas).where("value LIKE ?","%\"object_id\":\"#{self.id}\"%").where("value LIKE ?","%\"type\":\"#{self.taxonomy}\"%").readonly(false)
|
@@ -18,9 +18,7 @@ class CamaleonCms::User < ActiveRecord::Base
|
|
18
18
|
include CamaleonCms::Metas
|
19
19
|
include CamaleonCms::CustomFieldsRead
|
20
20
|
self.table_name = "#{PluginRoutes.static_system_info["db_prefix"]}users"
|
21
|
-
attr_accessible :username, :role, :email, :parent_id, :last_login_at, :site_id, :password, :password_confirmation #, :profile_attributes
|
22
|
-
attr_accessible :data_options
|
23
|
-
attr_accessible :data_metas
|
21
|
+
attr_accessible :username, :role, :email, :parent_id, :last_login_at, :site_id, :password, :password_confirmation, :first_name, :last_name #, :profile_attributes
|
24
22
|
attr_accessible :is_valid_email
|
25
23
|
|
26
24
|
default_scope {order("#{CamaleonCms::User.table_name}.role ASC")}
|
@@ -63,7 +61,7 @@ class CamaleonCms::User < ActiveRecord::Base
|
|
63
61
|
end
|
64
62
|
|
65
63
|
def fullname
|
66
|
-
|
64
|
+
"#{self.first_name} #{self.last_name}".titleize
|
67
65
|
end
|
68
66
|
|
69
67
|
def admin?
|
@@ -79,12 +77,6 @@ class CamaleonCms::User < ActiveRecord::Base
|
|
79
77
|
@_user_role ||= site.user_roles.where(slug: self.role).first
|
80
78
|
end
|
81
79
|
|
82
|
-
def set_meta_from_form(metas)
|
83
|
-
metas.each do |key, value|
|
84
|
-
self.metas.where({key: key}).update_or_create({value: value})
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
80
|
def assign_site(site)
|
89
81
|
self.user_relationships.where(term_taxonomy_id: site.id).first_or_create
|
90
82
|
end
|
@@ -11,7 +11,7 @@ module CamaleonCms::CustomFieldsRead extend ActiveSupport::Concern
|
|
11
11
|
before_destroy :_destroy_custom_field_groups
|
12
12
|
has_many :fields, ->(object){ where(:object_class => object.class.to_s.gsub("Decorator","").gsub("CamaleonCms::",""))} , :class_name => "CamaleonCms::CustomField" ,foreign_key: :objectid
|
13
13
|
has_many :field_values, ->(object){where(object_class: object.class.to_s.gsub("Decorator","").gsub("CamaleonCms::",""))}, :class_name => "CamaleonCms::CustomFieldsRelationship", foreign_key: :objectid, dependent: :delete_all
|
14
|
-
has_many :custom_field_values, :class_name => "CamaleonCms::CustomFieldsRelationship", foreign_key: :objectid, dependent: :delete_all
|
14
|
+
has_many :custom_field_values, ->(object){ where(object_class: object.class.to_s.gsub("Decorator","").gsub("CamaleonCms::", ""))}, :class_name => "CamaleonCms::CustomFieldsRelationship", foreign_key: :objectid, dependent: :delete_all
|
15
15
|
|
16
16
|
# valid only for simple groups and not for complex like: posts, post, ... where the group is for individual or children groups
|
17
17
|
has_many :field_groups, ->(object){where(object_class: object.class.to_s.parseCamaClass)}, :class_name => "CamaleonCms::CustomFieldGroup", foreign_key: :objectid
|
@@ -24,10 +24,11 @@ module CamaleonCms::CustomFieldsRead extend ActiveSupport::Concern
|
|
24
24
|
# args: (Hash)
|
25
25
|
# kind: argument only for PostType Objects: (Post (Default) | Category | PostTag).
|
26
26
|
# If kind = "post_type" this will return groups for all post_types
|
27
|
+
# If kind = "Post" this will return all groups for all posts from current post type + groups of current post type
|
27
28
|
# include_parent: (boolean, default false) Permit to recover groups from self + parent post_type (argument valid only for Post | PostTag | Category)
|
28
29
|
# args: (String) => is a value for kind attribute
|
29
30
|
def get_field_groups(args = {})
|
30
|
-
args = args.is_a?(String) ? {kind: args, include_parent: false } : {kind: "
|
31
|
+
args = args.is_a?(String) ? {kind: args, include_parent: false } : {kind: "Post", include_parent: false }.merge(args)
|
31
32
|
class_name = self.class.to_s.parseCamaClass
|
32
33
|
case class_name
|
33
34
|
when 'Category','Post','PostTag'
|
@@ -36,12 +37,6 @@ module CamaleonCms::CustomFieldsRead extend ActiveSupport::Concern
|
|
36
37
|
else
|
37
38
|
CamaleonCms::CustomFieldGroup.where(objectid: self.id || -1, object_class: class_name)
|
38
39
|
end
|
39
|
-
when 'Widget::Main'
|
40
|
-
self.field_groups
|
41
|
-
when 'Theme'
|
42
|
-
self.field_groups
|
43
|
-
when 'Site'
|
44
|
-
self.field_groups
|
45
40
|
when 'NavMenuItem'
|
46
41
|
self.main_menu.field_groups
|
47
42
|
when 'PostType'
|
@@ -52,7 +47,7 @@ module CamaleonCms::CustomFieldsRead extend ActiveSupport::Concern
|
|
52
47
|
else
|
53
48
|
CamaleonCms::CustomFieldGroup.where(object_class: "PostType_#{args[:kind]}", objectid: self.id )
|
54
49
|
end
|
55
|
-
else # 'Plugin' or other
|
50
|
+
else # 'Plugin' or other classes
|
56
51
|
self.field_groups
|
57
52
|
end
|
58
53
|
end
|
@@ -143,6 +138,8 @@ module CamaleonCms::CustomFieldsRead extend ActiveSupport::Concern
|
|
143
138
|
values = values.with_indifferent_access
|
144
139
|
group = get_field_groups(kind).where(slug: values[:slug]).first
|
145
140
|
unless group.present?
|
141
|
+
site = _cama_get_field_site
|
142
|
+
values[:parent_id] = site.id if site.present?
|
146
143
|
group = get_field_groups(kind).create(values)
|
147
144
|
end
|
148
145
|
group
|
@@ -225,4 +222,15 @@ module CamaleonCms::CustomFieldsRead extend ActiveSupport::Concern
|
|
225
222
|
get_field_groups().destroy_all if get_field_groups.present?
|
226
223
|
end
|
227
224
|
end
|
225
|
+
# return the Site Model owner of current model
|
226
|
+
def _cama_get_field_site
|
227
|
+
case self.class.to_s.parseCamaClass
|
228
|
+
when 'Category','Post','PostTag'
|
229
|
+
self.post_type.site
|
230
|
+
when 'Site'
|
231
|
+
self
|
232
|
+
else
|
233
|
+
self.site
|
234
|
+
end
|
235
|
+
end
|
228
236
|
end
|