Hey, I just came to the forums to post about this. People you can read up on why XHTML sent as text/html is bad here:
http://www.hixie.ch/advocacy/xhtml
Basically, sending xhtml as text/html makes the browsers interpret it as tag soup anyway.
Reasons XHTML is better:
1. It's been the W3C recommendation since 1999, replacing HTML 4.01. Thats 6 years.
2. It's a simple transition to learn as the Web moves toward increasingly more XML.
3. It's far more flexible than HTML with being accessible to wireless devices, screen readers and other devices for the disabled (which helps by leaps and bounds with meeting accessibility guidelines and the U.S. 508 guidelines ).
4. XHTML is a cleaner, more logical markup.
5. XHTML is faster to parse (must faster), and thus display.
6. I like the idea of giving the browser what it prefers.
7. Its extensible in lots of fancy ways none of us need.
And you are right, sending pages as application/xhtml+xml to IE causes it to prompt to download, which is why it is best to use content negotiation.
Content Negotiation gives browsers what they prefer, old browser like IE get html and new browser get XHTML. It not only sends the header, but converts the content.
See here for a nice thing on content negotiation:
http://www.autisticcuckoo.net/archive.p … egotiation
Delivering documents in XHTML causes lazily written javascript to break (due to reliance on innerhtml and document.write, rather then DOM methods like CreateElementNS()) and can cause CSS to be displayed differently.
Anyway, punbb does not work in xhtml mode. The forums function just fine, but the styles are all broken. I dont have the time right now to check out why. I just registered here on the forums to point this out, in hopes it will get fixed. Punbb is claiming XHTML support, but it isn't really
Anyway, I don't have too much time right now (which is why I haven't looked through the CSS files myself to find out why they are breaking - something I will attempt later tonight), so I gotta wrap this post up.
Here are some easy steps to add content negotiation to Punbb.
1. In header.php:
After the "Send no-cache headers" add:
$xhtml = false;
if (preg_match('/application\/xhtml\+xml(;q=(\d+\.\d+))?/i', $_SERVER['HTTP_ACCEPT'], $matches)) {
$xhtmlQ = isset($matches[2]) ? $matches[2] : 1;
if (preg_match('/text\/html(;q=(\d+\.\d+))?/i', $_SERVER['HTTP_ACCEPT'], $matches)) {
$htmlQ = isset($matches[2]) ? $matches[2] : 1;
$xhtml = ($xhtmlQ >= $htmlQ);
} else {
$xhtml = true;
}
}
// Here we can sniff the UA's and override the negotiated value if we want. While sniffing the UA is generaly not a good idea, there are cases where it
// is necessary or actually is a good idea. For example, here I am sniffing the WCC validators, because they do not properly declare XHTML support.
if(stristr($_SERVER["HTTP_USER_AGENT"],"W3C_Validator") ||
stristr($_SERVER["HTTP_USER_AGENT"],"W3C_CSS_Validator") ||
stristr($_SERVER["HTTP_USER_AGENT"],"WDG_Validator")) {
$xhtml = true;
}
Find this line in header.php:
<link rel="stylesheet" type="text/css" href="style/<?php echo $pun_user['style'].'.css' ?>" />
and change it to:
<link xmlns="http://www.w3.org/1999/xhtml" rel="stylesheet" type="text/css" href="style/<?php echo $pun_user['style'].'.css' ?>" />
2. Create xhtml.php in the include folder in punbb:
<?php
/* Here we give the browser the XHTML or HTML headers. We also give the correct document type declaration and document type declaration, and language tag */
if ((isset($xhtml)) and ($xhtml)) {
$headerstring = 'Content-Type: application/xhtml+xml; charset=' . $lang_common['lang_encoding'];
header($headerstring);
echo '<?xml version="1.0" encoding="utf-8"?>', "\n";
echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">', "\n";
echo '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"';
} else {
$headerstring = 'Content-Type: text/html; charset=' . $lang_common['lang_encoding'];
header($headerstring);
echo '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/DTD/strict.dtd">', "\n";
echo '<html lang="en"';
}
?>
3. Edit template files (given stock templates). Take everything before pun_head, and remove it and replace with:
<pun_include "include/xhtml.php"> dir="<pun_content_direction>">
4. Edit footer.php. Write before the end, before "// Spit out the page" add:
// If page is being delivered as HTML, take the buffer and convert it to HTML
if ($xhtml != "true") {
$xml = array('/>', 'xml:lang=', 'xmlns="http://www.w3.org/1999/xhtml"');
$html = array('>', 'lang=', '');
$tpl_main = str_replace($xml, $html, $tpl_main);
}
Upload these changed files, and now in XHTML capable browsers, the page will be delivered with the correct xhtml headers. On html page, the page will be converted to html (the conversion is all I need, your xhtml app might require additional conversion, although probably not unless you are using xhtml specific extensions like mathml). with the appropriate headers.
If your site is like mine, you will see that the styles of punbb are no longer properly applied.
I like to add a query string that lets me force either html or xhtml for testing. In header.php AFTER the content stuff we added, add:
/* I want to give a query string option to override this content negotiation. So, lets check for two force queries and set our output o match */
if (isset($forcexhtml) and $forcexhtml == "true") {
$xhtml = true;
}
if (isset($forcehtml) and forcehtml == "true") {
$xhtml = false;
}
That will give you querry strings to force the output either way (if you have register globals off, you'll have to compensate).
So, anyway I gotta run, and I'll look into this more later, but this is the only thing I've ran into with punbb. Hopefully we can fix it so punbb has *real* xhtml support.