function socialfeed_twitter_posts in Social Feed 7
Same name and namespace in other branches
- 7.2 socialfeed.block.inc \socialfeed_twitter_posts()
Uses socialfeed_twitter_posts() for fetching Twitter tweets.
1 call to socialfeed_twitter_posts()
- socialfeed_block_view in ./
socialfeed.module - Implements hook_block_view().
File
- ./
socialfeed.module, line 320 - Provide Facebook, Twitter and Instagram.
Code
function socialfeed_twitter_posts() {
$twitter_tweets = array();
$display_time = '';
$settings = array(
'oauth_access_token' => variable_get('socialfeed_twitter_access_token'),
'oauth_access_token_secret' => variable_get('socialfeed_twitter_access_token_secret'),
'consumer_key' => variable_get('socialfeed_twitter_consumer_key'),
'consumer_secret' => variable_get('socialfeed_twitter_consumer_secret'),
);
$tweets_count = variable_get('socialfeed_twitter_tweets_count');
$twitter_username = variable_get('socialfeed_twitter_username');
$url = "https://api.twitter.com/1.1/statuses/user_timeline.json";
$request_method = "GET";
$getfield = '?screen_name=' . $twitter_username . '&count=' . $tweets_count;
// Loading TwitterAPIExchange.
libraries_load('twitter');
$twitter = new TwitterAPIExchange($settings);
$twitter_values = json_decode($twitter
->setGetfield($getfield)
->buildOauth($url, $request_method)
->performRequest(), $assoc = TRUE);
if (isset($twitter_values) && !empty($twitter_values)) {
if (array_key_exists('errors', $twitter_values)) {
if ($twitter_values["errors"][0]["message"] != "") {
echo "<h3>Sorry, there was a problem.</h3><p>Twitter returned the following error message:</p><p><em>" . $twitter_values[errors][0]["message"] . "</em></p>";
exit;
}
}
$display_time = variable_get('socialfeed_twitter_time_stamp');
foreach ($twitter_values as $key => $twitter_value) {
$twitter_tweets[$key]['username'] = $twitter_value['user']['screen_name'];
$twitter_tweets[$key]['full_username'] = 'http://twitter.com/' . $twitter_value['user']['screen_name'];
preg_match_all('#\\bhttps?://[^\\s()<>]+(?:\\([\\w\\d]+\\)|([^[:punct:]\\s]|/))#', $twitter_value['text'], $extra_links);
foreach ($extra_links[0] as $extra_link) {
$twitter_tweets[$key]['extra_links'][] = $extra_link;
}
$twitter_tweets[$key]['tweet'] = rtrim($twitter_value['text'], $extra_link);
if ($display_time == 1) {
$formatted_twitter_date = new DateTime($twitter_value['created_at']);
$twitter_tweets[$key]['twitter_date'] = $formatted_twitter_date
->format(variable_get('socialfeed_twitter_time_format'));
}
}
return theme('socialfeed_twitter', array(
'twitter' => $twitter_tweets,
));
}
}