脚本处理
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace app\command;
|
||||
|
||||
use app\common\model\InquiryLog;
|
||||
use app\common\model\User;
|
||||
use app\common\model\UserSn;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Helper\Table;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use support\Db;
|
||||
|
||||
class DomainCommand extends Command
|
||||
{
|
||||
protected static $defaultName = 'domain';
|
||||
protected static $defaultDescription = '';
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$log = new InquiryLog();
|
||||
$list = $log->orderBy('id', 'desc')->get();
|
||||
|
||||
foreach ($list as $item) {
|
||||
if (!$item->content) {
|
||||
continue;
|
||||
}
|
||||
$item->content = processRichTextImagesEnhanced($item->content);
|
||||
$item->save();
|
||||
}
|
||||
return self::SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 增强版 - 为富文本内容中的图片URL添加域名前缀
|
||||
*
|
||||
* @param string $content 富文本HTML内容
|
||||
* @param string $domain 域名(如: https://fdesk.hnxinyouhe.com)
|
||||
* @return string 处理后的富文本内容
|
||||
*/
|
||||
function processRichTextImagesEnhanced($content, $domain = 'https://fdesk.hnxinyouhe.com') {
|
||||
// 确保域名不以斜杠结尾
|
||||
$domain = rtrim($domain, '/');
|
||||
|
||||
// 要处理的属性列表
|
||||
$attributes = ['src', 'data-href', 'href', 'data-src', 'data-original'];
|
||||
|
||||
foreach ($attributes as $attr) {
|
||||
$content = preg_replace(
|
||||
'/('.$attr.'=["\'])(\/uploads\/)/i',
|
||||
'$1' . $domain . '$2',
|
||||
$content
|
||||
);
|
||||
}
|
||||
|
||||
return $content;
|
||||
}
|
||||
Reference in New Issue
Block a user