Client parser for browser detection
Inheritance: extends DeviceDetector\Parser\Client\ClientParserAbstract
Example #1
0
 public function showList()
 {
     Piwik::checkUserHasSomeAdminAccess();
     $view = new View('@DevicesDetection/list');
     $type = Common::getRequestVar('type', 'brands', 'string');
     $list = array();
     switch ($type) {
         case 'brands':
             $availableBrands = \DeviceDetector\Parser\Device\DeviceParserAbstract::$deviceBrands;
             foreach ($availableBrands as $short => $name) {
                 if ($name != 'Unknown') {
                     $list[$name] = getBrandLogo($name);
                 }
             }
             break;
         case 'browsers':
             $availableBrowsers = \DeviceDetector\Parser\Client\Browser::getAvailableBrowsers();
             foreach ($availableBrowsers as $short => $name) {
                 $list[$name] = getBrowserLogo($short);
             }
             break;
         case 'browserfamilies':
             $availableBrowserFamilies = \DeviceDetector\Parser\Client\Browser::getAvailableBrowserFamilies();
             foreach ($availableBrowserFamilies as $name => $browsers) {
                 $list[$name] = getBrowserFamilyLogo($name);
             }
             break;
         case 'os':
             $availableOSs = \DeviceDetector\Parser\OperatingSystem::getAvailableOperatingSystems();
             foreach ($availableOSs as $short => $name) {
                 $list[$name] = getOsLogo($short);
             }
             break;
         case 'osfamilies':
             $osFamilies = \DeviceDetector\Parser\OperatingSystem::getAvailableOperatingSystemFamilies();
             foreach ($osFamilies as $name => $oss) {
                 $list[$name] = getOsFamilyLogo($name);
             }
             break;
         case 'devicetypes':
             $deviceTypes = \DeviceDetector\Parser\Device\DeviceParserAbstract::getAvailableDeviceTypes();
             foreach ($deviceTypes as $name => $id) {
                 $list[$name] = getDeviceTypeLogo($name);
             }
             break;
     }
     $view->itemList = $list;
     return $view->render();
 }
Example #2
0
 public function detect($userAgent = null, $advanced = false)
 {
     $userAgent = $userAgent ?: env('HTTP_USER_AGENT');
     DeviceParserAbstract::setVersionTruncation(DeviceParserAbstract::VERSION_TRUNCATION_NONE);
     $detect = new DeviceDetector($userAgent);
     $detect->parse();
     $return = [];
     if ($detect->isBot()) {
         $return['bot'] = $detect->getBot();
         return $return;
     }
     //device wrapper
     $devicelist = ['desktop' => 'computer', 'smartphone' => 'phone', 'tablet' => 'tablet', 'feature phone' => 'phone'];
     $os = $detect->getOs();
     $client = $detect->getClient();
     $devicename = $detect->getDeviceName();
     $devicetype = isset($devicelist[$devicename]) ? $devicelist[$devicename] : 'computer';
     //legacy params
     $return['device'] = $devicename;
     $return['type'] = $devicetype;
     $return['brand'] = $detect->getBrandName();
     $return['os'] = $os['name'];
     $return['os_version'] = $os['version'];
     $return['os_code'] = $os['short_name'];
     $return['browser'] = $client['name'];
     $return['browser_version'] = $client['version'];
     $return['browser_code'] = $client['short_name'];
     $return['browser_type'] = $client['type'];
     $return['browser_engine'] = $client['engine'];
     if (!$advanced) {
         return array_map('trim', $return);
     }
     //advanced params
     $osFamily = OperatingSystem::getOsFamily($os['short_name']);
     $return['os_family'] = $osFamily !== false ? $osFamily : 'Unknown';
     $return['model'] = $detect->getModel();
     $browserFamily = Browser::getBrowserFamily($client['short_name']);
     $return['browser_family'] = $browserFamily !== false ? $browserFamily : 'Unknown';
     $touch = $detect->isTouchEnabled();
     $return['touch'] = $touch[0];
     unset($os, $client, $osFamily, $browserFamily, $touch);
     return array_map('trim', $return);
 }
