<?php
submitfilter($_GET['list']);
$phpcolor->table="bar";
$phpcolor->field="*";
$phpcolor->where="id = '".$_GET['list']."'";
$bar=$phpcolor->exist(1);
if(!$bar)
  jump("index.php");
$phpcolor->where="merge like '%|".$bar['barname']."|%'";
if($barid=$phpcolor->exist(1))
  jump(htmlurl($core_url,"list",$barid['id'],0,$core_rewrite));
if($bar['state']=="0" and $_COOKIE["core_user_rank"]!="2")
  jump("error.php?id=5");
if($bar['state']=="2" && $_COOKIE["core_user_rank"]!="2" && $bar['ausername']!=$_SERVER['REMOTE_ADDR'] && $bar['ausername']!=$_COOKIE['core_user_name'])
  jump("error.php?id=6");
if($bar['style']!="0")
{
  $phpcolor->table="style";
  $phpcolor->field="link,phpfile";
  $phpcolor->where="id=".$bar['style'];
  if($style=$phpcolor->exist(1))
    $core_style=$style['link'];
}
//小说
$phpcolor->table="book";
$phpcolor->field="*";
$phpcolor->where="bookname = '".$bar['barname']."' and status >= 1";
$book=$phpcolor->exist(1);
$picfile=ceil(($book['id']/5000));
if(file_exists("upload/bookpic/".$picfile."/".$book['id'].".jpg"))
  $book['pic']="upload/bookpic/".$picfile."/".$book['id'].".jpg";
else
  $book['pic']="images/img/booknopic.jpeg";
$book['introduction']=str_replace("<br/>","",$book['introduction']);
$book['introduction']=str_replace("<br>","",$book['introduction']);
$book['introduction']=str_replace("　","",$book['introduction']);
$book['introduction']=str_replace("&nbsp;"," ",$book['introduction']);
$book['introduction']=str_replace("  "," ",$book['introduction']);
$book['introduction']=$phpcolor->mysubstr($book['introduction'],0,100)." <a href='book.php?action=book&id=".$book['id']."'>[阅读]</a>";
//广告
$ad[1]["code"]=$phpcolor->adshow(1,$bar['id']);
$ad[2]["code"]=$phpcolor->adshow(2,$bar['id']);
$ad[6]["code"]=$phpcolor->adshow(6,$bar['id']);
$ad[7]["code"]=$phpcolor->adshow(7,$bar['id']);
$phpcolor->table="bar_user";
$phpcolor->field="uid";
$phpcolor->where="bid = '".$bar['id']."' and rank=2";
$rs=$phpcolor->assignment();
for($count=0;$count<count($rs);$count++)
{
  $phpcolor->table="user";
  $phpcolor->field="username";
  $phpcolor->where="id = '".$rs[$count]['uid']."'";
  $rsm=$phpcolor->exist(1);
  $master[$count]['username'] = $rsm['username'];
  $master[$count]['uid'] = $rs[$count]['uid'];
}
$count = count($rs);
$show = "yes";
$ismaster = 0;
if($count >= $core_barmastercount)
  $show = "no";
$isuser=0;
$phpcolor->table="bar_user";
$phpcolor->field="*";
$phpcolor->where="bid = '".$bar['id']."'";
$barusercount=$phpcolor->exist(2);
if(isset($_COOKIE['core_user_name']))
{
  //是否拥有管理权限
  if($ismaster = $phpcolor->isuorm($userv['id'],$bar['id'],2))
    $show = "no";
  if($_COOKIE["core_user_rank"] != '0')
    $ismaster = 1;
  //是否是吧会员
  $isuser=$phpcolor->isuorm($userv['id'],$bar['id'],1);
  $phpcolor->where="bid = '".$bar['id']."' and rank = 2";
  $count=$phpcolor->exist(2);
  $phpcolor->table="apply_master";
  $phpcolor->where="username = '".$_COOKIE["core_user_name"]."' and type=1";
  $count1=$phpcolor->exist(2);
  if($count+$count1 >= $core_ubarmastercount)
    $show = "no";
  //每日打卡
  $punch=$phpcolor->punch($bar['id'],$userv['id'],$int_yhdk,$isuser,$int_mrdk,$_GET['action']);
}
//本吧地址
$barurl=$core_url;
$phpcolor->table="bar_domain";
$phpcolor->field="domain";
$phpcolor->where="bid = '".$bar['id']."'";
if($bardomain=$phpcolor->exist(1))
{
  $bar['url']="http://".$bardomain['domain']."/";
  $barurl=$bar['url'];
}
else
  $bar['url']=htmlurl($core_url,"list",$bar['id'],0,$core_rewrite);
