From 5d25ad7fd115f1ba38ec29b77b0053b6ab5b5ce9 Mon Sep 17 00:00:00 2001
From: Cerdic <cedric@yterium.com>
Date: Sat, 17 Nov 2007 17:14:08 +0000
Subject: [PATCH] aafficher_contenu_objet abandonne l'usine a gaz au profit
 d'un squelette personalisable par type, dont le resultat passe dans un
 pipeline pour permettre l'extension par les plugins

---
 .gitattributes                        |   4 +
 dist/prive/contenu/article.html       |  41 +++++++++
 dist/prive/contenu/breve.html         |  21 +++++
 dist/prive/contenu/rubrique.html      |  21 +++++
 dist/prive/contenu/site.html          |  17 ++++
 ecrire/inc/afficher_contenu_objet.php | 127 ++------------------------
 6 files changed, 111 insertions(+), 120 deletions(-)
 create mode 100644 dist/prive/contenu/article.html
 create mode 100644 dist/prive/contenu/breve.html
 create mode 100644 dist/prive/contenu/rubrique.html
 create mode 100644 dist/prive/contenu/site.html

diff --git a/.gitattributes b/.gitattributes
index 35d03b01d5..2e19856f8d 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -266,6 +266,10 @@ dist/prive/article_infos_fonctions.php -text
 dist/prive/auteur_infos.html -text
 dist/prive/breve_infos.html -text
 dist/prive/breve_infos_fonctions.php -text
+dist/prive/contenu/article.html -text
+dist/prive/contenu/breve.html -text
+dist/prive/contenu/rubrique.html -text
+dist/prive/contenu/site.html -text
 dist/prive/rubrique_infos.html -text
 dist/prive/site_infos.html -text
 dist/prive/site_infos_fonctions.php -text
