WordPress.org

Making WordPress.org


Ignore:
Timestamp:
10/02/2017 03:53:11 PM (4 years ago)
Author:
coffee2code
Message:

Browse Happy API: Add support for Amazon Silk as a browser and Fire OS as a platform.

  • Adds Amazon Silk as a recognized browser
  • Changes existing "Kindle" to "Kindle Browser"
  • Removes hacky override that set Kindle's platform to "Kindle"
  • Attributes Amazon Silk and Kindle Browser to Fire OS platform
  • Omits version number from Kindle Browser
  • Updates existing Kindle unit tests to reflect these changes
File:
1 edited

Legend:

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

    r5980 r5984  
    4949    // Properly set platform if Android is actually being reported.
    5050    if ( 'Linux' === $data['platform'] && false !== strpos( $user_agent, 'Android' ) ) {
    51         $data['platform'] = 'Android';
     51        if ( strpos( $user_agent, 'Kindle' ) ) {
     52            $data['platform'] = 'Fire OS';
     53        } else {
     54            $data['platform'] = 'Android';
     55        }
    5256    } elseif ( 'Windows Phone' === $data['platform'] ) {
    5357        $data['platform'] = 'Windows Phone OS';
    5458    }
    5559
    56     if ( in_array( $data['platform'], array( 'Android', 'iPad', 'iPhone', 'PlayBook', 'RIM Tablet OS', 'Windows Phone OS' ) ) ) {
     60    if ( in_array( $data['platform'], array( 'Android', 'Fire OS', 'iPad', 'iPhone', 'PlayBook', 'RIM Tablet OS', 'Windows Phone OS' ) ) ) {
    5761        $data['mobile'] = true;
    5862    }
    5963
    6064    preg_match_all(
    61         '%(?P<name>Opera Mini|Opera|OPR|Edge|Trident|Camino|Kindle|Firefox|(?:Mobile )?Safari|NokiaBrowser|MSIE|RockMelt|AppleWebKit|Chrome|IEMobile|Version)(?:[/ ])(?P<version>[0-9.]+)%im',
     65        '%(?P<name>Opera Mini|Opera|OPR|Edge|Trident|Silk|Camino|Kindle|Firefox|(?:Mobile )?Safari|NokiaBrowser|MSIE|RockMelt|AppleWebKit|Chrome|IEMobile|Version)(?:[/ ])(?P<version>[0-9.]+)%im',
    6266        $user_agent,
    6367        $result,
     
    9397    }
    9498    // Nokia Browser
    95     elseif ( $key = array_search( 'NokiaBrowser', $result['name'] ) ) {
     99    elseif ( false !== ( $key = array_search( 'NokiaBrowser', $result['name'] ) ) ) {
    96100        $data['name']     = 'Nokia Browser';
    97101        $data['version']  = $result['version'][ $key ];
    98102        $data['mobile']   = true;
    99     } elseif ( 'AppleWebKit' == $result['name'][0] ) {
     103    }
     104    // Amazon Silk
     105    elseif ( false !== ( $key = array_search( 'Silk', $result['name'] ) ) ) {
     106        $data['name']     = 'Amazon Silk';
     107        $data['version']  = $result['version'][ $key ];
     108        $version          = '';
     109    }
     110    // Kindle Browser
     111    elseif ( false !== ( $key = array_search( 'Kindle', $result['name'] ) ) ) {
     112        $data['name']     = 'Kindle Browser';
     113        $data['version']  = $result['version'][ $key ];
     114    }
     115    // AppleWebKit-emulating browsers
     116    elseif ( 'AppleWebKit' == $result['name'][0] ) {
    100117        if ( $key = array_search( 'Edge', $result['name'] ) ) {
    101118            $data['name'] = 'Microsoft Edge';
     
    106123            } elseif ( 'Android' === $data['platform'] ) {
    107124                $data['name'] = 'Android Browser';
     125            } elseif ( 'Fire OS' === $data['platform'] ) {
     126                $data['name'] = 'Kindle Browser';
    108127            } else {
    109128                $data['name'] = 'Mobile Safari';
     
    117136        } elseif ( ! empty( $data['platform'] ) && 'PlayBook' == $data['platform'] ) {
    118137            $data['name'] = 'PlayBook';
    119         } elseif ( $key = array_search( 'Kindle', $result['name'] ) ) {
    120             $data['name'] = 'Kindle';
    121138        } elseif ( $key = array_search( 'Safari', $result['name'] ) ) {
    122139            if ( 'Android' === $data['platform'] ) {
     
    155172    }
    156173
    157     if ( in_array( $data['name'], array( 'Kindle' ) ) ) {
    158         $data['platform'] = $data['name'];
     174    // Set the platform for Amazon-related browsers.
     175    if ( in_array( $data['name'], array( 'Amazon Silk', 'Kindle Browser' ) ) ) {
     176        $data['platform'] = 'Fire OS';
     177        $data['mobile']   = true;
    159178    }
    160179
Note: See TracChangeset for help on using the changeset viewer.