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.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.php
584 lines
1 <?php
2 /**
3 * View class.
4 *
5 * @since 2.3.0
6 */
7
8 // Exit if accessed directly
9 if ( ! defined( 'ABSPATH' ) ) {
10 exit;
11 }
12
13 if ( ! class_exists( 'Strong_View' ) ) :
14
15 class Strong_View {
16
17 /**
18 * The view settings.
19 *
20 * @var array
21 */
22 public $atts;
23
24 /**
25 * The query.
26 */
27 public $query;
28
29 /**
30 * The template file.
31 */
32 public $template_file;
33
34 /**
35 * The view output.
36 *
37 * @var string
38 */
39 public $html;
40
41 /**
42 * The plugin version.
43 *
44 * @var string
45 */
46 public $plugin_version;
47
48 /**
49 * The stylesheet handle. For adding inline style.
50 *
51 * @since 2.31.8
52 * @var string
53 */
54 public $stylesheet;
55
56 /**
57 * Strong_View constructor.
58 *
59 * @param array $atts
60 */
61 public function __construct( $atts = array() ) {
62 $this->atts = apply_filters( 'wpmtst_view_atts', $atts );
63 $this->plugin_version = get_option( 'wpmtst_plugin_version' );
64 }
65
66 /**
67 * Return a specific view attribute.
68 *
69 * @param $att
70 * @since 2.33.0
71 *
72 * @return mixed|null
73 */
74 public function get_att( $att ) {
75 return isset( $this->atts[ $att ] ) ? $this->atts[ $att ] : null;
76 }
77
78 /**
79 * Return our rendered template.
80 *
81 * @return string
82 */
83 public function output() {
84 return $this->html;
85 }
86
87 /**
88 * Warning message of view not found.
89 *
90 * @return string
91 */
92 public function nothing_found() {
93 ob_start();
94 ?>
95 <p style="color: #CD0000;">
96 <?php esc_html_e( 'No testimonials found. Check your view settings.', 'strong-testimonials' ); ?><br>
97 <span style="color: #777; font-size: 0.9em;"><?php esc_html_e( '(Only administrators see this message.)', 'strong-testimonials' ); ?></span>
98 </p>
99 <?php
100
101 return apply_filters( 'wpmtst_message_nothing_found', ob_get_clean() );
102 }
103
104 /**
105 * Process the view.
106 *
107 * Used by main class to load the scripts and styles for this View.
108 */
109 public function process() {}
110
111 /**
112 * Build the view.
113 */
114 public function build() {}
115
116 /**
117 * Add content filters.
118 */
119 public function add_content_filters() {
120
121 if ( 'truncated' === $this->get_att( 'content' ) ) {
122
123 // automatic excerpt
124
125 $this->excerpt_filters();
126
127 $this->hybrid_content();
128
129 add_filter( 'wpmtst_get_the_excerpt', 'wpmtst_bypass_excerpt', 1 );
130
131 if ( $this->get_att( 'more_post_ellipsis' ) ) {
132 add_filter( 'wpmtst_use_ellipsis', '__return_true' );
133 }
134 } elseif ( 'excerpt' === $this->get_att( 'content' ) ) {
135
136 // manual excerpt (if no excerpt then use automatic excerpt)
137
138 $this->excerpt_filters();
139
140 $this->hybrid_content();
141
142 if ( $this->get_att( 'more_full_post' ) ) {
143 add_filter( 'wpmtst_get_the_excerpt', array( $this, 'manual_excerpt_more' ), 20 );
144 }
145
146 if ( $this->get_att( 'more_post_ellipsis' ) ) {
147 add_filter( 'wpmtst_use_ellipsis', array( $this, 'has_no_excerpt' ) );
148 } else {
149 add_filter( 'wpmtst_use_ellipsis', '__return_false' );
150 }
151 } else {
152
153 // full content
154 add_filter( 'wpmtst_get_the_content', 'wpmtst_the_content_filtered' );
155
156 }
157 }
158
159 /**
160 * Add excerpt filters.
161 *
162 * @since 2.33.0
163 */
164 public function excerpt_filters() {
165 add_filter( 'wpmtst_get_the_content', 'wpmtst_the_excerpt_filtered' );
166 add_filter( 'wpmtst_get_the_excerpt', 'wpmtst_trim_excerpt' );
167
168 if ( ! $this->get_att( 'use_default_length' ) ) {
169 add_filter( 'excerpt_length', array( $this, 'excerpt_length' ), 999 );
170 }
171
172 if ( ! $this->get_att( 'use_default_more' ) ) {
173 add_filter( 'excerpt_more', array( $this, 'excerpt_more' ), 99999 );
174 }
175 }
176
177 /**
178 * Add hybrid content filters.
179 *
180 * @since 2.33.0
181 */
182 public function hybrid_content() {
183 if ( $this->get_att( 'more_post_in_place' ) ) {
184 add_filter( 'wpmtst_is_hybrid_content', '__return_true' );
185 } else {
186 add_filter( 'wpmtst_read_more_post_link', 'wpmtst_prepend_ellipsis' );
187 }
188 }
189
190 /**
191 * Remove content filters.
192 *
193 * @since 2.33.0
194 */
195 public function remove_content_filters() {
196 remove_filter( 'wpmtst_get_the_content', 'wpmtst_the_content_filtered' );
197 remove_filter( 'wpmtst_get_the_content', 'wpmtst_the_excerpt_filtered' );
198
199 remove_filter( 'excerpt_length', array( $this, 'excerpt_length' ) );
200 remove_filter( 'excerpt_more', array( $this, 'excerpt_more' ) );
201 remove_filter( 'wpmtst_read_more_post_link', 'wpmtst_prepend_ellipsis' );
202
203 remove_filter( 'wpmtst_get_the_excerpt', 'wpmtst_bypass_excerpt', 1 );
204 remove_filter( 'wpmtst_get_the_excerpt', 'wpmtst_hybrid_excerpt' );
205 remove_filter( 'wpmtst_get_the_excerpt', 'wpmtst_trim_excerpt' );
206 remove_filter( 'wpmtst_get_the_excerpt', array( $this, 'manual_excerpt_more' ), 20 );
207
208 remove_filter( 'wpmtst_is_hybrid_content', '__return_true' );
209 remove_filter( 'wpmtst_use_ellipsis', '__return_true' );
210 remove_filter( 'wpmtst_use_ellipsis', array( $this, 'has_no_excerpt' ) );
211 }
212
213 /**
214 * Return true if post has no manual excerpt.
215 *
216 * @since 2.33.0
217 *
218 * @return bool
219 */
220 public function has_no_excerpt() {
221 return ! has_excerpt();
222 }
223
224 /**
225 * Set custom excerpt length.
226 *
227 * @param $words
228 * @since 2.33.0
229 *
230 * @return mixed|null
231 */
232 public function excerpt_length( $words ) {
233 $excerpt_length = $this->get_att( 'excerpt_length' );
234
235 return $excerpt_length ? $excerpt_length : $words;
236 }
237
238 /**
239 * The read-more link, maybe prepended with an ellipsis.
240 *
241 * @param $more
242 * @since 2.33.0
243 *
244 * @return string
245 */
246 public function excerpt_more( $more ) {
247 return wpmtst_get_excerpt_more_link();
248 }
249
250 /**
251 * Maybe add read-more to manual excerpt.
252 *
253 * @since 2.26.0
254 * @param $excerpt
255 *
256 * @return string
257 */
258 public function manual_excerpt_more( $excerpt ) {
259 if ( has_excerpt() ) {
260 $excerpt .= apply_filters( 'excerpt_more', ' [&hellip;]' );
261 }
262
263 return $excerpt;
264 }
265
266 /**
267 * Build our query based on view attributes.
268 */
269 public function build_query() {}
270
271 /**
272 * Build class list based on view attributes.
273 *
274 * This must happen after the query.
275 */
276 public function build_classes() {}
277
278 /**
279 * Load template's extra stylesheets.
280 *
281 * @since 2.11.12
282 * @since 2.16.0 In Strong_View class.
283 */
284 public function load_extra_stylesheets() {
285 $styles = WPMST()->templates->get_template_config( $this->atts, 'styles', false );
286 if ( $styles ) {
287 $styles_array = explode( ',', str_replace( ' ', '', $styles ) );
288 foreach ( $styles_array as $handle ) {
289 WPMST()->render->add_style( $handle );
290 }
291 }
292 }
293
294 /**
295 * Load template's script and/or dependencies.
296 *
297 * @since 1.25.0
298 * @since 2.16.0 In Strong_View class.
299 */
300 public function load_dependent_scripts() {
301 // Scripts that are already registered.
302 $deps = WPMST()->templates->get_template_config( $this->atts, 'scripts', false );
303 $deps_array = $deps ? explode( ',', str_replace( ' ', '', $deps ) ) : array();
304
305 // A single script included in directory.
306 $script = WPMST()->templates->get_template_config( $this->atts, 'script', false );
307
308 if ( $script ) {
309 $handle = 'testimonials-' . $this->get_att( 'template' );
310 wp_register_script( $handle, $script, $deps_array );
311 WPMST()->render->add_script( $handle );
312 } else {
313 foreach ( $deps_array as $handle ) {
314 WPMST()->render->add_script( $handle );
315 }
316 }
317 }
318
319 /**
320 * Find a template's associated stylesheet.
321 *
322 * @since 1.23.0
323 * @since 2.16.0 In Strong_View class.
324 *
325 * @param bool $enqueue True = enqueue the stylesheet, @since 2.3
326 *
327 * @return bool|string
328 */
329 public function find_stylesheet( $enqueue = true ) {
330 // In case of deactivated widgets still referencing deleted Views
331 if ( ! $this->get_att( 'template' ) ) {
332 return false;
333 }
334
335 $stylesheet = WPMST()->templates->get_template_attr( $this->atts, 'stylesheet', false );
336 if ( $stylesheet ) {
337 $handle = 'testimonials-' . str_replace( ':', '-', $this->get_att( 'template' ) );
338 $this->set_stylesheet( $handle );
339 wp_register_style( $handle, $stylesheet, array(), $this->plugin_version );
340 if ( $enqueue ) {
341 WPMST()->render->add_style( $handle );
342 } else {
343 return $handle;
344 }
345 }
346
347 return false;
348 }
349
350 /**
351 * Assemble list of CSS classes.
352 *
353 * @since 2.11.0
354 * @since 2.30.0 Adding template option classes.
355 *
356 * @return array
357 */
358 public function get_template_css_class() {
359 $template_name = isset( $this->atts['template'] ) ? $this->atts['template'] : '';
360 $template_settings = $this->get_att( 'template_settings' );
361
362 // Maintain back-compat with template format version 1.0.
363 $class = str_replace( ':content', '', $template_name );
364 $class = str_replace( ':', '-', $class );
365 $class = str_replace( '-form-form', '-form', $class );
366 $class = $class . ' wpmtst-' . $class;
367 $class_list = array( $class );
368
369 $template_object = WPMST()->templates->get_template_by_name( $template_name );
370
371 if ( isset( $template_object['config']['options'] ) && is_array( ( $template_object['config']['options'] ) ) ) {
372
373 foreach ( $template_object['config']['options'] as $option ) {
374
375 if ( ! isset( $option->values ) ) {
376 continue;
377 }
378
379 if ( isset( $template_settings[ $template_name ][ $option->name ] ) ) {
380
381 foreach ( $option->values as $value ) {
382 if ( $value->value === $template_settings[ $template_name ][ $option->name ] ) {
383 if ( isset( $value->class_name ) ) {
384 $class_list[] = $value->class_name;
385 }
386 }
387 }
388 }
389 }
390 }
391
392 return array_filter( $class_list );
393 }
394
395 /**
396 * Print our custom style.
397 *
398 * @since 2.22.0
399 */
400 public function add_custom_style() {
401 $this->custom_background();
402 $this->custom_font_color();
403
404 /**
405 * Hook to add more inline style.
406 *
407 * @since 2.22.0
408 */
409 do_action( 'wpmtst_view_custom_style', $this );
410 }
411
412 /**
413 * Is this a form view?
414 *
415 * @since 2.30.0
416 *
417 * @return bool
418 */
419 public function is_form() {
420 return ( 'form' === $this->get_att( 'mode' ) );
421 }
422
423 /**
424 * Build CSS for custom font color.
425 *
426 * @since 2.30.0
427 */
428 public function custom_font_color() {
429 $font_color = $this->get_att( 'font-color' );
430 if ( ! isset( $font_color['type'] ) || 'custom' !== $font_color['type'] ) {
431 return;
432 }
433
434 $c1 = isset( $font_color['color'] ) ? $font_color['color'] : '';
435 $css = '';
436 if ( $c1 ) {
437 $view_el = ".strong-view-id-{$this->get_att( 'view' )}";
438 $handle = $this->get_stylesheet();
439
440 if ( $this->is_form() ) {
441 $css .= "$view_el .strong-form-inner { color: $c1; }";
442 } else {
443 $css .= "$view_el .wpmtst-testimonial-heading," .
444 "$view_el .wpmtst-testimonial-content p," .
445 "$view_el .wpmtst-testimonial-content span," .
446 "$view_el .wpmtst-testimonial-content a.readmore," .
447 "$view_el .wpmtst-testimonial-content div.readmore-content," .
448 "$view_el .wpmtst-testimonial-content div.readmore-excerpt," .
449 "$view_el .wpmtst-testimonial-inner .wpmtst-testimonial-field," .
450 "$view_el .wpmtst-testimonial-inner .wpmtst-testimonial-field a," .
451 "$view_el .wpmtst-testimonial-client div," .
452 "$view_el .wpmtst-testimonial-client a { color: $c1; }";
453 }
454 if ( wp_style_is( $handle, 'done' ) ) {
455 echo '<style type="text/css" id="wpmtst-view-custom-style">' . $css . '</style>';
456 } else {
457 wp_add_inline_style( $handle, $css );
458 }
459 }
460 }
461
462 /**
463 * Build CSS for custom background.
464 */
465 public function custom_background() {
466
467 $background = $this->get_att( 'background' );
468 if ( ! isset( $background['type'] ) ) {
469 return;
470 }
471
472 $handle = $this->get_stylesheet();
473 $c1 = '';
474 $c2 = '';
475
476 switch ( $background['type'] ) {
477 case 'preset':
478 $preset = wpmtst_get_background_presets( $background['preset'] );
479 $c1 = $preset['color'];
480 if ( isset( $preset['color2'] ) ) {
481 $c2 = $preset['color2'];
482 }
483 break;
484 case 'gradient':
485 $c1 = $background['gradient1'];
486 $c2 = $background['gradient2'];
487 break;
488 case 'single':
489 $c1 = $background['color'];
490 break;
491 default:
492 }
493
494 // Special handling for Divi Builder
495 $prefix = '';
496 $css = '';
497 if ( $this->get_att( 'divi_builder' ) && wpmtst_divi_builder_active() ) {
498 $prefix = '#et_builder_outer_content ';
499 }
500
501 $view_el = "$prefix.strong-view-id-{$this->get_att( 'view' )}";
502
503 // Includes special handling for Bold template.
504 if ( $c1 && $c2 ) {
505
506 $gradient = self::gradient_rules( $c1, $c2 );
507
508 if ( $this->is_form() ) {
509
510 $css = "$view_el .strong-form-inner { $gradient }";
511 } else {
512
513 $css = "$view_el .wpmtst-testimonial-inner { $gradient }";
514
515 if ( 'bold' === WPMST()->atts( 'template' ) ) {
516 $css .= "$view_el .readmore-page { background: $c2 }";
517 }
518 }
519 } elseif ( $c1 ) {
520 if ( $this->is_form() ) {
521 $css = "{$view_el} .strong-form-inner { background: {$c1}; }";
522 } else {
523
524 $css = "$view_el .wpmtst-testimonial-inner { background: $c1; }";
525
526 if ( 'bold' === WPMST()->atts( 'template' ) ) {
527 $css .= "$view_el .readmore-page { background: $c1 }";
528 }
529 }
530 }
531
532 if ( wp_style_is( $handle, 'done' ) ) {
533 echo '<style type="text/css" id="wpmtst-custom-style">' . $css . '</style>';
534 } else {
535 wp_add_inline_style( $handle, $css );
536 }
537 }
538
539 /**
540 * Print gradient rules.
541 *
542 * @param $c1
543 * @param $c2
544 *
545 * @return string
546 */
547 public function gradient_rules( $c1, $c2 ) {
548 return "background: {$c1};
549 background: -moz-linear-gradient(top, {$c1} 0%, {$c2} 100%);
550 background: -webkit-gradient(linear, left top, left bottom, color-stop(0%, {$c1}), color-stop(100%, {$c2}));
551 background: -webkit-linear-gradient(top, {$c1} 0%, {$c2} 100%);
552 background: -o-linear-gradient(top, {$c1} 0%, {$c2} 100%);
553 background: -ms-linear-gradient(top, {$c1} 0%, {$c2} 100%);
554 background: linear-gradient(to bottom, {$c1} 0%, {$c2} 100%);
555 filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='{$c1}', endColorstr='{$c2}', GradientType=0);";
556 }
557
558 /**
559 * Stars
560 *
561 * @since 2.16.0 In Strong_View class.
562 */
563 public function has_stars() {
564 if ( $this->get_att( 'client_section' ) ) {
565 foreach ( $this->get_att( 'client_section' ) as $field ) {
566 if ( 'rating' === $field['type'] ) {
567 WPMST()->render->add_style( 'wpmtst-rating-display' );
568 break;
569 }
570 }
571 }
572 }
573
574 public function set_stylesheet( $handle = '' ) {
575 $this->stylesheet = $handle;
576 }
577
578 public function get_stylesheet() {
579 return $this->stylesheet;
580 }
581 }
582
583 endif;
584