<?php
ob_start();//在你的开始处加入ob_start();
/**
 * TMBLOG 首页文件
 * ============================================================================
 * 版权所有 2008-2009 梧州腾马网络服务中心，并保留所有权利。
 * 网站地址: http://php.tmacn.cn；
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和
 * 使用；不允许对程序代码以任何形式任何目的的再发布。
 * ============================================================================
 * $Author: tm $
*/

define('IN_ECS', true);

require(dirname(__FILE__) . '/includes/init.php');

if ((DEBUG_MODE & 2) != 2)
{
    $smarty->caching = true;
}

$smarty->assign('siteinfo',      get_site_info()); // 网站信息

$smarty->assign('tmbloggree',    get_gree_info()); // 导航栏

$smarty->assign('tmcategory',    get_category()); // 日志分类

$smarty->assign('tmpiccategory',    get_pic_category()); // 相册分类

$smarty->assign('tmarttj',         get_art_tj()); // 文章列表

$smarty->assign('userlist',        get_user_px()); // 评论用户排名

$smarty->assign('adtoplist',        get_adtop_list()); // 顶部通栏广告

$smarty->assign('adflashlist',        get_adflash_list()); // 右边轮播广告

$smarty->assign('adrightlist',        get_adright_list()); // 右边广告

$smarty->assign('tmdate',        get_date_list()); // 文章归档

$smarty->assign('tmtag',        get_tag_list()); // 网站标签

$smarty->assign('sitefoot',      get_foot_info()); // 底部信息

$smarty->assign('tmblog_dir',      request_uri()); // 目录

$smarty->assign('gglist',      get_gg_list()); // 公告

if(isset($_GET['id']))
   $id=$_GET['id'];
$sql="select tm_art.*,tm_art_class.art_name as classname,tm_art_class.filename from tm_art left join tm_art_class on  tm_art.art_class=tm_art_class.art_id where tm_art.art_id='$id'";
$rs=mysql_fetch_object(mysql_query($sql));
if(!$rs)
   {
      $message=array();
      $message[sb]=0;
      $message[info]="文章不存在!";
      $message[url]="javascript:history.go(-1);";
      $smarty->assign('message', $message);
      $smarty->display('message.dwt');
      exit();
   }
$cname=$rs->classname;
$filedir=$rs->filename;//生成文件目录
$des=$rs->art_key;
$smarty->assign('cname',      $cname);
$smarty->assign('des',      mb_substr(htmlspecialchars(strip_tags($des)),0,150,"utf-8"));
$art=array();
$art['id']=$rs->art_id;
$art['cname']=$rs->classname;
$art['title']=$rs->art_title;
$art['name']=$rs->art_name;
$art['inname']=$rs->art_zt;
$art['filename']=$filedir;
$art['year']= substr($rs->art_date,0,7);
$art['day']= substr($rs->art_date,8,2);
$art['cont']=$rs->art_cont;
$art['date']=$rs->art_date;
$arr['year']= substr($rs->art_date,0,7);
$arr['day']= substr($rs->art_date,8,2);
$art['cid']=$rs->art_class;
$art['url']=$filedir.$id.".html"."#postComments";
$art['nowurl']="http://".$_SERVER['SERVER_NAME'].request_uri().$rs->filename."/".substr(ereg_replace('-',"",$rs->art_date),0,6)."/".ereg_replace('-',"",$rs->art_date).$rs->art_id.".html";
$sql="select * from tm_tag where tag_id='$rs->art_tag'";
$resultc=mysql_query($sql) or die(mysql_error());
$rsc=mysql_fetch_object($resultc);
$art['tag']=$rsc->tag_name;	
$art['tag_id']=$rs->art_tag;	

$smarty->assign('art', $art);

$smarty->assign('dhindex',      "http://".$_SERVER['SERVER_NAME'].request_uri()."artlist.php?id=".$art['cid']);

