<?php 
require "../Run.php";
require "../include/page.inc.php";
require "../include/reply.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;
$textFile = 'data/'.$_GET['id'].'.data.php';
if(is_file($textFile) && filemtime($textFile) > time()-$cfg['art_hc_time'] && $cfg['art_hc'] == TRUE ){
	function ReadData($textFile,$key){
	$pattern ='/\<\-(?:[key])+\=\"(?:['.$key.'])+\" (?:[value])+\=\"(.+?)\"\-\>/is';
	$con     = file_get_contents($textFile);
	preg_match($pattern,$con,$match);
	return $match[1];
	}
	$articleid  =  ReadData($textFile,'id');
	$userid     =  ReadData($textFile,'user');
	$title      =  ReadData($textFile,'title');
	$content    =  ReadData($textFile,'content');
	$pic        =  ReadData($textFile,'pic');
	$name       =  ReadData($textFile,'name');
	$v          =  ReadData($textFile,'v');
	$time       =  ReadData($textFile,'time');
	$gro        =  ReadData($textFile,'gro');
}else{
$sql="SELECT articleid,userid,title,content,pic,name,v,time,gro FROM article WHERE articleid='{$_GET['id']}'";
	$view = mysql_query($sql);
	if($view && mysql_num_rows($view)>0){
		list($articleid,$userid,$title,$content,$pic,$name,$v,$time,$gro) = mysql_fetch_row($view);
		if($pic == NULL){$pics='NULL';}else{$pics = $pic;}
		if($cfg['art_hc'] == TRUE){
		//当文章缓存开启时，才进行缓存数据操作
		$fileContent ='
		<-key="id" value="'.$articleid.'"->
		<-key="user" value="'.$userid.'"->
		<-key="title" value="'.$title.'"->
		<-key="content" value="'.$content.'"->
		<-key="pic" value="'.$pics.'"->
		<-key="name" value="'.$name.'"->
		<-key="v" value="'.$v.'"->
		<-key="time" value="'.$time.'"->
		<-key="gro" value="'.$gro.'"->';
		$fileContent = '<?php  die("数据资源禁止直接阅读：STOP TO READ!"); ?>
		'.$fileContent;
		file_put_contents($textFile,$fileContent);
			}
	}else{
		$tip = "哎呀，找不到资源，该文章可能已经被删除了，也可能是您的地址写错喽!";
		}
	}
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($pic==NULL||$pic == 'NULL'){
$pic = NULL;
}else{
$pic = '<div class="pic">
<img src="article/uploads/'.$pic.'">
</div>';
}
//获取上下条内容
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;
	 }
function art_reply(){


}
	 $upStr   =  up_down($gro,$articleid,$wapid,"up","上一篇:");
	 $downStr =  up_down($gro,$articleid,$wapid,"down","下一篇:");
	 if($upStr == NULL && $downStr == NULL)
	 {
	 $nav='';
	 }else{
	       if($upStr == NULL || $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;
if(!$_GET['page']){
$p=1;
		}elseif($_GET['page']<=0){
	$p=1;
		}else{
	$p=$_GET['page'];
	}
$s = ($p-1)*$l;
$text = mb_substr($content,$s,$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');
}
$html = head($title).UBB(class_get_info($_GET['cid'],"top_three",$wapid),$wapid).'
<div class="art">
<div class="art_title">'.$title.'</div>
<div class="art_sub">
作者:'.$userid.'&nbsp;&nbsp;人气:'.$v.'&nbsp;&nbsp;时间'.$time.'
</div>
<div class="art_view">
	<pre>'.$pic.$text.'</pre>
	<div class="mylink">'.$page.'</div>
	</div></div>'.$nav.'<div class="comm"><div class="title">精彩评论</div>'.listReply($_GET['id'],'article').'<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);?>
	