From 889ec38121a2056ab033b4fb26e271beba6f50a2 Mon Sep 17 00:00:00 2001
From: Fil <fil@rezo.net>
Date: Sun, 20 Aug 2006 21:17:47 +0000
Subject: [PATCH] revision du comportement standard des modeles inexistants +
 qqs bizarreries ;#TRADUCTIONS devient #ARTICLE_TRADUCTIONS et est appelable
 par <article12|traductions>

---
 .gitattributes                                |  2 +-
 dist/article.html                             |  2 +-
 ...ductions.html => article_traductions.html} |  0
 dist/spip_style.css                           |  3 ++
 dist/style_prive.html                         |  4 ++
 ecrire/inc/texte.php                          |  4 +-
 ecrire/inc/utils.php                          | 37 ++++++++++--------
 ecrire/public/assembler.php                   | 38 ++++++++++++-------
 8 files changed, 56 insertions(+), 34 deletions(-)
 rename dist/modeles/{traductions.html => article_traductions.html} (100%)

diff --git a/.gitattributes b/.gitattributes
index b49192083f..2a2956d5b2 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -9,6 +9,7 @@ dist/inc-head.html -text
 dist/inc-petition.html -text
 dist/inc-pied.html -text
 dist/inc-rubriques.html -text
+dist/modeles/article_traductions.html -text
 dist/modeles/doc.html -text
 dist/modeles/emb.html -text
 dist/modeles/fromage.html -text
@@ -19,7 +20,6 @@ dist/modeles/pagination_page.html -text
 dist/modeles/pagination_page_precedent_suivant.html -text
 dist/modeles/pagination_precedent_suivant.html -text
 dist/modeles/paginationitem.html -text
-dist/modeles/traductions.html -text
 dist/polices/dustismo-license.txt -text svneol=unset#application/octet-stream
 dist/polices/dustismo.ttf -text
 dist/polices/dustismo_bold.ttf -text
