Ejemplo n.º 1
0
 function getHandsetInfo()
 {
     $result = array();
     if (isset($_SESSION['handsets'])) {
         $result = $_SESSION['handsets'];
     } else {
         require LIB_PATH . "Tera-WURFL/TeraWurfl.php";
         try {
             // Instantiate the Tera-WURFL object
             $wurflObj = new TeraWurfl();
             // Get the capabilities from the object
             $wurflObj->GetDeviceCapabilitiesFromAgent();
             //optionally pass the UA and HTTP_ACCEPT here
             // Print the capabilities array
             $handset = $wurflObj->capabilities;
         } catch (Exception $e) {
         }
         $result['fullname'] = $handset['product_info']['brand_name'] . ' ' . $handset['product_info']['model_name'];
         $result['id'] = $handset['id'];
         $result['user_agent'] = $handset['user_agent'];
         $result['product_info'] = $handset['product_info'];
         $_SESSION['handsets'] = $result;
         $result = $_SESSION['handsets'];
     }
     return $result;
 }
Ejemplo n.º 2
0
 public function rebuildCacheTable()
 {
     // We'll 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;
     $checkcachequery = "SHOW TABLES LIKE '{$cachetable}'";
     $checkres = $this->dbcon->query($checkcachequery);
     $this->numQueries++;
     if ($checkres->num_rows === 0) {
         // This can only happen if the table doesn't exist
         $this->createCacheTable();
         $this->numQueries++;
         // This table must be empty, so we're finished
         //			$rebuilder->toLog($query,LOG_ERR,"rebuildCacheTable");
         $rebuilder->toLog("Created empty cache table", LOG_NOTICE, "rebuildCacheTable");
         return true;
     }
     $droptemptable = "DROP TABLE IF EXISTS `{$temptable}`";
     $this->numQueries++;
     $this->dbcon->query($droptemptable);
     $query = "RENAME TABLE `{$cachetable}` TO `{$temptable}`";
     $this->numQueries++;
     $this->dbcon->query($query);
     $this->createCacheTable();
     $query = "SELECT `user_agent` FROM `{$temptable}`";
     $this->numQueries++;
     $res = $this->dbcon->query($query);
     if ($res->num_rows == 0) {
         // No records in cache table == nothing to rebuild
         $rebuilder->toLog("Rebuilt cache table, existing table was empty - this is very unusual.", LOG_WARNING, "rebuildCacheTable");
         return true;
     }
     while ($dev = $res->fetch_assoc()) {
         // Just looking the device up will force it to be cached
         $rebuilder->GetDeviceCapabilitiesFromAgent($dev['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;
     }
     $droptable = "DROP TABLE IF EXISTS `{$temptable}`";
     $this->numQueries++;
     $this->dbcon->query($droptable);
     $rebuilder->toLog("Rebuilt cache table.", LOG_NOTICE, "rebuildCacheTable");
     return true;
 }
Ejemplo n.º 3
0
<?php

/**
 * Tera_WURFL - PHP MySQL driven WURFL
 * 
 * Tera-WURFL was written by Steve Kamerman, and is based on the
 * Java WURFL Evolution package by Luca Passani and WURFL PHP Tools by Andrea Trassati.
 * This version uses a MySQL database to store the entire WURFL file, multiple patch
 * files, and a persistent caching mechanism to provide extreme performance increases.
 * 
 * @package TeraWurfl
 * @author Steve Kamerman <stevekamerman AT gmail.com>
 * @version Stable 2.1.3 $Date: 2010/09/18 15:43:21
 * @license http://www.mozilla.org/MPL/ MPL Vesion 1.1
 */
// Include the Tera-WURFL file
require_once realpath(dirname(__FILE__) . '/TeraWurfl.php');
// Instantiate the Tera-WURFL object
$wurflObj = new TeraWurfl();
// Get the capabilities from the object
$wurflObj->GetDeviceCapabilitiesFromAgent();
//optionally pass the UA and HTTP_ACCEPT here
// Print the capabilities array
echo "<pre>" . htmlspecialchars(var_export($wurflObj->capabilities, true)) . "</pre>";
 public function rebuildCacheTable()
 {
     // We'll 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->numQueries++;
     if (!$this->tableExists($cachetable)) {
         // This can only happen if the table doesn't exist
         $this->createCacheTable();
         $this->numQueries++;
         // This table must be empty, so we're finished
         $rebuilder->toLog("Created empty cache table", LOG_NOTICE, "rebuildCacheTable");
         return true;
     }
     $this->numQueries++;
     $this->dropTableIfExists($temptable);
     $this->renameTable($cachetable, $temptable);
     $this->numQueries++;
     $this->createCacheTable();
     $query = "SELECT user_agent FROM {$temptable}";
     $this->numQueries++;
     $res = sqlsrv_query($this->dbcon, $query);
     if (!sqlsrv_has_rows($res)) {
         // No records in cache table == nothing to rebuild
         $rebuilder->toLog("Rebuilt cache table, existing table was empty.", LOG_WARNING, "rebuildCacheTable");
         return true;
     }
     while ($dev = sqlsrv_fetch_array($res)) {
         // Just looking the device up will force it to be cached
         $rebuilder->GetDeviceCapabilitiesFromAgent($dev['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->numQueries++;
     $this->dropTableIfExists($temptable);
     $rebuilder->toLog("Rebuilt cache table.", LOG_NOTICE, "rebuildCacheTable");
     return true;
 }
Ejemplo n.º 5
0
  <li><pre>NokiaN90-1/3.0541.5.2 Series60/2.8 Profile/MIDP-2.0 Configuration/CLDC-1.1</pre></li>
</ul>
<hr size="1" />
<?php 
list($usec, $sec) = explode(" ", microtime());
$start = (double) $usec + (double) $sec;
// Include the Tera-WURFL file
require_once realpath(dirname(__FILE__) . '/TeraWurfl.php');
list($usec, $sec) = explode(" ", microtime());
$load_class = (double) $usec + (double) $sec;
// instantiate the Tera-WURFL object
$wurflObj = new TeraWurfl();
list($usec, $sec) = explode(" ", microtime());
$init_class = (double) $usec + (double) $sec;
// Get the capabilities from the object
$matched = $wurflObj->GetDeviceCapabilitiesFromAgent($_GET['force_ua']);
list($usec, $sec) = explode(" ", microtime());
$end = (double) $usec + (double) $sec;
echo "Time to load TeraWurfl.php:" . ($load_class - $start) . "<br>\n";
echo "Time to initialize class:" . ($init_class - $load_class) . "<br>\n";
echo "Time to find the user agent:" . ($end - $init_class) . "<br>\n";
echo "Total:" . ($end - $start) . "<br>\n";
$cached = $wurflObj->foundInCache ? "<strong>(Found in cache)</strong>" : "";
echo "<br>Total Queries: " . $wurflObj->db->numQueries . " {$cached}<br>\n";
$text = $matched ? "a conlusive" : "an <font color=\"#990000\">inconclusive</font>";
echo "<h3>Test resulted in {$text} match</h3>";
echo "<pre>";
var_export($wurflObj->capabilities);
echo "</pre>";
?>
<form action="check_wurfl.php" method="GET">