filemanager 0.1.0 → 0.3.1

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 (73) hide show
  1. data/CHANGELOG +23 -1
  2. data/README.zh_CN +32 -0
  3. data/Rakefile +3 -3
  4. data/{rails → filemanager}/app/views/fm/filemanager/index.html.erb +9 -9
  5. data/{rails → filemanager}/app/views/fm/filemanager/view.html.erb +1 -1
  6. data/{rails/config → filemanager}/filemanager.yml +2 -2
  7. data/lib/filemanager/controller.rb +205 -185
  8. data/lib/filemanager.rb +51 -59
  9. metadata +127 -127
  10. data/README +0 -32
  11. data/rails/app/helpers/fm/filemanager_helper.rb +0 -61
  12. /data/{rails → filemanager}/app/controllers/fm/filemanager_controller.rb +0 -0
  13. /data/{rails → filemanager}/public/filemanager/images/avi.gif +0 -0
  14. /data/{rails → filemanager}/public/filemanager/images/box.gif +0 -0
  15. /data/{rails → filemanager}/public/filemanager/images/bullet.gif +0 -0
  16. /data/{rails → filemanager}/public/filemanager/images/close.gif +0 -0
  17. /data/{rails → filemanager}/public/filemanager/images/closelabel.gif +0 -0
  18. /data/{rails → filemanager}/public/filemanager/images/doc.gif +0 -0
  19. /data/{rails → filemanager}/public/filemanager/images/donate-button.gif +0 -0
  20. /data/{rails → filemanager}/public/filemanager/images/download-icon.gif +0 -0
  21. /data/{rails → filemanager}/public/filemanager/images/folder.gif +0 -0
  22. /data/{rails → filemanager}/public/filemanager/images/gif.gif +0 -0
  23. /data/{rails → filemanager}/public/filemanager/images/htm.gif +0 -0
  24. /data/{rails → filemanager}/public/filemanager/images/html.gif +0 -0
  25. /data/{rails → filemanager}/public/filemanager/images/image-1.jpg +0 -0
  26. /data/{rails → filemanager}/public/filemanager/images/image.gif +0 -0
  27. /data/{rails → filemanager}/public/filemanager/images/jpg.gif +0 -0
  28. /data/{rails → filemanager}/public/filemanager/images/loading.gif +0 -0
  29. /data/{rails → filemanager}/public/filemanager/images/mov.gif +0 -0
  30. /data/{rails → filemanager}/public/filemanager/images/nextlabel.gif +0 -0
  31. /data/{rails → filemanager}/public/filemanager/images/pdf.gif +0 -0
  32. /data/{rails → filemanager}/public/filemanager/images/png.gif +0 -0
  33. /data/{rails → filemanager}/public/filemanager/images/ppt.gif +0 -0
  34. /data/{rails → filemanager}/public/filemanager/images/prevlabel.gif +0 -0
  35. /data/{rails → filemanager}/public/filemanager/images/rar.gif +0 -0
  36. /data/{rails → filemanager}/public/filemanager/images/rm.gif +0 -0
  37. /data/{rails → filemanager}/public/filemanager/images/rmvb.gif +0 -0
  38. /data/{rails → filemanager}/public/filemanager/images/separator.gif +0 -0
  39. /data/{rails → filemanager}/public/filemanager/images/spacer.gif +0 -0
  40. /data/{rails → filemanager}/public/filemanager/images/swf.gif +0 -0
  41. /data/{rails → filemanager}/public/filemanager/images/thumb-1.jpg +0 -0
  42. /data/{rails → filemanager}/public/filemanager/images/tool_copy.gif +0 -0
  43. /data/{rails → filemanager}/public/filemanager/images/tool_cut.gif +0 -0
  44. /data/{rails → filemanager}/public/filemanager/images/tool_del.gif +0 -0
  45. /data/{rails → filemanager}/public/filemanager/images/tool_folder.gif +0 -0
  46. /data/{rails → filemanager}/public/filemanager/images/tool_imagemanager.gif +0 -0
  47. /data/{rails → filemanager}/public/filemanager/images/tool_new.gif +0 -0
  48. /data/{rails → filemanager}/public/filemanager/images/tool_paste.gif +0 -0
  49. /data/{rails → filemanager}/public/filemanager/images/tool_props.gif +0 -0
  50. /data/{rails → filemanager}/public/filemanager/images/tool_refresh.gif +0 -0
  51. /data/{rails → filemanager}/public/filemanager/images/tool_unzip.gif +0 -0
  52. /data/{rails → filemanager}/public/filemanager/images/tool_upload.gif +0 -0
  53. /data/{rails → filemanager}/public/filemanager/images/tool_zip.gif +0 -0
  54. /data/{rails → filemanager}/public/filemanager/images/txt.gif +0 -0
  55. /data/{rails → filemanager}/public/filemanager/images/unknown.gif +0 -0
  56. /data/{rails → filemanager}/public/filemanager/images/wmv.gif +0 -0
  57. /data/{rails → filemanager}/public/filemanager/images/xls.gif +0 -0
  58. /data/{rails → filemanager}/public/filemanager/images/zip.gif +0 -0
  59. /data/{rails → filemanager}/public/filemanager/javascripts/builder.js +0 -0
  60. /data/{rails → filemanager}/public/filemanager/javascripts/effects.js +0 -0
  61. /data/{rails → filemanager}/public/filemanager/javascripts/filemanager.js +0 -0
  62. /data/{rails → filemanager}/public/filemanager/javascripts/lang/en.js +0 -0
  63. /data/{rails → filemanager}/public/filemanager/javascripts/lang/zh_CN.js +0 -0
  64. /data/{rails → filemanager}/public/filemanager/javascripts/lightbox.js +0 -0
  65. /data/{rails → filemanager}/public/filemanager/javascripts/prototype.js +0 -0
  66. /data/{rails → filemanager}/public/filemanager/javascripts/prototype_ext.js +0 -0
  67. /data/{rails → filemanager}/public/filemanager/javascripts/scriptaculous.js +0 -0
  68. /data/{rails → filemanager}/public/filemanager/javascripts/translate.js +0 -0
  69. /data/{rails/public/fm_resources → filemanager/public/filemanager/resources}/resources.txt +0 -0
  70. /data/{rails → filemanager}/public/filemanager/stylesheets/filelist.css +0 -0
  71. /data/{rails → filemanager}/public/filemanager/stylesheets/general.css +0 -0
  72. /data/{rails → filemanager}/public/filemanager/stylesheets/lightbox.css +0 -0
  73. /data/{rails/fm_temp → filemanager/temp}/temp +0 -0
