<?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_model extends MY_Model {
    /**
    * Constructor
    */
    public function __construct() 
    {
        parent::__construct(1,1,3);
        $this->load->library('ArrayIconv');
    }
    
    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 = GB_CITY.'_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[] = iconv('gbk','utf-8',$item['keyword']);
				}
			}
			
			$this->mc->set($cache_key, $data, 600);
		}
		
		$keyword = iconv('gbk','utf-8',$keyword);
		$i = 0;
		foreach($data as $key => $value)
		{	
			$strpos = strpos($keyword,$value);

			if($strpos === 0 || $strpos > 0)
			{
				$i++;

				if($i == 3)
				{
					break;
				}

				$result .= iconv('utf-8','gbk',$value).",";
			}
		}

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