[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

title

Body

[close]

/wp-includes/ -> class-wp-simplepie-file.php (source)

   1  <?php
   2  /**
   3   * Feed API: WP_SimplePie_File class
   4   *
   5   * @package WordPress
   6   * @subpackage Feed
   7   * @since 4.7.0
   8   */
   9  
  10  /**
  11   * Core class for fetching remote files and reading local files with SimplePie.
  12   *
  13   * @since 2.8.0
  14   *
  15   * @see SimplePie_File
  16   */
  17  class WP_SimplePie_File extends SimplePie_File {
  18  
  19      /**
  20       * Constructor.
  21       *
  22       * @since 2.8.0
  23       * @since 3.2.0 Updated to use a PHP5 constructor.
  24       *
  25       * @param string       $url             Remote file URL.
  26       * @param integer      $timeout         Optional. How long the connection should stay open in seconds.
  27       *                                      Default 10.
  28       * @param integer      $redirects       Optional. The number of allowed redirects. Default 5.
  29       * @param string|array $headers         Optional. Array or string of headers to send with the request.
  30       *                                      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
  33       *                                      connection or not. Default false.
  34       */
  35  	public function __construct( $url, $timeout = 10, $redirects = 5, $headers = null, $useragent = null, $force_fsockopen = false ) {
  36          $this->url       = $url;
  37          $this->timeout   = $timeout;
  38          $this->redirects = $redirects;
  39          $this->headers   = $headers;
  40          $this->useragent = $useragent;
  41  
  42          $this->method = SIMPLEPIE_FILE_SOURCE_REMOTE;
  43  
  44          if ( preg_match( '/^http(s)?:\/\//i', $url ) ) {
  45              $args = array(
  46                  'timeout'     => $this->timeout,
  47                  'redirection' => $this->redirects,
  48              );
  49  
  50              if ( ! empty( $this->headers ) ) {
  51                  $args['headers'] = $this->headers;
  52              }
  53  
  54              if ( SIMPLEPIE_USERAGENT != $this->useragent ) { //Use default WP user agent unless custom has been specified
  55                  $args['user-agent'] = $this->useragent;
  56              }
  57  
  58              $res = wp_safe_remote_request( $url, $args );
  59  
  60              if ( is_wp_error( $res ) ) {
  61                  $this->error   = 'WP HTTP Error: ' . $res->get_error_message();
  62                  $this->success = false;
  63              } else {
  64                  $this->headers     = wp_remote_retrieve_headers( $res );
  65                  $this->body        = wp_remote_retrieve_body( $res );
  66                  $this->status_code = wp_remote_retrieve_response_code( $res );
  67              }
  68          } else {
  69              $this->error   = '';
  70              $this->success = false;
  71          }
  72      }
  73  }


Generated: Fri Oct 25 08:20:01 2019 Cross-referenced by PHPXref 0.7