コード例 #1
0
 /**
  * 取得查询参数(有值才返回)
  *
  * @return  array(
  *              'keyword'   => array('aa', 'bb'),
  *              'cate_id'   => 2,
  *              'layer'     => 2, // 分类层级
  *              'brand'     => 'ibm',
  *              'region_id' => 23,
  *              'price'     => array('min' => 10, 'max' => 100),
  *          )
  */
 function _get_query_param()
 {
     $url_param = "";
     static $res = null;
     if ($res === null) {
         $res = array();
         // keyword
         $keyword = safe(trim($_GET['keyword']));
         if ($keyword != '') {
             $this->assign('keyword', $keyword);
             $this->assign('keyword_param', '&keyword=' . $keyword);
             //$keyword = preg_split("/[\s," . Lang::get('comma') . Lang::get('whitespace') . "]+/", $keyword);
             $tmp = str_replace(array(Lang::get('comma'), Lang::get('whitespace'), ' '), ',', $keyword);
             /* xunsearch SCWS 分词 */
             try {
                 // 创建初始XS项目,否则无法定位服务端会抛出异常
                 $xs = new XS('95180');
                 // 创建分词对象实例
                 $tokenizer = new XSTokenizerScws();
                 // 让返回的分词结果忽略标点符号
                 $tokenizer->setIgnore(true);
                 $tokenizer->setDuality(true);
                 // 对分词结果中的连续单字做二元组合
                 $tokenizer->setMulti(0x4);
                 // 设置复合分词方案:0x01-长词切为短词,0x02-单字二元,0x04-重要单字,0x08-全部单字
                 $tmp = $tokenizer->getResult($tmp);
                 // 返回分词结果
                 $keyword = array();
                 foreach ($tmp as $word) {
                     array_push($keyword, $word['word']);
                 }
             } catch (XSException $e) {
                 echo $e;
                 // 直接输出异常描述
                 if (defined('DEBUG')) {
                     // 如果是 DEBUG 模式,则输出堆栈情况
                     echo "\n" . $e->getTraceAsString() . "\n";
                 }
             }
             $res['keyword'] = $keyword;
         }
         // cate_id
         if (isset($_GET['cate_id']) && intval($_GET['cate_id']) > 0) {
             $url_param .= "&cate_id=" . $_GET['cate_id'];
             $this->assign('cate_id_param', "&cate_id=" . intval($_GET['cate_id']));
             $res['cate_id'] = $cate_id = intval($_GET['cate_id']);
             $gcategory_mod =& bm('gcategory');
             $res['layer'] = $gcategory_mod->get_layer($cate_id, true);
         }
         //stock 是否有货
         if (isset($_POST['stock']) && $_POST['stock'] == "on") {
             $this->assign('stock_status', true);
             $res['stock'] = true;
         }
         $res['url_param'] = $url_param;
     }
     return $res;
 }
コード例 #2
0
 /**
  * 取得查询参数(有值才返回)
  *
  * @return  array(
  *              'keyword'   => array('aa', 'bb'),
  *              'cate_id'   => 2,
  *              'layer'     => 2, // 分类层级
  *              'brand'     => 'ibm',
  *              'region_id' => 23,
  *              'price'     => array('min' => 10, 'max' => 100),
  *          )
  */
 function _get_query_param()
 {
     $url_param = "";
     static $res = null;
     if ($res === null) {
         $res = array();
         // keyword
         $keyword = safe(trim($_GET['keyword']));
         if ($keyword != '') {
             //$url_param .= "&keyword=".$keyword;
             $this->assign('keyword', $keyword);
             $this->assign('keyword_param', '&keyword=' . $keyword);
             //$keyword = preg_split("/[\s," . Lang::get('comma') . Lang::get('whitespace') . "]+/", $keyword);
             $tmp = str_replace(array(Lang::get('comma'), Lang::get('whitespace'), ' '), ',', $keyword);
             /* xunsearch SCWS 分词 */
             try {
                 // 创建初始XS项目,否则无法定位服务端会抛出异常
                 $xs = new XS('95180');
                 // 创建分词对象实例
                 $tokenizer = new XSTokenizerScws();
                 // 让返回的分词结果忽略标点符号
                 $tokenizer->setIgnore(true);
                 $tokenizer->setDuality(true);
                 // 对分词结果中的连续单字做二元组合
                 $tokenizer->setMulti(0x4);
                 // 设置复合分词方案:0x01-长词切为短词,0x02-单字二元,0x04-重要单字,0x08-全部单字
                 $tmp = $tokenizer->getResult($tmp);
                 // 返回分词结果
                 $keyword = array();
                 foreach ($tmp as $word) {
                     array_push($keyword, $word['word']);
                 }
             } catch (XSException $e) {
                 echo $e;
                 // 直接输出异常描述
                 if (defined('DEBUG')) {
                     // 如果是 DEBUG 模式,则输出堆栈情况
                     echo "\n" . $e->getTraceAsString() . "\n";
                 }
             }
             $res['keyword'] = $keyword;
         }
         // cate_id
         if (isset($_GET['cate_id']) && intval($_GET['cate_id']) > 0) {
             $url_param .= "&cate_id=" . $_GET['cate_id'];
             $this->assign('cate_id_param', "&cate_id=" . intval($_GET['cate_id']));
             $res['cate_id'] = $cate_id = intval($_GET['cate_id']);
             $gcategory_mod =& bm('gcategory');
             $res['layer'] = $gcategory_mod->get_layer($cate_id, true);
         }
         // brand
         /*
         if (isset($_GET['brand']))
         {
             $brand = trim($_GET['brand']);
             $res['brand'] = $brand;
         }
         */
         // region_id
         /*
         if (isset($_GET['region_id']) && intval($_GET['region_id']) > 0)
         {
             $res['region_id'] = intval($_GET['region_id']);
         }
         */
         // price
         /*
         if (isset($_GET['price']))
         {
             $arr = explode('-', $_GET['price']);
             $min = abs(floatval($arr[0]));
             $max = abs(floatval($arr[1]));
             if ($min * $max > 0 && $min > $max)
             {
                 list($min, $max) = array($max, $min);
             }
         
             $res['price'] = array(
                 'min' => $min,
                 'max' => $max
             );
         }
         */
         // tyioocom 获取属性参数
         /*
         			if (isset($_GET['props']))
         			{
         				if($this->_check_query_param_by_props()){
         					$res['props'] = trim($_GET['props']);
         				}
         			}
         */
         //attribute 商品属性
         if (isset($_GET['attr']) && isset($_GET['cate_id']) && intval($_GET['cate_id']) > 0) {
             $url_param .= "&attr=" . $_GET['attr'];
             $this->assign('attr', "&attr=" . $_GET['attr']);
             $value_id_arr = explode(',', $_GET['attr']);
             $attr_arr = array();
             foreach ($value_id_arr as $value) {
                 if ($value) {
                     $arr_temp = array_values($this->_attribute_value_mod->get_attr_values_by_value_id($value));
                     array_push($attr_arr, $arr_temp[0]);
                 } else {
                     array_push($attr_arr, array('value_id' => 0, 'attr_id' => 0, 'attr_value' => '', 'sort_order' => 0));
                 }
             }
             $res['attr'] = $attr_arr;
         }
         //stock 是否有货
         if (isset($_GET['stock']) && $_GET['stock'] == "on") {
             $this->assign('stock_status', true);
             $res['stock'] = true;
         }
         $res['url_param'] = $url_param;
     }
     return $res;
 }
