queue as $handle) { $style = isset($styles->registered[$handle]) ? $styles->registered[$handle] : null; if (!$style || !is_string($style->src) || $style->src === '') { continue; } if (!$styles->get_data($handle, 'path')) { continue; } $min = self::rewrite($style->src); if ($min === $style->src) { continue; } $path_part = (string) wp_parse_url($min, PHP_URL_PATH); $pos = strpos($path_part, '/plugins/'); if ($pos === false) { continue; } $abs = WP_PLUGIN_DIR . substr($path_part, $pos + strlen('/plugins')); if (!is_file($abs)) { continue; } $styles->add_data($handle, 'path', wp_normalize_path($abs)); } } public static function module_src($abs, $url) { if (defined('SCRIPT_DEBUG') && SCRIPT_DEBUG) { return $url; } $min_abs = preg_replace('/\.js$/', '.min.js', (string) $abs); if ($min_abs === $abs || !is_file($min_abs) || !is_file($abs) || filemtime($min_abs) < filemtime($abs)) { return $url; } return preg_replace('/\.js(?=[?#]|$)/', '.min.js', (string) $url, 1); } private static $deferred_modules = array(); public static function defer_module($id, $url, $ver = '') { if (defined('AIEO_ENGINE_DIR')) { wp_enqueue_script_module((string) $id); return; } if (empty(self::$deferred_modules)) { add_action('wp_print_footer_scripts', array(__CLASS__, 'print_deferred_modules'), 30); } self::$deferred_modules[(string) $id] = '' !== (string) $ver ? add_query_arg('ver', (string) $ver, (string) $url) : (string) $url; } public static function print_deferred_modules() { if (empty(self::$deferred_modules)) { return; } $urls = array_values(array_map('esc_url_raw', self::$deferred_modules)); self::$deferred_modules = array(); $js = '(function(){var m=' . wp_json_encode($urls) . ',d=false;function go(){if(d){return;}d=true;m.forEach(function(u){try{import(u).catch(function(){});}catch(e){}});}' . "['pointerdown','keydown','touchstart','wheel','scroll'].forEach(function(e){addEventListener(e,go,{once:true,passive:true});});" . "addEventListener('rooster:human',go,{once:true});})();"; echo '' . "\n"; } public static function rewrite($src) { if (!is_string($src) || $src === '') { return $src; } if (strpos($src, '/ai-eshop-optimizer/') === false && strpos($src, '/ai-eshop-optimizer-runtime/') === false && strpos($src, '/ai-eshop-optimizer-pro/') === false) { return $src; } if (preg_match('#\.min\.(?:css|js)(?:[?\#]|$)#', $src)) { return $src; } if (!preg_match('#\.(css|js)(?:([?\#]).*)?$#', $src)) { return $src; } $min = preg_replace('#\.(css|js)(?=[?\#]|$)#', '.min.$1', $src, 1); $path_part = (string) wp_parse_url($min, PHP_URL_PATH); $marker = '/plugins/'; $pos = strpos($path_part, $marker); if ($pos === false) { return $src; } $abs = WP_PLUGIN_DIR . substr($path_part, $pos + strlen('/plugins')); if (!file_exists($abs)) { return $src; } $src_path = preg_replace('#\.min\.(css|js)$#', '.$1', $abs); if ($src_path !== $abs && file_exists($src_path) && filemtime($src_path) > filemtime($abs)) { return $src; } return $min; } } }