camaleon_cms 2.4.5.5 → 2.4.5.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. checksums.yaml +4 -4
  2. data/app/apps/themes/default/views/partials/_comments.html.erb +36 -21
  3. data/app/apps/themes/default/views/post.html.erb +1 -1
  4. data/app/assets/javascripts/camaleon_cms/admin/uploader/_media_manager.js.coffee +4 -4
  5. data/app/controllers/camaleon_cms/admin/categories_controller.rb +3 -0
  6. data/app/controllers/camaleon_cms/admin/media_controller.rb +9 -6
  7. data/app/controllers/camaleon_cms/admin/sessions_controller.rb +1 -1
  8. data/app/controllers/camaleon_cms/admin/settings/post_types_controller.rb +2 -0
  9. data/app/controllers/concerns/camaleon_cms/frontend_concern.rb +17 -13
  10. data/app/decorators/camaleon_cms/post_decorator.rb +0 -1
  11. data/app/helpers/camaleon_cms/captcha_helper.rb +1 -1
  12. data/app/helpers/camaleon_cms/frontend/nav_menu_helper.rb +1 -0
  13. data/app/helpers/camaleon_cms/hooks_helper.rb +6 -1
  14. data/app/helpers/camaleon_cms/site_helper.rb +1 -1
  15. data/app/helpers/camaleon_cms/uploader_helper.rb +36 -27
  16. data/app/models/camaleon_cms/custom_fields_relationship.rb +6 -0
  17. data/app/models/camaleon_cms/media.rb +54 -0
  18. data/app/models/camaleon_cms/post.rb +1 -0
  19. data/app/models/camaleon_cms/site.rb +7 -0
  20. data/app/uploaders/camaleon_cms_aws_uploader.rb +21 -23
  21. data/app/uploaders/camaleon_cms_local_uploader.rb +20 -26
  22. data/app/uploaders/camaleon_cms_uploader.rb +17 -45
  23. data/app/views/camaleon_cms/admin/categories/index.html.erb +2 -2
  24. data/app/views/camaleon_cms/admin/media/_render_file_item.html.erb +53 -36
  25. data/app/views/camaleon_cms/admin/media/index.html.erb +1 -1
  26. data/app/views/camaleon_cms/admin/post_tags/index.html.erb +4 -4
  27. data/app/views/camaleon_cms/admin/posts/index.html.erb +1 -0
  28. data/app/views/camaleon_cms/admin/settings/_configuration_settings.html.erb +5 -1
  29. data/app/views/camaleon_cms/admin/settings/post_types/_form.html.erb +1 -1
  30. data/app/views/camaleon_cms/default_theme/partials/_comments.html.erb +45 -28
  31. data/app/views/camaleon_cms/default_theme/single.html.erb +1 -1
  32. data/config/locales/camaleon_cms/admin/es.yml +1 -0
  33. data/config/locales/camaleon_cms/admin/js.yml +54 -3
  34. data/config/locales/camaleon_cms/admin/ru.yml +39 -28
  35. data/db/migrate/20180124132318_create_media.rb +17 -0
  36. data/lib/camaleon_cms/version.rb +1 -1
  37. data/lib/ext/string.rb +8 -0
  38. data/lib/generators/camaleon_cms/gem_plugin_generator.rb +29 -25
  39. data/lib/plugin_routes.rb +27 -0
  40. data/spec/dummy/config/application.rb +1 -0
  41. data/spec/dummy/config/environments/test.rb +2 -0
  42. data/spec/dummy/db/schema.rb +1 -140
  43. data/spec/dummy/db/test.sqlite3 +0 -0
  44. data/spec/dummy/public/favicon.ico +0 -0
  45. data/spec/factories/post_type.rb +17 -0
  46. data/spec/factories/site.rb +8 -0
  47. data/spec/features/{categories_spec.rb → admin/categories_spec.rb} +1 -1
  48. data/spec/features/{comments_spec.rb → admin/comments_spec.rb} +16 -9
  49. data/spec/features/{contact_form_spec.rb → admin/contact_form_spec.rb} +16 -9
  50. data/spec/features/{content_groups_spec.rb → admin/content_groups_spec.rb} +19 -11
  51. data/spec/features/{custom_fields_spec.rb → admin/custom_fields_spec.rb} +1 -1
  52. data/spec/features/{languages_spec.rb → admin/languages_spec.rb} +1 -1
  53. data/spec/features/{media_spec.rb → admin/media_spec.rb} +1 -1
  54. data/spec/features/{menus_spec.rb → admin/menus_spec.rb} +2 -2
  55. data/spec/features/{pages_spec.rb → admin/pages_spec.rb} +1 -1
  56. data/spec/features/{plugins_spec.rb → admin/plugins_spec.rb} +1 -1
  57. data/spec/features/{posts_spec.rb → admin/posts_spec.rb} +4 -3
  58. data/spec/features/admin/session_spec.rb +102 -0
  59. data/spec/features/{settings_spec.rb → admin/settings_spec.rb} +1 -1
  60. data/spec/features/{shortcodes_spec.rb → admin/shortcodes_spec.rb} +1 -1
  61. data/spec/features/{sites_spec.rb → admin/sites_spec.rb} +22 -14
  62. data/spec/features/{tags_spec.rb → admin/tags_spec.rb} +17 -8
  63. data/spec/features/{themes_spec.rb → admin/themes_spec.rb} +1 -1
  64. data/spec/features/{user_roles_spec.rb → admin/user_roles_spec.rb} +25 -19
  65. data/spec/features/{users_spec.rb → admin/users_spec.rb} +2 -2
  66. data/spec/features/{widgets_spec.rb → admin/widgets_spec.rb} +19 -12
  67. data/spec/features/frontend/pages_spec.rb +86 -5
  68. data/spec/features/frontend/post_type_spec.rb +16 -0
  69. data/spec/helpers/email_helper_spec.rb +1 -1
  70. data/spec/helpers/uploader_helper_spec.rb +56 -0
  71. data/spec/mailers/send_mail_spec.rb +3 -3
  72. data/spec/{decorators/camaleon_cms/post_decorator_spec.rb → models/post_spec.rb} +3 -3
  73. data/spec/rails_helper.rb +79 -0
  74. data/spec/spec_helper.rb +25 -56
  75. data/spec/support/common.rb +10 -24
  76. data/spec/support/fixtures/rails.png +0 -0
  77. data/spec/support/fixtures/rails_tmp.png +0 -0
  78. metadata +64 -50
  79. data/app/views/camaleon_cms/admin/media/_files_list.html.erb +0 -2
  80. data/app/views/camaleon_cms/admin/media/_render_folder_item.html.erb +0 -15
  81. data/spec/decorators/post_type_spec.rb +0 -13
  82. data/spec/features/session_spec.rb +0 -74
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8419630c27eedca0f0d5603ea0e405e69f680bcb
4
- data.tar.gz: d235701cf45e0ff0a79de9e372f223ef317425c6
3
+ metadata.gz: c40d70430d7edd9132d9ed5529735b8421054db1
4
+ data.tar.gz: f34b54e713ca8a1d88a8de55e1cd3b5d048cc08b
5
5
  SHA512:
