/** * Use HTML Tidy to validate the $text * Only runs when $config['HTML_Tidy'] is off * * @param string $text The html content to be checked. Passed by reference */ static function tidyFix(&$text, $ignore_config = false) { global $config; if (!$ignore_config) { if (empty($config['HTML_Tidy']) || $config['HTML_Tidy'] == 'off') { return true; } } if (!function_exists('tidy_parse_string')) { return false; } $options = array(); $options['wrap'] = 0; //keeps tidy from wrapping... want the least amount of space changing as possible.. could get rid of spaces between words with the str_replaces below $options['doctype'] = 'omit'; //omit, auto, strict, transitional, user $options['drop-empty-paras'] = true; //drop empty paragraphs $options['output-xhtml'] = true; //need this so that <br> will be <br/> .. etc $options['show-body-only'] = true; $options['hide-comments'] = false; //$options['anchor-as-name'] = true; //default is true, but not alwasy availabel. When true, adds an id attribute to anchor; when false, removes the name attribute... poorly designed, but we need it to be true // // php4 // if (function_exists('tidy_setopt')) { $options['char-encoding'] = 'utf8'; gp_edit::tidyOptions($options); $tidy = tidy_parse_string($text); tidy_clean_repair(); if (tidy_get_status() === 2) { // 2 is magic number for fatal error // http://www.php.net/manual/en/function.tidy-get-status.php $tidyErrors[] = 'Tidy found serious XHTML errors: <br/>' . nl2br(htmlspecialchars(tidy_get_error_buffer($tidy))); return false; } $text = tidy_get_output(); // // php5 // } else { $tidy = tidy_parse_string($text, $options, 'utf8'); tidy_clean_repair($tidy); if (tidy_get_status($tidy) === 2) { // 2 is magic number for fatal error // http://www.php.net/manual/en/function.tidy-get-status.php $tidyErrors[] = 'Tidy found serious XHTML errors: <br/>' . nl2br(htmlspecialchars(tidy_get_error_buffer($tidy))); return false; } $text = tidy_get_output($tidy); } return true; }