Bug 8733: Add IDreamBooks.com enhanced content
authorJared Camins-Esakov <jcamins@cpbibliography.com>
Mon, 24 Sep 2012 11:47:11 +0000 (07:47 -0400)
committerJared Camins-Esakov <jcamins@cpbibliography.com>
Mon, 4 Feb 2013 13:01:19 +0000 (08:01 -0500)
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 <nengard@bywatersolutions.com>
all tests pass.

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Jared Camins-Esakov <jcamins@cpbibliography.com>
Rebased to latest master 2012-12-31

Signed-off-by: Jonathan Druart <jonathan.druart@biblibre.com>
Signed-off-by: Jared Camins-Esakov <jcamins@cpbibliography.com>
installer/data/mysql/sysprefs.sql
installer/data/mysql/updatedatabase.pl
koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/enhanced_content.pref
koha-tmpl/opac-tmpl/ccsr/en/css/opac.css
koha-tmpl/opac-tmpl/prog/en/css/opac.css
koha-tmpl/opac-tmpl/prog/en/modules/opac-detail.tt
koha-tmpl/opac-tmpl/prog/en/modules/opac-results.tt
opac/opac-detail.pl
opac/opac-search.pl

index 7e9f43d..9032bfa 100644 (file)
@@ -408,3 +408,6 @@ INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('
 INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('NotesBlacklist','','List of notes fields that should not appear in the title notes/description separator of details',NULL,'free');
 INSERT INTO systempreferences (variable,value,options,explanation,type) VALUES ('SCOUserCSS', '', NULL, 'Add CSS to be included in the SCO module in an embedded <style> tag.', 'free');
 INSERT INTO systempreferences (variable,value,options,explanation,type) VALUES ('SCOUserJS', '', NULL, 'Define custom javascript for inclusion in the SCO module', 'free');
+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');
index 5571d1e..c8c9eee 100755 (executable)
@@ -6390,6 +6390,16 @@ if ( CheckVersion($DBversion) ) {
    SetVersion ($DBversion);
 }
 
+$DBversion ="3.11.00.XXX";
+if ( CheckVersion($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);
+}
+
+
 =head1 FUNCTIONS
 
 =head2 TableExists($table)
index 655ae34..74e6553 100644 (file)
@@ -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 <a href='http://idreambooks.com/'>IDreamBooks.com</a>.
+        -
+            - pref: IDreamBooksReadometer
+              choices:
+                  yes: Add
+                  no: "Don't add"
+            - a "Readometer" that summarizes the reviews gathered by <a href='http://idreambooks.com/'>IDreamBooks.com</a> to the OPAC details page.
+        -
+            - pref: IDreamBooksResults
+              choices:
+                  yes: Add
+                  no: "Don't add"
+            - the rating from <a href='http://idreambooks.com/'>IDreamBooks.com</a> to OPAC search results.
     OCLC:
         -
             - pref: XISBN
index 3fc9d5b..90a838f 100644 (file)
@@ -2681,3 +2681,53 @@ body#opac-main #opacmainuserblockmobile {
 .tagweight9 {
     font-size: 30px;
 }
+
+.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;
+}
index 37eb1c9..cdf7a4d 100644 (file)
@@ -2840,3 +2840,53 @@ body#opac-main #opacmainuserblockmobile {
 video {
     width: 480px;
 }
+
+.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;
+}
index 8998cc1..d5f4988 100644 (file)
@@ -181,8 +181,61 @@ $(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('<a href="'+json.book.detail_link+'" id="idreambooksreadometer"><img src="http://idreambooks.com/remotereadometer/'+isbn+'.jpg" alt="'+json.book.title+' by '+json.book.author+'" title="Rating based on reviews of '+json.book.title+'"></a>');
+[% 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("<span class='idreambookssummary results_summary'><a href='"+json.book.detail_link+"'><img src='"+json.book.to_read_or_not_small+"' alt='"+json.book.title+" by "+json.book.author+"' title='Rating based on reviews of "+json.book.title+"'>"+json.book.rating+"%</a> <a href='http://www.idreambooks.com/'>rating based on reviews at iDreamBooks.com</a></span>");
+
+        //insert data into Book reviews tab
+        $.each(json.book.critic_reviews, function(){
+                $("#idb_review_snippets").append("<div class='review'><div><a href='"+this.review_link+"'>"+this.source+"</a></div><div>\"..."+this.snippet+"...\"</div><div>Review date: "+this.review_date+"</div><div><a class='reviewlink' href='"+json.book.detail_link+"'>Review result: "+this.pos_or_neg+" <img src='"+this.smiley_or_sad_small+"' alt='iDreamBooks.com rating' title='"+this.pos_or_neg+"' /></a></div></div>");
+                });
+        $("#seemoreidb").attr('href', json.book.detail_link);
+        $("#tab_idb_critic_reviews").show();
+[% END %]
+
+    }
+
+}
+[% END %]
 
 [% IF ( OpacBrowseResults && busc ) %]
 var timeoutRFW;
