feat: 富文本相对路径替换
parent
af23d76c52
commit
bf74a6b4d3
|
@ -32,6 +32,13 @@ use think\facade\Db;
|
||||||
|
|
||||||
class GoodsLogic extends Logic
|
class GoodsLogic extends Logic
|
||||||
{
|
{
|
||||||
|
private static function replaceStoragePath ($content, $domain = ''){
|
||||||
|
if (empty($domain)) {
|
||||||
|
$domain = request()->domain();
|
||||||
|
}
|
||||||
|
$pregRule = "/<[img|IMG].*?src=[\'|\"][\/uploads]{1}(.*?(?:[\.jpg|\.jpeg|\.png|\.gif|\.bmp]))[\'|\"].*?[\/]?>/";
|
||||||
|
return preg_replace($pregRule, '< img src="' . $domain . '/${1}" style="max-width:100%">', (string)$content );
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* 商品详情
|
* 商品详情
|
||||||
*/
|
*/
|
||||||
|
@ -110,6 +117,8 @@ class GoodsLogic extends Logic
|
||||||
$goodsDetailArr['poster'] = !empty($goodsDetailArr['poster']) ? UrlServer::getFileUrl($goodsDetailArr['poster']) : '';
|
$goodsDetailArr['poster'] = !empty($goodsDetailArr['poster']) ? UrlServer::getFileUrl($goodsDetailArr['poster']) : '';
|
||||||
if (empty($goodsDetailArr['content'])) {
|
if (empty($goodsDetailArr['content'])) {
|
||||||
$goodsDetailArr['content'] = '<img src="'.$goodsDetailArr['image'].'" />';
|
$goodsDetailArr['content'] = '<img src="'.$goodsDetailArr['image'].'" />';
|
||||||
|
} else {
|
||||||
|
$goodsDetailArr['content'] = self::replaceStoragePath($goodsDetailArr['content']);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 新增点击记录
|
// 新增点击记录
|
||||||
|
|
Loading…
Reference in New Issue