Exemple #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;
 }
Exemple #2
0
 /**
  * Get features from request
  *
  * @param  array $request $_SERVER variable
  * @return array
  */
 public static function getFromRequest($request, array $config)
 {
     if (!class_exists('TeraWurfl')) {
         // If TeraWurfl class not found, see if we can load it from
         // configuration
         //
         if (!isset($config['terawurfl'])) {
             // No configuration
             require_once 'Zend/Http/UserAgent/Features/Exception.php';
             throw new Zend_Http_UserAgent_Features_Exception('"TeraWurfl" configuration is not defined');
         }
         $config = $config['terawurfl'];
         if (empty($config['terawurfl_lib_dir'])) {
             // No lib_dir given
             require_once 'Zend/Http/UserAgent/Features/Exception.php';
             throw new Zend_Http_UserAgent_Features_Exception('The "terawurfl_lib_dir" parameter is not defined');
         }
         // Include the Tera-WURFL file
         require_once $config['terawurfl_lib_dir'] . '/TeraWurfl.php';
     }
     // instantiate the Tera-WURFL object
     $wurflObj = new TeraWurfl();
     // Get the capabilities of the current client.
     $matched = $wurflObj->getDeviceCapabilitiesFromRequest(array_change_key_case($request, CASE_UPPER));
     return self::getAllCapabilities($wurflObj);
 }
 /**
  * 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;
 }
 protected function actionBucket()
 {
     header('Content-Type: text/plain');
     echo "Database API v{$this->wurfl->release_version}; " . $this->wurfl->getSetting(TeraWurfl::$SETTING_WURFL_VERSION) . "\n";
     $this->wurfl->dumpBuckets();
     exit;
 }
Exemple #5
0
require_once realpath(dirname(__FILE__) . '/../TeraWurfl.php');
require_once realpath(dirname(__FILE__) . '/../TeraWurflLoader.php');
require_once realpath(dirname(__FILE__) . '/../TeraWurflXMLParsers/TeraWurflXMLParser.php');
require_once realpath(dirname(__FILE__) . '/../TeraWurflXMLParsers/TeraWurflXMLParser_XMLReader.php');
require_once realpath(dirname(__FILE__) . '/../TeraWurflXMLParsers/TeraWurflXMLParser_SimpleXML.php');
@ini_set("display_errors", "on");
error_reporting(E_ALL);
if (TeraWurflConfig::$OVERRIDE_MEMORY_LIMIT) {
    ini_set("memory_limit", TeraWurflConfig::$MEMORY_LIMIT);
}
/**
 * Set the script time limit (default: 20 minutes)
 */
set_time_limit(60 * 20);
$source = isset($_GET['source']) ? $_GET['source'] : "local";
$base = new TeraWurfl();
if ($base->db->connected !== true) {
    throw new Exception("Cannot connect to database: " . $base->db->errors[0]);
}
if (isset($_GET['action']) && $_GET['action'] == 'rebuildCache') {
    $base->db->rebuildCacheTable();
    header("Location: index.php?msg=" . urlencode("The cache has been successfully rebuilt ({$base->db->numQueries} queries).") . "&severity=notice");
    exit(0);
}
if (isset($_GET['action']) && $_GET['action'] == 'clearCache') {
    $base->db->createCacheTable();
    header("Location: index.php?msg=" . urlencode("The cache has been successfully cleared ({$base->db->numQueries} queries).") . "&severity=notice");
    exit(0);
}
$newfile = TeraWurfl::absoluteDataDir() . TeraWurflConfig::$WURFL_FILE . ".zip";
$wurflfile = TeraWurfl::absoluteDataDir() . TeraWurflConfig::$WURFL_FILE;
 /**
  * @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;
 }
Exemple #7
0
 public function dispatchLoopStartup(Zend_Controller_Request_Abstract $request)
 {
     $tw = new TeraWurfl();
     $tw->getDeviceCapabilitiesFromAgent($request->getHeader('User-Agent'));
     Zend_Registry::set('twurfl', $tw);
 }
 /**
  * Loads the patch files from TeraWurflConfig::PATCH_FILE
  * @return bool Success
  */
 public function loadPatches()
 {
     if (!TeraWurflConfig::$PATCH_ENABLE) {
         return true;
     }
     $this->timepatch = microtime(true);
     // Explode the patchfile string into an array of patch files (normally just one file)
     $patches = explode(';', TeraWurflConfig::$PATCH_FILE);
     foreach ($patches as $patch) {
         $patch_devices = array();
         $this->wurfl->toLog("Loading patch: " . $patch, LOG_WARNING);
         $patch_parser = TeraWurflXMLParser::getInstance();
         $patch_parser->open(TeraWurfl::absoluteDataDir() . $patch, TeraWurflXMLParser::$TYPE_PATCH);
         $patch_parser->process($patch_devices);
         foreach ($patch_devices as $id => &$device) {
             // if the fall_back is blank, or equal to it's id, or the fall_back ID doesn't exist in the device table or this patch file,
             // then it will cause the API to fail.  We'll skip this device and report the error.  There is also the possibility that the
             // device has a valid fallback in a patch file that hasn't been prosessed yet, but this is not worth trying to detect.
             if (!isset($device['fall_back']) || $id == $device['fall_back'] || !$this->validID($device['fall_back']) && !in_array($device['fall_back'], $patch_devices)) {
                 $this->errors[] = "The device '{$id}' from patch file '{$patch}' has an invalid fall_back device ID and has been skipped.";
                 $this->wurfl->toLog("The device '{$id}' from patch file '{$patch}' has an invalid fall_back device ID and has been skipped.", LOG_WARNING);
                 continue;
             }
             if ($this->validID($id)) {
                 // Merge this device on top of the existing device
                 TeraWurfl::mergeCapabilities($this->devices[$id], $device);
                 $this->patchMergedDevices++;
             } else {
                 // Add this new device to the table
                 $this->devices[$id] = $device;
                 $this->patchAddedDevices++;
             }
         }
         unset($this->parser);
     }
     return true;
 }
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * Refer to the COPYING.txt file distributed with this package.
 *
 * @package    WURFL_Admin
 * @copyright  ScientiaMobile, Inc.
 * @author     Steve Kamerman <steve AT scientiamobile.com>
 * @license    GNU Affero General Public License
 * @version    $id$
 */
