<?php
include("require.php");
//贴吧域名绑定
$domain=$_SERVER['HTTP_HOST'];
$phpcolor->table="bar_domain";
$phpcolor->field="bid";
$phpcolor->where="domain = '".$domain."'";
if($bardomain=$phpcolor->exist(1))
  $_GET['list']=$bardomain['bid'];
//贴吧页
if(isset($_GET['list']))
{
  include("list.php");
  exit();
}
//强力推荐吧
$phpcolor->table="bar";
$phpcolor->field="id,barname,introduction,picture";
$phpcolor->where="recommend = 1 order by rand() limit 4";
$qtbar=$phpcolor->assignment();
for ($count=0;$count<count($qtbar);$count++)
{  
  $qtbar[$count]['introduction']=$phpcolor->mysubstr($qtbar[$count]['introduction'],0,84); 
  $qtbar[$count]['url']=htmlurl($core_url,"list",$qtbar[$count]['id'],0,$core_rewrite);
  $phpcolor->table="topic";
  $phpcolor->field="*";
  $phpcolor->where="belong='".$qtbar[$count]['id']."' and state = '1'";
  $qtbar[$count]["topic"] = $phpcolor->exist(2);
  $phpcolor->table="bar_user";
  $phpcolor->where="bid = '".$qtbar[$count]['id']."'";
  $qtbar[$count]["user"]=$phpcolor->exist(2);
}
//推荐吧
$phpcolor->table="bar";
$phpcolor->field="id,barname,introduction,picture";
$phpcolor->where="recommend = 2 order by rand() limit 8";
$bar=$phpcolor->assignment();
for ($count=0;$count<count($bar);$count++)
{
  $bar[$count]['url']=htmlurl($core_url,"list",$bar[$count]['id'],0,$core_rewrite);
  $phpcolor->table="topic";
  $phpcolor->field="*";
  $phpcolor->where="belong='".$bar[$count]['id']."' and state = '1'";
  $bar[$count]["topic"] = $phpcolor->exist(2);
  $phpcolor->table="bar_user";
  $phpcolor->where="bid = '".$bar[$count]['id']."'";
  $bar[$count]["user"]=$phpcolor->exist(2);
}
//吧分类
$phpcolor->table="class";
$phpcolor->field="id,classname,base";
$phpcolor->where="belong = 0 and indexs = 1 order by queue";
$bigsort=$phpcolor->assignment();
for ($count=0;$count<count($bigsort);$count++)
{
  $phpcolor->table="index";
  $phpcolor->field="*";
  $phpcolor->where="type = 1 and belong = '".$bigsort[$count]['id']."' order by id desc limit 5";
  $flzt[$count]=$phpcolor->assignment();
  for ($count1=0;$count1<count($flzt[$count]);$count1++)
  {  
    $flzt[$count][$count1]['url']=htmlurl($core_url,"read",$flzt[$count][$count1]['yid'],0,$core_rewrite);
  }
  if($bigsort[$count]['base']=="0")
  {
    $phpcolor->table="class";
    $phpcolor->field="id,classname";
    $phpcolor->where="belong = ".$bigsort[$count]['id']." and indexs = 1 order by queue limit 5";
    $smallsort[$count]=$phpcolor->assignment();
	for ($count1=0;$count1<count($smallsort[$count]);$count1++)
    {
	  $smallsort[$count][$count1]['nzs']=strlen($smallsort[$count][$count1]['classname'])+1;
	  $smallsort[$count][$count1]['url']=htmlurl($core_url,"class",$smallsort[$count][$count1]['id'],0,$core_rewrite);
	  $phpcolor->table="index";
      $phpcolor->field="*";
	  $phpcolor->where="type = 2 and belong = '".$smallsort[$count][$count1]['id']."' order by id desc";
      $fltb[$count][$count1]=$phpcolor->assignment();
	  for ($count2=0;$count2<count($fltb[$count][$count1]);$count2++)
      {
		$fltb[$count][$count1][$count2]['url']=htmlurl($core_url,"list",$fltb[$count][$count1][$count2]['yid'],0,$core_rewrite);
      }
	}
  }
  else
  {
    $phpcolor->table="bar";
    $phpcolor->field="id,barname";
    $phpcolor->where="barclass = ".$bigsort[$count]['id']." order by id desc limit 6";
    $smallsort[$count]=$phpcolor->assignment();
  }
}
//吧友推荐
$phpcolor->table="index";
$phpcolor->field="*";
$phpcolor->where="type = 3 and belong = 2 order by id desc limit 8";
$usertj=$phpcolor->assignment();
for ($count=0;$count<count($usertj);$count++)
{
  $usertj[$count]['url']=htmlurl($core_url,"read",$usertj[$count]['yid'],0,$core_rewrite);
}
//幻灯片
$phpcolor->table="indexpic";
$phpcolor->field="*";
$phpcolor->where="1=1 order by id desc limit 5";
$pic=$phpcolor->assignment();
//头条
$phpcolor->table="index";
$phpcolor->field="*";
$phpcolor->where="type = 4 and belong = 0 and barname='' order by id desc limit 3";
$headlines=$phpcolor->assignment();
for ($count=0;$count<count($headlines);$count++)
{
  $headlines[$count]['url']=htmlurl($core_url,"read",$headlines[$count]['yid'],0,$core_rewrite);
  $phpcolor->where="type = 4 and belong = ".$headlines[$count]['yid']." order by id limit 4";
  $posttj[$count]=$phpcolor->assignment();
  for ($count1=0;$count1<count($posttj[$count]);$count1++)
  {
    $posttj[$count][$count1]['url']=htmlurl($core_url,"read",$posttj[$count][$count1]['yid'],0,$core_rewrite);
  }
}
//公告
$phpcolor->table="placard";
$phpcolor->field="tid,theme";
$phpcolor->where="type = 1 order by placardtime desc limit 5";
$notice=$phpcolor->assignment();
for ($count=0;$count<count($notice);$count++)
{ 
  $notice[$count]['url']=htmlurl($core_url,"read",$notice[$count]['tid'],0,$core_rewrite);
}
//热门吧
$phpcolor->table="bar";
$phpcolor->field="id,barname,rankingq,rankings,ranking";
$phpcolor->where="state = 1 order by rankings desc limit 10";
$hotbar=$phpcolor->assignment();
for ($count=0;$count<count($hotbar);$count++)
{
  $hotbar[$count]['url']=htmlurl($core_url,"list",$hotbar[$count]['id'],0,$core_rewrite);
  if($hotbar[$count]["rankingq"]==0)
  {
    $hotbar[$count]["upordown"]="1";
	$hotbar[$count]["baifen"]=ceil($hotbar[$count]["rankings"]*100);
  }
  elseif($hotbar[$count]["rankings"]>$hotbar[$count]["rankingq"])
  {
    $hotbar[$count]["upordown"]="1";
	$hotbar[$count]["baifen"]=ceil(($hotbar[$count]["rankings"]-$hotbar[$count]["rankingq"])/$hotbar[$count]["rankingq"]*100);
  }
  else
  {
    $hotbar[$count]["upordown"]="2";
    $hotbar[$count]["baifen"]=ceil(($hotbar[$count]["rankingq"]-$hotbar[$count]["rankings"])/$hotbar[$count]["rankingq"]*100);
  }
}
//推荐用户
$phpcolor->table="user";
$phpcolor->field="id,username,picture";
$phpcolor->where="state = 2 order by rand() limit 10";
$user=$phpcolor->assignment();
//推荐小说
$phpcolor->table="book";
$phpcolor->field="id,bookname";
$phpcolor->where="recommend = 1 order by uptime desc limit 6";
$book=$phpcolor->assignment();
for ($count=0;$count<count($book);$count++)
{
  $picfile=ceil(($book[$count]['id']/5000));
  if(file_exists("upload/bookpic/".$picfile."/".$book[$count]['id'].".jpg"))
    $book[$count]['pic']="upload/bookpic/".$picfile."/".$book[$count]['id'].".jpg";
  else
    $book[$count]['pic']="images/img/booknopic.jpeg";
}
//友情链接
$phpcolor->table="link";
$phpcolor->field="name,link,picture,type";
$phpcolor->where="type != 0 order by type, queue";
$link=$phpcolor->assignment();
//广告
$ad[4]["code"]=$phpcolor->adshow(4,0);
$ad[3]["code"]=$phpcolor->adshow(3,0);
//用户签到
if(isset($_COOKIE['core_user_name']))
{
  $phpcolor->table="qiandao";
  $phpcolor->field="*";
  $yztime=date('Y-m-d',strtotime(date('Y-m-d H:i:s'))+$core_time*3600);
  $phpcolor->where="published like '%".$yztime."%' and belong='".$userv['id']."' and type='1'";
  $pd=$phpcolor->exist(2);
  if($pd)
    $qiandao="1";
  else
    $qiandao="0";
  $phpcolor->table="user";
  $phpcolor->field="picture";
  $phpcolor->where="username='".$_COOKIE['core_user_name']."'";
  $users=$phpcolor->exist(1);
}
$tpl -> assign("book", $book);
$tpl -> assign("users", $users);
$tpl -> assign("core_yjcm", $core_yjcm);
$tpl -> assign("core_keyword", $core_keyword);
$tpl -> assign("core_description", $core_description);
$tpl -> assign("usertj", $usertj);
$tpl -> assign("flzt", $flzt);
$tpl -> assign("fltb", $fltb);
$tpl -> assign("core_vlogin", $core_vlogin);
$tpl -> assign("qiandao", $qiandao);
$tpl -> assign("pic", $pic);
$tpl -> assign("diandi", $diandi);
$tpl -> assign("notice", $notice);
$tpl -> assign("user", $user);
$tpl -> assign("zzzt", $zzzt);
$tpl -> assign("post", $post);
$tpl -> assign("hotbar", $hotbar);
$tpl -> assign("headlines", $headlines);
$tpl -> assign("posttj", $posttj);
$tpl -> assign("bigsort", $bigsort);
$tpl -> assign("smallsort", $smallsort);
$tpl -> assign("qtbar", $qtbar);
$tpl -> assign("bar", $bar);
$tpl -> assign("link", $link);
$tpl -> assign("ad", $ad);
$tpl -> display("$core_style/index.htm");
?>