fdfinder 1.0.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 (196) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +9 -0
  3. data/.travis.yml +3 -0
  4. data/CODE_OF_CONDUCT.md +13 -0
  5. data/Gemfile +4 -0
  6. data/LICENSE.txt +21 -0
  7. data/README.md +364 -0
  8. data/Rakefile +1 -0
  9. data/app/assets/images/fdfinder/about.png +0 -0
  10. data/app/assets/images/fdfinder/copy.png +0 -0
  11. data/app/assets/images/fdfinder/cut.png +0 -0
  12. data/app/assets/images/fdfinder/date_sorter.png +0 -0
  13. data/app/assets/images/fdfinder/delete.png +0 -0
  14. data/app/assets/images/fdfinder/directory-max.png +0 -0
  15. data/app/assets/images/fdfinder/directory.png +0 -0
  16. data/app/assets/images/fdfinder/directory_mini.png +0 -0
  17. data/app/assets/images/fdfinder/download.png +0 -0
  18. data/app/assets/images/fdfinder/duplicate.png +0 -0
  19. data/app/assets/images/fdfinder/edit.png +0 -0
  20. data/app/assets/images/fdfinder/files/7z.png +0 -0
  21. data/app/assets/images/fdfinder/files/Untitled-24.png +0 -0
  22. data/app/assets/images/fdfinder/files/avi.png +0 -0
  23. data/app/assets/images/fdfinder/files/bmp.png +0 -0
  24. data/app/assets/images/fdfinder/files/bz.png +0 -0
  25. data/app/assets/images/fdfinder/files/bz2.png +0 -0
  26. data/app/assets/images/fdfinder/files/css.png +0 -0
  27. data/app/assets/images/fdfinder/files/doc.png +0 -0
  28. data/app/assets/images/fdfinder/files/docx.png +0 -0
  29. data/app/assets/images/fdfinder/files/dv.png +0 -0
  30. data/app/assets/images/fdfinder/files/flv.png +0 -0
  31. data/app/assets/images/fdfinder/files/gif.png +0 -0
  32. data/app/assets/images/fdfinder/files/gz.png +0 -0
  33. data/app/assets/images/fdfinder/files/htm.png +0 -0
  34. data/app/assets/images/fdfinder/files/html.png +0 -0
  35. data/app/assets/images/fdfinder/files/ico.png +0 -0
  36. data/app/assets/images/fdfinder/files/jpeg.png +0 -0
  37. data/app/assets/images/fdfinder/files/jpg.png +0 -0
  38. data/app/assets/images/fdfinder/files/js.png +0 -0
  39. data/app/assets/images/fdfinder/files/mid.png +0 -0
  40. data/app/assets/images/fdfinder/files/mkv.png +0 -0
  41. data/app/assets/images/fdfinder/files/mov.png +0 -0
  42. data/app/assets/images/fdfinder/files/mp3.png +0 -0
  43. data/app/assets/images/fdfinder/files/mp4.png +0 -0
  44. data/app/assets/images/fdfinder/files/mp4a.png +0 -0
  45. data/app/assets/images/fdfinder/files/mpg.png +0 -0
  46. data/app/assets/images/fdfinder/files/ogg.png +0 -0
  47. data/app/assets/images/fdfinder/files/other.png +0 -0
  48. data/app/assets/images/fdfinder/files/pdf.png +0 -0
  49. data/app/assets/images/fdfinder/files/php.png +0 -0
  50. data/app/assets/images/fdfinder/files/png.png +0 -0
  51. data/app/assets/images/fdfinder/files/pps.png +0 -0
  52. data/app/assets/images/fdfinder/files/ppt.png +0 -0
  53. data/app/assets/images/fdfinder/files/pptx.png +0 -0
  54. data/app/assets/images/fdfinder/files/psd.png +0 -0
  55. data/app/assets/images/fdfinder/files/rar.png +0 -0
  56. data/app/assets/images/fdfinder/files/rb.png +0 -0
  57. data/app/assets/images/fdfinder/files/swf.png +0 -0
  58. data/app/assets/images/fdfinder/files/tar.png +0 -0
  59. data/app/assets/images/fdfinder/files/tbz.png +0 -0
  60. data/app/assets/images/fdfinder/files/tga.png +0 -0
  61. data/app/assets/images/fdfinder/files/tgz.png +0 -0
  62. data/app/assets/images/fdfinder/files/tif.png +0 -0
  63. data/app/assets/images/fdfinder/files/tiff.png +0 -0
  64. data/app/assets/images/fdfinder/files/txt.png +0 -0
  65. data/app/assets/images/fdfinder/files/wav.png +0 -0
  66. data/app/assets/images/fdfinder/files/wm.png +0 -0
  67. data/app/assets/images/fdfinder/files/wma.png +0 -0
  68. data/app/assets/images/fdfinder/files/xls.png +0 -0
  69. data/app/assets/images/fdfinder/files/xlsx.png +0 -0
  70. data/app/assets/images/fdfinder/files/xml.png +0 -0
  71. data/app/assets/images/fdfinder/files/zip.png +0 -0
  72. data/app/assets/images/fdfinder/finder.png +0 -0
  73. data/app/assets/images/fdfinder/icon_view.png +0 -0
  74. data/app/assets/images/fdfinder/info.png +0 -0
  75. data/app/assets/images/fdfinder/info2.png +0 -0
  76. data/app/assets/images/fdfinder/kind_sorter.png +0 -0
  77. data/app/assets/images/fdfinder/list_view.png +0 -0
  78. data/app/assets/images/fdfinder/name_sorter.png +0 -0
  79. data/app/assets/images/fdfinder/new_folder.png +0 -0
  80. data/app/assets/images/fdfinder/paste.png +0 -0
  81. data/app/assets/images/fdfinder/preview.png +0 -0
  82. data/app/assets/images/fdfinder/refresh.png +0 -0
  83. data/app/assets/images/fdfinder/rename.png +0 -0
  84. data/app/assets/images/fdfinder/settings.png +0 -0
  85. data/app/assets/images/fdfinder/show_date.png +0 -0
  86. data/app/assets/images/fdfinder/show_size.png +0 -0
  87. data/app/assets/images/fdfinder/size_sorter.png +0 -0
  88. data/app/assets/images/fdfinder/sort.png +0 -0
  89. data/app/assets/images/fdfinder/tree/folder.png +0 -0
  90. data/app/assets/images/fdfinder/tree/loader.gif +0 -0
  91. data/app/assets/images/fdfinder/tree/minus.png +0 -0
  92. data/app/assets/images/fdfinder/tree/plus.png +0 -0
  93. data/app/assets/images/fdfinder/up_folder.png +0 -0
  94. data/app/assets/images/fdfinder/upload.png +0 -0
  95. data/app/assets/javascripts/fdfinder.js +1697 -0
  96. data/app/assets/stylesheets/fdfinder.css +347 -0
  97. data/app/assets/stylesheets/fdfinder.css.scss +347 -0
  98. data/bin/console +14 -0
  99. data/bin/setup +7 -0
  100. data/fdfinder.gemspec +31 -0
  101. data/lib/fdfinder.rb +7 -0
  102. data/lib/fdfinder/connector.rb +612 -0
  103. data/lib/fdfinder/engine.rb +12 -0
  104. data/lib/fdfinder/version.rb +3 -0
  105. data/lib/fdfinder/zip_file_generator.rb +47 -0
  106. data/screenshots/fcfinder_interface.png +0 -0
  107. data/vendor/assets/images/fcfinder/about.png +0 -0
  108. data/vendor/assets/images/fcfinder/copy.png +0 -0
  109. data/vendor/assets/images/fcfinder/cut.png +0 -0
  110. data/vendor/assets/images/fcfinder/date_sorter.png +0 -0
  111. data/vendor/assets/images/fcfinder/delete.png +0 -0
  112. data/vendor/assets/images/fcfinder/directory-max.png +0 -0
  113. data/vendor/assets/images/fcfinder/directory.png +0 -0
  114. data/vendor/assets/images/fcfinder/directory_mini.png +0 -0
  115. data/vendor/assets/images/fcfinder/download.png +0 -0
  116. data/vendor/assets/images/fcfinder/duplicate.png +0 -0
  117. data/vendor/assets/images/fcfinder/edit.png +0 -0
  118. data/vendor/assets/images/fcfinder/files/7z.png +0 -0
  119. data/vendor/assets/images/fcfinder/files/Untitled-24.png +0 -0
  120. data/vendor/assets/images/fcfinder/files/avi.png +0 -0
  121. data/vendor/assets/images/fcfinder/files/bmp.png +0 -0
  122. data/vendor/assets/images/fcfinder/files/bz.png +0 -0
  123. data/vendor/assets/images/fcfinder/files/bz2.png +0 -0
  124. data/vendor/assets/images/fcfinder/files/css.png +0 -0
  125. data/vendor/assets/images/fcfinder/files/doc.png +0 -0
  126. data/vendor/assets/images/fcfinder/files/docx.png +0 -0
  127. data/vendor/assets/images/fcfinder/files/dv.png +0 -0
  128. data/vendor/assets/images/fcfinder/files/flv.png +0 -0
  129. data/vendor/assets/images/fcfinder/files/gif.png +0 -0
  130. data/vendor/assets/images/fcfinder/files/gz.png +0 -0
  131. data/vendor/assets/images/fcfinder/files/htm.png +0 -0
  132. data/vendor/assets/images/fcfinder/files/html.png +0 -0
  133. data/vendor/assets/images/fcfinder/files/ico.png +0 -0
  134. data/vendor/assets/images/fcfinder/files/jpeg.png +0 -0
  135. data/vendor/assets/images/fcfinder/files/jpg.png +0 -0
  136. data/vendor/assets/images/fcfinder/files/js.png +0 -0
  137. data/vendor/assets/images/fcfinder/files/mid.png +0 -0
  138. data/vendor/assets/images/fcfinder/files/mkv.png +0 -0
  139. data/vendor/assets/images/fcfinder/files/mov.png +0 -0
  140. data/vendor/assets/images/fcfinder/files/mp3.png +0 -0
  141. data/vendor/assets/images/fcfinder/files/mp4.png +0 -0
  142. data/vendor/assets/images/fcfinder/files/mp4a.png +0 -0
  143. data/vendor/assets/images/fcfinder/files/mpg.png +0 -0
  144. data/vendor/assets/images/fcfinder/files/ogg.png +0 -0
  145. data/vendor/assets/images/fcfinder/files/other.png +0 -0
  146. data/vendor/assets/images/fcfinder/files/pdf.png +0 -0
  147. data/vendor/assets/images/fcfinder/files/php.png +0 -0
  148. data/vendor/assets/images/fcfinder/files/png.png +0 -0
  149. data/vendor/assets/images/fcfinder/files/pps.png +0 -0
  150. data/vendor/assets/images/fcfinder/files/ppt.png +0 -0
  151. data/vendor/assets/images/fcfinder/files/pptx.png +0 -0
  152. data/vendor/assets/images/fcfinder/files/psd.png +0 -0
  153. data/vendor/assets/images/fcfinder/files/rar.png +0 -0
  154. data/vendor/assets/images/fcfinder/files/rb.png +0 -0
  155. data/vendor/assets/images/fcfinder/files/swf.png +0 -0
  156. data/vendor/assets/images/fcfinder/files/tar.png +0 -0
  157. data/vendor/assets/images/fcfinder/files/tbz.png +0 -0
  158. data/vendor/assets/images/fcfinder/files/tga.png +0 -0
  159. data/vendor/assets/images/fcfinder/files/tgz.png +0 -0
  160. data/vendor/assets/images/fcfinder/files/tif.png +0 -0
  161. data/vendor/assets/images/fcfinder/files/tiff.png +0 -0
  162. data/vendor/assets/images/fcfinder/files/txt.png +0 -0
  163. data/vendor/assets/images/fcfinder/files/wav.png +0 -0
  164. data/vendor/assets/images/fcfinder/files/wm.png +0 -0
  165. data/vendor/assets/images/fcfinder/files/wma.png +0 -0
  166. data/vendor/assets/images/fcfinder/files/xls.png +0 -0
  167. data/vendor/assets/images/fcfinder/files/xlsx.png +0 -0
  168. data/vendor/assets/images/fcfinder/files/xml.png +0 -0
  169. data/vendor/assets/images/fcfinder/files/zip.png +0 -0
  170. data/vendor/assets/images/fcfinder/finder.png +0 -0
  171. data/vendor/assets/images/fcfinder/icon_view.png +0 -0
  172. data/vendor/assets/images/fcfinder/info.png +0 -0
  173. data/vendor/assets/images/fcfinder/info2.png +0 -0
  174. data/vendor/assets/images/fcfinder/kind_sorter.png +0 -0
  175. data/vendor/assets/images/fcfinder/list_view.png +0 -0
  176. data/vendor/assets/images/fcfinder/name_sorter.png +0 -0
  177. data/vendor/assets/images/fcfinder/new_folder.png +0 -0
  178. data/vendor/assets/images/fcfinder/paste.png +0 -0
  179. data/vendor/assets/images/fcfinder/preview.png +0 -0
  180. data/vendor/assets/images/fcfinder/refresh.png +0 -0
  181. data/vendor/assets/images/fcfinder/rename.png +0 -0
  182. data/vendor/assets/images/fcfinder/settings.png +0 -0
  183. data/vendor/assets/images/fcfinder/show_date.png +0 -0
  184. data/vendor/assets/images/fcfinder/show_size.png +0 -0
  185. data/vendor/assets/images/fcfinder/size_sorter.png +0 -0
  186. data/vendor/assets/images/fcfinder/sort.png +0 -0
  187. data/vendor/assets/images/fcfinder/tree/folder.png +0 -0
  188. data/vendor/assets/images/fcfinder/tree/loader.gif +0 -0
  189. data/vendor/assets/images/fcfinder/tree/minus.png +0 -0
  190. data/vendor/assets/images/fcfinder/tree/plus.png +0 -0
  191. data/vendor/assets/images/fcfinder/up_folder.png +0 -0
  192. data/vendor/assets/images/fcfinder/upload.png +0 -0
  193. data/vendor/assets/javascripts/fcfinder.js +1698 -0
  194. data/vendor/assets/stylesheets/fcfinder.css +347 -0
  195. data/vendor/assets/stylesheets/fcfinder.css.erb +347 -0
  196. metadata +297 -0
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "fcfinder"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'fdfinder/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "fdfinder"
8
+ spec.version = Fdfinder::VERSION
9
+ spec.authors = ["Furkan \xC3\x87elik", "Indra Dhanurendra"]
10
+ spec.email = ["furkan.celik32@gmail.com", "indra.dhanurendra@gmail.com"]
11
+
12
+ spec.summary = %q{Rails web-based file explorer}
13
+ spec.description = %q{Web File Manager For The Rails Integrated in ckeditor and TinyMCE with File Explorer you can use as a quick and simple way. English version of Fcvinder}
14
+ spec.homepage = "https://github.com/indradha/fcfinder-en"
15
+ spec.license = "MIT"
16
+
17
+
18
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
19
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.9"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_dependency "mini_magick", "~> 4.2"
26
+ spec.add_dependency "rubyzip", "~> 1.1"
27
+
28
+ #spec.requirements << "zip"
29
+ #spec.requirements << "mini_magick"
30
+
31
+ end
@@ -0,0 +1,7 @@
1
+ require 'fileutils'
2
+ require 'zip'
3
+ require 'mini_magick'
4
+ require 'fdfinder/version'
5
+ require 'fdfinder/engine'
6
+ require 'fdfinder/zip_file_generator'
7
+ require 'fdfinder/connector'
@@ -0,0 +1,612 @@
1
+ module Fdfinder
2
+ class Connector
3
+ attr_reader :run
4
+
5
+ def initialize(file,host_url,fc_params=nil,options = {})
6
+
7
+ #Max dosya boyutu boş ise 1MB dosya yüklemesine izin ver
8
+ @max_file_size = options[:max_file_size] ||= 1_000_000
9
+ @allowed_mime = options[:allowed_mime] ||= {}
10
+ @disallowed_mime = options[:disallowed_mime] ||= {}
11
+ #izin verilen dosyalar
12
+ @permission_mime = permission_mime(@allowed_mime,@disallowed_mime)
13
+
14
+ @file = file
15
+ @fcdir = file.chomp('/*')
16
+ @main_folder = @fcdir.split('/').last
17
+ @host_url = host_url
18
+ @main_file = {}
19
+
20
+
21
+ if fc_params.nil?
22
+ @main_params = append_file(file)
23
+ @main_params[:main_file] = {:path => file.split('/')[-2], :url => file, :sub_dir => @main_file[:sub_dir]}
24
+ result = [@main_params, @main_params[:directory].size+@main_params[:file].size, format_mb(directory_size(@main_params[:main_file][:url].chomp('/*')))]
25
+ else
26
+ result = case fc_params[:type]
27
+ when 'path_to_url'
28
+ path_to_url(get_path(fc_params[:path]))
29
+
30
+ #Tum Dosyaları Listele
31
+ #Klasor Secilme İslemi Yapilinca
32
+ when 'all_file_list'
33
+ all_file_list(get_path(fc_params[:url]))
34
+
35
+ #Yeni Klasor Olusturma
36
+ when 'create_directory'
37
+ create_directory(fc_params[:path], fc_params[:directory_name])
38
+
39
+ #Yenileme Islemi
40
+ when 'refresh'
41
+ refresh(get_path(fc_params[:path]))
42
+
43
+ #Dosya Indirme Islemi
44
+ when 'download'
45
+ download(get_path(fc_params[:path]))
46
+
47
+ #Bilgiler
48
+ when 'info'
49
+ info_and_preview(fc_params[:file], fc_params[:kind])
50
+
51
+ #Onizleme
52
+ when 'preview'
53
+ info_and_preview(fc_params[:file], fc_params[:kind])
54
+
55
+ #Dosya Kopyala
56
+ when 'copy'
57
+ copy(get_path(fc_params[:copy_file_path]), get_path(fc_params[:this_folder_path]))
58
+
59
+ #Dosya Zorunlu Kopyala
60
+ when 'copy!'
61
+ copy!(get_path(fc_params[:copy_file_path]), get_path(fc_params[:this_folder_path]))
62
+
63
+ #Dosya Kesme
64
+ when 'cut'
65
+ cut(get_path(fc_params[:cut_file_path]), get_path(fc_params[:this_folder_path]))
66
+
67
+ #Dosyayı Zorla Kes
68
+ when 'cut!'
69
+ cut!(get_path(fc_params[:cut_file_path]), get_path(fc_params[:this_folder_path]))
70
+
71
+ #Dosya Kopyasını Oluşturma
72
+ when 'duplicate'
73
+ duplicate(get_path(fc_params[:file_path]))
74
+
75
+ #Dosya Yeniden Adlandır
76
+ when 'file_rename'
77
+ file_rename(get_path(fc_params[:path]), fc_params[:file_name])
78
+
79
+ #Dosya Silme İşlemi
80
+ when 'delete'
81
+ delete!(get_path(fc_params[:file_path]))
82
+
83
+ #Dosya Yükleme İşlemi
84
+ when 'upload'
85
+ upload(fc_params[:upload], get_path(fc_params[:path]))
86
+
87
+ #Dosya Duzenleme
88
+ when 'edit_file'
89
+ edit_file(get_path(fc_params[:file_path]))
90
+ else
91
+ # type code here
92
+ end
93
+ end
94
+ @run = result.to_json
95
+ end
96
+
97
+
98
+ def path_to_url(path)
99
+ if File.exist?(path)
100
+ ['true',get_url(set_path(path))]
101
+ else
102
+ %w(false 0)
103
+ end
104
+ end
105
+
106
+
107
+ def all_file_list(url)
108
+ @url_params = append_file(url+'/*')
109
+ [@url_params,@url_params[:directory].size+@url_params[:file].size,format_mb(directory_size(url))]
110
+ end
111
+
112
+ def create_directory(path,directory_name)
113
+ create_file_path = File.join(get_path(path),directory_name)
114
+ create_file_thumbs = create_file_path.sub(@fcdir.chomp('/'),@fcdir.chomp('/')+'/.thumbs')
115
+ if File.exist?(create_file_path)
116
+ #-1 => Aynı İsimde Dosya Var Dosya Oluşmadı
117
+ %w(false -1)
118
+ else
119
+ if Dir.mkdir(create_file_path) && Dir.mkdir(create_file_thumbs)
120
+ ['true', {:top_dir => path, :path => set_path(create_file_path)}]
121
+ else
122
+ #0 => Herhangibir Hata var Dosya Oluşmadı
123
+ %w(false 0)
124
+ end
125
+ end
126
+ end
127
+
128
+ def refresh(path)
129
+ append_file(File.join(path,'/*'))
130
+ end
131
+
132
+ def add_zip_file(path, output_file)
133
+ zf = ZipFileGenerator.new(path, output_file)
134
+ zf.write
135
+ end
136
+
137
+ def download(path)
138
+ begin
139
+ if File.directory?(path)
140
+ output_file = path.chomp('/')+'.zip'
141
+ add_zip_file(path, output_file)
142
+ file = set_path(output_file).sub('fcdir:/', '').split('/').join(':')
143
+ type = path.chomp('/')+'.zip'
144
+ else
145
+ file = set_path(path).sub('fcdir:/', '').split('/').join(':')
146
+ type = path
147
+ end
148
+ result = { :file => file, :type => MIME::Types.type_for(type).first.content_type }
149
+ rescue Exception => e
150
+ result = ['false', '0',e.to_s]
151
+ end
152
+ result
153
+ end
154
+
155
+ def info_and_preview(file,kind)
156
+ { :url => get_url(file),
157
+ :path => file,
158
+ :size => kind=='directory' ? format_mb(directory_size(get_path(file))) : format_mb(File.size(get_path(file))),
159
+ :ctime => File.ctime(get_path(file)).strftime('%d/%m/%Y %H:%M'),
160
+ :mtime => File.mtime(get_path(file)).strftime('%d/%m/%Y %H:%M'),
161
+ :type => File.directory?(get_path(file)) ? 'directory' : set_type(MIME::Types.type_for(get_path(file)).first.content_type) ,
162
+ :mime_type => File.directory?(get_path(file)) ? 'directory' : MIME::Types.type_for(get_path(file)).first.content_type ,
163
+ :permissions => {:write => File.writable?(get_path(file)).to_s, :read => File.readable?(get_path(file)).to_s}
164
+ }
165
+ end
166
+
167
+ def thumbs(opt)
168
+ thumbs = ''
169
+ thumbs = opt[:target].sub(@fcdir.chomp('/'),@fcdir.chomp('/')+'/.thumbs') if opt[:type] == :cut || opt[:type] == :copy || opt[:type] == :rename
170
+ thumbs = opt[:file_path].sub(@fcdir.chomp('/'), @fcdir.chomp('/')+'/.thumbs') if opt[:type] == :duplicate || opt[:type] == :duplicate2
171
+ if File.directory?(opt[:file])
172
+ FileUtils.cp_r(opt[:file].sub(@fcdir.chomp('/'),@fcdir.chomp('/')+'/.thumbs'),thumbs) if opt[:type ] == :copy
173
+ FileUtils.mv(opt[:file].sub(@fcdir.chomp('/'),@fcdir.chomp('/')+'/.thumbs'),thumbs) if opt[:type ] == :cut
174
+ FileUtils.cp_r(thumbs, opt[:folder_name].sub(@fcdir.chomp('/'), @fcdir.chomp('/')+'/.thumbs')+'/'+opt[:file_name]+' copy 1'+opt[:extension]) if opt[:type ] == :duplicate
175
+ FileUtils.cp_r(thumbs, opt[:new_file_path].sub(@fcdir.chomp('/'), @fcdir.chomp('/')+'/.thumbs')) if opt[:type2] == :duplicate2
176
+ FileUtils.mv(thumbs, File.join(opt[:folder_name].sub(@fcdir.chomp('/'), @fcdir.chomp('/')+'/.thumbs'),opt[:file_name])) if opt[:type] == :rename
177
+ else
178
+ if %w(image/x-ms-bmp image/jpeg image/gif image/png).include?(MIME::Types.type_for(opt[:file]).first.content_type)
179
+ unless File.exist?(thumbs)
180
+ _folder = ''
181
+ thumbs.split('/').each do |folder|
182
+ _folder << folder+'/'
183
+ unless File.exist?(_folder)
184
+ Dir.mkdir(_folder.chomp('/'))
185
+ end
186
+ end
187
+ end
188
+ FileUtils.cp_r(opt[:file].sub(@fcdir.chomp('/'),@fcdir.chomp('/')+'/.thumbs'),thumbs) if opt[:type] == :copy
189
+ FileUtils.mv(opt[:file].sub(@fcdir.chomp('/'),@fcdir.chomp('/')+'/.thumbs'),thumbs) if opt[:type] == :cut
190
+ FileUtils.cp_r(thumbs, opt[:folder_name].sub(@fcdir.chomp('/'), @fcdir.chomp('/')+'/.thumbs')+'/'+opt[:file_name]+' copy 1'+opt[:extension]) if opt[:type] == :duplicate
191
+ FileUtils.cp_r(thumbs, opt[:new_file_path].sub(@fcdir.chomp('/'), @fcdir.chomp('/')+'/.thumbs')) if opt[:type] == :duplicate2
192
+ FileUtils.mv(thumbs, File.join(opt[:folder_name].sub(@fcdir.chomp('/'), @fcdir.chomp('/')+'/.thumbs'),opt[:file_name])) if opt[:type] == :rename
193
+ end
194
+ end
195
+ end
196
+
197
+ def image_resize(file_path)
198
+ file_path.each do |file|
199
+ #ORJ=>thumbs = file.sub(@fcdir.chomp('/'), @fcdir.chomp('/')+'/.thumbs').chomp(file.sub(@fcdir.chomp('/'), @fcdir.chomp('/')+'/.thumbs').split('/').last).chomp('/')
200
+ thumbs = file.sub(@fcdir.chomp('/'), @fcdir.chomp('/')+'/.thumbs').chomp(file.split('/').last).chomp('/')
201
+ unless File.exist?(thumbs)
202
+ _folder = ''
203
+ thumbs.split('/').each do |folder|
204
+ _folder << folder + '/'
205
+ unless File.exist?(_folder)
206
+ Dir.mkdir(_folder.chomp('/'))
207
+ end
208
+ end
209
+ end
210
+ image = MiniMagick::Image.open(file)
211
+ image.resize '64x64'
212
+ image.write(file.sub(@fcdir.chomp('/'), @fcdir.chomp('/')+'/.thumbs'))
213
+ end
214
+ end
215
+
216
+ def copy(file,target)
217
+ begin
218
+ file_path = File.join(target,file.split('/').last)
219
+ if File.exist?(file_path)
220
+ #0 => Aynı Dosyadan Var
221
+ result = %w(false 0)
222
+ else
223
+ #Kopyalama İşlemini Gerçekleştir
224
+ FileUtils.cp_r(file,target)
225
+ thumbs({:file=>file, :target=>target, :type=>:copy})
226
+ result = %w(true)
227
+ end
228
+ rescue Exception => e
229
+ result = ['false', '-1',e.to_s]
230
+ end
231
+ result
232
+ end
233
+
234
+ def copy!(file,target)
235
+ begin
236
+ #Kopyalama İşlemini Gerçekleştir
237
+ FileUtils.cp_r(file,target)
238
+
239
+ #thumbs'a kopyasını gönder
240
+ thumbs({:file=>file, :target=>target, :type=>:copy})
241
+ result = %w(true)
242
+ rescue Exception => e
243
+ result = ['false', '-1',e.to_s]
244
+ end
245
+ result
246
+ end
247
+
248
+ def cut(file,target)
249
+ begin
250
+ file_path = target.chomp('/')+'/'+file.split('/').last
251
+ if File.exist?(file_path) || File.directory?(file_path)
252
+ #0 => Aynı Dosyadan Var
253
+ result = %w(false 0)
254
+ else
255
+ #Kesme İşlemini Gerçekleştir
256
+ FileUtils.mv(file,target)
257
+ #thumbs'a kopyasını gönder
258
+ thumbs({:file=>file, :target=>target, :type=>:cut})
259
+ result = %w(true)
260
+ end
261
+ rescue Exception => e
262
+ result = ['false', '-1',e.to_s]
263
+ end
264
+ result
265
+ end
266
+
267
+ def cut!(file,target)
268
+ begin
269
+ #Kesme İşlemini Gerçekleştir
270
+ FileUtils.mv(file,target)
271
+ #thumbs'a kopyasını gönder
272
+ thumbs({:file=>file, :target=>target, :type=>:cut})
273
+ result = %w(true)
274
+ rescue Exception => e
275
+ result = ['false', '-1',e.to_s]
276
+ end
277
+ result
278
+ end
279
+
280
+ def duplicate(file)
281
+ begin
282
+ file_path = file.chomp('/')
283
+ extension = (file_path.split('/').last.split('.').size>1) ? '.'+file_path.split('/').last.split('.').last : ''
284
+ file_name = file_path.split('/').last.chomp(extension)
285
+ folder_name = file_path.chomp(file_path.split('/').last).chomp('/')
286
+
287
+ reg_file = "#{file_name}".match(/(.+?) copy ([0-9])/i)
288
+ if reg_file.nil? && !File.exist?(folder_name+'/'+file_name+' copy 1'+extension)
289
+ FileUtils.cp_r(file_path, folder_name+'/'+file_name+' copy 1'+extension)
290
+ #thumbs dosyaları ekle
291
+ thumbs({:file_path=>file_path,:file=>file_path,:type=>:duplicate,:folder_name=>folder_name,:file_name=>file_name,:extension=>extension})
292
+ result = %w(true)
293
+ else
294
+ #"file_name copy 1" şeklinde bir dosya adı var
295
+ reg_file = "#{file_name} copy 1#{extension}".match(/(.+?) copy ([0-9])/i) if reg_file.nil?
296
+ j = Dir.glob("#{folder_name}/#{reg_file[1]} copy *#{extension}").last.match(/#{reg_file[1]} copy ([0-9])#{extension}/)[1].to_i + 1
297
+
298
+ new_file_name = "#{reg_file[1]} copy #{j}#{extension}"
299
+ new_file_path = folder_name.chomp('/')+'/'+new_file_name
300
+ FileUtils.cp_r(file_path, new_file_path)
301
+ #thumbs'a kopyasını gönder
302
+ thumbs({:file_path=>file_path,:file=>file_path,:type=>:duplicate2,:new_file_path=>new_file_path})
303
+ result = %w(true)
304
+ end
305
+ rescue Exception => e
306
+ result = ['false', '-1',e.to_s]
307
+ end
308
+ result
309
+ end
310
+
311
+ def file_rename(path,file_name)
312
+ begin
313
+ if File.exist?(path)
314
+ folder_name = path.chomp(path.split('/').last).chomp('/')
315
+ FileUtils.mv(path,folder_name+'/'+file_name)
316
+ #thumbs'a kopyasını gönder
317
+ thumbs({:file=>path,:target=>path,:type=>:rename,:folder_name=>folder_name,:file_name=>file_name})
318
+ result = %w(true)
319
+ else
320
+ #return false Dosya Yok!
321
+ result = %w(false)
322
+ end
323
+ rescue Exception => e
324
+ result = ['false', '-1',e.to_s]
325
+ end
326
+ result
327
+ end
328
+
329
+ def delete!(path)
330
+ begin
331
+ if File.exist?(path)
332
+ FileUtils.rm_rf(path)
333
+ FileUtils.rm_rf(path.sub(@fcdir.chomp('/'), @fcdir.chomp('/')+'/.thumbs')) if File.exist?(path.sub(@fcdir.chomp('/'), @fcdir.chomp('/')+'/.thumbs'))
334
+ result = %w(true)
335
+ else
336
+ #return false Dosya Yok!
337
+ result = %w(false 0)
338
+ end
339
+ rescue Exception => e
340
+ result = ['false', '-1',e.to_s]
341
+ end
342
+ result
343
+ end
344
+
345
+ def upload(upload_files,path)
346
+ begin
347
+ image_mime_type = %w(image/x-ms-bmp image/jpeg image/gif image/png)
348
+ file_path,error_delete_file = [],[]
349
+ upload_files.each do |file|
350
+ #dosya büyük
351
+ return ['false', '0',format_mb(@max_file_size)] if file.tempfile.size > @max_file_size
352
+ #format yok
353
+ return ['false', '-1',@permission_mime.to_a] unless @permission_mime.has_key?(file.original_filename.split('.').last) || @permission_mime[file.original_filename.split('.').last]==file.content_type
354
+ file_path.push(File.join(path,file.original_filename)) if image_mime_type.include?(file.content_type)
355
+ error_delete_file.push(File.join(path,file.original_filename))
356
+ File.open(File.join(path,file.original_filename), 'wb') do |f|
357
+ f.write(file.read)
358
+ end
359
+ end
360
+
361
+ # resimleri yeniden boyutlandır
362
+ image_resize(file_path)
363
+ result = %w(true)
364
+ rescue Exception => e
365
+ error_delete_file.each do |file|
366
+ FileUtils.rm_rf(file) unless File.size(file) > 0
367
+ end
368
+ result = ['false', '-2',e.to_s]
369
+ end
370
+ result
371
+ end
372
+
373
+ def edit_file(path)
374
+ File.exist?(path) ?
375
+ { :url => get_url(set_path(path)), :title => path.chomp('/').split('/').last } :
376
+ %w(false 0)
377
+ end
378
+
379
+ def append_file(files_url)
380
+ all_file,all_dir = {},{}
381
+ Dir.glob(files_url).each do |file|
382
+ if File.directory?(file)
383
+ @main_file[:sub_dir] = true if @main_file[:sub_dir].nil?
384
+ all_dir[file.split('/').last] = {:file=>file,:url => get_url(set_path(file)), :sub_dir => false, :size_2 => directory_size(file), :size => format_mb(directory_size(file)), :ctime => File.ctime(file).strftime('%d/%m/%Y %H:%M'), :path => set_path(file), :type => '_directory'}
385
+ Dir.glob(file+'/*').each do |sub_dir|
386
+ if File.directory?(sub_dir)
387
+ all_dir[file.split('/').last][:sub_dir] = true
388
+ end
389
+ end
390
+ else
391
+ all_file[file.split('/').last] = {:file=>file, :path => set_path(file), :url => get_url(set_path(file)), :type => set_type(MIME::Types.type_for(file).first.content_type), :size_2 => File.size(file), :size => format_mb(File.size(file)), :ctime => File.ctime(file).strftime('%d/%m/%Y %H:%M')}
392
+ end
393
+ end
394
+ { :directory => all_dir, :file => all_file }
395
+ end
396
+
397
+
398
+ def set_path(path)
399
+ path.chomp('/').sub(@fcdir, 'fcdir:')
400
+ end
401
+
402
+
403
+ def get_path(path)
404
+ path.chomp('/').sub('fcdir:',@fcdir)
405
+ end
406
+
407
+
408
+ def set_url(path)
409
+ path.chomp('/').sub(File.join(@host_url,@main_folder)+@main_folder, 'fcdir:')
410
+ end
411
+
412
+
413
+ def get_url(path)
414
+ path.chomp('/').sub('fcdir:',File.join(@host_url,@main_folder))
415
+ end
416
+
417
+
418
+ def set_type(type)
419
+ case type
420
+ when 'application/vnd.ms-word'
421
+ 'doc'
422
+ when 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'
423
+ 'docx'
424
+ when 'application/vnd.ms-excel'
425
+ 'xls'
426
+ when 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
427
+ 'xlsx'
428
+ when 'application/vnd.openxmlformats-officedocument.presentationml.presentation'
429
+ 'pptx'
430
+ when 'application/vnd.ms-powerpoint'
431
+ 'ppt'
432
+ when 'application/pdf'
433
+ 'pdf'
434
+ when 'application/xml'
435
+ 'xml'
436
+ when 'application/x-shockwave-flash'
437
+ 'swf'
438
+ when 'application/x-gzip', 'application/gzip'
439
+ 'gz'
440
+ when 'application/x-gtar'
441
+ 'tgz'
442
+ when 'application/x-bzip'
443
+ 'bz'
444
+ when 'application/x-bzip2'
445
+ 'bz2'
446
+ when 'application/zip'
447
+ 'zip'
448
+ when 'application/x-rar', 'application/x-rar-compressed'
449
+ 'rar'
450
+ when 'application/x-tar'
451
+ 'tar'
452
+ when 'application/x-7z-compressed'
453
+ '7z'
454
+ when 'text/plain'
455
+ 'txt'
456
+ when 'text/x-php', 'application/x-httpd-php'
457
+ 'php'
458
+ when 'text/html'
459
+ 'html'
460
+ when 'text/htm'
461
+ 'htm'
462
+ when 'application/javascript'
463
+ 'js'
464
+ when 'text/css'
465
+ 'css'
466
+ when 'application/x-ruby'
467
+ 'rb'
468
+ when 'image/tiff'
469
+ 'tiff'
470
+ when 'image/x-targa'
471
+ 'tga'
472
+ when 'image/vnd.adobe.photoshop'
473
+ 'psd'
474
+ when 'image/x-icon'
475
+ 'ico'
476
+ when 'audio/mpeg'
477
+ 'mp3'
478
+ when 'audio/midi'
479
+ 'mid'
480
+ when 'audio/ogg'
481
+ 'ogg'
482
+ when 'audio/mp4'
483
+ 'mp4a'
484
+ when 'audio/wav', 'audio/x-wav'
485
+ 'wav'
486
+ when 'audio/x-ms-wma'
487
+ 'vma'
488
+ when 'video/x-msvideo'
489
+ 'avi'
490
+ when 'video/x-dv'
491
+ 'dv'
492
+ when 'video/mp4'
493
+ 'mp4'
494
+ when 'video/mpeg'
495
+ 'mpeg'
496
+ when 'video/mpeg'
497
+ 'mpg'
498
+ when 'video/quicktime'
499
+ 'mov'
500
+ when 'video/x-ms-wmv'
501
+ 'vm'
502
+ when 'video/x-flv'
503
+ 'flv'
504
+ when 'video/x-matroska'
505
+ 'mkv'
506
+ when 'image/png', 'image/jpeg','image/x-ms-bmp','image/gif'
507
+ 'image_file'
508
+ else
509
+ 'other'
510
+ end
511
+ end
512
+
513
+
514
+ def directory_size(path)
515
+ path << '/' unless path.end_with?('/')
516
+ raise RuntimeError, "#{path} is not a directory" unless File.directory?(path)
517
+ total_size = 0
518
+ Dir["#{path}**/*"].each do |f|
519
+ total_size += File.size(f) if File.file?(f) && File.size?(f)
520
+ end
521
+ total_size
522
+ end
523
+
524
+
525
+ def format_mb(size)
526
+ conv = %w(B KB MB GB TER PB EB)
527
+ scale = 1024
528
+ ndx=1
529
+ return "#{(size)} #{conv[ndx-1]}" if size < 2*(scale**ndx)
530
+ size=size.to_f
531
+ [2,3,4,5,6,7].each do |ndx|
532
+ return "#{'%.3f' % (size/(scale**(ndx-1)))} #{conv[ndx-1]}" if size < 2*(scale**ndx)
533
+ end
534
+ ndx=7
535
+ "#{'%.3f' % (size/(scale**(ndx-1)))} #{conv[ndx-1]}"
536
+ end
537
+
538
+
539
+ def permission_mime(allowed_mime,disallowed_mime)
540
+ permission = {
541
+ 'doc' => 'application/vnd.ms-word',
542
+ 'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
543
+ 'xls' => 'application/vnd.ms-excel',
544
+ 'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
545
+ 'ppt' => 'application/vnd.ms-powerpoint',
546
+ 'pps' => 'application/vnd.ms-powerpoint',
547
+ 'pptx' => 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
548
+ 'pdf' => 'application/pdf',
549
+ 'xml' => 'application/xml',
550
+ 'swf' => 'application/x-shockwave-flash',
551
+ # archives
552
+ 'gz' => 'application/x-gzip',
553
+ 'tgz' => 'application/x-gzip',
554
+ 'bz' => 'application/x-bzip2',
555
+ 'bz2' => 'application/x-bzip2',
556
+ 'tbz' => 'application/x-bzip2',
557
+ 'zip' => 'application/zip',
558
+ 'rar' => 'application/x-rar',
559
+ 'tar' => 'application/x-tar',
560
+ #'rar' => 'application/x-rar-compressed',
561
+ '7z' => 'application/x-7z-compressed',
562
+ # texts
563
+ 'txt' => 'text/plain',
564
+ 'php' => 'text/x-php',
565
+ 'html' => 'text/html',
566
+ 'htm' => 'text/html',
567
+ 'js' => 'text/javascript',
568
+ 'css' => 'text/css',
569
+ 'rtf' => 'text/rtf',
570
+ 'rtfd' => 'text/rtfd',
571
+ 'py' => 'text/x-python',
572
+ 'java' => 'text/x-java-source',
573
+ 'rb' => 'text/x-ruby',
574
+ 'erb' => 'text/x-ruby',
575
+ 'sh' => 'text/x-shellscript',
576
+ 'pl' => 'text/x-perl',
577
+ 'sql' => 'text/x-sql',
578
+ # images
579
+ 'bmp' => 'image/x-ms-bmp',
580
+ 'jpg' => 'image/jpeg',
581
+ 'jpeg' => 'image/jpeg',
582
+ 'gif' => 'image/gif',
583
+ 'png' => 'image/png',
584
+ 'tif' => 'image/tiff',
585
+ 'tiff' => 'image/tiff',
586
+ 'tga' => 'image/x-targa',
587
+ 'psd' => 'image/vnd.adobe.photoshop',
588
+ 'ico' => 'image/x-icon',
589
+ # audio
590
+ 'mp3' => 'audio/mpeg',
591
+ 'mid' => 'audio/midi',
592
+ 'ogg' => 'audio/ogg',
593
+ 'mp4a' => 'audio/mp4',
594
+ 'wav' => 'audio/wav',
595
+ 'wma' => 'audio/x-ms-wma',
596
+ # video
597
+ 'avi' => 'video/x-msvideo',
598
+ 'dv' => 'video/x-dv',
599
+ 'mp4' => 'video/mp4',
600
+ 'mpeg' => 'video/mpeg',
601
+ 'mpg' => 'video/mpeg',
602
+ 'mov' => 'video/quicktime',
603
+ 'wm' => 'video/x-ms-wmv',
604
+ 'flv' => 'video/x-flv',
605
+ 'mkv' => 'video/x-matroska'
606
+ }
607
+ permission.merge!(allowed_mime)
608
+ permission.delete_if {|key| disallowed_mime.include?(key) }
609
+ permission
610
+ end
611
+ end
612
+ end