require_once realpath(dirname(__FILE__) . '/../TeraWurfl.php');
try {
    $tw = new TeraWurfl();
} catch (Exception $e) {
}
$db = $tw->db;
$wurflfile = $tw->rootdir . TeraWurflConfig::$DATADIR . TeraWurflConfig::$WURFL_FILE;
$missing_tables = false;
if ($db->connected === true) {
    $required_tables = array(TeraWurflConfig::$TABLE_PREFIX . 'Cache', TeraWurflConfig::$TABLE_PREFIX . 'Index', TeraWurflConfig::$TABLE_PREFIX . 'Merge');
    $tables = $db->getTableList();
    // See what tables are in the DB
    //die(var_export($tables,true));
    foreach ($required_tables as $req_table) {
        if (!in_array($req_table, $tables)) {
            $missing_tables = true;
        }
    }
 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;
     }
 }
Exemple #11
0
<ul>
  <li><pre>SonyEricssonK700i/R2AC SEMC-Browser/4.0.2 Profile/MIDP-2.0 Configuration/CLDC-1.1</pre></li>
  <li><pre>MOT-T720/S_G_05.30.0CR MIB/2.0 Profile/MIDP-1.0 Configuration/CLDC-1.0</pre></li>
  <li><pre>SAGEM-myX5-2/1.0 Profile/MIDP-2.0 Configuration/CLDC-1.0 UP.Browser/6.2.2.6.d.2 (GUI) MMP/1.0</pre></li>
  <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>";
