<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
 * zsb
 *
 * 业务类库
 *
 * @package         zsb
 * @author          EllisLab Dev Team
 * @copyright       Copyright (c) 2006 - 2014, HOUSE365, Inc.
 * @link            http://nj.sell.house.com
 * @since           Version 1.0
 * @filesource
 */

// ------------------------------------------------------------------------

/**
 * ajax处理类
 *
 *
 * @package         zsb
 * @subpackage      Models
 * @category        Models
 * @author          fisher
 */

class ajax_wang_model extends MY_Model {
    /**
    * Constructor
    */
    public function __construct() 
    {
         parent::__construct(1,1,3);		
		//var_dump($this->db);exit();
       // $this->load->library('ArrayIconv');
		
		//$this->load->library('server',array('appName'=>NS_SELL,'strCheckMethod'=>"",'returnMethod'=>"ary",'returnCharSet'=>"gbk"));
    }
    
    public function array_to_json($array)
    {
        return json_encode(ArrayIconv::Conversion($array, 'gbk', 'utf-8'));
    }

	public function check_sensitive_word($keyword = '')
	{	
		$result = '';

		if(empty($keyword))
		{
			return $result;
		}	

		$cache_key = 'sensitive_word_cache';
		$data = $this->mc->get($cache_key);
		
		if(empty($data))
		{
			$info_arr = $this->dbback->select('keyword')->get('sensitive_word')->result_array();
			
			$data = array();
			if(!empty($info_arr))
			{
				foreach($info_arr as $key => $item)
				{
					$data[] = $item['keyword'];
				}
			}
			
			$this->mc->set($cache_key, $data, 600);
		}
		//echo $keyword.'<br>';
		$i = 0;
		$keyword = iconv('gbk','utf-8',$keyword);
		foreach($data as $key => $value)
		{	//iconv('utf-8','gbk',$value)
			
			$values = iconv('gbk','utf-8',$value);
			$strpos = strpos($keyword,$values);

            
			if($strpos === 0 || $strpos > 0)
			//if($value != '$'  && preg_match('/'.htmlspecialchars($value).'/',$keyword))
			{
				//echo $value.'<br>'.$keyword.'<br>'.'/\\'.$value.'/';die;
				$i++;

				if($i == 3)
				{
					break;
				}
				//echo $value;die;
				$result .= $value.",";
			}
		}

		if(!empty($result))
		{
			$result = substr($result,0,-1);
			
			$html = '';
			if($i == 3)
			{
				$html = '等';
			}
		
			$result = '因标题包含敏感词"'.$result.'"'.$html.'，您的房源将无法发布成功';
		}
		
		return $result;
	}
}
