tion file_log($text){ file_put_contents('_debug_.log',$text.PHP_EOL,FILE_APPEND); } function console_log($text){ echo ''; } //文章内容随机推荐 function get_recommend_list($fid){ $result = cache_get('get_recommend_list'); if(empty($result)){ $result = db_sql_find('SELECT * FROM bbs_thread WHERE fid='.$fid.' ORDER BY RAND() LIMIT 10'); cache_set('get_recommend_list',$result,86400);//有效期1天 } return $result; } //获取回复最多的文章,默认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; } function get_site_new_user($num=16){ //先获取用户列表 $userlist = cache_get('get_site_new_user'); if(empty($userlist)){ $userlist = db_find('user', array(), array('uid'=>-1), 1, $num, 'uid'); foreach ($userlist as &$user) { $username = $user['username']; xn_strlen($username)>4 && $username = xn_substr($username, 0, 4); $user['dname'] = $username; } cache_set('get_site_new_user',$userlist,86400);//有效期1天 } return $userlist; } //随机获取N篇文章 function get_site_rand_list($num=10){ $result = cache_get('get_site_rand_list'); if(empty($result)){ $result = db_sql_find('SELECT * FROM bbs_thread WHERE images >= 1 ORDER BY RAND() LIMIT '.$num); $tids = array(); foreach($result as $val) array_push($tids,$val['tid']); //顺便查询图片 $cond = db_cond_to_sqladd(array('tid'=>$tids,'isimage'=>1)); $attachlist = db_sql_find("SELECT * FROM `bbs_attach` $cond ORDER BY width DESC");//获取最大的一张图片 foreach($result as &$val){ foreach($attachlist as $attach){ if($attach['tid']==$val['tid']){ $val['img'] = $attach['filename']; break; } } } cache_set('get_site_rand_list',$result,86400);//有效期1天 } return $result; } function echo_site_rand_list($num=10){ $randlist = get_site_rand_list($num); echo_site_info($randlist, '推荐阅读'); } //获取最新回复 function get_site_new_reply($num=8,$show_admin_reply=0){ $reply = cache_get('get_site_new_reply'); if(!empty($reply) && count($reply) != $num){ cache_delete('get_site_new_reply'); $reply = null; } if(empty($reply)){ if($show_admin_reply) $reply = db_find('post',array('isfirst'=>0),array('create_date'=>2),1,$num); else $reply = db_find('post',array('isfirst'=>0,'uid'=>array('!='=>1)),array('create_date'=>2),1,$num); foreach ($reply as &$value){ $user = user_read_cache($value['uid']); $username = $user['username']; xn_strlen($username)>5 && $username = xn_substr($username, 0, 5); $value['uname'] = $username; } cache_set('get_site_new_reply',$reply,36000);//有效期10小时 } return $reply; } //获取回复最多的num条 function get_site_top_reply($num=10){ //SELECT * FROM `bbs_thread` ORDER BY posts DESC LIMIT 10; $result = cache_get('get_site_top_post'); if(empty($result)){ $result = db_sql_find('SELECT * FROM bbs_thread WHERE images >= 1 ORDER BY posts DESC LIMIT '.$num); $tids = array(); foreach($result as $val) array_push($tids,$val['tid']); //顺便查询图片 $cond = db_cond_to_sqladd(array('tid'=>$tids,'isimage'=>1)); $attachlist = db_sql_find("SELECT * FROM `bbs_attach` $cond ORDER BY width DESC");//获取最大的一张图片 foreach($result as &$val){ foreach($attachlist as $attach){ if($attach['tid']==$val['tid']){ $val['img'] = $attach['filename']; break; } } } cache_set('get_site_top_post',$result,86400);//有效期1天 } return $result; } function echo_site_top_reply($num){ $randlist = get_site_top_reply($num); echo_site_info($randlist, '热评文章'); } function echo_site_info($list,$title){ echo '
'.'';
}else{
if(isset($value['img']))
echo '