<?php
/**
 * The file of html inside the loop.
 *
 * @package Smart_Post_Show_Pro
 * @subpackage Smart_Post_Show_Pro/public/helper
 *
 * @since 2.0.0
 */

// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
	die;
}
/**
 * Post all html method.
 *
 * @since 2.0.0
 */
class SP_PCP_HTML {

	/**
	 * Post title html.
	 *
	 * @param array  $sorter post content option array.
	 * @param string $layout layout preset.
	 * @param string $options Shortcode options.
	 * @param object $post post.
	 * @param bool   $is_table is table layout.
	 * @return void
	 */
	public static function pcp_post_title( $sorter, $layout, $options, $post, $is_table = false ) {

		$_meta_settings     = SP_PCP_Functions::pcp_metabox_value( 'pcp_post_meta', $sorter );
		$post_meta_fields   = SP_PCP_Functions::pcp_metabox_value( 'pcp_post_meta_group', $_meta_settings );
		$show_post_meta     = SP_PCP_Functions::pcp_metabox_value( 'show_post_meta', $_meta_settings, true );
		$pcp_page_link_type = SP_PCP_Functions::pcp_metabox_value( 'pcp_page_link_type', $options );
		$pcp_link_rel       = SP_PCP_Functions::pcp_metabox_value( 'pcp_link_rel', $options );
		$pcp_link_rel_text  = '1' === $pcp_link_rel ? 'rel=nofollow' : '';

		$pcp_link_target = SP_PCP_Functions::pcp_metabox_value( 'pcp_link_target', $options );
		if ( is_array( $post_meta_fields ) && 'accordion_layout' !== $layout && $show_post_meta ) {
			foreach ( $post_meta_fields as $each_meta ) {
				if ( 'taxonomy' === $each_meta['select_post_meta'] ) {
					$taxonomy      = $each_meta['post_meta_taxonomy'] ?? '';
					$meta_position = $each_meta['pcp_meta_position'];
					if ( 'above_title' === $meta_position ) {
						$terms = get_the_term_list( $post->ID, $taxonomy, '', ' ' );
						if ( $terms ) {
							ob_start();
							include SP_PCP_Functions::pcp_locate_template( 'item/meta-over-title.php' );
							$meta_over_title = apply_filters( 'pcp_meta_over_title', ob_get_clean() );
							echo wp_kses_post( $meta_over_title );
						}
					}
				}
			}
		}

		$post_title_setting = isset( $sorter['pcp_post_title'] ) ? $sorter['pcp_post_title'] : '';
		$show_post_title    = SP_PCP_Functions::pcp_metabox_value( 'show_post_title', $post_title_setting );

		$pcp_post_title = get_the_title( $post->ID );
		if ( $show_post_title && ! empty( $pcp_post_title ) ) {
			// Post Title Settings.
			$post_title_tag             = SP_PCP_Functions::pcp_metabox_value( 'post_title_tag', $post_title_setting, 'h2' );
			$limit_post_title           = SP_PCP_Functions::pcp_metabox_value( 'post_title_limit', $post_title_setting );
			$show_product_category_name = isset( $post_title_setting['show_product_category_name'] ) ? $post_title_setting['show_product_category_name'] : '';

			if ( 'limit-title' === $limit_post_title ) {
				$post_title_length = ! empty( $post_title_setting['pcp_title_length']['all'] ) ? $post_title_setting['pcp_title_length'] : array(
					'all'  => '30',
					'unit' => 'characters',
				);
				if ( 'words' === $post_title_length['unit'] ) {
					$pcp_post_title = SP_PCP_Functions::pcp_extract_words_from_html( $pcp_post_title, (int) $post_title_length['all'], '...' );
				} else {
					$pcp_post_title = SP_PCP_Functions::limit_post_title( $pcp_post_title, (int) $post_title_length['all'] );
				}
			}

			$allowed_html_tags = array(
				'em'     => array(),
				'strong' => array(),
				'sup'    => array(),
				'i'      => array(),
				'small'  => array(),
				'del'    => array(),
				'ins'    => array(),
				'br'     => array(),
				'span'   => array(
					'style' => array(),
					'class' => array(),
				),
			);
			$td                = self::table_td( $is_table );
			$allow_tag         = array( 'td' => array() );
			ob_start();
			echo wp_kses( $td['start'], $allow_tag );
			include SP_PCP_Functions::pcp_locate_template( 'item/title.php' );
			echo wp_kses( $td['end'], $allow_tag );
			$title = apply_filters( 'pcp_item_title', ob_get_clean() );
			echo wp_kses_post( $title );
		}
	}

	/**
	 * Show product rating.
	 *
	 * @param  array $sorter field sorter.
	 * @param  array $options shortcode options.
	 * @param  int   $id post id.
	 * @param bool  $is_table is table layout.
	 * @return void
	 */
	public static function pcp_product_rating( $sorter, $options, $id, $is_table = false ) {
		$pcp_product_rating            = SP_PCP_Functions::pcp_metabox_value( 'pcp_product_rating', $sorter );
		$pcp_show_product_rating       = SP_PCP_Functions::pcp_metabox_value( 'pcp_show_product_rating', $pcp_product_rating );
		$pcp_show_product_review_count = SP_PCP_Functions::pcp_metabox_value( 'pcp_show_product_review_count', $pcp_product_rating );
		$pcp_select_post_type          = SP_PCP_Functions::pcp_metabox_value( 'pcp_select_post_type', $options );
		$td                            = self::table_td( $is_table );
		$allow_tag                     = array( 'td' => array() );
		if ( $pcp_show_product_rating && 'product' === $pcp_select_post_type && 'product' === get_post_type( $id ) ) {
			$product        = wc_get_product( $id );
			$av_rating      = $product->get_average_rating();
			$review_count   = $product->get_review_count();
			$average_rating = ( $av_rating / 5 ) * 100;
			ob_start();
			echo wp_kses( $td['start'], $allow_tag );
			if ( $average_rating > 0 ) {
				include SP_PCP_Functions::pcp_locate_template( 'item/product-rating.php' );
			}
			echo wp_kses( $td['end'], $allow_tag );
			$product_rating = apply_filters( 'pcp_item_product_rating', ob_get_clean() );
			echo wp_kses_post( $product_rating );
		}
	}

	/**
	 * Show product price.
	 *
	 * @param array $sorter The field ID array.
	 * @param array $options options.
	 * @param int   $id post id.
	 * @param bool  $is_table is table layout.
	 * @return void
	 */
	public static function pcp_product_price( $sorter, $options, $id, $is_table = false ) {
		$pcp_product_price      = SP_PCP_Functions::pcp_metabox_value( 'pcp_product_price', $sorter );
		$pcp_show_product_price = SP_PCP_Functions::pcp_metabox_value( 'pcp_show_product_price', $pcp_product_price );
		$pcp_select_post_type   = SP_PCP_Functions::pcp_metabox_value( 'pcp_select_post_type', $options );
		if ( $pcp_show_product_price && 'product' === $pcp_select_post_type && 'product' === get_post_type( $id ) ) {
			$td         = self::table_td( $is_table );
			$allow_tag  = array( 'td' => array() );
			$product    = wc_get_product( $id );
			$price_html = $product->get_price_html();
			if ( ! empty( $price_html ) ) {
				ob_start();
				echo wp_kses( $td['start'], $allow_tag );
				include SP_PCP_Functions::pcp_locate_template( 'item/product-price.php' );
				echo wp_kses( $td['end'], $allow_tag );
				$product_price = apply_filters( 'pcp_item_product_price', ob_get_clean() );
				echo wp_kses_post( $product_price );
			}
		}
	}

	/**
	 * Show product cart.
	 *
	 * @param array $sorter The field ID array.
	 * @param array $options options.
	 * @param int   $id post id.
	 * @param bool  $is_table is table layout.
	 * @return void
	 */
	public static function pcp_product_cart( $sorter, $options, $id, $is_table = false ) {
		$pcp_product_cart             = SP_PCP_Functions::pcp_metabox_value( 'pcp_product_cart', $sorter );
		$pcp_show_product_cart_button = SP_PCP_Functions::pcp_metabox_value( 'pcp_show_product_cart_button', $pcp_product_cart );
		$pcp_select_post_type         = SP_PCP_Functions::pcp_metabox_value( 'pcp_select_post_type', $options );
		if ( $pcp_show_product_cart_button && 'product' === $pcp_select_post_type && 'product' === get_post_type( $id ) ) {
			$td        = self::table_td( $is_table );
			$allow_tag = array( 'td' => array() );
			$pcp_cart  = apply_filters( 'pcp_filter_product_cart', do_shortcode( '[add_to_cart id="' . $id . '" show_price="false" style="none"]' ) );
			ob_start();
			echo wp_kses( $td['start'], $allow_tag );
			include SP_PCP_Functions::pcp_locate_template( 'item/product-cart.php' );
			echo wp_kses( $td['end'], $allow_tag );
			$product_cart = apply_filters( 'pcp_item_product_cart', ob_get_clean() );

			echo wp_kses_post( $product_cart );
		}
	}

	/**
	 * Show Post Content html.
	 *
	 * @param array  $sorter The field ID array.
	 * @param string $layout layout preset.
	 * @param array  $options options.
	 * @param object $post post.
	 * @param bool   $is_table is table layout.
	 * @return void
	 */
	public static function pcp_content_html( $sorter, $layout, $options, $post, $is_table = false ) {
		$post_content_setting          = SP_PCP_Functions::pcp_metabox_value( 'pcp_post_content', $sorter );
		$show_post_content             = SP_PCP_Functions::pcp_metabox_value( 'show_post_content', $post_content_setting );
		$show_read_more                = SP_PCP_Functions::pcp_metabox_value( 'show_read_more', $post_content_setting );
		$pcp_content_type              = SP_PCP_Functions::pcp_metabox_value( 'post_content_type', $post_content_setting );
		$pcp_select_post_type          = SP_PCP_Functions::pcp_metabox_value( 'pcp_select_post_type', $options );
		$pcp_select_multiple_post_type = SP_PCP_Functions::pcp_metabox_value( 'pcp_select_multiple_post_type', $options );
		$_meta_settings                = SP_PCP_Functions::pcp_metabox_value( 'pcp_post_meta', $sorter );
		$show_product_category_name    = isset( $sorter['pcp_post_title']['show_product_category_name'] ) ? $sorter['pcp_post_title']['show_product_category_name'] : '';
		$td                            = self::table_td( $is_table );
		$allow_tag                     = array( 'td' => array() );
		if ( $show_post_content || $show_read_more ) {
			ob_start();
			echo wp_kses( $td['start'], $allow_tag );
			include SP_PCP_Functions::pcp_locate_template( 'item/content.php' );
			echo wp_kses( $td['end'], $allow_tag );
			$description = apply_filters( 'pcp_item_description', ob_get_clean() );
			echo $description;
		}
	}