6
- metadata.gz: dd7fbc9ba304c545ae752e5260dc4df8bd3e6e642781acb480212d5bec08c1e0bd9b9f42987152eceec3dae23d17963a2d1c07b2c789f37255c179ac06294177
7
- data.tar.gz: 8a03d1a54e9f4dac2dd75fd313cc073e118e144a59ce494aa8c2a08ce953a28b4c5a0955f4f5362f851fba0c953e94c3625e6488399c01a688ba85fbfcc4a90b
6
+ metadata.gz: 4bdd8d1ce6f4a4ceaddd893c5ca4cf4d478ca3f5ede911b4cf86935ab39fcf6637abd300073a69dd194666366c90e2919bf65fabdba7fe21771e3b159bb68eb9
7
+ data.tar.gz: f6c8551c32f86b304a0b328b725b5bb0efcd9546784b56151ebe70aaaaaaf5e2ec62b1d0f2b7183f48e4593504bac472be12418796f2c940f162a4e6a67833f7
@@ -1,25 +1,40 @@
1
1
  <section id="comments" class="comments-area">
2
- <% if post.the_comments.count > 0 %>
3
- <h2 class="comments-title"><%= post.the_comments.count %> <%= ct('comments', default: 'Comments')%> "<span><%= post.the_title %></span>"</h2>
4
- <section class="comment-list">
5
- <%= render partial: "partials/comments_list", locals: { comments: post.the_comments, children: "" } %>
6
- </section>
7
- <% end %>
2
+ <% if post.the_comments.count > 0 %>
3
+ <h2 class="comments-title"><%= post.the_comments.count %> <%= ct('comments', default: 'Comments') %>
4
+ "<span><%= post.the_title %></span>"</h2>
5
+ <section class="comment-list">
6
+ <%= render partial: "partials/comments_list", locals: {comments: post.the_comments, children: ""} %>
7
+ </section>
8
+ <% end %>
9
+ <% if post.can_commented? %>
8
10
  <div id="respond" class="comment-respond">
