/**
  * @param RokBooster_Compressor_File $file
  *
  * @return bool
  */
 public function fileBelongs(RokBooster_Compressor_File $file)
 {
     $belong = false;
     $file_state = self::STATE_IGNORE;
     if (!$file->isExternal() && !$file->isIgnored()) {
         $file_state = self::STATE_INCLUDE;
     }
     if ($this->status == $file_state) {
         $belong = true;
     }
     return $belong;
 }
Example #2
0
 /**
  * @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);
 }
Example #3
0
 /**
  *
  */
 protected function identifyStyleFiles()
 {
     $doc = JFactory::getDocument();
     foreach ($doc->_styleSheets as $filename => $fileinfo) {
         $file = new RokBooster_Compressor_File($filename, $this->options->root_url, $this->options->root_path);
         $file->setType('css');
         $file->setMime($fileinfo['mime']);
         $file->setAttributes($fileinfo['attribs']);
         $file->addAttribute('media', $fileinfo['media']);
         if (in_array($file->file, $this->options->ignored_files)) {
             $file->setIgnored(true);
         }
         $this->style_file_sorter->addFile($file);
     }
     $file_groups = $this->style_file_sorter->getGroups();
     foreach ($file_groups as &$file_group) {
         if ($this->isCacheExpired($file_group->getChecksum()) && !$this->isBeingRendered($file_group->getChecksum())) {
             $this->render_style_file_groups[] = $file_group;
             $this->setCurrentlyRendering($file_group->getChecksum());
         }
     }
 }
 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 $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];
     }
 }
Example #6
0
 protected function encodeFile($fullPath)
 {
     $encoded = base64_encode(file_get_contents($fullPath));
     $mime = RokBooster_Compressor_File::mime_content_type($fullPath);
     return sprintf('data:%s;base64,%s', $mime, $encoded);
 }
 /**
  *
  */
 protected function identifyStyleFiles()
 {
     $header_links = pq($this->prefix . 'link[href][rel=stylesheet]', $this->document);
     foreach ($header_links as $link) {
         $attribs = pq($link, $this->document)->attr('*');
         $href = $attribs['href'];
         unset($attribs['href']);
         $mime = $attribs['type'];
         unset($attribs['type']);
         unset($attribs['rel']);
         $file = new RokBooster_Compressor_File($href, $this->options->root_url, $this->options->root_path);
         $file->setMime($mime);
         $file->setType('css');
         $file->setAttributes($attribs);
         if (in_array($file->file, $this->options->ignored_files)) {
             $file->setIgnored(true);
         }
         $this->style_file_sorter->addFile($file);
     }
     $file_groups = $this->style_file_sorter->getGroups();
     foreach ($file_groups as &$file_group) {
         if ($this->isCacheExpired($file_group->getChecksum()) && !$this->isBeingRendered($file_group->getChecksum())) {
             $this->render_style_file_groups[] = $file_group;
             $this->setCurrentlyRendering($file_group->getChecksum());
         }
     }
 }