mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-08 19:21:40 +09:00
fix #1510 이미지 상대경로 처리 보완
This commit is contained in:
parent
f6a538a655
commit
0130ab6493
2 changed files with 23 additions and 5 deletions
|
|
@ -236,7 +236,7 @@ class TemplateHandler
|
|||
$buff = preg_replace('@<!--//.*?-->@s', '', $buff);
|
||||
|
||||
// replace value of src in img/input/script tag
|
||||
$buff = preg_replace_callback('/<(?:img|input|script)(?(?=[[:space:]]+?cond=")[[:space:]]+?cond="[^"]+"|)[^<>]*[[:space:]]src="(?!https?:\/\/|[\/\{])([^"]+)"/is', array($this, '_replacePath'), $buff);
|
||||
$buff = preg_replace_callback('/(<(?:img|input|script).+src=")(?!(?:https?|file):\/\/|[\/\{])([^"]+)("[^>]+>)/is', array($this, '_replacePath'), $buff);
|
||||
|
||||
// replace loop and cond template syntax
|
||||
$buff = $this->_parseInline($buff);
|
||||
|
|
@ -415,18 +415,18 @@ class TemplateHandler
|
|||
private function _replacePath($match)
|
||||
{
|
||||
//return origin conde when src value started '${'.
|
||||
if(preg_match('@^\${@', $match[1]))
|
||||
if(preg_match('@^\${@', $match[2]))
|
||||
{
|
||||
return $match[0];
|
||||
}
|
||||
|
||||
//return origin code when src value include variable.
|
||||
if(preg_match('@^[\'|"]\s*\.\s*\$@', $match[1]))
|
||||
if(preg_match('@^[\'|"]\s*\.\s*\$@', $match[2]))
|
||||
{
|
||||
return $match[0];
|
||||
}
|
||||
|
||||
$src = preg_replace('@^(\./)+@', '', trim($match[1]));
|
||||
$src = preg_replace('@^(\./)+@', '', trim($match[2]));
|
||||
|
||||
$src = $this->web_path . $src;
|
||||
$src = str_replace('/./', '/', $src);
|
||||
|
|
@ -439,7 +439,7 @@ class TemplateHandler
|
|||
$src = $tmp;
|
||||
}
|
||||
|
||||
return substr($match[0], 0, -strlen($match[1]) - 6) . "src=\"{$src}\"";
|
||||
return $match[1] . $src . $match[3];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -245,6 +245,24 @@ class TemplateHandlerTest extends \Codeception\TestCase\Test
|
|||
'<img src="../common/mobile.gif" cond="$foo->bar" />',
|
||||
PHP_EOL . 'if($__Context->foo->bar){ ?><img src="/xe/tests/unit/classes/common/mobile.gif" /><?php } ?>'
|
||||
),
|
||||
// https://github.com/xpressengine/xe-core/issues/1510
|
||||
array(
|
||||
'<img class="tmp_class" cond="!$module_info->title" src="../img/common/blank.gif" />',
|
||||
PHP_EOL . 'if(!$__Context->module_info->title){ ?><img class="tmp_class" src="/xe/tests/unit/classes/img/common/blank.gif" /><?php } ?>'
|
||||
),
|
||||
// https://github.com/xpressengine/xe-core/issues/1510
|
||||
array(
|
||||
'<img cond="$mi->title" class="tmp_class"|cond="$mi->use" src="../img/common/blank.gif" />',
|
||||
PHP_EOL . 'if($__Context->mi->title){ ?><img<?php if($__Context->mi->use){ ?> class="tmp_class"<?php } ?> src="/xe/tests/unit/classes/img/common/blank.gif" /><?php } ?>'
|
||||
),
|
||||
array(
|
||||
'<input foo="bar" /> <img cond="$foo->bar" alt="alt" src="../common/mobile.gif" />',
|
||||
'?><input foo="bar" /> <?php if($__Context->foo->bar){ ?><img alt="alt" src="/xe/tests/unit/classes/common/mobile.gif" /><?php } ?>'
|
||||
),
|
||||
array(
|
||||
'asf <img src="{$foo->bar}" />',
|
||||
'?>asf <img src="<?php echo $__Context->foo->bar ?>" />'
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue