View | Details | Raw Unified | Return to bug 10320
Collapse All | Expand All

(-)a/C4/External/OverDrive.pm (+141 lines)
Line 0 Link Here
1
package C4::External::OverDrive;
2
3
# Copyright (c) 2013 ByWater
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 2 of the License, or ( at your option )  any later
10
# version.
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
use strict;
21
use warnings;
22
23
use JSON;
24
use Koha::Cache;
25
use HTTP::Request;
26
use HTTP::Request::Common;
27
use LWP::Authen::Basic;
28
use LWP::UserAgent;
29
30
BEGIN {
31
    require Exporter;
32
    our $VERSION = 3.07.00.049;
33
    our @ISA = qw( Exporter ) ;
34
    our @EXPORT = qw(
35
        IsOverDriveEnabled
36
        GetOverDriveToken
37
    );
38
}
39
40
sub _request {
41
    my ( $request ) = @_;
42
    my $ua = LWP::UserAgent->new( "Koha " . C4::Context->KOHAVERSION );
43
44
    my $response;
45
    eval {
46
        $response = $ua->request( $request ) ;
47
    };
48
    if ( $@ )  {
49
        warn "OverDrive request failed: $@";
50
        return;
51
    }
52
53
    return $response;
54
}
55
56
=head1 NAME
57
58
C4::External::OverDrive - Retrieve OverDrive content availability information
59
60
=head2 FUNCTIONS
61
62
This module provides content search for OverDrive,
63
64
=over
65
66
=item IsOverDriveEnabled
67
68
Returns 1 if all of the necessary system preferences for OverDrive are set.
69
70
=back
71
72
=cut
73
74
sub IsOverDriveEnabled {
75
    return (
76
        C4::Context->preference( 'OverDriveClientKey' ) &&
77
        C4::Context->preference( 'OverDriveClientSecret' )
78
    );
79
}
80
81
=item GetOverDriveToken
82
83
Fetches an OAuth2 auth token for the OverDrive API, reusing an existing token in
84
Memcache if possible.
85
86
Returns the token ( as "bearer ..." )  or undef on failure. 
87
88
=back
89
90
=cut
91
92
sub GetOverDriveToken {
93
    my $key = C4::Context->preference( 'OverDriveClientKey' );
94
    my $secret = C4::Context->preference( 'OverDriveClientSecret' );
95
96
    return unless ( $key && $secret ) ;
97
98
    my $cache;
99
100
    eval { $cache = Koha::Cache->new() };
101
102
    my $token;
103
    $cache and $token = $cache->get_from_cache( "overdrive_token" ) and return $token;
104
105
    my $request = HTTP::Request::Common::POST( 'https://oauth.overdrive.com/token', [
106
        grant_type => 'client_credentials'
107
    ] ) ;
108
    $request->header( Authorization => LWP::Authen::Basic->auth_header( $key, $secret ) );
109
110
    my $response = _request( $request ) or return;
111
    if ( $response->header('Content-Type') !~ m!application/json! ) {
112
        warn "Could not connect to OverDrive: " . $response->message;
113
        return;
114
    }
115
    my $contents = from_json( $response->decoded_content );
116
117
    if ( !$response->is_success ) {
118
        warn "Could not log into OverDrive: " . ( $contents ? $contents->{'error_description'} : $response->decoded_content );
119
        return;
120
    }
121
122
    $token = $contents->{'token_type'} . ' ' . $contents->{'access_token'};
123
124
    # Fudge factor to prevent spurious failures
125
    $cache->set_in_cache( 'overdrive_token', $token, $contents->{'expires_in'} - 5 );
126
127
    return $token;
128
}
129
130
1;
131
__END__
132
133
=head1 NOTES
134
135
=cut
136
137
=head1 AUTHOR
138
139
Jesse Weaver <pianohacker@gmail.com>
140
141
=cut
(-)a/installer/data/mysql/updatedatabase.pl (+15 lines)
Lines 6991-6996 if ( CheckVersion($DBversion) ) { Link Here
6991
}
6991
}
6992
6992
6993
6993
6994
$DBversion = "3.13.00.XXX";
6995
if(CheckVersion($DBversion)) {
6996
    $dbh->do(
6997
"INSERT IGNORE INTO systempreferences (variable,value,explanation,options,type) VALUES('OverDriveClientKey','','Client key for OverDrive integration','30','Free')"
6998
    );
6999
    $dbh->do(
7000
"INSERT IGNORE INTO systempreferences (variable,value,explanation,options,type) VALUES('OverDriveClientSecret','','Client key for OverDrive integration','30','YesNo')"
7001
    );
7002
    $dbh->do(
7003
"INSERT IGNORE INTO systempreferences (variable,value,explanation,options,type) VALUES('OpacDriveLibraryID','','Library ID for OverDrive integration','','Integer')"
7004
    );
7005
    print "Upgrade to $DBversion done (Bug 10320 - Show results from library's OverDrive collection in OPAC search)\n";
7006
    SetVersion($DBversion);
7007
}
7008
6994
=head1 FUNCTIONS
7009
=head1 FUNCTIONS
6995
7010
6996
=head2 TableExists($table)
7011
=head2 TableExists($table)
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/enhanced_content.pref (+11 lines)
Lines 326-328 Enhanced Content: Link Here
326
                  yes: Enable
