/** * * @param DeviceDetector $dd * * @return bool */ private function hasResult(DeviceDetector $dd) { if ($dd->isBot() === true) { return true; } $client = $dd->getClient(); if (isset($client['name']) && $this->isRealResult($client['name'])) { return true; } $os = $dd->getOs(); if (isset($os['name']) && $this->isRealResult($os['name'])) { return true; } if ($dd->getDevice() !== null) { return true; } return false; }
/** * Information about client requesting * cache base on user agent + client ip */ public function getClientInfo($userAgent = '') { if ($this->clientInfo) { return $this->clientInfo; } $userAgent = $userAgent ? $userAgent : @$_SERVER['HTTP_USER_AGENT']; $UAHash = $this->makeUserAgentHash($userAgent); $cacheKey = "ClientInfo:{$UAHash}"; $fromCache = RedisHelper::get($cacheKey); if (!$fromCache) { DeviceParserAbstract::setVersionTruncation(DeviceParserAbstract::VERSION_TRUNCATION_NONE); $dd = new DeviceDetector($userAgent); // OPTIONAL: If called, getBot() will only return true if a bot was detected (speeds up detection a bit) $dd->discardBotInformation(); $dd->parse(); if ($dd->isBot()) { // handle bots,spiders,crawlers,... // $clientInfo = $dd->getBot(); return false; } else { $clientInfo['client'] = $dd->getClient(); // holds information about browser, feed reader, media player, ... $clientInfo['os'] = $dd->getOs(); $clientInfo['device'] = $dd->getDevice(); $clientInfo['brand'] = $dd->getBrand(); $clientInfo['model'] = $dd->getModel(); $piwik = new Common(); $clientInfo['client']['browser_language'] = $piwik::getBrowserLanguage(); } RedisHelper::set($cacheKey, json_encode($clientInfo), Config::get('cache_time.defaultCacheTimeInSeconds')); } else { $clientInfo = json_decode($fromCache, 1); } $this->clientInfo = $clientInfo; return $clientInfo; }
<?php require_once 'vendor/autoload.php'; use DeviceDetector\DeviceDetector; $userAgent = $argv[1]; $dd = new DeviceDetector($userAgent); $dd->parse(); if ($dd->isBot()) { var_dump($botInfo = $dd->getBot()); } else { $clientInfo = $dd->getClient(); // holds information about browser, feed reader, media player, ... $osInfo = $dd->getOs(); $device = $dd->getDevice(); $brand = $dd->getBrand(); $model = $dd->getModel(); var_dump($clientInfo, $osInfo, $device, $brand, $model); }