<?php 
require "../Run.php";
require "../include/page.inc.php";
require "../include/reply.fun.php";
require "../include/imageView.fun.php";

$css = '<style>
.art{font-family:"微软雅黑";font-size:18px;font-weight:normal;word-break:break-all;word-wrap:break-word;line-height:28px;color:#222;padding:0px;white-space:normal;margin:8px;border:1px solid #efefef;border-bottom:2px solid #efefef;border-right:2px solid #efefef;background-color:#fff;-moz-border-radius:5px;border-radius:5px;overflow:hidden;}
.art_title,.art_sub{padding:8px;text-align:center}
.art_title{color:#222;font-family:"微软雅黑";font-size:22px;font-weight: bolder;}
.art_sub{font-size:14px;color:#ccc;font-weight:normal;}
.art_sub a{font-size:14px;color:#ccc;font-weight:normal;}
.art_view{font-family:"微软雅黑";font-size:18px;font-weight:normal;word-break:break-all;word-wrap:break-word;line-height:28px;color:#222;padding:0px;white-space:normal;}
.art_view pre{word-break:break-all;-word-wrap:break-word;white-space: pre-wrap!important;padding:8px;}
</style>'.$css;
	$mysql2 = new D('dd_book_content');
	$content = $mysql2->where(array('bookid'=>$_GET['rid'],'siteid'=>WAPID))
					->limit(slist($_GET['p'],20),20)
					->find();
	if(!$content)
	{
		ehtml("哎呀，找不到资源，该文章可能已经被删除了，也可能是您的地址写错喽!");
		exit();
	}
if($_GET['cid']==''||$_GET['cid']==NULL){
     header("location: http://".$_SERVER["HTTP_HOST"]."/book/content.php?cid=".$gro."&id=".$_GET['id']);
}
/*访问量统计*/
$vs=$content['v']+1;
mysql_query("UPDATE dd_book_content SET v='$vs' WHERE bookid='{$_GET["rid"]}'");
function utf8_strlen($string = null) {
preg_match_all("/./us", $string, $match);
return count($match[0]);
}
//获取上下条内容
function up_down($gro,$articleid,$wapid,$upORdown,$q){
   if($upORdown=='up'){
        $sql = "SELECT bookid,groid,title,v,content,time FROM dd_book_content WHERE groid='{$gro}' AND bookid<{$articleid} ORDER BY articleid DESC LIMIT 1";
        $result = mysql_query($sql);      
	    if($result && mysql_num_rows($result)>0){
	    $i=0;
	    while(list($bookid,$gro,$title,$v,$content,$time)=mysql_fetch_row($result)){
	    $html .=  '<a href="read.php?cid='.$_GET['cid'].'&id='.$gro.'&rid='.$bookid.'" target="_blank">'.$q.$title.'</a>';
	     }
	 }else{
	 $html = NULL;
	     }
	 }elseif($upORdown=='down'){
	      $sql="SELECT articleid,groid,title,v,content,time FROM dd_book_content WHERE groid='{$gro}' AND bookid>{$articleid} ORDER BY articleid  LIMIT 1";
	      /*执行数据查询语句*/  
          $result=mysql_query($sql);      
	      if($result && mysql_num_rows($result)>0){
	      $i=0;
	      while(list($articleid,$gro,$title,$v,$content,$time)=mysql_fetch_row($result)){
	      $html .= '<a href="read.php?cid='.$_GET['cid'].'&id='.$gro.'&rid='.$bookid.'" target="_blank">'.$q.$title.'</a>';
	      }
	 }else{
	 $html = NULL;
	     }
	 
	    }
		return $html;
	 }
	 $upStr   =  up_down($_GET['id'],$_GET['rid'],WAPID,"up","上一章:");
	 $downStr =  up_down($_GET['id'],$_GET['rid'],WAPID,"down","下一章:");
	 if($upStr == NULL && $downStr == NULL)
	 {
	 $nav = NULL;
	 }else{
	       if($upStr == NULL XOR $downStr == NULL)
	       {
	     $brHml = '';
	 }else{
	     $brHml = '<br>';
	 }
	 $nav = '<div class="listnav">'.up_down($_GET['id'],$_GET['rid'],WAPID,"up","上一章:").$brHml.up_down($_GET['id'],$_GET['rid'],WAPID,"down","下一章:").'</div>';
	 }
//长度处理
$l=1200;
$text = mb_substr($content['content'],slist($_GET['p'],1200),$l,"UTF-8");
//if(utf8_strlen($content)>$l){}
$nums     =     utf8_strlen($content);
$limit    =     $l;
//加载文章分页
if($nums  > $limit){
$url      =     'read.php?cid='.$_GET['cid'].'&id='.$_GET['id'].'&rid='.$_GET['rid'].'&';
$page     =      '<div class="mylink">'.page($nums,$limit,$url,'p','view').'</div>';
}
$html = head($content['title']).UBB(class_get_info($_GET['cid'],"top_three",$wapid),$wapid).'
<div class="art">
<div class="art_title">'.$content['title'].'</div>
<div class="art_sub">
作者:'.$content['userid'].'&nbsp;&nbsp;人气:'.$content['v'].'&nbsp;&nbsp;时间'.date("Y/m/d H:i",$content['time']).'
</div>
<div class="art_view">
	<pre>'.$text.'</pre>
	'.$page.'</div></div>'.$nav.'<div class="comm"><div class="title">精彩评论</div>'.listReply($_GET['id'],'dd_book_name').'<div class="title">发表评论</div><form  method="post" action="reply.php">
 <textarea type="input" name="content"></textarea>
  <input type="hidden" name="gro" value="'.$_GET['id'].'"><br>
  <input type="submit" value="发表评论">
</form></div>';	
$html= $html.class_get_info($_GET['cid'],"bottom_three",$wapid);
echo UBB($html,$wapid);
?>
<div class="mylink">
<a href="list.php?&cid=<?php  echo $gro;?>">返回上级</a><a href="../index.php">返回首页</a>
	</div>
<?php  echo footer(1);?>