vc-images-carousel.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. if ( ! defined( 'ABSPATH' ) ) {
  3. die( '-1' );
  4. }
  5. require_once vc_path_dir( 'SHORTCODES_DIR', 'vc-gallery.php' );
  6. /**
  7. * Class WPBakeryShortCode_Vc_images_carousel
  8. */
  9. class WPBakeryShortCode_Vc_Images_Carousel extends WPBakeryShortCode_Vc_Gallery {
  10. protected static $carousel_index = 1;
  11. /**
  12. * WPBakeryShortCode_Vc_images_carousel constructor.
  13. * @param $settings
  14. */
  15. public function __construct( $settings ) {
  16. parent::__construct( $settings );
  17. $this->jsCssScripts();
  18. }
  19. public function jsCssScripts() {
  20. wp_register_script( 'vc_transition_bootstrap_js', vc_asset_url( 'lib/vc_carousel/js/transition.min.js' ), array(), WPB_VC_VERSION, true );
  21. wp_register_script( 'vc_carousel_js', vc_asset_url( 'lib/vc_carousel/js/vc_carousel.min.js' ), array( 'vc_transition_bootstrap_js' ), WPB_VC_VERSION, true );
  22. wp_register_style( 'vc_carousel_css', vc_asset_url( 'lib/vc_carousel/css/vc_carousel.min.css' ), array(), WPB_VC_VERSION );
  23. }
  24. /**
  25. * @return string
  26. */
  27. public static function getCarouselIndex() {
  28. return ( self::$carousel_index ++ ) . '-' . time();
  29. }
  30. /**
  31. * @param $size
  32. * @return string
  33. */
  34. protected function getSliderWidth( $size ) {
  35. global $_wp_additional_image_sizes;
  36. $width = '100%';
  37. if ( in_array( $size, get_intermediate_image_sizes(), true ) ) {
  38. if ( in_array( $size, array(
  39. 'thumbnail',
  40. 'medium',
  41. 'large',
  42. ), true ) ) {
  43. $width = get_option( $size . '_size_w' ) . 'px';
  44. } else {
  45. if ( isset( $_wp_additional_image_sizes ) && isset( $_wp_additional_image_sizes[ $size ] ) ) {
  46. $width = $_wp_additional_image_sizes[ $size ]['width'] . 'px';
  47. }
  48. }
  49. } else {
  50. preg_match_all( '/\d+/', $size, $matches );
  51. if ( count( $matches[0] ) > 1 ) {
  52. $width = $matches[0][0] . 'px';
  53. }
  54. }
  55. return $width;
  56. }
  57. }