/** * 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; }
/** * Make path absolute * * @param $path string * * @return string * * @throws Exceptions\FileNotFoundException */ protected function cannonicalizePath($path) { if (file_exists($path)) { return $path; } $abs = Files\Path::normalize($path); if (file_exists($abs)) { return $abs; } throw new Exceptions\FileNotFoundException("File '{$path}' does not exist."); }