	/**
	 * Read more function
	 *
	 * @param array  $view_options Read more options array.
	 * @param array  $content_type The content type.
	 * @param array  $options Shortcode options.
	 * @param object $post post.
	 */
	public static function pcp_readmore( $view_options, $content_type, $options, $post ) {
		$show_read_more = isset( $view_options['show_read_more'] ) ? $view_options['show_read_more'] : '';
		if ( ! $show_read_more || 'full_content' === $content_type ) {
			return '';
		}
		$read_more_type     = isset( $view_options['read_more_type'] ) ? $view_options['read_more_type'] : '';
		$pcp_read_label     = isset( $view_options['pcp_read_label'] ) ? $view_options['pcp_read_label'] : '';
		$pcp_page_link_type = SP_PCP_Functions::pcp_metabox_value( 'pcp_page_link_type', $options );
		$pcp_link_rel       = SP_PCP_Functions::pcp_metabox_value( 'pcp_link_rel', $options );
		$pcp_link_rel_text  = '';
		$pcp_link_rel_text  = '1' === $pcp_link_rel ? 'rel=nofollow' : '';

		$readmore_target = SP_PCP_Functions::pcp_metabox_value( 'pcp_link_target', $options );
		ob_start();
		include SP_PCP_Functions::pcp_locate_template( 'item/read-more.php' );
		$read_more_button = apply_filters( 'pcp_read_more_btn', ob_get_clean(), $link = get_permalink( $post ) );
		echo wp_kses_post( $read_more_button );
	}

	/**
	 * Post thumb HTML.
	 *
	 * @param array  $sorter post content option array.
	 * @param int    $scode_id Shortcode ID.
	 * @param object $slide The slide/post.
	 * @param array  $options Shortcode options.
	 * @param array  $layout layout options.
	 * @param bool   $is_table is table layout.
	 * @return void
	 */
	public static function pcp_post_thumb_html( $sorter, $scode_id, $slide, $options, $layout, $is_table = false ) {
		$_post_thumb_setting = SP_PCP_Functions::pcp_metabox_value( 'pcp_post_thumb', $sorter );
		$pcp_page_link_type  = SP_PCP_Functions::pcp_metabox_value( 'pcp_page_link_type', $options );
		$pcp_link_rel        = SP_PCP_Functions::pcp_metabox_value( 'pcp_link_rel', $options );
		$pcp_post_type       = isset( $options['pcp_select_post_type'] ) && ! empty( $options['pcp_select_post_type'] ) ? $options['pcp_select_post_type'] : 'any';
		$is_attachment       = false;
		if ( 'attachment' === $pcp_post_type ) {
			$is_attachment = true;
		}
		$pcp_link_rel_text    = '1' === $pcp_link_rel ? 'rel=nofollow' : '';
		$pcp_select_post_type = SP_PCP_Functions::pcp_metabox_value( 'pcp_select_post_type', $options );
		$pcp_link_target      = SP_PCP_Functions::pcp_metabox_value( 'pcp_link_target', $options );
		if ( SP_PCP_Functions::pcp_metabox_value( 'post_thumb_show', $_post_thumb_setting ) ) {
			$pcp_image_attr  = SP_PCP_Functions::pcp_sized_thumb( $_post_thumb_setting, $slide->ID, $is_attachment, $scode_id );
			$thumb_url       = $pcp_image_attr['src'];
			$retina_img_src  = $pcp_image_attr['2x_src'];
			$retina_img_attr = '';
			if ( ! empty( $retina_img_src ) ) {
				$retina_img_attr = 'srcset="' . esc_attr( $thumb_url ) . ', ' . esc_attr( $retina_img_src ) . ' 2x"';
			}
			$alter_text       = SP_PCP_Functions::pcp_thumb_alter_text( $slide->ID );
			$_meta_settings   = SP_PCP_Functions::pcp_metabox_value( 'pcp_post_meta', $sorter );
			$post_meta_fields = SP_PCP_Functions::pcp_metabox_value( 'pcp_post_meta_group', $_meta_settings );
			$show_post_meta   = SP_PCP_Functions::pcp_metabox_value( 'show_post_meta', $_meta_settings, true );
			$td               = self::table_td( $is_table );
			$allow_tag        = array( 'td' => array() );
			if ( ! empty( $thumb_url ) ) {
				ob_start();
				echo wp_kses( $td['start'], $allow_tag );
				include SP_PCP_Functions::pcp_locate_template( 'item/thumbnail.php' );
				echo wp_kses( $td['end'], $allow_tag );

				$item_thumb = apply_filters( 'pcp_item_thumbnail', ob_get_clean() );
				echo $item_thumb; // phpcs:ignore
			}
		}
	}

	/**
	 * Over Thumb meta taxonomy
	 *
	 * @param  mixed  $post_meta_fields meta field.
	 * @param  mixed  $show_post_meta show meta.
	 * @param  object $post post.
	 * @return void
	 */
	public static function over_thumb_meta_taxonomy( $post_meta_fields, $show_post_meta, $post ) {
		if ( is_array( $post_meta_fields ) && $show_post_meta ) {
			foreach ( $post_meta_fields as $each_meta ) {
				if ( 'taxonomy' === $each_meta['select_post_meta'] ) {
					$taxonomy      = $each_meta['post_meta_taxonomy'] ?? '';
					$meta_position = $each_meta['pcp_meta_position'];
					if ( 'over_thumb' === $meta_position ) {
						$meta_over_thumb_position = isset( $each_meta['pcp_meta_over_thump_position'] ) ? $each_meta['pcp_meta_over_thump_position'] : 'top_left';
						$terms                    = get_the_term_list( $post->ID, $taxonomy, '', ' ' );
						if ( $terms ) {
							ob_start();
							include SP_PCP_Functions::pcp_locate_template( 'item/over-thumb-taxonomy.php' );
							$item_over_thumb_taxonomy = apply_filters( 'item_over_thumb_taxonomy', ob_get_clean(), $terms );
							echo wp_kses_post( $item_over_thumb_taxonomy );
						}
					}
				}
			}
		}
	}

	/**
	 * Post meta HTML
	 *
	 * @param array  $sorter post content option array.
	 * @param int    $visitor_count views count.
	 * @param array  $options options.
	 * @param object $post post.
	 * @param object $is_table check table layout or not.
	 * @return void
	 */
	public static function pcp_post_meta_html( $sorter, $visitor_count, $options, $post, $is_table = false ) {
		$_meta_settings       = SP_PCP_Functions::pcp_metabox_value( 'pcp_post_meta', $sorter );
		$post_meta_fields     = SP_PCP_Functions::pcp_metabox_value( 'pcp_post_meta_group', $_meta_settings );
		$show_post_meta       = SP_PCP_Functions::pcp_metabox_value( 'show_post_meta', $_meta_settings, true );
		$_meta_separator      = SP_PCP_Functions::pcp_metabox_value( 'meta_separator', $_meta_settings );
		$pcp_select_post_type = SP_PCP_Functions::pcp_metabox_value( 'pcp_select_post_type', $options );
		if ( $post_meta_fields && $show_post_meta && 'product' !== $pcp_select_post_type ) {
			ob_start();
			include SP_PCP_Functions::pcp_locate_template( 'item/meta.php' );
			$item_meta = apply_filters( 'pcp_item_meta', ob_get_clean() );
			echo wp_kses_post( $item_meta );
		}
	}

	/**
	 * Post Social Html
	 *
	 * @param array  $field_id post content option array.
	 * @param array  $options options.
	 * @param object $pcp_post post.
	 * @param bool   $is_table is table layout.
	 * @return void
	 */
	public static function pcp_social_share_html( $field_id, $options, $pcp_post, $is_table = false ) {
		$post_social          = SP_PCP_Functions::pcp_metabox_value( 'pcp_social_share', $field_id );
		$social_share_media   = SP_PCP_Functions::pcp_metabox_value( 'social_sharing_media', $post_social );
		$social_icon_shape    = SP_PCP_Functions::pcp_metabox_value( 'social_icon_shape', $post_social );
		$pcp_select_post_type = SP_PCP_Functions::pcp_metabox_value( 'pcp_select_post_type', $options );
		$td                   = self::table_td( $is_table );
		$allow_tag            = array( 'td' => array() );
		?>
		<?php
		if ( $social_share_media && 'product' !== $pcp_select_post_type ) {
			ob_start();
			echo wp_kses( $td['start'], $allow_tag );
				include SP_PCP_Functions::pcp_locate_template( 'item/social-share.php' );
			echo wp_kses( $td['end'], $allow_tag );
			$social_share = apply_filters( 'pcp_item_social_share', ob_get_clean() );
			echo $social_share;
		}
	}

