전체 새글 rss 출력하기 [업그레이드] > 그누4 팁자료실

그누4 팁자료실

그누보드4와 관련된 팁을 여러분들과 함께 공유하세요.
나누면 즐거움이 커집니다.

전체 새글 rss 출력하기 [업그레이드] 정보

전체 새글 rss 출력하기 [업그레이드]

첨부파일

newrss.php (3.5K) 267회 다운로드 2006-08-10 18:32:18

본문

[요약 설명]
rss 제목을 홈페이지 제목 말고 임의로 설정할수 있도록 하였습니다.
rrs 출력 갯수를 조정할수 있도록 하였습니다.
내용에서 파일업로드된 이미지도 출력되게끔 하였습니다.
그룹제목과 게시판 제목으로 카테고리를 만들어 보여줍니다.


이하 소스입니다. 아래의 소스를 복사하여
자신의 그누보드 내 bbs/newrss.php 로 저장하십시오.
utf8 환경인 경우에는 에디터 플러스 같은것으로 저장할때 utf8로 저장하십시오.


----------------------------------------------------------------------------------------------------------------------------------------


<?

//환경설정
$Ynum = 20;//몇개를 보여줄것인지 셑팅하세요
$Ytitle = '팔봉이의 전체 새글';//기본 환경 설정의 사이트 제목 말고, 다르게 사이트 제목을 출력하고 싶을때 사용하세요. 비워두면 기본 환경설정 사이트 제목이 들어갑니다.



include_once './_common.php';

// 특수문자 변환
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;
}

if (empty($g4['title']))
  $g4['title'] = $config['cf_title'];

if (!empty($Ytitle))
  $g4['title'] = $Ytitle;

$SiteTitle = specialchars_replace($g4['title']);
$SiteUrl = specialchars_replace($g4['url'] . '/');



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

echo "<?xml version=\"1.0\" encoding=\"" . $g4['charset'] . "\"?>\n";
echo "<rss version=\"2.0\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\">\n";
echo "<channel>\n";
echo "<title>" . $SiteTitle . "</title>\n";
echo "<link>" . $SiteUrl . "</link>\n";
echo "<description>" . $SiteTitle . "</description>\n";
echo "<language>ko</language>\n";

$sql_common = " from " . $g4['board_new_table'] . " a, " . $g4['board_table'] . " b, " . $g4['group_table'] . " c where a.bo_table = b.bo_table and b.gr_id = c.gr_id and b.bo_use_search = '1' ";

if (!empty($gr_id))
  $sql_common .= " and b.gr_id = '$gr_id' ";

$sql_common .= " and a.wr_id = a.wr_parent ";

$sql_order = " order by a.bn_id desc ";

$sql = " select a.*, b.bo_subject, c.gr_subject
                      $sql_common
                      $sql_order
                      limit $Ynum ";

$result = sql_query($sql);
for ($i=0; $row=sql_fetch_array($result); $i++) {

  $tmp_write_table = $g4['write_prefix'] . $row['bo_table'];

  $row2 = sql_fetch(" select * from $tmp_write_table where wr_id = '" . $row['wr_id'] . "' ");

  //비밀글이면 통과
  if (preg_match("`secret`", $row2['wr_option'])) continue;

  $title = specialchars_replace($row2['wr_subject']);
  $link = specialchars_replace($g4['url'] . "/" . $g4['bbs'] . "/board.php?bo_table=" . $row['bo_table'] . "&wr_id=" . $row['wr_id']);

  $html = 0;
  if (strstr($row2['wr_option'], 'html1'))
    $html = 1;
  else if (strstr($row2['wr_option'], 'html2'))
    $html = 2;

  $row2['content'] = conv_content($row2['wr_content'], $html);
  $content = '<span>';

  $row2['file'] = get_file($row['bo_table'], $row['wr_id']);
  for ($j=0; $j<=count($row2['file']); $j++) {

    if ($row2['file'][$j]['view'])
      $content .= preg_replace("'([^:])//'", '\\1/' . $row['bo_table'] . '/', str_replace($g4['path'] . '/', $g4['url'] . '/', $row2['file'][$j]['view'])) . "<p>";
  }
  $content .= $row2['content'] . '</span>';

  $name = specialchars_replace($row2['wr_name']);
  $cate1 = specialchars_replace(preg_replace("` *?게시판`", "", $row['gr_subject']));
  $cate2 = specialchars_replace(preg_replace("` *?게시판`", "", $row['bo_subject']));

  $date = $row2['wr_datetime'];
  $date = date('r', strtotime($date));

  echo "<item>\n";
  echo "<title>" . $title . "</title>\n";
  echo "<link>" . $link . "</link>\n";
  echo "<description><![CDATA[" . $content . "]]></description>\n";
  echo "<dc:creator>" . $name . "</dc:creator>\n";
  echo "<category>" . $cate1 . "</category>\n";
  echo "<category>" . $cate2 . "</category>\n";
  echo "<dc:date>" . $date . "</dc:date>\n";
  echo "</item>\n";
}

echo "</channel>\n";
echo "</rss>\n";

?>
추천
4
  • 복사

댓글 12개

$content에 데이타(이미지) 전체 주소만 뽑고 싶습니다.
어떻게 해야하는지 알려주시면 감사하겠습니다.

또한 전체 게시판을 추출하는 것이 아니라 특정 게시판(갤러리)을 뽑기위해서 어디를 어떻게 해야하는지 자세히 알려주면 감사하겠습니다.

그리고 데이터(이미지)가 없을 때 안보여지게 예외 처리를 할 수 있게 할려면 어떻게 해야하는지도 알려주시면 감사하겠습니다.
특정 그룹만을 제외하고 싶으면
위소스에서