9
- <% if signin? %>
10
- <h3 id="reply-title" class="comment-reply-title"><%= ct('comment_new', default: 'New Comment')%></h3>
11
- <%= form_for post, url:{action: :save_comment, post_id: post.id}, html: {method: "post", class: "comment-form"} do |f|%>
12
- <input type="hidden" name="post_comment[post_id]" value="<%= post.id %>">
13
- <input type="hidden" name="slug" value="<%= post.slug %>">
14
- <div class="mb-20">
15
- <textarea id="textarea_comments" name="post_comment[content]" class="form-control counted" placeholder="<%= ct('comment', default: 'Enter youe comment here')%>"></textarea>
16
- </div>
17
- <div class="mb-20">
18
- <button type="submit" class="btn btn-info pull-right"><%= ct('comment', default: 'Comment')%></button>
19
- </div>
20
- <% end %>
21
- <% else %>
22
- <div class="panel-login-comment"><%= ct('comment_msg', default: 'You need to be logged in')%> <a class="link-login-comment" href="<%= cama_admin_path %>"><%= ct('login', default: 'Login')%></a></div>
23
- <% end %>
11
+ <h3><%= ct('comment_new', default: 'New Comment') %></h3>
12
+ <% if signin? || current_site.get_option('permit_anonimos_comment', false) %>
13
+ <%= form_for post, url: {action: :save_comment, post_id: post.id}, html: {method: "post", class: "form-comment comment-form", id: 'form-comment'} do |f| %>
14
+ <%= render partial: "camaleon_cms/flash_messages", locals: {flash: (flash[:comment_submit] || {}).with_indifferent_access} %>
15
+ <% unless signin? %>
16
+ <div class="form-group">
17
+ <%= text_field_tag 'post_comment[name]', '', class: 'form-control required', placeholder: t('.anonymous_name', default: 'Name') %>
18
+ </div>
19
+ <div class="form-group">
20
+ <%= email_field_tag 'post_comment[email]', '', class: 'form-control required', placeholder: t('.anonymous_email', default: 'Email') %>
21
+ </div>
22
+ <% if current_site.is_enable_captcha_for_comments? %>
23
+ <%= content_tag :div, raw(cama_captcha_tag), class: 'form-group' %>
24
+ <% end %>
25
+ <% end %>
26
+ <div class="form-group">
27
+ <%= text_area_tag 'post_comment[content]', '', class: 'form-control required counted', placeholder: ct('comment', default: 'Here your comment') %>
28
+ </div>
29
+ <div class="form-group text-right">
30
+ <button type="submit" class="btn btn-info"><%= ct('comment', default: 'Comment') %></button>
31
+ </div>
32
+ <% end %>
33
+ <% else %>
34
+ <div class="panel-login-comment"><%= ct('comment_msg', default: 'You must be logged in to post a comment') %>
35
+ <a class="link-login-comment" href="<%= cama_admin_path %>"><%= ct('login', default: 'Login') %></a>
36
+ </div>
37
+ <% end %>
24
38
  </div>
39
+ <% end %>
25
40
  </section>
@@ -11,4 +11,4 @@
11
11
  <%= raw @post.the_content %>
12
12
  </div><!-- .entry-content -->
13
13
  </article><!-- #post -->
14
- <%= render partial: 'partials/comments', locals: {post: @post} if @post.can_commented? %>
14
+ <%= render partial: 'partials/comments', locals: {post: @post} %>
@@ -20,18 +20,18 @@ window["cama_init_media"] = (media_panel) ->
20
20
  "<div class='p_label'><b>"+I18n("button.name")+": </b><br> <span>"+data["name"]+"</span></div>" +
21
21
  "<div class='p_body'>" +
22
22
  "<div style='overflow: auto;'><b>"+I18n("button.url")+":</b><br> <a target='_blank' href='"+data["url"]+"'>"+data["url"]+"</a></div>" +
23
- "<div><b>"+I18n("button.size")+":</b> <span>"+cama_humanFileSize(data["size"])+"</span></div>" +
23
+ "<div><b>"+I18n("button.size")+":</b> <span>"+cama_humanFileSize(parseFloat(data["file_size"]))+"</span></div>" +
24
24
  "</div>"
25
25
 
26
26
  if window["callback_media_uploader"]
27
- if !media_panel.attr("data-formats") || (media_panel.attr("data-formats") && ($.inArray(data["format"], media_panel.attr("data-formats").split(",")) >= 0 || $.inArray(data["url"].split(".").pop().toLowerCase(), media_panel.attr("data-formats").split(",")) >= 0))
27
+ if !media_panel.attr("data-formats") || (media_panel.attr("data-formats") && ($.inArray(data["file_type"], media_panel.attr("data-formats").split(",")) >= 0 || $.inArray(data["url"].split(".").pop().toLowerCase(), media_panel.attr("data-formats").split(",")) >= 0))
28
28
  tpl += "<div class='p_footer'>" +
29
29
  "<button class='btn btn-primary insert_btn'>"+I18n("button.insert")+"</button>" +
30
30
  "</div>"
31
31
 
32
32
  media_info.html(tpl)
33
33
  media_info.find(".p_thumb").html(item.find(".thumb").html())
