脚本处理
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;
|
||||||
|
}
|
||||||
@@ -25,25 +25,4 @@ class TbCommand extends Command
|
|||||||
}
|
}
|
||||||
return self::SUCCESS;
|
return self::SUCCESS;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function replaceRichTextUrls($input) {
|
|
||||||
// 匹配旧域名及其引号包裹情况(包含http/https协议)
|
|
||||||
$pattern = '#(https?://server\.xyh\.hnzhwlkj\.club|["\']https?://server\.xyh\.hnzhwlkj\.club)(/[^\s"\'<>]*)?#iu';
|
|
||||||
|
|
||||||
$replacement = function ($matches) {
|
|
||||||
$originalQuote = '';
|
|
||||||
$path = $matches[2] ?? '';
|
|
||||||
|
|
||||||
// 检测是否以引号开头
|
|
||||||
if (isset($matches[0][0]) && in_array($matches[0][0], ['"', "'"])) {
|
|
||||||
$originalQuote = $matches[0][0];
|
|
||||||
}
|
|
||||||
|
|
||||||
// 构建新URL(强制使用http协议)
|
|
||||||
return $originalQuote . 'http://219.157.255.213:25326' . $path;
|
|
||||||
};
|
|
||||||
|
|
||||||
return preg_replace_callback($pattern, $replacement, $input);
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user