Browse Source

限制朋友圈文字长度,评论长度,连接+跳转标签

master
wanghongjun 7 months ago
parent
commit
f5d1a86b48
  1. 33
      app/enterprise/controller/Posts.php
  2. 1
      app/lang/en_us.php
  3. 1
      app/lang/zh_cn.php

33
app/enterprise/controller/Posts.php

@ -270,6 +270,11 @@ class Posts extends BaseController
$type = ''; $type = '';
if (!empty($content)) { if (!empty($content)) {
$type = '1'; $type = '1';
$detectionRes = $this->detectionProcessingText($content);
if (isset($detectionRes['error'])) {
return error($detectionRes['error']);
}
$content = $detectionRes['content'];
} }
if (!empty($imgArr)) { if (!empty($imgArr)) {
if (is_array($imgArr) && count($imgArr) > 9) { if (is_array($imgArr) && count($imgArr) > 9) {
@ -395,6 +400,28 @@ class Posts extends BaseController
return $data; return $data;
} }
// 检查文本输入内容
protected function detectionProcessingText($content, $type = 1)
{
// 限制文字内容长度
$text = strip_tags($content);
$textLen = mb_strlen($text);
$length = 2048;
$error = lang('posts.msgContentLimit') . $textLen;
if ($type == 2) {
$length = 500;
$error = lang('im.msgContentLimit') . $textLen;
} else {
$content = preg_link($content);
}
if ($textLen > $length) {
return ['error' => $error];
}
// 接入聊天内容检测服务
event('GreenText',['content'=>$content,'service'=>"chat_detection"]);
return ['content' => $content];
}
// 获取上传草稿帖子数据 // 获取上传草稿帖子数据
public function getLastPosts() public function getLastPosts()
{ {
@ -504,6 +531,12 @@ class Posts extends BaseController
return error(lang('system.fail')); return error(lang('system.fail'));
} }
$detectionRes = $this->detectionProcessingText($content, 2);
if (isset($detectionRes['error'])) {
return error($detectionRes['error']);
}
$content = $detectionRes['content'];
$pid = $this->request->param('pid', 0); $pid = $this->request->param('pid', 0);
$reply_user_id = 0; $reply_user_id = 0;
if (!empty($pid)) { if (!empty($pid)) {

1
app/lang/en_us.php

@ -170,5 +170,6 @@ return [
'img_max_length' => 'Up to 9 images can be uploaded', 'img_max_length' => 'Up to 9 images can be uploaded',
'comment_del' => 'This comment has been deleted', 'comment_del' => 'This comment has been deleted',
'postsDel' => 'This content has been deleted', 'postsDel' => 'This content has been deleted',
'msgContentLimit' => 'The length of the content you entered is too long',
] ]
]; ];

1
app/lang/zh_cn.php

@ -169,5 +169,6 @@ return [
'img_max_length' => '图片最多上传9张', 'img_max_length' => '图片最多上传9张',
'comment_del' => '此条评论已被删除', 'comment_del' => '此条评论已被删除',
'postsDel' => '该内容已被删除', 'postsDel' => '该内容已被删除',
'msgContentLimit' => '你输入的内容长度太长了!',
] ]
]; ];
Loading…
Cancel
Save