PageRenderTime 57ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/themes/aurum/inc/lib/visual-composer/laborator-shortcodes/laborator_logo_carousel.php

https://gitlab.com/pongpanich/niyomprathai
PHP | 224 lines | 177 code | 37 blank | 10 comment | 9 complexity | 248c8463b952287911ad082583aee416 MD5 | raw file
  1. <?php
  2. /**
  3. * Logo Carousel for Visual Composer
  4. *
  5. * Laborator.co
  6. * www.laborator.co
  7. */
  8. class WPBakeryShortCode_laborator_logo_carousel extends WPBakeryShortCode
  9. {
  10. public function content($atts, $content = null)
  11. {
  12. if( function_exists( 'vc_map_get_attributes' ) ) {
  13. $atts = vc_map_get_attributes( $this->getShortcode(), $atts );
  14. }
  15. extract(shortcode_atts(array(
  16. 'title' => '',
  17. 'images' => '',
  18. 'max_height' => '',
  19. 'custom_links' => '',
  20. 'target' => '',
  21. 'img_size' => '',
  22. 'columns' => '',
  23. 'show_navigation'=> '',
  24. 'autoswitch' => '',
  25. 'el_class' => '',
  26. 'css' => '',
  27. ), $atts));
  28. $css_class = apply_filters(VC_SHORTCODE_CUSTOM_CSS_FILTER_TAG,'lab_vc_logo_carousel wpb_content_element '.$el_class.vc_shortcode_custom_css_class($css, ' '), $this->settings['base']);
  29. $rand_id = "el_" . time() . mt_rand(10000,99999);
  30. wp_enqueue_script('owl-carousel');
  31. wp_enqueue_style('owl-carousel');
  32. $show_navigation = explode(',', $show_navigation);
  33. ob_start();
  34. $images = explode(',', $images);
  35. $custom_links = explode(",", $custom_links);
  36. ?>
  37. <div class="<?php echo $css_class; ?>">
  38. <div class="logos-carousel is-hidden<?php echo in_array('pagination', $show_navigation) ? ' has-numbers' : ''; ?>" id="<?php echo $rand_id; ?>">
  39. <?php
  40. foreach($images as $i => $img_id):
  41. $img = wpb_getImageBySize( array( 'attach_id' => $img_id, 'thumb_size' => $img_size ) );
  42. $link = isset($custom_links[$i]) ? $custom_links[$i] : '';
  43. if( ! isset($img) || ! isset($img['thumbnail']))
  44. continue;
  45. ?>
  46. <div class="logo-entry">
  47. <?php if($link): ?>
  48. <a href="<?php echo $link; ?>" target="<?php echo $target; ?>">
  49. <?php endif; ?>
  50. <?php echo $img['thumbnail']; ?>
  51. <?php if($link): ?>
  52. </a>
  53. <?php endif; ?>
  54. </div>
  55. <?php
  56. endforeach;
  57. ?>
  58. </div>
  59. </div>
  60. <script type="text/javascript">
  61. jQuery(document).ready(function($)
  62. {
  63. var $carousel_el = $("#<?php echo $rand_id; ?>");
  64. $carousel_el.removeClass('is-hidden');
  65. $carousel_el.owlCarousel({
  66. items: <?php echo $columns; ?>,
  67. navigation: <?php echo in_array('next_prev', $show_navigation) ? 'true' : 'false'; ?>,
  68. pagination: <?php echo in_array('pagination', $show_navigation) ? 'true' : 'false'; ?>,
  69. autoPlay: <?php echo absint($autoswitch) <= 0 ? 'false' : $autoswitch * 1000; ?>,
  70. stopOnHover: true,
  71. singleItem: <?php echo $columns == 1 ? 'true' : 'false'; ?>,
  72. direction: _rtl()
  73. });
  74. });
  75. </script>
  76. <?php if ( $max_height ) : $max_height = intval( $max_height ); ?>
  77. <style>
  78. #<?php echo $rand_id; ?> .logo-entry,
  79. #<?php echo $rand_id; ?> .logo-entry a {
  80. height: <?php echo $max_height; ?>px;
  81. line-height: <?php echo $max_height; ?>px;
  82. }
  83. </style>
  84. <?php endif; ?>
  85. <?php
  86. $output = ob_get_contents();
  87. ob_end_clean();
  88. return $output;
  89. }
  90. }
  91. // Shortcode Options
  92. $target_arr = array(
  93. __( 'Same window', 'lab_composer') => '_self',
  94. __( 'New window', 'lab_composer') => "_blank"
  95. );
  96. $opts = array(
  97. "name" => __("Logos Carousel", 'lab_composer'),
  98. "description" => __('Your clients logos into a rotative carousel.', 'lab_composer'),
  99. "base" => "laborator_logo_carousel",
  100. "class" => "vc_laborator_logo_carousel",
  101. "icon" => "icon-lab-logo-carousel",
  102. "controls" => "full",
  103. "category" => __('Laborator', 'lab_composer'),
  104. "params" => array(
  105. array(
  106. "type" => "textfield",
  107. "heading" => __("Widget title", 'lab_composer'),
  108. "param_name" => "title",
  109. "value" => "",
  110. "description" => __("Enter text which will be used as widget title. Leave blank if no title is needed.", 'lab_composer')
  111. ),
  112. array(
  113. 'type' => 'attach_images',
  114. 'heading' => __( 'Images', 'lab_composer'),
  115. 'param_name' => 'images',
  116. 'value' => '',
  117. 'description' => __( 'Select images (logos) from media library.', 'lab_composer')
  118. ),
  119. array(
  120. "type" => "textfield",
  121. "heading" => __("Maximum Height", 'lab_composer'),
  122. "param_name" => "max_height",
  123. "value" => "",
  124. "description" => __("Enter maximum height for logo images in pixels. (Optional)", 'lab_composer')
  125. ),
  126. array(
  127. 'type' => 'exploded_textarea',
  128. 'heading' => __( 'Custom links', 'lab_composer'),
  129. 'param_name' => 'custom_links',
  130. 'description' => __( 'Enter links for each slide here. Divide links with linebreaks (Enter). Leave blank if you don\'t want to add links.', 'lab_composer'),
  131. ),
  132. array(
  133. 'type' => 'dropdown',
  134. 'heading' => __( 'Target', 'lab_composer'),
  135. 'param_name' => 'target',
  136. 'value' => $target_arr,
  137. 'dependency' => array( 'element'=>'custom_links', 'not_empty'=>true )
  138. ),
  139. array(
  140. 'type' => 'textfield',
  141. 'heading' => __( 'Image size', 'lab_composer'),
  142. 'param_name' => 'img_size',
  143. 'value' => 'thumbnail',
  144. 'description' => __( 'Enter image size. Example: thumbnail, medium, large, full or other sizes defined by current theme. Alternatively enter image size in pixels: 200x100 (Width x Height). Leave empty to use "thumbnail" size.', 'lab_composer')
  145. ),
  146. array(
  147. 'type' => 'dropdown',
  148. 'heading' => __( 'Columns per slide', 'lab_composer'),
  149. 'param_name' => 'columns',
  150. 'value' => range(1,18),
  151. 'std' => 5,
  152. 'description' => __( 'How many logos you want to show per row (slide).', 'lab_composer'),
  153. ),
  154. array(
  155. 'type' => 'checkbox',
  156. 'heading' => __( 'Slider navigation', 'lab_composer'),
  157. 'param_name' => 'show_navigation',
  158. 'description' => __( 'Select whether you want to display carousel navigation links.', 'lab_composer'),
  159. 'value' => array(
  160. __( 'Display pext/previous<br />', 'lab_composer') => 'next_prev' ,
  161. __( 'Display numbers (circles)', 'lab_composer') => 'pagination'
  162. ),
  163. ),
  164. array(
  165. "type" => "textfield",
  166. "heading" => __("Auto rotate", 'lab_composer'),
  167. "param_name" => "autoswitch",
  168. "value" => "5",
  169. "description" => __("Auto rotate slides each X seconds. Leave blank to disable auto switching.", 'lab_composer')
  170. ),
  171. array(
  172. "type" => "textfield",
  173. "heading" => __("Extra class name", 'lab_composer'),
  174. "param_name" => "el_class",
  175. "value" => "",
  176. "description" => __("If you wish to style particular content element differently, then use this field to add a class name and then refer to it in your css file.", 'lab_composer')
  177. ),
  178. array(
  179. "type" => "css_editor",
  180. "heading" => __('Css', 'lab_composer'),
  181. "param_name" => "css",
  182. "group" => __('Design options', 'lab_composer')
  183. )
  184. )
  185. );
  186. // Add & init the shortcode
  187. vc_map($opts);