Commit 7152ca2a authored by Erick Hitter's avatar Erick Hitter
Browse files

Initial public release.

parents
<?php
/*
* Plugin Name: Jetpack Photon for NextGEN Gallery
* Plugin URI: http://www.ethitter.com/plugins/jetpack-photon-for-nextgen/
* Description: Extend Jetpack's Photon module to images in NextGEN Galleries. Requires both the <a href="http://wordpress.org/extend/plugins/jetpack/" target="_blank">Jetpack</a> and <a href="http://wordpress.org/extend/plugins/nextgen-gallery/" target="_blank">NextGEN Gallery</a> plugins to be of any use.
* Author: Erick Hitter
* Version: 0.2
* Author URI: http://www.ethitter.com/
* License: GPL2+
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
class Jetpack_Photon_for_NextGEN {
/**
* Class variables
*/
// Oh look, a singleton
private static $__instance = null;
// NextGEN image settings
private $src_width = false;
private $src_height = false;
private $thumb_width = false;
private $thumb_height = false;
private $thumb_transform = 'resize';
/**
* Singleton implementation
*
* @return object
*/
public static function instance() {
if ( ! is_a( self::$__instance, 'Jetpack_Photon_for_NextGEN' ) ) {
self::$__instance = new Jetpack_Photon_for_NextGEN;
self::$__instance->setup();
}
return self::$__instance;
}
/**
* Silence is golden.
*/
private function __construct() {}
/**
* Since this plugin relies on Jetpack, defer adding its actions until Jetpack's presence can be reliably determined.
*
* @uses add_action
* @return null
*/
private function setup() {
add_action( 'wp_loaded', array( $this, 'action_wp_loaded' ) );
}
/**
* Load plugin's actions if Jetpack is present.
*
* @uses add_action
*/
public function action_wp_loaded() {
// Requires Jetpack
if ( ! function_exists( 'jetpack_photon_url' ) )
return;
// Don't mess with the admin, unless someone really wants to
if ( is_admin() && ! apply_filters( 'jpn_apply_in_admin', false ) )
return;
// Populate options from NextGEN
$this->parse_nextgen_options();
// Filter image properties
add_action( 'ngg_get_image', array( $this, 'action_ngg_get_image' ) );
}
/**
* Parse NextGEN settings relevant to our resizing
*
* @uses get_option
* @return null
*/
private function parse_nextgen_options() {
$options = get_option( 'ngg_options' );
if ( is_array( $options ) && ! empty( $options ) ) {
// Full-size image
if ( array_key_exists( 'imgWidth', $options ) )
$this->src_width = (int) $options['imgWidth'];
if ( array_key_exists( 'imgHeight', $options ) )
$this->src_height = (int) $options['imgHeight'];
// Thumbnails
if ( array_key_exists( 'thumbwidth', $options ) )
$this->thumb_width = (int) $options['thumbwidth'];
if ( array_key_exists( 'thumbheight', $options ) )
$this->thumb_height = (int) $options['thumbheight'];
// Thumbnail resizing type
if ( array_key_exists( 'thumbfix', $options ) )
$this->thumb_transform = (bool) $options['thumbfix'] ? 'resize' : 'fit';
}
}
/**
* Filter NextGEN image objects to point to Photon.
* Dimensions aren't available, so only CDN aspect will be utilized.
*
* @param object $image
* @uses jetpack_photon_url
* @return null
*/
public function action_ngg_get_image( $image ) {
// Alias image URLs
$src = $src_orig = $image->imageURL;
$thumb = $thumb_orig = $image->thumbURL;
// Pass fullsize image to Photon
$src_args = array();
if ( is_int( $this->src_width ) && is_int( $this->src_height ) )
$src_args['fit'] = $this->src_width . ',' . $this->src_height;
$src = jetpack_photon_url( $src, $src_args );
// Pass thumbnail to Photon
$thumb_args = array();
if ( is_int( $this->thumb_width ) && is_int( $this->thumb_height ) )
$thumb_args[ $this->thumb_transform ] = $this->thumb_width . ',' . $this->thumb_height;
$thumb = jetpack_photon_url( empty( $thumb_args ) ? $thumb : $src_orig, $thumb_args );
// Update image URLs
$image->imageURL = $src;
$image->thumbURL = $thumb;
//Update markup
$properties = array(
'href',
'imageHTML',
'thumbHTML'
);
foreach ( $properties as $property ) {
$image->{$property} = str_replace( $src_orig, $src, $image->{$property} );
$image->{$property} = str_replace( $thumb_orig, $thumb, $image->{$property} );
}
}
}
Jetpack_Photon_for_NextGEN::instance();
\ No newline at end of file
=== Jetpack Photon for NextGEN Gallery ===
Contributors: ethitter
Tags: jetpack, photon, nextgen, gallery
Requires at least: 3.5
Tested up to: 3.5
Stable tag:
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Extend Jetpack's Photon CDN to images in NextGEN Galleries.
== Description ==
If you're using Jetpack's [Photon](http://developer.wordpress.com/docs/photon/) CDN, this plugin will extend the service to galleries created with NextGEN Gallery. Just activate it and gallery images are automatically served from Photon.
== Installation ==
1. Upload jetpack-photon-for-nextgen.php to /wp-content/plugins/.
2. Activate plugin through the WordPress Plugins menu.
== Frequently Asked Questions ==
= Are there any options? =
Nope, it's a pretty straightforward plugin. So long as you have [Jetpack](http://wordpress.org/extend/plugins/jetpack/) and [NextGEN Gallery](http://wordpress.org/extend/plugins/nextgen-gallery/) installed, and you have galleries, it just works.
== Changelog ==
= 0.2 =
* Initial public release.
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment