Class: CamaleonCms::Admin::MediaController
- Inherits:
-
CamaleonCms::AdminController
- Object
- ApplicationController
- CamaleonController
- CamaleonCms::AdminController
- CamaleonCms::Admin::MediaController
- Defined in:
- app/controllers/camaleon_cms/admin/media_controller.rb
Constant Summary
Constants included from UploaderHelper
UploaderHelper::SUSPICIOUS_PATTERNS
Instance Method Summary collapse
-
#actions ⇒ Object
do background actions in fog.
-
#ajax ⇒ Object
render media for modal content.
-
#crop ⇒ Object
crop a image to save as a new file.
-
#download_private_file ⇒ Object
download private files.
-
#index ⇒ Object
render media section.
-
#upload(settings = {}) ⇒ Object
upload files from media uploader.
Methods inherited from CamaleonCms::AdminController
Methods included from ApplicationHelper
#cama_do_pagination, #cama_get_i18n_frontend, #cama_shortcode_print
Methods included from CustomFieldsHelper
#cama_custom_field_elements, #cf_add_model
Methods included from CategoryHelper
#cama_category_get_options_html
Methods included from PostTypeHelper
#cama_hierarchy_post_list, #post_type_html_inputs, #post_type_list_taxonomy, #post_type_status
Methods included from MenusHelper
#admin_menu_add_menu, #admin_menu_append_menu_item, #admin_menu_draw, #admin_menu_insert_menu_after, #admin_menu_insert_menu_before, #admin_menu_prepend_menu_item, #admin_menus_add_commons
Methods included from BreadcrumbHelper
#admin_breadcrumb_add, #cama_admin_title_draw
Methods inherited from CamaleonController
Methods included from EmailHelper
#cama_send_email, #cama_send_mail_to_admin, #send_email, #send_password_reset_email, #send_user_confirm_email
Methods included from HooksHelper
#hook_run, #hook_skip, #hooks_run
Methods included from PluginsHelper
#current_plugin, #plugin_asset_path, #plugin_asset_url, #plugin_destroy, #plugin_install, #plugin_layout, #plugin_load_helpers, #plugin_uninstall, #plugin_upgrade, #plugin_view, #plugins_initialize, #self_plugin_key
Methods included from SiteHelper
#cama_current_site_host_port, #cama_get_list_layouts_files, #cama_get_list_template_files, #cama_is_test_request?, #current_locale, #current_site, #current_theme, #site_after_install, #site_install_theme, #site_uninstall_theme
Methods included from UploaderHelper
#cama_crop_image, #cama_file_path_to_url, #cama_resize_and_crop, #cama_resize_upload, #cama_tmp_upload, #cama_uploader, #cama_uploader_generate_thumbnail, #cama_url_to_file_path, #slugify, #slugify_folder, #upload_file, #uploader_verify_name
Methods included from CamaleonHelper
#cama_cache_fetch, #cama_draw_timer, #cama_edit_link, #cama_is_admin_request?, #cama_pluralize_text, #cama_requestAction, #cama_sitemap_cats_generator, #cama_t, #ct
Methods included from CaptchaHelper
#cama_captcha_build, #cama_captcha_increment_attack, #cama_captcha_reset_attack, #cama_captcha_tag, #cama_captcha_tags_if_under_attack, #cama_captcha_total_attacks, #cama_captcha_under_attack?, #cama_captcha_verified?, #captcha_verify_if_under_attack
Methods included from ContentHelper
#cama_content_after_draw, #cama_content_append, #cama_content_before_draw, #cama_content_init, #cama_content_prepend
Methods included from ThemeHelper
#self_theme_key, #theme_asset_file_path, #theme_asset_path, #theme_asset_url, #theme_home_page, #theme_init, #theme_layout, #theme_view
Methods included from ShortCodeHelper
#cama_strip_shortcodes, #do_shortcode, #render_shortcode, #shortcode_add, #shortcode_change_template, #shortcode_delete, #shortcodes_init
Methods included from UserRolesHelper
Methods included from HtmlHelper
#append_asset_content, #append_asset_libraries, #append_pre_asset_content, #cama_assets_library_register, #cama_draw_custom_assets, #cama_draw_pre_asset_contents, #cama_get_options_html_from_items, #cama_html_helpers_init, #cama_html_tooltip, #cama_load_libraries
Methods included from SessionHelper
#cama_authenticate, #cama_current_role, #cama_current_user, #cama_get_session_id, #cama_logout_user, #cama_on_heroku?, #cama_register_user, #cama_sign_in?, #cookie_auth_token_complete?, #cookie_split_auth_token, #login_user, #login_user_with_password, #session_back_to_parent, #session_switch_user, #user_auth_token_from_cookie
Instance Method Details
#actions ⇒ Object
do background actions in fog
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'app/controllers/camaleon_cms/admin/media_controller.rb', line 53 def actions :manage, :media if params[:media_action] != 'crop_url' params[:folder] = params[:folder].gsub('//', '/') if params[:folder].present? case params[:media_action] when 'new_folder' params[:folder] = slugify_folder(params[:folder]) r = cama_uploader.add_folder(params[:folder]) return render partial: 'render_file_item', locals: { files: [r] } if r[:error].blank? when 'del_folder' r = cama_uploader.delete_folder(params[:folder]) when 'del_file' r = cama_uploader.delete_file(params[:folder].gsub('//', '/')) when 'crop_url' user_url = params[:url].to_s user_url = "#{current_site.the_url(locale: nil)}#{user_url}" unless user_url.start_with?('data:', 'http') url_validation_result = UserUrlValidator.validate(user_url) r = if url_validation_result.is_a?(Array) { error: url_validation_result.join(', ') } else cama_tmp_upload(user_url, formats: params[:formats], name: params[:name]) end if r[:error].blank? params[:file_upload] = r[:file_path] sett = { remove_source: true } sett[:same_name] = true if params[:same_name].present? sett[:name] = params[:name] if params[:name].present? return upload(sett) end end return render plain: helpers.sanitize(r[:error]) if r[:error].present? render plain: '' end |
#ajax ⇒ Object
render media for modal content
39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'app/controllers/camaleon_cms/admin/media_controller.rb', line 39 def ajax @show_file_actions = true if current_site.get_option('file_actions_in_modals') == 'yes' @tree = cama_uploader.search(params[:search]) if params[:search].present? @files = @tree.paginate(page: params[:page], per_page: 100) @next_page = @files.current_page < @files.total_pages ? @files.current_page + 1 : nil if params[:partial].present? render json: { next_page: @next_page, html: render_to_string(partial: 'render_file_item', locals: { files: @files }) } else render 'index', layout: false unless params[:partial].present? end end |
#crop ⇒ Object
crop a image to save as a new file
19 20 21 22 23 24 25 |
# File 'app/controllers/camaleon_cms/admin/media_controller.rb', line 19 def crop path_image = cama_tmp_upload(params[:cp_img_path])[:file_path] crop_path = cama_crop_image(path_image, params[:ic_w], params[:ic_h], params[:ic_x], params[:ic_y]) res = upload_file(crop_path, { remove_source: true }) CamaleonCms::User.find(params[:saved_avatar]).('avatar', res['url']) if params[:saved_avatar].present? render html: res['url'].html_safe end |
#download_private_file ⇒ Object
download private files
28 29 30 31 32 33 34 35 36 |
# File 'app/controllers/camaleon_cms/admin/media_controller.rb', line 28 def download_private_file cama_uploader.enable_private_mode! file = cama_uploader.fetch_file("private/#{params[:file]}") return render plain: helpers.sanitize(file[:error]) if file.is_a?(Hash) && file[:error].present? send_file file, disposition: 'inline' end |
#index ⇒ Object
render media section
10 11 12 13 14 15 16 |
# File 'app/controllers/camaleon_cms/admin/media_controller.rb', line 10 def index :manage, :media @show_file_actions = true @files = @tree.paginate(page: params[:page], per_page: 100) @next_page = @files.current_page < @files.total_pages ? @files.current_page + 1 : nil I18n.t('camaleon_cms.admin.sidebar.media') end |
#upload(settings = {}) ⇒ Object
upload files from media uploader
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'app/controllers/camaleon_cms/admin/media_controller.rb', line 90 def upload(settings = {}) params[:dimension] = nil if params[:skip_auto_crop].present? f = { error: 'File not found.' } if params[:file_upload].present? f = upload_file(params[:file_upload], { folder: params[:folder], dimension: params['dimension'], formats: params[:formats], versions: params[:versions], thumb_size: params[:thumb_size] }.merge(settings)) end if f[:error].present? render plain: helpers.sanitize(f[:error]) else render partial: 'render_file_item', locals: { files: [f] } end end |