line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Jifty::Plugin::Media::View; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
#use utf8; |
4
|
1
|
|
|
1
|
|
3640
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
27
|
|
5
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
30
|
|
6
|
1
|
|
|
1
|
|
365
|
use Jifty::View::Declare -base; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 NAME |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
Jifty::Plugin::Media::View - TD views for media plugin |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=cut |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
template 'media_browse' => sub { |
15
|
|
|
|
|
|
|
my $dir = get('dir') || ''; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
my $read = Jifty::Plugin::Media->read_dir($dir); |
18
|
|
|
|
|
|
|
return if ! $read; |
19
|
|
|
|
|
|
|
my @folders = @{$read->{Folders}}; |
20
|
|
|
|
|
|
|
my @files = @{$read->{Files}}; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
return if scalar @folders + scalar @files == 0; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
outs_raw " |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
# print Folders |
27
|
|
|
|
|
|
|
foreach my $file (sort @folders) { |
28
|
|
|
|
|
|
|
outs_raw '
29
|
|
|
|
|
|
|
&HTML::Entities::encode($dir . $file) . '/">' . |
30
|
|
|
|
|
|
|
&HTML::Entities::encode($file) . ''; |
31
|
|
|
|
|
|
|
}; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
# print Files |
34
|
|
|
|
|
|
|
foreach my $file (sort @files) { |
35
|
|
|
|
|
|
|
$file =~ /\.(.+)$/; |
36
|
|
|
|
|
|
|
next if $file =~ /^\./; #don't show hidden files |
37
|
|
|
|
|
|
|
my $ext = $1 || ''; |
38
|
|
|
|
|
|
|
outs_raw '
39
|
|
|
|
|
|
|
&HTML::Entities::encode($dir . $file) . '">' . |
40
|
|
|
|
|
|
|
&HTML::Entities::encode($file) . ''; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
}; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
outs_raw "\n"; |
45
|
|
|
|
|
|
|
}; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
template 'media_manage_page' => page { |
48
|
|
|
|
|
|
|
render_region ( name => 'media_manage', path => 'media_manage'); |
49
|
|
|
|
|
|
|
}; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
template 'media_manage_dir' => sub { |
53
|
|
|
|
|
|
|
my $self = shift; |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
my $dir = get('mediadir') || ''; |
56
|
|
|
|
|
|
|
my $rootdir = get('rootdir') || '/'; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
$dir =~ s/\.\.//g; $dir =~ s/^\.//; |
59
|
|
|
|
|
|
|
$dir .= '/' if $dir !~ m/\/$/; |
60
|
|
|
|
|
|
|
$dir = '/'.$dir if $dir !~ m/^\//; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
$rootdir =~ s/\.\.//g; $rootdir =~ s/^\.//; |
63
|
|
|
|
|
|
|
$rootdir .= '/' if $rootdir !~ m/\/$/; |
64
|
|
|
|
|
|
|
$rootdir = '/'.$rootdir if $rootdir !~ m/^\//; |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
outs_raw <<"EOF"; |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
EOF |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
}; |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
template 'media_manage' => sub { |
90
|
|
|
|
|
|
|
my $self = shift; |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
my $dir = get('mediadir') || ''; |
93
|
|
|
|
|
|
|
# don't allow relative path |
94
|
|
|
|
|
|
|
$dir =~ s/\.\.//g; |
95
|
|
|
|
|
|
|
# don't allow cached path |
96
|
|
|
|
|
|
|
$dir =~ s/^\.//; |
97
|
|
|
|
|
|
|
$dir .= '/' if $dir !~ m/\/$/; |
98
|
|
|
|
|
|
|
$dir = '/'.$dir if $dir !~ m/^\//; |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
my $rootdir = get('rootdir') || '/'; |
101
|
|
|
|
|
|
|
$rootdir =~ s/\.\.//g; $rootdir =~ s/^\.//; |
102
|
|
|
|
|
|
|
$rootdir .= '/' if $rootdir !~ m/\/$/; |
103
|
|
|
|
|
|
|
$rootdir = '/'.$rootdir if $rootdir !~ m/^\//; |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
$dir = $rootdir if($dir eq '/' && $rootdir); |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
my ($plugin) = Jifty->find_plugin('Jifty::Plugin::Media'); |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
div { class is 'media-manage'; |
110
|
|
|
|
|
|
|
h2 { _('Manage media') }; |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
render_region( name => 'fmediadir', path => 'media_manage_dir'); |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
div { class is 'menu'; |
115
|
|
|
|
|
|
|
form { |
116
|
|
|
|
|
|
|
my $upload = new_action('Jifty::Plugin::Media::Action::ManageFile', moniker => 'upload'); |
117
|
|
|
|
|
|
|
my $selected_name = $upload->form_field('selected')->id() ; |
118
|
|
|
|
|
|
|
div { attr { class => "form_field argument-selected"}; |
119
|
|
|
|
|
|
|
label { attr { class => "label text argument-selected", for => "static-selected-id" }; |
120
|
|
|
|
|
|
|
outs '/static/'.$plugin->default_root; |
121
|
|
|
|
|
|
|
}; |
122
|
|
|
|
|
|
|
outs_raw(''); |
123
|
|
|
|
|
|
|
span { attr { class => "hints text argument-selected"}; outs _('Current selected url'); }; |
124
|
|
|
|
|
|
|
foreach my $i ( qw(error warning canonicalization_note) ) { |
125
|
|
|
|
|
|
|
outs_raw(''); |
126
|
|
|
|
|
|
|
#span { attr { style =>"display: none;"; class => "$i text argument-selected"; id => $i.'-'.$selected_name}; outs ' ';}; |
127
|
|
|
|
|
|
|
}; |
128
|
|
|
|
|
|
|
}; |
129
|
|
|
|
|
|
|
div { class is 'submit_button'; |
130
|
|
|
|
|
|
|
$upload->button (label => _('View'), class => 'view', |
131
|
|
|
|
|
|
|
onclick => [ |
132
|
|
|
|
|
|
|
{ submit => { action => $upload, arguments => { action => 'view' } } }, |
133
|
|
|
|
|
|
|
{ refresh => 'fmediadir', }, |
134
|
|
|
|
|
|
|
{ args => { viewfile => { result_of => $upload, name => 'viewfile' } } }, |
135
|
|
|
|
|
|
|
]); |
136
|
|
|
|
|
|
|
$upload->button (label => _('Delete'), class => 'delete', |
137
|
|
|
|
|
|
|
onclick => [ |
138
|
|
|
|
|
|
|
{ confirm => _('Really delete?'), submit => { action => $upload, arguments => { action => 'delete' } } }, |
139
|
|
|
|
|
|
|
{ refresh => 'fmediadir', }, |
140
|
|
|
|
|
|
|
{ args => { mediadir => { result_of => $upload, name => 'dir' }, rootdir => $rootdir } }, |
141
|
|
|
|
|
|
|
]); |
142
|
|
|
|
|
|
|
}; |
143
|
|
|
|
|
|
|
my $view = get('viewfile') || ''; |
144
|
|
|
|
|
|
|
if ($view) { |
145
|
|
|
|
|
|
|
return if $view !~ /^\//; |
146
|
|
|
|
|
|
|
$view =~ /\.(\w+)$/; |
147
|
|
|
|
|
|
|
my $ext = $1 || ''; |
148
|
|
|
|
|
|
|
div { class is 'preview'; |
149
|
|
|
|
|
|
|
my ($sname,$size,$date) = Jifty::Plugin::Media->file_info($view); |
150
|
|
|
|
|
|
|
outs( _(' preview for ') ); outs $view; |
151
|
|
|
|
|
|
|
br {}; |
152
|
|
|
|
|
|
|
if ( $ext eq 'png' || $ext eq 'gif' || $ext eq 'jpg' ) { |
153
|
|
|
|
|
|
|
img { attr { src => $view }; }; |
154
|
|
|
|
|
|
|
} |
155
|
|
|
|
|
|
|
else { |
156
|
|
|
|
|
|
|
hyperlink( label => _('Download file'), class => 'preview', url => $view); |
157
|
|
|
|
|
|
|
}; |
158
|
|
|
|
|
|
|
div { class is 'info'; |
159
|
|
|
|
|
|
|
br {}; |
160
|
|
|
|
|
|
|
outs $sname.' : '.$size; |
161
|
|
|
|
|
|
|
br {}; outs $date; |
162
|
|
|
|
|
|
|
br {}; br {}; |
163
|
|
|
|
|
|
|
}; |
164
|
|
|
|
|
|
|
}; |
165
|
|
|
|
|
|
|
}; |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
render_param($upload,'create_dir'); |
168
|
|
|
|
|
|
|
div { class is 'submit_button'; |
169
|
|
|
|
|
|
|
$upload->button (label => _('Create dir'), class => 'add-folder', |
170
|
|
|
|
|
|
|
onclick => [ |
171
|
|
|
|
|
|
|
{ submit => { action => $upload, arguments => { action => 'create_dir' } } }, |
172
|
|
|
|
|
|
|
{ args => { mediadir => { result_of => $upload, name => 'dir' }, rootdir => $rootdir } }, |
173
|
|
|
|
|
|
|
{ refresh => 'fmediadir', } |
174
|
|
|
|
|
|
|
]); |
175
|
|
|
|
|
|
|
}; |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
render_param($upload,'file'); |
178
|
|
|
|
|
|
|
div { class is 'submit_button'; |
179
|
|
|
|
|
|
|
hyperlink (label => _('Upload'), class => 'upload', |
180
|
|
|
|
|
|
|
onclick => [ |
181
|
|
|
|
|
|
|
{ submit => { action => $upload, arguments => { action => 'upload' } } }, |
182
|
|
|
|
|
|
|
{ refresh => 'fmediadir', }, |
183
|
|
|
|
|
|
|
{ args => { mediadir => { result_of => $upload, name => 'dir' }, rootdir => $rootdir } }, |
184
|
|
|
|
|
|
|
]); |
185
|
|
|
|
|
|
|
}; |
186
|
|
|
|
|
|
|
}; |
187
|
|
|
|
|
|
|
}; |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
}; |
190
|
|
|
|
|
|
|
}; |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
1; |