| @@ -1,9 +1,5 @@ | ||
| 1 | 1 | <?php //phpcs:ignore WordPress.Files.FileName.InvalidClassFileName |
| 2 | - | |
| 3 | -use Automattic\Jetpack\Assets; | |
| 4 | -use Automattic\Jetpack\Extensions\Slideshow; | |
| 5 | - | |
| 6 | 2 | /** |
| 7 | 3 | * Slideshow shortcode. |
| 8 | 4 | * Adds a new "slideshow" gallery type when adding a gallery using the classic editor. |
| 9 | 5 | * |
| @@ -9,10 +5,19 @@ | ||
| 9 | 5 | * |
| 10 | 6 | * @package automattic/jetpack |
| 11 | 7 | */ |
| 12 | 8 | |
| 9 | +use Automattic\Jetpack\Assets; | |
| 10 | +use Automattic\Jetpack\Extensions\Slideshow; | |
| 11 | + | |
| 12 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 13 | + exit( 0 ); | |
| 14 | +} | |
| 15 | + | |
| 13 | 16 | /** |
| 14 | 17 | * Slideshow shortcode usage: [gallery type="slideshow"] or the older [slideshow] |
| 18 | + * | |
| 19 | + * @phan-constructor-used-for-side-effects | |
| 15 | 20 | */ |
| 16 | 21 | class Jetpack_Slideshow_Shortcode { |
| 17 | 22 | /** |
| 18 | 23 | * Number of slideshows on a page. |
| @@ -138,9 +143,9 @@ | ||
| 138 | 143 | |
| 139 | 144 | $gallery = array(); |
| 140 | 145 | foreach ( $attachments as $attachment ) { |
| 141 | 146 | $attachment_image_src = wp_get_attachment_image_src( $attachment->ID, $attr['size'] ); |
| 142 | - $attachment_image_src = $attachment_image_src[0]; // [url, width, height]. | |
| 147 | + $attachment_image_src = false !== $attachment_image_src ? $attachment_image_src[0] : ''; // [url, width, height]. | |
| 143 | 148 | $attachment_image_title = get_the_title( $attachment->ID ); |
| 144 | 149 | $attachment_image_alt = get_post_meta( $attachment->ID, '_wp_attachment_image_alt', true ); |
| 145 | 150 | /** |
| 146 | 151 | * Filters the Slideshow slide caption. |
| @@ -182,9 +187,12 @@ | ||
| 182 | 187 | esc_html__( 'Click to view slideshow.', 'jetpack' ) |
| 183 | 188 | ); |
| 184 | 189 | } |
| 185 | 190 | |
| 186 | - if ( class_exists( 'Jetpack_AMP_Support' ) && Jetpack_AMP_Support::is_amp_request() ) { | |
| 191 | + if ( | |
| 192 | + class_exists( 'Jetpack_AMP_Support' ) | |
| 193 | + && Jetpack_AMP_Support::is_amp_request() | |
| 194 | + ) { | |
| 187 | 195 | // Load the styles and use the rendering method from the Slideshow block. |
| 188 | 196 | Jetpack_Gutenberg::load_styles_as_required( 'slideshow' ); |
| 189 | 197 | |
| 190 | 198 | $amp_args = array( |
| @@ -194,8 +202,18 @@ | ||
| 194 | 202 | if ( 'true' == $autostart ) { // phpcs:ignore Universal.Operators.StrictComparisons.LooseEqual -- attribute can be stored as boolean or string. |
| 195 | 203 | $amp_args['autoplay'] = true; |
| 196 | 204 | } |
| 197 | 205 | |
| 206 | + /* | |
| 207 | + * Blocks can be disabled in Jetpack Settings. | |
| 208 | + * If that's the case, we need to include the slideshow block manually. | |
| 209 | + * render_amp() lives in the block's render.php, which is loaded lazily, | |
| 210 | + * so make sure it is available before calling it. | |
| 211 | + */ | |
| 212 | + if ( ! function_exists( 'Automattic\Jetpack\Extensions\Slideshow\render_amp' ) ) { | |
| 213 | + require_once JETPACK__PLUGIN_DIR . 'extensions/blocks/slideshow/render.php'; | |
| 214 | + } | |
| 215 | + | |
| 198 | 216 | return Slideshow\render_amp( $amp_args ); |
| 199 | 217 | } |
| 200 | 218 | |
| 201 | 219 | return $this->slideshow_js( $js_attr ); |
| @@ -247,13 +265,20 @@ | ||
| 247 | 265 | * Actually enqueues the scripts and styles. |
| 248 | 266 | */ |
| 249 | 267 | public function enqueue_scripts() { |
| 250 | 268 | |
| 251 | - wp_enqueue_script( 'jquery-cycle', plugins_url( '/js/jquery.cycle.min.js', __FILE__ ), array( 'jquery' ), '20161231', true ); | |
| 269 | + wp_register_script( | |
| 270 | + 'jetpack-shortcode-deps', | |
| 271 | + plugins_url( '_inc/build/shortcodes/js/dependencies.min.js', JETPACK__PLUGIN_FILE ), | |
| 272 | + array( 'jquery' ), | |
| 273 | + '20250905', | |
| 274 | + true | |
| 275 | + ); | |
| 276 | + | |
| 252 | 277 | wp_enqueue_script( |
| 253 | 278 | 'jetpack-slideshow', |
| 254 | 279 | Assets::get_file_url_for_environment( '_inc/build/shortcodes/js/slideshow-shortcode.min.js', 'modules/shortcodes/js/slideshow-shortcode.js' ), |
| 255 | - array( 'jquery', 'jquery-cycle' ), | |
| 280 | + array( 'jquery', 'jetpack-shortcode-deps' ), | |
| 256 | 281 | '20160119.1', |
| 257 | 282 | true |
| 258 | 283 | ); |
| 259 | 284 | wp_enqueue_style( |
| @@ -263,8 +288,9 @@ | ||
| 263 | 288 | JETPACK__VERSION |
| 264 | 289 | ); |
| 265 | 290 | wp_style_add_data( 'jetpack-slideshow', 'rtl', 'replace' ); |
| 266 | 291 | |
| 292 | + require_once JETPACK__PLUGIN_DIR . '_inc/lib/class-jetpack-spinner.php'; | |
| 267 | 293 | wp_localize_script( |
| 268 | 294 | 'jetpack-slideshow', |
| 269 | 295 | 'jetpackSlideshowSettings', |
| 270 | 296 | /** |
| @@ -284,9 +310,9 @@ | ||
| 284 | 310 | */ |
| 285 | 311 | apply_filters( |
| 286 | 312 | 'jetpack_js_slideshow_settings', |
| 287 | 313 | array( |
| 288 | - 'spinner' => plugins_url( '/img/slideshow-loader.gif', __FILE__ ), | |
| 314 | + 'spinner' => 'data:image/svg+xml,' . rawurlencode( Jetpack_Spinner::render( 24 ) ), | |
| 289 | 315 | 'speed' => '4000', |
| 290 | 316 | 'label_prev' => __( 'Previous Slide', 'jetpack' ), |
| 291 | 317 | 'label_stop' => __( 'Pause Slideshow', 'jetpack' ), |
| 292 | 318 | 'label_next' => __( 'Next Slide', 'jetpack' ), |