From 09ff4a810aa13c35f05d32f6e289a7d0b1bb47c4 Mon Sep 17 00:00:00 2001
From: Fil <fil@rezo.net>
Date: Wed, 21 Dec 2005 00:27:37 +0000
Subject: [PATCH] clarification sur l'emploi du filtre interdire_scripts
 (changement de nomenclature dans le code, a fonctionnalite equivalente)
 attention ca casse un peu l'API pour ceux qui ont des balises persos.

---
 inc-balises.php3       | 84 +++++++++++++++++++++---------------------
 inc-compilo-api.php3   |  9 ++---
 inc-compilo-index.php3 | 13 ++++---
 inc-compilo.php3       |  4 +-
 4 files changed, 56 insertions(+), 54 deletions(-)

diff --git a/inc-balises.php3 b/inc-balises.php3
index e8cb1db5eb..c98d342976 100644
--- a/inc-balises.php3
+++ b/inc-balises.php3
@@ -76,47 +76,47 @@ function balise_distante_interdite($p) {
 //
 function balise_NOM_SITE_SPIP_dist($p) {
 	$p->code = "\$GLOBALS['meta']['nom_site']";
-	$p->statut = 'html';
+	#$p->interdire_scripts = true;
 	return $p;
 }
 
 function balise_EMAIL_WEBMASTER_dist($p) {
 	$p->code = "\$GLOBALS['meta']['email_webmaster']";
-	$p->statut = 'html';
+	#$p->interdire_scripts = true;
 	return $p;
 }
 
 function balise_CHARSET_dist($p) {
 	$p->code = "\$GLOBALS['meta']['charset']";
-	$p->statut = 'html';
+	#$p->interdire_scripts = true;
 	return $p;
 }
 
 function balise_LANG_LEFT_dist($p) {
 	$_lang = champ_sql('lang', $p);
 	$p->code = "lang_dir(($_lang ? $_lang : \$GLOBALS['spip_lang']),'left','right')";
-	$p->statut = 'php';
+	$p->interdire_scripts = false;
 	return $p;
 }
 
 function balise_LANG_RIGHT_dist($p) {
 	$_lang = champ_sql('lang', $p);
 	$p->code = "lang_dir(($_lang ? $_lang : \$GLOBALS['spip_lang']),'right','left')";
-	$p->statut = 'php';
+	$p->interdire_scripts = false;
 	return $p;
 }
 
 function balise_LANG_DIR_dist($p) {
 	$_lang = champ_sql('lang', $p);
 	$p->code = "lang_dir(($_lang ? $_lang : \$GLOBALS['spip_lang']),'ltr','rtl')";
-	$p->statut = 'php';
+	$p->interdire_scripts = false;
 	return $p;
 }
 
 function balise_PUCE_dist($p) {
 	$_lang = champ_sql('lang', $p);
 	$p->code = "((lang_dir(($_lang ? $_lang : \$GLOBALS['spip_lang']),false,true) && \$GLOBALS['puce_rtl']) ? \$GLOBALS['puce_rtl'] : \$GLOBALS['puce'])";
-	$p->statut = 'php';
+	$p->interdire_scripts = false;
 	return $p;
 }
 
@@ -127,7 +127,7 @@ function balise_PUCE_dist($p) {
 function balise_DATE_dist ($p) {
 	$_date = champ_sql('date', $p);
 	$p->code = "$_date";
-	$p->statut = 'php';
+	$p->interdire_scripts = false;
 	return $p;
 }
 
@@ -136,7 +136,7 @@ function balise_DATE_dist ($p) {
 function balise_DATE_REDAC_dist ($p) {
 	$_date = champ_sql('date_redac', $p);
 	$p->code = "$_date";
-	$p->statut = 'php';
+	$p->interdire_scripts = false;
 	return $p;
 }
 
@@ -145,7 +145,7 @@ function balise_DATE_REDAC_dist ($p) {
 function balise_DATE_MODIF_dist ($p) {
 	$_date = champ_sql('date_modif', $p);
 	$p->code = "$_date";
-	$p->statut = 'php';
+	$p->interdire_scripts = false;
 	return $p;
 }
 
@@ -156,19 +156,19 @@ function balise_DATE_NOUVEAUTES_dist($p) {
 	AND @file_exists(_DIR_SESSIONS . 'mail.lock')) ?
 	normaliser_date(@filemtime(_DIR_SESSIONS . 'mail.lock')) :
 	\"'0000-00-00'\")";
-	$p->statut = 'php';
+	$p->interdire_scripts = false;
 	return $p;
 }
 
 function balise_DOSSIER_SQUELETTE_dist($p) {
 	$p->code = "'" . addslashes(dirname($p->descr['sourcefile'])) . "'" ;
-	$p->statut = 'php';
+	$p->interdire_scripts = false;
 	return $p;
 }
 
 function balise_URL_SITE_SPIP_dist($p) {
 	$p->code = "\$GLOBALS['meta']['adresse_site']";
-	$p->statut = 'html';
+	#$p->interdire_scripts = true;
 	return $p;
 }
 
@@ -190,7 +190,7 @@ function balise_URL_ARTICLE_dist($p) {
 			$p->code = "url_var_recherche(" . $p->code . ")";
 	}
 
-	$p->statut = 'php';
+	$p->interdire_scripts = false;
 	return $p;
 }
 
@@ -201,7 +201,7 @@ function balise_URL_RUBRIQUE_dist($p) {
 	if ($p->boucles[$p->nom_boucle ? $p->nom_boucle : $p->id_boucle]->hash)
 	$p->code = "url_var_recherche(" . $p->code . ")";
 
-	$p->statut = 'php';
+	$p->interdire_scripts = false;
 	return $p;
 }
 
@@ -212,7 +212,7 @@ function balise_URL_BREVE_dist($p) {
 	if ($p->boucles[$p->nom_boucle ? $p->nom_boucle : $p->id_boucle]->hash)
 	$p->code = "url_var_recherche(" . $p->code . ")";
 
-	$p->statut = 'php';
+	$p->interdire_scripts = false;
 	return $p;
 }
 
@@ -224,7 +224,7 @@ function balise_URL_MOT_dist($p) {
 	if ($p->boucles[$p->nom_boucle ? $p->nom_boucle : $p->id_boucle]->hash)
 	$p->code = "url_var_recherche(" . $p->code . ")";
 
-	$p->statut = 'php';
+	$p->interdire_scripts = false;
 	return $p;
 }
 
@@ -241,7 +241,7 @@ function balise_URL_FORUM_dist($p) {
 	if ($p->boucles[$p->nom_boucle ? $p->nom_boucle : $p->id_boucle]->hash)
 	$p->code = "url_var_recherche(" . $p->code . ")";
 
-	$p->statut = 'php';
+	$p->interdire_scripts = false;
 	return $p;
 }
 
@@ -249,7 +249,7 @@ function balise_URL_DOCUMENT_dist($p) {
 	$p->code = "generer_url_document(" .
 	champ_sql('id_document',$p) . ")";
 
-	$p->statut = 'php';
+	$p->interdire_scripts = false;
 	return $p;
 }
 
@@ -259,20 +259,20 @@ function balise_URL_AUTEUR_dist($p) {
 	if ($p->boucles[$p->nom_boucle ? $p->nom_boucle : $p->id_boucle]->hash)
 	$p->code = "url_var_recherche(" . $p->code . ")";
 
-	$p->statut = 'php';
+	$p->interdire_scripts = false;
 	return $p;
 }
 
 function balise_NOTES_dist($p) {
 	// Recuperer les notes
 	$p->code = 'calculer_notes()';
-	$p->statut = 'html';
+	#$p->interdire_scripts = true;
 	return $p;
 }
 
 function balise_RECHERCHE_dist($p) {
 	$p->code = 'htmlspecialchars($GLOBALS["recherche"])';
-	$p->statut = 'php';
+	$p->interdire_scripts = false;
 	return $p;
 }
 
@@ -287,7 +287,7 @@ function balise_COMPTEUR_BOUCLE_dist($p) {
 	} else {
 		$p->code = "\$Numrows['$b']['compteur_boucle']";
 		$p->boucles[$b]->cptrows = true;
-		$p->statut = 'num';
+		$p->interdire_scripts = false;
 		return $p;
 	}
 }
@@ -303,7 +303,7 @@ function balise_TOTAL_BOUCLE_dist($p) {
 	} else {
 		$p->code = "\$Numrows['$b']['total']";
 		$p->boucles[$b]->numrows = true;
-		$p->statut = 'num';
+		$p->interdire_scripts = false;
 	}
 	return $p;
 }
