/** * @param RokBooster_Compressor_File $file * * @return mixed */ public function addFile(RokBooster_Compressor_File $file) { if ($file->isIgnored() || $file->isExternal()) { $current_type = RokBooster_Compressor_FileGroup::STATE_IGNORE; } else { $current_type = RokBooster_Compressor_FileGroup::STATE_INCLUDE; } if (!isset($this->current_group) || ($current_type != $this->current_group->getStatus() || !is_null($this->current_group) && $this->current_group->getMime() != $file->getMime() || $file->getAttributes() != $this->current_group->getAttributes())) { $this->last_type = $current_type; $group = new RokBooster_Compressor_FileGroup($current_type, $file->getMime(), $file->getAttributes()); $this->groups[] =& $group; $this->current_group =& $group; } $this->current_group->addItem($file); }
protected function identifyImageSources() { $image_links = pq('img[src]', $this->document); foreach ($image_links as $image) { $attribs = pq($image, $this->document)->attr('*'); $src = $attribs['src']; unset($attribs['src']); $file = new RokBooster_Compressor_File($src, $this->options->root_url, $this->options->root_path); $file->setAttributes($attribs); $ext = strtolower(pathinfo($file->getPath(), PATHINFO_EXTENSION)); $file->setMime(RokBooster_Compressor_File::mime_content_type($file->getPath())); if (!$file->isExternal() && is_file($file->getPath())) { list(, , , , , , , $size, , $mtime, $ctime, , ) = @stat($file->getPath()); if ($this->strposArray($src, $this->options->ignored_files) === false && $size <= $this->options->max_data_uri_image_size) { $this->images[$file->getFile()] = $file; $group = new RokBooster_Compressor_FileGroup(RokBooster_Compressor_FileGroup::STATE_INCLUDE, $file->getMime()); $group->addItem($file); $this->imageFileGroups[$file->getFile()] = $group; } } } foreach ($this->imageFileGroups as $image_file_group) { if ($image_file_group->getStatus() != RokBooster_Compressor_IGroup::STATE_IGNORE && $this->isOutputExpired($image_file_group, false) && !$this->isBeingRendered($image_file_group)) { $this->encode_image_file_groups[] = $image_file_group; $this->setCurrentlyRendering($image_file_group); } } }
/** * @param RokBooster_Compressor_FileGroup $group */ protected function storeFileInfo(RokBooster_Compressor_FileGroup $group) { $group->cleanup(); $this->file_info_cache->store(serialize($group), $group->getChecksum() . '_fileinfo'); }
/** * @param RokBooster_Compressor_FileGroup $files */ protected function processStyleFiles(RokBooster_Compressor_FileGroup &$files) { $content = ''; foreach ($files as $file) { /** @var $file RokBooster_Compressor_File */ if ($file->getContent()) { $this->current_css_url = $file->getFile(); if ($this->options->imported_css) { try { $compiled_content = RokBooster_Compressor_CssAggregator::combine($file->content, dirname($file->getPath())); $file->content = $compiled_content; } catch (Exception $e) { JLog::add(JText::sprintf('PLG_SYSTEM_ROKBOOSTER_CSS_FILE_COMPILE_ERROR', $e->getMessage(), $file->path), JLog::ERROR, 'rokbooster'); } } $file->content = preg_replace('~@import\\s?[\'"]([^\'"]+?)[\'"];~', '@import url("$1");', $file->content); $file->content = preg_replace_callback('~url\\s?\\([\'"]?(?![a-z]+:|/+)([^\'")]+)[\'"]?\\)~i', array($this, 'correctUrl'), $file->content); unset($this->current_css_url); $content .= $file->content . ' '; } } //$files->setResult($content); $files->setResult(RokBooster_Compressor_Processor_YUI::_minify($content)); }
/** * @param RokBooster_Compressor_FileGroup $filegroup */ public function writeStyleFile(RokBooster_Compressor_FileGroup $filegroup) { $this->write($filegroup->getChecksum(), $filegroup->getResult(), true, 'text/css', true); }
/** * @param RokBooster_Compressor_FileGroup $files */ protected function processStyleFiles(RokBooster_Compressor_FileGroup &$files) { $content = ''; foreach ($files as $file) { /** @var $file RokBooster_Compressor_File */ if ($file->getContent()) { $this->current_css_url = $file->getFile(); if ($this->options->imported_css) { try { $compiled_content = RokBooster_Compressor_CssAggregator::combine($file->content, dirname($file->getPath())); $file->content = $compiled_content; } catch (Exception $e) { JLog::add(JText::sprintf('PLG_SYSTEM_ROKBOOSTER_CSS_FILE_COMPILE_ERROR', $e->getMessage(), $file->path), JLog::ERROR, 'rokbooster'); } } $file->content = preg_replace('~@import\\s?[\'"]([^\'"]+?)[\'"];~', '@import url("$1");', $file->content); $file->content = preg_replace_callback('~url\\s?\\([\'"]?(?![a-z]+:|/+)([^\'")]+)[\'"]?\\)~i', array($this, 'correctUrl'), $file->content); unset($this->current_css_url); $content .= $file->content . ' '; $fixed_content = ''; if (($match_count = preg_match_all('/@import\\s+(?:url\\()?["\\\']?([^"\\\'\\)]+)["\\\']?(?:\\))?(?:[\\s\\w\\d\\-._,]*);/i', $content, $matches)) > 0) { for ($i = 0; $i < $match_count; $i++) { if (!empty($matches[1][$i])) { $fixed_content .= $matches[0][$i]; $content = str_replace($matches[0][$i], '', $content); } } } $fixed_content .= $content; $content = $fixed_content; } } if ($this->options->minify_css == 'compress') { $files->setResult(RokBooster_Compressor_Processor_YUI::_minify($content)); } else { $files->setResult($content); } }
/** * @param RokBooster_Compressor_FileGroup $files */ protected function processStyleFiles(RokBooster_Compressor_FileGroup &$files) { $content = ''; foreach ($files as $file) { /** @var $file RokBooster_Compressor_File */ if ($file->getContent()) { $this->current_css_url = $file->getFile(); if ($this->options->imported_css) { try { $compiled_content = RokBooster_Compressor_CssCompiler::compile($file->content, dirname($file->getPath())); $file->content = $compiled_content; } catch (Exception $e) { } } $file->content = preg_replace('~@import\\s?[\'"]([^\'"]+?)[\'"];~', '@import url("$1");', $file->content); $file->content = preg_replace_callback('~url\\s?\\([\'"]?(?![a-z]+:|/+)([^\'")]+)[\'"]?\\)~i', array($this, 'correctUrl'), $file->content); unset($this->current_css_url); $content .= $file->content . ' '; } } $files->setResult(RokBooster_Compressor_Processor_YUI::_minify($content)); }