WordPress.org

Making WordPress.org

Changeset 5963


Ignore:
Timestamp:
09/25/2017 07:09:46 PM (22 months ago)
Author:
coffee2code
Message:

Browse Happy API: Improve detection of Opera and add detection of Opera Mini.

  • Detects modern desktop Opera user-agents (previously misidentified as Chrome)
  • Detects Opera Mini user-agents
  • Fix to identify Linux as platform for Linux Opera
  • Adds more Opera-related user-agents for unit testing

TODO: Separately notify about the 12.x branch and desktop versions of Opera (the latest of which is 47), and maybe eventually Opera Mini.

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

    r5962 r5963  
    4040
    4141    if ( preg_match(
    42         '/^.+?(?P<platform>Android|iPhone|iPad|Windows|Linux|Macintosh|Windows Phone OS|RIM Tablet OS|PlayBook)(?: NT)*(?: [ix]?[0-9._]+)*(;|\))/im',
     42        '/^.+?(?P<platform>Android|iPhone|iPad|Windows|Linux|Macintosh|Windows Phone OS|RIM Tablet OS|PlayBook)(?: (NT|zvav))*(?: [ix]?[0-9._]+)*(;|\))/im',
    4343        $user_agent,
    4444        $regs
     
    5757
    5858    preg_match_all(
    59         '%(?P<name>Trident|Camino|Kindle|Firefox|(?:Mobile )?Safari|MSIE|RockMelt|AppleWebKit|Chrome|IEMobile|Opera|Version)(?:[/ ])(?P<version>[0-9.]+)%im',
     59        '%(?P<name>Opera Mini|Opera|OPR|Trident|Camino|Kindle|Firefox|(?:Mobile )?Safari|MSIE|RockMelt|AppleWebKit|Chrome|IEMobile|Version)(?:[/ ])(?P<version>[0-9.]+)%im',
    6060        $user_agent,
    6161        $result,
     
    7070    }
    7171
    72     if ( 'AppleWebKit' == $result['name'][0] ) {
     72    // Opera
     73    if (
     74        false !== ( $key = array_search( 'Opera Mini', $result['name'] ) )
     75    ||
     76        false !== ( $key = array_search( 'Opera', $result['name'] ) )
     77    ||
     78        false !== ( $key = array_search( 'OPR', $result['name'] ) )
     79    ) {
     80        $data['name'] = $result['name'][ $key ];
     81        if ( 'OPR' === $data['name'] ) {
     82            $data['name'] = 'Opera';
     83        } elseif ( 'Opera Mini' === $data['name'] ) {
     84            $data['mobile'] = true;
     85        }
     86        $data['version'] = $result['version'][ $key ];
     87    } elseif ( 'AppleWebKit' == $result['name'][0] ) {
    7388        if ( $key = array_search( 'Mobile Safari', $result['name'] ) ) {
    7489            $data['name'] = 'Mobile Safari';
     
    88103            $data['name'] = 'webkit';
    89104        }
    90         $data['version'] = $result['version'][ $key ];
    91     } elseif ( $key = array_search( 'Opera', $result['name'] ) ) {
    92         $data['name'] = $result['name'][ $key ];
    93105        $data['version'] = $result['version'][ $key ];
    94106    } elseif ( 'MSIE' == $result['name'][0] ) {
  • sites/trunk/api.wordpress.org/public_html/core/browse-happy/1.0/tests/phpunit/tests/browse-happy.php

    r5962 r5963  
    9191                'Windows Chrome 7.0.517.41',
    9292            ],
     93
     94            // Opera
     95
    9396            [
    9497                'Opera/9.80 (Windows NT 6.0; U; en) Presto/2.8.99 Version/11.10',
     
    115118                'Windows Opera 11.01',
    116119            ],
     120            [
     121                'Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.112 Safari/537.36 OPR/36.0.2130.80',
     122                'Windows Opera 36.0.2130.80',
     123            ],
     124            [
     125                'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36 OPR/43.0.2442.991',
     126                'Windows Opera 43.0.2442.991',
     127            ],
     128            [
     129                'Opera/9.80 (X11; Linux zvav; U; en) Presto/2.8.119 Version/11.10',
     130                'Linux Opera 11.10',
     131            ],
     132            [
     133                'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.87 Safari/537.36 OPR/37.0.2178.31 (Edition beta)',
     134                'Linux Opera 37.0.2178.31',
     135            ],
     136            [
     137                'Opera/9.80 (Macintosh; Intel Mac OS X 10.10.5) Presto/2.12.388 Version/12.16',
     138                'Macintosh Opera 12.16',
     139            ],
    117140            // #3161
    118141            [
     
    120143                'Windows Opera 12.18',
    121144            ],
     145
     146            // Opera Mini
     147
     148            [
     149                'Opera/9.80 (Android; Opera Mini/24.0.2254/62.178; U; en) Presto/2.12.423 Version/12.16',
     150                'Android Opera Mini 12.16',
     151            ],
     152            [
     153                'Opera/9.80 (J2ME/MIDP; Opera Mini/4.2/28.3590; U; en) Presto/2.8.119 Version/11.10',
     154                'Mobile Opera Mini 11.10',
     155            ],
     156            [
     157                'Opera/9.80 (SpreadTrum; Opera Mini/4.4.31492/66.299; U; en) Presto/2.12.423 Version/12.16',
     158                'Mobile Opera Mini 12.16',
     159            ],
     160
    122161            [
    123162                'Mozilla/5.0 (Windows; U; Windows NT 6.1; tr-TR) AppleWebKit/533.20.25 (KHTML, like Gecko) Version/5.0.4 Safari/533.20.27',
Note: See TracChangeset for help on using the changeset viewer.