From 6dbdcbfe615b7dc11ef5a432b8d009ed16d2efba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Delaune?= Date: Fri, 3 Feb 2012 16:21:08 +0100 Subject: [PATCH] Bug 4032:XSLT systempreference takes a path to file rather than YesNo --- C4/Search.pm | 3 +- C4/VirtualShelves/Page.pm | 2 +- C4/XSLT.pm | 48 +++++++++++--------- catalogue/detail.pl | 2 +- installer/data/mysql/sysprefs.sql | 8 ++-- installer/data/mysql/updatedatabase.pl | 31 +++++++++++++ .../prog/en/modules/admin/preferences/opac.pref | 12 ++--- .../en/modules/admin/preferences/staff_client.pref | 12 ++--- opac/opac-detail.pl | 3 +- 9 files changed, 74 insertions(+), 47 deletions(-) diff --git a/C4/Search.pm b/C4/Search.pm index e86bb26..43a19a5 100644 --- a/C4/Search.pm +++ b/C4/Search.pm @@ -1839,8 +1839,7 @@ sub searchResults { $oldbiblio->{XSLTResultsRecord} = XSLTParse4Display($oldbiblio->{biblionumber}, $marcrecord, - 'Results', - $search_context, + C4::Context->preference("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..d30db85 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, C4::Context->preference("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..a64ffe3 100755 --- 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,7 @@ sub getAuthorisedValues4MARCSubfields { my $stylesheet; sub XSLTParse4Display { - my ( $biblionumber, $orig_record, $xsl_suffix, $interface, $fixamps, $hidden_items ) = @_; - $interface = 'opac' unless $interface; + my ( $biblionumber, $orig_record, $xslfilename, $fixamps, $hidden_items ) = @_; # 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 +168,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 =~ /http:/ ) { + 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..1d3155d 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, C4::Context->preference("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 100755 --- 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..bd6a79e 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -37,6 +37,7 @@ use Getopt::Long; use C4::Context; use C4::Installer; use C4::Dates; +use C4::Templates; use MARC::Record; use MARC::File::XML ( BinaryEncoding => 'utf8' ); @@ -4663,6 +4664,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 = C4::Context->config('intrahtdocs').'/'.C4::Context->preference("template").'/'.C4::Templates::_current_language().'/xslt/'.C4::Context->preference('marcflavour')."slim2intranetDetail.xsl" if (C4::Context->preference("XSLTDetailsDisplay")); + $valueXSLTResultsDisplay = C4::Context->config('intrahtdocs').'/'.C4::Context->preference("template").'/'.C4::Templates::_current_language().'/xslt/'.C4::Context->preference('marcflavour')."slim2intranetResults.xsl" if (C4::Context->preference("XSLTResultsDisplay")); + $valueOPACXSLTDetailsDisplay = C4::Context->config('opachtdocs').'/'.C4::Context->preference("opacthemes").'/'.C4::Templates::_current_language().'/xslt/'.C4::Context->preference('marcflavour')."slim2OPACDetail.xsl" if (C4::Context->preference("OPACXSLTDetailsDisplay")); + $valueOPACXSLTResultsDisplay = C4::Context->config('opachtdocs').'/'.C4::Context->preference("opacthemes").'/'.C4::Templates::_current_language().'/xslt/'.C4::Context->preference('marcflavour')."slim2OPACResults.xsl" 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..e71b4f4 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,13 @@ OPAC: no: Show - lost items on search and detail pages. - - - Show biblio records on OPAC result page + - XSLT path for the OPAC result page - pref: OPACXSLTResultsDisplay - choices: - yes: using XSLT stylesheets. - no: normally. + class: file - - - Show item details pages on the OPAC + - XSLT path for the details pages on the OPAC - pref: OPACXSLTDetailsDisplay - choices: - yes: using XSLT stylesheets. - no: normally. + class: file - - 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..2e2e0f7 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,13 @@ 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 + - XSLT path for the result page in the staff client - pref: XSLTResultsDisplay - choices: - yes: using XSLT stylesheets. - no: normally. + class: file - - - Show item details pages in the staff client + - XSLT path for the details pages in the staff client - pref: XSLTDetailsDisplay - choices: - yes: using XSLT stylesheets. - no: normally. + class: file - - Use the Yahoo UI libraries - pref: yuipath diff --git a/opac/opac-detail.pl b/opac/opac-detail.pl index c4d8218..21d7b48 100755 --- a/opac/opac-detail.pl +++ b/opac/opac-detail.pl @@ -79,10 +79,9 @@ 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, C4::Context->preference("OPACXSLTDetailsDisplay") ) ); } - # We look for the busc param to build the simple paging from the search my $session = get_session($query->cookie("CGISESSID")); my %paging = (previous => {}, next => {}); -- 1.7.0.4