From 3a88e6cd4254d10193f81b167fd89708c2d99cc6 Mon Sep 17 00:00:00 2001
From: "Committo,Ergo:sum" <esj@rezo.net>
Date: Mon, 17 Sep 2007 22:43:30 +0000
Subject: [PATCH] =?UTF-8?q?Multi-base:=20r=C3=A9=C3=A9criture=20de=20la=20?=
 =?UTF-8?q?balise=20'''#INTRODUCTION'''=20afin=20qu'elle=20traite=20correc?=
 =?UTF-8?q?tement=20les=20raccourcis=20lorsqu'appliqu=C3=A9e=20sur=20une?=
 =?UTF-8?q?=20base=20externe.=20Attention,=20on=20a=20d=C3=BB=20changer=20?=
 =?UTF-8?q?le=20code=20compil=C3=A9=20en=20profondeur:=20le=20r=C3=A9sulta?=
 =?UTF-8?q?t=20typographique=20standard=20est=20le=20m=C3=AAme=20sauf=20er?=
 =?UTF-8?q?reur,=20{{{=20chercher=5Ffiltre=20}}}=20est=20toujours=20appliq?=
 =?UTF-8?q?u=C3=A9=20sur=20{{{introduction}}}=20mais=20les=20arguments=20t?=
 =?UTF-8?q?ransmis=20ne=20sont=20plus=20les=20m=C3=AAmes=20et=20la=20d?=
 =?UTF-8?q?=C3=A9finition=20standard=20de=20=20=20'''filtre=5Fintroduction?=
 =?UTF-8?q?''''=20a=20chang=C3=A9.=20En=20gros,=20l'esentiel=20de=20l'anci?=
 =?UTF-8?q?enne=20d=C3=A9finition=20est=20=C3=A0=20pr=C3=A9sent=20dans=20l?=
 =?UTF-8?q?e=20code=20compil=C3=A9,=20et=20la=20nouvelle=20d=C3=A9finition?=
 =?UTF-8?q?=20est=20essentiellement=20{{{=20couper=5Fintroduction=20}}}?=
 =?UTF-8?q?=C2=A0qui=20disparait=20(elle=20n'avait=20d'ailleurs=20pas=20sa?=
 =?UTF-8?q?=20place=20dans=20texte.php=20qui=20n'est=20pas=20utilis=C3=A9?=
 =?UTF-8?q?=20seulement=20par=20le=20compilateur.?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 ecrire/inc/texte.php       | 32 ++++--------------------
 ecrire/public/balises.php  | 14 ++++++-----
 ecrire/public/composer.php | 50 +++++++++++++++++---------------------
 3 files changed, 35 insertions(+), 61 deletions(-)

diff --git a/ecrire/inc/texte.php b/ecrire/inc/texte.php
index 13e5489e2c..b047c11863 100644
--- a/ecrire/inc/texte.php
+++ b/ecrire/inc/texte.php
@@ -313,13 +313,13 @@ function echappe_retour_modeles($letexte)
 }
 
 // http://doc.spip.org/@nettoyer_raccourcis_typo
-function nettoyer_raccourcis_typo($texte){
+function nettoyer_raccourcis_typo($texte, $connect=''){
 	$texte = pipeline('nettoyer_raccourcis_typo',$texte);
 	// remplacer les liens
 	if (preg_match_all(',[[]([^][]*)->(>?)([^][]*)[]],S', $texte, $regs, PREG_SET_ORDER))
 		foreach ($regs as $reg) {
 			list ($titre,,)= traiter_raccourci_lien_atts($reg[1]);
-			$titre = calculer_url($reg[3], $titre, 'titre');
+			$titre = calculer_url($reg[3], $titre, 'titre', $connect);
 			$titre = corriger_typo(supprimer_tags($titre));
 			$texte = str_replace($reg[0], $titre, $texte);
 		}
@@ -405,30 +405,6 @@ function couper($texte, $taille=50, $suite = '&nbsp;(...)') {
 	return quote_amp(trim($texte)).$points;
 }
 
-// prendre <intro>...</intro> sinon couper a la longueur demandee
-// http://doc.spip.org/@couper_intro
-function couper_intro($texte, $long, $suite = '&nbsp;(...)') {
-	$texte = extraire_multi(preg_replace(",(</?)intro>,i", "\\1intro>", $texte)); // minuscules
-	$intro = '';
-	while ($fin = strpos($texte, "</intro>")) {
-		$zone = substr($texte, 0, $fin);
-		$texte = substr($texte, $fin + strlen("</intro>"));
-		if ($deb = strpos($zone, "<intro>") OR substr($zone, 0, 7) == "<intro>")
-			$zone = substr($zone, $deb + 7);
-		$intro .= $zone;
-	}
-
-	if ($intro)
-		$intro .= $suite;
-	else {
-		$intro = preg_replace(',([|]\s*)+,S', '; ', couper($texte, $long, $suite));
-	}
-
-	// supprimer un eventuel chapo redirecteur =http:/.....
-	return $intro;
-}
-
-
 //
 // Les elements de propre()
 //
@@ -634,7 +610,7 @@ function typer_raccourci ($lien) {
 
 // http://doc.spip.org/@calculer_url
 function calculer_url ($lien, $texte='', $pour='url', $connect='') {
-
+	include_spip('base/abstract_sql');
 	if ($match = typer_raccourci($lien)) {
 		@list($f,,$id,,$param,,$ancre) = $match;
 		$res = '';
@@ -1312,6 +1288,8 @@ function chapo_redirige($chapo, $url=false)
 	return !$url ? $m[3] : calculer_url($m[3]);
 }
 
+function chapo_redirigetil($chapo) { return $chapo[0] == '=';}
+
 // http://doc.spip.org/@traiter_poesie
 function traiter_poesie($letexte)
 {
diff --git a/ecrire/public/balises.php b/ecrire/public/balises.php
index 40be94afd9..a5518fb458 100644
--- a/ecrire/public/balises.php
+++ b/ecrire/public/balises.php
@@ -392,15 +392,17 @@ function balise_SPIP_CRON_dist ($p) {
 function balise_INTRODUCTION_dist ($p) {
 	$type = $p->type_requete;
 	$_texte = champ_sql('texte', $p);
-	if ($type == 'articles') {
-	  $_chapo = champ_sql('chapo', $p);
-	  $_descriptif =  champ_sql('descriptif', $p);
+	if ($type != 'articles') {
+		$code = $_texte;
 	} else {
-	  $_chapo = "''";
-	  $_descriptif =  "''";
+		$_chapo = champ_sql('chapo', $p);
+		$_descriptif =  champ_sql('descriptif', $p);
+		$code = "($_descriptif ? $_descriptif\n\t" .
+		": (chapo_redirigetil($_chapo) ? ''\n\t\t" .
+		": ($_chapo . \"\n\n\n\" . $_texte)))";
 	}
 	$f = chercher_filtre('introduction');
-	$p->code = $f."('$type', $_texte, $_chapo, $_descriptif)";
+	$p->code = "$f($code, '$type', \$connect)";
 
 	#$p->interdire_scripts = true;
 	return $p;
diff --git a/ecrire/public/composer.php b/ecrire/public/composer.php
index b6dac6faf4..7b47e77441 100644
--- a/ecrire/public/composer.php
+++ b/ecrire/public/composer.php
@@ -180,38 +180,32 @@ function calcule_logo($type, $onoff, $id, $id_rubrique, $flag_fichier) {
 //
 // fonction standard de calcul de la balise #INTRODUCTION
 // on peut la surcharger en definissant dans mes_fonctions :
-// function introduction($type,$texte,$chapo,$descriptif) {...}
+// function introduction ...
 //
+@define('_INTRODUCTION_SUITE', '&nbsp;(...)');
+
 // http://doc.spip.org/@filtre_introduction_dist
-function filtre_introduction_dist($type, $texte, $chapo='', $descriptif='') {
-	define('_INTRODUCTION_SUITE', '&nbsp;(...)');
-
-	switch ($type) {
-		case 'articles':
-			# si descriptif contient juste des espaces ca produit une intro vide, 
-			# c'est une fonctionnalite, pas un bug
-			if (strlen($descriptif))
-				return propre($descriptif);
-			else if (substr($chapo, 0, 1) == '=')	// article virtuel
-				return '';
-			else
-				return PtoBR(propre(supprimer_tags(couper_intro($chapo."\n\n\n".$texte, 500, _INTRODUCTION_SUITE))));
-			break;
-		case 'breves':
-			return PtoBR(propre(supprimer_tags(couper_intro($texte, 300, _INTRODUCTION_SUITE))));
-			break;
-		case 'forums':
-			return PtoBR(propre(supprimer_tags(couper_intro($texte, 600, _INTRODUCTION_SUITE))));
-			break;
-		case 'rubriques':
-			if (strlen($descriptif))
-				return propre($descriptif);
-			else
-				return PtoBR(propre(supprimer_tags(couper_intro($texte, 600, _INTRODUCTION_SUITE))));
-			break;
+function filtre_introduction_dist($texte, $type, $connect) {
+
+// prendre <intro>...</intro> sinon couper a la longueur demandee
+  
+	$texte = extraire_multi(preg_replace(",(</?)intro>,i", "\\1intro>", $texte)); // minuscules
+	$intro = '';
+	while ($fin = strpos($texte, "</intro>")) {
+		$zone = substr($texte, 0, $fin);
+		$texte = substr($texte, $fin + strlen("</intro>"));
+		if ($deb = strpos($zone, "<intro>") OR substr($zone, 0, 7) == "<intro>")
+			$zone = substr($zone, $deb + 7);
+		$intro .= $zone;
 	}
-}
+	$texte = nettoyer_raccourcis_typo($intro ? $intro : $texte);
+	$long =  $type=='articles' ? 600 : 300;
 
+	// il faudrait optimiser un peu le traitement des raccourcis
+	// (car traiter_raccourcis ne fait pas que ce qu'elle dit)
+	return PtoBR(traiter_raccourcis(preg_replace(',([|]\s*)+,S', '; ', 
+		couper($texte, $long, _INTRODUCTION_SUITE))));
+}
 
 //
 // Balises dynamiques
-- 
GitLab