64 * @use WP_PROXY_PASSWORD |
64 * @use WP_PROXY_PASSWORD |
65 * |
65 * |
66 * @return bool |
66 * @return bool |
67 */ |
67 */ |
68 public function use_authentication() { |
68 public function use_authentication() { |
69 return defined('WP_PROXY_USERNAME') && defined('WP_PROXY_PASSWORD'); |
69 return defined( 'WP_PROXY_USERNAME' ) && defined( 'WP_PROXY_PASSWORD' ); |
70 } |
70 } |
71 |
71 |
72 /** |
72 /** |
73 * Retrieve the host for the proxy server. |
73 * Retrieve the host for the proxy server. |
74 * |
74 * |
75 * @since 2.8.0 |
75 * @since 2.8.0 |
76 * |
76 * |
77 * @return string |
77 * @return string |
78 */ |
78 */ |
79 public function host() { |
79 public function host() { |
80 if ( defined('WP_PROXY_HOST') ) |
80 if ( defined( 'WP_PROXY_HOST' ) ) { |
81 return WP_PROXY_HOST; |
81 return WP_PROXY_HOST; |
|
82 } |
82 |
83 |
83 return ''; |
84 return ''; |
84 } |
85 } |
85 |
86 |
86 /** |
87 /** |
165 public function send_through_proxy( $uri ) { |
169 public function send_through_proxy( $uri ) { |
166 /* |
170 /* |
167 * parse_url() only handles http, https type URLs, and will emit E_WARNING on failure. |
171 * parse_url() only handles http, https type URLs, and will emit E_WARNING on failure. |
168 * This will be displayed on sites, which is not reasonable. |
172 * This will be displayed on sites, which is not reasonable. |
169 */ |
173 */ |
170 $check = @parse_url($uri); |
174 $check = @parse_url( $uri ); |
171 |
175 |
172 // Malformed URL, can not process, but this could mean ssl, so let through anyway. |
176 // Malformed URL, can not process, but this could mean ssl, so let through anyway. |
173 if ( $check === false ) |
177 if ( $check === false ) { |
174 return true; |
178 return true; |
175 |
179 } |
176 $home = parse_url( get_option('siteurl') ); |
180 |
|
181 $home = parse_url( get_option( 'siteurl' ) ); |
177 |
182 |
178 /** |
183 /** |
179 * Filters whether to preempt sending the request through the proxy server. |
184 * Filters whether to preempt sending the request through the proxy server. |
180 * |
185 * |
181 * Returning false will bypass the proxy; returning true will send |
186 * Returning false will bypass the proxy; returning true will send |
187 * @param string $uri URL to check. |
192 * @param string $uri URL to check. |
188 * @param array $check Associative array result of parsing the URI. |
193 * @param array $check Associative array result of parsing the URI. |
189 * @param array $home Associative array result of parsing the site URL. |
194 * @param array $home Associative array result of parsing the site URL. |
190 */ |
195 */ |
191 $result = apply_filters( 'pre_http_send_through_proxy', null, $uri, $check, $home ); |
196 $result = apply_filters( 'pre_http_send_through_proxy', null, $uri, $check, $home ); |
192 if ( ! is_null( $result ) ) |
197 if ( ! is_null( $result ) ) { |
193 return $result; |
198 return $result; |
194 |
199 } |
195 if ( 'localhost' == $check['host'] || ( isset( $home['host'] ) && $home['host'] == $check['host'] ) ) |
200 |
|
201 if ( 'localhost' == $check['host'] || ( isset( $home['host'] ) && $home['host'] == $check['host'] ) ) { |
196 return false; |
202 return false; |
197 |
203 } |
198 if ( !defined('WP_PROXY_BYPASS_HOSTS') ) |
204 |
|
205 if ( ! defined( 'WP_PROXY_BYPASS_HOSTS' ) ) { |
199 return true; |
206 return true; |
200 |
207 } |
201 static $bypass_hosts = null; |
208 |
|
209 static $bypass_hosts = null; |
202 static $wildcard_regex = array(); |
210 static $wildcard_regex = array(); |
203 if ( null === $bypass_hosts ) { |
211 if ( null === $bypass_hosts ) { |
204 $bypass_hosts = preg_split('|,\s*|', WP_PROXY_BYPASS_HOSTS); |
212 $bypass_hosts = preg_split( '|,\s*|', WP_PROXY_BYPASS_HOSTS ); |
205 |
213 |
206 if ( false !== strpos(WP_PROXY_BYPASS_HOSTS, '*') ) { |
214 if ( false !== strpos( WP_PROXY_BYPASS_HOSTS, '*' ) ) { |
207 $wildcard_regex = array(); |
215 $wildcard_regex = array(); |
208 foreach ( $bypass_hosts as $host ) |
216 foreach ( $bypass_hosts as $host ) { |
209 $wildcard_regex[] = str_replace( '\*', '.+', preg_quote( $host, '/' ) ); |
217 $wildcard_regex[] = str_replace( '\*', '.+', preg_quote( $host, '/' ) ); |
210 $wildcard_regex = '/^(' . implode('|', $wildcard_regex) . ')$/i'; |
218 } |
|
219 $wildcard_regex = '/^(' . implode( '|', $wildcard_regex ) . ')$/i'; |
211 } |
220 } |
212 } |
221 } |
213 |
222 |
214 if ( !empty($wildcard_regex) ) |
223 if ( ! empty( $wildcard_regex ) ) { |
215 return !preg_match($wildcard_regex, $check['host']); |
224 return ! preg_match( $wildcard_regex, $check['host'] ); |
216 else |
225 } else { |
217 return !in_array( $check['host'], $bypass_hosts ); |
226 return ! in_array( $check['host'], $bypass_hosts ); |
|
227 } |
218 } |
228 } |
219 } |
229 } |