コード例 #3
0
ファイル: story.app.php プロジェクト: 184609680/wcy_O2O_95180
 function search()
 {
     $cate_id = !empty($_GET['cate_id']) ? intval($_GET['cate_id']) : 15;
     //如果cate_id为空则默认显示商城快讯
     $this->assign("cid", $cate_id);
     /* 取得当前分类及子孙分类cate_id */
     $cate_ids = array();
     if ($cate_id > 0 && $cate_id != $this->_ACC[ACC_SYSTEM]) {
         $cate_ids = $this->_acategory_mod->get_descendant($cate_id);
         if (!$cate_ids) {
             $this->show_no();
             return;
         }
     } else {
         $this->show_no();
         return;
     }
     $this->_cate_ids = $cate_ids;
     /* 文章分类 */
     $acategories = $this->_get_acategory($cate_id);
     foreach ($acategories as $k => &$cate) {
         $sql = "SELECT COUNT(*) FROM {$this->_article_mod->table} WHERE cate_id = " . $cate['cate_id'];
         $cate['count'] = $this->_article_mod->getone($sql);
     }
     $keyword = isset($_POST['keyword']) ? $_POST['keyword'] : trim($_GET['keyword']);
     $this->assign("q", $keyword);
     $curlocal[] = array('text' => $keyword);
     $this->_curlocal($curlocal);
     $tmp = str_replace(array(Lang::get('comma'), Lang::get('whitespace'), ' '), ',', $keyword);
     try {
         // 创建初始XS项目,否则无法定位服务端会抛出异常
         $xs = new XS('95180');
         // 创建分词对象实例
         $tokenizer = new XSTokenizerScws();
         // 让返回的分词结果忽略标点符号
         $tokenizer->setIgnore(true);
         $tokenizer->setDuality(true);
         // 对分词结果中的连续单字做二元组合
         $tokenizer->setMulti(0x4);
         // 设置复合分词方案:0x01-长词切为短词,0x02-单字二元,0x04-重要单字,0x08-全部单字
         $tmp = $tokenizer->getResult($tmp);
         // 返回分词结果
         $keyword = array();
         foreach ($tmp as $word) {
             array_push($keyword, $word['word']);
         }
     } catch (XSException $e) {
         echo $e;
         // 直接输出异常描述
         if (defined('DEBUG')) {
             // 如果是 DEBUG 模式,则输出堆栈情况
             echo "\n" . $e->getTraceAsString() . "\n";
         }
     }
     $condition = $this->_get_conditions_by_keyword($keyword, $cached);
     /* 搜索故事列表 */
     $page = $this->_get_page();
     $articles = $this->_article_mod->find(array('conditions' => $condition, 'order' => "add_time desc", 'limit' => $page['limit']));
     $user_mod =& m('member');
     foreach ($articles as $k => $article) {
         $articles[$k]['add_time'] = date("Y.m.d", $articles[$k]['add_time']);
         $articles[$k]['content'] = str_replace(' ', '', $articles[$k]['content']);
         $articles[$k]['wx'] = $this->generateQRfromGoogle($articles[$k]['article_id']);
         $articles[$k]['tag'] = unserialize($articles[$k]['tag']);
         $info = $user_mod->get_info($articles[$k]['uid']);
         $articles[$k]['author'] = $info['user_name'];
         $articles[$k]['portrait'] = portrait($info['user_id'], $info['portrait'], 'middle');
     }
     $page['item_count'] = count($articles);
     $this->_format_page($page);
     $this->assign('page_info', $page);
     // 页面标题
     $category = $this->_acategory_mod->get_info($cate_id);
     $this->_config_seo('title', $category['cate_name'] . ' - ' . Conf::get('site_title'));
     $this->assign('stories', $articles);
     $this->assign("hottags", $this->hot_tag());
     $this->_format_page($page);
     $this->assign('page_info', $page);
     $this->assign('acategories', $acategories);
     $this->display('story.index.html');
 }