attributes = $this->obtain_attributes( $atts ); $this->output = ''; if ( $this->validate_data() ) { do_action( 'agnosia_bootstrap_carousel_before_init' ); $this->container_style = $this->get_container_style(); $this->item_style = $this->get_item_style(); $this->posts = $this->get_posts(); $this->output = $this->get_output(); do_action( 'agnosia_bootstrap_carousel_init' ); } } public function __get( $property ) { if ( property_exists( $this, $property ) ) { return $this->$property; } } public function __set( $property, $value ) { if ( property_exists( $this, $property ) ) { $this->$property = $value; } return $this; } /** * Obtain shortcode attributes. * * @return array Mixed array of shortcode attributes. */ private function obtain_attributes( $atts ) { // Define data by given attributes. $attributes = shortcode_atts( array( /* Ids for the images to use. */ 'ids' => false, /* Type of gallery. If it's not "carousel", nothing will be done. */ 'type' => '', /* Alternative appearing order of images. */ 'orderby' => '', /* Any name. String will be sanitize to be used as HTML ID. Recomended * when you want to have more than one carousel in the same page. * Default: agnosia-bootstrap-carousel. */ 'name' => 'agnosia-bootstrap-carousel', /* Carousel container width, in px or % */ 'width' => '', /* Carousel item height, in px or % */ 'height' => '', /* Accepted values: before-inner, after-inner, after-control, false. * Default: before-inner. */ 'indicators' => 'before-inner', /* Accepted values: true, false. Default: true. */ 'control' => 'true', /* The amount of time to delay between automatically cycling an item. * If false, carousel will not automatically cycle. */ 'interval' => 5000, /* Pauses the cycling of the carousel on mouseenter and resumes the * cycling of the carousel on mouseleave. */ 'pause' => 'hover', /* Define tag for image title. Default: h4. */ 'titletag' => 'h4', /* Show or hide image title. Set false to hide. Default: true. */ 'title' => 'true', /* Type of link to show if "title" is set to true. */ 'link' => '', /* Show or hide image text. Set false to hide. Default: true. */ 'text' => 'true', /* Auto-format text. Default: true. */ 'wpautop' => 'true', /* Extra class for container. */ 'containerclass' => '', /* Extra class for item. */ 'itemclass' => '', /* Extra class for caption. */ 'captionclass' => '', /* Size for image attachment. Accepted values: thumbnail, medium, * large, full. Default: full. See wp_get_attachment_image_src() for * further reference. */ 'size' => 'full' ), $atts ); $attributes = apply_filters( 'agnosia_bootstrap_carousel_attributes', $attributes ); return $attributes; } /** * Check if the received data can make a valid carousel. * * @return boolean */ private function validate_data() { // Initialize boolean. $bool = false; // Convert attributes to variables. extract( $this->attributes ); /* Validate for necessary data */ if ( isset( $ids ) && isset( $type ) && 'carousel' == $type ) { $bool = true; } return $bool; } /** * Obtain posts array by given IDs. * * @return array Array of WordPress $post objects. */ private function get_posts() { $posts = array(); extract( $this->attributes ); $images = $this->make_array( $ids, $orderby ); if ( is_array( $images ) and !empty( $images ) ) { foreach ( $images as $image_id ) { $posts[] = get_post( intval( $image_id ) , ARRAY_A ); } } $posts = apply_filters( 'agnosia_bootstrap_carousel_posts', $posts, $this->attributes ); return $posts; } /** * Define width of carousel container. * * @return string HTML result. */ private function get_container_style() { extract( $this->attributes ); $container_style = ''; if ( $width ) { $container_style = 'style="width:' . $width . ';"'; } $container_style = apply_filters( 'agnosia_bootstrap_carousel_container_style', $container_style, $this->attributes ); return $container_style; } /** * Define height of carousel item. * * @return string HTML result. */ private function get_item_style() { extract( $this->attributes ); $item_style = ''; if ( $height ) { $item_style = 'style="height:' . $height . ';"' ; } $item_style = apply_filters( 'agnosia_bootstrap_carousel_item_style', $item_style, $this->attributtes ); return $item_style; } /** * Obtain complete HTML output for carousel. * * @return string HTML result. */ private function get_output() { // Convert attributes to variables. extract( $this->attributes ); // Initialize carousel HTML. $output = $this->get_carousel_container( 'start' ); // Try to obtain indicators before inner. $output .= ( 'before-inner' == $indicators ) ? $this->get_indicators() : '' ; // Initialize inner. $output .= $this->get_carousel_inner( 'start' ); // Start counter for posts iteration. $i = 0; // Process each item into $this->posts array and create HTML. foreach ( $this->posts as $post ) { // Make sure to include only attachments into the carousel. if ( 'attachment' == $post['post_type'] ) { $class = ( 0 == $i ) ? 'active ' : ''; $output .= $this->get_img_container( 'start', $i ); $output .= $this->get_img( $post ); if ( 'false' !== $title || 'false' !== $text ) { $output .= $this->get_caption_container( 'start' ); $output .= $this->get_title( $post ); $output .= $this->get_excerpt( $post ); $output .= $this->get_caption_container( 'end' ); } $output .= $this->get_img_container( 'end' ); $i++; } } // End inner. $output .= $this->get_carousel_inner( 'end' ); // Try to obtain indicators after inner. $output .= ( 'after-inner' == $indicators ) ? $this->get_indicators() : '' ; // Obtain links for carousel control. $output .= ( 'false' !== $control ) ? $this->get_control() : '' ; // Try to obtain indicators after control. */ $output .= ( 'after-control' == $indicators ) ? $this->get_indicators() : '' ; // End carousel HTML. $output .= $this->get_carousel_container( 'end' ); // Obtain javascript for carousel. $output .= $this->get_javascript(); $output = apply_filters( 'agnosia_bootstrap_carousel_output', $output, $this->attributes ); return $output; } /** * Get starting and ending HTML tag for carousel container. * * @param string $position Indicator for starting or ending tag. * @return string HTML result. */ private function get_carousel_container( $position ) { $output = ''; switch ( $position ) { case 'start': extract( $this->attributes ); $output .= '
'; break; default: // Do nothing. break; } $output = apply_filters( 'agnosia_bootstrap_carousel_container', $output, $this->attributes ); return $output; } /** * Get starting and ending HTML tag for carousel inner element. * * @param string $position Indicator for starting or ending tag. * @return string HTML result. */ private function get_carousel_inner( $position ) { $output = ''; switch ( $position ) { case 'start': extract( $this->attributes ); $output = '