@@ -320,19 +320,19 @@ function balise_POPULARITE_ABSOLUE_dist($p) {
 	$p->code = 'ceil(' .
 	champ_sql('popularite', $p) .
 	')';
-	$p->statut = 'num';
+	$p->interdire_scripts = false;
 	return $p;
 }
 
 function balise_POPULARITE_SITE_dist($p) {
 	$p->code = 'ceil($GLOBALS["meta"][\'popularite_total\'])';
-	$p->statut = 'num';
+	$p->interdire_scripts = false;
 	return $p;
 }
 
 function balise_POPULARITE_MAX_dist($p) {
 	$p->code = 'ceil($GLOBALS["meta"][\'popularite_max\'])';
-	$p->statut = 'num';
+	$p->interdire_scripts = false;
 	return $p;
 }
 
@@ -388,7 +388,7 @@ function calculer_balise_expose($p, $on, $off)
 	$p->code = '(calcul_exposer('
 	.champ_sql($primary_key, $p)
 	.", '$primary_key', \$Pile[0]) ? $on : $off)";
-	$p->statut = 'php';
+	$p->interdire_scripts = false;
 	return $p;
 }
 
@@ -402,7 +402,7 @@ function balise_EMBED_DOCUMENT_dist($p) {
 	  argumenter_balise($p->fonctions, "|") .
 	  ", \$doublons, '" . $p->descr['documents'] . "')";
 	$p->param = array();
-	$p->statut = 'html';
+	#$p->interdire_scripts = true;
 	return $p;
 }
 