	/**
	 * Post content with thumb.
	 *
	 * @param array  $sorter post sorting option.
	 * @param string $layout Layout preset.
	 * @param int    $visitor_count visitor number.
	 * @param int    $scode_id The Shortcode ID.
	 * @param object $post The Post object.
	 * @param array  $options Shortcode options.
	 * @param bool   $is_table is table layout.
	 * @return void
	 */
	public static function pcp_post_content_with_thumb( $sorter, $layout, $visitor_count, $scode_id, $post, $options, $is_table = false ) {
		if ( $sorter ) {
			foreach ( $sorter as $style_key => $style_value ) {
				switch ( $style_key ) {
					case 'pcp_post_thumb':
						self::pcp_post_thumb_html( $sorter, $scode_id, $post, $options, $layout, $is_table );
						break;
					case 'pcp_post_title':
						self::pcp_post_title( $sorter, $layout, $options, $post, $is_table );
						break;
					case 'pcp_post_content':
						self::pcp_content_html( $sorter, $layout, $options, $post, $is_table );
						break;
					case 'pcp_post_meta':
						self::pcp_post_meta_html( $sorter, $visitor_count, $options, $post, $is_table );
						break;
					case 'pcp_social_share':
						self::pcp_social_share_html( $sorter, $options, $post, $is_table );
						break;
					case 'pcp_custom_fields':
						sp_pcp_custom_field_html( $post, $sorter, true, $is_table );
						break;
					case 'pcp_product_rating':
						self::pcp_product_rating( $sorter, $options, $post->ID, $is_table );
						break;
					case 'pcp_product_price':
						self::pcp_product_price( $sorter, $options, $post->ID, $is_table );
						break;
					case 'pcp_product_cart':
						self::pcp_product_cart( $sorter, $options, $post->ID, $is_table );
						break;
				}
			}
		}
	}

	/**
	 * Table Heading
	 *
	 * @param  array $sorter sorter setting.
	 * @param  bool  $is_product is product type.
	 * @return void
	 */
	public static function pcp_post_with_table_heading( $sorter, $is_product = false ) {
		$th_start  = '<th>';
		$th_end    = '</th>';
		$allow_tag = array( 'th' => array() );
		if ( $sorter ) {
			foreach ( $sorter as $style_key => $style_value ) {
				switch ( $style_key ) {
					case 'pcp_post_thumb':
						$_post_thumb_setting = SP_PCP_Functions::pcp_metabox_value( 'pcp_post_thumb', $sorter );
						if ( SP_PCP_Functions::pcp_metabox_value( 'post_thumb_show', $_post_thumb_setting ) ) {
							echo wp_kses( $th_start, $allow_tag );
							echo esc_html__( 'Thumbnail', 'smart-post-show-pro' );
							echo wp_kses( $th_end, $allow_tag );
						}
						break;
					case 'pcp_post_title':
						$post_title_setting = isset( $sorter['pcp_post_title'] ) ? $sorter['pcp_post_title'] : '';
						$show_post_title    = SP_PCP_Functions::pcp_metabox_value( 'show_post_title', $post_title_setting );
						if ( $show_post_title ) {
							echo wp_kses( $th_start, $allow_tag );
							echo esc_html__( 'Title', 'smart-post-show-pro' );
							echo wp_kses( $th_end, $allow_tag );
						}
						break;
					case 'pcp_post_content':
						$post_content_setting = SP_PCP_Functions::pcp_metabox_value( 'pcp_post_content', $sorter );
						$show_post_content    = SP_PCP_Functions::pcp_metabox_value( 'show_post_content', $post_content_setting );
						$show_read_more       = SP_PCP_Functions::pcp_metabox_value( 'show_read_more', $post_content_setting );
						if ( $show_post_content || $show_read_more ) {
								echo wp_kses( $th_start, $allow_tag );
								echo esc_html__( 'Content', 'smart-post-show-pro' );
								echo wp_kses( $th_end, $allow_tag );
						}
						break;
					case 'pcp_post_meta':
						if ( ! $is_product ) {
							$_meta_settings   = SP_PCP_Functions::pcp_metabox_value( 'pcp_post_meta', $sorter );
							$_show_post_meta  = SP_PCP_Functions::pcp_metabox_value( 'show_post_meta', $_meta_settings );
							$post_meta_fields = SP_PCP_Functions::pcp_metabox_value( 'pcp_post_meta_group', $_meta_settings );
							if ( $_show_post_meta ) {
								SP_PCP_Functions::pcp_get_post_meta_on_table_heading( $post_meta_fields );
							}
						}
						break;
					case 'pcp_social_share':
						$post_social        = SP_PCP_Functions::pcp_metabox_value( 'pcp_social_share', $sorter );
						$social_share_media = SP_PCP_Functions::pcp_metabox_value( 'social_sharing_media', $post_social );
						if ( $social_share_media ) {
							echo wp_kses( $th_start, $allow_tag );
							echo esc_html__( 'Social', 'smart-post-show-pro' );
							echo wp_kses( $th_end, $allow_tag );

						}
						break;
					case 'pcp_custom_fields':
						$pcp_custom_fields   = $sorter['pcp_custom_fields'];
						$custom_field_groups = SP_PCP_Functions::pcp_metabox_value( 'pcp_custom_fields_group', $pcp_custom_fields );
						if ( ! empty( $custom_field_groups ) ) {
							echo wp_kses( $th_start, $allow_tag );
							echo esc_html__( 'Fields', 'smart-post-show-pro' );
							echo wp_kses( $th_end, $allow_tag );

						}
						break;
					case 'pcp_product_rating':
						$pcp_product_rating      = SP_PCP_Functions::pcp_metabox_value( 'pcp_product_rating', $sorter );
						$pcp_show_product_rating = SP_PCP_Functions::pcp_metabox_value( 'pcp_show_product_rating', $pcp_product_rating );
						if ( $pcp_show_product_rating && $is_product ) {
							echo wp_kses( $th_start, $allow_tag );
							echo esc_html__( 'Rating', 'smart-post-show-pro' );
							echo wp_kses( $th_end, $allow_tag );

						}
						break;
					case 'pcp_product_price':
						$pcp_product_price      = SP_PCP_Functions::pcp_metabox_value( 'pcp_product_price', $sorter );
						$pcp_show_product_price = SP_PCP_Functions::pcp_metabox_value( 'pcp_show_product_price', $pcp_product_price );
						if ( $pcp_show_product_price && $is_product ) {
							echo wp_kses( $th_start, $allow_tag );
							echo esc_html__( 'Price', 'smart-post-show-pro' );
							echo wp_kses( $th_end, $allow_tag );

						}
						break;
					case 'pcp_product_cart':
						$pcp_product_price            = SP_PCP_Functions::pcp_metabox_value( 'pcp_product_cart', $sorter );
						$pcp_show_product_cart_button = SP_PCP_Functions::pcp_metabox_value( 'pcp_show_product_cart_button', $pcp_product_price );
						if ( $pcp_show_product_cart_button && $is_product ) {
							echo wp_kses( $th_start, $allow_tag );
							echo esc_html__( 'Add to cart', 'smart-post-show-pro' );
							echo wp_kses( $th_end, $allow_tag );

						}
						break;
				}
			}
		}
	}
	/**
	 * Post content without thumb.
	 *
	 * @param array  $sorter post sorting option.
	 * @param string $layout Layout preset.
	 * @param int    $visitor_count visitor number.
	 * @param object $post visitor number.
	 * @param array  $options Shortcode options.
	 * @return void
	 */
	public static function pcp_post_content_without_thumb( $sorter, $layout, $visitor_count, $post, $options ) {
		if ( $sorter ) {
			foreach ( $sorter as $style_key => $style_value ) {
				switch ( $style_key ) {
					case 'pcp_post_title':
						self::pcp_post_title( $sorter, $layout, $options, $post );
						break;
					case 'pcp_post_content':
						self::pcp_content_html( $sorter, $layout, $options, $post );
						break;
					case 'pcp_post_meta':
						self::pcp_post_meta_html( $sorter, $visitor_count, $options, $post );
						break;
					case 'pcp_social_share':
						self::pcp_social_share_html( $sorter, $options, $post );
						break;
					case 'pcp_custom_fields':
						sp_pcp_custom_field_html( $post, $sorter );
						break;
					case 'pcp_product_rating':
						self::pcp_product_rating( $sorter, $options, $post->ID );
						break;
					case 'pcp_product_price':
						self::pcp_product_price( $sorter, $options, $post->ID );
						break;
					case 'pcp_product_cart':
						self::pcp_product_cart( $sorter, $options, $post->ID );
						break;
				}
			}
		}
	}

	/**
	 * HTML classes for Post.
	 *
	 * @param array  $options setting.
	 * @param array  $layout_settings layouts settings.
	 * @param string $post_id shortcode id.
	 * @return string
	 */
	public static function pcp_alt_post_class( $options, $layout_settings, $post_id = null ) {
		// $layout           = SP_PCP_Functions::view_layouts( $post_id );
		$layout_preset            = isset( $layout_settings['pcp_layout_preset'] ) ? $layout_settings['pcp_layout_preset'] : '';
		$post_content_orientation = isset( $options['post_content_orientation'] ) ? $options['post_content_orientation'] : '';

		$post_list_orientation = $layout_settings['post_list_orientation'] ?? '';

		$content_position = 'slider_layout' === $layout_preset || 'thumbnails_slider' === $layout_preset ? 'overlay' : $post_content_orientation;
		if ( 'list_layout' === $layout_preset ) {
			if ( 'left-thumb' === $post_list_orientation ) {
				$pcp_alt_post_class = 'sp-pcp-post left-thumb';
			} else {
				$pcp_alt_post_class = 'right-thumb sp-pcp-post';
			}
		} elseif ( 'left-thumb' === $content_position ) {
			$pcp_alt_post_class = 'sp-pcp-post left-thumb';
		} elseif ( 'carousel_layout' === $layout_preset || 'filter_layout' === $layout_preset || 'grid_layout' === $layout_preset || 'glossary_layout' === $layout_preset || 'large_with_small' === $layout_preset ) {
			if ( 'right-thumb' === $content_position ) {
				$pcp_alt_post_class = 'right-thumb sp-pcp-post';
			} elseif ( 'card' === $content_position ) {
				$pcp_alt_post_class = 'sp-pcp-content-padding sp-pcp-post';
			} elseif ( 'overlay' === $content_position ) {
				$pcp_alt_post_class = 'sp-overlay sp-pcp-post';
				switch ( $options['overlay_content_position'] ) {
					case 'top':
						$pcp_alt_post_class .= ' overlay-content-position-top';
						break;
					case 'middle':
						$pcp_alt_post_class .= ' overlay-content-position-middle';
						break;
					case 'bottom':
						$pcp_alt_post_class .= ' overlay-content-position-bottom';
						break;
				}
			} elseif ( 'overlay-box' === $content_position ) {
				$pcp_alt_post_class = 'sp-pcp-content-box sp-pcp-post';
				switch ( $options['box_content_position'] ) {
					case 'in_top':
						$pcp_alt_post_class .= ' content-box-position-in-top';
						break;
					case 'in_middle':
						$pcp_alt_post_class .= ' content-box-position-in-middle';
						break;
					case 'in_bottom':
						$pcp_alt_post_class .= ' content-box-position-in-bottom';
						break;
					case 'outer_right':
						$pcp_alt_post_class .= ' content-box-position-outer-right';
						break;
					case 'outer_top':
						$pcp_alt_post_class .= ' content-box-position-outer-top';
						break;
					case 'outer_bottom':
						$pcp_alt_post_class .= ' content-box-position-outer-bottom';
						break;
					case 'outer_left':
						$pcp_alt_post_class .= ' content-box-position-outer-left';
						break;
				}
			} else {
				$pcp_alt_post_class = 'sp-pcp-post';
			}
		} elseif ( 'slider_layout' === $layout_preset || 'thumbnails_slider' === $layout_preset ) {
			$pcp_alt_post_class                            = 'sp-overlay sp-pcp-post';
			$options['thumbnails_slider_content_position'] = isset( $options['thumbnails_slider_content_position'] ) ? $options['thumbnails_slider_content_position'] : 'middle';
			switch ( $options['thumbnails_slider_content_position'] ) {
				case 'top':
					$pcp_alt_post_class .= ' overlay-content-position-top';
					break;
				case 'middle':
					$pcp_alt_post_class .= ' overlay-content-position-middle';
					break;
				case 'bottom':
					$pcp_alt_post_class .= ' overlay-content-position-bottom';
					break;
				case 'in_middle':
					$pcp_alt_post_class = 'sp-pcp-content-box sp-pcp-post content-box-position-in-middle';
					break;
			}
		} elseif ( 'timeline_layout' === $layout_preset ) {
			$pcp_alt_post_class = 'sp-pcp-post pcp-timeline sp-pcp-inner-padding';
		} else {
			$pcp_alt_post_class = 'sp-pcp-post';
		}
		return apply_filters( 'post_post_class_name', $pcp_alt_post_class );
	}

