patch against Evergreen to grab data from bucket to feed a carousel
[equinox-eg-opac-skin.git] / carousel / custom_carousel.patch
1 diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm
2 index 6aa1f58..08074e1 100644
3 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm
4 +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm
5 @@ -15,6 +15,7 @@ use OpenILS::Utils::Fieldmapper;
6  use DateTime::Format::ISO8601;
7  use CGI qw(:all -utf8);
8  use Time::HiRes;
9 +use Net::HTTP::NB;
10  
11  # EGCatLoader sub-modules 
12  use OpenILS::WWW::EGCatLoader::Util;
13 @@ -128,7 +129,7 @@ sub load {
14      (undef, $self->ctx->{mylist}) = $self->fetch_mylist unless
15          $path =~ /opac\/my(opac\/lists|list)/;
16  
17 -    return $self->load_simple("home") if $path =~ m|opac/home|;
18 +    return $self->load_home("home") if $path =~ m|opac/home|;
19      return $self->load_simple("css") if $path =~ m|opac/css|;
20      return $self->load_simple("advanced") if
21          $path =~ m:opac/(advanced|numeric|expert):;
22 @@ -250,6 +251,42 @@ sub load_simple {
23      return Apache2::Const::OK;
24  }
25  
26 +sub load_home {
27 +    my ($self, $page) = @_;
28 +    $self->ctx->{page} = $page;
29 +    $self->ctx->{search_ou} = $self->_get_search_lib();
30 +
31 +    my $req = Net::HTTP::NB->new(
32 +        Host => '127.0.0.1', Timeout => 1, PeerPort => 80);
33 +    if (!$req) {
34 +        $logger->warn("Unable to connect look up bookbag");
35 +    } else {
36 +        $req->host($self->apache->hostname);
37 +        $req->write_request(GET => "/opac/extras/feed/bookbag/marcxml/12");
38 +        my $sel = IO::Select->new($req);
39 +        if ($sel->can_read(3)) {
40 +            my ($code) = $req->read_response_headers;
41 +
42 +            my $content = '';
43 +            if ($code eq '200') {
44 +                while (1) {
45 +                    my $buf;
46 +                    my $n = $req->read_entity_body($buf, 1024);
47 +                    last unless $n;
48 +                    $content .= $buf;
49 +                }
50 +                $self->ctx->{carousel} = [];
51 +                while ($content =~ m!(<record xmlns.*?</record>)!gs) {
52 +                    push @{ $self->ctx->{carousel} }, (new XML::LibXML)->parse_string($1);
53 +                }
54 +            }
55 +        }
56 +        $req->shutdown(2);
57 +    }
58 +
59 +    return Apache2::Const::OK;
60 +}
61 +
62  # -----------------------------------------------------------------------------
63  # Tests to see if the user is authenticated and sets some common context values
64  # -----------------------------------------------------------------------------