WordPress.org

Making WordPress.org

Changeset 6011


Ignore:
Timestamp:
10/09/2017 05:35:09 PM (2 years ago)
Author:
coffee2code
Message:

Browse Happy API: Add support for Symbian as a platform and Ovi Browser as a browser.

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

    r6010 r6011  
    4242    // Identify platform/OS in user-agent string.
    4343    if ( preg_match(
    44         '/^.+?(?P<platform>Windows Phone( OS)?|Android|iPhone|iPad|Windows|Linux|Macintosh|RIM Tablet OS|PlayBook)(?: (NT|zvav))*(?: [ix]?[0-9._]+)*(;|\))/im',
     44        '/^.+?(?P<platform>Windows Phone( OS)?|Symbian|SymbOS|Android|iPhone|iPad|Windows|Linux|Macintosh|RIM Tablet OS|PlayBook)(?: (NT|zvav))*(?: [ix]?[0-9._]+)*(;|\))/im',
    4545        $user_agent,
    4646        $regs
     
    5151    // Find tokens of interest in user-agent string.
    5252    preg_match_all(
    53         '%(?P<name>Opera Mini|Opera|OPR|Edge|UCBrowser|UCWEB|QQBrowser|Trident|Silk|Camino|Kindle|Firefox|SamsungBrowser|(?:Mobile )?Safari|NokiaBrowser|MSIE|RockMelt|AppleWebKit|Chrome|IEMobile|Version)(?:[/ ])(?P<version>[0-9.]+)%im',
     53        '%(?P<name>Opera Mini|Opera|OPR|Edge|UCBrowser|UCWEB|QQBrowser|SymbianOS|Symbian|S40OviBrowser|Trident|Silk|Camino|Kindle|Firefox|SamsungBrowser|(?:Mobile )?Safari|NokiaBrowser|MSIE|RockMelt|AppleWebKit|Chrome|IEMobile|Version)(?:[/ ])(?P<version>[0-9.]+)%im',
    5454        $user_agent,
    5555        $result,
     
    6868    elseif ( 'Windows Phone' === $data['platform'] ) {
    6969        $data['platform'] = 'Windows Phone OS';
     70    }
     71    // Standardize Symbian OS name.
     72    elseif (
     73        in_array( $data['platform'], array( 'Symbian', 'SymbOS' ) )
     74    ||
     75        false !== ( $key = array_search( 'SymbianOS', $result['name'] ) )
     76    ||
     77        false !== ( $key = array_search( 'Symbian', $result['name'] ) )
     78    ) {
     79        if ( ! in_array( $data['platform'], array( 'Symbian', 'SymbOS' ) ) ) {
     80            unset( $result['name'][ $key ] );
     81            unset( $result['version'][ $key ] );
     82        }
     83        $data['platform'] = 'Symbian';
    7084    }
    7185    // Generically detect some mobile devices.
     
    8094
    8195    // Flag known mobile platforms as mobile.
    82     if ( in_array( $data['platform'], array( 'Android', 'Fire OS', 'iPad', 'iPhone', 'Mobile', 'PlayBook', 'RIM Tablet OS', 'Windows Phone OS' ) ) ) {
     96    if ( in_array( $data['platform'], array( 'Android', 'Fire OS', 'iPad', 'iPhone', 'Mobile', 'PlayBook', 'RIM Tablet OS', 'Symbian', 'Windows Phone OS' ) ) ) {
    8397        $data['mobile'] = true;
    8498    }
     
    217231            if ( 'Android' === $data['platform'] ) {
    218232                $data['name'] = 'Android Browser';
     233            } elseif ( 'Symbian' === $data['platform'] ) {
     234                $data['name'] = 'Nokia Browser';
     235                $result['version'][ $key ] = '';
    219236            } else {
    220237                $data['name'] = 'Safari';
     
    227244        }
    228245        $data['version'] = $result['version'][ $key ];
     246    }
     247    // Ovi Browser
     248    elseif ( false !== ( $key = array_search( 'S40OviBrowser', $result['name'] ) ) ) {
     249        $data['name']     = 'Ovi Browser';
     250        $data['version']  = $result['version'][ $key ];
     251        $data['platform'] = 'Symbian';
     252        $data['mobile']   = true;
    229253    }
    230254    // Fall back to whatever is being reported.
  • sites/trunk/api.wordpress.org/public_html/core/browse-happy/1.0/tests/phpunit/tests/browse-happy.php

    r5995 r6011  
    6363                'Android Android Browser 4.0',
    6464            ],
     65            [
     66                'Mozilla/5.0 (Linux; U; Android 4.2.2; en-us; IdeaTab S6000-F Build/JDQ39) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Safari/534.30',
     67                'Android Android Browser 4.0', // Actually: Symbian, but not worth accurately detecting.
     68            ],
    6569            [ // on Galaxy SIII
    6670                'Mozilla/5.0 (Linux; U; Android 4.4.2; en-us; SCH-I535 Build/KOT49H) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30',
     
    379383                'Mobile Nokia Browser 8.5.0',
    380384            ],
     385            [
     386                'Nokia5250/10.0.011 (SymbianOS/9.4; U; Series60/5.0 Mozilla/5.0; Profile/MIDP-2.1 Configuration/CLDC-1.1 ) AppleWebKit/525 (KHTML, like Gecko) Safari/525 3gpp-gba',
     387                'Symbian Nokia Browser',
     388            ],
     389            [
     390                'Mozilla/5.0 (SymbianOS/9.4; Series60/5.0 Nokia5233/51.1.002; Profile/MIDP-2.1 Configuration/CLDC-1.1 ) AppleWebKit/533.4 (KHTML, like Gecko) NokiaBrowser/7.3.1.33 Mobile Safari/533.4 3gpp-gba',
     391                'Symbian Nokia Browser 7.3.1.33',
     392            ],
     393            [
     394                'Mozilla/5.0 (Symbian/3; Series60/5.3 NokiaN8-00/111.040.1511; Profile/MIDP-2.1 Configuration/CLDC-1.1 ) AppleWebKit/535.1 (KHTML, like Gecko) NokiaBrowser/8.3.1.4 Mobile Safari/535.1 3gpp-gba',
     395                'Symbian Nokia Browser 8.3.1.4',
     396            ],
    381397
    382398            // Opera
     
    445461                'Mobile Opera Mini 12.16',
    446462            ],
     463            [
     464                'Opera/9.80 (J2ME/MIDP; Opera Mini/9.80 (S60; SymbOS; Opera Mobi/23.348; U; en) Presto/2.5.25 Version/10.54',
     465                'Symbian Opera Mini 10.54',
     466            ],
     467
     468            // Ovi Browser
     469
     470            [
     471                'Mozilla/5.0 (Series40; Nokia2055/03.20; Profile/MIDP-2.1 Configuration/CLDC-1.1) Gecko/20100401 S40OviBrowser/5.5.0.0.27',
     472                'Symbian Ovi Browser 5.5.0.0.27'
     473            ],
    447474
    448475            // QQ Browser
     
    568595                'Nokia5200/2.0 (05.00) Profile/MIDP-2.0 Configuration/CLDC-1.1 UCWEB/2.0 (Java; U; MIDP-2.0; id; Nokia5200) U2/1.0.0 UCBrowser/9.5.0.449 U2/1.0.0 Mobile',
    569596                'Mobile UC Browser 9.5.0.449',
     597            ],
     598            [
     599                'UCWEB/2.0 (Symbian; U; S60 V5; en-US; Nokia5233) U2/1.0.0 UCBrowser/9.2.0.336 U2/1.0.0 Mobile',
     600                'Symbian UC Browser 9.2.0.336',
    570601            ],
    571602            [
     
    682713        $parsed = browsehappy_parse_user_agent( $header );
    683714
    684         if ( in_array( $parsed['platform'], array( 'Android', 'Fire OS', 'iPad', 'iPhone', 'Mobile', 'PlayBook', 'RIM Tablet OS', 'Windows Phone OS' ) ) ) {
     715        if ( in_array( $parsed['platform'], array( 'Android', 'Fire OS', 'iPad', 'iPhone', 'Mobile', 'PlayBook', 'RIM Tablet OS', 'Symbian', 'Windows Phone OS' ) ) ) {
    685716            $this->assertTrue( $parsed['mobile'] );
    686717        } else {
Note: See TracChangeset for help on using the changeset viewer.