Ejemplo n.º 1
0
 /**
  * Detects the capabilities of a device from a given user agent and optionally, the HTTP Accept Headers
  * @param String HTTP User Agent
  * @param String HTTP Accept Header
  * @return Bool matching device was found
  */
 public function getDeviceCapabilitiesFromAgent($userAgent = null, $httpAccept = null)
 {
     $this->db->numQueries = 0;
     $this->matchData = array("num_queries" => 0, "actual_root_device" => '', "match_type" => '', "matcher" => '', "match" => false, "lookup_time" => 0, "fall_back_tree" => '');
     $this->lookup_start = microtime(true);
     $this->foundInCache = false;
     $this->capabilities = array();
     // Define User Agent
     $this->userAgent = is_null($userAgent) ? WurflSupport::getUserAgent() : $userAgent;
     if (strlen($this->userAgent) > 255) {
         $this->userAgent = substr($this->userAgent, 0, 255);
     }
     // Use the ultra high performance SimpleDesktopMatcher if enabled
     if (TeraWurflConfig::$SIMPLE_DESKTOP_ENGINE_ENABLE) {
         require_once realpath(dirname(__FILE__) . '/UserAgentMatchers/SimpleDesktopUserAgentMatcher.php');
         if (SimpleDesktopUserAgentMatcher::isDesktopBrowser($userAgent)) {
             $this->userAgent = WurflConstants::$SIMPLE_DESKTOP_UA;
         }
     }
     // Define HTTP ACCEPT header.  Default: DO NOT use HTTP_ACCEPT headers
     //$this->httpAccept= (is_null($httpAccept))? WurflSupport::getAcceptHeader(): $httpAccept;
     $this->userAgent = UserAgentUtils::cleanUserAgent($this->userAgent);
     // Check cache for device
     if (TeraWurflConfig::$CACHE_ENABLE) {
         $cacheData = $this->db->getDeviceFromCache($this->userAgent);
         // Found in cache
         if ($cacheData !== false) {
             $this->capabilities = $cacheData;
             $this->foundInCache = true;
             $deviceID = $cacheData['id'];
         }
     }
     if (!$this->foundInCache) {
         require_once realpath(dirname(__FILE__) . '/UserAgentMatchers/SimpleDesktopUserAgentMatcher.php');
         // Find appropriate user agent matcher
         $this->userAgentMatcher = UserAgentFactory::createUserAgentMatcher($this, $this->userAgent);
         // Find the best matching WURFL ID
         $deviceID = $this->getDeviceIDFromUALoose($userAgent);
         // Get the capabilities of this device and all its ancestors
         $this->getFullCapabilities($deviceID);
         // Now add in the Tera-WURFL results array
         $this->lookup_end = microtime(true);
         $this->matchData['num_queries'] = $this->db->numQueries;
         $this->matchData['lookup_time'] = $this->lookup_end - $this->lookup_start;
         // Add the match data to the capabilities array so it gets cached
         $this->addCapabilities(array($this->matchDataKey => $this->matchData));
     }
     if (TeraWurflConfig::$CACHE_ENABLE == true && !$this->foundInCache) {
         // Since this device was not cached, cache it now.
         $this->db->saveDeviceInCache($this->userAgent, $this->capabilities);
     }
     return $this->capabilities[$this->matchDataKey]['match'];
 }
Ejemplo n.º 2
0
echo WurflSupport::showLogLevel(TeraWurflConfig::$LOG_LEVEL);
?>
						</span>, desired logging level. Use the same constants as for PHP logging<br />
					OVERRIDE_MEMORY_LIMIT <span class="setting">
						<?php 
echo WurflSupport::showBool(TeraWurflConfig::$OVERRIDE_MEMORY_LIMIT);
?>
						</span>, override PHP's default memory limit<br />
					MEMORY_LIMIT <span class="setting">
						<?php 
echo TeraWurflConfig::$MEMORY_LIMIT;
?>
						</span>, the amount of memory to allocate to PHP if OVERRIDE_MEMORY_LIMIT is enabled<br />
					SIMPLE_DESKTOP_ENGINE_ENABLE <span class="setting">
						<?php 
echo WurflSupport::showBool(TeraWurflConfig::$SIMPLE_DESKTOP_ENGINE_ENABLE);
?>
						</span>, enable the SimpleDesktop Detection Engine to increase performance<br />
					CAPABILITY_FILTER:
						<?php 
echo "<pre class=\"setting\">" . var_export(TeraWurflConfig::$CAPABILITY_FILTER, true) . "</pre>";
?>
						the capability filter that is used to determine which capabilities are available<br />
			</p>
				</td>
		</tr>
	</table>
	<p>&nbsp;</p>
	<table width="800" border="0" cellpadding="0" cellspacing="0">
		<tr>
			<th scope="col">Log File (last 30 lines) </th>
