PATH:
home
/
letacommog
/
opilot
/
wp-content
/
themes
/
dt-the7
/
inc
/
shortcodes
/
includes
/
blog-carousel
<?php /** * Blog Carousel shortcode * */ // File Security Check if ( ! defined( 'ABSPATH' ) ) { exit; } require_once trailingslashit( PRESSCORE_SHORTCODES_INCLUDES_DIR ) . 'abstract-dt-shortcode-with-inline-css.php'; if ( ! class_exists( 'DT_Shortcode_Blog_Carousel', false ) ) : class DT_Shortcode_Blog_Carousel extends DT_Shortcode_With_Inline_Css { /** * @var string */ protected $post_type; /** * @var string */ protected $taxonomy; /** * @var DT_Blog_Shortcode_Carousel */ public static $instance = null; /** * @return DT_Blog_Shortcode_Carousel */ public static function get_instance() { if ( null === self::$instance ) { self::$instance = new self(); } return self::$instance; } public function __construct() { $this->sc_name = 'dt_blog_carousel'; $this->unique_class_base = 'blog-carousel-shortcode-id'; $this->taxonomy = 'category'; $this->post_type = 'post'; $this->default_atts = array( 'category' => '', 'order' => 'desc', 'orderby' => 'date', 'dis_posts_total' => '6', 'layout' => 'classic', 'bo_content_width' => '75%', 'bo_content_overlap' => '100px', 'grovly_content_overlap' => '0px', 'content_bg' => 'y', 'custom_content_bg_color' => '', 'post_content_paddings' => '25px 30px 30px 30px', 'image_sizing' => 'resize', 'resized_image_dimensions' => '3x2', 'image_paddings' => '0px 0px 0px 0px', 'image_scale_animation_on_hover' => 'y', 'image_hover_bg_color' => 'y', 'slide_to_scroll' => 'single', 'slides_on_desk' => '3', 'slides_on_lapt' => '3', 'slides_on_h_tabs' => '3', 'slides_on_v_tabs' => '2', 'slides_on_mob' => '1', 'adaptive_height' => 'y', 'item_space' => '30', 'speed' => '600', 'autoplay' => 'n', 'autoplay_speed' => "6000", 'content_alignment' => 'left', 'post_title_font_style' => '', 'post_title_font_size' => '', 'post_title_line_height' => '', 'custom_title_color' => '', 'post_title_bottom_margin' => '5px', 'post_date' => 'y', 'post_category' => 'y', 'post_author' => 'y', 'post_comments' => 'y', 'meta_info_font_style' => '', 'meta_info_font_size' => '', 'meta_info_line_height' => '', 'custom_meta_color' => '', 'meta_info_bottom_margin' => '15px', 'post_content' => 'show_excerpt', 'excerpt_words_limit' => '', 'content_font_style' => '', 'content_font_size' => '', 'content_line_height' => '', 'custom_content_color' => '', 'content_bottom_margin' => '5px', 'read_more_button' => 'default_link', 'read_more_button_text' => 'Read more', 'fancy_date' => 'n', 'fancy_date_font_color' => '', 'fancy_date_bg_color' => '', 'fancy_date_line_color' => '', 'fancy_categories' => 'n', 'fancy_categories_font_color' => '', 'fancy_categories_bg_color' => '', 'arrows' => 'y', 'arrow_icon_size' => '18px', 'r_arrow_icon_paddings' => '0 0 0 0', 'l_arrow_icon_paddings' => '0 0 0 0', 'arrow_bg_width' => "36px", 'arrow_bg_height' => "36px", 'arrow_border_radius' => '500px', 'arrow_border_width' => '0', 'arrow_icon_color' => '#ffffff', 'arrow_border_color' => '', 'arrows_bg_show' => 'y', 'arrow_bg_color' => '', 'arrow_icon_color_hover' => 'rgba(255,255,255,0.75)', 'arrow_border_color_hover' => '', 'arrows_bg_hover_show' => 'y', 'arrow_bg_color_hover' => '', 'r_arrow_v_position' => 'center', 'r_arrow_h_position' => 'right', 'r_arrow_v_offset' => '0', 'r_arrow_h_offset' => '-43px', 'l_arrow_v_position' => 'center', 'l_arrow_h_position' => 'left', 'l_arrow_v_offset' => '0', 'l_arrow_h_offset' => '-43px', 'arrow_responsiveness' => 'reposition-arrows', 'hide_arrows_mobile_switch_width' => '768px', 'reposition_arrows_mobile_switch_width' => '768px', 'l_arrows_mobile_h_position' => '10px', 'r_arrows_mobile_h_position' => '10px', 'show_bullets' => 'n', 'bullets_style' => 'small-dot-stroke', 'bullet_size' => '10px', 'bullet_color' => '', 'bullet_color_hover' => '', 'bullet_gap' => "16px", 'bullets_v_position' => 'bottom', 'bullets_h_position' => 'center', 'bullets_v_offset' => '20px', 'bullets_h_offset' => '0', 'next_icon' => 'icon-ar-017-r', 'prev_icon' => 'icon-ar-017-l', 'css_dt_blog_carousel' => '', 'el_class' => '', ); parent::__construct(); } /** * Do shortcode here. */ protected function do_shortcode( $atts, $content = '' ) { $attributes = &$this->atts; // Loop query. $query = $this->get_posts_by_terms( $this->get_query_args() ); do_action( 'presscore_before_shortcode_loop', $this->sc_name, $this->atts ); echo '<div ' . $this->get_container_html_class( array( 'owl-carousel blog-carousel-shortcode' ) ) . ' ' . $this->get_container_data_atts() . '>'; if ( $query->have_posts() ): while( $query->have_posts() ): $query->the_post(); do_action('presscore_before_post'); $post_class_array = array( 'post', ); echo '<article ' . $this->post_class( $post_class_array ) . ' data-name="' . esc_attr( get_the_title() ) . '" data-date="' . esc_attr( get_the_date( 'c' ) ) . '">'; // Print custom css for VC scripts. if ( 'show_content' === $this->get_att( 'post_content' ) && function_exists( 'visual_composer' ) ) { visual_composer()->addShortcodesCustomCss(); } // Post media. $thumb_args = apply_filters( 'dt_post_thumbnail_args', array( 'img_id' => get_post_thumbnail_id(), 'class' => 'post-thumbnail-rollover', 'href' => get_permalink(), 'wrap' => '<a %HREF% %CLASS% %CUSTOM%><img %IMG_CLASS% %SRC% %ALT% %IMG_TITLE% %SIZE% /></a>', 'echo' => false, ) ); $post_media = dt_get_thumb_img( $thumb_args ); $details_btn_style = $this->get_att( 'read_more_button' ); $details_btn_text = $this->get_att( 'read_more_button_text' ); $details_btn_class = ('default_button' === $details_btn_style ? array( 'dt-btn-s', 'dt-btn' ) : array()); presscore_get_template_part( 'shortcodes', 'blog-carousel/tpl-layout', $this->get_att( 'layout' ), array( 'post_media' => $post_media, 'details_btn' => DT_Blog_Shortcode_HTML::get_details_btn( $details_btn_style, $details_btn_text, $details_btn_class ), 'post_excerpt' => $this->get_post_excerpt(), 'fancy_category_args' => array( 'custom_text_color' => ( ! $this->get_att( 'fancy_categories_font_color' ) ), 'custom_bg_color' => ( ! $this->get_att( 'fancy_categories_bg_color' ) ), ), ) ); echo '</article>'; do_action('presscore_after_post'); endwhile; endif; echo '</div>'; do_action( 'presscore_after_shortcode_loop', $this->sc_name, $this->atts ); } protected function get_container_html_class( $class = array() ) { $attributes = &$this->atts; $el_class = $this->atts['el_class']; // Unique class. $class[] = $this->get_unique_class(); if ( 'center' === $this->get_att( 'content_alignment' ) ) { $class[] = 'content-align-center'; }; $layout_classes = array( 'classic' => 'classic-layout-list', 'bottom_overlap' => 'bottom-overlap-layout-list', 'gradient_overlap' => 'gradient-overlap-layout-list', 'gradient_overlay' => 'gradient-overlay-layout-list', 'gradient_rollover' => 'content-rollover-layout-list', ); $layout = $this->get_att( 'layout' ); if ( array_key_exists( $layout, $layout_classes ) ) { $class[] = $layout_classes[ $layout ]; }; if ( $this->get_flag( 'content_bg' ) ) { $class[] = 'content-bg-on'; } if ( $this->get_flag( 'image_scale_animation_on_hover' ) ) { $class[] = 'scale-img'; } if ( $this->get_flag( 'image_hover_bg_color' ) ) { $class[] = 'enable-bg-rollover'; } if ( ! ( $this->get_flag( 'post_date' ) || $this->get_flag( 'post_category' ) || $this->get_flag( 'post_comments' ) || $this->get_flag( 'post_author' ) ) ) { $class[] = 'meta-info-off'; } if ( in_array( $layout, array( 'gradient_overlay', 'gradient_rollover' ) ) && 'off' === $this->get_att( 'post_content' ) && 'off' === $this->get_att( 'read_more_button' ) ) { $class[] = 'disable-layout-hover'; } if ( $this->get_flag( 'fancy_date' ) ) { $class[] = presscore_blog_fancy_date_class(); } switch ( $attributes['bullets_style'] ) { case 'scale-up': $class[] = 'bullets-scale-up'; break; case 'stroke': $class[] = 'bullets-stroke'; break; case 'fill-in': $class[] = 'bullets-fill-in'; break; case 'small-dot-stroke': $class[] = 'bullets-small-dot-stroke'; break; case 'ubax': $class[] = 'bullets-ubax'; break; case 'etefu': $class[] = 'bullets-etefu'; break; }; switch ( $attributes['arrow_responsiveness'] ) { case 'hide-arrows': $class[] = 'hide-arrows'; break; case 'reposition-arrows': $class[] = 'reposition-arrows'; break; }; if($this->atts['arrows_bg_show'] === 'y'){ $class[] = 'arrows-bg-on'; }else{ $class[] = 'arrows-bg-off'; }; if($this->atts['arrows_bg_hover_show'] === 'y'){ $class[] = 'arrows-hover-bg-on'; }else{ $class[] = 'arrows-hover-bg-off'; }; if ( function_exists( 'vc_shortcode_custom_css_class' ) ) { $class[] = vc_shortcode_custom_css_class( $this->atts['css_dt_blog_carousel'], ' ' ); }; $class[] = $el_class; return 'class="' . esc_attr( implode( ' ', $class ) ) . '"'; } /** * Return post classes. * * @param string|array $class * * @return string */ protected function post_class( $class = array() ) { if ( ! is_array( $class ) ) { $class = explode( ' ', $class ); } return 'class="' . join( ' ', get_post_class( $class, null ) ) . '"'; } /** * Return post excerpt with $length words. * * @return mixed */ protected function get_post_excerpt() { if ( 'off' === $this->atts['post_content'] ) { return ''; } if ( 'show_content' === $this->atts['post_content'] ) { return apply_filters( 'the_content', get_the_content( '' ) ); } $length = absint( $this->atts['excerpt_words_limit'] ); $excerpt = get_the_excerpt(); // VC excerpt fix. if ( function_exists( 'vc_manager' ) ) { $excerpt = vc_manager()->vc()->excerptFilter( $excerpt ); } if ( $length ) { $excerpt = wp_trim_words( $excerpt, $length ); } return apply_filters( 'the_excerpt', $excerpt ); } protected function get_container_data_atts() { $data_atts = array( 'scroll-mode' => ($this->atts['slide_to_scroll'] == "all") ? 'page' : '1', 'col-num' => $this->atts['slides_on_desk'], 'laptop-col' => $this->atts['slides_on_lapt'], 'h-tablet-columns-num' => $this->atts['slides_on_h_tabs'], 'v-tablet-columns-num' => $this->atts['slides_on_v_tabs'], 'phone-columns-num' => $this->atts['slides_on_mob'], 'auto-height' => ($this->atts['adaptive_height'] === 'y') ? 'true' : 'false', 'col-gap' => $this->atts['item_space'], 'speed' => $this->atts['speed'], 'autoplay' => ($this->atts['autoplay'] === 'y') ? 'true' : 'false', 'autoplay_speed' => $this->atts['autoplay_speed'], 'arrows' => ($this->atts['arrows'] === 'y') ? 'true' : 'false', 'bullet' => ($this->atts['show_bullets'] === 'y') ? 'true' : 'false', 'next-icon'=> $this->atts['next_icon'], 'prev-icon'=> $this->atts['prev_icon'], ); return presscore_get_inlide_data_attr( $data_atts ); } /** * Setup theme config for shortcode. */ protected function setup_config() { $config = presscore_config(); $show_post_content = ( 'off' !== $this->get_att( 'post_content' ) ); $config->set( 'show_excerpts', $show_post_content ); $config->set( 'post.preview.content.visible', $show_post_content ); $config->set( 'show_details', ( 'off' !== $this->get_att( 'read_more_button' ) ) ); $config->set( 'image_layout', ( 'resize' === $this->get_att( 'image_sizing' ) ? $this->get_att( 'image_sizing' ) : 'original' ) ); if ( 'resize' == $this->get_att( 'image_sizing' ) && $this->get_att( 'resized_image_dimensions' ) ) { // Sanitize. $img_dim = array_slice( array_map( 'absint', explode( 'x', strtolower( $this->get_att( 'resized_image_dimensions' ) ) ) ), 0, 2 ); // Make sure that all values is set. for ( $i = 0; $i < 2; $i++ ) { if ( empty( $img_dim[ $i ] ) ) { $img_dim[ $i ] = ''; } } $config->set( 'thumb_proportions', array( 'width' => $img_dim[0], 'height' => $img_dim[1] ) ); } else { $config->set( 'thumb_proportions', '' ); } $config->set( 'post.meta.fields.date', $this->get_flag( 'post_date' ) ); $config->set( 'post.meta.fields.categories', $this->get_flag( 'post_category' ) ); $config->set( 'post.meta.fields.comments', $this->get_flag( 'post_comments' ) ); $config->set( 'post.meta.fields.author', $this->get_flag( 'post_author' ) ); $config->set( 'post.fancy_date.enabled', $this->get_flag( 'fancy_date' ) ); $config->set( 'post.fancy_category.enabled', $this->get_flag( 'fancy_categories' ) ); $config->set( 'post.preview.background.enabled', false ); $config->set( 'post.preview.background.style', '' ); } /** * Return array of prepared less vars to insert to less file. * * @return array */ protected function get_less_vars() { $storage = new Presscore_Lib_SimpleBag(); $factory = new Presscore_Lib_LessVars_Factory(); $less_vars = new DT_Blog_LessVars_Manager( $storage, $factory ); $less_vars->add_keyword( 'unique-shortcode-class-name', 'blog-carousel-shortcode.' . $this->get_unique_class(), '~"%s"' ); $less_vars->add_pixel_or_percent_number( 'post-content-width', $this->get_att( 'bo_content_width' ) ); $less_vars->add_pixel_number( 'post-content-top-overlap', $this->get_att( 'bo_content_overlap' ) ); $less_vars->add_pixel_or_percent_number( 'post-content-overlap', $this->get_att( 'grovly_content_overlap' ) ); $less_vars->add_keyword( 'post-content-bg', $this->get_att( 'custom_content_bg_color', '~""' ) ); $less_vars->add_paddings( array( 'post-content-padding-top', 'post-content-padding-right', 'post-content-padding-bottom', 'post-content-padding-left', ), $this->get_att( 'post_content_paddings' ) ); $less_vars->add_paddings( array( 'post-thumb-padding-top', 'post-thumb-padding-right', 'post-thumb-padding-bottom', 'post-thumb-padding-left', ), $this->get_att( 'image_paddings' ), '%|px' ); //Post tab $less_vars->add_font_style( array( 'post-title-font-style', 'post-title-font-weight', 'post-title-text-transform', ), $this->get_att( 'post_title_font_style' ) ); $less_vars->add_pixel_number( 'post-title-font-size', $this->get_att( 'post_title_font_size' ) ); $less_vars->add_pixel_number( 'post-title-line-height', $this->get_att( 'post_title_line_height' ) ); $less_vars->add_pixel_number( 'post-meta-font-size', $this->get_att( 'meta_info_font_size' ) ); $less_vars->add_pixel_number( 'post-meta-line-height', $this->get_att( 'meta_info_line_height' ) ); $less_vars->add_keyword( 'post-title-color', $this->get_att( 'custom_title_color', '~""' ) ); $less_vars->add_keyword( 'post-meta-color', $this->get_att( 'custom_meta_color', '~""' ) ); $less_vars->add_keyword( 'post-content-color', $this->get_att( 'custom_content_color', '~""' ) ); $less_vars->add_pixel_number( 'post-excerpt-font-size', $this->get_att( 'content_font_size' ) ); $less_vars->add_pixel_number( 'post-excerpt-line-height', $this->get_att( 'content_line_height' ) ); $less_vars->add_pixel_number( 'post-meta-margin-bottom', $this->get_att( 'meta_info_bottom_margin' ) ); $less_vars->add_pixel_number( 'post-title-margin-bottom', $this->get_att( 'post_title_bottom_margin' ) ); $less_vars->add_pixel_number( 'post-excerpt-margin-bottom', $this->get_att( 'content_bottom_margin' ) ); $less_vars->add_font_style( array( 'post-meta-font-style', 'post-meta-font-weight', 'post-meta-text-transform', ), $this->get_att( 'meta_info_font_style' ) ); $less_vars->add_font_style( array( 'post-content-font-style', 'post-content-font-weight', 'post-content-text-transform', ), $this->get_att( 'content_font_style' ) ); $less_vars->add_keyword( 'fancy-data-color', $this->get_att( 'fancy_date_font_color', '~""' ) ); $less_vars->add_keyword( 'fancy-data-bg', $this->get_att( 'fancy_date_bg_color', '~""' ) ); $less_vars->add_keyword( 'fancy-data-line-color', $this->get_att( 'fancy_date_line_color', '~""' ) ); $less_vars->add_keyword( 'fancy-category-color', $this->get_att( 'fancy_categories_font_color', '~""' ) ); $less_vars->add_keyword( 'fancy-category-bg', $this->get_att( 'fancy_categories_bg_color', '~""' ) ); $less_vars->add_pixel_number( 'icon-size', $this->get_att( 'arrow_icon_size' ) ); $less_vars->add_paddings( array( 'l-icon-padding-top', 'l-icon-padding-right', 'l-icon-padding-bottom', 'l-icon-padding-left', ), $this->get_att( 'l_arrow_icon_paddings' ) ); $less_vars->add_paddings( array( 'r-icon-padding-top', 'r-icon-padding-right', 'r-icon-padding-bottom', 'r-icon-padding-left', ), $this->get_att( 'r_arrow_icon_paddings' ) ); $less_vars->add_pixel_number( 'arrow-width', $this->get_att( 'arrow_bg_width' ) ); $less_vars->add_pixel_number( 'arrow-height', $this->get_att( 'arrow_bg_height' ) ); $less_vars->add_pixel_number( 'arrow-border-radius', $this->get_att( 'arrow_border_radius' ) ); $less_vars->add_pixel_number( 'arrow-border-width', $this->get_att( 'arrow_border_width' ) ); $less_vars->add_keyword( 'icon-color', $this->get_att( 'arrow_icon_color', '~""' ) ); $less_vars->add_keyword( 'arrow-border-color', $this->get_att( 'arrow_border_color', '~""' ) ); $less_vars->add_keyword( 'arrow-bg', $this->get_att( 'arrow_bg_color', '~""' ) ); $less_vars->add_keyword( 'icon-color-hover', $this->get_att( 'arrow_icon_color_hover', '~""' ) ); $less_vars->add_keyword( 'arrow-border-color-hover', $this->get_att( 'arrow_border_color_hover', '~""' ) ); $less_vars->add_keyword( 'arrow-bg-hover', $this->get_att( 'arrow_bg_color_hover', '~""' ) ); $less_vars->add_keyword( 'arrow-right-v-position', $this->get_att( 'r_arrow_v_position' ) ); $less_vars->add_keyword( 'arrow-right-h-position', $this->get_att( 'r_arrow_h_position' ) ); $less_vars->add_pixel_number( 'r-arrow-v-position', $this->get_att( 'r_arrow_v_offset' ) ); $less_vars->add_pixel_number( 'r-arrow-h-position', $this->get_att( 'r_arrow_h_offset' ) ); $less_vars->add_keyword( 'arrow-left-v-position', $this->get_att( 'l_arrow_v_position' ) ); $less_vars->add_keyword( 'arrow-left-h-position', $this->get_att( 'l_arrow_h_position' ) ); $less_vars->add_pixel_number( 'l-arrow-v-position', $this->get_att( 'l_arrow_v_offset' ) ); $less_vars->add_pixel_number( 'l-arrow-h-position', $this->get_att( 'l_arrow_h_offset' ) ); $less_vars->add_pixel_number( 'hide-arrows-switch', $this->get_att( 'hide_arrows_mobile_switch_width' ) ); $less_vars->add_pixel_number( 'reposition-arrows-switch', $this->get_att( 'reposition_arrows_mobile_switch_width' ) ); $less_vars->add_pixel_number( 'arrow-left-h-position-mobile', $this->get_att( 'l_arrows_mobile_h_position' ) ); $less_vars->add_pixel_number( 'arrow-right-h-position-mobile', $this->get_att( 'r_arrows_mobile_h_position' ) ); $less_vars->add_pixel_number( 'bullet-size', $this->get_att( 'bullet_size' ) ); $less_vars->add_keyword( 'bullet-color', $this->get_att( 'bullet_color', '~""' ) ); $less_vars->add_keyword( 'bullet-color-hover', $this->get_att( 'bullet_color_hover', '~""' ) ); $less_vars->add_pixel_number( 'bullet-gap', $this->get_att( 'bullet_gap' ) ); $less_vars->add_keyword( 'bullets-v-position', $this->get_att( 'bullets_v_position' ) ); $less_vars->add_keyword( 'bullets-h-position', $this->get_att( 'bullets_h_position' ) ); $less_vars->add_pixel_number( 'bullet-v-position', $this->get_att( 'bullets_v_offset' ) ); $less_vars->add_pixel_number( 'bullet-h-position', $this->get_att( 'bullets_h_offset' ) ); return $less_vars->get_vars(); } protected function get_less_file_name() { // @TODO: Remove in production. $less_file_name = 'dt-blog-carousel'; $less_file_path = trailingslashit( get_template_directory() ) . "css/dynamic-less/shortcodes/{$less_file_name}.less"; return $less_file_path; } /** * Return dummy html for VC inline editor. * * @return string */ protected function get_vc_inline_html() { return $this->vc_inline_dummy( array( 'class' => 'dt_blog_carousel', 'title' => _x( 'Blog Carousel', 'vc inline dummy', 'the7mk2' ), ) ); } protected function get_query_args() { //$posts_total = -1; $posts_total = $this->get_att( 'dis_posts_total', '-1' ); //$posts_total = $this->get_att( 'dis_posts_total' ); $category_att = $this->get_att( 'category' ); $terms_slugs = ''; if ( $category_att ) { $terms_slugs = presscore_sanitize_explode_string( $category_att ); } $query_args = array( 'orderby' => $this->get_att( 'orderby' ), 'order' => $this->get_att( 'order' ), 'number' => $posts_total, 'select' => ( $terms_slugs ? 'only' : 'all' ), 'category' => $terms_slugs, ); return $query_args; } } // create shortcode DT_Shortcode_Blog_Carousel::get_instance()->add_shortcode(); endif;
[+]
..
[-] blog-carousel.php
[edit]
[-] tpl-layout.php
[edit]
[-] tpl-layout-gradient_rollover.php
[edit]
[-] tpl-layout-gradient_overlay.php
[edit]
[-] index.php
[edit]