Example #1
0
 /**
  * Perform a HEAD request to the specified URL.
  * 
  * Note : 
  * 
  * Since the MediaFire checker works by parsing the "Location" header, redirect following
  * _must_ be disabled. This can become a problem on servers where WP is forced to fall back
  * on using WP_Http_Fopen which ignores the 'redirection' flag. WP_Http_Fsockopen would work, 
  * but it has the lowest priority of all transports. 
  * 
  * Alas, there is no way to reliably influence which transport is chosen - the WP_Http::_getTransport
  * function caches the available choices, so plugins can disable individual transports only during
  * its first run. Therefore, we must pick the best transport manually.
  * 
  * @param string $url
  * @return array|WP_Error
  */
 function head($url)
 {
     //Only consider transports that allow redirection to be disabled.
     $args = array();
     if (class_exists('WP_Http_ExtHttp') && true === WP_Http_ExtHttp::test($args)) {
         $transport = new WP_Http_ExtHttp();
     } else {
         if (class_exists('WP_Http_Curl') && true === WP_Http_Curl::test($args)) {
             $transport = new WP_Http_Curl();
         } else {
             if (class_exists('WP_Http_Curl') && true === WP_Http_Fsockopen::test($args)) {
                 $transport = new WP_Http_Fsockopen();
             } else {
                 return new WP_Error('no_suitable_transport', "No suitable HTTP transport found. Please upgrade to a more recent version of PHP or install the CURL extension.");
             }
         }
     }
     $conf = blc_get_configuration();
     $args = array('timeout' => $conf->options['timeout'], 'redirection' => 0, 'method' => 'HEAD');
     return $transport->request($url, $args);
 }
Example #2
0
 /**
  * Tests the WordPress HTTP objects for an object to use and returns it.
  *
  * Tests all of the objects and returns the object that passes. Also caches
  * that object to be used later. This is for posting content to a URL and
  * is used when there is a body. The plain Fopen Transport can not be used
  * to send content, but the streams transport can. This is a limitation that
  * is addressed here, by just not including that transport.
  *
  * @since 2.7.0
  * @access private
  *
  * @param array $args Request args, default us an empty array
  * @return object|null Null if no transports are available, HTTP transport object.
  */
 function &_postTransport($args = array())
 {
     static $working_transport, $blocking_transport, $nonblocking_transport;
     if (is_null($working_transport)) {
         if (true === WP_Http_ExtHttp::test($args)) {
             $working_transport['exthttp'] = new WP_Http_ExtHttp();
             $blocking_transport[] =& $working_transport['exthttp'];
         } else {
             if (true === WP_Http_Curl::test($args)) {
                 $working_transport['curl'] = new WP_Http_Curl();
                 $blocking_transport[] =& $working_transport['curl'];
             } else {
                 if (true === WP_Http_Streams::test($args)) {
                     $working_transport['streams'] = new WP_Http_Streams();
                     $blocking_transport[] =& $working_transport['streams'];
                 } else {
                     if (true === WP_Http_Fsockopen::test($args)) {
                         $working_transport['fsockopen'] = new WP_Http_Fsockopen();
                         $blocking_transport[] =& $working_transport['fsockopen'];
                     }
                 }
             }
         }
         foreach (array('curl', 'streams', 'fsockopen', 'exthttp') as $transport) {
             if (isset($working_transport[$transport])) {
                 $nonblocking_transport[] =& $working_transport[$transport];
             }
         }
     }
     do_action('http_transport_post_debug', $working_transport, $blocking_transport, $nonblocking_transport);
     if (isset($args['blocking']) && !$args['blocking']) {
         return $nonblocking_transport;
     } else {
         return $blocking_transport;
     }
 }
Example #3
0
 /**
  * Tests the WordPress HTTP objects for an object to use and returns it.
  *
  * Tests all of the objects and returns the object that passes. Also caches
  * that object to be used later. This is for posting content to a URL and
  * is used when there is a body. The plain Fopen Transport can not be used
  * to send content, but the streams transport can. This is a limitation that
  * is addressed here, by just not including that transport.
  *
  * @since 2.7.0
  * @access private
  *
  * @param array $args Request args, default us an empty array
  * @return object|null Null if no transports are available, HTTP transport object.
  */
 function &_postTransport($args = array())
 {
     static $working_transport, $blocking_transport, $nonblocking_transport;
     if (is_null($working_transport)) {
         if (true === WP_Http_ExtHttp::test() && apply_filters('use_http_extension_transport', true)) {
             $working_transport['exthttp'] = new WP_Http_ExtHttp();
             $blocking_transport[] =& $working_transport['exthttp'];
         } else {
             if (true === WP_Http_Streams::test() && apply_filters('use_streams_transport', true)) {
                 $working_transport['streams'] = new WP_Http_Streams();
                 $blocking_transport[] =& $working_transport['streams'];
             } else {
                 if (true === WP_Http_Fsockopen::test() && apply_filters('use_fsockopen_transport', true)) {
                     $working_transport['fsockopen'] = new WP_Http_Fsockopen();
                     $blocking_transport[] =& $working_transport['fsockopen'];
                 }
             }
         }
         foreach (array('streams', 'fsockopen', 'exthttp') as $transport) {
             if (isset($working_transport[$transport])) {
                 $nonblocking_transport[] =& $working_transport[$transport];
             }
         }
     }
     if (has_filter('http_transport_post_debug')) {
         do_action('http_transport_post_debug', $working_transport, $blocking_transport, $nonblocking_transport);
     }
     if (isset($args['blocking']) && !$args['blocking']) {
         return $nonblocking_transport;
     } else {
         return $blocking_transport;
     }
 }