Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. protected function searchTwitterFor($searchString)
  2. {
  3. $searchResults;
  4.            
  5. // To improve search results call this method with a string of keywords like this "keyword one two three"
  6. $encodedQuery = urlencode( $searchString );
  7. $params = array(
  8.             'q' => $encodedQuery,
  9.             'count' => mCollection::TWEETS_PER_PAGE,
  10.             'lang' => 'en',
  11.             'result_type' => 'recent'
  12.         );
  13.            
  14. // Should this be search_tweets instead of just search? YES! Do my arguments have to be in an array? Not necessarily...
  15. $searchResults = $this->codeBird->search_tweets($params);
  16.  
  17. return $searchResults;
  18. }
  19.  
  20. public function displayRecentTweetsFor( $searchString )
  21. {
  22. // Another method handles the searching but displaying the results just the way Twitter wants is work, hence this method
  23. $tweets = $this->searchTwitterFor( $searchString );
  24.            
  25. // Now I have to loop through the results and display them as per the standard.
  26. if (count($tweets->statuses) > 0)
  27. {
  28.     print('<div class="tweets">');
  29.     foreach ($tweets->statuses as $this_tweet)
  30.     {
  31.         // Following Ross's example I'm close to meeting the display requirements. Timestamp may be incorrectly formatted.
  32.         // Do I need little logos for Reply, Retweet, and Favourite?
  33.         // https://dev.twitter.com/terms/display-requirements
  34.         print('<div class="tweet-container">');
  35.         print('<a class="tweet-user-avatar" href="https://twitter.com/intent/user?user_id=' . $this_tweet->user->id_str . '">');
  36.         print('<img width="32" height="32" src="' . $this_tweet->user->profile_image_url . '" /></a>');
  37.    
  38.         print('<p class="tweet-user-names">');
  39.         print('<a class="tweet-display-name" href="https://twitter.com/intent/user?user_id=' . $this_tweet->user->id_str . '">');
  40.         print($this_tweet->user->name . '</a>');
  41.         print('<a class="tweet-account-name" href="https://twitter.com/intent/user?user_id=' . $this_tweet->user->id_str . '">');
  42.         print('@' . $this_tweet->user->screen_name . '</a></p>');
  43.                    
  44.         // I think Tweet time should be below tweet-text and the follow button in the top right...
  45.                    
  46.         // Working but it is too damn long, can I remove the @ part? Yes but it still renders it, I think it is needed...
  47.         // The follow button works either way though there is no popup, instead the button turns grey but a trip to Twitter.com confirms I did follow them.
  48.                    
  49.         print('<a href="https://twitter.com/' . $this_tweet->user->screen_name .  '" class="twitter-follow-button" data-show-count="false" data-dnt="true">Follow @' . $this_tweet->user->name . '</a>');
  50.  
  51.         print('<div class="tweet-text">');
  52.         print(linkify_tweet( $this_tweet->text, $this_tweet ));
  53.         print('</div>');
  54.                    
  55.         print('<div class="tweet-time">');
  56.         print('<a href="http://twitter.com/' . $this_tweet->user->screen_name . '/status/' . $this_tweet->id_str . '">');
  57.         print(relativeTime( strtotime( $this_tweet->created_at))); // Couldn't I just print the time string?
  58.         print('</a></div>');
  59.                    
  60.         print('<div class="tweet-intents">');
  61.         // Web Intents aren't working perfectly or at least I have no little images. Could switch to UL LI and unique bullet
  62.         // Complete with fancy CSS roll over Eric Meyer style.
  63.         // Extra attributes in tag remove:
  64.         /*
  65.         class="intent-reply" title="Reply to this Tweet"
  66.         class="intent-retweet" title="Retweet this Tweet"
  67.         class="intent-favorite" title="Favourite this Tweet"
  68.         */
  69.         print('<a href="https://twitter.com/intent/tweet?in_reply_to=' . $this_tweet->id_str . '">Reply</a>');
  70.         print('<a href="https://twitter.com/intent/retweet?tweet_id=' . $this_tweet->id_str . '">Retweet</a>');
  71.         print('<a href="https://twitter.com/intent/favorite?tweet_id=' . $this_tweet->id_str . '">Favourite</a>');
  72.         print('</div></div>');
  73.         }
  74.     print('</div>');
  75.     }
  76.            
  77. // Don't need to return anything not even null in PHP apparently, I really am not a PHP guy, I don't know best practices at all.
  78. }