326
                  yes: Enable
327
                  no: "Don't enable"
327
                  no: "Don't enable"
328
            - the ability to use Koha Plugins. Note, the plugin system must also be enabled in the Koha configuration file to be fully enabled.
328
            - the ability to use Koha Plugins. Note, the plugin system must also be enabled in the Koha configuration file to be fully enabled.
329
    OverDrive:
330
        -
331
            - Include OverDrive availability information with the client key 
332
            - pref: OverDriveClientKey
333
            - and client secret
334
            - pref: OverDriveClientSecret
335
            - .
336
        -
337
            - "Show items from the OverDrive catalog of library #"
338
            - pref: OverDriveLibraryID
339
            - .
(-)a/koha-tmpl/opac-tmpl/ccsr/en/js/overdrive.js (+61 lines)
Line 0 Link Here
1
if ( typeof KOHA == "undefined" || !KOHA ) {
2
    var KOHA = {};
3
}
4
5
KOHA.OverDrive = ( function() {
6
    var proxy_base_url = '/cgi-bin/koha/svc/overdrive_proxy';
7
    var library_base_url = 'http://api.overdrive.com/v1/libraries/';
8
    return {
9
        Get: function( url, params, callback ) {
10
            $.ajax( {
11
                type: 'GET',
12
                url: url.replace( /https?:\/\/api.overdrive.com\/v1/, proxy_base_url ),
13
                dataType: 'json',
14
                data: params,
15
                error: function( xhr, error ) {
16
                    try {
17
                        callback( JSON.parse( xhr.responseText ));
18
                    } catch ( e ) {
19
                        callback( {error: xhr.responseText || true} );
20
                    }
21
                },
22
                success: callback
23
            } );
24
        },
25
        GetCollectionURL: function( library_id, callback ) {
26
            if ( KOHA.OverDrive.collection_url ) {
27
                callback( KOHA.OverDrive.collection_url );
28
                return;
29
            }
30
31
            KOHA.OverDrive.Get(
32
                library_base_url + library_id,
33
                {},
34
                function ( data ) {
35
                    if ( data.error ) {
36
                        callback( data );
37
                        return;
38
                    }
39
40
                    KOHA.OverDrive.collection_url = data.links.products.href;
41
42
                    callback( data.links.products.href );
43
                }
44
            );
45
        },
46
        Search: function( library_id, q, limit, offset, callback ) {
47
            KOHA.OverDrive.GetCollectionURL( library_id, function( data ) {
48
                if ( data.error ) {
49
                    callback( data );
50
                    return;
51
                }
52
53
                KOHA.OverDrive.Get(
54
                    data,
55
                    {q: q, limit: limit, offset: offset},
56
                    callback
57
                );
58
            } );
59
        }
60
    };
61
} )();
(-)a/koha-tmpl/opac-tmpl/prog/en/css/opac.css (+9 lines)
Lines 2964-2966 padding: 0.1em 0; Link Here
2964
.thumbnail-shelfbrowser span {
2964
.thumbnail-shelfbrowser span {
2965
    margin: 0px auto;
2965
    margin: 0px auto;
2966
}
2966
}
2967
2968
#overdrive-results {
2969
    font-weight: bold;
