Welcome to mirror list, hosted at ThFree Co, Russian Federation.

UserAgentParserEnhanced.php « UserAgentParserEnhanced « DevicesDetection « plugins - github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 9031b0fd33e727e410978e2b6d8706b174c18bdb (plain)
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
<?php

/**
 * Piwik - Open source web analytics
 *
 * @link http://piwik.org
 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
 *
 * @category Piwik_Plugins
 * @package Piwik_DevicesDetection
 */
//yml parser
require_once('spyc.php');

class UserAgentParserEnhanced
{

    public static $deviceTypes = array('car browser', 'console', 'desktop', 'feature phone', 'smartphone', 'tablet', 'tv');
    public static $deviceBrands = array(
        'AC' => 'Acer',
        'AI' => 'Airness',
        'AL' => 'Alcatel',
        'AO' => 'Amoi',
        'AP' => 'Apple',
        'AU' => 'Asus',
        'AV' => 'Avvio',
        'AX' => 'Audiovox',
        'BE' => 'Becker',
        'BI' => 'Bird',
        'BL' => 'Beetel',
        'BQ' => 'BenQ',
        'BS' => 'BenQ-Siemens',
        'CK' => 'Cricket',
        'CL' => 'Compal',
        'CT' => 'Capitel',
        'DB' => 'Dbtel',
        'DC' => 'DoCoMo',
        'DI' => 'Dicam',
        'DL' => 'Dell',
        'DP' => 'Dopod',
        'EC' => 'Ericsson',
        'EI' => 'Ezio',
        'ER' => 'Ericy',
        'ET' => 'eTouch',
        'EZ' => 'Ezze',
        'FL' => 'Fly',
        'GI' => 'Gionee',
        'GO' => 'Google',
        'GR' => 'Gradiente',
        'GU' => 'Grundig',
        'HA' => 'Haier',
        'HP' => 'HP',
        'HT' => 'HTC',
        'HU' => 'Huawei',
        'IK' => 'iKoMo',
        'IM' => 'i-mate',
        'IN' => 'Innostream',
        'IO' => 'i-mobile',
        'IQ' => 'INQ',
        'KA' => 'Karbonn',
        'KD' => 'KDDI',
        'KN' => 'Kindle',
        'KO' => 'Konka',
        'KY' => 'Kyocera',
        'LA' => 'Lanix',
        'LC' => 'LCT',
        'LE' => 'Lenovo',
        'LG' => 'LG',
        'LU' => 'LGUPlus',
        'MI' => 'MicroMax',
        'MO' => 'Mio',
        'MR' => 'Motorola',
        'MS' => 'Microsoft',
        'MT' => 'Mitsubishi',
        'MY' => 'MyPhone',
        'NE' => 'NEC',
        'NG' => 'NGM',
        'NI' => 'Nintendo',
        'NK' => 'Nokia',
        'NW' => 'Newgen',
        'NX' => 'Nexian',
        'OD' => 'Onda',
        'OP' => 'OPPO',
        'OR' => 'Orange',
        'OT' => 'O2',
        'PA' => 'Panasonic',
        'PH' => 'Philips',
        'PM' => 'Palm',
        'PO' => 'phoneOne',
        'PT' => 'Pantech',
        'QT' => 'Qtek',
        'RM' => 'RIM',
        'RO' => 'Rover',
        'SA' => 'Samsung',
        'SD' => 'Sega',
        'SE' => 'Sony Ericsson',
        'SF' => 'Softbank',
        'SG' => 'Sagem',
        'SH' => 'Sharp',
        'SI' => 'Siemens',
        'SN' => 'Sendo',
        'SO' => 'Sony',
        'SP' => 'Spice',
        'SY' => 'Sanyo',
        'TA' => 'Tesla',
        'TC' => 'TCL',
        'TE' => 'Telit',
        'TH' => 'TiPhone',
        'TI' => 'TIANYU',
        'TM' => 'T-Mobile',
        'TO' => 'Toplux',
        'TS' => 'Toshiba',
        'UT' => 'UTStarcom',
        'VD' => 'Videocon',
        'VE' => 'Vertu',
        'VI' => 'Vitelcom',
        'VK' => 'VK Mobile',
        'VO' => 'Voxtel',
        'WB' => 'Web TV',
        'WE' => 'WellcoM',
        'WO' => 'Wonu',
        'XX' => 'Unknown',
        'ZO' => 'Zonda',
        'ZT' => 'ZTE',
    );
    public static $osShorts = array(
        'AIX' => 'AIX',
        'Android' => 'AND',
        'Apple TV' => 'ATV',
        'Arch Linux' => 'ARL',
        'BackTrack' => 'BTR',
        'Bada' => 'SBA',
        'BlackBerry OS' => 'BLB',
        'BlackBerry Tablet OS' => 'QNX',
        'Bot' => 'BOT',
        'Brew' => 'BMP',
        'CentOS' => 'CES',
        'Chrome OS' => 'COS',
        'Debian' => 'DEB',
        'DragonFly' => 'DFB',
        'Fedora' => 'FED',
        'Firefox OS' => 'FOS',
        'FreeBSD' => 'BSD',
        'Gentoo' => 'GNT',
        'Google TV' => 'GTV',
        'HP-UX' => 'HPX',
        'IRIX' => 'IRI',
        'Knoppix' => 'KNO',
        'Kubuntu' => 'KBT',
        'Linux' => 'LIN',
        'Lubuntu' => 'LBT',
        'Mac' => 'MAC',
        'Mandriva' => 'MDR',
        'MeeGo' => 'SMG',
        'Mint' => 'MIN',
        'NetBSD' => 'NBS',
        'Nintendo' => 'WII',
        'Nintendo Mobile' => 'NDS',
        'OS/2' => 'OS2',
        'OSF1' => 'T64',
        'OpenBSD' => 'OBS',
        'PlayStation' => 'PSP',
        'PlayStation 3' => 'PS3',
        'Presto' => 'PRS',
        'Puppy' => 'PPY',
        'Red Hat' => 'RHT',
        'SUSE' => 'SSE',
        'Slackware' => 'SLW',
        'Solaris' => 'SOS',
        'Syllable' => 'SYL',
        'Symbian' => 'SYM',
        'Symbian OS' => 'SYS',
        'Symbian OS Series 40' => 'S40',
        'Symbian OS Series 60' => 'S60',
        'Symbian^3' => 'SY3',
        'Talkatone' => 'TKT',
        'Tizen' => 'TIZ',
        'Ubuntu' => 'UBT',
        'WebTV' => 'WTV',
        'WinWAP' => 'WWP',
        'Windows' => 'WIN',
        'Windows 2000' => 'W2K',
        'Windows 3.1' => 'W31',
        'Windows 7' => 'WI7',
        'Windows 8' => 'WI8',
        'Windows 95' => 'W95',
        'Windows 98' => 'W98',
        'Windows CE' => 'WCE',
        'Windows ME' => 'WME',
        'Windows Mobile' => 'WMO',
        'Windows NT' => 'WNT',
        'Windows Phone' => 'WPH',
        'Windows RT' => 'WRT',
        'Windows Server 2003' => 'WS3',
        'Windows Vista' => 'WVI',
        'Windows XP' => 'WXP',
        'Xbox' => 'XBX',
        'Xubuntu' => 'XBT',
        'YunOs' => 'YNS',
        'iOS' => 'IOS',
        'palmOS' => 'POS',
        'webOS' => 'WOS'
    );
    protected static $desktopOsArray = array('IBM', 'Linux', 'Mac', 'Unix', 'Windows');
    public static $osFamilies = array(
        'Android' => array('AND'),
        'Apple TV' => array('ATV'),
        'BlackBerry' => array('BLB'),
        'Bot' => array('BOT'),
        'Brew' => array('BMP'),
        'Chrome OS' => array('COS'),
        'Firefox OS' => array('FOS'),
        'Gaming Console' => array('WII', 'PS3'),
        'Google TV' => array('GTV'),
        'IBM' => array('OS2'),
        'iOS' => array('IOS'),
        'Linux' => array('LIN', 'ARL', 'DEB', 'KNO', 'MIN', 'UBT', 'KBT', 'XBT', 'LBT', 'FED', 'RHT', 'MDR', 'GNT', 'SLW', 'SSE', 'PPY', 'CES', 'BTR', 'YNS', 'PRS'),
        'Mac' => array('MAC'),
        'Mobile Gaming Console' => array('PSP', 'NDS', 'XBX'),
        'Other Mobile' => array('WOS', 'POS', 'QNX', 'SBA', 'TIZ'),
        'Simulator' => array('TKT', 'WWP'),
        'Symbian' => array('SYM', 'SYS', 'SY3', 'S60', 'S40', 'SMG'),
        'Unix' => array('SOS', 'AIX', 'HPX', 'BSD', 'NBS', 'OBS', 'DFB', 'SYL', 'IRI', 'T64'),
        'WebTV' => array('WTV'),
        'Windows' => array('WI8', 'WI7', 'WVI', 'WS3', 'WXP', 'W2K', 'WNT', 'WME', 'W98', 'W95', 'WRT', 'W31', 'WIN'),
        'Windows Mobile' => array('WPH', 'WMO', 'WCE')
    );
    public static $browserFamilies = array(
        'Android Browser' => array('AN'),
        'BlackBerry Browser' => array('BB'),
        'Chrome' => array('CH', 'CM', 'CI', 'CF', 'CR', 'RM'),
        'Firefox' => array('FF', 'FE', 'SX', 'FB', 'PX', 'MB'),
        'Internet Explorer' => array('IE', 'IM'),
        'Konqueror' => array('KO'),
        'NetFront' => array('NF'),
        'Nokia Browser' => array('NB'),
        'Opera' => array('OP', 'OM', 'OI'),
        'Safari' => array('SF', 'MF')
    );
    public static $browsers = array(
        'AB' => 'ABrowse',
        'AM' => 'Amaya',
        'AN' => 'Android Browser',
        'AR' => 'Arora',
        'AV' => 'Amiga Voyager',
        'AW' => 'Amiga Aweb',
        'BB' => 'BlackBerry Browser',
        'BD' => 'Baidu Browser',
        'BE' => 'Beonex',
        'BX' => 'BrowseX',
        'CA' => 'Camino',
        'CF' => 'Chrome Frame',
        'CH' => 'Chrome',
        'CI' => 'Chrome Mobile iOS',
        'CK' => 'Conkeror',
        'CM' => 'Chrome Mobile',
        'CO' => 'CometBird',
        'CR' => 'Chromium',
        'CS' => 'Cheshire',
        'DF' => 'Dolphin',
        'DI' => 'Dillo',
        'EL' => 'Elinks',
        'EP' => 'Epiphany',
        'FB' => 'Firebird',
        'FD' => 'Fluid',
        'FE' => 'Fennec',
        'FF' => 'Firefox',
        'FL' => 'Flock',
        'FN' => 'Fireweb Navigator',
        'GA' => 'Galeon',
        'GE' => 'Google Earth',
        'HJ' => 'HotJava',
        'IB' => 'IBrowse',
        'IC' => 'iCab',
        'IE' => 'Internet Explorer',
        'IM' => 'IE Mobile',
        'IR' => 'Iron',
        'JS' => 'Jasmine',
        'KI' => 'Kindle Browser',
        'KM' => 'K-meleon',
        'KO' => 'Konqueror',
        'KP' => 'Kapiko',
        'KZ' => 'Kazehakase',
        'LG' => 'Lightning',
        'LI' => 'Links',
        'LX' => 'Lynx',
        'MB' => 'MicroB',
        'MC' => 'NCSA Mosaic',
        'MF' => 'Mobile Safari',
        'MI' => 'Midori',
        'MS' => 'Mobile Silk',
        'MX' => 'Maxthon',
        'NB' => 'Nokia Browser',
        'NF' => 'NetFront',
        'NL' => 'NetFront Life',
        'NS' => 'Netscape',
        'OB' => 'Obigo',
        'OI' => 'Opera Mini',
        'OM' => 'Opera Mobile',
        'OP' => 'Opera',
        'OV' => 'Openwave Mobile Browser',
        'OW' => 'OmniWeb',
        'PL' => 'Palm Blazer',
        'PR' => 'Palm Pre',
        'PX' => 'Phoenix',
        'RK' => 'Rekonq',
        'RM' => 'RockMelt',
        'SF' => 'Safari',
        'SM' => 'SeaMonkey',
        'SN' => 'Snowshoe',
        'SX' => 'Swiftfox',
        'TZ' => 'Tizen Browser',
        'UC' => 'UC Browser',
        'WO' => 'wOSBrowser',
        'YA' => 'Yandex Browser'
    );

