From e15c573d2bfcafa70170d7568b0fee47d55143dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Delaune?= Date: Wed, 8 Feb 2012 12:12:16 +0100 Subject: [PATCH 2/2] Bug 4032:XSLT systempreference takes a path to file rather than YesNo --- C4/Search.pm | 6 +- C4/VirtualShelves/Page.pm | 2 +- C4/XSLT.pm | 80 ++++++++++++++----- catalogue/detail.pl | 2 +- installer/data/mysql/sysprefs.sql | 8 +- installer/data/mysql/updatedatabase.pl | 30 +++++++ .../prog/en/modules/admin/preferences/opac.pref | 14 ++-- .../en/modules/admin/preferences/staff_client.pref | 14 ++-- opac/opac-detail.pl | 2 +- 9 files changed, 110 insertions(+), 48 deletions(-) diff --git a/C4/Search.pm b/C4/Search.pm index 43e7b8a..5910707 100644 --- a/C4/Search.pm +++ b/C4/Search.pm @@ -1781,8 +1781,7 @@ sub searchResults { $debug && warn $marcrecord->as_formatted; my $interface = $search_context eq 'opac' ? 'OPAC' : ''; if (!$scan && C4::Context->preference($interface . "XSLTResultsDisplay")) { - $oldbiblio->{XSLTResultsRecord} = XSLTParse4Display($oldbiblio->{biblionumber}, $marcrecord, 'Results', - $search_context, 1); + $oldbiblio->{XSLTResultsRecord} = XSLTParse4Display($oldbiblio->{biblionumber}, $marcrecord, $interface."XSLTResultsDisplay", 1); # the last parameter tells Koha to clean up the problematic ampersand entities that Zebra outputs } @@ -1850,8 +1849,7 @@ sub searchResults { $oldbiblio->{XSLTResultsRecord} = XSLTParse4Display($oldbiblio->{biblionumber}, $marcrecord, - 'Results', - $search_context, + "OPACXSLTResultsDisplay", 1, # clean up the problematic ampersand entities that Zebra outputs \@hiddenitems ); diff --git a/C4/VirtualShelves/Page.pm b/C4/VirtualShelves/Page.pm index cfa4f60..0f52a14 100644 --- a/C4/VirtualShelves/Page.pm +++ b/C4/VirtualShelves/Page.pm @@ -208,7 +208,7 @@ sub shelfpage ($$$$$) { my $biblionumber = $this_item->{'biblionumber'}; my $record = GetMarcBiblio($biblionumber); $this_item->{XSLTBloc} = - XSLTParse4Display($biblionumber, $record, 'Results', 'opac') + XSLTParse4Display($biblionumber, $record, "OPACXSLTResultsDisplay") if C4::Context->preference("OPACXSLTResultsDisplay") && $type eq 'opac'; # the virtualshelfcontents table does not store these columns nor are they retrieved from the items diff --git a/C4/XSLT.pm b/C4/XSLT.pm index 06dfaf4..31039a5 100644 --- a/C4/XSLT.pm +++ b/C4/XSLT.pm @@ -3,6 +3,7 @@ package C4::XSLT; # # Parts Copyright Katrin Fischer 2011 # Parts Copyright ByWater Solutions 2011 +# Parts Copyright Biblibre 2012 # # This file is part of Koha. # @@ -32,6 +33,7 @@ use C4::Reserves; use Encode; use XML::LibXML; use XML::LibXSLT; +use LWP::Simple; use vars qw($VERSION @ISA @EXPORT); @@ -41,6 +43,7 @@ BEGIN { @ISA = qw(Exporter); @EXPORT = qw( &XSLTParse4Display + &GetURI ); } @@ -50,6 +53,19 @@ C4::XSLT - Functions for displaying XSLT-generated content =head1 FUNCTIONS +=head2 GetURI + +GetURI file and returns the xslt as a string + +=cut + +sub GetURI { + my ($uri) = @_; + my $string; + $string = get $uri ; + return $string; +} + =head2 transformMARCXML4XSLT Replaces codes with authorized values in a MARC::Record object @@ -121,8 +137,39 @@ sub getAuthorisedValues4MARCSubfields { my $stylesheet; sub XSLTParse4Display { - my ( $biblionumber, $orig_record, $xsl_suffix, $interface, $fixamps, $hidden_items ) = @_; - $interface = 'opac' unless $interface; + my ( $biblionumber, $orig_record, $xslsyspref, $fixamps, $hidden_items ) = @_; + my $xslfilename = C4::Context->preference($xslsyspref); + if ( $xslfilename =~ /^\s*"?default"?\s*$/i ) { + if ($xslsyspref eq "XSLTDetailsDisplay") { + $xslfilename = C4::Context->config('intrahtdocs') . + '/' . C4::Context->preference("template") . + '/' . C4::Templates::_current_language() . + '/xslt/' . + C4::Context->preference('marcflavour') . + "slim2intranetDetail.xsl"; + } elsif ($xslsyspref eq "XSLTResultsDisplay") { + $xslfilename = C4::Context->config('intrahtdocs') . + '/' . C4::Context->preference("template") . + '/' . C4::Templates::_current_language() . + '/xslt/' . + C4::Context->preference('marcflavour') . + "slim2intranetResults.xsl"; + } elsif ($xslsyspref eq "OPACXSLTDetailsDisplay") { + $xslfilename = C4::Context->config('opachtdocs') . + '/' . C4::Context->preference("opacthemes") . + '/' . C4::Templates::_current_language() . + '/xslt/' . + C4::Context->preference('marcflavour') . + "slim2OPACDetail.xsl"; + } elsif ($xslsyspref eq "OPACXSLTResultsDisplay") { + $xslfilename = C4::Context->config('opachtdocs') . + '/' . C4::Context->preference("opacthemes") . + '/' . C4::Templates::_current_language() . + '/xslt/' . + C4::Context->preference('marcflavour') . + "slim2OPACResults.xsl"; + } + } # grab the XML, run it through our stylesheet, push it out to the browser my $record = transformMARCXML4XSLT($biblionumber, $orig_record); #return $record->as_formatted(); @@ -153,29 +200,20 @@ sub XSLTParse4Display { # don't die when you find &, >, etc $parser->recover_silently(0); my $source = $parser->parse_string($xmlrecord); - unless ( $stylesheet ) { + unless ( $stylesheet->{$xslfilename} ) { my $xslt = XML::LibXSLT->new(); - my $xslfile; - if ($interface eq 'intranet') { - $xslfile = C4::Context->config('intrahtdocs') . - '/' . C4::Context->preference("template") . - '/' . C4::Templates::_current_language() . - '/xslt/' . - C4::Context->preference('marcflavour') . - "slim2intranet$xsl_suffix.xsl"; + my $style_doc; + if ( $xslfilename =~ /^https?:\/\// ) { + my $xsltstring = GetURI($xslfilename); + $style_doc = $parser->parse_string($xsltstring); } else { - $xslfile = C4::Context->config('opachtdocs') . - '/' . C4::Context->preference("opacthemes") . - '/' . C4::Templates::_current_language() . - '/xslt/' . - C4::Context->preference('marcflavour') . - "slim2OPAC$xsl_suffix.xsl"; + use Cwd; + $style_doc = $parser->parse_file($xslfilename); } - my $style_doc = $parser->parse_file($xslfile); - $stylesheet = $xslt->parse_stylesheet($style_doc); + $stylesheet->{$xslfilename} = $xslt->parse_stylesheet($style_doc); } - my $results = $stylesheet->transform($source); - my $newxmlrecord = $stylesheet->output_string($results); + my $results = $stylesheet->{$xslfilename}->transform($source); + my $newxmlrecord = $stylesheet->{$xslfilename}->output_string($results); return $newxmlrecord; } diff --git a/catalogue/detail.pl b/catalogue/detail.pl index db38551..219d0f5 100755 --- a/catalogue/detail.pl +++ b/catalogue/detail.pl @@ -84,7 +84,7 @@ my $marcflavour = C4::Context->preference("marcflavour"); # XSLT processing of some stuff if (C4::Context->preference("XSLTDetailsDisplay") ) { $template->param('XSLTDetailsDisplay' =>'1', - 'XSLTBloc' => XSLTParse4Display($biblionumber, $record, 'Detail','intranet') ); + 'XSLTBloc' => XSLTParse4Display($biblionumber, $record, "XSLTDetailsDisplay") ); } $template->param( 'SpineLabelShowPrintOnBibDetails' => C4::Context->preference("SpineLabelShowPrintOnBibDetails") ); diff --git a/installer/data/mysql/sysprefs.sql b/installer/data/mysql/sysprefs.sql index 5e3d79d..4c06fe0 100644 --- a/installer/data/mysql/sysprefs.sql +++ b/installer/data/mysql/sysprefs.sql @@ -218,10 +218,10 @@ INSERT INTO `systempreferences` (variable,value,options,explanation,type) VALUES INSERT INTO `systempreferences` (variable,value,options,explanation,type) VALUES('OPACShelfBrowser','1','','Enable/disable Shelf Browser on item details page. WARNING: this feature is very resource consuming on collections with large numbers of items.','YesNo'); INSERT INTO `systempreferences` (variable,value,options,explanation,type) VALUES -('OPACXSLTDetailsDisplay','0','','Enable XSL stylesheet control over details page display on OPAC','YesNo'), -('OPACXSLTResultsDisplay','0','','Enable XSL stylesheet control over results page display on OPAC','YesNo'), -('XSLTDetailsDisplay','0','','Enable XSL stylesheet control over details page display on intranet','YesNo'), -('XSLTResultsDisplay','0','','Enable XSL stylesheet control over results page display on intranet','YesNo'); +('OPACXSLTDetailsDisplay','','','Enable XSL stylesheet control over details page display on OPAC','Free'), +('OPACXSLTResultsDisplay','','','Enable XSL stylesheet control over results page display on OPAC','Free'), +('XSLTDetailsDisplay','','','Enable XSL stylesheet control over details page display on intranet','Free'), +('XSLTResultsDisplay','','','Enable XSL stylesheet control over results page display on intranet','Free'); INSERT INTO `systempreferences` (variable,value,options,explanation,type) VALUES('AdvancedSearchTypes','itemtypes','itemtypes|ccode','Select which set of fields comprise the Type limit in the advanced search','Choice'); INSERT INTO `systempreferences` (variable,value,options,explanation,type) VALUES('AllowOnShelfHolds', '0', '', 'Allow hold requests to be placed on items that are not on loan', 'YesNo'); INSERT INTO `systempreferences` (variable,value,options,explanation,type) VALUES('AllowHoldsOnDamagedItems', '1', '', 'Allow hold requests to be placed on damaged items', 'YesNo'); diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index 099dfb9..96f6241 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -4663,6 +4663,36 @@ ENDOFRENEWAL print "Upgrade to $DBversion done (Added a system preference to allow renewal of Patron account either from todays date or from existing expiry date in the patrons account.)\n"; SetVersion($DBversion); } + +$DBversion = "XXX"; +if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) { + my $countXSLTDetailsDisplay = 0; + my $valueXSLTDetailsDisplay = ""; + my $valueXSLTResultsDisplay = ""; + my $valueOPACXSLTDetailsDisplay = ""; + my $valueOPACXSLTResultsDisplay = ""; + #the line below test if database comes from a BibLibre's branch + $countXSLTDetailsDisplay = $dbh->do('SELECT 1 FROM `systempreferences` WHERE `variable`="IntranetXSLTDetailsDisplay"'); + if ($countXSLTDetailsDisplay > 0) + { + #the two lines below will only be used to update the databases from the BibLibre's branch. They will not affect the others + $dbh->do(q|UPDATE `systempreferences` SET `variable`="XSLTDetailsDisplay" WHERE `variable`="IntranetXSLTDetailsDisplay"|); + $dbh->do(q|UPDATE `systempreferences` SET `variable`="XSLTResultsDisplay" WHERE `variable`="IntranetXSLTResultsDisplay"|); + } + else + { + $valueXSLTDetailsDisplay = "default" if (C4::Context->preference("XSLTDetailsDisplay")); + $valueXSLTResultsDisplay = "default" if (C4::Context->preference("XSLTResultsDisplay")); + $valueOPACXSLTDetailsDisplay = "default" if (C4::Context->preference("OPACXSLTDetailsDisplay")); + $valueOPACXSLTResultsDisplay = "default" if (C4::Context->preference("OPACXSLTResultsDisplay")); + $dbh->do("UPDATE systempreferences SET type='Free', value=\"$valueXSLTDetailsDisplay\" WHERE variable='XSLTDetailsDisplay'"); + $dbh->do("UPDATE systempreferences SET type='Free', value=\"$valueXSLTResultsDisplay\" WHERE variable='XSLTResultsDisplay'"); + $dbh->do("UPDATE systempreferences SET type='Free', value=\"$valueOPACXSLTDetailsDisplay\" WHERE variable='OPACXSLTDetailsDisplay'"); + $dbh->do("UPDATE systempreferences SET type='Free', value=\"$valueOPACXSLTResultsDisplay\" WHERE variable='OPACXSLTResultsDisplay'"); + } + print "XSLT systempreference takes a path to file rather than YesNo\n"; + SetVersion($DBversion); +} =head1 FUNCTIONS =head2 DropAllForeignKeys($table) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref index d6ae2b2..bb6b74e 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref @@ -48,17 +48,15 @@ OPAC: no: Show - lost items on search and detail pages. - - - Show biblio records on OPAC result page + - 'Display OPAC results using XSLT stylesheet at: ' - pref: OPACXSLTResultsDisplay - choices: - yes: using XSLT stylesheets. - no: normally. + class: file + - '
Options:
- leave empty for "no xslt"
- enter "default" for the default one
- put a path to define a xslt file
- put an URL for an external specific stylesheet.' - - - Show item details pages on the OPAC + - 'Display OPAC details using XSLT stylesheet at: ' - pref: OPACXSLTDetailsDisplay - choices: - yes: using XSLT stylesheets. - no: normally. + class: file + - '
Options:
- leave empty for "no xslt"
- enter "default" for the default one
- put a path to define a xslt file
- put an URL for an external specific stylesheet.' - - On pages displayed with XSLT stylesheets on the OPAC, - pref: DisplayOPACiconsXSLT diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/staff_client.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/staff_client.pref index df0a434..008ef5d 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/staff_client.pref +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/staff_client.pref @@ -51,17 +51,15 @@ Staff Client: class: url - for the Staff Client's favicon. (This should be a complete URL, starting with http://.) - - - Show biblio records on result page in the staff client + - 'Display results in the staff client using XSLT stylesheet at: ' - pref: XSLTResultsDisplay - choices: - yes: using XSLT stylesheets. - no: normally. + class: file + - '
Options:
- leave empty for "no xslt"
- enter "default" for the default one
- put a path to define a xslt file
- put an URL for an external specific stylesheet.' - - - Show item details pages in the staff client + - 'Display details in the staff client using XSLT stylesheet at: ' - pref: XSLTDetailsDisplay - choices: - yes: using XSLT stylesheets. - no: normally. + class: file + - '
Options:
- leave empty for "no xslt"
- enter "default" for the default one
- put a path to define a xslt file
- put an URL for an external specific stylesheet.' - - Use the Yahoo UI libraries - pref: yuipath diff --git a/opac/opac-detail.pl b/opac/opac-detail.pl index c4d8218..4c2fa7c 100755 --- a/opac/opac-detail.pl +++ b/opac/opac-detail.pl @@ -79,7 +79,7 @@ SetUTF8Flag($record); # XSLT processing of some stuff if (C4::Context->preference("OPACXSLTDetailsDisplay") ) { - $template->param( 'XSLTBloc' => XSLTParse4Display($biblionumber, $record, 'Detail', 'opac') ); + $template->param( 'XSLTBloc' => XSLTParse4Display($biblionumber, $record, "OPACXSLTDetailsDisplay" ) ); } -- 1.7.0.4