	/**
	 * Post Loop.
	 *
	 * @param array  $options Views options.
	 * @param string $layout_settings Layout settings.
	 * @param array  $sorter Post sorting options.
	 * @param int    $pcp_count post number.
	 * @param int    $scode_id Shortcode ID.
	 * @param object $post post.
	 * @param int    $add_key ads position.
	 * @param array  $add_position_number ads position.
	 * @param array  $ads_content ads array.
	 * @return void
	 */
	public static function pcp_post_loop( $options, $layout_settings, $sorter, $pcp_count, $scode_id, $post, &$add_key, $add_position_number = array(), $ads_content = array() ) {
		// Fixed Visual composer shortcode during using ajax popup.
		if ( class_exists( 'WPBMap' ) && method_exists( 'WPBMap', 'addAllMappedShortcodes' ) ) {
			WPBMap::addAllMappedShortcodes();
		}
		$layout            = isset( $layout_settings['pcp_layout_preset'] ) ? $layout_settings['pcp_layout_preset'] : '';
		$number_of_columns = SP_PCP_Functions::pcp_metabox_value( 'pcp_number_of_columns', $options );
		$slide_effect      = SP_PCP_Functions::pcp_metabox_value( 'pcp_slide_effect', $options );
		$show_adv          = SP_PCP_Functions::pcp_metabox_value( 'show_adv', $options );
		$adv_position      = SP_PCP_Functions::pcp_metabox_value( 'adv_position', $options );
		$repeat_ads        = SP_PCP_Functions::pcp_metabox_value( 'repeat_ads', $options );
		$visitor_count     = get_post_meta( $post->ID, '_post_views_count', true );
		$lazy_load         = SP_PCP_Functions::pcp_metabox_value( 'pcp_lazy_load', $options );
		if ( 'cube' === $slide_effect || 'flip' === $slide_effect ) {
			$lazy_load = 'false';
		}
		$content_position = 'slider_layout' === $layout || 'thumbnails_slider' === $layout ? 'overlay' : SP_PCP_Functions::pcp_metabox_value( 'post_content_orientation', $options );

		if ( ( 'carousel_layout' === $layout || 'grid_layout' === $layout || 'filter_layout' === $layout || 'glossary_layout' === $layout ) && ( 'default' === $content_position ) ) {
			if ( $show_adv && is_array( $add_position_number ) ) {
				$real_adv_position = $pcp_count;
				if ( 'manual' === $adv_position ) {
					$real_adv_position = $add_key + $pcp_count;
				}
				if ( in_array( $real_adv_position, $add_position_number ) ) {
					?>
				<div class="<?php echo esc_attr( self::pcp_post_responsive_columns( $layout, $number_of_columns, $post->ID ) ); ?> pcp-advertisement-items">
					<?php
					$ads_content = self::pcp_ads_content( $add_key, $ads_content, $adv_position, $repeat_ads );
					echo $ads_content['content'];
					$add_key = $ads_content['key'];
					?>
				</div>
					<?php
				}
			}
			?>
		<div class="<?php echo esc_attr( self::pcp_post_responsive_columns( $layout, $number_of_columns, $post->ID ) ); ?>">
			<div class="sp-pcp-post pcp-item-<?php echo esc_attr( $post->ID ); ?>" data-id="<?php echo esc_attr( $post->ID ); ?>">
				<?php
				self::pcp_post_content_with_thumb( $sorter, $layout, $visitor_count, $scode_id, $post, $options );
				?>
			</div>
			<?php if ( ( 'carousel_layout' === $layout || 'slider_layout' === $layout || 'thumbnails_slider' === $layout ) && $lazy_load && 'ticker' !== SP_PCP_Functions::pcp_metabox_value( 'pcp_carousel_mode', $options ) ) { ?>
			<?php } ?>
		</div>
			<?php
		} elseif ( 'accordion_layout' === $layout ) {
			if ( $show_adv && is_array( $add_position_number ) ) {
				$real_adv_position = $pcp_count;
				if ( 'manual' === $adv_position ) {
					$real_adv_position = $add_key + $pcp_count;
				}
				if ( in_array( $real_adv_position, $add_position_number ) ) {
					?>
				<div class="sp-pcp-single-accordion pcp-advertisement-items">
					<?php
					$ads_content = self::pcp_ads_content( $add_key, $ads_content, $adv_position, $repeat_ads );
					echo $ads_content['content'];
					$add_key = $ads_content['key'];
					?>
				</div>
					<?php

				}
			}
			?>
			<div class="sp-pcp-single-accordion">
			<?php self::pcp_post_title( $sorter, $layout, $options, $post ); ?>
				<div class="pcp-collapse-body">
					<div class="sp-pcp-post left-thumb pcp-item-<?php echo esc_attr( $post->ID ); ?>" data-id="<?php echo esc_attr( $post->ID ); ?>">
				<?php self::pcp_post_thumb_html( $sorter, $scode_id, $post, $options, $layout ); ?>
					<div class="sp-pcp-post-details">
					<?php
					if ( $sorter ) {
						foreach ( $sorter as $style_key => $style_value ) {
							switch ( $style_key ) {
								case 'pcp_post_content':
									self::pcp_content_html( $sorter, $layout, $options, $post );
									break;
								case 'pcp_post_meta':
									self::pcp_post_meta_html( $sorter, $visitor_count, $options, $post );
									break;
								case 'pcp_social_share':
									self::pcp_social_share_html( $sorter, $options, $post );
									break;
								case 'pcp_custom_fields':
									sp_pcp_custom_field_html( $post, $sorter );
									break;
								case 'pcp_product_rating':
									self::pcp_product_rating( $sorter, $options, $post->ID );
									break;
								case 'pcp_product_price':
									self::pcp_product_price( $sorter, $options, $post->ID );
									break;
								case 'pcp_product_cart':
									self::pcp_product_cart( $sorter, $options, $post->ID );
									break;
							}
						}
					}
					?>
						</div>
					</div>
				</div>
			</div>
				<?php
		} elseif ( 'large_with_small' === $layout ) {
			$hierarchical_style = isset( $layout_settings['_one_other_style'] ) ? $layout_settings['_one_other_style'] : 'style_1';
			$animation_class    = '';
			if ( ( 'overlay' === $content_position || 'overlay-box' === $content_position ) ) {
					$animation_class = ( 'on_hover' === SP_PCP_Functions::pcp_metabox_value( 'post_overlay_content_visibility', $options ) ) ? SP_PCP_Functions::pcp_metabox_value( 'post_animation', $options ) . ' animated' : '';
			}
			if ( 1 === $pcp_count ) {
				$sorter['pcp_post_content']['pcp_content_length_type']['all'] = apply_filters( 'pcp_hr_grid_first_item_content_limit', $sorter['pcp_post_content']['pcp_content_length_type']['all'], $scode_id );
			}
			if ( 'style_2' === $hierarchical_style ) {
				if ( 1 === $pcp_count ) {
					?>
					<div class="sp-pcp-block-hierarchical  hierarchical-style-2">
				<?php } ?>
				<?php if ( 1 === $pcp_count || 2 === $pcp_count || 3 === $pcp_count || 4 === $pcp_count || 5 === $pcp_count ) { ?>
					<div class="sp-pcp-block-half style-2">
				<?php } elseif ( $pcp_count > 5 ) { ?>
					<div class="<?php echo esc_attr( self::pcp_post_responsive_columns( $layout, $number_of_columns, $post->ID ) ); ?>">
					<?php
				}
				?>
					<div class="<?php echo esc_attr( self::pcp_alt_post_class( $options, $layout_settings, $scode_id ) ); ?> pcp-item-<?php echo esc_attr( $post->ID ); ?>" data-id="<?php echo esc_attr( $post->ID ); ?>">
					<?php
					if ( $show_adv && is_array( $add_position_number ) ) {
						$real_adv_position = $pcp_count;
						if ( 'manual' === $adv_position ) {
							$real_adv_position = $add_key + $pcp_count;
						}
						if ( in_array( $real_adv_position, $add_position_number ) ) {
							$ads_content = self::pcp_ads_content( $add_key, $ads_content, $adv_position, $repeat_ads );
							echo $ads_content['content'];
							$add_key = $ads_content['key'];
						}
					}
					self::pcp_post_thumb_html( $sorter, $scode_id, $post, $options, $layout );
					?>
						<div class="sp-pcp-post-details <?php echo esc_html( $animation_class ); ?>">
							<div class="sp-pcp-post-details-content">
							<?php
							self::pcp_post_content_without_thumb( $sorter, $layout, $visitor_count, $post, $options );
							?>
							</div>
						</div>
					</div>
				</div>
				<?php
				if ( 5 === $pcp_count ) {
					echo '</div>';
				}
			} elseif ( 'style_4' === $hierarchical_style ) {
				if ( 1 === $pcp_count ) {
					?>
					<div class="sp-pcp-block-hierarchical  hierarchical-style-4">
				<?php } ?>
				<?php if ( 1 === $pcp_count || 2 === $pcp_count || 3 === $pcp_count || 4 === $pcp_count ) { ?>
					<div class="sp-pcp-block-half style-4">
				<?php } elseif ( $pcp_count > 4 ) { ?>
					<div class="<?php echo esc_attr( self::pcp_post_responsive_columns( $layout, $number_of_columns, $post->ID ) ); ?>">
					<?php
				}
				?>
					<div class="<?php echo esc_attr( self::pcp_alt_post_class( $options, $layout_settings, $scode_id ) ); ?> pcp-item-<?php echo esc_attr( $post->ID ); ?>" data-id="<?php echo esc_attr( $post->ID ); ?>">
					<?php
					if ( $show_adv && is_array( $add_position_number ) ) {
						$real_adv_position = $pcp_count;
						if ( 'manual' === $adv_position ) {
							$real_adv_position = $add_key + $pcp_count;
						}
						if ( in_array( $real_adv_position, $add_position_number ) ) {
							$ads_content = self::pcp_ads_content( $add_key, $ads_content, $adv_position, $repeat_ads );
							echo $ads_content['content'];
							$add_key = $ads_content['key'];
						}
					}
					self::pcp_post_thumb_html( $sorter, $scode_id, $post, $options, $layout );
					?>
						<div class="sp-pcp-post-details <?php echo esc_html( $animation_class ); ?>">
							<div class="sp-pcp-post-details-content">
							<?php
							self::pcp_post_content_without_thumb( $sorter, $layout, $visitor_count, $post, $options );
							?>
							</div>
						</div>
					</div>
				</div>
				<?php
				if ( 4 === $pcp_count ) {
					echo '</div>';
				}
			} elseif ( 'style_3' === $hierarchical_style ) {
				if ( 1 === $pcp_count ) {
					?>
				<div class="sp-pcp-col-xs-1">
				<?php } else { ?>
					<div class="<?php echo esc_attr( self::pcp_post_responsive_columns( $layout, $number_of_columns, $post->ID ) ); ?>">
						<?php
				}
				?>
				<div class="<?php echo esc_attr( self::pcp_alt_post_class( $options, $layout_settings, $scode_id ) ); ?> pcp-item-<?php echo esc_attr( $post->ID ); ?>" data-id="<?php echo esc_attr( $post->ID ); ?>">
				<?php
				if ( $show_adv && is_array( $add_position_number ) ) {
					$real_adv_position = $pcp_count;
					if ( 'manual' === $adv_position ) {
						$real_adv_position = $add_key + $pcp_count;
					}
					if ( in_array( $real_adv_position, $add_position_number ) ) {
						$ads_content = self::pcp_ads_content( $add_key, $ads_content, $adv_position, $repeat_ads );
						echo $ads_content['content'];
						$add_key = $ads_content['key'];
					}
				}

					self::pcp_post_thumb_html( $sorter, $scode_id, $post, $options, $layout );
				?>
					<div class="sp-pcp-post-details <?php echo esc_html( $animation_class ); ?>">
						<div class="sp-pcp-post-details-content">
						<?php
						self::pcp_post_content_without_thumb( $sorter, $layout, $visitor_count, $post, $options );
						?>
						</div>
					</div>
				</div>
			</div>
				<?php
			} elseif ( 'style_5' === $hierarchical_style ) {
				if ( 1 === $pcp_count || 2 === $pcp_count ) {
					echo '<div class="sp-pcp-block-6">';
				} elseif ( $pcp_count > 2 ) {
					?>
					<div class="<?php echo esc_attr( self::pcp_post_responsive_columns( $layout, $number_of_columns, $post->ID ) ); ?>">
					<?php
				}
				?>
				<div class="<?php echo esc_attr( self::pcp_alt_post_class( $options, $layout_settings, $scode_id ) ); ?> pcp-item-<?php echo esc_attr( $post->ID ); ?>" data-id="<?php echo esc_attr( $post->ID ); ?>">
					<?php
					if ( $show_adv && is_array( $add_position_number ) ) {
						$real_adv_position = $pcp_count;
						if ( 'manual' === $adv_position ) {
							$real_adv_position = $add_key + $pcp_count;
						}
						if ( in_array( $real_adv_position, $add_position_number ) ) {
							$ads_content = self::pcp_ads_content( $add_key, $ads_content, $adv_position, $repeat_ads );
							echo $ads_content['content'];
							$add_key = $ads_content['key'];
						}
					}

					self::pcp_post_thumb_html( $sorter, $scode_id, $post, $options, $layout );
					?>
					<div class="sp-pcp-post-details <?php echo esc_html( $animation_class ); ?>">
						<div class="sp-pcp-post-details-content">
					<?php
					self::pcp_post_content_without_thumb( $sorter, $layout, $visitor_count, $post, $options );
					?>
						</div>
					</div>
				</div>
			</div>
				<?php
			} else {
				if ( 1 === $pcp_count ) {
					echo '<div class="sp-pcp-block-hierarchical hierarchical-style-1">';
				}
				if ( 1 === $pcp_count || 2 === $pcp_count || 3 === $pcp_count ) {
					echo '<div class="sp-pcp-block-half style-1">';
				} elseif ( $pcp_count > 3 ) {
					?>
					<div class="<?php echo esc_attr( self::pcp_post_responsive_columns( $layout, $number_of_columns, $post->ID ) ); ?>">
					<?php
				}
				?>
				<div class="<?php echo esc_attr( self::pcp_alt_post_class( $options, $layout_settings, $scode_id ) ); ?> pcp-item-<?php echo esc_attr( $post->ID ); ?>" data-id="<?php echo esc_attr( $post->ID ); ?>">
					<?php
					if ( $show_adv && is_array( $add_position_number ) ) {
						$real_adv_position = $pcp_count;
						if ( 'manual' === $adv_position ) {
							$real_adv_position = $add_key + $pcp_count;
						}
						if ( in_array( $real_adv_position, $add_position_number ) ) {
							$ads_content = self::pcp_ads_content( $add_key, $ads_content, $adv_position, $repeat_ads );
							echo $ads_content['content'];
							$add_key = $ads_content['key'];
						}
					}

					self::pcp_post_thumb_html( $sorter, $scode_id, $post, $options, $layout );
					?>
					<div class="sp-pcp-post-details <?php echo esc_html( $animation_class ); ?>">
						<div class="sp-pcp-post-details-content">
					<?php
					self::pcp_post_content_without_thumb( $sorter, $layout, $visitor_count, $post, $options );
					?>
						</div>
					</div>
				</div>
			</div>
							<?php
							if ( 3 === $pcp_count ) {
								echo '</div>';
							}
			}
		} elseif ( 'table_layout' === $layout ) {
			if ( $show_adv && is_array( $add_position_number ) ) {
				$real_adv_position = $pcp_count;
				if ( 'manual' === $adv_position ) {
					$real_adv_position = $add_key + $pcp_count;
				}
				if ( in_array( $real_adv_position, $add_position_number ) ) {
					?>
				<tr class="sp-pcp-post pcp-item-<?php echo esc_attr( $post->ID ); ?> pcp-advertisement-items">
					<td>
					<?php
					$ads_content = self::pcp_ads_content( $add_key, $ads_content, $adv_position, $repeat_ads );
					echo $ads_content['content'];
					$add_key = $ads_content['key'];
					?>
					</td>
				</tr>
					<?php
				}
			}
			?>
			<tr class="sp-pcp-post pcp-item-<?php echo esc_attr( $post->ID ); ?>" data-id="<?php echo esc_attr( $post->ID ); ?>">
				<?php
				self::pcp_post_content_with_thumb( $sorter, $layout, $visitor_count, $scode_id, $post, $options, true );
				?>
			</tr>
			<?php
		} elseif ( 'timeline_layout' === $layout ) {
			// $layout_style   = SP_PCP_Functions::view_layouts( $scode_id );
			$timeline_style = isset( $layout_settings['timeline_other_style'] ) ? $layout_settings['timeline_other_style'] : 'timeline_style_1';
			if ( $show_adv && is_array( $add_position_number ) ) {
				$real_adv_position = $pcp_count;
				if ( 'manual' === $adv_position ) {
					$real_adv_position = $add_key + $pcp_count;
				}
				if ( in_array( $real_adv_position, $add_position_number ) ) {
					?>
				<div class="pcp-timeline-item pcp-advertisement-items">
					<div class="sp-pcp-post pcp-timeline sp-pcp-inner-padding">
						<?php
						$ads_content = self::pcp_ads_content( $add_key, $ads_content, $adv_position, $repeat_ads );
						echo $ads_content['content'];
						$add_key = $ads_content['key'];
						?>
					</div>
				</div>
					<?php
				}
			}
			?>
			<div class="pcp-timeline-item swiper-slide">
				<?php
				if ( 'timeline_style_1' !== $timeline_style ) {
					echo '<div class="sps-timeline-post-date">';
					$post_date = apply_filters( 'sps_timeline_top_date_modify', esc_html( date_i18n( get_option( 'date_format' ), strtotime( $post->post_date ) ) ) );
					?>
				<time class="entry-date published updated"><?php echo wp_kses_post( $post_date ); ?></time>
					<?php
					echo '</div>';
				}
				?>

				<div class="sp-pcp-post pcp-timeline sp-pcp-inner-padding pcp-item-<?php echo esc_attr( $post->ID ); ?>" data-id="<?php echo esc_attr( $post->ID ); ?>">
			<?php
				self::pcp_post_content_with_thumb( $sorter, $layout, $visitor_count, $scode_id, $post, $options );
			?>
				</div>
			</div>
			<?php
		} else {
			$animation_class = '';
			if ( ( 'overlay' === $content_position || 'overlay-box' === $content_position ) ) {
					$animation_class = ( 'on_hover' === SP_PCP_Functions::pcp_metabox_value( 'post_overlay_content_visibility', $options ) ) ? SP_PCP_Functions::pcp_metabox_value( 'post_animation', $options ) . ' animated' : '';
			}
			if ( 'list_layout' === $layout || 'zigzag_layout' === $layout ) {
				$animation_class = '';
			}
			if ( $show_adv && is_array( $add_position_number ) ) {
				$real_adv_position = $pcp_count;
				if ( 'manual' === $adv_position ) {
					$real_adv_position = $add_key + $pcp_count;
				}
				if ( in_array( $real_adv_position, $add_position_number ) ) {
					?>
				<div class="<?php echo esc_attr( self::pcp_post_responsive_columns( $layout, $number_of_columns, $post->ID ) ); ?> pcp-advertisement-items">
					<?php
					$ads_content = self::pcp_ads_content( $add_key, $ads_content, $adv_position, $repeat_ads );
					echo $ads_content['content'];
					$add_key = $ads_content['key'];
					?>
				</div>
					<?php
				}
			}
			?>
			<div class="<?php echo esc_attr( self::pcp_post_responsive_columns( $layout, $number_of_columns, $post->ID ) ); ?>">
			<div class="<?php echo esc_attr( self::pcp_alt_post_class( $options, $layout_settings, $scode_id ) ); ?> pcp-item-<?php echo esc_attr( $post->ID ); ?>" data-id="<?php echo esc_attr( $post->ID ); ?>">
			<?php
			self::pcp_post_thumb_html( $sorter, $scode_id, $post, $options, $layout );
			?>
				<div class="sp-pcp-post-details <?php echo esc_html( $animation_class ); ?>">
					<div class="sp-pcp-post-details-content">
			<?php
				self::pcp_post_content_without_thumb( $sorter, $layout, $visitor_count, $post, $options );
			?>
					</div>
				</div>
			</div>
			</div>
				<?php
		}
	}
	/**
	 * Ads content.
	 *
	 * @param int    $add_key ads position.
	 * @param array  $ads_content ads array.
	 * @param string $adv_position adv_position type.
	 * @param int    $repeat_ads repeat adv number.
	 * @return array
	 */
	public static function pcp_ads_content( $add_key, $ads_content = array(), $adv_position = 'random', $repeat_ads = 1 ) {
		$is_balance_tag  = apply_filters( 'pcp_ads_force_balance_tags', true );
		$pcp_ads_content = $is_balance_tag ? force_balance_tags( $ads_content[ $add_key ] ) : $ads_content[ $add_key ];
		$add_count       = count( $ads_content );
		if ( $add_key >= ( $add_count - 1 ) && ( 'random' === $adv_position || $repeat_ads > 1 ) ) {
			$add_key = 0;
		} else {
			++$add_key;
		}
		$pcp_ads_content = array(
			'content' => $pcp_ads_content,
			'key'     => $add_key,
		);
		return $pcp_ads_content;
	}