@@ -431,7 +431,7 @@ function balise_FIN_SURLIGNE_dist($p) {
 // ATTENTION: cette balise efface parfois les boutons admin implicites
 function balise_SPIP_CRON_dist ($p) {
 	$p->code = "'<div style=\\'position: absolute; background-image: url(\"spip_background.php3\"); height: 1px; width: 1px;\\'></div>'";
-	$p->statut='php';
+	$p->interdire_scripts = false;
 	return $p;
 }
 
@@ -445,7 +445,7 @@ function balise_INTRODUCTION_dist ($p) {
 	$_descriptif = champ_sql('descriptif', $p);
 	$p->code = "calcul_introduction('$_type', $_texte, $_chapo, $_descriptif)";
 
-	$p->statut = 'html';
+	#$p->interdire_scripts = true;
 	return $p;
 }
 
@@ -455,7 +455,7 @@ function balise_INTRODUCTION_dist ($p) {
 function balise_LANG_dist ($p) {
 	$_lang = champ_sql('lang', $p);
 	$p->code = "($_lang ? $_lang : \$GLOBALS['spip_lang'])";
-	$p->statut = 'php';
+	$p->interdire_scripts = false;
 	return $p;
 }
 
@@ -488,7 +488,7 @@ function balise_LESAUTEURS_dist ($p) {
 			"')";
 	}
 
-	$p->statut = 'html';
+	#$p->interdire_scripts = true;
 	return $p;
 }
 
@@ -509,7 +509,7 @@ function balise_PETITION_dist ($p) {
 			"','" .
 			$p->boucles[$nom]->sql_serveur .
 			"', \$Cache)";
-	$p->statut = 'php';
+	$p->interdire_scripts = false;
 	return $p;
 }
 
@@ -520,7 +520,7 @@ function balise_POPULARITE_dist ($p) {
 	$_popularite = champ_sql('popularite', $p);
 	$p->code = "(ceil(min(100, 100 * $_popularite
 	/ max(1 , 0 + \$GLOBALS['meta']['popularite_max']))))";
