[Mobile/Web] WURFL1.4.3를 사용해서 device 얻기

Mobile/Web 2012/12/17 22:00
<?php
function formatBoolean($value)
{
  return $value ? ("Yes") : ("No");
}

function formatArray($value)
{
  $output = "[";
  join(',',$value);
  $output .= "]";
  return $output;
}

function writeCapability($name, $value)
{
  $output = '<li><span class="capaName">' . $name . '</span>?<span class="capaValue">';
  if(is_bool($value))
  {
    $output .= formatBoolean($value);
  }
  else if(is_array($value))
  {
    $output .= formatArray($value);
  }
  else
  {
    $output .= $value;
  }
  $output .= '</span></li>';
  return $output;
}

define("TITLE""WURFL Device Info");

$wurflDir = './wurfl-php-1.4.3.0./WURFL';
$resourcesDir = './wurfl-php-1.4.3.0/examples/resources';

require_once $wurflDir.'/Application.php';

$persistenceDir = $resourcesDir.'/storage/persistence';
$cacheDir = $resourcesDir.'/storage/cache';

// Create WURFL Configuration
$wurflConfig = new WURFL_Configuration_InMemoryConfig();

// Set location of the WURFL File
$wurflConfig->wurflFile($resourcesDir.'/wurfl.zip');

// Set the match mode for the API ('performance' or 'accuracy')
$wurflConfig->matchMode('performance');

// Setup WURFL Persistence
$wurflConfig->persistence('file', array('dir' => $persistenceDir));

// Setup Caching
$wurflConfig->cache('file', array('dir' => $cacheDir, 'expiration' => 36000));

// Create a WURFL Manager Factory from the WURFL Configuration
$wurflManagerFactory = new WURFL_WURFLManagerFactory($wurflConfig);

// Create a WURFL Manager
/* @var $wurflManager WURFL_WURFLManager */
$wurflManager = $wurflManagerFactory->create();

/*
require_once('./wurfl-php-1.4.3.0/WURFL/WURFLManagerProvider.php');
$wurflConfigFile = "C:\nginx-1.3.9\html\wurfl-php-1.4.3.0\examples\resources\wurfl-config.xml";
$wurflManager = WURFL_WURFLManagerProvider::getWURFLManager($wurflConfigFile);
*/

$device = $wurflManager->getDeviceForHttpRequest($_SERVER);
?>

<?= writeCapability("User-Agent", $_SERVER['HTTP_USER_AGENT']) ?>
<?= writeCapability("Brand Name", $device->getCapability('brand_name')) ?>
<?= writeCapability("Model Name", $device->getCapability('model_name')) ?>
<?= writeCapability("Pointing Method", $device->getCapability('pointing_method')) ?>
<?= writeCapability("Screen Width", $device->getCapability('resolution_width')) ?>
<?= writeCapability("Screen Height", $device->getCapability('resolution_height')) ?>
<?= writeCapability("Mobile Device", $device->getCapability('is_wireless_device')) ?>
<?= writeCapability("Supports Web Standards", $device->getCapability('device_claims_web_support')) ?>
<?= writeCapability("Preferred Markup", $device->getCapability('preferred_markup')) ?>
<?= writeCapability("Supports Access Keys", $device->getCapability('access_key_support')) ?>
</ul>


Trackback 0 : Comment 0
◀ PREV : [1] : ... [33] : [34] : [35] : [36] : [37] : [38] : [39] : [40] : [41] : ... [291] : NEXT ▶

티스토리 툴바