|
<? include "RSSReader.php";
/** * GMT 날짜를 현지 날짜로 변경한다. * * @access private * @param string pubdate * @return string */ function _TopubDate($pubdate,$fmt = "Y/m/d H:i:s"){ $result = strtotime($pubdate); if($result > 0){ return date($fmt,$result); } else { if(preg_match("/(d{4})-(d{2})-(d{2})T(d{2}):(d{2})(:(d{2})|)([-|+])(d{2}):(d{2})/", $pubdate,$matches)){ $op = ($matches[8] == "-")? -1:1; $hour = $matches[9]*$op; $min = $matches[10]*$op; $timestamp = mktime ($matches[4]+$hour,$matches[5]+$min,$matches[6],$matches[2],$matches[3],$matches[1]); return date($fmt,$timestamp); } else { } } }
/** * 날짜별로 정열 * * @access private * @return void */ function cmp ($a, $b) { return strcmp($b["IDXPUBDATE"],$a["IDXPUBDATE"]); }
/** * 뉴스목록의 선택여부 * * @access private * @param string news key * @return boolean */ function isChoice($key){ global $ns; return in_array($key,$ns); }
$news = array( "chosun" => array("조선일보","http://www.chosun.com/rss/rss.xml"), "joins" => array("중앙일보","http://rss.joins.com/joins_news_list.xml"), "kbench" => array("케이벤치","http://rss.kbench.com/news.xml") );
$ns = $HTTP_GET_VARS["ns"]; if(empty($ns)){ $ns = array_keys($news); }
$newsList = array(); while (list($key, $value) = each ($news)) { $url = $value[1]; $rss = new RSSReader($url,true,600,"./cache"); $response = $rss->Read();
foreach($rss->getItems() as $item){
if(isChoice($key)){ if(isset($item["dc:date"])) $item["pubdate"] = $item["dc:date"]; //array_push($newsList,array($value[0],$item["title"],$item["link"],$item["description"],$item["pubdate"])); array_push($newsList, array( NAME => $value[0], TITLE => $item["title"], LINK => $item["link"], DESCRIPTION => $item["description"], PUBDATE => $item["pubdate"], TOPUBDATE => _Topubdate($item["pubdate"]), IDXPUBDATE => _Topubdate($item["pubdate"],"YmdHis") ) ); } }
$rss->free(); unset($rss); }
usort($newsList,"cmp");
echo "<html><head><title>뉴스모와</title> "; echo "<style><!-- BODY,TD,SELECT { FONT: 9pt Arial; LINE-HEIGHT: 17px;} //--></style> "; echo "<body>"; echo "<form>"; echo "<table width=100% border=1> "; echo "<tr><td> ";
foreach($news as $key => $value) { $checked = isChoice($key)? "checked":""; echo "<input type=checkbox name=ns[] value=$key $checked> $value[0] "; }
echo "<input type=submit value="조회"></td></tr> "; echo "</table>"; echo "</form>";
echo "<table width=100% border=1> "; echo "<tr><td>제목</td><td align=center>발행일</td><td align=center>출처</td></tr> "; foreach($newsList as $list){ printf("<tr><td><a href="%s" target=_blank>%s</td><td align=center>%s</td><td align=center>%s</td></tr> ", $list[LINK],$list[TITLE],$list[TOPUBDATE],$list[NAME]); } echo "</table>";
echo "</body></html> "; ?> |