컨텐츠 위젯, RSS 기능에 ATOM1.0,RSS1.0 읽기 능력 부여

git-svn-id: http://xe-core.googlecode.com/svn/sandbox@5880 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
misol 2009-03-15 16:27:32 +00:00
parent c796cf467e
commit b058303c22

View file

@ -397,7 +397,7 @@
* @brief rss 주소로 부터 내용을 받아오는 함수
* tistory 경우 원본 주소가 location 헤더를 뿜는다. (내용은 없음)이를 해결하기 위한 수정 - rss_reader 위젯과 방식 동일
**/
function requestRssContents($rss_url) {
function requestFeedContents($rss_url) {
// request rss
$rss_url = Context::convertEncodingStr($rss_url);
$URL_parsed = parse_url($rss_url);
@ -430,7 +430,7 @@
}
$header = $oReqeust->getResponseHeader();
if($header['location']) {
return $this->requestRssContents(trim($header['location']));
return $this->requestFeedContents(trim($header['location']));
}
else {
return $oReqeust->getResponseBody();
@ -441,46 +441,179 @@
// 날짜 형태
$DATE_FORMAT = $args->date_format ? $args->date_format : "Y-m-d H:i:s";
$buff = $this->requestRssContents($args->rss_url);
$buff = $this->requestFeedContents($args->rss_url);
$encoding = preg_match("/<\?xml.*encoding=\"(.+)\".*\?>/i", $buff, $matches);
if($encoding && !preg_match("/UTF-8/i", $matches[1])) $buff = trim(iconv($matches[1]=="ks_c_5601-1987"?"EUC-KR":$matches[1], "UTF-8", $buff));
if($encoding && !preg_match("/UTF-8/i", $matches[1])) $buff = Context::convertEncodingStr($buff);
$buff = preg_replace("/<\?xml.*\?>/i", "", $buff);
$oXmlParser = new XmlParser();
$xml_doc = $oXmlParser->parse($buff);
$rss->title = $xml_doc->rss->channel->title->body;
$rss->link = $xml_doc->rss->channel->link->body;
if($xml_doc->rss) {
$rss->title = $xml_doc->rss->channel->title->body;
$rss->link = $xml_doc->rss->channel->link->body;
$items = $xml_doc->rss->channel->item;
$items = $xml_doc->rss->channel->item;
if(!$items) return;
if($items && !is_array($items)) $items = array($items);
if(!$items) return;
if($items && !is_array($items)) $items = array($items);
$content_items = array();
$content_items = array();
foreach ($items as $key => $value) {
if($key >= $args->list_count * $args->page_count) break;
unset($item);
foreach ($items as $key => $value) {
if($key >= $args->list_count * $args->page_count) break;
unset($item);
foreach($value as $key2 => $value2) {
if(is_array($value2)) $value2 = array_shift($value2);
$item->{$key2} = $this->_getRssBody($value2);
foreach($value as $key2 => $value2) {
if(is_array($value2)) $value2 = array_shift($value2);
$item->{$key2} = $this->_getRssBody($value2);
}
$content_item = new contentItem($rss->title);
$content_item->setContentsLink($rss->link);
$content_item->setTitle($item->title);
$content_item->setNickName(max($item->author,$item->{'dc:creator'}));
//$content_item->setCategory($item->category);
$item->description = preg_replace('!<a href=!is','<a onclick="window.open(this.href);return false" href=', $item->description);
$content_item->setContent($item->description);
$content_item->setLink($item->link);
$date = date('YmdHis', strtotime(max($item->pubdate,$item->pubDate,$item->{'dc:date'})));
$content_item->setRegdate($date);
$content_items[] = $content_item;
}
} elseif($xml_doc->{'rdf:RDF'}) {
$rss->title = $xml_doc->{'rdf:RDF'}->channel->title->body;
$rss->link = $xml_doc->{'rdf:RDF'}->channel->link->body;
$content_item = new contentItem($rss->title);
$content_item->setContentsLink($rss->link);
$content_item->setTitle($item->title);
$content_item->setNickName(max($item->author,$item->{'dc:creator'}));
//$content_item->setCategory($item->category);
$item->description = preg_replace('!<a href=!is','<a onclick="window.open(this.href);return false" href=', $item->description);
$content_item->setContent($item->description);
$content_item->setLink($item->link);
$date = date('YmdHis', strtotime(max($item->pubdate,$item->pubDate,$item->{'dc:date'})));
$content_item->setRegdate($date);
$items = $xml_doc->{'rdf:RDF'}->item;
$content_items[] = $content_item;
if(!$items) return;
if($items && !is_array($items)) $items = array($items);
$content_items = array();
foreach ($items as $key => $value) {
if($key >= $args->list_count * $args->page_count) break;
unset($item);
foreach($value as $key2 => $value2) {
if(is_array($value2)) $value2 = array_shift($value2);
$item->{$key2} = $this->_getRssBody($value2);
}
$content_item = new contentItem($rss->title);
$content_item->setContentsLink($rss->link);
$content_item->setTitle($item->title);
$content_item->setNickName(max($item->author,$item->{'dc:creator'}));
//$content_item->setCategory($item->category);
$item->description = preg_replace('!<a href=!is','<a onclick="window.open(this.href);return false" href=', $item->description);
$content_item->setContent($item->description);
$content_item->setLink($item->link);
$date = date('YmdHis', strtotime(max($item->pubdate,$item->pubDate,$item->{'dc:date'})));
$content_item->setRegdate($date);
$content_items[] = $content_item;
}
} elseif($xml_doc->{'rdf:rdf'}) {
$rss->title = $xml_doc->{'rdf:rdf'}->channel->title->body;
$rss->link = $xml_doc->{'rdf:rdf'}->channel->link->body;
$items = $xml_doc->{'rdf:rdf'}->item;
if(!$items) return;
if($items && !is_array($items)) $items = array($items);
$content_items = array();
foreach ($items as $key => $value) {
if($key >= $args->list_count * $args->page_count) break;
unset($item);
foreach($value as $key2 => $value2) {
if(is_array($value2)) $value2 = array_shift($value2);
$item->{$key2} = $this->_getRssBody($value2);
}
$content_item = new contentItem($rss->title);
$content_item->setContentsLink($rss->link);
$content_item->setTitle($item->title);
$content_item->setNickName(max($item->author,$item->{'dc:creator'}));
//$content_item->setCategory($item->category);
$item->description = preg_replace('!<a href=!is','<a onclick="window.open(this.href);return false" href=', $item->description);
$content_item->setContent($item->description);
$content_item->setLink($item->link);
$date = date('YmdHis', strtotime(max($item->pubdate,$item->pubDate,$item->{'dc:date'})));
$content_item->setRegdate($date);
$content_items[] = $content_item;
}
} elseif($xml_doc->feed && $xml_doc->feed->attrs->xmlns == 'http://www.w3.org/2005/Atom') {
$rss->title = $xml_doc->feed->title->body;
$links = $xml_doc->feed->link;
if(is_array($links)) {
foreach ($links as $value) {
if($value->attrs->rel == 'alternate') {
$rss->link = $value->attrs->href;
break;
}
}
}
elseif($links->attrs->rel == 'alternate') $rss->link = $links->attrs->href;
$items = $xml_doc->feed->entry;
if(!$items) return;
if($items && !is_array($items)) $items = array($items);
$content_items = array();
foreach ($items as $key => $value) {
if($key >= $args->list_count * $args->page_count) break;
unset($item);
foreach($value as $key2 => $value2) {
if(is_array($value2)) $value2 = array_shift($value2);
$item->{$key2} = $this->_getRssBody($value2);
}
$content_item = new contentItem($rss->title);
$links = $value->link;
if(is_array($links)) {
foreach ($links as $val) {
if($val->attrs->rel == 'alternate') {
$item->link = $val->attrs->href;
break;
}
}
}
elseif($links->attrs->rel == 'alternate') $item->link = $links->attrs->href;
$content_item->setContentsLink($rss->link);
if($item->title) {
if(!preg_match("/html/i", $value->title->attrs->type)) $item->title = $value->title->body;
}
$content_item->setTitle($item->title);
$content_item->setNickName(max($item->author,$item->{'dc:creator'}));
//$content_item->setCategory($item->category);
$item->description = preg_replace('!<a href=!is','<a onclick="window.open(this.href);return false" href=', $item->content);
if($item->description) {
if(!preg_match("/html/i", $value->content->attrs->type)) $item->description = htmlspecialchars($item->description);
}
if(!$item->description) {
$item->description = $item->summary;
if($item->description) {
if(!preg_match("/html/i", $value->summary->attrs->type)) $item->description = htmlspecialchars($item->description);
}
}
$content_item->setContent($item->description);
$content_item->setLink($item->link);
$date = date('YmdHis', strtotime(max($item->published,$item->updated,$item->{'dc:date'})));
$content_item->setRegdate($date);
$content_items[] = $content_item;
}
}
return $content_items;
}