From c113bde0615e82accb3c5569735d24bb7f287a6f Mon Sep 17 00:00:00 2001 From: Jared Camins-Esakov Date: Mon, 24 Sep 2012 07:47:11 -0400 Subject: [PATCH] [SIGNED-OFF] Bug 8733: Add IDreamBooks.com enhanced content Adds the following enhanced content to the OPAC, all controlled by separate sysprefs: 1) A "Readometer" which summarizes reviews on the OPAC detail page 2) A tab with snippets of critical reviews on the OPAC detail page 3) A computed rating on the results page To test: Find a book that is listed on IDreamBooks.com (you may have to make sure that you have the first edition), and one that is not. Try each of IDreamBooksReadometer, IDreamBooksReviews, and IDreamBooksResults sysprefs, taking note of the content appearing (or not) as appropriate. Updated to add missing CSS to new theme. Signed-off-by: Nicole C. Engard all tests pass. --- installer/data/mysql/sysprefs.sql | 3 + installer/data/mysql/updatedatabase.pl | 8 +++ .../admin/preferences/enhanced_content.pref | 19 ++++++ koha-tmpl/opac-tmpl/ccsr/en/css/opac.css | 50 +++++++++++++++ koha-tmpl/opac-tmpl/prog/en/css/opac.css | 50 +++++++++++++++ koha-tmpl/opac-tmpl/prog/en/modules/opac-detail.tt | 65 ++++++++++++++++++++ .../opac-tmpl/prog/en/modules/opac-results.tt | 41 ++++++++++++ opac/opac-detail.pl | 4 + opac/opac-search.pl | 3 + 9 files changed, 243 insertions(+), 0 deletions(-) diff --git a/installer/data/mysql/sysprefs.sql b/installer/data/mysql/sysprefs.sql index ef2538c..0c78238 100644 --- a/installer/data/mysql/sysprefs.sql +++ b/installer/data/mysql/sysprefs.sql @@ -383,3 +383,6 @@ INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES(' INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('OpacShowLibrariesPulldownMobile','1','Show the libraries pulldown on the mobile version of the OPAC.',NULL,'YesNo'); INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('OpacShowFiltersPulldownMobile','1','Show the search filters pulldown on the mobile version of the OPAC.',NULL,'YesNo'); INSERT IGNORE INTO systempreferences (variable,value,explanation,options,type) VALUES('AuthDisplayHierarchy','0','Display authority hierarchies','','YesNo'); +INSERT IGNORE INTO systempreferences (variable,value,explanation,options,type) VALUES('IDreamBooksReviews','0','Display book review snippets from IDreamBooks.com','','YesNo'); +INSERT IGNORE INTO systempreferences (variable,value,explanation,options,type) VALUES('IDreamBooksReadometer','0','Display Readometer from IDreamBooks.com','','YesNo'); +INSERT IGNORE INTO systempreferences (variable,value,explanation,options,type) VALUES('IDreamBooksResults','0','Display IDreamBooks.com rating in search results','','YesNo'); diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index eb45fb2..92cc959 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -5973,6 +5973,14 @@ if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) { SetVersion($DBversion); } +$DBversion ="3.09.00.XXX"; +if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) { + $dbh->do("INSERT IGNORE INTO systempreferences (variable,value,explanation,options,type) VALUES('IDreamBooksReviews','0','Display book review snippets from IDreamBooks.com','','YesNo');"); + $dbh->do("INSERT IGNORE INTO systempreferences (variable,value,explanation,options,type) VALUES('IDreamBooksReadometer','0','Display Readometer from IDreamBooks.com','','YesNo');"); + $dbh->do("INSERT IGNORE INTO systempreferences (variable,value,explanation,options,type) VALUES('IDreamBooksResults','0','Display IDreamBooks.com rating in search results','','YesNo');"); + print "Upgrade to $DBversion done (Add IDreamBooks enhanced content)\n"; + SetVersion($DBversion); +} $DBversion = "3.09.00.057"; if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) { diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/enhanced_content.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/enhanced_content.pref index d1f2814..239f351 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/enhanced_content.pref +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/enhanced_content.pref @@ -141,6 +141,25 @@ Enhanced Content: choices: yes: in tabs. no: in line with the bibliographic information. + IDreamLibraries: + - + - pref: IDreamBooksReviews + choices: + yes: Add + no: "Don't add" + - a tab on the OPAC details with book reviews from critics aggregated by IDreamBooks.com. + - + - pref: IDreamBooksReadometer + choices: + yes: Add + no: "Don't add" + - a "Readometer" that summarizes the reviews gathered by IDreamBooks.com to the OPAC details page. + - + - pref: IDreamBooksResults + choices: + yes: Add + no: "Don't add" + - the rating from IDreamBooks.com to OPAC search results. OCLC: - - pref: XISBN diff --git a/koha-tmpl/opac-tmpl/ccsr/en/css/opac.css b/koha-tmpl/opac-tmpl/ccsr/en/css/opac.css index cdf6441..aa2f8fb 100644 --- a/koha-tmpl/opac-tmpl/ccsr/en/css/opac.css +++ b/koha-tmpl/opac-tmpl/ccsr/en/css/opac.css @@ -2637,3 +2637,53 @@ body#opac-main #opacmainuserblockmobile { .mobile_only { display : none; } + +.review { + margin-bottom: 20px; +} + +#idreambooksreadometer { + float: right; +} +a.idreambooksrating { + font-size: 30px; + color: #29ADE4; + padding-left: 85px; + line-height: 30px; + text-decoration: none; +} + +.idreambookslegend { + font-size: small; +} + +a.reviewlink,a.reviewlink:visited { + text-decoration: none; + color: black; + font-weight: normal; +} + +.idreambookssummary a { + color: #707070; + text-decoration: none; +} + +.idreambookssummary img, .idbresult img { + vertical-align: middle; +} + +.idbresult { + color: #29ADE4; + text-align: center; + margin: 0.5em; + padding: 0.5em; +} + +.idbresult a, .idbresult a:visited { + text-decoration: none; + color: #29ADE4; +} + +.idbresult img { + padding-right: 6px; +} diff --git a/koha-tmpl/opac-tmpl/prog/en/css/opac.css b/koha-tmpl/opac-tmpl/prog/en/css/opac.css index 8610573..fb0cdf4 100644 --- a/koha-tmpl/opac-tmpl/prog/en/css/opac.css +++ b/koha-tmpl/opac-tmpl/prog/en/css/opac.css @@ -2767,3 +2767,53 @@ body#opac-main #opacmainuserblockmobile { .mobile_only { display : none; } + +.review { + margin-bottom: 20px; +} + +#idreambooksreadometer { + float: right; +} +a.idreambooksrating { + font-size: 30px; + color: #29ADE4; + padding-left: 85px; + line-height: 30px; + text-decoration: none; +} + +.idreambookslegend { + font-size: small; +} + +a.reviewlink,a.reviewlink:visited { + text-decoration: none; + color: black; + font-weight: normal; +} + +.idreambookssummary a { + color: #707070; + text-decoration: none; +} + +.idreambookssummary img, .idbresult img { + vertical-align: middle; +} + +.idbresult { + color: #29ADE4; + text-align: center; + margin: 0.5em; + padding: 0.5em; +} + +.idbresult a, .idbresult a:visited { + text-decoration: none; + color: #29ADE4; +} + +.idbresult img { + padding-right: 6px; +} diff --git a/koha-tmpl/opac-tmpl/prog/en/modules/opac-detail.tt b/koha-tmpl/opac-tmpl/prog/en/modules/opac-detail.tt index f740488..54cfa84 100644 --- a/koha-tmpl/opac-tmpl/prog/en/modules/opac-detail.tt +++ b/koha-tmpl/opac-tmpl/prog/en/modules/opac-detail.tt @@ -160,7 +160,60 @@ $(function () { }); // ----------------------------------------------------- [% END %] +[% IF ( IDreamBooksReviews || IDreamBooksReadometer ) %] + var isbn = $(".isbn:last").text().split(" ")[1]; + if (isbn) { + isbn = isbn.replace(/\W*$/, ''); + + if ($.browser.msie && parseInt($.browser.version, 10) >= 8 && window.XDomainRequest) { + // Use Microsoft XDR for IE version 8 or above + var xdr = new XDomainRequest(); + xdr.open("get", "http://idreambooks.com/newbooks/api.json?q="+encodeURIComponent(isbn)+"&key=8bf66516232d1b72f3e47df939653e1e"); + xdr.onload = function() { + json = 'json = '+xdr.responseText; // the string now looks like.. json = { ... }; + eval(json); // json is now a regular JSON object + parseIDBJSON(json); // parse using same function as for jQuery's success event + } + xdr.send(); + } else { + $.getJSON("http://idreambooks.com/newbooks/api.json?q="+encodeURIComponent(isbn)+"&key=8bf66516232d1b72f3e47df939653e1e", function(json){ + parseIDBJSON(json); + }); + } + } + +[% END %] }); +[% IF ( IDreamBooksReviews || IDreamBooksReadometer ) %] +function parseIDBJSON( json ) { + if(json.total_results > 0 && json.book.rating > 0){ + var isbn = $(".isbn:last").text().split(" ")[1]; + +[% IF ( IDreamBooksReadometer ) %] + $(".title").append(''+json.book.title+' by '+json.book.author+''); +[% END %] + + +[% IF ( IDreamBooksReviews ) %] + //build new tab for critic reviews + $("#tab_idb_critic_reviews a").text($("#tab_idb_critic_reviews a").text().replace('XXX', json.book.review_count)); + + //append happy-sad cloud review + + $("#catalogue_detail_biblio").append(""+json.book.title+" by "+json.book.author+""+json.book.rating+"% rating based on reviews at iDreamBooks.com"); + + //insert data into Book reviews tab + $.each(json.book.critic_reviews, function(){ + $("#idb_review_snippets").append("
"+this.source+"
\"..."+this.snippet+"...\"
Review date: "+this.review_date+"
Review result: "+this.pos_or_neg+" iDreamBooks.com rating
"); + }); + $("#seemoreidb").attr('href', json.book.detail_link); + $("#tab_idb_critic_reviews").show(); +[% END %] + + } + +} +[% END %] [% IF ( OpacBrowseResults && busc ) %] var timeoutRFW; @@ -708,6 +761,9 @@ YAHOO.util.Event.onContentReady("furtherm", function () { [% IF ( OPACLocalCoverImages ) %][% IF ( localimages ) %]
  • Images
  • [% END %][% END %] +[% IF ( IDreamBooksReviews ) %] + +[% END %] [% IF ( serialcollection ) %] @@ -1153,6 +1209,14 @@ YAHOO.util.Event.onContentReady("furtherm", function () { [% END %] +[% IF ( IDreamBooksReviews ) %] + +[% END %] + [% IF ( NovelistSelectProfile ) %][% IF ( NovelistSelectView == 'below' ) %] @@ -1172,6 +1236,7 @@ YAHOO.util.Event.onContentReady("furtherm", function () {
    [% END %] + diff --git a/koha-tmpl/opac-tmpl/prog/en/modules/opac-results.tt b/koha-tmpl/opac-tmpl/prog/en/modules/opac-results.tt index e5238f7..534c5aa 100644 --- a/koha-tmpl/opac-tmpl/prog/en/modules/opac-results.tt +++ b/koha-tmpl/opac-tmpl/prog/en/modules/opac-results.tt @@ -103,6 +103,39 @@ $(document).ready(function(){ }); [% END %] + [% IF ( IDreamBooksResults ) %] + $('.idbresult').each(function() { + var isbn = $(this).children('a').text().replace(/\s*/,''); + var element = this; + + if ($.browser.msie && parseInt($.browser.version, 10) >= 8 && window.XDomainRequest) { + // Use Microsoft XDR for IE version 8 or above + var xdr = new XDomainRequest(); + xdr.open("get", "http://idreambooks.com/newbooks/api.json?q="+encodeURIComponent(isbn)+"&key=8bf66516232d1b72f3e47df939653e1e"); + xdr.onload = function() { + json = 'json = '+xdr.responseText; // the string now looks like.. json = { ... }; + eval(json); // json is now a regular JSON object + if(json.total_results > 0 && json.book.rating > 0){ + $(element).children('a').html(""+json.book.title+" by "+json.book.author+""+json.book.rating+"%"); + $(element).show(); + } else { + $(element).remove(); + } + } + xdr.send(); + } else { + $.getJSON("http://idreambooks.com/newbooks/api.json?q="+encodeURIComponent(isbn)+"&key=8bf66516232d1b72f3e47df939653e1e", function(json){ + if(json.total_results > 0 && json.book.rating > 0){ + $(element).children('a').html(""+json.book.title+" by "+json.book.author+""+json.book.rating+"%"); + $(element).show(); + } else { + $(element).remove(); + } + }); + } + }); + [% END %] + [% IF ( opacbookbag ) %]$(".addtocart").show();[% END %] [% IF ( opacbookbag ) %] @@ -643,6 +676,14 @@ $(document).ready(function(){ [% IF OpenLibraryCovers %][% IF SEARCH_RESULT.normalized_isbn %][% ELSE %]No cover image available[% END %][% END %] [% IF ( BakerTaylorEnabled ) %][% IF ( SEARCH_RESULT.normalized_isbn ) %]See Baker & Taylor[% ELSE %]No cover image available[% END %][% END %] + [% IF ( IDreamBooksResults ) %][% IF ( SEARCH_RESULT.normalized_isbn ) %] + [% END %][% END %] [% END %] diff --git a/opac/opac-detail.pl b/opac/opac-detail.pl index cdb4a5a..a5609f3 100755 --- a/opac/opac-detail.pl +++ b/opac/opac-detail.pl @@ -970,6 +970,10 @@ if (C4::Context->preference('OPACLocalCoverImages') == 1) { $template->{VARS}->{localimages} = \@images; } +$template->{VARS}->{IDreamBooksReviews} = C4::Context->preference('IDreamBooksReviews'); +$template->{VARS}->{IDreamBooksReadometer} = C4::Context->preference('IDreamBooksReadometer'); +$template->{VARS}->{IDreamBooksResults} = C4::Context->preference('IDreamBooksResults'); + if (C4::Context->preference('OpacHighlightedWords')) { $template->{VARS}->{query_desc} = $query->param('query_desc'); } diff --git a/opac/opac-search.pl b/opac/opac-search.pl index 9aac79d..6379e0d 100755 --- a/opac/opac-search.pl +++ b/opac/opac-search.pl @@ -824,6 +824,9 @@ if (C4::Context->preference('GoogleIndicTransliteration')) { } $template->{VARS}->{DidYouMeanFromAuthorities} = C4::Context->preference('DidYouMeanFromAuthorities'); +$template->{VARS}->{IDreamBooksReviews} = C4::Context->preference('IDreamBooksReviews'); +$template->{VARS}->{IDreamBooksReadometer} = C4::Context->preference('IDreamBooksReadometer'); +$template->{VARS}->{IDreamBooksResults} = C4::Context->preference('IDreamBooksResults'); $template->param( borrowernumber => $borrowernumber); output_with_http_headers $cgi, $cookie, $template->output, $content_type; -- 1.7.2.3