Plugin Directory

Changeset 748098


Ignore:
Timestamp:
07/30/2013 01:59:04 AM (13 years ago)
Author:
mglaman
Message:

Updating development branch: added caching, along with workaround to fix thumbnail resolution

Location:
facebook-albums/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • facebook-albums/trunk/fbalbum.php

    r737404 r748098  
    44Plugin URI: http://glamanate.com/wordpress/facebook-album/?utm_source=fbalbum_pluginspage&utm_medium=website&utm_campaign=fbalbum
    55Description: Facebook Albums allows you to display Facebook Albums on your WordPress site. Brought to you by <a href="http://dooleyandassociates.com/?utm_source=fbalbum&utm_medium=referral&utm_campaign=Facebook%2BAlbum">Dooley & Associates</a>
    6 Version: 2.0.3
     6Version: 2.0.2
    77Author: Matt Glaman
    88Author URI: http://glamanate.com
     
    130130                return 'Facebook API came back with a faulty result. You may be accessing an album you do not have permissions to access.';                     
    131131            self::_enqueue_resources();
    132            
     132
    133133            $html = '<div class="facebook-album-container">';
    134134            if(self::$options['title']) $html .= '<h2><a href="' . self::_clean_url(self::_get_album_url()) . '" target="_blank"">' . $fb['name'] . '</a></h2>';
     
    140140            foreach ($fb['photos']['data'] as $img) {
    141141                $photo_title = (isset(self::$options['photo_title'])) ? $img['name'] : '';
     142                //Quick workaround to fix thumbnail resolution without causing issues on current saved data.
     143                $thumb_size = self::$options['size'] - 1;
    142144               
    143145                $html .= '<div class="facebook-album-wrapper" style="float: left;margin: 2px;">';
    144146                $html   .= '<a href="'. self::_clean_url($img['source']) . '" title="'. $photo_title .'" rel="lightbox" class="fbalbum cboxElement">';
    145                 $html   .= '<div class="image size-'. self::$options['size'] .'" style="background-image: url(' . self::_clean_url($img['images'][self::$options['size']]['source']) . ')">&nbsp;</div>';
     147                $html   .= '<div class="image size-'. self::$options['size'] .'" style="background-image: url(' . self::_clean_url($img['images'][$thumb_size]['source']) . ')">&nbsp;</div>';
    146148                $html   .= '</a>';
    147149                $html .= '</div>';
     
    197199                'secret' => self::$options['app_secret'],
    198200            ));
    199             if(!empty(self::$options['access_token'])) {
     201            if(self::$facebook_sdk->getUser()) {
     202                try{
     203
     204                }
     205                catch (FacebookApiException $e) {
     206                    echo "<!--DEBUG: ".$e." :END-->";
     207                    error_log($e);
     208                }
     209            }
     210           
     211            if(!empty(self::$options['access_token']))
    200212                self::$facebook_sdk->setAccessToken(self::$options['access_token']);
    201213                self::$facebook_sdk->setExtendedAccessToken();
    202214                self::$options['access_token'] = FB_Album::$facebook_sdk->getAccessToken();
    203215                update_option('facebookalbum', self::$options);
    204             }
    205216        }
    206217       
     
    215226     */
    216227    public static function _get_graph_results($limit) {
    217             if(!empty(self::$facebook_sdk)) {
    218                 try {
    219                     $api_call = '/'.self::_get_album_id()."?fields=id,name,photos.limit({$limit}).fields(source,link,images,name)";
    220                     $album = self::$facebook_sdk->api($api_call);
    221                   } catch (FacebookApiException $e) {
    222                     error_log($e);
    223                     $album = null;
    224                   }
     228       
     229        if(self::get_api_cache())
     230            return self::get_api_cache();
     231        if(!empty(self::$facebook_sdk)) {
     232            try {
     233                $api_call = '/'.self::_get_album_id()."?fields=id,name,photos.limit({$limit}).fields(source,link,images,name)";
     234                $album = self::$facebook_sdk->api($api_call);
     235                //We're good to go, let's cache the JSON
     236                self::set_api_cache($album);
     237            } catch (FacebookApiException $e) {
     238                error_log($e);
     239                 $album = null;
     240            }
    225241                return $album;
    226242            } else {
    227243                //Just in case the user did not set API access through a Facebook application
    228244                $facebook_graph_url = str_replace(array('{ALBUM_ID}', '{LIMIT}'), array(self::_get_album_id(), $limit), self::$graph_url);
     245                //We're good to go, let's cache the JSON
     246                self::set_api_cache($album);
    229247                return self::decap_do_curl($facebook_graph_url);               
    230248            }
     
    291309        self::_set_album_id( $facebook_album_id );
    292310    }
     311
     312    /**
     313     * Sets WordPress transient to cache API response
     314     */
     315    protected function set_api_cache($json) {
     316        //Just in case
     317        if(!self::$album_id)
     318            return;
     319        $cahce_lifetime = (isset(self::$options['cache'])) ? self::$options['cache'] * DAY_IN_SECONDS : DAY_IN_SECONDS;
     320
     321        set_transient("fbalbum_".self::$album_id, $json, DAY_IN_SECONDS); //caching for 24 hours
     322    }
     323
     324    /**
     325     * Gets WordPress transient of cached JSON response
     326     **/
     327    protected function get_api_cache() {
     328        return get_transient("fbalbum_".self::$album_id);
     329    }
    293330   
    294331    /**
  • facebook-albums/trunk/inc/options-facebookalbum.php

    r737404 r748098  
    4949                            <option value="3" <?php selected($options['size'], 3) ?>>Bigger</option>
    5050                            <option value="2" <?php selected($options['size'], 2) ?>>Large</option>
     51                        </select>
     52                    </p>
     53                    <p><label for="fbalbum_cache">Cache Lifetime (Days)</label>:
     54                        <select name="facebookalbum[cache]" id="fbalbum_cache" value="" class="regular-text">
     55                            <option value="1" <?php selected($options['cache'], 1) ?>>1 day</option>
     56                            <option value="2" <?php selected($options['cache'], 2) ?>>2 days</option>
     57                            <option value="3" <?php selected($options['cache'], 3) ?>>3 days</option>
     58                            <option value="4" <?php selected($options['cache'], 4) ?>>4 days</option>
     59                            <option value="5" <?php selected($options['cache'], 5) ?>>5 days</option>
     60                            <option value="6" <?php selected($options['cache'], 6) ?>>6 days</option>
     61                            <option value="7" <?php selected($options['cache'], 7) ?>>7 days</option>
    5162                        </select>
    5263                    </p>
  • facebook-albums/trunk/readme.txt

    r737404 r748098  
    55Requires at least: 3.4
    66Tested up to: 3.5.1
    7 Stable tag: 2.0.3
     7Stable tag: 2.0.2
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    1818Through Settings -> Facebook Album you can adjust the thumbnail sizes of your album's photos when they are displayed, along with enabling or disabling the album's title or the photo's description display.
    1919
     20This plugin comes bundled with Colorbox, which can be disabled. Certain colorbox options are configurable, more will be soon. Priority was integrating Facebook app's.
     21
    2022= Please consult developer if having issues integrating plugin with Facebook App for personal photo album use! =
    21 
    22 This plugin comes bundled with Colorbox, which can be disabled. Certain colorbox options are configurable, more will be soon. Priority was integrating Facebook app's.
    2323
    2424= Shortcode Example: =
     
    5151
    5252== Changelog ==
     53
     54= 2.0.3 =
     55* Add WordPress transients to cache Facebook response to increase performance
     56* Adjusted thumbnail resolution
    5357
    5458= 2.0.1/2.0.2 =
Note: See TracChangeset for help on using the changeset viewer.