Parses the useragent for operating system information Detected operating systems can be found in self::$operatingSystems and /regexes/oss.yml This class also defined some operating system families and methods to get the family for a specific os
Inheritance: extends ParserAbstract
コード例 #1
0
ファイル: Menu.php プロジェクト: emersonmatsumoto/piwik
 private function addTopMenuMobileApp(MenuTop $menu)
 {
     if (empty($_SERVER['HTTP_USER_AGENT'])) {
         return;
     }
     if (!class_exists("DeviceDetector\\DeviceDetector")) {
         throw new \Exception("DeviceDetector could not be found, maybe you are using Piwik from git and need to update Composer. Execute this command: php composer.phar update");
     }
     $ua = new OperatingSystem($_SERVER['HTTP_USER_AGENT']);
     $ua->setCache(new DeviceDetectorCache('tracker', 86400));
     $parsedOS = $ua->parse();
     if (!empty($parsedOS['short_name']) && in_array($parsedOS['short_name'], array(self::DD_SHORT_NAME_ANDROID, self::DD_SHORT_NAME_IOS))) {
         $menu->add('Piwik Mobile App', null, array('module' => 'Proxy', 'action' => 'redirect', 'url' => 'http://piwik.org/mobile/'), true, 4);
     }
 }
コード例 #2
0
 public function getAllOs()
 {
     $allOs = array_keys(OperatingSystem::getAvailableOperatingSystems());
     $allOs = array_map(function ($os) {
         return array($os);
     }, $allOs);
     return $allOs;
 }
コード例 #3
0
ファイル: Controller.php プロジェクト: piwik/piwik
 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();
 }
コード例 #4
0
ファイル: Device.php プロジェクト: speedwork/view
 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);
 }
コード例 #5
0
 */
include __DIR__ . '/../vendor/autoload.php';
?>
## What Device Detector is able to detect

The lists below are auto generated and updated from time to time. Some of them might not be complete.

*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());
?>
コード例 #6
0
ファイル: functions.php プロジェクト: diosmosis/piwik
/**
 * Returns the path to the logo for the given OS
 *
 * First try to find a logo for the given short code
 * If none can be found try to find a logo for the os family
 * Return unknown logo otherwise
 *
 * @param string  $short  Shortcode or name of OS
 *
 * @return string  path to image
 */
function getOsLogo($short)
{
    $path = 'plugins/DevicesDetection/images/os/%s.gif';
    $short = _mapLegacyOsShortCodes($short);
    // If name is given instead of short code, try to find matching shortcode
    if (strlen($short) > 3) {
        if (in_array($short, OperatingSystemParser::getAvailableOperatingSystems())) {
            $short = array_search($short, OperatingSystemParser::getAvailableOperatingSystems());
        } else {
            $short = substr($short, 0, 3);
        }
    }
    $family = getOSFamilyFullName($short);
    $osFamilies = OperatingSystemParser::getAvailableOperatingSystemFamilies();
    if (!empty($short) && array_key_exists($short, OperatingSystemParser::getAvailableOperatingSystems()) && file_exists(PIWIK_INCLUDE_PATH . '/' . sprintf($path, $short))) {
        return sprintf($path, $short);
    } elseif (!empty($family) && array_key_exists($family, $osFamilies) && file_exists(PIWIK_INCLUDE_PATH . '/' . sprintf($path, $osFamilies[$family][0]))) {
        return sprintf($path, $osFamilies[$family][0]);
    }
    return sprintf($path, 'UNK');
}
コード例 #7
0
 /**
  * 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;
 }
コード例 #8
0
 public function getOSFamily()
 {
     return OperatingSystem::getOsFamily($this->deviceDetector->getOs('short_name'));
 }
コード例 #9
0
 public function testAllBrowsersTested()
 {
     $allBrowsers = array_keys(OperatingSystem::getAvailableOperatingSystems());
     $osNotTested = array_diff($allBrowsers, self::$osTested);
     $this->assertEmpty($osNotTested, 'Following browsers are not tested: ' . implode(', ', $osNotTested));
 }