<?php
/*
 +----------------------------------------------------------------------
 | TEMMOKUMVC [ NO BEST, ONLY BETTER ]
 +----------------------------------------------------------------------
 | Copyright (c) 2018~2019 https://www.temmoku.cn All rights reserved.
 +----------------------------------------------------------------------
 | Author: 张宗强 Email:webmaster@temmoku.cn QQ:158726877 516669373 TEL:17895221001 微信:temmokumvc
 +---------------------------------------------------------------------- 
*/
namespace News\home\controller;
use \temmoku\db;
use \temmoku\controller;
class Index extends Controller
{


    public function index()
    {
		$cache_dir=RUNTIME_PATH."/cache/".MODULE.'/'.DEVICE."/index.txt";
    	if(C(MODULE.'|setting.index_cache_time') && is_file($cache_dir) && time()-@filemtime($cache_dir) < C(MODULE.'|setting.index_cache_time')*3600){
    		echo get_cache($cache_dir);
    		exit;
    	}
    	//title标签
    	$title=C(MODULE.'|setting.web_seo_webname') ? C(MODULE.'|setting.web_seo_webname') : C('WEB_SEO_WEBNAME');
    	$TITLE=$title.'_'.C('WEBNAME');
    	//关键字标签
    	$KEYWORDS=C(MODULE.'|setting.web_seo_keywords') ?  C(MODULE.'|setting.web_seo_keywords') : C('WEB_SEO_KEYWORDS');
    	//描述标签
    	$DESCRIPTION=C(MODULE.'|setting.web_seo_description') ? C(MODULE.'|setting.web_seo_description') : C('WEB_SEO_DESCRIPTION');
    	
    	
    	$this->assign('WEBNAME',$TITLE);
    	$this->assign('KEYWORDS',$KEYWORDS);
    	$this->assign('DESCRIPTION',$DESCRIPTION);
		
		//不是pc设备才去获取
		if(DEVICE !='pc'){
			//网站名称,或者是栏目名称
			$this->assign('webname',C('webname'));
			//获取所有一级栏目
			$menu_more_list=db::select('*')->from(M_jab.'category')->where("upcid=0")->query();
			$this->assign('menu_more_list',$menu_more_list);
			
			//获取最新5张图片内容
			$new_photo=db::select('*')->from(M_jab.'article')->where("state=1 AND is_pic=1")->limit(5)->orderByDESC(['aid'])->query();
			$this->assign('new_photo',$new_photo);
			//根据一级栏目获取相关内容
			$list=[];
			foreach($menu_more_list as $row){
				$cid=C(MODULE.'|category_setting.'.$row['cid'])[son] ? C(MODULE.'|category_setting.'.$row['cid'])[son] : $row['cid'];
				$list[$row['cid']]=db::select('*')->from(M_jab.'article')->where("state=1 AND cid IN (".$cid.")")->orderByDESC(['aid'])->limit(10)->query();
			}
			$this->assign('list',$list);
		}
		
		
		
        $this->display(tpl('index'));
        if(C(MODULE.'|setting.index_cache_time')){
			write_file($cache_dir,ob_get_contents());
		}
    }
}
?>