<?php 
require "../Run.php";
require "../include/page.inc.php";
require "../include/reply.fun.php";
require "../include/imageView.fun.php";
	$view = mysql_query("SELECT articleid,userid,title,content,pic,spic,name,v,time,gro FROM article WHERE articleid='{$_GET['id']}'");
	if($view && mysql_num_rows($view)>0){
		list($articleid,$userid,$title,$content,$pic,$spic,$name,$v,$time,$gro) = mysql_fetch_row($view);
		if($pic == NULL){
			$pics='NULL';
		}else{
			$pics = $pic;
			}
	}else{
		ehtml("哎呀，找不到资源，该文章可能已经被删除了，也可能是您的地址写错喽!");
		exit();
		}
if($_GET['cid']<=0||$_GET['cid']==''||$_GET['cid']==NULL){
     header("location: http://".$_SERVER["HTTP_HOST"]."/article/content.php?cid=".$gro."&id=".$_GET['id']);
}
/*访问量统计*/
$vs=$v+1;
$sql="UPDATE article SET v='$vs' WHERE articleid='{$_GET["id"]}'";
$result=mysql_query($sql);
$title = $title; 
//统计字数
function utf8_strlen($string = null) {
preg_match_all("/./us", $string, $match);
return count($match[0]);
}
//图片处理
if($spic == NULL||$spic == 'NULL'){
$spic = NULL;
}else{
$spic = explode("|",$spic);
$spic = imageView($spic,'?cid='.$_GET['cid'].'&id='.$_GET['id'].'&page='.$_GET['page'].'&');
}
//获取上下条内容
function up_down($gro,$articleid,$wapid,$upORdown,$q){
   if($upORdown=='up'){
        $sql = "SELECT articleid,gro,title,v,content,time FROM article WHERE gro='{$gro}' AND articleid<{$articleid} ORDER BY articleid DESC 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="content.php?cid='.$gro.'&id='.$articleid.'" target="_blank">'.$q.$title.'</a>';
	     }
	 }else{
	 $html = NULL;
	     }
	 }elseif($upORdown=='down'){
	      $sql="SELECT articleid,gro,title,v,content,time FROM article WHERE gro='{$gro}' AND articleid>{$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="content.php?cid='.$gro.'&id='.$articleid.'&" target="_blank">'.$q.$title.'</a>';
	      }
	 }else{
	 $html = NULL;
	     }
	 
	    }
		return $html;
	 }
	 $upStr   =  up_down($gro,$articleid,WAPID,"up","上一篇:");
	 $downStr =  up_down($gro,$articleid,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($gro,$articleid,$wapid,"up"," 上一篇:").$brHml.up_down($gro,$articleid,$wapid,"down","下一篇:").'</div>';
	 }
//长度处理
$l=1200;
$text = mb_substr($content,slist($_GET['page'],$l),$l,"UTF-8");
//if(utf8_strlen($content)>$l){}
$nums     =     utf8_strlen($content);
$limit    =     $l;
//加载文章分页
if($nums  > $limit){
$url      =     'content.php?action=view&cid='.$_GET['cid'].'&id='.$_GET['id'].'&';
$page     =     page($nums,$limit,$url,NULL,'view');
}	
$tpl = new dd_Tpl;
$tpl->tpl_path(root_path . '/DdTpl/comdir');
$assign = array(
	'title'=>$title,
	'content'=>$spic.$text,
	'user'=>$userid,
	'v'=>$v,
	'time'=>date('Y/m/d H:i',$time),
	'page'=>$page,
	'nav'=>$nav,
	'replay'=>listReply($_GET['id'],'article'),
	'id'=>$_GET['id'],
	'gro'=>$gro,
);
$tpl->assign($assign);
echo head($title);
echo UBB(class_get_info($_GET['cid'],"top_three"));
$tpl->display('article');
echo UBB(class_get_info($_GET['cid'],"bottom_three"));
echo footer(1);
?>