Browse Source

优化采集时的数据过滤

magicblack 3 years ago
parent
commit
3321511bc7
2 changed files with 30 additions and 23 deletions
  1. 2 0
      application/common/model/Collect.php
  2. 28 23
      application/common/model/Vod.php

+ 2 - 0
application/common/model/Collect.php

@@ -703,6 +703,7 @@ class Collect extends Base {
                         $tmp = $this->syncImages($config_sync_pic,  $v['vod_pic'], 'vod');
                         $v['vod_pic'] = mac_filter_xss((string)$tmp['pic']);
                         $msg = $tmp['msg'];
+                        $v = model('Vod')->formatDataBeforeDb($v);
                         $vod_id = model('Vod')->insert($v, false, true);
                         if ($vod_id > 0) {
                             $vod_search->checkAndUpdateTopResults(['vod_id' => $vod_id] + $v, true);
@@ -929,6 +930,7 @@ class Collect extends Base {
                             $update['vod_time'] = time();
                             $where = [];
                             $where['vod_id'] = $info['vod_id'];
+                            $update = model('Vod')->formatDataBeforeDb($update);
                             $res = model('Vod')->where($where)->update($update);
                             $color = 'green';
                             if ($res === false) {

+ 28 - 23
application/common/model/Vod.php

@@ -626,7 +626,32 @@ class Vod extends Base {
         unset($data['uptime']);
         unset($data['uptag']);
 
-        // xss过滤、长度裁剪
+        $data = $this->formatDataBeforeDb($data);
+        if(!empty($data['vod_id'])){
+            $where=[];
+            $where['vod_id'] = ['eq',$data['vod_id']];
+            $res = $this->allowField(true)->where($where)->update($data);
+        }
+        else{
+            $data['vod_plot'] = 0;
+            $data['vod_plot_name']='';
+            $data['vod_plot_detail']='';
+            $data['vod_time_add'] = time();
+            $data['vod_time'] = time();
+            $res = $this->allowField(true)->insert($data, false, true);
+            if ($res > 0) {
+                model('VodSearch')->checkAndUpdateTopResults(['vod_id' => $res] + $data);
+            }
+        }
+        if(false === $res){
+            return ['code'=>1002,'msg'=>lang('save_err').':'.$this->getError() ];
+        }
+        return ['code'=>1,'msg'=>lang('save_ok')];
+    }
+
+    // xss过滤、长度裁剪
+    public function formatDataBeforeDb($data)
+    {
         $filter_fields = [
             'vod_name'         => 255,
             'vod_sub'          => 255,
@@ -679,29 +704,9 @@ class Vod extends Base {
                 continue;
             }
             $data[$filter_field] = mac_filter_xss($data[$filter_field]);
-            $data[$filter_field] = mb_substr($data[$filter_field], 0, $field_length - 1);
-        }
-
-        if(!empty($data['vod_id'])){
-            $where=[];
-            $where['vod_id'] = ['eq',$data['vod_id']];
-            $res = $this->allowField(true)->where($where)->update($data);
-        }
-        else{
-            $data['vod_plot'] = 0;
-            $data['vod_plot_name']='';
-            $data['vod_plot_detail']='';
-            $data['vod_time_add'] = time();
-            $data['vod_time'] = time();
-            $res = $this->allowField(true)->insert($data, false, true);
-            if ($res > 0) {
-                model('VodSearch')->checkAndUpdateTopResults(['vod_id' => $res] + $data);
-            }
+            $data[$filter_field] = mb_substr($data[$filter_field], 0, $field_length);
         }
-        if(false === $res){
-            return ['code'=>1002,'msg'=>lang('save_err').':'.$this->getError() ];
-        }
-        return ['code'=>1,'msg'=>lang('save_ok')];
+        return $data;
     }
 
     public function savePlot($data)