X-Git-Url: http://git.cyclocoop.org/?p=ptitvelo%2Fweb%2Fwww.git;a=blobdiff_plain;f=www%2Fecrire%2Fpublic%2Fphraser_html.php;fp=www%2Fecrire%2Fpublic%2Fphraser_html.php;h=cf15a28afca0b56256106c458095ae7a6977e062;hp=1467851ef348a6f12390a56a9e7052c1bd367e3e;hb=b97874b04ea8ca43d21b7ef7309feff8ef0e4a07;hpb=92c7d7f7bccb9629bb7c81b9582b56b61c3f8ec9 diff --git a/www/ecrire/public/phraser_html.php b/www/ecrire/public/phraser_html.php index 1467851..cf15a28 100644 --- a/www/ecrire/public/phraser_html.php +++ b/www/ecrire/public/phraser_html.php @@ -32,7 +32,8 @@ define('CHAMP_ETENDU', '/\[([^]\[]*)\(' . NOM_DE_CHAMP . '([^[)]*\)[^]\[]*)\]/S' define('BALISE_INCLURE','/(.*),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;