you should have commit the original one first and then the modified one in order to allow to see differences.
#SET{val,(#TAG|filter)}
was allready possible, but not the use of in {}. Difficulty is to keep all existant case working... I have to say i tried this but it looked to be too constrained by existing cases for me...
I'll see your changes ![]()
Cedric
renatoformato@virgilio.it a écrit :
Author: renatoformato@virgilio.it
Date: Thu Aug 31 19:01:42 2006
New Revision: 5017Log:
an experimental phraseur that can process tags with args containing extended tag notation. #SET{val,[(#TAG|filter)]}. Can be usefull for spiipAdded:
_plugins_/_ze_laboratoire_/phraseur_args_etendus/
_plugins_/_ze_laboratoire_/phraseur_args_etendus/plugin.xml
_plugins_/_ze_laboratoire_/phraseur_args_etendus/public/
_plugins_/_ze_laboratoire_/phraseur_args_etendus/public/phraser_html.phpAdded: _plugins_/_ze_laboratoire_/phraseur_args_etendus/plugin.xml
--- _plugins_/_ze_laboratoire_/phraseur_args_etendus/plugin.xml (added)
+++ _plugins_/_ze_laboratoire_/phraseur_args_etendus/plugin.xml Thu Aug 31 19:01:42 2006
@@ -0,0 +1 @@
+<plugin>
<nom> <!-- Nom du plugin -->
Phraseur args etendus
</nom>
<auteur> <!-- Auteur du plugin -->
Renato Formato [->renatoformato@virgilio.it]
</auteur>
<version>
0.1
</version>
<etat>
dev
</etat>
<description>
A "Phraseur" that can process extended notation inside arguments of tags. _ EX : <code>#SET{val,[before(#ENV{test,0}|filter)after]}</code>
</description>
<prefix>
phraseur_args_etendus
</prefix>
</plugin>
\ No newline at end of fileAdded: _plugins_/_ze_laboratoire_/phraseur_args_etendus/public/phraser_html.php
--- _plugins_/_ze_laboratoire_/phraseur_args_etendus/public/phraser_html.php (added)
+++ _plugins_/_ze_laboratoire_/phraseur_args_etendus/public/phraser_html.php Thu Aug 31 19:01:42 2006
@@ -0,0 +1,691 @@
+<?php
+
+/***************************************************************************\
+ * SPIP, Systeme de publication pour l'internet *
+ * *
+ * Copyright (c) 2001-2006 *
+ * Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James *
+ * *
+ * Ce programme est un logiciel libre distribue sous licence GNU/GPL. *
+ * Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne. *
+\***************************************************************************/
+
+if (!defined("_ECRIRE_INC_VERSION")) return;
+
+# Ce fichier doit IMPERATIVEMENT definir la fonction "public_phraser_html"
+# qui transforme un squelette en un tableau d'objets de classe Boucle
+# il est charge par un include calcule dans inc-calcul-squel
+# pour permettre differentes syntaxes en entree
+
+define('BALISE_BOUCLE', '<BOUCLE');
+define('BALISE_FIN_BOUCLE', '</BOUCLE');
+define('BALISE_PRE_BOUCLE', '<B');
+define('BALISE_POST_BOUCLE', '</B');
+define('BALISE_ALT_BOUCLE', '<//B');
+
+define('TYPE_RECURSIF', 'boucle');
+define('SPEC_BOUCLE','/\s*\(\s*([^\s)]+)(\s*[^)]*)\)/');
+define('NOM_DE_BOUCLE', "[0-9]+|[-_][-_.a-zA-Z0-9]*");
+# ecriture alambiquee pour rester compatible avec les hexadecimaux des vieux squelettes
+define('NOM_DE_CHAMP', "#((" . NOM_DE_BOUCLE . "):)?(([A-F]*[G-Z_][A-Z_0-9]*)|[A-Z_]+)(\*{0,2})");
+define('CHAMP_ETENDU', '\[([^]\*)\(' . NOM_DE_CHAMP . '([^[)]*\)[^]\*)\]');
+
+define('BALISE_INCLURE','<INCLU[DR]E[[:space:]]*(\(([^)]*)\))?');
+
+define('SQL_ARGS', '(\([^)]*\))');
+define('CHAMP_SQL_PLUS_FONC', '`?([A-Za-z_][A-Za-z_0-9]*)' . SQL_ARGS . '?`?');
+
+// http://doc.spip.org/@phraser_arguments_inclure
+function phraser_arguments_inclure($p,$rejet_filtres = false){
+ $champ = new Inclure;
+ // on assimile {var=val} a une liste de un argument sans fonction
+ foreach ($p->param as $k => $v) {
+ $var = $v[1][0];
+ if ($var==NULL){
+ if ($rejet_filtres)
+ break; // on est arrive sur un filtre sans argument qui suit la balise
+ else
+ $champ->param[$k] = $v;
+ }
+ else {
+ if ($var->type != 'texte')
+ erreur_squelette(_T('zbug_parametres_inclus_incorrects'),
+ $match[0]);
+ else {
+ $champ->param[$k] = $v;
+ ereg("^([^=]*)(=)?(.*)$", $var->texte,$m);
+ if ($m[2]) {
+ $champ->param[$k][0] = $m[1];
+ $val = $m[3];
+ if (ereg('^[\'"](.*)[\'"]$', $val, $m)) $val = $m[1];
+ $champ->param[$k][1][0]->texte = $val;
+ }
+ else
+ $champ->param[$k] = array($m[1]);
+ }
+ }
+ }
+ return $champ;
+}
+
+// http://doc.spip.org/@phraser_inclure
+function phraser_inclure($texte, $ligne, $result) {
+
+ while (ereg(BALISE_INCLURE, $texte, $match)) {
+ $p = strpos($texte,$match[0]);
+ $debut = substr($texte, 0, $p);
+ if ($p) $result = phraser_idiomes($debut, $ligne, $result);
+ $ligne += substr_count($debut, "\n");
+ $champ = new Inclure;
+ $champ->ligne = $ligne;
+ $ligne += substr_count($match[0], "\n");
+ $champ->texte = $match[2];
+ $texte = substr($texte, $p+strlen($match[0]));
+ // on assimile {var=val} a une liste de un argument sans fonction
+ phraser_args($texte,">","",$result,$champ);
+ $champ_ = phraser_arguments_inclure($champ);
+ $champ->param = $champ_->param;
+ $texte = substr($champ->apres,1);
+ $champ->apres = "";
+ $result = $champ;
+ }
+ return (($texte==="") ? $result : phraser_idiomes($texte, $ligne, $result));
+}
+
+// http://doc.spip.org/@phraser_polyglotte
+function phraser_polyglotte($texte,$ligne, $result) {
+
+ if (preg_match_all(",<multi>(.*)</multi>,Uims", $texte, $m, PREG_SET_ORDER))
+ foreach ($m as $match) {
+ $p = strpos($texte, $match[0]);
+ $debut = substr($texte, 0, $p);
+ if ($p) {
+ $champ = new Texte;
+ $champ->texte = $debut;
+ $champ->ligne = $ligne;
+ $result = $champ;
+ $ligne += substr_count($champ->texte, "\n");
+ }
+
+ $champ = new Polyglotte;
+ $champ->ligne = $ligne;
+ $ligne += substr_count($match[0], "\n");
+ $lang = '';
+ $bloc = $match[1];
+ $texte = substr($texte,$p+strlen($match[0]));
+ while (preg_match("/^[[:space:]]*([^[{]*)[[:space:]]*[[{]([a-z_]+)}](.*)$/si", $bloc, $regs)) {
+ $trad = $regs[1];
+ if ($trad OR $lang) + $champ->traductions[$lang] = $trad;
+ $lang = $regs[2];
+ $bloc = $regs[3];
+ }
+ $champ->traductions[$lang] = $bloc;
+ $result = $champ;
+ }
+ if ($texte!=="") {
+ $champ = new Texte;
+ $champ->texte = $texte;
+ $champ->ligne = $ligne;
+ $result = $champ;
+ }
+ return $result;
+}
+
+// http://doc.spip.org/@phraser_idiomes
+function phraser_idiomes($texte,$ligne,$result) {
+
+ // Reperer les balises de traduction <:toto:>
+ while (eregi("<:(([a-z0-9_]+):)?([a-z0-9_]+)((\|[^:>]*)?:>)", $texte, $match)) {
+ $p = strpos($texte, $match[0]);
+ $debut = substr($texte, 0, $p);
+ if ($p) $result = phraser_champs($debut, $ligne, $result);
+ $champ = new Idiome;
+ $ligne += substr_count($debut, "\n");
+ $champ->ligne = $ligne;
+ $ligne += substr_count($match[0], "\n");
+ $texte = substr($texte,$p+strlen($match[0]));
+ $champ->nom_champ = strtolower($match[3]);
+ $champ->module = $match[2] ? $match[2] : 'public/spip/ecrire';
+ // pas d'imbrication pour les filtres sur langue
+ phraser_args($match[5], ":", '', array(), $champ);
+ $result = $champ;
+ }
+ if ($texte!=="") $result = phraser_champs($texte,$ligne,$result);
+ return $result;
+}
+
+// http://doc.spip.org/@phraser_champs
+function phraser_champs($texte,$ligne,$result) {
+ while (ereg(NOM_DE_CHAMP, $texte, $match)) {
+ $p = strpos($texte, $match[0]);
+ $suite = substr($texte,$p+strlen($match[0]));
+ if ($match[5] || (strpos($suite[0], "[0-9]") === false)) {
+ $debut = substr($texte, 0, $p);
+ if ($p) $result = phraser_polyglotte($debut, $ligne, $result);
+ $ligne += substr_count($debut, "\n");
+ $champ = new Champ;
+ $champ->ligne = $ligne;
+ $ligne += substr_count($match[0], "\n");
+ $champ->nom_boucle = $match[2];
+ $champ->nom_champ = $match[3];
+ $champ->etoile = $match[5];
+ if ($suite[0] == '{') {
+ phraser_arg($suite, '', array(), $champ);
+ }
+ $texte = $suite;
+ $result = $champ;
+ } else {
+ // faux champ
+ $result = phraser_polyglotte (substr($texte, 0, $p+1), $ligne, $result);
+ $texte = (substr($texte, $p+1));
+ }
+ }
+ if ($texte!=="") $result = phraser_polyglotte($texte, $ligne, $result);
+ return $result;
+}
+
+// Gestion des imbrications:
+// on cherche les [..] les plus internes et on les remplace par une chaine
+// %###N@ ou N indexe un tableau comportant le resultat de leur analyse
+// on recommence tant qu'il y a des [...] en substituant a l'appel suivant
+
+// http://doc.spip.org/@phraser_champs_etendus
+function phraser_champs_etendus($texte, $ligne,$result) {
+ if ($texte==="") return $result;
+ $sep = '##';
+ while (strpos($texte,$sep)!== false)
+ $sep .= '#';
+ return array_merge($result, phraser_champs_interieurs($texte, $ligne, $sep, array()));
+}
+
+// Analyse les filtres d'un champ etendu et affecte le resultat
+// renvoie la liste des lexemes d'origine augmentee
+// de ceux trouves dans les arguments des filtres (rare)
+// sert aussi aux arguments des includes et aux criteres de boucles
+// Tres chevelu
+
+// http://doc.spip.org/@phraser_args
+function phraser_args($texte, $fin, $sep, $result, &$pointeur_champ) {
+ $texte = ltrim($texte);
+ while (($texte!=="") && strpos($fin, $texte[0]) === false) {
+ $result = phraser_arg($texte, $sep, $result, $pointeur_champ);
+ }
+# mettre ici la suite du texte, +# notamment pour que l'appelant vire le caractere fermant si besoin
+ $pointeur_champ->apres = $texte;
+ return $result;
+}
+
+// http://doc.spip.org/@phraser_arg
+function phraser_arg(&$texte, $sep, $result, &$pointeur_champ) {
+ preg_match(",^(\|?[^}{)|]*)(.*)$,ms", $texte, $match);
+ $suite = ltrim($match[2]);
+ $fonc = trim($match[1]);[... 466 lines stripped ...]
_______________________________________________
Spip-zone-commit@rezo.net - http://listes.rezo.net/mailman/listinfo/spip-zone-commit