Projet

Général

Profil

Révision 41cc1b08

Ajouté par Assos Assos il y a presque 9 ans

Update feeds 7.x-2.0-alpha9 -> 7.x-2.0-beta1

Install lib simplepie 1.3.1

Voir les différences:

drupal7/sites/all/modules/feeds/plugins/FeedsHTTPFetcher.inc
11 11
 * Result of FeedsHTTPFetcher::fetch().
12 12
 */
13 13
class FeedsHTTPFetcherResult extends FeedsFetcherResult {
14

  
15
  /**
16
   * The URL of the feed being fetched.
17
   *
18
   * @var string
19
   */
14 20
  protected $url;
15
  protected $file_path;
21

  
22
  /**
23
   * The timeout in seconds to wait for a download.
24
   *
25
   * @var int
26
   */
16 27
  protected $timeout;
17 28

  
29
  /**
30
   *
31
   * Whether to ignore SSL validation errors.
32
   *
33
   * @var bool
34
   */
35
  protected $acceptInvalidCert;
36

  
18 37
  /**
19 38
   * Constructor.
20 39
   */
21 40
  public function __construct($url = NULL) {
22 41
    $this->url = $url;
23
    parent::__construct('');
24 42
  }
25 43

  
26 44
  /**
27 45
   * Overrides FeedsFetcherResult::getRaw();
28 46
   */
29 47
  public function getRaw() {
30
    feeds_include_library('http_request.inc', 'http_request');
31
    $result = http_request_get($this->url, NULL, NULL, NULL, $this->timeout);
32
    if (!in_array($result->code, array(200, 201, 202, 203, 204, 205, 206))) {
33
      throw new Exception(t('Download of @url failed with code !code.', array('@url' => $this->url, '!code' => $result->code)));
48
    if (!isset($this->raw)) {
49
      feeds_include_library('http_request.inc', 'http_request');
50
      $result = http_request_get($this->url, NULL, NULL, $this->acceptInvalidCert, $this->timeout);
51
      if (!in_array($result->code, array(200, 201, 202, 203, 204, 205, 206))) {
52
        throw new Exception(t('Download of @url failed with code !code.', array('@url' => $this->url, '!code' => $result->code)));
53
      }
54
      $this->raw = $result->data;
34 55
    }
35
    return $this->sanitizeRaw($result->data);
56

  
57
    return $this->sanitizeRaw($this->raw);
36 58
  }
37 59

  
38 60
  public function getTimeout() {
......
42 64
  public function setTimeout($timeout) {
43 65
    $this->timeout = $timeout;
44 66
  }
67

  
68
  /**
69
   * Sets the accept invalid certificates option.
70
   *
71
   * @param bool $accept_invalid_cert
72
   *   Whether to accept invalid certificates.
73
   */
74
  public function setAcceptInvalidCert($accept_invalid_cert) {
75
    $this->acceptInvalidCert = (bool) $accept_invalid_cert;
76
  }
77

  
45 78
}
46 79

  
47 80
/**
......
60 93
    $fetcher_result = new FeedsHTTPFetcherResult($source_config['source']);
61 94
    // When request_timeout is empty, the global value is used.
62 95
    $fetcher_result->setTimeout($this->config['request_timeout']);
96
    $fetcher_result->setAcceptInvalidCert($this->config['accept_invalid_cert']);
63 97
    return $fetcher_result;
64 98
  }
65 99

  
......
108 142
      'use_pubsubhubbub' => FALSE,
109 143
      'designated_hub' => '',
110 144
      'request_timeout' => NULL,
145
      'auto_scheme' => 'http',
146
      'accept_invalid_cert' => FALSE,
111 147
    );
112 148
  }
113 149

  
......
128 164
      '#description' => t('Attempt to use a <a href="http://en.wikipedia.org/wiki/PubSubHubbub">PubSubHubbub</a> subscription if available.'),
129 165
      '#default_value' => $this->config['use_pubsubhubbub'],
130 166
    );
131
    $form['designated_hub'] = array(
167
    $form['advanced'] = array(
168
      '#title' => t('Advanced settings'),
169
      '#type' => 'fieldset',
170
      '#collapsible' => TRUE,
171
      '#collapsed' => TRUE,
172
    );
173
    $form['advanced']['auto_scheme'] = array(
174
      '#type' => 'textfield',
175
      '#title' => t('Automatically add scheme'),
176
      '#description' => t('If the supplied URL does not contain the scheme, use this one automatically. Keep empty to force the user to input the scheme.'),
177
      '#default_value' => $this->config['auto_scheme'],
178
    );
179
    $form['advanced']['designated_hub'] = array(
132 180
      '#type' => 'textfield',
133 181
      '#title' => t('Designated hub'),
134 182
      '#description' => t('Enter the URL of a designated PubSubHubbub hub (e. g. superfeedr.com). If given, this hub will be used instead of the hub specified in the actual feed.'),
135 183
      '#default_value' => $this->config['designated_hub'],
136
      '#dependency' => array(
137
        'edit-use-pubsubhubbub' => array(1),
184
      '#states' => array(
185
        'visible' => array(':input[name="use_pubsubhubbub"]' => array('checked' => TRUE)),
138 186
      ),
139 187
    );
140
   // Per importer override of global http request timeout setting.
141
   $form['request_timeout'] = array(
142
     '#type' => 'textfield',
143
     '#title' => t('Request timeout'),
144
     '#description' => t('Timeout in seconds to wait for an HTTP get request to finish.</br>' .
188
    // Per importer override of global http request timeout setting.
189
    $form['advanced']['request_timeout'] = array(
190
      '#type' => 'textfield',
191
      '#title' => t('Request timeout'),
192
      '#description' => t('Timeout in seconds to wait for an HTTP get request to finish.</br>' .
145 193
                         '<b>Note:</b> this setting will override the global setting.</br>' .
146 194
                         'When left empty, the global value is used.'),
147
     '#default_value' => $this->config['request_timeout'],
148
     '#element_validate' => array('element_validate_integer_positive'),
149
     '#maxlength' => 3,
150
     '#size'=> 30,
151
   );
195
      '#default_value' => $this->config['request_timeout'],
196
      '#element_validate' => array('element_validate_integer_positive'),
197
      '#maxlength' => 3,
198
      '#size'=> 30,
199
    );
200
    $form['advanced']['accept_invalid_cert'] = array(
201
      '#type' => 'checkbox',
202
      '#title' => t('Accept invalid SSL certificates'),
203
      '#description' => t('<strong>IMPORTANT:</strong> This setting will force cURL to completely ignore all SSL errors. This is a <strong>major security risk</strong> and should only be used during development.'),
204
      '#default_value' => $this->config['accept_invalid_cert'],
205
    );
206

  
152 207
    return $form;
153 208
  }
154 209

  
......
174 229
  public function sourceFormValidate(&$values) {
175 230
    $values['source'] = trim($values['source']);
176 231

  
232
    // Keep a copy for error messages.
233
    $original_url = $values['source'];
234

  
235
    $parts = parse_url($values['source']);
236
    if (empty($parts['scheme']) && $this->config['auto_scheme']) {
237
      $values['source'] = $this->config['auto_scheme'] . '://' . $values['source'];
238
    }
239

  
177 240
    if (!feeds_valid_url($values['source'], TRUE)) {
178 241
      $form_key = 'feeds][' . get_class($this) . '][source';
179
      form_set_error($form_key, t('The URL %source is invalid.', array('%source' => $values['source'])));
242
      form_set_error($form_key, t('The URL %source is invalid.', array('%source' => $original_url)));
180 243
    }
181 244
    elseif ($this->config['auto_detect_feeds']) {
182 245
      feeds_include_library('http_request.inc', 'http_request');
183
      if ($url = http_request_get_common_syndication($values['source'])) {
246
      $url = http_request_get_common_syndication($values['source'], array(
247
        'accept_invalid_cert' => $this->config['accept_invalid_cert'],
248
      ));
249
      if ($url) {
184 250
        $values['source'] = $url;
185 251
      }
186 252
    }

Formats disponibles : Unified diff