function twitter_block_block_view in Twitter Block 7
Same name and namespace in other branches
- 7.2 twitter_block.module \twitter_block_block_view()
Implements hook_block_view().
File
- ./
twitter_block.module, line 250 - A module to provide simple Twitter blocks using the Twitter Search API.
Code
function twitter_block_block_view($delta) {
// Load the configuration.
$config = twitter_block_block_get($delta);
// Use the MD5 of the block config as the cache cid.
$cid = 'twitter_block_feed_' . md5(serialize($config));
$cache_bin = 'cache';
// Build the object.
$twitter = new TwitterBlockSearch($config);
$response = $twitter
->getJSON();
$results = array();
if (empty($response) || !is_array($response) || !isset($response['status']) || $response['status'] !== TRUE) {
watchdog('Twitter Block', 'Recieved an unexpected reply from Twitter. ' . 'Perhaps just a fail whale?<br/>' . 'URL: url_query<br />' . 'response', array(
'url_query' => $twitter->url_query,
'response' => print_r($response, TRUE),
), WATCHDOG_NOTICE);
}
else {
$results = $response['results'];
}
// Create a variable to hold the tweets.
$tweets = array();
// Theme each of the returned tweets.
foreach ($results as $tweet) {
$tweets[] = theme('twitter_block_tweet', array(
'tweet' => $tweet,
'api' => $twitter
->getApi(),
));
}
$block = array();
$block['subject'] = check_plain($config['info']);
$block['content'] = array(
'#theme' => 'item_list',
'#items' => $tweets,
'#attached' => array(
'css' => array(
drupal_get_path('module', 'twitter_block') . '/twitter_block.css',
),
),
);
return $block;
}