]> git.donarmstrong.com Git - deb_pkgs/libapache-gallery-perl.git/blobdiff - lib/Apache/Gallery.pm
fix ImgFile syntax error
[deb_pkgs/libapache-gallery-perl.git] / lib / Apache / Gallery.pm
index 8826d4a4e1ed553de2ce223f21a469e9f7c93fe4..aa60b7a46977dd6c5cb56ba4a4cc23ab7e74383d 100644 (file)
@@ -1,13 +1,13 @@
 package Apache::Gallery;
 
-# $Author: mil $ $Rev: 324 $
-# $Date: 2011-02-22 21:56:06 +0100 (Tue, 22 Feb 2011) $
+# $Author: mil $ $Rev: 335 $
+# $Date: 2011-06-08 20:47:46 +0200 (Wed, 08 Jun 2011) $
 
 use strict;
 
 use vars qw($VERSION);
 
-$VERSION = "1.0.1";
+$VERSION = "1.0.2";
 
 BEGIN {
 
@@ -75,7 +75,7 @@ sub handler {
        }
 
        $r->headers_out->{"X-Powered-By"} = "apachegallery.dk $VERSION - Hest design!";
-       $r->headers_out->{"X-Gallery-Version"} = '$Rev: 324 $ $Date: 2011-02-22 21:56:06 +0100 (Tue, 22 Feb 2011) $';
+       $r->headers_out->{"X-Gallery-Version"} = '$Rev: 335 $ $Date: 2011-06-08 20:47:46 +0200 (Wed, 08 Jun 2011) $';
 
        my $filename = $r->filename;
        $filename =~ s/\/$//;
@@ -120,7 +120,12 @@ sub handler {
        
        # Let Apache serve icons without us modifying the request
        if ($r->uri =~ m/^\/icons/i) {
-               return $::MP2 ? Apache2::Const::DECLINED() : Apache::Constants::DECLINED();
+           if ($r->uri =~ m/^\/icons\/gallery\/([^\/]+$)/i) {
+            $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
@@ -144,32 +149,8 @@ sub handler {
                my $file = cache_dir($r, 0);
                $file =~ s/\.cache//;
 
-               my $subr = $r->lookup_file($file);
-               $r->content_type($subr->content_type());
-
-               if ($::MP2) {
-                       my $fileinfo = stat($file);
+        return send_file($r,$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();
-               }
                
        }
 
@@ -183,7 +164,7 @@ sub handler {
 
        my $doc_pattern = $r->dir_config('GalleryDocFile');
        unless ($doc_pattern) {
-               $doc_pattern = '\.(mpe?g|avi|mov|asf|wmv|doc|mp3|ogg|pdf|rtf|wav|dlt|html?|csv|eps)$'
+               $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) {
@@ -351,7 +332,8 @@ sub handler {
 
                                my $fileurl = $uri."/".$file;
 
-                               if (-d $thumbfilename) {
+                               # Debian bug #619625 <http://bugs.debian.org/619625>
+                               if (-d $thumbfilename && ! -e $thumbfilename . ".ignore") {
                                        my $dirtitle = '';
                                        if (-e $thumbfilename . ".folder") {
                                                $dirtitle = get_filecontent($thumbfilename . ".folder");
@@ -367,7 +349,8 @@ sub handler {
                                                                           );
 
                                }
-                               elsif (-f $thumbfilename && $thumbfilename =~ /$doc_pattern/i && $thumbfilename !~ /$img_pattern/i) {
+                               # Debian bug #619625 <http://bugs.debian.org/619625>
+                               elsif (-f $thumbfilename && $thumbfilename =~ /$doc_pattern/i && $thumbfilename !~ /$img_pattern/i && ! -e $thumbfilename . ".ignore") {
                                        my $type = lc($1);
                                        my $stat = stat($thumbfilename);
                                        my $size = $stat->size;
@@ -385,9 +368,14 @@ sub handler {
                                                $filetype = "unknown";
                                        }
 
-                                       # Debian bug #348724 <http://bugs.debian.org/348724>
+                                       # Debian bug #337012 <http://bugs.debian.org/337012>
                                        # not images
                                        my $filetitle = $file;
+                                       if (-e $thumbfilename . ".file") {
+                                               $filetitle = get_filecontent($thumbfilename . ".file");
+                                       }
+
+                                       # Debian bug #348724 <http://bugs.debian.org/348724>
                                        $filetitle =~ s/_/ /g if $r->dir_config('GalleryUnderscoresToSpaces');
 
                                        $tpl_vars{FILES} .=
@@ -400,7 +388,8 @@ sub handler {
                                                                               }
                                                                      );
                                }
-                               elsif (-f $thumbfilename) {
+                               # Debian bug #619625 <http://bugs.debian.org/619625>
+                               elsif (-f $thumbfilename && ! -e $thumbfilename . ".ignore") {
 
                                        my ($width, $height, $type) = imgsize($thumbfilename);
                                        next if $type eq 'Data stream is not a known image file format';
@@ -414,9 +403,14 @@ sub handler {
 
                                        my $rotate = readfile_getnum($r, $imageinfo, $thumbfilename.".rotate");
 
-                                       # Debian bug #348724 <http://bugs.debian.org/348724>
+                                       # Debian bug #337012 <http://bugs.debian.org/337012>
                                        # HTML <img> tag, alt attribute
                                        my $filetitle = $file;
+                                       if (-e $thumbfilename . ".file") {
+                                               $filetitle = get_filecontent($thumbfilename . ".file");
+                                       }
+
+                                       # Debian bug #348724 <http://bugs.debian.org/348724>
                                        $filetitle =~ s/_/ /g if $r->dir_config('GalleryUnderscoresToSpaces');
 
                                        my %file_vars = (FILEURL => uri_escape($fileurl, $escape_rule),
@@ -464,7 +458,8 @@ sub handler {
                                return $::MP2 ? Apache2::Const::OK() : Apache::Constants::OK();
                        }
        
-                       my @neighbour_directories = grep { !/^\./ && -d "$parent_filename/$_" } readdir (PARENT_DIR);
+                       # Debian bug #619625 <http://bugs.debian.org/619625>
+                       my @neighbour_directories = grep { !/^\./ && -d "$parent_filename/$_" && ! -e "$parent_filename/$_" . ".ignore" } readdir (PARENT_DIR);
                        my $dirsortby;
                        if (defined($r->dir_config('GalleryDirSortBy'))) {
                                $dirsortby=$r->dir_config('GalleryDirSortBy');
@@ -499,7 +494,7 @@ sub handler {
                                        }
                                        if ($neightbour_counter < scalar @neighbour_directories - 1) {
                                                my $linktext = $neighbour_directories[$neightbour_counter+1];
-                                               if (-e $parent_filename.'/'.$neighbour_directories[$neightbour_counter-1] . ".folder") {
+                                               if (-e $parent_filename.'/'.$neighbour_directories[$neightbour_counter+1] . ".folder") {
                                                        $linktext = get_filecontent($parent_filename.'/'.$neighbour_directories[$neightbour_counter+1] . ".folder");
                                                }
                                                my %info = (
@@ -556,6 +551,20 @@ sub handler {
                                return $::MP2 ? Apache2::Const::FORBIDDEN() : Apache::Constants::FORBIDDEN();
                        }
                }
+        if (defined $ENV{QUERY_STRING} && $ENV{QUERY_STRING} eq 'thumbonly' &&
+            $r->dir_config('GalleryAllowThumbonly') &&
+            -f $filename) {
+
+            my ($width, $height, $type) = imgsize($filename);
+            my @filetypes = qw(JPG TIF PNG PPM GIF);
+            if (grep $type eq $_, @filetypes) {
+                my ($thumbnailwidth, $thumbnailheight) = get_thumbnailsize($r, $width, $height);
+                my $imageinfo = get_imageinfo($r, $filename, $type, $width, $height);
+                my $cached = get_scaled_picture_name($filename, $thumbnailwidth, $thumbnailheight);
+                $r->headers_out->set(Location => uri_escape(".cache/$cached", $escape_rule));
+                return $::MP2 ? Apache2::Const::REDIRECT() : Apache::Constants::REDIRECT();
+            }
+        }
        
                # Create cache dir if not existing
                my @tmp = split (/\//, $filename);
@@ -616,7 +625,7 @@ sub handler {
                        show_error($r, 500, "Unable to access directory", "Unable to access directory $path");
                        return $::MP2 ? Apache2::Const::OK() : Apache::Constants::OK();
                }
-               my @pictures = grep { /$img_pattern/i } readdir (DATADIR);
+               my @pictures = grep { /$img_pattern/i && ! -e "$path/$_" . ".ignore" } readdir (DATADIR);
                closedir(DATADIR);
                @pictures = gallerysort($r, @pictures);
 
@@ -642,9 +651,14 @@ sub handler {
                                        my ($thumbnailwidth, $thumbnailheight) = get_thumbnailsize($r, $orig_width, $orig_height);      
                                        my $imageinfo = get_imageinfo($r, $path.$prevpicture, $type, $orig_width, $orig_height);
                                        my $cached = get_scaled_picture_name($path.$prevpicture, $thumbnailwidth, $thumbnailheight);
+                                       # Debian bug #337012 <http://bugs.debian.org/337012>
+                                       my $prevpicture_title = $prevpicture;
+                                       if (-e $path."/".$prevpicture . ".file") {
+                                               $prevpicture_title = get_filecontent($path."/".$prevpicture . ".file");
+                                       }
                                        my %nav_vars;
                                        $nav_vars{URL}       = uri_escape($prevpicture, $escape_rule);
-                                       $nav_vars{FILENAME}  = $prevpicture;
+                                       $nav_vars{FILENAME}  = $prevpicture_title;
                                        $nav_vars{WIDTH}     = $width;
                                        $nav_vars{PICTURE}   = uri_escape(".cache/$cached", $escape_rule);
                                        $nav_vars{DIRECTION} = "&laquo; <u>p</u>rev";
@@ -665,9 +679,14 @@ sub handler {
                                        my ($thumbnailwidth, $thumbnailheight) = get_thumbnailsize($r, $orig_width, $orig_height);      
                                        my $imageinfo = get_imageinfo($r, $path.$nextpicture, $type, $thumbnailwidth, $thumbnailheight);
                                        my $cached = get_scaled_picture_name($path.$nextpicture, $thumbnailwidth, $thumbnailheight);
+                                       # Debian bug #337012 <http://bugs.debian.org/337012>
+                                       my $nextpicture_title = $nextpicture;
+                                       if (-e $path."/".$nextpicture . ".file") {
+                                               $nextpicture_title = get_filecontent($path."/".$nextpicture . ".file");
+                                       }
                                        my %nav_vars;
                                        $nav_vars{URL}       = uri_escape($nextpicture, $escape_rule);
-                                       $nav_vars{FILENAME}  = $nextpicture;
+                                       $nav_vars{FILENAME}  = $nextpicture_title;
                                        $nav_vars{WIDTH}     = $width;
                                        $nav_vars{PICTURE}   = uri_escape(".cache/$cached", $escape_rule);
                                        $nav_vars{DIRECTION} = "<u>n</u>ext &raquo;";
@@ -844,6 +863,35 @@ sub handler {
 
 }
 
+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) = @_;
@@ -852,7 +900,7 @@ sub cache_dir {
 
        unless ($r->dir_config('GalleryCacheDir')) {
 
-               $cache_root = '/var/tmp/Apache-Gallery/';
+               $cache_root = '/var/cache/www/';
                if ($r->server->is_virtual) {
                        $cache_root = File::Spec->catdir($cache_root, $r->server->server_hostname);
                } else {
@@ -1453,6 +1501,10 @@ sub generate_menu {
        my $picturename;
        if (-f $filename) {
                $picturename = pop(@links);     
+               # Debian bug #337012 <http://bugs.debian.org/337012>
+               if (-e $filename . ".file") {
+                       $picturename = get_filecontent($filename . ".file");
+               }
        }
 
        if ($r->uri eq $root_path) {
@@ -1659,7 +1711,7 @@ directories.
 The options are set in the httpd.conf/.htaccess file using the syntax:
 B<PerlSetVar OptionName 'value'>
 
-Example: B<PerlSetVar GalleryCacheDir '/var/tmp/Apache-Gallery/'>
+Example: B<PerlSetVar GalleryCacheDir '/var/cache/www/'>
 
 =over 4
 
@@ -1676,9 +1728,9 @@ to 0.
 =item B<GalleryCacheDir>
 
 Directory where Apache::Gallery should create its cache with scaled
-pictures. The default is /var/tmp/Apache-Gallery/ . Here, a directory
-for each virtualhost or location will be created automaticly. Make
-sure your webserver has write access to the CacheDir.
+pictures. The default is /var/cache/www/ . Here, a directory for each
+virtualhost or location will be created automatically. Make sure your
+webserver has write access to the CacheDir.
 
 =item B<GalleryTemplateDir>
 
@@ -1746,6 +1798,14 @@ resizing or putting the CopyrightImage on it.
 
 Set to 1 or 0, default is 0
 
+=item B<GalleryAllowThumbOnly>
+
+If true, B<GalleryAllowThumbOnly> allows fooimg.jpg?thumbonly urls
+to output the thumbnail of the image. This is useful when including
+images in a blog (or similar).
+
+Defaults to '0' (false).
+
 =item B<GallerySlideshowIntervals>
 
 With this option you can configure which intervals can be selected for
@@ -1795,7 +1855,7 @@ If you set this option to 'variables' the items you configure in GalleryInfo
 will be available to your templates as $EXIF_<KEYNAME> (in all uppercase). 
 That means that with the default setting "Picture Taken => DateTimeOriginal, 
 Flash => Flash" you will have the variables $EXIF_DATETIMEORIGINAL and 
-$EXIF_FLASH avilable to your templates. You can place them
+$EXIF_FLASH available to your templates. You can place them
 anywhere you want.
 
 =item B<GalleryRootPath>
@@ -1825,7 +1885,7 @@ Pattern matching the files you want Apache::Gallery to view in the index
 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|ogg|pdf|rtf|wav|dlt|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>
 
@@ -1913,6 +1973,8 @@ of directory and file names, as well as in the alt attribute for HTML
 
 =back
 
+=over 4
+
 =item B<GalleryCommentExifKey>
 
 Set this option to e.g. ImageDescription to use this field as comments
@@ -1923,6 +1985,8 @@ for images.
 Set this option to 1 to enable generation of a media RSS feed. This
 can be used e.g. together with the PicLens plugin from http://piclens.com
 
+=back
+
 =head1 FEATURES
 
 =over 4
@@ -1931,7 +1995,7 @@ can be used e.g. together with the PicLens plugin from http://piclens.com
 
 Some cameras, like the Canon G3, detects the orientation of a picture
 and adds this info to the EXIF header. Apache::Gallery detects this
-and automaticly rotates images with this info.
+and automatically rotates images with this info.
 
 If your camera does not support this, you can rotate the images 
 manually, This can also be used to override the rotate information
@@ -1939,7 +2003,7 @@ from a camera that supports that. You can also disable this behavior
 with the GalleryAutoRotate option.
 
 To use this functionality you have to create file with the name of the 
-picture you want rotated appened with ".rotate". The file should include 
+picture you want rotated appended with ".rotate". The file should include 
 a number where these numbers are supported:
 
        "1", rotates clockwise by 90 degree
@@ -1950,6 +2014,11 @@ So if we want to rotate "Picture1234.jpg" 90 degrees clockwise we would
 create a file in the same directory called "Picture1234.jpg.rotate" with
 the number 1 inside of it.
 
+=item B<Ignore directories/files>
+
+To ignore a directory or a file (of any kind, not only images) you
+create a <directory|file>.ignore file.
+
 =item B<Comments>
 
 To include comments for a directory you create a <directory>.comment
@@ -1971,6 +2040,10 @@ The visible name of the folder is by default identical to the name of
 the folder, but can be changed by creating a file <directory>.folder
 with the visible name of the folder.
 
+Similarly, the visible name of any file is by default identical to the
+name of the file, but can be changed by creating a file <file>.file
+with the visible name of the file.
+
 It is also possible to set GalleryCommentExifKey to the name of an EXIF
 field containing the comment, e.g. ImageDescription. The EXIF comment is
 overridden by the .comment file if it exists.
@@ -2009,7 +2082,7 @@ Michael Legart <michael@legart.dk>
 
 =head1 COPYRIGHT AND LICENSE
 
-Copyright (C) 2001-2005 Michael Legart <michael@legart.dk>
+Copyright (C) 2001-2011 Michael Legart <michael@legart.dk>
 
 Templates designed by Thomas Kjaer <tk@lnx.dk>