private function removeHttpProtocol() { $scripts = array('img', 'link', 'script'); $attr = array('src', 'href', 'data-ll'); foreach ($scripts as $script) { $html = $this->DOMHtml->getContent(); $regex = '/<' . $script . '((?:.)*?)>/smix'; $content = preg_replace_callback($regex, function ($srcpt) use($attr, $script) { $regex_img = '/(\\S+)=["\']((?:.(?!["\']?\\s+(?:\\S+)=|[>"\']))+.)["\']/'; preg_match_all($regex_img, $srcpt[1], $matches); if (isset($matches[1]) && isset($matches[2])) { foreach ($matches[1] as $k => $key) { $attributes[trim($key)] = trim($matches[2][$k]); } } if (isset($attributes) && is_array($attributes)) { foreach ($attr as $att) { if (isset($attributes[$att]) && $attributes[$att]) { $attributes[$att] = Url::normalizeUrl($attributes[$att]); } } $return = '<' . $script; foreach ($attributes as $key => $a) { $return .= ' ' . $key . '="' . $a . '"'; } $return .= '>'; return $return; } else { return $srcpt[0]; } }, $html); $this->DOMHtml->setContent($content ?: $html); } }
public static function imgLazyLoad($config) { self::init($config); $htmlContent = self::$DOMHtml->getContent(); if (self::$config['LazyLoadImages'] && !self::ignoreLazyLoad($htmlContent)) { self::removeImagesFromScripts(); $regex = '/<img((?:.)*?)>/smix'; $content = preg_replace_callback($regex, function ($script) { return LazyLoad::prepareImg($script); }, $htmlContent); self::$DOMHtml->setContent($content ?: $htmlContent); self::returnImagesFromScripts(); self::lazyLoadHead(); } }