[SPIP] v3.2.1-->v3.2.2
[lhc/web/www.git] / www / ecrire / public / format_html.php
1 <?php
2
3 /***************************************************************************\
4 * SPIP, Systeme de publication pour l'internet *
5 * *
6 * Copyright (c) 2001-2019 *
7 * Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James *
8 * *
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 \***************************************************************************/
12
13 if (!defined('_ECRIRE_INC_VERSION')) {
14 return;
15 }
16
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>" : "";
21 if (!$corps) {
22 $corps = " />";
23 } else {
24 $corps = ">$corps</BOUCLE$nom>";
25 }
26
27 return "$avant<BOUCLE$nom($type)$crit$corps$apres$altern";
28 }
29
30 function format_inclure_html($file, $args, $prof) {
31 if (strpos($file, '#') === false) {
32 $t = $file ? ("(" . $file . ")") : "";
33 } else {
34 $t = "{fond=" . $file . '}';
35 }
36 $args = !$args ? '' : ("{" . join(", ", $args) . "}");
37
38 return ("<INCLURE" . $t . $args . ">");
39 }
40
41 function format_polyglotte_html($args, $prof) {
42 $contenu = array();
43 foreach ($args as $l => $t) {
44 $contenu[] = ($l ? "[$l]" : '') . $t;
45 }
46
47 return ("<multi>" . join(" ", $contenu) . "</multi>");
48 }
49
50 function format_idiome_html($nom, $module, $args, $filtres, $prof) {
51 foreach ($args as $k => $v) {
52 $args[$k] = "$k=$v";
53 }
54 $args = (!$args ? '' : ('{' . join(',', $args) . '}'));
55
56 return ("<:" . ($module ? "$module:" : "") . $nom . $args . $filtres . ":>");
57 }
58
59 function format_champ_html($nom, $boucle, $etoile, $avant, $apres, $args, $filtres, $prof) {
60 $nom = "#"
61 . ($boucle ? ($boucle . ":") : "")
62 . $nom
63 . $etoile
64 . $args
65 . $filtres;
66
67 // Determiner si c'est un champ etendu,
68
69 $s = ($avant or $apres or $filtres
70 or (strpos($args, '(#') !== false));
71
72 return ($s ? "[$avant($nom)$apres]" : $nom);
73 }
74
75 function format_critere_html($critere) {
76 foreach ($critere as $k => $crit) {
77 $crit_s = '';
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);
84 }
85 }
86 $crit_s .= $valeur;
87 }
88 $critere[$k] = $crit_s;
89 }
90
91 return (!$critere ? "" : ("{" . join(",", $critere) . "}"));
92 }
93
94 function format_liste_html($fonc, $args, $prof) {
95 return ((($fonc !== '') ? "|$fonc" : $fonc)
96 . (!$args ? "" : ("{" . join(",", $args) . "}")));
97 }
98
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) {
105 continue;
106 }
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 . ')]';
113 }
114 } else {
115 if ($type == 'texte') {
116 continue;
117 }
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))
123 ) {
124 $args[$i][0] = '[(' . $texte . ')]';
125 }
126 }
127 }
128
129 return join("", array_map('array_shift', $args));
130 }
131
132 function format_texte_html($texte) {
133 return $texte;
134 }