<?php
include("require.php");
//二级域名
if($core_opendomain==1)
{
  $domainrs=$_SERVER['HTTP_HOST'];
  $domain=str_replace(".".$core_erdomain,"",$domainrs);
  $phpcolor->table=$core_mysql_prefix."bar";
  $phpcolor->field="id";
  $phpcolor->where="domain = '".$domain."'";
  if($bardomain=$phpcolor->exist(1))
    Header("Location: ".$core_url."/list.php?bid=".$bardomain['id']);
}
//推荐贴吧
$phpcolor->table=$core_mysql_prefix."bar";
$phpcolor->field="id,barname,introduction,picture";
$phpcolor->where="recommend = 1 order by rand() limit 8";
$bar=$phpcolor->assignment();
for ($count=0;$count<count($bar);$count++)
{  
  $bar[$count]['introduction']=$phpcolor->mysubstr($bar[$count]['introduction'],0,84); 
}
//贴吧分类
$phpcolor->table=$core_mysql_prefix."class";
$phpcolor->field="id,classname,base";
$phpcolor->where="belong = 0 order by queue";
$bigsort=$phpcolor->assignment();
for ($count=0;$count<count($bigsort);$count++)
{
  if($bigsort[$count]['base']=="0")
  {
    $phpcolor->table=$core_mysql_prefix."class";
    $phpcolor->field="id,classname";
    $phpcolor->where="belong = ".$bigsort[$count]['id']." order by queue limit 6";
    $smallsort[$count]=$phpcolor->assignment();
  }
  else
  {
    $phpcolor->table=$core_mysql_prefix."bar";
    $phpcolor->field="id,barname";
    $phpcolor->where="barclass = ".$bigsort[$count]['id']." order by id desc limit 6";
    $smallsort[$count]=$phpcolor->assignment();
  }
}
//幻灯片
$phpcolor->table=$core_mysql_prefix."indexpic";
$phpcolor->field="*";
$phpcolor->where="1=1 order by id desc limit 5";
$rs=$phpcolor->assignment();
for ($count=0;$count<count($rs);$count++)
{ 
  if($count==0)
  {
    $pic['pics']=$rs[$count]["picture"];
    $pic['links']=$rs[$count]["link"];
    $pic['texts']=$rs[$count]["theme"];
  }
  else
  {
    $pic['pics'].="|".$rs[$count]["picture"];
    $pic['links'].="|".$rs[$count]["link"];
    $pic['texts'].="|".$rs[$count]["theme"];
  }
}
//头条
$phpcolor->table=$core_mysql_prefix."topic";
$phpcolor->field="id,theme,content";
$phpcolor->where="recommend = 2 and state!=0 order by rand() limit 2";
$headlines=$phpcolor->assignment();
for ($count=0;$count<count($headlines);$count++)
{ 
  $headlines[$count]['theme']=$phpcolor->mysubstr($headlines[$count]['theme'],0,50); 
  $headlines[$count]['content']=str_replace("<br />","",$headlines[$count]['content']);
  $headlines[$count]['content']=$phpcolor->mysubstr($headlines[$count]['content'],0,116); 
} 
//推荐主题
$phpcolor->field="id,theme,belong";
$phpcolor->where="recommend = 1 and state!=0 order by rand() limit 10";
$post=$phpcolor->assignment();
$phpcolor->table=$core_mysql_prefix."bar";
for ($count=0;$count<count($post);$count++)
{ 
  $phpcolor->field="barname";
  $phpcolor->where="id = '".$post[$count]['belong']."'";
  $rs=$phpcolor->exist(1);
  $post[$count]['belongbn']=$rs['barname'];
  $post[$count]['theme']=$phpcolor->mysubstr($post[$count]['theme'],0,34); 
}
//贴吧公告
$phpcolor->table=$core_mysql_prefix."topic";
$phpcolor->field="id,theme";
$phpcolor->where="state = 2 order by published desc limit 5";
$notice=$phpcolor->assignment();
for ($count=0;$count<count($notice);$count++)
{ 
  $notice[$count]['theme']=$phpcolor->mysubstr($notice[$count]['theme'],0,27); 
}
//推荐用户
$phpcolor->table=$core_mysql_prefix."user";
$phpcolor->field="id,username,picture";
$phpcolor->where="state = 2 order by rand() limit 10";
$user=$phpcolor->assignment();
//友情链接
$phpcolor->table=$core_mysql_prefix."link";
$phpcolor->field="name,link,picture,type";
$phpcolor->where="type != 0 order by type, queue";
$link=$phpcolor->assignment();
//广告
$phpcolor->table=$core_mysql_prefix."ad";
$phpcolor->field="name,site,type,theme,picture,link,code";
$phpcolor->where="site = 4 order by rand() limit 3";
$rs[4]=$phpcolor->assignment();
for ($count=0;$count<count($rs[4]);$count++)
{
  if($rs[4][$count]['type']==1)
    $ad[4][$count]="<a href=".$rs[4][$count]['link']." target='_blank'><img src=".$rs[4][$count]['picture']." width='234' height='60' style='border:0px;'></a>";
  elseif($rs[4][$count]['type']==2)
    $ad[4][$count]="<a href=".$rs[4][$count]['link']." target='_blank'>".$rs[4][$count]['theme']."</a>";
  else
    $ad[4][$count]=$rs[4][$count]['code'];
}
$phpcolor->where="site = 3 order by rand()";
$rs[3]=$phpcolor->assignment();
for ($count=0;$count<count($rs[3]);$count++)
{
  if($rs[3][$count]['type']==1)
    $ad[3][$count]="<a href=".$rs[3][$count]['link']."><img src=".$rs[3][$count]['picture']." width='728' height='90' style='border:0px;'></a>";
  elseif($rs[3][$count]['type']==2)
    $ad[3][$count]="<a href=".$rs[3][$count]['link'].">".$rs[3][$count]['theme']."</a>";
  else
    $ad[3][$count]=$rs[3][$count]['code'];
}
//
if(isset($_COOKIE['core_user_name']))
{
  $phpcolor->table=$core_mysql_prefix."qiandao";
  $phpcolor->field="*";
  $yztime=date('Y-m-d',strtotime(date('Y-m-d H:i:s'))+$core_time*60*60);
  $phpcolor->where="published like '%".$yztime."%' and belong='".$userv['id']."' and type='1'";
  $pd=$phpcolor->exist(2);
  if($pd)
    $qiandao="1";
  else
    $qiandao="0";
}
$tpl -> assign("core_verifyopen", $core_verifyopen);
$tpl -> assign("qiandao", $qiandao);
$tpl -> assign("pic", $pic);
$tpl -> assign("notice", $notice);
$tpl -> assign("user", $user);
$tpl -> assign("post", $post);
$tpl -> assign("headlines", $headlines);
$tpl -> assign("bigsort", $bigsort);
$tpl -> assign("smallsort", $smallsort);
$tpl -> assign("bar", $bar);
$tpl -> assign("link", $link);
$tpl -> assign("ad", $ad);
$tpl -> display("$core_style/index.htm");
?>