e2aaa4044aeebac9df8c0ea8cab761f80b5ee5a5
3 /***************************************************************************\
4 * SPIP, Systeme de publication pour l'internet *
6 * Copyright (c) 2001-2017 *
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')) {
17 function format_boucle_html($avant, $nom, $type, $crit, $corps, $apres, $altern, $prof) {
18 $avant = $avant ?
"<B$nom>$avant" : "";
19 $apres = $apres ?
"$apres</B$nom>" : "";
20 $altern = $altern ?
"$altern<//B$nom>" : "";
24 $corps = ">$corps</BOUCLE$nom>";
27 return "$avant<BOUCLE$nom($type)$crit$corps$apres$altern";
30 function format_inclure_html($file, $args, $prof) {
31 if (strpos($file, '#') === false) {
32 $t = $file ?
("(" . $file . ")") : "";
34 $t = "{fond=" . $file . '}';
36 $args = !$args ?
'' : ("{" . join(", ", $args) . "}");
38 return ("<INCLURE" . $t . $args . ">");
41 function format_polyglotte_html($args, $prof) {
43 foreach ($args as $l => $t) {
44 $contenu[] = ($l ?
"[$l]" : '') . $t;
47 return ("<multi>" . join(" ", $contenu) . "</multi>");
50 function format_idiome_html($nom, $module, $args, $filtres, $prof) {
51 foreach ($args as $k => $v) {
54 $args = (!$args ?
'' : ('{' . join(',', $args) . '}'));
56 return ("<:" . ($module ?
"$module:" : "") . $nom . $args . $filtres . ":>");
59 function format_champ_html($nom, $boucle, $etoile, $avant, $apres, $args, $filtres, $prof) {
61 . ($boucle ?
($boucle . ":") : "")
67 // Determiner si c'est un champ etendu,
69 $s = ($avant or $apres or $filtres
70 or (strpos($args, '(#') !== false));
72 return ($s ?
"[$avant($nom)$apres]" : $nom);
75 function format_critere_html($critere) {
76 foreach ($critere as $k => $crit) {
78 foreach ($crit as $operande) {
79 list($type, $valeur) = $operande;
80 if ($type == 'champ' and $valeur[0] == '[') {
81 $valeur = substr($valeur, 1, -1);
82 if (preg_match(',^[(](#[^|]*)[)]$,sS', $valeur)) {
83 $valeur = substr($valeur, 1, -1);
88 $critere[$k] = $crit_s;
91 return (!$critere ?
"" : ("{" . join(",", $critere) . "}"));
94 function format_liste_html($fonc, $args, $prof) {
95 return ((($fonc !== '') ?
"|$fonc" : $fonc)
96 . (!$args ?
"" : ("{" . join(",", $args) . "}")));
99 // Concatenation sans separateur: verifier qu'on ne cree pas de faux lexemes
100 function format_suite_html($args) {
101 for ($i = 0; $i < count($args) - 1; $i++
) {
102 list($texte, $type) = $args[$i];
103 list($texte2, $type2) = $args[$i +
1];
104 if (!$texte or !$texte2) {
107 $c1 = substr($texte, -1);
108 if ($type2 !== 'texte') {
109 // si un texte se termine par ( et est suivi d'un champ
110 // ou assimiles, forcer la notation pleine
111 if ($c1 == '(' and substr($texte2, 0, 1) == '#') {
112 $args[$i +
1][0] = '[(' . $texte2 . ')]';
115 if ($type == 'texte') {
118 // si un champ ou assimiles est suivi d'un texte
119 // et si celui-ci commence par un caractere de champ
120 // forcer la notation pleine
121 if (($c1 == '}' and substr(ltrim($texte2), 0, 1) == '|')
122 or (preg_match('/[\w\d_*]/', $c1) and preg_match('/^[\w\d_*{|]/', $texte2))
124 $args[$i][0] = '[(' . $texte . ')]';
129 return join("", array_map('array_shift', $args));
132 function format_texte_html($texte) {