PageRenderTime 62ms CodeModel.GetById 34ms RepoModel.GetById 0ms app.codeStats 0ms

/handy/THEME/handystore/handystore/shortcodes/builder_shortcodes/carousel/carousel.php

https://gitlab.com/hop23typhu/list-theme
PHP | 299 lines | 260 code | 21 blank | 18 comment | 35 complexity | daf2635b2effaa12b672d4036370c754 MD5 | raw file
  1. <?php
  2. if ( ! class_exists( 'IG_Carousel' ) ) {
  3. class IG_Carousel extends IG_Pb_Shortcode_Parent {
  4. public function __construct() {
  5. parent::__construct();
  6. }
  7. /**
  8. * DEFINE configuration information of shortcode
  9. */
  10. public function element_config() {
  11. $this->config['shortcode'] = strtolower( __CLASS__ );
  12. $this->config['name'] = esc_html__( 'PT Carousel', 'plumtree' );
  13. $this->config['has_subshortcode'] = 'IG_Item_' . str_replace( 'IG_', '', __CLASS__ );
  14. $this->config['edit_using_ajax'] = true;
  15. $this->config['exception'] = array(
  16. 'default_content' => esc_html__( 'PT Carousel', 'plumtree' ),
  17. 'data-modal-title' => esc_html__( 'PT Carousel', 'plumtree' ),
  18. 'admin_assets' => array(
  19. // Shortcode initialization
  20. 'row.js',
  21. 'ig-colorpicker.js',
  22. ),
  23. );
  24. }
  25. /**
  26. * DEFINE setting options of shortcode
  27. */
  28. public function element_items() {
  29. $this->items = array(
  30. 'content' => array(
  31. array(
  32. 'name' => esc_html__( 'Element Title', 'plumtree' ),
  33. 'id' => 'el_title',
  34. 'type' => 'text_field',
  35. 'class' => 'jsn-input-xxlarge-fluid',
  36. 'std' => '',
  37. 'role' => 'title',
  38. 'tooltip' => esc_html__( 'Set title for current element for identifying easily', 'plumtree' )
  39. ),
  40. array(
  41. 'id' => 'carousel_items',
  42. 'type' => 'group',
  43. 'shortcode' => ucfirst( __CLASS__ ),
  44. 'sub_item_type' => $this->config['has_subshortcode'],
  45. 'sub_items' => array(
  46. array('std' => ''),
  47. array('std' => ''),
  48. ),
  49. ),
  50. ),
  51. 'styling' => array(
  52. array(
  53. 'name' => esc_html__( 'Items per Slide', 'plumtree' ),
  54. 'id' => 'per_slide',
  55. 'type' => 'select',
  56. 'std' => '3',
  57. 'options' => array(
  58. '1' => esc_html__( '1 item in row', 'plumtree' ),
  59. '2' => esc_html__( '2 items in row', 'plumtree' ),
  60. '3' => esc_html__( '3 items in row', 'plumtree' ),
  61. '6' => esc_html__( '6 items in 2 rows', 'plumtree' ),
  62. 'n' => esc_html__( 'n items in row', 'plumtree' )
  63. ),
  64. 'has_depend' => '1',
  65. ),
  66. array(
  67. 'name' => esc_html__( 'How many slides to show in one moment', 'plumtree' ),
  68. 'id' => 'slides_qty',
  69. 'type' => 'select',
  70. 'std' => '4',
  71. 'options' => array(
  72. '2' => esc_html__( '2 Slides', 'plumtree' ),
  73. '3' => esc_html__( '3 Slides', 'plumtree' ),
  74. '4' => esc_html__( '4 Slides', 'plumtree' ),
  75. '5' => esc_html__( '5 Slides', 'plumtree' ),
  76. '6 ' => esc_html__( '6 Slides', 'plumtree' ),
  77. ),
  78. 'dependency' => array( 'per_slide', '=', 'n'),
  79. ),
  80. array(
  81. 'name' => esc_html__( 'Animation on hover', 'plumtree' ),
  82. 'id' => 'hover_animation',
  83. 'type' => 'select',
  84. 'std' => 'shift',
  85. 'options' => array(
  86. 'shift' => esc_html__( 'Full height shift', 'plumtree' ),
  87. 'fading' => esc_html__( 'Full height fading', 'plumtree' ),
  88. 'bottom-sliding' => esc_html__( 'Sliding from bottom', 'plumtree' ),
  89. 'none' => esc_html__( 'No animation', 'plumtree' ),
  90. ),
  91. ),
  92. array(
  93. 'name' => esc_html__( 'Dimension', 'plumtree' ),
  94. 'container_class' => 'combo-group',
  95. 'id' => 'dimension',
  96. 'type' => 'dimension',
  97. 'extended_ids' => array( 'dimension_width', 'dimension_height', 'dimension_width_unit' ),
  98. 'dimension_width' => array( 'std' => '' ),
  99. 'dimension_height' => array( 'std' => '' ),
  100. 'dimension_width_unit' => array(
  101. 'options' => array( 'px' => 'px', '%' => '%' ),
  102. 'std' => 'px',
  103. ),
  104. 'tooltip' => esc_html__( 'Set width and height of element', 'plumtree' ),
  105. ),
  106. array(
  107. 'name' => esc_html__( 'Transition Type', 'plumtree' ),
  108. 'id' => 'transition_type',
  109. 'type' => 'select',
  110. 'std' => 'fade',
  111. 'options' => array(
  112. 'fade' => esc_html__( 'Fade', 'plumtree' ),
  113. 'backSlide' => esc_html__( 'Back Slide', 'plumtree' ),
  114. 'goDown' => esc_html__( 'Go Down', 'plumtree' ),
  115. 'fadeUp' => esc_html__( 'Fade Up', 'plumtree' ),
  116. ),
  117. ),
  118. array(
  119. 'name' => esc_html__( 'Show Page Navigation', 'plumtree' ),
  120. 'id' => 'show_indicator',
  121. 'type' => 'radio',
  122. 'std' => 'yes',
  123. 'options' => array( 'yes' => esc_html__( 'Yes', 'plumtree' ), 'no' => esc_html__( 'No', 'plumtree' ) ),
  124. 'tooltip' => esc_html__( 'Show/hide navigation buttons under your carousel', 'plumtree' ),
  125. ),
  126. array(
  127. 'name' => esc_html__( 'Show Arrows', 'plumtree' ),
  128. 'id' => 'show_arrows',
  129. 'type' => 'radio',
  130. 'std' => 'yes',
  131. 'options' => array( 'yes' => esc_html__( 'Yes', 'plumtree' ), 'no' => esc_html__( 'No', 'plumtree' ) ),
  132. 'tooltip' => esc_html__( 'Show/hide arrow buttons', 'plumtree' ),
  133. ),
  134. array(
  135. 'name' => esc_html__( 'Autoplay', 'plumtree' ),
  136. 'id' => 'autoplay',
  137. 'type' => 'radio',
  138. 'std' => 'no',
  139. 'options' => array( 'yes' => esc_html__( 'Yes', 'plumtree' ), 'no' => esc_html__( 'No', 'plumtree' ) ),
  140. 'tooltip' => esc_html__( 'Whether to running your carousel automatically or not', 'plumtree' ),
  141. ),
  142. array(
  143. 'name' => esc_html__( 'Add "lazyload" to this element?', 'plumtree' ),
  144. 'id' => 'lazyload',
  145. 'type' => 'radio',
  146. 'std' => 'no',
  147. 'options' => array( 'yes' => esc_html__( 'Yes', 'plumtree' ), 'no' => esc_html__( 'No', 'plumtree' ) ),
  148. ),
  149. )
  150. );
  151. }
  152. /**
  153. * DEFINE shortcode content
  154. *
  155. * @param type $atts
  156. * @param type $content
  157. */
  158. public function element_shortcode_full( $atts = null, $content = null ) {
  159. $arr_params = shortcode_atts( $this->config['params'], $atts );
  160. extract( $arr_params );
  161. $html_output = '';
  162. $lazy_param = '';
  163. // Container Styles
  164. $container_class = 'pt-carousel animation-'.$hover_animation.' '.$css_suffix;
  165. $container_id = uniqid('owl',false);
  166. if ($arr_params['lazyload'] == 'yes') { $lazy_param = ' data-expand="-100"'; $container_class = $container_class.' lazyload'; }
  167. $container_class = ( ! empty( $container_class ) ) ? ' class="' . $container_class . '"' : '';
  168. $styles = array();
  169. if ( ! empty( $dimension_width ) )
  170. $styles[] = "width : {$dimension_width}{$dimension_width_unit};";
  171. if ( ! empty( $dimension_height ) )
  172. $styles[] = "height : {$dimension_height}px;";
  173. $styles = trim( implode( ' ', $styles ) );
  174. $styles = ! empty( $styles ) ? "style='$styles'" : '';
  175. // Responsive qty
  176. if ( $slides_qty=='2' && (pt_show_layout()!='layout-one-col') ) {
  177. $qty_sm = $qty_xs = 1;
  178. $qty_md = 2;
  179. } elseif ( $slides_qty=='2' && (pt_show_layout()=='layout-one-col') ) {
  180. $qty_sm = $qty_xs = 1;
  181. $qty_md = 2;
  182. } elseif ( $slides_qty!='2' && (pt_show_layout()!='layout-one-col') ) {
  183. $qty_md = 3;
  184. $qty_sm = 2;
  185. $qty_xs = 2;
  186. } elseif ( $slides_qty!='2' && (pt_show_layout()=='layout-one-col') ) {
  187. $qty_md = $slides_qty;
  188. $qty_sm = 2;
  189. $qty_xs = 1;
  190. }
  191. // Carousel Parameters
  192. $owlAutoPlay = 'false';
  193. if ( $autoplay == 'yes' )
  194. $owlAutoPlay = 'true';
  195. $owlPagination = 'false';
  196. if ( $show_indicator == 'yes' )
  197. $owlPagination = 'true';
  198. $owlTransition = $transition_type;
  199. $owlSingleItem = 'false';
  200. if ($per_slide!='n') {
  201. $owlSingleItem = 'true';
  202. }
  203. // Get Carousel Items
  204. $sub_shortcode = IG_Pb_Helper_Shortcode::remove_autop( $content );
  205. $items = explode( '<!--separate-->', $sub_shortcode );
  206. array_pop($items);
  207. $total = count($items);
  208. $new_items = '';
  209. $test = '';
  210. if ( $total<(int)$per_slide || (int)$per_slide==1 || $per_slide=='n' ) {
  211. foreach ($items as $position => $item) {
  212. $new_items .= '<div class="carousel-item">'.$item.'</div>';
  213. }
  214. unset($item);
  215. } else {
  216. foreach ($items as $position => $item) {
  217. $current_position = $position + 1;
  218. if ( ($current_position == 1) || ($current_position % (int)$per_slide == 1) ) {
  219. $new_items .= '<div class="carousel-item">'.$item;
  220. if ($current_position == $total) {
  221. $new_items .= '</div>';
  222. }
  223. } elseif ( $current_position == $total ) {
  224. $new_items .= $item.'</div>';
  225. } elseif ( $current_position % (int)$per_slide == 0 ) {
  226. $new_items .= $item.'</div>';
  227. } else {
  228. $new_items .= $item;
  229. }
  230. }
  231. unset($item);
  232. }
  233. $carousel_content = $new_items;
  234. // Output Carousel
  235. $html_output .= "<div{$container_class} id='{$container_id}'{$lazy_param}>";
  236. if ( $el_title && $el_title !='' ) { $html_output .= "<div class='title-wrapper'><h3>{$el_title}</h3>"; }
  237. if ( $show_arrows == 'yes' ) { $html_output .= "<div class='slider-navi'><span class='prev'></span><span class='next'></span></div>"; }
  238. if ( $el_title && $el_title !='' ) { $html_output .= "</div>"; }
  239. $html_output .= "<div class='carousel-container per-slide-{$per_slide}' {$styles}>";
  240. $html_output .= $carousel_content;
  241. $html_output .= "</div></div>";
  242. $html_output.='
  243. <script type="text/javascript">
  244. (function($) {
  245. $(document).ready(function() {
  246. var owl = $("#'.$container_id.' .carousel-container");
  247. owl.owlCarousel({
  248. navigation : false,
  249. pagination : '.$owlPagination.',
  250. autoPlay : '.$owlAutoPlay.',
  251. slideSpeed : 300,
  252. paginationSpeed : 400,
  253. singleItem : '.$owlSingleItem.',
  254. transitionStyle : "'.$owlTransition.'",';
  255. if ($per_slide=='n') {
  256. $html_output.= 'items : '.$slides_qty.',
  257. itemsDesktop : [1199,'.$qty_md.'],
  258. itemsDesktopSmall : [979,'.$qty_sm.'],
  259. itemsTablet: [768,'.$qty_xs.'],
  260. itemsMobile : [479,1],';
  261. }
  262. $html_output.= '});
  263. // Custom Navigation Events
  264. $("#'.$container_id.'").find(".next").click(function(){
  265. owl.trigger("owl.next");
  266. })
  267. $("#'.$container_id.'").find(".prev").click(function(){
  268. owl.trigger("owl.prev");
  269. })
  270. });
  271. })(jQuery);
  272. </script>';
  273. return $this->element_wrapper( $html_output, $arr_params );
  274. }
  275. }
  276. }