[SPIP] +2.1.12
[velocampus/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-2011 *
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')) return;
14
15 function format_boucle_html ($avant, $nom, $type, $crit, $corps, $apres, $altern, $prof)
16 {
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";
22 }
23
24 function format_inclure_html ($file, $args, $prof)
25 {
26 if (strpos($file, '#')===false)
27 $t = $file ? ("(" . $file . ")") : "" ;
28 else {
29 $t = "{fond=" . $file . '}';
30 }
31 $args = !$args ? '' : ("{" . join(", ",$args) . "}");
32 return ("<INCLURE" . $t . $args . ">");
33 }
34
35 function format_polyglotte_html ($args, $prof)
36 {
37 $contenu = array();
38 foreach($args as $l=>$t)
39 $contenu[]= ($l ? "[$l]" : '') . $t;
40 return ("<multi>" . join(" ", $contenu) . "</multi>");
41 }
42
43 function format_idiome_html ($nom, $module, $args, $filtres, $prof)
44 {
45 foreach ($args as $k => $v) $args[$k] = "$k=$v";
46 $args = (!$args ? '' : ('{' . join(',', $args) . '}'));
47 return ("<:" . ($module ? "$module:" : "") . $nom . $args . $filtres . ":>");
48 }
49
50 function format_champ_html ($nom, $boucle, $etoile, $avant, $apres, $args, $filtres, $prof)
51 {
52 $nom = "#"
53 . ($boucle ? ($boucle . ":") : "")
54 . $nom
55 . $etoile
56 . $args
57 . $filtres;
58
59 // Determiner si c'est un champ etendu,
60
61 $s = ($avant OR $apres OR $filtres
62 OR (strpos($args, '(#') !==false));
63
64 return ($s ? "[$avant($nom)$apres]" : $nom);
65 }
66
67 function format_critere_html ($critere)
68 {
69 foreach ($critere as $k => $crit) {
70 $crit_s = '';
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);
77 }
78 $crit_s .= $valeur;
79 }
80 $critere[$k] = $crit_s;
81 }
82 return (!$critere ? "" : ("{" . join(",", $critere) . "}"));
83 }
84
85 function format_liste_html ($fonc, $args, $prof)
86 {
87 return ((($fonc!=='') ? "|$fonc" : $fonc)
88 . (!$args ? "" : ("{" . join(",", $args) . "}")));
89 }
90
91 // Concatenation sans separateur: verifier qu'on ne cree pas de faux lexemes
92 function format_suite_html ($args)
93 {
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 . ')]';
104 } else {
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 . ')]';
112 }
113 }
114 return join("", array_map('array_shift', $args));
115 }
116
117 function format_texte_html ($texte)
118 {
119 return $texte;
120 }
121
122 ?>