Commit | Line | Data |
---|---|---|
c495c100 P |
1 | <?php |
2 | ||
3 | /***************************************************************************\ | |
4 | * SPIP, Systeme de publication pour l'internet * | |
5 | * * | |
6 | * Copyright (c) 2001-2007 * | |
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 | ||
14 | // | |
15 | // Ce fichier regroupe la quasi totalite des definitions de #BALISES de spip | |
16 | // Pour chaque balise, il est possible de surcharger, dans mes_fonctions, | |
17 | // la fonction balise_TOTO_dist par une fonction balise_TOTO() respectant la | |
18 | // meme API : | |
19 | // elle recoit en entree un objet de classe CHAMP, le modifie et le retourne. | |
20 | // Cette classe est definie dans inc-compilo-index | |
21 | // | |
22 | ||
23 | if (!defined("_ECRIRE_INC_VERSION")) return; | |
24 | ||
25 | // http://doc.spip.org/@interprete_argument_balise | |
26 | function interprete_argument_balise($n,$p) { | |
27 | if (($p->param) && (!$p->param[0][0]) && (count($p->param[0])>$n)) | |
28 | return calculer_liste($p->param[0][$n], | |
29 | $p->descr, | |
30 | $p->boucles, | |
31 | $p->id_boucle); | |
32 | else | |
33 | return NULL; | |
34 | } | |
35 | // | |
36 | // Definition des balises | |
37 | // | |
38 | // http://doc.spip.org/@balise_NOM_SITE_SPIP_dist | |
39 | function balise_NOM_SITE_SPIP_dist($p) { | |
40 | $p->code = "\$GLOBALS['meta']['nom_site']"; | |
41 | #$p->interdire_scripts = true; | |
42 | return $p; | |
43 | } | |
44 | ||
45 | // http://doc.spip.org/@balise_EMAIL_WEBMASTER_dist | |
46 | function balise_EMAIL_WEBMASTER_dist($p) { | |
47 | $p->code = "\$GLOBALS['meta']['email_webmaster']"; | |
48 | #$p->interdire_scripts = true; | |
49 | return $p; | |
50 | } | |
51 | ||
52 | // http://doc.spip.org/@balise_DESCRIPTIF_SITE_SPIP_dist | |
53 | function balise_DESCRIPTIF_SITE_SPIP_dist($p) { | |
54 | $p->code = "\$GLOBALS['meta']['descriptif_site']"; | |
55 | #$p->interdire_scripts = true; | |
56 | return $p; | |
57 | } | |
58 | ||
59 | // http://doc.spip.org/@balise_CHARSET_dist | |
60 | function balise_CHARSET_dist($p) { | |
61 | $p->code = "\$GLOBALS['meta']['charset']"; | |
62 | #$p->interdire_scripts = true; | |
63 | return $p; | |
64 | } | |
65 | ||
66 | // http://doc.spip.org/@balise_LANG_LEFT_dist | |
67 | function balise_LANG_LEFT_dist($p) { | |
68 | $_lang = champ_sql('lang', $p); | |
69 | $p->code = "lang_dir(($_lang ? $_lang : \$GLOBALS['spip_lang']),'left','right')"; | |
70 | $p->interdire_scripts = false; | |
71 | return $p; | |
72 | } | |
73 | ||
74 | // http://doc.spip.org/@balise_LANG_RIGHT_dist | |
75 | function balise_LANG_RIGHT_dist($p) { | |
76 | $_lang = champ_sql('lang', $p); | |
77 | $p->code = "lang_dir(($_lang ? $_lang : \$GLOBALS['spip_lang']),'right','left')"; | |
78 | $p->interdire_scripts = false; | |
79 | return $p; | |
80 | } | |
81 | ||
82 | // http://doc.spip.org/@balise_LANG_DIR_dist | |
83 | function balise_LANG_DIR_dist($p) { | |
84 | $_lang = champ_sql('lang', $p); | |
85 | $p->code = "lang_dir(($_lang ? $_lang : \$GLOBALS['spip_lang']),'ltr','rtl')"; | |
86 | $p->interdire_scripts = false; | |
87 | return $p; | |
88 | } | |
89 | ||
90 | // http://doc.spip.org/@balise_PUCE_dist | |
91 | function balise_PUCE_dist($p) { | |
92 | $p->code = "definir_puce()"; | |
93 | $p->interdire_scripts = false; | |
94 | return $p; | |
95 | } | |
96 | ||
97 | // #DATE | |
98 | // Cette fonction sait aller chercher dans le contexte general | |
99 | // quand #DATE est en dehors des boucles | |
100 | // http://www.spip.net/fr_article1971.html | |
101 | // http://doc.spip.org/@balise_DATE_dist | |
102 | function balise_DATE_dist ($p) { | |
103 | $_date = champ_sql('date', $p); | |
104 | $p->code = "$_date"; | |
105 | $p->interdire_scripts = false; | |
106 | return $p; | |
107 | } | |
108 | ||
109 | // #DATE_REDAC | |
110 | // http://www.spip.net/fr_article1971.html | |
111 | // http://doc.spip.org/@balise_DATE_REDAC_dist | |
112 | function balise_DATE_REDAC_dist ($p) { | |
113 | $_date = champ_sql('date_redac', $p); | |
114 | $p->code = "$_date"; | |
115 | $p->interdire_scripts = false; | |
116 | return $p; | |
117 | } | |
118 | ||
119 | // #DATE_MODIF | |
120 | // http://www.spip.net/fr_article1971.html | |
121 | // http://doc.spip.org/@balise_DATE_MODIF_dist | |
122 | function balise_DATE_MODIF_dist ($p) { | |
123 | $_date = champ_sql('date_modif', $p); | |
124 | $p->code = "$_date"; | |
125 | $p->interdire_scripts = false; | |
126 | return $p; | |
127 | } | |
128 | ||
129 | // #DATE_NOUVEAUTES | |
130 | // http://www.spip.net/fr_article1971.html | |
131 | // http://doc.spip.org/@balise_DATE_NOUVEAUTES_dist | |
132 | function balise_DATE_NOUVEAUTES_dist($p) { | |
133 | $p->code = "((\$GLOBALS['meta']['quoi_de_neuf'] == 'oui' | |
134 | AND @file_exists(_DIR_TMP . 'mail.lock')) ? | |
135 | normaliser_date(@filemtime(_DIR_TMP . 'mail.lock')) : | |
136 | \"'0000-00-00'\")"; | |
137 | $p->interdire_scripts = false; | |
138 | return $p; | |
139 | } | |
140 | ||
141 | // http://doc.spip.org/@balise_DOSSIER_SQUELETTE_dist | |
142 | function balise_DOSSIER_SQUELETTE_dist($p) { | |
143 | $code = substr(addslashes(dirname($p->descr['sourcefile'])), strlen(_DIR_RACINE)); | |
144 | $p->code = "_DIR_RACINE . '$code'" . | |
145 | $p->interdire_scripts = false; | |
146 | return $p; | |
147 | } | |
148 | ||
149 | // http://doc.spip.org/@balise_SQUELETTE_dist | |
150 | function balise_SQUELETTE_dist($p) { | |
151 | $code = addslashes($p->descr['sourcefile']); | |
152 | $p->code = "'$code'" . | |
153 | $p->interdire_scripts = false; | |
154 | return $p; | |
155 | } | |
156 | ||
157 | // http://doc.spip.org/@balise_SPIP_VERSION_dist | |
158 | function balise_SPIP_VERSION_dist($p) { | |
159 | $p->code = "spip_version()"; | |
160 | $p->interdire_scripts = false; | |
161 | return $p; | |
162 | } | |
163 | ||
164 | // http://doc.spip.org/@balise_URL_SITE_SPIP_dist | |
165 | function balise_URL_SITE_SPIP_dist($p) { | |
166 | $p->code = "sinon(\$GLOBALS['meta']['adresse_site'],'.')"; | |
167 | $p->code = "htmlspecialchars(".$p->code.")"; | |
168 | $p->interdire_scripts = false; | |
169 | return $p; | |
170 | } | |
171 | ||
172 | ||
173 | // http://doc.spip.org/@balise_URL_ARTICLE_dist | |
174 | function balise_URL_ARTICLE_dist($p) { | |
175 | $_type = $p->type_requete; | |
176 | ||
177 | // Cas particulier des boucles (SYNDIC_ARTICLES) | |
178 | if ($_type == 'syndic_articles') { | |
179 | $p->code = champ_sql('url', $p); | |
180 | } | |
181 | ||
182 | // Cas general : chercher un id_article dans la pile | |
183 | else { | |
184 | $_id_article = interprete_argument_balise(1,$p); | |
185 | if (!$_id_article) | |
186 | $_id_article = champ_sql('id_article', $p); | |
187 | $p->code = "generer_url_article($_id_article)"; | |
188 | ||
189 | if ($p->boucles[$p->nom_boucle ? $p->nom_boucle : $p->id_boucle]->hash) | |
190 | $p->code = "url_var_recherche(" . $p->code . ")"; | |
191 | } | |
192 | ||
193 | $p->interdire_scripts = false; | |
194 | return $p; | |
195 | } | |
196 | ||
197 | // http://doc.spip.org/@balise_URL_RUBRIQUE_dist | |
198 | function balise_URL_RUBRIQUE_dist($p) { | |
199 | $_id_rubrique = interprete_argument_balise(1,$p); | |
200 | if (!$_id_rubrique) | |
201 | $_id_rubrique = champ_sql('id_rubrique',$p); | |
202 | $p->code = "generer_url_rubrique($_id_rubrique)" ; | |
203 | ||
204 | if ($p->boucles[$p->nom_boucle ? $p->nom_boucle : $p->id_boucle]->hash) | |
205 | $p->code = "url_var_recherche(" . $p->code . ")"; | |
206 | ||
207 | $p->interdire_scripts = false; | |
208 | return $p; | |
209 | } | |
210 | ||
211 | // http://doc.spip.org/@balise_URL_BREVE_dist | |
212 | function balise_URL_BREVE_dist($p) { | |
213 | $_id_breve = interprete_argument_balise(1,$p); | |
214 | if (!$_id_breve) | |
215 | $_id_breve = champ_sql('id_breve',$p); | |
216 | $p->code = "generer_url_breve($_id_breve)"; | |
217 | ||
218 | if ($p->boucles[$p->nom_boucle ? $p->nom_boucle : $p->id_boucle]->hash) | |
219 | $p->code = "url_var_recherche(" . $p->code . ")"; | |
220 | ||
221 | $p->interdire_scripts = false; | |
222 | return $p; | |
223 | } | |
224 | ||
225 | // http://doc.spip.org/@balise_URL_MOT_dist | |
226 | function balise_URL_MOT_dist($p) { | |
227 | $_id_mot = interprete_argument_balise(1,$p); | |
228 | if (!$_id_mot) | |
229 | $_id_mot = champ_sql('id_mot',$p); | |
230 | $p->code = "generer_url_mot($_id_mot)"; | |
231 | ||
232 | if ($p->boucles[$p->nom_boucle ? $p->nom_boucle : $p->id_boucle]->hash) | |
233 | $p->code = "url_var_recherche(" . $p->code . ")"; | |
234 | ||
235 | $p->interdire_scripts = false; | |
236 | return $p; | |
237 | } | |
238 | ||
239 | // #NOM_SITE affiche le nom du site, ou sinon l'URL ou le titre de l'objet | |
240 | // http://doc.spip.org/@balise_NOM_SITE_dist | |
241 | function balise_NOM_SITE_dist($p) { | |
242 | if (!$p->etoile) { | |
243 | $p->code = "construire_titre_lien(" . | |
244 | champ_sql('nom_site',$p) ."," . | |
245 | champ_sql('url_site',$p) . | |
246 | ")"; | |
247 | } else | |
248 | $p->code = champ_sql('nom_site',$p); | |
249 | ||
250 | $p->interdire_scripts = true; | |
251 | return $p; | |
252 | } | |
253 | ||
254 | # URL_SITE est une donnee "brute" tiree de la base de donnees | |
255 | # URL_SYNDIC correspond a l'adresse de son backend. | |
256 | # Il n'existe pas de balise pour afficher generer_url_site($id_syndic), | |
257 | # a part [(#ID_SYNDIC|generer_url_site)] | |
258 | ||
259 | // http://doc.spip.org/@balise_URL_FORUM_dist | |
260 | function balise_URL_FORUM_dist($p, $show_thread = 'false') { | |
261 | $_id_forum = interprete_argument_balise(1,$p); | |
262 | if (!$_id_forum) | |
263 | $_id_forum = champ_sql('id_forum',$p); | |
264 | $p->code = "generer_url_forum($_id_forum, $show_thread)"; | |
265 | ||
266 | if ($p->boucles[$p->nom_boucle ? $p->nom_boucle : $p->id_boucle]->hash) | |
267 | $p->code = "url_var_recherche(" . $p->code . ")"; | |
268 | ||
269 | $p->interdire_scripts = false; | |
270 | return $p; | |
271 | } | |
272 | ||
273 | // http://doc.spip.org/@balise_URL_DOCUMENT_dist | |
274 | function balise_URL_DOCUMENT_dist($p) { | |
275 | $_id_document = interprete_argument_balise(1,$p); | |
276 | if (!$_id_document) | |
277 | $_id_document = champ_sql('id_document',$p); | |
278 | $p->code = "generer_url_document($_id_document)"; | |
279 | ||
280 | $p->interdire_scripts = false; | |
281 | return $p; | |
282 | } | |
283 | ||
284 | // http://doc.spip.org/@balise_URL_AUTEUR_dist | |
285 | function balise_URL_AUTEUR_dist($p) { | |
286 | $_id_auteur = interprete_argument_balise(1,$p); | |
287 | if (!$_id_auteur) | |
288 | $_id_auteur = champ_sql('id_auteur',$p); | |
289 | $p->code = "generer_url_auteur($_id_auteur)"; | |
290 | ||
291 | if ($p->boucles[$p->nom_boucle ? $p->nom_boucle : $p->id_boucle]->hash) | |
292 | $p->code = "url_var_recherche(" . $p->code . ")"; | |
293 | ||
294 | $p->interdire_scripts = false; | |
295 | return $p; | |
296 | } | |
297 | ||
298 | // http://doc.spip.org/@balise_NOTES_dist | |
299 | function balise_NOTES_dist($p) { | |
300 | // Recuperer les notes | |
301 | $p->code = 'calculer_notes()'; | |
302 | #$p->interdire_scripts = true; | |
303 | return $p; | |
304 | } | |
305 | ||
306 | // http://doc.spip.org/@balise_RECHERCHE_dist | |
307 | function balise_RECHERCHE_dist($p) { | |
308 | $p->code = 'entites_html(_request("recherche"))'; | |
309 | $p->interdire_scripts = false; | |
310 | return $p; | |
311 | } | |
312 | ||
313 | // http://doc.spip.org/@balise_COMPTEUR_BOUCLE_dist | |
314 | function balise_COMPTEUR_BOUCLE_dist($p) { | |
315 | $b = $p->nom_boucle ? $p->nom_boucle : $p->descr['id_mere']; | |
316 | if ($b === '') { | |
317 | erreur_squelette( | |
318 | _T('zbug_champ_hors_boucle', | |
319 | array('champ' => '#COMPTEUR_BOUCLE') | |
320 | ), $p->id_boucle); | |
321 | $p->code = "''"; | |
322 | } else { | |
323 | $p->code = "\$Numrows['$b']['compteur_boucle']"; | |
324 | $p->boucles[$b]->cptrows = true; | |
325 | $p->interdire_scripts = false; | |
326 | return $p; | |
327 | } | |
328 | } | |
329 | ||
330 | // http://doc.spip.org/@balise_TOTAL_BOUCLE_dist | |
331 | function balise_TOTAL_BOUCLE_dist($p) { | |
332 | $b = $p->nom_boucle ? $p->nom_boucle : $p->descr['id_mere']; | |
333 | if ($b === '' || !isset($p->boucles[$b])) { | |
334 | erreur_squelette( | |
335 | _T('zbug_champ_hors_boucle', | |
336 | array('champ' => "#$b" . 'TOTAL_BOUCLE') | |
337 | ), $p->id_boucle); | |
338 | $p->code = "''"; | |
339 | } else { | |
340 | $p->code = "\$Numrows['$b']['total']"; | |
341 | $p->boucles[$b]->numrows = true; | |
342 | $p->interdire_scripts = false; | |
343 | } | |
344 | return $p; | |
345 | } | |
346 | ||
347 | // Si on est hors d'une boucle {recherche}, ne pas "prendre" cette balise | |
348 | // http://doc.spip.org/@balise_POINTS_dist | |
349 | function balise_POINTS_dist($p) { | |
350 | if ($p->boucles[$p->nom_boucle ? $p->nom_boucle : $p->id_boucle]->hash) | |
351 | return rindex_pile($p, 'points', 'recherche'); | |
352 | else | |
353 | return NULL; | |
354 | } | |
355 | ||
356 | // http://doc.spip.org/@balise_POPULARITE_ABSOLUE_dist | |
357 | function balise_POPULARITE_ABSOLUE_dist($p) { | |
358 | $p->code = 'ceil(' . | |
359 | champ_sql('popularite', $p) . | |
360 | ')'; | |
361 | $p->interdire_scripts = false; | |
362 | return $p; | |
363 | } | |
364 | ||
365 | // http://doc.spip.org/@balise_POPULARITE_SITE_dist | |
366 | function balise_POPULARITE_SITE_dist($p) { | |
367 | $p->code = 'ceil($GLOBALS["meta"][\'popularite_total\'])'; | |
368 | $p->interdire_scripts = false; | |
369 | return $p; | |
370 | } | |
371 | ||
372 | // http://doc.spip.org/@balise_POPULARITE_MAX_dist | |
373 | function balise_POPULARITE_MAX_dist($p) { | |
374 | $p->code = 'ceil($GLOBALS["meta"][\'popularite_max\'])'; | |
375 | $p->interdire_scripts = false; | |
376 | return $p; | |
377 | } | |
378 | ||
379 | // http://doc.spip.org/@balise_EXPOSE_dist | |
380 | function balise_EXPOSE_dist($p) { | |
381 | $on = "'on'"; | |
382 | $off= "''"; | |
383 | ||
384 | if (($v = interprete_argument_balise(1,$p))!==NULL){ | |
385 | $on = $v; | |
386 | if (($v = interprete_argument_balise(2,$p))!==NULL) | |
387 | $off = $v; | |
388 | ||
389 | // autres filtres | |
390 | array_shift($p->param); | |
391 | } | |
392 | return calculer_balise_expose($p, $on, $off); | |
393 | } | |
394 | ||
395 | // #EXPOSER est obsolete. utiliser #EXPOSE ci-dessus | |
396 | // http://doc.spip.org/@balise_EXPOSER_dist | |
397 | function balise_EXPOSER_dist($p) | |
398 | { | |
399 | $on = "'on'"; | |
400 | $off= "''"; | |
401 | if ($a = ($p->fonctions)) { | |
402 | // Gerer la notation [(#EXPOSER|on,off)] | |
403 | $onoff = array_shift($a); | |
404 | preg_match("#([^,]*)(,(.*))?#", $onoff[0], $regs); | |
405 | $on = "" . _q($regs[1]); | |
406 | $off = "" . _q($regs[3]) ; | |
407 | // autres filtres | |
408 | array_shift($p->param); | |
409 | } | |
410 | return calculer_balise_expose($p, $on, $off); | |
411 | } | |
412 | ||
413 | // http://doc.spip.org/@calculer_balise_expose | |
414 | function calculer_balise_expose($p, $on, $off) | |
415 | { | |
416 | $primary_key = $p->boucles[$p->id_boucle]->primary; | |
417 | if (!$primary_key) { | |
418 | erreur_squelette(_T('zbug_champ_hors_boucle', | |
419 | array('champ' => '#EXPOSER') | |
420 | ), $p->id_boucle); | |
421 | ||
422 | } | |
423 | ||
424 | $p->code = '(calcul_exposer(' | |
425 | .champ_sql($primary_key, $p) | |
426 | .", '$primary_key', \$Pile[0]) ? $on : $off)"; | |
427 | $p->interdire_scripts = false; | |
428 | return $p; | |
429 | } | |
430 | ||
431 | // | |
432 | // Inserer directement un document dans le squelette | |
433 | // devient un alias de #MODELE{emb} | |
434 | // | |
435 | // On insere simplement un argument {emb} en debut de liste | |
436 | // | |
437 | // Attention la syntaxe est derogatoire : il faut donc attraper | |
438 | // tous les faux-filtres "|autostart=true" et les transformer | |
439 | // en arguments "{autostart=true}" | |
440 | // | |
441 | // On s'arrete au premier filtre ne contenant pas de =, afin de | |
442 | // pouvoir filtrer le resultat | |
443 | // | |
444 | // http://doc.spip.org/@balise_EMBED_DOCUMENT_dist | |
445 | function balise_EMBED_DOCUMENT_dist($p) { | |
446 | balise_distante_interdite($p); | |
447 | ||
448 | if (!is_array($p->param)) | |
449 | $p->param=array(); | |
450 | ||
451 | // Produire le premier argument {emb} | |
452 | $texte = new Texte; | |
453 | $texte->type='texte'; | |
454 | $texte->texte='emb'; | |
455 | $param = array(0=>NULL, 1=>array(0=>$texte)); | |
456 | array_unshift($p->param, $param); | |
457 | ||
458 | // Transformer les filtres en arguments | |
459 | for ($i=1; $i<count($p->param); $i++) { | |
460 | if ($p->param[$i][0]) { | |
461 | if (!strstr($p->param[$i][0], '=')) | |
462 | break;# on a rencontre un vrai filtre, c'est fini | |
463 | $texte = new Texte; | |
464 | $texte->type='texte'; | |
465 | $texte->texte=$p->param[$i][0]; | |
466 | $param = array(0=>$texte); | |
467 | $p->param[$i][1] = $param; | |
468 | $p->param[$i][0] = NULL; | |
469 | } | |
470 | } | |
471 | ||
472 | // Appeler la balise #MODELE{emb}{arguments} | |
473 | if (!function_exists($f = 'balise_modele')) | |
474 | $f = 'balise_modele_dist'; | |
475 | return $f($p); | |
476 | } | |
477 | ||
478 | // Debut et fin de surlignage auto des mots de la recherche | |
479 | // on insere une balise Span avec une classe sans spec: | |
480 | // c'est transparent s'il n'y a pas de recherche, | |
481 | // sinon elles seront remplacees par les fontions de inc_surligne | |
482 | ||
483 | // http://doc.spip.org/@balise_DEBUT_SURLIGNE_dist | |
484 | function balise_DEBUT_SURLIGNE_dist($p) { | |
485 | include_spip('inc/surligne'); | |
486 | $p->code = "'<" . MARQUEUR_SURLIGNE . "'"; | |
487 | return $p; | |
488 | } | |
489 | // http://doc.spip.org/@balise_FIN_SURLIGNE_dist | |
490 | function balise_FIN_SURLIGNE_dist($p) { | |
491 | include_spip('inc/surligne'); | |
492 | $p->code = "'<" . MARQUEUR_FSURLIGNE . "'"; | |
493 | return $p; | |
494 | } | |
495 | ||
496 | ||
497 | // #SPIP_CRON | |
498 | // a documenter | |
499 | // insere un <div> avec un lien background-image vers les taches de fond. | |
500 | // Si cette balise est presente sur la page de sommaire, le site ne devrait | |
501 | // quasiment jamais se trouver ralenti par des taches de fond un peu lentes | |
502 | // http://doc.spip.org/@balise_SPIP_CRON_dist | |
503 | function balise_SPIP_CRON_dist ($p) { | |
504 | $p->code = '"<!-- SPIP-CRON --><div style=\"background-image: url(\'' . | |
505 | generer_url_action('cron') . | |
506 | '\');\"></div>"'; | |
507 | $p->interdire_scripts = false; | |
508 | return $p; | |
509 | } | |
510 | ||
511 | ||
512 | // #INTRODUCTION | |
513 | // http://www.spip.net/@introduction | |
514 | // http://doc.spip.org/@balise_INTRODUCTION_dist | |
515 | function balise_INTRODUCTION_dist ($p) { | |
516 | $type = $p->type_requete; | |
517 | $_texte = champ_sql('texte', $p); | |
518 | if ($type == 'articles') { | |
519 | $_chapo = champ_sql('chapo', $p); | |
520 | $_descriptif = champ_sql('descriptif', $p); | |
521 | } else { | |
522 | $_chapo = "''"; | |
523 | $_descriptif = "''"; | |
524 | } | |
525 | $p->code = "calcul_introduction('$type', $_texte, $_chapo, $_descriptif)"; | |
526 | ||
527 | #$p->interdire_scripts = true; | |
528 | return $p; | |
529 | } | |
530 | ||
531 | ||
532 | // #LANG | |
533 | // affiche la langue de l'objet (ou superieure), et a defaut la langue courante | |
534 | // (celle du site ou celle qui a ete passee dans l'URL par le visiteur) | |
535 | // #LANG* n'affiche rien si aucune langue n'est trouvee dans le sql/le contexte | |
536 | // http://doc.spip.org/@balise_LANG_dist | |
537 | function balise_LANG_dist ($p) { | |
538 | $_lang = champ_sql('lang', $p); | |
539 | if (!$p->etoile) | |
540 | $p->code = "htmlentities($_lang ? $_lang : \$GLOBALS['spip_lang'])"; | |
541 | else | |
542 | $p->code = "htmlentities($_lang)"; | |
543 | $p->interdire_scripts = false; | |
544 | return $p; | |
545 | } | |
546 | ||
547 | ||
548 | // #LESAUTEURS | |
549 | // les auteurs d'un article (ou d'un article syndique) | |
550 | // http://www.spip.net/fr_article902.html | |
551 | // http://www.spip.net/fr_article911.html | |
552 | // http://doc.spip.org/@balise_LESAUTEURS_dist | |
553 | function balise_LESAUTEURS_dist ($p) { | |
554 | // Cherche le champ 'lesauteurs' dans la pile | |
555 | $_lesauteurs = champ_sql('lesauteurs', $p); | |
556 | ||
557 | // Si le champ n'existe pas (cas de spip_articles), on applique | |
558 | // le modele lesauteurs.html en passant id_article dans le contexte; | |
559 | // dans le cas contraire on prend le champ 'lesauteurs' (cas de | |
560 | // spip_syndic_articles) | |
561 | if ($_lesauteurs AND $_lesauteurs != '$Pile[0][\'lesauteurs\']') { | |
562 | $p->code = "safehtml($_lesauteurs)"; | |
563 | // $p->interdire_scripts = true; | |
564 | } else { | |
565 | $p->code = "recuperer_fond( | |
566 | 'modeles/lesauteurs', | |
567 | array('id_article' => ".champ_sql('id_article', $p)."))"; | |
568 | $p->interdire_scripts = false; // securite apposee par recuperer_fond() | |
569 | } | |
570 | ||
571 | return $p; | |
572 | } | |
573 | ||
574 | ||
575 | // #RANG | |
576 | // affiche le "numero de l'article" quand on l'a titre '1. Premier article'; | |
577 | // ceci est transitoire afin de preparer une migration vers un vrai systeme de | |
578 | // tri des articles dans une rubrique (et plus si affinites) | |
579 | // http://doc.spip.org/@balise_RANG_dist | |
580 | function balise_RANG_dist ($p) { | |
581 | $_titre = champ_sql('titre', $p); | |
582 | $_rang = champ_sql('rang', $p); | |
583 | $p->code = "(($_rang)?($_rang):recuperer_numero($_titre))"; | |
584 | $p->interdire_scripts = false; | |
585 | return $p; | |
586 | } | |
587 | ||
588 | ||
589 | // #PETITION | |
590 | // retourne '' si l'article courant n'a pas de petition | |
591 | // le texte de celle-ci sinon (et ' ' si il est vide) | |
592 | // cf FORMULAIRE_PETITION | |
593 | ||
594 | // http://doc.spip.org/@balise_PETITION_dist | |
595 | function balise_PETITION_dist ($p) { | |
596 | $nom = $p->id_boucle; | |
597 | $p->code = "sql_petitions(" . | |
598 | champ_sql('id_article', $p) . | |
599 | ",'" . | |
600 | $p->boucles[$nom]->type_requete . | |
601 | "','" . | |
602 | $nom . | |
603 | "','" . | |
604 | $p->boucles[$nom]->sql_serveur . | |
605 | "', \$Cache)"; | |
606 | $p->interdire_scripts = false; | |
607 | return $p; | |
608 | } | |
609 | ||
610 | ||
611 | // #POPULARITE | |
612 | // http://www.spip.net/fr_article1846.html | |
613 | // http://doc.spip.org/@balise_POPULARITE_dist | |
614 | function balise_POPULARITE_dist ($p) { | |
615 | $_popularite = champ_sql('popularite', $p); | |
616 | $p->code = "(ceil(min(100, 100 * $_popularite | |
617 | / max(1 , 0 + \$GLOBALS['meta']['popularite_max']))))"; | |
618 | $p->interdire_scripts = false; | |
619 | return $p; | |
620 | } | |
621 | ||
622 | // #PAGINATION | |
623 | // http://www.spip.net/fr_articleXXXX.html | |
624 | // http://doc.spip.org/@balise_PAGINATION_dist | |
625 | function balise_PAGINATION_dist($p, $liste='true') { | |
626 | $b = $p->nom_boucle ? $p->nom_boucle : $p->descr['id_mere']; | |
627 | ||
628 | // s'il n'y a pas de nom de boucle, on ne peut pas paginer | |
629 | if ($b === '') { | |
630 | erreur_squelette( | |
631 | _T('zbug_champ_hors_boucle', | |
632 | array('champ' => '#PAGINATION') | |
633 | ), $p->id_boucle); | |
634 | $p->code = "''"; | |
635 | return $p; | |
636 | } | |
637 | ||
638 | // s'il n'y a pas de total_parties, c'est qu'on se trouve | |
639 | // dans un boucle recurive ou qu'on a oublie le critere {pagination} | |
640 | if (!$p->boucles[$b]->total_parties) { | |
641 | erreur_squelette( | |
642 | _T('zbug_pagination_sans_critere', | |
643 | array('champ' => '#PAGINATION') | |
644 | ), $p->id_boucle); | |
645 | $p->code = "''"; | |
646 | return $p; | |
647 | } | |
648 | $__modele = interprete_argument_balise(1,$p); | |
649 | $__modele = $__modele?",$__modele":""; | |
650 | ||
651 | $p->boucles[$b]->numrows = true; | |
652 | ||
653 | $p->code = "calcul_pagination( | |
654 | (isset(\$Numrows['$b']['grand_total']) ? | |
655 | \$Numrows['$b']['grand_total'] : \$Numrows['$b']['total'] | |
656 | ), ".$p->boucles[$b]->modificateur['debut_nom'].", " | |
657 | . $p->boucles[$b]->total_parties | |
658 | . ", $liste $__modele)"; | |
659 | ||
660 | $p->interdire_scripts = false; | |
661 | return $p; | |
662 | } | |
663 | ||
664 | // N'afficher que l'ancre de la pagination (au-dessus, par exemple, alors | |
665 | // qu'on mettra les liens en-dessous de la liste paginee) | |
666 | // http://doc.spip.org/@balise_ANCRE_PAGINATION_dist | |
667 | function balise_ANCRE_PAGINATION_dist($p) { | |
668 | $p = balise_PAGINATION_dist($p, $liste='false'); | |
669 | return $p; | |
670 | } | |
671 | ||
672 | // equivalent a #TOTAL_BOUCLE sauf pour les boucles paginees, ou elle | |
673 | // indique le nombre total d'articles repondant aux criteres hors pagination | |
674 | // http://doc.spip.org/@balise_GRAND_TOTAL_dist | |
675 | function balise_GRAND_TOTAL_dist($p) { | |
676 | $b = $p->nom_boucle ? $p->nom_boucle : $p->descr['id_mere']; | |
677 | if ($b === '' || !isset($p->boucles[$b])) { | |
678 | erreur_squelette( | |
679 | _T('zbug_champ_hors_boucle', | |
680 | array('champ' => "#$b" . 'TOTAL_BOUCLE') | |
681 | ), $p->id_boucle); | |
682 | $p->code = "''"; | |
683 | } else { | |
684 | $p->code = "(isset(\$Numrows['$b']['grand_total']) | |
685 | ? \$Numrows['$b']['grand_total'] : \$Numrows['$b']['total'])"; | |
686 | $p->boucles[$b]->numrows = true; | |
687 | $p->interdire_scripts = false; | |
688 | } | |
689 | return $p; | |
690 | } | |
691 | ||
692 | ||
693 | ||
694 | // | |
695 | // Fonction commune aux balises #LOGO_XXXX | |
696 | // (les balises portant ce type de nom sont traitees en bloc ici) | |
697 | // | |
698 | // http://doc.spip.org/@calculer_balise_logo_dist | |
699 | function calculer_balise_logo_dist ($p) { | |
700 | ||
701 | preg_match(",^LOGO_([A-Z]+)(_.*)?$,i", $p->nom_champ, $regs); | |
702 | $type_objet = $regs[1]; | |
703 | $suite_logo = $regs[2]; | |
704 | ||
705 | // cas de #LOGO_SITE_SPIP | |
706 | if (preg_match(",^_SPIP(.*)$,", $suite_logo, $regs)) { | |
707 | $type_objet = 'SITE'; | |
708 | $suite_logo = $regs[1]; | |
709 | $_id_objet = "\"'0'\""; | |
710 | $id_objet = 'id_syndic'; # parait faux mais donne bien "siteNN" | |
711 | } else { | |
712 | if ($type_objet == 'SITE') | |
713 | $id_objet = "id_syndic"; | |
714 | else | |
715 | $id_objet = "id_".strtolower($type_objet); | |
716 | $_id_objet = champ_sql($id_objet, $p); | |
717 | } | |
718 | ||
719 | // analyser les faux filtres | |
720 | $flag_fichier = $flag_stop = $flag_lien_auto = $code_lien = $filtres = $align = $lien = $params = ''; | |
721 | ||
722 | if (is_array($p->fonctions)) { | |
723 | foreach($p->fonctions as $couple) { | |
724 | if (!$flag_stop) { | |
725 | $nom = trim($couple[0]); | |
726 | ||
727 | // double || signifie "on passe aux vrais filtres" | |
728 | if ($nom == '') { | |
729 | if ($couple[1]) { | |
730 | $params = $couple[1]; // recuperer #LOGO_DOCUMENT{20,30} | |
731 | array_shift($p->param); | |
732 | } | |
733 | else | |
734 | $flag_stop = true; | |
735 | } else { | |
736 | // faux filtres | |
737 | array_shift($p->param); | |
738 | switch($nom) { | |
739 | case 'left': | |
740 | case 'right': | |
741 | case 'center': | |
742 | case 'top': | |
743 | case 'bottom': | |
744 | $align = $nom; | |
745 | break; | |
746 | ||
747 | case 'lien': | |
748 | $flag_lien_auto = 'oui'; | |
749 | $flag_stop = true; # apres |lien : vrais filtres | |
750 | break; | |
751 | ||
752 | case 'fichier': | |
753 | $flag_fichier = 1; | |
754 | $flag_stop = true; # apres |fichier : vrais filtres | |
755 | break; | |
756 | ||
757 | default: | |
758 | $lien = $nom; | |
759 | $flag_stop = true; # apres |#URL... : vrais filtres | |
760 | break; | |
761 | } | |
762 | } | |
763 | } | |
764 | } | |
765 | } | |
766 | ||
767 | // | |
768 | // Preparer le code du lien | |
769 | // | |
770 | // 1. filtre |lien | |
771 | if ($flag_lien_auto AND !$lien) | |
772 | $code_lien = '($lien = generer_url_'.$type_objet.'('.$_id_objet.')) ? $lien : ""'; | |
773 | // 2. lien indique en clair (avec des balises : imprimer#ID_ARTICLE.html) | |
774 | else if ($lien) { | |
775 | $code_lien = "'".texte_script(trim($lien))."'"; | |
776 | while (preg_match(",^([^#]*)#([A-Za-z_]+)(.*)$,", $code_lien, $match)) { | |
777 | $c = new Champ(); | |
778 | $c->nom_champ = $match[2]; | |
779 | $c->id_boucle = $p->id_boucle; | |
780 | $c->boucles = &$p->boucles; | |
781 | $c->descr = $p->descr; | |
782 | $c = calculer_champ($c); | |
783 | $code_lien = str_replace('#'.$match[2], "'.".$c.".'", $code_lien); | |
784 | } | |
785 | // supprimer les '' disgracieux | |
786 | $code_lien = preg_replace("@^''\.|\.''$@", "", $code_lien); | |
787 | } | |
788 | ||
789 | if ($flag_fichier) | |
790 | $code_lien = "'',''" ; | |
791 | else { | |
792 | if (!$code_lien) | |
793 | $code_lien = "''"; | |
794 | $code_lien .= ", '". $align . "'"; | |
795 | } | |
796 | ||
797 | // cas des documents | |
798 | if ($type_objet == 'DOCUMENT') { | |
799 | $p->code = "calcule_logo_document($_id_objet, '" . | |
800 | $p->descr['documents'] . | |
801 | '\', $doublons, '. intval($flag_fichier).", $code_lien, '". | |
802 | // #LOGO_DOCUMENT{x,y} donne la taille maxi | |
803 | texte_script($params) | |
804 | ."')"; | |
805 | } | |
806 | else { | |
807 | $p->code = "affiche_logos(calcule_logo('$id_objet', '" . | |
808 | (($suite_logo == '_SURVOL') ? 'off' : | |
809 | (($suite_logo == '_NORMAL') ? 'on' : 'ON')) . | |
810 | "', $_id_objet," . | |
811 | (($suite_logo == '_RUBRIQUE') ? | |
812 | champ_sql("id_rubrique", $p) : | |
813 | (($type_objet == 'RUBRIQUE') ? "sql_parent($_id_objet)" : "''")) . | |
814 | ", '$flag_fichier'), $code_lien)"; | |
815 | } | |
816 | ||
817 | $p->interdire_scripts = false; | |
818 | return $p; | |
819 | } | |
820 | ||
821 | // #EXTRA | |
822 | // [(#EXTRA|extra{isbn})] | |
823 | // ou [(#EXTRA|isbn)] (ce dernier applique les filtres definis dans mes_options) | |
824 | // Champs extra | |
825 | // Non documentes, en voie d'obsolescence, cf. ecrire/inc/extra | |
826 | // http://doc.spip.org/@balise_EXTRA_dist | |
827 | function balise_EXTRA_dist ($p) { | |
828 | $_extra = champ_sql('extra', $p); | |
829 | $p->code = $_extra; | |
830 | ||
831 | // Gerer la notation [(#EXTRA|isbn)] | |
832 | if ($p->fonctions) { | |
833 | list($champ,) = $p->fonctions[0]; | |
834 | include_spip('inc/extra'); | |
835 | $type_extra = $p->type_requete; | |
836 | ||
837 | // ci-dessus est sans doute un peu buggue : si on invoque #EXTRA | |
838 | // depuis un sous-objet sans champ extra d'un objet a champ extra, | |
839 | // on aura le type_extra du sous-objet (!) | |
840 | if (extra_champ_valide($type_extra, $champ)) { | |
841 | array_shift($p->fonctions); | |
842 | array_shift($p->param); | |
843 | // Appliquer les filtres definis par le webmestre | |
844 | $p->code = 'extra('.$p->code.', "'.$champ.'")'; | |
845 | ||
846 | $filtres = extra_filtres($type_extra, $champ); | |
847 | if ($filtres) foreach ($filtres as $f) | |
848 | $p->code = "$f($p->code)"; | |
849 | } else { | |
850 | if (!function_exists($champ)) { | |
851 | spip_log("erreur champ extra |$champ"); | |
852 | array_shift($p->fonctions); | |
853 | array_shift($p->param); | |
854 | } | |
855 | } | |
856 | } | |
857 | ||
858 | #$p->interdire_scripts = true; | |
859 | return $p; | |
860 | } | |
861 | ||
862 | // | |
863 | // Parametres de reponse a un forum | |
864 | // | |
865 | ||
866 | // http://doc.spip.org/@balise_PARAMETRES_FORUM_dist | |
867 | function balise_PARAMETRES_FORUM_dist($p) { | |
868 | $_id_article = champ_sql('id_article', $p); | |
869 | $p->code = ' | |
870 | // refus des forums ? | |
871 | (sql_accepter_forum('.$_id_article.')=="non" OR | |
872 | ($GLOBALS["meta"]["forums_publics"] == "non" | |
873 | AND sql_accepter_forum('.$_id_article.') == "")) | |
874 | ? "" : // sinon: | |
875 | '; | |
876 | ||
877 | switch ($p->type_requete) { | |
878 | case 'articles': | |
879 | $c = '"id_article=".' . champ_sql('id_article', $p); | |
880 | break; | |
881 | case 'breves': | |
882 | $c = '"id_breve=".' . champ_sql('id_breve', $p); | |
883 | break; | |
884 | case 'rubriques': | |
885 | $c = '"id_rubrique=".' . champ_sql('id_rubrique', $p); | |
886 | break; | |
887 | case 'syndication': | |
888 | $c = '"id_syndic=".' . champ_sql('id_syndic', $p); | |
889 | break; | |
890 | case 'forums': | |
891 | default: | |
892 | $liste_champs = array ("id_article","id_breve","id_rubrique","id_syndic","id_forum"); | |
893 | $c = ''; | |
894 | foreach ($liste_champs as $champ) { | |
895 | $x = champ_sql( $champ, $p); | |
896 | $c .= (($c) ? ".\n" : "") . "((!$x) ? '' : ('&$champ='.$x))"; | |
897 | } | |
898 | $c = "substr($c,1)"; | |
899 | break; | |
900 | } | |
901 | ||
902 | // Syntaxe [(#PARAMETRES_FORUM{#SELF})] pour fixer le retour du forum | |
903 | # note : ce bloc qui sert a recuperer des arguments calcules pourrait | |
904 | # porter un nom et faire partie de l'API. | |
905 | $retour = interprete_argument_balise(1,$p); | |
906 | if ($retour===NULL) | |
907 | $retour = "''"; | |
908 | ||
909 | // Attention un eventuel &retour=xxx dans l'URL est prioritaire | |
910 | $c .= '. | |
911 | (($lien = (_request("retour") ? _request("retour") : str_replace("&", "&", '.$retour.'))) ? "&retour=".rawurlencode($lien) : "")'; | |
912 | ||
913 | // Ajouter le code d'invalideur specifique a cette balise | |
914 | include_spip('inc/invalideur'); | |
915 | if (function_exists($i = 'code_invalideur_forums')) | |
916 | $p->code .= $i($p, '('.$c.')'); | |
917 | ||
918 | $p->interdire_scripts = false; | |
919 | return $p; | |
920 | } | |
921 | ||
922 | ||
923 | // Reference a l'URL de la page courante | |
924 | // Attention dans un INCLURE() ou une balise dynamique on n'a pas le droit de | |
925 | // mettre en cache #SELF car il peut correspondre a une autre page (attaque XSS) | |
926 | // (Dans ce cas faire <INCLURE{self=#SELF}> pour differencier les caches.) | |
927 | // http://www.spip.net/@self | |
928 | // http://doc.spip.org/@balise_SELF_dist | |
929 | function balise_SELF_dist($p) { | |
930 | $p->code = 'quote_amp(self())'; | |
931 | $p->interdire_scripts = false; | |
932 | return $p; | |
933 | } | |
934 | ||
935 | ||
936 | // | |
937 | // #URL_PAGE{backend} -> backend.php3 ou ?page=backend selon les cas | |
938 | // Pour les pages qui commencent par "spip_", il faut eventuellement | |
939 | // aller chercher spip_action.php?action=xxxx | |
940 | // | |
941 | // http://doc.spip.org/@balise_URL_PAGE_dist | |
942 | function balise_URL_PAGE_dist($p) { | |
943 | ||
944 | $p->code = interprete_argument_balise(1,$p); | |
945 | $args = interprete_argument_balise(2,$p); | |
946 | if ($args != "''" && $args!==NULL) | |
947 | $p->code .= ','.$args; | |
948 | ||
949 | // autres filtres (???) | |
950 | array_shift($p->param); | |
951 | ||
952 | $p->code = 'generer_url_public(' . $p->code .')'; | |
953 | ||
954 | #$p->interdire_scripts = true; | |
955 | return $p; | |
956 | } | |
957 | ||
958 | // | |
959 | // #URL_ECRIRE{naviguer} -> ecrire/?exec=naviguer | |
960 | // | |
961 | // http://doc.spip.org/@balise_URL_ECRIRE_dist | |
962 | function balise_URL_ECRIRE_dist($p) { | |
963 | ||
964 | $p->code = interprete_argument_balise(1,$p); | |
965 | $args = interprete_argument_balise(2,$p); | |
966 | if ($args != "''" && $args!==NULL) | |
967 | $p->code .= ','.$args; | |
968 | ||
969 | // autres filtres (???) | |
970 | array_shift($p->param); | |
971 | ||
972 | $p->code = 'generer_url_ecrire(' . $p->code .')'; | |
973 | ||
974 | #$p->interdire_scripts = true; | |
975 | return $p; | |
976 | } | |
977 | ||
978 | // | |
979 | // #URL_ACTION_AUTEUR{converser,arg,redirect} -> ecrire/?action=converser&arg=arg&hash=xxx&redirect=redirect | |
980 | // | |
981 | // http://doc.spip.org/@balise_URL_ACTION_AUTEUR_dist | |
982 | function balise_URL_ACTION_AUTEUR_dist($p) { | |
983 | ||
984 | $p->code = interprete_argument_balise(1,$p); | |
985 | $args = interprete_argument_balise(2,$p); | |
986 | if ($args != "''" && $args!==NULL) | |
987 | $p->code .= ".'\",\"'.".$args; | |
988 | $redirect = interprete_argument_balise(3,$p); | |
989 | if ($redirect != "''" && $redirect!==NULL) | |
990 | $p->code .= ".'\",\"'.".$redirect; | |
991 | ||
992 | $p->code = "'<"."?php echo generer_action_auteur(\"'." . $p->code .".'\"); ?>'"; | |
993 | ||
994 | $p->interdire_scripts = false; | |
995 | return $p; | |
996 | } | |
997 | ||
998 | // | |
999 | // #CHEMIN{fichier} -> find_in_path(fichier) | |
1000 | // | |
1001 | // http://doc.spip.org/@balise_CHEMIN_dist | |
1002 | function balise_CHEMIN_dist($p) { | |
1003 | $p->code = interprete_argument_balise(1,$p); | |
1004 | $p->code = 'find_in_path(' . $p->code .')'; | |
1005 | ||
1006 | #$p->interdire_scripts = true; | |
1007 | return $p; | |
1008 | } | |
1009 | ||
1010 | // | |
1011 | // #ENV | |
1012 | // l'"environnement", id est le $contexte (ou $contexte_inclus) | |
1013 | // | |
1014 | // en standard on applique |entites_html, mais si vous utilisez | |
1015 | // [(#ENV*{toto})] il *faut* vous assurer vous-memes de la securite | |
1016 | // anti-javascript (par exemple en filtrant avec |safehtml) | |
1017 | // | |
1018 | // La syntaxe #ENV{toto, rempl} renverra 'rempl' si $toto est vide | |
1019 | // | |
1020 | // http://doc.spip.org/@balise_ENV_dist | |
1021 | function balise_ENV_dist($p, $src = NULL) { | |
1022 | // le tableau de base de la balise (cf #META ci-dessous) | |
1023 | if (!$src) $src = '$Pile[0]'; | |
1024 | ||
1025 | $_nom = interprete_argument_balise(1,$p); | |
1026 | $_sinon = interprete_argument_balise(2,$p); | |
1027 | ||
1028 | if (!$_nom) { | |
1029 | // cas de #ENV sans argument : on retourne le serialize() du tableau | |
1030 | // une belle fonction [(#ENV|affiche_env)] serait pratique | |
1031 | $p->code = 'serialize('.$src.')'; | |
1032 | } else { | |
1033 | // admet deux arguments : nom de variable, valeur par defaut si vide | |
1034 | $p->code = $src."[$_nom]"; | |
1035 | if ($_sinon) | |
1036 | $p->code = 'sinon('. | |
1037 | $p->code.",$_sinon)"; | |
1038 | } | |
1039 | #$p->interdire_scripts = true; | |
1040 | ||
1041 | return $p; | |
1042 | } | |
1043 | ||
1044 | // | |
1045 | // #CONFIG | |
1046 | // les reglages du site | |
1047 | // | |
1048 | // Par exemple #CONFIG{gerer_trad} donne 'oui' ou 'non' selon le reglage | |
1049 | // Attention c'est brut de decoffrage de la table spip_meta | |
1050 | // | |
1051 | // La balise fonctionne exactement comme #ENV (ci-dessus) | |
1052 | // | |
1053 | // http://doc.spip.org/@balise_CONFIG_dist | |
1054 | function balise_CONFIG_dist($p) { | |
1055 | if(function_exists('balise_ENV')) | |
1056 | return balise_ENV($p, '$GLOBALS["meta"]'); | |
1057 | else | |
1058 | return balise_ENV_dist($p, '$GLOBALS["meta"]'); | |
1059 | } | |
1060 | ||
1061 | ||
1062 | // | |
1063 | // #EVAL{...} | |
1064 | // evalue un code php ; a utiliser avec precaution :-) | |
1065 | // | |
1066 | // rq: #EVAL{code} produit eval('return code;') | |
1067 | // mais si le code est une expression sans balise, on se dispense | |
1068 | // de passer par une construction si compliquee, et le code est | |
1069 | // passe tel quel (entre parentheses, et protege par interdire_scripts) | |
1070 | // Exemples : #EVAL**{6+9} #EVAL**{_DIR_IMG_PACK} #EVAL{'date("Y-m-d")'} | |
1071 | // #EVAL{'str_replace("r","z", "roger")'} (attention les "'" sont interdits) | |
1072 | // http://doc.spip.org/@balise_EVAL_dist | |
1073 | function balise_EVAL_dist($p) { | |
1074 | $php = interprete_argument_balise(1,$p); | |
1075 | if ($php) { | |
1076 | # optimisation sur les #EVAL{une expression sans #BALISE} | |
1077 | # attention au commentaire "// x signes" qui precede | |
1078 | if (preg_match(",^([[:space:]]*//[^\n]*\n)'([^']+)'$,ms", | |
1079 | $php,$r)) | |
1080 | $p->code = /* $r[1]. */'('.$r[2].')'; | |
1081 | else | |
1082 | $p->code = "eval('return '.$php.';')"; | |
1083 | } else | |
1084 | $p->code = ''; | |
1085 | ||
1086 | #$p->interdire_scripts = true; | |
1087 | ||
1088 | return $p; | |
1089 | } | |
1090 | ||
1091 | // | |
1092 | // #REM | |
1093 | // pour les remarques : renvoie toujours '' | |
1094 | // | |
1095 | // http://doc.spip.org/@balise_REM_dist | |
1096 | function balise_REM_dist($p) { | |
1097 | $p->code="''"; | |
1098 | $p->interdire_scripts = false; | |
1099 | return $p; | |
1100 | } | |
1101 | ||
1102 | ||
1103 | // | |
1104 | // #HTTP_HEADER | |
1105 | // pour les entetes de retour http | |
1106 | // Ne fonctionne pas sur les INCLURE ! | |
1107 | // #HTTP_HEADER{Content-Type: text/css} | |
1108 | // | |
1109 | // http://doc.spip.org/@balise_HTTP_HEADER_dist | |
1110 | function balise_HTTP_HEADER_dist($p) { | |
1111 | ||
1112 | $header = interprete_argument_balise(1,$p); | |
1113 | $p->code = "'<'.'?php header(\"' . " | |
1114 | . $header | |
1115 | . " . '\"); ?'.'>'"; | |
1116 | $p->interdire_scripts = false; | |
1117 | return $p; | |
1118 | } | |
1119 | ||
1120 | // | |
1121 | // #CACHE | |
1122 | // definit la duree de vie ($delais) du squelette | |
1123 | // #CACHE{24*3600} | |
1124 | // parametre(s) supplementaire(s) : | |
1125 | // #CACHE{24*3600, cache-client} autorise gestion du IF_MODIFIED_SINCE | |
1126 | // http://doc.spip.org/@balise_CACHE_dist | |
1127 | function balise_CACHE_dist($p) { | |
1128 | $duree = valeur_numerique($p->param[0][1][0]->texte); | |
1129 | ||
1130 | // noter la duree du cache dans un entete proprietaire | |
1131 | $p->code .= '\'<'.'?php header("X-Spip-Cache: ' | |
1132 | . $duree | |
1133 | . '"); ?'.'>\''; | |
1134 | ||
1135 | // Remplir le header Cache-Control | |
1136 | // cas #CACHE{0} | |
1137 | if ($duree == 0) | |
1138 | $p->code .= '.\'<' | |
1139 | .'?php header("Cache-Control: no-store, no-cache, must-revalidate"); ?' | |
1140 | .'><' | |
1141 | .'?php header("Pragma: no-cache"); ?' | |
1142 | .'>\''; | |
1143 | ||
1144 | // cas #CACHE{360, cache-client} | |
1145 | if (isset($p->param[0][2])) { | |
1146 | $second = ($p->param[0][2][0]->texte); | |
1147 | if ($second == 'cache-client' | |
1148 | AND $duree > 0) | |
1149 | $p->code .= '.\'<'.'?php header("Cache-Control: max-age=' | |
1150 | . $duree | |
1151 | . '"); ?'.'>\''; | |
1152 | } | |
1153 | ||
1154 | $p->interdire_scripts = false; | |
1155 | return $p; | |
1156 | } | |
1157 | ||
1158 | // | |
1159 | // #INSERT_HEAD | |
1160 | // pour permettre aux plugins d'inserer des styles, js ou autre | |
1161 | // dans l'entete sans modification du squelette | |
1162 | // | |
1163 | // http://doc.spip.org/@balise_INSERT_HEAD_dist | |
1164 | function balise_INSERT_HEAD_dist($p) { | |
1165 | $p->code = "pipeline('insert_head','<!-- insert_head -->')"; | |
1166 | $p->interdire_scripts = false; | |
1167 | return $p; | |
1168 | } | |
1169 | ||
1170 | // | |
1171 | // #INCLURE statique | |
1172 | // l'inclusion est realisee au calcul du squelette, pas au service | |
1173 | // ainsi le produit du squelette peut etre utilise en entree de filtres a suivre | |
1174 | // on peut faire un #INCLURE{fichier} sans squelette | |
1175 | // http://doc.spip.org/@balise_INCLUDE_dist | |
1176 | function balise_INCLUDE_dist($p) { | |
1177 | if(function_exists('balise_INCLURE')) | |
1178 | return balise_INCLURE($p); | |
1179 | else | |
1180 | return balise_INCLURE_dist($p); | |
1181 | } | |
1182 | // http://doc.spip.org/@balise_INCLURE_dist | |
1183 | function balise_INCLURE_dist($p) { | |
1184 | $champ = phraser_arguments_inclure($p, true); | |
1185 | $l = argumenter_inclure($champ, $p->descr, $p->boucles, $p->id_boucle, false); | |
1186 | ||
1187 | if (isset($l['fond'])) { | |
1188 | $p->code = "recuperer_fond('',array(".implode(',',$l)."))"; | |
1189 | } else { | |
1190 | $n = interprete_argument_balise(1,$p); | |
1191 | $p->code = '(($c = find_in_path(' . $n . ')) ? spip_file_get_contents($c) : "")'; | |
1192 | } | |
1193 | ||
1194 | $p->interdire_scripts = false; | |
1195 | return $p; | |
1196 | } | |
1197 | ||
1198 | // Inclure un modele : #MODELE{modele, params} | |
1199 | // http://doc.spip.org/@balise_MODELE_dist | |
1200 | function balise_MODELE_dist($p) { | |
1201 | $contexte = array(); | |
1202 | ||
1203 | // recupere le premier argument, qui est obligatoirement le nom du modele | |
1204 | if (!is_array($p->param)) | |
1205 | die("erreur de compilation #MODELE{nom du modele}"); | |
1206 | ||
1207 | // Transforme l'ecriture du deuxieme param {truc=chose,machin=chouette} en | |
1208 | // {truc=chose}{machin=chouette}... histoire de simplifier l'ecriture pour | |
1209 | // le webmestre : #MODELE{emb}{autostart=true,truc=1,chose=chouette} | |
1210 | if ($p->param[0]) { | |
1211 | while (count($p->param[0])>2){ | |
1212 | $p->param[]=array(0=>NULL,1=>array_pop($p->param[0])); | |
1213 | } | |
1214 | } | |
1215 | $modele = array_shift($p->param); | |
1216 | $nom = strtolower($modele[1][0]->texte); | |
1217 | if (!$nom) | |
1218 | die("erreur de compilation #MODELE{nom du modele}"); | |
1219 | ||
1220 | $champ = phraser_arguments_inclure($p, true); | |
1221 | ||
1222 | // a priori true | |
1223 | // si false, le compilo va bloquer sur des syntaxes avec un filtre sans argument qui suit la balise | |
1224 | // si true, les arguments simples (sans truc=chose) vont degager | |
1225 | $code_contexte = argumenter_inclure($champ, $p->descr, $p->boucles, $p->id_boucle, false); | |
1226 | ||
1227 | // Si le champ existe dans la pile, on le met dans le contexte | |
1228 | // (a priori c'est du code mort ; il servait pour #LESAUTEURS dans | |
1229 | // le cas spip_syndic_articles) | |
1230 | #$code_contexte[] = "'$nom='.".champ_sql($nom, $p); | |
1231 | ||
1232 | // Reserver la cle primaire de la boucle courante | |
1233 | if ($primary = $p->boucles[$p->id_boucle]->primary) { | |
1234 | $id = champ_sql($primary, $p); | |
1235 | $code_contexte[] = "'$primary='.".$id; | |
1236 | } | |
1237 | ||
1238 | $p->code = "( ((\$recurs=(isset(\$Pile[0]['recurs'])?\$Pile[0]['recurs']:0))<5)? | |
1239 | recuperer_fond('modeles/".$nom."', | |
1240 | creer_contexte_de_modele(array(".join(',', $code_contexte).",'recurs='.(++\$recurs), \$GLOBALS['spip_lang']))):'')"; | |
1241 | $p->interdire_scripts = false; // securite assuree par le squelette | |
1242 | ||
1243 | return $p; | |
1244 | } | |
1245 | ||
1246 | // | |
1247 | // #SET | |
1248 | // Affecte une variable locale au squelette | |
1249 | // #SET{nom,valeur} | |
1250 | // la balise renvoie la valeur | |
1251 | // http://doc.spip.org/@balise_SET_dist | |
1252 | function balise_SET_dist($p){ | |
1253 | $_nom = interprete_argument_balise(1,$p); | |
1254 | $_valeur = interprete_argument_balise(2,$p); | |
1255 | ||
1256 | if ($_nom AND $_valeur) | |
1257 | $p->code = "vide(\$Pile['vars'][$_nom] = $_valeur)"; | |
1258 | else | |
1259 | $p->code = "''"; | |
1260 | ||
1261 | $p->interdire_scripts = false; // la balise ne renvoie rien | |
1262 | return $p; | |
1263 | } | |
1264 | ||
1265 | // | |
1266 | // #GET | |
1267 | // Recupere une variable locale au squelette | |
1268 | // #GET{nom,defaut} renvoie defaut si la variable nom n'a pas ete affectee | |
1269 | // | |
1270 | // http://doc.spip.org/@balise_GET_dist | |
1271 | function balise_GET_dist($p) { | |
1272 | $p->interdire_scripts = false; // le contenu vient de #SET, donc il est de confiance | |
1273 | if (function_exists('balise_ENV')) | |
1274 | return balise_ENV($p, '$Pile["vars"]'); | |
1275 | else | |
1276 | return balise_ENV_dist($p, '$Pile["vars"]'); | |
1277 | } | |
1278 | ||
1279 | // | |
1280 | // #PIPELINE | |
1281 | // pour permettre aux plugins d'inserer des sorties de pipeline dans un squelette | |
1282 | // #PIPELINE{insert_body} | |
1283 | // #PIPELINE{insert_body,flux} | |
1284 | // | |
1285 | // http://doc.spip.org/@balise_PIPELINE_dist | |
1286 | function balise_PIPELINE_dist($p) { | |
1287 | $_pipe = interprete_argument_balise(1,$p); | |
1288 | $_flux = interprete_argument_balise(2,$p); | |
1289 | $_flux = $_flux?$_flux:"''"; | |
1290 | $p->code = "pipeline( $_pipe , $_flux )"; | |
1291 | $p->interdire_scripts = false; | |
1292 | return $p; | |
1293 | } | |
1294 | ||
1295 | // | |
1296 | // #EDIT | |
1297 | // une balise qui ne fait rien, pour surcharge par le plugin widgets | |
1298 | // | |
1299 | // http://doc.spip.org/@balise_EDIT_dist | |
1300 | function balise_EDIT_dist($p) { | |
1301 | $p->code = "''"; | |
1302 | $p->interdire_scripts = false; | |
1303 | return $p; | |
1304 | } | |
1305 | ||
1306 | ||
1307 | // | |
1308 | // #TOTAL_UNIQUE | |
1309 | // pour recuperer le nombre d'elements affiches par l'intermediaire du filtre | |
1310 | // |unique | |
1311 | // usage: | |
1312 | // #TOTAL_UNIQUE afiche le nombre de #BALISE|unique | |
1313 | // #TOTAL_UNIQUE{famille} afiche le nombre de #BALISE|unique{famille} | |
1314 | // | |
1315 | // http://doc.spip.org/@balise_TOTAL_UNIQUE_dist | |
1316 | function balise_TOTAL_UNIQUE_dist($p) { | |
1317 | $_famille = interprete_argument_balise(1,$p); | |
1318 | $_famille = $_famille ? $_famille : "''"; | |
1319 | $p->code = "unique('', $_famille, true)"; | |
1320 | return $p; | |
1321 | } | |
1322 | ||
1323 | // | |
1324 | // #ARRAY | |
1325 | // pour creer un array php a partir d'arguments calcules | |
1326 | // #ARRAY{key1,val1,key2,val2 ...} returne array(key1=>val1,...) | |
1327 | // | |
1328 | // http://doc.spip.org/@balise_ARRAY_dist | |
1329 | function balise_ARRAY_dist($p) { | |
1330 | $_code= ""; | |
1331 | $n=1; | |
1332 | $_key = interprete_argument_balise($n++,$p); | |
1333 | $_val = interprete_argument_balise($n++,$p); | |
1334 | while ($_key && $_val){ | |
1335 | $_code .= ", $_key => $_val"; | |
1336 | $_key = interprete_argument_balise($n++,$p); | |
1337 | $_val = interprete_argument_balise($n++,$p); | |
1338 | } | |
1339 | if (strlen($_code)) | |
1340 | $_code = substr($_code,2); | |
1341 | $p->code = "array($_code)"; | |
1342 | $p->interdire_scripts = false; | |
1343 | return $p; | |
1344 | } | |
1345 | ||
1346 | ?> |