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