Fix some missing updates (#1373)
[openemr.git] / portal / patient / fwk / libs / verysimple / HTTP / BrowserDevice.php
blobaaeef8e8a4000e68cc5dafe0da3539d8718d4354
1 <?php
2 /** @package verysimple::HTTP */
4 /**
5 * BrowserDevice represents a device used when browsing (or executing)
6 * the current code.
7 * This is a Singleton pattern, cannot be
8 * instantiated directly.
10 * TODO: this only has minimal support and basically only supplies
11 * information about whether the device is mobile or not, and if so
12 * it supplies the major vendor name.
14 * Usage:
15 * $browser = BrowserDevice::GetInstance();
16 * if ($device->IsMobile()) dosomething();
18 * @package verysimple::HTTP
19 * @author VerySimple Inc.
20 * @copyright 1997-2007 VerySimple, Inc. http://www.verysimple.com
21 * @license http://www.gnu.org/licenses/lgpl.html LGPL
22 * @version 1.0
24 class BrowserDevice
27 /**
28 * patters to search for devices
30 * @var Array
32 static $DESKTOP_DEVICE_PATTERNS = array (
33 'AdobeAIR' => 'AdobeAIR',
34 'chrome' => 'google',
35 'firefox' => 'mozilla',
36 'MSIE' => 'microsoft',
37 'safari' => 'apple'
40 /**
41 * patters to search for devices
43 * @var Array
45 static $MOBILE_DEVICE_PATTERNS = array (
46 '(ipad|ipod|iphone)' => 'apple',
47 'android' => 'android',
48 'opera mini' => 'opera',
49 'blackberry' => 'blackberry',
50 '(pre\/|palm os|palm|hiptop|avantgo|plucker|xiino|blazer|elaine)' => 'palm',
51 '(iris|3g_t|windows ce|opera mobi|windows ce; smartphone;|windows ce; iemobile)' => 'windows',
52 '(mini 9.5|vx1000|lge |m800|e860|u940|ux840|compal|wireless| mobi|ahong|lg380|lgku|lgu900|lg210|lg47|lg920|lg840|lg370|sam-r|mg50|s55|g83|t66|vx400|mk99|d615|d763|el370|sl900|mp500|samu3|samu4|vx10|xda_|samu5|samu6|samu7|samu9|a615|b832|m881|s920|n210|s700|c-810|_h797|mob-x|sk16d|848b|mowser|s580|r800|471x|v120|rim8|c500foma:|160x|x160|480x|x640|t503|w839|i250|sprint|w398samr810|m5252|c7100|mt126|x225|s5330|s820|htil-g1|fly v71|s302|-x113|novarra|k610i|-three|8325rc|8352rc|sanyo|vx54|c888|nx250|n120|mtk |c5588|s710|t880|c5005|i;458x|p404i|s210|c5100|teleca|s940|c500|s590|foma|samsu|vx8|vx9|a1000|_mms|myx|a700|gu1100|bc831|e300|ems100|me701|me702m-three|sd588|s800|8325rc|ac831|mw200|brew |d88|htc\/|htc_touch|355x|m50|km100|d736|p-9521|telco|sl74|ktouch|m4u\/|me702|8325rc|kddi|phone|lg |sonyericsson|samsung|240x|x320|vx10|nokia|sony cmd|motorola|up.browser|up.link|mmp|symbian|smartphone|midp|wap|vodafone|o2|pocket|kindle|mobile|psp|treo)' => 'unknown'
54 private static $instance;
55 public $UserAgent;
56 public $IsWAP;
57 public $IsMobile;
58 public $IsTablet;
59 public $IsConsole;
60 public $Vendor;
61 public $SupportsJS;
62 public $SupportsCSS;
63 public $IsNativeDevice;
64 public $NativeClientVersion;
66 /**
67 * Private constructor enforces the Singleton pattern
69 private function __construct()
71 // do nothing
74 /**
75 * Parse the user agent and detect the browser, populating
76 * all internal properties accordingly
78 public function Detect()
80 // RESET DEFAULT VALUES
81 $this->IsWAP = false;
82 $this->IsMobile = false;
83 $this->IsTablet = false;
84 $this->IsConsole = false;
85 $this->Vendor = 'unknown';
86 $this->SupportsJS = true;
87 $this->SupportsCSS = true;
89 $this->UserAgent = isset($_SERVER ['HTTP_USER_AGENT']) ? $_SERVER ['HTTP_USER_AGENT'] : "";
90 $wap = isset($_SERVER ['HTTP_X_WAP_PROFILE']) ? $_SERVER ['HTTP_X_WAP_PROFILE'] : "";
92 if (! $this->UserAgent) {
93 $this->IsConsole = true;
94 } else {
95 foreach (BrowserDevice::$MOBILE_DEVICE_PATTERNS as $key => $val) {
96 if (preg_match('/' . $key . '/i', $this->UserAgent)) {
97 $this->IsMobile = true;
98 $this->Vendor = $val;
99 break;
103 if ($this->IsMobile == false) {
104 foreach (BrowserDevice::$DESKTOP_DEVICE_PATTERNS as $key => $val) {
105 if (preg_match('/' . $key . '/i', $this->UserAgent)) {
106 $this->Vendor = $val;
107 break;
115 * Returns an instance of a BrowserDevice populated based on the
116 * server variables provided
118 * @return BrowserDevice
120 public static function GetInstance()
122 if (! isset(self::$instance)) {
123 $c = __CLASS__;
124 self::$instance = new $c ();
125 self::$instance->Detect();
128 return self::$instance;