| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package CGI::Application::PhotoGallery; |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
=head1 NAME |
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
CGI::Application::PhotoGallery - module to provide a simple photo gallery |
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
use CGI::Application::PhotoGallery; |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
my $webapp = CGI::Application::PhotoGallery->new( |
|
12
|
|
|
|
|
|
|
PARAMS => { |
|
13
|
|
|
|
|
|
|
photos_dir => '/path/to/photos' |
|
14
|
|
|
|
|
|
|
} |
|
15
|
|
|
|
|
|
|
); |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
$webapp->run(); |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
CGI::Application::PhotoGallery is a L module allowing people |
|
22
|
|
|
|
|
|
|
to create their own simple photo gallery. There is no need to generate your |
|
23
|
|
|
|
|
|
|
own thumbnails since they are created on the fly (using either the GD or |
|
24
|
|
|
|
|
|
|
Image::Magick modules). |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
To use this module you need to create an instance script. It |
|
27
|
|
|
|
|
|
|
should look like: |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
#!/usr/bin/perl |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
use CGI::Application::PhotoGallery; |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
my $webapp = CGI::Application::PhotoGallery->new( |
|
34
|
|
|
|
|
|
|
PARAMS => { |
|
35
|
|
|
|
|
|
|
photos_dir => '/path/to/photos' |
|
36
|
|
|
|
|
|
|
} |
|
37
|
|
|
|
|
|
|
); |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
$webapp->run(); |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
You'll need to replace the "/path/to/photos" with the real path to your |
|
42
|
|
|
|
|
|
|
photos (see the photos_dir options below). |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
Put this somewhere where CGIs can run and name it something like |
|
45
|
|
|
|
|
|
|
C. |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
This gets you the default behavior and look. To get something more to |
|
48
|
|
|
|
|
|
|
your specifications you can use the options described below. |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=head1 INSTALLATION |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
perl Makefile.PL |
|
53
|
|
|
|
|
|
|
make |
|
54
|
|
|
|
|
|
|
make test |
|
55
|
|
|
|
|
|
|
make install |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=head1 OPTIONS |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
L modules accept options using the PARAMS arguement to |
|
60
|
|
|
|
|
|
|
C. To give options for this module you change the C |
|
61
|
|
|
|
|
|
|
call in the instance script shown above: |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
my $webapp = CGI::Application::PhotoGallery->new( |
|
64
|
|
|
|
|
|
|
PARAMS => { |
|
65
|
|
|
|
|
|
|
photos_dir => '/path/to/photos', |
|
66
|
|
|
|
|
|
|
title => 'My Photos' |
|
67
|
|
|
|
|
|
|
} |
|
68
|
|
|
|
|
|
|
); |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
The C option tells PhotoGallery to use 'My Photos' as the title |
|
71
|
|
|
|
|
|
|
rather than the default value. See below for more information |
|
72
|
|
|
|
|
|
|
about C and other options. |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=head2 photos_dir (required) |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
This parameter is used to specify where all of your photos are |
|
77
|
|
|
|
|
|
|
located. |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
Previous limitations of this directory have been lifted. |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
Your photos directory can have any number of images and sub-directories |
|
82
|
|
|
|
|
|
|
of images. This is applied recursively so a gallery can have any number |
|
83
|
|
|
|
|
|
|
of sub-galleries. |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=head2 script_name |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
This parameter uses C<$0> by default, you can change it (or set it to the |
|
88
|
|
|
|
|
|
|
empty string) if you neeed to. It is needed for creating self referencial |
|
89
|
|
|
|
|
|
|
links. |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head2 title |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
By default every page will start with the title "My Photo Gallery". |
|
94
|
|
|
|
|
|
|
You can specify your own using the title parameter. |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=head2 thumb_size |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
By default PhotoGallery displays thumbnail images that are 100 x 100 |
|
99
|
|
|
|
|
|
|
on the index page. You can change this by specifying a number |
|
100
|
|
|
|
|
|
|
(in pixels) for this option. |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=head2 preview_thumbs |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
Before viewing the entire contents of a gallery, you are shown a few |
|
105
|
|
|
|
|
|
|
preview image. The default number of thumbnails is C<4>. You |
|
106
|
|
|
|
|
|
|
can change it by specifying your own value in the instance script. |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=head2 graphics_lib |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
You can specifify which graphics library you wish to use to size your |
|
111
|
|
|
|
|
|
|
thumbnails. Included in this package are C (Image::Magick) and |
|
112
|
|
|
|
|
|
|
the default: C. You can also create your own if you wish. |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=head2 index_template |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
This application uses L to generate its HTML pages. If |
|
117
|
|
|
|
|
|
|
you would like to customize the HTML you can copy the default form |
|
118
|
|
|
|
|
|
|
template and edit it to suite your needs. The default form template |
|
119
|
|
|
|
|
|
|
is called 'photos_index.tmpl' and you can get it from the distribution |
|
120
|
|
|
|
|
|
|
or from wherever this module ended up in your C<@INC>. Pass in the |
|
121
|
|
|
|
|
|
|
path to your custom template as the value of this parameter. |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
See L for more information about the template syntax. |
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=head2 single_template |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
The default template for an individual photo is called |
|
128
|
|
|
|
|
|
|
'photos_single.tmpl' and you can get it from the distribution or from |
|
129
|
|
|
|
|
|
|
wherever this module ended up in your C<@INC>. Pass in the path to |
|
130
|
|
|
|
|
|
|
your custom template as the value of this parameter. |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
See L for more information about the template syntax. |
|
133
|
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=head2 max_width |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
Setting this value will force the browser to scale images down to this |
|
137
|
|
|
|
|
|
|
particular width and proportioned height. This is done by setting the width |
|
138
|
|
|
|
|
|
|
and height attributes on the image tag, thus saving the image will retain the |
|
139
|
|
|
|
|
|
|
full resolution. |
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=head2 max_height |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
Setting this value will force the browser to scale images down to this |
|
144
|
|
|
|
|
|
|
particular height and proportioned width. This is done by setting the width |
|
145
|
|
|
|
|
|
|
and height attributes on the image tag, thus saving the image will retain the |
|
146
|
|
|
|
|
|
|
full resolution. |
|
147
|
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=head2 cache_root |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
Specifies where the file cache data will be stored. Defaults to FileCache |
|
151
|
|
|
|
|
|
|
under the OS-specific temporary filesdirectory (e.g. /tmp/FileCache). You |
|
152
|
|
|
|
|
|
|
may want to move this to make the cache persist. Under selinux, however, |
|
153
|
|
|
|
|
|
|
be careful to put it in a webserver-writable directory. |
|
154
|
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=head2 cache_namespace |
|
156
|
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
Specifies the namespace for this gallery's cache data. Defaults to the |
|
158
|
|
|
|
|
|
|
gallery title - or 'default'. Changing this will orphan the cache data. |
|
159
|
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=head2 cache_dirumask |
|
161
|
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
Specifies the umask value to use when cache directories are created. Defaults |
|
163
|
|
|
|
|
|
|
to 0007 to avoid cache poisioning attacks. |
|
164
|
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=head2 cache_datumask |
|
166
|
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
Specifies the umask value to use when cache data is written. Defaults to 006 |
|
168
|
|
|
|
|
|
|
to avoid cache poisioning attacks. Note that this becomes the umask for all |
|
169
|
|
|
|
|
|
|
files written by this script. (See Cache::FileCache documentation for why.) |
|
170
|
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=head1 CAPTIONS |
|
172
|
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
You can include captions for your photos by creating a tab-separated |
|
174
|
|
|
|
|
|
|
database named C in your C. The filename |
|
175
|
|
|
|
|
|
|
should be specified relative of your C. |
|
176
|
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
1.jpg This is a caption. |
|
178
|
|
|
|
|
|
|
Test Gallery/1.jpg This is another caption. |
|
179
|
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=head1 METHODS |
|
181
|
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
=cut |
|
183
|
|
|
|
|
|
|
|
|
184
|
1
|
|
|
1
|
|
45816
|
use base qw( CGI::Application ); |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
1289
|
|
|
185
|
|
|
|
|
|
|
|
|
186
|
1
|
|
|
1
|
|
40357
|
use strict; |
|
|
1
|
|
|
|
|
6
|
|
|
|
1
|
|
|
|
|
45
|
|
|
187
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
|
1
|
|
|
|
|
8
|
|
|
|
1
|
|
|
|
|
193
|
|
|
188
|
|
|
|
|
|
|
|
|
189
|
1
|
|
|
1
|
|
6
|
use File::Basename; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
211
|
|
|
190
|
1
|
|
|
1
|
|
1940
|
use Cache::FileCache; |
|
|
1
|
|
|
|
|
144755
|
|
|
|
1
|
|
|
|
|
52
|
|
|
191
|
1
|
|
|
1
|
|
965
|
use MIME::Types; |
|
|
1
|
|
|
|
|
6119
|
|
|
|
1
|
|
|
|
|
44
|
|
|
192
|
1
|
|
|
1
|
|
1152
|
use File::Find::Rule; |
|
|
1
|
|
|
|
|
14728
|
|
|
|
1
|
|
|
|
|
11
|
|
|
193
|
1
|
|
|
1
|
|
1084
|
use File::ShareDir; |
|
|
1
|
|
|
|
|
21737
|
|
|
|
1
|
|
|
|
|
94
|
|
|
194
|
1
|
|
|
1
|
|
1176
|
use HTTP::Date (); |
|
|
1
|
|
|
|
|
216664
|
|
|
|
1
|
|
|
|
|
4601
|
|
|
195
|
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
our $VERSION = '0.16'; |
|
197
|
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
=head2 setup( ) |
|
199
|
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
This method sets the default options and makes sure all required |
|
201
|
|
|
|
|
|
|
parameteres are set. |
|
202
|
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
=cut |
|
204
|
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
sub setup { |
|
206
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
207
|
|
|
|
|
|
|
|
|
208
|
0
|
|
|
|
|
|
$self->mode_param( 'mode' ); |
|
209
|
0
|
|
|
|
|
|
$self->run_modes( |
|
210
|
|
|
|
|
|
|
index => 'gallery_index', |
|
211
|
|
|
|
|
|
|
thumb => 'thumbnail', |
|
212
|
|
|
|
|
|
|
full => 'show_image', |
|
213
|
|
|
|
|
|
|
view => 'single_index', |
|
214
|
|
|
|
|
|
|
AUTOLOAD => 'gallery_index' |
|
215
|
|
|
|
|
|
|
); |
|
216
|
0
|
|
|
|
|
|
$self->start_mode( 'index' ); |
|
217
|
0
|
|
|
|
|
|
$self->error_mode( 'handle_error' ); |
|
218
|
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
# setup defaults |
|
220
|
|
|
|
|
|
|
|
|
221
|
0
|
0
|
|
|
|
|
$self->param( thumb_size => 100 ) |
|
222
|
|
|
|
|
|
|
unless defined $self->param( 'thumb_size' ); |
|
223
|
0
|
0
|
|
|
|
|
$self->param( preview_thumbs => 4 ) |
|
224
|
|
|
|
|
|
|
unless defined $self->param( 'preview_thumbs' ); |
|
225
|
0
|
0
|
|
|
|
|
$self->param( title => 'My Photo Gallery' ) |
|
226
|
|
|
|
|
|
|
unless defined $self->param( 'title' ); |
|
227
|
0
|
0
|
|
|
|
|
$self->param( graphics_lib => 'GD' ) |
|
228
|
|
|
|
|
|
|
unless defined $self->param( 'graphics_lib' ); |
|
229
|
0
|
0
|
|
|
|
|
$self->param( script_name => $0 ) |
|
230
|
|
|
|
|
|
|
unless defined $self->param( 'script_name' ); |
|
231
|
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
# check required params |
|
233
|
|
|
|
|
|
|
|
|
234
|
0
|
0
|
|
|
|
|
die |
|
235
|
|
|
|
|
|
|
"PARAMS => { photos_dir => '/path/to/photos' } not set in your instance script!" |
|
236
|
|
|
|
|
|
|
unless defined $self->param( 'photos_dir' ); |
|
237
|
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
# fixes $0 for win32 |
|
239
|
|
|
|
|
|
|
|
|
240
|
0
|
0
|
|
|
|
|
$self->param( script_name => basename( $self->param( 'script_name' ) ) ) |
|
241
|
|
|
|
|
|
|
if $self->param( 'script_name' ); |
|
242
|
|
|
|
|
|
|
} |
|
243
|
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
=head2 get_photos( $dir ) |
|
245
|
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
This method finds all of the C files in the specified |
|
247
|
|
|
|
|
|
|
directory. |
|
248
|
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
=cut |
|
250
|
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
sub get_photos { |
|
252
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
253
|
0
|
|
|
|
|
|
my $dir = shift; |
|
254
|
0
|
|
|
|
|
|
my $types = $self->mime_types; |
|
255
|
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
my @photos = sort File::Find::Rule->maxdepth( 1 )->file->exec( |
|
257
|
|
|
|
|
|
|
sub { |
|
258
|
0
|
|
|
0
|
|
|
my $name = pop; |
|
259
|
0
|
0
|
|
|
|
|
return 0 if basename( $name ) eq 'favicon.ico'; |
|
260
|
0
|
|
|
|
|
|
my $mime = $types->mimeTypeOf( $name ); |
|
261
|
0
|
0
|
0
|
|
|
|
return 1 if $mime && $mime->mediaType eq 'image'; |
|
262
|
|
|
|
|
|
|
} |
|
263
|
0
|
|
|
|
|
|
)->in( $dir ); |
|
264
|
|
|
|
|
|
|
|
|
265
|
0
|
|
|
|
|
|
return @photos; |
|
266
|
|
|
|
|
|
|
} |
|
267
|
|
|
|
|
|
|
|
|
268
|
|
|
|
|
|
|
=head2 mime_types( ) |
|
269
|
|
|
|
|
|
|
|
|
270
|
|
|
|
|
|
|
This method will create (if needed) and return a new L object. |
|
271
|
|
|
|
|
|
|
|
|
272
|
|
|
|
|
|
|
=cut |
|
273
|
|
|
|
|
|
|
|
|
274
|
|
|
|
|
|
|
sub mime_types { |
|
275
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
276
|
|
|
|
|
|
|
|
|
277
|
0
|
0
|
|
|
|
|
unless ( $self->{ _mime_types } ) { |
|
278
|
0
|
|
|
|
|
|
my $types = MIME::Types->new( only_complete => 1 ); |
|
279
|
0
|
|
|
|
|
|
$types->create_type_index; |
|
280
|
0
|
|
|
|
|
|
$self->{ _mime_types } = $types; |
|
281
|
|
|
|
|
|
|
} |
|
282
|
|
|
|
|
|
|
|
|
283
|
0
|
|
|
|
|
|
return $self->{ _mime_types }; |
|
284
|
|
|
|
|
|
|
} |
|
285
|
|
|
|
|
|
|
|
|
286
|
|
|
|
|
|
|
=head2 gfx_lib( ) |
|
287
|
|
|
|
|
|
|
|
|
288
|
|
|
|
|
|
|
This method will create (if needed) and return the graphics adaptor specified by |
|
289
|
|
|
|
|
|
|
the user (default is GD). |
|
290
|
|
|
|
|
|
|
|
|
291
|
|
|
|
|
|
|
=cut |
|
292
|
|
|
|
|
|
|
|
|
293
|
|
|
|
|
|
|
sub gfx_lib { |
|
294
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
295
|
|
|
|
|
|
|
|
|
296
|
0
|
0
|
|
|
|
|
unless ( $self->{ _gfx_lib } ) { |
|
297
|
0
|
|
|
|
|
|
my $lib = 'CGI::Application::PhotoGallery::' |
|
298
|
|
|
|
|
|
|
. $self->param( 'graphics_lib' ); |
|
299
|
0
|
|
|
|
|
|
eval "require $lib"; |
|
300
|
0
|
|
|
|
|
|
$self->{ _gfx_lib } = $lib->new; |
|
301
|
|
|
|
|
|
|
} |
|
302
|
|
|
|
|
|
|
|
|
303
|
0
|
|
|
|
|
|
return $self->{ _gfx_lib }; |
|
304
|
|
|
|
|
|
|
} |
|
305
|
|
|
|
|
|
|
|
|
306
|
|
|
|
|
|
|
=head2 cache( ) |
|
307
|
|
|
|
|
|
|
|
|
308
|
|
|
|
|
|
|
This method will create (if needed) and return a L object, |
|
309
|
|
|
|
|
|
|
|
|
310
|
|
|
|
|
|
|
=cut |
|
311
|
|
|
|
|
|
|
|
|
312
|
|
|
|
|
|
|
sub cache { |
|
313
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
314
|
|
|
|
|
|
|
|
|
315
|
0
|
0
|
|
|
|
|
unless ( $self->{ _cache } ) { |
|
316
|
0
|
|
|
|
|
|
my %options = ( namespace => $self->param( 'title' ), |
|
317
|
|
|
|
|
|
|
directory_umask => 0007 ); |
|
318
|
|
|
|
|
|
|
|
|
319
|
0
|
0
|
|
|
|
|
$options{ 'cache_root' } = $self->param( 'cache_root' ) |
|
320
|
|
|
|
|
|
|
if defined $self->param( 'cache_root' ); |
|
321
|
0
|
0
|
|
|
|
|
$options{ 'namespace' } = $self->param( 'cache_namespace' ) |
|
322
|
|
|
|
|
|
|
if defined $self->param( 'cache_namespace' ); |
|
323
|
0
|
0
|
|
|
|
|
$options{ 'directory_umask' } = $self->param( 'cache_dirumask' ) |
|
324
|
|
|
|
|
|
|
if defined $self->param( 'cache_dirumask' ); |
|
325
|
0
|
0
|
|
|
|
|
if ( defined $self->param( 'cache_datumask' ) ) { |
|
326
|
0
|
|
|
|
|
|
umask $self->param( 'cache_datumask' ); |
|
327
|
|
|
|
|
|
|
} |
|
328
|
|
|
|
|
|
|
else { |
|
329
|
0
|
|
|
|
|
|
umask 006; |
|
330
|
|
|
|
|
|
|
} |
|
331
|
0
|
|
|
|
|
|
$self->{ _cache } = Cache::FileCache->new( \%options ); |
|
332
|
|
|
|
|
|
|
} |
|
333
|
|
|
|
|
|
|
|
|
334
|
0
|
|
|
|
|
|
return $self->{ _cache }; |
|
335
|
|
|
|
|
|
|
|
|
336
|
|
|
|
|
|
|
} |
|
337
|
|
|
|
|
|
|
|
|
338
|
|
|
|
|
|
|
=head1 RUN MODES |
|
339
|
|
|
|
|
|
|
|
|
340
|
|
|
|
|
|
|
=head2 gallery_index( ) |
|
341
|
|
|
|
|
|
|
|
|
342
|
|
|
|
|
|
|
Reads in the contents of your C and generates an index of photos. |
|
343
|
|
|
|
|
|
|
|
|
344
|
|
|
|
|
|
|
=cut |
|
345
|
|
|
|
|
|
|
|
|
346
|
|
|
|
|
|
|
sub gallery_index { |
|
347
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
348
|
0
|
|
|
|
|
|
my $types = $self->mime_types; |
|
349
|
0
|
|
|
|
|
|
my $query = $self->query; |
|
350
|
|
|
|
|
|
|
|
|
351
|
0
|
|
|
|
|
|
my $limit = $self->param( 'preview_thumbs' ); |
|
352
|
0
|
|
|
|
|
|
my $photo_dir = $self->param( 'photos_dir' ); |
|
353
|
0
|
|
0
|
|
|
|
my $user_dir = $self->query->param( 'dir' ) || ''; |
|
354
|
|
|
|
|
|
|
|
|
355
|
0
|
|
|
|
|
|
$user_dir =~ s/\.\.//g; |
|
356
|
0
|
|
|
|
|
|
$user_dir =~ s/\/$//; |
|
357
|
|
|
|
|
|
|
|
|
358
|
0
|
|
|
|
|
|
my $parent = $user_dir; |
|
359
|
0
|
|
|
|
|
|
$parent =~ s{^(.*?)/([^/]+?)/?$}{$1/}; |
|
360
|
|
|
|
|
|
|
|
|
361
|
0
|
|
|
|
|
|
my $directory = $photo_dir . $user_dir; |
|
362
|
0
|
0
|
|
|
|
|
die "ERROR: File not found." unless -e $directory; |
|
363
|
0
|
0
|
|
|
|
|
die "ERROR: '$directory' is not a directory" unless -d $directory; |
|
364
|
|
|
|
|
|
|
|
|
365
|
0
|
|
|
|
|
|
my $output; |
|
366
|
0
|
|
|
|
|
|
my $cache = $self->cache; |
|
367
|
0
|
|
|
|
|
|
my $key = $directory; |
|
368
|
0
|
|
|
|
|
|
my $lastmod = ( stat( $directory ) )[ 9 ]; |
|
369
|
0
|
|
|
|
|
|
my $cstamp = "$directory/.cachetime"; |
|
370
|
|
|
|
|
|
|
|
|
371
|
0
|
0
|
|
|
|
|
if ( $output = $cache->get( $key ) ) { |
|
372
|
0
|
|
|
|
|
|
my $cachetime = $cache->get( $cstamp ); |
|
373
|
0
|
0
|
0
|
|
|
|
if ( $cachetime && $cachetime == $lastmod ) { |
|
374
|
0
|
|
|
|
|
|
my $reqmod; |
|
375
|
0
|
0
|
|
|
|
|
if ( my $header = $query->http( 'If-Modified-Since' ) ) { |
|
376
|
0
|
|
|
|
|
|
$reqmod = HTTP::Date::str2time( |
|
377
|
|
|
|
|
|
|
( split( /;/, $header, 2 ) )[ 0 ] ); |
|
378
|
|
|
|
|
|
|
|
|
379
|
0
|
0
|
0
|
|
|
|
if ( $reqmod && $reqmod == $lastmod ) { |
|
380
|
0
|
|
|
|
|
|
$self->header_props( { -status => '304 Not Modified' } ); |
|
381
|
0
|
|
|
|
|
|
return; |
|
382
|
|
|
|
|
|
|
} |
|
383
|
|
|
|
|
|
|
} |
|
384
|
|
|
|
|
|
|
|
|
385
|
|
|
|
|
|
|
$self->header_add( |
|
386
|
0
|
|
|
|
|
|
{ -last_modified => HTTP::Date::time2str( $lastmod ) } ); |
|
387
|
0
|
|
|
|
|
|
return $output; |
|
388
|
|
|
|
|
|
|
} |
|
389
|
|
|
|
|
|
|
} |
|
390
|
|
|
|
|
|
|
|
|
391
|
0
|
|
|
|
|
|
my @dirs = sort File::Find::Rule->directory->mindepth( 1 )->maxdepth( 1 ) |
|
392
|
|
|
|
|
|
|
->in( $directory ); |
|
393
|
|
|
|
|
|
|
|
|
394
|
0
|
|
|
|
|
|
my @galleries; |
|
395
|
0
|
|
|
|
|
|
for my $dir ( $directory, @dirs ) { |
|
396
|
0
|
|
|
|
|
|
my @files = map { s/^$photo_dir//; { filename => $_ }; } |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
397
|
|
|
|
|
|
|
$self->get_photos( $dir ); |
|
398
|
|
|
|
|
|
|
|
|
399
|
|
|
|
|
|
|
# only limit the number of photos on sub-galleries |
|
400
|
0
|
0
|
|
|
|
|
if ( $dir ne $directory ) { |
|
401
|
0
|
0
|
|
|
|
|
@files = @files[ 0 .. $limit - 1 ] if @files > $limit; |
|
402
|
|
|
|
|
|
|
} |
|
403
|
|
|
|
|
|
|
|
|
404
|
0
|
|
|
|
|
|
( my $location = $dir ) =~ s/^$photo_dir//; |
|
405
|
0
|
|
|
|
|
|
push @galleries, |
|
406
|
|
|
|
|
|
|
{ |
|
407
|
|
|
|
|
|
|
dir => $location, |
|
408
|
|
|
|
|
|
|
title => basename( $dir ), |
|
409
|
|
|
|
|
|
|
photos => \@files |
|
410
|
|
|
|
|
|
|
}; |
|
411
|
|
|
|
|
|
|
} |
|
412
|
|
|
|
|
|
|
|
|
413
|
0
|
|
|
|
|
|
my $current = shift( @galleries ); |
|
414
|
|
|
|
|
|
|
|
|
415
|
0
|
|
0
|
|
|
|
my $html = $self->load_tmpl( |
|
416
|
|
|
|
|
|
|
$self->param( 'index_template' ) |
|
417
|
|
|
|
|
|
|
|| $self->_dist_file( 'photos_index.tmpl' ), |
|
418
|
|
|
|
|
|
|
associate => $self, |
|
419
|
|
|
|
|
|
|
global_vars => 1, |
|
420
|
|
|
|
|
|
|
loop_context_vars => 1, |
|
421
|
|
|
|
|
|
|
die_on_bad_params => 0 |
|
422
|
|
|
|
|
|
|
); |
|
423
|
|
|
|
|
|
|
|
|
424
|
|
|
|
|
|
|
$html->param( |
|
425
|
|
|
|
|
|
|
photos => $current->{ photos }, |
|
426
|
|
|
|
|
|
|
gallery_name => |
|
427
|
0
|
0
|
|
|
|
|
( $user_dir ? $current->{ title } : $self->param( 'title' ) ), |
|
428
|
|
|
|
|
|
|
galleries => \@galleries, |
|
429
|
|
|
|
|
|
|
parent => $parent, |
|
430
|
|
|
|
|
|
|
); |
|
431
|
|
|
|
|
|
|
|
|
432
|
0
|
|
|
|
|
|
$self->header_add( |
|
433
|
|
|
|
|
|
|
{ -last_modified => HTTP::Date::time2str( $lastmod ) } ); |
|
434
|
0
|
|
|
|
|
|
$output = $html->output; |
|
435
|
0
|
|
|
|
|
|
$cache->set( $key => $output ); |
|
436
|
0
|
|
|
|
|
|
$cache->set( $cstamp => $lastmod ); |
|
437
|
|
|
|
|
|
|
|
|
438
|
0
|
|
|
|
|
|
return $output; |
|
439
|
|
|
|
|
|
|
} |
|
440
|
|
|
|
|
|
|
|
|
441
|
|
|
|
|
|
|
=head2 thumbnail( ) |
|
442
|
|
|
|
|
|
|
|
|
443
|
|
|
|
|
|
|
Generates a thumbnail for the requested image using the selected graphics |
|
444
|
|
|
|
|
|
|
library. |
|
445
|
|
|
|
|
|
|
|
|
446
|
|
|
|
|
|
|
=cut |
|
447
|
|
|
|
|
|
|
|
|
448
|
|
|
|
|
|
|
sub thumbnail { |
|
449
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
450
|
0
|
|
|
|
|
|
my $query = $self->query; |
|
451
|
0
|
|
|
|
|
|
my $dir = $self->param( 'photos_dir' ); |
|
452
|
0
|
|
|
|
|
|
my $photo = $query->param( 'photo' ); |
|
453
|
0
|
|
|
|
|
|
my $size = $self->param( 'thumb_size' ); |
|
454
|
|
|
|
|
|
|
|
|
455
|
0
|
0
|
|
|
|
|
die 'ERROR: Missing photo query argument.' unless $photo; |
|
456
|
|
|
|
|
|
|
|
|
457
|
0
|
|
|
|
|
|
my $path = "$dir$photo"; |
|
458
|
0
|
|
|
|
|
|
my $cache = $self->cache; |
|
459
|
0
|
|
|
|
|
|
my $key = "$path$size"; |
|
460
|
0
|
|
|
|
|
|
my $lastmod = ( stat( $path ) )[ 9 ]; |
|
461
|
|
|
|
|
|
|
|
|
462
|
0
|
|
|
|
|
|
my $data; |
|
463
|
0
|
0
|
|
|
|
|
if ( $data = $cache->get( $key ) ) { |
|
464
|
0
|
|
|
|
|
|
my $reqmod; |
|
465
|
0
|
0
|
|
|
|
|
if ( my $header = $query->http( 'If-Modified-Since' ) ) { |
|
466
|
0
|
|
|
|
|
|
$reqmod |
|
467
|
|
|
|
|
|
|
= HTTP::Date::str2time( ( split( /;/, $header, 2 ) )[ 0 ] ); |
|
468
|
|
|
|
|
|
|
} |
|
469
|
|
|
|
|
|
|
|
|
470
|
0
|
0
|
0
|
|
|
|
if ( $reqmod && $reqmod == $lastmod ) { |
|
471
|
0
|
|
|
|
|
|
$self->header_props( { -status => '304 Not Modified' } ); |
|
472
|
0
|
|
|
|
|
|
return; |
|
473
|
|
|
|
|
|
|
} |
|
474
|
|
|
|
|
|
|
else { |
|
475
|
0
|
|
|
|
|
|
$data = undef; |
|
476
|
|
|
|
|
|
|
} |
|
477
|
|
|
|
|
|
|
} |
|
478
|
|
|
|
|
|
|
|
|
479
|
0
|
0
|
|
|
|
|
unless ( $data ) { |
|
480
|
0
|
|
|
|
|
|
my $gfx = $self->gfx_lib; |
|
481
|
0
|
|
|
|
|
|
$data = $gfx->resize( $path, $size ); |
|
482
|
0
|
|
|
|
|
|
$cache->set( $key => $data ); |
|
483
|
|
|
|
|
|
|
} |
|
484
|
|
|
|
|
|
|
|
|
485
|
|
|
|
|
|
|
$self->header_props( |
|
486
|
0
|
|
|
|
|
|
{ -type => $self->mime_types->mimeTypeOf( $path ), |
|
487
|
|
|
|
|
|
|
-last_modified => HTTP::Date::time2str( $lastmod ) |
|
488
|
|
|
|
|
|
|
} |
|
489
|
|
|
|
|
|
|
); |
|
490
|
|
|
|
|
|
|
|
|
491
|
0
|
|
|
|
|
|
binmode STDOUT; |
|
492
|
0
|
|
|
|
|
|
return $data; |
|
493
|
|
|
|
|
|
|
} |
|
494
|
|
|
|
|
|
|
|
|
495
|
|
|
|
|
|
|
=head2 show_image( ) |
|
496
|
|
|
|
|
|
|
|
|
497
|
|
|
|
|
|
|
Sends the contents of the image to the browser. |
|
498
|
|
|
|
|
|
|
|
|
499
|
|
|
|
|
|
|
=cut |
|
500
|
|
|
|
|
|
|
|
|
501
|
|
|
|
|
|
|
sub show_image { |
|
502
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
503
|
0
|
|
|
|
|
|
my $query = $self->query; |
|
504
|
0
|
|
|
|
|
|
my $dir = $self->param( 'photos_dir' ); |
|
505
|
0
|
|
|
|
|
|
my $photo = $query->param( 'photo' ); |
|
506
|
0
|
|
|
|
|
|
my $path = "$dir$photo"; |
|
507
|
|
|
|
|
|
|
|
|
508
|
0
|
0
|
|
|
|
|
die 'ERROR: Missing $photo query argument.' unless $photo; |
|
509
|
|
|
|
|
|
|
|
|
510
|
0
|
|
|
|
|
|
my $lastmod = ( stat( $path ) )[ 9 ]; |
|
511
|
|
|
|
|
|
|
|
|
512
|
0
|
|
|
|
|
|
my $reqmod; |
|
513
|
0
|
0
|
|
|
|
|
if ( my $header = $query->http( 'If-Modified-Since' ) ) { |
|
514
|
0
|
|
|
|
|
|
$reqmod = HTTP::Date::str2time( ( split( /;/, $header, 2 ) )[ 0 ] ); |
|
515
|
|
|
|
|
|
|
} |
|
516
|
|
|
|
|
|
|
|
|
517
|
0
|
0
|
0
|
|
|
|
if ( $reqmod && $reqmod == $lastmod ) { |
|
518
|
0
|
|
|
|
|
|
$self->header_props( { -status => '304 Not Modified' } ); |
|
519
|
0
|
|
|
|
|
|
return; |
|
520
|
|
|
|
|
|
|
} |
|
521
|
|
|
|
|
|
|
|
|
522
|
0
|
0
|
|
|
|
|
open( PHOTO, $path ) or die "ERROR: Cannot open $path: $!"; |
|
523
|
0
|
|
|
|
|
|
binmode PHOTO; |
|
524
|
0
|
|
|
|
|
|
my $data = do { local $/; }; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
525
|
0
|
|
|
|
|
|
close( PHOTO ); |
|
526
|
|
|
|
|
|
|
|
|
527
|
0
|
|
|
|
|
|
$self->header_props( |
|
528
|
|
|
|
|
|
|
{ -type => $self->mime_types->mimeTypeOf( $path ), |
|
529
|
|
|
|
|
|
|
-last_modified => HTTP::Date::time2str( $lastmod ) |
|
530
|
|
|
|
|
|
|
} |
|
531
|
|
|
|
|
|
|
); |
|
532
|
|
|
|
|
|
|
|
|
533
|
0
|
|
|
|
|
|
return $data; |
|
534
|
|
|
|
|
|
|
} |
|
535
|
|
|
|
|
|
|
|
|
536
|
|
|
|
|
|
|
=head2 single_index( ) |
|
537
|
|
|
|
|
|
|
|
|
538
|
|
|
|
|
|
|
Fills and sends the template for viewing an individual image. |
|
539
|
|
|
|
|
|
|
|
|
540
|
|
|
|
|
|
|
=cut |
|
541
|
|
|
|
|
|
|
|
|
542
|
|
|
|
|
|
|
sub single_index { |
|
543
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
544
|
0
|
|
|
|
|
|
my $query = $self->query(); |
|
545
|
0
|
|
|
|
|
|
my $dir = $self->param( 'photos_dir' ); |
|
546
|
0
|
|
|
|
|
|
my $photo = $query->param( 'photo' ); |
|
547
|
0
|
|
|
|
|
|
my $path = "$dir$photo"; |
|
548
|
|
|
|
|
|
|
|
|
549
|
0
|
0
|
|
|
|
|
die 'ERROR: Missing photo query argument.' unless $photo; |
|
550
|
0
|
0
|
|
|
|
|
die 'ERROR: File not found' unless -e $path; |
|
551
|
|
|
|
|
|
|
|
|
552
|
0
|
|
|
|
|
|
my $caption_path = "$dir/captions.txt"; |
|
553
|
|
|
|
|
|
|
|
|
554
|
0
|
|
|
|
|
|
my $output; |
|
555
|
0
|
|
|
|
|
|
my $cache = $self->cache; |
|
556
|
0
|
|
|
|
|
|
my $key = "$path.#frame"; |
|
557
|
0
|
|
|
|
|
|
my $lastmod = ( stat( $path ) )[ 9 ]; |
|
558
|
|
|
|
|
|
|
|
|
559
|
|
|
|
|
|
|
# Directory change means links may have changed |
|
560
|
|
|
|
|
|
|
# Caption file change is a content change |
|
561
|
0
|
|
|
|
|
|
my $lastdir = ( stat( $dir ) )[ 9 ]; |
|
562
|
0
|
0
|
|
|
|
|
$lastmod = $lastdir if ( $lastdir > $lastmod ); |
|
563
|
0
|
|
|
|
|
|
my $lastcap = 0; |
|
564
|
0
|
0
|
|
|
|
|
$lastcap = ( stat( $caption_path ) )[ 9 ] if ( -r $caption_path ); |
|
565
|
0
|
0
|
|
|
|
|
$lastmod = $lastcap if ( $lastcap > $lastmod ); |
|
566
|
0
|
|
|
|
|
|
my $cstamp = "$key#cachetime"; |
|
567
|
|
|
|
|
|
|
|
|
568
|
0
|
0
|
|
|
|
|
if ( $output = $cache->get( $key ) ) { |
|
569
|
0
|
|
|
|
|
|
my $cachetime = $cache->get( $cstamp ); |
|
570
|
0
|
0
|
0
|
|
|
|
if ( $cachetime && $cachetime == $lastmod ) { |
|
571
|
0
|
|
|
|
|
|
my $reqmod; |
|
572
|
0
|
0
|
|
|
|
|
if ( my $header = $query->http( 'If-Modified-Since' ) ) { |
|
573
|
0
|
|
|
|
|
|
$reqmod = HTTP::Date::str2time( |
|
574
|
|
|
|
|
|
|
( split( /;/, $header, 2 ) )[ 0 ] ); |
|
575
|
|
|
|
|
|
|
|
|
576
|
0
|
0
|
0
|
|
|
|
if ( $reqmod && $reqmod == $lastmod ) { |
|
577
|
0
|
|
|
|
|
|
$self->header_props( { -status => '304 Not Modified' } ); |
|
578
|
0
|
|
|
|
|
|
return; |
|
579
|
|
|
|
|
|
|
} |
|
580
|
|
|
|
|
|
|
} |
|
581
|
|
|
|
|
|
|
|
|
582
|
|
|
|
|
|
|
$self->header_add( |
|
583
|
0
|
|
|
|
|
|
{ -last_modified => HTTP::Date::time2str( $lastmod ) } ); |
|
584
|
0
|
|
|
|
|
|
return $output; |
|
585
|
|
|
|
|
|
|
} |
|
586
|
|
|
|
|
|
|
} |
|
587
|
|
|
|
|
|
|
|
|
588
|
0
|
|
|
|
|
|
my $gfx = $self->gfx_lib; |
|
589
|
|
|
|
|
|
|
|
|
590
|
0
|
|
|
|
|
|
my ( $width, $height ) = eval { $gfx->size( $path ); }; |
|
|
0
|
|
|
|
|
|
|
|
591
|
|
|
|
|
|
|
|
|
592
|
0
|
0
|
|
|
|
|
die "Unable to determine size of $path; file may be corrupt.\nError string: $@" if $@; |
|
593
|
|
|
|
|
|
|
|
|
594
|
|
|
|
|
|
|
# get data for prev/next/parent links |
|
595
|
0
|
|
|
|
|
|
my ( undef, $search_dir ) = fileparse( $path ); |
|
596
|
0
|
|
|
|
|
|
my ( undef, $parent ) = fileparse( $photo ); |
|
597
|
0
|
|
|
|
|
|
my @files = $self->get_photos( $search_dir ); |
|
598
|
0
|
|
|
|
|
|
my ( $prev, $next ); |
|
599
|
|
|
|
|
|
|
|
|
600
|
0
|
|
|
|
|
|
while ( my $f = shift @files ) { |
|
601
|
0
|
|
|
|
|
|
$f =~ s{^$dir}{}; |
|
602
|
0
|
0
|
|
|
|
|
if ( $f ne $photo ) { |
|
603
|
0
|
|
|
|
|
|
$prev = $f; |
|
604
|
0
|
|
|
|
|
|
next; |
|
605
|
|
|
|
|
|
|
} |
|
606
|
|
|
|
|
|
|
else { |
|
607
|
0
|
|
|
|
|
|
$next = shift @files; |
|
608
|
0
|
0
|
|
|
|
|
$next =~ s{^$dir}{} if $next; |
|
609
|
0
|
|
|
|
|
|
last; |
|
610
|
|
|
|
|
|
|
} |
|
611
|
|
|
|
|
|
|
} |
|
612
|
|
|
|
|
|
|
|
|
613
|
0
|
|
0
|
|
|
|
my $html = $self->load_tmpl( |
|
614
|
|
|
|
|
|
|
$self->param( 'single_template' ) |
|
615
|
|
|
|
|
|
|
|| $self->_dist_file( 'photos_single.tmpl' ), |
|
616
|
|
|
|
|
|
|
associate => $self, |
|
617
|
|
|
|
|
|
|
global_vars => 1, |
|
618
|
|
|
|
|
|
|
die_on_bad_params => 0 |
|
619
|
|
|
|
|
|
|
); |
|
620
|
|
|
|
|
|
|
|
|
621
|
0
|
0
|
|
|
|
|
if ( defined( my $max_width = $self->param( 'max_width' ) ) ) { |
|
622
|
0
|
0
|
|
|
|
|
if ( $width > $max_width ) { |
|
623
|
0
|
|
|
|
|
|
my $scale = $max_width / $width; |
|
624
|
0
|
|
|
|
|
|
$width = int( $width * $scale ); |
|
625
|
0
|
|
|
|
|
|
$height = int( $height * $scale ); |
|
626
|
|
|
|
|
|
|
} |
|
627
|
|
|
|
|
|
|
} |
|
628
|
|
|
|
|
|
|
|
|
629
|
0
|
0
|
|
|
|
|
if ( defined( my $max_height = $self->param( 'max_height' ) ) ) { |
|
630
|
0
|
0
|
|
|
|
|
if ( $height > $max_height ) { |
|
631
|
0
|
|
|
|
|
|
my $scale = $max_height / $height; |
|
632
|
0
|
|
|
|
|
|
$width = int( $width * $scale ); |
|
633
|
0
|
|
|
|
|
|
$height = int( $height * $scale ); |
|
634
|
|
|
|
|
|
|
} |
|
635
|
|
|
|
|
|
|
} |
|
636
|
|
|
|
|
|
|
|
|
637
|
|
|
|
|
|
|
$html->param( |
|
638
|
0
|
|
|
|
|
|
photo => $photo, |
|
639
|
|
|
|
|
|
|
width => $width, |
|
640
|
|
|
|
|
|
|
height => $height, |
|
641
|
|
|
|
|
|
|
next => $next, |
|
642
|
|
|
|
|
|
|
prev => $prev, |
|
643
|
|
|
|
|
|
|
parent => $parent, |
|
644
|
|
|
|
|
|
|
); |
|
645
|
|
|
|
|
|
|
|
|
646
|
|
|
|
|
|
|
# get caption, if available |
|
647
|
0
|
0
|
|
|
|
|
if ( -e $caption_path ) { |
|
648
|
0
|
0
|
|
|
|
|
open( CAPTIONS, $caption_path ) |
|
649
|
|
|
|
|
|
|
or die "ERROR: Cannot open caption file $caption_path: $!"; |
|
650
|
0
|
|
|
|
|
|
while ( my $caption = ) { |
|
651
|
0
|
0
|
|
|
|
|
if ( $caption =~ /^\Q$photo\E\t(.+)$/ ) { |
|
652
|
0
|
|
|
|
|
|
$html->param( caption => $1 ); |
|
653
|
0
|
|
|
|
|
|
last; |
|
654
|
|
|
|
|
|
|
} |
|
655
|
|
|
|
|
|
|
} |
|
656
|
0
|
|
|
|
|
|
close( CAPTIONS ); |
|
657
|
|
|
|
|
|
|
} |
|
658
|
|
|
|
|
|
|
|
|
659
|
|
|
|
|
|
|
$self->header_add( |
|
660
|
0
|
|
|
|
|
|
{ -last_modified => HTTP::Date::time2str( $lastmod ) } ); |
|
661
|
0
|
|
|
|
|
|
$output = $html->output; |
|
662
|
0
|
|
|
|
|
|
$cache->set( $key => $output ); |
|
663
|
0
|
|
|
|
|
|
$cache->set( $cstamp => $lastmod ); |
|
664
|
|
|
|
|
|
|
|
|
665
|
0
|
|
|
|
|
|
return $output; |
|
666
|
|
|
|
|
|
|
} |
|
667
|
|
|
|
|
|
|
|
|
668
|
|
|
|
|
|
|
sub _dist_file { |
|
669
|
0
|
|
|
0
|
|
|
my ( $self, $file ) = @_; |
|
670
|
0
|
|
|
|
|
|
return File::ShareDir::dist_file( 'CGI-Application-PhotoGallery', $file ); |
|
671
|
|
|
|
|
|
|
} |
|
672
|
|
|
|
|
|
|
|
|
673
|
|
|
|
|
|
|
=head2 handle_error( ) |
|
674
|
|
|
|
|
|
|
|
|
675
|
|
|
|
|
|
|
Renders a template for any failed action. |
|
676
|
|
|
|
|
|
|
|
|
677
|
|
|
|
|
|
|
=cut |
|
678
|
|
|
|
|
|
|
|
|
679
|
|
|
|
|
|
|
sub handle_error { |
|
680
|
0
|
|
|
0
|
1
|
|
my ( $self, $error ) = @_; |
|
681
|
|
|
|
|
|
|
|
|
682
|
0
|
0
|
|
|
|
|
if ( $error =~ m{file not found}i ) { |
|
683
|
0
|
|
|
|
|
|
$self->header_props( { -status => '404 Not Found' } ); |
|
684
|
0
|
|
|
|
|
|
$error = 'ERROR: File not found.'; |
|
685
|
|
|
|
|
|
|
} |
|
686
|
|
|
|
|
|
|
else { |
|
687
|
|
|
|
|
|
|
# log non-404 errors |
|
688
|
0
|
|
|
|
|
|
warn $error; |
|
689
|
0
|
|
|
|
|
|
$error =~ s{\n}{ }g; |
|
690
|
0
|
|
|
|
|
|
$self->header_props( { -status => '500 Error' } ); |
|
691
|
|
|
|
|
|
|
} |
|
692
|
|
|
|
|
|
|
|
|
693
|
0
|
|
0
|
|
|
|
my $html = $self->load_tmpl( |
|
694
|
|
|
|
|
|
|
$self->param( 'error_template' ) || $self->_dist_file( 'error.tmpl' ), |
|
695
|
|
|
|
|
|
|
associate => $self, |
|
696
|
|
|
|
|
|
|
global_vars => 1, |
|
697
|
|
|
|
|
|
|
die_on_bad_params => 0 |
|
698
|
|
|
|
|
|
|
); |
|
699
|
|
|
|
|
|
|
|
|
700
|
0
|
|
|
|
|
|
$html->param( error => $error ); |
|
701
|
|
|
|
|
|
|
|
|
702
|
0
|
|
|
|
|
|
return $html->output; |
|
703
|
|
|
|
|
|
|
} |
|
704
|
|
|
|
|
|
|
|
|
705
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
706
|
|
|
|
|
|
|
|
|
707
|
|
|
|
|
|
|
=over 4 |
|
708
|
|
|
|
|
|
|
|
|
709
|
|
|
|
|
|
|
=item * L |
|
710
|
|
|
|
|
|
|
|
|
711
|
|
|
|
|
|
|
=item * L |
|
712
|
|
|
|
|
|
|
|
|
713
|
|
|
|
|
|
|
=item * L |
|
714
|
|
|
|
|
|
|
|
|
715
|
|
|
|
|
|
|
=back |
|
716
|
|
|
|
|
|
|
|
|
717
|
|
|
|
|
|
|
=head1 AUTHOR |
|
718
|
|
|
|
|
|
|
|
|
719
|
|
|
|
|
|
|
Brian Cassidy Ebricas@cpan.orgE |
|
720
|
|
|
|
|
|
|
|
|
721
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
722
|
|
|
|
|
|
|
|
|
723
|
|
|
|
|
|
|
Copyright 2003-2013 by Brian Cassidy |
|
724
|
|
|
|
|
|
|
|
|
725
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
|
726
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
|
727
|
|
|
|
|
|
|
|
|
728
|
|
|
|
|
|
|
=cut |
|
729
|
|
|
|
|
|
|
|
|
730
|
|
|
|
|
|
|
1; |