if($bar['rankfw']>0 && !isset($_COOKIE["core_user_name"]))
  jump("login.php?action=login&last=".$bar['url']);
if($bar['rankfw']>1 && $isuser==0 && ($_COOKIE["core_user_rank"]=="0" || !isset($_COOKIE["core_user_rank"])))
  jump("bar_user.php?bid=".$bar['id']);
if($bar['rankfw']>2 && $ismaster==0 && ($_COOKIE["core_user_rank"]=="0" || !isset($_COOKIE["core_user_rank"])))
  jump("error.php?id=5");
$phpcolor->table="bar";
//友情吧
$friendbar = split("\|", $bar['friendbar']);
for ($count=0;$count<count($friendbar);$count++)
{
  $phpcolor->field="id";
  $phpcolor->where="barname = '".$friendbar[$count]."'";
  $friendbarid[$count]=$phpcolor->exist(1);
  $friendbarid[$count]['url']=htmlurl($core_url,"list",$friendbarid[$count]['id'],0,$core_rewrite);
}
if(!isset($_GET['page']))
  $_GET['page']=0;
submitfilter($_GET['page']);
$sort = 0;
if($bar['barclass']!=0)
{
  $phpcolor->table="class";
  $phpcolor->field="classname";
  $phpcolor->where="id = '".$bar['barclass']."'";
  $sort = $phpcolor->exist(1);
}
$phpcolor->table="topic";
if(isset($_GET['show']) and $_GET['show'] == "boutique")
{
  $phpcolor->field="*";
  $phpcolor->where="(belong='".$bar['id']."' and boutique ='1' and state = '1') or state = '2'";
  $count = $phpcolor->exist(2);
  $phpcolor->where="(belong='".$bar['id']."' and boutique ='1' and state = '1') or state = '2' order by pxtime desc limit ".($_GET['page']*$core_listpage).",".$core_listpage."";
  $page=pages($count,$core_listpage,$_GET['page'],'list','&show=boutique&bid=',$bar['id'],$core_rewrite);
}
elseif(isset($_GET['show']) and $_GET['show'] == "postclass")
{
  submitfilter($_GET['cid']);
  $phpcolor->field="*";
  $phpcolor->where="(belong='".$bar['id']."' and postclass ='".$_GET['cid']."' and state = '1') or state = '2'";
  $count = $phpcolor->exist(2);
  $phpcolor->where="(belong='".$bar['id']."' and postclass ='".$_GET['cid']."' and state = '1') or state = '2' order by pxtime desc limit ".($_GET['page']*$core_listpage).",".$core_listpage."";
  $page=pages($count,$core_listpage,$_GET['page'],'list','&show=postclass&bid=',$bar['id'],$core_rewrite);
}
elseif(isset($_GET['show']) and $_GET['show'] == "posttime")
{
  $phpcolor->field="*";
  $phpcolor->where="(belong = '".$bar['id']."' and state = '1') or state = '2'";
  $count = $phpcolor->exist(2);
  $phpcolor->where="(belong = '".$bar['id']."' and state = '1') or state = '2' order by top desc, published desc limit ".($_GET['page']*$core_listpage).",".$core_listpage."";
  $page=pages($count,$core_listpage,$_GET['page'],'list','&show=posttime&bid=',$bar['id'],$core_rewrite);
}
else
{
  $phpcolor->field="*";
  $phpcolor->where="(belong = '".$bar['id']."' and state = '1') or state = '2'";
  $count = $phpcolor->exist(2);
  $phpcolor->where="(belong = '".$bar['id']."' and state = '1') or state = '2' order by pxtime desc limit ".($_GET['page']*$core_listpage).",".$core_listpage."";
  $page=pages($count,$core_listpage,$_GET['page'],'list','&bid=',$bar['id'],$core_rewrite);
}
$phpcolor->field="id,theme,content,author,reauthor,published,republished,click,reply,top,boutique,locks,vote,state";
$post=$phpcolor->assignment();
$phpcolor->table="user";
$phpcolor->field="id";
for ($count=0;$count<count($post);$count++)
{
  $post[$count]['url']=htmlurl($barurl,"read",$post[$count]['id'],0,$core_rewrite);
  $post[$count]['theme']=$phpcolor->mysubstr($post[$count]['theme'],0,52);
  if(($core_listcon=="1" and $bar['listcon']!="2") or $bar['listcon']=="1")
  {
    //显示内容
    $post[$count]['content']=$phpcolor->listcontent($post[$count]['content']);
	$core_listcon="1";
  }
  else
    $core_listcon="0";
  if($post[$count]['authorip'] = is_ip($post[$count]['author']))
    $post[$count]['author'] = ip_three($post[$count]['author']);
  else
  {
    $phpcolor->where="username = '".$post[$count]['author']."'";
    $rsu=$phpcolor->exist(1);
    $post[$count]['authorid']=$rsu['id'];
    $phpcolor->table="attest";
    $phpcolor->where="uid='".$post[$count]['authorid']."' and type='1'";
    $post[$count]['authorv']="0";
    if($phpcolor->exist(2))
      $post[$count]['authorv']="1";
	//是否是VIP会员
    $post[$count]['authorvip']=$phpcolor->isvord($post[$count]['authorid'],1);
    //是否是达人
    $post[$count]['authordr']=$phpcolor->isvord($post[$count]['authorid'],2);
	//主题一举橙名
	//签到
    $qdqt=date('Y-m-d',strtotime(date('Y-m-d'))+$core_time*3600-86400*$core_yjcm);
    $phpcolor->table="qiandao";
    $phpcolor->where="belong='".$post[$count]['authorid']."' and type='1' and published>'".$qdqt."'";
    $post[$count]['authorc']="0";
    if($phpcolor->exist(2)>=$core_yjcm)
      $post[$count]['authorc']="1";
	//打卡
	if($post[$count]['authorc']=="0")
	{
      $qdqt=date('Y-m-d',strtotime(date('Y-m-d'))+$core_time*3600-86400*$core_yjcmdb);
      $phpcolor->table="punch";
      $phpcolor->where="uid='".$post[$count]['authorid']."' and bid='".$bar['id']."' and published>'".$qdqt."'";
	  if($phpcolor->exist(2)>=$core_yjcmdb)
        $post[$count]['authorc']="1";
	}
    $phpcolor->table="user";
  }
  if($post[$count]['reauthorip'] = is_ip($post[$count]['reauthor']))
    $post[$count]['reauthor'] = ip_three($post[$count]['reauthor']);
  else
  {
    $phpcolor->where="username = '".$post[$count]['reauthor']."'";
    $rsu=$phpcolor->exist(1);
    $post[$count]['reauthorid']=$rsu['id'];
    $phpcolor->table="attest";
    $phpcolor->where="uid = '".$post[$count]['reauthorid']."' and type='1'";
    $post[$count]['reauthorv']="0";
    if($phpcolor->exist(2))
      $post[$count]['reauthorv']="1";
    //是否是VIP会员
    $post[$count]['reauthorvip']=$phpcolor->isvord($post[$count]['reauthorid'],1);
    //是否是达人
    $post[$count]['reauthordr']=$phpcolor->isvord($post[$count]['reauthorid'],2);
    //回复一举橙名
	//签到
    $qdqt=date('Y-m-d',strtotime(date('Y-m-d'))+$core_time*3600-86400*$core_yjcm);
    $phpcolor->table="qiandao";
    $phpcolor->where="belong='".$post[$count]['reauthorid']."' and type='1' and published>'".$qdqt."'";
    $post[$count]['reauthorc']="0";
    if($phpcolor->exist(2)>=$core_yjcm)
      $post[$count]['reauthorc']="1";
	//打卡
	if($post[$count]['reauthorc']=="0")
	{
      $qdqt=date('Y-m-d',strtotime(date('Y-m-d'))+$core_time*3600-86400*$core_yjcmdb);
      $phpcolor->table="punch";
      $phpcolor->where="uid='".$post[$count]['reauthorid']."' and bid='".$bar['id']."' and published>'".$qdqt."'";
	  if($phpcolor->exist(2)>=$core_yjcmdb)
        $post[$count]['reauthorc']="1";
	}
    $phpcolor->table="user";
  }
  $date=substr($post[$count]['republished'],0,10);
  $time=substr($post[$count]['republished'],11,18);
  if($date==date('Y-m-d',strtotime(date('Y-m-d'))+$core_time*3600))
    $post[$count]['republished']=$time;
  else
    $post[$count]['republished']=$date;
  $date=substr($post[$count]['published'],0,10);
  $time=substr($post[$count]['published'],11,18);
  if($date==date('Y-m-d',strtotime(date('Y-m-d'))+$core_time*3600))
    $post[$count]['published']=$time;
  else
    $post[$count]['published']=$date;
}
$bar['introduction']=autourl($bar['introduction']);
if($bar['verify']==0)
  $core_vpost=0;