data/CHANGELOG CHANGED
@@ -1,3 +1,25 @@
1
+ Changes in version 0.3.1 (2009-4-14)
2
+ fix bugs about config file's location
3
+
4
+ Changes in version 0.3.0 (2009-2-19)
5
+ support rails 2.3
6
+
7
+ Changes in version 0.2.2 (2008-11-25)
8
+ -------------------------------------
9
+ fix a bug due to miss dependency "uri"
10
+
11
+ Changes in version 0.2.1 (2008-07-10)
12
+ -------------------------------------
13
+ support rails 2.1
14
+
15
+ Changes in version 0.2.0 (2008-05-20)
16
+ -------------------------------------
17
+ refactory for folder structure, don't copy files to app
18
+
19
+ Changes in version 0.1.1 (2008-05-19)
20
+ -------------------------------------
21
+ fix a bug about sub-directories' number
22
+
1
23
  Changes in version 0.1.0 (2008-05-18)
2
24
  -------------------------------------
3
- initial release
25
+ initial release
data/README.zh_CN ADDED
@@ -0,0 +1,32 @@
1
+ Filemanager, release 0.2.2 (Nov. 2008)
2
+ Rails��Ŀ�������ļ�������
3
+
4
+ ����
5
+ =======
6
+ 1. �ļ���Ŀ¼����������ƣ����У�ճ������������ɾ���������ȹ���
7
+ 2. ��ѹzip�ļ�
8
+ 3. ѹ��������ָ���Ķ���ļ���Ŀ¼
9
+ 4. �ϴ��ļ�
10
+ 5. �����ļ���ʽ�鿴�ļ�
11
+ 6. �ļ���Ŀ¼�����ʻ���ҳ���������ʻ�
12
+
13
+ ����
14
+ =======
15
+ #������������environment.rb����
16
+
17
+ $FM_OVERWRITE = true
18
+ require 'filemanager'
19
+
20
+ #ע��: �������Ҫ��������Ŀ�ж�Filemanager�ĸı䣬�����ɾ��$FM_OVERWRITE��һ��
21
+ #��ͬʱҲ�ᵼ��Filemanager����ʱijЩ������ܷ������ã�����Ը�����Ҫ����$FM_OVERWRITE���趨
22
+
23
+ ʹ��
24
+ =======
25
+ ����rails����� http://localhost:3000/fm/filemanager
26
+ �������ܶ��������Ҽ��˵���
27
+
28
+ ����������� "RAILS_ROOT/confile/filemanager.yml"
29
+ Ĭ�ϵĹ���Ŀ¼�� "RAILS_ROOT/public/fm_resources"
30
+ ҳ������i18n�� "RAILS_ROOT/public/filemanager/javascripts/lang"
31
+
32
+ Copyright (c) 2008 Leon Li, released under the MIT license
data/Rakefile CHANGED
@@ -1,12 +1,12 @@
1
1
  require 'rubygems'