환경설정 부분에다가
아래와 같이 한줄 추가해주시고요


//환경설정
$Ynum = 20;//몇개를 보여줄것인지 셑팅하세요
$Ytitle = '팔봉이의 전체 새글';//기본 환경 설정의 사이트 제목 말고, 다르게 사이트 제목을 출력하고 싶을때 사용하세요. 비워두면 기본 환경설정 사이트 제목이 들어갑니다.

$Yread_not_group = "test|test1";//읽어오지 않을 그룹아디를 적습니다. 구분자는 |로 하세요 옆의 예제는 test그룹과 test1그룹을 읽어오지 않겠다는 뜻입니다.



아래 부분을 찾으셔서
if (!empty($gr_id))
  $sql_common .= " and b.gr_id = '$gr_id' ";

아래와 같이 고쳐주세요.
if (!empty($gr_id))
  $sql_common .= " and b.gr_id = '$gr_id' ";

if (!empty($Yread_not_group)) {

  $temp = explode('|', $Yread_not_group);
  foreach($temp as $val){

    $val = trim($val);
    if (empty($val)) continue;

    $sql_common .= " and b.gr_id <> '$val' ";
  }
}


이렇게만 해주면 되겟습니다.



전체소스


<?

//환경설정
$Ynum = 20;//몇개를 보여줄것인지 셑팅하세요
$Ytitle = '팔봉이의 전체 새글';//기본 환경 설정의 사이트 제목 말고, 다르게 사이트 제목을 출력하고 싶을때 사용하세요. 비워두면 기본 환경설정 사이트 제목이 들어갑니다.

$Yread_not_group = "test|test1";//읽어오지 않을 그룹아디를 적습니다. 구분자는 |로 하세요 옆의 예제는 test그룹과 test1그룹을 읽어오지 않겠다는 뜻입니다.



include_once './_common.php';

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

  if ($len)
    $str = substr($str, 0, $len);

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

if (empty($g4['title']))
  $g4['title'] = $config['cf_title'];

if (!empty($Ytitle))
  $g4['title'] = $Ytitle;

$SiteTitle = specialchars_replace($g4['title']);
$SiteUrl = specialchars_replace($g4['url'] . '/');



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

echo "<?xml version=\"1.0\" encoding=\"" . $g4['charset'] . "\"?>\n";
echo "<rss version=\"2.0\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\">\n";
echo "<channel>\n";
echo "<title>" . $SiteTitle . "</title>\n";
echo "<link>" . $SiteUrl . "</link>\n";
echo "<description>" . $SiteTitle . "</description>\n";
echo "<language>ko</language>\n";

$sql_common = " from " . $g4['board_new_table'] . " a, " . $g4['board_table'] . " b, " . $g4['group_table'] . " c where a.bo_table = b.bo_table and b.gr_id = c.gr_id and b.bo_use_search = '1' ";

if (!empty($gr_id))
  $sql_common .= " and b.gr_id = '$gr_id' ";

if (!empty($Yread_not_group)) {

  $temp = explode('|', $Yread_not_group);
  foreach($temp as $val){

    $val = trim($val);
    if (empty($val)) continue;

    $sql_common .= " and b.gr_id <> '$val' ";
  }
}

$sql_common .= " and a.wr_id = a.wr_parent ";

$sql_order = " order by a.bn_id desc ";

$sql = " select a.*, b.bo_subject, c.gr_subject
                      $sql_common
                      $sql_order
                      limit $Ynum ";

$result = sql_query($sql);
for ($i=0; $row=sql_fetch_array($result); $i++) {

  $tmp_write_table = $g4['write_prefix'] . $row['bo_table'];

  $row2 = sql_fetch(" select * from $tmp_write_table where wr_id = '" . $row['wr_id'] . "' ");

  //비밀글이면 통과
  if (preg_match("`secret`", $row2['wr_option'])) continue;

  $title = specialchars_replace($row2['wr_subject']);
  $link = specialchars_replace($g4['url'] . "/" . $g4['bbs'] . "/board.php?bo_table=" . $row['bo_table'] . "&wr_id=" . $row['wr_id']);

  $html = 0;
  if (strstr($row2['wr_option'], 'html1'))
    $html = 1;
  else if (strstr($row2['wr_option'], 'html2'))
    $html = 2;

  $row2['content'] = conv_content($row2['wr_content'], $html);
  $content = '<span>';

  $row2['file'] = get_file($row['bo_table'], $row['wr_id']);
  for ($j=0; $j<=count($row2['file']); $j++) {

    if ($row2['file'][$j]['view']) 
      $content .= preg_replace("'([^:])//'", '\\1/' . $row['bo_table'] . '/', str_replace($g4['path'] . '/', $g4['url'] . '/', $row2['file'][$j]['view'])) . "<p>";
  }
  $content .= $row2['content'] . '</span>';

  $name = specialchars_replace($row2['wr_name']);
  $cate1 = specialchars_replace(preg_replace("` *?게시판`", "", $row['gr_subject']));
  $cate2 = specialchars_replace(preg_replace("` *?게시판`", "", $row['bo_subject']));

  $date = $row2['wr_datetime'];
  $date = date('r', strtotime($date));

  echo "<item>\n";
  echo "<title>" . $title . "</title>\n";
  echo "<link>" . $link . "</link>\n";
  echo "<description><![CDATA[" . $content . "]]></description>\n";
  echo "<dc:creator>" . $name . "</dc:creator>\n";
  echo "<category>" . $cate1 . "</category>\n";
  echo "<category>" . $cate2 . "</category>\n";
  echo "<dc:date>" . $date . "</dc:date>\n";
  echo "</item>\n";
}

echo "</channel>\n";
echo "</rss>\n";

?>
© SIRSOFT
현재 페이지 제일 처음으로