<?php
class IndexAction extends baseAction {
    public function index(){
    // echo convert_html_to_swf("http://v.qq.com/cover/j/jts0frrj1jankdg.html?vid=l0198e7fwvc");
    $data = D('pages');
    $start_time = time()-(60*60*24*7);
	$map = " 1=1 and a.status='1' and a.addtime > ". $start_time ." ";
	$order = ' order by a.yes desc,a.comment desc, a.id desc ';
	$result = $data->content_page(25,$map,$order,'index');
	// print_r($result);
	$this->assign('list',$result['list']);
	$this->assign('page',$result['page']);
	//调取列表页笑话大全
	$dq_list = M('tag')->order("number desc")->limit(30)->select();
	//调取爆笑精选，带图片
	$bx_list = M('content_content')->where("status=1 and thumb != ''")->order('rand()')->limit(10)->select();
	$this->assign('dq_list',$dq_list);
	$this->assign('bx_list',$bx_list);
	$this->assign('model','index');
	$this->assign('action','index');
	$this->display(C('default_tpl').'/Index/index');
    }
    public function h24(){
    $data = D('pages');
    $start_time = time()-(60*60*24);
	$map = " 1=1 and a.status='1' and a.addtime > ". $start_time ." ";
	$order = ' order by a.yes desc,a.comment desc, a.id desc ';
	$result = $data->content_page(25,$map,$order,'h24');
	// print_r($result);
	$this->assign('list',$result['list']);
	$this->assign('page',$result['page']);
	//调取列表页笑话大全
	$dq_list = M('tag')->order("number desc")->limit(30)->select();
	//调取爆笑精选，带图片
	$bx_list = M('content_content')->where("status=1 and thumb != ''")->order('rand()')->limit(10)->select();
	$this->assign('dq_list',$dq_list);
	$this->assign('bx_list',$bx_list);
	$this->assign('model','index');
	$this->assign('action','h24');
	$this->display(C('default_tpl').'/Index/index');
    }
    public function history(){
    $data = D('pages');
    if(I('token') == '') {
    $result = M('content_content')->order('rand()')->find();
    // print_r($result);
    $y = date("Y",$result['addtime']);
    $m = date("m",$result['addtime']);
    $d = date("d",$result['addtime']);
    $start_time= mktime(0,0,0,$m,$d,$y);//开始时间
    //种cookie 防止刷新后重复
    if(cookie('feimao_history')) {
    	for($i=0;$i<100;$i++){
    		if(cookie('feimao_history') == $start_time){
    			$result = M('content_content')->order('rand()')->find();
			    // print_r($result);
			    $y = date("Y",$result['addtime']);
			    $m = date("m",$result['addtime']);
			    $d = date("d",$result['addtime']);
			    $start_time= mktime(0,0,0,$m,$d,$y);
    		}else{
    			break;
    		}
    	}
    }
    cookie('history',$start_time,array('expire'=>C('logint'),'prefix'=>'feimao_'));

    //
    $end_time = $start_time+(60*60*24);

	$map = " 1=1 and a.status='1' and a.addtime > ". $start_time ." and a.addtime < ". $end_time ." ";
	$order = ' order by a.yes desc,a.comment desc, a.id desc ';
	$url = str_replace('+','--',encrypt($y.'-'.$m.'-'.$d));
	$result = $data->content_page(25,$map,$order,'history',$url);
	$data_date = $y.'年'.$m.'月'.$d.'日';
	}else{
		$token = str_replace('--','+',I('token'));
		$token = explode('-',decrypt($token));
		$start_time = strtotime($token[0].'-'.$token[1].'-'.$token[2]);
		$end_time = $start_time+(60*60*24);
		$map = " 1=1 and a.status='1' and a.addtime > ". $start_time ." and a.addtime < ". $end_time ." ";
		$order = ' order by a.yes desc,a.comment desc, a.id desc ';
		$url = I('token');
		$result = $data->content_page(25,$map,$order,'history',$url);
		$data_date = $token[0].'年'.$token[1].'月'.$token[2].'日';
	}

	$this->assign('list',$result['list']);
	$this->assign('page',$result['page']);
	//调取列表页笑话大全
	$dq_list = M('tag')->order("number desc")->limit(30)->select();
	//调取爆笑精选，带图片
	$bx_list = M('content_content')->where("status=1 and thumb != ''")->order('rand()')->limit(10)->select();
	$this->assign('dq_list',$dq_list);
	$this->assign('bx_list',$bx_list);
	$this->assign('model','index');
	$this->assign('action','history');
	$this->assign('data_date',$data_date);
	$this->display(C('default_tpl').'/Index/index');
    }
}