camaleon_media_paperclip 0.1.0
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.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +24 -0
- data/Rakefile +17 -0
- data/app/assets/javascripts/admin/elfinder/upload_elfinder.js +237 -0
- data/app/controllers/plugins/camaleon_media_paperclip/admin_controller.rb +58 -0
- data/app/helpers/plugins/camaleon_media_paperclip/helper.rb +48 -0
- data/app/models/plugins/camaleon_media_paperclip.rb +5 -0
- data/app/models/plugins/camaleon_media_paperclip/file.rb +33 -0
- data/app/models/plugins/camaleon_media_paperclip/folder.rb +54 -0
- data/app/views/plugins/camaleon_media_paperclip/admin/settings.html.erb +39 -0
- data/config/camaleon_plugin.json +36 -0
- data/config/routes.rb +5 -0
- data/lib/camaleon_media_paperclip.rb +6 -0
- data/lib/camaleon_media_paperclip/engine.rb +11 -0
- data/lib/camaleon_media_paperclip/version.rb +3 -0
- data/lib/tasks/camaleon_media_paperclip_tasks.rake +4 -0
- metadata +116 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ea27a35608e4611b0d94a3e09a8ecd18fc9166e6
|
4
|
+
data.tar.gz: 01f7d4be1784e3e0382927f143ed5b99a5f31eca
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0ac7c29e30adad6dd3bc788f9203d7fa242beec5888dff30b70875b2394fe2cec91bcbcaffe68a878c056918cab0a9fab7df9c7cf3d7f54f0ec33fa147305e5f
|
7
|
+
data.tar.gz: 18eed33fcb5839bc558d4f292d1be66013d7ede59956ead098839d8f362694659fdf42820f9a9b762d9ba5fa76fe089db9ea4e0cb1daee236b58cb19abd3a7f4
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2015 TODO: Write your name
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# CamaleonMediaPaperclip
|
2
|
+
|
3
|
+
CamaleonMediaPaperclip is a Rails 4 engine that uses paperclip to manage
|
4
|
+
uploaded media files.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add to you Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'camaleon_media_paperclip', path: 'vendor/engines'
|
12
|
+
```
|
13
|
+
|
14
|
+
Bundle and run migrations:
|
15
|
+
|
16
|
+
```sh
|
17
|
+
bundle
|
18
|
+
rake db:migrate
|
19
|
+
```
|
20
|
+
|
21
|
+
## Configuration
|
22
|
+
|
23
|
+
Most configuration (app-wide defaults) should be configured in the host app
|
24
|
+
via paperclip. More to come once it's figured out.
|
data/Rakefile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'CamaleonMediaPaperclip'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.rdoc')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
Bundler::GemHelper.install_tasks
|
@@ -0,0 +1,237 @@
|
|
1
|
+
// options:
|
2
|
+
// - title: Title Modal, default: Upload File
|
3
|
+
// - type: image, video, audio, application/pdf or file extensions (jpg, png, ..),... default: 'all'
|
4
|
+
// - multiple: return array files or uniq file, default: true
|
5
|
+
// - mode, menubar icons visibility, default: basic, values: full, basic
|
6
|
+
// - params: in mode basic use options toolbar: default: [], example: ['resize','mkdir']
|
7
|
+
// - tree: in mode basic use, default: false
|
8
|
+
// - validate_size, resize validate, sample: 40x62
|
9
|
+
// callback: function called after imported the file on elfinder.
|
10
|
+
|
11
|
+
// elfinder for file uploads
|
12
|
+
!(function($){
|
13
|
+
$.fn.upload_elfinder = function(options){
|
14
|
+
var default_options = {type:"all",selected:false, mode: 'basic', params: [], tree: false, multiple: true, validate_size: false};
|
15
|
+
options = $.extend(default_options, options);
|
16
|
+
if(!options.locale) options.locale = CURRENT_LOCALE;
|
17
|
+
|
18
|
+
var mime_type = options.type;
|
19
|
+
|
20
|
+
var $content = $(this);
|
21
|
+
|
22
|
+
var ui_opts = ['toolbar','tree', 'path', 'stat'];
|
23
|
+
var toolbar_ui = null;
|
24
|
+
switch (options.mode){
|
25
|
+
case 'full':
|
26
|
+
var cmds = [
|
27
|
+
'open', 'reload', 'home', 'up', 'back', 'forward', 'getfile', 'quicklook',
|
28
|
+
/*'download',*/ 'rm', 'duplicate', 'rename', 'mkdir', 'mkfile', 'upload', 'copy',
|
29
|
+
'cut', 'paste'/*, 'edit', 'extract', 'archive', 'search'*/, 'info', 'view'/*, 'help'*/,
|
30
|
+
'resize', 'sort'
|
31
|
+
]
|
32
|
+
break;
|
33
|
+
default:
|
34
|
+
var cmds = [ 'rm', 'info', 'sort', 'view','upload', "resize"];
|
35
|
+
if(options.params) cmds = cmds.concat(options.params);
|
36
|
+
if(options.validate_size) cmds = cmds.concat(['resize']);
|
37
|
+
toolbar_ui = [];
|
38
|
+
if(!options.tree){
|
39
|
+
ui_opts = ['toolbar', 'path', 'stat', "sort"];
|
40
|
+
}else{
|
41
|
+
toolbar_ui = [
|
42
|
+
['home', 'up'],
|
43
|
+
['back', 'forward', 'reload']
|
44
|
+
];
|
45
|
+
cmds = cmds.concat(['open', 'reload', 'home', 'up', 'back', 'forward']);
|
46
|
+
}
|
47
|
+
toolbar_ui = toolbar_ui.concat([
|
48
|
+
['upload','mkdir'],
|
49
|
+
['info'],
|
50
|
+
['rm'],
|
51
|
+
['resize'],
|
52
|
+
['view'],
|
53
|
+
['sort']
|
54
|
+
]);
|
55
|
+
break;
|
56
|
+
}
|
57
|
+
|
58
|
+
function hide_info(){
|
59
|
+
$content.find('#import_button').parent().hide();
|
60
|
+
$content.find('.content-panel-info').hide().html('');
|
61
|
+
}
|
62
|
+
|
63
|
+
var init_elfinder = function()
|
64
|
+
{
|
65
|
+
window.content_elfinder = $content.elfinder({
|
66
|
+
|
67
|
+
url : "/admin/elfinder".to_url(), // connector URL (REQUIRED)
|
68
|
+
lang: options.locale,
|
69
|
+
height: '500',
|
70
|
+
// transport : new elFinderSupportVer1(),
|
71
|
+
handlers : {
|
72
|
+
init : function(event, _elfinder) {
|
73
|
+
$content.find('.elfinder-navbar').append('<div id="elfinder-panel-info" class="">'+
|
74
|
+
'<div class="body-panel">'+
|
75
|
+
'<div class="content-panel-info"></div>'+
|
76
|
+
'<div class="col-md-12" style="display: none">' +
|
77
|
+
(options.selected ? '<button id="import_button" class="btn btn-primary btn-block">'+_elfinder.messages.import+'</button>' : '') +
|
78
|
+
'</div>'+
|
79
|
+
'</div>'+
|
80
|
+
'</div>' +
|
81
|
+
'<button id="upload_button" class="btn btn-info btn-block" >'+_elfinder.messages.cmdupload+'</button>');
|
82
|
+
$content.find('#upload_button').unbind().click(function(){
|
83
|
+
$('.elfinder-button form input').click()
|
84
|
+
return false;
|
85
|
+
});
|
86
|
+
|
87
|
+
},
|
88
|
+
select : function(event, elfinderInstance) {
|
89
|
+
var selected = event.data.selected;
|
90
|
+
|
91
|
+
if (selected.length) {
|
92
|
+
var datas = [];
|
93
|
+
for(var i=0; i<selected.length;i++){
|
94
|
+
var file = elfinderInstance.file(selected[i]);
|
95
|
+
if(file.mime && (mime_type == "all" || $.inArray(true, mime_type.split(",").map(function(format){ return file.mime.indexOf(format) > -1 })) >= 0 || $.inArray(file.name.split(".").pop().toLowerCase(), mime_type.split(",")) > -1 )){
|
96
|
+
if(file.size > 0) datas.push(file);
|
97
|
+
}
|
98
|
+
}
|
99
|
+
infoFile(elfinderInstance.file(selected[0]), datas);
|
100
|
+
$content.find('#import_button').unbind().click(function(){
|
101
|
+
if(options.selected){
|
102
|
+
function l_oad(datas){
|
103
|
+
options.selected(options.multiple ? datas : _.first(datas));
|
104
|
+
if(modal_elfinder) modal_elfinder.modal("hide");
|
105
|
+
}
|
106
|
+
var file = _.first(datas);
|
107
|
+
if(options.validate_size){
|
108
|
+
if(options.validate_size == file.dim){
|
109
|
+
l_oad(datas)
|
110
|
+
}else{
|
111
|
+
alert("Required size: " + options.validate_size);
|
112
|
+
$('.elfinder-button .elfinder-button-icon-resize').parent().click()
|
113
|
+
}
|
114
|
+
}else{
|
115
|
+
l_oad(datas)
|
116
|
+
}
|
117
|
+
|
118
|
+
}
|
119
|
+
});
|
120
|
+
|
121
|
+
}else{
|
122
|
+
hide_info()
|
123
|
+
}
|
124
|
+
},
|
125
|
+
dblclick : function(event, elfinderInstance) {
|
126
|
+
event.preventDefault();
|
127
|
+
elfinderInstance.exec('getfile')
|
128
|
+
.done(function() { elfinderInstance.exec('quicklook'); })
|
129
|
+
.fail(function() { elfinderInstance.exec('open'); });
|
130
|
+
}
|
131
|
+
},
|
132
|
+
|
133
|
+
getFileCallback : function(files, fm) {
|
134
|
+
return false;
|
135
|
+
},
|
136
|
+
|
137
|
+
commandsOptions : {
|
138
|
+
quicklook : {
|
139
|
+
width : 640, // Set default width/height voor quicklook
|
140
|
+
height : 480
|
141
|
+
}
|
142
|
+
},
|
143
|
+
ui: ui_opts,
|
144
|
+
uiOptions : {
|
145
|
+
toolbar : toolbar_ui ? toolbar_ui : [
|
146
|
+
['home', 'up'],
|
147
|
+
['back', 'forward'],
|
148
|
+
['reload'],
|
149
|
+
['mkdir', 'mkfile', 'upload'],
|
150
|
+
['download', 'getfile'],
|
151
|
+
['info'],
|
152
|
+
['quicklook'],
|
153
|
+
['copy', 'cut', 'paste'],
|
154
|
+
['rm'],
|
155
|
+
['duplicate', 'rename', 'edit', 'resize'],
|
156
|
+
['search'],
|
157
|
+
['view']
|
158
|
+
]
|
159
|
+
},
|
160
|
+
commands : cmds
|
161
|
+
}).elfinder('instance');
|
162
|
+
if($.fn.tooltip) $('.elfinder-button').tooltip({placement: 'bottom'});
|
163
|
+
};
|
164
|
+
|
165
|
+
if($content.size()){
|
166
|
+
var modal_elfinder = false;
|
167
|
+
init_elfinder();
|
168
|
+
}else{
|
169
|
+
var html = '<div id="modal_elfinder" class="modal fade bs-example-modal-lg" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true">'+
|
170
|
+
'<div class="modal-dialog modal-lg">'+
|
171
|
+
'<div class="modal-content">'+
|
172
|
+
'<div class="modal-header">'+
|
173
|
+
'<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>'+
|
174
|
+
'<h4 class="modal-title" id="defModalHead">Media</h4>'+
|
175
|
+
'</div>'+
|
176
|
+
'<div id="content_elfinder"></div>'+
|
177
|
+
'</div>'+
|
178
|
+
'</div>'+
|
179
|
+
'</div>';
|
180
|
+
|
181
|
+
var modal_elfinder = $(html);
|
182
|
+
modal_elfinder.modal();
|
183
|
+
modal_elfinder.on('shown.bs.modal', function (e){
|
184
|
+
$content = $('#modal_elfinder #content_elfinder');
|
185
|
+
init_elfinder();
|
186
|
+
});
|
187
|
+
modal_elfinder.on('hidden.bs.modal', function (e){
|
188
|
+
$("#modal_elfinder").remove();
|
189
|
+
try{ modal_fix_multiple(); }catch(e){}
|
190
|
+
});
|
191
|
+
}
|
192
|
+
|
193
|
+
// ************ utils //**************/
|
194
|
+
|
195
|
+
var infoFile = function(elemFirst, datas){
|
196
|
+
var panelInfo = "<div class='row'><h4 class='col-md-12'>"+content_elfinder.messages.details+" <a href='#' class='btn-close text-danger pull-right'><i class='ui-icon ui-icon-circle-close'></i></a> </h4></div>"+
|
197
|
+
"<div id='panel-info-title' class='row'>"+
|
198
|
+
"<div class='image col-md-4'>"+imageFile(elemFirst)+"</div>"+
|
199
|
+
"<div class='detail col-md-8'>"+
|
200
|
+
"<strong>"+elemFirst.name+"</strong>"+"<br>"+
|
201
|
+
"<span>"+elemFirst.mime+"</span>"+
|
202
|
+
"</div>"+
|
203
|
+
"</div>"+
|
204
|
+
"<div id='panel-info-content' class='row'>"+
|
205
|
+
"<p class='col-md-12'>"+content_elfinder.messages.size+" : <span>"+content_elfinder.formatSize(elemFirst.size)+"</span></p>"+
|
206
|
+
"<p class='col-md-12'>URL : <span><input type='text' value='"+elemFirst.url+"' /></span></p>"+
|
207
|
+
(is_image_data(elemFirst) ? "<p class='col-md-12'>"+content_elfinder.messages.thumb+" : <span><input type='text' value='"+ (elemFirst.tmb != "1" ? elemFirst.tmb.toString() : elemFirst.url) +"' /></span></p>" : "")+
|
208
|
+
"<p class='col-md-12'>"+content_elfinder.messages.dim+" : <span>"+elemFirst.dim+"</span></p>"+
|
209
|
+
"<p class='col-md-12'>"+content_elfinder.messages.modify+" : <span>"+elemFirst.date.replace('-0400','')+"</span></p>"+
|
210
|
+
"</div>";
|
211
|
+
|
212
|
+
$content.find('.content-panel-info').show().html(panelInfo);
|
213
|
+
$content.find('.content-panel-info .btn-close').unbind().click(function(){
|
214
|
+
hide_info()
|
215
|
+
return false;
|
216
|
+
});
|
217
|
+
if($.inArray(elemFirst, datas) >= 0)
|
218
|
+
$content.find('#import_button').parent().show();
|
219
|
+
else
|
220
|
+
$content.find('#import_button').parent().hide();
|
221
|
+
};
|
222
|
+
|
223
|
+
var imageFile = function (datas){
|
224
|
+
if(is_image_data(datas)){
|
225
|
+
//return "<img title='"+datas.name+"' style='width: 100%' src='"+datas.url+'?q='+ Math.random() +"'>";
|
226
|
+
return "<img title='"+datas.name+"' style='width: 100%' src='"+(datas.tmb == "1" ? datas.url : datas.tmb)+"'>";
|
227
|
+
|
228
|
+
}else{
|
229
|
+
return '<div class="elfinder-cwd-file-wrapper ui-corner-all ui-draggable ui-draggable-handle ui-state-hover">'+
|
230
|
+
'<div class="elfinder-cwd-icon elfinder-cwd-icon-application ui-corner-all '+content_elfinder.mime2class(datas.mime)+'" unselectable="on"></div>'+
|
231
|
+
'</div>';
|
232
|
+
}
|
233
|
+
};
|
234
|
+
// check if datas is image format
|
235
|
+
function is_image_data(datas){ return datas.mime && datas.mime.indexOf("image") > -1 }
|
236
|
+
}
|
237
|
+
})(jQuery);
|
@@ -0,0 +1,58 @@
|
|
1
|
+
class Plugins::CamaleonMediaPaperclip::AdminController < Apps::PluginsAdminController
|
2
|
+
include Plugins::CamaleonMediaPaperclip::Helper
|
3
|
+
|
4
|
+
skip_before_filter :authenticate, only: :img
|
5
|
+
skip_before_filter :admin_logged_actions, except: :settings
|
6
|
+
skip_before_filter :verify_authenticity_token
|
7
|
+
|
8
|
+
def index
|
9
|
+
authorize! :manager, :media
|
10
|
+
end
|
11
|
+
|
12
|
+
def settings
|
13
|
+
@camaleon_media_paperclip = current_site.get_meta('camaleon_media_paperclip_config')
|
14
|
+
end
|
15
|
+
|
16
|
+
def save_settings
|
17
|
+
current_site.set_meta(
|
18
|
+
'camaleon_media_paperclip_config',
|
19
|
+
bucket_name: params[:camaleon_media_paperclip][:bucket_name],
|
20
|
+
region: params[:camaleon_media_paperclip][:region],
|
21
|
+
access_key_id: params[:camaleon_media_paperclip][:access_key_id],
|
22
|
+
secret_access_key: params[:camaleon_media_paperclip][:secret_access_key],
|
23
|
+
cdn_base_path: params[:camaleon_media_paperclip][:cdn_base_path]
|
24
|
+
)
|
25
|
+
flash[:notice] = "#{t('plugin.camaleon_media_paperclip.messages.settings_saved')}"
|
26
|
+
redirect_to action: :settings
|
27
|
+
end
|
28
|
+
|
29
|
+
# here add your custom functions
|
30
|
+
|
31
|
+
def elfinder
|
32
|
+
plugin_config = current_site.get_meta('camaleon_media_paperclip_config')
|
33
|
+
dirname = '/'
|
34
|
+
r = { dirname: dirname }
|
35
|
+
hooks_run('elfinder', r)
|
36
|
+
|
37
|
+
connector = CamaleonMediaPaperclip::ElFinder::Connector.new(
|
38
|
+
home: t('admin.media.home')
|
39
|
+
)
|
40
|
+
h, r = connector.run(params)
|
41
|
+
|
42
|
+
headers.merge!(h)
|
43
|
+
|
44
|
+
render (r.empty? ? { nothing: true } : { text: r.to_json }), layout: false
|
45
|
+
end
|
46
|
+
|
47
|
+
def iframe
|
48
|
+
render layout: true
|
49
|
+
end
|
50
|
+
|
51
|
+
def crop
|
52
|
+
url_image = crop_image(params[:cp_img_path], params[:ic_w], params[:ic_h], params[:ic_x], params[:ic_y])
|
53
|
+
if params[:saved_avatar].present?
|
54
|
+
User.find(params[:saved_avatar]).set_meta('avatar', url_image)
|
55
|
+
end
|
56
|
+
render text: url_image
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module Plugins::CamaleonMediaPaperclip::Helper
|
2
|
+
def self.included(_klass)
|
3
|
+
# klass.helper_method [:my_helper_method] rescue "" # here your methods accessible from views
|
4
|
+
end
|
5
|
+
|
6
|
+
# here all actions on going to active
|
7
|
+
# you can run sql commands like this:
|
8
|
+
# results = ActiveRecord::Base.connection.execute(query);
|
9
|
+
# plugin: plugin model
|
10
|
+
def camaleon_media_paperclip_on_active(_plugin)
|
11
|
+
current_site.set_meta(
|
12
|
+
'camaleon_media_paperclip_config',
|
13
|
+
get: { sec: 20, max: 10 },
|
14
|
+
post: { sec: 20, max: 5 },
|
15
|
+
msg: "#{t('.request_limit_exceeded')}",
|
16
|
+
ban: 5,
|
17
|
+
cleared: Time.now
|
18
|
+
)
|
19
|
+
end
|
20
|
+
|
21
|
+
# here all actions on going to inactive
|
22
|
+
# plugin: plugin model
|
23
|
+
def camaleon_media_paperclip_on_inactive(_plugin)
|
24
|
+
# if ActiveRecord::Base.connection.table_exists? 'plugins_media_files_search_caches'
|
25
|
+
# ActiveRecord::Base.connection.drop_table :plugins_media_files_search_caches
|
26
|
+
# end
|
27
|
+
end
|
28
|
+
|
29
|
+
def camaleon_media_paperclip_plugin_options(arg)
|
30
|
+
arg[:links] << link_to(t('.settings'), admin_plugins_camaleon_media_paperclip_settings_path)
|
31
|
+
end
|
32
|
+
|
33
|
+
def camaleon_media_paperclip_front_before_load
|
34
|
+
# append_asset_libraries(
|
35
|
+
# 'plugin_camaleon_media_paperclip' => {
|
36
|
+
# js: [plugin_asset_path('camaleon_media_paperclip', 'js/main')]
|
37
|
+
# }
|
38
|
+
# )
|
39
|
+
end
|
40
|
+
|
41
|
+
def camaleon_media_paperclip_admin_before_load
|
42
|
+
# append_asset_libraries(
|
43
|
+
# 'plugin_camaleon_media_paperclip' => {
|
44
|
+
# js: [plugin_asset_path('camaleon_media_paperclip', 'js/main')]
|
45
|
+
# }
|
46
|
+
# )
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
class Plugins::CamaleonMediaPaperclip::File < ActiveRecord::Base
|
2
|
+
belongs_to :folder
|
3
|
+
|
4
|
+
has_attached_file :content
|
5
|
+
|
6
|
+
before_save :set_dimensions, if: :image?
|
7
|
+
|
8
|
+
def self.find_by_pathname(pathname)
|
9
|
+
dirname, basename = Pathname.new(pathname).cleanpath.split
|
10
|
+
find_by(dirname: dirname, basename: basename)
|
11
|
+
end
|
12
|
+
|
13
|
+
def image?
|
14
|
+
# This regex comes from paperclip wiki, there is probably a better way
|
15
|
+
content_content_type =~ %r{^(image|(x-)?application)/(bmp|gif|jpeg|jpg|pjpeg|png|x-png)$}
|
16
|
+
end
|
17
|
+
|
18
|
+
def dimensions
|
19
|
+
image? && "#{width}x#{height}"
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def set_dimensions
|
25
|
+
return unless image?
|
26
|
+
tempfile = content.queued_for_write[:original]
|
27
|
+
unless tempfile.nil?
|
28
|
+
geometry = Paperclip::Geometry.from_file(tempfile)
|
29
|
+
self.width = geometry.width.to_i
|
30
|
+
self.height = geometry.height.to_i
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module Plugins::CamaleonMediaPaperclip
|
2
|
+
CMP = self
|
3
|
+
|
4
|
+
class Folder < ActiveRecord::Base
|
5
|
+
include CamaleonMediaPaperclip::HashUtils
|
6
|
+
|
7
|
+
has_many :files
|
8
|
+
has_many :folders
|
9
|
+
belongs_to :folder
|
10
|
+
|
11
|
+
def children
|
12
|
+
files = CMP::File.where(folder_id: id).
|
13
|
+
select(CMP::File.arel_table[:filename].as('pathname')).
|
14
|
+
arel
|
15
|
+
folders = CMP::Folder.where(folder_id: id).
|
16
|
+
select(CMP::Folder.arel_table[:path].as('pathname')).
|
17
|
+
arel
|
18
|
+
|
19
|
+
union = Arel::Nodes::Union.new(files, folders)
|
20
|
+
query = Arel::Nodes::TableAlias.new(union, 'query')
|
21
|
+
|
22
|
+
CMP::Folder.from(query.to_sql).pluck(:pathname)
|
23
|
+
end
|
24
|
+
|
25
|
+
def name
|
26
|
+
::Pathname.new(path.to_s).basename.to_s
|
27
|
+
end
|
28
|
+
|
29
|
+
def mtime
|
30
|
+
updated_at.try(:tv_sec).to_i
|
31
|
+
end
|
32
|
+
|
33
|
+
def cwd
|
34
|
+
entry = {
|
35
|
+
name: name,
|
36
|
+
hash: "v0_#{to_base64url(path.to_s)}",
|
37
|
+
mime: 'directory',
|
38
|
+
ts: mtime,
|
39
|
+
size: 0,
|
40
|
+
dirs: self.class.exists?(folder_id: id),
|
41
|
+
read: 1,
|
42
|
+
write: 1,
|
43
|
+
locked: 0
|
44
|
+
}
|
45
|
+
entry[:volumeid] = 'v0_' unless id
|
46
|
+
entry[:phash] = "v0_#{to_base64url(folder.path.to_s)}" if id
|
47
|
+
entry
|
48
|
+
end
|
49
|
+
|
50
|
+
def file_entries(include_tree)
|
51
|
+
[]
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
<%= form_for(admin_plugins_camaleon_media_paperclip_settings_path, html: {id: "camaleon_media_paperclip_form", class: "validate"}) do %>
|
2
|
+
<div class="panel panel-default">
|
3
|
+
<div class="panel-heading">
|
4
|
+
<h3 class="panel-title"><%= t('plugin.camaleon_media_paperclip.settings.title') %></h3>
|
5
|
+
</div>
|
6
|
+
<div class="panel-body">
|
7
|
+
<div class="form-group">
|
8
|
+
<div class="input-group">
|
9
|
+
<span class="input-group-addon"><%= t('plugin.camaleon_media_paperclip.settings.bucket') %></span>
|
10
|
+
<%= text_field_tag('camaleon_media_paperclip[bucket_name]', @camaleon_media_paperclip[:bucket_name], class: 'required form-control') %>
|
11
|
+
|
12
|
+
<span class="input-group-addon"><%= t('plugin.camaleon_media_paperclip.settings.region') %></span>
|
13
|
+
<%= text_field_tag('camaleon_media_paperclip[region]', @camaleon_media_paperclip[:region], class: 'required form-control') %>
|
14
|
+
</div>
|
15
|
+
</div>
|
16
|
+
|
17
|
+
<div class="form-group">
|
18
|
+
<div class="input-group">
|
19
|
+
<span class="input-group-addon"><%= t('plugin.camaleon_media_paperclip.settings.access_key_id') %></span>
|
20
|
+
<%= text_field_tag('camaleon_media_paperclip[access_key_id]', @camaleon_media_paperclip[:access_key_id], class: 'required form-control') %>
|
21
|
+
|
22
|
+
<span class="input-group-addon"><%= t('plugin.camaleon_media_paperclip.settings.secret_access_key') %></span>
|
23
|
+
<%= text_field_tag('camaleon_media_paperclip[secret_access_key]', @camaleon_media_paperclip[:secret_access_key], class: 'required form-control') %>
|
24
|
+
</div>
|
25
|
+
</div>
|
26
|
+
|
27
|
+
<div class="form-group">
|
28
|
+
<div class="input-group">
|
29
|
+
<span class="input-group-addon"><%= t('plugin.camaleon_media_paperclip.settings.cdn_base_path') %></span>
|
30
|
+
<%= text_field_tag('camaleon_media_paperclip[cdn_base_path]', @camaleon_media_paperclip[:cdn_base_path], class: 'required form-control') %>
|
31
|
+
</div>
|
32
|
+
</div>
|
33
|
+
</div>
|
34
|
+
<div class="panel-footer">
|
35
|
+
<a class="btn btn-default" href="<%= url_for admin_plugins_path %>"><%= t('admin.button.back') %></a>
|
36
|
+
<button class="btn btn-primary pull-right" type="submit"><%= t('admin.button.submit') %></button>
|
37
|
+
</div>
|
38
|
+
</div>
|
39
|
+
<% end %>
|
@@ -0,0 +1,36 @@
|
|
1
|
+
{
|
2
|
+
"title": "Media with Paperclip",
|
3
|
+
"descr": "",
|
4
|
+
"version": "0.1.0",
|
5
|
+
"key": "camaleon_media_paperclip",
|
6
|
+
"helpers": [
|
7
|
+
"Plugins::CamaleonMediaPaperclip::Helper"
|
8
|
+
],
|
9
|
+
"options": [
|
10
|
+
{
|
11
|
+
"label": "Settings",
|
12
|
+
"url": "admin_plugin_camaleon_media_paperclip_settings_path",
|
13
|
+
"eval_url": true
|
14
|
+
}
|
15
|
+
],
|
16
|
+
"hooks": {
|
17
|
+
"on_destroy": [
|
18
|
+
"camaleon_media_paperclip_on_destroy"
|
19
|
+
],
|
20
|
+
"on_active": [
|
21
|
+
"camaleon_media_paperclip_on_active"
|
22
|
+
],
|
23
|
+
"on_inactive": [
|
24
|
+
"camaleon_media_paperclip_on_inactive"
|
25
|
+
],
|
26
|
+
"on_upgrade": [
|
27
|
+
"camaleon_media_paperclip_on_upgrade"
|
28
|
+
],
|
29
|
+
"front_before_load": [
|
30
|
+
"camaleon_media_paperclip_front_before_load"
|
31
|
+
],
|
32
|
+
"plugin_options": [
|
33
|
+
"camaleon_media_paperclip_plugin_options"
|
34
|
+
]
|
35
|
+
}
|
36
|
+
}
|
data/config/routes.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
module CamaleonMediaPaperclip
|
2
|
+
class Engine < ::Rails::Engine
|
3
|
+
initializer :append_migrations do |app|
|
4
|
+
unless app.root.to_s.match root.to_s
|
5
|
+
config.paths['db/migrate'].expanded.each do |expanded_path|
|
6
|
+
app.config.paths['db/migrate'] << expanded_path
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
metadata
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: camaleon_media_paperclip
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- QuintEvents
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-12-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: el_finder2
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.1.5
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.1.5
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: sqlite3
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: pry
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rubocop
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: Camaleon CMS plugin to store media uploads with paperclip
|
70
|
+
email:
|
71
|
+
- dev@quintevents.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- MIT-LICENSE
|
77
|
+
- README.md
|
78
|
+
- Rakefile
|
79
|
+
- app/assets/javascripts/admin/elfinder/upload_elfinder.js
|
80
|
+
- app/controllers/plugins/camaleon_media_paperclip/admin_controller.rb
|
81
|
+
- app/helpers/plugins/camaleon_media_paperclip/helper.rb
|
82
|
+
- app/models/plugins/camaleon_media_paperclip.rb
|
83
|
+
- app/models/plugins/camaleon_media_paperclip/file.rb
|
84
|
+
- app/models/plugins/camaleon_media_paperclip/folder.rb
|
85
|
+
- app/views/plugins/camaleon_media_paperclip/admin/settings.html.erb
|
86
|
+
- config/camaleon_plugin.json
|
87
|
+
- config/routes.rb
|
88
|
+
- lib/camaleon_media_paperclip.rb
|
89
|
+
- lib/camaleon_media_paperclip/engine.rb
|
90
|
+
- lib/camaleon_media_paperclip/version.rb
|
91
|
+
- lib/tasks/camaleon_media_paperclip_tasks.rake
|
92
|
+
homepage: http://example.com
|
93
|
+
licenses:
|
94
|
+
- MIT
|
95
|
+
metadata: {}
|
96
|
+
post_install_message:
|
97
|
+
rdoc_options: []
|
98
|
+
require_paths:
|
99
|
+
- lib
|
100
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
requirements: []
|
111
|
+
rubyforge_project:
|
112
|
+
rubygems_version: 2.4.8
|
113
|
+
signing_key:
|
114
|
+
specification_version: 4
|
115
|
+
summary: Camaleon CMS plugin to store media uploads with paperclip
|
116
|
+
test_files: []
|