ILIAS  release_8 Revision v8.24
AgentDetermination.php
Go to the documentation of this file.
1<?php
2
4
6
7/******************************************************************************
8 *
9 * This file is part of ILIAS, a powerful learning management system.
10 *
11 * ILIAS is licensed with the GPL-3.0, you should have received a copy
12 * of said license along with the source code.
13 *
14 * If this is not the case or you just want to try ILIAS, you'll find
15 * us at:
16 * https://www.ilias.de
17 * https://github.com/ILIAS-eLearning
18 *
19 *****************************************************************************/
26{
27 protected string $agent_name;
28 protected string $agent_version;
29 protected string $agent_platform;
30 protected string $accept;
31 protected string $user_agent;
32 protected bool $is_mobile = false;
33 protected bool $is_generic = false;
34
35 protected array $devices = [
36 'android' => 'android.*mobile',
37 'androidtablet' => 'android(?!.*mobile)',
38 'blackberry' => 'blackberry',
39 'blackberrytablet' => 'rim tablet os',
40 'iphone' => '(iphone|ipod)',
41 'ipad' => '(ipad)',
42 'palm' => '(avantgo|blazer|elaine|hiptop|palm|plucker|xiino)',
43 'windows' => 'windows ce; (iemobile|ppc|smartphone)',
44 'windowsphone' => 'windows phone os',
45 'generic' => '(kindle|mobile|mmp|midp|o2|pda|pocket|psp|symbian|smartphone|treo|up.browser|up.link|vodafone|wap|opera mini)'
46 ];
47
48 public function __construct()
49 {
50 $HTTP_USER_AGENT = $_SERVER['HTTP_USER_AGENT'] ?? 'undefined';
51 /*
52 Determine browser and version
53 */
54 if (preg_match('/MSIE (\d.\d{1,2})/', $HTTP_USER_AGENT, $log_version)) {
55 $this->agent_version = $log_version[1];
56 $this->agent_name = 'IE';
57 } elseif (preg_match('/Opera (\d.\d{1,2})/', $HTTP_USER_AGENT, $log_version) ||
58 preg_match('/Opera\/(\d.\d{1,2})/', $HTTP_USER_AGENT, $log_version)) {
59 $this->agent_version = $log_version[1];
60 $this->agent_name = 'OPERA';
61 } elseif (preg_match('/Safari ([0-9\/.]*)/', $HTTP_USER_AGENT, $log_version) ||
62 preg_match('/Safari\/([0-9\/.]*)/', $HTTP_USER_AGENT, $log_version)) {
63 $this->agent_version = $log_version[1];
64 $this->agent_name = 'Safari';
65 } elseif (preg_match('/Firefox ([0-9\/.]*)/', $HTTP_USER_AGENT, $log_version) ||
66 preg_match('/Firefox\/([0-9\/.]*)/', $HTTP_USER_AGENT, $log_version)) {
67 $this->agent_version = $log_version[1];
68 $this->agent_name = 'Firefox';
69 } elseif (preg_match('/iCab (\d.[0-9a-zA-Z]{1,4})/', $HTTP_USER_AGENT, $log_version) ||
70 preg_match('/iCab\/(\d.[0-9a-zA-Z]{1,4})/', $HTTP_USER_AGENT, $log_version)) {
71 $this->agent_version = $log_version[1];
72 $this->agent_name = 'iCab';
73 } elseif (preg_match('/Mozilla (\d.[0-9a-zA-Z]{1,4})/', $HTTP_USER_AGENT, $log_version) ||
74 preg_match('/Mozilla\/(\d.[0-9a-zA-Z]{1,4})/', $HTTP_USER_AGENT, $log_version)) {
75 $this->agent_version = $log_version[1];
76 $this->agent_name = preg_match('/Gecko/', $HTTP_USER_AGENT, $log_version) ? 'Mozilla' : 'Netscape';
77 } elseif (preg_match('/Konqueror\/(\d.\d.\d{1,2})/', $HTTP_USER_AGENT, $log_version) ||
78 preg_match('/Konqueror\/(\d.\d{1,2})/', $HTTP_USER_AGENT, $log_version)) {
79 $this->agent_version = $log_version[1];
80 $this->agent_name = 'Konqueror';
81 } else {
82 $this->agent_version = 0;
83 $this->agent_name = 'OTHER';
84 }
85
86 /*
87 Determine platform
88 */
89 if (strstr($HTTP_USER_AGENT, 'Win')) {
90 $this->agent_platform = 'Win';
91 } elseif (strstr($HTTP_USER_AGENT, 'Mac')) {
92 $this->agent_platform = 'Mac';
93 } elseif (strstr($HTTP_USER_AGENT, 'Linux')) {
94 $this->agent_platform = 'Linux';
95 } elseif (strstr($HTTP_USER_AGENT, 'Unix')) {
96 $this->agent_platform = 'Unix';
97 } elseif (strstr($HTTP_USER_AGENT, 'Beos')) {
98 $this->agent_platform = 'Beos';
99 } else {
100 $this->agent_platform = 'Other';
101 }
102
103 // Mobile detection
104 $this->user_agent = $_SERVER['HTTP_USER_AGENT'] ?? 'undefined';
105 $this->accept = $_SERVER['HTTP_ACCEPT'] ?? 'undefined';
106
107 if (isset($_SERVER['HTTP_X_WAP_PROFILE']) || isset($_SERVER['HTTP_PROFILE'])) {
108 $this->is_mobile = true;
109 } elseif (strpos($this->accept, 'text/vnd.wap.wml') > 0 || strpos(
110 $this->accept,
111 'application/vnd.wap.xhtml+xml'
112 ) > 0) {
113 $this->is_mobile = true;
114 } else {
115 foreach (array_keys($this->devices) as $device) {
116 if ($this->isDevice($device)) {
117 $this->is_mobile = true;
118 }
119 }
120 }
121 }
122
123 public function isMobile(): bool
124 {
125 if ($this->is_mobile) {
126 return true;
127 }
128
129 if (preg_match(
130 '/android.+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i',
131 $this->user_agent
132 ) || preg_match(
133 '/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|e\-|e\/|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(di|rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|xda(\-|2|g)|yas\-|your|zeto|zte\-/i',
134 substr($this->user_agent, 0, 4)
135 )) {
136 return true;
137 } else {
138 return false;
139 }
140 }
141
147 public function __call($name, $arguments)
148 {
149 throw new \BadFunctionCallException('no generic method-call possible, please contact the maintainer');
151 /*$device = substr($name, 2);
152 if ($name === 'is' . ucfirst($device) && array_key_exists(strtolower($device), $this->devices)) {
153 return $this->isDevice($device);
154 } else {
155 throw new ilException('Method ' . $name . ' not defined');
156 }*/
157 }
158
159 public function isIpad(): bool
160 {
161 return $this->isDevice('ipad');
162 }
163
164 protected function isDevice(string $device): bool
165 {
166 $var = 'is' . ucfirst($device);
167 $return = $this->{$var} ?? (bool) preg_match(
168 '/' . $this->devices[strtolower($device)] . '/i',
170 );
171 if ($device !== 'generic' && $return === true) {
172 $this->is_generic = false;
173 }
174
175 return $return;
176 }
177}
This library is borrowed from the phpGroupWare API http://www.phpgroupware.org/api Modifications made...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
if($format !==null) $name
Definition: metadata.php:247
$_SERVER['HTTP_HOST']
Definition: raiseError.php:10