[SPIP] +2.1.12
[velocampus/web/www.git] / www / plugins / auto / couteau_suisse / couteau_suisse / outils / introduction_fonctions.php
1 <?php
2
3 @define('_INTRODUCTION_CODE', '@@CS_SUITE@@');
4
5 // compatibilite avec SPIP 1.92 et anterieurs
6 $GLOBALS['cs_couper_intro'] = 'couper_intro';
7 if (!defined('_SPIP19300')) {
8 $GLOBALS['cs_couper_intro'] = 'couper_intro2';
9 function couper_intro2($texte, $long, $suite) {
10 $texte = couper_intro($texte, $long);
11 $i = strpos($texte, '&nbsp;(...)');
12 if (strlen($texte) - $i == 11)
13 $texte = substr($texte, 0, $i) . _INTRODUCTION_CODE;
14 return $texte;
15 }
16 function chapo_redirigetil($chapo) { return $chapo && $chapo[0] == '='; }
17 function objet_type($table_objet){ return preg_replace(',^spip_|s$,', '', $table_objet); }
18 }
19 // compatibilite avec SPIP 2.0 : la balise a fortement change !! >> TODO
20 // la fonction couper_intro a disparu.
21 // voir function filtre_introduction_dist
22 if (defined('_SPIP19300')) {
23 $GLOBALS['cs_couper_intro'] = 'couper_intro3';
24 function couper_intro3($texte, $long, $suite) {
25 $texte = extraire_multi(preg_replace(",(</?)intro>,i", "\\1intro>", $texte)); // minuscules
26 $intro = '';
27 while ($fin = strpos($texte, "</intro>")) {
28 $zone = substr($texte, 0, $fin);
29 $texte = substr($texte, $fin + strlen("</intro>"));
30 if ($deb = strpos($zone, "<intro>") OR substr($zone, 0, 7) == "<intro>")
31 $zone = substr($zone, $deb + 7);
32 $intro .= $zone;
33 }
34 $texte = nettoyer_raccourcis_typo($intro ? $intro : $texte);
35 return PtoBR(traiter_raccourcis(preg_replace(',([|]\s*)+,S', '; ', couper($texte, $long, _INTRODUCTION_CODE))));
36 }
37 }
38
39 function remplace_points_de_suite($texte, $id, $racc) {
40 if (strpos($texte, _INTRODUCTION_CODE) === false) return $texte;
41 // des points de suite bien propres
42 @define('_INTRODUCTION_SUITE', '&nbsp;(...)');
43 $intro_suite = cs_propre(_INTRODUCTION_SUITE);
44 // si les points de suite sont cliquables
45 if ($id && _INTRODUCTION_LIEN == 1) {
46 $url = (defined('_SPIP19300') && test_espace_prive())
47 ?generer_url_entite_absolue($id, $racc, '', '', true):"$racc$id";
48 $intro_suite = strncmp($intro_suite, '<br />', 6)===0
49 ?'<br />'.cs_lien($url, substr($intro_suite, 6))
50 :'&nbsp;'.cs_lien($url, $intro_suite);
51 $intro_suite = inserer_attribut($intro_suite, 'class', extraire_attribut($intro_suite,'class') . ' pts_suite');
52 }
53 return str_replace(_INTRODUCTION_CODE, $intro_suite, $texte);
54 }
55
56 // lgr>0 : aucun parametre, donc lgr par defaut
57 // lgr<0 : parametre #INTRODUCTION{longeur}
58 // lgr=0 : pas possible
59 // TODO : $connect est pour SPIP 2.0
60 function cs_introduction($texte, $descriptif, $lgr, $id, $racc, $connect) {
61 @define('_INTRODUCTION_LGR', 100);
62 // fonction couper_intro
63 $couper = $GLOBALS['cs_couper_intro'];
64 if (strlen($descriptif))
65 # si descriptif contient juste des espaces ca produit une intro vide,
66 # c'est une fonctionnalite, pas un bug
67 // ici le descriptif est coupe s'il est trop long
68 $texte = $lgr<0?propre($couper($descriptif, -$lgr, _INTRODUCTION_CODE)):propre($descriptif);
69 else {
70 // pas de maths dans l'intro...
71 $texte = preg_replace(',<math>.*</math>,imsU', '', $texte);
72 // on coupe proprement...
73 $lgr = $lgr>0?round($lgr*_INTRODUCTION_LGR/100):-$lgr;
74 $texte = cs_propre(supprimer_tags($couper(cs_introduire($texte), $lgr, _INTRODUCTION_CODE)));
75 }
76 // si les points de suite ont ete ajoutes
77 return remplace_points_de_suite($texte, $id, $racc);
78 } // introduction()
79
80 if (!function_exists('balise_INTRODUCTION')) {
81 // #INTRODUCTION_SPIP (pour tests)
82 function balise_INTRODUCTION_SPIP($p) {
83 return balise_INTRODUCTION_dist($p);
84 }
85 include_spip('public/interfaces');
86 global $table_des_traitements;
87 // INTRODUCTION_SPIP est une INTRODUCTION !
88 if (!isset($table_des_traitements['INTRODUCTION_SPIP']))
89 $table_des_traitements['INTRODUCTION_SPIP'] = $table_des_traitements['INTRODUCTION'];
90 // #INTRODUCTION
91 function balise_INTRODUCTION($p) {
92 $type = $p->type_requete;
93 $_texte = champ_sql('texte', $p);
94 $_descriptif = "''";
95 $_id = 0;
96 $_lgr = "600";
97 switch ($type) {
98 case 'articles':
99 $_chapo = champ_sql('chapo', $p);
100 $_descriptif = champ_sql('descriptif', $p);
101 $_texte = "(strlen($_descriptif) OR chapo_redirigetil($_chapo)) ? '' : $_chapo . \"\\n\\n\" . $_texte";
102 $_lgr = "500";
103 break;
104 case 'rubriques':
105 $_descriptif = champ_sql('descriptif', $p);
106 break;
107 case 'breves':
108 $_lgr = "300";
109 break;
110 }
111 // longueur en parametre ?
112 if(($v = interprete_argument_balise(1,$p))!==NULL) $_lgr = "-intval($v)" ;
113 $_id = champ_sql(id_table_objet($racc = objet_type($type)), $p);
114 $p->code = "cs_introduction($_texte, $_descriptif, $_lgr, $_id, '$racc', \$connect)";
115 #$p->interdire_scripts = true;
116 $p->etoile = '*'; // propre est deja fait dans le calcul de l'intro
117 return $p;
118 }
119
120 } //!function_exists('balise_INTRODUCTION')
121 else spip_log("Erreur - balise_INTRODUCTION() existe deja et ne peut pas etre surchargee par le Couteau Suisse !");
122
123 ?>