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