diff options
Diffstat (limited to 'plugins/jetpack/modules/widgets/gallery.php')
-rw-r--r-- | plugins/jetpack/modules/widgets/gallery.php | 131 |
1 files changed, 70 insertions, 61 deletions
diff --git a/plugins/jetpack/modules/widgets/gallery.php b/plugins/jetpack/modules/widgets/gallery.php index 83b73845..8cb24d01 100644 --- a/plugins/jetpack/modules/widgets/gallery.php +++ b/plugins/jetpack/modules/widgets/gallery.php @@ -9,15 +9,15 @@ Author URI: http://automattic.com */ class Jetpack_Gallery_Widget extends WP_Widget { - const THUMB_SIZE = 45; - const DEFAULT_WIDTH = 265; + const THUMB_SIZE = 45; + const DEFAULT_WIDTH = 265; - protected $_instance_width ; + protected $_instance_width; public function __construct() { - $widget_ops = array( - 'classname' => 'widget-gallery', - 'description' => __( 'Display a photo gallery or slideshow', 'jetpack' ), + $widget_ops = array( + 'classname' => 'widget-gallery', + 'description' => __( 'Display a photo gallery or slideshow', 'jetpack' ), 'customize_selective_refresh' => true, ); @@ -70,10 +70,11 @@ class Jetpack_Gallery_Widget extends WP_Widget { // with other tiled galleries, regardless of whether or not the widget was set to Carousel mode. The onClick selector // is simply too broad, since it was not written with widgets in mind. This special class prevents that behavior, via // an override handler in gallery.js - if( 'carousel' != $instance['link'] && 'slideshow' != $instance['type'] ) + if ( 'carousel' != $instance['link'] && 'slideshow' != $instance['type'] ) { $classes[] = 'no-carousel'; - else + } else { $classes[] = 'carousel'; + } $classes = implode( ' ', $classes ); @@ -95,8 +96,9 @@ class Jetpack_Gallery_Widget extends WP_Widget { /** This filter is documented in core/src/wp-includes/default-widgets.php */ $title = apply_filters( 'widget_title', $instance['title'] ); - if ( $title ) + if ( $title ) { echo $before_title . esc_html( $title ) . $after_title . "\n"; + } echo '<div class="' . esc_attr( $classes ) . '">' . "\n"; @@ -119,8 +121,9 @@ class Jetpack_Gallery_Widget extends WP_Widget { // can appropriately size the tiles. add_filter( 'tiled_gallery_content_width', array( $this, 'tiled_gallery_content_width' ) ); - if ( method_exists( $this, $method ) ) + if ( method_exists( $this, $method ) ) { echo $this->$method( $args, $instance ); + } // Remove the stored $_instance_width, as it is no longer needed $this->_instance_width = null; @@ -142,21 +145,23 @@ class Jetpack_Gallery_Widget extends WP_Widget { * @param array $instance The Widget instance for which you'd like attachments * @return array Array of attachment objects for the Widget in $instance */ - public function get_attachments( $instance ){ + public function get_attachments( $instance ) { $ids = explode( ',', $instance['ids'] ); if ( isset( $instance['random'] ) && 'on' == $instance['random'] ) { shuffle( $ids ); } - $attachments_query = new WP_Query( array( - 'post__in' => $ids, - 'post_status' => 'inherit', - 'post_type' => 'attachment', - 'post_mime_type' => 'image', - 'posts_per_page' => -1, - 'orderby' => 'post__in', - ) ); + $attachments_query = new WP_Query( + array( + 'post__in' => $ids, + 'post_status' => 'inherit', + 'post_type' => 'attachment', + 'post_mime_type' => 'image', + 'posts_per_page' => -1, + 'orderby' => 'post__in', + ) + ); $attachments = $attachments_query->get_posts(); @@ -174,7 +179,7 @@ class Jetpack_Gallery_Widget extends WP_Widget { */ public function rectangular_widget( $args, $instance ) { if ( ! class_exists( 'Jetpack_Tiled_Gallery' ) - && ! class_exists( 'Jetpack_Tiled_Gallery_Layout_Rectangular') ) { + && ! class_exists( 'Jetpack_Tiled_Gallery_Layout_Rectangular' ) ) { return; } @@ -193,7 +198,7 @@ class Jetpack_Gallery_Widget extends WP_Widget { */ public function square_widget( $args, $instance ) { if ( ! class_exists( 'Jetpack_Tiled_Gallery' ) - && ! class_exists( 'Jetpack_Tiled_Gallery_Layout_Square') ) { + && ! class_exists( 'Jetpack_Tiled_Gallery_Layout_Square' ) ) { return; } @@ -212,7 +217,7 @@ class Jetpack_Gallery_Widget extends WP_Widget { */ public function circle_widget( $args, $instance ) { if ( ! class_exists( 'Jetpack_Tiled_Gallery' ) - && ! class_exists( 'Jetpack_Tiled_Gallery_Layout_Circle') ) { + && ! class_exists( 'Jetpack_Tiled_Gallery_Layout_Circle' ) ) { return; } @@ -234,17 +239,19 @@ class Jetpack_Gallery_Widget extends WP_Widget { require_once plugin_dir_path( realpath( dirname( __FILE__ ) . '/../shortcodes/slideshow.php' ) ) . 'slideshow.php'; - if ( ! class_exists( 'Jetpack_Slideshow_Shortcode' ) ) + if ( ! class_exists( 'Jetpack_Slideshow_Shortcode' ) ) { return; + } - if ( count( $instance['attachments'] ) < 1 ) + if ( count( $instance['attachments'] ) < 1 ) { return; + } $slideshow = new Jetpack_Slideshow_Shortcode(); $slideshow->enqueue_scripts(); - $gallery_instance = "widget-" . $args['widget_id']; + $gallery_instance = 'widget-' . $args['widget_id']; $gallery = array(); @@ -252,33 +259,34 @@ class Jetpack_Gallery_Widget extends WP_Widget { $attachment_image_src = wp_get_attachment_image_src( $attachment->ID, 'full' ); $attachment_image_src = jetpack_photon_url( $attachment_image_src[0], array( 'w' => $this->_instance_width ) ); // [url, width, height] - $caption = wptexturize( strip_tags( $attachment->post_excerpt ) ); + $caption = wptexturize( strip_tags( $attachment->post_excerpt ) ); - $gallery[] = (object) array( + $gallery[] = (object) array( 'src' => (string) esc_url_raw( $attachment_image_src ), 'id' => (string) $attachment->ID, 'caption' => (string) $caption, ); } - $max_width = intval( get_option( 'large_size_w' ) ); + $max_width = intval( get_option( 'large_size_w' ) ); $max_height = 175; - if ( intval( $content_width ) > 0 ) + if ( intval( $content_width ) > 0 ) { $max_width = min( intval( $content_width ), $max_width ); + } - $color = Jetpack_Options::get_option( 'slideshow_background_color', 'black' ); + $color = Jetpack_Options::get_option( 'slideshow_background_color', 'black' ); $autostart = isset( $attr['autostart'] ) ? $attr['autostart'] : true; $js_attr = array( - 'gallery' => $gallery, - 'selector' => $gallery_instance, - 'width' => $max_width, - 'height' => $max_height, - 'trans' => 'fade', - 'color' => $color, + 'gallery' => $gallery, + 'selector' => $gallery_instance, + 'width' => $max_width, + 'height' => $max_height, + 'trans' => 'fade', + 'color' => $color, 'autostart' => $autostart, - ); + ); $html = $slideshow->slideshow_js( $js_attr ); @@ -300,10 +308,10 @@ class Jetpack_Gallery_Widget extends WP_Widget { } public function form( $instance ) { - $defaults = $this->defaults(); - $allowed_values = $this->allowed_values(); + $defaults = $this->defaults(); + $allowed_values = $this->allowed_values(); - $instance = wp_parse_args( (array) $instance, $defaults ); + $instance = wp_parse_args( (array) $instance, $defaults ); include dirname( __FILE__ ) . '/gallery/templates/form.php'; } @@ -325,7 +333,7 @@ class Jetpack_Gallery_Widget extends WP_Widget { */ public function sanitize( $instance ) { $allowed_values = $this->allowed_values(); - $defaults = $this->defaults(); + $defaults = $this->defaults(); foreach ( $instance as $key => $value ) { $value = trim( $value ); @@ -356,18 +364,18 @@ class Jetpack_Gallery_Widget extends WP_Widget { $allowed_columns = array_combine( range( 1, $max_columns ), range( 1, $max_columns ) ); return array( - 'type' => array( - 'rectangular' => __( 'Tiles', 'jetpack' ), - 'square' => __( 'Square Tiles', 'jetpack' ), - 'circle' => __( 'Circles', 'jetpack' ), - 'slideshow' => __( 'Slideshow', 'jetpack' ), + 'type' => array( + 'rectangular' => __( 'Tiles', 'jetpack' ), + 'square' => __( 'Square Tiles', 'jetpack' ), + 'circle' => __( 'Circles', 'jetpack' ), + 'slideshow' => __( 'Slideshow', 'jetpack' ), + ), + 'columns' => $allowed_columns, + 'link' => array( + 'carousel' => __( 'Carousel', 'jetpack' ), + 'post' => __( 'Attachment Page', 'jetpack' ), + 'file' => __( 'Media File', 'jetpack' ), ), - 'columns' => $allowed_columns, - 'link' => array( - 'carousel' => __( 'Carousel', 'jetpack' ), - 'post' => __( 'Attachment Page', 'jetpack' ), - 'file' => __( 'Media File', 'jetpack' ), - ) ); } @@ -381,11 +389,11 @@ class Jetpack_Gallery_Widget extends WP_Widget { */ public function defaults() { return array( - 'title' => '', - 'type' => 'rectangular', - 'ids' => '', - 'columns' => 3, - 'link' => 'carousel' + 'title' => '', + 'type' => 'rectangular', + 'ids' => '', + 'columns' => 3, + 'link' => 'carousel', ); } @@ -415,13 +423,13 @@ class Jetpack_Gallery_Widget extends WP_Widget { ), array( 'media-models', - 'media-views' + 'media-views', ), '20150501' ); $js_settings = array( - 'thumbSize' => self::THUMB_SIZE + 'thumbSize' => self::THUMB_SIZE, ); wp_localize_script( 'gallery-widget-admin', '_wpGalleryWidgetAdminSettings', $js_settings ); @@ -449,7 +457,8 @@ function jetpack_gallery_widget_init() { && Jetpack_Options::get_option( 'gallery_widget_migration' ) ) { return; - } - if ( ! method_exists( 'Jetpack', 'is_module_active' ) || Jetpack::is_module_active( 'tiled-gallery' ) ) + } + if ( ! method_exists( 'Jetpack', 'is_module_active' ) || Jetpack::is_module_active( 'tiled-gallery' ) ) { register_widget( 'Jetpack_Gallery_Widget' ); + } } |