/** * @see ILess_Node */ public function compile(ILess_Environment $env, $arguments = null, $important = null) { $value = $this->value->compile($env); $rootPath = isset($this->currentFileInfo) && $this->currentFileInfo->rootPath ? $this->currentFileInfo->rootPath : false; if ($rootPath && is_string($value->value) && ILess_Util::isPathRelative($value->value)) { $quoteExists = self::propertyExists($value, 'quote'); if ($quoteExists && empty($value->quote) || !$quoteExists) { $rootPath = preg_replace_callback('/[\\(\\)\'"\\s]/', array($this, 'rootPathReplaceCallback'), $rootPath); } $value->value = $rootPath . $value->value; } $value->value = ILess_Util::normalizePath($value->value, false); return new ILess_Node_Url($value, null); }
/** * Inlines a resource and falls back to url() if the ieCompat option is on * and the resource is too large, or if you use the function in the browser. * If the mime is not given then node uses the mime package to determine the correct mime type. * * @param string $mimeType A mime type string * @param string $url The URL of the file to inline. */ public function dataUri(ILess_Node $mimeType, ILess_Node $filePath = null) { if (func_num_args() < 2) { $path = $mimeType->value; $mime = false; // we will detect it later } else { $path = $filePath->value; $mime = $mimeType->value; } $path = ILess_Util::sanitizePath($path); if (ILess_Util::isPathRelative($path)) { if ($this->env->relativeUrls) { $path = $this->env->currentFileInfo->currentDirectory . $path; } else { $path = $this->env->currentFileInfo->entryPath . $path; } $path = ILess_Util::normalizePath($path); } if ($mime === false) { $mime = ILess_Mime::lookup($path); // use base 64 unless it's an ASCII or UTF-8 format $charset = ILess_Mime::charsetsLookup($mime); $useBase64 = !in_array($charset, array('US-ASCII', 'UTF-8')); if ($useBase64) { $mime .= ';base64'; } } else { $useBase64 = preg_match('/;base64$/', $mime); } $buffer = false; if (is_readable($path)) { $buffer = file_get_contents($path); } // IE8 cannot handle a data-uri larger than 32KB. If this is exceeded // and the --ieCompat option is enabled, return a normal url() instead. if ($this->env->ieCompat && $buffer !== false) { $fileSizeInKB = round(strlen($buffer) / 1024); if ($fileSizeInKB >= self::IE8_DATA_URI_MAX_KB) { $url = new ILess_Node_Url($filePath ? $filePath : $mimeType, $this->env->currentFileInfo); return $url->compile($this->env); } } if ($buffer !== false) { $buffer = $useBase64 ? base64_encode($buffer) : rawurlencode($buffer); $path = "'data:" . $mime . ',' . $buffer . "'"; } return new ILess_Node_Url(new ILess_Node_Anonymous($path)); }
/** * Compiles the path * * @param ILess_Environment $env * @return ILess_Node_Url */ public function compilePath(ILess_Environment $env) { $path = $this->path->compile($env); if (!$path instanceof ILess_Node_Url) { $rootPath = $this->currentFileInfo && $this->currentFileInfo->rootPath ? $this->currentFileInfo->rootPath : false; if ($rootPath) { $pathValue = $path->value; // Add the base path if the import is relative if ($pathValue && ILess_Util::isPathRelative($pathValue)) { $path->value = $rootPath . $pathValue; } } $path->value = ILess_Util::normalizePath($path->value); } return $path; }