[SPIP] ~maj v3.0.14-->v3.0.17
[ptitvelo/web/www.git] / www / ecrire / public / sandbox.php
index 8f3cb75..a742c23 100644 (file)
@@ -48,7 +48,16 @@ function sandbox_composer_filtre($fonc, $code, $arglist, &$p){
        // le filtre est defini sous forme de fonction ou de methode
        // par ex. dans inc_texte, inc_filtres ou mes_fonctions
        elseif ($f = chercher_filtre($fonc)) {
-               $code = "$f($code$arglist)";
+               // cas particulier : le filtre |set doit acceder a la $Pile
+               // proto: filtre_set(&$Pile, $val, $args...)
+               $refl = new ReflectionFunction($f);
+               $refs = $refl->getParameters();
+               if (isset($refs[0]) AND $refs[0]->name == 'Pile') {
+                       $code = "$f(\$Pile,$code$arglist)";
+               }
+               else {
+                       $code = "$f($code$arglist)";
+               }
        }
        // le filtre n'existe pas,
        // on le notifie
@@ -59,9 +68,13 @@ function sandbox_composer_filtre($fonc, $code, $arglist, &$p){
 
 // Calculer un <INCLURE(xx.php)>
 // La constante ci-dessous donne le code general quand il s'agit d'un script.
-define('CODE_INCLURE_SCRIPT', 'if (($path = %s) AND is_readable($path)) {
-include $path;
-} else erreur_squelette(array("fichier_introuvable", array("fichier" => "%s")), array(%s));'
+define('CODE_INCLURE_SCRIPT', 'if (!($path = %s) OR !is_readable($path))
+       erreur_squelette(array("fichier_introuvable", array("fichier" => "%s")), array(%s));
+else {
+       $contexte_inclus = %s;
+       include $path;
+}
+'
 );
 
 /**
@@ -69,16 +82,17 @@ include $path;
  *
  * @param string $fichier
  * @param Object $p
+ * @param array $_contexte
  * @return string
  */
-function sandbox_composer_inclure_php($fichier, &$p){
+function sandbox_composer_inclure_php($fichier, &$p, $_contexte){
        $compil = texte_script(memoriser_contexte_compil($p));
        // si inexistant, on essaiera a l'execution
        if ($path = find_in_path($fichier))
                $path = "\"$path\"";
        else $path = "find_in_path(\"$fichier\")";
 
-       return sprintf(CODE_INCLURE_SCRIPT, $path, $fichier, $compil);
+       return sprintf(CODE_INCLURE_SCRIPT, $path, $fichier, $compil, $_contexte);
 }
 
 /**