[ Index ] |
|
Code source de Dotclear 1.2.5 |
1 <?php 2 # ***** BEGIN LICENSE BLOCK ***** 3 # This file is part of DotClear. 4 # Copyright (c) 2004 Olivier Meunier and contributors. All rights 5 # reserved. 6 # 7 # DotClear is free software; you can redistribute it and/or modify 8 # it under the terms of the GNU General Public License as published by 9 # the Free Software Foundation; either version 2 of the License, or 10 # (at your option) any later version. 11 # 12 # DotClear is distributed in the hope that it will be useful, 13 # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 # GNU General Public License for more details. 16 # 17 # You should have received a copy of the GNU General Public License 18 # along with DotClear; if not, write to the Free Software 19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 20 # 21 # ***** END LICENSE BLOCK ***** 22 23 class validator 24 { 25 function xhtml($input,$charset='UTF-8') 26 { 27 $res = array('valid' => NULL, 'errors' => ''); 28 $content = validator::__getContent($input); 29 30 $http = new HttpClient('www.htmlhelp.com',80); 31 $http->setUserAgent('Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.3a) Gecko/20021207'); 32 $http->useGzip(false); 33 $http->setPersistReferers(false); 34 35 $params = array('area' => $content,'charset' => $charset); 36 37 if ($http->post('/cgi-bin/validate.cgi',$params) !== false) 38 { 39 $result = $http->getContent(); 40 41 if (strpos($result,'<p class=congratulations><strong>Congratulations, no errors!</strong></p>')) 42 { 43 $res['valid'] = true; 44 } 45 else 46 { 47 $res['valid'] = false; 48 if ($errors = preg_match('#<h2>Errors</h2>[\s]*(<ul>.*</ul>)#msU',$result,$matches)) 49 { 50 $res['errors'] = strip_tags($matches[1],'<ul><li><pre><b>'); 51 } 52 } 53 54 return $res; 55 } 56 57 return false; 58 } 59 60 function __getContent($input) 61 { 62 return 63 '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" '. 64 '"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'."\n". 65 '<html xmlns="http://www.w3.org/1999/xhtml">'."\n". 66 '<head>'."\n". 67 '<title>validation</title>'."\n". 68 '</head>'."\n". 69 '<body>'."\n". 70 $input."\n". 71 '</body>'."\n". 72 '</html>'; 73 } 74 } 75 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Fri Feb 23 21:40:15 2007 | par Balluche grâce à PHPXref 0.7 |