<?
header("Content-Type: text/xml; charset=UTF-8");

include "/home/tig/public_html/global/global.inc.php";
include "/home/tig/public_html/global/template.inc.php";
include "/home/tig/public_html/global/main.inc.php";
//include "include/index0.inc.php";

db_connect();

function strip_htm($str) {
	$str = str_replace("[[[", "<img src=", $str);
	$str = str_replace("]]]", ">", $str);
	$str = str_replace("[[#", "<img src=", $str);
	$str = str_replace("#]]", ">", $str);
	$str = str_replace("<br><br>", "<br>", $str);
	$str = str_replace("<br><br>", "<br>", $str);
	$str = str_replace("</p>", "&nbsp;", $str);
	$str = str_replace("</P>", "&nbsp;", $str);
	$str = strip_tags($str, "<br><a>");
	$str = str_replace("\n", "&nbsp;", $str);
	$str = str_replace("\r", "", $str);
	$str = str_replace("&acute;", "'", $str);
	$str = str_replace("&quot;","'", $str);
	$str = str_replace("<br>","&nbsp;", $str);
	$str = str_replace("<BR>","&nbsp;", $str);
	$str = str_replace("&nbsp;&nbsp;","&nbsp;", $str);
	$str = str_replace("&nbsp;&nbsp;","&nbsp;", $str);
	$str = str_replace(" &nbsp;","&nbsp;", $str);
	$str = str_replace("&nbsp;&nbsp;","&nbsp;", $str);
	$str = str_cut($str, 600);
//	$str = str_replace("&", "&amp;", $str);
//	$str = str_replace("<", "&lt;", $str);
//	$str = str_replace(">", "&gt;", $str);
//	$str = str_replace("\"", "&quot;", $str);

	return $str;
}




function get_boardname($category) {
	$query = "select ba_name from boardadmin_tb where ba_category = $category";
	$result = db_query($query);
	return db_result($result);
}

$board_title = get_boardname($category);
$board_title = str_replace("&", "&amp;", $board_title);
$board_title = str_replace("/", "&amp;", $board_title); //메뉴명에서 자주 사용하는 & 특문 들어가서 XML 깨지는 경우 방지

$rss  = '<';
$rss .= '?xml';
$rss .= " version=\"1.0\" encoding=\"utf-8\"";
$rss .= '?';
$rss .= '>';
$rss .= "\r\n";
$rss .= "<rss version=\"2.0\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\">\r\n";

$date = date("r");

$rss .= "	<channel>\r\n";
$rss .= "		<title>디스이즈게임/".$board_title."</title>\r\n";
$rss .= "		<link>http://thisisgame.com/board/list.php?category=$category</link>\r\n";
$rss .=	"		<image>\r\n";
$rss .= "			<title>디스이즈게임/".$board_title."</title>\r\n";
$rss .= "			<url>http://www.thisisgame.com/images/tigrss.jpg</url>\r\n";
$rss .= "			<link>http://thisisgame.com</link>\r\n";
$rss .= "		</image>\r\n";
$rss .= "	<description>디스이즈게임(http://thisisgame.com)의 ".$board_title." RSS입니다.</description>\r\n";
$rss .= "	<language>ko</language>\r\n";
$rss .= "	<generator>Thisisgame.com</generator>\r\n";
$rss .= "	<copyright>Copyright (c) thisisgame.com All Rights reserved</copyright>\r\n";
$rss .= "	<lastBuildDate>$date</lastBuildDate>\r\n";


$query = "select b_comment, b_name, b_id, b_category, b_subcategory, b_title, b_image, b_img0, b_img1, b_img2, b_img3, b_subtitle, bv_content as b_content, UNIX_TIMESTAMP(b_firstdeskdate) as bdate from board_0,boardview_0 where b_id = bv_board and b_status in (0, 2) and b_original != 2 and b_category = $category order by b_firstdeskdate DESC limit 30"; //b_firstdeskdate와 b_date가 꼬여있어서 하나로 통일
$result = db_query($query);
$rows = db_num_rows($result);



$image_dir = "../board/files/thumnail";
$image_dir2 = "files/thumnail";


for($i=0;$i<$rows;$i++) {
	$row = db_fetch_array($result);
	
	$b_date = date("r", $row[bdate]);
	$b_firstdeskdate = date("r", $row[b_firstdeskdate]);
	
//	$row[b_content] = str_replace("/board/files/0/img/", "/board/files/0/img/", $row[b_content]);
	$b_content = strip_htm($row[b_content]);
	$row[b_title] = strip_htm($row[b_title]);

	if($b_content == ""){
		$row[b_content] = "내용이 없거나 이미지로 된 게시물입니다";
		}
	else {
		$row[b_content] = $b_content."...";
	}


/// 썸네일 처리
		if (is_file("$image_dir/$row[b_img1]")){
			$row[b_content] = "<img src='/board/".$image_dir2."/".$row[b_img1]."' style='float:left; margin: 0 12 12 0;'>".$row[b_content];
		}
		else if (is_file("$image_dir/$row[b_img2]")){
		$row[b_content] = "<img src='/board/".$image_dir2."/".$row[b_img2]."' style='float:left; margin: 0 12 12 0;'>".$row[b_content];
		}



//실시간 정보일 경우 작성자 
	if($category == 101){
		$row[b_name] = "디스이즈게임";
			}
	else {};
	
	if($row[b_comment])	$row[b_title] .= "";
	
	$rss .= "			<item>\r\n";	
	$rss .= "				<title><![CDATA[ $row[b_title] ]]></title>\r\n"; // 번호
	$rss .= "				<link><![CDATA[ http://www.thisisgame.com/board/view.php?id=$row[b_id]&category=$row[b_category] ]]></link>\r\n"; // 번호
	$rss .= "				<description><![CDATA[ $row[b_content]]]></description>\r\n";	
	$rss .= "				<category>".$board_title."</category>\r\n";	
	$rss .= "				<author>$row[b_name]</author>\r\n";	
	$rss .= "				<pubDate>$b_date</pubDate>\r\n";	
	$rss .= "			</item>\r\n";
}

$rss .= "	</channel>\r\n";
$rss .= " </rss>\r\n";

if (in_array($category, array(101, 102, 115, 103, 116, 104, 404, 410, 4001, 106, 207, 203, 607, 16001, 19001, 19002, 19003, 19004)) ) {
	echo $rss;
	}
	else {
		$rss = "RSS를 제공하지 않는 게시판입니다";
	echo $rss;
	}
?>
