@@ -, +, @@ images Tools This needs to be turned on to show local cover images in OPAC. --- catalogue/detail.pl | 6 + catalogue/image.pl | 108 ++++++++++++++++++++ catalogue/imageviewer.pl | 51 +++++++++ .../intranet-tmpl/prog/en/css/staff-global.css | 3 + .../prog/en/includes/doc-head-close.inc | 8 ++ koha-tmpl/intranet-tmpl/prog/en/js/localcovers.js | 44 ++++++++ .../prog/en/modules/catalogue/detail.tt | 12 ++ .../prog/en/modules/catalogue/imageviewer.tt | 43 ++++++++ .../prog/en/modules/tools/upload-images.tt | 2 +- .../opac-tmpl/prog/en/includes/doc-head-close.inc | 9 ++ koha-tmpl/opac-tmpl/prog/en/js/localcovers.js | 44 ++++++++ koha-tmpl/opac-tmpl/prog/en/modules/opac-detail.tt | 18 ++++ .../opac-tmpl/prog/en/modules/opac-imageviewer.tt | 43 ++++++++ .../opac-tmpl/prog/en/modules/opac-results.tt | 2 + opac/opac-detail.pl | 11 ++ opac/opac-image.pl | 108 ++++++++++++++++++++ opac/opac-imageviewer.pl | 51 +++++++++ opac/opac-search.pl | 4 + tools/upload-cover-image.pl | 3 +- 19 files changed, 568 insertions(+), 2 deletions(-) create mode 100755 catalogue/image.pl create mode 100755 catalogue/imageviewer.pl create mode 100644 koha-tmpl/intranet-tmpl/prog/en/js/localcovers.js create mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/imageviewer.tt create mode 100644 koha-tmpl/opac-tmpl/prog/en/js/localcovers.js create mode 100644 koha-tmpl/opac-tmpl/prog/en/modules/opac-imageviewer.tt create mode 100755 opac/opac-image.pl create mode 100755 opac/opac-imageviewer.pl --- a/catalogue/detail.pl +++ a/catalogue/detail.pl @@ -37,6 +37,7 @@ use C4::External::Amazon; use C4::Search; # enabled_staff_search_views use C4::VirtualShelves; use C4::XSLT; +use C4::Images; # use Smart::Comments; @@ -384,6 +385,11 @@ if ( C4::Context->preference("AmazonEnabled") == 1 ) { } } +if ( C4::Context->preference("LocalCoverImages") == 1 ) { + my @images = ListImagesForBiblio($biblionumber); + $template->{VARS}->{localimages} = \@images; +} + # Get OPAC URL if (C4::Context->preference('OPACBaseURL')){ $template->param( OpacUrl => C4::Context->preference('OPACBaseURL') ); --- a/catalogue/image.pl +++ a/catalogue/image.pl @@ -0,0 +1,108 @@ +#!/usr/bin/perl +# +# based on patronimage.pl +# +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 2 of the License, or (at your option) any later +# version. +# +# Koha is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with Koha; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +# +# +# + +use strict; +use warnings; + +use CGI; #qw(:standard escapeHTML); +use C4::Context; +use C4::Images; + +$|=1; + +my $DEBUG = 1; +my $data = new CGI; +my $imagenumber; + +=head1 NAME + +image.pl - Script for retrieving and formatting local cover images for display + +=head1 SYNOPSIS + + + + + + +=head1 DESCRIPTION + +This script, when called from within HTML and passed a valid imagenumber or +biblionumber, will retrieve the image data associated with that biblionumber +if one exists, format it in proper HTML format and pass it back to be displayed. +If the parameter thumbnail has been provided, a thumbnail will be returned +rather than the full-size image. When a biblionumber is provided rather than an +imagenumber, a random image is selected. + +=cut + +if (defined $data->param('imagenumber')) { + $imagenumber = $data->param('imagenumber'); +} elsif (defined $data->param('biblionumber')) { + my @imagenumbers = ListImagesForBiblio($data->param('biblionumber')); + if (@imagenumbers) { + $imagenumber = $imagenumbers[0]; + } else { + warn "No images for this biblio" if $DEBUG; + error(); + } +} else { + $imagenumber = shift; +} + +if ($imagenumber) { + warn "imagenumber passed in: $imagenumber" if $DEBUG; + my $imagedata = RetrieveImage($imagenumber); + + error() unless $imagedata; + + if ($imagedata) { + my $image; + if ($data->param('thumbnail')) { + $image = $imagedata->{'thumbnail'}; + } else { + $image = $imagedata->{'imagefile'}; + } + print $data->header (-type => $imagedata->{'mimetype'}, -'Cache-Control' => 'no-store', -expires => 'now', -Content_Length => length ($image)), $image; + exit; + } else { + warn "No image exists for $imagenumber" if $DEBUG; + error(); + } +} else { + error(); +} + +error(); + +sub error { + print $data->header ( -status=> '404', -expires => 'now' ); + exit; +} + +=head1 AUTHOR + +Chris Nighswonger cnighswonger foundations edu + +modified for local cover images by Koustubha Kale kmkale anantcorp com + +=cut --- a/catalogue/imageviewer.pl +++ a/catalogue/imageviewer.pl @@ -0,0 +1,51 @@ +#!/usr/bin/perl + +# Copyright 2011 C & P Bibliography Services +# +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 2 of the License, or (at your option) any later +# version. +# +# Koha is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with Koha; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +use strict; +use warnings; + +use CGI; +use C4::Auth; +use C4::Biblio; +use C4::Output; +use C4::Images; + +my $query = new CGI; +my ( $template, $borrowernumber, $cookie ) = get_template_and_user( + { + template_name => "catalogue/imageviewer.tmpl", + query => $query, + type => "intranet", + authnotrequired => 0, + flagsrequired => { catalogue => 1 }, + } +); + +my $biblionumber = $query->param('biblionumber') || $query->param('bib'); +my ($count, $biblio) = GetBiblio($biblionumber); + +if (C4::Context->preference("LocalCoverImages")) { + my @images = ListImagesForBiblio($biblionumber); + $template->{VARS}->{'LocalCoverImages'} = 1; + $template->{VARS}->{'images'} = \@images; +} + +$template->{VARS}->{'biblio'} = $biblio; + +output_html_with_http_headers $query, $cookie, $template->output; --- a/koha-tmpl/intranet-tmpl/prog/en/css/staff-global.css +++ a/koha-tmpl/intranet-tmpl/prog/en/css/staff-global.css @@ -2133,3 +2133,6 @@ div.pager input.pagedisplay { font-weight: bold; text-align : center; } +.localimage { + padding: .3em; +} --- a/koha-tmpl/intranet-tmpl/prog/en/includes/doc-head-close.inc +++ a/koha-tmpl/intranet-tmpl/prog/en/includes/doc-head-close.inc @@ -99,3 +99,11 @@ [% IF ( virtualshelves || intranetbookbag ) %] [% END %] +[% IF LocalCoverImages %] + + +[% END %] --- a/koha-tmpl/intranet-tmpl/prog/en/js/localcovers.js +++ a/koha-tmpl/intranet-tmpl/prog/en/js/localcovers.js @@ -0,0 +1,44 @@ +if (typeof KOHA == "undefined" || !KOHA) { + var KOHA = {}; +} + +/** + * A namespace for local cover related functions. + */ +KOHA.LocalCover = { + + + /** + * Search all: + *
+ * or + *
+ * and run a search with all collected isbns to Open Library Book Search. + * The result is asynchronously returned by OpenLibrary and catched by + * olCallBack(). + */ + GetCoverFromBibnumber: function(uselink) { + $("div [id^=local-thumbnail]").each(function(i) { + var mydiv = this; + var message = document.createElement("span"); + $(message).attr("class","no-image"); + $(message).html(NO_LOCAL_JACKET); + $(mydiv).append(message); + var img = $("").attr('src', + '/cgi-bin/koha/catalogue/image.pl?thumbnail=1&biblionumber=' + $(mydiv).attr("class")) + .load(function () { + if (!this.complete || typeof this.naturalWidth == "undefined" || this.naturalWidth == 0) { + } else { + if (uselink) { + var a = $("").attr('href', '/cgi-bin/koha/catalogue/imageviewer.pl?biblionumber=' + $(mydiv).attr("class")); + $(a).append(img); + $(mydiv).append(a); + } else { + $(mydiv).append(img); + } + $(mydiv).children('.no-image').remove(); + } + }) + }); + } +}; --- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt @@ -233,6 +233,7 @@ function verify_images() { [% IF ( subscriptionsnumber ) %]
  • Subscriptions
  • [% END %] [% IF ( FRBRizeEditions ) %][% IF ( XISBNS ) %]
  • Editions
  • [% END %][% END %] [% IF ( AmazonSimilarItems ) %]
  • Related Titles
  • [% END %] +[% IF ( LocalCoverImages ) %]
  • Images
  • [% END %]
    @@ -524,6 +525,17 @@ function verify_images() {
    [% END %][% END %] +[% IF ( LocalCoverImages ) %] +
    +
    Click on an image to view it in the image viewer
    +[% FOREACH image IN localimages %] +[% IF image %] +img +[% END %] +[% END %] +
    +[% END %] +
    --- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/imageviewer.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/imageviewer.tt @@ -0,0 +1,43 @@ +[% INCLUDE 'doc-head-open.inc' %] +[% IF ( LibraryNameTitle ) %][% LibraryNameTitle %][% ELSE %]Koha Online[% END %] Catalog › Images for: [% biblio.title |html %] +[% INCLUDE 'doc-head-close.inc' %] + + + + +
    Large view
    +[% IF LocalCoverImages == 1 %] +[% FOREACH img IN images %] +[% IF img %] +Image +[% END %] +[% END %] +[% biblio.title %] [% biblio.author %] +[% ELSE %] +Unfortunately, images are not enabled for this catalog at this time. +[% END %] + + --- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/upload-images.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/upload-images.tt @@ -109,7 +109,7 @@ function CheckForm(f) { Options
    1. - +
    --- a/koha-tmpl/opac-tmpl/prog/en/includes/doc-head-close.inc +++ a/koha-tmpl/opac-tmpl/prog/en/includes/doc-head-close.inc @@ -98,6 +98,15 @@ var NO_OL_JACKET = _("No cover image available"); [% END %] +[% IF OPACLocalCoverImages %] + + +[% END %] + [% IF ( BakerTaylorEnabled ) %] + + + +
    Large view
    +[% IF OPACLocalCoverImages == 1 %] +[% FOREACH img IN images %] +[% IF img %] +Image +[% END %] +[% END %] +[% biblio.title %] [% biblio.author %] +[% ELSE %] +Unfortunately, images are not enabled for this catalog at this time. +[% END %] + + --- a/koha-tmpl/opac-tmpl/prog/en/modules/opac-results.tt +++ a/koha-tmpl/opac-tmpl/prog/en/modules/opac-results.tt @@ -229,6 +229,7 @@ $(document).ready(function(){ [% END %] [% END %][% END %] [% IF OpenLibraryCovers %]KOHA.OpenLibrary.GetCoverFromIsbn();[% END %] + [% IF OPACLocalCoverImages %]KOHA.LocalCover.GetCoverFromBibnumber(false);[% END %] [% IF ( GoogleJackets ) %]KOHA.Google.GetCoverFromIsbn();[% END %] }); //]]> @@ -528,6 +529,7 @@ $(document).ready(function(){ + [% IF ( OPACLocalCoverImages ) %]
    [% END %] [% IF ( OPACAmazonEnabled ) %][% IF ( OPACAmazonCoverImages ) %][% IF ( SEARCH_RESULT.normalized_isbn ) %][% ELSE %]No cover image available[% END %][% END %][% END %] [% IF ( SyndeticsEnabled ) %][% IF ( SyndeticsCoverImages ) %][% IF ( using_https ) %] --- a/opac/opac-detail.pl +++ a/opac/opac-detail.pl @@ -45,6 +45,7 @@ use C4::Charset; use MARC::Record; use MARC::Field; use List::MoreUtils qw/any none/; +use C4::Images; BEGIN { if (C4::Context->preference('BakerTaylorEnabled')) { @@ -690,6 +691,11 @@ if (scalar(@serialcollections) > 0) { serialcollections => \@serialcollections); } +# Local cover Images stuff +if (C4::Context->preference("OPACLocalCoverImages")){ + $template->param(OPACLocalCoverImages => 1); +} + # Amazon.com Stuff if ( C4::Context->preference("OPACAmazonEnabled") ) { $template->param( AmazonTld => get_amazon_tld() ); @@ -915,4 +921,9 @@ my $defaulttab = ? 'serialcollection' : 'subscription'; $template->param('defaulttab' => $defaulttab); +if (C4::Context->preference('OPACLocalCoverImages') == 1) { + my @images = ListImagesForBiblio($biblionumber); + $template->{VARS}->{localimages} = \@images; +} + output_html_with_http_headers $query, $cookie, $template->output; --- a/opac/opac-image.pl +++ a/opac/opac-image.pl @@ -0,0 +1,108 @@ +#!/usr/bin/perl +# +# based on patronimage.pl +# +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 2 of the License, or (at your option) any later +# version. +# +# Koha is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with Koha; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +# +# +# + +use strict; +use warnings; + +use CGI; #qw(:standard escapeHTML); +use C4::Context; +use C4::Images; + +$|=1; + +my $DEBUG = 1; +my $data = new CGI; +my $imagenumber; + +=head1 NAME + +opac-image.pl - Script for retrieving and formatting local cover images for display + +=head1 SYNOPSIS + + + + + + +=head1 DESCRIPTION + +This script, when called from within HTML and passed a valid imagenumber or +biblionumber, will retrieve the image data associated with that biblionumber +if one exists, format it in proper HTML format and pass it back to be displayed. +If the parameter thumbnail has been provided, a thumbnail will be returned +rather than the full-size image. When a biblionumber is provided rather than an +imagenumber, a random image is selected. + +=cut + +if (defined $data->param('imagenumber')) { + $imagenumber = $data->param('imagenumber'); +} elsif (defined $data->param('biblionumber')) { + my @imagenumbers = ListImagesForBiblio($data->param('biblionumber')); + if (@imagenumbers) { + $imagenumber = $imagenumbers[0]; + } else { + warn "No images for this biblio" if $DEBUG; + error(); + } +} else { + $imagenumber = shift; +} + +if ($imagenumber) { + warn "imagenumber passed in: $imagenumber" if $DEBUG; + my $imagedata = RetrieveImage($imagenumber); + + error() unless $imagedata; + + if ($imagedata) { + my $image; + if ($data->param('thumbnail')) { + $image = $imagedata->{'thumbnail'}; + } else { + $image = $imagedata->{'imagefile'}; + } + print $data->header (-type => $imagedata->{'mimetype'}, -'Cache-Control' => 'no-store', -expires => 'now', -Content_Length => length ($image)), $image; + exit; + } else { + warn "No image exists for $imagenumber" if $DEBUG; + error(); + } +} else { + error(); +} + +error(); + +sub error { + print $data->header ( -status=> '404', -expires => 'now' ); + exit; +} + +=head1 AUTHOR + +Chris Nighswonger cnighswonger foundations edu + +modified for local cover images by Koustubha Kale kmkale anantcorp com + +=cut --- a/opac/opac-imageviewer.pl +++ a/opac/opac-imageviewer.pl @@ -0,0 +1,51 @@ +#!/usr/bin/perl + +# Copyright 2011 C & P Bibliography Services +# +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 2 of the License, or (at your option) any later +# version. +# +# Koha is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with Koha; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +use strict; +use warnings; + +use CGI; +use C4::Auth; +use C4::Biblio; +use C4::Output; +use C4::Images; + +my $query = new CGI; +my ( $template, $borrowernumber, $cookie ) = get_template_and_user( + { + template_name => "opac-imageviewer.tmpl", + query => $query, + type => "opac", + authnotrequired => ( C4::Context->preference("OpacPublic") ? 1 : 0 ), + flagsrequired => { borrow => 1 }, + } +); + +my $biblionumber = $query->param('biblionumber') || $query->param('bib'); +my ($count, $biblio) = GetBiblio($biblionumber); + +if (C4::Context->preference("OPACLocalCoverImages")) { + my @images = ListImagesForBiblio($biblionumber); + $template->{VARS}->{'OPACLocalCoverImages'} = 1; + $template->{VARS}->{'images'} = \@images; +} + +$template->{VARS}->{'biblio'} = $biblio; + +output_html_with_http_headers $query, $cookie, $template->output; --- a/opac/opac-search.pl +++ a/opac/opac-search.pl @@ -616,6 +616,10 @@ for (my $i=0;$i<@servers;$i++) { $template->param(SEARCH_RESULTS => \@newresults, OPACItemsResultsDisplay => (C4::Context->preference("OPACItemsResultsDisplay") eq "itemdetails"?1:0), ); + if (C4::Context->preference("OPACLocalCoverImages")){ + $template->param(OPACLocalCoverImages => 1); + $template->param(OPACLocalCoverImagesPriority => C4::Context->preference("OPACLocalCoverImagesPriority")); + } ## Build the page numbers on the bottom of the page my @page_numbers; # total number of pages there will be --- a/tools/upload-cover-image.pl +++ a/tools/upload-cover-image.pl @@ -66,7 +66,7 @@ my ($template, $loggedinuser, $cookie) my $filetype = $input->param('filetype'); my $biblionumber = $input->param('biblionumber'); my $uploadfilename = $input->param('uploadfile'); -my $replace = $input->param('replace'); +my $replace = !C4::Context->preference("AllowMultipleCovers") || $input->param('replace'); my $op = $input->param('op'); my %cookies = parse CGI::Cookie($cookie); my $sessionID = $cookies{'CGISESSID'}->value; @@ -78,6 +78,7 @@ $template->{VARS}->{'biblionumber'} = $biblionumber; my $total = 0; + if ($fileID) { my $uploaded_file = C4::UploadedFile->fetch($sessionID, $fileID); if ($filetype eq 'image') { --