elseif(($bar['verify']==1 && !isset($_COOKIE["core_user_name"])) || $bar['verify']==2 || ($bar['verify']==3 && $isuser==0))
  $core_vpost=1;
elseif(isset($_COOKIE["core_user_name"]))
  $core_vpost=0;
//是否具备发贴权限
$ismasters = $phpcolor->isuorm($userv['id'],$bar['id'],3);
if(isset($_COOKIE['core_user_name']) && $_COOKIE["core_user_rank"] != '0')
  $ismasters=1;
$postopen=$phpcolor->rankpost(0,$ismasters,$core_visitoropen,$bar['rankzt'],$isuser);
$fileopen=0;
if($core_file==2 || ($core_file==1 && isset($_COOKIE["core_user_name"])))
  $fileopen=1;
$phpcolor->table="postclass";
$phpcolor->field="id, name";
$phpcolor->where="belong = '".$bar['id']."'";
$postclass=$phpcolor->assignment();
if($isuser!=0)
{
  $phpcolor->table="bar_user";
  $phpcolor->field="*";
  $phpcolor->where="uid = '".$userv['id']."' and bid = '".$bar['id']."'";
  $muser=$phpcolor->exist(1);
  $muser['dj']=$phpcolor->djpd($bar['usergroup'],$bar['usergroupf'],$muser['integral']);
  $yztime=date('Y-m-d',strtotime(date('Y-m-d H:i:s'))+$core_time*3600);
  $phpcolor->where="accesstime like '%".$yztime."%' and uid='".$userv['id']."' and bid='".$bar['id']."'";
  $pd=$phpcolor->exist(2);
  if(!$pd)
  {
    $time=date('Y-m-d H:i:s',strtotime(date('Y-m-d H:i:s'))+$core_time*3600);
    $phpcolor->field="integral='".($muser['integral']+$int_fwb)."', accesstime='".$time."'";
    $phpcolor->where="uid='".$userv['id']."' and bid='".$bar['id']."'";
    $phpcolor->upgrade();
	//更新吧排名（会员首次访问）
    $phpcolor->upranking($int_hyfws,$bar['id']);
  }
  //更新吧排名（会员首次访问）
  else
    $phpcolor->upranking($int_hyfw,$bar['id']);
}
//更新吧排名（登录用户访问）
elseif(isset($_COOKIE["core_user_name"]))
  $phpcolor->upranking($int_zcfw,$bar['id']);
