コード例 #1
0
ファイル: CssRewriteUrlFilter.php プロジェクト: ejailesb/repo
 /**
  * {@inheritdoc}
  */
 public function filterContent(AssetInterface $asset)
 {
     // has path?
     if (!($path = $asset->getOption('path'))) {
         return;
     }
     // set base path
     $this->path = dirname($this->url->to($path)) . '/';
     $asset->setContent(preg_replace_callback('/url\\(\\s*[\'"]?(?![a-z]+:|\\/+)([^\'")]+)[\'"]?\\s*\\)/i', array($this, 'rewrite'), $asset->getContent()));
 }
コード例 #2
0
 /**
  * {@inheritdoc}
  */
 public function filterContent(AssetInterface $asset)
 {
     // has path?
     if (!$asset['path']) {
         return;
     }
     // resolve @import rules
     $content = $this->load($asset['path'], $asset->getContent());
     // move unresolved @import rules to the top
     $comments = array();
     $regexp = '/@import[^;]+;/i';
     $content = $this->replaceComments($content, $comments);
     if (preg_match_all($regexp, $content, $matches)) {
         $content = preg_replace($regexp, '', $content);
         $content = implode("\n", $matches[0]) . "\n" . $content;
     }
     $content = $this->restoreComments($content, $comments);
     $asset->setContent($content);
 }
コード例 #3
0
 /**
  * {@inheritdoc}
  */
 public function filterContent(AssetInterface $asset)
 {
     $images = array();
     $content = $asset->getContent();
     // get images and the related path
     if (preg_match_all('/url\\(\\s*[\'"]?([^\'"]+)[\'"]?\\s*\\)/Ui', $asset->getContent(), $matches)) {
         foreach ($matches[0] as $i => $url) {
             if (strpos($path = $matches[1][$i], $this->baseUrl) !== 0) {
                 continue;
             }
             if ($path = realpath($this->basePath . '/' . ltrim(substr($path, strlen($this->baseUrl)), '/'))) {
                 $images[$url] = $path;
             }
         }
     }
     // check if image exists and filesize < 10kb
     foreach ($images as $url => $path) {
         if (filesize($path) <= 10240 && preg_match('/\\.(gif|png|jpg)$/i', $path, $extension)) {
             $content = str_replace($url, sprintf('url(data:image/%s;base64,%s)', str_replace('jpg', 'jpeg', strtolower($extension[1])), base64_encode(file_get_contents($path))), $content);
         }
     }
     $asset->setContent($content);
 }
コード例 #4
0
ファイル: CssRtlFilter.php プロジェクト: ejailesb/repo
 /**
  * {@inheritdoc}
  */
 public function filterContent(AssetInterface $asset)
 {
     $asset->setContent($this->process($asset->getContent()));
 }