Just when Zend couldn’t get any better, it already is!!
Today we’re farting about with RSS feeds and Twitter feeds! It’s remarkably simple! Lets get cracking:
In your controller:
//look for Ron Paul news and twitter (Americans please vote this guy!!!) $q = 'Ron%20Paul'; $this->view->q = $q; //get twitter feeds $twitter = new Zend_Service_Twitter_Search(); $this->view->tweets = $twitter->search($q,array('lang' => 'en', 'rpp' => 8, 'show_user' => true)); // get Google News Atom feed $this->view->feeds = array(); $gnewsFeed = "http://news.google.com/news?hl=en&q=$q&output=atom"; $this->view->feeds = Zend_Feed_Reader::import($gnewsFeed);
Thats it!!! In your view:
<?php $count = 0; foreach ($this->feeds as $entry) { ?> <p class="post"> <span class="text"><a href="<?php echo $entry->getLink(); ?>"> <?php echo $entry->getTitle(); ?></a></span> <span class="time"><?php echo $entry->getDateModified(); ?></span> </p> <?php $count++; } ?>
And for the tweets:
<?php foreach ($this->tweets['results'] as $tweet) {?> <p class="tweet"> <span class="image"> <img src="<?php echo $tweet['profile_image_url']; ?>" /> </span> <span class="user"> <?php echo $tweet['from_user'] . ': '; ?> </span> <span class="text"> <?php echo $tweet['text']; ?> </span> <span class="time"> <?php echo $tweet['created_at']; ?> </span> </p> <?php } ?>
Ok, I mean come on, how much easier does this stuff get?!?!?!? Rock on, amigos!