* You can obtain one at http://mozilla.org/MPL/2.0/. */
include('../classes/useragent.php-class');
+include('../classes/document.php-class');
// read string from this file
$uafile = 'ua_list_raw.txt';
-print("<!DOCTYPE html>\n");
-print("<html>\n<head>\n");
-print(" <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\n");
-print(" <link rel=\"stylesheet\" type=\"text/css\" href=\"test.css\">\n");
-print(" <title>".'User Agents'."</title>\n");
-print("</head>\n<body>\n");
+// Start HTML document as a DOM object.
+extract(ExtendedDocument::initHTML5()); // sets $document, $html, $head, $title, $body
+$document->formatOutput = true; // we want a nice output
-print('<h1>User Agents</h1>'."\n");
+$style = $head->appendElement('link');
+$style->setAttribute('rel', 'stylesheet');
+$style->setAttribute('href', 'test.css');
+$title->appendText('User Agents');
+$h1 = $body->appendElement('h1', 'User Agents');
$ualist = is_readable($uafile)?file($uafile):array();
if (count($ualist)) {
- print('<table class="border" id="ualist">'."\n");
- print(' <tr>'."\n");
- print(' <th>User Agent string</th>'."\n");
- print(' <th>Brand</th>'."\n");
- print(' <th>Version</th>'."\n");
- print(' <th>Bot</th>'."\n");
- print(' <th>Mob</th>'."\n");
- print(' <th>Engine</th>'."\n");
- print(' <th>eVer</th>'."\n");
- print(' <th>OS</th>'."\n");
- print(' <th>Platform</th>'."\n");
- print(' <th>Lang</th>'."\n");
- print(' </tr>'."\n");
+ $tbl = $body->appendElement('table');
+ $tbl->setAttribute('class', 'border');
+ $tbl->setAttribute('id', 'ualist');
+ $thead = $tbl->appendElement('thead');
+ $trow = $thead->appendElement('tr');
+ $trow->appendElement('th', 'User Agent string');
+ $trow->appendElement('th', 'Brand');
+ $trow->appendElement('th', 'Version');
+ $trow->appendElement('th', 'Bot');
+ $trow->appendElement('th', 'Mob');
+ $trow->appendElement('th', 'Engine');
+ $trow->appendElement('th', 'eVer');
+ $trow->appendElement('th', 'OS');
+ $trow->appendElement('th', 'Platform');
+ $trow->appendElement('th', 'Lang');
+ $tbody = $tbl->appendElement('tbody');
foreach ($ualist as $uastring) {
$uastring = trim($uastring);
if (substr($uastring, 0, 1) == '#') {
// comment
- print(' <tr>'."\n");
- print(' <td colspan="10" class="comment">'.substr($uastring, 1).'</td>'."\n");
- print(' </tr>'."\n");
+ $trow = $tbody->appendElement('tr');
+ $cell = $trow->appendElement('td', substr($uastring, 1));
+ $cell->setAttribute('colspan', 10);
+ $cell->setAttribute('class', 'comment');
}
else {
$ua = new userAgent($uastring);
- print(' <tr>'."\n");
- print(' <td class="ua">'.$ua->getUAString().'</td>'."\n");
- print(' <td>'.$ua->getBrand().'</td>'."\n");
- print(' <td>'.$ua->getVersion().'</td>'."\n");
- print(' <td>'.($ua->isBot()?'x':'-').'</td>'."\n");
- print(' <td>'.($ua->isMobile()?'x':'-').'</td>'."\n");
- print(' <td>'.$ua->getEngine().'</td>'."\n");
- print(' <td>'.$ua->getEngineVersion().'</td>'."\n");
- print(' <td>'.$ua->getOS().'</td>'."\n");
- print(' <td>'.$ua->getPlatform().'</td>'."\n");
- print(' <td>'.$ua->getLanguage().'</td>'."\n");
- print(' </tr>'."\n");
+ $trow = $tbody->appendElement('tr');
+ $cell = $trow->appendElement('td', $ua->getUAString());
+ $cell->setAttribute('class', 'ua');
+ $trow->appendElement('td', $ua->getBrand());
+ $trow->appendElement('td', $ua->getVersion());
+ $trow->appendElement('td', ($ua->isBot()?'x':'-'));
+ $trow->appendElement('td', ($ua->isMobile()?'x':'-'));
+ $trow->appendElement('td', $ua->getEngine());
+ $trow->appendElement('td', $ua->getEngineVersion());
+ $trow->appendElement('td', $ua->getOS());
+ $trow->appendElement('td', $ua->getPlatform());
+ $trow->appendElement('td', $ua->getLanguage());
}
}
- print('</table>'."\n");
}
else {
- print('No User Agent strings found in file "'.$uafile.'".'."\n");
+ $body->appendElement('p', 'No User Agent strings found in file "'.$uafile.'".');
}
-print("<div id=\"copyright\">\n");
-print("Page code under Mozilla Public License, code available at <a href=\"https://github.com/KaiRo-at/php-utility-classes\">GitHub</a>.\n");
-print("</div>\n");
-print("</body></html>\n");
+$footer = $body->appendElement('footer', 'Page code under Mozilla Public License, code available at ');
+$footer->setAttribute('id', 'copyright');
+$footer->appendLink('https://github.com/KaiRo-at/php-utility-classes', 'GitHub');
+$footer->appendText('.');
+
+// Send HTML to client.
+print($document->saveHTML());
?>
* You can obtain one at http://mozilla.org/MPL/2.0/. */
include('../classes/useragent.php-class');
+include('../classes/document.php-class');
// set default time zone - right now, always the one the server is in!
date_default_timezone_set('Europe/Vienna');
-print("<!DOCTYPE html>\n");
-print("<html>\n<head>\n");
-print(" <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\n");
-print(" <link rel=\"stylesheet\" type=\"text/css\" href=\"test.css\">\n");
-print(" <title>".'User Agent Test'."</title>\n");
-print("</head>\n<body>\n");
+// Start HTML document as a DOM object.
+extract(ExtendedDocument::initHTML5()); // sets $document, $html, $head, $title, $body
+$document->formatOutput = true; // we want a nice output
+
+$style = $head->appendElement('link');
+$style->setAttribute('rel', 'stylesheet');
+$style->setAttribute('href', 'test.css');
+$title->appendText('User Agent Test');
+$h1 = $body->appendElement('h1', 'User Agent Test');
if (strlen($_REQUEST["ua"])) {
$ua = new userAgent($_REQUEST["ua"]);
$ua = new userAgent;
}
-print("<h1>User Agent Test</h1>\n");
-
-print("I read the following user agent string from ".(strlen($httpvars["ua"])?"your input":"your browser").":\n<br>");
-print("<b>".$ua->getUAString()."</b>\n");
+$para = $body->appendElement('p', 'I read the following user agent string from '.(strlen($httpvars['ua'])?'your input':'your browser').':');
+$para->appendElement('br');
+$para->appendElement('b', $ua->getUAString());
-print("<br><br>The browser brand is reported as "<b>".$ua->getBrand()."</b>"\n");
-print("<br>The browser version is reported as "<b>".$ua->getVersion()."</b>"\n");
-print("<br>The browser engine is reported as "<b>".$ua->getEngine()."</b>"\n");
-print("<br>The engine version is reported as "<b>".$ua->getEngineVersion()."</b>"\n");
-print("<br>The operating system is reported as "<b>".$ua->getOS()."</b>"\n");
-print("<br>The system platform is reported as "<b>".$ua->getPlatform()."</b>"\n");
-print("<br>The browser language is reported as "<b>".$ua->getLanguage()."</b>"\n");
+$ulist = $body->appendElement('ul');
+$ulist->setAttribute('class', 'flat');
+$litem = $ulist->appendElement('li');
+$litem->appendText('The browser brand is reported as "');
+$litem->appendElement('b', $ua->getBrand());
+$litem->appendText('"');
+$litem = $ulist->appendElement('li');
+$litem->appendText('The browser version is reported as "');
+$litem->appendElement('b', $ua->getVersion());
+$litem->appendText('"');
+$litem = $ulist->appendElement('li');
+$litem->appendText('The browser engine is reported as "');
+$litem->appendElement('b', $ua->getEngine());
+$litem->appendText('"');
+$litem = $ulist->appendElement('li');
+$litem->appendText('The engine version is reported as "');
+$litem->appendElement('b', $ua->getEngineVersion());
+$litem->appendText('"');
+$litem = $ulist->appendElement('li');
+$litem->appendText('The operating system is reported as "');
+$litem->appendElement('b', $ua->getOS());
+$litem->appendText('"');
+$litem = $ulist->appendElement('li');
+$litem->appendText('The system platform is reported as "');
+$litem->appendElement('b', $ua->getPlatform());
+$litem->appendText('"');
+$litem = $ulist->appendElement('li');
+$litem->appendText('The browser language is reported as "');
+$litem->appendElement('b', $ua->getLanguage());
+$litem->appendText('"');
if ($ua->hasEngine('gecko')) {
- print("<br>The Gecko date is reported as "<b>".$ua->getGeckoDate()."</b>"\n");
- print("<br>The full Gecko date/time is reported as "<b>".date('r',$ua->getGeckoTime())."</b>"\n");
+ $litem = $ulist->appendElement('li');
+ $litem->appendText('The Gecko date is reported as "');
+ $litem->appendElement('b', $ua->getGeckoDate());
+ $litem->appendText('"');
+ $litem = $ulist->appendElement('li');
+ $litem->appendText('The full Gecko date/time is reported as "');
+ $litem->appendElement('b', date('r',$ua->getGeckoTime()));
+ $litem->appendText('"');
+}
+$litem = $ulist->appendElement('li');
+$litem->setAttribute('class', 'summary');
+$litem->appendText('I conclude this must be ');
+$litem->appendElement('b', $ua->getBrand()." ".$ua->getVersion());
+$litem->appendText('.');
+$litem = $ulist->appendElement('li');
+$litem->appendText('This is ');
+$litem->appendElement('b', ($ua->isBot()?'an':'no'));
+$litem->appendText(' automated robot.');
+
+$para = $body->appendElement('p', 'Accepted Languages:');
+foreach ($acclang as $lang=>$q) {
+ $para->appendText($lang.'('.$q.') ');
}
-print("<br><br>I conclude this must be <b>".$ua->getBrand()." ".$ua->getVersion()."</b>\n");
-print("<br>This is <b>".($ua->isBot()?"an":"no")."</b> automated robot.\n");
-
-$acclang = $ua->getAcceptLanguages();
-print("<br><br>Accepted Languages: ");
-foreach ($acclang as $lang=>$q) { print($lang."(".$q.") "); }
-print("\n");
-
-print("<br><br>Test the following UA string (leave empty to read it from your browser):\n");
-print("<form method=\"POST\" action=\"\"><p>\n");
-print("<input type=\"text\" name=\"ua\" value=\"".htmlentities($ua->getUAString())."\" size=\"80\" maxlength=\"150\">\n");
-print("<br><input type=\"submit\" value=\"Test\"></p></form>\n");
-
-print("<div id=\"copyright\">\n");
-print("Page code under Mozilla Public License, code available at <a href=\"https://github.com/KaiRo-at/php-utility-classes\">GitHub</a>.\n");
-print("</div>\n");
-print("</body></html>\n");
+
+$para = $body->appendElement('p', 'Test the following UA string (leave empty to read it from your browser):');
+$form = $body->appendForm('', 'POST', 'uaform');
+$form->appendInputText('ua', 150, 80, null, $ua->getUAString());
+$form->appendElement('br');
+$form->appendInputSubmit(_('Test'));
+
+$footer = $body->appendElement('footer', 'Page code under Mozilla Public License, code available at ');
+$footer->setAttribute('id', 'copyright');
+$footer->appendLink('https://github.com/KaiRo-at/php-utility-classes', 'GitHub');
+$footer->appendText('.');
+
+// Send HTML to client.
+print($document->saveHTML());
?>