*/
/*
*	Get post types
*	@since 0.1
*/
$post_types = get_post_types('', 'names');
/* Remove known, not useful post types */
$excluded_post_types = array('testimonial', 'attachment', 'revision', 'nav_menu_item', 'product_variation', 'shop_order', 'shop_order_refund', 'shop_coupon', 'shop_webhook');
/* Allow users to exclude post types here as well */
$excluded_post_types = apply_filters('capt_expluded_review_post_types', $excluded_post_types);
/* Loop over and unset what we don't want */
foreach ($excluded_post_types as $post_type) {
    unset($post_types[$post_type]);
}
/* Get the previously stored option */
$options = Client_and_Product_Testimonials::get_cat_options();
$previously_saved_post_types = isset($options['_client_and_product_testimonial_post_page_reviews_post_types']) ? $options['_client_and_product_testimonial_post_page_reviews_post_types'] : array();
/* Build the dropdown */
?>
<div class="cmb-td">
	<select id="<?php 
echo $field->args['_id'];
?>
" name="<?php 
echo $field->args['_id'];
?>
[]" multiple>
		<?php 
foreach ($post_types as $post_type) {
    $post_type_labels = get_post_type_object($post_type);
    $post_type_name = isset($post_type_labels->labels->singular_name) ? $post_type_labels->labels->singular_name : $post_type;
function generate_fade_slider($atts)
{
    // start output buffering to catch the grid
    ob_start();
    // get our options
    $options = Client_and_Product_Testimonials::get_cat_options();
    // extract attributes
    $a = shortcode_atts(array(str_replace('testimonial_', '', rtrim($options['_client_and_product_testimonial_taxonomy'], 's')) => '', 'style' => '1', 'controls' => '1', 'automatic' => '1', 'duration' => '5', 'animation' => 'fade', 'order' => '', 'orderby' => '', 'exclude' => ''), $atts);
    $taxonomy = str_replace('_', '-', $options['_client_and_product_testimonial_taxonomy']);
    $taxonomy_name = str_replace('testimonial_', '', $options['_client_and_product_testimonial_taxonomy']);
    $preloader_selection = $options['_client_and_product_testimonial_preloader'];
    /* Should the fallback image be used? */
    $use_fallback_image = isset($options['_client_and_product_testimonial_use_fallback_image']) ? $options['_client_and_product_testimonial_use_fallback_image'] : '1';
    // set the image style
    $image_style = !empty($atts['image-style']) ? $atts['image-style'] : 'square';
    // set images to greyscale
    if (isset($atts['greyscale'])) {
        $images_greyscale = 'capt-image-greyscale';
    }
    if (isset($atts['grayscale'])) {
        $images_greyscale = 'capt-image-grayscale';
    }
    if (!isset($atts['greyscale']) && !isset($atts['grayscale'])) {
        $images_greyscale = '';
    }
    // Exclude testimonials
    $excluded_testimonials = !empty($atts['exclude']) ? explode(',', $atts['exclude']) : array();
    $excluded_testimonial_ids = array();
    /* Check for excluded testimonials */
    if (!empty($excluded_testimonials)) {
        foreach ($excluded_testimonials as $exclude_testimonial) {
            if (is_numeric($exclude_testimonial)) {
                $excluded_testimonial_ids[] = $exclude_testimonial;
            } else {
                $testimonial = get_page_by_title($exclude_testimonial, OBJECT, 'testimonial');
                if ($testimonial) {
                    $excluded_testimonial_ids[] = $testimonial->ID;
                }
            }
        }
    }
    if (!empty($atts[$taxonomy_name]) && $atts[$taxonomy_name] != '-1') {
        $taxonomy_terms = explode(',', $atts[$taxonomy_name]);
        // pass the taxonomy terms through our custom filters
        $taxonomy_terms = apply_filters('capt-wooc-single', apply_filters('capt-edd-single', $taxonomy_terms, $taxonomy), $taxonomy);
        $args = array('post_type' => 'testimonial', 'posts_per_page' => 99, 'status' => 'publish', 'orderby' => !empty($atts['orderby']) ? $atts['orderby'] : 'date', 'order' => !empty($atts['order']) ? $atts['order'] : 'DESC', 'tax_query' => array(array('taxonomy' => $taxonomy, 'field' => 'term_id', 'terms' => $taxonomy_terms)));
    } else {
        $args = array('post_type' => 'testimonial', 'posts_per_page' => 99, 'status' => 'publish', 'orderby' => !empty($atts['orderby']) ? $atts['orderby'] : 'date', 'order' => !empty($atts['order']) ? $atts['order'] : 'DESC');
        // pass the taxonomy terms through our custom filters
        $taxonomy_terms = apply_filters('capt-wooc-single', apply_filters('capt-edd-single', array(), $taxonomy), $taxonomy);
        /*
         *	If content is passed back via the filter,
         *	push in the tax_query data
         */
        if (!empty($taxonomy_terms)) {
            $args['tax_query'] = array(array('taxonomy' => $taxonomy, 'field' => 'term_id', 'terms' => $taxonomy_terms));
        }
    }
    /* 
     *	Append the excluded post IDs 
     *	passed in via exclude="1,2,3"
     */
    if (!empty($excluded_testimonial_ids)) {
        $args['post__not_in'] = $excluded_testimonial_ids;
    }
    $testmonial_query = new WP_Query(apply_filters('client_and_product_testimonials_slider_query_args', $args));
    wp_reset_query();
    /* Generate the HTML debugging comment (inside capt-helpers.php) */
    echo generate_capt_html_comments('Testimonial Fade Slider', $atts);
    if ($testmonial_query->have_posts()) {
        // Flex Slider Options
        $flex_slider_controls = isset($atts['controls']) && $atts['controls'] == '1' ? true : false;
        $flex_slider_auto = isset($atts['automatic']) && $atts['automatic'] == '1' ? true : false;
        $flex_slider_duration = isset($atts['duration']) ? $atts['duration'] : '5';
        $flex_slider_animation = isset($atts['animation']) && ($atts['animation'] == 'fade' || $atts['animation'] == 'slide') ? $atts['animation'] : 'fade';
        // Un-minified - for testing
        // Scripts
        // enqueue flexslider
        // wp_enqueue_script( 'testmonial-slider-init-js', Client_Product_Testimonials_URL . 'lib/public/js/testimonial-slider-init.js', array( 'jquery', 'flexslider.js' ), '', FALSE );
        // Styles
        // enqueue the slider styles
        // wp_enqueue_style( 'flexslider.css', Client_Product_Testimonials_URL . 'lib/public/css/flexslider.css' );
        // wp_enqueue_style( 'testimonial-fade-slider-css', Client_Product_Testimonials_URL . 'lib/public/css/testimonial-fade-slider.css', array( 'flexslider.css', capt_get_themes_last_enqueued_style() ) );
        // Minified - production
        // Scripts
        wp_enqueue_script('flexslider.js', Client_Product_Testimonials_URL . 'lib/public/js/min/jquery.flexslider-min.js', array('jquery'), '', FALSE);
        wp_enqueue_script('testmonial-slider-init-js', Client_Product_Testimonials_URL . 'lib/public/js/min/testimonial-slider-init.min.js', array('flexslider.js'), '', FALSE);
        // Styles - Global for all testimonial shortcodes
        wp_enqueue_style('capt-styles', Client_Product_Testimonials_URL . 'lib/public/css/min/client-and-product-testimonials.min.css', array(capt_get_themes_last_enqueued_style()));
        /* 
         *	Note: Flexslider options are stored as data-attr parameters on the div element
         *	This is so that we can initialize multiple sliders on a page, with separate options
         *	@since 0.1
         */
        ?>
<div id="testimonial-fade-slider" class="flexslider testimonial-fade-slider-flexslider" data-attr-controls="<?php 
        echo $flex_slider_controls;
        ?>
" data-attr-auto="<?php 
        echo $flex_slider_auto;
        ?>
" data-attr-speed="<?php 
        echo $flex_slider_duration;
        ?>
" data-attr-animation="<?php 
        echo $flex_slider_animation;
        ?>
"><?php 
        echo '<image src="' . apply_filters('client_and_product_testimonials_preloader_url', Client_Product_Testimonials_URL . 'lib/images/preloaders/Preloader_' . apply_filters('client_and_product_testimonials_preloader_number', $preloader_selection) . '.gif') . '" class="capt-preloader">';
        ?>
<ul class="slides"><?php 
        $i = 0;
        while ($testmonial_query->have_posts()) {
            $testmonial_query->the_post();
            /* Standard Testimonial */
            ?>
				<li>
				  <div class="slide-text">
						<?php 
            if (has_post_thumbnail(get_the_ID())) {
                $attachment_alt_text = get_post_meta(get_post_thumbnail_id(get_the_ID()), '_wp_attachment_image_alt', true);
                echo get_the_post_thumbnail(get_the_ID(), 'testimonial-image', array('class' => 'testimonial-image', 'alt' => $attachment_alt_text, 'title' => get_the_title()));
                $full_width_class = '';
            } else {
                if ($use_fallback_image == '1') {
                    $fallback_image_id = (int) $options['_client_and_product_testimonial_no_photo_fallback_id'];
                    echo wp_get_attachment_image($fallback_image_id, 'testimonial-image', false, array('class' => 'testimonial-image capt-image-' . $image_style . ' ' . $images_greyscale . ' wp-post-image', 'alt' => __('No Image Provided', 'client-and-product-testimonials'), 'title' => __('No Image Provided', 'client-and-product-testimonials')));
                    $full_width_class = '';
                } else {
                    $full_width_class = 'full-width-content';
                }
            }
            ?>
						<div class="testimonial-content <?php 
            echo $full_width_class;
            ?>
">
							<section class="testimonial-content-text">
								<cite>
									<?php 
            echo apply_filters('capt_content', get_the_content());
            ?>
								</cite>
							</section>
							<?php 
            echo eh_cmb2_get_star_rating_field(get_the_ID());
            ?>
							<span class="testimonial-author">
								<section><?php 
            the_title();
            ?>
</section>
							</span>
							<?php 
            echo eh_get_testimonial_details(get_the_ID());
            ?>
						</div>
				  </div>
				</li>
				<?php 
        }
        wp_reset_postdata();
        ?>
</ul><?php 
        ?>
</div><?php 
    } else {
        ?>
			<section class="capt-no-testimonials-found-error"><?php 
        _e('No testimonials found.', 'client-and-product-testimonials');
        ?>
</section>
		<?php 
    }
    // clean up output buffering
    $testimonial_grid = ob_get_clean();
    // return the grid
    return $testimonial_grid;
}
function generate_testimonial_list($atts)
{
    // get our options
    $options = Client_and_Product_Testimonials::get_cat_options();
    // extract attributes
    $a = shortcode_atts(array(str_replace('testimonial_', '', $options['_client_and_product_testimonial_taxonomy']) => '', 'style' => '1', 'columns' => '1', 'limit' => '16', 'image-style' => 'square', 'greyscale' => '', 'grayscale' => '', 'order' => '', 'orderby' => '', 'exclude' => ''), $atts);
    $taxonomy_name = str_replace('_', '-', $options['_client_and_product_testimonial_taxonomy']);
    $use_fallback_image = isset($options['_client_and_product_testimonial_use_fallback_image']) ? $options['_client_and_product_testimonial_use_fallback_image'] : '1';
    // set the list style
    $style = (int) (!empty($atts['style'])) ? $atts['style'] : '1';
    // set the columns
    $columns = (int) (!empty($atts['columns'])) ? $atts['columns'] : '1';
    // set the limit
    $limit = (int) (!empty($atts['limit'])) ? $atts['limit'] : '16';
    // set the image style
    $image_style = !empty($atts['image-style']) ? $atts['image-style'] : 'square';
    // set images to greyscale
    if (isset($atts['greyscale'])) {
        $images_greyscale = 'capt-image-greyscale';
    }
    if (isset($atts['grayscale'])) {
        $images_greyscale = 'capt-image-grayscale';
    }
    if (!isset($atts['greyscale']) && !isset($atts['grayscale'])) {
        $images_greyscale = '';
    }
    // Exclude testimonials
    $excluded_testimonials = !empty($atts['exclude']) ? explode(',', $atts['exclude']) : array();
    $excluded_testimonial_ids = array();
    /* Check for excluded testimonials */
    if (!empty($excluded_testimonials)) {
        foreach ($excluded_testimonials as $exclude_testimonial) {
            if (is_numeric($exclude_testimonial)) {
                $excluded_testimonial_ids[] = $exclude_testimonial;
            } else {
                $testimonial = get_page_by_title($exclude_testimonial, OBJECT, 'testimonial');
                if ($testimonial) {
                    $excluded_testimonial_ids[] = $testimonial->ID;
                }
            }
        }
    }
    if (!empty($atts[str_replace('testimonial_', '', $options['_client_and_product_testimonial_taxonomy'])]) && $atts[str_replace('testimonial_', '', $options['_client_and_product_testimonial_taxonomy'])] != '-1') {
        $tax_ids = explode(',', $atts[str_replace('testimonial_', '', $options['_client_and_product_testimonial_taxonomy'])]);
        if ($tax_ids && is_array($tax_ids)) {
            $taxonomy_ids = $tax_ids;
        } else {
            $taxonomy_ids = array($atts[str_replace('testimonial_', '', $options['_client_and_product_testimonial_taxonomy'])]);
        }
        $args = array('post_type' => 'testimonial', 'posts_per_page' => $limit, 'status' => 'publish', 'orderby' => !empty($atts['orderby']) ? $atts['orderby'] : 'date', 'order' => !empty($atts['order']) ? $atts['order'] : 'DESC', 'tax_query' => array(array('taxonomy' => $taxonomy_name, 'field' => 'term_id', 'terms' => apply_filters('capt-wooc-single', apply_filters('capt-edd-single', $taxonomy_ids, $taxonomy_name), $taxonomy_name))));
    } else {
        // query all
        $args = array('post_type' => 'testimonial', 'posts_per_page' => $limit, 'status' => 'publish', 'orderby' => !empty($atts['orderby']) ? $atts['orderby'] : 'date', 'order' => !empty($atts['order']) ? $atts['order'] : 'DESC');
        // pass the taxonomy terms through our custom filters
        $taxonomy_terms = apply_filters('capt-wooc-single', apply_filters('capt-edd-single', array(), $taxonomy_name), $taxonomy_name);
        /*
         *	If content is passed back via the filter,
         *	push in the tax_query data
         */
        if (!empty($taxonomy_terms)) {
            $args['tax_query'] = array(array('taxonomy' => $taxonomy_name, 'field' => 'term_id', 'terms' => $taxonomy_terms));
        }
    }
    /* 
     *	Append the excluded post IDs 
     *	passed in via exclude="1,2,3"
     */
    if (!empty($excluded_testimonial_ids)) {
        $args['post__not_in'] = $excluded_testimonial_ids;
    }
    $testmonial_query = new WP_Query(apply_filters('client_and_product_testimonials_list_query_args', $args));
    // start output buffering to catch the list
    ob_start();
    /* Generate the HTML debugging comment (inside capt-helpers.php) */
    echo generate_capt_html_comments('Testimonial List', $atts);
    if ($testmonial_query->have_posts()) {
        // un-minifed styles for testing
        // enqueue the list styles
        // wp_enqueue_style( 'testmonial-list-styles', Client_Product_Testimonials_URL . 'lib/public/css/testimonial-list-styles.css' );
        // Minified Styles - Global for all testimonial shortcodes
        wp_enqueue_style('testmonial-list-styles', Client_Product_Testimonials_URL . 'lib/public/css/min/client-and-product-testimonials.min.css', array(capt_get_themes_last_enqueued_style()));
        ?>
<div id="testimonial-list" class="capt-list-style-<?php 
        esc_attr_e($style);
        ?>
 capt-list-columns-<?php 
        esc_attr_e($columns);
        ?>
"><?php 
        ?>
<div class="list"><?php 
        $i = 1;
        $x = 1;
        $total_posts = $testmonial_query->found_posts;
        while ($testmonial_query->have_posts()) {
            $testmonial_query->the_post();
            /* Setup the containers */
            if ($columns > 1 && $x == 1) {
                ?>
						<section class="capt-row">
						<?php 
            }
            ?>
						
						<div class="list-item list-item-<?php 
            echo $i;
            ?>
">
							<?php 
            // Setup the fallback image
            if (has_post_thumbnail(get_the_ID())) {
                $attachment_alt_text = get_post_meta(get_post_thumbnail_id(get_the_ID()), '_wp_attachment_image_alt', true);
                echo get_the_post_thumbnail(get_the_ID(), 'testimonial-image', array('class' => 'testimonial-image capt-image-' . $image_style . ' ' . $images_greyscale, 'alt' => $attachment_alt_text, 'title' => get_the_title()));
                $testimonial_full_width = '';
            } else {
                if ($use_fallback_image == '1') {
                    $fallback_image_id = (int) $options['_client_and_product_testimonial_no_photo_fallback_id'];
                    echo wp_get_attachment_image($fallback_image_id, 'testimonial-image', false, array('class' => 'testimonial-image capt-image-' . $image_style . ' ' . $images_greyscale . ' wp-post-image', 'alt' => __('No Image Provided', 'client-and-product-testimonials'), 'title' => __('No Image Provided', 'client-and-product-testimonials')));
                    $testimonial_full_width = '';
                } else {
                    $testimonial_full_width = 'testimonial-content-full-width';
                }
            }
            ?>
								<div class="testimonial-content <?php 
            echo $testimonial_full_width;
            ?>
">
									<section class="testimonial-content-text">
										<cite>	
											<?php 
            echo apply_filters('capt_content', get_the_content());
            ?>
										</cite>
									</section>
									<span class="testimonial-author">
										<section><?php 
            echo get_the_title(get_the_ID());
            ?>
</section>
									</span>
									<small class="testimonial-details"><?php 
            echo eh_get_testimonial_details(get_the_ID());
            ?>
</small>
									<?php 
            echo eh_cmb2_get_star_rating_field(get_the_ID());
            ?>
								</div>
						</div>

						<?php 
            if ($i != $testmonial_query->found_posts && $columns == '1') {
                ?>
							<hr />
						<?php 
            }
            ?>
						
					<?php 
            /* Setup the containers */
            if ($columns > 1 && $x == $columns) {
                ?>
						</section>
						<?php 
                $x = 0;
            }
            $i++;
            $x++;
        }
        ?>
</div><?php 
        ?>
</div><?php 
    } else {
        ?>
				<section><?php 
        _e('No testimonials found.', 'client-and-product-testimonials');
        ?>
</section>
			<?php 
    }
    wp_reset_query();
    // clean up output buffering
    $testimonial_list = ob_get_clean();
    // return the list
    return $testimonial_list;
}
    public function form($instance)
    {
        // get our options
        $options = Client_and_Product_Testimonials::get_cat_options();
        // title
        $title = isset($instance['title']) ? $instance['title'] : __('Testimonials', 'client-and-product-testimonials');
        // selected taxonomy
        $selected_taxonomy = isset($instance['capt_taxonomy']) ? $instance['capt_taxonomy'] : null;
        // taxonomy
        $taxonomy = str_replace('_', '-', $options['_client_and_product_testimonial_taxonomy']);
        // split the taxonomy
        $split_taxonomy = explode('-', $taxonomy);
        // display controls
        $hide_controls = isset($instance['hide_controls']) ? $instance['hide_controls'] : 0;
        // auto start
        $automatic = isset($instance['automatic']) ? $instance['automatic'] : 0;
        // limit
        $limit = isset($instance['limit']) ? $instance['limit'] : 5;
        // style
        $style = isset($instance['style']) ? $instance['style'] : 'style-1';
        // is EDD active
        if (capt_is_edd_active()) {
            // EDD Override
            $edd_override = isset($instance['edd_override']) ? $instance['edd_override'] : 0;
        }
        // is WooCommerce active
        if (capt_is_woocommerce_active()) {
            // EDD Override
            $wooc_override = isset($instance['wooc_override']) ? $instance['wooc_override'] : 0;
        }
        // Widget admin form
        ?>
		<label for="<?php 
        echo $this->get_field_id('title');
        ?>
"><?php 
        _e('Title:');
        ?>
			<input class="widefat" id="<?php 
        echo $this->get_field_id('title');
        ?>
" name="<?php 
        echo $this->get_field_name('title');
        ?>
" type="text" value="<?php 
        echo esc_attr($title);
        ?>
" />
		</label> 
		<p class="description"><?php 
        _e('Enter a title for the testimonial widget.', 'client-and-product-testimonials');
        ?>
</p>
		
		<label for="<?php 
        echo $this->get_field_id('capt_taxonomy');
        ?>
"><?php 
        echo ucwords(rtrim(str_replace('testimonial_', '', $options['_client_and_product_testimonial_taxonomy']), 's'));
        ?>
			<?php 
        wp_dropdown_categories(array('taxonomy' => $taxonomy, 'show_option_none' => sprintf(__('All %s', 'client-and-product-testimonials'), ucwords($split_taxonomy[1])), 'option_none_value' => '-1', 'class' => 'widefat', 'hide_empty' => false, 'selected' => $selected_taxonomy, 'value_field' => 'term_id', 'name' => $this->get_field_name('capt_taxonomy')));
        ?>
		</label> 
		<p class="description"><?php 
        printf(__('Select one of your %s above.', 'client-and-product-testimonials'), $split_taxonomy[1]);
        ?>
</p>
		
		<label for="<?php 
        echo $this->get_field_id('limit');
        ?>
"><?php 
        _e('Number of Testimonials to Display:');
        ?>
			<input class="widefat" id="<?php 
        echo $this->get_field_id('limit');
        ?>
" name="<?php 
        echo $this->get_field_name('limit');
        ?>
" type="number" min="1" value="<?php 
        echo esc_attr($limit);
        ?>
" />
			<p class="description"><?php 
        _e('Limit the number of testimonials to display.', 'client-and-product-testimonials');
        ?>
</p>
		</label>
		
		<!--
			** To Do at a later point.. **
		<label for="<?php 
        echo $this->get_field_id('style');
        ?>
"><?php 
        _e('Display Controls:');
        ?>
			<select class="widefat" name="<?php 
        echo $this->get_field_name('style');
        ?>
" id="<?php 
        echo $this->get_field_id('style');
        ?>
">
				<option value="style-1" <?php 
        selected($style, 'style-1');
        ?>
><?php 
        _e('Style 1', 'client-and-product-testimonials');
        ?>
</option>
				<option value="style-2" <?php 
        selected($style, 'style-2');
        ?>
><?php 
        _e('Style 2', 'client-and-product-testimonials');
        ?>
</option>
				<option value="style-3" <?php 
        selected($style, 'style-3');
        ?>
><?php 
        _e('Style 3', 'client-and-product-testimonials');
        ?>
</option>
				<option value="style-4" <?php 
        selected($style, 'style-4');
        ?>
><?php 
        _e('Style 4', 'client-and-product-testimonials');
        ?>
</option>
				<option value="style-5" <?php 
        selected($style, 'style-5');
        ?>
><?php 
        _e('Style 5', 'client-and-product-testimonials');
        ?>
</option>
			</select>
			<p class="description"><?php 
        _e('Select the style for this slider.', 'client-and-product-testimonials');
        ?>
</p>
		</label>
		-->
		
		<?php 
        // Check if EDD is active, if so display custom options
        if (capt_is_edd_active()) {
            ?>
					<label for="<?php 
            echo $this->get_field_id('edd_override');
            ?>
"><?php 
            _e('Override Easy Digital Downloads:');
            ?>
						<select class="widefat" name="<?php 
            echo $this->get_field_name('edd_override');
            ?>
" id="<?php 
            echo $this->get_field_id('edd_override');
            ?>
">
							<option value="0" <?php 
            selected($edd_override, "0");
            ?>
><?php 
            _e('False', 'client-and-product-testimonials');
            ?>
</option>
							<option value="1" <?php 
            selected($edd_override, "1");
            ?>
><?php 
            _e('True', 'client-and-product-testimonials');
            ?>
</option>
						</select>
						<p class="description"><?php 
            printf(__("On any Easy Digital Downloads product page, override the testimonial set above and only display testimonials associated with that product. Set to false to disable the override and display your specific testimonials. %s", "client-and-product-testimonials"), "<br />(<code>" . htmlspecialchars("is_single() && \$" . "post->post_type == 'download'") . "</code>)");
            ?>
</p>
					</label>
				<?php 
        }
        // Check if WooCommerce is active, if so display custom options
        if (capt_is_woocommerce_active()) {
            ?>
					<label for="<?php 
            echo $this->get_field_id('wooc_override');
            ?>
"><?php 
            _e('Override WooCommerce:');
            ?>
						<select class="widefat" name="<?php 
            echo $this->get_field_name('wooc_override');
            ?>
" id="<?php 
            echo $this->get_field_id('wooc_override');
            ?>
">
							<option value="0" <?php 
            selected($wooc_override, "0");
            ?>
><?php 
            _e('False', 'client-and-product-testimonials');
            ?>
</option>
							<option value="1" <?php 
            selected($wooc_override, "1");
            ?>
><?php 
            _e('True', 'client-and-product-testimonials');
            ?>
</option>
						</select>
						<p class="description"><?php 
            printf(__("On any WooCommerce product page, override the testimonial set above and only display testimonials associated with that product. Set to false to disable the override and display your specific testimonials. %s", "client-and-product-testimonials"), "<br />(<code>" . htmlspecialchars("is_product()") . "</code>)");
            ?>
</p>
					</label>
				<?php 
        }
    }
function capt_add_taxonomy_filters()
{
    global $typenow;
    $options = Client_and_Product_Testimonials::get_cat_options();
    $selected_taxonomy = str_replace('_', '-', $options['_client_and_product_testimonial_taxonomy']);
    // an array of all the taxonomyies you want to display. Use the taxonomy name or slug
    $taxonomies = array($selected_taxonomy);
    // must set this to the post type you want the filter(s) displayed on
    if ($typenow == 'testimonial') {
        foreach ($taxonomies as $tax_slug) {
            $tax_obj = get_taxonomy($tax_slug);
            $tax_name = $tax_obj->labels->name;
            $terms = get_terms($tax_slug);
            if (count($terms) > 0) {
                echo "<select name='{$tax_slug}' id='{$tax_slug}' class='postform'>";
                echo "<option value=''>" . sprintf(__('Show All %s', 'client-and-product-testimonials'), $tax_name) . "</option>";
                foreach ($terms as $term) {
                    echo '<option value=' . $term->slug, isset($_GET[$tax_slug]) && $_GET[$tax_slug] == $term->slug ? ' selected="selected"' : '', '>' . $term->name . ' (' . $term->count . ')</option>';
                }
                echo "</select>";
            }
        }
    }
}
function capt_is_woocommerce_active()
{
    /* Get and store our options */
    $options = Client_and_Product_Testimonials::get_cat_options();
    if (is_plugin_active('woocommerce/woocommerce.php')) {
        /* confirm that the user has 'products' set, else this is not useful */
        if ($options['_client_and_product_testimonial_taxonomy'] != 'testimonial_products') {
            return false;
        }
        return true;
    }
    return false;
}
    /**
     * Add the options metabox to the array of metaboxes
     * @since  0.1.0
     */
    function add_options_page_metabox()
    {
        // print_r( get_option( 'cat_options' ) );
        $prefix = '_client_and_product_testimonial_';
        $regenerate_plugin_images_notice = $this->get_regen_image_notification();
        $options_page_links = '<hr /><a href="https://www.evan-herman.com" target="_blank"><img src="https://www.evan-herman.com/wp-content/plugins/timeline-express-pro/images/evan_herman_logo.png" alt="EH Dev Shop" title="EH Dev Shop Logo" style="margin-right:1em;width:50px;margin-top:10px;"></a><a href="http://captpro.evan-herman.com/documentation/" target="_blank" class="button-secondary" style="margin:.5em 0;" title="' . __('Documentation', 'client-and-product-testimonial-pro') . '">' . __('Documentation', 'client-and-product-testimonials') . '</a><hr />';
        $cmb = new_cmb2_box(array('id' => $this->metabox_id, 'hookup' => false, 'show_on' => array('key' => 'options-page', 'value' => array($this->key))));
        // Set our CMB2 fields
        // client or product taxonomy
        $cmb->add_field(array('name' => __('Clients or Products', 'client-and-product-testimonials'), 'desc' => __('Select which type of testimonial you want to display.', 'client-and-product-testimonials'), 'id' => $prefix . 'taxonomy', 'type' => 'select', 'options' => array('testimonial_clients' => 'Clients', 'testimonial_products' => 'Products'), 'before_row' => $options_page_links));
        // Star Ratings
        $cmb->add_field(array('name' => __('Star Ratings', 'client-and-product-testimonials'), 'desc' => __('When clients submit new testimonials, should they be allowed to leave a star rating as well?', 'client-and-product-testimonials'), 'id' => $prefix . 'enable_star_rating', 'type' => 'select', 'options' => array('0' => 'Disabled', '1' => 'Enabled')));
        // Hide Empty Stars
        $cmb->add_field(array('name' => __('Empty Star Visibility', 'client-and-product-testimonials'), 'desc' => __('Toggle the visibility of empty stars on the front end of the site. (eg: a 3 star rating will show 3 filled stars instead of 3 filled stars and 2 empty stars)', 'client-and-product-testimonials'), 'id' => $prefix . 'hide_empty_stars', 'type' => 'select', 'options' => array('0' => __('Visible', 'client-and-product-testimonials'), '1' => __('Hidden', 'client-and-product-testimonials'))));
        // Hide Empty Stars
        $cmb->add_field(array('name' => __('Fallback Image', 'client-and-product-testimonials'), 'desc' => __("If a testimonial doesn't have a profile photo assigned to it, should the fallback image be used?", 'client-and-product-testimonials'), 'id' => $prefix . 'use_fallback_image', 'type' => 'select', 'options' => array('1' => __('Use Fallback Image', 'client-and-product-testimonials'), '0' => __('Exclude Profile Photo', 'client-and-product-testimonials'))));
        // No Profile Fallback Image
        $cmb->add_field(array('name' => __('No Profile Photo', 'client-and-product-testimonials'), 'desc' => __('Select a fallback image to display when the user has not set a profile photo.', 'client-and-product-testimonials'), 'id' => $prefix . 'no_photo_fallback', 'type' => 'file', 'default' => ''));
        /**************
        			Preloader
        			*************/
        // Create an empty array to house our preloaders in $key => $value fashion
        $preloader_selection = array();
        $preloaders = glob(Client_Product_Testimonials_Path . 'lib/images/preloaders/*.gif');
        $preloader_count = count($preloaders);
        $x = 1;
        // $preloader_count == number of preloaders found in the preloaders directory
        // ~/plugins/client-and-product-tesetimonials/lib/images/preloaders/*.gif
        while ($x <= $preloader_count) {
            $preloader_selection[$x] = 'Style ' . $x;
            $x++;
        }
        // get our options
        $options = Client_and_Product_Testimonials::get_cat_options();
        $preloader_number = isset($options['_client_and_product_testimonial_preloader']) ? $options['_client_and_product_testimonial_preloader'] : '1';
        $cmb->add_field(array('name' => __('Preloader', 'client-and-product-testimonials'), 'desc' => sprintf(__('Select the pre-loader to use on the testimonial sliders. (tip: to use a custom preloader, see the following %s)', 'client-and-product-testimonials'), '<a href="#">' . __('knowledge base article', 'client-and-product-testimonials') . '</a>'), 'id' => $prefix . 'preloader', 'type' => 'select', 'default' => '1', 'options' => $preloader_selection, 'after_row' => '<div class="cmb-row">
										<div class="cmb-th">
											<label for="_client_and_product_testimonial_preloader">' . __('Preloader Preview', 'client-and-product-testimonials') . '</label>
										</div>
										<div class="cmb-td">
											<div class="capt-preloader-preview" style="width:50px;">
												<img src="' . Client_Product_Testimonials_URL . 'lib/images/preloaders/Preloader_' . $preloader_number . '.gif" title="Preloader ' . $preloader_number . '" />
											</div>
										</div>
									</div>'));
        // Schema Markup Option
        $cmb->add_field(array('name' => __('Schema Datatype', 'client-and-product-testimonials'), 'desc' => sprintf(__('For more info, see: %s and %s.', 'client-and-product-testimonials'), '<a href="http://schema.org/" target="_blank">schema.org</a>', '<a href="http://schema.org/docs/full.html" target="_blank">' . __('Schema Datatypes', 'client-and-product-testimonials') . '</a>'), 'id' => $prefix . 'schma_datatype', 'type' => 'schema_datatype_select', 'before_row' => '<hr /><h3>' . sprintf(__('Rich Snippet Schema Markup %s', 'client-and-product-testimonials'), '<small>(' . __('pro', 'client-and-product-testimonials') . ')</small>') . '</h3>'));
    }
    public function form($instance)
    {
        // get our options
        $options = Client_and_Product_Testimonials::get_cat_options();
        // title
        $title = isset($instance['title']) ? $instance['title'] : __('Testimonials', 'client-and-product-testimonials');
        // selected taxonomy
        $selected_taxonomy = isset($instance['capt_taxonomy']) ? $instance['capt_taxonomy'] : null;
        // taxonomy
        $taxonomy = str_replace('_', '-', $options['_client_and_product_testimonial_taxonomy']);
        // split the taxonomy
        $split_taxonomy = explode('-', $taxonomy);
        // Animation (fade/slide)
        $animation = isset($instance['animation']) ? $instance['animation'] : 'fade';
        // display controls
        $hide_controls = isset($instance['hide_controls']) ? $instance['hide_controls'] : 0;
        // auto start
        $automatic = isset($instance['automatic']) ? $instance['automatic'] : 0;
        // limit
        $limit = isset($instance['limit']) ? $instance['limit'] : 5;
        // duration
        $duration = isset($instance['duration']) ? $instance['duration'] : 5;
        // style
        $style = isset($instance['style']) ? $instance['style'] : 'style-1';
        // is EDD active
        if (capt_is_edd_active()) {
            // EDD Override
            $edd_override = isset($instance['edd_override']) ? $instance['edd_override'] : 0;
        }
        // is WooCommerce active
        if (capt_is_woocommerce_active()) {
            // EDD Override
            $wooc_override = isset($instance['wooc_override']) ? $instance['wooc_override'] : 0;
        }
        // Widget admin form
        ?>
		<label for="<?php 
        echo $this->get_field_id('title');
        ?>
"><?php 
        _e('Title:');
        ?>
			<input class="widefat" id="<?php 
        echo $this->get_field_id('title');
        ?>
" name="<?php 
        echo $this->get_field_name('title');
        ?>
" type="text" value="<?php 
        echo esc_attr($title);
        ?>
" />
		</label> 
		<p class="description"><?php 
        _e('Enter a title for the testimonial widget.', 'client-and-product-testimonials');
        ?>
</p>
		
		<label for="<?php 
        echo $this->get_field_id('capt_taxonomy');
        ?>
"><?php 
        echo ucwords(rtrim(str_replace('testimonial_', '', $options['_client_and_product_testimonial_taxonomy']), 's'));
        ?>
			<?php 
        wp_dropdown_categories(array('taxonomy' => $taxonomy, 'show_option_none' => sprintf(__('All %s', 'client-and-product-testimonials'), ucwords($split_taxonomy[1])), 'option_none_value' => '-1', 'class' => 'widefat', 'hide_empty' => false, 'selected' => $selected_taxonomy, 'value_field' => 'term_id', 'name' => $this->get_field_name('capt_taxonomy')));
        ?>
		</label> 
		<p class="description"><?php 
        printf(__('Select one of your %s above.', 'client-and-product-testimonials'), $split_taxonomy[1]);
        ?>
</p>
		
		<label for="<?php 
        echo $this->get_field_id('limit');
        ?>
"><?php 
        _e('Number of Testimonials to Display:');
        ?>
			<input class="widefat" id="<?php 
        echo $this->get_field_id('limit');
        ?>
" name="<?php 
        echo $this->get_field_name('limit');
        ?>
" type="number" min="1" value="<?php 
        echo esc_attr($limit);
        ?>
" />
			<p class="description"><?php 
        _e('Limit the number of testimonials to display.', 'client-and-product-testimonials');
        ?>
</p>
		</label>
				
		<label for="<?php 
        echo $this->get_field_id('animation');
        ?>
"><?php 
        _e('Animation Type:');
        ?>
			<select class="widefat" name="<?php 
        echo $this->get_field_name('animation');
        ?>
" id="<?php 
        echo $this->get_field_id('animation');
        ?>
">
				<option value="fade" <?php 
        selected($animation, "fade");
        ?>
><?php 
        _e('Fade', 'client-and-product-testimonials');
        ?>
</option>
				<option value="slide" <?php 
        selected($animation, "slide");
        ?>
><?php 
        _e('Slide', 'client-and-product-testimonials');
        ?>
</option>
			</select>
			<p class="description"><?php 
        _e('Select the animation for this slider (fade/slide).', 'client-and-product-testimonials');
        ?>
</p>
		</label>
		
		<label for="<?php 
        echo $this->get_field_id('hide_controls');
        ?>
"><?php 
        _e('Hide Controls:');
        ?>
			&nbsp;<input type="checkbox" id="<?php 
        echo $this->get_field_id('hide_controls');
        ?>
" name="<?php 
        echo $this->get_field_name('hide_controls');
        ?>
" value="1" <?php 
        checked($hide_controls, 1);
        ?>
>
			<p class="description"><?php 
        _e('Should the arrow controls be displayed below the slider?', 'client-and-product-testimonials');
        ?>
</p>
		</label>
		
		<label for="<?php 
        echo $this->get_field_id('automatic');
        ?>
"><?php 
        _e('Automatic:');
        ?>
			&nbsp;<input type="checkbox" id="<?php 
        echo $this->get_field_id('automatic');
        ?>
" name="<?php 
        echo $this->get_field_name('automatic');
        ?>
" value="1" <?php 
        checked($automatic, 1);
        ?>
 onchange="jQuery('.testimonial-duration-label').fadeToggle();return false;">
			<p class="description"><?php 
        _e('Should the slider start and transition automatically?', 'client-and-product-testimonials');
        ?>
</p>
		</label>
		
		<label class="testimonial-duration-label" for="<?php 
        echo $this->get_field_id('duration');
        ?>
" style="<?php 
        if ($automatic != 1) {
            echo 'display:none;';
        }
        ?>
 float:left;"><?php 
        _e('Tesitmonial Duration:');
        ?>
			<input style="width:60px;" class="" id="<?php 
        echo $this->get_field_id('duration');
        ?>
" name="<?php 
        echo $this->get_field_name('duration');
        ?>
" type="number" min="1.5" step="0.25" value="<?php 
        echo esc_attr($duration);
        ?>
" />&nbsp;<?php 
        _e('seconds', 'client-and-product-testimonials');
        ?>
			<p class="description"><?php 
        _e('Duration to display a single testimonial before displaying the next one. (in seconds)', 'client-and-product-testimonials');
        ?>
</p>
		</label>	
		
		<!-- 
			** To Do at a later point.. **
		<label for="<?php 
        echo $this->get_field_id('style');
        ?>
"><?php 
        _e('Display Controls:');
        ?>
			<select class="widefat" name="<?php 
        echo $this->get_field_name('style');
        ?>
" id="<?php 
        echo $this->get_field_id('style');
        ?>
">
				<option value="style-1" <?php 
        selected($style, 'style-1');
        ?>
><?php 
        _e('Style 1', 'client-and-product-testimonials');
        ?>
</option>
				<option value="style-2" <?php 
        selected($style, 'style-2');
        ?>
><?php 
        _e('Style 2', 'client-and-product-testimonials');
        ?>
</option>
				<option value="style-3" <?php 
        selected($style, 'style-3');
        ?>
><?php 
        _e('Style 3', 'client-and-product-testimonials');
        ?>
</option>
				<option value="style-4" <?php 
        selected($style, 'style-4');
        ?>
><?php 
        _e('Style 4', 'client-and-product-testimonials');
        ?>
</option>
				<option value="style-5" <?php 
        selected($style, 'style-5');
        ?>
><?php 
        _e('Style 5', 'client-and-product-testimonials');
        ?>
</option>
			</select>
			<p class="description"><?php 
        _e('Select the style for this slider.', 'client-and-product-testimonials');
        ?>
</p>
		</label>
		-->
		
		<?php 
        // Check if EDD is active, if so display custom options
        if (capt_is_edd_active()) {
            ?>
					<label for="<?php 
            echo $this->get_field_id('edd_override');
            ?>
"><?php 
            _e('Override Easy Digital Downloads:');
            ?>
						<select class="widefat" name="<?php 
            echo $this->get_field_name('edd_override');
            ?>
" id="<?php 
            echo $this->get_field_id('edd_override');
            ?>
">
							<option value="0" <?php 
            selected($edd_override, "0");
            ?>
><?php 
            _e('False', 'client-and-product-testimonials');
            ?>
</option>
							<option value="1" <?php 
            selected($edd_override, "1");
            ?>
><?php 
            _e('True', 'client-and-product-testimonials');
            ?>
</option>
						</select>
						<p class="description"><?php 
            printf(__("On any Easy Digital Downloads product page, override the testimonial set above and only display testimonials associated with that product. Set to false to disable the override and display your specific testimonials. %s", "client-and-product-testimonials"), "<br />(<code>" . htmlspecialchars("is_single() && \$" . "post->post_type == 'download'") . "</code>)");
            ?>
</p>
					</label>
				<?php 
        }
        // Check if WooCommerce is active, if so display custom options
        if (capt_is_woocommerce_active()) {
            ?>
					<label for="<?php 
            echo $this->get_field_id('wooc_override');
            ?>
"><?php 
            _e('Override WooCommerce:');
            ?>
						<select class="widefat" name="<?php 
            echo $this->get_field_name('wooc_override');
            ?>
" id="<?php 
            echo $this->get_field_id('wooc_override');
            ?>
">
							<option value="0" <?php 
            selected($wooc_override, "0");
            ?>
><?php 
            _e('False', 'client-and-product-testimonials');
            ?>
</option>
							<option value="1" <?php 
            selected($wooc_override, "1");
            ?>
><?php 
            _e('True', 'client-and-product-testimonials');
            ?>
</option>
						</select>
						<p class="description"><?php 
            printf(__("On any WooCommerce product page, override the testimonial set above and only display testimonials associated with that product. Set to false to disable the override and display your specific testimonials. %s", "client-and-product-testimonials"), "<br />(<code>" . htmlspecialchars("is_product()") . "</code>)");
            ?>
</p>
					</label>
				<?php 
        }
    }
function generate_testimonial_section($atts)
{
    // get our options
    $options = Client_and_Product_Testimonials::get_cat_options();
    // extract attributes
    $a = shortcode_atts(array('testimonial' => '', 'images' => 'square', 'greyscale' => '', 'grayscale' => '', 'order' => '', 'orderby' => '', 'exclude' => ''), $atts);
    // set images to greyscale
    if (isset($atts['greyscale'])) {
        $images_greyscale = 'capt-image-greyscale';
    }
    if (isset($atts['grayscale'])) {
        $images_greyscale = 'capt-image-grayscale';
    }
    if (!isset($atts['greyscale']) && !isset($atts['grayscale'])) {
        $images_greyscale = '';
    }
    // set the image style
    $image_style = !empty($atts['images']) ? $atts['images'] : 'square';
    /* Should the fallback image be used? */
    $use_fallback_image = isset($options['_client_and_product_testimonial_use_fallback_image']) ? $options['_client_and_product_testimonial_use_fallback_image'] : '1';
    // setup the testimonial ID to retreive
    if (isset($atts['testimonial'])) {
        $testimonial_array = explode(',', $atts['testimonial']);
        if ($testimonial_array && is_array($testimonial_array) && count($testimonial_array) > 1) {
            /* Array of testimonial IDs */
            $random_testimonial_id = array_rand($testimonial_array, 1);
            $testimonial_id = $testimonial_array[$random_testimonial_id];
        } else {
            if (is_numeric($atts['testimonial'])) {
                /* Single testimonial by ID */
                $testimonial_id = (int) $atts['testimonial'];
            } else {
                /* Pass in testimonial by title */
                $post_array = get_page_by_title($atts['testimonial'], OBJECT, 'testimonial');
                if (!is_wp_error($post_array)) {
                    $testimonial_id = $post_array->ID;
                }
            }
        }
    }
    // Exclude testimonials
    $excluded_testimonials = !empty($atts['exclude']) ? explode(',', $atts['exclude']) : array();
    $excluded_testimonial_ids = array();
    /* Check for excluded testimonials */
    if (!empty($excluded_testimonials)) {
        foreach ($excluded_testimonials as $exclude_testimonial) {
            if (is_numeric($exclude_testimonial)) {
                $excluded_testimonial_ids[] = $exclude_testimonial;
            } else {
                $testimonial = get_page_by_title($exclude_testimonial, OBJECT, 'testimonial');
                if ($testimonial) {
                    $excluded_testimonial_ids[] = $testimonial->ID;
                }
            }
        }
    }
    // Random post returned
    if (!isset($testimonial_id)) {
        $args = array('post_type' => 'testimonial', 'posts_per_page' => 1, 'status' => 'publish', 'orderby' => !empty($atts['orderby']) ? $atts['orderby'] : 'rand', 'order' => !empty($atts['order']) ? $atts['order'] : 'DESC');
    } else {
        // specific post is returned
        $args = array('post_type' => 'testimonial', 'posts_per_page' => 1, 'status' => 'publish', 'post__in' => array($testimonial_id));
    }
    /* 
     *	Append the excluded post IDs 
     *	passed in via exclude="1,2,3"
     */
    if (!empty($excluded_testimonial_ids)) {
        $args['post__not_in'] = $excluded_testimonial_ids;
    }
    $testmonial_query = new WP_Query(apply_filters('client_and_product_testimonials_full_width_query_args', $args));
    // start output buffering to catch the list
    ob_start();
    /* Generate the HTML debugging comment (inside capt-helpers.php) */
    echo generate_capt_html_comments('Testimonial Full Width', $atts);
    if ($testmonial_query->have_posts()) {
        $testmonial_query->the_post();
        // Un-minified for testing - enqueue the list styles
        // wp_enqueue_style( 'testmonial-full-width-styles', Client_Product_Testimonials_URL . 'lib/public/css/testimonial-full-width-styles.css', array( capt_get_themes_last_enqueued_style() ) );
        // Minified Styles - Global for all testimonial shortcodes
        wp_enqueue_style('capt-styles', Client_Product_Testimonials_URL . 'lib/public/css/min/client-and-product-testimonials.min.css', array(capt_get_themes_last_enqueued_style()));
        ?>
				<section class="capt-testimonial-full-width-section capt-testimonial-<?php 
        echo get_the_ID();
        ?>
">
					<section class="interior-container">
						<section class="testimonial-content-text">
							<cite><?php 
        echo apply_filters('capt_content', get_the_content());
        ?>
</cite>
						</section>
						<?php 
        if (has_post_thumbnail(get_the_ID())) {
            $attachment_alt_text = get_post_meta(get_post_thumbnail_id(get_the_ID()), '_wp_attachment_image_alt', true);
            echo get_the_post_thumbnail(get_the_ID(), 'testimonial-image', array('class' => 'testimonial-image capt-image-' . $image_style . ' ' . $images_greyscale, 'alt' => $attachment_alt_text, 'title' => get_the_title()));
        } else {
            if ($use_fallback_image == '1') {
                $fallback_image_id = (int) $options['_client_and_product_testimonial_no_photo_fallback_id'];
                echo wp_get_attachment_image($fallback_image_id, 'testimonial-image', false, array('class' => 'testimonial-image capt-image-' . $image_style . ' ' . $images_greyscale . ' wp-post-image', 'alt' => __('No Image Provided', 'client-and-product-testimonials'), 'title' => __('No Image Provided', 'client-and-product-testimonials')));
            }
        }
        ?>
						<span class="testimonial-author">
							<section><?php 
        echo get_the_title(get_the_ID());
        ?>
</section>
						</span>
						<small class="testimonial-details"><?php 
        echo eh_get_testimonial_details(get_the_ID());
        ?>
</small>
						<?php 
        echo eh_cmb2_get_star_rating_field(get_the_ID());
        ?>
					</section>
				</section>
			<?php 
    } else {
        ?>
				<section><?php 
        _e('Testimonial not found.', 'client-and-product-testimonials');
        ?>
</section>
			<?php 
    }
    wp_reset_query();
    // clean up output buffering
    $testimonial_section = ob_get_clean();
    // return the list
    return $testimonial_section;
}