2008년 3월 19일 수요일

[강좌] RSS,ATOM 생성 클래스 .. php에서 rss 새성하기

예전에 내가 급하게 만들었던 rss 만들기 클래스가 있었는데..
[강좌] php에서 rss 문서 만들기
간단하게 수정해서 쓸만하긴 하지만 먼가 어설퍼서  ㅋㅋ

feedcreator 라는 프로그램을 소개한다.~
http://www.bitfolge.de/rsscreator-en.html
RSS0.91, RSS1.0, RSS2.0, PIE0.1, MBOX, OPML, ATOM0.3, HTML, JS
다양한 포맷을 지원한다.

아래는 feedcreator.cass.php에 포함된 사용 예제..

include("feedcreator.class.php");

$rss = new UniversalFeedCreator();
$rss->useCached();

//타이틀
$rss->title = "PHP news";
//피드 설명
$rss->description = "daily news from the PHP scripting world";
//링크
$rss->link = "http://www.dailyphp.net/news";
//피드주소
$rss->feedURL = "http://www.dailyphp.net/".$PHP_SELF;

//이미지와 관련된것. 아마 이게 rss 2.0에 새로 생긴것같음..
// 글과 따로 이미지를 넣을수 있음
$image = new FeedImage();
$image->title = "dailyphp.net logo";
$image->url = "http://www.dailyphp.net/images/logo.gif";
$image->link = "http://www.dailyphp.net";
$image->description = "Feed provided by dailyphp.net. Click to visit.";

// 옵션
$image->descriptionTruncSize = 500;
$image->descriptionHtmlSyndicated = true;

$rss->image = $image;

// 대충 여기서 db 돌리고..
//mysql_select_db($dbHost, $dbUser, $dbPass);
//$res = mysql_query("SELECT * FROM news ORDER BY newsdate DESC");
//while ($data = mysql_fetch_object($res)) {
    $item = new FeedItem();

     //글 제목
    $item->title = "This is an the test title of an item";
    //글 주소
    $item->link = "http://localhost/item/";
    //글 내용
    $item->description = "<b>description in </b><br/>HTML";
   
    //피드 시간
    $item->date = time();
    $item->source = "http://www.dailyphp.net";
    $item->author = "John Doe";
    
    $rss->addItem($item);
//}

// 원하는 피드 형식을 정해주면 됨
// 피드 형식 :  RSS0.91, RSS1.0, RSS2.0, PIE0.1, MBOX, OPML, ATOM0.3, HTML, JS
echo $rss->saveFeed("RSS0.91", "feed.xml");
사용법 대충 보면 알겠지만 그다지 어렵지는 않다.

이거..강좌라고 해놓고 소개잖아 소개.. -_-;

댓글 없음: