mirror of
https://gitee.com/zongzhige/shopxo.git
synced 2024-12-03 12:29:57 +08:00
附件url替换使用配置文件地址
This commit is contained in:
parent
ea0a606a6d
commit
217958b0dd
@ -34,16 +34,30 @@ class ResourcesService
|
|||||||
*/
|
*/
|
||||||
public static function ContentStaticReplace($content, $type = 'get')
|
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)
|
switch($type)
|
||||||
{
|
{
|
||||||
// 读取内容
|
// 读取内容
|
||||||
case 'get':
|
case 'get':
|
||||||
return str_replace('src="/static/', 'src="'.__MY_PUBLIC_URL__.'static/', $content);
|
return str_replace('src="/static/', 'src="'.$attachment_host_path, $content);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// 内容写入
|
// 内容写入
|
||||||
case 'add':
|
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;
|
return $content;
|
||||||
}
|
}
|
||||||
|
@ -57,7 +57,7 @@ return [
|
|||||||
// 导航缓存信息
|
// 导航缓存信息
|
||||||
'cache_navigation_key' => 'cache_navigation_data_',
|
'cache_navigation_key' => 'cache_navigation_data_',
|
||||||
|
|
||||||
// 附件host, 数据库图片地址以/static/...开头
|
// 附件host、最后不要带/斜杠结尾, 数据库图片地址以/static/...开头
|
||||||
'attachment_host' => defined('__MY_PUBLIC_URL__') ? substr(__MY_PUBLIC_URL__, 0, -1) : '',
|
'attachment_host' => defined('__MY_PUBLIC_URL__') ? substr(__MY_PUBLIC_URL__, 0, -1) : '',
|
||||||
|
|
||||||
// 应用商店地址
|
// 应用商店地址
|
||||||
|
Loading…
Reference in New Issue
Block a user