/** * Used to check if we have to LazyLoad this or not * * @since 2.5.5 Don't apply LazyLoad on images from WP Retina x2 * @since 2.5 Don't apply LazyLoad on all images from LayerSlider * @since 2.4.2 Don't apply LazyLoad on all images from Media Grid * @since 2.3.11 Don't apply LazyLoad on all images from Timthumb * @since 2.3.10 Don't apply LazyLoad on all images from Revolution Slider & Justified Image Grid * @since 2.3.8 Don't apply LazyLoad on captcha from Really Simple CAPTCHA * @since 2.2 */ function __rocket_lazyload_replace_callback($matches) { // Don't apply LazyLoad on images from WP Retina x2 if (function_exists('wr2x_picture_rewrite')) { if (wr2x_get_retina(trailingslashit(ABSPATH) . wr2x_get_pathinfo_from_image_src(trim($matches[2], '"')))) { return $matches[0]; } } // TO DO - improve this code with a preg_match - it's ugly!!!! if (strpos($matches[1] . $matches[3], 'data-no-lazy=') === false && strpos($matches[1] . $matches[3], 'data-lazy-original=') === false && strpos($matches[1] . $matches[3], 'data-lazy-src=') === false && strpos($matches[1] . $matches[3], 'data-lazysrc=') === false && strpos($matches[1] . $matches[3], 'data-src=') === false && strpos($matches[1] . $matches[3], 'data-lazyload=') === false && strpos($matches[1] . $matches[3], 'data-bgposition=') === false && strpos($matches[2], '/wpcf7_captcha/') === false && strpos($matches[2], 'timthumb.php?src') === false && strpos($matches[1] . $matches[3], 'data-envira-src=') === false && strpos($matches[1] . $matches[3], 'fullurl=') === false && strpos($matches[1] . $matches[3], 'lazy-slider-img=') === false && strpos($matches[1] . $matches[3], 'srcset=') === false) { /** * Filter the LazyLoad placeholder on src attribute * * @since 2.6 * * @param string Output that will be printed */ $placeholder = apply_filters('rocket_lazyload_placeholder', 'data:image/gif;base64,R0lGODdhAQABAPAAAP///wAAACwAAAAAAQABAEACAkQBADs='); $html = sprintf('<img%1$s src="%4$s" data-lazy-src=%2$s%3$s><noscript><img%1$s src=%2$s%3$s></noscript>', $matches[1], $matches[2], $matches[3], $placeholder); /** * Filter the LazyLoad HTML output on images * * @since 2.3.8 * * @param string $html Output that will be printed */ $html = apply_filters('rocket_lazyload_html', $html, true); return $html; } else { return $matches[0]; } }
function wr2x_from_url_to_system($url) { $img_pathinfo = wr2x_get_pathinfo_from_image_src($url); $filepath = trailingslashit(wr2x_get_wordpress_root()) . $img_pathinfo; if (file_exists($filepath)) { return $filepath; } $filepath = trailingslashit(wr2x_get_upload_root()) . $img_pathinfo; if (file_exists($filepath)) { return $filepath; } return null; }
function wr2x_html_rewrite($buffer) { if (!isset($buffer) || trim($buffer) === '') { return $buffer; } $doc = new DOMDocument(); @$doc->loadHTML($buffer); // = ($doc->strictErrorChecking = false;) $imageTags = $doc->getElementsByTagName('img'); foreach ($imageTags as $tag) { //$img_info = parse_url( $tag->getAttribute('src') ); //$img_pathinfo = ltrim( $img_info['path'], '/' ); $img_pathinfo = wr2x_get_pathinfo_from_image_src($tag->getAttribute('src')); $filepath = trailingslashit(ABSPATH) . $img_pathinfo; $potential_retina = wr2x_get_retina($filepath); if ($potential_retina != null) { wr2x_log("Rewrite '{$filepath}' to '{$potential_retina}'."); $retina_pathinfo = ltrim(str_replace(ABSPATH, "", $potential_retina), '/'); $buffer = str_replace($img_pathinfo, $retina_pathinfo, $buffer); } } return $buffer; }