diff options
Diffstat (limited to 'plugins/jetpack/modules/tiled-gallery/tiled-gallery.php')
-rw-r--r-- | plugins/jetpack/modules/tiled-gallery/tiled-gallery.php | 133 |
1 files changed, 98 insertions, 35 deletions
diff --git a/plugins/jetpack/modules/tiled-gallery/tiled-gallery.php b/plugins/jetpack/modules/tiled-gallery/tiled-gallery.php index 768f8749..fcb5d89e 100644 --- a/plugins/jetpack/modules/tiled-gallery/tiled-gallery.php +++ b/plugins/jetpack/modules/tiled-gallery/tiled-gallery.php @@ -1,31 +1,51 @@ -<?php +<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName use Automattic\Jetpack\Assets; use Automattic\Jetpack\Status; // Include the class file containing methods for rounding constrained array elements. // Here the constrained array element is the dimension of a row, group or an image in the tiled gallery. -require_once dirname( __FILE__ ) . '/math/class-constrained-array-rounding.php'; +require_once __DIR__ . '/math/class-constrained-array-rounding.php'; // Layouts -require_once dirname( __FILE__ ) . '/tiled-gallery/tiled-gallery-rectangular.php'; -require_once dirname( __FILE__ ) . '/tiled-gallery/tiled-gallery-square.php'; -require_once dirname( __FILE__ ) . '/tiled-gallery/tiled-gallery-circle.php'; +require_once __DIR__ . '/tiled-gallery/tiled-gallery-rectangular.php'; +require_once __DIR__ . '/tiled-gallery/tiled-gallery-square.php'; +require_once __DIR__ . '/tiled-gallery/tiled-gallery-circle.php'; +/** + * Jetpack tiled gallery class. + */ class Jetpack_Tiled_Gallery { + /** + * Supported gallery design types. + * + * @var array + */ private static $talaveras = array( 'rectangular', 'square', 'circle', 'rectangle', 'columns' ); + /** + * Class constructor. + */ public function __construct() { add_action( 'admin_init', array( $this, 'settings_api_init' ) ); add_filter( 'jetpack_gallery_types', array( $this, 'jetpack_gallery_types' ), 9 ); add_filter( 'jetpack_default_gallery_type', array( $this, 'jetpack_default_gallery_type' ) ); } + /** + * Check whether tiling is enabled. + * + * @return bool + */ public function tiles_enabled() { - // Check the setting status - return '' != Jetpack_Options::get_option_and_ensure_autoload( 'tiled_galleries', '' ); + return '' !== Jetpack_Options::get_option_and_ensure_autoload( 'tiled_galleries', '' ); } + /** + * Set attributes. + * + * @param array $atts - the attributes. + */ public function set_atts( $atts ) { global $post; @@ -49,8 +69,8 @@ class Jetpack_Tiled_Gallery { $this->float = is_rtl() ? 'right' : 'left'; // Default to rectangular is tiled galleries are checked - if ( $this->tiles_enabled() && ( ! $this->atts['type'] || 'default' == $this->atts['type'] ) ) { - /** This filter is already documented in functions.gallery.php */ + if ( $this->tiles_enabled() && ( ! $this->atts['type'] || 'default' === $this->atts['type'] ) ) { + /** This filter is already documented in class-jetpack-gallery-settings.php */ $this->atts['type'] = apply_filters( 'jetpack_default_gallery_type', 'rectangular' ); } @@ -61,7 +81,7 @@ class Jetpack_Tiled_Gallery { } } - if ( 'rand' == strtolower( $this->atts['order'] ) ) { + if ( 'rand' === strtolower( $this->atts['order'] ) ) { $this->atts['orderby'] = 'rand'; } @@ -71,6 +91,11 @@ class Jetpack_Tiled_Gallery { } } + /** + * Get the media attachments. + * + * @return WP_Post[] + */ public function get_attachments() { $atts = $this->atts; @@ -130,6 +155,9 @@ class Jetpack_Tiled_Gallery { return $attachments; } + /** + * Enqueue the default scripts and styles. + */ public static function default_scripts_and_styles() { wp_enqueue_script( 'tiled-gallery', @@ -137,19 +165,27 @@ class Jetpack_Tiled_Gallery { '_inc/build/tiled-gallery/tiled-gallery/tiled-gallery.min.js', 'modules/tiled-gallery/tiled-gallery/tiled-gallery.js' ), - array() + array(), + JETPACK__VERSION, + false ); wp_enqueue_style( 'tiled-gallery', plugins_url( 'tiled-gallery/tiled-gallery.css', __FILE__ ), array(), '2012-09-21' ); wp_style_add_data( 'tiled-gallery', 'rtl', 'replace' ); } + /** + * The gallery shortcode. + * + * @param mixed $val - the value. + * @param array $atts - the attributes. + * + * @return string + */ public function gallery_shortcode( $val, $atts ) { if ( ! empty( $val ) ) { // something else is overriding post_gallery, like a custom VIP shortcode return $val; } - global $post; - $this->set_atts( $atts ); $attachments = $this->get_attachments(); @@ -161,21 +197,18 @@ class Jetpack_Tiled_Gallery { return ''; } - if ( - in_array( - $this->atts['type'], - /** - * Filters the permissible Tiled Gallery types. - * - * @module tiled-gallery - * - * @since 3.7.0 - * - * @param array Array of allowed types. Default: 'rectangular', 'square', 'circle', 'rectangle', 'columns'. - */ - $talaveras = apply_filters( 'jetpack_tiled_gallery_types', self::$talaveras ) - ) - ) { + /** + * Filters the permissible Tiled Gallery types. + * + * @module tiled-gallery + * + * @since 3.7.0 + * + * @param array Array of allowed types. Default: 'rectangular', 'square', 'circle', 'rectangle', 'columns'. + */ + $talaveras = apply_filters( 'jetpack_tiled_gallery_types', self::$talaveras ); + + if ( in_array( $this->atts['type'], $talaveras, true ) ) { // Enqueue styles and scripts self::default_scripts_and_styles(); @@ -198,6 +231,11 @@ class Jetpack_Tiled_Gallery { return ''; } + /** + * See if gallery is already defined. + * + * @return bool + */ public static function gallery_already_redefined() { global $shortcode_tags; $redefined = false; @@ -218,6 +256,9 @@ class Jetpack_Tiled_Gallery { return apply_filters( 'jetpack_tiled_gallery_shortcode_redefined', $redefined ); } + /** + * Initialize the tiled gallery. + */ public static function init() { if ( self::gallery_already_redefined() ) { return; @@ -227,6 +268,11 @@ class Jetpack_Tiled_Gallery { add_filter( 'post_gallery', array( $gallery, 'gallery_shortcode' ), 1001, 2 ); } + /** + * Get the width of the gallery. + * + * @return int + */ public static function get_content_width() { $tiled_gallery_content_width = Jetpack::get_content_width(); @@ -248,8 +294,12 @@ class Jetpack_Tiled_Gallery { /** * Media UI integration + * + * @param array $types - the type of gallery. + * + * @return array */ - function jetpack_gallery_types( $types ) { + public function jetpack_gallery_types( $types ) { if ( get_option( 'tiled_galleries' ) && isset( $types['default'] ) ) { // Tiled is set as the default, meaning that type='default' // will still display the mosaic. @@ -265,11 +315,21 @@ class Jetpack_Tiled_Gallery { return $types; } - function jetpack_default_gallery_type() { + /** + * Get the default gallery type. + * + * @return string + */ + public function jetpack_default_gallery_type() { return ( get_option( 'tiled_galleries' ) ? 'rectangular' : 'default' ); } - static function get_talaveras() { + /** + * Get the talaveras. + * + * @return array + */ + public static function get_talaveras() { return self::$talaveras; } @@ -277,7 +337,7 @@ class Jetpack_Tiled_Gallery { * Add a checkbox field to the Carousel section in Settings > Media * for setting tiled galleries as the default. */ - function settings_api_init() { + public function settings_api_init() { global $wp_settings_sections; // Add the setting field [tiled_galleries] and place it in Settings > Media @@ -291,10 +351,13 @@ class Jetpack_Tiled_Gallery { register_setting( 'media', 'tiled_galleries', 'esc_attr' ); } - function setting_html() { + /** + * Render the settings HTML. + */ + public function setting_html() { echo '<label><input name="tiled_galleries" type="checkbox" value="1" ' . - checked( 1, '' != get_option( 'tiled_galleries' ), false ) . ' /> ' . - __( 'Display all your gallery pictures in a cool mosaic.', 'jetpack' ) . '</br></label>'; + checked( 1, '' !== get_option( 'tiled_galleries' ), false ) . ' /> ' . + esc_html__( 'Display all your gallery pictures in a cool mosaic.', 'jetpack' ) . '</br></label>'; } } |