2970
    padding-left: 1em;
2971
}
2972
2973
.throbber {
2974
    vertical-align: middle;
2975
}
(-)a/koha-tmpl/opac-tmpl/prog/en/js/overdrive.js (+61 lines)
Line 0 Link Here
1
if ( typeof KOHA == "undefined" || !KOHA ) {
2
    var KOHA = {};
3
}
4
5
KOHA.OverDrive = ( function() {
6
    var proxy_base_url = '/cgi-bin/koha/svc/overdrive_proxy';
7
    var library_base_url = 'http://api.overdrive.com/v1/libraries/';
8
    return {
9
        Get: function( url, params, callback ) {
10
            $.ajax( {
11
                type: 'GET',
12
                url: url.replace( /https?:\/\/api.overdrive.com\/v1/, proxy_base_url ),
13
                dataType: 'json',
14
                data: params,
15
                error: function( xhr, error ) { 
16
                    try {
17
                        callback( JSON.parse( xhr.responseText ));
18
                    } catch ( e ) {
19
                        callback( {error: xhr.responseText || true} );
20
                    }
21
                },
22
                success: callback
23
            } );
24
        },
25
        GetCollectionURL: function( library_id, callback ) {
26
            if ( KOHA.OverDrive.collection_url ) {
27
                callback( KOHA.OverDrive.collection_url );
28
                return;
29
            }
30
31
            KOHA.OverDrive.Get(
32
                library_base_url + library_id,
33
                {},
34
                function ( data ) {
35
                    if ( data.error ) {
36
                        callback( data );
37
                        return;
38
                    }
39
40
                    KOHA.OverDrive.collection_url = data.links.products.href;
41
42
                    callback( data.links.products.href );
43
                }
44
            );
45
        },
46
        Search: function( library_id, q, limit, offset, callback ) {
47
            KOHA.OverDrive.GetCollectionURL( library_id, function( data ) {
48
                if ( data.error ) {
49
                    callback( data );
50
                    return;
51
                }
52
53
                KOHA.OverDrive.Get(
54
                    data,
55
                    {q: q, limit: limit, offset: offset},
56
                    callback
57
                );
58
            } );
59
        }
60
    };
61
} )();
(-)a/koha-tmpl/opac-tmpl/prog/en/modules/opac-overdrive-search.tt (+161 lines)
Line 0 Link Here
1
[% INCLUDE 'doc-head-open.inc' %]
2
[% IF ( LibraryNameTitle ) %][% LibraryNameTitle %][% ELSE %]Koha online[% END %] catalog &rsaquo; OverDrive search for '[% q | html %]'
3
[% INCLUDE 'doc-head-close.inc' %]
4
<script type="text/javascript" src="[% themelang %]/js/overdrive.js"></script>
5
<script type="text/javascript">
6
var querystring = "[% q |replace( "'", "\'" ) |replace( '\n', '\\n' ) |replace( '\r', '\\r' ) |html %]";
7
var results_per_page = [% OPACnumSearchResults %];
8
9
function fetch_availability( prod, $tr ) {
10
    var $availability_summary = $( '<span class="results_summary"></span>' );
11
    $tr.find( '.info' ).append( $availability_summary );
12
    $availability_summary.html( '<span class="label">Availability: </span> Loading...' );
13
14
    KOHA.OverDrive.Get(
15
        prod.links.availability.href,
16
        {},
17
        function ( data ) {
18
            if ( data.error ) return;
19
20
            $availability_summary.html( '<span class="label">Copies available: </span><span class="available"><strong>' +  data.copiesAvailable + '</strong> out of ' + data.copiesOwned + '</span>' );
21
22
            if ( data.numberOfHolds ) {
23
                $availability_summary.find( '.available' ).append( ', waiting holds: <strong>' + data.numberOfHolds + '</strong>' );
24
            }
25
26
            $tr.find( '.info' ).append( '<span class="results_summary actions"><span class="label">Actions: </span><a href="http://' + prod.contentDetails[0].href + '" ' + ( data.copiesAvailable ? ' class="addtocart">Check out' : ' class="hold">Place hold' ) + '</a></span>' );
27
        }
28
    );
29
}
30
31
function search( offset ) {
32
    $( '#overdrive-status' ).html( 'Searching OverDrive... <img class="throbber" src="/opac-tmpl/lib/jquery/plugins/themes/classic/throbber.gif" /></span>' );
33
34
    KOHA.OverDrive.Search( "[% OverDriveLibraryID %]", querystring, results_per_page, offset, function( data ) {
35
        if ( data.error ) {
36
            $( '#overdrive-status' ).html( '<strong class="unavailable">Error searching OverDrive collection.</strong>' );
37
            return;
38
        }
39
40
        if ( !data.totalItems ) {
41
            $( '#overdrive-status' ).html( '<strong>No results found in the library\'s OverDrive collection.</strong>' );
42
            return;
43
        }
44
45
        $( '#results tbody' ).empty();
46
47
        $( '#overdrive-status' ).html( '<strong>Found ' + data.totalItems + ' results in the library\'s OverDrive collection.</strong>' );
48
49
        for ( var i = 0; data.products[i]; i++ ) {
50
            var prod = data.products[i];
51
            var results = [];
52
53
            results.push( '<tr>' );
54
55
            results.push( '<td class="info"><a class="title" href="http://', prod.contentDetails[0].href, '">' );
56
            results.push( prod.title );
57
            if ( prod.subtitle ) results.push( ', ', prod.subtitle );
58
            results.push( '</a>' );
59
            results.push( '<p>by ', prod.primaryCreator.name, '</p>' );
60
            results.push( '<span class="results_summary"><span class="label">Type: </span>', prod.mediaType, '</span>' );
61
            if ( prod.starRating ) results.push( '<span class="results_summary"><span class="label">Average rating: <img src="[% themelang %]/../images/Star', Math.round( parseInt( prod.starRating )), '.gif" title="" style="max-height: 15px; vertical-align: bottom"/></span>' );
62
            results.push( '</td>' );
63
64
            results.push( '<td>' );
65
            if ( prod.images.thumbnail ) {
66
                results.push( '<a href="http://', prod.contentDetails[0].href, '">' );
67
                results.push( '<img class="thumbnail" src="', prod.images.thumbnail.href, '" />' );
68
                results.push( '</a>' );
69
            }
70
            results.push( '</td>' );
71
72
            results.push( '</tr>' );
73
            var $tr = $( results.join( '' ));
74
            $( '#results tbody' ).append( $tr );
75
76
            fetch_availability( prod, $tr );
77
        }
78
79
        $( '#results tr:odd' ).addClass( 'highlight' );
80
81
        var pages = [];
82
        var cur_page = offset / results_per_page;
83
        var max_page = Math.floor( data.totalItems / results_per_page );
84
85
        if ( cur_page != 0 ) {
86
            pages.push( '<a class="nav" href="#" data-offset="' + (offset - results_per_page) + '">&lt;&lt; Previous</a>' );
87
        }
88
89
        for ( var page = Math.max( 0, cur_page - 9 ); page <= Math.min( max_page, cur_page + 9 ); page++ ) {
90
            if ( page == cur_page ) {
91
                pages.push( ' <span class="current">' + ( page + 1 ) + '</span>' );
92
            } else {
93
                pages.push( ' <a class="nav" href="#" data-offset="' + ( page * results_per_page ) + '">' + ( page + 1 ) + '</a>' );
94
            }
95
        }
96
97
        if ( cur_page < max_page ) {
98
            pages.push( ' <a class="nav" href="#" data-offset="' + (offset + results_per_page) + '">Next >></a>' );
99
        }
100
101
        if ( pages.length > 1 ) $( '#top-pages, #bottom-pages' ).find( '.pages' ).html( pages.join( '' ) );
102
    } );
103
}
104
105
$( document ).ready( function() {
106
    $( '#breadcrumbs p' )
107
        .append( ' ' )
108
        .append( '<span id="overdrive-status"></span>' );
109
110
    $( document ).on( 'click', 'a.nav', function() {
111
        search( $( this ).data( 'offset' ) );
112
        return false;
113
    });
114
115
    search( 0 );
116
} );
117
</script>
118
<style>
119
.actions a.addtocart {
120
    display: inline;
121
}
122
</style>
123
</head>
124
<body>
125
[% IF ( OpacNav ) %]
126
<div id="doc3" class="yui-t1">
127
[% ELSE %]
128
<div id="doc3" class="yui-t7">
129
[% END %]
130
   <div id="bd">
