/** * Get the key capabilities of the device * @return associative array of the capabilities */ public function getKeyCapabilities() { if (!$this->keyCapabilitiesAreSet) { if ($this->teraWurflObject->getDeviceCapabilitiesFromAgent()) { foreach ($this->keyCapabilities as $key => $value) { $this->keyCapabilities[$key] = $this->teraWurflObject->getDeviceCapability($key); } } $this->keyCapabilitiesAreSet = TRUE; } return $this->keyCapabilities; }
<!DOCTYPE html> <html lang='en'> <?php $pageTitle = 'tera_wurfl raw demo'; require_once 'Tera-Wurfl/wurfl-dbapi/TeraWurfl.php'; $wurflObj = new TeraWurfl(); $wurflObj->getDeviceCapabilitiesFromAgent(); ?> <head> <title><?php print $pageTitle; ?> </title> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <link rel="stylesheet" type="text/css" href="../../css/allDevices.css" /> <link rel="stylesheet" type="text/css" href="../../css/mediaQueries.css" /> <!--[if IE]> <link rel="stylesheet" type="text/css" href="../../css/device/explorer.css" media="all" /> <![endif]--> </head> <body> <div id="container"> <h2><?php print $pageTitle; ?> </h2> <div id="content"> <h3>Raw Demo Results:</h3>
/** * @return boolean */ public function rebuildCacheTable() { // Use this instance to rebuild the cache and to facilitate logging $rebuilder = new TeraWurfl(); $cachetable = TeraWurflConfig::$TABLE_PREFIX . 'Cache'; $temptable = TeraWurflConfig::$TABLE_PREFIX . 'Cache' . self::$DB_TEMP_EXT; $this->_dropCollectionIfExists($temptable); $this->_renameCollection($cachetable, $temptable); $this->createCacheTable(); $tempcoll = $this->dbcon->selectCollection($temptable); $cachecoll = $this->dbcon->selectCollection($cachetable); /* @var $fromcache MongoCursor */ $fromcache = $tempcoll->find(array(), array("user_agent" => 1)); $this->numQueries++; // migrate cached items from old cache if (0 == $fromcache->count()) { // No records in cache table == nothing to rebuild $this->_dropCollectionIfExists($temptable); $rebuilder->toLog('Rebuilt cache table, existing table was empty - this is very unusual.', LOG_WARNING, __FUNCTION__); return true; } foreach ($fromcache as $item) { // Just looking the device up will force it to be cached $rebuilder->getDeviceCapabilitiesFromAgent($item['user_agent']); // Reset the number of queries since we're not going to re-instantiate the object $this->numQueries += $rebuilder->db->numQueries; $rebuilder->db->numQueries = 0; } $this->_dropCollectionIfExists($temptable); $rebuilder->toLog('Rebuilt cache table.', LOG_NOTICE, __FUNCTION__); return true; }
public function dispatchLoopStartup(Zend_Controller_Request_Abstract $request) { $tw = new TeraWurfl(); $tw->getDeviceCapabilitiesFromAgent($request->getHeader('User-Agent')); Zend_Registry::set('twurfl', $tw); }
protected function actionDebug(TeraWurflCLIArgument $arg) { switch ($arg->value) { case "constIDgrouped": $matcherList = WurflConstants::$matchers; foreach ($matcherList as $matcher) { $matcherClass = $matcher . "UserAgentMatcher"; $file = $this->wurfl->rootdir . "UserAgentMatchers/{$matcherClass}.php"; require_once $file; $properties = get_class_vars($matcherClass); if (empty($properties['constantIDs'])) { continue; } echo "\n{$matcherClass}\n\t" . implode("\n\t", $properties['constantIDs']); } break; case "constIDunique": $matcherList = WurflConstants::$matchers; $ids = array(); foreach ($matcherList as $matcher) { $matcherClass = $matcher . "UserAgentMatcher"; $file = $this->wurfl->rootdir . "UserAgentMatchers/{$matcherClass}.php"; require_once $file; $properties = get_class_vars($matcherClass); $ids = array_merge($ids, $properties['constantIDs']); } $ids = array_unique($ids); sort($ids); echo implode("\n", $ids); break; case "constIDsanity": $matcherList = WurflConstants::$matchers; $errors = 0; foreach ($matcherList as $matcher) { $matcherClass = $matcher . "UserAgentMatcher"; $file = $this->wurfl->rootdir . "UserAgentMatchers/{$matcherClass}.php"; require_once $file; $properties = get_class_vars($matcherClass); if (empty($properties['constantIDs'])) { continue; } foreach ($properties['constantIDs'] as $key => $value) { $deviceID = is_null($value) ? $key : $value; try { $this->wurfl->db->getDeviceFromID($deviceID); } catch (Exception $e) { $errors++; echo "Error: {$matcherClass} references an invalid WURFL ID: {$deviceID}\n"; } } } if ($errors === 0) { echo "Done. No errors detected.\n"; } else { echo "Done. {$errors} error(s) detected.\n"; } break; case "createProcs": echo "Recreating Procedures.\n"; $this->wurfl->db->createProcedures(); echo "Done.\n"; break; case "benchmark": $quiet = true; case "batchLookup": if (!isset($quiet)) { $quiet = false; } $fh = fopen($this->arguments->file->value, 'r'); $i = 0; $start = microtime(true); while (($ua = fgets($fh, 258)) !== false) { $ua = rtrim($ua); $this->wurfl->getDeviceCapabilitiesFromAgent($ua); if (!$quiet) { echo $ua . "\n"; echo $this->wurfl->capabilities['id'] . ": " . $this->wurfl->capabilities['product_info']['brand_name'] . " " . $this->wurfl->capabilities['product_info']['model_name'] . "\n\n"; } $i++; } fclose($fh); $duration = microtime(true) - $start; $speed = round($i / $duration, 2); echo "--------------------------\n"; echo "Tested {$i} devices in {$duration} sec ({$speed}/sec)\n"; if (!$quiet) { echo "*printing the UAs is very time-consuming, use --debug=benchmark for accurate speed testing\n"; } break; case "batchLookupUndetected": $fh = fopen($this->arguments->file->value, 'r'); $i = 0; $start = microtime(true); while (($line = fgets($fh, 1024)) !== false) { if (strpos($line, "\t") !== false) { list($ua, $uaprof) = @explode("\t", $line); } else { $ua = rtrim($line); } $this->wurfl->getDeviceCapabilitiesFromAgent($ua); $m = $this->wurfl->capabilities['tera_wurfl']['match_type']; if ($m == 'recovery' || $m == 'none') { echo $line; } $i++; } fclose($fh); $duration = microtime(true) - $start; $speed = round($i / $duration, 2); echo "--------------------------\n"; echo "Tested {$i} devices in {$duration} sec ({$speed}/sec)\n"; break; case "batchLookupFallback": $ids = file($this->arguments->file->value, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); foreach ($ids as $id) { $fallback = array(); if ($this->wurfl->db->db_implements_fallback) { $tree = $this->wurfl->db->getDeviceFallBackTree($id); foreach ($tree as $node) { $fallback[] = $node['id']; } } else { die("Unsupported on this platform\n"); } echo implode(', ', $fallback) . "\n"; } break; case "dumpBuckets": echo "Database API v{$this->wurfl->release_version}; " . $this->wurfl->getSetting(TeraWurfl::$SETTING_WURFL_VERSION) . "\n"; $this->wurfl->dumpBuckets(); break; } }
echo "Recreating Procedures.\n"; $base->db->createProcedures(); echo "Done.\n"; break; case "benchmark": $quiet = true; case "batchLookup": if (!isset($quiet)) { $quiet = false; } $fh = fopen($args['file'], 'r'); $i = 0; $start = microtime(true); while (($ua = fgets($fh, 258)) !== false) { $ua = rtrim($ua); $base->getDeviceCapabilitiesFromAgent($ua); if (!$quiet) { echo $ua . "\n"; echo $base->capabilities['id'] . ": " . $base->capabilities['product_info']['brand_name'] . " " . $base->capabilities['product_info']['model_name'] . "\n\n"; } $i++; } fclose($fh); $duration = microtime(true) - $start; $speed = round($i / $duration, 2); echo "--------------------------\n"; echo "Tested {$i} devices in {$duration} sec ({$speed}/sec)\n"; if (!$quiet) { echo "*printing the UAs is very time-consuming, use --debug=benchmark for accurate speed testing\n"; } break;
/** * Methods checks the database and performs an initial setup of it. * * @return boolean */ protected function checkDatabase() { try { $wurfl = new TeraWurfl(); $wurfl->getDeviceCapabilitiesFromAgent(null, null); return true; } catch (Exception $e) { $content = $this->getContentHead(); $content .= t3lib_div::makeInstance('t3lib_FlashMessage', 'No valid WURFL database found. An initial import has to be done.', 'Error', t3lib_FlashMessage::ERROR)->render(); // Use download url from extension configuration $extConf = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['contexts_wurfl']); $downloadUrl = $extConf['remoteRepository']; $content .= <<<HTML <div class="wurfl-module"> <div>Location: {$downloadUrl}</div> <div><em>The download url can be configured in the "contexts_wurfl" extension configuration.</em></div> <div style="margin: 20px 0px;"> HTML; $content .= t3lib_div::makeInstance('t3lib_FlashMessage', 'Be patient the initial import may take some time.', 'Info', t3lib_FlashMessage::INFO)->render(); $content .= <<<HTML </div> <input type="submit" name="cmd[updateDatabase]" value="Perform initial import" /> </div> HTML; $content .= $this->performDatabaseUpdate(true); $this->content .= $this->doc->section('Initial WURFL setup:', $content, false, true); } return false; }