Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. <?php
  2. require_once('../../Muskie/codebird.php');
  3. require_once('../../Muskie/myInfo.php');
  4.  
  5. header('Content-type:text/xml; charset=utf-8'); // You have to do this early to have a valid RSS feed
  6.  
  7. Codebird::setConsumerKey(myInfo::MY_TWITTER_PUBLIC_KEY, myInfo::MY_TWITTER_PRIVATE_KEY);
  8. $cb = Codebird::getInstance();
  9. $cb->setToken(myInfo::MY_TWITTER_ACCESS_TOKEN, myInfo::MY_TWITTER_ACCESS_TOKEN_SECRET);
  10. $searchResults = null;
  11. $searchTerm = null;
  12.  
  13. if(isset($_GET["q"]))
  14. {
  15.     $searchTerm = $_GET["q"]; // This should already be URL encoded I imagine, will have to test works for Vancouver
  16.     $encodedQuery = urlencode( $searchTerm ); // Re-encoded just in case
  17.     $params = array(
  18.             'q' => $encodedQuery,
  19.             'lang' => 'en',
  20.             'result_type' => 'recent'
  21.             );
  22.            
  23.     $searchResults = $cb->search_tweets($params);
  24. }
  25.  
  26. // Begin the RSS Feed
  27. echo '<?xml version="1.0" encoding="UTF-8" ?>';
  28. ?>
  29.  
  30. <rss version="0.91"> <!-- not sure if I should bother with RSS 2.0, simple is best IMHO -->
  31. <channel>
  32. <?php echo('<title>Twitter Search Result Feed for ' . $searchTerm . ' </title>'); ?>
  33. <link>http://www.muschamp.ca</link>
  34. <description>
  35. Recent tweets for keyword search as an RSS feed.
  36. </description>
  37. <language>en-us</language>
  38. <pubDate><?php echo date("D, d M Y H:i:s T"); ?></pubDate>
  39.  
  40.     <?php
  41.     foreach($searchResults->statuses as $this_tweet)
  42.     {      
  43.         print('<item>' . "\n");
  44.         print('<title>' . htmlspecialchars($this_tweet->text, 16, "UTF-8") . '</title>'. "\n");
  45.         print('<link>http://twitter.com/' . $this_tweet->user->screen_name . '/status/' . $this_tweet->id_str . '</link>' . "\n");
  46.         print('<description>' . $this_tweet->text . '</description>'. "\n");
  47.         $pubTime = strtotime($this_tweet->created_at);
  48.         $pubDate = date("D, d M Y H:i:s T", $pubTime);
  49.         print('<pubDate>' . $pubDate . '</pubDate>' . "\n");
  50.         print('</item>'. "\n");
  51.     }
  52.     ?>
  53.    
  54. </channel>
  55. </rss>