<?php
FLBuilderModel::default_settings($settings, array(
	'post_type' 		=> 'post',
	'show_image' 		=> 'yes',
	'image_thumb_size'	=> 'large',
	'show_author'		=> 'yes',
	'show_date'			=> 'yes',
	'show_categories'	=> 'no',
	'meta_separator'	=> ' | ',
	'show_content'		=> 'yes',
	'content_type'		=> 'excerpt',
	'content_length'	=> 300,
	'link_type'			=> 'title',
	'show_button'		=> 'no',
	'button_text'	=> __('Read More', 'bb-powerpack'),
	'post_taxonomies'	=> 'none',
	'image_position'	=> 'above_header'
));

// Save the current post, so that it can be restored later (see the end of this file).
global $post;
$initial_current_post = $post;

$query = FLBuilderLoop::query($settings);

// Render the posts.
if($query->have_posts()) :
?>
<div class="pp-post-timeline <?php echo esc_attr( $settings->post_timeline_layout ); ?> <?php if( $settings->post_timeline_layout == 'vertical' ) { ?><?php echo $settings->post_timeline_ver_direction; ?><?php } ?>">

	<?php if( $settings->post_timeline_layout == 'horizontal' ) { ?>
		<div id="post-timeline-slider-for-<?php echo $id; ?>" class="pp-post-timeline-slider-target pp-post-timeline-slide-navigation" post-timeline-slider-nav-for="post-timeline-slider-for-<?php echo $id; ?>">
			<?php
			while($query->have_posts()) :
			$query->the_post();
			$is_current_post = is_object( $post ) && isset( $post->ID ) && get_the_ID() == $post->ID;
			?>

				<div class="pp-post-timeline-icon-wrapper slick-arrow">
					<div class="pp-post-timeline-icon<?php echo $is_current_post ? ' pp-post-current' : ''; ?>">
						<span class="pp-timeline-icon <?php echo $settings->post_timeline_icon; ?>"></span>
					</div>
				</div>

			<?php endwhile; ?>
		</div>
	<?php } ?>

	<div class="pp-post-timeline-slider-target pp-post-timeline-content-wrapper post-timeline-slider-for-<?php echo $id; ?>">

		<?php
		$count = 0;
		while($query->have_posts()) :

		$query->the_post();

		$is_current_post = is_object( $post ) && isset( $post->ID ) && get_the_ID() == $post->ID;

		$terms_list = wp_get_post_terms( get_the_ID(), $settings->post_taxonomies );

		include $module->dir . 'includes/' . $settings->post_timeline_layout . '-timeline.php';

		$count++;

		endwhile; ?>
	</div>
</div>
<?php

endif;

wp_reset_postdata();

// Restore the original current post.
//
// Note that wp_reset_postdata() isn't enough because it resets the current post by using the main
// query, but it doesn't take into account the possibility that it might have been overridden by a
// third-party plugin in the meantime.
//
// Specifically, this used to cause problems with Toolset Views, when its Content Templates were used.
$post = $initial_current_post;
setup_postdata( $initial_current_post );

?>
