~maj v3.0.19-->v3.0.21
[ptitvelo/web/www.git] / www / ecrire / public / phraser_html.php
index 1467851..ea4aca8 100644 (file)
@@ -3,7 +3,7 @@
 /***************************************************************************\
  *  SPIP, Systeme de publication pour l'internet                           *
  *                                                                         *
- *  Copyright (c) 2001-2012                                                *
+ *  Copyright (c) 2001-2014                                                *
  *  Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James  *
  *                                                                         *
  *  Ce programme est un logiciel libre distribue sous licence GNU/GPL.     *
@@ -32,7 +32,8 @@ define('CHAMP_ETENDU', '/\[([^]\[]*)\(' . NOM_DE_CHAMP . '([^[)]*\)[^]\[]*)\]/S'
 
 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 . '?`?');
@@ -112,30 +113,33 @@ function phraser_polyglotte($texte,$ligne, $result) {
 }
 
 
+// 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
 // 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:>
        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);
+               $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;
-               $ligne += substr_count($debut, "\n");   
                $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());
+                       $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;
@@ -481,23 +485,24 @@ function phraser_criteres($params, &$result) {
                          $not = "";
                        } else {
                          // Le debut du premier argument est l'operateur
-                         preg_match("/^([!]?)([a-zA-Z][a-zA-Z0-9]*)[[:space:]]*(.*)$/ms", $param, $m);
+                         preg_match("/^([!]?)([a-zA-Z][a-zA-Z0-9_]*)[[:space:]]*(\??)[[:space:]]*(.*)$/ms", $param, $m);
                          $op = $m[2];
                          $not = $m[1];
+                         $cond = $m[3];
                          // virer le premier argument,
                          // et mettre son reliquat eventuel
                          // Recopier pour ne pas alterer le texte source
                          // utile au debusqueur
-                         if ($m[3]) {
+                         if ($m[4]) {
                            // une maniere tres sale de supprimer les "' autour de {critere "xxx","yyy"}
-                           if (preg_match(',^(["\'])(.*)\1$,', $m[3])) {
+                           if (preg_match(',^(["\'])(.*)\1$,', $m[4])) {
                                $c = null;
-                               eval ('$c = '.$m[3].';');
+                               eval ('$c = '.$m[4].';');
                                if (isset($c))
-                                       $m[3] = $c;
+                                       $m[4] = $c;
                            }
                            $texte = new Texte;
-                           $texte->texte = $m[3]; 
+                           $texte->texte = $m[4]; 
                            $v[1][0]= $texte;
                          } else array_shift($v[1]);
                        }
@@ -505,6 +510,7 @@ function phraser_criteres($params, &$result) {
                        $crit = new Critere;
                        $crit->op = $op;
                        $crit->not = $not;
+                       $crit->cond = $cond;
                        $crit->exclus ="";
                        $crit->param = $v;
                        $args[] = $crit;