bugfix: need to return something if an itemtype doesn't have an image
[koha.git] / C4 / Koha.pm
index 846af3e..a35909f 100644 (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);
 
@@ -42,11 +43,11 @@ BEGIN {
                &getFacets
                &displayServers
                &getnbpages
-               &getitemtypeimagesrcfromurl
                &get_infos_of
                &get_notforloan_label_of
                &getitemtypeimagedir
                &getitemtypeimagesrc
+               &getitemtypeimagelocation
                &GetAuthorisedValues
                &GetAuthorisedValueCategories
                &GetKohaAuthorisedValues
@@ -73,9 +74,8 @@ BEGIN {
 
 =head1 FUNCTIONS
 
-=over 2
-
 =cut
+
 =head2 slashifyDate
 
   $slash_date = &slashifyDate($dash_date);
@@ -441,21 +441,11 @@ sub getitemtypeinfo {
     $sth->execute($itemtype);
     my $res = $sth->fetchrow_hashref;
 
-    $res->{imageurl} = getitemtypeimagesrcfromurl( $res->{imageurl} );
+    $res->{imageurl} = getitemtypeimagelocation( 'intranet', $res->{imageurl} );
 
     return $res;
 }
 
-sub getitemtypeimagesrcfromurl {
-    my ($imageurl) = @_;
-
-    if ( defined $imageurl and $imageurl !~ m/^http/ ) {
-        $imageurl = getitemtypeimagesrc() . '/' . $imageurl;
-    }
-
-    return $imageurl;
-}
-
 =head2 getitemtypeimagedir
 
 =over
@@ -494,6 +484,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
@@ -646,7 +648,7 @@ sub GetPrinter ($$) {
     return $printer;
 }
 
-=item getnbpages
+=head2 getnbpages
 
 Returns the number of pages to display in a pagination bar, given the number
 of items and the number of items per page.
@@ -659,7 +661,7 @@ sub getnbpages {
     return int( ( $nb_items - 1 ) / $nb_items_per_page ) + 1;
 }
 
-=item getallthemes
+=head2 getallthemes
 
   (@themes) = &getallthemes('opac');
   (@themes) = &getallthemes('intranet');