コード例 #1
0
ファイル: class-feed.php プロジェクト: nxtclass/NXTClass
 function __construct($url, $timeout = 10, $redirects = 5, $headers = null, $useragent = null, $force_fsockopen = false)
 {
     $this->url = $url;
     $this->timeout = $timeout;
     $this->redirects = $redirects;
     $this->headers = $headers;
     $this->useragent = $useragent;
     $this->method = SIMPLEPIE_FILE_SOURCE_REMOTE;
     if (preg_match('/^http(s)?:\\/\\//i', $url)) {
         $args = array('timeout' => $this->timeout, 'redirection' => $this->redirects);
         if (!empty($this->headers)) {
             $args['headers'] = $this->headers;
         }
         if (SIMPLEPIE_USERAGENT != $this->useragent) {
             //Use default nxt user agent unless custom has been specified
             $args['user-agent'] = $this->useragent;
         }
         $res = nxt_remote_request($url, $args);
         if (is_nxt_error($res)) {
             $this->error = 'nxt HTTP Error: ' . $res->get_error_message();
             $this->success = false;
         } else {
             $this->headers = nxt_remote_retrieve_headers($res);
             $this->body = nxt_remote_retrieve_body($res);
             $this->status_code = nxt_remote_retrieve_response_code($res);
         }
     } else {
         if (!($this->body = file_get_contents($url))) {
             $this->error = 'file_get_contents could not read the file';
             $this->success = false;
         }
     }
 }
コード例 #2
0
ファイル: functions.php プロジェクト: nxtclass/NXTClass
/**
 * Retrieve HTTP Headers from URL.
 *
 * @since 1.5.1
 *
 * @param string $url
 * @param bool $deprecated Not Used.
 * @return bool|string False on failure, headers on success.
 */
function nxt_get_http_headers($url, $deprecated = false)
{
    if (!empty($deprecated)) {
        _deprecated_argument(__FUNCTION__, '2.7');
    }
    $response = nxt_remote_head($url);
    if (is_nxt_error($response)) {
        return false;
    }
    return nxt_remote_retrieve_headers($response);
}