WC_Gallery_Display_Class

WooCommerce Gallery Display Class.

Defined (1)

The class is defined in the following location(s).

/classes/class-wc-dynamic-gallery.php  
  1. class WC_Gallery_Display_Class 
  2. public static function frontend_register_scripts() { 
  3. $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; 
  4.  
  5. // If don't have any plugin or theme register font awesome style then register it from plugin framework 
  6. if ( ! wp_style_is( 'font-awesome-styles', 'registered' ) ) { 
  7. global $wc_dgallery_admin_interface; 
  8. $wc_dgallery_admin_interface->register_fontawesome_style(); 
  9. wp_register_style( 'a3-dgallery-style', WOO_DYNAMIC_GALLERY_JS_URL . '/mygallery/jquery.a3-dgallery.css', array( 'font-awesome-styles' ), WOO_DYNAMIC_GALLERY_VERSION ); 
  10.  
  11. wp_register_script( 'a3-dgallery-script', WOO_DYNAMIC_GALLERY_JS_URL . '/mygallery/jquery.a3-dgallery.js', array( 'jquery' ), WOO_DYNAMIC_GALLERY_VERSION, true ); 
  12. wp_register_script( 'a3-dgallery-variations-script', WOO_DYNAMIC_GALLERY_JS_URL . '/select_variations.js', array( 'jquery', 'wc-add-to-cart-variation' ), WOO_DYNAMIC_GALLERY_VERSION, true ); 
  13.  
  14. $popup_gallery = get_option( WOO_DYNAMIC_GALLERY_PREFIX.'popup_gallery' ); 
  15. if ( 'fb' == $popup_gallery ) { 
  16. wp_register_style( 'woocommerce_fancybox_styles', WOO_DYNAMIC_GALLERY_JS_URL . '/fancybox/fancybox.css', array(), '1.3.4' ); 
  17. wp_register_script( 'fancybox', WOO_DYNAMIC_GALLERY_JS_URL . '/fancybox/fancybox'.$suffix.'.js', array( 'jquery' ), '1.3.4', true ); 
  18. } elseif ( 'colorbox' == $popup_gallery ) { 
  19. wp_register_style( 'a3_colorbox_style', WOO_DYNAMIC_GALLERY_JS_URL . '/colorbox/colorbox.css', array(), '1.4.4' ); 
  20. wp_register_script( 'colorbox_script', WOO_DYNAMIC_GALLERY_JS_URL . '/colorbox/jquery.colorbox'.$suffix.'.js', array( 'jquery' ), '1.4.4', true ); 
  21.  
  22. public static function backend_register_scripts() { 
  23. $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; 
  24.  
  25. global $wc_dgallery_admin_interface; 
  26. $wc_dgallery_admin_interface->register_fontawesome_style(); 
  27.  
  28. wp_register_style( 'a3-dgallery-style', WOO_DYNAMIC_GALLERY_JS_URL . '/mygallery/jquery.a3-dgallery.css', array( 'thickbox', 'font-awesome-styles' ), WOO_DYNAMIC_GALLERY_VERSION ); 
  29. wp_register_style( 'woocommerce_fancybox_styles', WOO_DYNAMIC_GALLERY_JS_URL . '/fancybox/fancybox.css', array(), '1.3.4' ); 
  30. wp_register_style( 'a3_colorbox_style', WOO_DYNAMIC_GALLERY_JS_URL . '/colorbox/colorbox.css', array(), '1.4.4' ); 
  31. wp_register_style( 'a3-dynamic-metabox-admin-style', WOO_DYNAMIC_GALLERY_CSS_URL . '/a3.dynamic.metabox.admin.css', array(), WOO_DYNAMIC_GALLERY_VERSION ); 
  32. wp_register_style( 'a3-dynamic-metabox-admin-style-rtl', WOO_DYNAMIC_GALLERY_CSS_URL . '/a3.dynamic.metabox.admin.rtl.css', array(), WOO_DYNAMIC_GALLERY_VERSION ); 
  33.  
  34. wp_register_script( 'preview-gallery-script', WOO_DYNAMIC_GALLERY_JS_URL.'/galleries.js', array( 'jquery', 'thickbox' ), WOO_DYNAMIC_GALLERY_VERSION, true ); 
  35. wp_register_script( 'a3-dgallery-script', WOO_DYNAMIC_GALLERY_JS_URL . '/mygallery/jquery.a3-dgallery.js', array( 'jquery' ), WOO_DYNAMIC_GALLERY_VERSION, true ); 
  36.  
  37. wp_register_script( 'fancybox', WOO_DYNAMIC_GALLERY_JS_URL . '/fancybox/fancybox'.$suffix.'.js', array( 'jquery' ), '1.3.4', true ); 
  38. wp_register_script( 'colorbox_script', WOO_DYNAMIC_GALLERY_JS_URL . '/colorbox/jquery.colorbox'.$suffix.'.js', array( 'jquery' ), '1.4.4', true ); 
  39.  
  40. wp_register_script( 'a3-dynamic-metabox-admin-script', WOO_DYNAMIC_GALLERY_JS_URL . '/a3.dynamic.metabox.admin' . $suffix . '.js', array( 'jquery', 'jquery-ui-core', 'jquery-ui-widget', 'jquery-ui-mouse', 'jquery-ui-sortable' ), WOO_DYNAMIC_GALLERY_VERSION ); 
  41.  
  42. public static function wc_dynamic_gallery_display($product_id=0) { 
  43. /** 
  44. * Single Product Image 
  45. */ 
  46. global $post, $wc_dgallery_fonts_face; 
  47.  
  48. $global_stop_scroll_1image = get_option( WOO_DYNAMIC_GALLERY_PREFIX.'stop_scroll_1image' ); 
  49. $enable_scroll = 'true'; 
  50. $display_back_and_forward = 'true'; 
  51. $no_image_uri = WC_Dynamic_Gallery_Functions::get_no_image_uri(); 
  52.  
  53. $get_again = true; 
  54. if ( $product_id < 1 ) { 
  55. $product_id = $post->ID; 
  56. $get_again = false; 
  57.  
  58. // Get gallery of this product 
  59. $dgallery_ids = WC_Dynamic_Gallery_Functions::get_gallery_ids( $product_id ); 
  60. if ( ! is_array( $dgallery_ids ) ) { 
  61. $dgallery_ids = array(); 
  62.  
  63. $main_dgallery = array(); 
  64. $ogrinal_product_id = $product_id; 
  65. $product_id .= '_' . rand( 100, 10000 ); 
  66. $lightbox_class = 'lightbox'; 
  67. $thumbs_list_class = ''; 
  68. $max_height = 0; 
  69. $width_of_max_height = 0; 
  70.  
  71. // Process to get max height and width of max height for set gallery container 
  72. if ( count( $dgallery_ids ) > 0 ) { 
  73. $lightbox_class = 'lightbox'; 
  74.  
  75. // Assign image data into main gallery array 
  76. foreach ( $dgallery_ids as $img_id ) { 
  77. // Check if image id is existed on main gallery then just use it again for decrease query 
  78. if ( isset( $main_dgallery[$img_id] ) ) { 
  79. continue; 
  80.  
  81. $image_data = get_post( $img_id ); 
  82. $large_image_attribute = wp_get_attachment_image_src( $img_id, 'large' ); 
  83. $single_image_attribute = wp_get_attachment_image_src( $img_id, 'shop_single' ); 
  84. $thumb_image_attribute = wp_get_attachment_image_src( $img_id, 'shop_thumbnail' ); 
  85.  
  86. $alt = get_post_meta( $img_id, '_wp_attachment_image_alt', true ); 
  87. $single_srcset = ''; 
  88. $single_sizes = ''; 
  89. $thumb_srcset = ''; 
  90. $thumb_sizes = ''; 
  91.  
  92. if ( function_exists( 'wp_get_attachment_image_srcset' ) ) { 
  93. $single_srcset = wp_get_attachment_image_srcset( $img_id, 'shop_single' ); 
  94. $thumb_srcset = wp_get_attachment_image_srcset( $img_id, 'shop_thumbnail' ); 
  95. if ( function_exists( 'wp_get_attachment_image_sizes' ) ) { 
  96. $single_sizes = wp_get_attachment_image_sizes( $img_id, 'shop_single' ); 
  97. $thumb_sizes = wp_get_attachment_image_sizes( $img_id, 'shop_thumbnail' ); 
  98.  
  99. $main_dgallery[$img_id] = array ( 
  100. 'caption_text' => $image_data->post_excerpt,  
  101. 'alt_text' => $alt,  
  102. 'thumb' => array ( 
  103. 'url' => $thumb_image_attribute[0],  
  104. 'width' => $thumb_image_attribute[1],  
  105. 'height' => $thumb_image_attribute[2],  
  106. 'img_srcset' => $thumb_srcset,  
  107. 'img_sizes' => $thumb_sizes,  
  108. ),  
  109. 'single' => array ( 
  110. 'url' => $single_image_attribute[0],  
  111. 'width' => $single_image_attribute[1],  
  112. 'height' => $single_image_attribute[2],  
  113. 'img_srcset' => $single_srcset,  
  114. 'img_sizes' => $single_sizes,  
  115. ),  
  116. 'large' => array ( 
  117. 'url' => $large_image_attribute[0],  
  118. ),  
  119. ); 
  120.  
  121. $height_current = $single_image_attribute[2]; 
  122. if ( $height_current > $max_height ) { 
  123. $max_height = $height_current; 
  124. $width_of_max_height = $single_image_attribute[1]; 
  125. ?> 
  126.  
  127. <?php if ( ! $get_again ) { ?> 
  128. <div class="images gallery_container"> 
  129. <?php do_action('wc_dynamic_gallery_before_gallery'); ?> 
  130. <?php } ?> 
  131.  
  132. <div class="product_gallery"> 
  133. <?php 
  134. $woo_dg_width_type = get_option( WOO_DYNAMIC_GALLERY_PREFIX . 'width_type', '%' ); 
  135. $gallery_height_type = get_option( WOO_DYNAMIC_GALLERY_PREFIX . 'gallery_height_type', 'fixed' ); 
  136. if ( $woo_dg_width_type == 'px' ) { 
  137. $g_width = get_option( WOO_DYNAMIC_GALLERY_PREFIX.'product_gallery_width_fixed' ).'px'; 
  138. $g_height = get_option( WOO_DYNAMIC_GALLERY_PREFIX.'product_gallery_height' ); 
  139. } else { 
  140. $g_width = get_option( WOO_DYNAMIC_GALLERY_PREFIX.'product_gallery_width_responsive' ).'%'; 
  141.  
  142. // Set height for when gallery is responsive wide or dynamic height 
  143. if ( 'px' != $woo_dg_width_type || 'dynamic' == $gallery_height_type ) { 
  144. if ( $max_height > 0 ) { 
  145. $g_height = false; 
  146. ?> 
  147. <script type="text/javascript"> 
  148. (function($) { 
  149. $(function() { 
  150. a3revWCDynamicGallery_<?php echo $product_id; ?> = { 
  151.  
  152. setHeightProportional: function () { 
  153. var image_wrapper_width = parseInt( $( '#gallery_<?php echo $product_id; ?>' ).find('.a3dg-image-wrapper').outerWidth() ); 
  154. var width_of_max_height = parseInt(<?php echo $width_of_max_height; ?>); 
  155. var image_wrapper_height = parseInt(<?php echo $max_height; ?>); 
  156. if( width_of_max_height > image_wrapper_width ) { 
  157. var ratio = width_of_max_height / image_wrapper_width; 
  158. image_wrapper_height = parseInt(<?php echo $max_height; ?>) / ratio; 
  159. $( '#gallery_<?php echo $product_id; ?>' ).find('.a3dg-image-wrapper').css({ height: image_wrapper_height }); 
  160.  
  161. a3revWCDynamicGallery_<?php echo $product_id; ?>.setHeightProportional(); 
  162.  
  163. $( window ).resize(function() { 
  164. a3revWCDynamicGallery_<?php echo $product_id; ?>.setHeightProportional(); 
  165. }); 
  166. }); 
  167. })(jQuery); 
  168. </script> 
  169. <?php 
  170. } else { 
  171. $g_height = 138; 
  172.  
  173. $shop_thumbnail = wc_get_image_size( 'shop_thumbnail' ); 
  174. $g_thumb_width = $shop_thumbnail['width']; 
  175. $g_thumb_height = $shop_thumbnail['height']; 
  176. $thumb_show_type = get_option( WOO_DYNAMIC_GALLERY_PREFIX . 'thumb_show_type', 'slider' ); 
  177. $thumb_columns = get_option( WOO_DYNAMIC_GALLERY_PREFIX . 'thumb_columns', 3 ); 
  178. $thumb_spacing = get_option( WOO_DYNAMIC_GALLERY_PREFIX . 'thumb_spacing', 10 ); 
  179. if ( 'static' == $thumb_show_type ) { 
  180. $thumbs_list_class = 'a3dg-thumbs-static'; 
  181.  
  182. $g_auto = get_option( WOO_DYNAMIC_GALLERY_PREFIX.'product_gallery_auto_start' ); 
  183. $g_speed = get_option( WOO_DYNAMIC_GALLERY_PREFIX.'product_gallery_speed' ); 
  184. $g_effect = get_option( WOO_DYNAMIC_GALLERY_PREFIX.'product_gallery_effect' ); 
  185. $g_animation_speed = get_option( WOO_DYNAMIC_GALLERY_PREFIX.'product_gallery_animation_speed' ); 
  186. $product_gallery_nav = 'yes'; 
  187. $main_margin_left = get_option( WOO_DYNAMIC_GALLERY_PREFIX.'main_margin_left' ); 
  188. $main_margin_right = get_option( WOO_DYNAMIC_GALLERY_PREFIX.'main_margin_right' ); 
  189. $navbar_margin_left = get_option( WOO_DYNAMIC_GALLERY_PREFIX.'navbar_margin_left' ); 
  190. $navbar_margin_right = get_option( WOO_DYNAMIC_GALLERY_PREFIX.'navbar_margin_right' ); 
  191. $lazy_load_scroll = 'yes'; 
  192.  
  193. $default_enable_gallery_thumb = get_option( WOO_DYNAMIC_GALLERY_PREFIX.'enable_gallery_thumb', 'yes' ); 
  194. $enable_gallery_thumb = get_post_meta( $ogrinal_product_id, '_wc_dgallery_enable_gallery_thumb', true ); 
  195. if ( $enable_gallery_thumb == '' ) { 
  196. $enable_gallery_thumb = $default_enable_gallery_thumb; 
  197. if ( $enable_gallery_thumb == 1 || $enable_gallery_thumb == 'yes' ) { 
  198. $enable_gallery_thumb = 'yes'; 
  199. } else { 
  200. $enable_gallery_thumb = 'no'; 
  201.  
  202. $display_ctrl = ''; 
  203. if ( 'no' == $product_gallery_nav ) { 
  204. $display_ctrl = 'display:none !important;'; 
  205.  
  206. $popup_gallery = get_option( WOO_DYNAMIC_GALLERY_PREFIX.'popup_gallery' ); 
  207. $hide_thumb_1image = get_option( WOO_DYNAMIC_GALLERY_PREFIX.'hide_thumb_1image', 'yes' ); 
  208. $start_label = __('START SLIDESHOW', 'woo_dgallery'); 
  209. $stop_label = __('STOP SLIDESHOW', 'woo_dgallery'); 
  210.  
  211. if ( 'yes' == $global_stop_scroll_1image && count( $dgallery_ids ) <= 1 ) { 
  212. $enable_scroll = 'false'; 
  213. $display_back_and_forward = 'false'; 
  214. $start_label = ''; 
  215. $stop_label = ''; 
  216.  
  217. if ( 'static' == $thumb_show_type ) { 
  218. $display_back_and_forward = 'false'; 
  219.  
  220. $zoom_label = __('ZOOM +', 'woo_dgallery'); 
  221. if ( 'deactivate' == $popup_gallery ) { 
  222. $zoom_label = ''; 
  223. $lightbox_class = 'lightbox'; 
  224.  
  225. if ( '' == $lightbox_class && 'false' == $enable_scroll ) { 
  226. $display_ctrl = 'display:none !important;'; 
  227.  
  228. $_upload_dir = wp_upload_dir(); 
  229. global $wc_wc_dynamic_gallery_less; 
  230. if ( file_exists( $_upload_dir['basedir'] . '/sass/woo_dynamic_gallery.min.css' ) ) { 
  231. echo '<link media="all" type="text/css" href="' . str_replace(array('http:', 'https:'), '', $_upload_dir['baseurl'] ) . '/sass/woo_dynamic_gallery.min.css?ver='.$wc_wc_dynamic_gallery_less->get_css_file_version().'" rel="stylesheet" />' . "\n"; 
  232. } else { 
  233. include( WOO_DYNAMIC_GALLERY_DIR . '/templates/customized_style.php' ); 
  234.  
  235. echo '<style> 
  236. .product.has-default-attributes.has-children > .images { 
  237. opacity: 1 !important; 
  238. .a3-dgallery .a3dg-image-wrapper { 
  239. '. ( ( $g_height != false ) ? 'height: '. $g_height.'px;' : '' ) .' 
  240. .product_gallery #gallery_'.$product_id.' .a3dg-navbar-control { 
  241. '.$display_ctrl.'; 
  242. width: calc( 100% - '.( $navbar_margin_left + $navbar_margin_right ).'px ); 
  243. }'; 
  244.  
  245. if ( 'no' == $lazy_load_scroll ) { 
  246. echo '.a3-dgallery .lazy-load { 
  247. display: none !important; 
  248. }'; 
  249.  
  250. if ( 'yes' == $hide_thumb_1image && count( $dgallery_ids ) <= 1 ) { 
  251. echo '#gallery_'.$product_id.' .a3dg-nav { 
  252. display:none; 
  253. .woocommerce #gallery_'.$product_id.' .images { 
  254. margin-bottom: 15px; 
  255. }'; 
  256.  
  257. if ( 'yes' == $global_stop_scroll_1image && count( $dgallery_ids ) <= 1 ) { 
  258. echo '#gallery_'.$product_id.' .a3dg-navbar-control { 
  259. width: calc( 50% - '.( ( $navbar_margin_left + $navbar_margin_right ) / 2 ).'px ) !important; 
  260. #gallery_'.$product_id.' .a3dg-navbar-control .icon_zoom { 
  261. width: 100%; 
  262. #gallery_'.$product_id.' .a3dg-navbar-separator,  
  263. #gallery_'.$product_id.' .slide-ctrl { 
  264. display: none !important; 
  265. }'; 
  266. if ( 'deactivate' == $popup_gallery ) { 
  267. echo '.a3-dgallery .a3dg-image-wrapper .a3dg-image img { 
  268. cursor: default; 
  269. #gallery_'.$product_id.' .a3dg-navbar-control { 
  270. width: calc( 50% - '.( ( $navbar_margin_left + $navbar_margin_right ) / 2 ).'px ) !important; 
  271. float: right; 
  272. #gallery_'.$product_id.' .a3dg-navbar-control .slide-ctrl { 
  273. width: 100%; 
  274. #gallery_'.$product_id.' .a3dg-navbar-separator,  
  275. #gallery_'.$product_id.' .icon_zoom { 
  276. display: none; 
  277. }'; 
  278.  
  279. if ( 'no' == $enable_gallery_thumb ) { 
  280. echo '.a3dg-nav { 
  281. display:none; 
  282. height:1px; 
  283. .woocommerce .images { 
  284. margin-bottom: 15px; 
  285. }'; 
  286.  
  287. echo ' 
  288. </style>'; 
  289.  
  290. echo '<script type ="text/javascript"> 
  291. jQuery(function() { 
  292. var settings_defaults_'.$product_id.' = { loader_image: "'.WOO_DYNAMIC_GALLERY_JS_URL.'/mygallery/loader.gif",  
  293. start_at_index: 0,  
  294. gallery_ID: "'.$product_id.'",  
  295. lightbox_class: "'.$lightbox_class.'",  
  296. description_wrapper: false,  
  297. thumb_opacity: 0.5,  
  298. animate_first_image: false,  
  299. animation_speed: '.$g_animation_speed.'000,  
  300. width: false,  
  301. height: false,  
  302. display_next_and_prev: '.$enable_scroll.',  
  303. display_back_and_forward: '.$display_back_and_forward.',  
  304. scroll_jump: 0,  
  305. slideshow: { 
  306. enable: '.$enable_scroll.',  
  307. autostart: '.$g_auto.',  
  308. speed: '.$g_speed.'000,  
  309. start_label: "'.$start_label.'",  
  310. stop_label: "'.$stop_label.'",  
  311. zoom_label: "'.$zoom_label.'",  
  312. stop_on_scroll: true,  
  313. countdown_prefix: "(",  
  314. countdown_sufix: ")",  
  315. onStart: false,  
  316. onStop: false 
  317. },  
  318. effect: "'.$g_effect.'",  
  319. enable_keyboard_move: true,  
  320. cycle: true,  
  321. callbacks: { 
  322. init: false,  
  323. afterImageVisible: false,  
  324. beforeImageVisible: false 
  325. }; 
  326. jQuery("#gallery_'.$product_id.'").adGallery(settings_defaults_'.$product_id.'); 
  327. }); 
  328.  
  329. </script>'; 
  330.  
  331. echo '<img style="width: 0px ! important; height: 0px ! important; display: none ! important; position: absolute;" src="'.WOO_DYNAMIC_GALLERY_IMAGES_URL . '/blank.gif">'; 
  332.  
  333. echo '<div id="gallery_'.$product_id.'" 
  334. class="a3-dgallery" 
  335. data-height_type="'. esc_attr( $gallery_height_type ).'" 
  336. data-show_navbar_control="'. esc_attr( $product_gallery_nav ) .'" 
  337. data-show_thumb="'. esc_attr( $enable_gallery_thumb ) .'" 
  338. data-hide_one_thumb="'. esc_attr( $hide_thumb_1image ) .'" 
  339. data-thumb_show_type="'. esc_attr( $thumb_show_type ) .'" 
  340. data-thumb_visible="'. esc_attr( $thumb_columns ) .'" 
  341. data-thumb_spacing="'. esc_attr( $thumb_spacing ) .'" 
  342. style="width: 100%; 
  343. max-width: '.$g_width.';" 
  344. <div class="a3dg-image-wrapper" style="width: calc(100% - '.( (int) $main_margin_left + (int) $main_margin_right ).'px); ' . ( ( $g_height != false ) ? 'height: '.$g_height.'px;' : '' ) . '"></div> 
  345. <div class="lazy-load"></div> 
  346. <div style="clear: both"></div> 
  347. <div class="a3dg-navbar-control"><div class="a3dg-navbar-separator"></div></div> 
  348. <div style="clear: both"></div> 
  349. <div class="a3dg-nav"> 
  350. <div class="fa fa-angle-left a3dg-back"></div> 
  351. <div class="fa fa-angle-right a3dg-forward"></div> 
  352. <div class="a3dg-thumbs '.$thumbs_list_class.'"> 
  353. <ul class="a3dg-thumb-list">'; 
  354.  
  355. $script_colorbox = ''; 
  356. $script_fancybox = ''; 
  357. if ( count( $dgallery_ids ) > 0 ) { 
  358.  
  359. $current_color_text = __('image {current} of {total}', 'woo_dgallery'); 
  360. $current_color_text = ''; 
  361.  
  362. $script_colorbox .= '<script type="text/javascript">'; 
  363. $script_fancybox .= '<script type="text/javascript">'; 
  364. $script_colorbox .= '(function($) {'; 
  365. $script_fancybox .= '(function($) {'; 
  366. $script_colorbox .= '$(function() {'; 
  367. $script_fancybox .= '$(function() {'; 
  368. $script_colorbox .= '$(document).on("click", ".a3-dgallery .lightbox", function(ev) { if( $(this).attr("rel") == "gallery_'.$product_id.'") { 
  369. var idx = $("#gallery_'.$product_id.' .a3dg-image img").attr("idx");'; 
  370. $script_fancybox .= '$(document).on("click", ".a3-dgallery .lightbox", function(ev) { if( $(this).attr("rel") == "gallery_'.$product_id.'") { 
  371. var idx = $("#gallery_'.$product_id.' .a3dg-image img").attr("idx");'; 
  372.  
  373. if ( count( $dgallery_ids ) <= 1 ) { 
  374. $script_colorbox .= '$(".gallery_product_'.$product_id.'").colorbox({ current:"'.$current_color_text.'", open:true, maxWidth:"100%" });'; 
  375. $script_fancybox .= '$.fancybox('; 
  376. } else { 
  377. $script_colorbox .= '$(".gallery_product_'.$product_id.'").colorbox({ current:"'.$current_color_text.'", rel:"gallery_product_'.$product_id.'", maxWidth:"100%" }); $(".gallery_product_'.$product_id.'_"+idx).colorbox({ current:"'.$current_color_text.'", open:true, maxWidth:"100%" });'; 
  378. $script_fancybox .= '$.fancybox(['; 
  379.  
  380. $common = ''; 
  381. $idx = 0; 
  382.  
  383. foreach ( $dgallery_ids as $img_id ) { 
  384. if ( ! isset( $main_dgallery[$img_id] ) ) { 
  385. continue; 
  386.  
  387. // Get image data from main gallery array 
  388. $gallery_item = $main_dgallery[$img_id]; 
  389.  
  390. $li_class = ''; 
  391. if ( 'static' == $thumb_show_type ) { 
  392. if ( $idx % $thumb_columns == 0 ) { 
  393. $li_class = 'first_item'; 
  394. } elseif ( ( $idx % $thumb_columns + 1 ) == $thumb_columns ) { 
  395. $li_class = 'last_item'; 
  396. } else { 
  397. if ( $idx == 0 ) { 
  398. $li_class = 'first_item'; 
  399. } elseif ( $idx == count( $dgallery_ids ) - 1 ) { 
  400. $li_class = 'last_item'; 
  401.  
  402. $image_large_url = $gallery_item['large']['url']; 
  403. $image_single_url = $gallery_item['single']['url']; 
  404. $image_thumb_url = $gallery_item['thumb']['url']; 
  405.  
  406. $thumb_height = $g_thumb_height; 
  407. $thumb_width = $g_thumb_width; 
  408. $width_old = $gallery_item['thumb']['width']; 
  409. $height_old = $gallery_item['thumb']['height']; 
  410.  
  411. if ( $width_old > $g_thumb_width || $height_old > $g_thumb_height ) { 
  412. if ( $height_old > $g_thumb_height && $g_thumb_height > 0 ) { 
  413. $factor = ($height_old / $g_thumb_height); 
  414. $thumb_height = $g_thumb_height; 
  415. $thumb_width = $width_old / $factor; 
  416. if ( $thumb_width > $g_thumb_width && $g_thumb_width > 0 ) { 
  417. $factor = ($width_old / $g_thumb_width); 
  418. $thumb_height = $height_old / $factor; 
  419. $thumb_width = $g_thumb_width; 
  420. } elseif ( $thumb_width == $g_thumb_width && $width_old > $g_thumb_width && $g_thumb_width > 0 ) { 
  421. $factor = ($width_old / $g_thumb_width); 
  422. $thumb_height = $height_old / $factor; 
  423. $thumb_width = $g_thumb_width; 
  424. } else { 
  425. $thumb_height = $height_old; 
  426. $thumb_width = $width_old; 
  427.  
  428. echo '<li class="'.$li_class.'">'; 
  429. echo '<a alt="'. esc_attr( $gallery_item['alt_text'] ).'" class="gallery_product_'.$product_id.' gallery_product_'.$product_id.'_'.$idx.'" title="'. esc_attr( $gallery_item['caption_text'] ).'" rel="gallery_product_'.$product_id.'" href="'.$image_single_url.'">'; 
  430. echo '<img 
  431. org-width="'. esc_attr( $gallery_item['single']['width'] ).'" 
  432. org-height="'. esc_attr( $gallery_item['single']['height'] ).'" 
  433. org-sizes="'. esc_attr( $gallery_item['single']['img_sizes'] ).'" 
  434. org-srcset="'. esc_attr( $gallery_item['single']['img_srcset'] ).'" 
  435. sizes="'. esc_attr( $gallery_item['thumb']['img_sizes'] ) .'" 
  436. srcset="'. esc_attr( $gallery_item['thumb']['img_srcset'] ).'" 
  437. idx="'.$idx.'" 
  438. src="'.$image_thumb_url.'" 
  439. alt="'. esc_attr( $gallery_item['alt_text'] ).'" 
  440. data-caption="'. esc_attr( $gallery_item['caption_text'] ).'" 
  441. class="image'.$idx.'" 
  442. width="'.$thumb_width.'" 
  443. height="'.$thumb_height.'">'; 
  444. echo '</a>'; 
  445. echo '</li>'; 
  446.  
  447. if ( '' != trim( $gallery_item['caption_text'] ) ) { 
  448. $script_fancybox .= $common.'{href:"'.$image_large_url.'", title:"'.esc_js( $gallery_item['caption_text'] ).'"}'; 
  449. } else { 
  450. $script_fancybox .= $common.'{href:"'.$image_large_url.'", title:""}'; 
  451. $common = ', '; 
  452. $idx++; 
  453.  
  454. if ( count( $dgallery_ids ) <= 1 ) { 
  455. $script_fancybox .= ');'; 
  456. } else { 
  457. $script_fancybox .= '], { 
  458. \'index\': idx 
  459. });'; 
  460. $script_colorbox .= 'ev.preventDefault();'; 
  461. $script_colorbox .= '} });'; 
  462. $script_fancybox .= '} });'; 
  463. $script_colorbox .= '});'; 
  464. $script_fancybox .= '});'; 
  465. $script_colorbox .= '})(jQuery);'; 
  466. $script_fancybox .= '})(jQuery);'; 
  467. $script_colorbox .= '</script>'; 
  468. $script_fancybox .= '</script>'; 
  469.  
  470. } else { 
  471. echo '<li>'; 
  472. echo '<a class="" rel="gallery_product_'.$product_id.'" href="'.$no_image_uri.'">'; 
  473. echo '<img org-width="" org-height="" sizes="" srcset="" src="'.$no_image_uri.'" class="image" alt="">'; 
  474. echo '</a>'; 
  475. echo '</li>'; 
  476.  
  477. if ( 'deactivate' == $popup_gallery ) { 
  478. $script_colorbox = ''; 
  479. $script_fancybox = ''; 
  480. } elseif( 'colorbox' == $popup_gallery ) { 
  481. echo $script_colorbox; 
  482. } else { 
  483. echo $script_fancybox; 
  484.  
  485. echo '</ul> 
  486.  
  487. </div> 
  488. </div> 
  489. </div>'; 
  490. ?> 
  491. </div> 
  492.  
  493. <?php if ( ! $get_again ) { ?> 
  494. <?php do_action('wc_dynamic_gallery_after_gallery'); ?> 
  495. </div> 
  496. <?php } ?> 
  497.  
  498. <?php