71 lines
1.6 KiB
PHP
71 lines
1.6 KiB
PHP
<?php
|
||
// 这是系统自动生成的公共文件
|
||
|
||
if (!function_exists('image_domain_concat')) {
|
||
/**
|
||
* 图片域名拼接
|
||
* @param $path
|
||
* @return string
|
||
*/
|
||
function image_domain_concat($path)
|
||
{
|
||
if (empty($path)) {
|
||
return '';
|
||
}
|
||
|
||
$domain = env('OPENAPI.RESOURCE_IMAGES_DOMAIN');
|
||
if (empty($domain)) {
|
||
return $path;
|
||
}
|
||
|
||
return url_join($domain, $path);
|
||
}
|
||
}
|
||
|
||
if (!function_exists('video_domain_concat')) {
|
||
/**
|
||
* 视频域名拼接
|
||
* @param $path
|
||
* @return string
|
||
*/
|
||
function video_domain_concat($path)
|
||
{
|
||
if (empty($path)) {
|
||
return '';
|
||
}
|
||
|
||
$domain = env('OPENAPI.RESOURCE_VIDEOS_DOMAIN');
|
||
if (empty($domain)) {
|
||
return $path;
|
||
}
|
||
|
||
return url_join($domain, $path);
|
||
}
|
||
}
|
||
|
||
if (!function_exists('html_image_replace')) {
|
||
/**
|
||
* 替换html中的图片路径
|
||
* @param $html
|
||
* @return string
|
||
*/
|
||
function html_image_replace($html)
|
||
{
|
||
if (empty($html)) {
|
||
return '';
|
||
}
|
||
|
||
return preg_replace_callback('/<img[^>]+src\s*=\s*([\'"])((?:(?!\1).)*)\1[^>]*>/i',
|
||
function($matches) {
|
||
$src = $matches[2];
|
||
if (!empty($src) && !str_starts_with($src, 'http')) {
|
||
// 保留原始标签,只替换src属性
|
||
return str_replace($src, image_domain_concat($src), $matches[0]);
|
||
}
|
||
return $matches[0];
|
||
},
|
||
$html
|
||
);
|
||
}
|
||
}
|