Plugin Directory

Changeset 1303201


Ignore:
Timestamp:
12/08/2015 07:31:38 PM (10 years ago)
Author:
eroux
Message:

Improved cache handling

Location:
currently-reading/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • currently-reading/trunk/CurrentlyReading.php

    r1157833 r1303201  
    55    Description: Display a Currently Reading widget using the Google Books API
    66    Author: Eugéne Roux
    7     Version: 4.0.3
     7    Version: 4.0.4
    88    Author URI: http://damn.org.za/
    99 */
     
    5858                #print("\n\t<!-- Cache file is " . $cache . "... -->\n");
    5959
    60                 if ( file_exists( $cache ) and time() - filectime( $cache ) < $cachedays * 24 * 60 * 60 ) {
     60                if ( file_exists( $cache ) and time() - filectime( $cache ) < $cachedays * 24 * 60 * 60 and filesize( $cache ) > 50 ) {
    6161                    $bookdata = file_get_contents( $cache );
    6262                    $isbnjson = json_decode( $bookdata, true );
    6363                    print("\n\t<!-- Cache file read... -->\n");
    6464                } elseif (( $bookdata = file_get_contents( "https://www.googleapis.com/books/v1/volumes?q=isbn:" . $myisbn ))) {
    65                     print("\n\t<!-- Google Books API call successful... Write cache file. -->\n");
    66                     if ( !file_put_contents( $cache, $bookdata )) {
    67                         print("\n\t<!-- Cache file is not writable... This will end in tears. -->\n");
     65                    $isbnjson = json_decode( $bookdata, true );
     66                    if ( $isbnjson[ "totalItems" ] > 0 ) {
     67                        print("\n\t<!-- Google Books API call successful... Write cache file. -->\n");
     68                        if ( !file_put_contents( $cache, $bookdata )) {
     69                            print("\n\t<!-- Cache file is not writable... This will end in tears. -->\n");
     70                        }
     71                    } else {
     72                        print("\n\t<!-- Google Books API call to 'https://www.googleapis.com/books/v1/volumes?q=isbn:" . $myisbn . "' failed... -->\n");
    6873                    }
    69                     $isbnjson = json_decode( $bookdata, true );
    7074                } else {
    7175                    $booksapi = false;
  • currently-reading/trunk/readme.txt

    r1157836 r1303201  
    33Tags: books, read, reading, admin, administration, jadb
    44Requires at least: 3
    5 Tested up to: 4.2.2
     5Tested up to: 4.3
    66Stable tag: trunk
    77
     
    1515* Pad the Image (selected by default, uses internal CSS)
    1616* Display a Box-Shadow (selected by default, uses internal CSS)
    17 * Choose Alternate Google Country (defaults to "South Africa" since books.google.com seems to give a "500" error and South Africa seems to work just fine for US clients as well)
     17* Choose Alternate Google Country (defaults to "Worldwide")
    1818
    1919as well as
     
    4949== Frequently Asked Questions ==
    5050
    51 **I Get a '*Warning: file_get_contents ... : failed to open stream: HTTP request failed! HTTP/1.0 403 Forbidden*' Error on My Blog With No Books Displayed. Why Is This Happening?**
     51**I get a '*Warning: file_get_contents ... : failed to open stream: HTTP request failed! HTTP/1.0 403 Forbidden*' Error in my logs and no books are displayed. Why is this happening?**
    5252
    53 Your web-site has been configure not to allow outgoing HTTP requests and you have 'Use Google API' enabled or Google rejected your connection.
     53Your web-site has been configure not to allow outgoing HTTP requests and you have 'Use Google API' enabled.
    5454
    55 If the automated fail-back failed, please de-select the 'Use Google API' option to use the direct connection instead nd report this as a bug.
     55Please de-select the 'Use Google API' option to use the direct connection instead.
    5656
    57 **I Get a '*No Google Books Entry Found for ISBN:NUMBER*' on My Blog... Why?**
     57**I get a '*No Google Books Entry Found for ISBN:NUMBER*' on my Blog... Why?**
    5858
    5959Sometimes Google Books does not return any valid responses on ISBNs. Try the following:
     
    63633. Find the eBook on Google's Books Web Page and use its ISBN
    6464
    65 **I Get an *Image Not Available* Image on My Blog Instead of the Book Cover, and Clicking It Gives Me a Google 404 Error**
    66 
    67 You will only see this if you are *not* using the Google Books API or, if you are, it failed back to the previous system for some reason.
    68 
    69 Double-check the ISBN you used; it's either wrong or Google does not have an entry for the book referenced.
    70 
    71 **Are You Planning to Insert Other Sources Than Google Books to the Currently Reading Widget?**
     65**Are you planing to insert other sources than Google Books to the Currently Reading widget?**
    7266
    7367I'll have a look into supporting Amazon, though they do make you jump through hoops to use their API (which is the reason I settled on using Google Books to start with).
    7468
    75 **Is There a Way to Get This Plug-In to Do a Library of All of Your Books Into WordPress?**
     69**Is there a way to get this plugin to do a library of all of your books into WordPress?**
    7670
    77 It's not currently possible with this plug-in, no.
     71It's not currently possible with this plugin, no.
    7872
    7973I'll give it a bit of thought and see if I can extend it to do that; but it will most likely need the creation of an alternate plugin to do that.
     
    9185== Changelog ==
    9286
    93 = 4.0.3 =
     87= 4.0.4 =
    9488
    95 * Allow the centring of the Book Cover within the sidebar (Props Andy Tegala for the suggestion)
    96 * Cache Google Books API call (if successful) for (default) 30 days
    97 * (Semi-)Gently fall back to previous behaviour if Google Books API call fails
     89* Check cache before using it
     90* Check data validity before writing cache
    9891
    9992= 4.0.2 =
    10093
    101 * Allow *not* using the Google Books API in preference to the older -- direct -- connection
     94* Allow (and default to) *not* using the Google Books API in preference to the older -- direct -- connection
    10295* Since I'm probably the only Saffer using this, default to "books.google.com"
    10396
Note: See TracChangeset for help on using the changeset viewer.