Mail Index
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[ApacheGallery] more filetype patch
Heelo.
Attached is a patch for more configurable filetype selection with A::G. It
adds two configuration directives:
GalleryDocFile is a pattern matching all non-image files to be displayed
GalleryImgFile is a pattern matching all images file to be displayed
Exemple:
PerlSetVar GalleryDocFile '\.(mpe?g|avi|mov|asf|wmv|doc|mp3|ogg|
pdf|rtf|wav|txt|dlt|html?|csv|eps)$'
PerlSetVar GalleryImgFile '\.(jpe?g|png|tiff?|ppm|gif)$
I also changed a bit the way mimetype is selected, to allow for unknown files
to have their own icons. I think however base directory for icons should be
changed, so as to avoid conflict with apache filetype icons (c.png, for
instance).
I added GIF format in supported image format, with thumbnails in jpg. I also
tried EPS file, but very curiously, only the first one in directory is
correctly resized and displayed, and trying to select it result in a crash.
I have the following error messages in my log when accessing the directory:
ESP Ghostscript 7.07.1: Unrecoverable error, exit code 1
And the following when trying to access the image:
Can't call method "create_scaled_image" on an undefined value
at /usr/lib/perl5/vendor_perl/5.8.2/Apache/Gallery.pm line 1185
BTW, maybe what i'm trying to achieve (some kind of read-only file manager on
the web) isn't the objective of A::G. I anyone knows of a better suited
software, please let me know.
--
It is generally inadvisable to eject directly over the area you just bombed
-- Murphy's New Military Laws n°2
--- lib/Apache/Gallery.pm 2003-09-07 19:28:42.000000000 +0200
+++ /usr/lib/perl5/vendor_perl/5.8.2/Apache/Gallery.pm 2003-12-11 20:29:58.000000000 +0100
@@ -58,6 +58,8 @@
sub handler {
my $r = shift or Apache->request();
+ my $doc_pattern = $r->dir_config('GalleryDocFile');
+ my $img_pattern = $r->dir_config('GalleryImgFile');
if ((not $memoized) and ($r->dir_config('GalleryMemoize'))) {
require Memoize;
@@ -130,7 +132,7 @@
}
# Let Apache serve files we don't know how to handle anyway
- if (-f $filename && $filename !~ m/\.(?:jpe?g|png|tiff?|ppm)$/i) {
+ if (-f $filename && $filename !~ m/$img_pattern/i) {
return MP2 ? Apache::DECLINED : Apache::Constants::DECLINED;
}
@@ -186,11 +188,12 @@
my $file = $topdir."/".$picture;
- if ($file =~ m/\.(mpe?g|mov|avi|asf|wmv|wav|rtf|pdf|ogg|mp3|doc)$/i) {
+ if ($file =~ /$doc_pattern/i) {
push (@downloadable_files, $picture);
+
}
- if ($file =~ m/\.(?:jpe?g|png|tiff?|ppm)$/i) {
+ if ($file =~ /$img_pattern/i) {
push (@new_files, $picture);
}
@@ -279,17 +282,20 @@
$tpl->parse(FILES => '.directory');
}
- elsif (-f $thumbfilename && $thumbfilename =~ m/\.(mpe?g|avi|mov|asf|wmv|doc|mp3|ogg|pdf|rtf|wav)$/i) {
+ elsif (-f $thumbfilename && $thumbfilename =~ /$doc_pattern/i) {
my $type = lc($1);
my $stat = stat($thumbfilename);
my $size = $stat->size;
my $filetype;
if ($thumbfilename =~ m/\.(mpe?g|avi|mov|asf|wmv)$/i) {
- $filetype = "video";
- }
- else {
- $filetype = "application";
+ $filetype = "video-$type";
+ } elsif ($thumbfilename =~ m/\.(txt|html?)$/i) {
+ $filetype = "text-$type";
+ } elsif ($thumbfilename =~ m/\.(doc|mp3|ogg|pdf|rtf|wav|csv|eps)$/i) {
+ $filetype = "application-$type";
+ } else {
+ $filetype = "gallery-unknown";
}
$tpl->assign(FILEURL => uri_escape($fileurl, $escape_rule),
@@ -306,7 +312,7 @@
my ($width, $height, $type) = imgsize($thumbfilename);
next if $type eq 'Data stream is not a known image file format';
- my @filetypes = qw(JPG TIF PNG PPM);
+ my @filetypes = qw(JPG TIF PNG PPM GIF);
next unless (grep $type eq $_, @filetypes);
my ($thumbnailwidth, $thumbnailheight) = get_thumbnailsize($r, $width, $height);
@@ -459,7 +465,7 @@
show_error($r, 500, "Unable to access directory", "Unable to access directory $path");
return MP2 ? Apache::OK : Apache::Constants::OK;
}
- my @pictures = grep { /^[^.].*\.(jpe?g|png|ppm|tiff?)$/i } readdir (DATADIR);
+ my @pictures = grep { /$img_pattern/i } readdir (DATADIR);
closedir(DATADIR);
@pictures = sort @pictures;
@@ -737,7 +743,7 @@
my $scale = 1;
my $newfilename;
- if (grep $type eq $_, qw(PPM TIF)) {
+ if (grep $type eq $_, qw(PPM TIF GIF)) {
$newfilename = $width."x".$height."-".$filename;
# needs to be configurable
$newfilename =~ s/\.(\w+)$/-$1\.jpg/;
@@ -821,7 +827,7 @@
if ($type eq 'Data stream is not a known image file format') {
# should never be reached, this is supposed to be handled outside of here
Apache->request->log_error("Something was fishy with the type of the file $file\n");
- } elsif (grep $type eq $_, qw(PPM TIF PNG)) {
+ } elsif (grep $type eq $_, qw(PPM TIF PNG GIF)) {
# These files do not natively have EXIF info embedded in the file
my $tmpfilename = $file;
# We have a problem with Windows based file extensions here as they are often .THM