Пример #1
0
 function onDeviceDetection(&$MobileJoomla_Settings, &$MobileJoomla_Device)
 {
     if ($MobileJoomla_Device['markup'] !== false) {
         return;
     }
     require_once dirname(__FILE__) . '/amdd/config.php';
     $cache = (bool) $this->params->get('cache', 1);
     $cachesize = (int) $this->params->get('cachesize', 1000);
     AmddConfig::$cacheSize = $cache ? $cachesize : 0;
     require_once dirname(__FILE__) . '/amdd/amdd.php';
     try {
         $amddObj = Amdd::getCapabilities();
         if (!is_object($amddObj)) {
             return;
         }
     } catch (AmddDatabaseException $e) {
         error_log("Caught exception 'Exception' with message '" . $e->getMessage() . "' in " . $e->getFile() . ':' . $e->getLine());
         return;
     }
     $MobileJoomla_Device['amdd'] = $amddObj;
     switch ($amddObj->markup) {
         case 'tv':
         case 'gametv':
             $MobileJoomla_Device['markup'] = '';
             break;
         case 'gameport':
             $MobileJoomla_Device['markup'] = 'xhtml';
             break;
         default:
             $MobileJoomla_Device['markup'] = $amddObj->markup;
     }
     if (isset($amddObj->screenWidth)) {
         $MobileJoomla_Device['screenwidth'] = $amddObj->screenWidth;
     }
     if (isset($amddObj->screenHeight)) {
         $MobileJoomla_Device['screenheight'] = $amddObj->screenHeight;
     }
     if (isset($amddObj->imageFormats)) {
         $MobileJoomla_Device['imageformats'] = $amddObj->imageFormats;
     }
 }
Пример #2
0
 private static function getDevice($ua, $exact = false)
 {
     $db = AmddDatabase::getInstance(AmddConfig::$dbHandlerName);
     self::$matchType = 2;
     // load matched device
     $data = $db->getDevice($ua);
     if ($data !== null) {
         return $data;
     }
     if ($exact) {
         return null;
     }
     // fast test for bots and desktop browsers
     $group = AmddUA::getGroup($ua);
     if ($group === 'bot') {
         return null;
     }
     // load device from cache
     if (AmddConfig::$cacheSize != 0) {
         self::$matchType = 3;
         $data = $db->getDeviceFromCache($ua);
         if ($data !== null) {
             return empty($data) ? null : $data;
         }
     }
     // find closest device
     $devices = $db->getDevices($group);
     if (preg_match('#^(Mozilla|Opera|NetFront)/#', $ua)) {
         self::$matchType = 5;
         $data = self::findByLevenshtein($ua, $devices);
         if ($data === null) {
             $pos = strpos($ua, ')');
             if (!$pos) {
                 $pos = strlen($ua);
             }
             self::$matchType = 4;
             $data = self::findByPrefix($ua, $devices, $pos);
         }
     } else {
         preg_match('#^(DoCoMo|portalmmm)/.*?(\\(|$)#', $ua, $match) or preg_match('#^.{5,}?[ /]#', $ua, $match);
         $pos = isset($match[0]) ? strlen($match[0]) : strlen($ua);
         self::$matchType = 4;
         $data = self::findByPrefix($ua, $devices, $pos);
         if ($data === null) {
             self::$matchType = 5;
             $data = self::findByLevenshtein($ua, $devices);
         }
     }
     // save to cache
     $db->putDeviceToCache($ua, empty($data) ? '' : $data, AmddConfig::$cacheSize);
     return $data;
 }