	/**
	 * Post responsive columns class.
	 *
	 * @param string $layout Layout preset.
	 * @param string $columns Columns number.
	 * @param int    $id post id.
	 * @return string
	 */
	public static function pcp_post_responsive_columns( $layout, $columns, $id ) {
		$pcp_post_columns = '';
		if ( 'carousel_layout' === $layout || 'slider_layout' === $layout || 'thumbnails_slider' === $layout ) {
			$pcp_post_columns = 'swiper-slide swiper-lazy sp-smart-pro-item';
		} elseif ( 'zigzag_layout' === $layout || 'list_layout' === $layout ) {
			$pcp_post_columns = 'sp-pcp-col-xs-1';
		} else {
			$pcp_post_columns = " sp-pcp-col-xs-$columns[mobile] sp-pcp-col-sm-$columns[mobile_landscape] sp-pcp-col-md-$columns[tablet] sp-pcp-col-lg-$columns[desktop] sp-pcp-col-xl-$columns[lg_desktop]";
			if ( 'filter_layout' === $layout ) {
				$pcp_post_columns .= ' item ' . join( ' ', get_post_class( '', $id ) );
				// Remove entry class for Twenty Nineteen css conflict.
				$pcp_post_columns = str_replace( 'entry', '', $pcp_post_columns );
			}
		}
		return $pcp_post_columns;
	}

