• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

Services/XHTMLValidator/classes/class.ilValidatorAdapter.php

Go to the documentation of this file.
00001 <?php
00002 
00003 /*
00004         +-----------------------------------------------------------------------------+
00005         | ILIAS open source                                                           |
00006         +-----------------------------------------------------------------------------+
00007         | Copyright (c) 1998-2005 ILIAS open source, University of Cologne            |
00008         |                                                                             |
00009         | This program is free software; you can redistribute it and/or               |
00010         | modify it under the terms of the GNU General Public License                 |
00011         | as published by the Free Software Foundation; either version 2              |
00012         | of the License, or (at your option) any later version.                      |
00013         |                                                                             |
00014         | This program is distributed in the hope that it will be useful,             |
00015         | but WITHOUT ANY WARRANTY; without even the implied warranty of              |
00016         | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               |
00017         | GNU General Public License for more details.                                |
00018         |                                                                             |
00019         | You should have received a copy of the GNU General Public License           |
00020         | along with this program; if not, write to the Free Software                 |
00021         | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. |
00022         +-----------------------------------------------------------------------------+
00023 */
00024 
00025 require_once './Services/XHTMLValidator/validator/config.inc';
00026 $GLOBALS["opts"] = $opts;
00027 
00028 // include bundled Text_Diff PEAR package
00029 require_once './Services/XHTMLValidator/validator/Text_Diff/Diff.php';
00030 require_once './Services/XHTMLValidator/validator/Text_Diff/Renderer.php';
00031 require_once './Services/XHTMLValidator/validator/Text_Diff/unified.php';
00032 
00033 require_once './Services/XHTMLValidator/validator/include.inc';
00034 require_once './Services/XHTMLValidator/validator/validator.inc';
00035 
00036 
00046 class ilValidatorAdapter
00047 {
00048         
00049         function validate($a_html, $a_mode)
00050         {
00051                 // while php 5.1 isn't released we must keep compatibility with php 5.0
00052                 if (!defined('UPLOAD_ERR_CANT_WRITE'))
00053                         define('UPLOAD_ERR_CANT_WRITE', 7);
00054                 
00055                 /*
00056                    Mozilla, Firefox and friends have an error that lock radio buttons.
00057                    We use this to disable some feature for these browsers
00058                    More info at: http://bugzilla.mozilla.org/show_bug.cgi?id=229925
00059                 */
00060                 define('MOZILLA', (isset($_SERVER['HTTP_USER_AGENT']) && strpos($_SERVER['HTTP_USER_AGENT'], 'Mozilla/') !== false && strpos($_SERVER['HTTP_USER_AGENT'], 'Gecko/') !== false));
00061                 
00062                 //function mozilla($txt) {
00063                 //      return MOZILLA ? '' : $txt;
00064                 //}
00065                 
00066                 
00067                 if (empty($lang)) {
00068                         $lang = isset($_REQUEST['lang']) ? $_REQUEST['lang'] : 'en';
00069                 } else {
00070                         $redir = true;
00071                 }
00072 
00073                 /*
00074                 if (empty($_COOKIE['lang']) || $lang != $_COOKIE['lang']) {
00075                         setcookie('lang', $lang, time()+60*60*24*90, '/', 'validator.aborla.net');
00076                 }*/
00077 
00078                 //output_add_rewrite_var('lang', $lang);
00079                 
00080                 require './Services/XHTMLValidator/validator/local/en.inc'; // fallback for not translated messages
00081 
00082                 //if ($lang != 'en')
00083                 //      require "./local/$lang.inc"; //load localized messages
00084                 
00085                 //common_header();
00086                                 
00087                 
00088                 /****************** START OF THE VALIDATOR ITSELF *******************/
00089                 
00090                 // output: html/xhtml/xml, accessibility-check: 0-3
00091                 $options = array();
00092                 $options["charset"] = "utf8";
00093                 if ($a_mode == "accessibility")
00094                 {
00095                         $options["accessibility-check"] = 3;
00096                 }
00097 
00098                 $validator = new validator($options);
00099                 
00100                 //$result = $validator->parse_url((string)$_REQUEST['url']);
00101                 $result = $validator->parse_string($a_html);
00102                 
00103                 /* no fatal errors. continue */
00104                 if ($result){
00105 
00106                         if ($validator->internal_error()) {
00107                                 $answer.= "<p>$message[13]:<br />\n";
00108                                 $answer.= nl2br($validator->internal_errors_string()) . "</p>\n";
00109                         }
00110                 
00111                         $answer.= '<p>';
00112                 
00113                 
00114                         /* If the document contains too many errors, the version may not be found */
00115                         if ($detected_version = $validator->detected_version()) {
00116                                 $answer.= "<strong>$message[14]</strong>: $detected_version<br />\n";
00117                         }
00118                 
00119                         // enconding in use
00120                         $answer.= "<strong>$message[20]</strong>: {$validator->readable_charset()}";
00121                 
00122                         // language
00123                         if ($validator->lang)
00124                                 $answer.= "<br />\n<strong>$message[24]</strong>: {$langs[$validator->lang]}";
00125                 
00126                 
00127                         /* Show HTML/XML errors */
00128                         if ($errors = $validator->error()) {
00129                 
00130                                 $answer.= "<br />\n<strong>$message[21]</strong>: $errors</p>\n".
00131                                          "<h2>$message[16]</h2>\n";
00132                 
00133                                 if (empty($_REQUEST['errors']) || $_REQUEST['errors'] == 'along') {
00134                                         $answer.= '<code>' . $validator->errors_source() . "</code>\n\n";
00135                 
00136                                 } else { //errors alone
00137                                         $answer.= '<p>' . $validator->errors_string() . "</p>\n\n";
00138                                 }
00139                 
00140                         /* no errors found in the document */
00141                         } else {
00142                                 $answer.= "</p><p>$message[15]</p>\n";
00143                         }
00144                 
00145                 
00146                         /* show repaired document */
00147                         if (!isset($_REQUEST['repair']) || $_REQUEST['repair'] == 'full') {
00148                                 $html = strtr(nl2br(htmlspecialchars($validator->repaired_source(), ENT_QUOTES, 'UTF-8')), array('  ' => ' &nbsp;'));
00149                 
00150                                 $answer.= "\n<p>&nbsp;</p>\n<h2>$message[17]</h2>\n";
00151                                 $answer.= '<div class="code"><code>' . $html . "</code></div>\n";
00152                         }
00153                         /* Diff */
00154                 /*
00155                         } elseif ($_REQUEST['repair'] == 'diff' && $diff = $validator->repaired_diff()) {
00156                                 $diff = strtr($diff, array('  ' => ' &nbsp;'));
00157                 
00158                                 echo "\n<p>&nbsp;</p>\n<h2>$message[11]</h2>\n";
00159                                 echo '<div class="code"><code>' . $diff . "</code></div>\n";
00160                         }
00161                 */
00162                 
00163                 
00164                 /* there was some error handling the URL/file upload */
00165                 } else {
00166                         $answer.= "<p>$message[13]:<br />\n";
00167                         $answer.= nl2br($validator->internal_errors_string()) . "</p>\n";
00168                 }
00169 
00170                 return $answer;
00171         }
00172 }
00173 ?>

Generated on Fri Dec 13 2013 13:52:12 for ILIAS Release_3_7_x_branch .rev 46817 by  doxygen 1.7.1