From df0a6a71d7301e4e2e346bfe50e00a8e135da33e Mon Sep 17 00:00:00 2001 From: =?utf8?q?St=C3=A9phane=20Delaune?= Date: Wed, 8 Feb 2012 12:12:16 +0100 Subject: [PATCH] Bug 4032 XSLT systempreference takes a path to file rather than YesNo Signed-off-by: Marijana Glavica I am signing it off because it doesn't break anything and I will report another bug for language issues described in my previous comment. Removed MySQLism backquotes --- C4/Search.pm | 3 +- 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 +++++++ .../en/modules/admin/preferences/opac.pref | 14 ++-- .../admin/preferences/staff_client.pref | 14 ++-- opac/opac-detail.pl | 2 +- 9 files changed, 109 insertions(+), 46 deletions(-) diff --git a/C4/Search.pm b/C4/Search.pm index 9bc0af2842..56468b5098 100644 --- a/C4/Search.pm +++ b/C4/Search.pm @@ -1776,8 +1776,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, \@hiddenitems); + $oldbiblio->{XSLTResultsRecord} = XSLTParse4Display($oldbiblio->{biblionumber}, $marcrecord, $interface."XSLTResultsDisplay", 1, \@hiddenitems); # the last parameter tells Koha to clean up the problematic ampersand entities that Zebra outputs } diff --git a/C4/VirtualShelves/Page.pm b/C4/VirtualShelves/Page.pm index 125a1e6c74..d32afed84d 100644 --- a/C4/VirtualShelves/Page.pm +++ b/C4/VirtualShelves/Page.pm @@ -257,7 +257,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 7557efe5a2..621f08fdd5 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 da62e07e50..de355faffc 100755 --- a/catalogue/detail.pl +++ b/catalogue/detail.pl @@ -85,7 +85,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 e8c22ee83a..93b1303765 100644 --- a/installer/data/mysql/sysprefs.sql +++ b/installer/data/mysql/sysprefs.sql @@ -219,10 +219,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 ddc288c800..c297677e09 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -5109,6 +5109,36 @@ if (C4::Context->preference("Version") < TransformToNum($DBversion)) { SetVersion ($DBversion); } +$DBversion = "3.07.00.043"; +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 ae6b6205b9..b3bee949df 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 efa33a83c6..edb90725db 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 923f3ff6a9..a00e9762a2 100755 --- a/opac/opac-detail.pl +++ b/opac/opac-detail.pl @@ -91,7 +91,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" ) ); } -- 2.39.5