has('index')){ $index = $cache->get('index'); } } if(is_null($index)){ $category_config = getConfig('category'); $cate_list = getCategoryList($category_config); $pic_url = getConfig('pic_url'); $pic_path = getConfig('pic_path'); $last_articles = $db->select('article_article', '*', [ 'AND' => [ 'chapters[!]'=>0, 'display' =>0, 'power' =>0 ], 'ORDER'=>[ 'lastupdate'=>'DESC' ], 'LIMIT'=>30 ]); $post_articles = $db->select('article_article', '*', [ 'AND' => [ 'chapters[!]'=>0, 'display' =>0, 'power' =>0 ], 'ORDER'=>[ 'postdate'=>'DESC' ], 'LIMIT'=>30 ]); $web_setting =json_decode(getConfig('web_setting'), true); $recommend = explode(',', $web_setting['index_recommend']); $recommend_list = explode(',', $web_setting['index_recommend_list']); $recommend = $db->select('article_article', '*', [ 'AND' => [ 'articleid'=> $recommend, 'chapters[!]'=>0, 'display' =>0, 'power' =>0 ], 'ORDER'=>['articleid'=>$recommend] ]); $recommend_list = $db->select('article_article', '*', [ 'AND' => [ 'articleid'=> $recommend_list, 'chapters[!]'=>0, 'display' =>0, 'power' =>0 ], 'ORDER'=>['articleid'=>$recommend_list] ]); foreach ($recommend as $key => $value) { $recommend[$key]['lastupdate'] = date("m-d", $value['lastupdate']); $recommend[$key]['sortname'] = getSortName($value['sortid'], $cate_list); $recommend[$key]['column_name'] = getShortName($value['sortid'], $cate_list); $recommend[$key]['articleid1000'] = intval($value['articleid']/1000); $recommend[$key]['image'] = get_image($value['articleid'], $pic_url, $pic_path); } foreach ($recommend_list as $key => $value) { $recommend_list[$key]['lastupdate'] = date("m-d", $value['lastupdate']); $recommend_list[$key]['sortname'] = getSortName($value['sortid'], $cate_list); $recommend_list[$key]['column_name'] = getShortName($value['sortid'], $cate_list); $recommend_list[$key]['articleid1000'] = intval($value['articleid']/1000); $recommend_list[$key]['image'] = get_image($value['articleid'], $pic_url, $pic_path); } $last_modified_time= $last_articles[0]['lastupdate']; foreach ($last_articles as $key => $value) { $last_articles[$key]['lastupdate'] = date("m-d", $value['lastupdate']); $last_articles[$key]['sortname'] = getSortName($value['sortid'], $cate_list); $last_articles[$key]['column_name'] = getShortName($value['sortid'], $cate_list); $last_articles[$key]['articleid1000'] = intval($value['articleid']/1000); $last_articles[$key]['image'] = get_image($value['articleid'], $pic_url, $pic_path); } foreach ($post_articles as $key => $value) { $post_articles[$key]['postdate'] = date("m-d", $value['postdate']); $post_articles[$key]['sortname'] = getSortName($value['sortid'], $cate_list); $post_articles[$key]['column_name'] = getShortName($value['sortid'], $cate_list); $post_articles[$key]['articleid1000'] = intval($value['articleid']/1000); $post_articles[$key]['image'] = get_image($value['articleid'], $pic_url, $pic_path); } $index_center = str_replace("\r", '', $web_setting['index_center']); $centres = explode("\n", $index_center); $centre_list = []; foreach ($centres as $key => $value) { $data = explode('=', $value); $sort_id = $data['0']; $hots = explode(',', $data[1]); $index = $key + 1; $centre_list[$key] = []; $centre_list[$key]['c_id'] = $sort_id; $centre_list[$key]["sortname"] = getSortName($index, $cate_list); $centre_list[$key]["column_name"] = getSortName($index, $cate_list); $smarty->assign("sort" . $index, $centre_list[$key]); $hot = $db->select('article_article', '*', [ 'AND' => [ 'articleid'=> $hots, 'chapters[!]'=>0, 'display' =>0, 'power' =>0 ], 'ORDER'=>['articleid'=>$hots] ]); foreach ($hot as $key => $value) { $hot[$key]['postdate'] = date("m-d", $value['postdate']); $hot[$key]['sortname'] = getSortName($value['sortid'], $cate_list); $hot[$key]['column_name'] = getShortName($value['sortid'], $cate_list); $hot[$key]['articleid1000'] = intval($value['articleid']/1000); $hot[$key]['image'] = get_image($value['articleid'], $pic_url, $pic_path); } $first = array_shift($hot); $smarty->assign("sort{$index}_hot", $hot); $smarty->assign("sort{$index}_first_hot", $first); $lastupdate = $db->select('article_article', '*', [ 'AND' => [ 'chapters[!]'=>0, 'display' =>0, 'power' =>0, 'sortid'=>$sort_id ], 'ORDER'=>[ 'lastupdate'=>'DESC' ], 'LIMIT'=>13 ]); foreach ($lastupdate as $key => $value) { $lastupdate[$key]['postdate'] = date("m-d", $value['postdate']); $lastupdate[$key]['sortname'] = getSortName($value['sortid'], $cate_list); $lastupdate[$key]['column_name'] = getShortName($value['sortid'], $cate_list); $lastupdate[$key]['articleid1000'] = intval($value['articleid']/1000); $lastupdate[$key]['image'] = get_image($value['articleid'], $pic_url, $pic_path); } $first = array_shift($lastupdate); $smarty->assign("sort{$index}_lastupdate", $lastupdate); $smarty->assign("sort{$index}_first_lastupdate", $first); $postdate = $db->select('article_article', '*', [ 'AND' => [ 'chapters[!]'=>0, 'display' =>0, 'power' =>0, 'sortid'=>$sort_id ], 'ORDER'=>[ 'postdate'=>'DESC' ], 'LIMIT'=>13 ]); foreach ($postdate as $key => $value) { $postdate[$key]['postdate'] = date("m-d", $value['postdate']); $postdate[$key]['sortname'] = getSortName($value['sortid'], $cate_list); $postdate[$key]['column_name'] = getShortName($value['sortid'], $cate_list); $postdate[$key]['articleid1000'] = intval($value['articleid']/1000); $postdate[$key]['image'] = get_image($value['articleid'], $pic_url, $pic_path); } $first = array_shift($postdate); $smarty->assign("sort{$index}_postdate", $postdate); $smarty->assign("sort{$index}_first_postdate", $first); } $smarty->assign('lastupdate', $last_articles); $smarty->assign('postdate', $post_articles); $smarty->assign('hot_image', $recommend); $smarty->assign('hot', $recommend_list); //计算 last_modified 和etag $content =$smarty->fetch('index.html'); if(!is_null($cache)){ $time = time(); $cache->set('index',$content,60); $cache->set('index_time',$time); $cache->set('index_last_modified_time',$last_modified_time); $cache_time=$time; header("X-Cache-Status: MISS"); } }else{ $content = $index; $cache_time=$cache->get('index_time',time()); $last_modified_time = $cache->get('index_last_modified_time'); header("X-Cache-Status: HIT"); } $headers =nginx_headers(); $etag = sprintf('"%xT-%xO"',$cache_time,strlen($content)); $seconds_to_cache = 60-(time()-$cache_time); $ts = gmdate("D, d M Y H:i:s", time() + $seconds_to_cache) . " GMT"; header('Expires: '.gmdate('D, d M Y H:i:s', time() + 3600*24*60)." GMT"); //到期时间 header("Pragma: cache"); header("Etag: {$etag}"); header("Cache-Control: public, max-age=$seconds_to_cache"); header('Last-Modified: '.gmdate('D, d M Y H:i:s', $last_modified_time).' GMT', true, 200); echo $content; exit;