<?php
/**
 * 五十九秒网络购物cms Seo实体类
 * ============================================================================
 * 版权所有 2009-2012 五十九秒网络科技有限公司，并保留所有权利。
 * 网站地址: http://www.59miao.com；
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和
 * 使用；不允许对程序代码以任何形式任何目的的再发布。
 * ============================================================================
 * $Author: longzhang
 * 
*/
if (!defined('IN_59MIAO'))
{
	exit('Access Defined');
}
class SeoModel extends Model {
	public function __construct(){
		parent::__construct();
		$this->_fields = array('id','mark','title','keywords','info');
		$this->_tables = array(DB_FREFIX.'seo');	
		$this->_check = new SeoCheck();	
	}
	//获取一条数据
	public function findOne($where) {
		$_where = array("mark='{$where}'");	
		if (!$this->_check->oneCheck($this, $_where)) $this->_check->error();
		return parent::select(array('id','mark','title','keywords','info'),
											array('where'=>$_where, 'limit'=>'1'));
	}		
	//修改内容
	public function update($where){
		$_where=array("mark='{$where}'");		
		if (!$this->_check->oneCheck($this, $_where)) $this->_check->error();		
		if (!$this->_check->updateCheck($this)) $this->_check->error();			
		$_updateData = $this->getRequest()->update($this->_fields);
		return parent::update($_where, $_updateData);
	}
	public function set_rule(){		
		if(empty($_POST['index'])||empty($_POST['mall']) || empty($_POST['sellerinfo']) ||empty($_POST['all'])
		 || empty($_POST['b2c_category'])
		  ||empty($_POST['tao_category']) || empty($_POST['bitem'])|| empty($_POST['item'])
		   || empty($_POST['promo']) || empty($_POST['artile']) || empty($_POST['artilelist'])
		   || empty($_POST['artile_content'])
		    || empty($_POST['shop'])|| empty($_POST['search'])){
			return false;
		}
		
		$rewrite=trim($_POST['rewrite']);
		$rewrite_suffix=trim($_POST['rewrite_suffix']);
		$index=trim($_POST['index']);
		$mall=trim($_POST['mall']);		
		$sellerinfo=trim($_POST['sellerinfo']);
		$all=trim($_POST['all']);
		$b2c_category=trim($_POST['b2c_category']);
		$tao_category=trim($_POST['tao_category']);
		$bitem=trim($_POST['bitem']);
		$item=trim($_POST['item']);		
		$promo=trim($_POST['promo']);
		$artile=trim($_POST['artile']);
		$artilelist=trim($_POST['artilelist']);
		$artile_content=trim($_POST['artile_content']);		
		$shop=trim($_POST['shop']);
		$search=trim($_POST['search']);
		
		
		$_br = "\r\n";
		$_tab = "\t";		
		$_profile = '<?php'.$_br;
		$_profile .= $_tab."//seo规则配置文件".$_br;	
		$_profile .= $_tab."if (!defined('IN_59MIAO'))
		{
			exit('Access Defined');
		}".$_br;
		$_profile .= $_tab."define('REWRITE',{$rewrite});".$_br;
		$_profile .= $_tab."define('REWRITE_SUFFIX','{$rewrite_suffix}');".$_br;
		$_profile .= $_tab."define('INDEX','{$index}');".$_br;
		$_profile .= $_tab."define('MALL','{$mall}');".$_br;
		$_profile .= $_tab."define('SELLERINFO','{$sellerinfo}');".$_br;
		$_profile .= $_tab."define('ALL','{$all}');".$_br;
		$_profile .= $_tab."define('B2C_CATEGORY','{$b2c_category}');".$_br;
		$_profile .= $_tab."define('TAO_CATEGORY','{$tao_category}');".$_br;
		$_profile .= $_tab."define('BITEM','{$bitem}');".$_br;	
		$_profile .= $_tab."define('ITEM','{$item}');".$_br;
		$_profile .= $_tab."define('PROMO','{$promo}');".$_br;
		$_profile .= $_tab."define('ARTILE','{$artile}');".$_br;
		$_profile .= $_tab."define('ARTILELIST','{$artilelist}');".$_br;
		$_profile .= $_tab."define('ARTILE_CONTENT','{$artile_content}');".$_br;
		$_profile .= $_tab."define('SHOP','{$shop}');".$_br;
		$_profile .= $_tab."define('SEARCH','{$search}');".$_br;
				
		$_profile .= $_br;
		$_profile .= '?>'.$_br;		
		if (!file_put_contents('./configs/seo_rule.inc.php', $_profile)) {
			return false;
		}
		else{
			return true;
		}
	}
	//设置seo
	public function set_seo(){
		$seo_text="";	
		$seo_text .= "if (!defined('IN_59MIAO'))
		{
			exit('Access Defined');
		}"."\r\n";	
		$index=$this->findOne('index');		
		$index_title=$index[0]->title;
		$index_keywords=$index[0]->keywords;
		$index_info=$index[0]->info;		
		$seo_text.= '$index_title="'.$index_title.'";'."\n";
		$seo_text.= '$index_keywords="'.$index_keywords.'";'."\n";
		$seo_text.= '$index_info="'.$index_info.'";'."\r\n";
	
		
		$mall=$this->findOne('mall');		
		$mall_title=$mall[0]->title;
		$mall_keywords=$mall[0]->keywords;
		$mall_info=$mall[0]->info;
		$seo_text.= '$mall_title="'.$mall_title.'";'."\n";
		$seo_text.= '$mall_keywords="'.$mall_keywords.'";'."\n";
		$seo_text.= '$mall_info="'.$mall_info.'";'."\r\n";
		
		
		$seller_list=$this->findOne('seller_list');		
		$seller_list_title=$seller_list[0]->title;
		$seller_list_keywords=$seller_list[0]->keywords;
		$seller_list_info=$seller_list[0]->info;
		$seo_text.= '$seller_list_title="'.$seller_list_title.'";'."\n";
		$seo_text.= '$seller_list_keywords="'.$seller_list_keywords.'";'."\n";
		$seo_text.= '$seller_list_info="'.$seller_list_info.'";'."\r\n";
		
		$all=$this->findOne('all');		
		$all_title=$all[0]->title;
		$all_keywords=$all[0]->keywords;
		$all_info=$all[0]->info;
		$seo_text.= '$all_title="'.$all_title.'";'."\n";
		$seo_text.= '$all_keywords="'.$all_keywords.'";'."\n";
		$seo_text.= '$all_info="'.$all_info.'";'."\r\n";
		
		$promo=$this->findOne('promo');		
		$promo_title=$promo[0]->title;
		$promo_keywords=$promo[0]->keywords;
		$promo_info=$promo[0]->info;
		$seo_text.= '$promo_title="'.$promo_title.'";'."\n";
		$seo_text.= '$promo_keywords="'.$promo_keywords.'";'."\n";
		$seo_text.= '$promo_info="'.$promo_info.'";'."\r\n";		
		
		$product_list=$this->findOne('product_list');		
		$product_list_title=$product_list[0]->title;
		$product_list_keywords=$product_list[0]->keywords;
		$product_list_info=$product_list[0]->info;
		$seo_text.= '$product_list_title="'.$product_list_title.'";'."\n";
		$seo_text.= '$product_list_keywords="'.$product_list_title.'";'."\n";
		$seo_text.= '$product_list_info="'.$product_list_info.'";'."\r\n";		
		
		
		$product_content=$this->findOne('product_content');		
		$product_content_title=$product_content[0]->title;
		$product_content_keywords=$product_content[0]->keywords;
		$product_content_info=$product_content[0]->info;
		$seo_text.= '$product_content_title="'.$product_content_title.'";'."\n";
		$seo_text.= '$product_content_keywords="'.$product_content_keywords.'";'."\n";
		$seo_text.= '$product_content_info="'.$product_content_info.'";'."\r\n";	
		
		
		$taoshop=$this->findOne('taoshop');		
		$taoshop_title=$taoshop[0]->title;
		$taoshop_keywords=$taoshop[0]->keywords;
		$taoshop_info=$taoshop[0]->info;
		$seo_text.= '$taoshop_title="'.$taoshop_title.'";'."\n";
		$seo_text.= '$taoshop_keywords="'.$taoshop_keywords.'";'."\n";
		$seo_text.= '$taoshop_info="'.$taoshop_info.'";'."\n";	
		
		
		$artile=$this->findOne('artile');		
		$artile_title=$artile[0]->title;
		$artile_keywords=$artile[0]->keywords;
		$artile_info=$artile[0]->info;
		$seo_text.= '$artiletitle="'.$artile_title.'";'."\n";
		$seo_text.= '$artilekeywords="'.$artile_keywords.'";'."\n";
		$seo_text.= '$artileinfo="'.$artile_info.'";'."\r\n";	
		
		$artile_list=$this->findOne('artile_list');		
		$artile_list_title=$artile_list[0]->title;
		$artile_list_keywords=$artile_list[0]->keywords;
		$artile_list_info=$artile_list[0]->info;
		$seo_text.= '$artile_list_title="'.$artile_list_title.'";'."\n";
		$seo_text.= '$artile_list_keywords="'.$artile_list_keywords.'";'."\n";
		$seo_text.= '$artile_list_info="'.$artile_list_info.'";'."\r\n";	
		
		
		$artile_content=$this->findOne('artile_content');
		$artile_content_title=$artile_content[0]->title;
		$artile_content_keywords=$artile_content[0]->keywords;
		$artile_content_info=$artile_content[0]->info;
		$seo_text.= '$artile_content_title="'.$artile_content_title.'";'."\n";
		$seo_text.= '$artile_content_keywords="'.$artile_content_keywords.'";'."\n";
		$seo_text.= '$artile_content_info="'.$artile_content_info.'";'."\r\n";	
		
		if(file_put_contents("configs/seo_config.inc.php", "<?php \n".$seo_text."\n?>")){
			return true;
		}
		else{
			return false;
		}
	}
}
?>