| | 64 | |
| | 65 | /** |
| | 66 | * Tests through all WP_Http objects and stores the first match |
| | 67 | * and returns. |
| | 68 | * |
| | 69 | * Test Order: |
| | 70 | * |
| | 71 | * 1. exthttp : WP_Http_ExtHTTP |
| | 72 | * 2. curl : WP_Http_Curl |
| | 73 | * 3. streams : WP_Http_Streams |
| | 74 | * 4. fopen : WP_Http_Fopen |
| | 75 | * 5. fsockopen: WP_Http_Fsockopen |
| | 76 | * |
| | 77 | * Note: fopen is not used in post $context. |
| | 78 | * |
| | 79 | * @since 3.1.0 |
| | 80 | * @access private |
| | 81 | * @param string|array $named name context, use array of names to use multiple |
| | 82 | * @param array $args (optional) Request arguments |
| | 83 | * @return object|null Concrete HTTP Transport Object; Null if no transport was found. |
| | 84 | */ |
| | 85 | function &_namedTransport( $named, $args = array() ) { |
| | 86 | static $working, $blocking, $nonblocking; |
| | 88 | is_scalar( $named ) && ( $named = array( (string) $named ) ); |
| | 89 | |
| | 90 | foreach ( $named as $context ) { |
| | 91 | if ( !isset( $working[$context] ) ) { |
| | 92 | $transports = array( |
| | 93 | 'exthttp' => 'ExtHTTP', |
| | 94 | 'curl' => 'Curl', |
| | 95 | 'streams' => 'Streams', |
| | 96 | 'fopen' => 'Fopen', |
| | 97 | 'fsockopen' => 'Fsockopen', |
| | 98 | ); |
| | 99 | |
| | 100 | foreach ( $transports as $name => $spec ) { |
| | 101 | $class = 'WP_Http_' . $spec; |
| | 102 | if ( !call_user_func( array( $class, 'test' ), $args ) ) |
| | 103 | continue; |
| | 104 | |
| | 105 | $wp_http = new $class(); |
| | 106 | |
| | 107 | $working[$context][$name] = &$wp_http; |
| | 108 | $blocking[$context][] = &$wp_http; |
| | 109 | $nonblocking[$context][] = &$wp_http; |
| | 110 | |
| | 111 | break; |
| | 112 | } |
| | 113 | } |
| | 114 | do_action( 'http_transport_get_debug', $working[$context], $blocking[$context], $nonblocking[$context] ); |
| | 115 | } |
| | 116 | |
| | 117 | if ( isset($args['blocking']) && !$args['blocking'] ) |
| | 118 | return $nonblocking[$context]; |
| | 119 | else |
| | 120 | return $blocking[$context]; |
| | 121 | |
| | 122 | } |
| | 123 | |
| 89 | | static $working_transport, $blocking_transport, $nonblocking_transport; |
| 90 | | |
| 91 | | if ( is_null($working_transport) ) { |
| 92 | | if ( true === WP_Http_ExtHttp::test($args) ) { |
| 93 | | $working_transport['exthttp'] = new WP_Http_ExtHttp(); |
| 94 | | $blocking_transport[] = &$working_transport['exthttp']; |
| 95 | | } else if ( true === WP_Http_Curl::test($args) ) { |
| 96 | | $working_transport['curl'] = new WP_Http_Curl(); |
| 97 | | $blocking_transport[] = &$working_transport['curl']; |
| 98 | | } else if ( true === WP_Http_Streams::test($args) ) { |
| 99 | | $working_transport['streams'] = new WP_Http_Streams(); |
| 100 | | $blocking_transport[] = &$working_transport['streams']; |
| 101 | | } else if ( true === WP_Http_Fopen::test($args) ) { |
| 102 | | $working_transport['fopen'] = new WP_Http_Fopen(); |
| 103 | | $blocking_transport[] = &$working_transport['fopen']; |
| 104 | | } else if ( true === WP_Http_Fsockopen::test($args) ) { |
| 105 | | $working_transport['fsockopen'] = new WP_Http_Fsockopen(); |
| 106 | | $blocking_transport[] = &$working_transport['fsockopen']; |
| 107 | | } |
| 108 | | |
| 109 | | foreach ( array('curl', 'streams', 'fopen', 'fsockopen', 'exthttp') as $transport ) { |
| 110 | | if ( isset($working_transport[$transport]) ) |
| 111 | | $nonblocking_transport[] = &$working_transport[$transport]; |
| 112 | | } |
| 113 | | } |
| 114 | | |
| 115 | | do_action( 'http_transport_get_debug', $working_transport, $blocking_transport, $nonblocking_transport ); |
| 116 | | |
| 117 | | if ( isset($args['blocking']) && !$args['blocking'] ) |
| 118 | | return $nonblocking_transport; |
| 119 | | else |
| 120 | | return $blocking_transport; |
| | 147 | return $this->_namedTransport( 'get', $args ); |
| 139 | | static $working_transport, $blocking_transport, $nonblocking_transport; |
| 140 | | |
| 141 | | if ( is_null($working_transport) ) { |
| 142 | | if ( true === WP_Http_ExtHttp::test($args) ) { |
| 143 | | $working_transport['exthttp'] = new WP_Http_ExtHttp(); |
| 144 | | $blocking_transport[] = &$working_transport['exthttp']; |
| 145 | | } else if ( true === WP_Http_Curl::test($args) ) { |
| 146 | | $working_transport['curl'] = new WP_Http_Curl(); |
| 147 | | $blocking_transport[] = &$working_transport['curl']; |
| 148 | | } else if ( true === WP_Http_Streams::test($args) ) { |
| 149 | | $working_transport['streams'] = new WP_Http_Streams(); |
| 150 | | $blocking_transport[] = &$working_transport['streams']; |
| 151 | | } else if ( true === WP_Http_Fsockopen::test($args) ) { |
| 152 | | $working_transport['fsockopen'] = new WP_Http_Fsockopen(); |
| 153 | | $blocking_transport[] = &$working_transport['fsockopen']; |
| 154 | | } |
| 155 | | |
| 156 | | foreach ( array('curl', 'streams', 'fsockopen', 'exthttp') as $transport ) { |
| 157 | | if ( isset($working_transport[$transport]) ) |
| 158 | | $nonblocking_transport[] = &$working_transport[$transport]; |
| 159 | | } |
| 160 | | } |
| 161 | | |
| 162 | | do_action( 'http_transport_post_debug', $working_transport, $blocking_transport, $nonblocking_transport ); |
| 163 | | |
| 164 | | if ( isset($args['blocking']) && !$args['blocking'] ) |
| 165 | | return $nonblocking_transport; |
| 166 | | else |
| 167 | | return $blocking_transport; |
| | 166 | return $this->_namedTransport( 'post', $args ); |