Skip to content
Extraits de code Groupes Projets
Valider d8202bca rédigé par esj's avatar esj
Parcourir les fichiers

Quand la DTD donne une RegExp comme valeur admise pour l'attribut, l'appliquer...

Quand la DTD donne une RegExp comme valeur admise pour l'attribut, l'appliquer sur celui-ci à la validation. Et petite amélioration de présentation.
parent 12c2ce0a
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -70,8 +70,11 @@ function inc_validateur_dist($data) ...@@ -70,8 +70,11 @@ function inc_validateur_dist($data)
$val = expanserEntite($val, $phraseur_xml->entites); $val = expanserEntite($val, $phraseur_xml->entites);
$att = array(); $att = array();
if (preg_match_all("/\s*(\S+)\s+(([(][^)]*[)])|(\S+))\s+(\S+)(\s*'[^']*')?/", $val, $r2, PREG_SET_ORDER)) { if (preg_match_all("/\s*(\S+)\s+(([(][^)]*[)])|(\S+))\s+(\S+)(\s*'[^']*')?/", $val, $r2, PREG_SET_ORDER)) {
foreach($r2 as $m2) foreach($r2 as $m2) {
$att[$m2[1]] = $m2[5]; $v = preg_match('/^\w+$/', $m2[2]) ? ''
: ('/^' . preg_replace('/\s+/', '', $m2[2]) . '$/');
$att[$m2[1]] = array($v, $m2[5]);
}
} }
$res[$nom] = $att; $res[$nom] = $att;
} }
...@@ -120,7 +123,7 @@ function validerElement($parser, $name, $attrs) ...@@ -120,7 +123,7 @@ function validerElement($parser, $name, $attrs)
} }
} }
foreach ($phraseur_xml->attributs[$name] as $n => $v) foreach ($phraseur_xml->attributs[$name] as $n => $v)
{ if (($v == '#REQUIRED') AND (!isset($attrs[$n]))) { if (($v[1] == '#REQUIRED') AND (!isset($attrs[$n])))
$phraseur_xml->err[]= " <b>$n</b>" $phraseur_xml->err[]= " <b>$n</b>"
. '&nbsp;:&nbsp;' . '&nbsp;:&nbsp;'
. _L(" attribut obligatoire mais absent dans ") . _L(" attribut obligatoire mais absent dans ")
...@@ -134,16 +137,26 @@ function validerElement($parser, $name, $attrs) ...@@ -134,16 +137,26 @@ function validerElement($parser, $name, $attrs)
// http://doc.spip.org/@validerAttribut // http://doc.spip.org/@validerAttribut
function validerAttribut($parser, $name, $val, $bal) function validerAttribut($parser, $name, $val, $bal)
{ {
global $phraseur_xml; global $phraseur_xml;
if ($a = $phraseur_xml->attributs[$bal] $a = @$phraseur_xml->attributs[$bal]; // vide ou absent, pareil.
AND !isset($a[$name])) if (!isset($a[$name]))
$phraseur_xml->err[]= " <b>$name</b>" $phraseur_xml->err[]= " <b>$name</b>"
. _L(' attribut inconnu de ') . _L(' attribut inconnu de ')
. "<b>$bal</b>" . "<b>$bal</b>"
. coordonnees_erreur($parser); . coordonnees_erreur($parser);
elseif ($a[$name][0][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);
}
}
} }
?> ?>
...@@ -306,7 +306,7 @@ function reference_boucle_debug($n, $nom, $self) ...@@ -306,7 +306,7 @@ function reference_boucle_debug($n, $nom, $self)
function ancre_texte($texte, $fautifs=array()) function ancre_texte($texte, $fautifs=array())
{ {
global $var_mode_ligne; global $var_mode_ligne;
if ($var_mode_ligne) $fautifs[]=$var_mode_ligne; if ($var_mode_ligne) $fautifs[]= array($var_mode_ligne);
$res =''; $res ='';
$s = highlight_string($texte,true); $s = highlight_string($texte,true);
if (substr($s,0,6) == '<code>') { $s=substr($s,6); $res = '<code>';} if (substr($s,0,6) == '<code>') { $s=substr($s,6); $res = '<code>';}
...@@ -322,11 +322,27 @@ function ancre_texte($texte, $fautifs=array()) ...@@ -322,11 +322,27 @@ function ancre_texte($texte, $fautifs=array())
$formaterr="<span style='background-color: pink'>%s</span>"; $formaterr="<span style='background-color: pink'>%s</span>";
$i=1; $i=1;
$flignes = array();
foreach ($fautifs as $lc)
if (is_array($lc))
$flignes[$lc[0]] = $lc[1];
else $flignes[$lc] = 0;
foreach ($tableau as $ligne) { foreach ($tableau as $ligne) {
$res .= "<br />\n" if (isset($flignes[$i])) {
$ligne = str_replace('&nbsp;',' ', $ligne);
// tentative de pointer sur la colonne fautive;
// marche pas car highlight_string rajoute des entites. A revoir.
// $m = $flignes[$i];
// $ligne = substr($ligne, 0, $m-1) .
// sprintf($formaterr, substr($ligne,$m));
$ligne = sprintf($formaterr, $ligne);
}
$res .= "<br />\n"
. sprintf((($i%10) ? $format :$format10), $i, $i) . sprintf((($i%10) ? $format :$format10), $i, $i)
. sprintf(in_array($i, $fautifs) ? $formaterr : '%s', $ligne); . $ligne;
$i++; $i++;
} }
return "<div id='T$ancre'>$res</div>"; return "<div id='T$ancre'>$res</div>";
} }
...@@ -510,33 +526,32 @@ function emboite_texte($texte, $fonc='',$self='') ...@@ -510,33 +526,32 @@ function emboite_texte($texte, $fonc='',$self='')
if (!$texte) if (!$texte)
return array(ancre_texte($texte, array('','')), false); return array(ancre_texte($texte, array('','')), false);
elseif (preg_match_all(",([^0-9]* )([0-9]+)(.*?<br />),", elseif (!ereg("^[[:space:]]*([^<][^0-9]*)([0-9]*)(.*[^0-9])([0-9]*)$",
$GLOBALS['xhtml_error'],
$eregs))
return array(ancre_texte($texte, array('', '')), true);
if (!isset($GLOBALS['debug_objets'])) {
preg_match_all(",([^0-9]* )([0-9]+)(.*?(\d*)<br />),",
$GLOBALS['xhtml_error'], $GLOBALS['xhtml_error'],
$regs, $regs,
PREG_SET_ORDER)) { PREG_SET_ORDER);
$err = ''; $err = '';
$fautifs = array(); $fautifs = array();
foreach($regs as $r) { foreach($regs as $r) {
$err .= $r[1] . $err .= $r[1] .
"<a href='#L" . $r[2] . "'>$r[2]</a>$r[3]"; "<a href='#L" . $r[2] . "'>$r[2]</a>$r[3]";
$fautifs[]=$r[2]; $fautifs[]= array($r[2], $r[4]);
} }
return array(ancre_texte($texte, $fautifs), $err); return array(ancre_texte($texte, $fautifs), $err);
} elseif (!ereg("^[[:space:]]*([^<][^0-9]*)([0-9]*)(.*[^0-9])([0-9]*)$", } else {
$GLOBALS['xhtml_error'], $fermant = $eregs[2];
$r)) $ouvrant = $eregs[4];
return array(ancre_texte($texte, array('', '')), true); $rf = reference_boucle_debug($fermant, $fonc, $self);
else { $ro = reference_boucle_debug($ouvrant, $fonc, $self);
$fermant = $r[2]; $err = $eregs[1] .
$ouvrant = $r[4]; "<a href='#L" . $eregs[2] . "'>$eregs[2]</a>$rf" .
if (isset($GLOBALS['debug_objets'])) { $eregs[3] ."<a href='#L" . $eregs[4] . "'>$eregs[4]</a>$ro";
$rf = reference_boucle_debug($fermant, $fonc, $self); return array(ancre_texte($texte, array(array($ouvrant), array($fermant))), $err);
$ro = reference_boucle_debug($ouvrant, $fonc, $self);
} else $rf = $ro = '';
$err = $r[1] .
"<a href='#L" . $r[2] . "'>$r[2]</a>$rf" .
$r[3] ."<a href='#L" . $r[4] . "'>$r[4]</a>$ro";
return array(ancre_texte($texte, array($ouvrant, $fermant)), $err);
} }
} }
?> ?>
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter