aggregator_refresh
modules/aggregator/aggregator.module, строка 693
- Версии
- 5 – 6
aggregator_refresh($feed)
Проверяет фид новостей на наличие новых пунктов.
Параметры
$feed
Ассоциативный массив, определяющий фид, который будет обновлен.
Код
<?php
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)));
}
}
?>
Войдите или зарегистрируйтесь, чтобы получить возможность отправлять комментарии