Apache-Gallery
view release on metacpan or search on metacpan
lib/Apache/Gallery.pm view on Meta::CPAN
$comment_ref->{COMMENT} .= $_;
}
close(FH);
return $comment_ref;
}
sub show_error {
my ($r, $statuscode, $errortitle, $error) = @_;
my $tpl = $r->dir_config('GalleryTemplateDir');
my %templates = create_templates({layout => "$tpl/layout.tpl",
error => "$tpl/error.tpl",
});
my %tpl_vars;
$tpl_vars{TITLE} = "Error! $errortitle";
$tpl_vars{META} = "";
$tpl_vars{ERRORTITLE} = "Error! $errortitle";
$tpl_vars{ERROR} = $error;
$tpl_vars{MAIN} = $templates{error}->fill_in(HASH => \%tpl_vars);
$tpl_vars{PAGE} = $templates{layout}->fill_in(HASH => \%tpl_vars);
$r->status($statuscode);
$r->content_type('text/html');
$r->print($tpl_vars{PAGE});
}
sub generate_menu {
my $r = shift;
my $root_text = (defined($r->dir_config('GalleryRootText')) ? $r->dir_config('GalleryRootText') : "root:" );
my $root_path = (defined($r->dir_config('GalleryRootPath')) ? $r->dir_config('GalleryRootPath') : "" );
my $subr = $r->lookup_uri($r->uri);
my $filename = $subr->filename;
my @links = split (/\//, $r->uri);
my $uri = $r->uri;
$uri =~ s/^$root_path//g;
@links = split (/\//, $uri);
# Get the full path of the base directory
my $dirname;
{
my @direlem = split (/\//, $filename);
for my $i ( 0 .. ( scalar(@direlem) - scalar(@links) ) ) {
$dirname .= shift(@direlem) . '/';
}
chop $dirname;
}
my $picturename;
if (-f $filename) {
$picturename = pop(@links);
}
if ($r->uri eq $root_path) {
return qq{ <a href="$root_path">$root_text</a> };
}
my $menu;
my $menuurl = $root_path;
foreach my $link (@links) {
$menuurl .= $link."/";
my $linktext = $link;
unless (length($link)) {
$linktext = "$root_text ";
}
else {
$dirname = File::Spec->catdir($dirname, $link);
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) = @_;
# Load image
my $image = Image::Imlib2->load($infile) or warn("Unable to open file $infile, $!");
# Scale image
$image=$image->create_scaled_image($x, $y) or warn("Unable to scale image $infile. Are you running out of memory?");
# Rotate image
if ($rotate != 0) {
$image->image_orientate($rotate);
}
# blend copyright image onto image
if ($copyrightfile ne '') {
if (-f $copyrightfile and (my $logo=Image::Imlib2->load($copyrightfile))) {
my $x = $image->get_width();
my $y = $image->get_height();
my $logox = $logo->get_width();
my $logoy = $logo->get_height();
$image->blend($logo, 0, 0, 0, $logox, $logoy, $x-$logox, $y-$logoy, $logox, $logoy);
}
else {
log_error("GalleryCopyrightImage $copyrightfile was not found");
}
}
if ($GalleryTTFDir && $GalleryCopyrightText && $GalleryTTFFile && $text_color) {
if (!-d $GalleryTTFDir) {
log_error("GalleryTTFDir $GalleryTTFDir is not a dir\n");
} elsif ($GalleryCopyrightText eq '') {
log_error("GalleryCopyrightText is empty. No text inserted to picture\n");
} elsif (!-e "$GalleryTTFDir/$GalleryTTFFile") {
log_error("GalleryTTFFile $GalleryTTFFile was not found\n");
} else {
$GalleryTTFFile =~ s/\.TTF$//i;
$image->add_font_path("$GalleryTTFDir");
$image->load_font("$GalleryTTFFile/$GalleryTTFSize");
my($text_x, $text_y) = $image->get_text_size("$GalleryCopyrightText");
( run in 1.798 second using v1.01-cache-2.11-cpan-ceb78f64989 )