提交 217958b0 编写于 作者: D devil

附件url替换使用配置文件地址

上级 ea0a606a
......@@ -34,16 +34,30 @@ class ResourcesService
*/
public static function ContentStaticReplace($content, $type = 'get')
{
// 配置文件附件url地址
$attachment_host = config('shopxo.attachment_host');
if(empty($attachment_host))
{
$attachment_host = substr(__MY_PUBLIC_URL__, 0, -1);
}
$attachment_host_path = $attachment_host.'/static/';
// 根据类型处理附件地址
switch($type)
{
// 读取内容
case 'get':
return str_replace('src="/static/', 'src="'.__MY_PUBLIC_URL__.'static/', $content);
return str_replace('src="/static/', 'src="'.$attachment_host_path, $content);
break;
// 内容写入
case 'add':
return str_replace(array('src="'.__MY_PUBLIC_URL__.'static/', 'src="'.__MY_ROOT_PUBLIC__.'static/'), 'src="/static/', $content);
$search = [
'src="'.__MY_PUBLIC_URL__.'static/',
'src="'.__MY_ROOT_PUBLIC__.'static/',
'src="'.$attachment_host_path,
];
return str_replace($search, 'src="/static/', $content);
}
return $content;
}
......
......@@ -57,7 +57,7 @@ return [
// 导航缓存信息
'cache_navigation_key' => 'cache_navigation_data_',
// 附件host, 数据库图片地址以/static/...开头
// 附件host、最后不要带/斜杠结尾, 数据库图片地址以/static/...开头
'attachment_host' => defined('__MY_PUBLIC_URL__') ? substr(__MY_PUBLIC_URL__, 0, -1) : '',
// 应用商店地址
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册