
­­­­­­­­­­­­­­­­­­
<!DOCTYPE html>
<html>
<?php

if ( ! function_exists( 'vwspc_get_next_id' ) ) {
	function presso_spc_next_section_id() {
		global $presso_spc_section_id;
		if ( empty( $presso_spc_section_id ) ) $presso_spc_section_id = 0;

		return ++$presso_spc_section_id;
	}
}

if ( ! function_exists( 'presso_the_simple_page_composer2' ) ) {
	function presso_the_simple_page_composer2( $args=array() ) {
		$defaults = array(
			'before' => '',
			'after' => '',
			'before_section' => '<section class="vwspc-section vwspc-section-%s" id="vwspc-section-%s">',
			'after_section' => '</section>',
		);
		$args = wp_parse_args( $args, $defaults );
		$page_id = get_queried_object_id();

		if( have_rows('composer_blocks') ):

			// loop through the rows of data
			while ( have_rows('composer_blocks') ) : the_row();
				do_action( 'presso_action_spc_render_section_'.get_row_layout(), array(
					'page_id' => $page_id,
					'before_section' => $args['before_section'],
					'after_section' => $args['after_section'],
				) );

				// if( get_row_layout() == 'paragraph' ):

				// 	the_sub_field('text');

				// elseif( get_row_layout() == 'download' ): 

				// 	$file = get_sub_field('file');

				// endif;

			endwhile;


		endif;

	}
}

/* -----------------------------------------------------------------------------
 * Render Section: Post Slider
 * -------------------------------------------------------------------------- */
add_action( 'presso_action_spc_render_section_post_slider', 'presso_render_spc_section_post_slider' );
if ( ! function_exists( 'presso_render_spc_section_post_slider' ) ) {
	function presso_render_spc_section_post_slider( $args ) {
		global $presso_secondary_query;

		extract( $args );
		$number_of_slide = get_sub_field( 'number' );
		$layout = get_sub_field( 'layout' );
		$categories = get_sub_field( 'categories' );
		$exclude_categories = get_sub_field( 'exclude_categories' );
		$posts_order = get_sub_field( 'posts_order' );

		echo wp_kses_post( sprintf( $before_section, 'post-slider-section', esc_attr( presso_spc_next_section_id() ) ) );

		$args = array(
			'category__in' => $categories,
			'category__not_in' => $exclude_categories,
			'post_order' => $posts_order,
			'posts_per_page' => $number_of_slide,
			'has_post_thumbnail' => true,
			'layout' => $layout,
		);

		$require_container = array( 'slider-xlarge', 'slider-xlarge-2' );

		if ( in_array( $layout, $require_container ) ) {
			$args['before'] = '<div class="container">';
			$args['after'] = '</div>';
		}
		
		presso_enable_avoid_duplicate_post();
		presso_the_post_loop( $args );
		presso_disable_avoid_duplicate_post();

		echo wp_kses_post( $after_section );
	}
}

/* -----------------------------------------------------------------------------
 * Render Section: Post Box
 * -------------------------------------------------------------------------- */
