(bug #3042) Changing XSLT sysprefs to take filename
authorHenri-Damien LAURENT <henridamien.laurent@biblibre.com>
Wed, 6 Jan 2010 21:27:29 +0000 (22:27 +0100)
committerHenri-Damien LAURENT <henridamien.laurent@biblibre.com>
Mon, 11 Jan 2010 12:33:13 +0000 (13:33 +0100)
This change system preferences for XSLT management
bumps kohaversion to 3.0.6.03
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.

C4/Search.pm
C4/XSLT.pm
installer/data/mysql/en/mandatory/sysprefs.sql
installer/data/mysql/fr-FR/1-Obligatoire/unimarc_standard_systemprefs.sql
installer/data/mysql/updatedatabase30.pl
kohaversion.pl
opac/opac-detail.pl

index 8a62a40..43d21cc 100644 (file)
@@ -1338,7 +1338,6 @@ sub searchResults {
     my ( $searchdesc, $hits, $results_per_page, $offset, $scan, @marcresults ) = @_;
     my $dbh = C4::Context->dbh;
     my @newresults;
-
     #Build branchnames hash
     #find branchname
     #get branch information.....
@@ -1672,9 +1671,10 @@ sub searchResults {
         }
 
         # XSLT processing of some stuff
+        # 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
index 1073a2d..cd53e31 100644 (file)
@@ -26,6 +26,7 @@ use C4::Circulation;
 use Encode;
 use XML::LibXML;
 use XML::LibXSLT;
+use LWP::Simple;
 
 use strict;
 
@@ -37,6 +38,7 @@ BEGIN {
     @ISA = qw(Exporter);
     @EXPORT = qw(
         &XSLTParse4Display
+        &GetURI
     );
 }
 
@@ -46,6 +48,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,7 +133,7 @@ sub getAuthorisedValues4MARCSubfields {
 my $stylesheet;
 
 sub XSLTParse4Display {
-    my ( $biblionumber, $orig_record, $xsl_suffix ) = @_;
+    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();
@@ -129,17 +144,22 @@ sub XSLTParse4Display {
     # don't die when you find &, >, etc
     $parser->recover_silently(1);
     my $source = $parser->parse_string($xmlrecord);
-    unless ( $stylesheet ) {
+    unless ( $stylesheet->{$xslfilename} ) {
         my $xslt = XML::LibXSLT->new();
-        my $xslfile = C4::Context->config('opachtdocs') . 
-                      "/prog/en/xslt/" .
-                      C4::Context->preference('marcflavour') .
-                      "slim2OPAC$xsl_suffix.xsl";
-        my $style_doc = $parser->parse_file($xslfile);
-        $stylesheet = $xslt->parse_stylesheet($style_doc);
+        my $style_doc;
+        if ($xslfilename=~/http:/){
+            my $xsltstring=GetURI($xslfilename);
+            $style_doc = $parser->parse_string($xsltstring);
+        }
+        else {
+            use Cwd;
+            warn getcwd;
+            $style_doc = $parser->parse_file($xslfilename);
+        }
+        $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;
 }
 
index a2a4aba..f9ad18a 100644 (file)
@@ -204,8 +204,8 @@ 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
-('XSLTDetailsDisplay','0','','Enable XSL stylesheet control over details page display on OPAC WARNING: MARC21 Only','YesNo'),
-('XSLTResultsDisplay','0','','Enable XSL stylesheet control over results page display on OPAC WARNING: MARC21 Only','YesNo');
+('XSLTDetailsDisplay','0','','Enable XSL stylesheet control over details page display on OPAC exemple : ../koha-tmpl/opac-tmpl/prog/en/xslt/MARC21slim2OPACDetail.xsl','Textarea'),
+('XSLTResultsDisplay','0','','Enable XSL stylesheet control over results page display on OPAC exemple : ../koha-tmpl/opac-tmpl/prog/en/xslt/MARC21slim2OPACResults.xsl','Textarea');
 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');
index 8bca312..32628b8 100644 (file)
@@ -206,8 +206,8 @@ 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('XSLTDetailsDisplay','0','','Enable XSL stylesheet control over details page display on OPAC WARNING: MARC21 Only','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 (MARC21)','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 exemple : ../koha-tmpl/opac-tmpl/prog/en/xslt/MARC21slim2OPACDetail.xsl','Textarea');
+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 exemple : ../koha-tmpl/opac-tmpl/prog/en/xslt/MARC21slim2OPACResults.xsl','Textarea');
 INSERT INTO `systempreferences` (variable,value,options,explanation,type) VALUES('AdvancedSearchTypes','itemtypes','itemtypes|ccode','Détermine quel index utiliser lors des recherches par type de document','Choice');
 INSERT INTO `systempreferences` (variable,value,options,explanation,type) VALUES('AllowOnShelfHolds', '0', '', 'Permet la réservation d''exemplaires non disponibles', 'YesNo');
 INSERT INTO `systempreferences` (variable,value,options,explanation,type) VALUES('AllowHoldsOnDamagedItems', '1', '', 'Permet les réservations sur des exemplaires endommagés', 'YesNo');
index c3247ed..4df69dc 100644 (file)
@@ -705,6 +705,15 @@ if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
     SetVersion ($DBversion);
 }
 
+$DBversion = "3.00.06.003";
+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' 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' where variable='XSLTResultsDisplay' AND value=1;");
+    print "Upgrade to $DBversion done (Improve XSLT)\n";
+    SetVersion ($DBversion);
+}
+
+
 =item DropAllForeignKeys($table)
 
   Drop all foreign keys of the table $table
index fa25945..e8ea8e7 100644 (file)
@@ -10,7 +10,7 @@
 use strict;
 
 sub kohaversion {
-    our $VERSION = '3.00.05.003';
+    our $VERSION = '3.00.06.003';
     # version needs to be set this way
     # so that it can be picked up by Makefile.PL
     # during install
index 7febfa0..817c203 100755 (executable)
@@ -70,7 +70,7 @@ $template->param( biblionumber => $biblionumber );
 # XSLT processing of some stuff
 if (C4::Context->preference("XSLTDetailsDisplay") ) {
     $template->param(
-        'XSLTBloc' => XSLTParse4Display($biblionumber, $record, 'Detail') );
+        'XSLTBloc' => XSLTParse4Display($biblionumber, $record, C4::Context->preference("XSLTDetailsDisplay")) );
 }
 
 # change back when ive fixed request.pl