add MJ12bot to tests
[php-utility-classes.git] / tests / ua_list.php
1 <?php
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
4  * You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6 include('../classes/useragent.php-class');
7 include('../classes/document.php-class');
8
9 // read string from this file
10 $uafile = 'ua_list_raw.txt';
11
12 // Start HTML document as a DOM object.
13 extract(ExtendedDocument::initHTML5()); // sets $document, $html, $head, $title, $body
14 $document->formatOutput = true; // we want a nice output
15
16 $style = $head->appendElement('link');
17 $style->setAttribute('rel', 'stylesheet');
18 $style->setAttribute('href', 'test.css');
19 $title->appendText('User Agents');
20 $h1 = $body->appendElement('h1', 'User Agents');
21
22 $ualist = is_readable($uafile)?file($uafile):array();
23
24 if (count($ualist)) {
25   $tbl = $body->appendElement('table');
26   $tbl->setAttribute('class', 'border');
27   $tbl->setAttribute('id', 'ualist');
28   $thead = $tbl->appendElement('thead');
29   $trow = $thead->appendElement('tr');
30   $trow->appendElement('th', 'User Agent string');
31   $trow->appendElement('th', 'Brand');
32   $trow->appendElement('th', 'Version');
33   $trow->appendElement('th', 'Bot');
34   $trow->appendElement('th', 'Mob');
35   $trow->appendElement('th', 'Engine');
36   $trow->appendElement('th', 'eVer');
37   $trow->appendElement('th', 'OS');
38   $trow->appendElement('th', 'Platform');
39   $trow->appendElement('th', 'Lang');
40
41   $tbody = $tbl->appendElement('tbody');
42   foreach ($ualist as $uastring) {
43     $uastring = trim($uastring);
44     if (substr($uastring, 0, 1) == '#') {
45       // comment
46       $trow = $tbody->appendElement('tr');
47       $cell = $trow->appendElement('td', substr($uastring, 1));
48       $cell->setAttribute('colspan', 10);
49       $cell->setAttribute('class', 'comment');
50     }
51     else {
52       $ua = new userAgent($uastring);
53       $trow = $tbody->appendElement('tr');
54       $cell = $trow->appendElement('td', $ua->getUAString());
55       $cell->setAttribute('class', 'ua');
56       $trow->appendElement('td', $ua->getBrand());
57       $trow->appendElement('td', $ua->getVersion());
58       $trow->appendElement('td', ($ua->isBot()?'x':'-'));
59       $trow->appendElement('td', ($ua->isMobile()?'x':'-'));
60       $trow->appendElement('td', $ua->getEngine());
61       $trow->appendElement('td', $ua->getEngineVersion());
62       $trow->appendElement('td', $ua->getOS());
63       $trow->appendElement('td', $ua->getPlatform());
64       $trow->appendElement('td', $ua->getLanguage());
65     }
66   }
67 }
68 else {
69   $body->appendElement('p', 'No User Agent strings found in file "'.$uafile.'".');
70 }
71
72 $footer = $body->appendElement('footer', 'Page code under Mozilla Public License, code available at ');
73 $footer->setAttribute('id', 'copyright');
74 $footer->appendLink('https://github.com/KaiRo-at/php-utility-classes', 'GitHub');
75 $footer->appendText('.');
76
77 // Send HTML to client.
78 print($document->saveHTML());
79 ?>