131
[% INCLUDE 'masthead.inc' %]
132
133
	<h1>OverDrive search for '[% q | html %]'</h1>
134
    <div id="breadcrumbs">
135
        <p></p>
136
    </div>
137
138
	<div id="yui-main"><div class="yui-b searchresults">
139
        <div id="top-pages">
140
            <div class="pages">
141
            </div>
142
        </div>
143
        <table id="results">
144
            <tbody>
145
            </tbody>
146
        </table>
147
        <div id="bottom-pages">
148
            <div class="pages">
149
            </div>
150
        </div>
151
     </div></div>
152
153
[% IF ( OpacNav ) %]
154
<div class="yui-b"><div id="opacnav" class="container">
155
[% INCLUDE 'navigation.inc' %]
156
</div></div>
157
[% END %]
158
159
160
</div>
161
[% INCLUDE 'opac-bottom.inc' %]
(-)a/koha-tmpl/opac-tmpl/prog/en/modules/opac-results.tt (-2 / +26 lines)
Lines 13-18 Link Here
13
[% IF ( OpacStarRatings == 'all' ) %]<script type="text/javascript" src="[% themelang %]/lib/jquery/plugins/jquery.rating.js"></script>
13
[% IF ( OpacStarRatings == 'all' ) %]<script type="text/javascript" src="[% themelang %]/lib/jquery/plugins/jquery.rating.js"></script>
14
<link rel="stylesheet" type="text/css" href="[% themelang %]/css/jquery.rating.css" />[% END %]
14
<link rel="stylesheet" type="text/css" href="[% themelang %]/css/jquery.rating.css" />[% END %]
15
15
16
<script type="text/javascript" src="[% themelang %]/js/overdrive.js"></script>
16
<script type="text/javascript" src="[% themelang %]/lib/jquery/plugins/jquery.checkboxes.min.js"></script>
17
<script type="text/javascript" src="[% themelang %]/lib/jquery/plugins/jquery.checkboxes.min.js"></script>
17
[% IF ( OpacHighlightedWords ) %]<script type="text/javascript" src="[% themelang %]/lib/jquery/plugins/jquery.highlight-3.js"></script>
18
[% IF ( OpacHighlightedWords ) %]<script type="text/javascript" src="[% themelang %]/lib/jquery/plugins/jquery.highlight-3.js"></script>
18
[% END %]<script type="text/javascript">
19
[% END %]<script type="text/javascript">
Lines 247-253 $(document).ready(function(){ Link Here
247
[% END %]
248
[% END %]
248
    $("#holdDetails").hide();
249
    $("#holdDetails").hide();
249
250
250
[% IF ( query_desc ) %][% IF ( OpacHighlightedWords ) %]var query_desc = "[% query_desc |replace("'", "\'") |replace('\n', '\\n') |replace('\r', '\\r') |html %]";
251
[% IF ( query_desc ) %]
252
    var query_desc = "[% query_desc |replace("'", "\'") |replace('\n', '\\n') |replace('\r', '\\r') |html %]";
253
    var querystring = "[% querystring |replace("'", "\'") |replace('\n', '\\n') |replace('\r', '\\r') |html %]";
254
    [% IF ( OpacHighlightedWords ) %]
251
        q_array = query_desc.split(" ");
255
        q_array = query_desc.split(" ");
252
        // ensure that we don't have "" at the end of the array, which can
256
        // ensure that we don't have "" at the end of the array, which can
253
        // break the highlighter
257
        // break the highlighter
Lines 256-262 $(document).ready(function(){ Link Here
256
        }
260
        }
257
        highlightOn();
261
        highlightOn();
258
        $("#highlight_toggle_on" ).hide().click(function() {highlightOn() ;});
262
        $("#highlight_toggle_on" ).hide().click(function() {highlightOn() ;});
259
        $("#highlight_toggle_off").show().click(function() {highlightOff();});[% END %][% END %]
263
        $("#highlight_toggle_off").show().click(function() {highlightOff();});
264
    [% END %]
265
    [% IF ( OverDriveEnabled ) %]
266
        var $overdrive_results = $( '<span id="overdrive-results">Searching OverDrive... <img class="throbber" src="/opac-tmpl/lib/jquery/plugins/themes/classic/throbber.gif" /></span>' );
267
        $( '#breadcrumbs p' ).eq(0)
268
            .append( ' ' )
269
            .append( $overdrive_results );
270
        KOHA.OverDrive.Search( "[% OverDriveLibraryID %]", querystring, 1, 0, function( data ) {
271
            if ( data.error ) {
272
                $overdrive_results.html( 'Error searching OverDrive collection' );
273
                return;
274
            }
275
276
            if ( data.totalItems ) {
277
                $overdrive_results.html( 'Found <a href="/cgi-bin/koha/opac-overdrive-search.pl?q=' + escape( querystring ) + '">' + data.totalItems + ' results</a> in OverDrive collection' );
278
            } else {
279
                $overdrive_results.remove();
280
            }
281
        } );
282
    [% END %]
283
[% END %]
260
284
261
[% IF ( TagsInputEnabled && loggedinusername ) %]
285
[% IF ( TagsInputEnabled && loggedinusername ) %]
262
            $("#tagsel_tag").click(function(){
286
            $("#tagsel_tag").click(function(){
(-)a/opac/opac-overdrive-search.pl (+47 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
# Copyright 2009 BibLibre SARL
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 2 of the License, or (at your option) any later
10
# version.
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
use strict;
21
use warnings;
22
23
use CGI;
24
25
use C4::Auth qw(:DEFAULT get_session);
26
use C4::Output;
27
28
my $cgi = new CGI;
29
30
# Getting the template and auth
31
my ($template, $loggedinuser, $cookie)
32
= get_template_and_user({template_name => "opac-overdrive-search.tmpl",
33
                                query => $cgi,
34
                                type => "opac",
35
                                authnotrequired => 1,
36
                                flagsrequired => {borrowers => 1},
37
                                debug => 1,
38
                                });
39
40
$template->{'VARS'}->{'q'} = $cgi->param('q');
41
$template->{'VARS'}->{'limit'} = C4::Context->preference('OPACnumSearchResults') || 20;
42
$template->{'VARS'}->{'OPACnumSearchResults'} = C4::Context->preference('OPACnumSearchResults') || 20;
43
$template->{'VARS'}->{'OverDriveLibraryID'} = C4::Context->preference('OverDriveLibraryID');
44
45
output_html_with_http_headers $cgi, $cookie, $template->output;
46
47
(-)a/opac/opac-search.pl (+6 lines)
Lines 51-56 use C4::Tags qw(get_tags); Link Here
51
use C4::Branch; # GetBranches
51
use C4::Branch; # GetBranches
52
use C4::SocialData;
52
use C4::SocialData;
53
use C4::Ratings;
53
use C4::Ratings;
54
use C4::External::OverDrive;
54
55
55
use POSIX qw(ceil floor strftime);
56
use POSIX qw(ceil floor strftime);
56
use URI::Escape;
57
use URI::Escape;
Lines 899-903 $template->{VARS}->{IDreamBooksReviews} = C4::Context->preference('IDreamBooksRe Link Here
899
$template->{VARS}->{IDreamBooksReadometer} = C4::Context->preference('IDreamBooksReadometer');
900
$template->{VARS}->{IDreamBooksReadometer} = C4::Context->preference('IDreamBooksReadometer');
900
$template->{VARS}->{IDreamBooksResults} = C4::Context->preference('IDreamBooksResults');
901
$template->{VARS}->{IDreamBooksResults} = C4::Context->preference('IDreamBooksResults');
901
902
903
if ($offset == 0 && IsOverDriveEnabled()) {
904
    $template->param(OverDriveEnabled => 1);
905
    $template->param(OverDriveLibraryID => C4::Context->preference('OverDriveLibraryID'));
906
}
907
902
    $template->param( borrowernumber    => $borrowernumber);
908
    $template->param( borrowernumber    => $borrowernumber);
903
output_with_http_headers $cgi, $cookie, $template->output, $content_type;
909
output_with_http_headers $cgi, $cookie, $template->output, $content_type;
(-)a/opac/svc/overdrive_proxy (-1 / +83 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
# Copyright 2013 ByWater
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 2 of the License, or (at your option) any later
10
# version.
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
=head1 NAME
21
22
svc/overdrive_proxy: Proxy OAuth'd requests to OverDrive
23
24
=head1 SYNOPSIS
25
26
svc/overdrive_proxy/libraries/9001 -> https://api.overdrive.com/v1/libraries/9001
27
28
=head1 DESCRIPTION
29
30
This service proxies incoming requests to the OverDrive OAuth API, to keep the
31
JS side from having to deal with cross-origin/authentication issues.
32
33
=cut
34
35
use strict;
36
use warnings;
37
38
use CGI qw(-oldstyle_urls);
39
use JSON;
40
41
use C4::Context;
42
use C4::External::OverDrive;
43
use C4::Output;
44
45
my $query = new CGI;
46
47
my $token;
48
49
if ( !IsOverDriveEnabled() || !( $token = GetOverDriveToken() ) ) {
50
    print $query->header(
51
        -status => '400 Bad Request',
52
        -content
53
    );
54
55
    print to_json({
56
        error => 'invalid_client',
57
        error_description => 'OverDrive login failed'
58
    });
59
60
    exit;
61
}
62
63
my $request = HTTP::Request::Common::GET( "https://api.overdrive.com/v1" . $query->path_info . '?' . $query->query_string );
64
$request->header( Authorization => $token );
65
66
my $ua = LWP::UserAgent->new( "Koha " . C4::Context->KOHAVERSION );
67
68
my $response = $ua->request( $request ) ;
69
if ( $response->code eq '500' ) {
70
    print $query->header(
71
        -status => '500 Internal Server Error'
72
    );
73
74
    warn "OverDrive request failed: " . $response->message;
75
    print to_json({
76
        error => 'invalid_client',
77
        error_description => 'OverDrive request failed'
78
    });
79
80
    exit;
81
}
82
83
output_with_http_headers $query, undef, $response->content, 'json', $response->status_line;

Return to bug 10320