/** * @param $matches * * @return string */ protected function correctUrl($matches) { if (!preg_match('~^(/|http)~', $matches[1])) { $current_uri = parse_url($this->current_css_url); $cssRootPath = preg_replace('~/[^/]+\\.css~', '/', $current_uri['path']); $imagePath = $cssRootPath . $matches[1]; $imagePath = $this->normalize_path($imagePath); if ($this->options->convert_css_images) { $fullPath = RokBooster_Compressor_File::getFileLink($imagePath, $this->options->root_url, $this->options->root_path); $ext = strtolower(pathinfo(basename($fullPath), PATHINFO_EXTENSION)); if (in_array($ext, array('gif', 'jpg', 'jpeg', 'png')) && is_file($fullPath)) { list(, , , , , , , $size, , $mtime, $ctime, , ) = @stat($fullPath); // TODO replace size compare with property if ($size <= $this->options->max_data_uri_image_size) { $encoded = base64_encode(file_get_contents($fullPath)); $mime = RokBooster_Compressor_File::mime_content_type($fullPath); $imagePath = sprintf('data:%s;base64,%s', $mime, $encoded); } } } return 'url(\'' . $imagePath . '\')'; } else { return $matches[0]; } }
/** * @param $matches * * @return string */ protected function correctUrl($matches) { if (!preg_match('~^(/|http)~', $matches[1])) { $current_uri = parse_url($this->current_css_url); $cssRootPath = preg_replace('~/[^/]+\\.css~', '/', $current_uri['path']); $url_path = $cssRootPath . $matches[1]; $url_path = $this->normalize_path($url_path); $fullPath = RokBooster_Compressor_File::getFileLink($url_path, $this->options->root_url, $this->options->root_path); $ext = mb_strtolower(pathinfo(basename($fullPath), PATHINFO_EXTENSION)); if (in_array($ext, array('gif', 'jpg', 'jpeg', 'png')) && is_file($fullPath) && $this->options->convert_css_images) { list(, , , , , , , $size, , $mtime, $ctime, , ) = @stat($fullPath); if ($size <= $this->options->max_data_uri_image_size) { $url_path = $this->encodeFile($fullPath); } } if (in_array($ext, array('woff', 'ttf', 'svg', 'otf', 'eot')) && is_file($fullPath) && $this->options->convert_css_fonts) { list(, , , , , , , $size, , $mtime, $ctime, , ) = @stat($fullPath); if ($size <= $this->options->max_data_uri_font_size) { $url_path = $this->encodeFile($fullPath); } } return 'url(\'' . $url_path . '\')'; } else { return $matches[0]; } }