<?php
class getinfoAction extends BackendAction {
	public function _initialize() {
        parent::_initialize(); 						
    }
	public function index(){	
		$this->display();		
	}		
	
	public function caiji(){
		$p = I('p', 1, 'intval');
		if($p==1){
			$getinfo = 0;
		}else{
			if(F('getinfo')){
			$getinfo = F('getinfo');
			}else{
			$getinfo = 0;
			}
		}		
		$n = $p - 1;
		$map['status'] = 1;
		$map['fabu'] = 1;		
		$list = D('article')->order('id desc')->where($map)->limit($n.',1')->select();
		$data = $list[0];
		$count = D('article')->where($map)->count();
		if($p>$count){
		F('getinfo',NULL);	
		$this->ajaxReturn(0, '已经更新完成！请返回，谢谢');	
		}	
		$cid = $data['cate_id'];
		$info = D('article_'.$cid)->where(array('vid'=>$data['id']))->getField('info');		
		if($info){
		if(!$data['mpic']){	
		preg_match("<img.*src=[\"](.*?)[\"].*?>", $info, $match);	
		if($match[1]){
		$item['mpic'] = $match[1];
		}
		}
		if(!$data['intro']){	
		$item['intro'] = utf_substr($info,150);		
		}		
		}
 		if($item){
		$do = D('article')->where(array('id'=>$data['id']))->save($item);	
		}			
		if($do>0){
		$getinfo++;			
		}
		F('getinfo',$getinfo);	
		$this->assign('p', $p); 		
		$this->assign('coll', $getinfo); 			
		$fetch = $this->fetch('caiji');
		$this->ajaxReturn(1, '文章缩略图和简介更新', $fetch);	
	}
	
	
	
   
}   
