Esempio n. 1
0
 /**
  * @param $id
  *
  * @return AssetsLoader\Application\FileResponse|Application\Responses\TextResponse
  */
 public function actionFiles($id)
 {
     if (NULL === ($item = $this->fileCache->getItem(Utils\Strings::webalize($id)))) {
         return new Application\Responses\TextResponse('');
     }
     return new AssetsLoader\Application\FileResponse($item[Caching\FileCache::CONTENT]);
 }
Esempio n. 2
0
 /**
  * Make relative url absolute
  *
  * @param string $url image url
  * @param string $cssFile absolute css file path
  *
  * @return string
  */
 public function absolutizeUrl($url, $cssFile)
 {
     // Is already absolute
     if (preg_match('/^([a-z]+:\\/)?\\//', $url)) {
         return $url;
     }
     // Get css file real path
     $cssFile = Files\Path::normalize($cssFile);
     // Remove query string
     $url = preg_replace('/\\?.*/', '', $url);
     // Create full file path
     $filePath = realpath(rtrim(dirname(realpath($cssFile)), '/') . '/' . $url);
     // Check if file exists
     if (!$filePath || !file_exists($filePath)) {
         return $url;
     }
     // Check for images which can be encoded
     if (preg_match('/\\.(gif|png|jpg)$/i', $url) && filesize($filePath) <= 10240 && preg_match('/\\.(gif|png|jpg)$/i', $filePath, $extension)) {
         $path = sprintf('data:image/%s;base64,%s', str_replace('jpg', 'jpeg', strtolower($extension[1])), base64_encode(file_get_contents($filePath)));
         // Other files
     } else {
         // Create file hash
         $fileHash = $this->getHash($filePath);
         // Save file into cache
         $this->cache->save($fileHash, [Caching\FileCache::CONTENT => $filePath], [Caching\FileCache::TAGS => ['ipub.assetsloader', 'ipub.assetsloader.images'], Caching\FileCache::FILES => [$filePath]]);
         // Create route for specific file
         $path = $this->getPresenter()->link(':IPub:AssetsLoader:files', ['id' => $fileHash]);
     }
     return $path;
 }