Make WordPress Core

Ticket #5065: wp-user-agent.patch

File wp-user-agent.patch, 6.1 KB (added by docwhat, 17 years ago)

Best version - includes filter and akismet changes.

  • wp-admin/includes/update.php

     
    8282        $http_request .= "Host: api.wordpress.org\r\n";
    8383        $http_request .= "Content-Type: application/x-www-form-urlencoded; charset=" . get_option('blog_charset') . "\r\n";
    8484        $http_request .= "Content-Length: " . strlen($request) . "\r\n";
    85         $http_request .= 'User-Agent: WordPress/' . $wp_version . '; ' . get_bloginfo('url') . "\r\n";
     85        $http_request .= 'User-Agent: ' . wp_user_agent( Array( '(' . get_bloginfo('url') . ')' ) ) . "\r\n";
    8686        $http_request .= "\r\n";
    8787        $http_request .= $request;
    8888
  • wp-admin/update-links.php

     
    1818$http_request .= "Host: api.pingomatic.com\r\n";
    1919$http_request .= 'Content-Type: application/x-www-form-urlencoded; charset='.get_option('blog_charset')."\r\n";
    2020$http_request .= 'Content-Length: ' . strlen($query_string) . "\r\n";
    21 $http_request .= 'User-Agent: WordPress/' . $wp_version . "\r\n";
     21$http_request .= 'User-Agent: ' . wp_user_agent() . "\r\n";
    2222$http_request .= "\r\n";
    2323$http_request .= $query_string;
    2424
  • wp-includes/comment.php

     
    552552                return false;
    553553
    554554        // Send the GET request
    555         $request = "GET $path HTTP/1.1\r\nHost: $host\r\nUser-Agent: WordPress/$wp_version \r\n\r\n";
     555        $request = "GET $path HTTP/1.1\r\nHost: $host\r\nUser-Agent: " . wp_user_agent() . "\r\n\r\n";
    556556        // ob_end_flush();
    557557        fputs($fp, $request);
    558558
     
    778778        $http_request .= 'Host: '.$trackback_url['host']."\r\n";
    779779        $http_request .= 'Content-Type: application/x-www-form-urlencoded; charset='.get_option('blog_charset')."\r\n";
    780780        $http_request .= 'Content-Length: '.strlen($query_string)."\r\n";
    781         $http_request .= "User-Agent: WordPress/" . $wp_version;
     781        $http_request .= "User-Agent: " . wp_user_agent();
    782782        $http_request .= "\r\n\r\n";
    783783        $http_request .= $query_string;
    784784        if ( '' == $trackback_url['port'] )
  • wp-includes/functions.php

     
    529529        endforeach;
    530530}
    531531
     532/**
     533 * This function generates a User-Agent string suitable for making HTTP
     534 * requests with.
     535 * @param {Array} $extra A hash with extra key/versions to include.
     536 * @returns {String}
     537 */
     538function wp_user_agent( $extra='' ){
     539    /* Notes:
     540     * User-Agents are defined in RFC 1945 and RFC 2068.
     541     * Approximately, they may only consist of alpha-numerics and
     542     * periods and underlines.  Parenthesis enclose comments.
     543     */
     544    global $wp_version;
     545    $parts = Array("WordPress/" . $wp_version);
     546    if ( !empty($extra) ) {
     547        foreach ( $extra as $key => $version ) {
     548            if ( is_integer($key) ) {
     549                /* No key part was provided, the Array is incrementing. */
     550                array_push( $parts, $version );
     551            } elseif ( empty($version) ) {
     552                array_push( $parts, $key );
     553            } else {
     554                array_push( $parts, $key . '/' . $version );
     555            }
     556        }
     557    }
     558    return apply_filters('wp_user_agent', implode( ' ', $parts ));
     559}
     560
    532561function wp_get_http_headers( $url, $red = 1 ) {
    533562        global $wp_version;
    534563        @set_time_limit( 60 );
     
    542571        if ( !isset( $parts['port'] ) )
    543572                $parts['port'] = 80;
    544573
    545         $head = "HEAD $file HTTP/1.1\r\nHOST: $host\r\nUser-Agent: WordPress/" . $wp_version . "\r\n\r\n";
     574        $head = "HEAD $file HTTP/1.1\r\nHOST: $host\r\nUser-Agent: " . wp_user_agent() . "\r\n\r\n";
    546575
    547576        $fp = @fsockopen($host, $parts['port'], $err_num, $err_msg, 3);
    548577        if ( !$fp )
  • wp-includes/rss.php

     
    1111
    1212define('RSS', 'RSS');
    1313define('ATOM', 'Atom');
    14 define('MAGPIE_USER_AGENT', 'WordPress/' . $GLOBALS['wp_version']);
     14define('MAGPIE_USER_AGENT', wp_user_agent());
    1515
    1616class MagpieRSS {
    1717        var $parser;
     
    595595        }
    596596
    597597        if ( !defined('MAGPIE_USER_AGENT') ) {
    598                 $ua = 'WordPress/' . $GLOBALS['wp_version'];
     598                $ua = wp_user_agent();
    599599
    600600                if ( MAGPIE_CACHE_ON ) {
    601601                        $ua = $ua . ')';
     
    866866}
    867867endif;
    868868
    869 ?>
    870  No newline at end of file
     869?>
  • wp-includes/update.php

     
    2626        $http_request  = "GET /core/version-check/1.0/?version=$wp_version&php=$php_version&locale=$locale HTTP/1.0\r\n";
    2727        $http_request .= "Host: api.wordpress.org\r\n";
    2828        $http_request .= 'Content-Type: application/x-www-form-urlencoded; charset=' . get_option('blog_charset') . "\r\n";
    29         $http_request .= 'User-Agent: WordPress/' . $wp_version . '; ' . get_bloginfo('url') . "\r\n";
     29        $http_request .= 'User-Agent: ' . wp_user_agent( Array( '(' . get_bloginfo('url') . ')' ) ) . "\r\n";
    3030        $http_request .= "\r\n";
    3131
    3232        $response = '';
     
    5151
    5252add_action( 'init', 'wp_version_check' );
    5353
    54 ?>
    55  No newline at end of file
     54?>
  • wp-content/plugins/akismet/akismet.php

     
    165165        $http_request .= "Host: $host\r\n";
    166166        $http_request .= "Content-Type: application/x-www-form-urlencoded; charset=" . get_option('blog_charset') . "\r\n";
    167167        $http_request .= "Content-Length: " . strlen($request) . "\r\n";
    168         $http_request .= "User-Agent: WordPress/$wp_version | Akismet/2.0\r\n";
     168        $http_request .= "User-Agent: " . wp_user_agent( Array( 'Akismet' => '2.0') ) . "\r\n";
    169169        $http_request .= "\r\n";
    170170        $http_request .= $request;
    171171