34
- if data["format"] == "image"
34
+ if data["file_type"] == "image"
35
35
  if item.find('.edit_item') # add button to edit image
36
36
  edit_img = $('<button type="button" class="pull-right btn btn-default" title="Edit"><i class="fa fa-pencil"></i></button>').click ->
37
37
  item.find('.edit_item').trigger('click')
@@ -351,7 +351,7 @@ window["cama_init_media"] = (media_panel) ->
351
351
  title: I18n('button.edit_image', 'Edit Image')+' - ' + data['name'] + (if media_panel.attr("data-dimension") then " <small><i>("+media_panel.attr("data-dimension")+")</i></small>" else ''),
352
352
  content: '<div>' +
353
353
  '<div class="editable_wrapper">' +
354
- '<img style="max-width: 100%;" class="editable" id="media_editable_image" src="'+data['url']+'">' +
354
+ '<img style="max-width: 100%;" class="editable" id="media_editable_image" crossorigin src="'+data['url']+'">' +
355
355
  '</div>' +
356
356
  '<div class="row" style="margin-top: 5px;">' +
357
357
  '<div class="col-md-8">' +
@@ -32,9 +32,12 @@ class CamaleonCms::Admin::CategoriesController < CamaleonCms::AdminController
32
32
 
33
33
  def create
34
34
  @category = @post_type.categories.new(params.require(:category).permit!)
35
+ hooks_run("create_category", {category: @category, post_type: @post_type})
36
+
35
37
  if @category.save
36
38
  @category.set_options(params[:meta])
37
39
  @category.set_field_values(params[:field_options])
40
+ hooks_run("created_category", {category: @category, post_type: @post_type})
38
41
  flash[:notice] = t('camaleon_cms.admin.post_type.message.created')
39
42
  redirect_to action: :index
40
43
  else
@@ -8,7 +8,7 @@ class CamaleonCms::Admin::MediaController < CamaleonCms::AdminController
8
8
  def index
9
9
  authorize! :manage, :media
10
10
  @show_file_actions = true
11
- @files = @tree[:files].map{|k,v|v}.paginate(page: params[:page], per_page: 100)
11
+ @files = @tree.paginate(page: params[:page], per_page: 100)
12
12
  @next_page = @files.current_page < @files.total_pages ? @files.current_page + 1 : nil
13
13
  add_breadcrumb I18n.t("camaleon_cms.admin.sidebar.media")
14
14
  end
@@ -38,10 +38,10 @@ class CamaleonCms::Admin::MediaController < CamaleonCms::AdminController
38
38
  @show_file_actions = true
39
39
  end
40
40
  @tree = cama_uploader.search(params[:search]) if params[:search].present?
41
- @files = @tree[:files].map{|k,v|v}.paginate(page: params[:page], per_page: 100)
41
+ @files = @tree.paginate(page: params[:page], per_page: 100)
42
42
  @next_page = @files.current_page < @files.total_pages ? @files.current_page + 1 : nil
43
43
  if params[:partial].present?
44
- render json: {next_page: @next_page, html: render_to_string(partial: "files_list", locals: { files: @files, folders: params[:page].present? ? [] : @tree[:folders] })}
44
+ render json: {next_page: @next_page, html: render_to_string(partial: "render_file_item", locals: { files: @files })}
45
45
  else
46
46
  render "index", layout: false unless params[:partial].present?
47
47
  end
@@ -56,7 +56,7 @@ class CamaleonCms::Admin::MediaController < CamaleonCms::AdminController
56
56
  case params[:media_action]
57
57
  when "new_folder"
58
58
  params[:folder] = slugify_folder(params[:folder])
59
- render partial: "render_folder_item", locals: { fname: params[:folder].split("/").last, folder: cama_uploader.add_folder(params[:folder])}
59
+ render partial: "render_file_item", locals: {files: [cama_uploader.add_folder(params[:folder])]}
60
60
  when "del_folder"
61
61
  cama_uploader.delete_folder(params[:folder])
62
62
  render inline: ""
@@ -64,7 +64,9 @@ class CamaleonCms::Admin::MediaController < CamaleonCms::AdminController
64
64
  cama_uploader.delete_file(params[:folder].gsub("//", "/"))
65
65
  render inline: ""
66
66
  when 'crop_url'
67
- params[:url] = (params[:url].start_with?('http') ? '' : current_site.the_url(locale: nil)) + params[:url]
67
+ unless params[:url].start_with?('data:')
68
+ params[:url] = (params[:url].start_with?('http') ? '' : current_site.the_url(locale: nil)) + params[:url]
69
+ end
68
70
  r = cama_tmp_upload( params[:url], formats: params[:formats], name: params[:name])
69
71
  unless r[:error].present?
70
72
  params[:file_upload] = r[:file_path]
