3 /***************************************************************************\
4 * SPIP, Systeme de publication pour l'internet *
6 * Copyright (c) 2001-2011 *
7 * Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James *
9 * Ce programme est un logiciel libre distribue sous licence GNU/GPL. *
10 * Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne. *
11 \***************************************************************************/
13 if (!defined('_ECRIRE_INC_VERSION')) return;
15 function format_boucle_html ($avant, $nom, $type, $crit, $corps, $apres, $altern, $prof)
17 $avant = $avant ?
"<B$nom>$avant" : "";
18 $apres = $apres ?
"$apres</B$nom>" : "";
19 $altern = $altern ?
"$altern<//B$nom>" : "";
20 if (!$corps) $corps = " />"; else $corps = ">$corps</BOUCLE$nom>";
21 return "$avant<BOUCLE$nom($type)$crit$corps$apres$altern";
24 function format_inclure_html ($file, $args, $prof)
26 if (strpos($file, '#')===false)
27 $t = $file ?
("(" . $file . ")") : "" ;
29 $t = "{fond=" . $file . '}';
31 $args = !$args ?
'' : ("{" . join(", ",$args) . "}");
32 return ("<INCLURE" . $t . $args . ">");
35 function format_polyglotte_html ($args, $prof)
38 foreach($args as $l=>$t)
39 $contenu[]= ($l ?
"[$l]" : '') . $t;
40 return ("<multi>" . join(" ", $contenu) . "</multi>");
43 function format_idiome_html ($nom, $module, $args, $filtres, $prof)
45 foreach ($args as $k => $v) $args[$k] = "$k=$v";
46 $args = (!$args ?
'' : ('{' . join(',', $args) . '}'));
47 return ("<:" . ($module ?
"$module:" : "") . $nom . $args . $filtres . ":>");
50 function format_champ_html ($nom, $boucle, $etoile, $avant, $apres, $args, $filtres, $prof)
53 . ($boucle ?
($boucle . ":") : "")
59 // Determiner si c'est un champ etendu,
61 $s = ($avant OR $apres OR $filtres
62 OR (strpos($args, '(#') !==false));
64 return ($s ?
"[$avant($nom)$apres]" : $nom);
67 function format_critere_html ($critere)
69 foreach ($critere as $k => $crit) {
71 foreach ($crit as $operande) {
72 list($type, $valeur) = $operande;
73 if ($type == 'champ' AND $valeur[0]=='[') {
74 $valeur = substr($valeur,1,-1);
75 if (preg_match(',^[(](#[^|]*)[)]$,sS', $valeur))
76 $valeur = substr($valeur,1,-1);
80 $critere[$k] = $crit_s;
82 return (!$critere ?
"" : ("{" . join(",", $critere) . "}"));
85 function format_liste_html ($fonc, $args, $prof)
87 return ((($fonc!=='') ?
"|$fonc" : $fonc)
88 . (!$args ?
"" : ("{" . join(",", $args) . "}")));
91 // Concatenation sans separateur: verifier qu'on ne cree pas de faux lexemes
92 function format_suite_html ($args)
94 for($i=0; $i < count($args)-1; $i++
) {
95 list($texte, $type) = $args[$i];
96 list($texte2, $type2) = $args[$i+
1];
97 if (!$texte OR !$texte2) continue;
98 $c1 = substr($texte,-1);
99 if ($type2 !== 'texte') {
100 // si un texte se termine par ( et est suivi d'un champ
101 // ou assimiles, forcer la notation pleine
102 if ($c1 == '(' AND substr($texte2,0,1) == '#')
103 $args[$i+
1][0] = '[(' . $texte2 . ')]';
105 if ($type == 'texte') continue;
106 // si un champ ou assimiles est suivi d'un texte
107 // et si celui-ci commence par un caractere de champ
108 // forcer la notation pleine
109 if (($c1 == '}' AND substr(ltrim($texte2),0,1) == '|')
110 OR (preg_match('/[\w\d_*]/', $c1) AND preg_match('/^[\w\d_*{|]/', $texte2)))
111 $args[$i][0] = '[(' . $texte . ')]';
114 return join("", array_map('array_shift', $args));
117 function format_texte_html ($texte)