Przeglądaj źródła

增加搜索前置过滤

stanley-king 8 lat temu
rodzic
commit
a2b36b5e90
1 zmienionych plików z 27 dodań i 5 usunięć
  1. 27 5
      mobile/control/search.php

+ 27 - 5
mobile/control/search.php

@@ -8,6 +8,7 @@ require_once (BASE_ROOT_PATH . '/helper/history_helper.php');
 require_once (BASE_ROOT_PATH . '/helper/special_helper.php');
 require_once (BASE_ROOT_PATH . '/helper/goods_helper.php');
 require_once (BASE_ROOT_PATH . '/helper/search/tcp_client.php');
+require_once (BASE_ROOT_PATH . '/helper/search/util.php');
 
 define('MOBILE_SERVER',true);
 
@@ -23,10 +24,14 @@ class search_param
         $this->mBrandId = 0;
         $this->mHotId = 0;
 
-        if (!empty(trim($param['keyword']))) {
-            $this->mKeyWord = trim(urldecode($param['keyword']));
-            $helper = new history_helper();
-            $helper->add_word($this->mKeyWord);
+        if (!empty(trim($param['keyword'])))
+        {
+            $keywod = trim(urldecode($param['keyword']));
+            if($this->check($keywod)) {
+                $this->mKeyWord = trim(urldecode($param['keyword']));
+                $helper = new history_helper();
+                $helper->add_word($this->mKeyWord);
+            }
         }
         if (intval($param['brand_id']) > 0) {
             $this->mBrandId = intval($param['brand_id']);
@@ -50,10 +55,27 @@ class search_param
             return $result;
         }
     }
-
     public function brand_id() {
         return $this->mBrandId;
     }
+    private function mb_str_split( $string ) {
+        return preg_split('/(?<!^)(?!$)/u', $string );
+    }
+    private function check($keyword)
+    {
+        $words = [];
+        foreach ($this->mb_str_split($keyword) as $word)
+        {
+            if(search\filter::filter($word)) {
+                $words[] = $word;
+            }
+        }
+        if(empty($words)) {
+            return false;
+        } else {
+            return true;
+        }
+    }
 }
 
 class searchControl extends mobileHomeControl