@@ -93,7 +95,8 @@ class CamaleonCms::Admin::MediaController < CamaleonCms::AdminController
93
95
  # init basic media variables
94
96
  def init_media_vars
95
97
  @cama_uploader = CamaleonCmsLocalUploader.new({current_site: current_site, private: true}) if params[:private].present?
96
- cama_uploader.clear_cache if params[:cama_media_reload].present? && params[:cama_media_reload] == 'clear_cache'
98
+ cama_uploader.clear_cache if params[:cama_media_reload] == 'clear_cache'
99
+ cama_uploader.reload if params[:cama_media_reload] == 'reload'
97
100
  @media_formats = (params[:media_formats] || "").sub("media", ",video,audio").sub("all", "").split(",")
98
101
  @tree = cama_uploader.objects(@folder = params[:folder] || "/")
99
102
  @show_file_actions ||= params[:actions].to_s == 'true'
@@ -112,7 +112,7 @@ class CamaleonCms::Admin::SessionsController < CamaleonCms::CamaleonController
112
112
  user_data = user_permit_data
113
113
  result = cama_register_user(user_data, params[:meta])
114
114
  if result[:result] == false && result[:type] == :captcha_error
115
- @user.errors[:captcha] = t('camaleon_cms.admin.users.message.error_captcha')
115
+ @user.errors.add(:captcha, t('camaleon_cms.admin.users.message.error_captcha'))
116
116
  render 'register'
117
117
  elsif result[:result]
118
118
  flash[:notice] = result[:message]
@@ -19,6 +19,7 @@ class CamaleonCms::Admin::Settings::PostTypesController < CamaleonCms::Admin::Se
19
19
  def update
20
20
  if @post_type.update(@data_term)
21
21
  @post_type.set_field_values(params.require(:field_options).permit!) if params[:field_options].present?
22
+ hooks_run("updated_post_type", {post_type: @post_type})
22
23
  flash[:notice] = t('camaleon_cms.admin.post_type.message.updated')
23
24
  redirect_to action: :index
24
25
  else
@@ -30,6 +31,7 @@ class CamaleonCms::Admin::Settings::PostTypesController < CamaleonCms::Admin::Se
30
31
  @post_type = current_site.post_types.new(@data_term)
31
32
  if @post_type.save
32
33
  @post_type.set_field_values(params.require(:field_options).permit!) if params[:field_options].present?
34
+ hooks_run("created_post_type", {post_type: @post_type})
33
35
  flash[:notice] = t('camaleon_cms.admin.post_type.message.created')
34
36
  redirect_to action: :index
35
37
  else
@@ -31,6 +31,7 @@ module CamaleonCms::FrontendConcern extend ActiveSupport::Concern
31
31
  @post = current_site.posts.find_by_id(params[:post_id]).decorate
32
32
  user = cama_current_user
33
33
  comment_data = {}
34
+ flash[:comment_submit][:error] = t('.comments_not_enabled', default: 'This post can not be commented') if !@post.can_commented?
34
35
  if user.present?
35
36
  comment_data[:author] = user.fullname
36
37
  comment_data[:author_email] = user.email
@@ -39,23 +40,26 @@ module CamaleonCms::FrontendConcern extend ActiveSupport::Concern
39
40
  comment_data[:is_anonymous] = true
40
41
  comment_data[:author] = params[:post_comment][:name]
41
42
  comment_data[:author_email] = params[:post_comment][:email]
43
+ flash[:comment_submit][:error] = t('camaleon_cms.admin.users.message.error_captcha', default: 'Invalid captcha value') if current_site.is_enable_captcha_for_comments? && !cama_captcha_verified?
42
44
  end
43
45
 
44
- if @post.can_commented? && user.present?
45
- comment_data[:user_id] = user.id
46
- comment_data[:author_url] = params[:post_comment][:url] || ""
47
- comment_data[:author_IP] = request.remote_ip.to_s
48
- comment_data[:approved] = current_site.front_comment_status
49
- comment_data[:agent] = request.user_agent.force_encoding("ISO-8859-1").encode("UTF-8")
50
- comment_data[:content] = params[:post_comment][:content]
51
- @comment = params[:post_comment][:parent_id].present? ? @post.comments.find_by_id(params[:post_comment][:parent_id]).children.new(comment_data) : @post.comments.main.new(comment_data)
52
- if @comment.save
53
- flash[:comment_submit][:notice] = t('camaleon_cms.admin.comments.message.created')
46
+ unless flash[:comment_submit][:error]
47
+ if user.present?
48
+ comment_data[:user_id] = user.id
49
+ comment_data[:author_url] = params[:post_comment][:url] || ""
50
+ comment_data[:author_IP] = request.remote_ip.to_s
51
+ comment_data[:approved] = current_site.front_comment_status
52
+ comment_data[:agent] = request.user_agent.force_encoding("ISO-8859-1").encode("UTF-8")
53
+ comment_data[:content] = params[:post_comment][:content]
54
+ @comment = params[:post_comment][:parent_id].present? ? @post.comments.find_by_id(params[:post_comment][:parent_id]).children.new(comment_data) : @post.comments.main.new(comment_data)
55
+ if @comment.save
56
+ flash[:comment_submit][:notice] = t('camaleon_cms.admin.comments.message.created')
57
+ else
58
+ flash[:comment_submit][:error] = "#{t('camaleon_cms.common.comment_error', default: 'An error was occurred on save comment')}:<br> #{@comment.errors.full_messages.join(', ')}"
59
+ end
54
60
  else