Ejemplo n.º 3
0
    echo "done ({$wurflfile}: {$size})<br />Downloaded in {$download_time} sec @ {$download_rate} <br/><br/>";
    usleep(50000);
    flush();
}
$loader = new TeraWurflLoader($base);
//$ok = $base->db->initializeDB();
$ok = $loader->load();
if ($ok) {
    echo "<strong>Database Update OK</strong><hr />";
    echo "Total Time: " . $loader->totalLoadTime() . "<br/>";
    echo "Parse Time: " . $loader->parseTime() . " (" . $loader->getParserName() . ")<br/>";
    echo "Validate Time: " . $loader->validateTime() . "<br/>";
    echo "Sort Time: " . $loader->sortTime() . "<br/>";
    echo "Patch Time: " . $loader->patchTime() . "<br/>";
    echo "Database Time: " . $loader->databaseTime() . "<br/>";
    echo "Cache Rebuild Time: " . $loader->cacheRebuildTime() . "<br/>";
    echo "Number of Queries: " . $base->db->numQueries . "<br/>";
    if (version_compare(PHP_VERSION, '5.2.0') === 1) {
        echo "PHP Memory Usage: " . WurflSupport::formatBytes(memory_get_usage()) . "<br/>";
    }
    echo "--------------------------------<br/>";
    echo "WURFL Version: " . $loader->version . " (" . $loader->last_updated . ")<br />";
    echo "WURFL Devices: " . $loader->mainDevices . "<br/>";
    echo "PATCH New Devices: " . $loader->patchAddedDevices . "<br/>";
    echo "PATCH Merged Devices: " . $loader->patchMergedDevices . "<br/>";
} else {
    echo "ERROR LOADING DATA!<br/>";
    echo "Errors: <br/>\n";
    echo "<pre>" . htmlspecialchars(var_export($loader->errors, true)) . "</pre>";
}
echo "<hr/><a href=\"index.php\">Return to administration tool.</a>";
        foreach ($capability as $property => $value) {
            $class = $i++ % 2 == 0 ? 'lightrow' : 'darkrow';
            // Primary Group
            $value = is_bool($value) || $value == "true" || $value == "false" ? WurflSupport::showBool($value) : $value;
            if ($value == "") {
                $value = "[null]";
            } else {
                $value = htmlspecialchars($value);
            }
            $nicecap .= "<tr><td class=\"cap_title {$class}\">{$property}</td><td class=\"cap_value {$class}\">" . htmlspecialchars($value) . "</td></tr>\n";
        }
        $nicecap .= "</table>";
        $nicecap .= "</td></tr>\n";
    } else {
        // Top Level attribute
        $capability = is_bool($capability) || $capability == "true" || $capability == "false" ? WurflSupport::showBool($capability) : $capability;
        if ($capability == "") {
            $capability = "[null]";
        } else {
            $capability = htmlspecialchars($capability);
        }
        $nicecap .= "<tr><td class=\"cap_heading\">{$group}</td><td class=\"cap_value\">{$capability}</td></tr>\n";
    }
}
foreach ($groups as $num => $group) {
    $groups[$num] = "<a href=\"#{$group}\">{$group}</a>";
}
$grouplinks = implode(' | ', $groups);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
 public function downloadUpdate()
 {
     if ($this->verbose === true) {
         echo "Downloading WURFL from {$this->download_url} ...\n\n";
     }
     $download_start = microtime(true);
     if (!($gzdata = @file_get_contents($this->download_url))) {
         if (isset($http_response_header) && is_array($http_response_header)) {
             list($version, $status_code, $msg) = explode(' ', $http_response_header[0], 3);
             $status_code = (int) $status_code;
         } else {
             $status_code = 404;
             $msg = "File not found";
         }
         throw new TeraWurflUpdateDownloaderException("Unable to download WURFL file: HTTP Error {$status_code}: {$msg}", $status_code);
     }
     $this->download_time = microtime(true) - $download_start;
     file_put_contents($this->wurfl_file_zipped, $gzdata);
     $gzdata = null;
     $this->compressed_size = filesize($this->wurfl_file_zipped);
     // Try to use ZipArchive, included from 5.2.0
     if (class_exists("ZipArchive", false)) {
         $zip = new ZipArchive();
         if ($zip->open(str_replace('\\', '/', $this->wurfl_file_zipped)) === true) {
             $zip->extractTo(str_replace('\\', '/', dirname($this->wurfl_file_xml)), array('wurfl.xml'));
             $zip->close();
         } else {
             throw new TeraWurflException("Error: Unable to extract wurfl.xml from downloaded archive: {$this->wurfl_file_zipped}");
         }
     } else {
         system("gunzip {$this->wurfl_file_zipped}");
     }
     $this->uncompressed_size = filesize($this->wurfl_file_xml);
     $this->download_speed = WurflSupport::formatBitrate(filesize($this->wurfl_file_zipped), $this->download_time);
     if ($this->verbose === true) {
         $nice_size = WurflSupport::formatBytes($this->uncompressed_size) . " [" . WurflSupport::formatBytes($this->compressed_size) . " compressed]";
         echo "done ({$this->wurfl_file_xml}: {$nice_size})\nDownloaded in {$this->download_time} sec @ {$this->download_speed} \n\n";
         flush();
     }
     usleep(50000);
 }