add_action( 'presso_action_spc_render_section_post_box', 'presso_render_spc_section_post_box' );
if ( ! function_exists( 'presso_render_spc_section_post_box' ) ) {
	function presso_render_spc_section_post_box( $args ) {
		extract( $args );
		$number_of_post = get_sub_field( 'number' );
		$offset = get_sub_field( 'offset' );
		$supertitle = get_sub_field( 'supertitle' );
		$layout = get_sub_field( 'layout' );
		$lead_layout = get_sub_field( 'lead_layout' );
		$lead_layout_number = get_sub_field( 'lead_layout_number' );
		$title = get_sub_field( 'title' );
		$subtitle = get_sub_field( 'subtitle' );
		$categories = get_sub_field( 'categories' );
		$exclude_categories = get_sub_field( 'exclude_categories' );
		$posts_order = get_sub_field( 'posts_order' );
		$pagination = get_sub_field( 'pagination' );

		if ( 'hide' == $pagination ) {
			$paged = 1;
		} else {
			$paged = presso_get_paged();
		}

		$title_class = '';
		$additional_classes = ' '; // Need a space
		$additional_classes .= ' vwspc-post-box-layout-'.$layout;

		presso_enable_avoid_duplicate_post();
		
		echo wp_kses_post( sprintf( $before_section, esc_attr( 'post-box'.$additional_classes ), esc_attr( presso_spc_next_section_id() ) ) );

		$query_args = array(
			'category__in' => $categories,
			'category__not_in' => $exclude_categories,
			'paged' => $paged,
			'offset' => $offset,
			'post_order' => $posts_order,
			'posts_per_page' => $number_of_post,
			'layout' => $layout,
			'lead_layout' => $lead_layout,
			'lead_layout_number' => $lead_layout_number,
		);

		// Add title class for category
		if ( ! empty( $category ) && ! empty( $title ) ) {
			$title_class .= ' '.presso_get_the_category_class( $category );
		}

		$container_class = 'container';

		if ( $layout == 'large-2' ) {
			$container_class = 'container-fluid';
		}
		?>
		<div class="<?php echo esc_attr( $container_class ); ?> vwspc-section-content">
			<?php if ( ! empty ( $title ) ) : ?>
			<header class="vwspc-section-header">

				<?php if ( ! empty( $supertitle ) ) : ?>
				<span class="vwspc-section-supertitle vw-super-title">
					<?php echo do_shortcode( esc_html( $supertitle ) ); ?>
				</span>
				<?php endif; ?>

				<h3 class="vwspc-section-title">
					<?php printf( '<span class="%2$s">%1$s</span>', do_shortcode( esc_html( $title ) ), esc_attr( $title_class ) ); ?>
				</h3>

				<?php if ( ! empty( $subtitle ) ) : ?>
				<span class="vwspc-section-subtitle">
					<?php echo do_shortcode( esc_html( $subtitle ) ); ?>
				</span>
				<?php endif; ?>

			</header>
			<?php endif; ?>

			<?php presso_the_post_loop( $query_args ); ?>

			<?php if ( 'hide' != $pagination ) presso_the_pagination( $pagination ); ?>
		</div>
		<?php
		echo wp_kses_post( $after_section );
		presso_disable_avoid_duplicate_post();
	}
}

/* -----------------------------------------------------------------------------
 * Render Section: Post Box with Sidebar
 * -------------------------------------------------------------------------- */
add_action( 'presso_action_spc_render_section_post_box_sidebar', 'presso_render_spc_section_post_box_sidebar' );
if ( ! function_exists( 'presso_render_spc_section_post_box_sidebar' ) ) {
	function presso_render_spc_section_post_box_sidebar( $args ) {
		extract( $args );
		$number_of_post = get_sub_field( 'number' );
		$offset = get_sub_field( 'offset' );
		$layout = get_sub_field( 'layout' );
		$lead_layout = get_sub_field( 'lead_layout' );
		$lead_layout_number = get_sub_field( 'lead_layout_number' );
		$supertitle = get_sub_field( 'supertitle' );
		$title = get_sub_field( 'title' );
		$subtitle = get_sub_field( 'subtitle' );
		$categories = get_sub_field( 'categories' );
		$exclude_categories = get_sub_field( 'exclude_categories' );
		$posts_order = get_sub_field( 'posts_order' );
		$pagination = get_sub_field( 'pagination' );
		$sidebar = get_sub_field( 'sidebar' );

		if ( 'hide' == $pagination ) {
			$paged = 1;
		} else {
			$paged = presso_get_paged();
		}

		$title_class = '';
		$additional_classes = ' '; // Need a space
		$additional_classes .= ' vwspc-post-box-layout-'.$layout;

		$query_args = array(
			'category__in' => $categories,
			'category__not_in' => $exclude_categories,
			'paged' => $paged,
			'offset' => $offset,
			'post_order' => $posts_order,
			'posts_per_page' => $number_of_post,
			'layout' => $layout,
			'lead_layout' => $lead_layout,
			'lead_layout_number' => $lead_layout_number,
		);

		// Add title class for category
		if ( ! empty( $category ) && ! empty( $title ) ) {
			$title_class .= ' '.presso_get_the_category_class( $category );
		}

		echo wp_kses_post( sprintf( $before_section, esc_attr( 'post-box-sidebar'.$additional_classes ), esc_attr( presso_spc_next_section_id() ) ) );
		?>
		
		<div class="container">

			<div class="row">
				<div class="col-lg-8 vwspc-section-content">
					<?php if ( ! empty ( $title ) ) : ?>
					<header class="vwspc-section-header">
						<?php if ( ! empty( $supertitle ) ) : ?>
						<span class="vwspc-section-supertitle vw-super-title">
							<?php echo do_shortcode( esc_html( $supertitle ) ); ?>
						</span>
						<?php endif; ?>

						<h3 class="vwspc-section-title">
							<?php printf( '<span class="%2$s">%1$s</span>', do_shortcode( esc_html( $title ) ), esc_attr( $title_class ) ); ?>
						</h3>

						<?php if ( ! empty( $subtitle ) ) : ?>
						<span class="vwspc-section-subtitle">
							<?php echo do_shortcode( esc_html( $subtitle ) ); ?>
						</span>
						<?php endif; ?>

					</header>
					<?php endif; ?>
					
					<?php
					presso_enable_avoid_duplicate_post();
					presso_the_post_loop( $query_args );
					presso_disable_avoid_duplicate_post();
					?>

					<?php if ( 'hide' != $pagination ) presso_the_pagination( $pagination ); ?>
				</div>
				<div class="col-lg-4 vwspc-section-sidebar">
					<?php dynamic_sidebar( $sidebar ); ?>
				</div>
			</div>
			
		</div>
		<?php
		echo wp_kses_post( $after_section );
	}
}


