|
...
|
...
|
@@ -212,18 +212,20 @@ class NewsLogic extends BaseLogic |
|
|
|
return $this->success($param);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :处理text
|
|
|
|
* @name :handleText
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2024/11/7 17:20
|
|
|
|
*/
|
|
|
|
public function handleText($text){
|
|
|
|
$pattern = '/<img\s+[^>]*src=["\']([^"\']+)["\']/i';
|
|
|
|
$matches = [];
|
|
|
|
preg_match_all($pattern, $text, $matches);
|
|
|
|
$updatedSources = $this->saveBase64Images($matches[1]);
|
|
|
|
$text = $this->saveBase64Images($matches[1]);
|
|
|
|
if($this->user['project_id'] == 1618){
|
|
|
|
@file_put_contents(storage_path('logs/lyh_error.log'), var_export($updatedSources, true) . PHP_EOL, FILE_APPEND);
|
|
|
|
}
|
|
|
|
if(!empty($updatedSources)){
|
|
|
|
foreach($updatedSources as $k => $v){
|
|
|
|
$text = str_replace($v, $k, $text);
|
|
|
|
}
|
|
|
|
@file_put_contents(storage_path('logs/lyh_error.log'), var_export($text, true) . PHP_EOL, FILE_APPEND);
|
|
|
|
}
|
|
|
|
return $this->success($text);
|
|
|
|
}
|
|
...
|
...
|
@@ -235,20 +237,16 @@ class NewsLogic extends BaseLogic |
|
|
|
* @method :post
|
|
|
|
* @time :2024/11/7 16:52
|
|
|
|
*/
|
|
|
|
public function saveBase64Images($imageSources)
|
|
|
|
public function saveBase64Images($imageSources,&$text)
|
|
|
|
{
|
|
|
|
$updatedSources = [];
|
|
|
|
foreach ($imageSources as $src) {
|
|
|
|
if (preg_match('/^data:image\/(png|jpg|jpeg|gif);base64,/', $src, $match)) {
|
|
|
|
$imageType = $match[1]; // Image type (png, jpg, etc.)
|
|
|
|
$imageUrl = $this->manager_uploads($src,$imageType);
|
|
|
|
if($this->user['project_id'] == 1618){
|
|
|
|
@file_put_contents(storage_path('logs/lyh_error.log'), var_export($imageUrl, true) . PHP_EOL, FILE_APPEND);
|
|
|
|
}
|
|
|
|
$updatedSources[$imageUrl] = $src;
|
|
|
|
$text = str_replace($src, $imageUrl, $text);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $this->success($updatedSources);
|
|
|
|
return $this->success($text);
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* @remark :自调用
|
...
|
...
|
|