-	$p->statut = 'num';
+	$p->interdire_scripts = false;
 	return $p;
 }
 
@@ -631,7 +631,7 @@ function calculer_balise_logo ($p) {
 			(($type_objet == 'RUBRIQUE') ? "sql_parent($_id_objet)" : "''")) .
 			",  '$flag_fichier'), $code_lien)";
 	}
-	$p->statut = 'php';
+	$p->interdire_scripts = false;
 	return $p;
 }
 
@@ -666,7 +666,7 @@ function balise_EXTRA_dist ($p) {
 		}
 	}
 
-	$p->statut = 'html';
+	#$p->interdire_scripts = true;
 	return $p;
 }
 
@@ -729,7 +729,7 @@ function balise_PARAMETRES_FORUM_dist($p) {
 
 	$p->code .= code_invalideur_forums($p, "(".$c.")");
 
-	$p->statut = 'html';
+	#$p->interdire_scripts = true;
 	return $p;
 }
 
@@ -755,7 +755,7 @@ function code_invalideur_forums($p, $code) {
 // http://www.spip.net/@self
 function balise_SELF_dist($p) {
 	$p->code = 'quote_amp($GLOBALS["clean_link"]->getUrl())';
-	$p->statut = 'php';
+	$p->interdire_scripts = false;
 	return $p;
 }
 
@@ -786,7 +786,7 @@ function balise_ENV_dist($p) {
 		// cas de #ENV sans argument : on retourne le serialize() du tableau
 		// une belle fonction [(#ENV|affiche_env)] serait pratique
 		$p->code = 'serialize($Pile[0])';
-		$p->statut = 'html';
+		#$p->interdire_scripts = true;
 	} else {
 		// admet deux arguments : nom de variable, valeur par defaut si vide
 		$p->code = '$Pile[0]["' . addslashes($nom) . '"]';
@@ -795,7 +795,7 @@ function balise_ENV_dist($p) {
 				$p->code
 				. compose_filtres_args($p, $sinon, ',')
 				. ')';
-		$p->statut = 'php';
+		$p->interdire_scripts = false;
 	}
 
 	return $p;
@@ -807,7 +807,7 @@ function balise_ENV_dist($p) {
 //
 function balise_REM_dist($p) {
 	$p->code="''";
-	$p->statut='php';
+	$p->interdire_scripts = false;
 	return $p;
 }
 
diff --git a/inc-compilo-api.php3 b/inc-compilo-api.php3
index c0e3fcd4a4..c544c0903d 100644
--- a/inc-compilo-api.php3
+++ b/inc-compilo-api.php3
@@ -66,7 +66,7 @@ class Boucle {
 	var $lien = false;
 	var $sous_requete = false;
 	var $hierarchie = '';
-	var $statut = false;
+	var $statut = false; # definition/surcharge du statut des elements retournes
 	// champs pour la construction du corps PHP
 	var $id_table;
 	var $primary;
@@ -98,8 +98,7 @@ class Champ {
 	var $boucles;
 	var $type_requete;
 	var $code;	// code du calcul
-	var $statut;	// 'numerique, 'h'=texte (html) ou 'p'=script (php) ?
-			// -> definira les pre et post-traitements obligatoires
+	var $interdire_scripts = true; // false si on est sur de cette balise
 	// tableau pour la production de code dependant du contexte
 	// id_mere;  pour TOTAL_BOUCLE hors du corps
 	// document; pour embed et img dans les textes
@@ -122,7 +121,7 @@ class Idiome {
 	var $boucles;
 	var $type_requete;
 	var $code;
-	var $statut;
+	var $interdire_scripts = false;
 	var $descr = array();
 	var $ligne = 0; 
 }
@@ -135,7 +134,7 @@ class Polyglotte {
 //
 // Globales de description de la base
 
-//ces variabales ne sont pas initialisees par "$var = array()"
+//ces variables ne sont pas initialisees par "$var = array()"
 // afin de permettre leur extension dans mes_options.php etc
 
 global $tables_des_serveurs_sql, $tables_principales; // (voir inc_serialbase)
diff --git a/inc-compilo-index.php3 b/inc-compilo-index.php3
index ba8ad28dbc..fbe453f0e8 100644
--- a/inc-compilo-index.php3
+++ b/inc-compilo-index.php3
@@ -178,7 +178,9 @@ function calculer_balise($nom, $p) {
 	// ca pourrait etre un champ SQL homonyme,
 	$p->code = index_pile($p->id_boucle, $nom, $p->boucles, $p->nom_boucle);
 
-	if (strpos($nom, 'ID_') === 0) $p->statut = 'num';
+	// ne pas passer le filtre securite sur les id_xxx
+	if (strpos($nom, 'ID_') === 0)
+		$p->interdire_scripts = false;
 
 	// Compatibilite ascendante avec les couleurs html (#FEFEFE) :
 	// SI le champ SQL n'est pas trouve
@@ -190,7 +192,7 @@ function calculer_balise($nom, $p) {
 	AND !$p->etoile
 	AND !$p->fonctions) {
 		$p->code = "'#$nom'";
-		$p->statut = 'php';
+		$p->interdire_scripts = false;
 	}
 
 	return $p;
@@ -225,7 +227,7 @@ function calculer_balise_dynamique($p, $nom, $l) {
 	  . "), \$GLOBALS['spip_lang'],"
 	  . $p->ligne
 	  . ')';
-	$p->statut = 'php';
+	$p->interdire_scripts = false;
 	$p->fonctions = array();
 	$p->param = array();
 
@@ -264,7 +266,8 @@ function applique_filtres($p) {
 	// Appliquer les filtres perso
 	if ($p->param) $code = compose_filtres($p, $code);
 	// post-traitement securite
-	if ($p->statut == 'html') $code = "interdire_scripts($code)";
+	if ($p->interdire_scripts)
+		$code = "interdire_scripts($code)";
 	return $code;
 }
 
@@ -344,7 +347,7 @@ function rindex_pile($p, $champ, $motif)
 				'motif' => $motif)
 		), $p->id_boucle);
 	}
-	$p->statut = 'php';
+	$p->interdire_scripts = false;
 	return $p;
 }
 
diff --git a/inc-compilo.php3 b/inc-compilo.php3
index 4600250c1e..a2b6e64c97 100644
--- a/inc-compilo.php3
+++ b/inc-compilo.php3
@@ -456,7 +456,7 @@ function compile_cas($tableau, $descr, &$boucles, $id_boucle='') {
 			$p->code = "_T('" . $p->module . ":" .$p->nom_champ . "')";
 			$p->id_boucle = $id_boucle;
 			$p->boucles = &$boucles;
-			$p->statut = 'php'; // ne pas manger les espaces avec trim()
+			$p->interdire_scripts = false;
 			$commentaire = ":";
 			$code = applique_filtres($p);
 			$avant='';
@@ -470,7 +470,7 @@ function compile_cas($tableau, $descr, &$boucles, $id_boucle='') {
 			$p->id_boucle = $id_boucle;
 			$p->boucles = &$boucles;
 			$p->descr = $descr;
-			$p->statut = 'html';
+			#$p->interdire_scripts = true;
 			$p->type_requete = $type;
 
 			$code = calculer_champ($p);
-- 
GitLab