[Koha-patches] [PATCH 2/3] (bug #3042) Changing XSLT sysprefs to take filename
Henri-Damien LAURENT
henridamien.laurent at biblibre.com
Tue Feb 16 16:30:01 CET 2010
This change system preferences for XSLT management
bumps kohaversion to 3.01.00.111
If you are using Koha in a non devel mode AND use XSLT, then you HAVE TO adapt the system preference to point to your htdocs
WARNINGS :
- tested with UNIMARC XSL
- donot test the presence of the file, if file absent, then BOOM
- XSL CANNOT be different for intranet and OPAC for result lists.
- Adds a new system preference XSLTIntranetDetailsDisplay
---
C4/Search.pm | 6 +-
C4/XSLT.pm | 47 ++++++++++++--------
catalogue/detail.pl | 2 +-
installer/data/mysql/en/mandatory/sysprefs.sql | 13 ++++--
.../1-Obligatoire/unimarc_standard_systemprefs.sql | 10 +++--
installer/data/mysql/updatedatabase.pl | 8 +++
opac/opac-detail.pl | 4 +-
7 files changed, 57 insertions(+), 33 deletions(-)
diff --git a/C4/Search.pm b/C4/Search.pm
index 14e85ce..8b4e0cd 100644
--- a/C4/Search.pm
+++ b/C4/Search.pm
@@ -1349,10 +1349,9 @@ Format results in a form suitable for passing to the template
# IMO this subroutine is pretty messy still -- it's responsible for
# building the HTML output for the template
sub searchResults {
- my ( $searchdesc, $hits, $results_per_page, $offset, $scan, @marcresults, $hidelostitems ) = @_;
+ my ( $searchdesc, $hits, $results_per_page, $offset, $scan, @marcresults ) = @_;
my $dbh = C4::Context->dbh;
my @newresults;
-
#Build branchnames hash
#find branchname
#get branch information.....
@@ -1652,9 +1651,10 @@ sub searchResults {
use C4::Charset;
SetUTF8Flag($marcrecord);
$debug && warn $marcrecord->as_formatted;
+ # FIXME : This needs some work in order to be more flexible : Can not use a result list for intranet different from OPAC
if (C4::Context->preference("XSLTResultsDisplay") && !$scan) {
$oldbiblio->{XSLTResultsRecord} = XSLTParse4Display(
- $oldbiblio->{biblionumber}, $marcrecord, 'Results' );
+ $oldbiblio->{biblionumber}, $marcrecord, C4::Context->preference("XSLTResultsDisplay") );
}
# last check for norequest : if itemtype is notforloan, it can't be reserved either, whatever the items
diff --git a/C4/XSLT.pm b/C4/XSLT.pm
index a5cf211..22ce07d 100644
--- a/C4/XSLT.pm
+++ b/C4/XSLT.pm
@@ -29,6 +29,7 @@ use C4::Circulation;
use Encode;
use XML::LibXML;
use XML::LibXSLT;
+use LWP::Simple;
use vars qw($VERSION @ISA @EXPORT);
@@ -38,6 +39,7 @@ BEGIN {
@ISA = qw(Exporter);
@EXPORT = qw(
&XSLTParse4Display
+ &GetURI
);
}
@@ -47,6 +49,19 @@ C4::XSLT - Functions for displaying XSLT-generated content
=head1 FUNCTIONS
+=head1 GetURI
+
+=head2 GetURI file and returns the xslt as a string
+
+=cut
+
+sub GetURI {
+ my ($uri) = @_;
+ my $string;
+ $string = get $uri ;
+ return $string;
+}
+
=head1 transformMARCXML4XSLT
=head2 replaces codes with authorized values in a MARC::Record object
@@ -118,15 +133,13 @@ sub getAuthorisedValues4MARCSubfields {
my $stylesheet;
sub XSLTParse4Display {
- my ( $biblionumber, $orig_record, $xsl_suffix, $interface ) = @_;
- $interface = 'opac' unless $interface;
+ my ( $biblionumber, $orig_record, $xslfilename ) = @_;
# grab the XML, run it through our stylesheet, push it out to the browser
my $record = transformMARCXML4XSLT($biblionumber, $orig_record);
#return $record->as_formatted();
my $itemsxml = buildKohaItemsNamespace($biblionumber);
my $xmlrecord = $record->as_xml(C4::Context->preference('marcflavour'));
my $sysxml = "<sysprefs>\n";
-# warn $xmlrecord;
foreach my $syspref ( qw/OPACURLOpenInNewWindow DisplayOPACiconsXSLT URLLinkText/ ) {
$sysxml .= "<syspref name=\"$syspref\">" .
C4::Context->preference( $syspref ) .
@@ -140,25 +153,21 @@ 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') .
- "/prog/en/xslt/" .
- C4::Context->preference('marcflavour') .
- "slim2intranet$xsl_suffix.xsl";
- } else {
- $xslfile = C4::Context->config('opachtdocs') .
- "/prog/en/xslt/" .
- C4::Context->preference('marcflavour') .
- "slim2OPAC$xsl_suffix.xsl";
+ my $style_doc;
+ if ($xslfilename=~/http:/){
+ my $xsltstring=GetURI($xslfilename);
+ $style_doc = $parser->parse_string($xsltstring);
+ }
+ else {
+ 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 0c3a764..90c32ff 100755
--- a/catalogue/detail.pl
+++ b/catalogue/detail.pl
@@ -61,7 +61,7 @@ my $record = GetMarcBiblio($biblionumber);
# 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('IntranetXSLTDetailsDisplay')) );
}
$template->param( 'SpineLabelShowPrintOnBibDetails' => C4::Context->preference("SpineLabelShowPrintOnBibDetails") );
diff --git a/installer/data/mysql/en/mandatory/sysprefs.sql b/installer/data/mysql/en/mandatory/sysprefs.sql
index 3647715..1441c65 100644
--- a/installer/data/mysql/en/mandatory/sysprefs.sql
+++ b/installer/data/mysql/en/mandatory/sysprefs.sql
@@ -212,10 +212,11 @@ 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 exemple : ../koha-tmpl/opac-tmpl/prog/en/xslt/MARC21slim2OPACDetail.xsl','Free'),
+('IntranetXSLTDetailsDisplay','','','Enable XSL stylesheet control over details page display on Intranet exemple : ../koha-tmpl/opac-tmpl/prog/en/xslt/MARC21slim2OPACDetail.xsl','Free'),
+('IntranetXSLTResultsDisplay','','','Enable XSL stylesheet control over results page display both on Intranet and OPAC exemple : ../koha-tmpl/opac-tmpl/prog/en/xslt/MARC21slim2OPACResults.xsl','Free'),
+('XSLTDetailsDisplay','','','Enable XSL stylesheet control over details page display','YesNo'),
+('XSLTResultsDisplay','','','Enable XSL stylesheet control over results page display','YesNo');
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');
@@ -278,7 +279,11 @@ INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES
INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES ('RoutingListAddReserves','1','If ON the patrons on routing lists are automatically added to holds on the issue.','','YesNo');
INSERT INTO `systempreferences` (variable,value,options,explanation,type) VALUES ( 'OpacAddMastheadLibraryPulldown', '0', '', 'Adds a pulldown menu to select the library to search on the opac masthead.', 'YesNo' );
INSERT INTO systempreferences VALUES ('ImageLimit',5,'','Limit images stored in the database by the Patron Card image manager to this number.','Integer');
+<<<<<<< HEAD:installer/data/mysql/en/mandatory/sysprefs.sql
INSERT INTO `systempreferences` (variable,value,options,explanation,type) VALUES ('SpineLabelShowPrintOnBibDetails', '0', '', 'If turned on, a "Print Label" link will appear for each item on the bib details page in the staff interface.', 'YesNo');
INSERT INTO systempreferences (variable,value,explanation,options,type)VALUES('AutoSelfCheckAllowed', '0', 'For corporate and special libraries which want web-based self-check available from any PC without the need for a manual staff login. Most libraries will want to leave this turned off. If on, requires self-check ID and password to be entered in AutoSelfCheckID and AutoSelfCheckPass sysprefs.', '', 'YesNo');
INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('AutoSelfCheckID','','Staff ID with circulation rights to be used for automatic web-based self-check. Only applies if AutoSelfCheckAllowed syspref is turned on.','','free');
INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('AutoSelfCheckPass','','Password to be used for automatic web-based self-check. Only applies if AutoSelfCheckAllowed syspref is turned on.','','free');
+=======
+INSERT INTO systempreferences set value='../koha-tmpl/intranet-tmpl/prog/en/xslt/MARC21slim2IntranetDetails.xsl',type='Free', variable='IntranetXSLTResultsDisplay';
+>>>>>>> (bug #3042) Changing XSLT sysprefs to take filename:installer/data/mysql/en/mandatory/sysprefs.sql
diff --git a/installer/data/mysql/fr-FR/1-Obligatoire/unimarc_standard_systemprefs.sql b/installer/data/mysql/fr-FR/1-Obligatoire/unimarc_standard_systemprefs.sql
index 1738d8d..c5cdd55 100644
--- a/installer/data/mysql/fr-FR/1-Obligatoire/unimarc_standard_systemprefs.sql
+++ b/installer/data/mysql/fr-FR/1-Obligatoire/unimarc_standard_systemprefs.sql
@@ -214,10 +214,12 @@ INSERT INTO `systempreferences` (variable,value,options,explanation,type) VALUES
('TagsShowOnList', '6','','Nombre de tags à afficher sur la page de résultat, 0 désactivant l\'affichage.','Integer');
INSERT INTO `systempreferences` (variable,value,options,explanation,type) VALUES('OPACShelfBrowser','1','','Active le parcours des rayonnages sur la page de détail','YesNo');
-INSERT INTO `systempreferences` (variable,value,options,explanation,type) VALUES('OPACXSLTDetailsDisplay','0','','Activer la feuille XSL pour l''affichage à l''OPAC des notices détaillées','YesNo');
-INSERT INTO `systempreferences` (variable,value,options,explanation,type) VALUES('OPACXSLTResultsDisplay','0','','Activer la feuille XSL pour l''affichage à l''OPAC des listes de résultat','YesNo');
-INSERT INTO `systempreferences` (variable,value,options,explanation,type) VALUES('XSLTDetailsDisplay','0','','Activer la feuille XSL pour l''affichage des notices détaillées dans la partie pro','YesNo');
-INSERT INTO `systempreferences` (variable,value,options,explanation,type) VALUES('XSLTResultsDisplay','0','','Activer la feuille XSL pour l''affichage des listes de résultat dans la partie pro','YesNo');
+INSERT INTO `systempreferences` (variable,value,options,explanation,type) VALUES('XSLTDetailsDisplay','0','','Permet l''utilisation de feuilles de style XSLT pour l''affichage détaillé de notice','YesNo');
+INSERT INTO `systempreferences` (variable,value,options,explanation,type) VALUES('XSLTResultsDisplay','0','','Permet l''utilisation de Feuilles de style XSLT pour l''affichage des listes de résultat','YesNo');
+INSERT INTO `systempreferences` (variable,value,options,explanation,type) VALUES('IntranetXSLTDetailsDisplay','','','Activer la feuille XSL pour l''affichage des notices détaillées (Interface professionnelle) Insérer le chemin vers la feuille xslt exemple','Free');
+INSERT INTO `systempreferences` (variable,value,options,explanation,type) VALUES('OPACXSLTDetailsDisplay','','','Activer la feuille XSL pour l''affichage des notices détaillées (Interface OPAC) Insérer le chemin vers la feuille xslt exemple','Free');
+INSERT INTO `systempreferences` (variable,value,options,explanation,type) VALUES('IntranetXSLTResultsDisplay','','','Activer la feuille XSL pour l''affichage des listes de résultat Insérer le chemin vers la feuille xslt exemple :../koha-tmpl/opac-tmpl/prog/en/xslt/MARC21slim2IntranetDetail.xsl','Free');
+INSERT INTO `systempreferences` (variable,value,options,explanation,type) VALUES('IntranetXSLTResultsDisplay','','','Activer la feuille XSL pour l''affichage des listes de résultat (Interfaces pro et OPAC) Insérer le chemin vers la feuille xslt exemple :../koha-tmpl/opac-tmpl/prog/en/xslt/MARC21slim2OPACResults.xsl','Free');
INSERT INTO `systempreferences` (variable,value,options,explanation,type) VALUES('AdvancedSearchTypes','itemtypes','itemtypes|ccode','Définit quel champ est utilisé pour la limitation par type de document dans la recherche avancée','Choice');
INSERT INTO `systempreferences` (variable,value,options,explanation,type) VALUES('AllowOnShelfHolds', '0', '', 'Autorise les réservations de documents en rayon.', 'YesNo');
INSERT INTO `systempreferences` (variable,value,options,explanation,type) VALUES('AllowHoldsOnDamagedItems', '1', '', 'Autorise les réservations de documents déclarés endommagés', 'YesNo');
diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl
index 32ad48b..360bcb3 100755
--- a/installer/data/mysql/updatedatabase.pl
+++ b/installer/data/mysql/updatedatabase.pl
@@ -3390,6 +3390,14 @@ if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
print "Upgrade done (mark DBrev for 3.2-alpha release)\n";
SetVersion ($DBversion);
}
+$DBversion = "3.01.00.112";
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+ $dbh->do("UPDATE systempreferences set value='../koha-tmpl/opac-tmpl/prog/en/xslt/".C4::Context->preference('marcflavour')."slim2OPACDetail.xsl',type='Free' where variable='XSLTDetailsDisplay' AND value=1;");
+ $dbh->do("UPDATE systempreferences set value='../koha-tmpl/opac-tmpl/prog/en/xslt/".C4::Context->preference('marcflavour')."slim2OPACResults.xsl',type='Free' where variable='XSLTResultsDisplay' AND value=1;");
+ $dbh->do("INSERT INTO systempreferences set value='../koha-tmpl/intranet-tmpl/prog/en/xslt/".C4::Context->preference('marcflavour')."slim2IntranetDetails.xsl',type='Free', variable='IntranetXSLTResultsDisplay';");
+ print "Upgrade to $DBversion done (Improve XSLT)\n";
+ SetVersion ($DBversion);
+}
$DBversion = '3.01.00.112';
if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
diff --git a/opac/opac-detail.pl b/opac/opac-detail.pl
index cf5cf1b..d806057 100755
--- a/opac/opac-detail.pl
+++ b/opac/opac-detail.pl
@@ -72,9 +72,9 @@ if ( ! $record ) {
}
$template->param( biblionumber => $biblionumber );
# XSLT processing of some stuff
-if (C4::Context->preference("OPACXSLTDetailsDisplay") ) {
+if (C4::Context->preference("XSLTDetailsDisplay") ) {
$template->param(
- 'XSLTBloc' => XSLTParse4Display($biblionumber, $record, 'Detail'),'opac' );
+ 'XSLTBloc' => XSLTParse4Display($biblionumber, $record, C4::Context->preference("OPACXSLTDetailsDisplay")) );
}
$template->param('OPACShowCheckoutName' => C4::Context->preference("OPACShowCheckoutName") );
--
1.6.3.3
More information about the Koha-patches
mailing list