From fa5a6be99bbe956651701fbee4f27cbc6709ff42 Mon Sep 17 00:00:00 2001 From: James <james@rezo.net> Date: Thu, 19 Jul 2007 13:17:46 +0000 Subject: [PATCH] balise #FOREACH. afficher le contenu d'une balise composee d'un tableau asociatif en se basant sur un modele spip --- .gitattributes | 1 + dist/modeles/foreach.html | 1 + ecrire/inc/filtres.php | 14 +++++++++++++- ecrire/public/balises.php | 27 +++++++++++++++++++++++++++ 4 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 dist/modeles/foreach.html diff --git a/.gitattributes b/.gitattributes index 3122cc3343..e74b6b09fa 100644 --- a/.gitattributes +++ b/.gitattributes @@ -244,6 +244,7 @@ dist/modeles/article_mots.html -text dist/modeles/article_traductions.html -text dist/modeles/doc.html -text dist/modeles/emb.html -text +dist/modeles/foreach.html -text dist/modeles/img.html -text dist/modeles/lesauteurs.html -text dist/modeles/pagination.html -text diff --git a/dist/modeles/foreach.html b/dist/modeles/foreach.html new file mode 100644 index 0000000000..b984d3738c --- /dev/null +++ b/dist/modeles/foreach.html @@ -0,0 +1 @@ +#PUCE #ENV{cle} => #ENV{valeur}<br /> diff --git a/ecrire/inc/filtres.php b/ecrire/inc/filtres.php index 2db7ee30c8..b2c2d41391 100644 --- a/ecrire/inc/filtres.php +++ b/ecrire/inc/filtres.php @@ -2106,4 +2106,16 @@ function http_style_background($img, $att='') return " style='background: url(\"".http_wrapper($img)."\")" . ($att ? (' ' . $att) : '') . ";'"; } -?> + +//[(#ENV*|unserialize|foreach)] +function filtre_foreach_dist($balise_deserializee, $modele = 'foreach') { + $texte = ''; + foreach($balise_deserializee as $k => $v) + $texte .= recuperer_fond( + 'modeles/'.$modele, + array('cle' => $k, 'valeur' => $v) + ); + return $texte; +} + +?> \ No newline at end of file diff --git a/ecrire/public/balises.php b/ecrire/public/balises.php index 8c6c1dd760..44170585bc 100644 --- a/ecrire/public/balises.php +++ b/ecrire/public/balises.php @@ -1346,6 +1346,33 @@ function balise_ARRAY_dist($p) { return $p; } +//#FOREACH +// +function balise_FOREACH_dist($p) { + $_tableau = interprete_argument_balise(1,$p); + if($_tableau == "''" OR $_tableau == NULL) $_tableau = "'ENV'"; + $_code = interprete_argument_balise(2,$p); + if($_code == "''" OR $_code == NULL) $_code = "'foreach'"; + + $_tableau = str_replace("'", "", strtoupper($_tableau)); + $balise = function_exists($f ='balise_'.$_tableau) ? $f : + function_exists($g = $f.'_dist') ? $g : ''; + + + if($balise) { + $p->param = @array_shift(@array_shift($p->param)); + $p = $balise($p); + //retirer le serialize + $p->code = preg_replace(',^serialize\((.*)\)$,', '\1', $p->code); + $filtre = chercher_filtre('foreach'); + $p->code = $filtre . "(" . $p->code . ", " . $_code . ")"; + } + //On a pas trouve la balise correspondant au tableau a traiter + else { + $p->code = "''"; + } + return $p; +} // Appelle la fonction autoriser et renvoie ' ' si OK, '' si niet // A noter : la priorite des operateurs exige && plutot que AND -- GitLab