diff --git a/dist/prive/contenu/article.html b/dist/prive/contenu/article.html
new file mode 100644
index 0000000000..e9ebd5f0db
--- /dev/null
+++ b/dist/prive/contenu/article.html
@@ -0,0 +1,41 @@
+<BOUCLE_afficher_contenu(ARTICLES){id_article=#ENV{id}}{statut?}>
+<span class="champ contenu_surtitre[ (#SURTITRE*|?{'',vide})]">
+<span class='label'><:texte_sur_titre:></span>
+<span dir='#LANG_DIR' class='#EDIT{surtitre} surtitre'>#SURTITRE</span>
+</span>
+<span class="champ contenu_titre[ (#TITRE*|?{'',vide})]">
+<span class='label'><:info_titre:></span>
+<span dir='#LANG_DIR' class='#EDIT{titre} titre'>#TITRE</span>
+</span>
+<span class="champ contenu_soustitre[ (#SOUSTITRE*|?{'',vide})]">
+<span class='label'><:texte_sous_titre:></span>
+<span dir='#LANG_DIR' class='#EDIT{soustitre} soustitre'>#SOUSTITRE</span>
+</span>
+<span class="champ contenu_descriptif[ (#DESCRIPTIF*|?{'',vide})]">
+<span class='label'><:info_descriptif:></span>
+<span dir='#LANG_DIR' class='#EDIT{descriptif} descriptif'>#DESCRIPTIF</span>
+</span>
+<span class="champ contenu_chapo[ (#CHAPO*|?{'',vide})]">
+<span class='label'><:info_chapeau:></span>
+<span dir='#LANG_DIR' class='#EDIT{chapo} chapo'>#CHAPO</span>
+</span>
+<span class="champ contenu_nom_site[ (#NOM_SITE*|?{'',vide})]">
+<span class='label'><:lien_voir_en_ligne:></span>
+<span dir='#LANG_DIR' class='#EDIT{hyperlien} nom_site'><a href='#URL_SITE'>#NOM_SITE</a></span>
+</span>
+<span class="champ contenu_texte[ (#TEXTE*|?{'',vide})]">
+<span class='label'><:info_texte:></span>
+<span dir='#LANG_DIR' class='#EDIT{texte} texte'>#TEXTE</span>
+</span>
+<span class="champ contenu_ps[ (#PS*|?{'',vide})]">
+<span class='label'><:info_ps:></span>
+<span dir='#LANG_DIR' class='#EDIT{ps} ps'>#PS</span>
+</span>
+[<span class="champ contenu_notes">
+<span class='label'><:info_notes:></span>
+<span dir='#LANG_DIR' class='#EDIT{notes} notes'>(#NOTES)</span>
+</span>]
+[(#ENV{champs_extra}|?{' '})
+[(#EXTRA**|extra_affichage)]
+]
+</BOUCLE_afficher_contenu>
\ No newline at end of file
diff --git a/dist/prive/contenu/breve.html b/dist/prive/contenu/breve.html
new file mode 100644
index 0000000000..4c5be7a127
--- /dev/null
+++ b/dist/prive/contenu/breve.html
@@ -0,0 +1,21 @@
+<BOUCLE_afficher_contenu(BREVES){id_breve=#ENV{id}}{statut?}>
+<span class="champ contenu_titre[ (#TITRE*|?{'',vide})]">
+<span class='label'><:info_titre:></span>
+<span dir='#LANG_DIR' class='#EDIT{titre} titre'>#TITRE</span>
+</span>
+<span class="champ contenu_texte[ (#TEXTE*|?{'',vide})]">
+<span class='label'><:info_texte:></span>
+<span dir='#LANG_DIR' class='#EDIT{texte} texte'>#TEXTE</span>
+</span>
+<span class="champ contenu_lien_titre[ (#LIEN_TITRE*|?{'',vide})]">
+<span class='label'><:lien_voir_en_ligne:></span>
+<span dir='#LANG_DIR' class='#EDIT{hyperlien} lien_titre'><a href='#LIEN_URL'>#LIEN_TITRE</a></span>
+</span>
+[<span class="champ contenu_notes">
+<span class='label'><:info_notes:></span>
+<span dir='#LANG_DIR' class='#EDIT{notes} notes'>(#NOTES)</span>
+</span>]
+[(#ENV{champs_extra}|?{' '})
+[(#EXTRA**|extra_affichage)]
+]
+</BOUCLE_afficher_contenu>
\ No newline at end of file
diff --git a/dist/prive/contenu/rubrique.html b/dist/prive/contenu/rubrique.html
new file mode 100644
index 0000000000..b666522f20
--- /dev/null
+++ b/dist/prive/contenu/rubrique.html
@@ -0,0 +1,21 @@
+<BOUCLE_afficher_contenu(RUBRIQUES){id_rubrique=#ENV{id}}{statut?}>
+<span class="champ contenu_titre[ (#TITRE*|?{'',vide})]">
+<span class='label'><:info_titre:></span>
+<span dir='#LANG_DIR' class='#EDIT{titre} titre'>#TITRE</span>
+</span>
+<span class="champ contenu_descriptif[ (#DESCRIPTIF*|?{'',vide})]">
+<span class='label'><:info_descriptif:></span>
+<span dir='#LANG_DIR' class='#EDIT{descriptif} descriptif'>#DESCRIPTIF</span>
+</span>
+<span class="champ contenu_texte[ (#TEXTE*|?{'',vide})]">
+<span class='label'><:info_texte:></span>
+<span dir='#LANG_DIR' class='#EDIT{texte} texte'>#TEXTE</span>
+</span>
+[<span class="champ contenu_notes">
+<span class='label'><:info_notes:></span>
+<span dir='#LANG_DIR' class='#EDIT{notes} notes'>(#NOTES)</span>
+</span>]
+[(#ENV{champs_extra}|?{' '})
+[(#EXTRA**|extra_affichage)]
+]
+</BOUCLE_afficher_contenu>
\ No newline at end of file
diff --git a/dist/prive/contenu/site.html b/dist/prive/contenu/site.html
new file mode 100644
index 0000000000..66a9a8311a
--- /dev/null
+++ b/dist/prive/contenu/site.html
@@ -0,0 +1,17 @@
+<BOUCLE_afficher_contenu(SYNDIC){id_syndic=#ENV{id}}{statut?}>
+<span class="champ contenu_nom_site[ (#NOM_SITE*|?{'',vide})]">
+<span class='label'><:form_prop_nom_site:></span>
+<span dir='#LANG_DIR' class='#EDIT{hyperlien} nom_site'><a href='#URL_SITE'>#NOM_SITE</a></span>
+</span>
+<span class="champ contenu_descriptif[ (#DESCRIPTIF*|?{'',vide})]">
+<span class='label'><:info_descriptif:></span>
+<span dir='#LANG_DIR' class='#EDIT{descriptif} descriptif'>#DESCRIPTIF</span>
+</span>
+[<span class="champ contenu_notes">
+<span class='label'><:info_notes:></span>
+<span dir='#LANG_DIR' class='#EDIT{notes} notes'>(#NOTES)</span>
+</span>]
+[(#ENV{champs_extra}|?{' '})
+[(#EXTRA**|extra_affichage)]
+]
+</BOUCLE_afficher_contenu>
\ No newline at end of file
diff --git a/ecrire/inc/afficher_contenu_objet.php b/ecrire/inc/afficher_contenu_objet.php
index 2b7762ee82..4282fea735 100644
--- a/ecrire/inc/afficher_contenu_objet.php
+++ b/ecrire/inc/afficher_contenu_objet.php
@@ -13,93 +13,14 @@
 // affichage du contenu d'un objet spip (onglet contenu)
 // Cas generique, utilise pour tous les objets
 // http://doc.spip.org/@inc_afficher_contenu_objet_dist
-function inc_afficher_contenu_objet_dist($type, $id,$row = NULL){
-	$table = table_objet($type);
-	$key = id_table_objet($type);
-	if (!$row) {
-		$res = sql_select(array('*'),array("spip_$table"),array("$key=".sql_quote($id)));
-		$row = sql_fetch($res);
-	}
-	if (!$row) return "";
-
-	if (isset($row['lang'])) {
-		changer_typo($row['lang']);
-	}
- 	$lang_dir = lang_dir($GLOBALS['lang_objet']);
-
-	// demander un englobant des champs=>libelles a afficher pour cet objet
-	$champs_libelles = pipeline(
-		'afficher_objet_champs_libelles',
-		array(
-			'data'=>afficher_objet_champs_libelles($type,$table,$id,$row),
-			'args'=>array('type'=>$type,$key=>$id)
-		)
-	);
-	
-	// ne considerer que les champs presents en base
-	foreach($champs_libelles as $champ=>$libelle)
-		if ($champ!='notes' && !isset($row[$champ]))
-			unset($champs_libelles[$champ]);
-	if (isset($champs_libelles['nom_site']))
-		unset($champs_libelles['url_site']);
-	if (isset($champs_libelles['lien_titre']))
-		unset($champs_libelles['lien_url']);
-
-	/* TODO, mais il manque encore des concepts comme la boucle FOR pour y arriver
-	$contexte = array($key=>$id,'type'=>$type,'valeurs'=>$row, 'champs'=>$champs_libelles);
-	include_spip('inc/assembler');
-	$contenu_objet = recuperer_fond('prive/afficher_contenu_objet',$contexte);*/
-	
-	global  $table_des_traitements;
-	include_spip('public/interfaces');
-	// afficher chaque champ
-	// lui appliquer le traitement public
-	$contenu_objet = '';
-	foreach($champs_libelles as $champ=>$libelle) {
-		if ($champ!='notes') {
-			$valeur = $row[$champ];
-		}
-		else $valeur = $GLOBALS['les_notes'];
-		if (($champ=='nom_site') && isset($row['url_site']) && $row['url_site']){
-			$valeur = "[" . ($valeur?$valeur:$row['url_site']) . " -> " . $row['url_site'] ."]";
-			$valeur = propre($valeur);
-		}
-		elseif (($champ=='lien_titre') && isset($row['lien_url']) && $row['lien_url']){
-			$valeur = "[" . ($valeur?$valeur:$row['lien_titre']) . " -> " . $row['lien_url'] ."]";
-			$valeur = propre($valeur);
-		}
-		else {
-			$balise = strtoupper($champ);
-			if (isset($table_des_traitements[$balise])) {
-				$filtre = isset($table_des_traitements[$balise][$table])
-					? $table_des_traitements[$balise][$table]
-					: $table_des_traitements[$balise][0];
-				$filtre = str_replace('%s','$valeur', $filtre);
-
-				# dans l'espace prive on veut afficher le rang
-				# (temporaire, en attendant un vrai champ rang ??)
-				$filtre = str_replace('supprimer_numero(','(', $filtre);
-				$connect = "";
-
-				$valeur = eval("return $filtre;");
-			}
-		}
-		if ($champ!='notes' OR strlen($valeur))
-			$contenu_objet .= 
-				"<span class='champ contenu_$champ" .(strlen($valeur)?"":" vide") . "'>"
-				. "<span class='label'>$libelle</span>"
-				. "<span  dir='$lang_dir' class='$champ crayon $type-$champ-$id'>$valeur</span>"
-				. "</span>";
-
-	}
-
-	// pas de squelette pour les champs extra (vieillissants)
-	if ($GLOBALS['champs_extra'] AND $row['extra']) {
+function inc_afficher_contenu_objet_dist($type, $id,$row = NULL){	
+	include_spip('public/assembler');
+	if ($GLOBALS['champs_extra'] AND $row['extra'])
 		include_spip('inc/extra');
-		$contenu_objet .= extra_affichage($row['extra'], $table);
-	}
+	$contexte = array('id'=>$id,'champs_extra'=>$GLOBALS['champs_extra']);
+	$contenu_objet .= recuperer_fond("prive/contenu/$type",$contexte);
 	
-	// permettre a un plugin de faire des modifs
+	// permettre aux plugin de faire des modifs ou des ajouts
 	$contenu_objet = pipeline(
 		'afficher_contenu_objet',
 		array(
@@ -111,39 +32,5 @@ function inc_afficher_contenu_objet_dist($type, $id,$row = NULL){
 	return "<div id='wysiwyg'>$contenu_objet</div>";
 }
 
-// donner la liste des champs a afficher dans l'espace prive
-// pour un objet
-// cette liste peut etre un englobant, les elements non pertinents pour l'objet considere seront enleves
-// http://doc.spip.org/@afficher_objet_champs_libelles
-function afficher_objet_champs_libelles($type,$table,$id, $row){
-	$liste = array(
-		'surtitre' => _T('texte_sur_titre'),
-		'titre' => _T('info_titre'),
-		'soustitre' => _T('texte_sous_titre'),
-		'descriptif' => _T('info_descriptif'),
-		'chapo' => _T('info_chapeau'),
-		'nom_site' => ($type=='site'?_T('form_prop_nom_site'):_T('lien_voir_en_ligne')),
-		'url_site' => ($type=='site'?_T('form_prop_nom_site'):_T('info_lien_hypertexte')),
-		'texte' => _T('info_texte'),
-		'lien_titre' => _T('lien_voir_en_ligne'),
-		'lien_url' => _T('info_lien_hypertexte'),
-		'ps' => _T('info_ps'),
-		'notes' => _T('info_notes')
-	);
-
-	// gerer les champs desactives sur option
-	foreach($liste as $champ => $x) {
-		if (isset($GLOBALS['meta'][$x = ($table . '_' . $champ)])
-			AND $GLOBALS['meta'][$x]=='non'
-			AND (!isset($row[$champ]) OR !strlen($row[$champ]))) {
-				unset($liste[$champ]);
-			}
-	}
-	
-	// TODO , gerer ici des eventuelles autorisation de voir via autoriser ...
-
-	return $liste;
-}
-	
 
-?>
+?>
\ No newline at end of file
-- 
GitLab