<?
$g4_path = '..'; // common.php 의 상대 경로
include_once($g4_path.'/common.php');
include_once(AMINA_PATH.'/lib/view.lib.php');
include_once(AMINA_PATH.'/lib/tag.lib.php');

//뽑아올 글 수
$rss_rows = 10;

$yoil = array("Sun","Mon","Tue","Wed","Thu","Fri","Sat");

//특수문자 변환
function specialchars_replace($str, $len=0) {
    if ($len) {
        $str = substr($str, 0, $len);
    }

	$str = preg_replace("/&/", "&amp;", $str);
    $str = preg_replace("/</", "&lt;", $str);
    $str = preg_replace("/>/", "&gt;", $str);
    return $str;
}

Header("Content-type: text/xml; charset=utf-8"); 
header("Cache-Control: no-cache, must-revalidate"); 
header("Pragma: no-cache");   

echo '<?xml version="1.0" encoding="UTF-8"?>'."\n";

?>

<rss version="2.0">
<channel>
<title><?=specialchars_replace($config['cf_title'])?></title>
<link><?=specialchars_replace(G4_URL)?></link>
<description><?=specialchars_replace($config['cf_title'])?></description>
<language>ko</language>
<pubDate><?=$yoil[date('w', G4_SERVER_TIME)]?>, <?=date('d M Y H:i:s', G4_SERVER_TIME)?> +0900</pubDate>
<generator>AMINA SKIN for GNU Board</generator>

<?
//RSS 추출
$result = sql_query(" select * from {$g4['board_new_table']} where wr_rss != '' order by bn_id desc limit $rss_rows ");
for ($i=0; $row=sql_fetch_array($result); $i++) {

	//링크설정
	$link = G4_BBS_URL.'/board.php?bo_table='.$row['bo_table'].'&wr_id='.$row['wr_id']; //짧은 주소

    $board = sql_fetch(" select * from {$g4['board_table']} where bo_table = '{$row['bo_table']}' ");
	$row1 = sql_fetch(" select * from {$g4['write_prefix']}{$row[bo_table]} where wr_id = '$row[wr_id]' "); //글 정보 불러오기..

	$row1['file'] = get_file($row['bo_table'], $row['wr_id']);
	$row1['tag'] = amina_get_tag($row['bo_table'], $row['wr_id']);

	$wr_icon = amina_array_icon($row1['wr_5']);
	if($wr_icon['po_view_point'] > 0) {
		if($row1['wr_3']) {
			$wr_content = amina_text($row1['wr_3']);
		} else {
			$wr_content = amina_cut($row1['wr_content'], 250);
		}

		$po_img_list = '';
		if($wr_icon['po_img_cnt'] > 0) {
			$po_img = amina_thumb_img($row1['file'], $row1['wr_6'], $row1['wr_content'], $wr_icon['po_img_cnt'], $row1['wr_4'], $row1['wr_8'], '');

			for($p=0;$p < count($po_img);$p++) {
				$po_img_list .= "<br><br><img src='".$po_img[$p]."' border=0>";
			}
		}

		$row1['wr_content'] = '[미리보기] '.$wr_content.$po_img_list;

	} else {
		$wr_post = amina_array_write($row1['wr_10']);
		if($wr_post['img_location'] == "insert") $row1['wr_content'] = preg_replace("/{이미지\:([0-9]+)[:]?([^}]*)}/ie", "view_image(\$row1, '\\1', '\\2')", $row1['wr_content']);
	}

?>
	<item>
	<title><?=specialchars_replace($row1['wr_subject'])?></title>
	<link><?=specialchars_replace($link)?></link>
	<description><?=specialchars_replace(amina_view_contents($row1['wr_content'], $row1['file'], $row1['wr_6'], $wr_post, (int)$board['bo_image_width'],"rss"))?></description>
	<? if($row1['tag']) { ?>
		<tag><![CDATA[<?=specialchars_replace($row1['tag'])?>]]></tag>
	<? } ?>
	<author><?=specialchars_replace($row1['wr_name'])?></author>
	<guid><?=specialchars_replace($link)?></guid>
	<pubDate><?=$yoil[date('w', strtotime($row['bn_datetime']))]?>, <?=date('d M Y H:i:s', strtotime($row['bn_datetime']))?> +0900</pubDate>
	</item>
<? } ?>

</channel>
</rss>