ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilValidatorAdapter.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
4
5require_once './Services/XHTMLValidator/validator/config.inc';
6$GLOBALS["opts"] = $opts;
7
8// include bundled Text_Diff PEAR package
9require_once './Services/XHTMLValidator/validator/Text_Diff/Diff.php';
10require_once './Services/XHTMLValidator/validator/Text_Diff/Renderer.php';
11require_once './Services/XHTMLValidator/validator/Text_Diff/unified.php';
12
13require_once './Services/XHTMLValidator/validator/include.inc';
14require_once './Services/XHTMLValidator/validator/validator.inc';
15
16
27{
28 public static function validate($a_html, $a_mode)
29 {
30 // while php 5.1 isn't released we must keep compatibility with php 5.0
31 if (!defined('UPLOAD_ERR_CANT_WRITE')) {
32 define('UPLOAD_ERR_CANT_WRITE', 7);
33 }
34
35 /*
36 Mozilla, Firefox and friends have an error that lock radio buttons.
37 We use this to disable some feature for these browsers
38 More info at: http://bugzilla.mozilla.org/show_bug.cgi?id=229925
39 */
40 define('MOZILLA', (isset($_SERVER['HTTP_USER_AGENT']) && strpos($_SERVER['HTTP_USER_AGENT'], 'Mozilla/') !== false && strpos($_SERVER['HTTP_USER_AGENT'], 'Gecko/') !== false));
41
42 //function mozilla($txt) {
43 // return MOZILLA ? '' : $txt;
44 //}
45
46
47 if (empty($lang)) {
48 $lang = isset($_REQUEST['lang']) ? $_REQUEST['lang'] : 'en';
49 } else {
50 $redir = true;
51 }
52
53 /*
54 if (empty($_COOKIE['lang']) || $lang != $_COOKIE['lang']) {
55 setcookie('lang', $lang, time()+60*60*24*90, '/', 'validator.aborla.net');
56 }*/
57
58 //output_add_rewrite_var('lang', $lang);
59
60 require './Services/XHTMLValidator/validator/local/en.inc'; // fallback for not translated messages
61
62 //if ($lang != 'en')
63 // require "./local/$lang.inc"; //load localized messages
64
65 //common_header();
66
67
68 /****************** START OF THE VALIDATOR ITSELF *******************/
69
70 // output: html/xhtml/xml, accessibility-check: 0-3
71 $options = array();
72 $options["charset"] = "utf8";
73 if ($a_mode == "accessibility") {
74 $options["accessibility-check"] = 3;
75 }
76
77 $validator = new validator($options);
78
79 //$result = $validator->parse_url((string)$_REQUEST['url']);
80 $result = $validator->parse_string($a_html);
81
82 /* no fatal errors. continue */
83 if ($result) {
84 if ($validator->internal_error()) {
85 $answer .= "<p>$message[13]:<br />\n";
86 $answer .= nl2br($validator->internal_errors_string()) . "</p>\n";
87 }
88
89 $answer .= '<p>';
90
91
92 /* If the document contains too many errors, the version may not be found */
93 if ($detected_version = $validator->detected_version()) {
94 $answer .= "<strong>$message[14]</strong>: $detected_version<br />\n";
95 }
96
97 // enconding in use
98 $answer .= "<strong>$message[20]</strong>: {$validator->readable_charset()}";
99
100 // language
101 if ($validator->lang) {
102 $answer .= "<br />\n<strong>$message[24]</strong>: {$langs[$validator->lang]}";
103 }
104
105
106 /* Show HTML/XML errors */
107 if ($errors = $validator->error()) {
108 $answer .= "<br />\n<strong>$message[21]</strong>: $errors</p>\n" .
109 "<h2>$message[16]</h2>\n";
110
111 if (empty($_REQUEST['errors']) || $_REQUEST['errors'] == 'along') {
112 $answer .= '<code>' . $validator->errors_source() . "</code>\n\n";
113 } else { //errors alone
114 $answer .= '<p>' . $validator->errors_string() . "</p>\n\n";
115 }
116
117 /* no errors found in the document */
118 } else {
119 $answer .= "</p><p>$message[15]</p>\n";
120 }
121
122
123 /* show repaired document */
124 if (!isset($_REQUEST['repair']) || $_REQUEST['repair'] == 'full') {
125 $html = strtr(nl2br(htmlspecialchars($validator->repaired_source(), ENT_QUOTES, 'UTF-8')), array(' ' => ' &nbsp;'));
126
127 $answer .= "\n<p>&nbsp;</p>\n<h2>$message[17]</h2>\n";
128 $answer .= '<div class="code"><code>' . $html . "</code></div>\n";
129 }
130 /* Diff */
131 /*
132 } elseif ($_REQUEST['repair'] == 'diff' && $diff = $validator->repaired_diff()) {
133 $diff = strtr($diff, array(' ' => ' &nbsp;'));
134
135 echo "\n<p>&nbsp;</p>\n<h2>$message[11]</h2>\n";
136 echo '<div class="code"><code>' . $diff . "</code></div>\n";
137 }
138 */
139
140
141 /* there was some error handling the URL/file upload */
142 } else {
143 $answer .= "<p>$message[13]:<br />\n";
144 $answer .= nl2br($validator->internal_errors_string()) . "</p>\n";
145 }
146
147 return $answer;
148 }
149}
$result
An exception for terminatinating execution or to throw for unit testing.
$GLOBALS["opts"]
Adapter Class for XHTML Validator.
static validate($a_html, $a_mode)
$html
Definition: example_001.php:87
for($i=1; $i<=count($kw_cases_sel); $i+=1) $lang
Definition: langwiz.php:349
$errors
Definition: index.php:6
if((!isset($_SERVER['DOCUMENT_ROOT'])) OR(empty($_SERVER['DOCUMENT_ROOT']))) $_SERVER['DOCUMENT_ROOT']