#!/usr/bin/perl use strict; use CGI::Carp qw/fatalsToBrowser/; sub pad { my ($num, $length) = @_; ("0" x ($length - length($num))) . $num; } my %opts; if ($ENV{REQUEST_URI} =~ /^.*?\?(.*)/) { my $query = $1; map { /^([^=]+)(=(.*))/ && do { $opts{$1} = $3; 1; }; } split /&/, $query; } map { s/%([0-9A-F]{2})/chr hex $1/gie } values %opts; if ($opts{min} eq "" && $opts{url} !~ /%/) { if (($opts{url} =~ /^(.*\D)(\d+)(\D+)$/)) { $opts{url} = $1."%".$3; $opts{min} = int($2 / 20) * 20 + 1; $opts{min} = pad($opts{min}, length($2)); } } $opts{max} = $opts{min} + 19 unless $opts{max} =~ /./; $opts{max} = pad($opts{max}, length($opts{min})); if ($opts{next} eq "Next") { my $nm = $opts{max} + 1; $opts{max} = $nm + $opts{max} - $opts{min}; $opts{min} = pad($nm, length($opts{min})); } if ($opts{prev} eq "Prev") { my $nm = $opts{min} - ($opts{max} - $opts{min}) - 1; $opts{max} = $nm + $opts{max} - $opts{min}; $opts{min} = pad($nm, length($opts{min})); } $opts{max} = $opts{min} + 19 unless $opts{max} =~ /./; print "Content-type: text/html\n\n"; print ' '; printf '
'."\n"; printf ' url:
'."\n", $opts{url}; printf ' min: '."\n", $opts{min}; printf ' max:
'."\n", $opts{max}; printf '   
'."\n"; if ($opts{url} =~ /./) { for my $i ($opts{min}..$opts{max}) { my $xu = $opts{url}; my $lu = $xu; my $fancybox = ''; if ($lu =~ /%.*\d/) { $lu =~ s/%([^\d%]*)(\d+)(.*?)$/pad($i, length($opts{min})).$1."!!!".$3/e; my $t = $2; $lu =~ s/%/pad($i, length($opts{min}))/eg; $lu =~ s/!!!/%/; my $min = pad($t - (($t % 20) - 1), length($t)); $lu = "img?url=".$lu."&min=".$min; } else { $lu =~ s/%/pad($i, length($opts{min}))/eg; my $t = $lu; $t =~ s#.*/##; $fancybox = 'class="thumb" rel="gallery" title="'.$t.'"'; } $xu =~ s/%/pad($i, length($opts{min}))/eg; printf ' '."\n", $lu, $fancybox, $xu; } } printf '
'."\n"; printf '   
'."\n"; printf "
\n"; printf ' ';