rss 말고 json 으로 … 출력하는 방법
그누보드가 설치된 곳에서 rss.php 파일을 복사하여 api.php로 만든다.
/bbs/rss.php?bo_table=notice
아래와 같이 코드 만들면 url 호출 하면 됨.
/bbs/api.php?bo_table=notice
<?php
include_once('./_common.php');
// 특수문자 변환
function specialchars_replace($str, $len=0) {
if ($len) {
$str = substr($str, 0, $len);
}
$str = str_replace(array("&", "<", ">"), array("&", "<", ">"), $str);
/*
$str = preg_replace("/&/", "&", $str);
$str = preg_replace("/</", "<", $str);
$str = preg_replace("/>/", ">", $str);
*/
return $str;
}
$sql = " select gr_id, bo_subject, bo_page_rows, bo_read_level, bo_use_rss_view from {$g5['board_table']} where bo_table = '$bo_table' ";
$row = sql_fetch($sql);
$subj2 = specialchars_replace($row['bo_subject'], 255);
$lines = $row['bo_page_rows'];
// 비회원 읽기가 가능한 게시판만 RSS 지원
if ($row['bo_read_level'] >= 2) {
echo '비회원 읽기가 가능한 게시판만 RSS 지원합니다.';
exit;
}
// RSS 사용 체크
if (!$row['bo_use_rss_view']) {
echo 'RSS 보기가 금지되어 있습니다.';
exit;
}
header('Content-type: application/json');
header('Cache-Control: no-cache, must-revalidate');
header('Pragma: no-cache');
$sql = " select gr_subject from {$g5['group_table']} where gr_id = '{$row['gr_id']}' ";
$row = sql_fetch($sql);
$subj1 = specialchars_replace($row['gr_subject'], 255);
$sql = " select wr_id, wr_subject, wr_content, wr_name, wr_datetime, wr_option
from {$g5['write_prefix']}$bo_table
where wr_is_comment = 0
and wr_option not like '%secret%'
order by wr_num, wr_reply limit 0, $lines ";
$result = sql_query($sql);
$json_string = "{ \"items\": [";
for ($i=0; $row=sql_fetch_array($result); $i++) {
// echo " [ ";
$file = '';
// $json_string .= " \"item\": [";
if (strstr($row['wr_option'], 'html'))
$html = 1;
else
$html = 0;
$json_string .= json_encode($row) . ",";
}
$json_string = substr($json_string, 0, -1);
$json_string .= "]";
echo $json_string ;
echo "}";
?>