Posts Tagged ‘zend framework simplepie php’

h1

SimplePie & ZendFramework

April 21, 2009

I\’ve been working on my old site the past couple of days and needed to integrate a blog aggregator for my wordpress blog.

Instead of doing it all from scratch & reinventing the wheel, I decided to integrate SimplePie into my Zend Framework project.

Listed below are the steps I needed to get  SimplePie into Zend Framework.

  • Download SimplePie
  • Rename simplepie.inc to SimplePie.php & copy to the library directory of your ZF project.
  • If you want dates you will also need idn/idna_convert.class.php
  • Rename idna_convert.class.php to convert.php & create a directory called \’idna\’ within the library directory
  • Move the newly renamed convert.php & npdata.ser to library/idna
  • Now we are ready to utilise SimplePie within our project.

Below are excerpts from my project, hopefully it will help illustrate how to utilise SimplePie once you have made the necessary changes.


class BlogController extends BaseController {

	function init() {
		$feed = new SimplePie(\'https://baphled.wordpress.com/feed\');
		$feed->init();
		$this->view->title = $feed->get_title();
		$this->view->items = $feed->get_items();
		parent::init();
	}
	/**
	 * The default action - show the home page
	 */
	public function indexAction() {
	}

}

Above we instantiate SimplePie with the URL to our RSS feed, we then initialise our feed & retrieve it\’s title & items, assigning the variables to the view.

The next segment of code is for the index.phtml and basically populates our content with our aggregated blog feed.

foreach($this->items as $item): ?>
	<div class=\"chunk\" style=\"padding:0 15px;\">
		<h4><a href=\"{$item->get_permalink()}\" target=\"_blank\"><?php echo $item->get_title(); ?></a></h4>
		<?php echo $item->get_description(); ?>
		<p class=\"footnote favicons\" align=\"center\">
			<a href=\"<?php echo $item->add_to_blinklist(); ?>\" title=\"Add post to Blinklist\"><img src=\"/images/favicons/blinklist.png\" alt=\"Blinklist\" /></a>
			<a href=\"<?php echo $item->add_to_blogmarks(); ?>\" title=\"Add post to Blogmarks\"><img src=\"/images/favicons/blogmarks.png\" alt=\"Blogmarks\" /></a>
			<a href=\"<?php echo $item->add_to_delicious(); ?>\" title=\"Add post to del.icio.us\"><img src=\"/images/favicons/delicious.png\" alt=\"del.icio.us\" /></a>
			<a href=\"<?php echo $item->add_to_digg(); ?>\" title=\"Digg this!\"><img src=\"/images/favicons/digg.png\" alt=\"Digg\" /></a>
			<a href=\"<?php echo $item->add_to_magnolia(); ?>\" title=\"Add post to Ma.gnolia\"><img src=\"/images/favicons/magnolia.png\" alt=\"Ma.gnolia\" /></a>
			<a href=\"<?php echo $item->add_to_myweb20(); ?>\" title=\"Add post to My Web 2.0\"><img src=\"/images/favicons/myweb2.png\" alt=\"My Web 2.0\" /></a>
			<a href=\"<?php echo $item->add_to_newsvine(); ?>\" title=\"Add post to Newsvine\"><img src=\"/images/favicons/newsvine.png\" alt=\"Newsvine\" /></a>
			<a href=\"<?php echo $item->add_to_reddit(); ?>\" title=\"Add post to Reddit\"><img src=\"/images/favicons/reddit.png\" alt=\"Reddit\" /></a>
			<a href=\"<?php echo $item->add_to_segnalo(); ?>\" title=\"Add post to Segnalo\"><img src=\"/images/favicons/segnalo.png\" alt=\"Segnalo\" /></a>
			<a href=\"<?php echo $item->add_to_simpy(); ?>\" title=\"Add post to Simpy\"><img src=\"/images/favicons/simpy.png\" alt=\"Simpy\" /></a>
			<a href=\"<?php echo $item->add_to_spurl(); ?>\" title=\"Add post to Spurl\"><img src=\"/images/favicons/spurl.png\" alt=\"Spurl\" /></a>
			<a href=\"<?php echo $item->add_to_wists(); ?>\" title=\"Add post to Wists\"><img src=\"/images/favicons/wists.png\" alt=\"Wists\" /></a>
			<a href=\"<?php echo $item->search_technorati(); ?>\" title=\"Who\'s linking to this post?\"><img src=\"/images/favicons/technorati.png\" alt=\"Technorati\" /></a>
		</p>
	</div>
<?php endforeach; ?>