function aggregator_refresh in Drupal 5
Same name and namespace in other branches
- 4 modules/aggregator.module \aggregator_refresh()
- 6 modules/aggregator/aggregator.module \aggregator_refresh()
- 7 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/ aggregator.module - Menu callback; refreshes a feed, then redirects to the overview page.
- aggregator_cron in modules/
aggregator/ aggregator.module - Implementation of hook_cron().
File
- modules/
aggregator/ aggregator.module, line 693 - Used to aggregate syndicated content (RSS, RDF, and Atom).
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('There is no new syndicated content from %site.', array(
'%site' => $feed['title'],
)));
break;
case 301:
$feed['url'] = $result->redirect_url;
watchdog('aggregator', t('Updated URL for feed %title to %url.', array(
'%title' => $feed['title'],
'%url' => $feed['url'],
)));
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($value);
}
/*
** Prepare the image data (if any):
*/
foreach ($image as $key => $value) {
$image[$key] = trim($value);
}
if ($image['LINK'] && $image['URL'] && $image['TITLE']) {
// Note, we should really use theme_image() here but that only works with local images it won't work with images fetched with a URL unless PHP version > 5
$image = '<a href="' . check_url($image['LINK']) . '" class="feed-image"><img src="' . check_url($image['URL']) . '" alt="' . check_plain($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();
watchdog('aggregator', t('There is new syndicated content from %site.', array(
'%site' => $feed['title'],
)));
drupal_set_message(t('There is new syndicated content from %site.', array(
'%site' => $feed['title'],
)));
}
break;
default:
watchdog('aggregator', t('The feed from %site seems to be broken, due to "%error".', array(
'%site' => $feed['title'],
'%error' => $result->code . ' ' . $result->error,
)), WATCHDOG_WARNING);
drupal_set_message(t('The feed from %site seems to be broken, because of error "%error".', array(
'%site' => $feed['title'],
'%error' => $result->code . ' ' . $result->error,
)));
}
}