/* -----------------------------------------------------------------------------
 * Render Section: Full Page Link
 * -------------------------------------------------------------------------- */
add_action( 'presso_action_spc_render_section_full_page_link', 'presso_render_spc_section_full_page_link' );
if ( ! function_exists( 'presso_render_spc_section_full_page_link' ) ) {
	function presso_render_spc_section_full_page_link( $args ) {
		extract( $args );

		$title = get_sub_field( 'title' );
		$subtitle = get_sub_field( 'subtitle' );
		$button_label = get_sub_field( 'button_label' );
		$page_id = get_sub_field( 'page' );
		$background_image = get_sub_field( 'background_image' );

		$page_url = get_permalink( $page_id );
		$full_image_url = wp_get_attachment_image_src( $background_image, apply_filters( 'presso_filter_full_page_link_background_size', 'full' ) );
		if ( $full_image_url ) {
			$full_image_url = $full_image_url[0];
		} else {
			$full_image_url = '';
		}

		echo wp_kses_post( sprintf( $before_section, esc_attr( 'full-page-link' ), esc_attr(  presso_spc_next_section_id() ) ) );

		?>
		<div class="vw-full-page-link__background" style="background-image: url( <?php echo esc_url( $full_image_url ); ?> );"></div>

		<div class="vw-full-page-link__inner">

			<div class="container">
				<div class="vw-full-page-link__header">
					<?php if ( ! empty( $title ) ) : ?>
					<h2 class="vw-full-page-link__title">
						<a href="<?php echo esc_url( $page_url ); ?>"><?php echo do_shortcode( esc_html( $title ) ); ?></a>
					</h2>
					<?php endif; ?>

					<?php if ( ! empty( $subtitle ) ) : ?>
					<p class="vw-full-page-link__subtitle">
						<a href="<?php echo esc_url( $page_url ); ?>"><?php echo do_shortcode( esc_html( $subtitle ) ); ?></a>
					</p>
					<?php endif; ?>

					<?php if ( ! empty( $button_label ) ) :?>
					<a class="vw-button vw-button--accent" href="<?php echo esc_url( $page_url ); ?>" rel="bookmark"><?php echo esc_html( $button_label ); ?></a>
					<?php endif; ?>

				</div>
			</div>
		</div>

		<a class="vw-full-page-link__link" href="<?php echo esc_url( $page_url ); ?>"></a>

		<?php

		echo wp_kses_post( $after_section );
	}
}

/* -----------------------------------------------------------------------------
 * Render Section: 2 Sidebars
 * -------------------------------------------------------------------------- */
add_action( 'presso_action_spc_render_section_2_sidebars', 'presso_render_spc_section_2_sidebars' );
if ( ! function_exists( 'presso_render_spc_section_2_sidebars' ) ) {
	function presso_render_spc_section_2_sidebars( $args ) {
		extract( $args );

		$sidebar_1 = get_sub_field( 'sidebar_1' );
		$sidebar_2 = get_sub_field( 'sidebar_2' );

		echo wp_kses_post( sprintf( $before_section, esc_attr( '2-sidebars-section' ), esc_attr( presso_spc_next_section_id() ) ) );
		?>
		<div class="container">
			<div class="vwspc-section-content">
				<div class="vw-flex-grid vw-flex-grid--large-gap vw-flex-grid--lg-2">
					<div class="vw-flex-grid__item">
						<?php dynamic_sidebar( $sidebar_1 ); ?>
					</div>

					<div class="vw-flex-grid__item">
						<?php dynamic_sidebar( $sidebar_2 ); ?>
					</div>

				</div>
			</div>
		</div>

		<?php
		echo wp_kses_post( $after_section );
	}
}

