<?php
    $cachename = "lek8_hot_theme";//缓存key
	//cache_delete($cachename);//删除缓存
    $hotlist = cache_get($cachename);//获取缓存
	if($hotlist === NULL) {
		$times_tamp_a = strtotime("-1 week");//上周
		//$times_tamp_a = mktime(0,0,0,date('m'),date('d')-1,date('Y'));//昨天
		$hotlist = db_find('thread', array('create_date'=>array('>'=>$times_tamp_a)), array('views'=>-1), 1, 10, 'tid');
		thread_list_access_filter($hotlist, $gid);
		cache_set($cachename, $hotlist,3600);//设置缓存 和 过期时间
	}
?>

<?php

function console_log($text){
    echo '<script type="text/javascript">console.log(\'log:'.$text.'\');</script>';
}

//获取回复最多的文章，默认10篇
function get_site_top_list(){
	$result = cache_get('get_site_top_list');
	if(empty($result)){
		$result = db_find('thread', array(), array('views'=>2));//按views倒序
		cache_set('get_site_top_list',$result,86400);//有效期1天
	}
	return $result;
}
?>


<div class="card">
	<div class="card-header">
		<ul class="nav nav-tabs card-header-tabs" id="myTab" role="tablist">
			<li class="nav-item" role="presentation">
			  <a class="nav-link active" id="home-tab" data-toggle="tab" href="#all_rank" role="tab" aria-controls="home" aria-selected="true">总排行</a>
			</li>
			<li class="nav-item" role="presentation">
				<a class="nav-link" id="profile-tab" data-toggle="tab" href="#week_rank" role="tab" aria-controls="profile" aria-selected="false">周排行</a>
			  </li>
		  </ul>
	</div>
	<div class="card-body  py-1 small">
		<div class="tab-content" id="myTabContent">
			<div class="tab-pane fade show active" id="all_rank" role="tabpanel" aria-labelledby="home-tab"><?php
				$toplist = get_site_top_list();
				thread_list_access_filter($toplist, $gid);
				echo '<div class="site-top"><ul class="site-list-ul">';
				foreach ($toplist as $key => $value){
					$_class = $key < 3 ? 'jb-blue' : 'badge-secondary';
					echo '<li><span class="badge badge-pill mr-2 '.$_class.'">'.($key+1).'</span><a href="thread-'.$value['tid'].'.htm">'.$value['subject'].'</a></li>';
				}
				echo '</ul></div>';
			?></div>
			<div class="tab-pane fade" id="week_rank" role="tabpanel" aria-labelledby="profile-tab">
				<div class="site-top">
				<ul class="site-list-ul">
					<?php if($hotlist) {
						$loopNum = 1;
						foreach($hotlist as $_thread) {?>
						
					<li >
							<span class="badge badge-pill mr-2 <?php if($loopNum <= 3) { ?> jb-green <?php } else { ?> badge-secondary <?php }?>"><?php echo  $loopNum++ ;?></span><a href="<?php echo url("thread-$_thread[tid]");?>"><?php echo $_thread['subject'];?></a>
						
					</li>
					<?php }} else { ?>
						<?php echo lang('none');?>
					<?php } ?>
			</ul>	
			</div>	
			</div>
		  </div>
	</div>
	
</div>



