From 28fb14bbef4b971ba537b7d2e625d67e75a5fe6d Mon Sep 17 00:00:00 2001 From: "Committo,Ergo:sum" <esj@rezo.net> Date: Fri, 22 Dec 2006 07:37:46 +0000 Subject: [PATCH] =?UTF-8?q?Suite=20de=20[8129]:=20v=C3=A9rifier=20qu'un=20?= =?UTF-8?q?ID=20est=20alphanum=C3=A9rique,=20et=20traiter=20le=20cas=20IDR?= =?UTF-8?q?EFS=20en=20plus=20du=20cas=20IDREF=20de=20[8130].=20Utile=20pou?= =?UTF-8?q?r=20l'attribut=20{{{headers}}}=20de=20{{{th}}}.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ecrire/inc/presentation.php | 16 +++---- ecrire/inc/valider_xml.php | 83 +++++++++++++++++++++++-------------- 2 files changed, 61 insertions(+), 38 deletions(-) diff --git a/ecrire/inc/presentation.php b/ecrire/inc/presentation.php index 6639ba1392..51d9556f15 100644 --- a/ecrire/inc/presentation.php +++ b/ecrire/inc/presentation.php @@ -1741,14 +1741,16 @@ function fin_page() return debut_grand_cadre(true) . "\n" . (($spip_display == 4) - ? ("<div><a href='./?set_disp=2'>" - . _T("access_interface_graphique") - . "</a></div>") + ? ("<div><a href='./?set_disp=2&exec=" + . _request('exec') + . "'>" + . _T("access_interface_graphique") + . "</a></div>") : ('<div style="text-align: right; font-family: Verdana; font-size: 8pt">' - . info_copyright() - . "<br />" - . _T('info_copyright_doc') - . '</div>')) + . info_copyright() + . "<br />" + . _T('info_copyright_doc') + . '</div>')) . fin_grand_cadre(true) . "</div>" // cf. <div center> ouverte dans conmmencer_page() diff --git a/ecrire/inc/valider_xml.php b/ecrire/inc/valider_xml.php index 516be79219..26e2dba388 100644 --- a/ecrire/inc/valider_xml.php +++ b/ecrire/inc/valider_xml.php @@ -17,6 +17,8 @@ include_spip('inc/sax'); define('_REGEXP_DOCTYPE', '/^\s*(<[?][^>]*>\s*)?<!DOCTYPE\s+(\w+)\s+(\w+)\s*([^>]*)>/'); +define('_REGEXP_ID', '/^[A-Za-z_][\w_:.]*$/'); + // http://doc.spip.org/@validateur function validateur($data) { @@ -199,45 +201,64 @@ function validerAttribut($parser, $name, $val, $bal) . coordonnees_erreur($parser); } else{ $type = $a[$name][0]; - if ($type[0]=='/') { - if (!preg_match($a[$name][0], $val)) { - $phraseur_xml->err[]= " <p><b>$val</b>" - . _L(" valeur de l'attribut ") - . "<b>$name</b>" - . _L(' de ') - . "<b>$bal</b>" - . _L(" n'est pas conforme au motif</p><p>") - . "<b>" . $a[$name][0] . "</b></p>" - . coordonnees_erreur($parser); - } - } elseif ($type == 'ID') { + if ($type[0]=='/') + valider_motif($parser, $name, $val, $bal, $type); + elseif ($type == 'ID') { if (isset($phraseur_xml->ids[$val])) { + list($l,$c) = $phraseur_xml->ids[$val]; $phraseur_xml->err[]= " <p><b>$val</b>" . _L(" valeur de l'attribut ") . "<b>$name</b>" . _L(' de ') . "<b>$bal</b>" - . _L(" incorrect ") - . coordonnees_erreur($parser); - list($l,$c) = $phraseur_xml->ids[$val]; - $phraseur_xml->err[]= " <p><b>$val</b>" . _L(" vu auparavant ") - . $l - . " " - . $c; - } else $phraseur_xml->ids[$val] = array(xml_get_current_line_number($parser), xml_get_current_column_number($parser)); + . "(L$l,C$c)" + . coordonnees_erreur($parser); + } else { + valider_motif($parser, $name, $val, $bal, _REGEXP_ID); + $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)); + } elseif ($type == 'IDREFS') { + $phraseur_xml->idrefss[] = array($val, xml_get_current_line_number($parser), xml_get_current_column_number($parser)); } } } +function valider_motif($parser, $name, $val, $bal, $motif) +{ + global $phraseur_xml; + + if (!preg_match($motif, $val)) { + $phraseur_xml->err[]= " <p><b>$val</b>" + . _L(" valeur de l'attribut ") + . "<b>$name</b>" + . _L(' de ') + . "<b>$bal</b>" + . _L(" n'est pas conforme au motif</p><p>") + . "<b>" . $motif . "</b></p>" + . coordonnees_erreur($parser); + } +} + +function valider_idref($nom, $ligne, $col) +{ + global $phraseur_xml; + + if (!isset($phraseur_xml->ids[$nom])) + $phraseur_xml->err[]= " <p><b>$nom</b>" + . _L(" ID inconnu ") + . $ligne + . " " + . $col; +} + class ValidateurXML { // http://doc.spip.org/@debutElement function debutElement($phraseur, $name, $attrs) { - validerElement($phraseur, $name, $attrs); xml_debutElement($phraseur, $name, $attrs); foreach ($attrs as $k => $v) { @@ -275,19 +296,18 @@ function phraserTout($phraseur, $data) if (isset($phraseur_xml->entites['HTMLsymbol'])) $data = unicode2charset(html2unicode($data, true)); - xml_parsestring($phraseur, $data); if (!$phraseur_xml->err) { - foreach ($this->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 - . " " - . $col; - } + foreach ($this->idrefs as $idref) { + list($nom, $ligne, $col) = $idref; + valider_idref($nom, $ligne, $col); + } + foreach ($this->idrefss as $idref) { + list($noms, $ligne, $col) = $idref; + foreach(preg_split('/\s+/', $noms) as $nom) + valider_idref($nom, $ligne, $col); + } } return !$this->err ? $this->res : join('<br />', $this->err) . '<br />'; @@ -304,6 +324,7 @@ function phraserTout($phraseur, $data) var $attributs = array(); var $ids = array(); var $idrefs = array(); + var $idrefss = array(); var $err = array(); } -- GitLab