	/**
	 * Pagination function
	 *
	 * @param object $loop Query array.
	 * @param array  $view_options options.
	 * @param array  $layout layout.
	 * @param array  $smart_show_id id.
	 * @param array  $paged paged.
	 * @param array  $on_screen screen type.
	 */
	public static function pcp_pagination_bar( $loop, $view_options, $layout, $smart_show_id, $paged = null, $on_screen = null ) {
		$posts_found    = $loop->found_posts;
		$post_offset    = isset( $view_options['pcp_post_offset'] ) ? $view_options['pcp_post_offset'] : 0;
		$posts_found    = (int) $posts_found - (int) $post_offset;
		$post_limit     = isset( $view_options['pcp_post_limit'] ) && ! empty( $view_options['pcp_post_limit'] ) ? $view_options['pcp_post_limit'] : 100000;
		$post_limit     = ( $post_limit > 0 && $posts_found > $post_limit ) ? $post_limit : $posts_found;
		$post_per_page  = isset( $view_options['post_per_page'] ) ? $view_options['post_per_page'] : 12;
		$post_per_click = isset( $view_options['post_load_per_click'] ) ? $view_options['post_load_per_click'] : 12;

		$post_per_page = ( $post_per_page > $post_limit ) ? $post_limit : $post_per_page;

		$layout_preset = isset( $layout['pcp_layout_preset'] ) ? $layout['pcp_layout_preset'] : '';
		// Post display settings.
		if ( 'filter_layout' === $layout_preset ) {
			$pagination_type = isset( $view_options['filter_pagination_type'] ) ? $view_options['filter_pagination_type'] : '';
		} else {
			$pagination_type = isset( $view_options['post_pagination_type'] ) ? $view_options['post_pagination_type'] : 'ajax_load_more';
			if ( 'on_mobile' === $on_screen ) {
				$pagination_type = isset( $view_options['post_pagination_type_mobile'] ) ? $view_options['post_pagination_type_mobile'] : 'infinite_scroll';
			}
		}
		$post_limit = (int) $post_limit;
		if ( $post_limit < 1 ) {
			$pages = 0;
		} elseif ( ( 'ajax_load_more' === $pagination_type || 'infinite_scroll' === $pagination_type ) && $post_per_click ) {
				$pages = SP_PCP_Functions::pcp_per_click_max_pages( $post_limit, $post_per_page, $post_per_click );
		} else {
			$pages = SP_PCP_Functions::pcp_max_pages( $post_limit, $post_per_page );
		}
		$big = 999999999; // need an unlikely integer.
		if ( $pages > 1 ) {
			$page_current     = max( 1, get_query_var( 'paged' ) );
			$filter_url_value = isset( $_SERVER['QUERY_STRING'] ) ? wp_unslash( $_SERVER['QUERY_STRING'] ) : '';//phpcs:ignore
			if ( ! empty( $filter_url_value ) ) {
				$shortcode_id = isset( $_GET['sps'] ) ? wp_unslash( sanitize_text_field( $_GET['sps'] ) ) : '';//phpcs:ignore
				if ( $shortcode_id == $smart_show_id ) {
					$pcp_page = isset( $_GET['pcp_page'] ) ? wp_unslash( sanitize_text_field( $_GET['pcp_page'] ) ) : '';//phpcs:ignore
					if ( ! empty( $pcp_page ) ) {
						$page_current = $pcp_page;
					}
				}
			}

			if ( 'ajax_pagination' === $pagination_type ) {
				$page_links = paginate_links(
					array(
						'base'      => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
						'format'    => '?paged=%#%',
						'current'   => $page_current,
						'total'     => $pages,
						'show_all'  => true,
						'prev_next' => false,
						'type'      => 'array',
						'prev_text' => '<i class="fa fa-angle-left"></i>',
						'next_text' => '<i class="fa fa-angle-right"></i>',
					)
				);
				$prev_link  = '<a class="next page-numbers" href="#"><i class="fa fa-angle-right"></i></a>';
				$next_link  = '<a class="prev page-numbers active" href="#"><i class="fa fa-angle-left"></i></a>';
				array_unshift( $page_links, $next_link );
				$page_links[] = $prev_link;
				$html         = '';
				$p_num        = 0;
				foreach ( $page_links as $link ) {
					$class = 'page-numbers ';
					if ( strpos( $link, 'current' ) !== false ) {
						$class .= 'active';
					}
					if ( strpos( $link, 'next' ) !== false ) {
						$data_page = 'data-page="next"';
						$class    .= 'pcp_next ';
					} elseif ( strpos( $link, 'prev' ) !== false ) {
						$data_page = 'data-page="prev"';
						$class    .= 'pcp_prev';
					} else {
						$data_page = 'data-page="' . $p_num . '"';
					}
					$link  = preg_replace( '/<span[^>]*>/', '<a href="#" class="' . $class . '" ' . $data_page . '>', $link );
					$link  = preg_replace( '/<a [^>]*>/', '<a href="#" class="' . $class . '" ' . $data_page . '>', $link );
					$link  = str_replace( '</span>', '</a>', $link );
					$html .= $link;
					++$p_num;
				}
				echo $html; //phpcs:ignore
			} elseif ( 'no_ajax' === $pagination_type ) {

				$paged_var    = 'paged' . $smart_show_id;
				$page_current = ( ! empty( $_GET[ "$paged_var" ] ) ) ? sanitize_text_field( wp_unslash( $_GET[ "$paged_var" ] ) ) : 1;

				$page_links = paginate_links(
					array(
						'format'    => '?' . $paged_var . '=%#%',
						'current'   => $page_current,
						'total'     => $pages,
						'show_all'  => apply_filters( 'pcp_show_all_normal_pagination', true ),
						'prev_next' => true,
						'end_size'  => 2,
						'mid_size'  => 1,
						'type'      => 'array',
						'prev_text' => '<i class="fa fa-angle-left"></i>',
						'next_text' => '<i class="fa fa-angle-right"></i>',
					)
				);
				echo implode( $page_links );//phpcs:ignore
			} else {
				$page_links = paginate_links(
					array(
						'base'      => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
						'format'    => '?paged=%#%',
						'current'   => $page_current,
						'total'     => $pages,
						'show_all'  => true,
						'prev_next' => false,
						'type'      => 'array',
						'prev_text' => '<i class="fa fa-angle-left"></i>',
						'next_text' => '<i class="fa fa-angle-right"></i>',
					)
				);
				$html       = '';
				$p_num      = 1;
				foreach ( $page_links as $link ) {
					$class = 'page-numbers ';
					if ( strpos( $link, 'current' ) !== false ) {
						$class .= 'active';
					}
					if ( strpos( $link, 'next' ) !== false ) {
						$data_page = 'data-page="next"';
						$class    .= 'pcp_next ';
					} elseif ( strpos( $link, 'prev' ) !== false ) {
						$data_page = 'data-page="prev"';
						$class    .= 'pcp_prev active';
					} else {
						$data_page = 'data-page="' . $p_num . '"';
					}
					$link  = preg_replace( '/<span[^>]*>/', '<a href="#" class="' . $class . '" ' . $data_page . '>', $link );
					$link  = preg_replace( '/<a [^>]*>/', '<a href="#" class="' . $class . '" ' . $data_page . '>', $link );
					$link  = str_replace( '</span>', '</a>', $link );
					$html .= $link;
					++$p_num;
				}
				echo $html; //phpcs:ignore
			}
		}
	}

