8) { $n = 8; }
$mode = isset($s['thumbs_height_mode']) ? (string) $s['thumbs_height_mode'] : 'count';
if (!in_array($mode, array('count', 'fill'), true)) { $mode = 'count'; }
$lb = array(
'lb_thumbnails' => true,
'lb_thumb_size' => 96,
'lb_thumb_radius' => 0,
'lb_thumb_equal' => false,
'lb_thumb_border' => false,
'lb_thumb_border_colour' => '#ffffff',
'lb_dots' => true,
'lb_counter' => true,
'lb_share' => false,
'lb_arrow_style' => 'square',
'lb_arrow_colour' => '#333333',
'lb_backdrop_style' => 'dark',
'lb_backdrop_opacity' => 0.95,
'lb_autoplay' => false,
'lb_autoplay_delay' => 4000,
'lb_autoplay_pause_on_hover'=> true,
'lb_loop' => true,
'lb_close_on_scroll' => false,
);
foreach ($lb as $k => $v) {
if (isset($s[$k])) { $lb[$k] = is_bool($v) ? (bool) $s[$k] : $s[$k]; }
}
$lb['lb_thumb_size'] = max(48, min(200, (int) $lb['lb_thumb_size']));
$lb['lb_thumb_radius'] = max(0, min(24, (int) $lb['lb_thumb_radius']));
$lb['lb_autoplay_delay'] = max(1000, min(20000, (int) $lb['lb_autoplay_delay']));
$lb['lb_backdrop_opacity'] = max(0, min(1, (float) $lb['lb_backdrop_opacity']));
if (!in_array($lb['lb_arrow_style'], array('square', 'round', 'minimal', 'long', 'chevron'), true)) { $lb['lb_arrow_style'] = 'square'; }
if (!in_array($lb['lb_backdrop_style'], array('dark', 'light', 'glass'), true)) { $lb['lb_backdrop_style'] = 'dark'; }
$c = is_string($lb['lb_arrow_colour']) ? $lb['lb_arrow_colour'] : '';
$lb['lb_arrow_colour'] = preg_match('/^#[0-9a-fA-F]{3,8}$/', $c) ? $c : '#333333';
$c = is_string($lb['lb_thumb_border_colour']) ? $lb['lb_thumb_border_colour'] : '';
$lb['lb_thumb_border_colour'] = preg_match('/^#[0-9a-fA-F]{3,8}$/', $c) ? $c : '#ffffff';
$ao = array(
'ao_mode' => 'disabled',
'ao_slide' => 0,
'ao_mobile' => true,
'ao_breakpoint' => 768,
'ao_listing_patterns' => "/product-category/\n/shop\n?s=",
);
foreach ($ao as $k => $v) {
if (isset($s[$k])) { $ao[$k] = is_bool($v) ? (bool) $s[$k] : $s[$k]; }
}
if (!in_array($ao['ao_mode'], array('disabled', 'always', 'listing', 'internal'), true)) { $ao['ao_mode'] = 'disabled'; }
$ao['ao_slide'] = max(0, min(50, (int) $ao['ao_slide']));
$ao['ao_breakpoint'] = max(0, min(4000, (int) $ao['ao_breakpoint']));
$ao['ao_listing_patterns'] = is_string($ao['ao_listing_patterns']) ? $ao['ao_listing_patterns'] : '';
$pos = isset($s['thumbs_position']) ? (string) $s['thumbs_position'] : 'left';
$arrows = isset($s['arrow_style']) ? (string) $s['arrow_style'] : 'long';
if (self::theme_sets_gallery()) {
$pos = (string) ( function_exists( 'rooster_setting' ) ? 'rooster_setting' : 'roosterx_setting' )('design', 'gallery_thumbs', 'right');
$arrows = (string) ( function_exists( 'rooster_setting' ) ? 'rooster_setting' : 'roosterx_setting' )('design', 'gallery_arrows', 'long');
$lb['lb_arrow_style'] = in_array($arrows, array('long', 'chevron'), true) ? $arrows : 'long';
}
if (!in_array($pos, array('left', 'right', 'bottom', 'top'), true)) { $pos = 'left'; }
if (!in_array($arrows, array('long', 'chevron'), true)) { $arrows = 'long'; }
return array_merge(array(
'visible_thumbs' => $n,
'thumbs_height_mode' => $mode,
'thumbs_position' => $pos,
'arrow_style' => $arrows,
), $lb, $ao);
}
public static function theme_sets_gallery() {
return ( function_exists( 'rooster_setting' ) || function_exists( 'roosterx_setting' ) ) && ( function_exists( 'rooster_icon' ) || function_exists( 'roosterx_icon' ) );
}
public static function icon($slug) {
$slug = (string) $slug;
if (( function_exists( 'rooster_icon' ) || function_exists( 'roosterx_icon' ) )) {
$svg = (string) ( function_exists( 'rooster_icon' ) ? 'rooster_icon' : 'roosterx_icon' )($slug);
if ('' !== $svg) { return $svg; }
}
$paths = array(
'move-left' => '',
'move-right' => '',
'move-up' => '',
'move-down' => '',
'chevron-left' => '',
'chevron-right' => '',
'chevron-up' => '',
'chevron-down' => '',
'x' => '',
);
if (!isset($paths[$slug])) { return ''; }
return '';
}
public static function arrow_icons($style) {
$p = ('chevron' === $style) ? 'chevron-' : 'move-';
return array(
'prev' => self::icon($p . 'left'),
'next' => self::icon($p . 'right'),
'up' => self::icon($p . 'up'),
'down' => self::icon($p . 'down'),
'x' => self::icon('x'),
);
}
public static function gallery_classes($classes) {
if (!self::renders_gallery()) { return $classes; }
$s = self::settings();
$classes = is_array($classes) ? $classes : (array) $classes;
$classes[] = 'aieo-gl-thumbs-' . $s['thumbs_position'];
$classes[] = 'aieo-gl-arrows-' . $s['arrow_style'];
return $classes;
}
public static function carousel_options($options) {
if (!self::renders_gallery()) { return $options; }
$options = is_array($options) ? $options : array();
$icons = self::arrow_icons(self::settings()['arrow_style']);
$options['directionNav'] = true;
$options['prevText'] = $icons['prev'];
$options['nextText'] = $icons['next'];
return $options;
}
private static function asset($rel) {
$path = dirname(__DIR__) . '/' . $rel;
$ver = file_exists($path) ? filemtime($path) : '1.0';
return array(plugins_url($rel, __DIR__), $ver);
}
public static function enqueue_gallery() {
if (!function_exists('is_product') || !is_product()) { return; }
if (!self::renders_gallery()) { return; }
list($url, $ver) = self::asset('assets/css/aieo-pdp-gallery.css');
wp_enqueue_style('aieo-pdp-gallery', $url, array(), $ver);
$gs = self::settings();
if ('fill' === $gs['thumbs_height_mode']) {
wp_add_inline_style('aieo-pdp-gallery',
'@media (min-width:768px){'
. '.single-product .woocommerce-product-gallery .flex-control-thumbs{max-height:100%}'
. '.single-product .woocommerce-product-gallery .aieo-gallery-thumbs-strip{justify-content:space-between}'
. '.single-product .woocommerce-product-gallery .aieo-gallery-thumbs-strip .flex-control-thumbs{max-height:none;flex:1 1 auto}'
. '}'
);
} elseif (3 !== (int) $gs['visible_thumbs']) {
$n = (int) $gs['visible_thumbs'];
$cap = ($n * 104) + (($n - 1) * 8);
wp_add_inline_style('aieo-pdp-gallery',
'@media (min-width:768px){'
. '.single-product .woocommerce-product-gallery .flex-control-thumbs,'
. '.single-product .woocommerce-product-gallery .aieo-gallery-thumbs-strip .flex-control-thumbs{max-height:' . $cap . 'px}'
. '}'
);
}
if (in_array($gs['thumbs_position'], array('bottom', 'top'), true)) {
$n = (int) $gs['visible_thumbs'];
$cap = ('fill' === $gs['thumbs_height_mode']) ? 'none' : (($n * 104) + (($n - 1) * 8)) . 'px';
wp_add_inline_style('aieo-pdp-gallery',
'@media (min-width:768px){'
. '.single-product .woocommerce-product-gallery.aieo-gl-thumbs-' . $gs['thumbs_position'] . ' .flex-control-thumbs{max-width:' . $cap . ';max-height:none}'
. '}'
);
}
list($jsurl, $jsver) = self::asset('assets/js/aieo-pdp-gallery.js');
wp_enqueue_script('aieo-pdp-gallery', $jsurl, array('jquery'), $jsver, array('in_footer' => true, 'strategy' => 'defer'));
wp_add_inline_script('aieo-pdp-gallery', 'window.aieoPdpGallery=' . wp_json_encode(array(
'position' => (string) $gs['thumbs_position'],
'arrows' => (string) $gs['arrow_style'],
'icons' => self::arrow_icons($gs['arrow_style']),
)) . ';', 'before');
add_filter('rocket_delay_js_exclusions', array(__CLASS__, 'gallery_rocket_exclusions'));
add_filter('rocket_exclude_defer_js', array(__CLASS__, 'gallery_rocket_exclusions'));
add_filter('rocket_rucss_safelist', array(__CLASS__, 'gallery_rucss_safelist'));
}
public static function gallery_rocket_exclusions($excluded) {
if (!is_array($excluded)) { $excluded = array(); }
$excluded[] = 'aieo-pdp-gallery';
return $excluded;
}
public static function gallery_rucss_safelist($safelist) {
if (!is_array($safelist)) { $safelist = array(); }
$safelist[] = '.aieo-gallery-thumbs-strip';
$safelist[] = '.aieo-gallery-arrow';
$safelist[] = '.flex-direction-nav';
$safelist[] = '.aieo-gl-thumbs-left';
$safelist[] = '.aieo-gl-thumbs-right';
$safelist[] = '.aieo-gl-thumbs-bottom';
$safelist[] = '.aieo-gl-thumbs-top';
$safelist[] = '.flex-control-thumbs';
$safelist[] = '.elastislide-wrapper';
$safelist[] = '.elastislide-carousel';
return $safelist;
}
public static function gallery_sizes_attr() {
return (string) apply_filters('aieo_pdp_gallery_image_sizes', '(max-width: 991px) 100vw, 48vw');
}
public static function gallery_image_sizes($params, $attachment_id = 0, $image_size = '', $main_image = false) {
if (is_array($params) && function_exists('is_product') && is_product() && self::renders_gallery()) {
$params['sizes'] = self::gallery_sizes_attr();
self::record_gallery_renders_here();
}
return $params;
}
private static function record_gallery_renders_here() {
static $checked = false;
if ($checked) { return; }
$checked = true;
if (get_option(self::GALLERY_RENDERS_OPTION) !== 'yes') {
update_option(self::GALLERY_RENDERS_OPTION, 'yes', true);
}
}
public static function photoswipe_options($o) {
if (!self::owns_lightbox() || !function_exists('is_product') || !is_product()) { return $o; }
if (!is_array($o)) { $o = array(); }
$s = self::settings();
$o = array_merge($o, array(
'shareEl' => (bool) $s['lb_share'],
'counterEl' => (bool) $s['lb_counter'],
'bgOpacity' => round((float) $s['lb_backdrop_opacity'], 2),
'loop' => (bool) $s['lb_loop'],
'closeOnScroll' => (bool) $s['lb_close_on_scroll'],
'history' => false,
));
$bottom = 0;
if ($s['lb_thumbnails']) { $bottom += (int) $s['lb_thumb_size'] + 20; }
if ($s['lb_dots']) { $bottom += 26; }
if ($bottom > 0) {
$o['barsSize'] = array('top' => 44, 'bottom' => $bottom + 8);
}
return $o;
}
public static function enqueue_lightbox() {
if (!function_exists('is_product') || !is_product()) { return; }
if (!self::owns_lightbox()) { return; }
if (!current_theme_supports('wc-product-gallery-lightbox')) { return; }
$s = self::settings();
list($url, $ver) = self::asset('assets/css/aieo-lightbox.css');
wp_enqueue_style('aieo-lightbox', $url, array(), $ver);
wp_add_inline_style('aieo-lightbox',
':root{--aieo-lb-accent:' . $s['lb_arrow_colour']
. ';--aieo-lb-thumb:' . (int) $s['lb_thumb_size'] . 'px'
. ';--aieo-lb-thumb-radius:' . (int) $s['lb_thumb_radius'] . 'px'
. ';--aieo-lb-thumb-border:' . ($s['lb_thumb_border'] ? $s['lb_thumb_border_colour'] : 'transparent') . '}');
list($jsurl, $jsver) = self::asset('assets/js/aieo-lightbox.js');
wp_enqueue_script('aieo-lightbox', $jsurl, array(), $jsver, array('in_footer' => true, 'strategy' => 'defer'));
wp_add_inline_script('aieo-lightbox', 'window.aieoLightbox=' . wp_json_encode(array(
'thumbnails' => (bool) $s['lb_thumbnails'],
'dots' => (bool) $s['lb_dots'],
'autoplay' => (bool) $s['lb_autoplay'],
'autoplayDelay' => (int) $s['lb_autoplay_delay'],
'pauseOnHover' => (bool) $s['lb_autoplay_pause_on_hover'],
'arrowStyle' => (string) $s['lb_arrow_style'],
'backdrop' => (string) $s['lb_backdrop_style'],
'thumbEqual' => (bool) $s['lb_thumb_equal'],
'icons' => in_array((string) $s['lb_arrow_style'], array('long', 'chevron'), true) ? self::arrow_icons($s['lb_arrow_style']) : null,
)) . ';', 'before');
add_filter('rocket_delay_js_exclusions', array(__CLASS__, 'lightbox_rocket_exclusions'));
add_filter('rocket_exclude_defer_js', array(__CLASS__, 'lightbox_rocket_exclusions'));
add_filter('rocket_rucss_safelist', array(__CLASS__, 'lightbox_rucss_safelist'));
}
public static function lightbox_rocket_exclusions($excluded) {
if (!is_array($excluded)) { $excluded = array(); }
$excluded[] = 'aieo-lightbox';
$excluded[] = 'aieoLightbox';
return $excluded;
}
public static function lightbox_rucss_safelist($safelist) {
if (!is_array($safelist)) { $safelist = array(); }
$safelist[] = '.aieo-lb-arrows-long';
$safelist[] = '.aieo-lb-arrows-chevron';
$safelist[] = '.aieo-lb-x';
$safelist[] = '.aieo-lb-bottom';
$safelist[] = '.aieo-lb-dots';
$safelist[] = '.aieo-lb-dot';
$safelist[] = '.aieo-lb-strip';
$safelist[] = '.aieo-lb-thumb';
$safelist[] = '.aieo-lb-has-strip';
return $safelist;
}
public static function enqueue_autoopen() {
if (!function_exists('is_product') || !is_product()) { return; }
$s = self::settings();
if ('disabled' === $s['ao_mode']) { return; }
list($url, $ver) = self::asset('assets/js/aieo-lb-autoopen.js');
wp_enqueue_script('aieo-lb-autoopen', $url, array(), $ver, array('in_footer' => true, 'strategy' => 'defer'));
wp_add_inline_script('aieo-lb-autoopen', 'window.aieoLbAutoOpen=' . wp_json_encode(array(
'mode' => (string) $s['ao_mode'],
'slide' => (int) $s['ao_slide'],
'mobile' => (bool) $s['ao_mobile'],
'bp' => (int) $s['ao_breakpoint'],
'listings' => array_values(array_filter(preg_split('/\R/', (string) $s['ao_listing_patterns']))),
)) . ';', 'before');
add_filter('rocket_delay_js_exclusions', array(__CLASS__, 'autoopen_rocket_exclusions'));
add_filter('rocket_exclude_defer_js', array(__CLASS__, 'autoopen_rocket_exclusions'));
}
public static function autoopen_rocket_exclusions($excluded) {
if (!is_array($excluded)) { $excluded = array(); }
$excluded[] = 'aieo-lb-autoopen';
$excluded[] = 'aieoLbAutoOpen';
return $excluded;
}
}