55
- flash[:comment_submit][:error] = "#{t('camaleon_cms.common.comment_error', default: 'An error was occurred on save comment')}:<br> #{@comment.errors.full_messages.join(', ')}"
61
+ flash[:comment_submit][:error] = t('camaleon_cms.admin.message.unauthorized')
56
62
  end
57
- else
58
- flash[:comment_submit][:error] = t('camaleon_cms.admin.message.unauthorized')
59
63
  end
60
64
  params[:format] == 'json' ? render(json: flash.discard(:comment_submit).to_hash) : redirect_to(request.referer || @post.the_url(as_path: true))
61
65
  end
@@ -217,7 +217,6 @@ class CamaleonCms::PostDecorator < CamaleonCms::ApplicationDecorator
217
217
  # @param _parent: parent decorated model, like: (PostType *default), Category, PostTag, Site
218
218
  # @samples: my_post.the_next_post(), my_post.the_next_post(@category), my_post.the_next_post(current_site)
219
219
  def the_next_post(_parent = nil)
220
- puts "next for: #{object.slug}"
221
220
  (_parent.presence || the_post_type).the_posts.where("#{CamaleonCms::Post.table_name}.post_order > :position OR (#{CamaleonCms::Post.table_name}.post_order = :position and #{CamaleonCms::Post.table_name}.created_at > :created_at)", {position: object.post_order, created_at: object.created_at}).where.not(id: object.id).take.try(:decorate)
222
221
  end
223
222
 
@@ -34,7 +34,7 @@ module CamaleonCms::CaptchaHelper
34
34
 
35
35
  # verify captcha value
36
36
  def cama_captcha_verified?
37
- (session[:cama_captcha] || []).include?((params[:cama_captcha] || params[:captcha]).to_s.upcase) || Rails.env == "test"
37
+ (session[:cama_captcha] || []).include?((params[:cama_captcha] || params[:captcha]).to_s.upcase)
38
38
  end
39
39
 
40
40
  #************************* captcha in attack helpers ***************************#
@@ -166,6 +166,7 @@ module CamaleonCms::Frontend::NavMenuHelper
166
166
  # label => label of the link
167
167
  # url: url for the link
168
168
  def breadcrumb_add(label, url = "", prepend = false)
169
+ @_front_breadcrumb ||= []
169
170
  if prepend
170
171
  @_front_breadcrumb = @_front_breadcrumb.unshift([label, url])
171
172
  else
@@ -18,8 +18,13 @@ module CamaleonCms::HooksHelper
18
18
  PluginRoutes.enabled_apps(current_site).each do |plugin|
19
19
  _do_hook(plugin, hook_key, params)
20
20
  end
21
- end
22
21
 
22
+ # call all anonymous hooks
23
+ PluginRoutes.get_anonymous_hooks(hook_key).each do |_hook|
24
+ _hook.call(params)
25
+ end
26
+ end
27
+
23
28
  # skip hook function with name: hook_function_name
24
29
  def hook_skip(hook_function_name)
25
30
  @_hooks_skip << hook_function_name
@@ -11,7 +11,7 @@ module CamaleonCms::SiteHelper
11
11
  host << request.subdomain if request.subdomain.present?
12
12
  site = CamaleonCms::Site.where(slug: host).first.decorate rescue nil
13
13
  end
14
- r = {site: site, request: request};
14
+ r = {site: site, request: (request rescue nil)};
15
15
  cama_current_site_helper(r) rescue nil
16
16
  Rails.logger.error 'Camaleon CMS - Please define your current site: $current_site = CamaleonCms::Site.first.decorate or map your domains: http://camaleon.tuzitio.com/documentation/category/139779-examples/how.html'.cama_log_style(:red) if !r[:site].present?
17
17
  @current_site = r[:site]
@@ -1,5 +1,6 @@
1
1
  module CamaleonCms::UploaderHelper
2
2
  include ActionView::Helpers::NumberHelper
3
+ include CamaleonCms::CamaleonHelper
3
4
  # upload a file into server
4
5
  # settings:
5
6
  # folder: Directory where the file will be saved (default: "")
