Location: PHPKode > scripts > WP-Galleriffic > wp-galleriffic/wp-galleriffic.php
<?php
/*
Plugin Name: wp-galleriffic
Version: 1.0.1
Plugin URI: http://petermolnar.eu/wordpress/wp-galleriffic
Description: Adds Galleriffic gallery to Wordpress, based on Galleriffic ( http://www.twospy.com/galleriffic/ )
Author: Peter Molnar
Author URI: http://petermolnar.eu/
License: GPL2
*/

/*  Copyright 2010-2011 Peter Molnar  (email : hide@address.com )

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License, version 2, as
    published by the Free Software Foundation.

    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., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

*/

/* upload dir of (current) WordPress site for Multisite compatibility */
$wp_upload_dir = wp_upload_dir();

/* older wordpress fix */
if ( ! defined( 'WP_PLUGIN_URL' ) )
	define( 'WP_PLUGIN_URL', get_option( 'siteurl' ) . '/wp-content/plugins' );
if ( ! defined( 'WP_PLUGIN_DIR' ) )
	define( 'WP_PLUGIN_DIR', ABSPATH . 'wp-content/plugins' );

/* wp-galleriffic constants */
define ( 'WP_GALLERIFFIC_PARAM' , 'wp-galleriffic' );
define ( 'WP_GALLERIFFIC_OPTION_GROUP' , 'wp-galleriffic-params' );
define ( 'WP_GALLERIFFIC_URL' , WP_PLUGIN_URL . '/' . WP_GALLERIFFIC_PARAM  );
define ( 'WP_GALLERIFFIC_DIR' , WP_PLUGIN_DIR . '/' . WP_GALLERIFFIC_PARAM );
define ( 'WP_GALLERIFFIC_CACHE_DIR' , $wp_upload_dir['basedir'] . '/cache' );
define ( 'WP_GALLERIFFIC_CACHE_URL' , $wp_upload_dir['baseurl'] . '/cache' );
define ( 'WP_GALLERIFFIC_THUMB' , WP_GALLERIFFIC_PARAM . '-thumb' );
define ( 'WP_GALLERIFFIC_PREVIEW' , WP_GALLERIFFIC_PARAM . '-preview' );
define ( 'WP_GALLERIFFIC_FLICKR_METHOD' , 'flickr.photosets.getPhotos' );
define ( 'WP_GALLERIFFIC_FLICKR_FORMAT' , 'php_serial' );
define ( 'WP_GALLERIFFIC_FLICKR_BASE' , 'http://farm%FARM%.static.flickr.com/%SERVER%/%ID%_%SECRET%' );

