lazy_load = array();
$speedycache->lazy_load['exclude'] = array();
$speedycache->lazy_load['host'] = '';
$speedycache->lazy_load['placeholder'] = '';
$url = parse_url(site_url());
$speedycache->lazy_load['host'] = $url['host'];
if(!empty($speedycache->options['lazy_load_keywords']) && $speedycache->options['lazy_load_keywords']){
if(is_string($speedycache->options['lazy_load_keywords'])){
$speedycache->lazy_load['exclude'] = explode(',', $speedycache->options['lazy_load_keywords']);
} else {
$speedycache->lazy_load['exclude'] = $speedycache->options['lazy_load_keywords'];
}
}
self::set_placeholder();
}
static function set_placeholder(){
global $speedycache;
if(!empty($speedycache->options['lazy_load_placeholder']) && $speedycache->options['lazy_load_placeholder']){
if($speedycache->options['lazy_load_placeholder'] === 'default'){
$speedycache->lazy_load['placeholder'] = SPEEDYCACHE_PRO_URL . '/assets/images/image-palceholder.png';
} else if($speedycache->options['lazy_load_placeholder'] === 'base64'){
$speedycache->lazy_load['placeholder'] = 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7';
} else if($speedycache->options['lazy_load_placeholder'] === 'custom' && !empty($speedycache->options['lazy_load_placeholder_custom_url'])){
$speedycache->lazy_load['placeholder'] = $speedycache->options['lazy_load_placeholder_custom_url'];
}
return;
}
$speedycache->lazy_load['placeholder'] = SPEEDYCACHE_PRO_URL . '/assets/images/image-palceholder.png';
return;
}
static function instagram($tag){
$src = false;
if(preg_match("/src\s*\=\s*[\"\']([^\"\']+sb-instagram\.min\.js)/", $tag, $out)){
$src = $out[1];
}
if(empty($src)){
return $tag;
}
$tmp_script = '\n";
return $tmp_script;
}
static function mark_images($content){
global $speedycache;
if(speedycache_is_mobile()){
return $content;
}
preg_match_all('/]+>/i', $content, $matches);
if(count($matches[0]) <= 0){
return $content;
}
foreach($matches[0] as $img){
if(self::is_thumbnail($img) || self::is_third_party($img) || !self::is_full($img)){
continue;
}
$tmp_img = $img;
if(strpos($img, 'decoding') === FALSE){
$tmp_img = preg_replace("/
')){
return $attr;
}
}
if(empty($attachment)){
return $attr;
}
$attr['speedycache-lazyload-disable'] = 'true';
return $attr;
}
static function is_thumbnail($src){
$resolution_pregs = array(
'/\-[12]\d{0,2}x[12]\d{0,2}\.(jpg|jpeg|png)/i', // < 299x299
'/\-[12]\d{0,2}x\d{0,2}\.(jpg|jpeg|png)/i', // < 299x99
'/\-\d{0,2}x[12]\d{0,2}\.(jpg|jpeg|png)/i', // < 99x299
'/\-\d{0,2}x\d{0,2}\.(jpg|jpeg|png)/i' // < 99x99
);
foreach($resolution_pregs as $resolution_preg){
if(preg_match($resolution_preg, $src)){
return true;
}
}
return false;
}
static function is_third_party($src){
global $speedycache;
if(preg_match('/' . preg_quote($speedycache->lazy_load['host'], '/') . '/i', $src)){
return false;
}
return true;
}
static function is_full($img){
// to check homepage. sometimes is_home() does not work
if(isset($_SERVER['REQUEST_URI']) && strlen($_SERVER['REQUEST_URI']) < 2){
return false;
}
if(is_home() || is_archive()){
return false;
}
if(preg_match("/-\d+x\d+\.(jpg|jpeg|png)/i", $img)){
if(preg_match("/\sclass\=[\"\'][^\"\']*size-medium[^\"\']*[\"\']/", $img)){
return false;
}
}
return true;
}
static function is_exclude($source){
global $speedycache;
/*
to disable lazy load for rav-slider images
*/
if(preg_match('/class\="rev-slidebg"/i', $source) && preg_match("/data-(bg)*parallax\=/i", $source)){
return true;
}
/*
to exclude img tag which exists in json
var xxx = {"content":"
<\/a>"}
*/
if(preg_match("/\\\\\//", $source)){
return true;
}
/*
*/
if(preg_match("/data-(no|skip)-lazy\s*\=\s*[\"\']\s*1\s*[\"\']/i", $source)){
return true;
}
//Slider Revolution
//
if(preg_match("/\sdata-lazyload\=[\"\']/i", $source)){
return true;
}
//
//
if(preg_match("/\sdata-([a-z-]*)lazy-src\=[\"\']/i", $source)){
return true;
}
//
lazy_load['exclude'] as $key => $value){
if(preg_match('/' . preg_quote($value, '/') . '/i', $source)){
return true;
}
}
return false;
}
static function video($data, $inline_scripts){
global $speedycache;
if(isset($speedycache->settings['noscript'])){
$inline_scripts = $inline_scripts . $speedycache->settings['noscript'];
}
$video_list = array();
$video_start_index = false;
for ($i = 0; $i < strlen($data); $i++){
if(isset($data[$i - 5])){
if(substr($data, $i - 5, 6) == '