    const UNKNOWN = "UNK";
    protected static $regexesDir = '/regexes/';
    protected static $osRegexesFile = 'oss.yml';
    protected static $browserRegexesFile = 'browsers.yml';
    protected static $mobileRegexesFile = 'mobiles.yml';
    protected $userAgent;
    protected $os;
    protected $browser;
    protected $device;
    protected $brand;
    protected $model;
    protected $debug = false;

    public function __construct($userAgent)
    {
        $this->userAgent = $userAgent;
    }

    protected function getOsRegexes()
    {
        return Spyc::YAMLLoad(__DIR__ . self::$regexesDir . self::$osRegexesFile);
    }

    protected function getBrowserRegexes()
    {
        return Spyc::YAMLLoad(__DIR__ . self::$regexesDir . self::$browserRegexesFile);
    }

    protected function getMobileRegexes()
    {
        return Spyc::YAMLLoad(__DIR__ . self::$regexesDir . self::$mobileRegexesFile);
    }

    public function parse()
    {
        $this->parseOs();
        if ($this->isBot() || $this->isSimulator())
            return;

        $this->parseBrowser();

        if ($this->isMobile()) {
            $this->parseMobile();
        } else {
            $this->device = array_search('desktop', self::$deviceTypes);
        }
        if ($this->debug) {
            var_dump($this->brand, $this->model, $this->device);
        }
    }