	/**
	 * Section title
	 *
	 * @param int  $section_title_text title text.
	 * @param bool $show_section_title show title text.
	 * @return void
	 */
	public static function pcp_section_title( $section_title_text, $show_section_title ) {
		if ( $show_section_title ) {
			$section_title_text = apply_filters( 'pcp_section_title_text', $section_title_text );
			ob_start();
				do_action( 'pcp_before_section_title' );
					include SP_PCP_Functions::pcp_locate_template( 'section-title.php' );
				do_action( 'pcp_after_section_title' );
			$section_title = apply_filters( 'pcp_filter_section_title', ob_get_clean() );
			echo wp_kses_post( $section_title );
		}
	}

	/**
	 * Preloader
	 *
	 * @param bool $preloader show preloader.
	 * @return void
	 */
	public static function pcp_preloader( $preloader ) {
		if ( $preloader ) {
			ob_start();
			include SP_PCP_Functions::pcp_locate_template( 'preloader.php' );
			$preloader = apply_filters( 'pcp_preloader', ob_get_clean() );
			echo wp_kses_post( $preloader );
		}
	}

	/**
	 * Get all query posts.
	 *
	 * @param array  $options Views options.
	 * @param array  $layout_settings Layout settings.
	 * @param array  $sorter  Post sorting options.
	 * @param object $pcp_query post query.
	 * @param int    $view_id Shortcode ID.
	 * @return void
	 */
	public static function pcp_get_posts( $options, $layout_settings, $sorter, $pcp_query, $view_id ) {
		$pcp_count           = 1;
		$all_posts           = $pcp_query->posts;
		$show_adv            = SP_PCP_Functions::pcp_metabox_value( 'show_adv', $options );
		$ads_array           = SP_PCP_Functions::pcp_metabox_value( 'sps_ads', $options );
		$add_position_number = array();
		$ads_content         = array();
		$add_count           = 0;
		if ( $show_adv ) {

			$post_limit      = isset( $options['pcp_post_limit'] ) ? $options['pcp_post_limit'] : 10000;
			$post_per_page   = isset( $options['post_per_page'] ) ? $options['post_per_page'] : 12;
			$show_pagination = isset( $options['show_post_pagination'] ) ? $options['show_post_pagination'] : false;
			$post_per_page   = ( $post_per_page > $post_limit ) ? $post_limit : $post_per_page;
			$post_per_page   = ( ! $show_pagination ) ? $post_limit : $post_per_page;

			$adv_position        = SP_PCP_Functions::pcp_metabox_value( 'adv_position', $options );
			$adv_position_number = SP_PCP_Functions::pcp_metabox_value( 'adv_position_number', $options );
			$repeat_ads          = SP_PCP_Functions::pcp_metabox_value( 'repeat_ads', $options );
			if ( $ads_array && is_array( $ads_array ) ) {
				foreach ( $ads_array as $key => $value ) {
					$ads_content[ $key ] = $value['ads_content'];
				}
				$add_count = count( $ads_content );
			}
			$repeat_ads    = (int) $repeat_ads * $add_count;
			$possible_ads  = intval( $post_per_page ) / 2;
			$possible_ads  = ( $possible_ads >= $repeat_ads ) ? $repeat_ads : $possible_ads;
			$post_per_page = $post_per_page - $possible_ads;
			if ( 'random' === $adv_position ) {
				$random_number_array = range( 1, $post_per_page );
				shuffle( $random_number_array );
				$random_number_array = array_slice( $random_number_array, 0, $possible_ads );
				$add_position_number = $random_number_array;
			} elseif ( strpos( $adv_position_number, ',' ) ) {
					$add_position_number = explode( ',', $adv_position_number );
			} else {
				$add_position_number = explode( ' ', $adv_position_number );
			}
		}
		$add_key = 0;
		// Display posts based on the layout.
		if ( ! empty( $layout_settings['pcp_layout_preset'] ) && 'glossary_layout' === $layout_settings['pcp_layout_preset'] ) {
			self::display_glossary_posts( $all_posts, $options, $layout_settings, $sorter, $view_id, $ads_content, $add_position_number, $pcp_count, $add_key );
		} else {
			foreach ( $all_posts as $post ) {
				self::pcp_post_loop( $options, $layout_settings, $sorter, $pcp_count, $view_id, $post, $add_key, $add_position_number, $ads_content );
				++$pcp_count;
			}
		}
	}

	/**
	 * Display glossary layout posts.
	 *
	 * @param array  $all_posts — get all posts.
	 * @param array  $options — Views options.
	 * @param string $layout_settings — Layout settings.
	 * @param array  $sorter — Post sorting options.
	 * @param int    $view_id — shortcode ID.
	 * @param int    $ads_content — ads content.
	 * @param array  $add_position_number — position number.
	 * @param int    $pcp_count — post count.
	 * @param int    $add_key — Add key.
	 */
	private static function display_glossary_posts( $all_posts, $options, $layout_settings, $sorter, $view_id, $ads_content, $add_position_number, &$pcp_count, $add_key ) {
		$letters       = range( 'A', 'Z' );
		$matched_posts = array();
		$other_posts   = array();

		// Group posts by their first letter.
		foreach ( $all_posts as $post ) {
			$title        = get_the_title( $post->ID );
			$first_letter = ! empty( $title ) ? strtoupper( $title[0] ) : '';

			if ( in_array( $first_letter, $letters, true ) ) {
				$matched_posts[ $first_letter ][] = $post;
			} else {
				$other_posts[] = $post;
			}
		}

		// Output posts for each letter.
		foreach ( $letters as $letter ) {
			if ( ! empty( $matched_posts[ $letter ] ) ) {
				echo '<div class="sps-glossary-items-group sps-gls-' . esc_attr( $letter ) . '">';
				echo '<div class="sps-glossary-items-header">' . esc_html( $letter ) . '</div>';
				echo '<div class="sps-glossary-items-content">';
				foreach ( $matched_posts[ $letter ] as $matched_post ) {
					self::pcp_post_loop( $options, $layout_settings, $sorter, $pcp_count, $view_id, $matched_post, $add_key, $add_position_number, $ads_content );
					++$pcp_count;
				}
				echo '</div></div>';
			}
		}

		// Output posts in the "Other" section.
		if ( ! empty( $other_posts ) ) {
			echo '<div class="sps-glossary-items-group sps-gls-others">';
			echo '<div class="sps-glossary-items-header">Others</div>';
			echo '<div class="sps-glossary-items-content">';
			foreach ( $other_posts as $other_post ) {
				self::pcp_post_loop( $options, $layout_settings, $sorter, $pcp_count, $view_id, $other_post, $add_key, $add_position_number, $ads_content );
				++$pcp_count;
			}
			echo '</div></div>';
		}
	}

	/**
	 * Table td markup.
	 *
	 * @param  mixed $is_table check table layout.
	 * @return array
	 */
	public static function table_td( $is_table = false ) {
		$td_before = '';
		$td_after  = '';
		if ( $is_table ) {
			$td_before = '<td>';
			$td_after  = '</td>';
		}
		return array(
			'start' => $td_before,
			'end'   => $td_after,
		);
	}
	/**
	 * PCP shortcode markup wrapper class.
	 *
	 * @param string $layout_preset The selected layout name.
	 * @param int    $shortcode_id The shortcode ID.
	 * @param string $grid_style Grid style.
	 * @param string $item_same_height_class item same height.
	 */
	public static function pcp_wrapper_classes( $layout_preset, $shortcode_id, $grid_style = null, $item_same_height_class = '' ) {
		$wrapper_class = "sp-pcp-section sp-pcp-container pcp-wrapper-{$shortcode_id}";
		switch ( $layout_preset ) {
			case 'carousel_layout':
			case 'slider_layout':
			case 'thumbnails_slider':
				$wrapper_class .= " pcp-carousel-wrapper{$item_same_height_class}";
				break;
			case 'glossary_layout':
			case 'grid_layout':
				$wrapper_class .= ' pcp-even';
				$wrapper_class .= $item_same_height_class;
				break;
			case 'masonry_layout':
				$wrapper_class .= ' pcp-masonry';
				break;
			case 'filter_layout':
				$wrapper_class .= " pcp-filter-wrapper{$item_same_height_class}";
				break;
			case 'list_layout':
				$wrapper_class .= $item_same_height_class;
				break;
			case 'timeline_layout':
				$wrapper_class .= ' sp-pcp-timeline-section';
				break;
			case 'zigzag_layout':
				$wrapper_class .= ' zigzag-container';
				break;
			case 'accordion_layout':
				$wrapper_class .= '';
				break;
			case 'large_with_small':
				$wrapper_class .= $item_same_height_class;
				break;
		}
		echo esc_attr( apply_filters( 'sptp_wrapper_classes', $wrapper_class ) );
	}