/* -----------------------------------------------------------------------------
 * Render Section: 3 Sidebars
 * -------------------------------------------------------------------------- */
add_action( 'presso_action_spc_render_section_3_sidebars', 'presso_render_spc_section_3_sidebars' );
if ( ! function_exists( 'presso_render_spc_section_3_sidebars' ) ) {
	function presso_render_spc_section_3_sidebars( $args ) {
		extract( $args );

		$sidebar_1 = get_sub_field( 'sidebar_1' );
		$sidebar_2 = get_sub_field( 'sidebar_2' );
		$sidebar_3 = get_sub_field( 'sidebar_3' );

		echo wp_kses_post( sprintf( $before_section, esc_attr( '3-sidebars-section' ), esc_attr( presso_spc_next_section_id() ) ) );
		?>
		<div class="container">
			<div class="vwspc-section-content">
				<div class="vw-flex-grid vw-flex-grid--large-gap vw-flex-grid--lg-3">
					<div class="vw-flex-grid__item">
						<?php dynamic_sidebar( $sidebar_1 ); ?>
					</div>

					<div class="vw-flex-grid__item">
						<?php dynamic_sidebar( $sidebar_2 ); ?>
					</div>

					<div class="vw-flex-grid__item">
						<?php dynamic_sidebar( $sidebar_3 ); ?>
					</div>

				</div>
			</div>
		</div>

		<?php
		echo wp_kses_post( $after_section );
	}
}


/* -----------------------------------------------------------------------------
 * Render Section: Custom Content
 * -------------------------------------------------------------------------- */
add_action( 'presso_action_spc_render_section_custom_content', 'presso_render_spc_section_custom_content' );
if ( ! function_exists( 'presso_render_spc_section_custom_content' ) ) {
	function presso_render_spc_section_custom_content( $args ) {
		extract( $args );

		$supertitle = get_sub_field( 'supertitle' );
		$title = get_sub_field( 'title' );
		$subtitle = get_sub_field( 'subtitle' );
		$content = get_sub_field( 'content' );
		$sidebar = get_sub_field( 'sidebar' );

		$title_class = ' ';
		$additional_class = ' ';
		$col_class = 'col-lg-12';

		if ( ! empty( $sidebar ) ) {
			$col_class = 'col-lg-8';
		}

		echo wp_kses_post( sprintf( $before_section, esc_attr( 'custom-section'.$additional_class ), esc_attr( presso_spc_next_section_id() ) ) );
		?>
		<div class="container">
			<div class="row">
				<div class="<?php echo esc_attr( $col_class ); ?> vwspc-section-content">

					<?php if ( ! empty ( $title ) ) : ?>
					<header class="vwspc-section-header">
						<?php if ( ! empty( $supertitle ) ) : ?>
						<span class="vwspc-section-supertitle vw-super-title">
							<?php echo do_shortcode( esc_html( $supertitle ) ); ?>
						</span>
						<?php endif; ?>

						<h3 class="vwspc-section-title">
							<?php printf( '<span class="%2$s">%1$s</span>', do_shortcode( esc_html( $title ) ), esc_attr( $title_class ) ); ?>
						</h3>

						<?php if ( ! empty( $subtitle ) ) : ?>
						<span class="vwspc-section-subtitle">
							<?php echo do_shortcode( esc_html( $subtitle ) ); ?>
						</span>
						<?php endif; ?>
					</header>
					<?php endif; ?>

					<?php echo apply_filters( 'the_content', apply_filters( 'presso_filter_spc_custom_content_body', $content ) ); ?>
				
				</div>

				<?php if ( ! empty( $sidebar ) ) : ?>
				<div class="col-lg-4 vwspc-section-sidebar">
					<?php dynamic_sidebar( $sidebar ); ?>
				</div>
				<?php endif; ?>
			</div>
		</div>

		<?php
		echo wp_kses_post( $after_section );
	}
}