    protected function parseOs()
    {
        foreach ($this->getOsRegexes() as $osRegex) {
            $matches = $this->matchUserAgent($osRegex['regex']);
            if ($matches)
                break;
        }

        if (!$matches)
            return;

        if (in_array($osRegex['name'], self::$osShorts)) {
            $short = self::$osShorts[$osRegex['name']];
        } else {
            $short = 'UNK';
        }

        $this->os = array(
            'name' => $this->buildOsName($osRegex['name'], $matches),
            'short_name' => $short,
            'version' => $this->buildOsVersion($osRegex['version'], $matches)
        );

        if (array_key_exists($this->os['name'], self::$osShorts)) {
            $this->os['short_name'] = self::$osShorts[$this->os['name']];
        }
    }

    protected function parseBrowser()
    {
        foreach ($this->getBrowserRegexes() as $browserRegex) {
            $matches = $this->matchUserAgent($browserRegex['regex']);
            if ($matches)
                break;
        }

        if (!$matches)
            return;

        if (in_array($browserRegex['name'], self::$browsers)) {
            $short = array_search($browserRegex['name'], self::$browsers);
        } else {
            $short = 'XX';
        }

        $this->browser = array(
            'name' => $this->buildBrowserName($browserRegex['name'], $matches),
            'short_name' => $short,
            'version' => $this->buildBrowserVersion($browserRegex['version'], $matches)
        );
    }

    protected function parseMobile()
    {
        $mobileRegexes = $this->getMobileRegexes();
        $this->parseBrand($mobileRegexes);
        $this->parseModel($mobileRegexes);
    }

    protected function parseBrand($mobileRegexes)
    {
        foreach ($mobileRegexes as $brand => $mobileRegex) {
            $matches = $this->matchUserAgent($mobileRegex['regex']);
            if ($matches)
                break;
        }

        if (!$matches)
            return;
        $this->brand = array_search($brand, self::$deviceBrands);
        $this->fullName = $brand;

        if (isset($mobileRegex['device'])) {
            $this->device = array_search($mobileRegex['device'],self::$deviceTypes);
        }

        if (isset($mobileRegex['model'])) {
            $this->model = $this->buildModel($mobileRegex['model'], $matches);
        }
    }

    protected function parseModel($mobileRegexes)
    {
        if (empty($this->brand) || !empty($this->model))
            return;

        foreach ($mobileRegexes[$this->fullName]['models'] as $modelRegex) {
            $matches = $this->matchUserAgent($modelRegex['regex']);
            if ($matches)
                break;
        }

        if (!$matches) {
            return;
        }

        $this->model = $this->buildModel($modelRegex['model'], $matches);

        if (isset($modelRegex['device'])) {
            $this->device = array_search($modelRegex['device'], self::$deviceTypes);
        }
    }

