* @copyright Copyright 2009 Dan Coulter * @license http://www.gnu.org/licenses/gpl.txt GPL 2.0 * @version 1.2.7 * @link http://co.deme.me/projects/flickr-gallery/ */ if ( !defined('WP_CONTENT_URL') ) define( 'WP_CONTENT_URL', get_option('siteurl') . '/wp-content'); if ( !defined('WP_CONTENT_DIR') ) define( 'WP_CONTENT_DIR', ABSPATH . 'wp-content' ); if ( defined('CODEMEME_TEST') ) { define('CM_FLICKR_GALLERY_VERSION', rand()); } else { define('CM_FLICKR_GALLERY_VERSION', '1.2.7'); } class DC_FlickrGallery { /** * Return the filesystem path that the plugin lives in. * * @return string */ function getPath() { return dirname(__FILE__) . '/'; } /** * Returns the URL of the plugin's folder. * * @return string */ function getURL() { return WP_CONTENT_URL.'/plugins/'.basename(dirname(__FILE__)) . '/'; } function get_major_version() { global $wp_version; return (float) $wp_version; } /** * Initializes the phpFlickr object. Called on WP's init hook. * */ function init() { load_plugin_textdomain('flickr-gallery', 'wp-content/plugins/' . basename(dirname(__FILE__)) . '/i18n'); if ( get_option('fg-API-key') ) { global $phpFlickr; include_once dirname(__FILE__) . '/phpFlickr.php'; $phpFlickr = new phpFlickr(get_option('fg-API-key'), get_option('fg-secret') ? get_option('fg-secret') : null); if ( get_option('fg-token') ) { $phpFlickr->setToken(get_option('fg-token')); } if ( function_exists('curl_init') ) { $phpFlickr->custom_post = array('DC_FlickrGallery', 'curl_post'); } elseif ( class_exists('WP_Http') ) { $phpFlickr->custom_post = array('DC_FlickrGallery', 'wp_http_post'); } if ( get_option('fg-db-cache') == 1 ) { $phpFlickr->enableCache('custom', array(array('DC_FlickrGallery', 'cache_get'), array('DC_FlickrGallery', 'cache_set'))); } wp_enqueue_script('jquery-ui-tabs'); wp_enqueue_script('jquery-flightbox', DC_FlickrGallery::getURL() . 'flightbox/jquery.flightbox.js', array(), CM_FLICKR_GALLERY_VERSION); wp_enqueue_style('flickr-gallery', DC_FlickrGallery::getURL() . 'flickr-gallery.css', array(), CM_FLICKR_GALLERY_VERSION); if ( DC_FlickrGallery::get_major_version() >= 2.8 ) { wp_enqueue_style('fg-jquery-ui', DC_FlickrGallery::getURL() . 'tab-theme/jquery-ui-1.7.1.css', array(), '1.7.1'); } else { wp_enqueue_style('fg-jquery-ui', DC_FlickrGallery::getURL() . 'tab-theme/jquery-ui-1.5.2.css', array(), '1.5.2'); } wp_enqueue_style('jquery-flightbox', DC_FlickrGallery::getURL() . 'flightbox/jquery.flightbox.css', array(), CM_FLICKR_GALLERY_VERSION); } if ( $_GET['action'] == 'flickr-gallery-photoset' ) { DC_FlickrGallery::ajax_photoset($_GET['id'], $_GET['page']); } elseif ( $_POST['action'] == 'flickr-gallery-page' ) { DC_FlickrGallery::ajax_pagination(); } if ( is_admin() && $_GET['page'] == 'flickr-gallery/flickr-gallery.php' ) { wp_enqueue_script('jquery-form'); } if ( !is_admin() && (get_option('fg-flightbox') === false || get_option('fg-flightbox')) ) { add_action('wp_footer', array('DC_FlickrGallery', 'footer')); } } function wp_http_post($url, $data) { $http = new WP_Http(); $response = $http->post($url, array('body' => $data)); return $response['body']; } function curl_post($url, $data) { $ch = curl_init($url); curl_setopt($ch, CURLOPT_HEADER, 0); @curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); $result = curl_exec($ch); curl_close($ch); return $result; } function cache_get($key) { global $wpdb; $result = $wpdb->get_row(' SELECT * FROM `' . $wpdb->prefix . 'phpflickr_cache` WHERE request = "' . $wpdb->escape($key) . '" AND expiration >= NOW() '); if ( is_null($result) ) return false; return $result->response; } function cache_set($key, $value, $expire) { global $wpdb; $query = ' INSERT INTO `' . $wpdb->prefix . 'phpflickr_cache` ( request, response, expiration ) VALUES ( "' . $wpdb->escape($key) . '", "' . $wpdb->escape($value) . '", FROM_UNIXTIME(' . (time() + (int) $expire) . ') ) ON DUPLICATE KEY UPDATE response = VALUES(response), expiration = VALUES(expiration) '; $wpdb->query($query); } /** * Handles the [flickr-gallery] shortcode * * @param array $attr * @param string $content * @return string */ function gallery($attr, $content = '') { if ( get_option('fg-API-key') ) { $mv = DC_FlickrGallery::get_major_version() >= 2.8; $id = substr(md5(microtime()), 0, 8); global $phpFlickr; $attr = array_merge(array( 'pagination' => 1, 'photoset' => null, 'sort' => null, 'tags' => null, 'mode' => null, 'tag_mode' => 'any', 'user_id' => (isset($attr['mode']) && $attr['mode'] == 'search') ? null : get_option('fg-user_id'), 'per_page' => get_option('fg-per_page'), ), (is_array($attr) ? $attr : array())); $per_page = $attr['per_page']; if ( strpos($attr['extras'], 'media') === false ) $attr['extras'] .= ',media'; ob_start(); switch ($attr['mode']) { case 'photoset' : $url = DC_FlickrGallery::get_photo_url($photos['owner']); $pager = new phpFlickr_pager($phpFlickr, 'flickr.photosets.getPhotos', array( 'photoset_id' => $attr['photoset'], 'extras' => $attr['extras'], ), $attr['per_page']); break; case 'tag' : $url = DC_FlickrGallery::get_photo_url($attr['user_id']); $pager = new phpFlickr_pager($phpFlickr, "flickr.photos.search", array( 'user_id' => $attr['user_id'], 'tags' => $attr['tags'], 'sort' => $attr['sort'], 'tag_mode' => $attr['tag_mode'], 'extras' => $attr['extras'], ), $attr['per_page']); break; case 'recent' : $args = $attr; unset($args['mode']); $url = DC_FlickrGallery::get_photo_url($attr['user_id']); $pager = new phpFlickr_pager($phpFlickr, "flickr.photos.search", $args, $attr['per_page']); break; case 'interesting' : $args = $attr; unset($args['mode']); $args['sort'] = "interestingness-desc"; $pager = new phpFlickr_pager($phpFlickr, "flickr.photos.search", $args, $attr['per_page']); break; case 'search' : $args = $attr; unset($args['mode']); $pager = new phpFlickr_pager($phpFlickr, "flickr.photos.search", $args, $attr['per_page']); break; default : if ( !empty($attr['user_id']) ) { $url = DC_FlickrGallery::get_photo_url($attr['user_id']); $tabs = apply_filters('flickr_gallery_tabs', array( array('id'=>'photostream', 'name'=>'Photostream'), array('id'=>'sets', 'name'=>'Photosets'), array('id'=>'interesting', 'name'=>'Most Interesting'), )); $tab_count = 0; ?>
If you like this plugin, please consider donating a couple of dollars.