PluginProbe ʕ •ᴥ•ʔ
Strong Testimonials / 3.2.8
Strong Testimonials v3.2.8
3.3.6 3.3.5 3.3.4 3.3.3 3.3.2 3.3.1 trunk 1.0.1 2.30.9 2.31.10 2.32 2.32.1 2.32.2 2.32.3 2.32.4 2.33 2.34 2.35 2.36 2.37 2.38 2.38.1 2.39 2.39.1 2.39.2 2.39.3 2.40.0 2.40.1 2.40.2 2.40.3 2.40.4 2.40.5 2.40.6 2.40.7 2.41.0 2.41.1 2.50.0 2.50.1 2.50.2 2.50.3 2.50.4 2.51.0 2.51.1 2.51.2 2.51.3 2.51.4 2.51.5 2.51.6 2.51.7 2.51.8 2.51.9 3.0.0 3.0.1 3.0.2 3.0.3 3.1.0 3.1.1 3.1.10 3.1.11 3.1.12 3.1.13 3.1.14 3.1.15 3.1.16 3.1.17 3.1.18 3.1.19 3.1.2 3.1.20 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 3.2.0 3.2.1 3.2.10 3.2.11 3.2.12 3.2.13 3.2.14 3.2.15 3.2.16 3.2.17 3.2.18 3.2.19 3.2.2 3.2.20 3.2.21 3.2.22 3.2.3 3.2.4 3.2.5 3.2.6 3.2.7 3.2.8 3.2.9 3.3.0
strong-testimonials / includes / class-strong-view-slideshow.php
strong-testimonials / includes Last commit date
elementor 1 year ago logs 1 year ago strong-testimonials-beaver-block 1 year ago submodules 1 year ago class-strong-gutemberg.php 1 year ago class-strong-log.php 1 year ago class-strong-mail.php 1 year ago class-strong-testimonials-average-shortcode.php 1 year ago class-strong-testimonials-count-shortcode.php 1 year ago class-strong-testimonials-form.php 1 year ago class-strong-testimonials-order.php 1 year ago class-strong-testimonials-privacy.php 1 year ago class-strong-testimonials-render.php 1 year ago class-strong-testimonials-templates.php 1 year ago class-strong-testimonials-view-shortcode.php 1 year ago class-strong-testimonials-view-widget.php 1 year ago class-strong-view-display.php 1 year ago class-strong-view-form.php 1 year ago class-strong-view-slideshow.php 1 year ago class-strong-view.php 1 year ago class-walker-strong-category-checklist-front.php 1 year ago deprecated.php 1 year ago filters.php 1 year ago functions-activation.php 1 year ago functions-content.php 1 year ago functions-image.php 1 year ago functions-rating.php 1 year ago functions-template-form.php 1 year ago functions-template.php 1 year ago functions-views.php 1 year ago functions.php 1 year ago l10n-polylang.php 1 year ago l10n-wpml.php 1 year ago post-types.php 1 year ago retro.php 1 year ago scripts.php 1 year ago
class-strong-view-slideshow.php
510 lines
1 <?php
2 /**
3 * View Slideshow Mode class.
4 *
5 * @since 2.16.0
6 */
7
8 // Exit if accessed directly
9 if ( ! defined( 'ABSPATH' ) ) {
10 exit;
11 }
12
13 if ( ! class_exists( 'Strong_View_Slideshow' ) ) :
14
15 class Strong_View_Slideshow extends Strong_View_Display {
16
17 /**
18 * Strong_View constructor.
19 *
20 * @param array $atts
21 */
22 public function __construct( $atts = array() ) {
23 parent::__construct( $atts );
24 }
25
26 /**
27 * Process the view.
28 *
29 * Used by main class to load the scripts and styles for this View.
30 */
31 public function process() {
32 $this->build_query();
33 $this->build_classes();
34
35 $this->find_stylesheet();
36 $this->has_slideshow();
37 $this->has_stars();
38 $this->has_readmore();
39 $this->has_lazyload();
40
41 $this->load_extra_stylesheets();
42
43 // If we can preprocess, we can add the inline style in the <head>.
44 add_action( 'wp_enqueue_scripts', array( $this, 'add_custom_style' ), 20 );
45
46 do_action( 'wpmtst_view_processed' );
47 }
48
49 /**
50 * Build the view.
51 */
52 public function build() {
53 // May need to remove any hooks or filters that were set by other Views on the page.
54
55 do_action( 'wpmtst_view_build_before', $this );
56
57 $this->build_query();
58 $this->build_classes();
59
60 $this->find_stylesheet();
61 $this->has_slideshow();
62 $this->has_stars();
63 $this->has_readmore();
64
65 $this->load_dependent_scripts();
66 $this->load_extra_stylesheets();
67
68 // If we cannot preprocess, add the inline style to the footer.
69 add_action( 'wp_footer', array( $this, 'add_custom_style' ) );
70
71 /**
72 * Add filters.
73 */
74 $this->add_content_filters();
75 add_filter( 'get_avatar', 'wpmtst_get_avatar', 10, 3 );
76 add_filter( 'embed_defaults', 'wpmtst_embed_size', 10, 2 );
77
78 /**
79 * Add actions.
80 */
81
82 // Read more page
83 add_action( $this->atts['more_page_hook'], 'wpmtst_read_more_page' );
84
85 /**
86 * Locate template.
87 */
88 $this->template_file = apply_filters( 'wpmtst_view_template_file_slideshow', WPMST()->templates->get_template_attr( $this->atts, 'template' ) );
89
90 /**
91 * Allow add-ons to hijack the output generation.
92 */
93 $query = $this->query;
94 $atts = $this->atts;
95 if ( has_filter( 'wpmtst_render_view_template' ) ) {
96 $html = apply_filters( 'wpmtst_render_view_template', '', $this );
97 } else {
98
99 /**
100 * Gutenberg. Yay.
101 * @since 2.31.9
102 */
103 global $post;
104 $post_before = $post;
105
106 ob_start();
107 /** @noinspection PhpIncludeInspection */
108 include $this->template_file;
109 $html = ob_get_clean();
110
111 $post = $post_before;
112
113 }
114
115 /**
116 * Remove filters.
117 */
118 $this->remove_content_filters();
119 remove_filter( 'get_avatar', 'wpmtst_get_avatar' );
120 remove_filter( 'embed_defaults', 'wpmtst_embed_size' );
121
122 /**
123 * Remove actions.
124 */
125 remove_action( $this->atts['more_page_hook'], 'wpmtst_read_more_page' );
126
127 /**
128 * Hook to enqueue scripts.
129 */
130 do_action( 'wpmtst_view_rendered', $this->atts );
131
132 wp_reset_postdata();
133
134 $this->html = apply_filters( 'strong_view_html', $html, $this );
135 }
136
137 /**
138 * Build class list based on view attributes.
139 *
140 * This must happen after the query.
141 * TODO DRY
142 */
143 public function build_classes() {
144 $options = get_option( 'wpmtst_view_options' );
145
146 $container_class_list = array( 'strong-view-id-' . $this->atts['view'] );
147 $container_class_list = array_merge( $container_class_list, $this->get_template_css_class() );
148
149 if ( is_rtl() ) {
150 $container_class_list[] = 'rtl';
151 }
152
153 if ( $this->atts['class'] ) {
154 $container_class_list[] = $this->atts['class'];
155 }
156
157 $container_data_list = array(
158 'count' => $this->post_count,
159 );
160
161 $content_class_list = array();
162
163 $post_class_list = array( 'wpmtst-testimonial testimonial' );
164
165 if ( 'excerpt' === $this->atts['content'] ) {
166 $post_class_list[] = 'excerpt';
167 }
168
169 /**
170 * Slideshow
171 */
172 $settings = $this->atts['slideshow_settings'];
173
174 $container_class_list[] = 'slider-container';
175
176 if ( 'show_multiple' === $settings['type'] ) {
177 $container_class_list[] = 'carousel';
178 }
179
180 $container_class_list[] = 'slider-mode-' . $settings['effect'];
181
182 if ( $settings['adapt_height'] ) {
183 $container_class_list[] = 'slider-adaptive';
184 } elseif ( $settings['stretch'] ) {
185 $container_class_list[] = 'slider-stretch';
186 }
187
188 $nav_methods = $options['slideshow_nav_method'];
189 $nav_styles = $options['slideshow_nav_style'];
190 $control = $settings['controls_type'];
191 $control_style = $settings['controls_style'];
192 $pager = $settings['pager_type'];
193 $pager_style = $settings['pager_style'];
194
195 // Controls
196 if ( isset( $nav_methods['controls'][ $control ]['class'] ) && $nav_methods['controls'][ $control ]['class'] ) {
197 if ( 'sides' === $control ) {
198 if ( 'show_single' === $settings['type'] ) {
199 $container_class_list[] = $nav_methods['controls'][ $control ]['class'];
200 } else {
201 $container_class_list[] = $nav_methods['controls'][ $control ]['class'] . '-outside';
202 }
203 }
204 }
205
206 if ( 'none' !== $control ) {
207 if ( isset( $nav_styles['controls'][ $control_style ]['class'] ) && $nav_styles['controls'][ $control_style ]['class'] ) {
208 $container_class_list[] = $nav_styles['controls'][ $control_style ]['class'];
209 }
210 }
211
212 // Pager
213 if ( isset( $nav_methods['pager'][ $pager ]['class'] ) && $nav_methods['pager'][ $pager ]['class'] ) {
214 $container_class_list[] = $nav_methods['pager'][ $pager ]['class'];
215 }
216
217 if ( 'none' !== $pager ) {
218 if ( isset( $nav_styles['pager'][ $pager_style ]['class'] ) && $nav_styles['pager'][ $pager_style ]['class'] ) {
219 $container_class_list[] = $nav_styles['pager'][ $pager_style ]['class'];
220 }
221 }
222
223 // Position
224 // TODO Simplify logic.
225 if ( 'none' !== $pager || ( 'none' !== $control && 'sides' !== $control ) ) {
226 if ( 'show_multiple' === $settings['type'] ) {
227 $settings['nav_position'] = 'outside';
228 }
229 $container_class_list[] = 'nav-position-' . $settings['nav_position'];
230 }
231
232 $container_data_list['slider-var'] = $this->slideshow_signature();
233 $container_data_list['state'] = 'idle';
234
235 $content_class_list[] = 'wpmslider-content';
236
237 $post_class_list[] = 't-slide';
238
239 /**
240 * Filter classes.
241 */
242 $this->atts['container_data'] = apply_filters( 'wpmtst_view_container_data', $container_data_list, $this->atts );
243 $this->atts['container_class'] = implode( ' ', apply_filters( 'wpmtst_view_container_class', array_filter( $container_class_list ), $this->atts ) );
244 $this->atts['content_class'] = implode( ' ', apply_filters( 'wpmtst_view_content_class', array_filter( $content_class_list ), $this->atts ) );
245 $this->atts['post_class'] = implode( ' ', apply_filters( 'wpmtst_view_post_class', array_filter( $post_class_list ), $this->atts ) );
246
247 /**
248 * Store updated atts.
249 */
250 WPMST()->set_atts( $this->atts );
251 }
252
253 /**
254 * Slideshow
255 *
256 * @since 2.16.0 In Strong_View class.
257 */
258 public function has_slideshow() {
259
260 $settings = $this->atts['slideshow_settings'];
261 $not_full_controls = ( 'none' !== $settings['controls_type'] || 'full' !== $settings['controls_type'] );
262
263 /*
264 * Controls with or without Pagination
265 */
266 if ( isset( $settings['controls_type'] ) && 'none' !== $settings['controls_type'] ) {
267
268 $controls_type = $settings['controls_type'];
269 if ( 'sides' === $controls_type && 'show_multiple' === $settings['type'] ) {
270 $controls_type .= '-outside';
271 }
272
273 $filename = 'slider-controls-' . $controls_type . '-' . $settings['controls_style'];
274
275 if ( 'full' !== $settings['controls_type'] ) {
276 if ( isset( $settings['pager_style'] ) && 'none' !== $settings['pager_type'] ) {
277 $filename .= '-pager-' . $settings['pager_style'];
278 }
279 }
280
281 if ( file_exists( WPMTST_PUBLIC . "css/$filename.css" ) ) {
282 wp_register_style( "wpmtst-$filename", WPMTST_PUBLIC_URL . "css/$filename.css", array(), $this->plugin_version );
283 WPMST()->render->add_style( "wpmtst-$filename" );
284 }
285 } elseif ( $not_full_controls ) {
286
287 /*
288 * Pagination only
289 */
290 if ( isset( $settings['pager_type'] ) && 'none' !== $settings['pager_type'] ) {
291
292 //TODO Adapt for multiple pager types (only one right now).
293 $filename = 'slider-pager-' . $settings['pager_style'];
294
295 if ( file_exists( WPMTST_PUBLIC . "css/$filename.css" ) ) {
296 wp_register_style( "wpmtst-$filename", WPMTST_PUBLIC_URL . "css/$filename.css", array(), $this->plugin_version );
297 WPMST()->render->add_style( "wpmtst-$filename" );
298 }
299 }
300 }
301
302 WPMST()->render->add_script( 'wpmtst-slider' );
303 WPMST()->render->add_script_var( 'wpmtst-slider', $this->slideshow_signature(), $this->slideshow_args() );
304 WPMST()->render->add_script( 'wpmtst-controller' );
305 }
306
307 /**
308 * Create unique slideshow signature.
309 *
310 * @since 2.7.0
311 * @private
312 *
313 * @return string
314 */
315 private function slideshow_signature() {
316 return 'strong_slider_id_' . $this->atts['view'];
317 }
318
319 /**
320 * Assemble slideshow settings.
321 *
322 * @since 2.7.0
323 * @private
324 *
325 * @return array
326 */
327 private function slideshow_args() {
328 $options = get_option( 'wpmtst_options' );
329 $view_options = apply_filters( 'wpmtst_view_options', get_option( 'wpmtst_view_options' ) );
330 $compat_options = get_option( 'wpmtst_compat_options' );
331
332 /**
333 * Compatibility with lazy loading and use of imagesLoaded.
334 *
335 * @since 2.31.0 As user-configurable.
336 */
337 $compat = array();
338 $enabled = false;
339 $pairs = array();
340
341 // Presets
342 // Flatsome theme
343 if ( class_exists( 'FL_LazyLoad_Images' ) && get_theme_mod( 'lazy_load_images' ) ) {
344 $enabled = true;
345 $pairs[] = array(
346 'start' => 'lazy-load',
347 'finish' => '',
348 );
349 }
350
351 // User settings
352 if ( $compat_options['lazyload']['enabled'] ) {
353 $enabled = true;
354 foreach ( $compat_options['lazyload']['classes'] as $key => $pair ) {
355 $pairs[] = $pair;
356 }
357 }
358
359 // Bring together the presets and user settings.
360 $compat['lazyload'] = array(
361 'active' => $enabled,
362 'classes' => $pairs,
363 );
364
365 // Convert breakpoint variable names
366 // TODO Refactor to make this unnecessary.
367 $new_breakpoints = array();
368
369 // Fallback
370 $new_breakpoints['single'] = array(
371 'maxSlides' => $this->atts['slideshow_settings']['show_single']['max_slides'],
372 'moveSlides' => $this->atts['slideshow_settings']['show_single']['move_slides'],
373 'slideMargin' => $this->atts['slideshow_settings']['show_single']['margin'],
374 );
375
376 $breakpoints = $this->atts['slideshow_settings']['breakpoints'];
377 foreach ( $breakpoints as $key => $breakpoint ) {
378 $new_breakpoints['multiple'][ $key ] = array(
379 'width' => $breakpoints[ $key ]['width'],
380 'maxSlides' => $breakpoints[ $key ]['max_slides'],
381 'moveSlides' => $breakpoints[ $key ]['move_slides'],
382 'slideMargin' => $breakpoints[ $key ]['margin'],
383 );
384 }
385
386 $args = array(
387 'mode' => isset( $this->atts['slideshow_settings']['effect'] ) ? $this->atts['slideshow_settings']['effect'] : 'fade',
388 'speed' => isset( $this->atts['slideshow_settings']['speed'] ) ? $this->atts['slideshow_settings']['speed'] * 1000 : 1000,
389 'pause' => isset( $this->atts['slideshow_settings']['pause'] ) ? $this->atts['slideshow_settings']['pause'] * 1000 : 8000,
390 'autoHover' => ( isset( $this->atts['slideshow_settings']['auto_hover'] ) && $this->atts['slideshow_settings']['auto_hover'] ) ? 1 : 0,
391 'autoStart' => ( isset( $this->atts['slideshow_settings']['auto_start'] ) && $this->atts['slideshow_settings']['auto_start'] ) ? 1 : 0,
392 'infiniteLoop' => ( isset( $this->atts['slideshow_settings']['continuous_sliding'] ) && $this->atts['slideshow_settings']['continuous_sliding'] ) ? 1 : 0,
393 'stopAutoOnClick' => ( isset( $this->atts['slideshow_settings']['stop_auto_on_click'] ) && $this->atts['slideshow_settings']['stop_auto_on_click'] ) ? 1 : 0,
394 'adaptiveHeight' => ( isset( $this->atts['slideshow_settings']['adapt_height'] ) && $this->atts['slideshow_settings']['adapt_height'] ) ? 1 : 0,
395 'adaptiveHeightSpeed' => isset( $this->atts['slideshow_settings']['adapt_height_speed'] ) ? $this->atts['slideshow_settings']['adapt_height_speed'] * 1000 : 500,
396 'controls' => 0,
397 'autoControls' => 0,
398 'pager' => 0,
399 'slideCount' => $this->post_count,
400 'debug' => defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG && apply_filters( 'debug_strong_slider', true ),
401 'compat' => $compat,
402 'touchEnabled' => $options['touch_enabled'],
403 'type' => isset( $this->atts['slideshow_settings']['type'] ) ? $this->atts['slideshow_settings']['type'] : 'show_single',
404 'breakpoints' => $new_breakpoints,
405 );
406
407 if ( ! $this->atts['slideshow_settings']['adapt_height'] ) {
408 $args['stretch'] = $this->atts['slideshow_settings']['stretch'] ? 1 : 0;
409 }
410
411 /**
412 * Controls
413 */
414 $options = $view_options['slideshow_nav_method']['controls'];
415 $control_setting = $this->atts['slideshow_settings']['controls_type'];
416 if ( ! $control_setting ) {
417 $control_setting = 'none';
418 }
419 if ( isset( $options[ $control_setting ] ) && isset( $options[ $control_setting ]['args'] ) ) {
420 $args['controls'] = 1;
421 $args = array_merge( $args, $options[ $control_setting ]['args'] );
422 }
423
424 if ( 'none' !== $control_setting ) {
425 $options = $view_options['slideshow_nav_style']['controls'];
426 $setting = $this->atts['slideshow_settings']['controls_style'];
427 if ( ! $setting ) {
428 $setting = 'none';
429 }
430
431 /**
432 * Quick fix for ticket 12014 to translate slider text controls.
433 * TODO Refactor; see fix-i18n branch in translations.strong.test.
434 *
435 * @since 2.32.1
436 */
437 if ( 'text' === $setting ) {
438 $options['text']['args'] = array(
439 'startText' => esc_html_x( 'Play', 'slideshow control', 'strong-testimonials' ),
440 'stopText' => esc_html_x( 'Pause', 'slideshow control', 'strong-testimonials' ),
441 'prevText' => esc_html_x( 'Previous', 'slideshow_control', 'strong-testimonials' ),
442 'nextText' => esc_html_x( 'Next', 'slideshow_control', 'strong-testimonials' ),
443 );
444 }
445
446 if ( isset( $options[ $setting ] ) && isset( $options[ $setting ]['args'] ) ) {
447 $args = array_merge( $args, $options[ $setting ]['args'] );
448 }
449 }
450
451 /**
452 * Pager
453 */
454 $options = $view_options['slideshow_nav_method']['pager'];
455 $pager_setting = $this->atts['slideshow_settings']['pager_type'];
456 if ( ! $pager_setting ) {
457 $pager_setting = 'none';
458 }
459 if ( isset( $options[ $pager_setting ] ) && isset( $options[ $pager_setting ]['args'] ) ) {
460 $args = array_merge( $args, $options[ $pager_setting ]['args'] );
461 }
462
463 if ( 'none' !== $pager_setting ) {
464 $options = $view_options['slideshow_nav_style']['pager'];
465 $setting = $this->atts['slideshow_settings']['pager_style'];
466 if ( ! $setting ) {
467 $setting = 'none';
468 }
469 if ( isset( $options[ $setting ] ) && isset( $options[ $setting ]['args'] ) ) {
470 $args['pager'] = 1;
471 $args = array_merge( $args, $options[ $setting ]['args'] );
472 }
473 }
474
475 $args['nextUrl'] = __( 'next-slide', 'strong-testimonials' );
476 $args['prevUrl'] = __( 'previous-slide', 'strong-testimonials' );
477
478 return array( 'config' => apply_filters( 'wpmtst_slider_args', $args, $this->atts ) );
479 }
480
481 /**
482 * Lazy Load
483 *
484 * @since 2.40.4
485 */
486 public function has_lazyload() {
487 if ( ! function_exists( 'wp_lazy_loading_enabled' ) || ! apply_filters( 'wp_lazy_loading_enabled', true, 'img', 'strong_testimonials_has_lazyload' ) ) {
488 $options = get_option( 'wpmtst_options' );
489 if ( isset( $options['lazyload'] ) && $options['lazyload'] ) {
490 WPMST()->render->add_style( 'wpmtst-lazyload-css' );
491 WPMST()->render->add_script( 'wpmtst-lozad' );
492 WPMST()->render->add_script( 'wpmtst-lozad-load' );
493 }
494 }
495 }
496
497 /**
498 * Overwrites inherited method preventing pagination for slider type.
499 *
500 * @param $args
501 *
502 * @return array
503 */
504 public function query_pagination( $args ) {
505 return $args;
506 }
507 }
508
509 endif;
510