src/Resource/CssUrlProcessor.php
public function processSource($contents, FileSource $source)
	{
		$file = $source->getFileInfo();
		
		$contents = preg_replace_callback("'(\Wurl\s*\\()([^\\)]+)\\)'i", function(array $m) use($file) {
				
			$url = trim($m[2], '"\'');
				
			if(preg_match("'^[^:]+://.+'", $url))
			{
				return $m[0];
			}
				
			$base = dirname($file->getPathname());
			$loc = $base . '/' . ltrim($url, '/\\');
			$loc = preg_replace("'[^/]+/\\.\\./'", '', $loc);
			$params = [];
			
			if(false !== strpos($loc, '?'))
			{
				list($loc, $tmp) = explode('?', $loc, 2);
				parse_str($tmp, $params);
			}
				
			if($this->publisher->isPublic($loc))
			{
				return $m[1] . "'" . $this->publisher->getResourceUri($loc, $params) . "')";
			}
				
			if(!is_file($loc))
			{
				throw new \OutOfBoundsException(sprintf('Resource "%s" referenced by "%s" was not found', $loc, $file->getPathname()));
			}
				
			if(false === ($embed = @file_get_contents($loc)))
			{
				throw new \OutOfBoundsException(sprintf('Unable to load contents of resource "%s" embedded into "%s"', $loc, $file->getPathname()));
			}
				
			return sprintf(
				"%s'data:%s;base64,%s')",
				$m[1],
				Filesystem::guessMimeTypeFromFilename($loc),
				base64_encode($embed)
			);
		}, $contents);
		
		return $contents;
	}
public function processSource($contents, FileSource $source)
	{
		$file = $source->getFileInfo();
		
		$contents = preg_replace_callback("'(\Wurl\s*\\()([^\\)]+)\\)'i", function(array $m) use($file) {
				
			$url = trim($m[2], '"\'');
				
			if(preg_match("'^[^:]+://.+'", $url))
			{
				return $m[0];
			}
				
			$base = dirname($file->getPathname());
			$loc = $base . '/' . ltrim($url, '/\\');
			$loc = preg_replace("'[^/]+/\\.\\./'", '', $loc);
			$params = [];
			
			if(false !== strpos($loc, '?'))
			{
				list($loc, $tmp) = explode('?', $loc, 2);
				parse_str($tmp, $params);
			}
				
			if($this->publisher->isPublic($loc))
			{
				return $m[1] . "'" . $this->publisher->getResourceUri($loc, $params) . "')";
			}
				
			if(!is_file($loc))
			{
				throw new \OutOfBoundsException(sprintf('Resource "%s" referenced by "%s" was not found', $loc, $file->getPathname()));
			}
				
			if(false === ($embed = @file_get_contents($loc)))
			{
				throw new \OutOfBoundsException(sprintf('Unable to load contents of resource "%s" embedded into "%s"', $loc, $file->getPathname()));
			}
				
			return sprintf(
				"%s'data:%s;base64,%s')",
				$m[1],
				Filesystem::guessMimeTypeFromFilename($loc),
				base64_encode($embed)
			);
		}, $contents);
		
		return $contents;
	}
public function processSource ( $ contents , FileSource $ source ) { $ file = $ source -> getFileInfo ( ) ; $ contents = preg_replace_callback ( "'(\Wurl\s*\\()([^\\)]+)\\)'i" , function ( array $ m ) use ( $ file ) { $ url = trim ( $ m [ 2 ] , '"\'' ) ; if ( preg_match ( "'^[^:]+://.+'" , $ url ) ) { return $ m [ 0 ] ; } $ base = dirname ( $ file -> getPathname ( ) ) ; $ loc = $ base . '/' . ltrim ( $ url , '/\\' ) ; $ loc = preg_replace ( "'[^/]+/\\.\\./'" , '' , $ loc ) ; $ params = [ ] ; if ( false !== strpos ( $ loc , '?' ) ) { list ( $ loc , $ tmp ) = explode ( '?' , $ loc , 2 ) ; parse_str ( $ tmp , $ params ) ; } if ( $ this -> publisher -> isPublic ( $ loc ) ) { return $ m [ 1 ] . "'" . $ this -> publisher -> getResourceUri ( $ loc , $ params ) . "')" ; } if ( ! is_file ( $ loc ) ) { throw new \ OutOfBoundsException ( sprintf ( 'Resource "%s" referenced by "%s" was not found' , $ loc , $ file -> getPathname ( ) ) ) ; } if ( false === ( $ embed = @ file_get_contents ( $ loc ) ) ) { throw new \ OutOfBoundsException ( sprintf ( 'Unable to load contents of resource "%s" embedded into "%s"' , $ loc , $ file -> getPathname ( ) ) ) ; } return sprintf ( "%s'data:%s;base64,%s')" , $ m [ 1 ] , Filesystem :: guessMimeTypeFromFilename ( $ loc ) , base64_encode ( $ embed ) ) ; } , $ contents ) ; return $ contents ; }
{@inheritdoc}
{