<?php

$page = intval($_GET['page']) > 0 ? intval($_GET['page']) : 1;
$pagesize = isset($_GET['pagesize']) ? intval($_GET['pagesize']) : 20;
$start = ($page - 1) * $pagesize;

//查看推荐论坛是否存在以及bid是什么
$hot_community = get_mocuz_setting('hot_community');
$hot_community=$hot_community['hot_community'];
$hot_community_id = get_mocuz_setting('hot_community_id');
$hot_community_id=$hot_community_id['hot_community_id'];
$result=array();
// $result['is_show'] = $hot_community;
if(!empty($hot_community_id)){
  $sql = " a.bid =$hot_community_id";
}else{
  $sql = " 1=0 ";
}
//获取总数
$total = DB::result_first("SELECT count(*)  FROM ".DB::table('common_block_item_data')." as a left join ".DB::table('forum_thread')." as b  on a.id=b.tid   WHERE $sql  AND b.displayorder >= 0");
//$total = DB::result_first("SELECT count(*)  FROM ".DB::table('forum_thread')." as a left join ".DB::table('common_block_item_data')." as b WHERE $sql  AND a.displayorder >= 0");
$total_page = ceil($total/$pagesize);
//$query = DB::query("SELECT * FROM ".DB::table('forum_thread')." WHERE $sql AND displayorder >= 0 ORDER BY $order DESC LIMIT $start,$pagesize");
$query = DB::query("SELECT b.* FROM ".DB::table('common_block_item_data')." as a left join ".DB::table('forum_thread')." as b  on a.id=b.tid   WHERE $sql  AND b.displayorder >= 0 ORDER BY a.dateline DESC LIMIT $start,$pagesize");

require 'includes/class/thread_service.php';
$thread_sercie = new Thread_Service;

while($thread = DB::fetch($query)){
  //判断是否被移动过 lhw
  if($thread['closed'] > 1)
  {
      $thread['tid'] = $thread['closed'];
  }
	$thread_sercie->input_thread($thread);
}

$threads = $thread_sercie->output_threads('full');
for ($i=0; $i <count($threads) ; $i++) { 
    $threads[$i]['usergroup']=usergruop_level($threads[$i]['uid'],0);
}
$result['list'] = $threads;
$result['total'] = $total_page;
odz_result($result);
