12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- <?php
- /**
- * Created by PhpStorm.
- * User: stanley-king
- * Date: 2017/3/19
- * Time: 下午10:46
- */
- require_once (BASE_ROOT_PATH . '/helper/history_helper.php');
- class search_param
- {
- private $mKeyWord;
- private $mBrandId;
- private $mHotId;
- public function __construct($param)
- {
- $this->mKeyWord = '';
- $this->mBrandId = 0;
- $this->mHotId = 0;
- 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']);
- }
- if (!empty(trim($param['hot_id']))) {
- $this->mHotId = intval($param['hot_id']);
- }
- }
- public function format()
- {
- if (empty($this->mKeyWord) && $this->mBrandId == 0 && $this->mHotId == 0) {
- return false;
- } else {
- $result = [];
- $result['keyword'] = $this->mKeyWord;
- $result['brand_id'] = $this->mBrandId;
- $result['hot_id'] = $this->mHotId;
- 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;
- }
- }
- }
|