Making WordPress.org


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

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

File:
1 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.
Note: See TracChangeset for help on using the changeset viewer.