Posted By

manavecplan on 09/12/10


Tagged


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

luman


Twiter search


 / Published in: PHP
 

  1. function jorbin_firestream_search($atts){
  2. extract(shortcode_atts(array(
  3. 'phrase' => false,
  4. 'lang' => 'en',
  5. 'max_id' => false,
  6. 'since_id' => false,
  7. 'number' => '20'
  8. ), $atts));
  9. if ('phrase' == false){
  10. return false;
  11. }
  12. //*/ Build our search url and transient name
  13. $transient = 'tweet-'. esc_sql($phrase) . '&l=' . esc_sql($lang);
  14. $url = 'http://search.twitter.com/search.json?q='. urlencode($phrase) . '&show_user=true〈='. urlencode($lang) .'&rpp=' . $number;
  15.  
  16. if ($max_id != false){
  17. $url .= '&max_id=' . (int) $max_id;
  18. $transient .= '&m=' . (int) $max_id;
  19. }
  20. if ($since_id != false){
  21. $url .= '&since_id=' . (int) $since_id;
  22. $transient .= '&s=' . (int) $since_id;
  23. }
  24.  
  25. if ( $tweet_display = get_transient($transient) ){
  26. // It's allready been brought
  27. }
  28. else {
  29.  
  30. if ($search = wp_remote_get( $url ) ){
  31.  
  32. $results = json_decode($search['body']);
  33.  
  34. $tweets = $results->results;
  35. //*/
  36. foreach ( (array) $tweets as $tweet){
  37. $tweetcontent = $tweet->text;
  38. $newcontent = preg_replace('%@([^\s]*)%', "<a href="http://twitter.com/\\1">@\\1</a>", $tweetcontent);
  39. echo "<div class="twitter_shortcode"><p>
  40. <img class="twitter_shortcode_image" src="&quot;.esc_url($tweet-&gt;profile_image_url).&quot;"><span class="twitter_shotcode_username"><a href="http://twitter.com/&quot;.$tweet-&gt;from_user.&quot;">".$tweet-&gt;from_user."</a>&nbsp;—&nbsp;</span>". $newcontent ."</p>
  41. </div>";
  42.  
  43. }
  44. $tweet_display = ob_get_clean();
  45. set_transient($transient, $tweet_display, 300);
  46. }
  47. else
  48. {
  49. $tweet_display = "I'm sorry, no tweets are availailable at this time";
  50. }
  51. }
  52. return apply_filters('jorbin_tweet_content', $tweet_display) ;
  53. }
  54. add_filter('jorbin_tweet_content', 'make_clickable' );
  55. add_shortcode('twitter-search', 'jorbin_firestream_search');

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: thesocialhacker on September 22, 2010

does this use some pre-existing framework?

Posted By: manavecplan on January 2, 2011

Just wordpress...

You need to login to post a comment.