From 2427c0c50c2362b5be11000f41cbbaa7199fef09 Mon Sep 17 00:00:00 2001 From: Sam Minnee Date: Fri, 11 Jan 2008 00:10:27 +0000 Subject: [PATCH] #2094: Make ContentNegotiator send XHTML to the W3C validator git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@47875 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- core/control/ContentNegotiator.php | 33 ++++++++++++++++++------------ 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/core/control/ContentNegotiator.php b/core/control/ContentNegotiator.php index 3b537aded..ed3d54dda 100755 --- a/core/control/ContentNegotiator.php +++ b/core/control/ContentNegotiator.php @@ -44,20 +44,27 @@ class ContentNegotiator { $chosenFormat = $_GET['forceFormat']; } else { - foreach($mimes as $format => $mime) { - $regExp = '/' . str_replace(array('+','/'),array('\+','\/'), $mime) . '(;q=(\d+\.\d+))?/i'; - if (preg_match($regExp, $_SERVER['HTTP_ACCEPT'], $matches)) { - $preference = isset($matches[2]) ? $matches[2] : 1; - if(!isset($q[$preference])) $q[$preference] = $format; - } - } - - if($q) { - // Get the preferred format - krsort($q); - $chosenFormat = reset($q); + // The W3C validator doesn't send an HTTP_ACCEPT header, but it can support xhtml. We put this special case in here so that + // designers don't get worried that their templates are HTML4. + if(substr($_SERVER['HTTP_USER_AGENT'], 0, 14) == 'W3C_Validator/') { + $chosenFormat = "xhtml"; + } else { - $chosenFormat = "html"; + foreach($mimes as $format => $mime) { + $regExp = '/' . str_replace(array('+','/'),array('\+','\/'), $mime) . '(;q=(\d+\.\d+))?/i'; + if (preg_match($regExp, $_SERVER['HTTP_ACCEPT'], $matches)) { + $preference = isset($matches[2]) ? $matches[2] : 1; + if(!isset($q[$preference])) $q[$preference] = $format; + } + } + + if($q) { + // Get the preferred format + krsort($q); + $chosenFormat = reset($q); + } else { + $chosenFormat = "html"; + } } }