	/**
	 * Shortcode Wrapper data attributes.
	 *
	 * @param string $pagination_type The pagination type.
	 * @param string $pagination_type_mobile The pagination for mobile.
	 * @param int    $shortcode_id The shortcode ID.
	 * @return void
	 */
	public static function wrapper_data( $pagination_type, $pagination_type_mobile, $shortcode_id ) {
		$wrapper_data = '';
		if ( $pagination_type ) {
			$wrapper_data .= " data-pagination={$pagination_type}";
		}
		if ( $pagination_type_mobile ) {
			$wrapper_data .= " data-pagination_mobile={$pagination_type_mobile}";
		}
		if ( $shortcode_id ) {
			$wrapper_data .= " data-sid={$shortcode_id} ";
		}
		echo esc_html( $wrapper_data );
	}

	/**
	 * Post popup views.
	 *
	 * @param object $post post query.
	 * @param array  $popup_content_sorter The upper level field ID.
	 * @param array  $view_options Shortcode options.
	 */
	public static function sp_pcp_single_post( $post, $popup_content_sorter, $view_options ) {

		// Fixed Visual composer shortcode during using ajax popup.
		if ( class_exists( 'WPBMap' ) && method_exists( 'WPBMap', 'addAllMappedShortcodes' ) ) {
			\WPBMap::addAllMappedShortcodes();
		}
		$post_content_sorter = isset( $view_options['post_content_sorter'] ) ? $view_options['post_content_sorter'] : '';
		$popup_close_button  = isset( $view_options['popup_close_button'] ) ? $view_options['popup_close_button'] : false;
		$pcp_popup_img_sizes = isset( $view_options['pcp_popup_img_sizes'] ) ? $view_options['pcp_popup_img_sizes'] : 'full';

		$pcp_select_post_type = SP_PCP_Functions::pcp_metabox_value( 'pcp_select_post_type', $view_options );
		$pcp_post_type        = isset( $view_options['pcp_select_post_type'] ) && ! empty( $view_options['pcp_select_post_type'] ) ? $view_options['pcp_select_post_type'] : 'any';
		$visitor_count        = get_post_meta( $post->ID, '_post_views_count', true );
		$is_attachment        = false;
		if ( 'attachment' === $pcp_post_type ) {
			$is_attachment = true;
		}
		$pcp_image_attr = SP_PCP_Functions::pcp_sized_popup_thumb( $view_options, $post->ID, $is_attachment );
		$popup_thumb    = '';
		if ( isset( $pcp_image_attr['src'] ) && ! empty( $pcp_image_attr['src'] ) ) {
			$popup_thumb = '<img width="' . $pcp_image_attr['width'] . '" height="' . $pcp_image_attr['height'] . '" src="' . $pcp_image_attr['src'] . '" class="pcp-popup-image" alt="">';
		}
		include SP_PCP_Functions::pcp_locate_template( 'single-popup.php' );
	}

	/**
	 * Full html show.
	 *
	 * @param array  $view_options all options.
	 * @param array  $layout show layout.
	 * @param array  $smart_show_id Shortcode ID.
	 * @param array  $section_title section title.
	 * @param object $query layout query.
	 */
	public static function pcp_html_show( $view_options, $layout, $smart_show_id, $section_title = '', $query = array() ) {

		$options              = $view_options;
		$layout_preset        = isset( $layout['pcp_layout_preset'] ) ? $layout['pcp_layout_preset'] : 'carousel_layout';
		$pcp_settings         = get_option( 'sp_post_carousel_settings' );
		$grid_style           = isset( $layout['pcp_grid_style'] ) ? $layout['pcp_grid_style'] : 'even';
		$timeline_style       = isset( $layout['timeline_other_style'] ) ? $layout['timeline_other_style'] : 'timeline_style_1';
		$post_content_sorter  = isset( $view_options['post_content_sorter'] ) ? $view_options['post_content_sorter'] : '';
		$show_section_title   = isset( $view_options['section_title'] ) ? $view_options['section_title'] : false;
		$pcp_content_position = isset( $view_options['post_content_orientation'] ) ? $view_options['post_content_orientation'] : '';
		$margin_between_post  = isset( $view_options['margin_between_post'] ) ? $view_options['margin_between_post'] : array(
			'top-bottom' => 20,
			'left-right' => 20,
		);
		$show_preloader       = isset( $view_options['show_preloader'] ) ? $view_options['show_preloader'] : 0;

		$item_same_height_class = isset( $view_options['item_same_height'] ) && $view_options['item_same_height'] ? ' pcp_same_height ' : '';
		if ( is_object( $query ) && ! empty( $query ) ) {
			$query_args       = array();
			$pcp_query        = $query;
			$total_post_count = $pcp_query->post_count;
		} else {
			$query_args       = SP_PCP_QueryInside::get_filtered_content( $view_options, $smart_show_id, $layout );
			$pcp_query        = new WP_Query( $query_args );
			$total_post_count = $pcp_query->post_count;
		}

		// Pagination.
		$show_pagination = isset( $view_options['show_post_pagination'] ) ? $view_options['show_post_pagination'] : true;
		if ( 'filter_layout' === $layout_preset || 'glossary_layout' === $layout_preset ) {
			$pagination_type        = isset( $view_options['filter_pagination_type'] ) ? $view_options['filter_pagination_type'] : '';
			$pagination_type_mobile = isset( $view_options['filter_pagination_type'] ) ? $view_options['filter_pagination_type'] : '';
		} else {
			$pagination_type        = isset( $view_options['post_pagination_type'] ) ? $view_options['post_pagination_type'] : 'ajax_load_more';
			$pagination_type_mobile = isset( $view_options['post_pagination_type_mobile'] ) ? $view_options['post_pagination_type_mobile'] : 'infinite_scroll';
		}
		$accordion_mode  = isset( $view_options['accordion_mode'] ) ? $view_options['accordion_mode'] : '';
		$advanced_filter = isset( $view_options['pcp_advanced_filter'] ) ? $view_options['pcp_advanced_filter'] : false;
		// Enqueue Settings.
		$swiper_js   = isset( $pcp_settings['pcp_swiper_js'] ) ? $pcp_settings['pcp_swiper_js'] : true;
		$bx_js       = isset( $pcp_settings['pcp_bx_js'] ) ? $pcp_settings['pcp_bx_js'] : true;
		$magnific_js = isset( $pcp_settings['pcp_magnific_js'] ) ? $pcp_settings['pcp_magnific_js'] : true;
		$isotope_js  = isset( $pcp_settings['pcp_isotope_js'] ) ? $pcp_settings['pcp_isotope_js'] : true;
		if ( $magnific_js ) {
			wp_enqueue_script( 'pcp_popup' );
		}
		if ( $isotope_js ) {
			wp_enqueue_script( 'pcp_isotope' );
		}
		wp_enqueue_script( 'pcp_script' );
		$pcp_custom_js = isset( $pcp_settings['pcp_custom_js'] ) ? $pcp_settings['pcp_custom_js'] : '';
		if ( ! empty( $pcp_custom_js ) ) {
			wp_add_inline_script( 'pcp_script', $pcp_custom_js );
		}
		$spsp_lang = '';
		if ( function_exists( 'pll_current_language' ) ) {
			$spsp_lang = pll_current_language();
		} elseif ( class_exists( 'SitePress' ) ) {
			$spsp_lang = get_locale();
		}

		if ( 'carousel_layout' === $layout_preset || 'slider_layout' === $layout_preset ) {
			include SP_PCP_Functions::pcp_locate_template( 'carousel.php' );
		} elseif ( 'thumbnails_slider' === $layout_preset ) {
			include SP_PCP_Functions::pcp_locate_template( 'thumbnail-slider.php' );
		} elseif ( 'grid_layout' === $layout_preset ) {
			include SP_PCP_Functions::pcp_locate_template( 'grid.php' );
		} elseif ( 'masonry_layout' === $layout_preset ) {
			include SP_PCP_Functions::pcp_locate_template( 'masonry.php' );
		} elseif ( 'list_layout' === $layout_preset ) {
			include SP_PCP_Functions::pcp_locate_template( 'list.php' );
		} elseif ( 'timeline_layout' === $layout_preset ) {
			include SP_PCP_Functions::pcp_locate_template( 'timeline.php' );
		} elseif ( 'accordion_layout' === $layout_preset ) {
			include SP_PCP_Functions::pcp_locate_template( 'collapsible.php' );
		} elseif ( 'large_with_small' === $layout_preset ) {
			include SP_PCP_Functions::pcp_locate_template( 'block.php' );
		} elseif ( 'zigzag_layout' === $layout_preset ) {
			include SP_PCP_Functions::pcp_locate_template( 'zigzag.php' );
		} elseif ( 'filter_layout' === $layout_preset ) {
			include SP_PCP_Functions::pcp_locate_template( 'filter.php' );
		} elseif ( 'glossary_layout' === $layout_preset ) {
			include SP_PCP_Functions::pcp_locate_template( 'glossary.php' );
		} elseif ( 'table_layout' === $layout_preset ) {
			include SP_PCP_Functions::pcp_locate_template( 'table.php' );
		}
	}
	/**
	 * Minify output
	 *
	 * @param  string $html output.
	 * @return statement
	 */
	public static function minify_output( $html ) {
		$html = preg_replace( '/<!--(?!s*(?:[if [^]]+]|!|>))(?:(?!-->).)*-->/s', '', $html );
		$html = str_replace( array( "\r\n", "\r", "\n", "\t" ), '', $html );
		while ( stristr( $html, '  ' ) ) {
			$html = str_replace( '  ', ' ', $html );
		}
		return $html;
	}
}
