-
Notifications
You must be signed in to change notification settings - Fork 1
/
Wurfl.php
86 lines (72 loc) · 2.31 KB
/
Wurfl.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
if (!defined('BASEPATH')) exit('No direct script access allowed');
class Wurfl {
var $wurflManagerFactory;
var $wurflManager;
var $wurflConfig;
var $device;
var $id;
var $fallBack;
// Variables
private $persistenceDir = '';
private $cacheDir = '';
private $wurflDir = '';
private $resourcesDir = '';
private $wurflName = '';
private $wurflPatchName = '';
function __construct() {
// Declare some config variables
// Config Options
$this->persistenceDir = BASEPATH."WURFL/resources/storage/persistence";
$this->cacheDir = BASEPATH."WURFL/resources/storage/cache";
$this->wurflDir = BASEPATH."WURFL/";
$this->resourcesDir = BASEPATH."WURFL/resources/";
$this->wurflName = "wurfl.zip";
$this->wurflPatchName = "patch.xml";
// Include the application file
if (is_file($this->wurflDir . 'Application.php')){
require_once $this->wurflDir . 'Application.php';
// Load config
$this->wurflConfig = new WURFL_Configuration_InMemoryConfig ();
$this->wurflConfig
->wurflFile($this->resourcesDir . $this->wurflName)
->wurflPatch($this->resourcesDir . $this->wurflPatchName)
->persistence("file",array(
WURFL_Configuration_Config::DIR => $this->persistenceDir))
->cache("file", array(
WURFL_Configuration_Config::DIR => $this->cacheDir,
WURFL_Configuration_Config::EXPIRATION => 36000));
// Load WURFL
$this->wurflManagerFactory = new WURFL_WURFLManagerFactory($this->wurflConfig);
$this->wurflManager = $this->wurflManagerFactory->create(true);
}
}
function load($device = ""){
if (is_array($device)){
$this->device = $this->wurflManager->getDeviceForHttpRequest($device);
} else {
$this->device = $this->wurflManager->getDeviceForUserAgent($device);
}
if (!empty($this->device)){
$this->id = $this->device->id;
$this->fallBack = $this->device->fallBack;
} else {
return false;
}
}
function getDevice(){
return $this->device;
}
function getCapability($capabilityName = ""){
return $this->device->getCapability($capabilityName);
}
function getAllCapabilities(){
return $this->device->getAllCapabilities();
}
function getId(){
return $this->id;
}
function getFallback(){
return $this->fallback;
}
}