ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
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 
5 require_once './Services/XHTMLValidator/validator/config.inc';
6 $GLOBALS["opts"] = $opts;
7 
8 // include bundled Text_Diff PEAR package
9 require_once './Services/XHTMLValidator/validator/Text_Diff/Diff.php';
10 require_once './Services/XHTMLValidator/validator/Text_Diff/Renderer.php';
11 require_once './Services/XHTMLValidator/validator/Text_Diff/unified.php';
12 
13 require_once './Services/XHTMLValidator/validator/include.inc';
14 require_once './Services/XHTMLValidator/validator/validator.inc';
15 
16 
27 {
28 
29  function validate($a_html, $a_mode)
30  {
31  // while php 5.1 isn't released we must keep compatibility with php 5.0
32  if (!defined('UPLOAD_ERR_CANT_WRITE'))
33  define('UPLOAD_ERR_CANT_WRITE', 7);
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  {
75  $options["accessibility-check"] = 3;
76  }
77 
78  $validator = new validator($options);
79 
80  //$result = $validator->parse_url((string)$_REQUEST['url']);
81  $result = $validator->parse_string($a_html);
82 
83  /* no fatal errors. continue */
84  if ($result){
85 
86  if ($validator->internal_error()) {
87  $answer.= "<p>$message[13]:<br />\n";
88  $answer.= nl2br($validator->internal_errors_string()) . "</p>\n";
89  }
90 
91  $answer.= '<p>';
92 
93 
94  /* If the document contains too many errors, the version may not be found */
95  if ($detected_version = $validator->detected_version()) {
96  $answer.= "<strong>$message[14]</strong>: $detected_version<br />\n";
97  }
98 
99  // enconding in use
100  $answer.= "<strong>$message[20]</strong>: {$validator->readable_charset()}";
101 
102  // language
103  if ($validator->lang)
104  $answer.= "<br />\n<strong>$message[24]</strong>: {$langs[$validator->lang]}";
105 
106 
107  /* Show HTML/XML errors */
108  if ($errors = $validator->error()) {
109 
110  $answer.= "<br />\n<strong>$message[21]</strong>: $errors</p>\n".
111  "<h2>$message[16]</h2>\n";
112 
113  if (empty($_REQUEST['errors']) || $_REQUEST['errors'] == 'along') {
114  $answer.= '<code>' . $validator->errors_source() . "</code>\n\n";
115 
116  } else { //errors alone
117  $answer.= '<p>' . $validator->errors_string() . "</p>\n\n";
118  }
119 
120  /* no errors found in the document */
121  } else {
122  $answer.= "</p><p>$message[15]</p>\n";
123  }
124 
125 
126  /* show repaired document */
127  if (!isset($_REQUEST['repair']) || $_REQUEST['repair'] == 'full') {
128  $html = strtr(nl2br(htmlspecialchars($validator->repaired_source(), ENT_QUOTES, 'UTF-8')), array(' ' => ' &nbsp;'));
129 
130  $answer.= "\n<p>&nbsp;</p>\n<h2>$message[17]</h2>\n";
131  $answer.= '<div class="code"><code>' . $html . "</code></div>\n";
132  }
133  /* Diff */
134  /*
135  } elseif ($_REQUEST['repair'] == 'diff' && $diff = $validator->repaired_diff()) {
136  $diff = strtr($diff, array(' ' => ' &nbsp;'));
137 
138  echo "\n<p>&nbsp;</p>\n<h2>$message[11]</h2>\n";
139  echo '<div class="code"><code>' . $diff . "</code></div>\n";
140  }
141  */
142 
143 
144  /* there was some error handling the URL/file upload */
145  } else {
146  $answer.= "<p>$message[13]:<br />\n";
147  $answer.= nl2br($validator->internal_errors_string()) . "</p>\n";
148  }
149 
150  return $answer;
151  }
152 }
153 ?>