fix for bug 1771: Template errors with remote itemtype image

This adds a new function, getitemtypeimagelocation, that returns the image
unmodified for absolute urls and returns the proper intranet or opac path
otherwise. It also updates all of the relevant files to use that function.

Signed-off-by: Galen Charlton <galen.charlton@liblime.com>
This commit is contained in:
Jesse Weaver 2008-08-20 13:21:50 -05:00 committed by Galen Charlton
parent e957b3d3c7
commit 7da895cda7
15 changed files with 35 additions and 35 deletions

View file

@ -1419,7 +1419,7 @@ sub get_authorised_value_images {
&& $authorised_values->{ $this_authorised_value->{'category'} } eq $this_authorised_value->{'authorised_value'} ) {
# warn ( Data::Dumper->Dump( [ $this_authorised_value ], [ 'this_authorised_value' ] ) );
if ( defined $this_authorised_value->{'imageurl'} ) {
push @imagelist, { imageurl => C4::Koha::getitemtypeimagesrc( 'intranet' ) . '/' . $this_authorised_value->{'imageurl'},
push @imagelist, { imageurl => C4::Koha::getitemtypeimagelocation( 'intranet', $this_authorised_value->{'imageurl'} ),
label => $this_authorised_value->{'lib'},
category => $this_authorised_value->{'category'},
value => $this_authorised_value->{'authorised_value'}, };

View file

@ -21,6 +21,7 @@ package C4::Koha;
use strict;
use C4::Context;
use C4::Output;
use URI::Split qw(uri_split);
use vars qw($VERSION @ISA @EXPORT $DEBUG);
@ -47,6 +48,7 @@ BEGIN {
&get_notforloan_label_of
&getitemtypeimagedir
&getitemtypeimagesrc
&getitemtypeimagelocation
&GetAuthorisedValues
&GetAuthorisedValueCategories
&GetKohaAuthorisedValues
@ -493,6 +495,18 @@ sub getitemtypeimagesrc {
}
}
sub getitemtypeimagelocation($$) {
my ( $src, $image ) = @_;
return if ( !$image );
my $scheme = ( uri_split( $image ) )[0];
return $image if ( $scheme );
return getitemtypeimagesrc( $src ) . '/' . $image;
}
=head3 _getImagesFromDirectory
Find all of the image files in a directory in the filesystem

View file

@ -1262,15 +1262,8 @@ sub searchResults {
$oldbiblio->{result_number} = $i + 1;
# add imageurl to itemtype if there is one
if ( $itemtypes{ $oldbiblio->{itemtype} }->{imageurl} =~ /^http:/ ) {
$oldbiblio->{imageurl} =
$itemtypes{ $oldbiblio->{itemtype} }->{imageurl};
} else {
$oldbiblio->{imageurl} =
getitemtypeimagesrc() . "/"
. $itemtypes{ $oldbiblio->{itemtype} }->{imageurl}
if ( $itemtypes{ $oldbiblio->{itemtype} }->{imageurl} );
}
$oldbiblio->{imageurl} = getitemtypeimagelocation( 'opac', $itemtypes{ $oldbiblio->{itemtype} }->{imageurl} );
my $biblio_authorised_value_images = C4::Items::get_authorised_value_images( C4::Biblio::get_biblio_authorised_values( $oldbiblio->{biblionumber} ) );
$oldbiblio->{authorised_value_images} = $biblio_authorised_value_images;
my $aisbn = $oldbiblio->{'isbn'};
@ -1404,7 +1397,7 @@ s/\[(.?.?.?.?)$tagsubf(.*?)]/$1$subfieldvalue$2\[$1$tagsubf$2]/g;
$onloan_items->{$key}->{branchname} = $item->{branchname};
$onloan_items->{$key}->{location} = $shelflocations->{ $item->{location} };
$onloan_items->{$key}->{itemcallnumber} = $item->{itemcallnumber};
$onloan_items->{$key}->{imageurl} = getitemtypeimagesrc() . "/" . $itemtypes{ $item->{itype} }->{imageurl};
$onloan_items->{$key}->{imageurl} = getitemtypeimagelocation( 'opac', $itemtypes{ $item->{itype} }->{imageurl} );
# if something's checked out and lost, mark it as 'long overdue'
if ( $item->{itemlost} ) {
$onloan_items->{$prefix}->{longoverdue}++;
@ -1469,7 +1462,7 @@ s/\[(.?.?.?.?)$tagsubf(.*?)]/$1$subfieldvalue$2\[$1$tagsubf$2]/g;
$other_items->{$key}->{notforloan} = GetAuthorisedValueDesc('','',$item->{notforloan},'','',$notforloan_authorised_value) if $notforloan_authorised_value;
$other_items->{$key}->{count}++ if $item->{homebranch};
$other_items->{$key}->{location} = $shelflocations->{ $item->{location} };
$other_items->{$key}->{imageurl} = getitemtypeimagesrc() . "/" . $itemtypes{ $item->{itype} }->{imageurl};
$other_items->{$key}->{imageurl} = getitemtypeimagelocation( 'opac', $itemtypes{ $item->{itype} }->{imageurl} );
}
# item is available
else {
@ -1480,7 +1473,7 @@ s/\[(.?.?.?.?)$tagsubf(.*?)]/$1$subfieldvalue$2\[$1$tagsubf$2]/g;
$available_items->{$prefix}->{$_} = $item->{$_};
}
$available_items->{$prefix}->{location} = $shelflocations->{ $item->{location} };
$available_items->{$prefix}->{imageurl} = getitemtypeimagesrc() . "/" . $itemtypes{ $item->{itype} }->{imageurl};
$available_items->{$prefix}->{imageurl} = getitemtypeimagelocation( 'opac', $itemtypes{ $item->{itype} }->{imageurl} );
}
}
} # notforloan, item level and biblioitem level

View file

@ -247,7 +247,7 @@ sub default_form {
$row_data{category} = $results->[$i]{'category'};
$row_data{authorised_value} = $results->[$i]{'authorised_value'};
$row_data{lib} = $results->[$i]{'lib'};
$row_data{imageurl} = getitemtypeimagesrc('intranet') . '/' . $results->[$i]{'imageurl'};
$row_data{imageurl} = getitemtypeimagelocation( 'intranet', $results->[$i]{'imageurl'} );
$row_data{edit} = "$script_name?op=add_form&amp;id=".$results->[$i]{'id'};
$row_data{delete} = "$script_name?op=delete_confirm&amp;searchfield=$searchfield&amp;id=".$results->[$i]{'id'};
push(@loop_data, \%row_data);

View file

@ -244,7 +244,7 @@ else { # DEFAULT
my @loop;
foreach my $itemtype ( @{$results}[ $first .. $last ] ) {
$itemtype->{toggle} = ($toggle++ % 2) ? 0 : 1 ;
$itemtype->{imageurl} = getitemtypeimagesrc('intranet') . "/$itemtype->{imageurl}";
$itemtype->{imageurl} = getitemtypeimagelocation( 'intranet', $itemtype->{imageurl} );
$itemtype->{rentalcharge} = sprintf( '%.2f', $itemtype->{rentalcharge} );
push( @loop, $itemtype );
}

View file

@ -93,7 +93,7 @@ foreach my $subscription (@subscriptions) {
GetLatestSerials( $subscription->{subscriptionid}, 3 );
push @subs, \%cell;
}
$dat->{imageurl} = getitemtypeimagesrc() . "/".$itemtypes->{ $dat->{itemtype} }{imageurl};
$dat->{imageurl} = getitemtypeimagelocation( 'intranet', $itemtypes->{ $dat->{itemtype} }{imageurl} );
$dat->{'count'} = scalar @items;
my $shelflocations = GetKohaAuthorisedValues('items.location', $fw);
my $collections = GetKohaAuthorisedValues('items.ccode' , $fw);
@ -106,7 +106,7 @@ foreach my $item (@items) {
# format some item fields for display
$item->{ $item->{'publictype'} } = 1;
$item->{imageurl} = getitemtypeimagesrc() . "/".$itemtypes->{ $item->{itype} }{imageurl};
$item->{imageurl} = getitemtypeimagelocation( 'intranet', $itemtypes->{ $item->{itype} }{imageurl} );
foreach (qw(datedue datelastseen onloan)) {
$item->{$_} = format_date($item->{$_});
}

View file

@ -224,12 +224,11 @@ my $itype_or_itemtype = (C4::Context->preference("item-level_itypes"))?'itype':'
my @itemtypesloop;
my $selected=1;
my $cnt;
my $imgdir = getitemtypeimagesrc('intranet');
my $advanced_search_types = C4::Context->preference("AdvancedSearchTypes");
if (!$advanced_search_types or $advanced_search_types eq 'itemtypes') { foreach my $thisitemtype ( sort {$itemtypes->{$a}->{'description'} cmp $itemtypes->{$b}->{'description'} } keys %$itemtypes ) {
my %row =( number=>$cnt++,
imageurl=> $itemtypes->{$thisitemtype}->{'imageurl'}?($imgdir."/".$itemtypes->{$thisitemtype}->{'imageurl'}):"",
imageurl=> getitemtypeimagelocation( 'intranet', $itemtypes->{$thisitemtype}->{'imageurl'} ),
ccl => $itype_or_itemtype,
code => $thisitemtype,
selected => $selected,
@ -245,7 +244,7 @@ if (!$advanced_search_types or $advanced_search_types eq 'itemtypes') {
for my $thisitemtype (@$advsearchtypes) {
my %row =(
number=>$cnt++,
imageurl=> $thisitemtype->{'imageurl'}?($imgdir."/".$thisitemtype->{'imageurl'}):"",
imageurl=> getitemtypeimagelocation( 'intranet', $thisitemtype->{'imageurl'} ),
ccl => $advanced_search_types,
code => $thisitemtype->{authorised_value},
selected => $selected,

View file

@ -240,7 +240,7 @@ for ( my $i = 0 ; $i < $count ; $i++ ) {
my $itemtypeinfo = getitemtypeinfo($itemtype);
$row{'itemtype_description'} = $itemtypeinfo->{description};
$row{'itemtype_image'} = $itemtypeinfo->{imageurl};
$row{'itemtype_image'} = getitemtypelocation( 'opac', $itemtypeinfo->{imageurl} );
$row{'charge'} = sprintf( "%.2f", $charge );

View file

@ -81,12 +81,11 @@ if (!$dat) {
print $query->redirect("/cgi-bin/koha/errors/404.pl");
exit;
}
my $imgdir = getitemtypeimagesrc();
my $itemtypes = GetItemTypes();
# imageurl:
my $itemtype = $dat->{'itemtype'};
if ( $itemtype ) {
$dat->{'imageurl'} = $imgdir."/".$itemtypes->{$itemtype}->{'imageurl'};
$dat->{'imageurl'} = getitemtypeimagelocation( 'opac', $itemtypes->{$itemtype}->{'imageurl'} );
$dat->{'description'} = $itemtypes->{$itemtype}->{'description'};
}
my $shelflocations =GetKohaAuthorisedValues('items.location',$dat->{'frameworkcode'});
@ -139,7 +138,7 @@ for my $itm (@items) {
my $ccode= $itm->{'ccode'};
$itm->{'ccode'} = $collections->{$ccode} if(defined($collections) && exists($collections->{$ccode}));
$itm->{'location_description'} = $shelflocations->{$itm->{'location'} };
$itm->{'imageurl'} = $imgdir."/".$itemtypes->{ $itm->{itype} }->{'imageurl'};
$itm->{'imageurl'} = getitemtypeimagelocation( 'opac', $itemtypes->{ $itm->{itype} }->{'imageurl'} );
$itm->{'description'} = $itemtypes->{$itemtype}->{'description'};
$itemfields{ccode} = 1 if($itm->{ccode});
$itemfields{enumchron} = 1 if($itm->{enumchron});

View file

@ -45,7 +45,6 @@ my ( $borr ) = GetMemberDetails( $borrowernumber );
$template->param($borr);
my $imgdir = getitemtypeimagesrc();
my $itemtypes = GetItemTypes();
# get the record
@ -116,7 +115,7 @@ for ( my $i = 0 ; $i < $count ; $i++ ) {
$line{volumeddesc} = $issues->[$i]->{'volumeddesc'};
$line{counter} = $i + 1;
$line{'description'} = $itemtypes->{ $issues->[$i]->{'itemtype'} }->{'description'};
$line{imageurl} = $imgdir."/".$itemtypes->{ $issues->[$i]->{'itemtype'} }->{'imageurl'};
$line{imageurl} = getitemtypeimagelocation( 'opac', $itemtypes->{ $issues->[$i]->{'itemtype'} }->{'imageurl'} );
push( @loop_reading, \%line );
}

View file

@ -423,7 +423,7 @@ foreach my $biblioitemnumber (@biblioitemnumbers) {
while (my $wait_hashref = $sth2->fetchrow_hashref) {
$item->{waitingdate} = format_date($wait_hashref->{waitingdate});
}
$item->{imageurl} = getitemtypeimagesrc() . "/".$itemtypes->{ $item->{itype} }{imageurl};
$item->{imageurl} = getitemtypeimagelocation( 'opac', $itemtypes->{ $item->{itype} }{imageurl} );
push @{ $biblioitem->{itemloop} }, $item;
}

View file

@ -133,13 +133,12 @@ my $itype_or_itemtype = (C4::Context->preference("item-level_itypes"))?'itype':'
my @itemtypesloop;
my $selected=1;
my $cnt;
my $imgdir = getitemtypeimagesrc('opac');
my $advanced_search_types = C4::Context->preference("AdvancedSearchTypes");
if (!$advanced_search_types or $advanced_search_types eq 'itemtypes') {
foreach my $thisitemtype ( sort {$itemtypes->{$a}->{'description'} cmp $itemtypes->{$b}->{'description'} } keys %$itemtypes ) {
my %row =( number=>$cnt++,
imageurl=> $itemtypes->{$thisitemtype}->{'imageurl'}?($imgdir."/".$itemtypes->{$thisitemtype}->{'imageurl'}):"",
imageurl=> getitemtypeimagelocation( 'opac', $itemtypes->{$thisitemtype}->{'imageurl'} ),
ccl => $itype_or_itemtype,
code => $thisitemtype,
selected => $selected,
@ -155,7 +154,7 @@ if (!$advanced_search_types or $advanced_search_types eq 'itemtypes') {
for my $thisitemtype (@$advsearchtypes) {
my %row =(
number=>$cnt++,
imageurl=> $thisitemtype->{'imageurl'}?($imgdir."/".$thisitemtype->{'imageurl'}):"",
imageurl=> getitemtypeimagelocation( 'opac', $thisitemtype->{'imageurl'} ),
ccl => $advanced_search_types,
code => $thisitemtype->{authorised_value},
selected => $selected,

View file

@ -88,7 +88,6 @@ my $toggle = 0;
my $overdues_count = 0;
my @overdues;
my @issuedat;
my $imgdir = getitemtypeimagesrc();
my $itemtypes = GetItemTypes();
foreach my $issue ( @$issues ) {
if($count%2 eq 0){ $issue->{'toggle'} = 1; } else { $issue->{'toggle'} = 0; }
@ -132,7 +131,7 @@ foreach my $issue ( @$issues ) {
# imageurl:
my $itemtype = $issue->{'itemtype'};
if ( $itemtype ) {
$issue->{'imageurl'} = $imgdir."/".$itemtypes->{$itemtype}->{'imageurl'};
$issue->{'imageurl'} = getitemtypeimagelocation( 'opac', $itemtypes->{$itemtype}->{'imageurl'} );
$issue->{'description'} = $itemtypes->{$itemtype}->{'description'};
}
$issue->{date_due} = format_date($issue->{date_due});

View file

@ -255,7 +255,7 @@ foreach my $biblioitemnumber (@biblioitemnumbers) {
{
my $item = $iteminfos_of->{$itemnumber};
$item->{itypename} = $itemtypes->{ $item->{itype} }{description};
$item->{imageurl} = getitemtypeimagesrc() . "/".$itemtypes->{ $item->{itype} }{imageurl};
$item->{imageurl} = getitemtypeimagelocation( 'intranet', $itemtypes->{ $item->{itype} }{imageurl} );
$item->{homebranchname} =
$branches->{ $item->{homebranch} }{branchname};

View file

@ -180,7 +180,6 @@ if ($op eq "do_search" && $query) {
my @itemtypesloop;
my $selected=1;
my $cnt;
my $imgdir = getitemtypeimagesrc('intranet');
foreach my $thisitemtype ( sort {$itemtypes->{$a}->{'description'} cmp $itemtypes->{$b}->{'description'} } keys %$itemtypes ) {
my %row =(
code => $thisitemtype,
@ -207,7 +206,6 @@ if ($op eq "do_search" && $query) {
my @itemtypesloop;
my $selected=1;
my $cnt;
my $imgdir = getitemtypeimagesrc('intranet');
foreach my $thisitemtype ( sort {$itemtypes->{$a}->{'description'} cmp $itemtypes->{$b}->{'description'} } keys %$itemtypes ) {
my %row =(
code => $thisitemtype,