| @@ -1175,9 +1175,11 @@ | ||
| 1175 | 1175 | ################################################################################ |
| 1176 | 1176 | ## WordPress: Load in Snoopy from wp-includes ################################## |
| 1177 | 1177 | ################################################################################ |
| 1178 | 1178 | |
| 1179 | -require_once( dirname(__FILE__) . '/class-snoopy.php'); | |
| 1179 | +if (!function_exists('wp_remote_request')) : | |
| 1180 | + require_once( dirname(__FILE__) . '/class-snoopy.php'); | |
| 1181 | +endif; | |
| 1180 | 1182 | |
| 1181 | 1183 | ################################################################################ |
| 1182 | 1184 | ## rss_fetch.inc: from MagpieRSS 0.8a ########################################## |
| 1183 | 1185 | ################################################################################ |
| @@ -1273,9 +1275,9 @@ | ||
| 1273 | 1275 | |
| 1274 | 1276 | // setup headers |
| 1275 | 1277 | if ( $cache_status == 'STALE' ) { |
| 1276 | 1278 | $rss = $cache->get( $cache_key ); |
| 1277 | - if ( $rss and $rss->etag and $rss->last_modified ) { | |
| 1279 | + if ( $rss and isset($rss->etag) and $rss->last_modified ) { | |
| 1278 | 1280 | $request_headers['If-None-Match'] = $rss->etag; |
| 1279 | 1281 | $request_headers['If-Last-Modified'] = $rss->last_modified; |
| 1280 | 1282 | } |
| 1281 | 1283 | } |
| @@ -1389,20 +1391,42 @@ | ||
| 1389 | 1391 | headers to send along with the request (optional) |
| 1390 | 1392 | Output: an HTTP response object (see Snoopy.class.inc) |
| 1391 | 1393 | \*=======================================================================*/ |
| 1392 | 1394 | function _fetch_remote_file ($url, $headers = "" ) { |
| 1393 | - // Snoopy is an HTTP client in PHP | |
| 1394 | - $client = new Snoopy(); | |
| 1395 | - $client->agent = MAGPIE_USER_AGENT; | |
| 1396 | - $client->read_timeout = MAGPIE_FETCH_TIME_OUT; | |
| 1397 | - $client->use_gzip = MAGPIE_USE_GZIP; | |
| 1398 | - if (is_array($headers) ) { | |
| 1399 | - $client->rawheaders = $headers; | |
| 1400 | - } | |
| 1401 | - | |
| 1402 | - @$client->fetch($url); | |
| 1403 | - return $client; | |
| 1395 | + // WordPress 2.7 has deprecated Snoopy. It's still there, for now, but | |
| 1396 | + // I'd rather not rely on it. | |
| 1397 | + if (function_exists('wp_remote_request')) : | |
| 1398 | + $resp = wp_remote_request($url, array( | |
| 1399 | + 'headers' => $headers, | |
| 1400 | + 'timeout' => MAGPIE_FETCH_TIME_OUT) | |
| 1401 | + ); | |
| 1404 | 1402 | |
| 1403 | + if ( is_wp_error($resp) ) : | |
| 1404 | + $error = array_shift($resp->errors); | |
| 1405 | + | |
| 1406 | + $client = new stdClass; | |
| 1407 | + $client->status = 500; | |
| 1408 | + $client->response_code = 500; | |
| 1409 | + $client->error = $error[0] . "\n"; //\n = Snoopy compatibility | |
| 1410 | + else : | |
| 1411 | + $client = new stdClass; | |
| 1412 | + $client->status = $resp['response']['code']; | |
| 1413 | + $client->response_code = $resp['response']['code']; | |
| 1414 | + $client->headers = $resp['headers']; | |
| 1415 | + $client->results = $resp['body']; | |
| 1416 | + endif; | |
| 1417 | + else : | |
| 1418 | + // Snoopy is an HTTP client in PHP | |
| 1419 | + $client = new Snoopy(); | |
| 1420 | + $client->agent = MAGPIE_USER_AGENT; | |
| 1421 | + $client->read_timeout = MAGPIE_FETCH_TIME_OUT; | |
| 1422 | + $client->use_gzip = MAGPIE_USE_GZIP; | |
| 1423 | + if (is_array($headers) ) { | |
| 1424 | + $client->rawheaders = $headers; | |
| 1425 | + } | |
| 1426 | + @$client->fetch($url); | |
| 1427 | + endif; | |
| 1428 | + return $client; | |
| 1405 | 1429 | } |
| 1406 | 1430 | |
| 1407 | 1431 | /*=======================================================================*\ |
| 1408 | 1432 | Function: _response_to_rss |