/***************************************************************************\
* SPIP, Systeme de publication pour l'internet *
* *
- * Copyright (c) 2001-2011 *
+ * Copyright (c) 2001-2014 *
* Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James *
* *
* Ce programme est un logiciel libre distribue sous licence GNU/GPL. *
define('BALISE_INCLURE','/<INCLU[DR]E[[:space:]]*(\(([^)]*)\))?/S');
define('BALISE_POLYGLOTTE',',<multi>(.*)</multi>,Uims');
-define('BALISE_IDIOMES',',<:(([a-z0-9_]+):)?([a-z0-9_]+)({([^\|=>]*=[^\|>]*)})?((\|[^>]*)?:>),iS');
+define('BALISE_IDIOMES',',<:(([a-z0-9_]+):)?([a-z0-9_]*)({([^\|=>]*=[^>]*)})?((\|[^>]*)?:>),iS');
+define('BALISE_IDIOMES_ARGS', '@^\s*([^= ]*)\s*=\s*((' . NOM_DE_CHAMP . '[{][^}]*})?[^,]*)\s*,?\s*@s');
define('SQL_ARGS', '(\([^)]*\))');
define('CHAMP_SQL_PLUS_FONC', '`?([A-Z_][A-Z_0-9.]*)' . SQL_ARGS . '?`?');
}
-// http://doc.spip.org/@phraser_idiomes
-function phraser_idiomes($texte,$ligne,$result) {
- // Reperer les balises de traduction <:module:chaine{argument1=texte,argument2=#BALISE}|filtre1{texte,#BALISE}|filtre2:>
+/// Reperer les balises de traduction
+/// <:module:chaine{arg1=texte1,arg2=#BALISE}|filtre1{texte2,#BALISE}|filtre2:>
+/// chaine peut etre vide si =texte1 est present et arg1 est vide
+/// sinon ce n'est pas un idiome
+function phraser_idiomes($texte,$ligne,$result) {
while (preg_match(BALISE_IDIOMES, $texte, $match)) {
$p = strpos($texte, $match[0]);
- $debut = substr($texte, 0, $p);
- if ($p) $result = phraser_champs($debut, $ligne, $result);
- $champ = new Idiome;
+ $ko = (!$match[3] && ($match[5][0]!=='='));
+ $debut = substr($texte, 0, $p + ($ko ? strlen($match[0]) : 0));
+ if ($debut) $result = phraser_champs($debut, $ligne, $result);
+ $texte = substr($texte,$p+strlen($match[0]));
$ligne += substr_count($debut, "\n");
+ if ($ko) continue; // faux idiome
+ $champ = new Idiome;
$champ->ligne = $ligne;
$ligne += substr_count($match[0], "\n");
- $texte = substr($texte,$p+strlen($match[0]));
// Stocker les arguments de la balise de traduction
- $args=array();
- $vals=preg_split('/,\s*/',$match[5]);
- foreach ($vals as $val) {
- $arg=preg_split('/\s*=/',$val);
- if ($arg[0])
- $args[$arg[0]]=phraser_champs($arg[1], 0, array());
+ $args = array();
+ $largs = $match[5];
+ while (preg_match(BALISE_IDIOMES_ARGS, $largs, $r)) {
+ $args[$r[1]] = phraser_champs($r[2], 0, array(), true);
+ $largs = substr($largs, strlen($r[0]));
}
- $champ->arg=$args;
+ $champ->arg = $args;
$champ->nom_champ = strtolower($match[3]);
- $champ->module = $match[2] ? $match[2] : MODULES_IDIOMES;
+ $champ->module = $match[2];
// pas d'imbrication pour les filtres sur langue
phraser_args(@$match[7], ":", '', array(), $champ);
$result[] = $champ;
}
// http://doc.spip.org/@phraser_champs
-function phraser_champs($texte,$ligne,$result) {
+function phraser_champs($texte,$ligne,$result, $filtre=false) {
while (preg_match("/".NOM_DE_CHAMP."/S", $texte, $match)) {
$p = strpos($texte, $match[0]);
$suite = substr($texte,$p+strlen($match[0]));
}
*/
} else $texte = $suite;
+ if ($filtre) while ($texte[0]=='|') {
+ $result = phraser_args($texte, '', '', $result, $champ);
+ $args = $champ->apres ;
+ $champ->apres = '';
+ $texte = $args[0];
+ }
phraser_vieux($champ);
$result[] = $champ;
} else {