<?php
/**
 * 插件：违禁词插件
 * By IT平民
**/

class Admin extends PlugController
{
	public function __construct()
	{
		parent::__construct();
		if(!C('plug_badword'))
		{
			die('插件未安装');
		}
		$this->check_admin();
	}

	public function Index()
	{
		if(IS_POST)
		{
			$words=F('words');
			$data=explode("\r\n",$words);
			if(is_array($data))
			{
				foreach($data as $key => $val)
				{
					$val=trim($val);
					if($val!='')
					{
						$list=explode('|',$val);
						if(count($list)<=1)
						{
							$val=$val.'|*';
							$data[$key]=$val;
						}
					}
					else
					{
						unset($data[$key]);
					}
				}
			}
			$words=implode("@@",$data);
			$this->db->update("sd_badword","id=1",['words'=>$words]);
			$this->success("保存成功");
		}
		else
		{
			$rs=$this->db->row("select words from sd_badword where id=1");
			if($rs)
			{
				$this->assign("words",$rs['words']);
			}
			$this->display("admin/index.php");
		}
	}

}