<?php 
ob_start();//在你的开始处加入ob_start();
echo '<?'.'xml version="1.0" encoding="UTF-8"'.'?>';
?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/">
<channel>
<?php 
require( 'data/config.php');
$conn=mysql_connect($db_host,$db_user,$db_pass);
mysql_query("set names 'utf8'");
mysql_select_db($db_name);
if (PHP_VERSION >= '5.1' && !empty($timezone))
{
    date_default_timezone_set($timezone);
}
function _get($str){  
$val = !empty($_GET[$str]) ? $_GET[$str] : null;  
return $val;  
}
function _post($str){  
$val = !empty($_POST[$str]) ? $_POST[$str] : null;  
return $val;  
}
$sql = 'SELECT * ' .
            'FROM tm_php_info where id=1';
    $res = mysql_fetch_object(mysql_query($sql));

        $arr = array();
        $arr['title']= $res->title;
        $arr['cont']= $res->cont;
        $arr['foot'] = $res->foot;
		    $arr['bah'] = $res->bah;
		    $arr['url']= "http://".$_SERVER['SERVER_NAME'];
$id=_get('id');
$action=_get('action');
$sdate=_get('sdate');
$tagid=_get('tagid');
$pid=_get('pid');
if($sdate<>"")
   {
$date1=$sdate."-01";
$date2=$sdate."-31";
   }
if($action=="gg")
  {
  ?>
<title><?php echo $arr['title'];?> &#187; 公告列表</title>
<atom:link href="<?php echo $arr['url'].request_uri();?>rss.xml" rel="self" type="application/rss+xml" />
	<link><?php echo $arr['url'].request_uri();?></link>
	<description><?php echo $arr['cont'];?></description>
	<lastBuildDate><?php echo date('Y-m-d');?></lastBuildDate>
	<generator>http://php.tmacn.cn/index.php?v=6.0</generator>
	<language>zh-CN</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
  <?php 
  }
elseif($action=="artlist")
  {
  ?>
  <title><?php echo $res->title;?><?php if($id<>"") { $rs=mysql_fetch_object(mysql_query("select * from tm_art_class where art_id='$id'"));echo " &#187; ".$rs->art_name;}?></title>
	<atom:link href="<?php echo $arr['url'].request_uri();?>rss.xml" rel="self" type="application/rss+xml" />
	<link><?php echo $arr['url'].request_uri();?></link>
	<description><?php echo $arr['cont'];?></description>
	<lastBuildDate><?php echo date('Y-m-d');?></lastBuildDate>
	<generator>http://php.tmacn.cn/index.php?v=6.0</generator>
	<language>zh-CN</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
  <?php 
  }
elseif($action=="date")
  {
  ?>
  <title><?php echo $res->title;?><?php if($sdate<>"") echo  " &#187; 日期为".$sdate."的日志统计";?></title>
	<atom:link href="<?php echo $arr['url'].request_uri();?>rss.xml" rel="self" type="application/rss+xml" />
	<link><?php echo $arr['url'].request_uri();?></link>
	<description><?php echo $arr['cont'];?></description>
	<lastBuildDate><?php echo date('Y-m-d');?></lastBuildDate>
	<generator>http://php.tmacn.cn/index.php?v=6.0</generator>
	<language>zh-CN</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
  <?php 
  }
elseif($action=="tag")
  {
 $rs=mysql_fetch_object(mysql_query("select * from tm_tag where tag_id='$tagid'"));
  ?>
  <title><?php echo $res->title;?> &#187; “<?php echo $rs->tag_name?>”标签</title>
	<atom:link href="<?php echo $arr['url'].request_uri();?>rss.xml" rel="self" type="application/rss+xml" />
	<link><?php echo $arr['url'].request_uri();?></link>
	<description><?php echo $arr['cont'];?></description>
	<lastBuildDate><?php echo date('Y-m-d');?></lastBuildDate>
	<generator>http://php.tmacn.cn/index.php?v=6.0</generator>
	<language>zh-CN</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
  <?php 
  }
