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