Révision 41cc1b08
Ajouté par Assos Assos il y a presque 9 ans
drupal7/sites/all/modules/feeds/libraries/http_request.inc | ||
---|---|---|
38 | 38 |
* The discovered feed, or FALSE if the URL is not reachable or there was an |
39 | 39 |
* error. |
40 | 40 |
*/ |
41 |
function http_request_get_common_syndication($url, $settings = NULL) {
|
|
41 |
function http_request_get_common_syndication($url, $settings = array()) {
|
|
42 | 42 |
|
43 | 43 |
$accept_invalid_cert = isset($settings['accept_invalid_cert']) ? $settings['accept_invalid_cert'] : FALSE; |
44 | 44 |
$download = http_request_get($url, NULL, NULL, $accept_invalid_cert); |
... | ... | |
100 | 100 |
// Handle password protected feeds. |
101 | 101 |
$url_parts = parse_url($url); |
102 | 102 |
if (!empty($url_parts['user'])) { |
103 |
$password = $url_parts['pass'];
|
|
104 |
$username = $url_parts['user'];
|
|
103 |
$password = urldecode($url_parts['pass']);
|
|
104 |
$username = urldecode($url_parts['user']);
|
|
105 | 105 |
} |
106 | 106 |
} |
107 | 107 |
|
... | ... | |
110 | 110 |
// Only download and parse data if really needs refresh. |
111 | 111 |
// Based on "Last-Modified" and "If-Modified-Since". |
112 | 112 |
$headers = array(); |
113 |
if ($cache = cache_get('feeds_http_download_' . md5($url))) {
|
|
113 |
if ($cache = http_request_get_cache($url)) {
|
|
114 | 114 |
$last_result = $cache->data; |
115 | 115 |
$last_headers = array_change_key_case($last_result->headers); |
116 | 116 |
|
... | ... | |
178 | 178 |
curl_setopt($download, CURLOPT_RETURNTRANSFER, TRUE); |
179 | 179 |
curl_setopt($download, CURLOPT_ENCODING, ''); |
180 | 180 |
curl_setopt($download, CURLOPT_TIMEOUT, $request_timeout); |
181 |
|
|
182 |
$proxy_server = variable_get('proxy_server'); |
|
183 |
|
|
184 |
if ($proxy_server && _drupal_http_use_proxy($uri['host'])) { |
|
185 |
curl_setopt($download, CURLOPT_PROXY, $proxy_server); |
|
186 |
curl_setopt($download, CURLOPT_PROXYPORT, variable_get('proxy_port', 8080)); |
|
187 |
|
|
188 |
// Proxy user/password. |
|
189 |
if ($proxy_username = variable_get('proxy_username')) { |
|
190 |
$username_password = $proxy_username . ':' . variable_get('proxy_password', ''); |
|
191 |
|
|
192 |
curl_setopt($download, CURLOPT_PROXYUSERPWD, $username_password); |
|
193 |
curl_setopt($download, CURLOPT_PROXYAUTH, variable_get('proxy_auth_method', CURLAUTH_BASIC)); |
|
194 |
} |
|
195 |
} |
|
196 |
|
|
181 | 197 |
if ($accept_invalid_cert) { |
182 | 198 |
curl_setopt($download, CURLOPT_SSL_VERIFYPEER, 0); |
183 | 199 |
} |
... | ... | |
193 | 209 |
); |
194 | 210 |
} |
195 | 211 |
|
212 |
// When using a proxy, remove extra data from the header which is not |
|
213 |
// considered by CURLINFO_HEADER_SIZE (possibly cURL bug). |
|
214 |
// This data is only added when to HTTP header when working with a proxy. |
|
215 |
// Example string added: <HTTP/1.0 200 Connection established\r\n\r\n> |
|
216 |
// This was fixed in libcurl version 7.30.0 (0x71e00) (April 12, 2013), |
|
217 |
// so this workaround only removes the proxy-added headers if we are using |
|
218 |
// an older version of libcurl. |
|
219 |
$curl_ver = curl_version(); |
|
220 |
|
|
221 |
if ($proxy_server && $curl_ver['version_number'] < 0x71e00 && _drupal_http_use_proxy($uri['host'])) { |
|
222 |
$http_header_break = "\r\n\r\n"; |
|
223 |
$response = explode($http_header_break, $data); |
|
224 |
if (count($response) > 2) { |
|
225 |
$data = substr($data, strlen($response[0] . $http_header_break), strlen($data)); |
|
226 |
} |
|
227 |
} |
|
228 |
|
|
196 | 229 |
$header_size = curl_getinfo($download, CURLINFO_HEADER_SIZE); |
197 | 230 |
$header = substr($data, 0, $header_size - 1); |
198 | 231 |
$result->data = substr($data, $header_size); |
... | ... | |
237 | 270 |
else { |
238 | 271 |
// It's a tragedy, this file must exist and contain good data. |
239 | 272 |
// In this case, clear cache and repeat. |
240 |
cache_clear_all('feeds_http_download_' . md5($url), 'cache');
|
|
273 |
http_request_clear_cache($url);
|
|
241 | 274 |
return http_request_get($url, $username, $password, $accept_invalid_cert, $request_timeout); |
242 | 275 |
} |
243 | 276 |
} |
244 | 277 |
|
245 | 278 |
// Set caches. |
246 |
cache_set('feeds_http_download_' . md5($url), $result);
|
|
279 |
http_request_set_cache($url, $result);
|
|
247 | 280 |
$download_cache[$url] = $result; |
248 | 281 |
|
249 | 282 |
return $result; |
... | ... | |
253 | 286 |
* Decides if it's possible to use cURL or not. |
254 | 287 |
* |
255 | 288 |
* @return bool |
256 |
* TRUE if cURL is available, FALSE otherwise.
|
|
289 |
* TRUE if cURL may be used, FALSE otherwise.
|
|
257 | 290 |
*/ |
258 | 291 |
function http_request_use_curl() { |
259 | 292 |
// Allow site administrators to choose to not use cURL. |
... | ... | |
261 | 294 |
return FALSE; |
262 | 295 |
} |
263 | 296 |
|
264 |
// Check availability of cURL on the system. |
|
265 |
$basedir = ini_get("open_basedir"); |
|
266 |
return function_exists('curl_init') && !ini_get('safe_mode') && empty($basedir); |
|
297 |
// Check that the PHP cURL extension has been enabled. |
|
298 |
if (!extension_loaded('curl')) { |
|
299 |
return FALSE; |
|
300 |
} |
|
301 |
|
|
302 |
// cURL below PHP 5.6.0 must not have open_basedir or safe_mode enabled. |
|
303 |
if (version_compare(PHP_VERSION, '5.6.0', '<')) { |
|
304 |
return !ini_get('safe_mode') && !ini_get('open_basedir'); |
|
305 |
} |
|
306 |
|
|
307 |
// cURL in PHP 5.6.0 and above re-enables CURLOPT_FOLLOWLOCATION with |
|
308 |
// open_basedir so there is no need to check for this. |
|
309 |
return TRUE; |
|
267 | 310 |
} |
268 | 311 |
|
269 | 312 |
/** |
270 | 313 |
* Clear cache for a specific URL. |
314 |
* |
|
315 |
* @param string $url |
|
316 |
* The URL to clear. |
|
271 | 317 |
*/ |
272 | 318 |
function http_request_clear_cache($url) { |
273 |
cache_clear_all('feeds_http_download_' . md5($url), 'cache'); |
|
319 |
cache_clear_all(hash('sha256', $url), 'cache_feeds_http'); |
|
320 |
} |
|
321 |
|
|
322 |
/** |
|
323 |
* Gets the cache for a specific URL. |
|
324 |
* |
|
325 |
* @param string $url |
|
326 |
* The URL to find the cached item. |
|
327 |
* |
|
328 |
* @return object|false |
|
329 |
* The cache or FALSE on failure. |
|
330 |
*/ |
|
331 |
function http_request_get_cache($url) { |
|
332 |
return cache_get(hash('sha256', $url), 'cache_feeds_http'); |
|
333 |
} |
|
334 |
|
|
335 |
/** |
|
336 |
* Sets the cache for a specific URL. |
|
337 |
* |
|
338 |
* @param string $url |
|
339 |
* The URL to cache. |
|
340 |
* @param stdClass $result |
|
341 |
* The result of the HTTP request. |
|
342 |
*/ |
|
343 |
function http_request_set_cache($url, stdClass $result) { |
|
344 |
cache_set(hash('sha256', $url), $result, 'cache_feeds_http'); |
|
274 | 345 |
} |
275 | 346 |
|
276 | 347 |
/** |
... | ... | |
323 | 394 |
preg_match_all(HTTP_REQUEST_PCRE_TAG_ATTRIBUTES, $link_tag, $attributes, PREG_SET_ORDER); |
324 | 395 |
foreach ($attributes as $attribute) { |
325 | 396 |
// Find the key value pairs, attribute[1] is key and attribute[2] is the |
326 |
// value. |
|
397 |
// value. However, if the link tag used single quotes, the value might |
|
398 |
// be in attribute[3] instead. |
|
399 |
if (empty($attribute[2])) { |
|
400 |
$attribute[2] = $attribute[3]; |
|
401 |
} |
|
327 | 402 |
if (!empty($attribute[1]) && !empty($attribute[2])) { |
328 | 403 |
$candidate[drupal_strtolower($attribute[1])] = drupal_strtolower(decode_entities($attribute[2])); |
329 | 404 |
} |
Formats disponibles : Unified diff
Update feeds 7.x-2.0-alpha9 -> 7.x-2.0-beta1
Install lib simplepie 1.3.1