From a06d6ffa7e9126efd69295f0ae3227724ab11cd0 Mon Sep 17 00:00:00 2001
From: "Committo,Ergo:sum" <esj@rezo.net>
Date: Wed, 27 Dec 2006 10:46:04 +0000
Subject: [PATCH] =?UTF-8?q?Extension=20de=20la=20fonction=20sous=5Freperto?=
 =?UTF-8?q?ire,=20qui=20accepte=20un=20appel=20de=20forme=20{{{sous=5Frepe?=
 =?UTF-8?q?rtoire("d/f")}}}=20comme=20=C3=A9quivalent=20=C3=A0=20{{{sous?=
 =?UTF-8?q?=5Frepertoire("d",=20"f")}}}.=20Du=20coup,=20disparition=20d'un?=
 =?UTF-8?q?e=20incoh=C3=A9rence:=20la=20non=20utilisation=20de=20la=20cons?=
 =?UTF-8?q?tante=20=5FDIR=5FSKELS=20lors=20de=20la=20compilation=20d'un=20?=
 =?UTF-8?q?squelette.?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Cet appel est aussi utilisé pour la création du répertoire de cache des DTD, celui-ci s'annonçant comme bien rempli à l'avenir.
---
 ecrire/inc/flock.php       | 22 ++++++++++++++--------
 ecrire/inc/utils.php       |  6 +++---
 ecrire/inc/valider_xml.php |  3 ++-
 ecrire/public/compiler.php |  2 +-
 ecrire/public/composer.php |  2 +-
 5 files changed, 21 insertions(+), 14 deletions(-)

diff --git a/ecrire/inc/flock.php b/ecrire/inc/flock.php
index a4640271df..c45578e1f1 100644
--- a/ecrire/inc/flock.php
+++ b/ecrire/inc/flock.php
@@ -141,18 +141,24 @@ function supprimer_fichier($fichier) {
 
 //
 // Retourne $base/${subdir}/ si le sous-repertoire peut etre cree,
-// $base/${subdir}_ sinon ; le flag $nobase signale qu'on ne veut pas de $base/
+// $base/${subdir}_ sinon ; $nobase signale qu'on ne veut pas de $base/
+// On peut aussi ne donner qu'un seul argument, 
+// subdir valant alors ce qui suit le dernier / dans $base
 //
 // http://doc.spip.org/@sous_repertoire
-function sous_repertoire($base, $subdir, $nobase = false) {
-	if (!preg_match(',[/_]$,', $base)) $base .= '/';
+function sous_repertoire($base, $subdir='', $nobase = false) {
 	$base = str_replace("//", "/", $base);
+	if (preg_match(',[/_]$,', $base)) $base = substr($base,0,-1);
+	if (!strlen($subdir)) {
+		$n = strrpos($base, "/");
+		if ($n === false) return $nobase ? '' : ($base .'/');
+		$subdir = substr($base, $n+1);
+		$base = substr($base, 0, $n+1);
+	} else {
+		$base .= '/';
+		$subdir = str_replace("/", "", "$subdir");
+	}
 	$baseaff = $nobase ? '' : $base;
-	# $base = 'IMG/distant/' ou 'IMG/distant_'
-
-	if (!strlen($subdir)) return $baseaff;
-
-	$subdir = str_replace("/", "", "$subdir");
 
 	if (@file_exists("$base${subdir}.plat"))
 		return "$baseaff${subdir}_";; 
diff --git a/ecrire/inc/utils.php b/ecrire/inc/utils.php
index 8b3a6ad030..e124ddb1e7 100644
--- a/ecrire/inc/utils.php
+++ b/ecrire/inc/utils.php
@@ -935,7 +935,7 @@ function spip_initialisation($pi=NULL, $pa=NULL, $ti=NULL, $ta=NULL) {
 	define('_DIR_SESSIONS', $ti . "sessions/");
 	define('_DIR_TRANSFERT', $ti . "upload/");
 	define('_DIR_CACHE', $ti . "CACHE/");
-	define('_DIR_DTD', $ti . "CACHE/dtd");
+	define('_DIR_DTD', $ti . "CACHE/dtd/");
 	define('_DIR_SKELS', $ti . "CACHE/skel/");
 	define('_DIR_TMP', $ti);
 
@@ -991,8 +991,8 @@ function spip_initialisation($pi=NULL, $pa=NULL, $ti=NULL, $ta=NULL) {
 
 	define('_DOCTYPE_ECRIRE', 
 		// "<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN' 'http://www.w3.org/TR/html4/loose.dtd'>\n");
-		// "<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>");
-	            "<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>\n");
+		"<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>");
+	       //     "<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>\n");
 
 	define('_DOCTYPE_AIDE', 
 	       "<!DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.01 Frameset//EN' 'http://www.w3.org/TR/1999/REC-html401-19991224/frameset.dtd'>");
diff --git a/ecrire/inc/valider_xml.php b/ecrire/inc/valider_xml.php
index 6bcb1645b7..542e2d5b45 100644
--- a/ecrire/inc/valider_xml.php
+++ b/ecrire/inc/valider_xml.php
@@ -67,7 +67,8 @@ function analyser_dtd($grammaire, $avail, &$dtc)
 	if ($avail == 'SYSTEM')
 	  $file = $grammaire;
 	else
-	  $file = _DIR_CACHE . preg_replace('/[^\w.]/','_', $grammaire);
+	  $file = sous_repertoire(_DIR_DTD);
+	  $file .= preg_replace('/[^\w.]/','_', $grammaire);
 
 	if (@is_readable($file)) {
 		lire_fichier($file, $dtd);
diff --git a/ecrire/public/compiler.php b/ecrire/public/compiler.php
index a0e41605b8..529e735cc0 100644
--- a/ecrire/public/compiler.php
+++ b/ecrire/public/compiler.php
@@ -772,7 +772,7 @@ function public_compiler_dist($squelette, $nom, $gram, $sourcefile) {
 	$secondes = spip_timer('calcul_skel');
 	spip_log("COMPIL ($secondes) ["
 		.preg_replace(',\.html$,', '', $sourcefile)
-		."] ".sous_repertoire(_DIR_CACHE, 'skel', true)."$nom.php");
+		."] $nom.php");
 
 	$code = "<"."?php
 /*
diff --git a/ecrire/public/composer.php b/ecrire/public/composer.php
index 63e92aa45c..edbe947b6c 100644
--- a/ecrire/public/composer.php
+++ b/ecrire/public/composer.php
@@ -39,7 +39,7 @@ function public_composer_dist($squelette, $mime_type, $gram, $sourcefile) {
 	if (function_exists($nom))
 		return $nom;
 
-	$phpfile = sous_repertoire(_DIR_CACHE, 'skel') . $nom . '.php';
+	$phpfile = sous_repertoire(_DIR_SKELS) . $nom . '.php';
 
 	// si squelette est deja compile et perenne, le charger
 	if (!squelette_obsolete($phpfile, $sourcefile)
-- 
GitLab