| 1 |
<?php |
| 2 |
/** |
| 3 |
* @private |
| 4 |
*/ |
| 5 |
class Less_Tree_Url extends Less_Tree implements Less_Tree_HasValueProperty { |
| 6 |
|
| 7 |
/** @var Less_Tree_Variable|Less_Tree_Quoted|Less_Tree_Anonymous */ |
| 8 |
public $value; |
| 9 |
/** @var array|null */ |
| 10 |
public $currentFileInfo; |
| 11 |
/** @var bool|null */ |
| 12 |
public $isEvald; |
| 13 |
|
| 14 |
/** |
| 15 |
* @param Less_Tree_Variable|Less_Tree_Quoted|Less_Tree_Anonymous $value |
| 16 |
* @param array|null $currentFileInfo |
| 17 |
* @param bool|null $isEvald |
| 18 |
*/ |
| 19 |
public function __construct( Less_Tree $value, $currentFileInfo = null, $isEvald = null ) { |
| 20 |
$this->value = $value; |
| 21 |
$this->currentFileInfo = $currentFileInfo; |
| 22 |
$this->isEvald = $isEvald; |
| 23 |
} |
| 24 |
|
| 25 |
public function accept( $visitor ) { |
| 26 |
$this->value = $visitor->visitObj( $this->value ); |
| 27 |
} |
| 28 |
|
| 29 |
/** |
| 30 |
* @see Less_Tree::genCSS |
| 31 |
*/ |
| 32 |
public function genCSS( $output ) { |
| 33 |
$output->add( 'url(' ); |
| 34 |
$this->value->genCSS( $output ); |
| 35 |
$output->add( ')' ); |
| 36 |
} |
| 37 |
|
| 38 |
/** |
| 39 |
* @param Less_Environment $env |
| 40 |
*/ |
| 41 |
public function compile( $env ) { |
| 42 |
$val = $this->value->compile( $env ); |
| 43 |
|
| 44 |
if ( !$this->isEvald ) { |
| 45 |
// Add the base path if the URL is relative |
| 46 |
if ( Less_Parser::$options['relativeUrls'] |
| 47 |
&& $this->currentFileInfo |
| 48 |
&& is_string( $val->value ) |
| 49 |
&& Less_Environment::isPathRelative( $val->value ) |
| 50 |
) { |
| 51 |
$rootpath = $this->currentFileInfo['uri_root']; |
| 52 |
if ( !$val->quote ) { |
| 53 |
$rootpath = preg_replace( '/[\(\)\'"\s]/', '\\$1', $rootpath ); |
| 54 |
} |
| 55 |
$val->value = $rootpath . $val->value; |
| 56 |
} |
| 57 |
|
| 58 |
$val->value = Less_Environment::normalizePath( $val->value ); |
| 59 |
} |
| 60 |
|
| 61 |
// Add cache buster if enabled |
| 62 |
if ( Less_Parser::$options['urlArgs'] ) { |
| 63 |
if ( !preg_match( '/^\s*data:/', $val->value ) ) { |
| 64 |
$delimiter = !str_contains( $val->value, '?' ) ? '?' : '&'; |
| 65 |
$urlArgs = $delimiter . Less_Parser::$options['urlArgs']; |
| 66 |
$hash_pos = strpos( $val->value, '#' ); |
| 67 |
if ( $hash_pos !== false ) { |
| 68 |
$val->value = substr_replace( $val->value, $urlArgs, $hash_pos, 0 ); |
| 69 |
} else { |
| 70 |
$val->value .= $urlArgs; |
| 71 |
} |
| 72 |
} |
| 73 |
} |
| 74 |
|
| 75 |
return new self( $val, $this->currentFileInfo, true ); |
| 76 |
} |
| 77 |
|
| 78 |
} |