    protected function matchUserAgent($regex)
    {
        $regex = '/' . str_replace('/', '\/', $regex) . '/i';

        if (preg_match($regex, $this->userAgent, $matches)) {
            return $matches;
        }

        return false;
    }

    protected function buildOsName($osName, $matches)
    {
        return $this->buildByMatch($osName, $matches);
    }

    protected function buildOsVersion($osVersion, $matches)
    {
        $osVersion = $this->buildByMatch($osVersion, $matches);

        $osVersion = $this->buildByMatch($osVersion, $matches, '2');

        $osVersion = str_replace('_', '.', $osVersion);

        return $osVersion;
    }

    protected function buildBrowserName($browserName, $matches)
    {
        return $this->buildByMatch($browserName, $matches);
    }

    protected function buildBrowserVersion($browserVersion, $matches)
    {
        $browserVersion = $this->buildByMatch($browserVersion, $matches);

        $browserVersion = $this->buildByMatch($browserVersion, $matches, '2');

        $browserVersion = str_replace('_', '.', $browserVersion);

        return $browserVersion;
    }

    protected function buildModel($model, $matches)
    {
        $model = $this->buildByMatch($model, $matches);

        $model = $this->buildByMatch($model, $matches, '2');

        $model = $this->buildModelExceptions($model);

        $model = str_replace('_', ' ', $model);

        return $model;
    }

    protected function buildModelExceptions($model)
    {
        if ($this->brand == 'O2') {
            $model = preg_replace('/([a-z])([A-Z])/', '$1 $2', $model);
            $model = ucwords(str_replace('_', ' ', $model));
        }

        return $model;
    }

