<?php
/*
 *		Powered by YiCms 
 *
 *		mailto:yixiao@yicms.cn
 *
 */
	class RssAction extends Action{	
		public function checkUser($level){
			if(empty($_SESSION['aid'])) $this->redirect('/Admin/Index/login');
			if(!empty($level) && !in_array($level,$_SESSION['levels'])) $this->error('您没有此权限!.');
		
		}
		public function index(){
			$this->checkUser('3_1_2');
			if(empty($_POST['submit'])) exit;			
				$num=(int)$_POST['num'];
				$config=M('Config')->find();
$str='<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="/Public/css/xml.css"?>
<!-- generator="YiCms.Cn/v2.0" -->
<rss version="2.0">
<channel>
<title>'.$config['title'].'</title>
<description>'.$config['description'].'</description>
<link>'.$config['url'].'</link>
<lastBuildDate>'.date('D, d M Y H:i:s O',time()).'</lastBuildDate>
<generator>'.$config['url'].'</generator>';
$rss=M('News')->field('id,title,time,content')->where('pid=2 and state=1')->order('id desc')->limit($num)->select();
$url=rtrim($config['url'],'/');
foreach($rss as $vo){
$str.=' <item>
	<title>'.$vo['title'].'</title>
	<link>'.C('url').'/article/'.$vo['id'].'</link>
	<description>'.$vo['content'].'</description>
	<pubDate>'.date('Y-m-d H:i:s',$vo['time']).'</pubDate>
</item>	';
}
$str.='</channel></rss>';
				$put=( file_put_contents('rss.xml',$str));
				if($put){
					echo '共生成'.$num.'条Rss信息成功，<a href="'.C('url').'/rss.xml" target="_blank">点击预览</a>';
				}else{
					echo '警告,生成失败';
				}
		}
		public function set(){
				$this->display();	
		}
		public function setbaidu(){
				$this->display();				
		}
		public function setbaidumap(){
			$this->checkUser('3_1_2');
				if(empty($_POST['submit'])) exit;
				$num=(int)$_POST['num'];
				$config=M('Config')->find();
$str='<?xml version="1.0" encoding="UTF-8" ?>
<document xmlns:bbs="http://www.baidu.com/search/bbs_sitemap.xsd">
<!-- generator="YiCms/v2.0" -->
<!-- baidu-sitemap-generator-url="'.C('url').'/" baidu-sitemap-generator-version="1.31" -->
<!-- generated-on="'.date('Y-m-d H:i:s',time()).'" -->
<webSite>'.C('url').'</webSite>
<webMaster>admin@yicms.cn</webMaster>
<updatePeri>24</updatePeri>
<updatetime>'.date('Y-m-d H:i:s',time()).'</updatetime>';
$rss=M('News')->field('id,title,time')->where('pid=2 and state=1')->order('id desc')->limit($num)->select();
$url=rtrim($config['url'],'/');
foreach($rss as $vo){
$str.='<item>
		<link>'.C('url').'/article/'.$vo['id'].'</link>
		<title>'.$vo['title'].'</title>
		<pubDate>'.date('Y-m-d H:i:s',$vo['time']).'</pubDate>
	</item>
';
}
$str.="</document>";
				$put=( file_put_contents('baidumap.xml',trim($str,'\n')));
				if($put){
					echo '共生成'.$num.'条百度地图成功，<a href="'.C('URL').'/baidumap.xml" target="_blank">点击预览</a>';
				}else{
					echo '警告,生成失败';
				}
		}
		public function setgoogle(){
			$this->display();		
		}
		public function setgooglemap(){
			$this->checkUser('3_1_2');
			if(empty($_POST['submit'])) exit;
				$num=(int)$_POST['num'];
				$config=M('Config')->find();
$str='<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="YiCms/v2.0" -->
<!-- generated-on="'.date('Y-m-d H:i:s',time()).'" -->
<urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd" xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">	
';			
$rss=M('News')->field('id,title,time')->where('pid=2 and state=1')->order('id desc')->limit($num)->select();
foreach($rss as $vo){		
$str.='<url>
	<loc>'.C('url').'/article/'.$vo['id'].'</loc>
	<lastmod>'.date('Y-m-d H:i:s',$vo['time']).'</lastmod>
	<changefreq>24</changefreq>
	<priority>0.2</priority>
</url>';
}		
$str.='</urlset>';
			$put=( file_put_contents('googlemap.xml',trim($str,'\n')));
				if($put){
					echo '共生成'.$num.'条谷歌地图，<a href="'.C('url').'/googlemap.xml" target="_blank">点击预览</a>';
				}else{
					echo '警告,生成失败';
				}
		
		
		
		}
		
		
		
		
		
		
		
		
		
		
	}
?>