$bqlist=array();
$bqlist[0][img]="<img src='"."http://".$_SERVER['SERVER_NAME'].request_uri()."themes/default/images/smilies/icon_zui.gif' class='wp-smiley-select' />";
$bqlist[0][fh]=":zui:";
$bqlist[1][img]="<img src='"."http://".$_SERVER['SERVER_NAME'].request_uri()."themes/default/images/smilies/icon_wink.gif' class='wp-smiley-select' />";
$bqlist[1][fh]=":wink:";
$bqlist[2][img]="<img src='"."http://".$_SERVER['SERVER_NAME'].request_uri()."themes/default/images/smilies/icon_twisted.gif' class='wp-smiley-select' />";
$bqlist[2][fh]=":twisted:";
$bqlist[3][img]="<img src='"."http://".$_SERVER['SERVER_NAME'].request_uri()."themes/default/images/smilies/icon_rolleyes.gif' class='wp-smiley-select' />";
$bqlist[3][fh]=":roll:";
$bqlist[4][img]="<img src='"."http://".$_SERVER['SERVER_NAME'].request_uri()."themes/default/images/smilies/icon_redface.gif' class='wp-smiley-select' />";
$bqlist[4][fh]=":oops:";
$bqlist[5][img]="<img src='"."http://".$_SERVER['SERVER_NAME'].request_uri()."themes/default/images/smilies/icon_mrgreen.gif' class='wp-smiley-select' />";
$bqlist[5][fh]=":mrgreen:";
$bqlist[6][img]="<img src='"."http://".$_SERVER['SERVER_NAME'].request_uri()."themes/default/images/smilies/icon_love.gif' class='wp-smiley-select' />";
$bqlist[6][fh]=":love:";
$bqlist[7][img]="<img src='"."http://".$_SERVER['SERVER_NAME'].request_uri()."themes/default/images/smilies/icon_lol.gif' class='wp-smiley-select' />";
$bqlist[7][fh]=":lol:";
$bqlist[8][img]="<img src='"."http://".$_SERVER['SERVER_NAME'].request_uri()."themes/default/images/smilies/icon_jidong.gif' class='wp-smiley-select' />";
$bqlist[8][fh]=":jidong:";
$bqlist[9][img]="<img src='"."http://".$_SERVER['SERVER_NAME'].request_uri()."themes/default/images/smilies/icon_idea.gif' class='wp-smiley-select' />";
$bqlist[9][fh]=":idea:";
$bqlist[10][img]="<img src='"."http://".$_SERVER['SERVER_NAME'].request_uri()."themes/default/images/smilies/icon_han.gif' class='wp-smiley-select' />";
$bqlist[10][fh]=":han:";
$retlist=array();//评论
$i=0;
$sql="select * from tm_art_re where re_artid ='$id' order by re_id asc limit 5";
$rsql=mysql_query($sql);
while($rs=mysql_fetch_object($rsql))
      {
      $retlist[$i]['cont']=$rs->re_cont;
      for($j=0;$j<11;$j++)
          {
          $retlist[$i]['cont']=str_replace($bqlist[$j][fh],$bqlist[$j][img],$retlist[$i]['cont']);
          }
      $retlist[$i]['id']=$rs->re_id;
      $retlist[$i]['yid']=$rs->re_yid;
      for($j=0;$j<11;$j++)
          {
          $retlist[$i]['yid']=str_replace($bqlist[$j][fh],$bqlist[$j][img],$retlist[$i]['yid']);
          }
      $retlist[$i]['date']=$rs->re_date;
      $retlist[$i]['re_name']=$rs->re_name;
      $retlist[$i]['re_url']=$rs->re_url;
      $retlist[$i]['ip']=$rs->ip;
      $i++;
      }
$smarty->assign('retlist', $retlist);


//相关文章开始
$hotart = array();
$sql="select * from tm_art where art_class=".$art['cid']." order by rand() desc limit 10";
$rsql=mysql_query($sql);
$i=0;
while($rs=mysql_fetch_object($rsql))
     {
	    $hotart[$i]['url']="http://".$_SERVER['SERVER_NAME'].request_uri().$art['filename']."/".substr(ereg_replace('-',"",$rs->art_date),0,6)."/".ereg_replace('-',"",$rs->art_date).$rs->art_id.".html";
      $hotart[$i]['title']= mb_substr($rs->art_title,0,30,"utf-8");
      $hotart[$i]['id']= $rs->art_id;
		$i++;
	 }
$smarty->assign('hotart',      $hotart);
//相关文章结束

$smarty->assign('tmph',      "../../");

$smarty->assign('tmrss',      "rss.php?pid=".$id."&action=ret"); // 订阅

$smarty->display('art.dwt');
?>
<?php 
//在结尾加入ob_end_clean(),并把本页输出到一个变量中
$temp1=ob_get_contents();
ob_end_clean();
$filename=$filedir."/".substr(ereg_replace('-',"",$art['date']),0,6)."/".ereg_replace('-',"",$art['date']).$id.".html";
if(!file_exists($filedir))
		{
			//检查是否有该文件夹，如果没有就创建，并给予最高权限
			mkdir("$filedir", 0755);
		}
if(!file_exists($filedir."/".substr(ereg_replace('-',"",$art['date']),0,6)))
		{
			//检查是否有该文件夹，如果没有就创建，并给予最高权限
			mkdir($filedir."/".substr(ereg_replace('-',"",$art['date']),0,6), 0755);
		}
$fp=fopen("$filename",'w');
fwrite($fp,$temp1) or die('写文件错误'); //
echo "<script>location.href='".$filename."';</script>";
?>