Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PSDI Army
yii2
Commits
265a6f1c
Commit
265a6f1c
authored
May 26, 2013
by
Klimov Paul
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Relative path composing at "AssetController::adjustCssUrl()" has been complete.
parent
fbc8e265
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
13 deletions
+44
-13
AssetController.php
framework/yii/console/controllers/AssetController.php
+28
-9
AssetControllerTest.php
...nit/framework/console/controllers/AssetControllerTest.php
+16
-4
No files found.
framework/yii/console/controllers/AssetController.php
View file @
265a6f1c
...
@@ -536,15 +536,20 @@ EOD
...
@@ -536,15 +536,20 @@ EOD
*/
*/
protected
function
adjustCssUrl
(
$cssContent
,
$inputFilePath
,
$outputFilePath
)
protected
function
adjustCssUrl
(
$cssContent
,
$inputFilePath
,
$outputFilePath
)
{
{
$sharedPath
=
''
;
$sharedPathParts
=
array
();
for
(
$i
=
0
;
$i
<
strlen
(
$inputFilePath
);
$i
++
)
{
$inputFilePathParts
=
explode
(
'/'
,
$inputFilePath
);
if
(
!
isset
(
$outputFilePath
[
$i
]))
{
$inputFilePathPartsCount
=
count
(
$inputFilePathParts
);
$outputFilePathParts
=
explode
(
'/'
,
$outputFilePath
);
$outputFilePathPartsCount
=
count
(
$outputFilePathParts
);
for
(
$i
=
0
;
$i
<
$inputFilePathPartsCount
&&
$i
<
$outputFilePathPartsCount
;
$i
++
)
{
if
(
$inputFilePathParts
[
$i
]
==
$outputFilePathParts
[
$i
])
{
$sharedPathParts
[]
=
$inputFilePathParts
[
$i
];
}
else
{
break
;
break
;
}
}
if
(
$inputFilePath
[
$i
]
==
$outputFilePath
[
$i
])
{
$sharedPath
.=
$inputFilePath
[
$i
];
}
}
}
$sharedPath
=
implode
(
'/'
,
$sharedPathParts
);
$inputFileRelativePath
=
trim
(
str_replace
(
$sharedPath
,
''
,
$inputFilePath
),
'/'
);
$inputFileRelativePath
=
trim
(
str_replace
(
$sharedPath
,
''
,
$inputFilePath
),
'/'
);
$outputFileRelativePath
=
trim
(
str_replace
(
$sharedPath
,
''
,
$outputFilePath
),
'/'
);
$outputFileRelativePath
=
trim
(
str_replace
(
$sharedPath
,
''
,
$outputFilePath
),
'/'
);
$inputFileRelativePathParts
=
explode
(
'/'
,
$inputFileRelativePath
);
$inputFileRelativePathParts
=
explode
(
'/'
,
$inputFileRelativePath
);
...
@@ -554,12 +559,26 @@ EOD
...
@@ -554,12 +559,26 @@ EOD
$fullMatch
=
$matches
[
0
];
$fullMatch
=
$matches
[
0
];
$inputUrl
=
$matches
[
1
];
$inputUrl
=
$matches
[
1
];
$urlPrefix
=
str_repeat
(
'../'
,
count
(
$outputFileRelativePathParts
));
$outputUrlParts
=
array_fill
(
0
,
count
(
$outputFileRelativePathParts
),
'..'
);
$urlPrefix
.=
implode
(
'/'
,
$inputFileRelativePathParts
);
$outputUrlParts
=
array_merge
(
$outputUrlParts
,
$inputFileRelativePathParts
);
if
(
strpos
(
$inputUrl
,
'/'
)
!==
false
)
{
$inputUrlParts
=
explode
(
'/'
,
$inputUrl
);
foreach
(
$inputUrlParts
as
$key
=>
$inputUrlPart
)
{
if
(
$inputUrlPart
==
'..'
)
{
array_pop
(
$outputUrlParts
);
unset
(
$inputUrlParts
[
$key
]);
}
}
$outputUrlParts
[]
=
implode
(
'/'
,
$inputUrlParts
);
}
else
{
$outputUrlParts
[]
=
$inputUrl
;
}
$outputUrl
=
implode
(
'/'
,
$outputUrlParts
);
$outputUrl
=
$urlPrefix
.
'/'
.
$inputUrl
;
return
str_replace
(
$inputUrl
,
$outputUrl
,
$fullMatch
);
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
;
return
$cssContent
;
...
...
tests/unit/framework/console/controllers/AssetControllerTest.php
View file @
265a6f1c
...
@@ -263,16 +263,28 @@ class AssetControllerTest extends TestCase
...
@@ -263,16 +263,28 @@ class AssetControllerTest extends TestCase
{
{
return
array
(
return
array
(
array
(
array
(
'.
test-class {background-image: url("test
.png");}'
,
'.
published-same-dir-class {background-image: url("published_same_dir
.png");}'
,
'/test/base/path/assets/input'
,
'/test/base/path/assets/input'
,
'/test/base/path/assets/output'
,
'/test/base/path/assets/output'
,
'.
test-class {background-image: url("../input/test
.png");}'
,
'.
published-same-dir-class {background-image: url("../input/published_same_dir
.png");}'
,
),
),
array
(
array
(
'.
test-class {background-image: url("../img/test
.png");}'
,
'.
published-relative-dir-class {background-image: url("../img/published_relative_dir
.png");}'
,
'/test/base/path/assets/input'
,
'/test/base/path/assets/input'
,
'/test/base/path/assets/output'
,
'/test/base/path/assets/output'
,
'.test-class {background-image: url("../input/img/test.png");}'
,
'.published-relative-dir-class {background-image: url("../img/published_relative_dir.png");}'
,
),
array
(
'.static-same-dir-class {background-image: url("static_same_dir.png");}'
,
'/test/base/path/css'
,
'/test/base/path/assets/output'
,
'.static-same-dir-class {background-image: url("../../css/static_same_dir.png");}'
,
),
array
(
'.static-relative-dir-class {background-image: url("../img/static_relative_dir.png");}'
,
'/test/base/path/css'
,
'/test/base/path/assets/output'
,
'.static-relative-dir-class {background-image: url("../../img/static_relative_dir.png");}'
,
),
),
);
);
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment