add DomainCrawler to test list
[php-utility-classes.git] / tests / ua_list.php
CommitLineData
4a778b7e 1<?php
880bcb60
RK
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
39814159 6include('../classes/useragent.php-class');
432328ee 7include('../classes/document.php-class');
4a778b7e 8
9// read string from this file
10$uafile = 'ua_list_raw.txt';
11
432328ee
RK
12// Start HTML document as a DOM object.
13extract(ExtendedDocument::initHTML5()); // sets $document, $html, $head, $title, $body
14$document->formatOutput = true; // we want a nice output
4a778b7e 15
432328ee
RK
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');
4a778b7e 21
22$ualist = is_readable($uafile)?file($uafile):array();
23
24if (count($ualist)) {
432328ee
RK
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');
4a778b7e 40
432328ee 41 $tbody = $tbl->appendElement('tbody');
4a778b7e 42 foreach ($ualist as $uastring) {
43 $uastring = trim($uastring);
44 if (substr($uastring, 0, 1) == '#') {
45 // comment
432328ee
RK
46 $trow = $tbody->appendElement('tr');
47 $cell = $trow->appendElement('td', substr($uastring, 1));
48 $cell->setAttribute('colspan', 10);
49 $cell->setAttribute('class', 'comment');
4a778b7e 50 }
51 else {
52 $ua = new userAgent($uastring);
432328ee
RK
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());
4a778b7e 65 }
66 }
4a778b7e 67}
68else {
432328ee 69 $body->appendElement('p', 'No User Agent strings found in file "'.$uafile.'".');
4a778b7e 70}
71
432328ee
RK
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.
78print($document->saveHTML());
4a778b7e 79?>