From 7ad7c0beccc2a0f8f1383bfdd242b5581e8a9566 Mon Sep 17 00:00:00 2001 From: "Committo,Ergo:sum" <esj@rezo.net> Date: Tue, 19 Dec 2006 06:37:45 +0000 Subject: [PATCH] =?UTF-8?q?Validateur=20int=C3=A9gr=C3=A9:=20d=C3=A9noncer?= =?UTF-8?q?=20les=20IDREF=20inconnus=20(i.e.=20les=20attributs=20For=20de?= =?UTF-8?q?=20la=20balise=20Label=20qui=20n'ont=20pas=20pour=20valeur=20ce?= =?UTF-8?q?lle=20d'un=20attribut=20Id=20dans=20la=20page)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ecrire/inc/sax.php | 72 ++++++++++++++++++++++----------------- ecrire/inc/validateur.php | 7 ++-- 2 files changed, 45 insertions(+), 34 deletions(-) diff --git a/ecrire/inc/sax.php b/ecrire/inc/sax.php index ba7359d573..23a6911785 100644 --- a/ecrire/inc/sax.php +++ b/ecrire/inc/sax.php @@ -128,49 +128,58 @@ function defautElement($parser, $data) } // http://doc.spip.org/@xml_parsefile -function xml_parsefile($xml_parser, $file) +function xml_parsefile($phraseur, $file) { - if (!($fp = fopen($file, "r"))) { + if (!($fp = fopen($file, "r"))) { include_spip('inc/minipres'); echo minipres("Impossible d'ouvrir le fichier XML"); exit; - } - while ($data = fread($fp, 4096)) { - if (!xml_parse($xml_parser, str_replace('’',"'",$data), feof($fp))) { - return (sprintf("erreur XML : %s ligne %d", - xml_error_string(xml_get_error_code($xml_parser)), - xml_get_current_line_number($xml_parser))); - } - } - return ""; + } + while ($data = fread($fp, 4096)) { + if (!xml_parse($phraseur, + str_replace('’',"'",$data), feof($fp))) { + return (sprintf("erreur XML : %s ligne %d", + xml_error_string(xml_get_error_code($phraseur)), + xml_get_current_line_number($phraseur))); + } + } + return ""; } // http://doc.spip.org/@xml_parsestring -function xml_parsestring($xml_parser, $data) +function xml_parsestring($phraseur, $data) { global $phraseur_xml; $phraseur_xml->contenu[$phraseur_xml->depth] =''; - $r = ""; - if (!xml_parse($xml_parser, $data, true)) { + + if (!xml_parse($phraseur, $data, true)) { // ne pas commencer le message par un "<" (cf inc_sax_dist) - $r = xml_error_string(xml_get_error_code($xml_parser)) . - coordonnees_erreur($xml_parser) . '<br />' . - (!$phraseur_xml->depth ? '' : - ( - _L("dernière balise non refermée : ") . - "<tt>" . - $phraseur_xml->ouvrant[$phraseur_xml->depth] . - "</tt>" . - _L(" ligne ") . - $phraseur_xml->reperes[$phraseur_xml->depth] . - '<br />' )); - - } else if ($phraseur_xml->err) - $r = join('<br />', $phraseur_xml->err) . '<br />'; - else $r = $phraseur_xml->res; - - return $r; + return xml_error_string(xml_get_error_code($phraseur)) . + coordonnees_erreur($phraseur) . '<br />' . + (!$phraseur_xml->depth ? '' : + ( + _L("dernière balise non refermée : ") . + "<tt>" . + $phraseur_xml->ouvrant[$phraseur_xml->depth] . + "</tt>" . + _L(" ligne ") . + $phraseur_xml->reperes[$phraseur_xml->depth] . + '<br />' )); + } + foreach ($phraseur_xml->idrefs as $idref) { + list($nom, $ligne, $col) = $idref; + if (!isset($phraseur_xml->ids[$nom])) + $phraseur_xml->err[]= " <p><b>$nom</b>" + . _L(" ID inconnu ligne ") + . $ligne + . _L(" colonne ") + . $col; + } + if ($phraseur_xml->err) + return join('<br />', $phraseur_xml->err) . '<br />'; + + return $phraseur_xml->res; } var $depth = ""; @@ -182,6 +191,7 @@ function xml_parsestring($xml_parser, $data) var $entites = array(); var $attributs = array(); var $ids = array(); + var $idrefs = array(); var $err = array(); } diff --git a/ecrire/inc/validateur.php b/ecrire/inc/validateur.php index 11ded21c14..fe7836ba00 100644 --- a/ecrire/inc/validateur.php +++ b/ecrire/inc/validateur.php @@ -173,9 +173,10 @@ function validerAttribut($parser, $name, $val, $bal) . _L(" vu auparavant ligne ") . $l . _L(" colonne ") - . $c; - } - else $phraseur_xml->ids[$val] = array(xml_get_current_line_number($parser), xml_get_current_column_number($parser)); + . $c; + } else $phraseur_xml->ids[$val] = array(xml_get_current_line_number($parser), xml_get_current_column_number($parser)); + } elseif ($type == 'IDREF') { + $phraseur_xml->idrefs[] = array($val, xml_get_current_line_number($parser), xml_get_current_column_number($parser)); } } } -- GitLab