2
2
  require 'rake/gempackagetask'
3
3
  PKG_NAME = "filemanager"
4
- PKG_VERSION = "0.1.0"
4
+ PKG_VERSION = "0.3.1"
5
5
  PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}"
6
6
  PKG_FILES = FileList[
7
7
  '[A-Z]*',
8
8
  'lib/**/*',
9
- 'rails/**/*'
9
+ 'filemanager/**/*'
10
10
  ]
11
11
  spec = Gem::Specification.new do |s|
12
12
  s.platform = Gem::Platform::RUBY
@@ -27,4 +27,4 @@ end
27
27
  Rake::GemPackageTask.new(spec) do |pkg|
28
28
  pkg.need_zip = true
29
29
  pkg.need_tar = true
30
- end
30
+ end
@@ -151,13 +151,13 @@ background-color:#039;
151
151
  <td class=filelistheadcol id=fmodcol1 nowrap width="2%" align="center"> <span fmLang="modification_date">Modification Date</span> </td>
152
152
  </tr>
153
153
  <%
154
- path = encode(@path)
154
+ path = @controller.encode(@path)
155
155
  unless @parent_path.nil?
156
156
  %>
157
157
  <tr class=filelistroweven>
158
158
  <td width=1></td>
159
159
  <td><a onmousedown="return false;" href="#"><img class="" title=directory height=16 alt=directory src="/filemanager/images/folder.gif" width=16 border=0></a></td>
160
- <td class=filelistfilename><a onmousedown="return false;" href="?path=<%= encode(@parent_path) %>">..</a></td>
160
+ <td class=filelistfilename><a onmousedown="return false;" href="?path=<%= @controller.encode(@parent_path) %>">..</a></td>
161
161
  <td nowrap></td>
162
162
  <td nowrap><%= File.ctime(@resource_path + @parent_path).strftime("%Y-%m-%d %H:%M:%S") %></td>
163
163
  </tr>
@@ -167,7 +167,7 @@ background-color:#039;
167
167
  @directories.each do |i|
168
168
  next if i == '.' || i == '..'
169
169
  old_i = i
170
- i = encode(i)
170
+ i = @controller.encode(i)
171
171
  %>
172
172
  <tr class=filelistroweven id="tr_<%= i %>">
173
173
  <td width=1><input onclick="triggerselect(this)" type="checkbox" name="fileCheck" value="<%= i %>"></td>
@@ -185,15 +185,15 @@ background-color:#039;
185
185
  unless @files.nil?
186
186
  @files.each do |i|
187
187
  old_i = i
188
- i = encode(i)
188
+ i = @controller.encode(i)
189
189
  %>
190
190
  <tr class=filelistroweven id="tr_<%= i %>">
191
191
  <td width=1><input onclick="triggerselect(this)" type="checkbox" name="fileCheck" value="<%= i %>"></td>
192
- <td><a onmousedown="return false;" name="<%= i %>"></a><a href="#"><img class="" height=16 src="/filemanager/images/<%= get_file_type(i) %>.gif" width=16 border=0></a></td>
192
+ <td><a onmousedown="return false;" name="<%= i %>"></a><a href="#"><img class="" height=16 src="/filemanager/images/<%= @controller.get_file_type(i) %>.gif" width=16 border=0></a></td>
193
193
  <td class=filelistfilename>
