WordPress.org

Making WordPress.org

Changeset 5988


Ignore:
Timestamp:
10/02/2017 07:39:32 PM (2 years ago)
Author:
coffee2code
Message:

Browse Happy API: Improve indentification of BlackBerry, Nokia, and Sony Ericsson devices generically as mobile devices if platform not otherwise known.

Location:
sites/trunk/api.wordpress.org/public_html/core/browse-happy/1.0
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/api.wordpress.org/public_html/core/browse-happy/1.0/parse.php

    r5986 r5988  
    3838        'mobile'          => false,
    3939    );
     40    $mobile_device = '';
    4041
    4142    if ( preg_match(
     
    5455            $data['platform'] = 'Android';
    5556        }
    56     } elseif ( 'Windows Phone' === $data['platform'] ) {
     57    }
     58    // Normalize Windows Phone OS name when "OS" is omitted.
     59    elseif ( 'Windows Phone' === $data['platform'] ) {
    5760        $data['platform'] = 'Windows Phone OS';
    5861    }
    59 
    60     if ( in_array( $data['platform'], array( 'Android', 'Fire OS', 'iPad', 'iPhone', 'PlayBook', 'RIM Tablet OS', 'Windows Phone OS' ) ) ) {
     62    // Generically detect some mobile devices.
     63    elseif (
     64        ! $data['platform']
     65    &&
     66        preg_match( '/BlackBerry|Nokia|SonyEricsson/', $user_agent, $matches )
     67    ) {
     68        $data['platform'] = 'Mobile';
     69        $mobile_device    = $matches[0];
     70    }
     71
     72    // Flag known mobile platforms as mobile.
     73    if ( in_array( $data['platform'], array( 'Android', 'Fire OS', 'iPad', 'iPhone', 'Mobile', 'PlayBook', 'RIM Tablet OS', 'Windows Phone OS' ) ) ) {
    6174        $data['mobile'] = true;
    6275    }
     
    146159            $data['name'] = 'unknown';
    147160            $result['version'][ $key ] = '';
     161            $version = '';
    148162        }
    149163        $data['version'] = $result['version'][ $key ];
  • sites/trunk/api.wordpress.org/public_html/core/browse-happy/1.0/tests/phpunit/tests/browse-happy.php

    r5986 r5988  
    516516            ],
    517517            [
     518                'BlackBerry; U; Blackberry 9900; en',
     519                'Mobile unknown',
     520            ],
     521            [
     522                'BlackBerry8520/5.0.0.592 Profile/MIDP-2.1 Configuration/CLDC-1.1 VendorID/168',
     523                'Mobile unknown',
     524            ],
     525            [
    518526                'Nokia-MIT-Browser/3.0',
    519                 'unknown', // It's really a Nokia Browser, but not critical to recognize as such.
     527                'Mobile unknown', // It's really a Nokia Browser, but not critical to recognize as such.
     528            ],
     529            [
     530                'SonyEricssonW995a/R1GB Browser/NetFront/3.4 Profile/MIDP-2.1 Configuration/CLDC-1.1 JavaPlatform/JP-8.4.4',
     531                'Mobile unknown',
    520532            ],
    521533
Note: See TracChangeset for help on using the changeset viewer.