wp/wp-includes/class-wp-simplepie-file.php
changeset 9 177826044cd9
parent 7 cf61fcea0001
child 16 a86126ab1dd4
equal deleted inserted replaced
8:c7c34916027a 9:177826044cd9
    30 	 *                                      Default null.
    30 	 *                                      Default null.
    31 	 * @param string       $useragent       Optional. User-agent value sent. Default null.
    31 	 * @param string       $useragent       Optional. User-agent value sent. Default null.
    32 	 * @param boolean      $force_fsockopen Optional. Whether to force opening internet or unix domain socket
    32 	 * @param boolean      $force_fsockopen Optional. Whether to force opening internet or unix domain socket
    33 	 *                                      connection or not. Default false.
    33 	 *                                      connection or not. Default false.
    34 	 */
    34 	 */
    35 	public function __construct($url, $timeout = 10, $redirects = 5, $headers = null, $useragent = null, $force_fsockopen = false) {
    35 	public function __construct( $url, $timeout = 10, $redirects = 5, $headers = null, $useragent = null, $force_fsockopen = false ) {
    36 		$this->url = $url;
    36 		$this->url       = $url;
    37 		$this->timeout = $timeout;
    37 		$this->timeout   = $timeout;
    38 		$this->redirects = $redirects;
    38 		$this->redirects = $redirects;
    39 		$this->headers = $headers;
    39 		$this->headers   = $headers;
    40 		$this->useragent = $useragent;
    40 		$this->useragent = $useragent;
    41 
    41 
    42 		$this->method = SIMPLEPIE_FILE_SOURCE_REMOTE;
    42 		$this->method = SIMPLEPIE_FILE_SOURCE_REMOTE;
    43 
    43 
    44 		if ( preg_match('/^http(s)?:\/\//i', $url) ) {
    44 		if ( preg_match( '/^http(s)?:\/\//i', $url ) ) {
    45 			$args = array(
    45 			$args = array(
    46 				'timeout' => $this->timeout,
    46 				'timeout'     => $this->timeout,
    47 				'redirection' => $this->redirects,
    47 				'redirection' => $this->redirects,
    48 			);
    48 			);
    49 
    49 
    50 			if ( !empty($this->headers) )
    50 			if ( ! empty( $this->headers ) ) {
    51 				$args['headers'] = $this->headers;
    51 				$args['headers'] = $this->headers;
       
    52 			}
    52 
    53 
    53 			if ( SIMPLEPIE_USERAGENT != $this->useragent ) //Use default WP user agent unless custom has been specified
    54 			if ( SIMPLEPIE_USERAGENT != $this->useragent ) { //Use default WP user agent unless custom has been specified
    54 				$args['user-agent'] = $this->useragent;
    55 				$args['user-agent'] = $this->useragent;
       
    56 			}
    55 
    57 
    56 			$res = wp_safe_remote_request($url, $args);
    58 			$res = wp_safe_remote_request( $url, $args );
    57 
    59 
    58 			if ( is_wp_error($res) ) {
    60 			if ( is_wp_error( $res ) ) {
    59 				$this->error = 'WP HTTP Error: ' . $res->get_error_message();
    61 				$this->error   = 'WP HTTP Error: ' . $res->get_error_message();
    60 				$this->success = false;
    62 				$this->success = false;
    61 			} else {
    63 			} else {
    62 				$this->headers = wp_remote_retrieve_headers( $res );
    64 				$this->headers     = wp_remote_retrieve_headers( $res );
    63 				$this->body = wp_remote_retrieve_body( $res );
    65 				$this->body        = wp_remote_retrieve_body( $res );
    64 				$this->status_code = wp_remote_retrieve_response_code( $res );
    66 				$this->status_code = wp_remote_retrieve_response_code( $res );
    65 			}
    67 			}
    66 		} else {
    68 		} else {
    67 			$this->error = '';
    69 			$this->error   = '';
    68 			$this->success = false;
    70 			$this->success = false;
    69 		}
    71 		}
    70 	}
    72 	}
    71 }
    73 }