elseif($action=="ret")
  {
  $rs=mysql_fetch_object(mysql_query("select * from tm_art where art_id='$pid'"));
  ?>
  <title><?php echo $res->title;?> &#187; “<?php echo $rs->art_title;?>”的评论</title>
	<atom:link href="<?php echo $arr['url'].request_uri();?>rss.xml" rel="self" type="application/rss+xml" />
	<link><?php echo $arr['url'].request_uri();?></link>
	<description><?php echo $arr['cont'];?></description>
	<lastBuildDate><?php echo date('Y-m-d');?></lastBuildDate>
	<generator>http://php.tmacn.cn/index.php?v=6.0</generator>
	<language>zh-CN</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
  <?php 
  }
else
  {
  ?>
  	<title><?php echo $res->title;?></title>
	<atom:link href="<?php echo $arr['url'].request_uri();?>rss.xml" rel="self" type="application/rss+xml" />
	<link><?php echo $arr['url'].request_uri();?></link>
	<description><?php echo $arr['cont'];?></description>
	<lastBuildDate><?php echo date('Y-m-d');?></lastBuildDate>
	<generator>http://php.tmacn.cn/index.php?v=6.0</generator>
	<language>zh-CN</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
  <?php 
  }
?>

<?php 
if($action=="gg")
  {
  $sql="select * from tm_about order by id DESC limit 30";
$rsql=mysql_query($sql);
	while($res=mysql_fetch_object($rsql))
	     {
?>
<item>
		<title><?php echo $res->title;?></title>
		<link><?php echo $arr['url'].request_uri()."about.php?id=".$res->id;?></link>
		<pubDate><?php echo $res->date;?></pubDate>
		<dc:creator><?php echo $res->name;?></dc:creator>
		<category><![CDATA[<?php if($res->tj==1) echo "推荐"; else echo "非推荐";?>]]></category>
		<description><![CDATA[<?php echo $res->cont;?>]]></description>
</item>
<?php 
   }
}
elseif($action=="artlist")
  {
  ?>
  <?php 
$sql="select tm_art.*,tm_art_class.art_name as cart_name,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.show1=1 and tm_art.art_class='$id' order by tm_art.art_id DESC limit 30";	
$rsql=mysql_query($sql);

    $arr = array();
	$i=0;
	while($res=mysql_fetch_object($rsql))
	     {
?>
<item>
		<title><?php echo $res->art_title;?></title>
		<link><?php echo $arr['url'].request_uri().$res->filename."/".substr(ereg_replace('-',"",$res->art_date),0,6)."/".ereg_replace('-',"",$res->art_date).$res->art_id.".html";?></link>
		<pubDate><?php echo $res->art_date;?></pubDate>
		<dc:creator><?php echo $res->art_name;?></dc:creator>
		<category><![CDATA[<?php 
		$sql="select * from tm_tag where tag_id='$res->art_tag'";
$resultc=mysql_query($sql) or die(mysql_error());
$rsc=mysql_fetch_object($resultc);
echo $rsc->tag_name;	
		?>]]></category>
		<description><![CDATA[<?php echo $res->art_cont;?>]]></description>
</item>
<?php 
}
?>
  <?php 
  }
elseif($action=="date")
  {
  ?>
  <?php 
$sql="select tm_art.*,tm_art_class.art_name as cart_name,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_date>='$date1' and tm_art.art_date<='$date2' order by tm_art.art_id DESC limit 30";
$rsql=mysql_query($sql);
    $arr = array();
	$i=0;
	while($res=mysql_fetch_object($rsql))
	     {
?>
<item>
		<title><?php echo $res->art_title;?></title>
		<link><?php echo $arr['url'].request_uri().$res->filename."/".substr(ereg_replace('-',"",$res->art_date),0,6)."/".ereg_replace('-',"",$res->art_date).$res->art_id.".html";?></link>
		<pubDate><?php echo $res->art_date;?></pubDate>
		<dc:creator><?php echo $res->art_name;?></dc:creator>
		<category><![CDATA[<?php 
		$sql="select * from tm_tag where tag_id='$res->art_tag'";
$resultc=mysql_query($sql) or die(mysql_error());
$rsc=mysql_fetch_object($resultc);
echo $rsc->tag_name;	
		?>]]></category>
		<description><![CDATA[<?php echo $res->art_cont;?>]]></description>
</item>
<?php 
}
?>
  <?php 
  }
