From e9faef046f0927029f15ac282e85e8d39a22c03f Mon Sep 17 00:00:00 2001 From: Fil <fil@rezo.net> Date: Wed, 19 Sep 2007 07:34:53 +0000 Subject: [PATCH] retour exact au comportement precedent de #INTRODUCTION (ne pas couper le descriptif, longueurs de 500 pour les articles, 300 pour les breves etc) ; ajout d'un parametre de longueur : #INTRODUCTION{1000} --- ecrire/inc/texte.php | 2 +- ecrire/public/balises.php | 39 ++++++++++++++++++++++++++++-------- ecrire/public/composer.php | 25 ++++++++++++++--------- ecrire/public/interfaces.php | 1 + 4 files changed, 48 insertions(+), 19 deletions(-) diff --git a/ecrire/inc/texte.php b/ecrire/inc/texte.php index ea914dacd1..f5ca1603ce 100644 --- a/ecrire/inc/texte.php +++ b/ecrire/inc/texte.php @@ -337,7 +337,7 @@ function nettoyer_raccourcis_typo($texte, $connect=''){ // http://doc.spip.org/@couper function couper($texte, $taille=50, $suite = ' (...)') { - if (!strlen($texte)) return ''; + if (!strlen($texte) OR $taille <= 0) return ''; $offset = 400 + 2*$taille; if ( $offset<strlen($texte) && ($p_tag_ouvrant = strpos($texte,'<',$offset))!==NULL){ diff --git a/ecrire/public/balises.php b/ecrire/public/balises.php index 43f3726a3f..d5c2b5bfdb 100644 --- a/ecrire/public/balises.php +++ b/ecrire/public/balises.php @@ -387,22 +387,45 @@ function balise_SPIP_CRON_dist ($p) { // #INTRODUCTION +// #INTRODUCTION{longueur} // http://www.spip.net/@introduction // http://doc.spip.org/@balise_INTRODUCTION_dist -function balise_INTRODUCTION_dist ($p) { +function balise_INTRODUCTION_dist($p) { + $type = $p->type_requete; + $_texte = champ_sql('texte', $p); - if ($type != 'articles') { - $code = $_texte; - } else { + $_descriptif = "''"; + + if ($type == 'articles') { $_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)))"; + $_texte = "(strlen($_descriptif) OR chapo_redirigetil($_chapo)) + ? '' + : $_chapo . \"\\n\\n\" . $_texte"; } + + // longueur en parametre, ou valeur par defaut + if (($v = interprete_argument_balise(1,$p))!==NULL) { + $longueur = 'intval('.$v.')'; + } else { + switch ($type) { + case 'articles': + $longueur = '500'; + break; + case 'breves': + $longueur = '300'; + break; + case 'forums': + case 'rubriques': + default: + $longueur = '600'; + break; + } + } + $f = chercher_filtre('introduction'); - $p->code = "$f($code, '$type', \$connect)"; + $p->code = "$f($_descriptif, $_texte, $longueur, \$connect)"; #$p->interdire_scripts = true; return $p; diff --git a/ecrire/public/composer.php b/ecrire/public/composer.php index 7b47e77441..a5aa2a8f78 100644 --- a/ecrire/public/composer.php +++ b/ecrire/public/composer.php @@ -180,17 +180,22 @@ 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 ... +// function filtre_introduction() // @define('_INTRODUCTION_SUITE', ' (...)'); // http://doc.spip.org/@filtre_introduction_dist -function filtre_introduction_dist($texte, $type, $connect) { +function filtre_introduction_dist($descriptif, $texte, $longueur, $connect) { + // Si un descriptif est envoye, on l'utilise directement + if (strlen($descriptif)) + return $descriptif; -// prendre <intro>...</intro> sinon couper a la longueur demandee - - $texte = extraire_multi(preg_replace(",(</?)intro>,i", "\\1intro>", $texte)); // minuscules + // Prendre un extrait dans la bonne langue + $texte = extraire_multi($texte); + + // De preference ce qui est marque <intro>...</intro> $intro = ''; + $texte = preg_replace(",(</?)intro>,i", "\\1intro>", $texte); // minuscules while ($fin = strpos($texte, "</intro>")) { $zone = substr($texte, 0, $fin); $texte = substr($texte, $fin + strlen("</intro>")); @@ -199,12 +204,12 @@ function filtre_introduction_dist($texte, $type, $connect) { $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)))); + // On coupe + $texte = couper($texte, $longueur, _INTRODUCTION_SUITE); + + // on nettoie un peu car ce sera traite par traiter_raccourcis() + return preg_replace(',([|]\s*)+,S', '; ', $texte); } // diff --git a/ecrire/public/interfaces.php b/ecrire/public/interfaces.php index 9d4a2ad025..8d019c227b 100644 --- a/ecrire/public/interfaces.php +++ b/ecrire/public/interfaces.php @@ -284,6 +284,7 @@ $table_des_traitements['DATE_NOUVEAUTES'][]= 'vider_date(%s)'; $table_des_traitements['DATE_REDAC'][]= 'vider_date(%s)'; $table_des_traitements['DESCRIPTIF'][]= _TRAITEMENT_RACCOURCIS; $table_des_traitements['FICHIER']['documents']= 'get_spip_doc(%s)'; +$table_des_traitements['INTRODUCTION'][]= 'PtoBR(traiter_raccourcis(%s))'; $table_des_traitements['LIEN_TITRE'][]= _TRAITEMENT_TYPO; $table_des_traitements['LIEN_URL'][]= 'vider_url(%s)'; $table_des_traitements['MESSAGE'][]= _TRAITEMENT_RACCOURCIS; -- GitLab