Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class FeedItem
- {
- private $url;
- private $title;
- private $author;
- private $published;
- public function __construct($url, $title, $author, $published)
- {
- $this->url = $url;
- $this->title = $title;
- $this->author = $author;
- $this->published = $published;
- }
- public function getURL()
- {
- return $this->url;
- }
- public function getTitle()
- {
- return $this->title;
- }
- public function getAuthor()
- {
- return $this->author;
- }
- public function getPublished()
- {
- return $this->published;
- }
- }
- class NewsFeed implements Iterator
- {
- private $position = 0;
- private $feeditems = array();
- public function __construct()
- {
- $this->Update();
- }
- public function Update()
- {
- if (count($this->feeditems) > 0)
- {
- unset($this->feeditems);
- $this->feeditems = array();
- }
- $feed_xml = simplexml_load_file('http://buildandshoot.com/feed.php?mode=news');
- foreach ($feed_xml->entry as $entry)
- {
- $url = $entry->link['href'];
- $title = $entry->title;
- $author = $entry->author->name;
- $published = $entry->published;
- array_push($this->feeditems, new FeedItem($url, $title, $author, $published));
- }
- }
- function rewind()
- {
- $this->position = 0;
- }
- function current()
- {
- return $this->feeditems[$this->position];
- }
- function key()
- {
- return $this->position;
- }
- function next()
- {
- ++$this->position;
- }
- function valid()
- {
- return isset($this->feeditems[$this->position]);
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement