From 27f79fdab080de2133f985d5f26799512ecf227a Mon Sep 17 00:00:00 2001 From: moodler Date: Tue, 12 Dec 2006 07:24:32 +0000 Subject: [PATCH] Added changes suggested by Nick in MDL-7883 to help debug XHTML strict It only affects DEBUG_DEVELOPER mode, and causes the browser to break when it encounters non-strict XHTML. I took out the changes for DEBUG_NORMAL for now, might be premature. --- lib/weblib.php | 63 +++++++++++++++++++++++++++++++++++++++++++++++--- lib/xhtml.xsl | 6 +++++ 2 files changed, 66 insertions(+), 3 deletions(-) create mode 100644 lib/xhtml.xsl diff --git a/lib/weblib.php b/lib/weblib.php index 9c4288cdd02..da18a0296b7 100644 --- a/lib/weblib.php +++ b/lib/weblib.php @@ -837,7 +837,9 @@ function print_checkbox ($name, $value, $checked = true, $label = '', $alt = '', $name = 'unnamed'; } - if (!$alt) { + if ($alt) { + $alt = strip_tags($alt); + } else { $alt = 'checkbox'; } @@ -2118,8 +2120,9 @@ function print_header ($title='', $heading='', $navigation='', $focus='', } @header('Accept-Ranges: none'); - if ($usexml) { // Added by Gustav Delius / Mad Alex for MathML output - // Modified by Julian Sedding + if (empty($usexml)) { + $direction = ' xmlns="http://www.w3.org/1999/xhtml"'. $direction; // See debug_header + } else { $currentlanguage = current_language(); $mathplayer = preg_match("/MathPlayer/i", $_SERVER['HTTP_USER_AGENT']); if(!$mathplayer) { @@ -2179,6 +2182,10 @@ function print_header ($title='', $heading='', $navigation='', $focus='', $output = ob_get_contents(); ob_end_clean(); + if (debugging(NULL, DEBUG_DEVELOPER)) { // In developer debugging mode, convert page to XHTML strict + $output = debug_header($output); + } + if (!empty($CFG->messaging)) { $output .= message_popup_window(); } @@ -2190,6 +2197,56 @@ function print_header ($title='', $heading='', $navigation='', $focus='', } } +/** + * Debugging aid: serve page as 'application/xhtml+xml' where possible, + * and substitute the XHTML strict document type. + * Note, requires the 'xmlns' fix in function print_header above. + * See: http://tracker.moodle.org/browse/MDL-7883 + * TODO: + */ +function debug_header($output) { + global $CFG; + $strict = ''; + $xsl = '/lib/xhtml.xsl'; + + if (!headers_sent()) { + $ctype = 'Content-Type: '; + $prolog= "\n"; + + if (isset($_SERVER['HTTP_ACCEPT']) + && false !== strpos($_SERVER['HTTP_ACCEPT'], 'application/xhtml+xml')) { + //|| false !== strpos($_SERVER['HTTP_USER_AGENT'], 'Safari') //Safari "Entity 'copy' not defined". + // Firefox et al. + $ctype .= 'application/xhtml+xml'; + $prolog .= "\n"; + + } else if (file_exists($CFG->dirroot.$xsl) + && preg_match('/MSIE.*Windows NT/', $_SERVER['HTTP_USER_AGENT'])) { + // XSL hack for IE 5+ on Windows. + //$www_xsl = preg_replace('/(http:\/\/.+?\/).*/', '', $CFG->wwwroot) .$xsl; + $www_xsl = $CFG->wwwroot .$xsl; + $ctype .= 'application/xml'; + $prolog .= "\n"; + $prolog .= "\n"; + + } else { + //ELSE: Mac/IE, old/non-XML browsers. + $ctype .= 'text/html'; + $prolog = ''; + } + @header($ctype.'; charset=utf-8'); + $output = $prolog . $output; + + // Test parser error-handling. + if (isset($_GET['error'])) { + $output .= "__ TEST: XML well-formed error < __\n"; + } + } + return $output; +} + + + /** * This version of print_header is simpler because the course name does not have to be * provided explicitly in the strings. It can be used on the site page as in courses diff --git a/lib/xhtml.xsl b/lib/xhtml.xsl new file mode 100644 index 00000000000..722eeacc008 --- /dev/null +++ b/lib/xhtml.xsl @@ -0,0 +1,6 @@ + + + +