diff --git a/dist/article.html b/dist/article.html
index 600a702259..b666d66813 100644
--- a/dist/article.html
+++ b/dist/article.html
@@ -33,7 +33,7 @@
 
 				<p><small>[(#DATE|nom_jour) ][(#DATE|affdate)][, <:par_auteur:> (#LESAUTEURS)]</small></p>
 
-   			#TRADUCTIONS
+   			#ARTICLE_TRADUCTIONS
 			</div>
 			
 			#DEBUT_SURLIGNE
diff --git a/dist/modeles/traductions.html b/dist/modeles/article_traductions.html
similarity index 100%
rename from dist/modeles/traductions.html
rename to dist/modeles/article_traductions.html
diff --git a/dist/spip_style.css b/dist/spip_style.css
index 9da7cec748..6014506ba2 100644
--- a/dist/spip_style.css
+++ b/dist/spip_style.css
@@ -78,6 +78,9 @@ span.spip_documents_center { display:block; margin-top:1em; }
 /* Images typographiques (via image_typo), URL a revoir... */
 .format_png { behavior: url(win_png.htc); }
 
+/* modeles par defaut */
+.spip_modele {float:right; display:block; border:1px dotted grey; width:180px;}
+
 /* Barre de raccourcis typographiques */
 table.spip_barre { width: 100%; }
 
diff --git a/dist/style_prive.html b/dist/style_prive.html
index b65303b182..281fc76ebb 100644
--- a/dist/style_prive.html
+++ b/dist/style_prive.html
@@ -1307,6 +1307,10 @@ img, .spip_logos { margin: 0; padding: 0; border: none; }
 .spip_doc_titre { font-weight: bold; }
 .spip_doc_descriptif { clear: both; }
 
+
+/* modeles par defaut */
+.spip_modele {float:right; display:block; border:1px dotted grey; width:180px;}
+
 /* pour le plugin "revision_nbsp" */
 .spip-nbsp {
 	border-bottom: 2px solid #c8c8c8;
diff --git a/ecrire/inc/texte.php b/ecrire/inc/texte.php
index 6ae7f92bf8..69b0c0a2f1 100644
--- a/ecrire/inc/texte.php
+++ b/ecrire/inc/texte.php
@@ -597,11 +597,9 @@ function calculer_url ($lien, $texte='', $pour='url') {
 
 		// aliases (historique)
 		if ($f == 'art') $f = 'article';
-		else if ($f == 'art') $f = 'article';
-		else if ($f == 'rub') $f = 'rubrique';
 		else if ($f == 'rub') $f = 'rubrique';
 		else if ($f == 'aut') $f = 'auteur';
-		else if ($f == 'doc' OR $f == 'im' OR $f == 'img' OR $f == 'image')
+		else if ($f == 'doc' OR $f == 'im' OR $f == 'img' OR $f == 'image' OR $f == 'emb')
 			$f = 'document';
 		else if (preg_match(',^br..?ve$,S', $f)) $f = 'breve'; # accents :(
 
diff --git a/ecrire/inc/utils.php b/ecrire/inc/utils.php
index abc9b1d3b9..11e0bca957 100644
--- a/ecrire/inc/utils.php
+++ b/ecrire/inc/utils.php
@@ -440,22 +440,25 @@ function joli_repertoire($rep) {
 // http://doc.spip.org/@table_objet
 function table_objet($type) {
 	static $surnoms = array(
-                'article' => 'articles',
-                'auteur' => 'auteurs',
-                'breve' => 'breves',
-                'document' => 'documents',
-                'forum' => 'forum', # hum
-                'groupe_mots' => 'groupes_mots', # hum
-                'message' => 'messages',
-                'mot' => 'mots',
-                'petition' => 'petitions',
-                'rubrique' => 'rubriques',
-                'signature' => 'signatures',
-                'syndic' => 'syndic',
-                'site' => 'syndic', # hum hum
-                'syndic_article' => 'syndic_articles',
-                'type_document' => 'types_documents' # hum
-		);
+		'article' => 'articles',
+		'auteur' => 'auteurs',
+		'breve' => 'breves',
+		'document' => 'documents',
+		'doc' => 'documents', # pour les modeles
+		'img' => 'documents',
+		'emb' => 'documents',
+		'forum' => 'forum', # hum
+		'groupe_mots' => 'groupes_mots', # hum
+		'message' => 'messages',
+		'mot' => 'mots',
+		'petition' => 'petitions',
+		'rubrique' => 'rubriques',
+		'signature' => 'signatures',
+		'syndic' => 'syndic',
+		'site' => 'syndic', # hum hum
+		'syndic_article' => 'syndic_articles',
+		'type_document' => 'types_documents' # hum
+	);
 	return $surnoms[$type];
 }
 
@@ -465,6 +468,8 @@ function id_table_objet($type) {
 		return 'id_syndic';
 	else if ($type == 'forum')
 		return 'id_forum';
+	else if ($type=='doc' OR $type=='img' OR $type=='emb') # pour les modeles
+		return 'id_document';
 	else
 		return 'id_'.$type;
 }
diff --git a/ecrire/public/assembler.php b/ecrire/public/assembler.php
index a094f6b976..3c2c1f5c63 100644
--- a/ecrire/public/assembler.php
+++ b/ecrire/public/assembler.php
@@ -429,21 +429,31 @@ function inclure_modele($squelette, $type, $id) {
 		}
 	}
 
-	// special img, doc, emb
-	if (in_array($type, array('img', 'doc', 'emb')))
-		$id_type = 'id_document';
-	else
-		$id_type = 'id_'.$type;
+	// en cas d'echec, si l'objet demande a une url, on cree un petit encadre
+	// avec un lien vers l'objet ; sinon on passe la main au suivant
+	if (!find_in_path($fond.'.html')) {
+		$lien = calculer_url("$type$id", '', 'tout');
+		if ($lien[1] == 'spip_url')
+			return false;
+		else
+			return '<a href="'.$lien[0].'" class="spip_modele'
+				. ($class ? " $class" : '')
+				. '">'.sinon($lien[2], _T('ecrire:info_sans_titre'))."</a>";
+	}
 
-	// en cas d'echec on passe la main au suivant
-	if (!find_in_path($fond.'.html'))
-		return false;
 
+	// Creer le contexte
 	$contexte = array(
-		$id_type => $id,
 		'lang' => $GLOBALS['spip_lang'],
-		'fond' => $fond
+		'fond' => $fond,
+		'dir_racine' => _DIR_RACINE # eviter de mixer un cache racine et un cache ecrire (meme si pour l'instant les modeles ne sont pas caches, le resultat etant different il faut que le contexte en tienne compte
 	);
+	// Fixer l'identifiant qu'on passe dans #ENV ;
+	// pour le modele <site1> on veut id_syndic => 1
+	// par souci de systematisme on ajoute aussi
+	// id => 1.
+	$contexte[id_table_objet($type)] = $contexte['id'] = $id;
+
 	if ($align)
 		$contexte['align'] = $align;
 
@@ -452,10 +462,11 @@ function inclure_modele($squelette, $type, $id) {
 
 	// Traiter les parametres
 	// par exemple : <img1|center>, <emb12|autostart=true> ou <doc1|lang=en>
-	$contexte = array_merge($contexte, 
+	$contexte = array_merge($contexte,
 		creer_contexte_de_modele(explode('|', $squelette))); 
 
-	// Un marqueur de notes unique lie a ce modele
+	// On cree un marqueur de notes unique lie a ce modele
+	$enregistre_marqueur_notes = $GLOBALS['marqueur_notes'];
 	$GLOBALS['marqueur_notes'] = substr(md5(serialize($contexte)),0,8);
 	$GLOBALS['compt_note'] = 0;
 
@@ -465,8 +476,9 @@ function inclure_modele($squelette, $type, $id) {
 	// Si le modele n'a pas affiche ses notes, les supprimer (elles *doivent*
 	// etre dans le cache du modele, autrement elles ne seraient pas prises en
 	// compte a chaque calcul d'un texte contenant un modele, mais seulement
-	// quand le modele serait calcule)
+	// quand le modele serait calcule, et on aurait des resultats incoherents)
 	$GLOBALS['les_notes'] = '';
+	$GLOBALS['marqueur_notes'] = $enregistre_marqueur_notes;
 
 	$compteur--;
 	return $retour;
-- 
GitLab