@@ -21,7 +22,7 @@ module CamaleonCms::UploaderHelper
21
22
  def upload_file(uploaded_io, settings = {})
22
23
  cached_name = uploaded_io.is_a?(ActionDispatch::Http::UploadedFile) ? uploaded_io.original_filename : nil
23
24
  return {error: "File is empty", file: nil, size: nil} unless uploaded_io.present?
24
- if uploaded_io.is_a?(String) && (uploaded_io.start_with?("http://") || uploaded_io.start_with?("https://")) # download url file
25
+ if uploaded_io.is_a?(String) && uploaded_io.match(/^https?:\/\//).present? # download url file
25
26
  tmp = cama_tmp_upload(uploaded_io)
26
27
  return tmp if tmp[:error].present?
27
28
  settings[:remove_source] = true
@@ -58,22 +59,21 @@ module CamaleonCms::UploaderHelper
58
59
  end
59
60
  # save file
60
61
  key = File.join(settings[:folder], settings[:filename]).to_s.cama_fix_slash
61
- res = cama_uploader.add_file(uploaded_io, key, {same_name: settings[:same_name]})
62
+ res = cama_uploader.add_file(settings[:uploaded_io], key, {same_name: settings[:same_name]})
62
63
  {} if settings[:temporal_time] > 0 # temporal file upload (always put as local for temporal files) (TODO: use delayjob)
63
64
 
64
65
  # generate image versions
65
- if res['format'] == 'image'
66
+ if res['file_type'] == 'image'
66
67
  settings[:versions].to_s.gsub(' ', '').split(',').each do |v|
67
- version_path = cama_resize_upload(uploaded_io.path, v, {replace: false})
68
+ version_path = cama_resize_upload(settings[:uploaded_io].path, v, {replace: false})
68
69
  cama_uploader.add_file(version_path, cama_uploader.version_path(res['key'], v), is_thumb: true, same_name: true)
69
70
  FileUtils.rm_f(version_path)
70
71
  end
71
72
  end
72
73
 
73
74
  # generate thumb
74
- cama_uploader_generate_thumbnail(uploaded_io.path, res['key'], settings[:thumb_size]) if settings[:generate_thumb] && res['thumb'].present?
75
-
76
- FileUtils.rm_f(uploaded_io.path) if settings[:remove_source]
75
+ cama_uploader_generate_thumbnail(uploaded_io.path, res['key'], settings[:thumb_size], settings[:remove_source]) if settings[:generate_thumb] && res['thumb'].present?
76
+ FileUtils.rm_f(uploaded_io.path) if File.exist?(uploaded_io.path) if settings[:remove_source]
77
77
 
78
78
  hooks_run('after_upload', settings)
79
79
  res
@@ -82,13 +82,13 @@ module CamaleonCms::UploaderHelper
82
82
  # generate thumbnail of a existent image
83
83
  # key: key of the current file
84
84
  # the thumbnail will be saved in my_images/my_img.png => my_images/thumb/my_img.png
85
- def cama_uploader_generate_thumbnail(uploaded_io, key, thumb_size = nil)
85
+ def cama_uploader_generate_thumbnail(uploaded_io, key, thumb_size = nil, remove_source = false)
86
86
  w, h = cama_uploader.thumb[:w], cama_uploader.thumb[:h]
87
87
  w, h = thumb_size.split('x') if thumb_size.present?
88
88
  uploaded_io = File.open(uploaded_io) if uploaded_io.is_a?(String)
89
89
  path_thumb = cama_resize_and_crop(uploaded_io.path, w, h)
90
- thumb = cama_uploader.add_file(path_thumb, cama_uploader.version_path(key), is_thumb: true, same_name: true)
91
- FileUtils.rm_f(path_thumb)
90
+ thumb = cama_uploader.add_file(path_thumb, cama_uploader.version_path(key).sub('.svg', '.jpg'), is_thumb: true, same_name: true)
91
+ FileUtils.rm_f(path_thumb) if remove_source
92
92
  thumb
93
93
  end
94
94
 
@@ -133,24 +133,26 @@ module CamaleonCms::UploaderHelper
133
133
  def cama_crop_image(file_path, w=nil, h=nil, w_offset = 0, h_offset = 0, resize = false , replace = true)
134
134
  force = ""
135
135
  force = "!" if w.present? && h.present? && !w.include?("?") && !h.include?("?")
136
- image = MiniMagick::Image.open(file_path)
137
- w = image[:width].to_f > w.sub('?', '').to_i ? w.sub('?', "") : image[:width] if w.present? && w.to_s.include?('?')
138
- h = image[:height].to_f > h.sub('?', '').to_i ? h.sub('?', "") : image[:height] if h.present? && h.to_s.include?('?')
139
- image.combine_options do |i|
140
- i.resize("#{w if w.present?}x#{h if h.present?}#{force}") if resize
141
- i.crop "#{w if w.present?}x#{h if h.present?}+#{w_offset}+#{h_offset}#{force}" unless resize
136
+ img = MiniMagick::Image.open(file_path)
137
+ w = img[:width].to_f > w.sub('?', '').to_i ? w.sub('?', "") : img[:width] if w.present? && w.to_s.include?('?')
138
+ h = img[:height].to_f > h.sub('?', '').to_i ? h.sub('?', "") : img[:height] if h.present? && h.to_s.include?('?')
139
+ data = {img: img, w: w, h: h, w_offset: w_offset, h_offset: h_offset, resize: resize, replace: replace}; hooks_run("before_crop_image", data)
140
+ data[:img].combine_options do |i|
141
+ i.resize("#{w if w.present?}x#{h if h.present?}#{force}") if data[:resize]
142
+ i.crop "#{w if w.present?}x#{h if h.present?}+#{w_offset}+#{h_offset}#{force}" unless data[:resize]
142
143
  end
143
144
 
144
145
  res = file_path
145
- unless replace
146
+ unless data[:replace]
146
147
  ext = File.extname(file_path)
147
148
  res = file_path.gsub(ext, "_crop#{ext}")
148
149
  end
149
- image.write res
150
+ data[:img].write res
150
151
  res
151
152
  end
152
153
 
153
154
  # resize and crop a file
155
+ # SVGs are converted to JPEGs for editing
154
156
  # Params:
155
157
  # file: (String) File path
156
158
  # w: (Integer) width
@@ -164,6 +166,11 @@ module CamaleonCms::UploaderHelper
164
166
  def cama_resize_and_crop(file, w, h, settings = {})
165
167
  settings = {gravity: :north_east, overwrite: true, output_name: ""}.merge(settings)
166
168
  img = MiniMagick::Image.open(file)
169
+ if file.end_with? '.svg'
170
+ img.format 'jpg'
171
+ file.sub! '.svg', '.jpg'
172
+ settings[:output_name].sub!('.svg', '.jpg') if settings[:output_name]
173
+ end
167
174
  w = img[:width].to_f > w.sub('?', '').to_i ? w.sub('?', "") : img[:width] if w.present? && w.to_s.include?('?')
168
175
  h = img[:height].to_f > h.sub('?', '').to_i ? h.sub('?', "") : img[:height] if h.present? && h.to_s.include?('?')
169
176
  w_original, h_original = [img[:width].to_f, img[:height].to_f]
@@ -181,19 +188,21 @@ module CamaleonCms::UploaderHelper
181
188
  h_result = h
182
189
  end
183
190
 
184
- w_offset, h_offset = cama_crop_offsets_by_gravity(settings[:gravity], [w_result, h_result], [ w, h])
185
- img.combine_options do |i|
186
- i.resize(op_resize)
191
+ w_offset, h_offset = cama_crop_offsets_by_gravity(settings[:gravity], [w_result, h_result], [w, h])
192
+ data = {img: img, w: w, h: h, w_offset: w_offset, h_offset: h_offset, op_resize: op_resize, settings: settings}; hooks_run("before_resize_crop", data)
193
+ data[:img].combine_options do |i|
194
+ i.resize(data[:op_resize])
187
195
  i.gravity(settings[:gravity])
188
- i.crop "#{w.to_i}x#{h.to_i}+#{w_offset}+#{h_offset}!"
196
+ i.crop "#{data[:w].to_i}x#{data[:h].to_i}+#{data[:w_offset]}+#{data[:h_offset]}!"
189
197
  end
190
198
 
191
- img.write(file) if settings[:overwrite]
192
- unless settings[:overwrite]
199
+ if settings[:overwrite]
200
+ data[:img].write(file.sub '.svg', '.jpg')
201
+ else
193
202
  if settings[:output_name].present?
194
- img.write(file = File.join(File.dirname(file), settings[:output_name]).to_s)
203
+ data[:img].write(file = File.join(File.dirname(file), settings[:output_name]).to_s)
195
204
  else
196
- img.write(file = uploader_verify_name(File.join(File.dirname(file), "crop_#{File.basename(file)}")))
205
+ data[:img].write(file = uploader_verify_name(File.join(File.dirname(file), "crop_#{File.basename(file.sub '.svg', '.jpg')}")))
197
206
  end
198
207
  end
199
208
  file
@@ -271,7 +280,7 @@ module CamaleonCms::UploaderHelper
271
280
  }
272
281
  hooks_run("on_uploader", args)
273
282
  return args[:custom_uploader] if args[:custom_uploader].present?
274
-
283
+
275
284
  case args[:server]
276
285
  when 's3', 'aws'
277
286
  CamaleonCmsAwsUploader.new({current_site: current_site, thumb: args[:thumb], aws_settings: args[:aws_settings]}, self)