//更新吧排名（游客访问）
else
  $phpcolor->upranking($int_ykfw,$bar['id']);
$core_keyword=$bar['barname'].",".$core_keyword;
$core_description="讨论一切关于".$bar['barname']."的话题,".$core_description;
//吧导航
$phpcolor->table="bar_nav";
$phpcolor->field="*";
$phpcolor->where="belong = '".$bar['id']."' and type = '1' order by queue";
$barnav=$phpcolor->assignment();
//非默认模板加强
if($bar['style']!="0" and $style['phpfile']!="" and file_exists('includes/template/'.$style['phpfile'].'_list.php'))
  include(dirname(__FILE__)."/./includes/template/".$style['phpfile']."_list.php");
$tpl -> assign("barnav", $barnav);
$tpl -> assign("core_listcon", $core_listcon);
$tpl -> assign("book", $book);
$tpl -> assign("punch", $punch);
$tpl -> assign("core_yjcmdb", $core_yjcmdb);
$tpl -> assign("core_keyword", $core_keyword);
$tpl -> assign("core_description", $core_description);
$tpl -> assign("core_style", $core_style);
$tpl -> assign("ad", $ad);
$tpl -> assign("postclass", $postclass);
$tpl -> assign("post", $post); 
$tpl -> assign("page", $page);
$tpl -> assign("postopen", $postopen);
$tpl -> assign("core_vpost", $core_vpost);
$tpl -> assign("fileopen", $fileopen);
$tpl -> assign("verify", $_SESSION["verify"]);
$tpl -> assign("ismaster", $ismaster);
$tpl -> assign("friendbar", $friendbar);
$tpl -> assign("friendbarid", $friendbarid);
$tpl -> assign("barusercount", $barusercount);
$tpl -> assign("muser", $muser); 
$tpl -> assign("isuser", $isuser); 
$tpl -> assign("master", $master);
$tpl -> assign("bar", $bar);
$tpl -> assign("sort", $sort['classname']);
$tpl -> assign("show", $show);
$tpl -> assign("post_page", "list");
$tpl -> assign("post_belong", $bar['id']);
$tpl -> assign("core_header_title", $bar['barname']."吧 第".($_GET['page']+1)."页 - ");
$tpl -> display("$core_style/list.htm");
?>