| 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 | // set default time zone - right now, always the one the server is in! |
| 10 | date_default_timezone_set('Europe/Vienna'); |
| 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 Agent Test'); |
| 20 | $h1 = $body->appendElement('h1', 'User Agent Test'); |
| 21 | |
| 22 | if (strlen($_REQUEST["ua"])) { |
| 23 | $ua = new userAgent($_REQUEST["ua"]); |
| 24 | } |
| 25 | else { |
| 26 | $ua = new userAgent; |
| 27 | } |
| 28 | |
| 29 | $para = $body->appendElement('p', 'I read the following user agent string from '.(strlen($httpvars['ua'])?'your input':'your browser').':'); |
| 30 | $para->appendElement('br'); |
| 31 | $para->appendElement('b', $ua->getUAString()); |
| 32 | |
| 33 | $ulist = $body->appendElement('ul'); |
| 34 | $ulist->setAttribute('class', 'flat'); |
| 35 | $litem = $ulist->appendElement('li'); |
| 36 | $litem->appendText('The browser brand is reported as "'); |
| 37 | $litem->appendElement('b', $ua->getBrand()); |
| 38 | $litem->appendText('"'); |
| 39 | $litem = $ulist->appendElement('li'); |
| 40 | $litem->appendText('The browser version is reported as "'); |
| 41 | $litem->appendElement('b', $ua->getVersion()); |
| 42 | $litem->appendText('"'); |
| 43 | $litem = $ulist->appendElement('li'); |
| 44 | $litem->appendText('The browser engine is reported as "'); |
| 45 | $litem->appendElement('b', $ua->getEngine()); |
| 46 | $litem->appendText('"'); |
| 47 | $litem = $ulist->appendElement('li'); |
| 48 | $litem->appendText('The engine version is reported as "'); |
| 49 | $litem->appendElement('b', $ua->getEngineVersion()); |
| 50 | $litem->appendText('"'); |
| 51 | $litem = $ulist->appendElement('li'); |
| 52 | $litem->appendText('The operating system is reported as "'); |
| 53 | $litem->appendElement('b', $ua->getOS()); |
| 54 | $litem->appendText('"'); |
| 55 | $litem = $ulist->appendElement('li'); |
| 56 | $litem->appendText('The system platform is reported as "'); |
| 57 | $litem->appendElement('b', $ua->getPlatform()); |
| 58 | $litem->appendText('"'); |
| 59 | $litem = $ulist->appendElement('li'); |
| 60 | $litem->appendText('The browser language is reported as "'); |
| 61 | $litem->appendElement('b', $ua->getLanguage()); |
| 62 | $litem->appendText('"'); |
| 63 | if ($ua->hasEngine('gecko')) { |
| 64 | $litem = $ulist->appendElement('li'); |
| 65 | $litem->appendText('The Gecko date is reported as "'); |
| 66 | $litem->appendElement('b', $ua->getGeckoDate()); |
| 67 | $litem->appendText('"'); |
| 68 | $litem = $ulist->appendElement('li'); |
| 69 | $litem->appendText('The full Gecko date/time is reported as "'); |
| 70 | $litem->appendElement('b', date('r',$ua->getGeckoTime())); |
| 71 | $litem->appendText('"'); |
| 72 | } |
| 73 | $litem = $ulist->appendElement('li'); |
| 74 | $litem->setAttribute('class', 'summary'); |
| 75 | $litem->appendText('I conclude this must be '); |
| 76 | $litem->appendElement('b', $ua->getBrand()." ".$ua->getVersion()); |
| 77 | $litem->appendText('.'); |
| 78 | $litem = $ulist->appendElement('li'); |
| 79 | $litem->appendText('This is '); |
| 80 | $litem->appendElement('b', ($ua->isBot()?'an':'no')); |
| 81 | $litem->appendText(' automated robot.'); |
| 82 | |
| 83 | $para = $body->appendElement('p', 'Accepted Languages:'); |
| 84 | foreach ($acclang as $lang=>$q) { |
| 85 | $para->appendText($lang.'('.$q.') '); |
| 86 | } |
| 87 | |
| 88 | $para = $body->appendElement('p', 'Test the following UA string (leave empty to read it from your browser):'); |
| 89 | $form = $body->appendForm('', 'POST', 'uaform'); |
| 90 | $form->appendInputText('ua', 150, 80, null, $ua->getUAString()); |
| 91 | $form->appendElement('br'); |
| 92 | $form->appendInputSubmit(_('Test')); |
| 93 | |
| 94 | $footer = $body->appendElement('footer', 'Page code under Mozilla Public License, code available at '); |
| 95 | $footer->setAttribute('id', 'copyright'); |
| 96 | $footer->appendLink('https://github.com/KaiRo-at/php-utility-classes', 'GitHub'); |
| 97 | $footer->appendText('.'); |
| 98 | |
| 99 | // Send HTML to client. |
| 100 | print($document->saveHTML()); |
| 101 | ?> |