正在显示
1 个修改的文件
包含
12 行增加
和
14 行删除
| @@ -212,18 +212,20 @@ class NewsLogic extends BaseLogic | @@ -212,18 +212,20 @@ class NewsLogic extends BaseLogic | ||
| 212 | return $this->success($param); | 212 | return $this->success($param); |
| 213 | } | 213 | } |
| 214 | 214 | ||
| 215 | + /** | ||
| 216 | + * @remark :处理text | ||
| 217 | + * @name :handleText | ||
| 218 | + * @author :lyh | ||
| 219 | + * @method :post | ||
| 220 | + * @time :2024/11/7 17:20 | ||
| 221 | + */ | ||
| 215 | public function handleText($text){ | 222 | public function handleText($text){ |
| 216 | $pattern = '/<img\s+[^>]*src=["\']([^"\']+)["\']/i'; | 223 | $pattern = '/<img\s+[^>]*src=["\']([^"\']+)["\']/i'; |
| 217 | $matches = []; | 224 | $matches = []; |
| 218 | preg_match_all($pattern, $text, $matches); | 225 | preg_match_all($pattern, $text, $matches); |
| 219 | - $updatedSources = $this->saveBase64Images($matches[1]); | 226 | + $text = $this->saveBase64Images($matches[1]); |
| 220 | if($this->user['project_id'] == 1618){ | 227 | if($this->user['project_id'] == 1618){ |
| 221 | - @file_put_contents(storage_path('logs/lyh_error.log'), var_export($updatedSources, true) . PHP_EOL, FILE_APPEND); | ||
| 222 | - } | ||
| 223 | - if(!empty($updatedSources)){ | ||
| 224 | - foreach($updatedSources as $k => $v){ | ||
| 225 | - $text = str_replace($v, $k, $text); | ||
| 226 | - } | 228 | + @file_put_contents(storage_path('logs/lyh_error.log'), var_export($text, true) . PHP_EOL, FILE_APPEND); |
| 227 | } | 229 | } |
| 228 | return $this->success($text); | 230 | return $this->success($text); |
| 229 | } | 231 | } |
| @@ -235,20 +237,16 @@ class NewsLogic extends BaseLogic | @@ -235,20 +237,16 @@ class NewsLogic extends BaseLogic | ||
| 235 | * @method :post | 237 | * @method :post |
| 236 | * @time :2024/11/7 16:52 | 238 | * @time :2024/11/7 16:52 |
| 237 | */ | 239 | */ |
| 238 | - public function saveBase64Images($imageSources) | 240 | + public function saveBase64Images($imageSources,&$text) |
| 239 | { | 241 | { |
| 240 | - $updatedSources = []; | ||
| 241 | foreach ($imageSources as $src) { | 242 | foreach ($imageSources as $src) { |
| 242 | if (preg_match('/^data:image\/(png|jpg|jpeg|gif);base64,/', $src, $match)) { | 243 | if (preg_match('/^data:image\/(png|jpg|jpeg|gif);base64,/', $src, $match)) { |
| 243 | $imageType = $match[1]; // Image type (png, jpg, etc.) | 244 | $imageType = $match[1]; // Image type (png, jpg, etc.) |
| 244 | $imageUrl = $this->manager_uploads($src,$imageType); | 245 | $imageUrl = $this->manager_uploads($src,$imageType); |
| 245 | - if($this->user['project_id'] == 1618){ | ||
| 246 | - @file_put_contents(storage_path('logs/lyh_error.log'), var_export($imageUrl, true) . PHP_EOL, FILE_APPEND); | 246 | + $text = str_replace($src, $imageUrl, $text); |
| 247 | } | 247 | } |
| 248 | - $updatedSources[$imageUrl] = $src; | ||
| 249 | } | 248 | } |
| 250 | - } | ||
| 251 | - return $this->success($updatedSources); | 249 | + return $this->success($text); |
| 252 | } | 250 | } |
| 253 | /** | 251 | /** |
| 254 | * @remark :自调用 | 252 | * @remark :自调用 |
-
请 注册 或 登录 后发表评论