carousel_id = 'appw-carousel-' . self::$instance_id;
self::$instance_id++;
$this->carousel_inner_items = '';
$this->number_of_inner_items = 0;
$this->carousel_indicators = '';
$this->slide_to_index = 0;
}
/**
* Add the post markup to the carousel container.
*
* @param string $post_preview_container Markup for the post preview.
* @return void.
*/
public function add_post_markup( $post_preview_container ) {
foreach ( $post_preview_container as $post_preview ) {
$this->append_post_markup_to_inner_items( $post_preview );
$this->append_to_carousel_indicators();
$this->number_of_inner_items++;
}
}
/**
* Add Bootstrap inner items markup for each post.
*
* @param string $post_markup Markup to append to the carousel inner items.
* @return void.
*/
public function append_post_markup_to_inner_items( $post_markup ) {
$is_active = ( 0 === $this->slide_to_index ) ? 'active' : '';
$this->carousel_inner_items .=
'
'
. wp_kses_post( $post_markup )
. '
';
}
/**
* Add markup to carousel indicators for each post.
*
* @return void.
*/
public function append_to_carousel_indicators() {
$is_active = ( 0 === $this->slide_to_index ) ? 'active' : '';
$list_item = '';
$this->carousel_indicators .= $list_item;
$this->slide_to_index++;
}
/**
* Conditionally get the carousel controls.
*
* @return string $control_markup Bootstrap carousel control markup.
*/
public function maybe_get_controls() {
if ( $this->has_more_than_one_post() ) {
return '
';
} else {
return '';
}
}
/**
* Conditionally return Bootstrap indicator markup.
*
* @return string $indicator_markup Bootstrap carousel indicator markup.
*/
public function maybe_get_indicators() {
if ( $this->has_more_than_one_post() ) {
return ''
. $this->carousel_indicators
. '
';
} else {
return '';
}
}
/**
* Get the full markup of the Bootstrap carousel.
*
* @return string $markup Full Bootstrap carousel markup, with the posts.
*/
public function get() {
return ''
. $this->maybe_get_indicators()
. '
'
. $this->carousel_inner_items
. '
'
. $this->maybe_get_controls()
. '
';
}
/**
* Whether the carousel has more than a single post.
*
* @return boolean $has_more_than_one Whether the Bootstrap carousel has more than one post.
*/
public function has_more_than_one_post() {
return ( 1 < $this->number_of_inner_items );
}
}