PluginProbe
Sessions / 2.3.1
Sessions v2.3.1
2.1.0 2.10.0 2.11.0 2.12.0 2.13.0 2.13.1 2.13.2 2.13.3 2.14.0 2.2.0 2.3.0 2.3.1 2.4.0 2.4.1 2.5.0 2.6.0 2.6.1 2.6.2 2.7.0 2.8.0 2.9.0 2.9.1 3.0.0 3.1.0 3.1.1 All 39 releases
sessions / includes / system / class-useragent.php

class-useragent.php in Sessions 2.3.1, at includes/system/class-useragent.php

404 lines 8.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * UserAgent handling
4 *
5 * Handles all UserAgent operations and detection (via Sessions).
6 *
7 * @package System
8 * @author Pierre Lannoy <https://pierre.lannoy.fr/>.
9 * @since 1.0.0
10 */
11
12 namespace POSessions\System;
13
14 use POSessions\System\Favicon;
15 use Feather;
16
17 /**
18 * Define the UserAgent functionality.
19 *
20 * Handles all UserAgent operations and detection.
21 *
22 * @package System
23 * @author Pierre Lannoy <https://pierre.lannoy.fr/>.
24 * @since 1.0.0
25 */
26 class UserAgent {
27
28 /**
29 * Initialize a device and return it.
30 *
31 * @param string $ua Optional. The user-agent string.
32 * @return object The device object.
33 * @since 1.0.0
34 */
35 public static function get( $ua = '' ) {
36 if ( class_exists( 'PODeviceDetector\API\Device' ) && '-' !== $ua ) {
37 return \PODeviceDetector\API\Device::get( $ua );
38 } else {
39 return new static();
40 }
41 }
42
43 /**
44 * Get the url.
45 *
46 * @param array $fields Optional. The args to add.
47 * @param boolean $escape Optional. Forces url escaping.
48 * @return string The url.
49 * @since 1.0.0
50 */
51 public static function get_analytics_url( $fields = [], $escape = true ) {
52 if ( ! class_exists( 'PODeviceDetector\API\Device' ) ) {
53 return '';
54 }
55 $params = [];
56 foreach ( $fields as $key => $arg ) {
57 $params[ $key ] = $arg;
58 }
59 $url = admin_url( 'admin.php?page=podd-viewer' );
60 foreach ( $params as $key => $arg ) {
61 if ( '' !== $arg ) {
62 $url .= '&' . $key . '=' . rawurlencode( $arg );
63 }
64 }
65 $url = str_replace( '"', '\'\'', $url );
66 if ( $escape ) {
67 $url = esc_url( $url );
68 }
69 return $url;
70 }
71
72 /**
73 * Get the brand icon base64 encoded.
74 *
75 * @return string The icon base64 encoded.
76 * @since 1.0.0
77 */
78 public function brand_icon_base64() {
79 return Feather\Icons::get_base64( 'x', 'none', '#73879C' );
80 }
81
82 /**
83 * Get the brand icon html image tag.
84 *
85 * @return string The icon, as html image, ready to print.
86 * @since 1.0.0
87 */
88 public function brand_icon_image() {
89 return '<img class="podd-brand-icon podd-brand-icon-none" style="width:16px;vertical-align:top;" src="' . $this->brand_icon_base64() . '" />';
90 }
91
92 /**
93 * Get the os icon base64 encoded.
94 *
95 * @return string The icon base64 encoded.
96 * @since 1.0.0
97 */
98 public function os_icon_base64() {
99 return Feather\Icons::get_base64( 'x', 'none', '#73879C' );
100 }
101
102 /**
103 * Get the os icon html image tag.
104 *
105 * @return string The icon, as html image, ready to print.
106 * @since 1.0.0
107 */
108 public function os_icon_image() {
109 return '<img class="podd-os-icon podd-os-icon-none" style="width:16px;vertical-align:top;" src="' . $this->os_icon_base64() . '" />';
110 }
111
112 /**
113 * Get the browser icon base64 encoded.
114 *
115 * @return string The icon base64 encoded.
116 * @since 1.0.0
117 */
118 public function browser_icon_base64() {
119 return Feather\Icons::get_base64( 'x', 'none', '#73879C' );
120 }
121
122 /**
123 * Get the browser icon html image tag.
124 *
125 * @return string The icon, as html image, ready to print.
126 * @since 1.0.0
127 */
128 public function browser_icon_image() {
129 return '<img class="podd-browser-icon podd-browser-icon-none" style="width:16px;vertical-align:top;" src="' . $this->browser_icon_base64() . '" />';
130 }
131
132 /**
133 * Get the bot icon base64 encoded.
134 *
135 * @return string The icon base64 encoded.
136 * @since 1.0.0
137 */
138 public function bot_icon_base64() {
139 return Favicon::get_base64();
140 }
141
142 /**
143 * Get the bot icon html image tag.
144 *
145 * @return string The icon, as html image, ready to print.
146 * @since 1.0.0
147 */
148 public function bot_icon_image() {
149 return '<img class="podd-bot-icon podd-bot-icon-none" style="width:16px;vertical-align:top;" src="' . $this->bot_icon_base64() . '" />';
150 }
151
152 /**
153 * @var boolean True if it's a bot, false otherwise.
154 * @since 1.0.0
155 */
156 public $class_is_bot = false;
157
158 /**
159 * @var boolean True if it's a desktop, false otherwise.
160 * @since 1.0.0
161 */
162 public $class_is_desktop = false;
163
164 /**
165 * @var boolean True if it's a mobile, false otherwise.
166 * @since 1.0.0
167 */
168 public $class_is_mobile = false;
169
170 /**
171 * @var string The name of the class translated if translation exists, else in english.
172 * @since 1.0.0
173 */
174 public $class_full_type = '';
175
176 /**
177 * @var boolean True if it's a smartphone, false otherwise.
178 * @since 1.0.0
179 */
180 public $device_is_smartphone = false;
181
182 /**
183 * @var boolean True if it's a featurephone, false otherwise.
184 * @since 1.0.0
185 */
186 public $device_is_featurephone = false;
187
188 /**
189 * @var boolean True if it's a tablet, false otherwise.
190 * @since 1.0.0
191 */
192 public $device_is_tablet = false;
193
194 /**
195 * @var boolean True if it's a phablet, false otherwise.
196 * @since 1.0.0
197 */
198 public $device_is_phablet = false;
199
200 /**
201 * @var boolean True if it's a console, false otherwise.
202 * @since 1.0.0
203 */
204 public $device_is_console = false;
205
206 /**
207 * @var boolean True if it's a portable media player, false otherwise.
208 * @since 1.0.0
209 */
210 public $device_is_portable_media_player = false;
211
212 /**
213 * @var boolean True if it's a car browser, false otherwise.
214 * @since 1.0.0
215 */
216 public $device_is_car_browser = false;
217
218 /**
219 * @var boolean True if it's a tv, false otherwise.
220 * @since 1.0.0
221 */
222 public $device_is_tv = false;
223
224 /**
225 * @var boolean True if it's a smart display, false otherwise.
226 * @since 1.0.0
227 */
228 public $device_is_smart_display = false;
229
230 /**
231 * @var boolean True if it's a camera, false otherwise.
232 * @since 1.0.0
233 */
234 public $device_is_camera = false;
235
236 /**
237 * @var string The name of the device type translated if translation exists, else in english.
238 * @since 1.0.0
239 */
240 public $device_full_type = '';
241
242 /**
243 * @var boolean True if it's a browser, false otherwise.
244 * @since 1.0.0
245 */
246 public $client_is_browser = false;
247
248 /**
249 * @var boolean True if it's a feed reader, false otherwise.
250 * @since 1.0.0
251 */
252 public $client_is_feed_reader = false;
253
254 /**
255 * @var boolean True if it's a mobile app, false otherwise.
256 * @since 1.0.0
257 */
258 public $client_is_mobile_app = false;
259
260 /**
261 * @var boolean True if it's a PIM, false otherwise.
262 * @since 1.0.0
263 */
264 public $client_is_pim = false;
265
266 /**
267 * @var boolean True if it's a library, false otherwise.
268 * @since 1.0.0
269 */
270 public $client_is_library = false;
271
272 /**
273 * @var boolean True if it's a media player, false otherwise.
274 * @since 1.0.0
275 */
276 public $client_is_media_player = false;
277
278 /**
279 * @var string The name of the client type translated if translation exists, else in english.
280 * @since 1.0.0
281 */
282 public $client_full_type = '';
283
284 /**
285 * @var boolean True if device has touch enabled, false otherwise.
286 * @since 1.0.0
287 */
288 public $has_touch_enabled = false;
289
290 /**
291 * @var string The OS name.
292 * @since 1.0.0
293 */
294 public $os_name = '';
295
296 /**
297 * @var string The OS short name.
298 * @since 1.0.0
299 */
300 public $os_short_name = '';
301
302 /**
303 * @var string The OS version.
304 * @since 1.0.0
305 */
306 public $os_version = '';
307
308 /**
309 * @var string The OS platform.
310 * @since 1.0.0
311 */
312 public $os_platform = '';
313
314 /**
315 * @var string The client type.
316 * @since 1.0.0
317 */
318 public $client_type = '';
319
320 /**
321 * @var string The client name.
322 * @since 1.0.0
323 */
324 public $client_name = '';
325
326 /**
327 * @var string The client short name.
328 * @since 1.0.0
329 */
330 public $client_short_name = '';
331
332 /**
333 * @var string The client version.
334 * @since 1.0.0
335 */
336 public $client_version = '';
337
338 /**
339 * @var string The client engine.
340 * @since 1.0.0
341 */
342 public $client_engine = '';
343
344 /**
345 * @var string The client engine version.
346 * @since 1.0.0
347 */
348 public $client_engine_version = '';
349
350 /**
351 * @var string The brand name.
352 * @since 1.0.0
353 */
354 public $brand_name = '';
355
356 /**
357 * @var string The brand short name.
358 * @since 1.0.0
359 */
360 public $brand_short_name = '';
361
362 /**
363 * @var string The model name.
364 * @since 1.0.0
365 */
366 public $model_name = '';
367
368 /**
369 * @var string The bot name.
370 * @since 1.0.0
371 */
372 public $bot_name = '';
373
374 /**
375 * @var string The bot category.
376 * @since 1.0.0
377 */
378 public $bot_category = '';
379
380 /**
381 * @var string The bot category translated if translation exists, else in english.
382 * @since 1.0.0
383 */
384 public $bot_full_category = '';
385
386 /**
387 * @var string The bot url.
388 * @since 1.0.0
389 */
390 public $bot_url = '';
391
392 /**
393 * @var string The bot producer name.
394 * @since 1.0.0
395 */
396 public $bot_producer_name = '';
397
398 /**
399 * @var string The bot producer url.
400 * @since 1.0.0
401 */
402 public $bot_producer_url = '';
403
404 }