From 11bd4a7660e65c936001d15c0cf9316a96587fe9 Mon Sep 17 00:00:00 2001 From: Joshua Ferraro Date: Sun, 8 Feb 2009 12:59:21 -0600 Subject: [PATCH] Adds Syndetics Reviews Signed-off-by: Galen Charlton --- C4/Auth.pm | 1 + C4/External/Syndetics.pm | 116 ++++++++++++++++-- admin/systempreferences.pl | 1 + installer/data/mysql/updatedatabase.pl | 2 + .../prog/en/modules/opac-detail.tmpl | 23 ++++ opac/opac-detail.pl | 16 ++- 6 files changed, 145 insertions(+), 14 deletions(-) diff --git a/C4/Auth.pm b/C4/Auth.pm index b0330c4447..cfb65b1f5f 100644 --- a/C4/Auth.pm +++ b/C4/Auth.pm @@ -276,6 +276,7 @@ sub get_template_and_user { SyndeticsSummary => C4::Context->preference("SyndeticsSummary"), SyndeticsEditions => C4::Context->preference("SyndeticsEditions"), SyndeticsExcerpt => C4::Context->preference("SyndeticsExcerpt"), + SyndeticsReviews => C4::Context->preference("SyndeticsReviews"), ); if ( $in->{'type'} eq "intranet" ) { diff --git a/C4/External/Syndetics.pm b/C4/External/Syndetics.pm index f10fa3b2eb..b9f480bdeb 100644 --- a/C4/External/Syndetics.pm +++ b/C4/External/Syndetics.pm @@ -36,6 +36,7 @@ BEGIN { &get_syndetics_toc &get_syndetics_editions &get_syndetics_excerpt + &get_syndetics_reviews ); } @@ -69,11 +70,19 @@ sub get_syndetics_summary { my $syndetics_client_code = C4::Context->preference('SyndeticsClientCode'); my $url = "http://syndetics.com/index.aspx?isbn=$isbn/SUMMARY.XML&client=$syndetics_client_code&type=xw10"; - # warn $url; - my $content = get($url); + my $ua = LWP::UserAgent->new; + $ua->timeout(10); + $ua->env_proxy; + my $response = $ua->get($url); + unless ($response->content_type =~ /xml/) { + return; + } + + my $content = $response->content; + warn "could not retrieve $url" unless $content; my $xmlsimple = XML::Simple->new(); - my $response = $xmlsimple->XMLin( + $response = $xmlsimple->XMLin( $content, forcearray => [ qw(Fld520) ], ) unless !$content; @@ -93,11 +102,19 @@ sub get_syndetics_toc { my $syndetics_client_code = C4::Context->preference('SyndeticsClientCode'); my $url = "http://syndetics.com/index.aspx?isbn=$isbn/TOC.XML&client=$syndetics_client_code&type=xw10"; - #warn $url; - my $content = get($url); + my $ua = LWP::UserAgent->new; + $ua->timeout(10); + $ua->env_proxy; + + my $response = $ua->get($url); + unless ($response->content_type =~ /xml/) { + return; + } + + my $content = $response->content; warn "could not retrieve $url" unless $content; my $xmlsimple = XML::Simple->new(); - my $response = $xmlsimple->XMLin( + $response = $xmlsimple->XMLin( $content, forcearray => [ qw(Fld970) ], ) unless !$content; @@ -117,11 +134,18 @@ sub get_syndetics_excerpt { my $syndetics_client_code = C4::Context->preference('SyndeticsClientCode'); my $url = "http://syndetics.com/index.aspx?isbn=$isbn/DBCHAPTER.XML&client=$syndetics_client_code&type=xw10"; - #warn $url; - my $content = get($url); + my $ua = LWP::UserAgent->new; + $ua->timeout(10); + $ua->env_proxy; + my $response = $ua->get($url); + unless ($response->content_type =~ /xml/) { + return; + } + + my $content = $response->content; warn "could not retrieve $url" unless $content; my $xmlsimple = XML::Simple->new(); - my $response = $xmlsimple->XMLin( + $response = $xmlsimple->XMLin( $content, forcearray => [ qw(Fld520) ], ) unless !$content; @@ -131,6 +155,65 @@ sub get_syndetics_excerpt { return XMLout($excerpt) if $excerpt; } +sub get_syndetics_reviews { + my ( $isbn ) = @_; + + #normalize the ISBN + $isbn = _normalize_match_point ($isbn); + + # grab the AWSAccessKeyId: mine is '0V5RRRRJZ3HR2RQFNHR2' + my $syndetics_client_code = C4::Context->preference('SyndeticsClientCode'); + my @reviews; + my $review_sources = [ + {title => 'Library Journal Review', file => 'LJREVIEW.XML'}, + {title => 'Publishers Weekly Review', file => 'PWREVIEW.XML'}, + {title => 'School Library Journal Review', file => 'SLJREVIEW.XML'}, + {title => 'CHOICE Review', file => 'CHREVIEW.XML'}, + {title => 'Booklist Review', file => 'BLREVIEW.XML'}, + {title => 'Horn Book Review', file => 'HBREVIEW.XML'}, + {title => 'Kirkus Book Review', file => 'KIRKREVIEW.XML'}, + {title => 'Criticas Review', file => 'CRITICASREVIEW.XML'} + ]; + + for my $source (@$review_sources) { + my $url = "http://syndetics.com/index.aspx?isbn=$isbn/$source->{file}&client=$syndetics_client_code&type=xw10"; + + my $ua = LWP::UserAgent->new; + $ua->timeout(10); + $ua->env_proxy; + + my $response = $ua->get($url); + unless ($response->content_type =~ /xml/) { + next; + } + + my $content = $response->content; + warn "could not retrieve $url" unless $content; + my $xmlsimple = XML::Simple->new(); + eval { + $response = $xmlsimple->XMLin( + $content, + forcearray => [ qw(Fld520) ], + ) unless !$content; + }; + + # This particular review deserializes differently + if ($source->{file} =~ /BLREVIEW.XML/) { + for my $subfield_a (@{$response->{VarFlds}->{VarDFlds}->{Notes}->{Fld520}}) { + my @content; + for my $content (@{$subfield_a->{a}->{content}}) { + push @content, {content => $content}; + } + push @reviews, {title => $source->{title}, reviews => \@content}; #[ {content => $content} ]}; + } + } + else { + push @reviews, {title => $source->{title}, reviews => \@{$response->{VarFlds}->{VarDFlds}->{Notes}->{Fld520}}} unless $@; + } + + } + return \@reviews; +} sub get_syndetics_editions { my ( $isbn ) = @_; @@ -142,11 +225,20 @@ sub get_syndetics_editions { my $syndetics_client_code = C4::Context->preference('SyndeticsClientCode'); my $url = "http://syndetics.com/index.aspx?isbn=$isbn/FICTION.XML&client=$syndetics_client_code&type=xw10"; - # warn $url; - my $content = get($url); + my $ua = LWP::UserAgent->new; + $ua->timeout(10); + $ua->env_proxy; + + my $response = $ua->get($url); + unless ($response->content_type =~ /xml/) { + return; + } + + my $content = $response->content; + warn "could not retrieve $url" unless $content; my $xmlsimple = XML::Simple->new(); - my $response = $xmlsimple->XMLin( + $response = $xmlsimple->XMLin( $content, forcearray => [ qw(Fld020) ], ) unless !$content; diff --git a/admin/systempreferences.pl b/admin/systempreferences.pl index 29dbcecd3b..ee546fd390 100755 --- a/admin/systempreferences.pl +++ b/admin/systempreferences.pl @@ -239,6 +239,7 @@ $tabsysprefs{SyndeticsTOC} = 'EnhancedContent'; $tabsysprefs{SyndeticsSummary} = 'EnhancedContent'; $tabsysprefs{SyndeticsEditions} = 'EnhancedContent'; $tabsysprefs{SyndeticsExcerpt} = 'EnhancedContent'; +$tabsysprefs{SyndeticsReviews} = 'EnhancedContent'; # FRBR $tabsysprefs{FRBRizeEditions} = "EnhancedContent"; diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index a1080923df..09210cd13a 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -2236,6 +2236,8 @@ if (C4::Context->preference("Version") < TransformToNum($DBversion)) { $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('SyndeticsExcerpt', '0', 'Display Excerpts and first chapters on OPAC from Syndetics','','YesNo')"); + $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('SyndeticsReviews', '0', 'Display Reviews on OPAC from Syndetics','','YesNo')"); + print "Upgrade to $DBversion done (added Syndetics Enhanced Content system preferences)\n"; SetVersion ($DBversion); } diff --git a/koha-tmpl/opac-tmpl/prog/en/modules/opac-detail.tmpl b/koha-tmpl/opac-tmpl/prog/en/modules/opac-detail.tmpl index a5ef870535..256d850932 100644 --- a/koha-tmpl/opac-tmpl/prog/en/modules/opac-detail.tmpl +++ b/koha-tmpl/opac-tmpl/prog/en/modules/opac-detail.tmpl @@ -234,6 +234,9 @@
  • #excerpt">Excerpt
  • + +
  • #reviews">Reviews
  • +
  • #subscriptions">Subscriptions
  • @@ -416,6 +419,26 @@ + +
    +
    + + + +

    + + + + + + + + + + +
    +
    +

    This is a serial subscription

    diff --git a/opac/opac-detail.pl b/opac/opac-detail.pl index afd06022b6..0964647d8e 100755 --- a/opac/opac-detail.pl +++ b/opac/opac-detail.pl @@ -33,7 +33,7 @@ use C4::Tags qw(get_tags); use C4::Dates qw/format_date/; use C4::XISBN qw(get_xisbns get_biblionumber_from_isbn get_biblio_from_xisbn); use C4::External::Amazon; -use C4::External::Syndetics qw(get_syndetics_summary get_syndetics_toc get_syndetics_excerpt ); +use C4::External::Syndetics qw(get_syndetics_summary get_syndetics_toc get_syndetics_excerpt get_syndetics_reviews ); use C4::Review; use C4::Serials; use C4::Members; @@ -296,6 +296,8 @@ if ( C4::Context->preference("SyndeticsEnabled") && C4::Context->preference("Syn my $syndetics_summary = &get_syndetics_summary($xisbn); $template->param( SYNDETICS_SUMMARY => $syndetics_summary ); }; + warn $@ if $@; + } if ( C4::Context->preference("SyndeticsEnabled") && C4::Context->preference("SyndeticsTOC") ) { @@ -303,13 +305,23 @@ if ( C4::Context->preference("SyndeticsEnabled") && C4::Context->preference("Syn my $syndetics_toc = &get_syndetics_toc($xisbn); $template->param( SYNDETICS_TOC => $syndetics_toc ); }; + warn $@ if $@; } -if ( C4::Context->preference("SyndeticsEnabled") && C4::Context->preference("SyndeticsTOC") ) { +if ( C4::Context->preference("SyndeticsEnabled") && C4::Context->preference("SyndeticsExcerpt") ) { eval { my $syndetics_excerpt = &get_syndetics_excerpt($xisbn); $template->param( SYNDETICS_EXCERPT => $syndetics_excerpt ); }; + warn $@ if $@; +} + +if ( C4::Context->preference("SyndeticsEnabled") && C4::Context->preference("SyndeticsReviews") ) { + eval { + my $syndetics_reviews = &get_syndetics_reviews($xisbn); + $template->param( SYNDETICS_REVIEWS => $syndetics_reviews ); + }; + warn $@ if $@; } # Shelf Browser Stuff