Apache-Gallery
view release on metacpan or search on metacpan
lib/Apache/Gallery.pm view on Meta::CPAN
use URI::Escape;
use CGI;
use CGI::Cookie;
use Encode;
use HTTP::Date;
use Digest::MD5 qw(md5_base64);
use Data::Dumper;
# Regexp for escaping URI's
my $escape_rule = "^A-Za-z0-9\-_.!~*'()\/";
my $memoized;
sub handler {
my $r = shift or Apache2::RequestUtil->request();
unless (($r->method eq 'HEAD') or ($r->method eq 'GET')) {
return $::MP2 ? Apache2::Const::DECLINED() : Apache::Constants::DECLINED();
}
lib/Apache/Gallery.pm view on Meta::CPAN
$r->filename($file);
return Apache::Constants::DECLINED();
}
}
my $uri = $r->uri;
$uri =~ s/\/$//;
unless (-f $filename or -d $filename) {
show_error($r, 404, "404!", "No such file or directory: ".uri_escape($r->uri, $escape_rule));
return $::MP2 ? Apache2::Const::OK() : Apache::Constants::OK();
}
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|txt|html?|csv|eps)$'
}
my $img_pattern = $r->dir_config('GalleryImgFile');
unless ($img_pattern) {
$img_pattern = '\.(jpe?g|png|tiff?|ppm)$'
lib/Apache/Gallery.pm view on Meta::CPAN
if (-d $thumbfilename && ! -e $thumbfilename . ".ignore") {
my $dirtitle = '';
if (-e $thumbfilename . ".folder") {
$dirtitle = get_filecontent($thumbfilename . ".folder");
}
$dirtitle = $dirtitle ? $dirtitle : $file;
$dirtitle =~ s/_/ /g if $r->dir_config('GalleryUnderscoresToSpaces');
$tpl_vars{FILES} .=
$templates{directory}->fill_in(HASH=> {FILEURL => uri_escape($fileurl, $escape_rule),
FILE => $dirtitle,
}
);
}
# 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;
lib/Apache/Gallery.pm view on Meta::CPAN
$filetype = "unknown";
}
# Debian bug #348724 <http://bugs.debian.org/348724>
# not images
my $filetitle = $file;
$filetitle =~ s/_/ /g if $r->dir_config('GalleryUnderscoresToSpaces');
$tpl_vars{FILES} .=
$templates{file}->fill_in(HASH => {%tpl_vars,
FILEURL => uri_escape($fileurl, $escape_rule),
ALT => "Size: $size Bytes",
FILE => $filetitle,
TYPE => $type,
FILETYPE => $filetype,
}
);
}
# Debian bug #619625 <http://bugs.debian.org/619625>
elsif (-f $thumbfilename && ! -e $thumbfilename . ".ignore") {
lib/Apache/Gallery.pm view on Meta::CPAN
my $imageinfo = get_imageinfo($r, $thumbfilename, $type, $width, $height);
my $cached = get_scaled_picture_name($thumbfilename, $thumbnailwidth, $thumbnailheight);
my $rotate = readfile_getnum($r, $imageinfo, $thumbfilename.".rotate");
# Debian bug #348724 <http://bugs.debian.org/348724>
# HTML <img> tag, alt attribute
my $filetitle = $file;
$filetitle =~ s/_/ /g if $r->dir_config('GalleryUnderscoresToSpaces');
my %file_vars = (FILEURL => uri_escape($fileurl, $escape_rule),
FILE => $filetitle,
DATE => $imageinfo->{DateTimeOriginal} ? $imageinfo->{DateTimeOriginal} : '', # should this really be a stat of the file instead of ''?
SRC => uri_escape($uri."/.cache/$cached", $escape_rule),
HEIGHT => (grep($rotate==$_, (1, 3)) ? $thumbnailwidth : $thumbnailheight),
WIDTH => (grep($rotate==$_, (1, 3)) ? $thumbnailheight : $thumbnailwidth),
SELECT => $select_mode?'<input type="checkbox" name="selection" value="'.$file.'"> ':'',);
$tpl_vars{FILES} .= $templates{picture}->fill_in(HASH => {%tpl_vars,
%file_vars,
},
);
if ($media_rss_enabled) {
my ($content_image_width, undef, $content_image_height) = get_image_display_size($cgi, $r, $width, $height);
my %item_vars = (
THUMBNAIL => uri_escape($uri."/.cache/$cached", $escape_rule),
LINK => uri_escape($fileurl, $escape_rule),
TITLE => $file,
CONTENT => uri_escape($uri."/.cache/".$content_image_width."x".$content_image_height."-".$file, $escape_rule)
);
$tpl_vars{ITEMS} .= $templates{rss_item}->fill_in(HASH => {
%item_vars
});
}
}
}
}
else {
$tpl_vars{FILES} = "No files found";
lib/Apache/Gallery.pm view on Meta::CPAN
my %tpl_vars;
my $resolution = (($image_width > $orig_width) && ($height > $orig_height)) ?
"$orig_width x $orig_height" : "$image_width x $height";
$tpl_vars{TITLE} = "Viewing ".$r->uri()." at $image_width x $height";
$tpl_vars{META} = " ";
$tpl_vars{RESOLUTION} = $resolution;
$tpl_vars{MENU} = generate_menu($r);
$tpl_vars{SRC} = uri_escape(".cache/$cached", $escape_rule);
$tpl_vars{URI} = $r->uri();
my $exif_mode = $r->dir_config('GalleryEXIFMode');
unless ($exif_mode) {
$exif_mode = 'namevalue';
}
unless (opendir(DATADIR, $path)) {
show_error($r, 500, "Unable to access directory", "Unable to access directory $path");
return $::MP2 ? Apache2::Const::OK() : Apache::Constants::OK();
lib/Apache/Gallery.pm view on Meta::CPAN
if ($r->dir_config("GalleryWrapNavigation")) {
$prevpicture = $pictures[$i>0 ? $i-1 : $#pictures];
$displayprev = 1;
}
if ($prevpicture and $displayprev) {
my ($orig_width, $orig_height, $type) = imgsize($path.$prevpicture);
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);
my %nav_vars;
$nav_vars{URL} = uri_escape($prevpicture, $escape_rule);
$nav_vars{FILENAME} = $prevpicture;
$nav_vars{WIDTH} = $width;
$nav_vars{PICTURE} = uri_escape(".cache/$cached", $escape_rule);
$nav_vars{DIRECTION} = "« <u>p</u>rev";
$nav_vars{ACCESSKEY} = "P";
$tpl_vars{BACK} = $templates{navpicture}->fill_in(HASH => \%nav_vars);
}
else {
$tpl_vars{BACK} = " ";
}
$nextpicture = $pictures[$i+1];
if ($r->dir_config("GalleryWrapNavigation")) {
$nextpicture = $pictures[$i == $#pictures ? 0 : $i+1];
}
if ($nextpicture) {
my ($orig_width, $orig_height, $type) = imgsize($path.$nextpicture);
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);
my %nav_vars;
$nav_vars{URL} = uri_escape($nextpicture, $escape_rule);
$nav_vars{FILENAME} = $nextpicture;
$nav_vars{WIDTH} = $width;
$nav_vars{PICTURE} = uri_escape(".cache/$cached", $escape_rule);
$nav_vars{DIRECTION} = "<u>n</u>ext »";
$nav_vars{ACCESSKEY} = "N";
$tpl_vars{NEXT} = $templates{navpicture}->fill_in(HASH => \%nav_vars);
$tpl_vars{NEXTURL} = uri_escape($nextpicture, $escape_rule);
}
else {
$tpl_vars{NEXT} = " ";
$tpl_vars{NEXTURL} = '#';
}
}
}
my $foundcomment = 0;
if (-f $path . '/' . $picfilename . '.comment') {
lib/Apache/Gallery.pm view on Meta::CPAN
$tpl_vars{PICTUREINFO} = $templates{nopictureinfo}->fill_in(HASH => \%tpl_vars);
}
# Fill in sizes and determine if any are smaller than the
# actual image. If they are, $scaleable=1
my $scaleable = 0;
my @sizes = split (/ /, $r->dir_config('GallerySizes') ? $r->dir_config('GallerySizes') : '640 800 1024 1600');
foreach my $size (@sizes) {
if ($size<=$original_size) {
my %sizes_vars;
$sizes_vars{IMAGEURI} = uri_escape($r->uri(), $escape_rule);
$sizes_vars{SIZE} = $size;
$sizes_vars{WIDTH} = $size;
if ($width == $size) {
$tpl_vars{SIZES} .= $templates{scaleactive}->fill_in(HASH => \%sizes_vars);
}
else {
$tpl_vars{SIZES} .= $templates{scale}->fill_in(HASH => \%sizes_vars);
}
$scaleable = 1;
}
}
unless ($scaleable) {
my %sizes_vars;
$sizes_vars{IMAGEURI} = uri_escape($r->uri(), $escape_rule);
$sizes_vars{SIZE} = $original_size;
$sizes_vars{WIDTH} = $original_size;
$tpl_vars{SIZES} .= $templates{scaleactive}->fill_in(HASH => \%sizes_vars);
}
$tpl_vars{IMAGEURI} = uri_escape($r->uri(), $escape_rule);
if ($r->dir_config('GalleryAllowOriginal')) {
$tpl_vars{SIZES} .= $templates{orig}->fill_in(HASH => \%tpl_vars);
}
my @slideshow_intervals = split (/ /, $r->dir_config('GallerySlideshowIntervals') ? $r->dir_config('GallerySlideshowIntervals') : '3 5 10 15 30');
foreach my $interval (@slideshow_intervals) {
my %slideshow_vars;
$slideshow_vars{IMAGEURI} = uri_escape($r->uri(), $escape_rule);
$slideshow_vars{SECONDS} = $interval;
$slideshow_vars{WIDTH} = ($width > $height ? $width : $height);
if ($cgi->param('slideshow') && $cgi->param('slideshow') == $interval and $nextpicture) {
$tpl_vars{SLIDESHOW} .= $templates{intervalactive}->fill_in(HASH => \%slideshow_vars);
}
else {
$tpl_vars{SLIDESHOW} .= $templates{interval}->fill_in(HASH => \%slideshow_vars);
lib/Apache/Gallery.pm view on Meta::CPAN
if ($cgi->param('slideshow') and $nextpicture) {
$tpl_vars{SLIDESHOW} .= $templates{slideshowoff}->fill_in(HASH => \%tpl_vars);
unless ((grep $cgi->param('slideshow') == $_, @slideshow_intervals)) {
show_error($r, 200, "Invalid interval", "Invalid slideshow interval choosen");
return $::MP2 ? Apache2::Const::OK() : Apache::Constants::OK();
}
$tpl_vars{URL} = uri_escape($nextpicture, $escape_rule);
$tpl_vars{WIDTH} = ($width > $height ? $width : $height);
$tpl_vars{INTERVAL} = $cgi->param('slideshow');
$tpl_vars{META} .= $templates{refresh}->fill_in(HASH => \%tpl_vars);
}
else {
$tpl_vars{SLIDESHOW} .= $templates{slideshowisoff}->fill_in(HASH => \%tpl_vars);
}
$tpl_vars{MAIN} = $templates{picture}->fill_in(HASH => \%tpl_vars);
lib/Apache/Gallery.pm view on Meta::CPAN
if (-e $dirname . ".folder") {
$linktext = get_filecontent($dirname . ".folder");
}
}
if ("$root_path$uri" eq $menuurl) {
$menu .= "$linktext / ";
}
else {
$menu .= "<a href=\"".uri_escape($menuurl, $escape_rule)."\">$linktext</a> / ";
}
}
if (-f $filename) {
$menu .= $picturename;
}
else {
if ($r->dir_config('GallerySelectionMode') && $r->dir_config('GallerySelectionMode') eq '1') {
$menu .= "<a href=\"".uri_escape($menuurl, $escape_rule);
$menu .= "?select=1\">[select]</a> ";
}
}
return $menu;
}
sub resizepicture {
my ($r, $infile, $outfile, $x, $y, $rotate, $copyrightfile, $GalleryTTFDir, $GalleryCopyrightText, $text_color, $GalleryTTFFile, $GalleryTTFSize, $GalleryCopyrightBackgroundColor, $quality) = @_;
( run in 0.480 second using v1.01-cache-2.11-cpan-c21f80fb71c )