function twitter_pull_retrieve in Twitter Pull 6
Same name and namespace in other branches
- 6.2 twitter_pull.module \twitter_pull_retrieve()
- 7.2 twitter_pull.module \twitter_pull_retrieve()
- 7 twitter_pull.module \twitter_pull_retrieve()
Retrieves tweets by username, hashkey or search term.
Parameters
$twitkey: Twitter key, which can be a username (prepended with @), hashtag (prepended with #), or a search term.
$num_items: Number of tweets to retrieve from Twitter. Can't be more than 200.
1 call to twitter_pull_retrieve()
- twitter_pull_render in ./
twitter_pull.module - Retrieves appropriate tweets (by username, hashkey or search term) and passes over to the theming function with $themekey key passing tweets array along.
File
- ./
twitter_pull.module, line 88
Code
function twitter_pull_retrieve($twitkey, $num_items = NULL) {
// If $num_items is not set, use the default value.
// This value is checked more rigorously in twitter_puller->check_arguments().
$num_items = intval($num_items) > 0 ? intval($num_items) : twitter_pull_num_items();
// Cached value is specific to the Twitter key and number of tweets retrieved.
$cache_key = $twitkey . '::' . $num_items;
$cache = cache_get($cache_key, TWITTER_PULL_CACHE_TABLE);
$tweets = array();
if (!empty($cache) && !empty($cache->data) && time() < $cache->expire) {
$tweets = $cache->data;
}
else {
try {
$puller = new twitter_puller($twitkey, $num_items);
$puller
->get_items();
$tweets = $puller->tweets;
} catch (Exception $e) {
watchdog('Twitter Pull', $e
->getMessage(), array(), WATCHDOG_WARNING);
return twitter_pull_empty_message();
}
if (!empty($tweets) && is_array($tweets)) {
$cache_length = twitter_pull_cache_length() * 60;
//-- in the settings we indicate length in minutes, here we need seconds.
cache_set($cache_key, $tweets, TWITTER_PULL_CACHE_TABLE, time() + $cache_length);
}
}
return $tweets;
}