lizhen_gitee vor 10 Monaten
Ursprung
Commit
39c337c03f
2 geänderte Dateien mit 23 neuen und 48 gelöschten Zeilen
  1. 0 47
      application/api/controller/Topicdongtai.php
  2. 23 1
      application/common/library/Keyworld.php

+ 0 - 47
application/api/controller/Topicdongtai.php

@@ -13,48 +13,8 @@ class Topicdongtai extends Api
     protected $noNeedLogin = ['info','floor_info','topic_list'];
     protected $noNeedRight = ['*'];
 
-    //发布动态
-    public function addone(){
-        $content = input('content','');
-        $images = input('images','');
-        $topic_id = input('topic_id','');
-        if(!$content && !$images){
-            $this->error(__('Invalid parameters'));
-        }
-
-        //关键字替换
-        $content = Keyworld::sensitive($content);
-
-        $data = [
-            'topic_id' => $topic_id,
-            'user_id' => $this->auth->id,
-            'content' => $content,
-            'images' => $images,
-            'longitude' => input('longitude',''),
-            'latitude'  => input('latitude',''),
-            'createtime' => time(),
-            'updatetime' => time(),
-        ];
 
 
-        Db::startTrans();
-        $id = Db::name('topic_dongtai')->insertGetId($data);
-        //圈子新增一个贴
-        $rs = Db::name('topic_hub')->where('id',$topic_id)->setInc('t_number');
-
-        //tag任务赠送金币
-        //发动态奖励
-        $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,16);
-        if($task_rs === false){
-            Db::rollback();
-            $this->error('完成任务赠送奖励失败');
-        }
-
-        Db::commit();
-
-        $this->success('success',$id);
-    }
-
     //自己看列表
     //某用户的帖子列表
     public function my_lists(){
@@ -410,13 +370,6 @@ class Topicdongtai extends Api
                 $this->error('您的网络开小差啦~');
             }
         }
-        //tag任务赠送金币
-        //发动态奖励
-//        $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,16);
-//        if($task_rs === false){
-//            Db::rollback();
-//            $this->error('完成任务赠送奖励失败');
-//        }
 
         Db::commit();
 

+ 23 - 1
application/common/library/Keyworld.php

@@ -16,7 +16,7 @@ class Keyworld
      * @param string $string 要过滤的内容
      * @return string $log 处理结果
      */
-    public static function sensitive($string){
+    public static function sensitive_old($string){
         $count = 0; //违规词的个数
         $sensitiveWord = '';  //违规词
         $stringAfter = $string;  //替换后的内容
@@ -46,6 +46,28 @@ class Keyworld
         return $stringAfter;
     }
 
+    public static function sensitive($string){
+        if(empty($string)){
+            return $string;
+        }
+
+        $list = config('keyworld');  //定义敏感词数组
+        $replaceArray = [];          //含有的违禁词集合
+
+        foreach($list as $key => $word){
+            if(empty($word)){
+                continue;
+            }
+            $start = strpos($string,$word);
+            if($start !== false){
+                $replaceArray[$word] = '*';
+            }
+        }
+
+        $stringAfter = strtr($string, $replaceArray); //结果替换
+        return $stringAfter;
+    }
+
     public static function checkAction($data,$fields){
         //$string = 'likeyou小白喜欢小黑爱着的大黄'; //要过滤的内容
         foreach($data as $key => $string){