From c12ddc0f1df5f2e4f443720229082757160134fe Mon Sep 17 00:00:00 2001 From: Fil <fil@rezo.net> Date: Sat, 25 Sep 2004 16:52:37 +0000 Subject: [PATCH] la recherche de squelette conforme au F3C --- inc-calcul-outils.php3 | 28 +++++++++--------- inc-calcul.php3 | 38 ++++++++++-------------- inc-chercher.php3 | 67 ++++++++++++++++++++++++++---------------- 3 files changed, 71 insertions(+), 62 deletions(-) diff --git a/inc-calcul-outils.php3 b/inc-calcul-outils.php3 index 3d4705e99b..26f3ef3e55 100644 --- a/inc-calcul-outils.php3 +++ b/inc-calcul-outils.php3 @@ -342,18 +342,18 @@ function sql_chapo($id_article) function sql_rubrique_fond($contexte, $lang) { if ($id = intval($contexte['id_rubrique'])) { - $row = spip_abstract_fetsel(array('lang'), - array('rubriques'), - array("id_rubrique='$id'")); + $row = spip_abstract_fetsel(array('lang'), + array('rubriques'), + array("id_rubrique='$id'")); if ($row['lang']) $lang = $row['lang']; return array ($id, $lang); } if ($id = intval($contexte['id_breve'])) { - $row = spip_abstract_fetsel(array('id_rubrique', 'lang'), - array('breves'), - array("id_breve='$id'")); + $row = spip_abstract_fetsel(array('id_rubrique', 'lang'), + array('breves'), + array("id_breve='$id'")); $id_rubrique_fond = $row['id_rubrique']; if ($row['lang']) $lang = $row['lang']; @@ -361,22 +361,22 @@ function sql_rubrique_fond($contexte, $lang) { } if ($id = intval($contexte['id_syndic'])) { - $row = spip_abstract_fetsel(array('id_rubrique'), - array('syndic'), - array("id_syndic='$id'")); + $row = spip_abstract_fetsel(array('id_rubrique'), + array('syndic'), + array("id_syndic='$id'")); $id_rubrique_fond = $row['id_rubrique']; $row = spip_abstract_fetsel(array('lang'), - array('rubriques'), - array("id_rubrique='$id_rubrique_fond'")); + array('rubriques'), + array("id_rubrique='$id_rubrique_fond'")); if ($row['lang']) $lang = $row['lang']; return array($id_rubrique_fond, $lang); } if ($id = intval($contexte['id_article'])) { - $row = spip_abstract_fetsel(array('id_rubrique', 'lang'), - array('articles'), - array("id_article='$id'")); + $row = spip_abstract_fetsel(array('id_rubrique', 'lang'), + array('articles'), + array("id_article='$id'")); $id_rubrique_fond = $row['id_rubrique']; if ($row['lang']) $lang = $row['lang']; diff --git a/inc-calcul.php3 b/inc-calcul.php3 index 09ef5ba8b3..0d4e0dc44e 100644 --- a/inc-calcul.php3 +++ b/inc-calcul.php3 @@ -119,17 +119,28 @@ function charger_squelette ($squelette) { # definie dans inc-chercher, fichier non charge si elle est deja definie # (typiquement dans mes_fonctions.php3) -function cherche_page ($cache, $contexte, $fond, $id_rubrique, $lang='') { +function cherche_page ($cache, $contexte, $fond) { global $dossier_squelettes, $delais; if (!function_exists('chercher_squelette')) include_local("inc-chercher.php3"); # a renommer ? // Choisir entre $fond-dist.html, $fond=7.html, etc? + $id_rubrique_fond = 0; + // Si inc-urls veut fixer la langue, on la recupere ici + $lang = $contexte['lang']; + // Chercher le fond qui va servir de squelette + if ($r = sql_rubrique_fond($contexte, + $lang ? $lang : lire_meta('langue_site'))) + list($id_rubrique_fond, $lang) = $r; + + if (!$GLOBALS['forcer_lang']) + lang_select($lang); + $skel = chercher_squelette($fond, - $id_rubrique, + $id_rubrique_fond, $dossier_squelettes ? "$dossier_squelettes/" :'', - $lang); + $GLOBALS['spip_lang']); // Charger le squelette et recuperer sa fonction principale // (compilation automatique au besoin) et calculer @@ -181,7 +192,6 @@ function calculer_contexte() { } function calculer_page_globale($cache, $contexte_local, $fond) { - global $spip_lang; // Gestion des URLs personnalises - sale mais historique if (function_exists("recuperer_parametres_url")) { @@ -197,21 +207,8 @@ function calculer_page_globale($cache, $contexte_local, $fond) { $contexte_local = $contexte; } - $id_rubrique_fond = 0; - - // Si inc-urls veut fixer la langue, se baser ici - $lang = $contexte_local['lang']; - - // Chercher le fond qui va servir de squelette - if ($r = sql_rubrique_fond($contexte_local, - $lang ? $lang : lire_meta('langue_site'))) - list($id_rubrique_fond, $lang) = $r; - - if (!$GLOBALS['forcer_lang']) - lang_select($lang); - // Go to work ! - $page = cherche_page($cache, $contexte_local, $fond, $id_rubrique_fond, $spip_lang); + $page = cherche_page($cache, $contexte_local, $fond); $signal = array(); foreach(array('id_parent', 'id_rubrique', 'id_article', 'id_auteur', @@ -234,10 +231,7 @@ function calculer_page($chemin_cache, $elements, $delais, $inclusion=false) { if ($inclusion) { $contexte_inclus = $elements['contexte']; $page = cherche_page($chemin_cache, - $contexte_inclus, - $elements['fond'], - $contexte_inclus['id_rubrique'] - ); + $contexte_inclus, $elements['fond']); } else { diff --git a/inc-chercher.php3 b/inc-chercher.php3 index 167c4f3a0f..64bb1cc723 100644 --- a/inc-chercher.php3 +++ b/inc-chercher.php3 @@ -4,44 +4,59 @@ if (defined("_INC_CHERCHE")) return; define("_INC_CHERCHE", "1"); -// Ce fichier doit IMPERATIVEMENT contenir la fonction chercher-squelette +// Ce fichier doit imperativement contenir la fonction chercher-squelette // (cf commentaires dans inc-calcul) function chercher_squelette($fond, $id_rubrique, $dossier, $lang) { $ext = $GLOBALS['extension_squelette']; - if ($lang) { - lang_select($lang); - $f = "$fond.$lang"; - if (@file_exists("$f.$ext")) - $fond = $f; - } + $d ="$dossier$fond"; + // On selectionne, dans l'ordre : - // fond=10, fond-10 fond-<rubriques parentes> fond fond-dist + // fond=10 + $f = "$d=$id_rubrique"; if (($id_rubrique > 0) AND (@file_exists("$f.$ext"))) - return $f; + $squelette = $f; - while ($id_rubrique) { - if (@file_exists("$d-$id_rubrique.$ext")) - return "$d-$id_rubrique"; - else - $id_rubrique = sql_parent($id_rubrique); - } + // fond-10 fond-<rubriques parentes> + if (!$squelette) + while ($id_rubrique > 0) { + if (@file_exists("$d-$id_rubrique.$ext")) { + $squelette = "$d-$id_rubrique"; + break; + } + else + $id_rubrique = sql_parent($id_rubrique); + } - if (@file_exists("$d.$ext")) { - return $d; - } else if (@file_exists("$fond.$ext")) { - return $fond; - } else if (@file_exists("$fond-dist.$ext")) { - return "$fond-dist"; - } else { - // erreur webmaster : $fond ne correspond a rien - erreur_squelette(_T('info_erreur_squelette2', - array('fichier'=>$fond)), + if (!$squelette) { + // fond + if (@file_exists("$d.$ext")) + $squelette = $d; + // fond, a la racine + else if (@file_exists("$fond.$ext")) + $squelette = $fond; + else if (@file_exists("$fond-dist.$ext")) + $squelette = "$fond-dist"; + else { + // erreur webmaster : $fond ne correspond a rien + erreur_squelette(_T('info_erreur_squelette2', + array('fichier'=>$fond)), $dossier); - return ''; + return ''; + } } + + // Affiner par lang + if ($lang) { + lang_select($lang); + $f = "$squelette.$lang"; + if (@file_exists("$f.$ext")) + $squelette = $f; + } + + return $squelette; } ?> -- GitLab