Example #3
0
/**
 * Returns the path to the logo for the given browser
 *
 * First try to find a logo for the given short code
 * If none can be found try to find a logo for the browser family
 * Return unkown logo otherwise
 *
 * @param string  $short  Shortcode or name of browser
 *
 * @return string  path to image
 */
function getBrowserLogoExtended($short)
{
    $path = 'plugins/UserSettings/images/browsers/%s.gif';
    // If name is given instead of short code, try to find matching shortcode
    if (strlen($short) > 2) {
        if (in_array($short, BrowserParser::getAvailableBrowsers())) {
            $flippedBrowsers = array_flip(BrowserParser::getAvailableBrowsers());
            $short = $flippedBrowsers[$short];
        } else {
            $short = substr($short, 0, 2);
        }
    }
    $family = getBrowserFamilyFullNameExtended($short);
    $browserFamilies = BrowserParser::getAvailableBrowserFamilies();
    if (!empty($short) && array_key_exists($short, BrowserParser::getAvailableBrowsers()) && file_exists(PIWIK_INCLUDE_PATH . '/' . sprintf($path, $short))) {
        return sprintf($path, $short);
    } elseif (!empty($short) && array_key_exists($family, $browserFamilies) && file_exists(PIWIK_INCLUDE_PATH . '/' . sprintf($path, $browserFamilies[$family][0]))) {
        return sprintf($path, $browserFamilies[$family][0]);
    }
    return sprintf($path, 'UNK');
}
*Last update: <?php 
echo date('Y/m/d');
?>
*

### List of detected operating systems:

<?php 
echo implode(', ', \DeviceDetector\Parser\OperatingSystem::getAvailableOperatingSystems());
?>


### List of detected browsers:

<?php 
echo implode(', ', \DeviceDetector\Parser\Client\Browser::getAvailableBrowsers());
?>


### List of detected browser engines:

<?php 
echo implode(', ', \DeviceDetector\Parser\Client\Browser\Engine::getAvailableEngines());
?>


### List of detected libraries:

<?php 
echo implode(', ', \DeviceDetector\Parser\Client\Library::getAvailableClients());
?>
 /**
  * Parses a useragent and returns the detected data
  *
  * ATTENTION: Use that method only for testing or very small applications
  * To get fast results from DeviceDetector you need to make your own implementation,
  * that should use one of the caching mechanisms. See README.md for more information.
  *
  * @internal
  * @deprecated
  *
  * @param string $ua UserAgent to parse
  *
  * @return array
  */
 public static function getInfoFromUserAgent($ua)
 {
     $deviceDetector = new DeviceDetector($ua);
     $deviceDetector->parse();
     if ($deviceDetector->isBot()) {
         return array('user_agent' => $deviceDetector->getUserAgent(), 'bot' => $deviceDetector->getBot());
     }
     $osFamily = OperatingSystem::getOsFamily($deviceDetector->getOs('short_name'));
     $browserFamily = \DeviceDetector\Parser\Client\Browser::getBrowserFamily($deviceDetector->getClient('short_name'));
     $processed = array('user_agent' => $deviceDetector->getUserAgent(), 'os' => $deviceDetector->getOs(), 'client' => $deviceDetector->getClient(), 'device' => array('type' => $deviceDetector->getDeviceName(), 'brand' => $deviceDetector->getBrand(), 'model' => $deviceDetector->getModel()), 'os_family' => $osFamily !== false ? $osFamily : 'Unknown', 'browser_family' => $browserFamily !== false ? $browserFamily : 'Unknown');
     return $processed;
 }
 public function getBrowserFamily()
 {
     return Browser::getBrowserFamily($this->deviceDetector->getClient('short_name'));
 }
 public function testGetAvailableClients()
 {
     $available = Browser::getAvailableClients();
     $this->assertGreaterThan(count($available), count(Browser::getAvailableBrowsers()));
 }