194
194
  <a id="context_file_<%= i %>" title="<%= path + '/' + i %>" href="javascript:ajaxLink('/fm/filemanager/view?path=<%= path + '/' + i %>', 'view', 'none');" onmousedown="hideMenu();" onclick="showControl('<%= path + '/' + i %>')" ><%= i %></a>
195
195
  </td>
196
- <td nowrap><%= hsize(File.size(@current_path + '/' + old_i).to_f) %></td>
196
+ <td nowrap><%= @controller.hsize(File.size(@current_path + '/' + old_i).to_f) %></td>
197
197
  <td nowrap><%= File.ctime(@current_path + '/' + old_i).strftime("%Y-%m-%d %H:%M:%S") %></td>
198
198
  </tr>
199
199
  <%
@@ -209,11 +209,11 @@ background-color:#039;
209
209
  <legend align=left><span fmLang="directory_information">Directory Information</span></legend>
210
210
  <div style="margin: 2px; overflow: hidden; width: 100%">
211
211
  <div class=previewsubtitle><span fmLang="directory_name">Directory Name</span></div>
212
- <div class=previewtext><%= encode(File.basename(@current_path)) %></div>
212
+ <div class=previewtext><%= @controller.encode(File.basename(@current_path)) %></div>
213
213
  </div>
214
214
  <div style="float: left; margin: 2px; width: 45%">
215
215
  <div class=previewsubtitle><span fmLang="sub_directories">Sub-directories</span>:</div>
216
- <div class=previewtext><%= @directories.size %></div>
216
+ <div class=previewtext><%= @directories.size - 2 %></div>
217
217
  <div class=previewsubtitle><span fmLang="modification_date">Modification Date</span>:</div>
218
218
  <div class=previewtext><%= File.ctime(@current_path).strftime("%Y-%m-%d %H:%M:%S") %></div>
219
219
  </div>
@@ -221,7 +221,7 @@ background-color:#039;
221
221
  <div class=previewsubtitle><span fmLang="files">Files</span>:</div>
222
222
  <div class=previewtext><%= @files.size %></div>
223
223
  <div class=previewsubtitle><span fmLang="file_total_size">File Total Size</span>:</div>
224
- <div class=previewtext><%= hsize(@file_total_size) %></div>
224
+ <div class=previewtext><%= @controller.hsize(@file_total_size) %></div>
225
225
 
226
226
  </div>
227
227
  <br style="clear: both">
@@ -1,6 +1,6 @@
1
1
  <%
2
2
  randome_key = Time.new.to_i
3
- path = @lock_path + encode(@path) + '?' + randome_key.to_s
3
+ path = @lock_path + @controller.encode(@path) + '?' + randome_key.to_s
4
4
  if @controller.is_image?
5
5
  %>
6
6
 
@@ -9,8 +9,8 @@ excel.type: xls xla ods
9
9
  ppt.type: ppt pps ppz pot
10
10
  help.type: hlp chm
11
11
  none.type: rar zip
12
- resources.url: /fm_resources
13
- resources.path: <%= RAILS_ROOT %>/public/fm_resources
12
+ resources.url: /filemanager/resources
13
+ resources.path: <%= RAILS_ROOT %>/public/filemanager/resources
14
14
  encoding.to: UTF-8
15
15
  encoding.from:
16
16
  temp.dir:
@@ -8,190 +8,210 @@
8
8
  module Filemanager
9
9
  module Controller
10
10
  def set_up
