tb_media 1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/MIT-LICENSE +20 -0
- data/Rakefile +28 -0
- data/Readme.markdown +73 -0
- data/app/assets/images/spud/admin/files_thumbs/dat_thumb.png +0 -0
- data/app/assets/images/spud/admin/files_thumbs/doc_thumb.png +0 -0
- data/app/assets/images/spud/admin/files_thumbs/jpg_thumb.png +0 -0
- data/app/assets/images/spud/admin/files_thumbs/mp3_thumb.png +0 -0
- data/app/assets/images/spud/admin/files_thumbs/pdf_thumb.png +0 -0
- data/app/assets/images/spud/admin/files_thumbs/png_thumb.png +0 -0
- data/app/assets/images/spud/admin/files_thumbs/ppt_thumb.png +0 -0
- data/app/assets/images/spud/admin/files_thumbs/txt_thumb.png +0 -0
- data/app/assets/images/spud/admin/files_thumbs/xls_thumb.png +0 -0
- data/app/assets/images/spud/admin/files_thumbs/zip_thumb.png +0 -0
- data/app/assets/images/spud/admin/media/checkers.jpg +0 -0
- data/app/assets/images/spud/admin/media_thumb.png +0 -0
- data/app/assets/images/spud/admin/media_thumb@2x.png +0 -0
- data/app/assets/images/spud/admin/media_tiny.png +0 -0
- data/app/assets/javascripts/spud/admin/media/application.js +175 -0
- data/app/assets/javascripts/spud/admin/media/picker.js +219 -0
- data/app/assets/javascripts/spud/admin/media/plugin.js +99 -0
- data/app/assets/libs/jcrop/css/Jcrop.gif +0 -0
- data/app/assets/libs/jcrop/css/jquery.Jcrop.css +165 -0
- data/app/assets/libs/jcrop/css/jquery.Jcrop.min.css +29 -0
- data/app/assets/libs/jcrop/js/jquery.Jcrop.js +1694 -0
- data/app/assets/libs/jcrop/js/jquery.Jcrop.min.js +22 -0
- data/app/assets/libs/jcrop/js/jquery.color.js +661 -0
- data/app/assets/libs/jcrop/js/jquery.min.js +4 -0
- data/app/assets/libs/tiny_mce/plugins/spud_media/blank.htm +12 -0
- data/app/assets/libs/tiny_mce/plugins/spud_media/css/template.css +23 -0
- data/app/assets/libs/tiny_mce/plugins/spud_media/editor_plugin.js +1 -0
- data/app/assets/libs/tiny_mce/plugins/spud_media/editor_plugin_src.js +159 -0
- data/app/assets/libs/tiny_mce/plugins/spud_media/js/template.js +106 -0
- data/app/assets/libs/tiny_mce/plugins/spud_media/langs/en_dlg.js +1 -0
- data/app/assets/libs/tiny_mce/plugins/spud_media/template.htm +31 -0
- data/app/assets/stylesheets/spud/admin/media/application.css +103 -0
- data/app/assets/stylesheets/spud/admin/media/plugin.css +154 -0
- data/app/controllers/protected_media_controller.rb +26 -0
- data/app/controllers/spud/admin/media_controller.rb +73 -0
- data/app/controllers/spud/admin/media_picker_controller.rb +28 -0
- data/app/helpers/protected_media_helper.rb +3 -0
- data/app/helpers/spud/admin/users_helper.rb +2 -0
- data/app/helpers/spud/user_sessions_helper.rb +2 -0
- data/app/models/spud_media.rb +154 -0
- data/app/views/spud/admin/media/edit.html.erb +50 -0
- data/app/views/spud/admin/media/index.html.erb +37 -0
- data/app/views/spud/admin/media/new.html.erb +26 -0
- data/app/views/spud/admin/media_picker/_media.html.erb +19 -0
- data/app/views/spud/admin/media_picker/create.html.erb +1 -0
- data/app/views/spud/admin/media_picker/create.js.erb +1 -0
- data/app/views/spud/admin/media_picker/index.html.erb +103 -0
- data/config/routes.rb +13 -0
- data/db/migrate/20120101194256_create_spud_media.rb +11 -0
- data/db/migrate/20120501203325_add_protected_to_spud_media.rb +6 -0
- data/db/migrate/20120508132153_add_cropping_to_spud_media.rb +9 -0
- data/lib/spud_media/configuration.rb +11 -0
- data/lib/spud_media/engine.rb +16 -0
- data/lib/spud_media/version.rb +5 -0
- data/lib/tasks/spud_media_tasks.rake +15 -0
- data/lib/tb_media.rb +6 -0
- metadata +257 -0
@@ -0,0 +1,103 @@
|
|
1
|
+
/*
|
2
|
+
*= require jcrop/css/jquery.Jcrop
|
3
|
+
*= require spud/admin/media/plugin
|
4
|
+
*/
|
5
|
+
|
6
|
+
img.size-50-thumb {
|
7
|
+
width:50px;
|
8
|
+
padding-right:5px;
|
9
|
+
}
|
10
|
+
#details{
|
11
|
+
padding-bottom: 25px;
|
12
|
+
}
|
13
|
+
.page_row{
|
14
|
+
padding: 5px 0 5px 5px;
|
15
|
+
}
|
16
|
+
|
17
|
+
/* Crop tool
|
18
|
+
------------------------ */
|
19
|
+
#spud_media_cropper_outer{
|
20
|
+
width: 900px;
|
21
|
+
/*height: 800px;*/
|
22
|
+
margin:auto;
|
23
|
+
border: 1px solid #ccc;
|
24
|
+
border-top: none;
|
25
|
+
}
|
26
|
+
#spud_media_cropper{
|
27
|
+
position: relative;
|
28
|
+
overflow: hidden;
|
29
|
+
width: 900px;
|
30
|
+
/*height: 800px;*/
|
31
|
+
background:url('/assets/spud/admin/media/checkers.jpg');
|
32
|
+
margin:auto;
|
33
|
+
}
|
34
|
+
#spud_media_cropper_container{
|
35
|
+
|
36
|
+
}
|
37
|
+
#spud_media_cropper_jcrop_container{
|
38
|
+
position: absolute;
|
39
|
+
}
|
40
|
+
#spud_media_cropper_target{
|
41
|
+
position: absolute;
|
42
|
+
}
|
43
|
+
#spud_media_cropper_image{
|
44
|
+
position: absolute;
|
45
|
+
}
|
46
|
+
|
47
|
+
/* Crop toolbar
|
48
|
+
------------------ */
|
49
|
+
#spud_media_cropper_toolbar{
|
50
|
+
font-size: 11px;
|
51
|
+
background: #ccc;
|
52
|
+
width: 882px;
|
53
|
+
margin:0 auto;
|
54
|
+
padding: 5px 10px;
|
55
|
+
border-top-right-radius: 8px;
|
56
|
+
border-top-left-radius: 8px;
|
57
|
+
background-image: linear-gradient(bottom, rgb(204,204,204) 33%, rgb(230,230,230) 66%);
|
58
|
+
background-image: -o-linear-gradient(bottom, rgb(204,204,204) 33%, rgb(230,230,230) 66%);
|
59
|
+
background-image: -moz-linear-gradient(bottom, rgb(204,204,204) 33%, rgb(230,230,230) 66%);
|
60
|
+
background-image: -webkit-linear-gradient(bottom, rgb(204,204,204) 33%, rgb(230,230,230) 66%);
|
61
|
+
background-image: -ms-linear-gradient(bottom, rgb(204,204,204) 33%, rgb(230,230,230) 66%);
|
62
|
+
background-image: -webkit-gradient(
|
63
|
+
linear,
|
64
|
+
left bottom,
|
65
|
+
left top,
|
66
|
+
color-stop(0.33, rgb(204,204,204)),
|
67
|
+
color-stop(0.66, rgb(230,230,230))
|
68
|
+
);
|
69
|
+
clear: both;
|
70
|
+
}
|
71
|
+
#spud_media_cropper_toolbar form{
|
72
|
+
margin: 0;
|
73
|
+
-webkit-touch-callout: none;
|
74
|
+
-webkit-user-select: none;
|
75
|
+
-khtml-user-select: none;
|
76
|
+
-moz-user-select: none;
|
77
|
+
-ms-user-select: none;
|
78
|
+
user-select: none;
|
79
|
+
}
|
80
|
+
#spud_media_cropper_toolbar input[type=text],
|
81
|
+
#spud_media_cropper_toolbar label{
|
82
|
+
display: inline-block;
|
83
|
+
margin: 0;
|
84
|
+
font-size: 11px;
|
85
|
+
height: 11px;
|
86
|
+
line-height: 11px;
|
87
|
+
}
|
88
|
+
#spud_media_cropper_toolbar input[type=text]{
|
89
|
+
width: 30px;
|
90
|
+
}
|
91
|
+
.spud_media_cropper_toolbar_item{
|
92
|
+
margin-right: 6px;
|
93
|
+
padding-right: 6px;
|
94
|
+
display: inline-block;
|
95
|
+
border-right: 1px solid #ccc;
|
96
|
+
}
|
97
|
+
#spud_media_cropper_toolbar_actions{
|
98
|
+
float: right;
|
99
|
+
}
|
100
|
+
a[id^="spud_media_cropper_resize_"]:active{
|
101
|
+
position: relative;
|
102
|
+
top: 1px;
|
103
|
+
}
|
@@ -0,0 +1,154 @@
|
|
1
|
+
.spud_media_picker{
|
2
|
+
background: white;
|
3
|
+
font: normal 12px/12px sans-serif;
|
4
|
+
}
|
5
|
+
.spud_media_picker_container{
|
6
|
+
padding: 10px;
|
7
|
+
}
|
8
|
+
|
9
|
+
/* Picker Tabs
|
10
|
+
-------------- */
|
11
|
+
.spud_media_picker_tabs{
|
12
|
+
border-bottom: 1px solid #ccc;
|
13
|
+
margin: 0 0 10px;
|
14
|
+
}
|
15
|
+
.spud_media_picker_tab{
|
16
|
+
display: inline-block;
|
17
|
+
font: normal 12px/22px sans-serif;
|
18
|
+
padding: 0 5px;
|
19
|
+
margin: 0 5px 0 0;
|
20
|
+
position: relative;
|
21
|
+
top: 1px;
|
22
|
+
-webkit-touch-callout: none;
|
23
|
+
-webkit-user-select: none;
|
24
|
+
-khtml-user-select: none;
|
25
|
+
-moz-user-select: none;
|
26
|
+
-ms-user-select: none;
|
27
|
+
user-select: none;
|
28
|
+
}
|
29
|
+
.spud_media_picker_tab_active{
|
30
|
+
border: 1px solid #ccc;
|
31
|
+
border-bottom: 1px solid white;
|
32
|
+
}
|
33
|
+
.spud_media_picker_tab_body{
|
34
|
+
display: none;
|
35
|
+
height: 200px;
|
36
|
+
padding-bottom: 40px;
|
37
|
+
position: relative;
|
38
|
+
}
|
39
|
+
|
40
|
+
/* Buttons
|
41
|
+
------------ */
|
42
|
+
.spud_media_picker_buttons{
|
43
|
+
position: absolute;
|
44
|
+
bottom: 0;
|
45
|
+
left: 0;
|
46
|
+
width: 100%;
|
47
|
+
}
|
48
|
+
.spud_media_picker_buttons a, .spud_media_picker_buttons input, .spud_media_picker_buttons button{
|
49
|
+
float: right;
|
50
|
+
margin-left: 5px;
|
51
|
+
}
|
52
|
+
.spud_media_picker label{
|
53
|
+
font-size: 12px;
|
54
|
+
}
|
55
|
+
|
56
|
+
/* Uploader
|
57
|
+
------------ */
|
58
|
+
.spud_media_picker_upload_progress{
|
59
|
+
display: none;
|
60
|
+
}
|
61
|
+
.spud_media_picker_upload_progress .bar{
|
62
|
+
width: 0;
|
63
|
+
}
|
64
|
+
|
65
|
+
/* Picker List
|
66
|
+
--------------- */
|
67
|
+
.spud_media_picker_list{
|
68
|
+
height: 100%;
|
69
|
+
width: 200px;
|
70
|
+
overflow: auto;
|
71
|
+
border: 1px solid #ccc;
|
72
|
+
float: left;
|
73
|
+
margin: 0 0 10px 0;
|
74
|
+
}
|
75
|
+
.spud_media_picker_item{
|
76
|
+
cursor: pointer;
|
77
|
+
padding: 3px;
|
78
|
+
font: normal 12px/20px sans-serif;
|
79
|
+
border-top: 1px solid #ccc;
|
80
|
+
overflow: hidden;
|
81
|
+
height: 20px;
|
82
|
+
white-space: nowrap;
|
83
|
+
-webkit-touch-callout: none;
|
84
|
+
-webkit-user-select: none;
|
85
|
+
-khtml-user-select: none;
|
86
|
+
-moz-user-select: none;
|
87
|
+
-ms-user-select: none;
|
88
|
+
user-select: none;
|
89
|
+
}
|
90
|
+
.spud_media_picker_item:first-child{
|
91
|
+
border-top: none;
|
92
|
+
}
|
93
|
+
.spud_media_picker_item:last-child{
|
94
|
+
border-bottom: 1px solid #ccc;
|
95
|
+
}
|
96
|
+
.spud_media_picker_item:hover{
|
97
|
+
background: #E6E6E6;
|
98
|
+
}
|
99
|
+
.spud_media_picker_item_selected{
|
100
|
+
background: #D6E4F5;
|
101
|
+
}
|
102
|
+
.spud_media_picker_item img{
|
103
|
+
max-width: 20px;
|
104
|
+
max-height: 20px;
|
105
|
+
float: left;
|
106
|
+
margin: 0 4px 0 0;
|
107
|
+
}
|
108
|
+
|
109
|
+
/* Picker Details
|
110
|
+
-------------------- */
|
111
|
+
.spud_media_picker_details{
|
112
|
+
margin: 0 0 0 220px;
|
113
|
+
display: none;
|
114
|
+
overflow-x: hidden;
|
115
|
+
}
|
116
|
+
.spud_media_picker_details_thumb{
|
117
|
+
max-width: 100px;
|
118
|
+
max-height: 100px;
|
119
|
+
}
|
120
|
+
.spud_media_picker_details_meta{
|
121
|
+
font: bold 11px sans-serif;
|
122
|
+
margin: 10px 0 0;
|
123
|
+
padding: 0 0 0 15px;
|
124
|
+
white-space: nowrap;
|
125
|
+
}
|
126
|
+
.spud_media_picker_details_meta span{
|
127
|
+
font-weight: normal;
|
128
|
+
}
|
129
|
+
|
130
|
+
/* Advanced Options
|
131
|
+
------------------- */
|
132
|
+
.spud_media_picker_tab_advanced{
|
133
|
+
|
134
|
+
}
|
135
|
+
.spud_media_picker_option{
|
136
|
+
margin: 10px 0;
|
137
|
+
}
|
138
|
+
.spud_media_picker_tab_advanced label{
|
139
|
+
width: 100px;
|
140
|
+
padding: 0 5px 0 0;
|
141
|
+
text-align: right;
|
142
|
+
}
|
143
|
+
.spud_media_picker_tab_advanced label, .spud_media_picker_tab_advanced select, .spud_media_picker_tab_advanced input{
|
144
|
+
display: inline-block;
|
145
|
+
margin: 0;
|
146
|
+
}
|
147
|
+
.spud_media_picker_tab_advanced select{
|
148
|
+
font: normal 12px/12px sans-serif;
|
149
|
+
height: auto;
|
150
|
+
padding: 0;
|
151
|
+
}
|
152
|
+
.spud_media_picker_option_dimensions input{
|
153
|
+
width: 50px;
|
154
|
+
}
|
@@ -0,0 +1,26 @@
|
|
1
|
+
class ProtectedMediaController < Spud::ApplicationController
|
2
|
+
|
3
|
+
before_filter :require_user
|
4
|
+
|
5
|
+
def show
|
6
|
+
@media = SpudMedia.where(:id => params[:id]).first
|
7
|
+
if @media.blank?
|
8
|
+
flash[:error] = "The requested file could not be found"
|
9
|
+
redirect_to(root_url)
|
10
|
+
else
|
11
|
+
if Spud::Media.config.paperclip_storage == :s3
|
12
|
+
secure_url = @media.attachment.s3_object(params[:style]).url_for(:read, :secure => true, :expires => 10.minutes)
|
13
|
+
redirect_to(secure_url.to_s)
|
14
|
+
else
|
15
|
+
filepath = File.join(Rails.root, @media.attachment.path(params[:style]))
|
16
|
+
if !File.exists?(filepath)
|
17
|
+
flash[:error] = "The requested file could not be found"
|
18
|
+
redirect_to root_path
|
19
|
+
else
|
20
|
+
send_file(filepath, :disposition => 'inline')
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
class Spud::Admin::MediaController < Spud::Admin::ApplicationController
|
2
|
+
layout 'layouts/spud/admin/detail'
|
3
|
+
add_breadcrumb "Media", :spud_admin_media_path
|
4
|
+
belongs_to_spud_app :media
|
5
|
+
before_filter :load_media,:only => [:edit,:update,:show,:destroy,:set_private,:set_access]
|
6
|
+
|
7
|
+
def index
|
8
|
+
@media = SpudMedia.order("created_at DESC").paginate :page => params[:page]
|
9
|
+
respond_with @media
|
10
|
+
end
|
11
|
+
|
12
|
+
def new
|
13
|
+
@page_name = "New Media"
|
14
|
+
add_breadcrumb "New", :new_spud_admin_medium_path
|
15
|
+
@media = SpudMedia.new
|
16
|
+
respond_with @media
|
17
|
+
end
|
18
|
+
|
19
|
+
def create
|
20
|
+
@page_name = "New Media"
|
21
|
+
add_breadcrumb "New", :new_spud_admin_medium_path
|
22
|
+
@media = SpudMedia.new(params[:spud_media])
|
23
|
+
location = spud_admin_media_path
|
24
|
+
if @media.save
|
25
|
+
flash[:notice] = "File uploaded successfully"
|
26
|
+
if @media.is_image?
|
27
|
+
location = edit_spud_admin_medium_path(@media.id)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
respond_with @media, :location => location
|
31
|
+
end
|
32
|
+
|
33
|
+
def show
|
34
|
+
@page_name = "Media: #{@media.attachment_file_name}"
|
35
|
+
add_breadcrumb @media.attachment_file_name, :new_spud_admin_media_path
|
36
|
+
respond_with @media
|
37
|
+
end
|
38
|
+
|
39
|
+
def edit
|
40
|
+
if !@media.is_image?
|
41
|
+
flash[:error] = "Unable to edit #{@media.attachment_file_name}"
|
42
|
+
redirect_to spud_admin_media_url
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def update
|
47
|
+
if @media.update_attributes(params[:spud_media])
|
48
|
+
@media.attachment.reprocess!
|
49
|
+
end
|
50
|
+
respond_with @media, :location => spud_admin_media_url
|
51
|
+
end
|
52
|
+
|
53
|
+
def destroy
|
54
|
+
flash[:notice] = "File successfully destroyed" if @media.destroy
|
55
|
+
respond_with @media, :location => spud_admin_media_url
|
56
|
+
end
|
57
|
+
|
58
|
+
def set_access
|
59
|
+
is_protected = params[:protected] || false
|
60
|
+
@media.update_attribute(:is_protected, is_protected)
|
61
|
+
respond_with @media, :location => spud_admin_media_url
|
62
|
+
end
|
63
|
+
|
64
|
+
private
|
65
|
+
def load_media
|
66
|
+
@media = SpudMedia.where(:id => params[:id]).first
|
67
|
+
if @media.blank?
|
68
|
+
flash[:error] = "Media Asset not found!"
|
69
|
+
redirect_to spud_admin_media_url() and return
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
class Spud::Admin::MediaPickerController < Spud::Admin::ApplicationController
|
2
|
+
|
3
|
+
include RespondsToParent
|
4
|
+
|
5
|
+
layout false
|
6
|
+
respond_to :html
|
7
|
+
|
8
|
+
def index
|
9
|
+
@media = SpudMedia.all
|
10
|
+
respond_with @media
|
11
|
+
end
|
12
|
+
|
13
|
+
def create
|
14
|
+
@media = SpudMedia.new(params[:spud_media])
|
15
|
+
if @media.save
|
16
|
+
if request.xhr?
|
17
|
+
render 'create', :status => 200
|
18
|
+
else
|
19
|
+
respond_to_parent do
|
20
|
+
render 'create.js', :status => 200
|
21
|
+
end
|
22
|
+
end
|
23
|
+
else
|
24
|
+
render nil, :status => 422
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
@@ -0,0 +1,154 @@
|
|
1
|
+
class SpudMedia < ActiveRecord::Base
|
2
|
+
|
3
|
+
has_attached_file :attachment,
|
4
|
+
:storage => Spud::Media.paperclip_storage,
|
5
|
+
:s3_credentials => Spud::Media.s3_credentials,
|
6
|
+
:s3_permissions => lambda { |attachment, style|
|
7
|
+
attachment.instance.is_protected ? 'private' : 'public-read'
|
8
|
+
},
|
9
|
+
:path => Spud::Media.paperclip_storage == :s3 ? Spud::Media.storage_path : lambda { |attachment|
|
10
|
+
attachment.instance.is_protected ? Spud::Media.storage_path_protected : Spud::Media.storage_path
|
11
|
+
},
|
12
|
+
:url => Spud::Media.storage_url,
|
13
|
+
:styles => lambda { |attachment| attachment.instance.dynamic_styles }
|
14
|
+
|
15
|
+
attr_accessible :attachment_content_type,:attachment_file_name,:attachment_file_size,:attachment, :is_protected, :crop_x, :crop_y, :crop_w, :crop_h, :crop_s
|
16
|
+
|
17
|
+
validates_numericality_of :crop_x, :crop_y, :crop_w, :crop_h, :crop_s, :allow_nil => true
|
18
|
+
|
19
|
+
before_create :rename_file
|
20
|
+
#after_create :validate_permissions
|
21
|
+
before_update :validate_permissions
|
22
|
+
|
23
|
+
def rename_file
|
24
|
+
# remove periods and other unsafe characters from file name to make routing easier
|
25
|
+
extension = File.extname(attachment_file_name)
|
26
|
+
filename = attachment_file_name.chomp(extension).parameterize
|
27
|
+
attachment.instance_write :file_name, filename + extension
|
28
|
+
end
|
29
|
+
|
30
|
+
def image_from_type
|
31
|
+
|
32
|
+
if self.is_image? || self.is_pdf?
|
33
|
+
return self.attachment_url(:small)
|
34
|
+
|
35
|
+
elsif self.attachment_content_type.blank?
|
36
|
+
return "spud/admin/files_thumbs/dat_thumb.png"
|
37
|
+
|
38
|
+
elsif self.attachment_content_type.match(/jpeg|jpg/)
|
39
|
+
return "spud/admin/files_thumbs/jpg_thumb.png"
|
40
|
+
|
41
|
+
elsif self.attachment_content_type.match(/png/)
|
42
|
+
return "spud/admin/files_thumbs/png_thumb.png"
|
43
|
+
|
44
|
+
elsif self.attachment_content_type.match(/zip|tar|tar\.gz|gz/)
|
45
|
+
return "spud/admin/files_thumbs/zip_thumb.png"
|
46
|
+
|
47
|
+
elsif self.attachment_content_type.match(/xls|xlsx/)
|
48
|
+
return "spud/admin/files_thumbs/xls_thumb.png"
|
49
|
+
|
50
|
+
elsif self.attachment_content_type.match(/doc|docx/)
|
51
|
+
return "spud/admin/files_thumbs/doc_thumb.png"
|
52
|
+
|
53
|
+
elsif self.attachment_content_type.match(/ppt|pptx/)
|
54
|
+
return "spud/admin/files_thumbs/ppt_thumb.png"
|
55
|
+
|
56
|
+
elsif self.attachment_content_type.match(/txt|text/)
|
57
|
+
return "spud/admin/files_thumbs/txt_thumb.png"
|
58
|
+
|
59
|
+
elsif self.attachment_content_type.match(/pdf|ps/)
|
60
|
+
return "spud/admin/files_thumbs/pdf_thumb.png"
|
61
|
+
|
62
|
+
elsif self.attachment_content_type.match(/mp3|wav|aac/)
|
63
|
+
return "spud/admin/files_thumbs/mp3_thumb.png"
|
64
|
+
end
|
65
|
+
|
66
|
+
return "spud/admin/files_thumbs/dat_thumb.png"
|
67
|
+
end
|
68
|
+
|
69
|
+
def is_image?
|
70
|
+
if self.attachment_content_type.match(/jpeg|jpg|png/)
|
71
|
+
return true
|
72
|
+
else
|
73
|
+
return false
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def is_pdf?
|
78
|
+
if self.attachment_content_type.match(/pdf/)
|
79
|
+
return true
|
80
|
+
else
|
81
|
+
return false
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def has_custom_crop?
|
86
|
+
return (crop_x && crop_y && crop_w && crop_h && crop_s)
|
87
|
+
end
|
88
|
+
|
89
|
+
def dynamic_styles
|
90
|
+
styles = {}
|
91
|
+
if is_image? || is_pdf?
|
92
|
+
styles[:small] = '50'
|
93
|
+
if has_custom_crop?
|
94
|
+
styles[:cropped] = {:geometry => '', :convert_options => "-resize #{crop_s}% -crop #{crop_w}x#{crop_h}+#{crop_x}+#{crop_y}"}
|
95
|
+
end
|
96
|
+
end
|
97
|
+
return styles
|
98
|
+
end
|
99
|
+
|
100
|
+
# if you are using S3, attachment.url will automatically point to the S3 url
|
101
|
+
# protected files need to hit the rails middle-man first
|
102
|
+
# this method will provide the correct url for either case
|
103
|
+
def attachment_url(style=nil)
|
104
|
+
# defaults to cropped style if that style exists, otherwise use original
|
105
|
+
if !style
|
106
|
+
style = (is_image? && has_custom_crop?) ? 'cropped' : 'original'
|
107
|
+
end
|
108
|
+
if Spud::Media.paperclip_storage == :s3 && is_protected
|
109
|
+
return Paperclip::Interpolations.interpolate(Spud::Media.config.storage_url, attachment, style)
|
110
|
+
else
|
111
|
+
return attachment.url(style)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
# If is_protected has changed, we need to make sure we are setting the appropriate permissions
|
116
|
+
# This means either moving the file in the filesystem or setting the appropriate ACL in S3
|
117
|
+
def validate_permissions
|
118
|
+
if Spud::Media.config.paperclip_storage == :filesystem
|
119
|
+
validate_permissions_filesystem
|
120
|
+
elsif Spud::Media.config.paperclip_storage == :s3
|
121
|
+
validate_permissions_s3
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
private
|
126
|
+
|
127
|
+
def validate_permissions_filesystem
|
128
|
+
if is_protected
|
129
|
+
old_path = Paperclip::Interpolations.interpolate(Spud::Media.config.storage_path, attachment, 'original')
|
130
|
+
new_path = Paperclip::Interpolations.interpolate(Spud::Media.config.storage_path_protected, attachment, 'original')
|
131
|
+
else
|
132
|
+
old_path = Paperclip::Interpolations.interpolate(Spud::Media.config.storage_path_protected, attachment, 'original')
|
133
|
+
new_path = Paperclip::Interpolations.interpolate(Spud::Media.config.storage_path, attachment, 'original')
|
134
|
+
end
|
135
|
+
new_base_dir = File.dirname(File.dirname(new_path))
|
136
|
+
old_base_dir= File.dirname(File.dirname(old_path))
|
137
|
+
if File.directory?(old_base_dir)
|
138
|
+
FileUtils.mv(old_base_dir, new_base_dir)
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
def validate_permissions_s3
|
143
|
+
if is_protected
|
144
|
+
attachment.s3_object(:original).acl = :private
|
145
|
+
attachment.s3_object(:cropped).acl = :private if attachment.s3_object(:cropped).exists?
|
146
|
+
attachment.s3_object(:small).acl = :private if attachment.s3_object(:small).exists?
|
147
|
+
else
|
148
|
+
attachment.s3_object(:original).acl = :public_read
|
149
|
+
attachment.s3_object(:cropped).acl = :public_read if attachment.s3_object(:cropped).exists?
|
150
|
+
attachment.s3_object(:small).acl = :public_read if attachment.s3_object(:small).exists?
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
<%= error_messages_for(@media) %>
|
2
|
+
|
3
|
+
<div id="spud_media_cropper_toolbar">
|
4
|
+
<%= form_for @media, :url => spud_admin_medium_path(@media) do |f| %>
|
5
|
+
|
6
|
+
<div class="spud_media_cropper_toolbar_item">
|
7
|
+
<%= label_tag :x %>
|
8
|
+
<%= f.text_field :crop_x %>
|
9
|
+
</div>
|
10
|
+
|
11
|
+
<div class="spud_media_cropper_toolbar_item">
|
12
|
+
<%= label_tag :y %>
|
13
|
+
<%= f.text_field :crop_y %>
|
14
|
+
</div>
|
15
|
+
|
16
|
+
<div class="spud_media_cropper_toolbar_item">
|
17
|
+
<%= label_tag :width %>
|
18
|
+
<%= f.text_field :crop_w %>
|
19
|
+
</div>
|
20
|
+
|
21
|
+
<div class="spud_media_cropper_toolbar_item">
|
22
|
+
<%= label_tag :height %>
|
23
|
+
<%= f.text_field :crop_h %>
|
24
|
+
</div>
|
25
|
+
|
26
|
+
<div class="spud_media_cropper_toolbar_item">
|
27
|
+
<%= label_tag :scale, 'Size' %>
|
28
|
+
<%= f.hidden_field :crop_s %>
|
29
|
+
<a href="#" id="spud_media_cropper_resize_up"><i class="icon-plus"></i></a>
|
30
|
+
<a href="#" id="spud_media_cropper_resize_down"><i class="icon-minus"></i></a>
|
31
|
+
</div>
|
32
|
+
|
33
|
+
<div id="spud_media_cropper_toolbar_actions">
|
34
|
+
<%= f.submit 'Crop', :id => 'spud_media_cropper_submit', :class => 'btn btn-mini btn-primary' %>
|
35
|
+
<%= link_to "Don't Crop", spud_admin_media_path, :class => 'btn btn-mini' %>
|
36
|
+
</div>
|
37
|
+
<% end %>
|
38
|
+
</div>
|
39
|
+
|
40
|
+
<div id="spud_media_cropper_outer">
|
41
|
+
<div id="spud_media_cropper">
|
42
|
+
<div id="spud_media_cropper_jcrop_container">
|
43
|
+
<img src="<%= @media.attachment_url(:original) %>" id="spud_media_cropper_image" />
|
44
|
+
</div>
|
45
|
+
</div>
|
46
|
+
</div>
|
47
|
+
|
48
|
+
<script type="text/javascript">
|
49
|
+
$(window).load(spud.admin.media.edit);
|
50
|
+
</script>
|
@@ -0,0 +1,37 @@
|
|
1
|
+
<%=content_for :data_controls do%>
|
2
|
+
<%=link_to "Upload File",new_spud_admin_medium_path(),:class => "btn btn-primary",:title => "Upload File"%>
|
3
|
+
<%end%>
|
4
|
+
<%=content_for :detail do%>
|
5
|
+
<div class="page_list">
|
6
|
+
<%@media.each do |media|%>
|
7
|
+
<div class="page_row">
|
8
|
+
|
9
|
+
<span class="row_meta">
|
10
|
+
<% if media.is_protected && (media.is_image? || media.is_pdf?) %>
|
11
|
+
<img src="<%= media.image_from_type %>" class="size-50-thumb" />
|
12
|
+
<% else %>
|
13
|
+
<%= image_tag(media.image_from_type, :class => "size-50-thumb") %>
|
14
|
+
<% end %>
|
15
|
+
<%= link_to media.attachment.url.split("/").last, media.attachment_url %>
|
16
|
+
</span>
|
17
|
+
|
18
|
+
<span class="edit_controls">
|
19
|
+
<% if media.is_image? %>
|
20
|
+
<%= link_to 'Crop', edit_spud_admin_medium_path(media.id), :class => 'btn' %>
|
21
|
+
<% end %>
|
22
|
+
<% if media.is_protected %>
|
23
|
+
<%= link_to raw('<i class="icon-lock"></i> Protected'), set_access_spud_admin_medium_path(media.id, :protected => false), :method => :put, :class => 'btn' %>
|
24
|
+
<% else %>
|
25
|
+
<%= link_to 'Public', set_access_spud_admin_medium_path(media.id, :protected => true), :method => :put, :class => 'btn' %>
|
26
|
+
<% end %>
|
27
|
+
<%=link_to "Remove", spud_admin_medium_path(:id => media.id),:method => :delete,:class => 'btn btn-danger',:confirm => "Are you sure you want to remove this file?"%>
|
28
|
+
</span>
|
29
|
+
|
30
|
+
<br style="clear:both;"/>
|
31
|
+
</div>
|
32
|
+
<%end%>
|
33
|
+
<%=will_paginate @media%>
|
34
|
+
|
35
|
+
</div>
|
36
|
+
|
37
|
+
<%end%>
|
@@ -0,0 +1,26 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
|
4
|
+
<%=form_for @media,:url => spud_admin_media_path(),:html=>{:class=>"form-horizontal", :multipart => true} do |f|%>
|
5
|
+
<fieldset>
|
6
|
+
<legend>Upload Media</legend>
|
7
|
+
|
8
|
+
<div class="control-group">
|
9
|
+
<%=f.label :attachment, "Choose File",:class =>"control-label"%>
|
10
|
+
<div class="controls">
|
11
|
+
<%=f.file_field :attachment%>
|
12
|
+
</div>
|
13
|
+
</div>
|
14
|
+
|
15
|
+
<div class="control-group">
|
16
|
+
<%= f.label :is_protected, 'Protected File', :class => 'control-label' %>
|
17
|
+
<div class="controls">
|
18
|
+
<%= f.check_box :is_protected %>
|
19
|
+
</div>
|
20
|
+
</div>
|
21
|
+
|
22
|
+
<div class="form-actions">
|
23
|
+
<%=f.submit "Upload", :class=>"btn btn-primary","data-loading-text"=>"Uploading..."%> or <%=link_to "cancel",spud_admin_media_path,:class => "btn"%>
|
24
|
+
</div>
|
25
|
+
<%end%>
|
26
|
+
|
@@ -0,0 +1,19 @@
|
|
1
|
+
<%= content_tag :div, :class => 'spud_media_picker_item',
|
2
|
+
'data-id' => media.id,
|
3
|
+
'data-type' => (media.is_image? ? 'img' : 'file'),
|
4
|
+
'data-url' => media.attachment.url,
|
5
|
+
'data-name' => media.attachment_file_name,
|
6
|
+
'data-size' => media.attachment_file_size,
|
7
|
+
'data-lastmod' => media.attachment_updated_at.blank? == false ? media.attachment_updated_at.strftime("%l:%M %p, %D") : '',
|
8
|
+
'data-protected' => (media.is_protected ? 'Yes' : 'No') do %>
|
9
|
+
<span class="spud_media_picker_item_thumb">
|
10
|
+
<% if media.is_protected && (media.is_image? || media.is_pdf?) %>
|
11
|
+
<img src="<%= media.image_from_type %>"/>
|
12
|
+
<% else %>
|
13
|
+
<%= image_tag(media.image_from_type) %>
|
14
|
+
<% end %>
|
15
|
+
</span>
|
16
|
+
<span class="spud_media_picker_item_filename">
|
17
|
+
<%= media.attachment_file_name %>
|
18
|
+
</span>
|
19
|
+
<% end %>
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= render :partial => 'media', :locals => {:media => @media} %>
|
@@ -0,0 +1 @@
|
|
1
|
+
spud.admin.mediapicker.onLegacyUploadComplete("<%= escape_javascript(render :partial => 'media', :locals => {:media => @media}) %>");
|