if (!class_exists('WPGalleriffic')) {

	/**
	 * main class for wp-galleriffic
	 *
	 */
	class WPGalleriffic {

		var $options = array();
		var $defaults = array();
		var $sizes = array ( 'thumb' , 'preview' );

		/**
		* galleriffic constructor
		*
		*/
		function __construct() {

			/* register options */
			$this->options = $this->get_options();
			$this->defaults = $this->get_options(true);

			/* add image sizes */
			$crop = $this->options['thumbCrop'] ? true : false;
			add_image_size( WP_GALLERIFFIC_THUMB,	$this->options['thumbSize'],	$this->options['thumbSize'] ,	$crop);
			add_image_size( WP_GALLERIFFIC_PREVIEW,	$this->options['imgSize'],		$this->options['imgSize'],		false);

			/* add scripts for non-admin pages */
			if( ! is_admin() && ! is_feed() )
			{
				wp_enqueue_script('jquery');
				wp_enqueue_script( 'jquery.history.js' , WP_GALLERIFFIC_URL . '/js/jquery.history.js' , 'jquery' , '2.0' );
				wp_enqueue_script( 'jquery.opacityrollover.js' , WP_GALLERIFFIC_URL . '/js/jquery.opacityrollover.js' , 'jquery' , '2.0' );
				wp_enqueue_script( 'jquery.galleriffic.js' , WP_GALLERIFFIC_URL . '/js/jquery.galleriffic.js' , array('jquery','jquery.opacityrollover.js','jquery.history.js') , '2.0' );

				if ($this->options['defaultCSS'])
					wp_enqueue_style( 'wp-galleriffic.default.css' , WP_GALLERIFFIC_URL . '/css/wp-galleriffic.default.css', false, '0.1');
			}
			/* add CSS only for admin */
			else
			{
				wp_enqueue_style( 'wp-galleriffic.admin.css' , WP_GALLERIFFIC_URL . '/css/wp-galleriffic.admin.css', false, '0.1');
			}

			/* check for cache dir */
			if (!is_dir ( WP_GALLERIFFIC_CACHE_DIR ) )
				wp_mkdir_p ( WP_GALLERIFFIC_CACHE_DIR );

			/* on activation */
			register_activation_hook(__FILE__ , array( $this , 'activate') );

			/* on uninstall */
			register_uninstall_hook(__FILE__ , array( $this , 'uninstall') );

			/* init plugin in the admin section */
			add_action('admin_menu', array( $this , 'admin_init') );

			/* register shortcode */
			add_shortcode( WP_GALLERIFFIC_PARAM , array( $this , 'shortcode') );

		}

		/**
		 * activation hook: save default settings in order to eliminate bugs.
		 *
		 */
		function activate ( ) {
			$this->save_settings();
		}

		/**
		 * init function for admin section
		 *
		 */
		function admin_init () {
			/* register options */
			 register_setting( WP_GALLERIFFIC_OPTION_GROUP , WP_GALLERIFFIC_PARAM );
			 add_option( WP_GALLERIFFIC_PARAM, $this->options , '' , 'no');

			/* save parameter updates, if there are any */
			if ( isset($_POST[WP_GALLERIFFIC_PARAM . '-save']) )
			{
				$this->save_settings () ;
				header("Location: options-general.php?page=wp-galleriffic-options&saved=true");
			}

			/* add the options page to admin section for privileged for admin users */
			add_options_page('Edit wp-galleriffic options', __('WP-Galleriffic', WP_GALLERIFFIC_PARAM ), 10, 'wp-galleriffic-options', array ( $this , 'admin_panel' ) );
		}

		/**
		 * settings panel at admin section
		 *
		 */
		function admin_panel ( ) {

			/**
			 * security
			 */
			if( ! function_exists( 'current_user_can' ) || ! current_user_can( 'manage_options' ) ){
				die( );
			}

			/**
			 * if options were saved
			 */
			if ($_GET['saved']=='true') :
			?>

			<div id='setting-error-settings_updated' class='updated settings-error'><p><strong>Settings saved.</strong></p></div>

			<?php
			endif;

			/**
			 * the admin panel itself
			 */
			?>

			<div class="wrap">
			<h2><?php _e( ' wp-galleriffic settings', WP_GALLERIFFIC_PARAM ) ; ?></h2>
			<form method="post" action="#">
				<fieldset class="grid50">
				<legend><?php _e('Local gallery',WP_GALLERIFFIC_PARAM); ?></legend>
				<dl>

					<dt>
						<label for="thumbSize"><?php _e('Thumbnail max. size', WP_GALLERIFFIC_PARAM); ?></label>
					</dt>
					<dd>
						<input type="text" name="thumbSize" id="thumbSize" value="<?php echo $this->options['thumbSize']; ?>" />
						<span class="description"><?php _e('Maximum size of larger side of thumbnail in pixel.', WP_GALLERIFFIC_PARAM); ?></span>
						<span class="default"><?php _e('Default ', WP_GALLERIFFIC_PARAM); ?>: <?php echo $this->defaults['thumbSize']; ?></span>
						</p>
					</dd>

					<dt>
						<label for="imgSize"><?php _e('Image max size', WP_GALLERIFFIC_PARAM); ?></label>
					</dt>
					<dd>
						<input type="text" name="imgSize" id="imgSize" value="<?php echo $this->options['imgSize']; ?>" />
						<span class="description"><?php _e('Maximum size of larger side of large images.', WP_GALLERIFFIC_PARAM); ?></span>

						<span class="default"><?php _e('Default ', WP_GALLERIFFIC_PARAM); ?>: <?php echo $this->defaults['imgSize']; ?></span>
						</p>
					</dd>

					<dt>
						<label for="thumbCrop"><?php _e('Enable thumbnail cropping', WP_GALLERIFFIC_PARAM); ?></label>
					</dt>
					<dd>
						<input type="checkbox" name="thumbCrop" id="thumbCrop" value="1" <?php checked($this->options['thumbCrop'],true); ?> />
						<span class="description"><?php _e('Enable to cropping thumbnails to 1:1 ratio (square)', WP_GALLERIFFIC_PARAM); ?></span>
						<span class="default"><?php _e('Default ', WP_GALLERIFFIC_PARAM); ?>: <?php $this->print_bool( $this->defaults['thumbCrop']); ?></span>
						</p>
					</dd>

				</dl>
				</fieldset>

				<fieldset class="grid50">
					<legend><?php _e('Flickr gallery', WP_GALLERIFFIC_PARAM); ?></legend>
				<dl>

					<dt>
						<label for="flickr_thumbsource"><?php _e('Flickr image size for thumbnail', WP_GALLERIFFIC_PARAM); ?></label>
					</dt>
					<dd>
						<select name="flickr_thumbsource" id="flickr_thumbsource">
							<?php $this->flickr_sizes ( $this->options['flickr_thumbsource'] ) ?>
						</select>
						<span class="description"><?php _e('Select source Flickr image size for thumbnails.', WP_GALLERIFFIC_PARAM); ?></span>
						<span class="default"><?php _e('Default ', WP_GALLERIFFIC_PARAM); ?>: <?php $this->flickr_sizes( $this->defaults['flickr_thumbsource'] , true ) ; ?></span>
						</p>
					</dd>

					<dt>
						<label for="flickr_previewsource"><?php _e('Flickr image size for preview', WP_GALLERIFFIC_PARAM); ?></label>
					</dt>
					<dd>
						<select name="flickr_previewsource" id="flickr_previewsource">
							<?php $this->flickr_sizes ( $this->options['flickr_previewsource'] ) ?>
						</select>
						<span class="description"><?php _e('Select source Flickr image size for preview.', WP_GALLERIFFIC_PARAM); ?></span>
						<span class="default"><?php _e('Default ', WP_GALLERIFFIC_PARAM); ?>: <?php $this->flickr_sizes( $this->defaults['flickr_previewsource'] , true ) ; ?></span>
						</p>
					</dd>

					<dt>
						<label for="flickr_api"><?php _e('Flick API key', WP_GALLERIFFIC_PARAM); ?></label>
					</dt>
					<dd>
						<input type="text" name="flickr_api" id="flickr_api" value="<?php echo $this->options['flickr_api']; ?>" />
						<span class="description"><?php _e('Key to access Flickr. The default is a key registered by the author of the wp-galleriffic plugin.', WP_GALLERIFFIC_PARAM); ?></span>
						<span class="default"><?php _e('Default ', WP_GALLERIFFIC_PARAM); ?>: <?php echo $this->defaults['flickr_api']; ?></span>
						</p>
					</dd>

					<dt>
						<label for="flickr_resize"><?php _e('Resize Flick images?', WP_GALLERIFFIC_PARAM); ?></label>
					</dt>
					<dd>
						<input type="checkbox" name="flickr_resize" id="flickr_resize" value="1" <?php checked($this->options['flickr_resize'],true); ?> />
						<span class="description"><?php _e('Resize Flickr images and serve them from local cache.', WP_GALLERIFFIC_PARAM); ?></span>
						<span class="default"><?php _e('Default ', WP_GALLERIFFIC_PARAM); ?>: <?php $this->print_bool( $this->defaults['flickr_resize']); ?></span>
						</p>
					</dd>

				</dl>
				</fieldset>

				<fieldset class="grid50">
					<legend><?php _e('Slideshow',WP_GALLERIFFIC_PARAM); ?></legend>
				<dl>
					<dt>
						<label for="delay"><?php _e('Delay', WP_GALLERIFFIC_PARAM); ?></label>
					</dt>
					<dd>
						<input type="text" name="delay" id="delay" value="<?php echo $this->options['delay']; ?>" />
						<span class="description"><?php _e('Specifies the visibility time for in image in slideshow mode.', WP_GALLERIFFIC_PARAM); ?></span>
						<span class="default"><?php _e('Default ', WP_GALLERIFFIC_PARAM); ?>: <?php echo $this->defaults['delay']; ?></span>
						</p>
					</dd>

					<dt>
						<label for="defaultTransitionDuration"><?php _e('Effect speed', WP_GALLERIFFIC_PARAM); ?></label>
					</dt>
					<dd>
						<input type="text" name="defaultTransitionDuration" id="defaultTransitionDuration" value="<?php echo $this->options['defaultTransitionDuration']; ?>" />
						<span class="description"><?php _e('If using the default transitions, specifies the duration of the transitions', WP_GALLERIFFIC_PARAM); ?></span>
						<span class="default"><?php _e('Default ', WP_GALLERIFFIC_PARAM); ?>: <?php echo $this->defaults['defaultTransitionDuration']; ?></span>
						</p>
					</dd>

					<dt>
						<label for="renderSSControls"><?php _e('Show slideshow Play and Pause links', WP_GALLERIFFIC_PARAM); ?></label>
					</dt>
					<dd>
						<input type="checkbox" name="renderSSControls" id="renderSSControls" value="1" <?php checked($this->options['renderSSControls'],true); ?> />
						<span class="description"><?php _e('Specifies whether the slideshow Play and Pause links should be rendered', WP_GALLERIFFIC_PARAM); ?></span>
						<span class="default"><?php _e('Default ', WP_GALLERIFFIC_PARAM); ?>: <?php $this->print_bool( $this->defaults['renderSSControls'] ); ?></span>
						</p>
					</dd>

					<dt>
						<label for="autoStart"><?php _e('Enable slideshow autostart', WP_GALLERIFFIC_PARAM); ?></label>
					</dt>
					<dd>
						<input type="checkbox" name="autoStart" id="autoStart" value="1" <?php checked($this->options['autoStart'],true); ?> />
						<span class="description"><?php _e('Specifies whether the slideshow should be playing or paused when the page first loads', WP_GALLERIFFIC_PARAM); ?></span>
						<span class="default"><?php _e('Default ', WP_GALLERIFFIC_PARAM); ?>: <?php $this->print_bool( $this->defaults['autoStart'] ); ?></span>
						</p>
					</dd>

				</dl>
				</fieldset>

				<fieldset class="grid50">
					<legend><?php _e('Layout',WP_GALLERIFFIC_PARAM); ?></legend>
				<dl>

					<dt>
						<label for="numThumbs"><?php _e('Thumbs/page', WP_GALLERIFFIC_PARAM); ?></label>
					</dt>
					<dd>
						<input type="text" name="numThumbs" id="numThumbs" value="<?php echo $this->options['numThumbs']; ?>" />
						<span class="description"><?php _e('The number of thumbnails to show per page', WP_GALLERIFFIC_PARAM); ?></span>
						<span class="default"><?php _e('Default ', WP_GALLERIFFIC_PARAM); ?>: <?php echo $this->defaults['numThumbs']; ?></span>
						</p>
					</dd>

					<dt>
						<label for="maxPagesToShow"><?php _e('Maximum number of pages', WP_GALLERIFFIC_PARAM); ?></label>
					</dt>
					<dd>
						<input type="text" name="maxPagesToShow" id="maxPagesToShow" value="<?php echo $this->options['maxPagesToShow']; ?>" />
						<span class="description"><?php _e('The maximum number of pages to display in either the top or bottom pager', WP_GALLERIFFIC_PARAM); ?></span>
						<span class="default"><?php _e('Default ', WP_GALLERIFFIC_PARAM); ?>: <?php echo $this->defaults['maxPagesToShow']; ?></span>
						</p>
					</dd>

					<dt>
						<label for="mouseOutOpacity"><?php _e('Inactive thumbnail opacity', WP_GALLERIFFIC_PARAM); ?></label>
					</dt>
					<dd>
						<input type="text" name="mouseOutOpacity" id="mouseOutOpacity" value="<?php echo $this->options['mouseOutOpacity']; ?>" />
						<span class="description"><?php _e('The opacity of the currently no active thumbnails in percents (100 means no opacity).', WP_GALLERIFFIC_PARAM); ?></span>
						<span class="default"><?php _e('Default ', WP_GALLERIFFIC_PARAM); ?>: <?php echo $this->defaults['mouseOutOpacity']; ?></span>
						</p>
					</dd>

					<dt>
						<label for="enableTopPager"><?php _e('Enable pager on top', WP_GALLERIFFIC_PARAM); ?></label>
					</dt>
					<dd>
						<input type="checkbox" name="enableTopPager" id="enableTopPager" value="1" <?php checked($this->options['enableTopPager'],true); ?> />
						<span class="description"><?php _e('Show pagination on the top', WP_GALLERIFFIC_PARAM); ?></span>
						<span class="default"><?php _e('Default ', WP_GALLERIFFIC_PARAM); ?>: <?php $this->print_bool( $this->defaults['enableTopPager']); ?></span>
						</p>
					</dd>

					<dt>
						<label for="enableBottomPager"><?php _e('Enable pager on bottom', WP_GALLERIFFIC_PARAM); ?></label>
					</dt>
					<dd>
						<input type="checkbox" name="enableBottomPager" id="enableBottomPager" value="1" <?php checked($this->options['enableBottomPager'],true); ?> />
						<span class="description"><?php _e('Show pagination on the bottom', WP_GALLERIFFIC_PARAM); ?></span>
						<span class="default"><?php _e('Default ', WP_GALLERIFFIC_PARAM); ?>: <?php $this->print_bool( $this->defaults['enableBottomPager'] ); ?></span>
						</p>
					</dd>

					<dt>
						<label for="renderCaption"><?php _e('Show Captions', WP_GALLERIFFIC_PARAM); ?></label>
					</dt>
					<dd>
						<input type="checkbox" name="renderCaption" id="renderCaption" value="1" <?php checked($this->options['renderCaption'],true); ?> />
						<span class="description"><?php _e('Specifies whether the image captions should be rendered', WP_GALLERIFFIC_PARAM); ?></span>
						<span class="default"><?php _e('Default ', WP_GALLERIFFIC_PARAM); ?>: <?php $this->print_bool( $this->defaults['renderCaption'] ); ?></span>
						</p>
					</dd>

					<dt>
						<label for="defaultCSS"><?php _e('Use default CSS', WP_GALLERIFFIC_PARAM); ?></label>
					</dt>
					<dd>
						<input type="checkbox" name="defaultCSS" id="defaultCSS" value="1" <?php checked($this->options['defaultCSS'],true); ?> />
						<span class="description"><?php _e('Enable use of CSS provided with the plugins.', WP_GALLERIFFIC_PARAM); ?></span>
						<span class="default"><?php _e('Default ', WP_GALLERIFFIC_PARAM); ?>: <?php $this->print_bool( $this->defaults['defaultCSS'] ); ?></span>
						</p>
					</dd>

					<dt>
						<label for="cssautofix"><?php _e('Enable CSS autofix', WP_GALLERIFFIC_PARAM); ?></label>
					</dt>
					<dd>
						<input type="checkbox" name="cssautofix" id="cssautofix" value="1" <?php checked($this->options['cssautofix'],true); ?> />
						<span class="description"><?php _e('Enable CSS fix for aligning large pictures to the vertical center and fix duplicate images error. The image container will be the size of image + size of border in height and ( size of image + size of border ) *1.1 in width. This hack can be avoided with correctly coded CSS.', WP_GALLERIFFIC_PARAM); ?></span>
						<span class="default"><?php _e('Default ', WP_GALLERIFFIC_PARAM); ?>: <?php $this->print_bool( $this->defaults['cssautofix'] ); ?></span>
						</p>
					</dd>

				</dl>
				</fieldset>

				<fieldset class="grid50">
					<legend><?php _e('Texts', WP_GALLERIFFIC_PARAM); ?></legend>
				<dl>

					<dt>
						<label for="playLinkText"><?php _e('Text of Play link', WP_GALLERIFFIC_PARAM); ?></label>
					</dt>
					<dd>
						<input type="text" name="playLinkText" id="playLinkText" value="<?php echo $this->options['playLinkText']; ?>" />
						<span class="default"><?php _e('Default ', WP_GALLERIFFIC_PARAM); ?>: <?php echo $this->defaults['playLinkText']; ?></span>
						</p>
					</dd>

					<dt>
						<label for="pauseLinkText"><?php _e('Text of Pause link', WP_GALLERIFFIC_PARAM); ?></label>
					</dt>
					<dd>
						<input type="text" name="pauseLinkText" id="pauseLinkText" value="<?php echo $this->options['pauseLinkText']; ?>" />
						<span class="default"><?php _e('Default ', WP_GALLERIFFIC_PARAM); ?>: <?php echo $this->defaults['pauseLinkText']; ?></span>
						</p>
					</dd>

					<dt>
						<label for="nextPageLinkText"><?php _e('Text of Next page link', WP_GALLERIFFIC_PARAM); ?></label>
					</dt>
					<dd>
						<input type="text" name="nextPageLinkText" id="nextPageLinkText" value="<?php echo $this->options['nextPageLinkText']; ?>" />
						<span class="default"><?php _e('Default ', WP_GALLERIFFIC_PARAM); ?>: <?php echo $this->defaults['nextPageLinkText']; ?></span>
						</p>
					</dd>

					<dt>
						<label for="prevPageLinkText"><?php _e('Text of Previous page link', WP_GALLERIFFIC_PARAM); ?></label>
					</dt>
					<dd>
						<input type="text" name="prevPageLinkText" id="prevPageLinkText" value="<?php echo $this->options['prevPageLinkText']; ?>" />
						<span class="default"><?php _e('Default ', WP_GALLERIFFIC_PARAM); ?>: <?php echo $this->defaults['prevPageLinkText']; ?></span>
						</p>
					</dd>

				</dl>
				</fieldset>

				<fieldset class="grid50">
					<legend><?php _e('System Settings', WP_GALLERIFFIC_PARAM); ?></legend>
				<dl>

					<dt>
						<label for="preloadAhead"><?php _e('Number of images to preload', WP_GALLERIFFIC_PARAM); ?></label>
					</dt>
					<dd>
						<input type="text" name="preloadAhead" id="preloadAhead" value="<?php echo $this->options['preloadAhead']; ?>" />
						<span class="description"><?php _e('Preload this number of images in the background for smoothless playback. (-1 means unlimited, use it with care!)', WP_GALLERIFFIC_PARAM); ?></span>
						<span class="default"><?php _e('Default ', WP_GALLERIFFIC_PARAM); ?>: <?php echo $this->defaults['preloadAhead']; ?></span>
						</p>
					</dd>

					<dt>
						<label for="enableHistory"><?php _e('Enable browser history', WP_GALLERIFFIC_PARAM); ?></label>
					</dt>
					<dd>
						<input type="checkbox" name="enableHistory" id="enableHistory" value="1" <?php checked($this->options['enableHistory'],true); ?> />
						<span class="description"><?php _e('Specifies whether the url hash and the browser history cache should update when the current slideshow image changes', WP_GALLERIFFIC_PARAM); ?></span>
						<span class="default"><?php _e('Default ', WP_GALLERIFFIC_PARAM); ?>: <?php $this->print_bool( $this->defaults['enableHistory'] ); ?></span>
						</p>
					</dd>

					<dt>
						<label for="enableKeyboardNavigation"><?php _e('Enable keyboard navigation', WP_GALLERIFFIC_PARAM); ?></label>
					</dt>
					<dd>
						<input type="checkbox" name="enableKeyboardNavigation" id="enableKeyboardNavigation" value="1" <?php checked($this->options['enableKeyboardNavigation'],true); ?> />
						<span class="description"><?php _e('Navigate through images with arrow keys.', WP_GALLERIFFIC_PARAM); ?></span>
						<span class="default"><?php _e('Default ', WP_GALLERIFFIC_PARAM); ?>: <?php $this->print_bool( $this->defaults['enableKeyboardNavigation'] ); ?></span>
						</p>
					</dd>

				</dl>
				</fieldset>

				<?php settings_fields( WP_GALLERIFFIC_OPTION_GROUP ); ?>
				<p class="grid75"><input class="button-primary" type="submit" name="<?php echo WP_GALLERIFFIC_PARAM; ?>-save" id="<?php echo WP_GALLERIFFIC_PARAM; ?>-save" value="Save Changes" /></p>
			</form>
			<?php

		}

		/**
		 * generate resized cache images for Flickr image, thumbnail & preview
		 *
		 * @param $img
		 * 	$img contains informations of image, the important ones in this case:
		 *		$img['thumb'][0] for URL of thumbnail source image
		 *		$img['title'] for the title of the source image
		 * 		$img['preview'][0] for URL of preview source image
		 *
		 * @return
		 * 	comes back with the same array as the input, but replaced with modified values
		 */
		function flickr_cache_image ( $img ) {

			/* generate nice title for image from grapped img title */
			$imgslug = sanitize_title( $img['title'] );

			/* tmp file location */
			$imgtmp = WP_GALLERIFFIC_CACHE_DIR . '/' . $imgslug;

			foreach ($this->sizes as $sizetype )
			{
				if ( $sizetype == 'thumb' )
				{
					$optname = 'thumbSize';
					/* clear exif, don't waste bandwidth */
					$exif = '';
				}
				elseif ( $sizetype == 'preview' )
				{
					$optname = 'imgSize';
					/* keep exif */
					$exif = '&amp;exif';
				}

				$imgname = $imgslug . '-' . $this->options[ $optname ] . '.jpg';
				$imgout = WP_GALLERIFFIC_CACHE_DIR . '/' . $imgname;

				$query = WP_GALLERIFFIC_URL . '/image.php?'
					. 'width=' . $this->options[ $optname ]
					. '&amp;height=' . $this->options[ $optname ]
					. $exif
					. '&amp;out=' . $imgname
					. '&amp;source=' . $img[ $sizetype ][ 0 ];

				if ( file_exists( $imgout ))
				{
					$img[ $sizetype ][ 0 ] = WP_GALLERIFFIC_CACHE_URL . '/' . $imgname;
				}
				else
				{
					$img[ $sizetype ][ 0 ] = $query;
				}

			}

			return $img;
		}

		/**
		 * Flickr API requests handler
		 *
		 * @param $this->options
		 * 	array with the required parameters for Flickr request
		 *
		 */
		function flickr_request ( $options ) {

			$encoded_params = array();
			foreach ($options as $k => $v){
				$encoded_params[] = urlencode($k).'='.urlencode($v);
			}

			return unserialize ( file_get_contents( "http://api.flickr.com/services/rest/?".implode('&', $encoded_params) ) );
		}

		/**
		 * Flickr image sizes
		 *
		 * @param $current
		 * 	the active or required size's identifier
		 *
		 * @param $returntext
		 * 	boolean: is true, the description will be returned of $current size
		 *
		 * @return
		 * 	prints either description of $current
		 * 	or option list for a <select> input field with $current set as active
		 *
		 */
		function flickr_sizes ( $current , $returntext = false ) {

			$sizes = array (
				's' => 'square, 75x75',
				't' => 'thumbnail, 100 on longest side',
				'm' => 'small, 240 on longest side',
				'-' => 'medium, 500 on longest side',
				'z' => 'large medium, 640 on longest side',
				'b' => 'large, 1024 on longest side',
				'o' => 'original image'
			);

			$this->print_select_options ( $sizes , $current , $returntext );

		}

		/**
		 * parameters array with default values;
		 *
		 * @param $def
		 * 	is false, the function returns with the current settings, if true, the defaults will be returned
		 *
		 */
		function get_options ($def=false) {
			$defaults = array (
				'thumbSize'=>40,
				'imgSize'=>560,
				'thumbCrop'=>true,
				'delay'=>3000,
				'numThumbs'=>22,
				'preloadAhead'=>6,
				'enableTopPager'=>true,
				'enableBottomPager'=>false,
				'maxPagesToShow'=>7,
				'renderSSControls'=>true,
				'renderCaption'=>true,
				'playLinkText'=>'Start slideshow',
				'pauseLinkText'=>'Pause slideshow',
				'nextPageLinkText'=>'Next &rsaquo;',
				'prevPageLinkText'=>'&lsaquo; Prev',
				'enableHistory'=>false,
				'enableKeyboardNavigation'=>true,
				'autoStart'=>true,
				'syncTransitions'=>false,
				'defaultTransitionDuration'=>1500,
				'mouseOutOpacity'=>0.6,
				'cssautofix'=>false,
				'defaultCSS'=>false,
				/* prev/next link is full of bugs in the JS, these are not yet active */
				'renderNavControls'=>false,
				'prevLinkText'=>'Previous',
				'nextLinkText'=>'Next',
				'flickr_api'=>'83f1fed4ea8153f9fc3f70be1293166f',
				'flickr_thumbsource' => 's',
				'flickr_previewsource' => '-',
				'flickr_resize' =>false,
			);
			$this->defaults = $defaults;

			$this->options = get_option( WP_GALLERIFFIC_PARAM , $defaults );
		}

		/**
		 * save settings function
		 *
		 */
		function save_settings () {

			/**
			 * update params from $_POST
			 */
			foreach ($this->options as $name=>$optionvalue)
			{
				if (!empty($_POST[$name]))
				{
					$update = $_POST[$name];
					if (strlen($update)!=0 && !is_numeric($update))
						$update = stripslashes($update);
				}
				else
				{
					$update = 0;
				}
				$this->options[$name] = $update;
			}
			update_option( WP_GALLERIFFIC_PARAM , $this->options );
		}

		/**
		 * shortcode function
		 *
		 * @param $atts
		 *	array of passed attributes in shortcode, for example [wp-galleriffic set=ID]
		 *
		 * @param $content
		 * 	optional content between [wp-galleriffic][/wp-galleriffic]
		 *
		 * @return
		 * 	returns with the HTML code to print out
		 */
		function shortcode( $atts ,  $content = null ) {

			global $post;
			global $wp_upload_dir;
			extract( shortcode_atts(array(
				'set' => '',
			), $atts));

			$images = array();
			$imgid=0;

			/**
			 * normal gallery
			 */
			if ( empty( $set ) )
			{

				/* get the attachments for current post */
				$attachments = get_children( array (
					'post_parent'=>$post->ID,
					'post_type'=>'attachment',
					'post_mime_type'=>'image',
					'orderby'=>'menu_order',
					'order'=>'asc'
				) );

				if ( !empty($attachments) )
				{
					foreach ( $attachments as $aid => $attachment )
					{

						$_post = & get_post($aid);

						$img['title'] = attribute_escape($_post->post_title);
						$img['alttext'] = get_post_meta($aid, '_wp_attachment_image_alt', true);
						$img['caption'] = attribute_escape($_post->post_excerpt);
						$img['description'] = attribute_escape($_post->post_content);
						$img['preview'] = wp_get_attachment_image_src( $aid, WP_GALLERIFFIC_PREVIEW );
						$img['thumb'] = wp_get_attachment_image_src( $aid, WP_GALLERIFFIC_THUMB );

						if ( !$img['preview '] || !$img['thumb'] )
						{
							require_once( ABSPATH . '/wp-admin/includes/image.php' );
							wp_generate_attachment_metadata( $aid , get_attached_file( $aid ) );
						}

						$images[$imgid] = $img;
						$imgid++;
					}
				}

			}
			/**
			 * sets are needed to be specified for Flickr galleries
			 * so if specified, get images from the flickr set
			 */
			else
			{

				$flickrparams = array(
					'api_key'	=> $this->options['flickr_api'],
					'method'	=> WP_GALLERIFFIC_FLICKR_METHOD,
					'photoset_id'	=> $set,
					'format'	=> WP_GALLERIFFIC_FLICKR_FORMAT,
				);
				$flickrset = $this->flickr_request ( $flickrparams );

				$replaces = array (
					'%FARM%',
					'%SERVER%',
					'%ID%',
					'%SECRET%'
				);

				foreach ($flickrset['photoset']['photo'] as $item)
				{
					$img['title'] = $img['alttext'] = $img['caption'] = $img['description'] = $item['title'];

					$replacements = array (
						$item['farm'],
						$item['server'],
						$item['id'],
						$item['secret']
					);

					$base = str_replace ( $replaces, $replacements, WP_GALLERIFFIC_FLICKR_BASE );

					foreach ($this->sizes as $flickrsize )
					{
						$optname = 'flickr_' . $flickrsize . 'source';

						switch ( $this->options[ $optname ] )
						{
							case '-':
								$img[ $flickrsize ][0] = $base . '.jpg';
								break;
							default :
								$img[ $flickrsize ][0] = $base . '_' . $this->options[ $optname ] . '.jpg';
						}
					}

					/* if resize required */
					if ( $this->options['flickr_resize'] )
					{
						$img = $this->flickr_cache_image( $img );
					}

					$images[$imgid] = $img;
					$imgid++;
				}
			}

			foreach ($images as $id=>$img)
			{
				$titles = array ( $img['caption'], $img['title']);
				$caption = false;
				foreach ($titles as $title)
				{
					if (!empty($title) && empty($caption))
						$caption = $title;
				}

				$thumbs .= '
				<li>
					<a class="thumb" href="'. $img['preview'][0] .'" title="'. $img['title'] .'">
						<img src="'. $img['thumb'][0] .'" alt="'. $img['alttext'] .'" />
					</a>
					<div class="caption">'. $caption .'</div>
				</li>';

			}

			$js = "
				<script type='text/javascript'>
					jQuery(document).ready(function($) {

						var onMouseOutOpacity = ". $this->options['mouseOutOpacity'] .";
						$('#thumbs ul li').opacityrollover({
							mouseOutOpacity: onMouseOutOpacity,
							mouseOverOpacity: 1.0,
							fadeSpeed: 'fast',
							exemptionSelector: '.selected'
						});

						var gallery = $('#thumbs').galleriffic({";

						/**
						 * there wouldn't be need for all params, but it's a lot easier to put them out all
						 */
						foreach ($this->options as $key=>$value) {
							if ( is_bool ( $value ) )
								$value = empty ( $value ) ? 'false' : 'true';
							elseif ( !is_int ( $value ) )
								$value = "'" . $value . "'";

							$js .= "\n					" . $key . ": " . $value . ",";
						}

							$js .= "
							thumbRatio: '1:1',
							imageContainerSel: '#slideshow',
							controlsContainerSel: '#controls',
							captionContainerSel: '#caption',
							loadingContainerSel: '#loading',
							onSlideChange: function(prevIndex, nextIndex) {
								this.find('ul.thumbs').children()
									.eq(prevIndex).fadeTo('fast', onMouseOutOpacity).end()
									.eq(nextIndex).fadeTo('fast', 1.0);
							},
							onPageTransitionOut: function(callback) {
								this.fadeTo('fast', 0.0, callback);
							},
							onPageTransitionIn: function() {
								this.fadeTo('fast', 1.0);
							}
						});

						function pageload(hash) {
							if(hash) {
								$.galleriffic.gotoImage(hash);
							} else {
								gallery.gotoIndex(0);
							}
						}

						$.historyInit(pageload, 'advanced.html');

						$(\"a[rel='history']\").live('click', function(e) {
							if (e.button != 0) return true;
							var hash = this.href;
							hash = hash.replace(/^.*#/, '');
							$.historyLoad(hash);
							return false;
						});
			";

			/**
			 * this is best-practise. I've tested a lot, played a lot with the numbers, but
			 * this fixed the image duplication for me in all the cases I could create.
			 * No, I don't have explanation for the multiplication, it just has to be there.
			 */
			if ( $this->options['cssautofix'] )
			{
				$width = $this->options['imgSize'];
				$height = $width = round($this->options['imgSize'] * 1.06);

				$js .= '
						$("div#gallery").css({
							"width" : "' . $width . 'px",
							"margin-left" : "auto",
							"margin-right" : "auto",
						});
						$("div#slideshow-container").css({
							"width" : "' . $width . 'px",
							"height" : "' . $height . 'px",
						});
						$("div#slideshow").css({
							"line-height" : "' . $height . 'px",
						});
					';
			}

			$js .= "
					});
				</script>
			";

			$output = '
			<div id="wp-galleriffic">
			<div id="thumbs">
				<ul class="thumbs noscript">
				' . $thumbs . '
				</ul>
			</div>
			<div id="gallery">
				<div id="controls"></div>
				<div id="caption"></div>
				<div id="slideshow-container">
					<div id="slideshow"></div>
				</div>
				<div id="loading"></div>
			</div>
			<div class="placeholder">&nbsp;</div>
			</div>
				' . $js;

			return $output;
		}


		/**
		 * prints `true` or `false` depending on a bool variable.
		 *
		 * @param $val
		 * 	The boolen variable to print status of.
		 *
		 */
		function print_bool ( $val ) {
			$bool = $val? 'true' : 'false';
			echo $bool;
		}

		/**
		 * select field processor
		 *
		 * @param sizes
		 * 	array to build <option> values of
		 *
		 * @param $current
		 * 	the current resize type
		 *
		 * @param $returntext
		 * 	boolean: is true, the description will be returned of $current type
		 *
		 * @return
		 * 	prints either description of $current
		 * 	or option list for a <select> input field with $current set as active
		 *
		 */
		function print_select_options ( $sizes, $current, $returntext=false ) {

			if ( $returntext )
			{
				_e( $sizes[ $current ] , WP_GALLERIFFIC_PARAM);
				return;
			}

			foreach ($sizes as $ext=>$name)
			{
				?>
				<option value="<?php echo $ext ?>" <?php selected( $ext , $current ); ?>>
					<?php _e( $name , WP_GALLERIFFIC_PARAM); ?>
				</option>
				<?php
			}

		}

		/**
		 * clean up at uninstall
		 *
		 */
		function uninstall ( ) {
			delete_option( WP_GALLERIFFIC_PARAM );
		}

	}
}

/**
 * instantiate the class
 */
$wp_galleriffic = new WPGalleriffic();


?>
Return current item: WP-Galleriffic