Same name and namespace in other branches
- 4.7.x modules/aggregator.module \aggregator_refresh()
- 5.x modules/aggregator/aggregator.module \aggregator_refresh()
- 6.x modules/aggregator/aggregator.module \aggregator_refresh()
- 7.x modules/aggregator/aggregator.module \aggregator_refresh()
Checks a news feed for new items.
2 calls to aggregator_refresh()
- aggregator_admin_refresh_feed in modules/
aggregator.module - Menu callback; refreshes a feed, then redirects to the overview page.
- aggregator_cron in modules/
aggregator.module - Implementation of hook_cron().
File
- modules/
aggregator.module, line 328 - Used to aggregate syndicated content (RSS and RDF).
Code
function aggregator_refresh($feed) {
global $channel, $image;
// Generate conditional GET headers.
$headers = array();
if ($feed['etag']) {
$headers['If-None-Match'] = $feed['etag'];
}
if ($feed['modified']) {
$headers['If-Modified-Since'] = gmdate('D, d M Y H:i:s', $feed['modified']) . ' GMT';
}
// Request feed.
$result = drupal_http_request($feed['url'], $headers);
// Process HTTP response code.
switch ($result->code) {
case 304:
db_query('UPDATE {aggregator_feed} SET checked = %d WHERE fid = %d', time(), $feed['fid']);
drupal_set_message(t('No new syndicated content from %site.', array(
'%site' => theme('placeholder', $feed['title']),
)));
break;
case 301:
$feed['url'] = $result->redirect_url;
watchdog('aggregator', t('Updated URL for feed %title to %url.', array(
'%title' => theme('placeholder', $feed['title']),
'%url' => theme('placeholder', $feed['url']),
)));
break;
case 200:
case 302:
case 307:
// Filter the input data:
if (aggregator_parse_feed($result->data, $feed)) {
if ($result->headers['Last-Modified']) {
$modified = strtotime($result->headers['Last-Modified']);
}
/*
** Prepare the channel data:
*/
foreach ($channel as $key => $value) {
$channel[$key] = trim(strip_tags($value));
}
/*
** Prepare the image data (if any):
*/
foreach ($image as $key => $value) {
$image[$key] = trim($value);
}
if ($image['LINK'] && $image['URL'] && $image['TITLE']) {
$image = '<a href="' . $image['LINK'] . '"><img src="' . $image['URL'] . '" alt="' . $image['TITLE'] . '" /></a>';
}
else {
$image = NULL;
}
/*
** Update the feed data:
*/
db_query("UPDATE {aggregator_feed} SET url = '%s', checked = %d, link = '%s', description = '%s', image = '%s', etag = '%s', modified = %d WHERE fid = %d", $feed['url'], time(), $channel['LINK'], $channel['DESCRIPTION'], $image, $result->headers['ETag'], $modified, $feed['fid']);
/*
** Clear the cache:
*/
cache_clear_all();
$message = t('Syndicated content from %site.', array(
'%site' => theme('placeholder', $feed[title]),
));
watchdog('aggregator', $message);
drupal_set_message($message);
}
break;
default:
$message = t('Failed to parse RSS feed %site: %error.', array(
'%site' => theme('placeholder', $feed['title']),
'%error' => theme('placeholder', $result->code . ' ' . $result->error),
));
watchdog('aggregator', $message, WATCHDOG_WARNING);
drupal_set_message($message);
}
}