Merge branch 'MDL-46588-27' of git://github.com/jleyva/moodle into MOODLE_27_STABLE
[moodle.git] / lib / lessphp / Tree / Url.php
blob52384c9961de1f1ef2ad228e175bd443d7f99d88
1 <?php
3 /**
4 * Url
6 * @package Less
7 * @subpackage tree
8 */
9 class Less_Tree_Url extends Less_Tree{
11 public $attrs;
12 public $value;
13 public $currentFileInfo;
14 public $isEvald;
15 public $type = 'Url';
17 public function __construct($value, $currentFileInfo = null, $isEvald = null){
18 $this->value = $value;
19 $this->currentFileInfo = $currentFileInfo;
20 $this->isEvald = $isEvald;
23 function accept( $visitor ){
24 $this->value = $visitor->visitObj($this->value);
27 /**
28 * @see Less_Tree::genCSS
30 function genCSS( $output ){
31 $output->add( 'url(' );
32 $this->value->genCSS( $output );
33 $output->add( ')' );
36 /**
37 * @param Less_Functions $ctx
39 public function compile($ctx){
40 $val = $this->value->compile($ctx);
42 if( !$this->isEvald ){
43 // Add the base path if the URL is relative
44 if( Less_Parser::$options['relativeUrls']
45 && $this->currentFileInfo
46 && is_string($val->value)
47 && Less_Environment::isPathRelative($val->value)
49 $rootpath = $this->currentFileInfo['uri_root'];
50 if ( !$val->quote ){
51 $rootpath = preg_replace('/[\(\)\'"\s]/', '\\$1', $rootpath );
53 $val->value = $rootpath . $val->value;
56 $val->value = Less_Environment::normalizePath( $val->value);
59 // Add cache buster if enabled
60 if( Less_Parser::$options['urlArgs'] ){
61 if( !preg_match('/^\s*data:/',$val->value) ){
62 $delimiter = strpos($val->value,'?') === false ? '?' : '&';
63 $urlArgs = $delimiter . Less_Parser::$options['urlArgs'];
64 $hash_pos = strpos($val->value,'#');
65 if( $hash_pos !== false ){
66 $val->value = substr_replace($val->value,$urlArgs, $hash_pos, 0);
67 } else {
68 $val->value .= $urlArgs;
73 return new Less_Tree_URL($val, $this->currentFileInfo, true);