Browse Source

Method "AssetController::adjustCssUrl()" has been implemented in basic.

tags/2.0.0-beta
Klimov Paul 11 years ago
parent
commit
fbc8e265ad
  1. 27
      framework/yii/console/controllers/AssetController.php

27
framework/yii/console/controllers/AssetController.php

@ -536,10 +536,31 @@ EOD
*/
protected function adjustCssUrl($cssContent, $inputFilePath, $outputFilePath)
{
$callback = function($matches) use ($inputFilePath, $outputFilePath) {
return $matches[0];
$sharedPath = '';
for ($i = 0; $i < strlen($inputFilePath); $i++) {
if (!isset($outputFilePath[$i])) {
break;
}
if ($inputFilePath[$i] == $outputFilePath[$i]) {
$sharedPath .= $inputFilePath[$i];
}
}
$inputFileRelativePath = trim(str_replace($sharedPath, '', $inputFilePath), '/');
$outputFileRelativePath = trim(str_replace($sharedPath, '', $outputFilePath), '/');
$inputFileRelativePathParts = explode('/', $inputFileRelativePath);
$outputFileRelativePathParts = explode('/', $outputFileRelativePath);
$callback = function($matches) use ($inputFileRelativePathParts, $outputFileRelativePathParts) {
$fullMatch = $matches[0];
$inputUrl = $matches[1];
$urlPrefix = str_repeat('../', count($outputFileRelativePathParts));
$urlPrefix .= implode('/', $inputFileRelativePathParts);
$outputUrl = $urlPrefix . '/' . $inputUrl;
return str_replace($inputUrl, $outputUrl, $fullMatch);
};
$cssContent = preg_replace_callback('/[\w\-]:\s*url\("(.*)"\)+/is', $callback, $cssContent);
$cssContent = preg_replace_callback('/[\w\-]:\s*url\("([^"]*)"\)+/is', $callback, $cssContent);
return $cssContent;
}

Loading…
Cancel
Save