Projet

Général

Profil

Paste
Télécharger (1,66 ko) Statistiques
| Branche: | Révision:

root / drupal7 / modules / aggregator / aggregator.fetcher.inc @ db2d93dd

1
<?php
2

    
3
/**
4
 * @file
5
 * Fetcher functions for the aggregator module.
6
 */
7

    
8
/**
9
 * Implements hook_aggregator_fetch_info().
10
 */
11
function aggregator_aggregator_fetch_info() {
12
  return array(
13
    'title' => t('Default fetcher'),
14
    'description' => t('Downloads data from a URL using Drupal\'s HTTP request handler.'),
15
  );
16
}
17

    
18
/**
19
 * Implements hook_aggregator_fetch().
20
 */
21
function aggregator_aggregator_fetch($feed) {
22
  $feed->source_string = FALSE;
23

    
24
  // Generate conditional GET headers.
25
  $headers = array();
26
  if ($feed->etag) {
27
    $headers['If-None-Match'] = $feed->etag;
28
  }
29
  if ($feed->modified) {
30
    $headers['If-Modified-Since'] = gmdate(DATE_RFC7231, $feed->modified);
31
  }
32

    
33
  // Request feed.
34
  $result = drupal_http_request($feed->url, array('headers' => $headers));
35

    
36
  // Process HTTP response code.
37
  switch ($result->code) {
38
    case 304:
39
      break;
40
    case 301:
41
      $feed->url = $result->redirect_url;
42
      // Do not break here.
43
    case 200:
44
    case 302:
45
    case 307:
46
      if (!isset($result->data)) {
47
        $result->data = '';
48
      }
49
      if (!isset($result->headers)) {
50
        $result->headers = array();
51
      }
52
      $feed->source_string = $result->data;
53
      $feed->http_headers = $result->headers;
54
      break;
55
    default:
56
      watchdog('aggregator', 'The feed from %site seems to be broken, due to "%error".', array('%site' => $feed->title, '%error' => $result->code . ' ' . $result->error), WATCHDOG_WARNING);
57
      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)));
58
  }
59

    
60
  return $feed->source_string === FALSE ? FALSE : TRUE;
61
}