<?
session_start();
include $_SERVER[DOCUMENT_ROOT] . "/common/conf/config.inc.php";

// m3 google sitemap ver 1.23 by mahler83 2009-11-16
// please give feedbacks to bomool.net
// Google_Sitemap_Generator : Modify http://3dstock.co.kr   2014-12-19

$url = "http://".$_SERVER['HTTP_HOST']; 				//::::::::::::::: write your GNUboard root path

$lastmod=date("Y-m-d")."T00:00:00+00:00"; 

$xmlDoc="<?xml version='1.0' encoding='UTF-8'?>
<urlset xmlns='http://www.sitemaps.org/schemas/sitemap/0.9' 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/09/sitemap.xsd'>";
$xmlDoc.="
<url> 
  <loc>$url</loc> 
  <lastmod>$lastmod</lastmod>
  <priority>0.5</priority>
  <changefreq>daily</changefreq>
</url>"; 
/* 그누보드 URL 수정(.htaccess)  하신분 샘플  $url/ 뒷부분만 'Community' 수정하세요*/ 
$xmlDoc.="
<url> 
  <loc>$url/Community</loc> 
  <lastmod>$lastmod</lastmod>
  <priority>0.5</priority>
  <changefreq>daily</changefreq>
</url>";  
 /*  카테고리샘플 시작 $url 뒷부분의 '3D_Printing', '서울' 을 자신의 사이트 맞게 수정하세요 */ 
$xmlDoc.="
<url>
  <loc>$url/bbs/board.php?bo_table=3D_Printing&amp;sca=서울</loc> 
  <lastmod>$lastmod</lastmod>
  <priority>0.5</priority>
  <changefreq>weekly</changefreq>
</url>"; 
/*  카테고리예제 끝 */   
?> 
<?
$query = sql_query("select board_id from tbl_board_info ");
while($temp = sql_fetch_array($query)) {
	$bo_arr[] = $temp[board_id];
} 
$i = 1;
foreach($bo_arr as $bo) {
	// list of board_id
$xmlDoc.="
<url>
	<loc>$url/bbs/board.php?board_id=$bo</loc>";
	$temp = sql_fetch("select wdate from `$g5[write_prefix]$bo` order by wdate DESC");
	$lastmod = str_replace(" ", "T", substr($temp[wdate], 0, 30))."+00:00";
	
	// if 
	if(!$lastmod || strlen($lastmod) < 25 || strcmp($lastmod, "+00:00")) $lastmod = "2014-12-12T00:00:00+00:00";
	
$xmlDoc.="
	<lastmod>$lastmod</lastmod>
	<changefreq>daily</changefreq>
	<priority>0.9</priority>
</url>";

	$query = sql_query("select wr_id, wdate from `$g5[write_prefix]$bo` where wr_is_comment='0' AND wr_option NOT LIKE '%secret%'");
	while($row = sql_fetch_array($query)) {
		// list of each article
$xmlDoc.="
<url>
	<loc>$url/bbs/board.php?board_id=$bo&amp;wr_id=$row[wr_id]</loc>
";
		$temp = sql_fetch("select wdate from `$g5[write_prefix]$bo` where wr_parent='$row[wr_id]' order by wr_id DESC");
		$lastmod = str_replace(" ", "T", substr($temp[wdate], 0, 30))."+00:00";
		if(!$lastmod) {
			$temp = sql_fetch("select wdate from `$g5[write_prefix]$bo` where wr_id='$row[wr_id]'");
			$lastmod = str_replace(" ", "T", substr($temp[wdate], 0, 30))."+00:00";
		}
		if(!$lastmod) $lastmod = $g5[time_ymd];
$xmlDoc.="
	<lastmod>$lastmod</lastmod>	
	<changefreq>weekly</changefreq>	
	<priority>0.5</priority>	
</url>";
	}
	$i++;
}
$xmlDoc.="
</urlset>";
$fp = fopen("./sitemap.xml","w");
fputs($fp, $xmlDoc);
fclose($fp);
?>
