# Let Apache serve icons without us modifying the request
if ($r->uri =~ m/^\/icons/i) {
if ($r->uri =~ m/^\/icons\/gallery\/([^\/]+$)/i) {
- $filename = "/usr/share/libapache-gallery-perl/icons/$filename";
- $r->filename($filename);
- }
- return $::MP2 ? Apache2::Const::DECLINED() : Apache::Constants::DECLINED();
+ $filename = "/usr/share/libapache-gallery-perl/icons/$1";
+ return send_file($r,$filename);
+ } else {
+ return $::MP2 ? Apache2::Const::DECLINED() : Apache::Constants::DECLINED();
+ }
}
# Lookup the file in the cache and scale the image if the cached
# image does not exist
my $file = cache_dir($r, 0);
$file =~ s/\.cache//;
- my $subr = $r->lookup_file($file);
- $r->content_type($subr->content_type());
+ return send_file($r,$file);
- if ($::MP2) {
- my $fileinfo = stat($file);
-
- my $nonce = md5_base64($fileinfo->ino.$fileinfo->mtime);
- if ($r->headers_in->{"If-None-Match"} eq $nonce) {
- return Apache2::Const::HTTP_NOT_MODIFIED();
- }
-
- if ($r->headers_in->{"If-Modified-Since"} && str2time($r->headers_in->{"If-Modified-Since"}) < $fileinfo->mtime) {
- return Apache2::Const::HTTP_NOT_MODIFIED();
- }
-
- $r->headers_out->{"Content-Length"} = $fileinfo->size;
- $r->headers_out->{"Last-Modified-Date"} = time2str($fileinfo->mtime);
- $r->headers_out->{"ETag"} = $nonce;
- $r->sendfile($file);
- return Apache2::Const::OK();
- }
- else {
- $r->path_info('');
- $r->filename($file);
- return Apache::Constants::DECLINED();
- }
}
unless ($doc_pattern) {
$doc_pattern = '\.(mpe?g|avi|mov|asf|wmv|doc|mp3|mp4|ogg|pdf|rtf|wav|dlt|txt|html?|csv|eps)$'
}
- my $img_pattern = $r->dir_config('GalleryImgFile');
- unless ($img_pattern) {
+ my $img_pattern = $r->dir_config('GalleryImgFile') unless ($img_pattern) {
$img_pattern = '\.(jpe?g|png|tiff?|ppm)$'
}
}
+sub send_file {
+ my ($r,$file) = @_;
+ my $subr = $r->lookup_file($file);
+ $r->content_type($subr->content_type());
+ if ($::MP2) {
+ my $fileinfo = stat($file);
+
+ my $nonce = md5_base64($fileinfo->ino.$fileinfo->mtime);
+ if ($r->headers_in->{"If-None-Match"} eq $nonce) {
+ return Apache2::Const::HTTP_NOT_MODIFIED();
+ }
+
+ if ($r->headers_in->{"If-Modified-Since"} && str2time($r->headers_in->{"If-Modified-Since"}) < $fileinfo->mtime) {
+ return Apache2::Const::HTTP_NOT_MODIFIED();
+ }
+
+ $r->headers_out->{"Content-Length"} = $fileinfo->size;
+ $r->headers_out->{"Last-Modified-Date"} = time2str($fileinfo->mtime);
+ $r->headers_out->{"ETag"} = $nonce;
+ $r->sendfile($file);
+ return Apache2::Const::OK();
+ }
+ else {
+ $r->path_info('');
+ $r->filename($file);
+ return Apache::Constants::DECLINED();
+ }
+}
+
sub cache_dir {
my ($r, $strip_filename) = @_;
as normal files. All other filetypes will still be served by Apache::Gallery
but are not visible in the index.
-The default is
-
- '\.(mpe?g|avi|mov|asf|wmv|doc|mp3|mp4
- |ogg|pdf|rtf|wav|dlt|txt|html?|csv|eps)$'
+The default is '\.(mpe?g|avi|mov|asf|wmv|doc|mp3|mp4|ogg|pdf|rtf|wav|dlt|txt|html?|csv|eps)$'
=item B<GalleryTTFDir>
}
my $r=request(undef, 1);
-is(Apache::Gallery::cache_dir($r, 1), '/var/tmp/Apache-Gallery/hostname/uripath1/uripath2');
-is(Apache::Gallery::cache_dir($r, 0), '/var/tmp/Apache-Gallery/hostname/uripath1/uripath2/urifile');
+is(Apache::Gallery::cache_dir($r, 1), '/var/cache/www/hostname/uripath1/uripath2');
+is(Apache::Gallery::cache_dir($r, 0), '/var/cache/www/hostname/uripath1/uripath2/urifile');
$r=request(undef, 0);
-is(Apache::Gallery::cache_dir($r, 1), '/var/tmp/Apache-Gallery/location/uripath1/uripath2');
-is(Apache::Gallery::cache_dir($r, 0), '/var/tmp/Apache-Gallery/location/uripath1/uripath2/urifile');
+is(Apache::Gallery::cache_dir($r, 1), '/var/cache/www/location/uripath1/uripath2');
+is(Apache::Gallery::cache_dir($r, 0), '/var/cache/www/location/uripath1/uripath2/urifile');
$r=request('t/cachetest', 1);
is(Apache::Gallery::cache_dir($r, 1), 't/cachetest/uripath1/uripath2');