<?php
/* ==========================================================
  Testimonials
=========================================================== */
if ( !function_exists('confin_testimonial_function')) {
  function confin_testimonial_function( $atts, $content = NULL ) {
    extract($atts);

    $e_uniqid       = uniqid();
    $inline_style   = '';

    if ( $title_size || $title_color ) {
      $title_style = ' style="';
      $title_style .= $title_size ? 'font-size: '. confin_plugin_check_px($title_size) .';': '';
      $title_style .= $title_color ? 'color: '.$title_color : '';
      $title_style .= '"';
    } else {
      $title_style = '';
    }
    if ( $subtitle_size || $subtitle_color ) {
      $subtitle_style = ' style="';
      $subtitle_style .= $subtitle_size ? 'font-size: '. confin_plugin_check_px($subtitle_size) .';': '';
      $subtitle_style .= $subtitle_color ? 'color: '.$subtitle_color : '';
      $subtitle_style .= '"';
    } else {
      $subtitle_style = '';
    }
    if ( $subtitle_color ) {
      $image_style = ' style="';
      $image_style .= $subtitle_color ? 'border-color: '.$subtitle_color : '';
      $image_style .= '"';
    } else {
      $image_style = '';
    }

    if ( $desc_size || $desc_color ) {
      $desc_style = ' style="';
      $desc_style .= $desc_size ? 'font-size: '. confin_plugin_check_px($desc_size) .';': '';
      $desc_style .= $desc_color ? 'color: '.$desc_color : '';
      $desc_style .= '"';
    } else {
      $desc_style = '';
    }

     if ( $dots_color ) {
        $inline_style .= '.testimonials-wrap-'.$e_uniqid .'.testimonials-section .owl-theme .owl-dots .owl-dot.active span {';
        $inline_style .= ( $dots_color ) ? 'background-color:'. $dots_color .';' : '';
        $inline_style .= '}';
      }
     if ( $icon_color ) {
        $inline_style .= '.testimonials-wrap-'.$e_uniqid .'.testimonials-section-s2 .testimonials-grids .grid:before {';
        $inline_style .= ( $icon_color ) ? 'color:'. $icon_color .';' : '';
        $inline_style .= '}';
      }
     if ( $button_color ) {
        $inline_style .= '.testimonials-wrap-'.$e_uniqid .'.testimonials-section .testimonials-grids .details a.theme-btn-s3 {';
        $inline_style .= ( $button_color ) ? 'border-color:'. $button_color .';' : '';
        $inline_style .= '}';
      }
     if ( $button_hover ) {
        $inline_style .= '.testimonials-wrap-'.$e_uniqid .'.testimonials-section .testimonials-grids .details a.theme-btn-s3:hover {';
        $inline_style .= ( $button_hover ) ? 'background-color:'. $button_hover .';' : '';
        $inline_style .= '}';
      }

    // add inline style
    add_inline_style( $inline_style );
    $styled_class  = 'testimonials-wrap-'.$e_uniqid.' ';

    $testimonial_items = ( $testimonial_items ) ? (array) $testimonial_items : array();
     ob_start();
    $background_img = $background_img ? 'background-image: url('.esc_url( wp_get_attachment_url( $background_img ) ).');' : '';
 ?>
      <div class="testimonials-section <?php echo esc_attr( $styled_class.$class ); ?>" style="<?php echo esc_attr($background_img); ?>">
		<div class="container">
       <div class="row">
        <div class="col col-lg-8 col-lg-offset-2 col-sm-10 col-sm-offset-1">
            <div class="testimonials-grids testimonials-slider">
             <?php if ( $testimonial_items ) {
                foreach ( $testimonial_items as $key => $testimonial_item ) {
                $image_url = wp_get_attachment_url( $testimonial_item->testi_image );
                $image_alt = get_post_meta($testimonial_item->testi_image, '_wp_attachment_image_alt', true);
                 ?>
                <div class="grid">
                  <div class="quote">
                    <p <?php echo wp_kses_post( $desc_style ); ?>><?php echo esc_html( $testimonial_item->desc ); ?></p>
                  </div>
                  <div class="client-info">
                      <div class="client-pic">
                          <img src="<?php echo esc_url( $image_url ); ?>" alt="<?php echo esc_attr( $image_alt ) ?>">
                      </div>
                        <h5 <?php echo wp_kses_post( $title_style ); ?>><?php echo esc_html( $testimonial_item->title ); ?></h5>
                        <span <?php echo wp_kses_post( $subtitle_style ); ?>><?php echo esc_html( $testimonial_item->subtitle ); ?></span>
                  </div>
                </div>
              <?php } } ?>
            </div>
        </div>
      </div> 
	</div>
    </div>
    <?php
     return ob_get_clean();
  }
}
add_shortcode( 'tpl_testimonial', 'confin_testimonial_function' );
