feat: 开放API文章相关
This commit is contained in:
@@ -1,2 +1,70 @@
|
||||
<?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 rtrim($domain, '/') . '/' . ltrim($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 rtrim($domain, '/') . '/' . ltrim($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
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user