Make WordPress Core

Changeset 29229


Ignore:
Timestamp:
07/18/2014 09:46:24 PM (12 years ago)
Author:
DrewAPicture
Message:

Fix syntax for single- and multi-line comments in wp-includes/class-http.php.

See #28943 and #28931.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-http.php

    r29223 r29229  
    178178                        return new WP_Error( 'http_request_failed', __( 'User has blocked requests through HTTP.' ) );
    179179
    180                 // Determine if this is a https call and pass that on to the transport functions
    181                 // so that we can blacklist the transports that do not support ssl verification
     180                /*
     181                 * Determine if this is a https call and pass that on to the transport functions
     182                 * so that we can blacklist the transports that do not support ssl verification
     183                 */
    182184                $r['ssl'] = $arrURL['scheme'] == 'https' || $arrURL['scheme'] == 'ssl';
    183185
    184                 // Determine if this request is to OUR install of WordPress
     186                // Determine if this request is to OUR install of WordPress.
    185187                $homeURL = parse_url( get_bloginfo( 'url' ) );
    186188                if ( isset( $homeURL['host'] ) ) {
    … …  
    191193                unset( $homeURL );
    192194
    193                 // If we are streaming to a file but no filename was given drop it in the WP temp dir
    194                 // and pick its name using the basename of the $url
     195                /*
     196                 * If we are streaming to a file but no filename was given drop it in the WP temp dir
     197                 * and pick its name using the basename of the $url.
     198                 */
    195199                if ( $r['stream']  && empty( $r['filename'] ) )
    196200                        $r['filename'] = get_temp_dir() . basename( $url );
    197201
    198                 // Force some settings if we are streaming to a file and check for existence and perms of destination directory
     202                /*
     203                 * Force some settings if we are streaming to a file and check for existence and perms
     204                 * of destination directory.
     205                 */
    199206                if ( $r['stream'] ) {
    200207                        $r['blocking'] = true;
    … …  
    225232                }
    226233
    227                 // Construct Cookie: header if any cookies are set
     234                // Construct Cookie: header if any cookies are set.
    228235                WP_Http::buildCookieHeader( $r );
    229236
    230                 // Avoid issues where mbstring.func_overload is enabled
     237                // Avoid issues where mbstring.func_overload is enabled.
    231238                mbstring_binary_safe_encoding();
    232239
    … …  
    295302                $request_order = apply_filters( 'http_api_transports', array( 'curl', 'streams' ), $args, $url );
    296303
    297                 // Loop over each transport on each HTTP request looking for one which will serve this request's needs
     304                // Loop over each transport on each HTTP request looking for one which will serve this request's needs.
    298305                foreach ( $request_order as $transport ) {
    299306                        $class = 'WP_HTTP_' . $transport;
    300307
    301                         // Check to see if this transport is a possibility, calls the transport statically
     308                        // Check to see if this transport is a possibility, calls the transport statically.
    302309                        if ( !call_user_func( array( $class, 'test' ), $args, $url ) )
    303310                                continue;
    … …  
    451458         */
    452459        public static function processHeaders( $headers, $url = '' ) {
    453                 // split headers, one per array element
     460                // Split headers, one per array element.
    454461                if ( is_string($headers) ) {
    455                         // tolerate line terminator: CRLF = LF (RFC 2616 19.3)
     462                        // Tolerate line terminator: CRLF = LF (RFC 2616 19.3).
    456463                        $headers = str_replace("\r\n", "\n", $headers);
    457                         // unfold folded header fields. LWS = [CRLF] 1*( SP | HT ) <US-ASCII SP, space (32)>, <US-ASCII HT, horizontal-tab (9)> (RFC 2616 2.2)
     464                        /*
     465                         * Unfold folded header fields. LWS = [CRLF] 1*( SP | HT ) <US-ASCII SP, space (32)>,
     466                         * <US-ASCII HT, horizontal-tab (9)> (RFC 2616 2.2).
     467                         */
    458468                        $headers = preg_replace('/\n[ \t]/', ' ', $headers);
    459                         // create the headers array
     469                        // Create the headers array.
    460470                        $headers = explode("\n", $headers);
    461471                }
    … …  
    463473                $response = array('code' => 0, 'message' => '');
    464474
    465                 // If a redirection has taken place, The headers for each page request may have been passed.
    466                 // In this case, determine the final HTTP header and parse from there.
     475                /*
     476                 * If a redirection has taken place, The headers for each page request may have been passed.
     477                 * In this case, determine the final HTTP header and parse from there.
     478                 */
    467479                for ( $i = count($headers)-1; $i >= 0; $i-- ) {
    468480                        if ( !empty($headers[$i]) && false === strpos($headers[$i], ':') ) {
    … …  
    519531        public static function buildCookieHeader( &$r ) {
    520532                if ( ! empty($r['cookies']) ) {
    521                         // Upgrade any name => value cookie pairs to WP_HTTP_Cookie instances
     533                        // Upgrade any name => value cookie pairs to WP_HTTP_Cookie instances.
    522534                        foreach ( $r['cookies'] as $name => $value ) {
    523535                                if ( ! is_object( $value ) )
    … …  
    555567
    556568                $parsed_body = '';
    557                 $body_original = $body; // We'll be altering $body, so need a backup in case of error
     569
     570                // We'll be altering $body, so need a backup in case of error.
     571                $body_original = $body;
    558572
    559573                while ( true ) {
    … …  
    565579                        $chunk_length = strlen( $match[0] );
    566580
    567                         // Parse out the chunk of data
     581                        // Parse out the chunk of data.
    568582                        $parsed_body .= substr( $body, $chunk_length, $length );
    569583
    570                         // Remove the chunk from the raw data
     584                        // Remove the chunk from the raw data.
    571585                        $body = substr( $body, $length + $chunk_length );
    572586
    573                         // End of document
     587                        // End of the document.
    574588                        if ( '0' === trim( $body ) )
    575589                                return $parsed_body;
    … …  
    607621                $home = parse_url( get_option('siteurl') );
    608622
    609                 // Don't block requests back to ourselves by default
     623                // Don't block requests back to ourselves by default.
    610624                if ( $check['host'] == 'localhost' || $check['host'] == $home['host'] ) {
    611625                        /**
    … …  
    647661                        return $maybe_relative_path;
    648662
    649                 // Check for a scheme
     663                // Check for a scheme.
    650664                if ( false !== strpos( $maybe_relative_path, '://' ) )
    651665                        return $maybe_relative_path;
    … …  
    661675                        $absolute_path .= ':' . $url_parts['port'];
    662676
    663                 // Start off with the Absolute URL path
     677                // Start off with the Absolute URL path.
    664678                $path = ! empty( $url_parts['path'] ) ? $url_parts['path'] : '/';
    665679
    666                 // If it's a root-relative path, then great
     680                // If it's a root-relative path, then great.
    667681                if ( ! empty( $relative_url_parts['path'] ) && '/' == $relative_url_parts['path'][0] ) {
    668682                        $path = $relative_url_parts['path'];
    669683
    670                 // Else it's a relative path
     684                // Else it's a relative path.
    671685                } elseif ( ! empty( $relative_url_parts['path'] ) ) {
    672                         // Strip off any file components from the absolute path
     686                        // Strip off any file components from the absolute path.
    673687                        $path = substr( $path, 0, strrpos( $path, '/' ) + 1 );
    674688
    675                         // Build the new path
     689                        // Build the new path.
    676690                        $path .= $relative_url_parts['path'];
    677691
    678                         // Strip all /path/../ out of the path
     692                        // Strip all /path/../ out of the path.
    679693                        while ( strpos( $path, '../' ) > 1 ) {
    680694                                $path = preg_replace( '![^/]+/\.\./!', '', $path );
    681695                        }
    682696
    683                         // Strip any final leading ../ from the path
     697                        // Strip any final leading ../ from the path.
    684698                        $path = preg_replace( '!^/(\.\./)+!', '', $path );
    685699                }
    686700
    687                 // Add the Query string
     701                // Add the Query string.
    688702                if ( ! empty( $relative_url_parts['query'] ) )
    689703                        $path .= '?' . $relative_url_parts['query'];
    … …  
    707721                        return false;
    708722
    709                 // Only perform redirections on redirection http codes
     723                // Only perform redirections on redirection http codes.
    710724                if ( $response['response']['code'] > 399 || $response['response']['code'] < 300 )
    711725                        return false;
    712726
    713                 // Don't redirect if we've run out of redirects
     727                // Don't redirect if we've run out of redirects.
    714728                if ( $args['redirection']-- <= 0 )
    715729                        return new WP_Error( 'http_request_failed', __('Too many redirects.') );
    … …  
    717731                $redirect_location = $response['headers']['location'];
    718732
    719                 // If there were multiple Location headers, use the last header specified
     733                // If there were multiple Location headers, use the last header specified.
    720734                if ( is_array( $redirect_location ) )
    721735                        $redirect_location = array_pop( $redirect_location );
    … …  
    723737                $redirect_location = WP_HTTP::make_absolute_url( $redirect_location, $url );
    724738
    725                 // POST requests should not POST to a redirected location
     739                // POST requests should not POST to a redirected location.
    726740                if ( 'POST' == $args['method'] ) {
    727741                        if ( in_array( $response['response']['code'], array( 302, 303 ) ) )
    … …  
    729743                }
    730744
    731                 // Include valid cookies in the redirect process
     745                // Include valid cookies in the redirect process.
    732746                if ( ! empty( $response['cookies'] ) ) {
    733747                        foreach ( $response['cookies'] as $cookie ) {
    … …  
    806820                }
    807821
    808                 // Construct Cookie: header if any cookies are set
     822                // Construct Cookie: header if any cookies are set.
    809823                WP_Http::buildCookieHeader( $r );
    810824
    … …  
    831845                }
    832846
    833                 // Certain versions of PHP have issues with 'localhost' and IPv6, It attempts to connect to ::1,
    834                 // which fails when the server is not set up for it. For compatibility, always connect to the IPv4 address.
     847                /*
     848                 * Certain versions of PHP have issues with 'localhost' and IPv6, It attempts to connect
     849                 * to ::1, which fails when the server is not set up for it. For compatibility, always
     850                 * connect to the IPv4 address.
     851                 */
    835852                if ( 'localhost' == strtolower( $connect_host ) )
    836853                        $connect_host = '127.0.0.1';
    … …  
    877894                $connect_timeout = max( $timeout, 1 );
    878895
    879                 $connection_error = null; // Store error number
    880                 $connection_error_str = null; // Store error string
     896                // Store error number.
     897                $connection_error = null;
     898
     899                // Store error string.
     900                $connection_error_str = null;
    881901
    882902                if ( !WP_DEBUG ) {
    883                         // In the event that the SSL connection fails, silence the many PHP Warnings
     903                        // In the event that the SSL connection fails, silence the many PHP Warnings.
    884904                        if ( $secure_transport )
    885905                                $error_reporting = error_reporting(0);
    … …  
    901921
    902922                if ( false === $handle ) {
    903                         // SSL connection failed due to expired/invalid cert, or, OpenSSL configuration is broken
     923                        // SSL connection failed due to expired/invalid cert, or, OpenSSL configuration is broken.
    904924                        if ( $secure_transport && 0 === $connection_error && '' === $connection_error_str )
    905925                                return new WP_Error( 'http_request_failed', __( 'The SSL certificate for the host could not be verified.' ) );
    … …  
    908928                }
    909929
    910                 // Verify that the SSL certificate is valid for this request
     930                // Verify that the SSL certificate is valid for this request.
    911931                if ( $secure_transport && $ssl_verify && ! $proxy->is_enabled() ) {
    912932                        if ( ! self::verify_ssl_certificate( $handle, $arrURL['host'] ) )
    … …  
    964984                        $block_size = min( $block_size, $r['limit_response_size'] );
    965985
    966                 // If streaming to a file setup the file handle
     986                // If streaming to a file setup the file handle.
    967987                if ( $r['stream'] ) {
    968988                        if ( ! WP_DEBUG )
    … …  
    10301050                $response = array(
    10311051                        'headers' => $arrHeaders['headers'],
    1032                         'body' => null, // Not yet processed
     1052                        // Not yet processed.
     1053                        'body' => null,
    10331054                        'response' => $arrHeaders['response'],
    10341055                        'cookies' => $arrHeaders['cookies'],
    … …  
    10361057                );
    10371058
    1038                 // Handle redirects
     1059                // Handle redirects.
    10391060                if ( false !== ( $redirect_response = WP_HTTP::handle_redirects( $url, $r, $response ) ) )
    10401061                        return $redirect_response;
    … …  
    10821103                        return false;
    10831104
    1084                 // If the request is being made to an IP address, we'll validate against IP fields in the cert (if they exist)
     1105                /*
     1106                 * If the request is being made to an IP address, we'll validate against IP fields
     1107                 * in the cert (if they exist)
     1108                 */
    10851109                $host_type = ( WP_HTTP::is_ip_address( $host ) ? 'ip' : 'dns' );
    10861110
    … …  
    10941118                        }
    10951119                } elseif ( !empty( $cert['subject']['CN'] ) ) {
    1096                         // Only use the CN when the certificate includes no subjectAltName extension
     1120                        // Only use the CN when the certificate includes no subjectAltName extension.
    10971121                        $certificate_hostnames[] = strtolower( $cert['subject']['CN'] );
    10981122                }
    10991123
    1100                 // Exact hostname/IP matches
     1124                // Exact hostname/IP matches.
    11011125                if ( in_array( strtolower( $host ), $certificate_hostnames ) )
    11021126                        return true;
    11031127
    1104                 // IP's can't be wildcards, Stop processing
     1128                // IP's can't be wildcards, Stop processing.
    11051129                if ( 'ip' == $host_type )
    11061130                        return false;
    11071131
    1108                 // Test to see if the domain is at least 2 deep for wildcard support
     1132                // Test to see if the domain is at least 2 deep for wildcard support.
    11091133                if ( substr_count( $host, '.' ) < 2 )
    11101134                        return false;
    11111135
    1112                 // Wildcard subdomains certs (*.example.com) are valid for a.example.com but not a.b.example.com
     1136                // Wildcard subdomains certs (*.example.com) are valid for a.example.com but not a.b.example.com.
    11131137                $wildcard_host = preg_replace( '/^[^.]+\./', '*.', $host );
    11141138
    … …  
    11631187 */
    11641188class WP_HTTP_Fsockopen extends WP_HTTP_Streams {
    1165         // For backwards compatibility for users who are using the class directly
     1189        // For backwards compatibility for users who are using the class directly.
    11661190}
    11671191
    … …  
    12711295                }
    12721296
    1273                 // CURLOPT_TIMEOUT and CURLOPT_CONNECTTIMEOUT expect integers. Have to use ceil since
    1274                 // a value of 0 will allow an unlimited timeout.
     1297                /*
     1298                 * CURLOPT_TIMEOUT and CURLOPT_CONNECTTIMEOUT expect integers. Have to use ceil since.
     1299                 * a value of 0 will allow an unlimited timeout.
     1300                 */
    12751301                $timeout = (int) ceil( $r['timeout'] );
    12761302                curl_setopt( $handle, CURLOPT_CONNECTTIMEOUT, $timeout );
    … …  
    12831309                curl_setopt( $handle, CURLOPT_CAINFO, $r['sslcertificates'] );
    12841310                curl_setopt( $handle, CURLOPT_USERAGENT, $r['user-agent'] );
    1285                 // The option doesn't work with safe mode or when open_basedir is set, and there's a
    1286                 // bug #17490 with redirected POST requests, so handle redirections outside Curl.
     1311
     1312                /*
     1313                 * The option doesn't work with safe mode or when open_basedir is set, and there's
     1314                 * a bug #17490 with redirected POST requests, so handle redirections outside Curl.
     1315                 */
    12871316                curl_setopt( $handle, CURLOPT_FOLLOWLOCATION, false );
    12881317                if ( defined( 'CURLOPT_PROTOCOLS' ) ) // PHP 5.2.10 / cURL 7.19.4
    … …  
    13201349                        $this->max_body_length = false;
    13211350
    1322                 // If streaming to a file open a file handle, and setup our curl streaming handler
     1351                // If streaming to a file open a file handle, and setup our curl streaming handler.
    13231352                if ( $r['stream'] ) {
    13241353                        if ( ! WP_DEBUG )
    … …  
    13331362
    13341363                if ( !empty( $r['headers'] ) ) {
    1335                         // cURL expects full header strings in each element
     1364                        // cURL expects full header strings in each element.
    13361365                        $headers = array();
    13371366                        foreach ( $r['headers'] as $name => $value ) {
    … …  
    13861415                $curl_error = curl_errno( $handle );
    13871416
    1388                 // If an error occured, or, no response
     1417                // If an error occured, or, no response.
    13891418                if ( $curl_error || ( 0 == strlen( $theBody ) && empty( $theHeaders['headers'] ) ) ) {
    13901419                        if ( CURLE_WRITE_ERROR /* 23 */ == $curl_error &&  $r['stream'] ) {
    … …  
    14191448                );
    14201449
    1421                 // Handle redirects
     1450                // Handle redirects.
    14221451                if ( false !== ( $redirect_response = WP_HTTP::handle_redirects( $url, $r, $response ) ) )
    14231452                        return $redirect_response;
    … …  
    14681497                }
    14691498
    1470                 // Upon event of this function returning less than strlen( $data ) curl will error with CURLE_WRITE_ERROR
     1499                // Upon event of this function returning less than strlen( $data ) curl will error with CURLE_WRITE_ERROR.
    14711500                return $bytes_written;
    14721501        }
    … …  
    14881517                if ( $is_ssl ) {
    14891518                        $curl_version = curl_version();
    1490                         if ( ! (CURL_VERSION_SSL & $curl_version['features']) ) // Does this cURL version support SSL requests?
     1519                        // Check whether this cURL version support SSL requests.
     1520                        if ( ! (CURL_VERSION_SSL & $curl_version['features']) )
    14911521                                return false;
    14921522                }
    … …  
    16581688         */
    16591689        public function send_through_proxy( $uri ) {
    1660                 // parse_url() only handles http, https type URLs, and will emit E_WARNING on failure.
    1661                 // This will be displayed on blogs, which is not reasonable.
     1690                /*
     1691                 * parse_url() only handles http, https type URLs, and will emit E_WARNING on failure.
     1692                 * This will be displayed on blogs, which is not reasonable.
     1693                 */
    16621694                $check = @parse_url($uri);
    16631695
    … …  
    17971829
    17981830                if ( is_string( $data ) ) {
    1799                         // Assume it's a header string direct from a previous request
     1831                        // Assume it's a header string direct from a previous request.
    18001832                        $pairs = explode( ';', $data );
    18011833
    1802                         // Special handling for first pair; name=value. Also be careful of "=" in value
     1834                        // Special handling for first pair; name=value. Also be careful of "=" in value.
    18031835                        $name  = trim( substr( $pairs[0], 0, strpos( $pairs[0], '=' ) ) );
    18041836                        $value = substr( $pairs[0], strpos( $pairs[0], '=' ) + 1 );
    18051837                        $this->name  = $name;
    18061838                        $this->value = urldecode( $value );
    1807                         array_shift( $pairs ); //Removes name=value from items.
    1808 
    1809                         // Set everything else as a property
     1839
     1840                        // Removes name=value from items.
     1841                        array_shift( $pairs );
     1842
     1843                        // Set everything else as a property.
    18101844                        foreach ( $pairs as $pair ) {
    18111845                                $pair = rtrim($pair);
    1812                                 if ( empty($pair) ) //Handles the cookie ending in ; which results in a empty final pair
     1846
     1847                                // Handle the cookie ending in ; which results in a empty final pair.
     1848                                if ( empty($pair) )
    18131849                                        continue;
    18141850
    … …  
    18231859                                return false;
    18241860
    1825                         // Set properties based directly on parameters
     1861                        // Set properties based directly on parameters.
    18261862                        foreach ( array( 'name', 'value', 'path', 'domain', 'port' ) as $field ) {
    18271863                                if ( isset( $data[ $field ] ) )
    … …  
    18511887                        return false;
    18521888
    1853                 // Expires - if expired then nothing else matters
     1889                // Expires - if expired then nothing else matters.
    18541890                if ( isset( $this->expires ) && time() > $this->expires )
    18551891                        return false;
    18561892
    1857                 // Get details on the URL we're thinking about sending to
     1893                // Get details on the URL we're thinking about sending to.
    18581894                $url = parse_url( $url );
    18591895                $url['port'] = isset( $url['port'] ) ? $url['port'] : ( 'https' == $url['scheme'] ? 443 : 80 );
    18601896                $url['path'] = isset( $url['path'] ) ? $url['path'] : '/';
    18611897
    1862                 // Values to use for comparison against the URL
     1898                // Values to use for comparison against the URL.
    18631899                $path   = isset( $this->path )   ? $this->path   : '/';
    18641900                $port   = isset( $this->port )   ? $this->port   : null;
    … …  
    18671903                        $domain .= '.local';
    18681904
    1869                 // Host - very basic check that the request URL ends with the domain restriction (minus leading dot)
     1905                // Host - very basic check that the request URL ends with the domain restriction (minus leading dot).
    18701906                $domain = substr( $domain, 0, 1 ) == '.' ? substr( $domain, 1 ) : $domain;
    18711907                if ( substr( $url['host'], -strlen( $domain ) ) != $domain )
    18721908                        return false;
    18731909
    1874                 // Port - supports "port-lists" in the format: "80,8000,8080"
     1910                // Port - supports "port-lists" in the format: "80,8000,8080".
    18751911                if ( !empty( $port ) && !in_array( $url['port'], explode( ',', $port) ) )
    18761912                        return false;
    18771913
    1878                 // Path - request path must start with path restriction
     1914                // Path - request path must start with path restriction.
    18791915                if ( substr( $url['path'], 0, strlen( $path ) ) != $path )
    18801916                        return false;
    … …  
    20062042        public static function compatible_gzinflate($gzData) {
    20072043
    2008                 // Compressed data might contain a full header, if so strip it for gzinflate()
     2044                // Compressed data might contain a full header, if so strip it for gzinflate().
    20092045                if ( substr($gzData, 0, 3) == "\x1f\x8b\x08" ) {
    20102046                        $i = 10;
    … …  
    20462082                $compression_enabled = WP_Http_Encoding::is_available();
    20472083
    2048                 if ( ! $args['decompress'] ) // decompression specifically disabled
     2084                if ( ! $args['decompress'] ) // Decompression specifically disabled.
    20492085                        $compression_enabled = false;
    2050                 elseif ( $args['stream'] ) // disable when streaming to file
     2086                elseif ( $args['stream'] ) // Disable when streaming to file.
    20512087                        $compression_enabled = false;
    2052                 elseif ( isset( $args['limit_response_size'] ) ) // If only partial content is being requested, we won't be able to decompress it
     2088                elseif ( isset( $args['limit_response_size'] ) ) // If only partial content is being requested, we won't be able to decompress it.
    20532089                        $compression_enabled = false;
    20542090
Note: See TracChangeset for help on using the changeset viewer.