<?php

/*
 * Copyright (C) xgcms.com
 */

class rss extends base_model {
	
	function __construct(&$conf) {
		parent::__construct($conf);
	}
	public function sitemap(){
		
		$file=POST_PATH.'sitemap.xml';
		$i=false;
		if(is_file($file)){
			$update_time=filectime($file);
			$time=$_SERVER['time'];
			if(($time-$update_time)>3600){
				$i=true;
			}
		
		}else{
			$i=true;
			
		}
		if($i){
		        $app_url=$this->conf['app_url'];
				$list=$this->topic->index_fetch(array('dateline'=>array('<'=>$_SERVER['time'])),array('dateline'=>-1),0,5000);
				$htm='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>'.$this->conf['app_name'].'-站点地图</title>
<style type="text/css">
.text-list{}
.text-list li{line-height:25px;}
.text-list li a{ text-decoration:none}
</style>
</head>
<body>
<h1><a href="'.$this->conf['app_url'].'">'.$this->conf['app_name'].'</a>>站点地图</h1>
<div class="text-list">
<ul>';
				$str='<?xml version="1.0" encoding="UTF-8"?>
							<urlset>';
	            $forumarr=array();
				foreach($list as $v){
					if(!isset($forumarr[$v['fid']])){
						$forumarr[$v['fid']]=$forum=$this->mcache->read('forum',$v['fid']);
						if(!$forum) continue;
					}elseif(empty($forumarr[$v['fid']])){
						 continue;
					}else{
						$forum=$forumarr[$v['fid']];
					}
				   $this->topic->format($v,1,$forum);
				   $htm.='<li><a href="'.$v['url'].'">'.$v['subject'].'</a></li>';
				   $str.=' <url>
					  <loc>'.$v['url'].'</loc>
					  <lastmod>'.date('Y-m-d',$v['dateline']).'</lastmod>
					  <changefreq>always</changefreq>
					  <priority>1.0</priority>
					</url>';
				}
				$htm.='</ul></div></body></html>';
				$str.='
					   </urlset>';
				
				@file_put_contents(POST_PATH.'sitemap.html',$htm);	
				@file_put_contents($file,$str);		
		}
		
	}
	
	
}

?>