11
- @lock_path = FM_LOCK_PATH
12
- @source = params[:source]
13
- @source = decode(@source) unless @source.nil?
14
- @path = (params[:path].nil? || ! params[:path].index('..').nil?) ? '' : params[:path]
15
- @path = '' if @path == '/'
16
- @path = decode(@path)
17
- @resource_path = FM_RESOURCES_PATH
18
- @current_path = @resource_path + @path
19
- @current_file = (File.directory?(@current_path) ? Dir.new(@current_path) : File.new(@current_path))
20
- @parent_path = (!@path.blank? && !@path.rindex('/').nil?) ? (@path.rindex('/') == 0 ? '/' : @path[0..(@path.rindex('/')-1)]) : nil
21
- @path_suffix = @path.index('.').nil? || @path[-1] == '.' ? '' : @path[@path.index('.')+1..-1]
22
- if File.directory?(@current_path)
23
- @all_files = Dir.entries(@current_path)
24
- @directories = @all_files.map{|f| File.directory?(@current_path + File::SEPARATOR + f) ? f : nil}.compact
25
- @files = @all_files.map{|f| File.directory?(@current_path + File::SEPARATOR + f) ? nil : f}.compact
26
- @file_total_size = @files.inject(0){|size, f| size + File.size(@current_path + File::SEPARATOR + f)}
27
- end
28
- end
29
-
30
- def tear_off
31
- @current_file.close unless @current_file.nil?
32
- end
33
-
34
- def index
35
-
36
- end
37
-
38
- def view
39
- # respond_to do |wants|
40
- # wants.js { render :text => File.size(@current_path) > 1000000 ? 'File too big' : File.read(@current_path) }
41
- # end
42
- end
43
-
44
- def file_content
45
- File.size(@current_path) > 1000000 ? 'File too big' : File.read(@current_path)
46
- end
47
-
48
- # def office
49
- # render :action=>'excel' if is_excel?
50
- # render :action=>'word' if is_word?
51
- # render :action=>'ppt' if is_ppt?
52
- # render :action=>'help' if is_help?
53
- # end
54
-
55
- def rename
56
- old_name = @current_path + File::SEPARATOR + decode(params[:old_name])
57
- new_name = @current_path + File::SEPARATOR + decode(params[:new_name])
58
- File.rename(old_name, new_name)
59
- success
60
- end
61
-
62
- def remove
63
- FileUtils.rm_rf(@source.map{|s| @current_path + File::SEPARATOR + s})
64
- success
65
- end
66
-
67
- def new_file
68
- File.new(@current_path + File::SEPARATOR + decode(params[:new_name]), 'w')
69
- success
70
- end
71
-
72
- def new_folder
73
- Dir.mkdir(@current_path + File::SEPARATOR + decode(params[:new_name]))
74
- success
75
- end
76
-
77
- def copy
78
- session[:source] = @source.map{|s| @current_path + File::SEPARATOR + s}
79
- session[:remove] = false
80
- success
81
- end
82
-
83
- def cut
84
- session[:source] = @source.map{|s| @current_path + File::SEPARATOR + s}
85
- session[:remove] = true
86
- success
87
- end
88
-
89
- def paste
90
- return error if session[:remove].nil? || session[:source].nil?
91
- begin
92
- session[:remove] == true ? FileUtils.mv(session[:source], @current_path) : FileUtils.cp_r(session[:source], @current_path)
93
- session[:remove] = nil
94
- session[:source] = nil
95
- success
96
- rescue => exception
97
- result(exception)
98
- end
99
-
100
- end
101
-
102
- def download
103
- now = Time.new
104
- now = "#{now.to_i}#{now.usec}"
105
- temp_file = FM_TEMP_DIR + File::SEPARATOR + now + '.zip'
106
- FileUtils.cd(@current_path) do |dir|
107
- system "zip -r #{temp_file} #{@source.map{|s| '"' + s + '"'}.join(' ')}"
108
- end
109
- send_file(temp_file)
110
- end
111
-
112
-
113
- def upload
114
- file = params[:upload]
115
- filename = decode(file.original_filename)
116
- File.open(@current_path + File::SEPARATOR + filename, "wb") do |f|
117
- f.write(file.read)
118
- end
119
- to_index
120
- end
121
-
122
-
123
-
124
- #TODO
125
- def adjust_size
126
-
127
- end
128
-
129
- #TODO
130
- def rotate
131
-
132
- end
133
-
134
- #TODO
135
- def unzip
136
- filename = decode(params[:old_name])
137
- FileUtils.cd(@current_path) do |dir|
138
- system "unzip -o #{filename}"
139
- end
140
- to_index
141
- end
142
-
143
- def to_index
144
- redirect_to :action => 'index', :path => encode(@path)
145
- end
146
-
147
- def success
148
- result("SUCCESS")
149
- end
150
-
151
- def error()
152
- result("ERROR")
153
- end
154
-
155
- def result(message)
156
- respond_to do |wants|
157
- wants.js { render :text => message }
158
- end
159
- end
160
-
161
- #methods for view
162
- def method_missing(method_id, *args)
163
- method_id_s = method_id.to_s
164
- if method_id_s[0, 3] == 'is_' && method_id_s[-1, 1] == '?'
165
- instance_eval %{
166
- def #{method_id}(*args)
167
- FM_#{method_id_s[3..-2].upcase}_TYPES.include?(@path_suffix)
168
- end
169
- }
170
- send(method_id, *args)
171
- else
172
- super
173
- end
174
- end
175
-
176
- def transfer(from, to, target)
177
- if FM_ENCODING_TO.nil?
178
- target
179
- else
180
- if target.is_a?(Array)
181
- target.map{|i| to.nil? ? i : Iconv.conv(to, from, i)}
182
- else
183
- Iconv.conv(to, from, target)
184
- end
185
- end
186
- end
187
-
188
- def encode(target)
189
- transfer(FM_ENCODING_FROM, FM_ENCODING_TO, target);
190
- end
191
-
192
- def decode(target)
193
- transfer(FM_ENCODING_TO, FM_ENCODING_FROM, target);
194
- end
195
-
11
+ @lock_path = FM_LOCK_PATH
12
+ @source = params[:source]
13
+ @source = decode(@source) unless @source.nil?
14
+ @path = (params[:path].nil? || ! params[:path].index('..').nil?) ? '' : params[:path]
15
+ @path = '' if @path == '/'
16
+ @path = decode(@path)
17
+ @resource_path = FM_RESOURCES_PATH
18
+ @current_path = @resource_path + @path
19
+ @current_file = (File.directory?(@current_path) ? Dir.new(@current_path) : File.new(@current_path))
20
+ @parent_path = (!@path.blank? && !@path.rindex('/').nil?) ? (@path.rindex('/') == 0 ? '/' : @path[0..(@path.rindex('/')-1)]) : nil
21
+ @path_suffix = @path.index('.').nil? || @path[-1] == '.' ? '' : @path[@path.index('.')+1..-1].downcase
22
+ if File.directory?(@current_path)
23
+ @all_files = Dir.entries(@current_path)
24
+ @directories = @all_files.map{|f| File.directory?(@current_path + File::SEPARATOR + f) ? f : nil}.compact
25
+ @files = @all_files.map{|f| File.directory?(@current_path + File::SEPARATOR + f) ? nil : f}.compact
26
+ @file_total_size = @files.inject(0){|size, f| size + File.size(@current_path + File::SEPARATOR + f)}
27
+ end
28
+ end
29
+
30
+ def tear_off
31
+ @current_file.close unless @current_file.nil?
32
+ end
33
+
34
+ def index
35
+
36
+ end
37
+
38
+ def view
39
+ # respond_to do |wants|
40
+ # wants.js { render :text => File.size(@current_path) > 1000000 ? 'File too big' : File.read(@current_path) }
41
+ # end
42
+ end
43
+
44
+ def file_content
45
+ File.size(@current_path) > 1000000 ? 'File too big' : File.read(@current_path)
46
+ end
47
+
48
+ # def office
49
+ # render :action=>'excel' if is_excel?
50
+ # render :action=>'word' if is_word?
51
+ # render :action=>'ppt' if is_ppt?
52
+ # render :action=>'help' if is_help?
53
+ # end
54
+
55
+ def rename
56
+ old_name = @current_path + File::SEPARATOR + decode(params[:old_name])
57
+ new_name = @current_path + File::SEPARATOR + decode(params[:new_name])
58
+ File.rename(old_name, new_name)
59
+ success
60
+ end
61
+
62
+ def remove
63
+ FileUtils.rm_rf(@source.map{|s| @current_path + File::SEPARATOR + s})
64
+ success
65
+ end
66
+
67
+ def new_file
68
+ File.new(@current_path + File::SEPARATOR + decode(params[:new_name]), 'w')
69
+ success
70
+ end
71
+
72
+ def new_folder
73
+ Dir.mkdir(@current_path + File::SEPARATOR + decode(params[:new_name]))
74
+ success
75
+ end
76
+
77
+ def copy
78
+ session[:source] = @source.map{|s| @current_path + File::SEPARATOR + s}
79
+ session[:remove] = false
80
+ success
81
+ end
82
+
83
+ def cut
84
+ session[:source] = @source.map{|s| @current_path + File::SEPARATOR + s}
85
+ session[:remove] = true
86
+ success
87
+ end
88
+
89
+ def paste
90
+ return error if session[:remove].nil? || session[:source].nil?
91
+ begin
92
+ session[:remove] == true ? FileUtils.mv(session[:source], @current_path) : FileUtils.cp_r(session[:source], @current_path)
93
+ session[:remove] = nil
94
+ session[:source] = nil
95
+ success
96
+ rescue => exception
97
+ result(exception)
98
+ end
99
+
100
+ end
101
+
102
+ def download
103
+ now = Time.new
104
+ now = "#{now.to_i}#{now.usec}"
105
+ temp_file = FM_TEMP_DIR + File::SEPARATOR + now + '.zip'
106
+ FileUtils.cd(@current_path) do |dir|
107
+ system "zip -r #{temp_file} #{@source.map{|s| '"' + s + '"'}.join(' ')}"
108
+ end
109
+ send_file(temp_file)
110
+ end
111
+
112
+
113
+ def upload
114
+ file = params[:upload]
115
+ filename = decode(file.original_filename)
116
+ File.open(@current_path + File::SEPARATOR + filename, "wb") do |f|
117
+ f.write(file.read)
118
+ end
119
+ to_index
120
+ end
121
+
122
+
123
+
124
+ #TODO
125
+ def adjust_size
126
+
127
+ end
128
+
129
+ #TODO
130
+ def rotate
131
+
132
+ end
133
+
134
+ #TODO
135
+ def unzip
136
+ filename = decode(params[:old_name])
137
+ FileUtils.cd(@current_path) do |dir|
138
+ system "unzip -o #{filename}"
139
+ end
140
+ to_index
141
+ end
142
+
143
+ def to_index
144
+ redirect_to :action => 'index', :path => encode(@path)
145
+ end
146
+
147
+ def success
148
+ result("SUCCESS")
149
+ end
150
+
151
+ def error()
152
+ result("ERROR")
153
+ end
154
+
155
+ def result(message)
156
+ respond_to do |wants|
157
+ wants.js { render :text => message }
158
+ end
159
+ end
160
+
161
+ #methods for view
162
+ def method_missing(method_id, *args)
163
+ method_id_s = method_id.to_s
164
+ if method_id_s[0, 3] == 'is_' && method_id_s[-1, 1] == '?'
165
+ instance_eval %{
166
+ def #{method_id}(*args)
167
+ FM_#{method_id_s[3..-2].upcase}_TYPES.include?(@path_suffix)
168
+ end
169
+ }
170
+ send(method_id, *args)
171
+ else
172
+ super
173
+ end
174
+ end
175
+
176
+ def transfer(from, to, target)
177
+ if FM_ENCODING_TO.nil?
178
+ target
179
+ else
180
+ if target.is_a?(Array)
181
+ target.map{|i| to.nil? ? i : Iconv.conv(to, from, i)}
182
+ else
183
+ Iconv.conv(to, from, target)
184
+ end
185
+ end
186
+ end
187
+
188
+ def encode(target)
189
+ transfer(FM_ENCODING_FROM, FM_ENCODING_TO, target);
190
+ end
191
+
192
+ def decode(target)
193
+ transfer(FM_ENCODING_TO, FM_ENCODING_FROM, target);
194
+ end
195
+
196
+ def hsize(size)
197
+ size = size/1024
198
+ if size > 1024
199
+ size = size/1024
200
+ size = format('%0.2f',(size)) + ' mb'
201
+ else
202
+ size = format('%0.2f', size) + ' kb'
203
+ end
204
+ end
205
+
206
+ def get_file_type(file)
207
+ type = File.extname(file)
208
+
209
+ unless type.blank?
210
+ type = type.downcase[1..-1]
211
+ return type if FM_SUPPORT_TYPES.include?(type)
212
+ end
213
+ FM_UNKNOWN_TYPE
214
+ end
215
+
196
216
  end
197
217
  end