elseif($action=="tag")
  {
  ?>
  <?php 
$sql="select tm_art.*,tm_art_class.art_name as cart_name,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_tag='$tagid' order by tm_art.art_id DESC limit 30";
$rsql=mysql_query($sql);
    $arr = array();
	$i=0;
	while($res=mysql_fetch_object($rsql))
	     {
?>
<item>
		<title><?php echo $res->art_title;?></title>
		<link><?php echo $arr['url'].request_uri().$res->filename."/".substr(ereg_replace('-',"",$res->art_date),0,6)."/".ereg_replace('-',"",$res->art_date).$res->art_id.".html";?></link>
		<pubDate><?php echo $res->art_date;?></pubDate>
		<dc:creator><?php echo $res->art_name;?></dc:creator>
		<category><![CDATA[<?php 
		$sql="select * from tm_tag where tag_id='$res->art_tag'";
$resultc=mysql_query($sql) or die(mysql_error());
$rsc=mysql_fetch_object($resultc);
echo $rsc->tag_name;	
		?>]]></category>
		<description><![CDATA[<?php echo $res->art_cont;?>]]></description>
</item>
<?php 
}
?>
  <?php 
  }
elseif($action=="ret")
  {
  ?>
  <?php 
  
$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:";

$sql="select * from tm_art_re where re_artid ='$pid' order by re_id desc limit 30";
$rsql=mysql_query($sql);
    $arr = array();
	$i=0;
	while($res=mysql_fetch_object($rsql))
	     {
?>
<item>
		<title><?php echo $res->re_name;?>的评论</title>
		<link><?php echo $arr['url'].request_uri().$res->filename."/".substr(ereg_replace('-',"",$res->art_date),0,6)."/".ereg_replace('-',"",$res->art_date).$res->art_id.".html";?></link>
		<pubDate><?php echo $res->re_date;?></pubDate>
		<dc:creator><?php echo $res->re_name;?></dc:creator>
		<category><![CDATA[<?php echo $res->re_name;?>]]></category>
		<description><![CDATA[<?php 
		$cont=$res->re_cont;
      for($j=0;$j<11;$j++)
          {
          $cont=str_replace($bqlist[$j][fh],$bqlist[$j][img],$cont);
          }
		  echo $cont;
		?>]]></description>
</item>
<?php 
}
?>
  <?php 
  }
else
  {
?>
<?php 
$sql="select tm_art.*,tm_art_class.art_name as cart_name,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.show1=1 order by tm_art.art_id DESC limit 30";	  

$rsql=mysql_query($sql);

    $arr = array();
	$i=0;
	while($res=mysql_fetch_object($rsql))
	     {
?>
<item>
		<title><?php echo $res->art_title;?></title>
		<link><?php echo $arr['url'].request_uri().$res->filename."/".substr(ereg_replace('-',"",$res->art_date),0,6)."/".ereg_replace('-',"",$res->art_date).$res->art_id.".html";?></link>
		<pubDate><?php echo $res->art_date;?></pubDate>
		<dc:creator><?php echo $res->art_name;?></dc:creator>
		<category><![CDATA[<?php 
		$sql="select * from tm_tag where tag_id='$res->art_tag'";
$resultc=mysql_query($sql) or die(mysql_error());
$rsc=mysql_fetch_object($resultc);
echo $rsc->tag_name;	
		?>]]></category>
		<description><![CDATA[<?php echo $res->art_cont;?>]]></description>
</item>
<?php }
}
?>
</channel>
</rss>
<?php 
//在结尾加入ob_end_clean(),并把本页输出到一个变量中
$temp1=ob_get_contents();
ob_end_clean();
$filename="rss.xml";
$fp=fopen("$filename",'w');
fwrite($fp,$temp1) or die('写文件错误'); //
?>
<?php 
readfile("rss.xml", "r");
function request_uri() 
{ 
if (isset($_SERVER['REQUEST_URI'])) 
{ 
$uri = $_SERVER['REQUEST_URI'];
} 
else 
{ 
if (isset($_SERVER['argv']))
{ 
$uri = $_SERVER['PHP_SELF'] .'?'. $_SERVER['argv'][0]; 
} 
else 
{ 
$uri = $_SERVER['PHP_SELF'] .'?'. $_SERVER['QUERY_STRING'];
} 
} 
$temp=array();
$temp=explode("/",$uri);
$uri="";
for($i=0;$i<(count($temp)-1);$i++)
    $uri.=$temp[$i]."/";
return $uri;
}
?>