$organization_id = 0;
$geo_block_id = 0;
$ip = DB::quote(ip2long($_SERVER['REMOTE_ADDR']));
/***BEGIN GEO TRACKING****/
if (bt_geo_enabled()) {
    require BT_ROOT . '/private/includes/traffic/geolookup.php';
    $geo_block_id = runGeoLookup();
}
/***END GEO TRACKING****/
/***BEGIN MOBILE TRACKING****/
if (bt_mobile_enabled()) {
    require BT_ROOT . '/private/includes/traffic/organization.php';
    $organization_id = runOrganizationLookup();
    //Track Devices:
    require_once BT_ROOT . '/private/libs/wurfl/TeraWurfl.php';
    $wurflObj = new TeraWurfl();
    $wurflObj->getDeviceCapabilitiesFromAgent();
    //dont run for desktop OSes.
    $is_wireless = $wurflObj->getDeviceCapability('is_wireless_device');
    $is_tablet = $wurflObj->getDeviceCapability('is_tablet');
    $is_phone = $wurflObj->getDeviceCapability('can_assign_phone_number');
    $is_desktop = true;
    if ($is_wireless == 'true') {
        $is_desktop = false;
    } else {
        if ($is_tablet == 'true') {
            $is_desktop = false;
        } else {
            if ($is_phone == 'true') {
                $is_desktop = false;
            }
Exemple #13
0
require_once realpath(dirname(__FILE__) . '/../TeraWurflXMLParsers/TeraWurflXMLParser_SimpleXML.php');
error_reporting(E_ALL);
if (TeraWurflConfig::$OVERRIDE_MEMORY_LIMIT) {
    ini_set("memory_limit", TeraWurflConfig::$MEMORY_LIMIT);
}
$args = parseArgs($_SERVER['argv']);
@set_time_limit(60 * 20);
if (array_key_exists('altClass', $args) && array_key_exists('require', $args)) {
    require_once $args['require'];
    if (class_exists($args['altClass'], false) && is_subclass_of($args['altClass'], 'TeraWurfl')) {
        $base = new $args['altClass']();
    } else {
        throw new Exception("Error: {$args['altClass']} must extend TeraWurfl.");
    }
} else {
    $base = new TeraWurfl();
}
if ($base->db->connected !== true) {
    throw new Exception("Cannot connect to database: " . $base->db->errors[0]);
}
$twversion = $base->release_branch . " " . $base->release_version;
$wurflversion = $base->db->getSetting('wurfl_version');
$lastupdated = date('r', $base->db->getSetting('loaded_date'));
//var_export($args);
if (empty($args) || array_key_exists('help', $args)) {
    $usage = <<<EOL

Tera-WURFL {$twversion}
The command line WURFL updater for Tera-WURFL
Loaded WURFL: {$wurflversion}
Last Updated: {$lastupdated}
<?php

/**
 * Copyright (c) 2011 ScientiaMobile, Inc.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * Refer to the COPYING.txt file distributed with this package.
 *
 * @package    WURFL
 * @copyright  ScientiaMobile, Inc.
 * @author     Steve Kamerman <steve AT scientiamobile.com>
 * @license    GNU Affero General Public License
 * @version    $id$
 */
// 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->getDeviceCapabilitiesFromRequest();
// 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;
 }
 protected function checkPermissions()
 {
     if (!file_exists($this->wurfl_file_zipped) && !is_writable($this->wurfl->rootdir . TeraWurflConfig::$DATADIR)) {
         $this->wurfl->toLog("Cannot write to data directory (permission denied)", LOG_ERR);
         throw new TeraWurflException("Fatal Error: Cannot write to data directory (permission denied). (" . $this->wurfl->rootdir . TeraWurflConfig::$DATADIR . ")\n\nPlease make the data directory writable by the user or group that runs the webserver process, in Linux this command would do the trick if you're not too concerned about security: chmod -R 777 " . $this->wurfl->rootdir . TeraWurflConfig::$DATADIR);
     }
     if (file_exists($this->wurfl_file_zipped) && !is_writable($this->wurfl_file_zipped)) {
         $this->wurfl->toLog("Cannot overwrite WURFL file (permission denied)", LOG_ERR);
         throw new TeraWurflException("Fatal Error: Cannot overwrite WURFL file (permission denied). (" . $this->wurfl->rootdir . TeraWurflConfig::$DATADIR . ")\n\nPlease make the data directory writable by the user or group that runs the webserver process, in Linux this command would do the trick if you're not too concerned about security: chmod -R 777 " . $this->wurfl->rootdir . TeraWurflConfig::$DATADIR);
     }
 }
Exemple #17
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>";
<?php

require_once "TeraWurfl.php";
//include the Tera-WURFL file
$wurflObj = new TeraWurfl();
//instantiate the Tera-WURFL object
$wurflObj->getDeviceCapabilitiesFromAgent();
//get the capabilities of the current client
//see if this client is on a wireless device (or if they can't be identified)
if (!$wurflObj->getDeviceCapability("is_wireless_device")) {
    echo "<h2>You should not be here</h2>";
}
echo "Markup: " . $wurflObj->getDeviceCapability("preferred_markup");
//see what this device's preferred markup language is
$width = $wurflObj->getDeviceCapability("resolution_width");
//see the display resolution WIDTH
$height = $wurflObj->getDeviceCapability("resolution_height");
//see the display resolution HEIGHT
echo "<br/>Resolution: {$width} x {$height}<br/>";
 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;
 }
Exemple #20
0
 /**
  * Loads the patch files from TeraWurflConfig::PATCH_FILE
  * @return Bool Success
  */
 public function loadPatches()
 {
     if (!TeraWurflConfig::$PATCH_ENABLE) {
         return true;
     }
     $this->timepatch = microtime(true);
     // Explode the patchfile string into an array of patch files (normally just one file)
     $patches = explode(';', TeraWurflConfig::$PATCH_FILE);
     foreach ($patches as $patch) {
         $patch_devices = array();
         $this->wurfl->toLog("Loading patch: " . $patch, LOG_WARNING);
         $patch_parser = TeraWurflXMLParser::getInstance();
         $patch_parser->open(TeraWurfl::absoluteDataDir() . $patch, TeraWurflXMLParser::$TYPE_PATCH);
         $patch_parser->process($patch_devices);
         foreach ($patch_devices as $id => &$device) {
             if ($this->validID($id)) {
                 // Merge this device on top of the existing device
                 TeraWurfl::mergeCapabilities($this->devices[$id], $device);
                 $this->patchMergedDevices++;
             } else {
                 // Add this new device to the table
                 $this->devices[$id] = $device;
                 $this->patchAddedDevices++;
             }
         }
         unset($this->parser);
     }
     return true;
 }
<!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>
    /**
     * 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;
    }