Module: IqFckeditor::Controller

Extended by:
ActiveSupport::Concern
Included in:
SimpleFckUploadController
Defined in:
lib/iq_fckeditor.rb

Overview

Include as InstanceMethods into the acts_as_fckeditor_file_provider

Constant Summary collapse

MIME_TYPES =

accepted MIME types for upload

[
  "text/comma-separated-values",
  "text/csv",
  "application/vnd.ms-excel",
  "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
  "image/jpeg",
  "image/pjpeg",
  "image/gif",
  "image/png",
  "application/pdf",
  "application/zip",
  "application/x-shockwave-flash",
  "application/octet-stream" #TODO: Muss weg!
]

Instance Method Summary collapse

Instance Method Details

#fckeditor_commandObject

Executes some server side commands the js client side calls:

GetFoldersAndFiles, GetFolders (2.times{GET})
CreateFolder (GET)
FileUpload (POST)

These operations are addessed by parameters:

fckeditor_command?Command=<command>

I found no way to configure this in the FCK javascriptside. Also the GETs on modifications realy suck. If you find a way to modify this: please tell me how you did it.



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/iq_fckeditor.rb', line 107

def fckeditor_command
  case params[:Command]
  when 'GetFoldersAndFiles', 'GetFolders'
    respond_to do |format|
      format.xml do
        fckeditor_get_folders_and_files(params[:Command] == 'GetFoldersAndFiles')
      end
    end
  when 'CreateFolder'
    respond_to do |format|
      format.xml do
        fckeditor_create_folder
      end
    end
  when 'FileUpload'
    respond_to do |format|
      format.html do
        fckeditor_upload
      end
    end
  else
    if (params[:NewFile])
      fckeditor_upload
    else
      head 404
    end
  end
end

#fckeditor_custom_configObject

Generates a config providing urls for the plugin. This is the hook to provide different fck configs for different resources



49
50
51
52
53
54
55
56
# File 'lib/iq_fckeditor.rb', line 49

def fckeditor_custom_config
  respond_to do |format|
    @command_url = self.fckeditor_command_action_url || url_for_action("fckeditor_command")
    format.js do
      render :template => 'iq_fckeditor/custom_config', :layout => false
    end
  end
end

#fckeditor_directoryObject

This is a resource based variant of fckeditor_command?Command=GetFoldersAndFiles



90
91
92
93
94
95
96
# File 'lib/iq_fckeditor.rb', line 90

def fckeditor_directory
  respond_to do |format|
    format.xml do
      fckeditor_get_folders_and_files(true)
    end
  end
end

#fckeditor_fileObject

Accessor to the uploaded files. E.g. an image will have the path:

<controller resource path>/fckeditor_file?file=<path and filename>


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 'lib/iq_fckeditor.rb', line 60

def fckeditor_file
  if (params[:file])
    dir, url_to_dir = fckeditor_base_dir_and_url
    path = append_path dir, params[:file]
    if FileTest.file?(path)
      if (params[:thumb] =~ /^[1-9][0-9][0-9]?$/) # 10 - 999
        ext = File.extname(path)
        thumb_path = File.join(File.dirname(path), '.thumbs', File.basename(path, ext)) + ".#{params[:thumb]}#{ext}"
        if !(FileTest.file?(thumb_path))
          FileUtils.mkdir(File.dirname(thumb_path)) unless File.directory?(File.dirname(thumb_path))
          tmp = Paperclip::Thumbnail.new(File.new(path), :geometry => "#{params[:thumb]}x#{params[:thumb]}>").make
          FileUtils.mv(tmp.path, thumb_path)
          tmp.unlink
        end
        path = thumb_path
      end
      if stale?(:last_modified => File.mtime(path).utc)
        if stale?(:etag => Digest::MD5.hexdigest(File.read(path))) #Only calc checksum if :last_modified 'failes'
          send_file(path, :type => Mime::Type.lookup_by_extension(File.extname(path)), :disposition => 'inline') #Finally send the file
        end
      end
    else
      head 404
    end
  else
    head 404
  end
end