19 include_once($ROOT_PATH.
'wysiwyg_plugin.inc');
20 require_once SQ_DATA_PATH.
'/private/conf/tools.inc';
46 var $_new_inline_tags = Array();
53 var $_show_in_toolbar = FALSE;
61 var $htmltidy_status =
'pass';
63 var $htmltidy_errors = NULL;
66 var $html_standards = Array(
67 'HTML_4.01_Transitional' =>
'<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">',
68 'HTML_4.01_Strict' =>
'<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> ',
69 'HTML_4.01_Frameset' =>
'<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">',
70 'XHTML_1.0_Strict' =>
'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">',
71 'XHTML_1.0_Transitional' =>
'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">',
72 'XHTML_1.0_Frameset' =>
'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">',
73 'XHTML_1.1' =>
'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">',
100 if (in_array($tag_name, $this->_new_inline_tags)) {
103 $this->_new_inline_tags[] = $tag_name;
119 $this->htmltidy_status =
'pass';
121 if (!file_exists(SQ_TOOL_HTML_TIDY_PATH)) {
123 $this->htmltidy_status =
'disabled';
124 }
else if (empty($html)) {
135 $search = Array(
'%u2018',
'%u2019',
'%u2013',
'%u2014',
'%u2026',
'%u201C',
'%u201D');
136 $replace = Array(
'‘',
'’',
'–',
'—',
'…',
'“',
'”');
137 $html = str_replace($search, $replace, $html);
142 if (SQ_CONF_DEFAULT_CHARACTER_SET !=
'utf-8') {
143 $html = str_replace(chr(145),
'‘', $html);
144 $html = str_replace(chr(146),
'’', $html);
145 $html = str_replace(chr(147),
'“', $html);
146 $html = str_replace(chr(148),
'”', $html);
147 $html = str_replace(chr(149),
'–', $html);
148 $html = str_replace(chr(150),
'–', $html);
149 $html = str_replace(chr(151),
'—', $html);
153 $html = preg_replace(
'/%u([0-9A-Fa-f]{4})/',
'&#x$1;', $html);
160 $html = preg_replace(
'|<([\w]+)([^>]+?)class="?mso[^">]+"?([^>]+)?>|is',
'<\\1>', $html);
161 $html = preg_replace(
'|<([\w]+)([^>]+?)style="([^"]+)?mso([^"]+)?"([^>]+)?>|is',
'<\\1>', $html);
162 $html = preg_replace(
'|<\/?\w+:[^>]*>|is',
'', $html);
163 $html = preg_replace(
'|<font[^>]+>(.+?)</font>|is',
'\\1', $html);
164 $html = preg_replace(
'|<span([^>]+?)lang=[^\s]+([^>]+?)xml:lang="[^\s]+">(.+?)</span>|is',
'\\3', $html);
165 $html = preg_replace(
'|<\?xml[^>]+microsoft[^>]+\?>|is',
'', $html);
166 $html = preg_replace(
'|<\/?\w+:[^>]*>|is',
'', $html);
167 $html = preg_replace(
'|<\\?\??xml[^>]>|is',
'', $html);
170 $html = preg_replace(
'|<script\b[^>]*>(.*?)</script>|is',
'', $html);
178 require SQ_FUDGE_PATH.
'/standards_lists/character_sets.inc';
179 $tidy_char_set = array_get_index($standards_lists_tidy_char_sets, SQ_CONF_DEFAULT_CHARACTER_SET);
182 $path_to_tidy = SQ_TOOL_HTML_TIDY_PATH;
185 '--preserve-entities' => TRUE,
186 '--show-body-only' => TRUE,
187 '--show-errors' => 1,
188 '--show-warnings' => TRUE,
190 '--word-2000' => TRUE,
191 '--force-output' => TRUE,
192 '--logical-emphasis' => TRUE,
193 '--char-encoding' => $tidy_char_set,
194 '-access' => SQ_TOOL_HTML_TIDY_ACCESSIBILITY_LEVEL,
199 if (!empty($this->_new_inline_tags)) {
200 $config[
'--new-inline-tags'] = implode(
'","',$this->_new_inline_tags);
204 $args =
' -iq -asxhtml';
205 foreach ($config as $param => $option) {
206 $args .=
' '.$param.
' '.((is_bool($option)) ? (
int) $option : $option);
209 $doctype_header= $this->html_standards[SQ_TOOL_HTML_TIDY_HTML_STANDARD ? SQ_TOOL_HTML_TIDY_HTML_STANDARD :
'HTML_4.01_Transitional'];
210 $complete_html = $doctype_header.
'
211 <html lang="en"><head><title></title>
212 <meta name="description" content="test content" />
217 $input_file = tempnam(SQ_TEMP_PATH,
'tidy_in_');
218 $output_file = tempnam(SQ_TEMP_PATH,
'tidy_out_');
219 $error_file = tempnam(SQ_TEMP_PATH,
'tidy_err_');
221 file_put_contents($input_file, $complete_html);
225 $descriptorspec = array(
226 0 => Array(
"file", $input_file,
"r"),
227 1 => Array(
"file", $output_file,
"w"),
228 2 => Array(
"file", $error_file,
"w"),
231 $process = proc_open(
"$path_to_tidy $args ", $descriptorspec, $pipes);
233 if (is_resource($process)) {
234 $return = proc_close($process);
236 $tidy = file_get_contents($output_file);
237 $error = file_get_contents($error_file);
241 unlink($output_file);
246 foreach ($ignore_errors_list as $err) {
247 $error = str_replace($err,
'', $error);
251 foreach ($this->_new_inline_tags as $tag) {
252 $error = preg_replace(
'/line \d+ column \d+\ - Warning\: <'.$tag.
'> is not approved by W3C/',
'', $error);
255 $this->htmltidy_errors = trim($error);
259 if (($return >= 2) || empty($tidy) || empty($tidy_char_set)) {
260 $this->htmltidy_status =
'fail';
267 $html = preg_replace(
'|<pre>\n|is',
'<pre>', $html);
268 $html = preg_replace(
'|\n</pre>|is',
'</pre>', $html);
272 $this->htmltidy_status =
'wait';
290 if (SQ_TOOL_HTML_TIDY_ENABLED && file_exists(SQ_TOOL_HTML_TIDY_PATH)) {
293 return translate(
'wysiwyg_htmltidy_status_disabled');
306 $ignore_list = Array();
307 $ignore_list[] =
'line 1 column 1 - Access: [3.3.1.1]: use style sheets to control presentation.';
309 Accessibility Checks: Version 0.1