From a2652236168bb88db080f8ce2d8b59ef67ce1faf Mon Sep 17 00:00:00 2001
From: Fil <fil@rezo.net>
Date: Wed, 8 Mar 2006 00:29:47 +0000
Subject: [PATCH] =?UTF-8?q?on=20ne=20peut=20pas=20gerer=20le=20noyau=20au?=
 =?UTF-8?q?=20niveau=20de=20find=5Fin=5Fpath(),=20sinon=20on=20y=20m=C3=A9?=
 =?UTF-8?q?morise=20toutes=20les=20recherches=20de=20squelettes=20(article?=
 =?UTF-8?q?-1.html,=20article=3D1.html,=20autant=20de=20fois=20qu'il=20exi?=
 =?UTF-8?q?ste=20de=20rubriques)...?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 ecrire/inc/meta.php  |  5 ++---
 ecrire/inc/utils.php | 46 ++++++++++++++++++++++++++++++--------------
 ecrire/public.php    |  2 +-
 3 files changed, 35 insertions(+), 18 deletions(-)

diff --git a/ecrire/inc/meta.php b/ecrire/inc/meta.php
index b0778c212e..f9ac4a175a 100644
--- a/ecrire/inc/meta.php
+++ b/ecrire/inc/meta.php
@@ -13,9 +13,8 @@
 if (!defined("_ECRIRE_INC_VERSION")) return;
 
 function lire_metas() {
-	// preserver le noyau, sauf si recalcul
-	if (_DIR_RESTREINT
-	AND !_request('var_mode'))
+	// preserver le noyau
+	if (_DIR_RESTREINT)
 		$noyau = $GLOBALS['meta']['noyau'];
 	else
 		$noyau = array();
diff --git a/ecrire/inc/utils.php b/ecrire/inc/utils.php
index 19a3aaa630..9ce68540e5 100644
--- a/ecrire/inc/utils.php
+++ b/ecrire/inc/utils.php
@@ -82,16 +82,39 @@ function include_spip($f, $include = true) {
 	// Hack pour pouvoir appeler cette fonction depuis mes_options.
 	define('_DIR_INCLUDE', _DIR_RESTREINT);
 
+
 	// chercher le fichier dans le chemin (eventuellement, surcharge)
-	if (!$s = find_in_path($f . '.php')
-	AND (!_EXTENSION_PHP OR !$s = find_in_path($f . '.php3')))
+
+	// est-ce dans les chemins du noyau (optimises) ?
+	if (_DIR_RESTREINT) {
+		if (isset($GLOBALS['meta']['noyau'][$f])) {
+			$s = $GLOBALS['meta']['noyau'][$f];
+			if (!$s) return false;
+		}
+		// sinon on se souvient qu'il faudra ecrire le noyau dans public/global
+		else
+			define('ecrire_noyau', 1);
+	}
+
+	if (!isset($s)
+	AND !$s = find_in_path($f . '.php')
+	AND (!_EXTENSION_PHP OR !$s = find_in_path($f . '.php3'))) {
+		if (_DIR_RESTREINT)
+			$GLOBALS['meta']['noyau'][$f] = false;
 		return $included_files[$f] = false;
+	}
 
 	// deja charge (chemin complet) ?
-	if (isset($included_files[$s]))
+	if (isset($included_files[$s])) {
+		if (_DIR_RESTREINT)
+			$GLOBALS['meta']['noyau'][$f] = $included_files[$s];
 		return $included_files[$f] = $included_files[$s];
-	else
+	}
+	else {
+		if (_DIR_RESTREINT)
+			$GLOBALS['meta']['noyau'][$f] = $s;
 		$included_files[$f] = $included_files[$s] = $s;
+	}
 
 	// alors on le charge (sauf si on ne voulait que son chemin)
 	if ($include) {
@@ -626,14 +649,6 @@ function find_in_path ($filename) {
 	static $path_a = array();
 	static $c = '';
 
-	// est-ce dans les chemins deja connus (optimises) ?
-	if (_DIR_RESTREINT) {
-		if (isset($GLOBALS['meta']['noyau'][$filename]))
-			return $GLOBALS['meta']['noyau'][$filename];
-		// sinon on se souvient qu'il faudra ecrire le noyau dans public/global
-		define('ecrire_noyau', 1);
-	}
-
 	// on calcule le chemin si le nombre de plugins a change
 	if ($c != count($GLOBALS['plugins']).$GLOBALS['dossier_squelettes']) {
 		$c = count($GLOBALS['plugins']).$GLOBALS['dossier_squelettes'];
@@ -674,13 +689,11 @@ function find_in_path ($filename) {
 	foreach ($path_a as $dir) {
 		if (@is_readable($f = "$dir$filename")) {
 # spip_log("find_in_path trouve $f");
-			if (_DIR_RESTREINT) $GLOBALS['meta']['noyau'][$filename] = $f;
 			return $f;
 		}
 	}
 
 # spip_log("find_in_path n'a pas vu '$filename' dans " . $path);
-	if (_DIR_RESTREINT) $GLOBALS['meta']['noyau'][$filename] = false;
 	return false;
 }
 
@@ -1049,6 +1062,11 @@ function spip_initialisation() {
 		ecrire_metas();
 	}
 
+	// supprimer le noyau si on recalcul
+	if ($_REQUEST['var_mode']) {
+		$GLOBALS['meta']['noyau'] = array();
+		define('ecrire_noyau', 1);
+	}
 
 	// Langue principale du site
 	$GLOBALS['langue_site'] = $GLOBALS['meta']['langue_site'];
diff --git a/ecrire/public.php b/ecrire/public.php
index 25c2833d7d..f43f52d6ca 100644
--- a/ecrire/public.php
+++ b/ecrire/public.php
@@ -184,7 +184,7 @@ if (defined('_INC_PUBLIC')) {
 	// Ecrire le noyau s'il a change ;
 	// c'est avant cron() pour ne pas l'alourdir
 	if (defined('ecrire_noyau')) {
-		include_spip('inc_meta');
+		include_spip('inc/meta');
 		ecrire_metas();
 	}
 
-- 
GitLab