enhanced = array(); $speedycache->enhanced['html'] = ''; $speedycache->enhanced['head_html'] = ''; $speedycache->enhanced['body_html'] = ''; $speedycache->enhanced['inline_scripts'] = ''; $speedycache->enhanced['cache_speedycache_minified'] = ''; $speedycache->enhanced['cache_speedycache_minified'] = 'cache/speedycache/'.SPEEDYCACHE_SERVER_HOST. '/assets'; } // Removes white space after & \r & any white space static function remove_trailing_html_space($content){ global $speedycache; $content = preg_replace("/<\/html>\s+/", '', $content); $content = str_replace("\r", '', $content); return preg_replace("/^\s+/m", '', ((string) $content)); } static function remove_head_comments(){ global $speedycache; $data = $speedycache->enhanced['head_html']; $comment_list = array(); $comment_start_index = false; for($i = 0; $i < strlen( $data ); $i++){ if(isset($data[$i-3])){ if($data[$i-3].$data[$i-2].$data[$i-1].$data[$i] == ''){ array_push($comment_list, array('start' => $comment_start_index, 'end' => $i)); $comment_start_index = false; } } } } if(!empty($comment_list)){ foreach(array_reverse($comment_list) as $key => $value){ $data = substr_replace($data, '', $value['start'], ($value['end'] - $value['start'] + 1)); } $speedycache->enhanced['html'] = str_replace($speedycache->enhanced['head_html'], $data, $speedycache->enhanced['html']); } return $speedycache->enhanced['html']; } static function eliminate_newline($start_string, $end_string, $tmp_html){ $data = $tmp_html; $list = array(); $start_index = false; $end_index = false; for($i = 0; $i < strlen( $data ); $i++){ if(substr($data, $i, strlen($start_string)) == $start_string){ if(!$end_index){ $start_index = $i; } } if($start_index && $i > $start_index){ if(substr($data, $i, strlen($end_string)) == $end_string){ $end_index = $i + strlen($end_string) - 1; $text = substr($data, $start_index, ($end_index - $start_index + 1)); array_push($list, array('start' => $start_index, 'end' => $end_index, 'text' => $text)); $start_index = false; $end_index = false; } } } if(isset($list[0])){ $list = array_reverse($list); foreach($list as $key => $value){ if(preg_match("/(').prependTo($body); if(preg_match("/\)\.prependTo\(/i", $value['text'])){ continue; } //
if(preg_match("/]*>/i", $value['text'])){ continue; } $value['text'] = preg_replace("/\s+/", " ", ((string)$value['text'])); $tmp_html = substr_replace($tmp_html, $value['text'], $value['start'], ($value['end'] - $value['start'] + 1)); } } return $tmp_html; } static function minify_inline_css($data){ global $speedycache; $style_list = array(); $style_start_index = false; for($i = 0; $i < strlen( $data ); $i++){ if(isset($data[$i-5])){ if(substr($data, $i - 5, 6) == ''){ array_push($style_list, array('start' => $style_start_index, 'end' => $i)); $style_start_index = false; } } } } if(!empty($style_list)){ foreach(array_reverse($style_list) as $key => $value){ // document.write(' tag $inline_style = str_replace(' type="text/css"', '', $inline_style); $inline_style = str_replace(' type="text/css"', '', $inline_style); $data = substr_replace($data, $inline_style, $value['start'], ($value['end'] - $value['start'] + 1)); } } return $data; } static function remove_html_comments($data){ $comment_list = array(); $comment_start_index = false; for($i = 0; $i < strlen($data); $i++){ if(isset($data[$i-3])){ if($data[$i-3].$data[$i-2].$data[$i-1].$data[$i] == "'){ array_push($comment_list, array('start' => $comment_start_index, 'end' => $i)); $comment_start_index = false; } } } } if(!empty($comment_list)){ foreach(array_reverse($comment_list) as $key => $value){ if(($value['end'] - $value['start']) > 4){ $comment_html = substr($data, $value['start'], ($value['end'] - $value['start'] + 1)); if(preg_match("/google\_ad\_slot/i", $comment_html)){ }else{ $data = substr_replace($data, '', $value['start'], ($value['end'] - $value['start'] + 1)); } } } } return $data; } static function minify_html(&$content){ global $speedycache; if(defined('SPEEDYCACHE_VERSION') && version_compare(SPEEDYCACHE_VERSION, '1.2.0', '<')){ return $speedycache->enhanced['html']; } $tmp_html = $content; $tmp_html = self::remove_trailing_html_space($tmp_html); $tmp_html = self::eliminate_newline('', $tmp_html); $tmp_html = self::eliminate_newline('', $tmp_html); $tmp_html = self::minify_inline_js($tmp_html); $tmp_html = self::minify_inline_css($tmp_html); $tmp_html = self::remove_html_comments($tmp_html); $tag_list = 'p|div|span|img|nav|ul|li|header|a|b|i|article|section|footer|style|script|link|meta|body'; $tmp_html = preg_replace_callback("/\<(".$tag_list.")\s+[^\>\<]+\>/i", '\SpeedyCache\Enhanced::remove_spaces_in_tag', $tmp_html); $tmp_html = preg_replace('/\h+<\//', ' // - need to remove spaces between > < // - need to remove spaces between Assdfdf // $tmp_html = preg_replace("/\h*\<(".$tag_list.")\s+([^\>]+)>\h*/i", "<$1 $2>", $tmp_html); // $tmp_html = preg_replace("/\h*\<\/(".$tag_list.")>\h*/i", "", $tmp_html); $tmp_html = preg_replace("/\s*<\/div>\s*/is", "
", $tmp_html); $content = $tmp_html; } static function search_in_inline_scripts($content){ global $speedycache; if(strpos($speedycache->enhanced['inline_scripts'], $content) === false){ return false; } return true; } static function remove_spaces_in_tag($matches){ if(self::search_in_inline_scripts($matches[0])){ return $matches[0]; } /** * Structure of this array is * searchable => replacer */ $pregs_replaces = array( '/([\"\'])\s+\/>/' => '$1/>', // '/\s+/' => ' ', //
'/\s+([\"\'])/' => '$1', //
'/([a-z])\=([\"\'])\s+/' => '$1=$2', //
'/\h*class\=\'\'\h*/' => ' ', //