diff options
Diffstat (limited to 'plugins/jetpack/modules/after-the-deadline/proxy.php')
-rw-r--r-- | plugins/jetpack/modules/after-the-deadline/proxy.php | 72 |
1 files changed, 56 insertions, 16 deletions
diff --git a/plugins/jetpack/modules/after-the-deadline/proxy.php b/plugins/jetpack/modules/after-the-deadline/proxy.php index 3d5ef3b6..c0299da1 100644 --- a/plugins/jetpack/modules/after-the-deadline/proxy.php +++ b/plugins/jetpack/modules/after-the-deadline/proxy.php @@ -16,16 +16,38 @@ function AtD_http_post( $request, $host, $path, $port = 80 ) { 'User-Agent' => 'AtD/0.1' ), 'httpversion' => '1.0', + /** + * Change the timeout time for AtD post. + * + * @since 1.2.3 + * + * @param int $var Timeout time in seconds, default 15. + */ 'timeout' => apply_filters( 'atd_http_post_timeout', 15 ), ); - $AtD_url = "http://{$host}{$path}"; + + // Handle non-standard ports being passed in. + if ( ( 80 !== $port ) && is_numeric( $port ) && ( intval( $port ) > 0 ) ) { + $host .= ':' . intval( $port ); + } + // Strip any / off the begining so we can add it back and protect against SSRF + $path = ltrim( $path, '/' ); + $AtD_url = set_url_scheme( "http://{$host}/{$path}" ); $response = wp_remote_post( $AtD_url, $http_args ); - $code = (int) wp_remote_retrieve_response_code( $response ); + $code = (int) wp_remote_retrieve_response_code( $response ); if ( is_wp_error( $response ) ) { + /** + * Fires when there is a post error to AtD. + * + * @since 1.2.3 + * + * @param int|string http-error The error that AtD runs into. + */ do_action( 'atd_http_post_error', 'http-error' ); return array(); } elseif ( 200 != $code ) { + /** This action is documented in modules/after-the-deadline/proxy.php */ do_action( 'atd_http_post_error', $code ); } @@ -39,31 +61,49 @@ function AtD_http_post( $request, $host, $path, $port = 80 ) { * This function is called as an action handler to admin-ajax.php */ function AtD_redirect_call() { - if ( $_SERVER['REQUEST_METHOD'] === 'POST' ) - $postText = trim( file_get_contents( 'php://input' ) ); + if ( $_SERVER['REQUEST_METHOD'] === 'POST' ) + $postText = trim( file_get_contents( 'php://input' ) ); - $url = $_GET['url']; + check_admin_referer( 'proxy_atd' ); + $url = $_GET['url']; + /** + * Change the AtD service domain. + * + * @since 1.2.3 + * + * @param string $var The URL for AtD service domain, default is service.afterthedeadline.com. + */ $service = apply_filters( 'atd_service_domain', 'service.afterthedeadline.com' ); - if ( defined('WPLANG') ) { - if ( strpos(WPLANG, 'pt') !== false ) + + $user = wp_get_current_user(); + + $atd_lang = get_locale(); + + // If we're on WPCOM, this function should be available. + if ( function_exists( 'get_user_lang_code' ) ) { + $atd_lang = get_user_lang_code( $user->ID ); + } + + if ( ! empty( $atd_lang ) ) { + if ( strpos($atd_lang, 'pt') !== false ) $service = 'pt.service.afterthedeadline.com'; - else if ( strpos(WPLANG, 'de') !== false ) + else if ( strpos($atd_lang, 'de') !== false ) $service = 'de.service.afterthedeadline.com'; - else if ( strpos(WPLANG, 'es') !== false ) + else if ( strpos($atd_lang, 'es') !== false ) $service = 'es.service.afterthedeadline.com'; - else if ( strpos(WPLANG, 'fr') !== false ) + else if ( strpos($atd_lang, 'fr') !== false ) $service = 'fr.service.afterthedeadline.com'; } - $user = wp_get_current_user(); + $guess = strcmp( AtD_get_setting( $user->ID, 'AtD_guess_lang' ), "true" ) == 0 ? "true" : "false"; - $data = AtD_http_post( $postText . "&guess=$guess", defined('ATD_HOST') ? ATD_HOST : $service, $url, defined('ATD_PORT') ? ATD_PORT : 80 ); + $data = AtD_http_post( $postText . "&guess=$guess", defined('ATD_HOST') ? ATD_HOST : $service, $url, defined('ATD_PORT') ? ATD_PORT : 80 ); - header( 'Content-Type: text/xml' ); + header( 'Content-Type: text/xml' ); - if ( !empty($data[1]) ) - echo $data[1]; + if ( ! empty( $data[1] ) ) + echo $data[1]; - die(); + die(); } |