    /**
     * This method is used in this class for processing results of pregmatch 
     * results into string containing recognized information.
     * 
     * General algorithm:
     * Parsing UserAgent string consists of trying to match it against list of
     * regular expressions for three different information: 
     * browser + version,
     * OS + version, 
     * device manufacturer + model. 
     * 
     * After match has been found iteration stops, and results are processed 
     * by buildByMatch.
     * As $item we get decoded name (name of browser, name of OS, name of manufacturer).
     * In array $match we recieve preg_match results containing whole string matched at index 0
     * and following matches in further indexes. Desired action now is to concatenate
     * decoded name ($item) with matches found. First step is to append first found match,
     * which is located in index=1 (that's why $nb is 1 by default).
     * In other cases, where whe know that preg_match may return more than 1 result,
     * we call buildByMatch with $nb = 2 or more, depending on what will be returned from
     * regular expression.
     * 
     * Example:
     * We are parsing UserAgent of Firefox 20.0 browser. 
     * UserAgentParserEnhanced calls buildBrowserName() and buildBrowserVersion() in order
     * to retrieve those information.
     * In buildBrowserName() we only have one call of buildByMatch, where passed argument
     * is regular expression testing given string for browser name. In this case, we are only
     * interrested in first hit, so no $nb parameter will be set to 1. After finding match, and calling
     * buildByMatch - we will receive just the name of browser.
     * 
     * Also after decoding browser we will get list of regular expressions for this browser name
     * testing UserAgent string for version number. Again we iterate over this list, and after finding first
     * occurence - we break loop and proceed to build by match. Since browser regular expressions can
     * contain two hits (major version and minor version) in function buildBrowserVersion() we have
     * two calls to buildByMatch, one without 3rd parameter, and second with $nb set to 2.
     * This way we can retrieve version number, and assign it to object property.
     * 
     * In case of mobiles.yml this schema slightly varies, but general idea is the same.
     * 
     * @param string $item
     * @param array $matches
     * @param int $nb
     * @return type
     */
    protected function buildByMatch($item, $matches, $nb = '1')
    {
        if (strpos($item, '$' . $nb) === false)
            return $item;

        $replace = isset($matches[$nb]) ? $matches[$nb] : '';
        return trim(str_replace('$' . $nb, $replace, $item));
    }

    public function isBot()
    {
        $decodedFamily = '';
        if (in_array($this->getOs('name'), self::$osShorts)) {
            $osShort = self::$osShorts[$this->getOs('name')];
        } else {
            $osShort = '';
        }
        foreach (self::$osFamilies as $family => $familyOs) {
            if (in_array($osShort, $familyOs)) {
                $decodedFamily = $family;
                break;
            }
        }

        return $decodedFamily == 'Bot';
    }

    public function isSimulator()
    {
        $decodedFamily = '';
        if (in_array($this->getOs('name'), self::$osShorts)) {
            $osShort = self::$osShorts[$this->getOs('name')];
        } else {
            $osShort = '';
        }
        foreach (self::$osFamilies as $family => $familyOs) {
            if (in_array($osShort, $familyOs)) {
                $decodedFamily = $family;
                break;
            }
        }
        return $decodedFamily == 'Simulator';
    }

    public function isMobile()
    {
        return !$this->isDesktop();
    }

    public function isDesktop()
    {
        $osName = $this->getOs('name');
        if (empty($osName) || empty(self::$osShorts[$osName])) {
            return false;
        }

        $osShort = self::$osShorts[$osName];
        foreach (self::$osFamilies as $family => $familyOs) {
            if (in_array($osShort, $familyOs)) {
                $decodedFamily = $family;
                break;
            }
        }
        return in_array($decodedFamily, self::$desktopOsArray);
    }

    public function getOs($attr = '')
    {
        if ($attr == '') {
            return $this->os;
        }

        if (!isset($this->os[$attr])) {
            return self::UNKNOWN;
        }

        if ($attr == 'version') {
            $this->os['version'] = $this->os['version'];
        }
        return $this->os[$attr];
    }

    public function getBrowser($attr = '')
    {
        if ($attr == '') {
            return $this->browser;
        }

        if (!isset($this->browser[$attr])) {
            return self::UNKNOWN;
        }

        return $this->browser[$attr];
    }

    public function getDevice()
    {
        return $this->device;
    }

    public function getBrand()
    {
        return $this->brand;
    }

    public function getModel()
    {
        return $this->model;
    }

    public function getUserAgent()
    {
        return $this->userAgent;
    }

    public static function getOsFamily($osLabel)
    {
        $osShortName = substr($osLabel, 0, 3);

        foreach (self::$osFamilies as $osFamily => $osShortNames) {
            if (in_array($osShortName, $osShortNames)) {
                return $osFamily;
            }
        }

        return 'Other';
    }

    public static function getBrowserFamily($browserLabel)
    {
        foreach (self::$browserFamilies as $browserFamily => $browserShortNames) {
            if (in_array($browserLabel, $browserShortNames)) {
                return $browserFamily;
            }
        }

        return 'Other';
    }

}