function execute(&$controller, &$request, &$user) { $member = $user->getAttribute('member', GLU_NS); // my feeds $source = DB_DataObject::factory('source'); $source->whereAdd('member_id = ' . $source->escape($member->id)); if ($request->hasParameter('id')) { $source->whereAdd('id = ' . $source->escape($request->getParameter('id'))); } $source->find(); $feeds = array(); while ($source->fetch()) { $rss = new FeedParser($source->uri); $rss->parse(); foreach ($rss->getItems() as $item) { $feed['id'] = $source->id; $feed['title'] = $item['title']; $feed['link'] = $item['link']; $feed['description'] = isset($item['description']) ? $item['description'] : ''; $feed['date'] = isset($item['dc:date']) ? $item['dc:date'] : (isset($item['date']) ? $item['date'] : ''); $feeds[] = $feed; } } $haj = new HTML_AJAX_JSON(); $output = $haj->encode($feeds); header('Content-Type: application/x-javascript; charset=utf-8'); echo $output; return VIEW_NONE; }
function testRSS20() { $uri = 'http://plnet.jp/test_feed/p0t-rss20.xml'; $feed = new FeedParser($uri); $feed->parse(); $this->assertEquals('p0t', $feed->getTitle()); $this->assertEquals('http://p0t.jp/mt/', $feed->getLink()); $this->assertEquals('http://p0t.jp/mt/favicon.ico', $feed->getFavicon()); print_r($feed->data); $uri = 'http://plnet.jp/test_feed/d.hatena-rss20.xml'; $feed = new FeedParser($uri); $feed->parse(); $this->assertEquals('m-komagataの日記', $feed->getTitle()); $this->assertEquals('http://d.hatena.ne.jp/m-komagata/', $feed->getLink()); $this->assertEquals('http://d.hatena.ne.jp/images/de_favicon.ico', $feed->getFavicon()); $items = $feed->getItems(); $this->assertEquals('テストタイトル2', $items[0]['title']); }
/** * Displays a static page. */ function display() { $path = func_get_args(); $count = count($path); if (!$count) { $this->redirect('/'); } $page = $subpage = $title_for_layout = null; if (!empty($path[0])) { $page = $path[0]; } if (!empty($path[1])) { $subpage = $path[1]; } if (!empty($path[$count - 1])) { $this->title_for_layout = Inflector::humanize($path[$count - 1]); if ($this->title_for_layout == 'Home') { $this->title_for_layout = ''; } } App::import('Vendor', 'feedparser/feedparser'); $Parser = new FeedParser(); $Parser->parse('http://blog.simpleve.com/feed/'); $items = $Parser->getItems(); $this->set('blogrss', $items); $Parser = new FeedParser(); $Parser->parse('http://www.eveonline.com/feed/rdfdevblog.asp'); $items = $Parser->getItems(); $this->set('evedevblogrss', $items); $motd = file_get_contents('http://www.eveonline.com/motd.asp?s=xml'); $motd = trim(str_replace('MOTD', '', $motd)); $motd = trim(str_replace('shellexec:', '', $motd)); $motd = trim(str_replace('<center>', '', $motd)); $motd = trim(str_replace('</center>', '', $motd)); $this->set('evemotd', $motd); $this->set(compact('page', 'subpage', 'title_for_layout')); $this->render(implode('/', $path)); }
<?php include 'FeedParser.php'; $Parser = new FeedParser(); $Parser->parse('http://www.sitepoint.com/rss.php'); $channels = $Parser->getChannels(); $items = $Parser->getItems(); ?> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Testing the PHP Universal Feed Parser</title> <style type="text/css"> body{ padding: 0px; margin: 50px 150px; border: 1px solid #ddd; font-family: verdana, arial; } h1#title { background-color: #eee; border-bottom : 1px solid #ddd; margin: 0px 0px 15px; padding:10px; text-align: center; } h1#title a{ font-size: 18px; }
<?php // The only thing we need is include base class file require_once 'FeedParser.php'; // Get XML serialization of feed $xml = file_get_contents($_POST['filename']); // This is great. To work with feed we invoke only base class. All other work is // transparent. $feed = new FeedParser($xml); //Because we have interface for feeds, we invoke interface methods echo '<b>Type:</b>' . $feed->getFeedType() . "<br/>"; echo '<b>Title:</b>' . $feed->getTitle() . "<br/>"; echo '<b>Description:</b>' . $feed->getDescription() . "<br/>"; echo '<b>Feed link:</b>' . $feed->getFeedLink() . "<br/>"; echo '<b>Link:</b>' . $feed->getLink() . "<br/>"; $items = $feed->getItems(); // Stuff in your items can be empty, so you should somehow handle it. // I've prepared is_empty function for you - enjoy. $i = 1; foreach ($items as $item) { //Because we have interface for items, we invoke interface methods echo "<h1>"; if (is_empty($item->getLink())) { echo '<a href="#">'; } else { echo '<a href="' . $item->getLink() . '">'; } if (is_empty($item->getTitle())) { echo "No title"; } else { echo "{$i}. " . $item->getTitle();