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

This commit is contained in:
devil 2020-08-23 20:42:49 +08:00
parent ea0a606a6d
commit 217958b0dd
2 changed files with 17 additions and 3 deletions

View File

@ -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;
}

View File

@ -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) : '',
// 应用商店地址