@@ -725,6 +778,9 @@ YAHOO.util.Event.onContentReady("furtherm", function () {
     <li id="tab_html5media"><a href="#html5media">Play media</a></li>
 [% END %][% END %]
 
+[% IF ( IDreamBooksReviews ) %]
+    <li id='tab_idb_critic_reviews' style="display:none;"><a href='#idb_critic_reviews'>Book reviews by critics ( XXX )</a></li>
+[% END %]
 </ul>
 
 [% IF ( serialcollection ) %]
@@ -1084,6 +1140,14 @@ YAHOO.util.Event.onContentReady("furtherm", function () {
 </div>
 [% END %]
 
+[% IF ( IDreamBooksReviews ) %]
+    <div id="idb_critic_reviews">
+        <div id="idb_review_snippets">
+        </div>
+        <span><a id="seemoreidb">More book reviews at iDreamBooks.com</a></span>
+    </div>
+[% END %]
+
 
 </div>
 [% IF ( NovelistSelectProfile ) %][% IF ( NovelistSelectView == 'below' ) %]
@@ -1103,6 +1167,7 @@ YAHOO.util.Event.onContentReady("furtherm", function () {
     <div id="BW_videos"></div>
 [% END %]
 
+
 </div>
 
 
index bd7d04d..30682c4 100644 (file)
@@ -109,6 +109,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("<img src='"+json.book.to_read_or_not_small+"' alt='"+json.book.title+" by "+json.book.author+"' title='Rating based on reviews of "+json.book.title+"'>"+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("<img src='"+json.book.to_read_or_not_small+"' alt='"+json.book.title+" by "+json.book.author+"' title='Rating based on reviews of "+json.book.title+"'>"+json.book.rating+"%");
+                        $(element).show();
+                    } else {
+                        $(element).remove();
+                    }
+                });
+            }
+        });
+    [% END %]
+
     [% IF ( opacbookbag ) %]$(".addtocart").show();[% END %]
 
 [% IF ( opacbookbag ) %]
@@ -650,6 +683,14 @@ $(document).ready(function(){
         [% IF OpenLibraryCovers %][% IF SEARCH_RESULT.normalized_isbn %]<span style="block" title="[% SEARCH_RESULT.biblionumber %]" class="[% SEARCH_RESULT.normalized_isbn %]" id="openlibrary-thumbnail[% loop.count %]"></span>[% ELSE %]<span class="no-image">No cover image available</span>[% END %][% END %]
                 </a>
                 [% IF ( BakerTaylorEnabled ) %][% IF ( SEARCH_RESULT.normalized_isbn ) %]<a href="https://[% BakerTaylorBookstoreURL |html %][% SEARCH_RESULT.normalized_isbn %]"><img alt="See Baker &amp; Taylor" src="[% BakerTaylorImageURL |html %][% SEARCH_RESULT.normalized_isbn %]" /></a>[% ELSE %]<span class="no-image">No cover image available</span>[% END %][% END %]
+                [% IF ( IDreamBooksResults ) %][% IF ( SEARCH_RESULT.normalized_isbn ) %]<div class="idbresult" style="display: none;">
+                    [% IF ( IDreamBooksReviews ) %]
+                        <a href="/cgi-bin/koha/opac-detail.pl?biblionumber=[% SEARCH_RESULT.biblionumber %]#idb_critic_reviews">
+                    [% ELSE %]
+                        <a href="/cgi-bin/koha/opac-detail.pl?biblionumber=[% SEARCH_RESULT.biblionumber %]">
+                    [% END %]
+                    [% SEARCH_RESULT.normalized_isbn %]</a></div>
+                [% END %][% END %]
                 </td>
                 </tr>
                 [% END %]
index 8970090..94edb35 100755 (executable)
@@ -998,6 +998,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');
 }
index 9708176..97a7bc4 100755 (executable)
@@ -833,6 +833,9 @@ if (C4::Context->preference('GoogleIndicTransliteration')) {
 }
 
 $template->{VARS}->{DidYouMean} = C4::Context->preference('OPACdidyoumean') =~ m/enable/;
+$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;