function tweet_feed_process_tweets in Tweet Feed 6
Same name and namespace in other branches
- 7.3 tweet_feed.module \tweet_feed_process_tweets()
- 7 tweet_feed.module \tweet_feed_process_tweets()
- 7.2 tweet_feed.module \tweet_feed_process_tweets()
process tweet data from what we have retrieved from the Twitter API
1 call to tweet_feed_process_tweets()
- tweet_feed_cron in ./
tweet_feed.module - implementation of hook_cron()
File
- ./
tweet_feed.module, line 212
Code
function tweet_feed_process_tweets($tdata) {
$tweets = array();
if (!empty($tdata)) {
if (!empty($tdata->errors)) {
foreach ($tdata->errors as $error) {
drupal_set_message(t('Tweet Feed Fail: ') . $error->message . ': ' . $error->code, 'error');
return array(
'tweets' => FALSE,
'lowest_id' => -1,
);
}
}
else {
foreach ($tdata as $key => $tweet) {
// find out if we already have this tweet, if we do, add it to the update pk
$count = db_result(db_query("SELECT COUNT(*) FROM {tweet_feed} \n WHERE tweet_id = %s", $tweet->id));
$pk = $count > 0 ? array(
'tweet_id',
) : array();
$creation_timestamp = strtotime($tweet->created_at);
$lowest_id = $key == 0 ? $tweet->id : $lowest_id;
$lowest_id = $tweet->id < $lowest_id ? $tweet->id : $lowest_id;
$tweet_html = tweet_feed_format_output($tweet->text);
$hashtags = tweet_feed_get_hashtags($tweet->entities->hashtags);
$data = array(
'tweet' => utf8_encode($tweet_html),
'created_at' => $creation_timestamp,
'user_id' => $tweet->user->id,
'profile_image_url' => $tweet->user->profile_image_url,
'profile_image_https_url' => $tweet->user->profile_image_url_https,
'screen_name' => $tweet->user->screen_name,
'hashtags' => $hashtags,
'tweet_id' => $tweet->id,
);
$tweets[] = $data;
drupal_write_record('tweet_feed', $data, $pk);
}
}
}
else {
return array(
'tweets' => FALSE,
'lowest_id' => -1,
);
}
return array(
'tweets' => $tweets,
'lowest_id' => $lowest_id,
);
}