/**
* 替换模块中图片路径
*
* @author liupeng
* @param string $source 内容
* @return string
**/
function smarty_prefilter_preCompile($source)
{
$file_type = strtolower(strrchr($this->_current_file, '.'));
$tmp_dir = '' ; /* 替换文件编码头部 */
if (strpos($source, "\xEF\xBB\xBF") !== FALSE)
{
$source = str_replace("\xEF\xBB\xBF", '', $source);
}
if ($this->store_id > 0)
{
if (strpos($this->_current_file, '/mall/resource') !== false)
{
$mall_skin = $this->options['mall_skin'];
$tmp_dir = "themes/mall/skin/$mall_skin/" ;
}
else
{
$tmp_dir = "themes/store/skin/" . $this->skin . '/' ;
}
}
else {
$tmp_dir = "themes/mall/skin/" . $this->skin . '/' ;
} $pattern = array(
'/<!--[^>|\n]*?({.+?})[^<|{|\n]*?-->/', // 替换smarty注释
'/<!--[^<|>|{|\n]*?-->/', // 替换不换行的html注释
'/(href=["|\'])\.\.\/(.*?)(["|\'])/i', // 替换相对链接
'/((?:background|src)\s*=\s*["|\'])(?:\.\/|\.\.\/)?(images\/.*?["|\'])/is', // 在images前加上 $tmp_dir
'/((?:background|background-image):\s*?url\()(?:\.\/|\.\.\/)?(images\/)/is', // 在images前加上 $tmp_dir
'/{nocache}(.+?){\/nocache}/ise', //无缓存模块
);
$replace = array(
'\1',
'',
'\1\2\3',
'\1' . $tmp_dir . '\2',
'\1' . $tmp_dir . '\2',
"'{insert name=\"nocache\" ' . '" . $this->_echash . "' . base64_encode('\\1') . '}'",
); return preg_replace($pattern, $replace, $source);
}
各位大神,ecmall的,preg_replace怎么改成preg_replace_callback
'/<!--[^>|\n]*?({.+?})[^<|{|\n]*?-->/', // 替换smarty注释
'/<!--[^<|>|{|\n]*?-->/', // 替换不换行的html注释
'/(href=["|\'])\.\.\/(.*?)(["|\'])/i', // 替换相对链接
'/((?:background|src)\s*=\s*["|\'])(?:\.\/|\.\.\/)?(images\/.*?["|\'])/is', // 在images前加上 $tmp_dir
'/((?:background|background-image):\s*?url\()(?:\.\/|\.\.\/)?(images\/)/is', // 在images前加上 $tmp_dir
//'/{nocache}(.+?){\/nocache}/ise', //无缓存模块
//'/{nocache}(.+?){\/nocache}/is', //无缓存模块
);
$pattern_callback = '/{nocache}(.+?){\/nocache}/is';
$replace = array(
'\1',
'',
'\1\2\3',
'\1' . $tmp_dir . '\2',
'\1' . $tmp_dir . '\2',
//"'{insert name=\"nocache\" ' . '" . $this->_echash . "' . base64_encode('\\1') . '}'",
);
//$replace_callback = "'{insert name=\"nocache\" ' . '" . $this->_echash . "' . base64_encode('\\1') . '}'";
$source = preg_replace($pattern, $replace, $source);
//return preg_replace($pattern, $replace, $source);
return preg_replace_callback($pattern_callback,
function ($matches) {
return '{insert name=\"nocache\" ' . $this->_echash . base64_encode($matches[1]) . '}';
}
, $source);try.