feat: 富文本相对路径替换

master
yin5th 2023-12-07 09:57:40 +08:00
parent af23d76c52
commit bf74a6b4d3
1 changed files with 9 additions and 0 deletions

View File

@ -32,6 +32,13 @@ use think\facade\Db;
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']) : '';
if (empty($goodsDetailArr['content'])) {
$goodsDetailArr['content'] = '<img src="'.$goodsDetailArr['image'].'" />';
} else {
$goodsDetailArr['content'] = self::replaceStoragePath($goodsDetailArr['content']);
}
// 新增点击记录