protected function searchTwitterFor($searchString)
{
$searchResults;
// To improve search results call this method with a string of keywords like this "keyword one two three"
$encodedQuery = urlencode( $searchString );
$params = array(
'q' => $encodedQuery,
'count' => mCollection::TWEETS_PER_PAGE,
'lang' => 'en',
'result_type' => 'recent'
);
// Should this be search_tweets instead of just search? YES! Do my arguments have to be in an array? Not necessarily...
$searchResults = $this->codeBird->search_tweets($params);
return $searchResults;
}
public function displayRecentTweetsFor( $searchString )
{
// Another method handles the searching but displaying the results just the way Twitter wants is work, hence this method
$tweets = $this->searchTwitterFor( $searchString );
// Now I have to loop through the results and display them as per the standard.
if (count($tweets->statuses) > 0)
{
print('<div class="tweets">');
foreach ($tweets->statuses as $this_tweet)
{
// Following Ross's example I'm close to meeting the display requirements. Timestamp may be incorrectly formatted.
// Do I need little logos for Reply, Retweet, and Favourite?
// https://dev.twitter.com/terms/display-requirements
print('<div class="tweet-container">');
print('<a class="tweet-user-avatar" href="https://twitter.com/intent/user?user_id=' . $this_tweet->user->id_str . '">');
print('<img width="32" height="32" src="' . $this_tweet->user->profile_image_url . '" /></a>');
print('<p class="tweet-user-names">');
print('<a class="tweet-display-name" href="https://twitter.com/intent/user?user_id=' . $this_tweet->user->id_str . '">');
print($this_tweet->user->name . '</a>');
print('<a class="tweet-account-name" href="https://twitter.com/intent/user?user_id=' . $this_tweet->user->id_str . '">');
print('@' . $this_tweet->user->screen_name . '</a></p>');
// I think Tweet time should be below tweet-text and the follow button in the top right...
// Working but it is too damn long, can I remove the @ part? Yes but it still renders it, I think it is needed...
// 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.
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>');
print('<div class="tweet-text">');
print(linkify_tweet( $this_tweet->text, $this_tweet ));
print('</div>');
print('<div class="tweet-time">');
print('<a href="http://twitter.com/' . $this_tweet->user->screen_name . '/status/' . $this_tweet->id_str . '">');
print(relativeTime( strtotime( $this_tweet->created_at))); // Couldn't I just print the time string?
print('</a></div>');
print('<div class="tweet-intents">');
// Web Intents aren't working perfectly or at least I have no little images. Could switch to UL LI and unique bullet
// Complete with fancy CSS roll over Eric Meyer style.
// Extra attributes in tag remove:
/*
class="intent-reply" title="Reply to this Tweet"
class="intent-retweet" title="Retweet this Tweet"
class="intent-favorite" title="Favourite this Tweet"
*/
print('<a href="https://twitter.com/intent/tweet?in_reply_to=' . $this_tweet->id_str . '">Reply</a>');
print('<a href="https://twitter.com/intent/retweet?tweet_id=' . $this_tweet->id_str . '">Retweet</a>');
print('<a href="https://twitter.com/intent/favorite?tweet_id=' . $this_tweet->id_str . '">Favourite</a>');
print('</div></div>');
}
print('</div>');
}
// 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.
}