[SPIP] v3.2.1-->v3.2.2
[lhc/web/www.git] / www / ecrire / public / normaliser.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 // Les fonctions de ce fichier sont appelees en certains points
18 // de l'analyseur syntaxique afin de normaliser de vieilles syntaxes,
19 // pour fournir au compilateur un arbre de syntaxe abstraite homogene
20
21 // Cas des pseudos filtres |fichier et |lien qui donnent le chemin du fichier
22 // et son URL, remplaces par ** et *: LOGO_XXX** et LOGO_XXX*
23 // Il y a aussi le futur attribut align et l'ecriture #LOGO|#URL
24 // qui passent en arguments de la balise: #LOGO{left,#URL...}
25 // -> http://www.spip.net/fr_article901.html
26
27 function phraser_vieux_logos(&$p) {
28 if ($p->param[0][0]) {
29 $args = array('');
30 } else {
31 $args = array_shift($p->param);
32 }
33
34 foreach ($p->param as $couple) {
35 $nom = trim($couple[0]);
36 if ($nom == '') {
37 array_shift($p->param);
38 break;
39 }
40 $r = phraser_logo_faux_filtres($nom);
41 if ($r === 0) {
42 $c = new Texte;
43 $c->texte = $nom;
44 $args[] = array($c);
45 array_shift($p->param);
46 spip_log("filtre de logo obsolete $nom", 'vieilles_defs');
47 } elseif ($r === 2) {
48 $p->etoile = '**';
49 array_shift($p->param);
50 spip_log("filtre de logo obsolete $nom", 'vieilles_defs');
51 } elseif ($r === 1) {
52 array_shift($p->param);
53 $p->etoile = '*';
54 spip_log("filtre de logo obsolete $nom", 'vieilles_defs');
55
56 } elseif (preg_match("/^" . NOM_DE_CHAMP . '(.*)$/sS', $nom, $m)) {
57 $champ = new Champ();
58 $champ->nom_boucle = $m[2];
59 $champ->nom_champ = $m[3];
60 $champ->etoile = $m[5];
61 $champ = array($champ);
62 if ($m[6]) {
63 $r = new Texte;
64 $r->texte = $m[6];
65 $champ[] = $r;
66 }
67 $args[] = $champ;
68 array_shift($p->param);
69 spip_log("filtre de logo obsolete $nom", 'vieilles_defs');
70
71 } // le cas else est la seule incompatibilite
72
73 }
74 array_unshift($p->param, $args);
75 }
76
77
78 function phraser_logo_faux_filtres($nom) {
79 switch ($nom) {
80 case 'top':
81 case 'left':
82 case 'right':
83 case 'center':
84 case 'bottom':
85 return 0;
86 case 'lien':
87 return 1;
88 case 'fichier':
89 return 2;
90 default:
91 return $nom;
92 }
93 }
94
95
96 // La balise embed_document est a present le modele emb
97
98 function phraser_vieux_emb(&$p) {
99 if (!is_array($p->param)) {
100 $p->param = array();
101 }
102
103 // Produire le premier argument {emb}
104 $texte = new Texte;
105 $texte->texte = 'emb';
106 $param = array('', array($texte));
107
108 // Transformer les filtres en arguments
109 for ($i = 0; $i < count($p->param); $i++) {
110 if ($p->param[$i][0]) {
111 if (!strstr($p->param[$i][0], '=')) {
112 break;
113 }# on a rencontre un vrai filtre, c'est fini
114 $texte = new Texte;
115 $texte->texte = $p->param[$i][0];
116 $param[] = array($texte);
117 }
118 array_shift($p->param);
119 }
120 array_unshift($p->param, $param);
121 spip_log('balise EMBED_DOCUMENT obsolete', 'vieilles_defs');
122 $p->nom_champ = 'MODELE';
123 }
124
125 // Vieux formulaire de recherch
126
127 function phraser_vieux_recherche($p) {
128 if ($p->param[0][0]) {
129 $c = new Texte;
130 $c->texte = $p->param[0][0];
131 $p->param[0][1] = array($c);
132 $p->param[0][0] = '';
133 $p->fonctions = array();
134 spip_log('FORMULAIRE_RECHERCHE avec filtre ' . $c->texte, 'vieilles_defs');
135 }
136 }
137
138 // Gerer la notation [(#EXPOSER|on,off)]
139 function phraser_vieux_exposer($p) {
140 if ($a = $p->fonctions) {
141 preg_match("#([^,]*)(,(.*))?#", $a[0][0], $regs);
142 $args = array();
143 if ($regs[1]) {
144 $a = new Texte;
145 $a->texte = $regs[1];
146 $args = array('', array($a));
147 if ($regs[3]) {
148 $a = new Texte;
149 $a->texte = $regs[3];
150 $args[] = array($a);
151 }
152 }
153 $p->param[0] = $args;
154 $p->fonctions = array();
155 $p->nom_champ = 'EXPOSE';
156 }
157 }
158
159 function phraser_vieux_modele($p) { normaliser_args_inclumodel($p); }
160
161 function phraser_vieux_inclu($p) { normaliser_args_inclumodel($p); }
162
163 function normaliser_args_inclumodel($p) {
164 $params = $p->param;
165 if (!$params) {
166 return;
167 }
168 $args = $params[0];
169 if ($args[0]) {
170 return;
171 } // filtre immediat
172 array_shift($p->param);
173 foreach ($p->param as $l) {
174 if (!array_shift($l)) {
175 $args = array_merge($args, $l);
176 array_shift($p->param);
177 } else {
178 break;
179 } // filtre
180 }
181 array_unshift($p->param, $args);
182 }
183
184 function normaliser_inclure($champ) {
185 normaliser_args_inclumodel($champ);
186 $l = $champ->param[0];
187 if (is_array($l) and !$l[0]) {
188 foreach ($l as $k => $p) {
189 if ($p and $p[0]->type == 'texte' and !strpos($p[0]->texte, '=')) {
190 $p[0]->texte = trim($p[0]->texte);
191 }
192 }
193 foreach ($l as $k => $p) {
194 if (!$p or $p[0]->type != 'texte' or
195 !preg_match('/^fond\s*=\s*(.*)$/', $p[0]->texte, $r)
196 ) {
197 continue;
198 }
199
200 if ($r[1]) {
201 $p[0]->texte = $r[1];
202 } else {
203 unset($p[0]);
204 }
205 $champ->texte = $p;
206 unset($champ->param[0][$k]);
207 if (count($champ->param[0]) == 1) {
208 array_shift($champ->param);
209 }
210
211 return;
212 }
213 }
214 spip_log("inclure sans fond ni fichier");
215 }