Are we sending the wrong Mime type?

Talk about writing modules and plugins for CMS Made Simple, or about specific core functionality. This board is for PHP programmers that are contributing to CMSMS not for site developers
Post Reply
mahjong

Are we sending the wrong Mime type?

Post by mahjong »

After reading this article, I'm not convince sending XHTML as text/html is what we should be doing.

As this other article points out,
some sites may wish to take advantage of the extensibility of XML, so delivering in XHTML with the correct MIME may be important.


The proposed solution is elegant, and could be integrate to CMSMS, but not without some major rethinking of the content postrender procedure (lines 276 in index.php) .

Code: Select all

$charset = (isset($pageinfo->template_encoding) && $pageinfo->template_encoding != ''?$pageinfo->template_encoding:get_encoding());
$mime = "text/html";
$language = "en"; // UNSOLVED YET- this settings should created and stored/linked somehow with the pages

function fix_code($buffer) {
	return (preg_replace("!\s*/>!", ">", $buffer));
}
	
if(stristr($_SERVER["HTTP_ACCEPT"],"application/xhtml+xml")) {
	if(preg_match("/application\/xhtml\+xml;q=([01]|0\.\d{1,3}|1\.0)/i",$_SERVER["HTTP_ACCEPT"],$matches)) {
		$xhtml_q = $matches[1];
		if(preg_match("/text\/html;q=q=([01]|0\.\d{1,3}|1\.0)/i",$_SERVER["HTTP_ACCEPT"],$matches)) {
			$html_q = $matches[1];
			if((float)$xhtml_q >= (float)$html_q) {
				$mime = "application/xhtml+xml";
			}
		}
	} else {
		$mime = "application/xhtml+xml";
	}
}

if($mime == "application/xhtml+xml") {
	$prolog_type = "<?xml version="1.0" encoding="$charset" ?>\n<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\n<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="$language" lang="$language">\n";
} else {
	ob_start("fix_code");
	$prolog_type = "<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">\n<html lang="$language">\n";
}
header("Content-Type: $mime;charset=$charset");
header("Vary: Accept");
print $prolog_type;  // UNSOLVED YET - an override needs to be available somehow
Last edited by mahjong on Sun Jul 23, 2006 8:36 pm, edited 1 time in total.
tsw
Power Poster
Power Poster
Posts: 1408
Joined: Tue Dec 13, 2005 10:50 pm
Location: Finland

Re: Are we sending the wrong Mime type?

Post by tsw »

There has been conversation about this earlier.

but no solution.

Im not entirely sure about some of those problems mentioned in first document.

Why would html4 be parsed better than xhtml send with wrong mimetype? (they both are handled by the same "tag soup" parser arent they)

as IE doesnt support xhtml (or anything else funny) I think that the best solution might be changing doctype...


or just wait for better times when all borwsers support all standards and render pages alike (and then I woke up)
Post Reply

Return to “Developers Discussion”