<?php
class newsModel extends Model {
     //自动验证函数 
	 function judge($value)
	 {
	    if(isset($value) && $value == "on")
		{
		    return "1";
		}else
		{
		   return "0";
		}
	 }
	//分离出图片
	function getImg()
   {
     $content = $_POST["content"];
     $regex = "/src=(.+?).(jpg|gif|png|bmp)/i";
     $matches = array();
  if(preg_match_all($regex, $content, $matches)){
        $src = $matches["1"]["0"];
        return substr($src,1,strlen($src)-1);
    }
   else
   {
     return "";
   }
}
	 
	
    // 自动验证设置
    protected $_validate = array(
        array('title', 'require', '标题必须填写！', 1),//1为必须验证
		array('category', 'require', '栏目必须填写！', 1),//1为必须验证
		array('author', 'require', '作者必须填写！', 1),//1为必须验证
		array('content', 'require', '内容必须填写！', 1),//1为必须验证
    );
	//自动完成
	protected $_auto = array(
	  array('times','time',1,'function'),
	  array('tj','judge',1,'callback'),
	  array('top','judge',1,'callback'),
	 array('images','getImg',1,'callback'),
	  array('flash','judge',1,'callback'),
	  array('description','msubstr',1,'function'),
	  array('content','strip',1,'function')
	);
}
?>