X-Git-Url: http://git.cyclocoop.org/?a=blobdiff_plain;f=www%2Fecrire%2Fpublic%2Fsandbox.php;h=3f615b068eeed8cb7171cf4486e3aca3417496ae;hb=d18fcb8f27a4016e3fa7b50a9b2255d529dca543;hp=8f3cb75aa6b4dacab14efa69a24fd94790e430ba;hpb=5be150361b3c836d9206941ba43f862df11466db;p=ptitvelo%2Fweb%2Fwww.git diff --git a/www/ecrire/public/sandbox.php b/www/ecrire/public/sandbox.php index 8f3cb75..3f615b0 100644 --- a/www/ecrire/public/sandbox.php +++ b/www/ecrire/public/sandbox.php @@ -48,7 +48,20 @@ 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...) + if (strpbrk($f, ':')) { // Class::method + $refl = new ReflectionMethod($f); + } else { + $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 +72,13 @@ function sandbox_composer_filtre($fonc, $code, $arglist, &$p){ // Calculer un // 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 +86,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); } /**