| 64 | |
| 65 | /** |
| 66 | * Tests through all WP_Http objects and store the first match |
| 67 | * and return. |
| 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 | * @since 3.1.0 |
| 78 | * @access private |
| 79 | * @param string|array $named name context, use array of names to use multiple |
| 80 | * @param array $args (optional) Request arguments |
| 81 | * @return object|null Concrete HTTP Transport Object; Null if no transport was found. |
| 82 | */ |
| 83 | function &_namedTransport( $named, $args = array() ) { |
| 84 | static $working, $blocking, $nonblocking; |
| 86 | !is_array( $named ) && ( $named = array( (string) $named ) ); |
| 87 | |
| 88 | foreach( $named as $context ) { |
| 89 | if ( !isset( $working[$context] ) ) { |
| 90 | $transports = array( |
| 91 | 'exthttp' => 'ExtHTTP', |
| 92 | 'curl' => 'Curl', |
| 93 | 'streams' => 'Streams', |
| 94 | 'fopen' => 'Fopen', |
| 95 | 'fsockopen' => 'Fsockopen', |
| 96 | ); |
| 97 | |
| 98 | foreach( $transports as $name => $spec) { |
| 99 | $class = 'WP_Http_' . $spec; |
| 100 | if ( !call_user_func( array( $class, 'test' ), $args ) ) |
| 101 | continue; |
| 102 | |
| 103 | $wp_http = new $class(); |
| 104 | |
| 105 | $working[$context][$name] = &$wp_http; |
| 106 | $blocking[$context][] = &$wp_http; |
| 107 | $nonblocking[$context][] = &$wp_http; |
| 108 | |
| 109 | break; |
| 110 | } |
| 111 | } |
| 112 | do_action( 'http_transport_get_debug', $working[$context], $blocking[$context], $nonblocking[$context] ); |
| 113 | } |
| 114 | |
| 115 | if ( isset($args['blocking']) && !$args['blocking'] ) |
| 116 | return $nonblocking[$context]; |
| 117 | else |
| 118 | return $blocking[$context]; |
| 119 | |
| 120 | } |
| 121 | |
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; |
| 145 | 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; |
| 164 | return $this->_namedTransport( 'post', $args ); |