Ejemplo n.º 6
0
 function Wall($ua = false)
 {
     global $_GET, $_SERVER;
     if (!$ua) {
         $this->ua = isset($_GET['UA']) ? $_GET['UA'] : getenv('HTTP_USER_AGENT');
     } else {
         $this->ua = $ua;
     }
     if (defined('WALL_USE_TERA_WURFL') && WALL_USE_TERA_WURFL) {
         switch (TERA_WURFL_VERSION) {
             case 1:
                 require_once WURFL_CLASS_FILE;
                 $this->wurfl = new tera_wurfl();
                 $this->wurfl->getDeviceCapabilitiesFromAgent($this->ua);
                 break;
             case 2:
                 // The class file was loaded in wall_prepend.php
                 $this->wurfl = new TeraWurfl();
                 if (!$ua) {
                     $this->ua = WurflSupport::getUserAgent();
                 }
                 $this->wurfl->getDeviceCapabilitiesFromAgent($this->ua);
                 break;
             case 'webservice':
                 $this->wurfl = new TeraWurflRemoteClient(TERA_WURFL_WEBSERVICE_URL, TeraWurflRemoteClient::$FORMAT_JSON);
                 if (!$ua) {
                     $this->ua = TeraWurflRemoteClient::getUserAgent();
                 }
                 $this->wurfl->getCapabilitiesFromAgent($this->ua, $GLOBALS['WALLWurflCapabilities']);
                 break;
         }
     } else {
         $this->wurfl = new wurfl_class();
         $this->wurfl->getDeviceCapabilitiesFromAgent($this->ua);
     }
     ob_start(array($this, '_obCallBack'));
     register_shutdown_function(array($this, '_obEndFlush'));
 }
    protected function actionStats(TeraWurflCLIArgument $arg)
    {
        $twversion = $this->wurfl->release_branch . " " . $this->wurfl->release_version;
        $wurflversion = $this->wurfl->db->getSetting('wurfl_version');
        $lastupdated = date('r', $this->wurfl->db->getSetting('loaded_date'));
        $config = $this->wurfl->rootdir . "TeraWurflConfig.php";
        $dbtype = str_replace("TeraWurflDatabase_", "", get_class($this->wurfl->db));
        $dbver = $this->wurfl->db->getServerVersion();
        $mergestats = $this->wurfl->db->getTableStats(TeraWurflConfig::$TABLE_PREFIX . 'Merge');
        $mergestats['bytesize'] = WurflSupport::formatBytes($mergestats['bytesize']);
        $merge = "\n > MERGE\n   Rows:    {$mergestats['rows']}\n   Devices: {$mergestats['actual_devices']}\n   Size:    {$mergestats['bytesize']}\n";
        $index = "";
        $indexstats = $this->wurfl->db->getTableStats(TeraWurflConfig::$TABLE_PREFIX . 'Index');
        if (!empty($indexstats)) {
            $indexstats['bytesize'] = WurflSupport::formatBytes($indexstats['bytesize']);
            $index = "\n > INDEX\n   Rows:    {$indexstats['rows']}\n   Size:    {$indexstats['bytesize']}\n";
        }
        $cachestats = $this->wurfl->db->getTableStats(TeraWurflConfig::$TABLE_PREFIX . 'Cache');
        $cachestats['bytesize'] = WurflSupport::formatBytes($cachestats['bytesize']);
        $cache = "\n > CACHE\n   Rows:    {$cachestats['rows']}\n   Size:    {$cachestats['bytesize']}\n";
        $matcherList = $this->wurfl->db->getMatcherTableList();
        $matchers = array();
        foreach ($matcherList as $name) {
            $matchers[] = array('name' => $name, 'stats' => $this->wurfl->db->getTableStats($name));
        }
        $out = <<<EOF
Tera-WURFL {$twversion}
Database Type: {$dbtype} (ver {$dbver})
Loaded WURFL: {$wurflversion}
Last Updated: {$lastupdated}
Config File: {$config}
---------- Table Stats -----------
{$merge}{$index}{$cache}
EOF;
        echo $out;
    }