From fbc8e265ad81b6b6542aa7b93c189210c1d2cdb7 Mon Sep 17 00:00:00 2001 From: Klimov Paul Date: Sun, 26 May 2013 18:55:12 +0300 Subject: [PATCH] Method "AssetController::adjustCssUrl()" has been implemented in basic. --- .../yii/console/controllers/AssetController.php | 27 +++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/framework/yii/console/controllers/AssetController.php b/framework/yii/console/controllers/AssetController.php index 852b892..71709e8 100644 --- a/framework/yii/console/controllers/AssetController.php +++ b/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; }