[SPIP] +2.1.12
[velocampus/web/www.git] / www / plugins / auto / couteau_suisse / couteau_suisse / outils / blocs.php
1 <?php
2
3 /*
4 Cet outil 'blocs' permet aux redacteurs d'un site spip d'inclure des blocs visibles ou invisibles dans leurs textes
5 balises : <bloc></bloc> ou <invisible></invisible>, et <visible></visible>
6 le titre est obtenu en sautant deux lignes a l'interieur du bloc
7 Attention : seules les balises en minuscules sont reconnues.
8 */
9
10 @define('_BLOC_TITRE_H', 'h4');
11
12 // depliage/repliage - fonction de personnalisation des title a placer dans mes_fonctions.php
13 // function blocs_title($titre='', $corps='', $num='') {
14 // return array(_T('couteau:bloc_deplier'), _T('couteau:bloc_replier'));
15 // }
16
17 // liste des nouveaux raccourcis ajoutes par l'outil
18 // si cette fonction n'existe pas, le plugin cherche alors _T('couteauprive:un_outil:aide');
19 function blocs_raccourcis() {
20 return _T('couteauprive:blocs:aide');
21 }
22
23 function blocs_callback($matches) {
24 list($titre, $corps) = preg_split(',(\n\n|\r\n\r\n|\r\r),', trim($matches[3]), 2);
25 // pas de corps !
26 if(!strlen($corps = trim($corps))) {
27 $corps = $titre;
28 $titre = preg_replace(',[\n\r]+,s', ' ', couper(propre($titre), 30));
29 }
30 // pas d'intertitre !
31 $titre = preg_replace(',^{{{(.*)}}}$,', '$1', trim($titre));
32 if(!strlen($titre)) $titre = '???';
33 // un resume facultatif
34 if(preg_match(',<resume>(.*)</resume>\s?(.*)$,ms', $corps, $res))
35 { $corps = $res[2]; $res = $res[1]; } else $res = '';
36 // types de blocs : bloc|invisible|visible
37 if ($matches[1]=='visible' || defined('_CS_PRINT')) {
38 $h = $d = '';
39 $r = ' blocs_invisible blocs_slide';
40 } else {
41 $h = ' blocs_replie';
42 $d = ' blocs_invisible blocs_slide';
43 $r = '';
44 }
45
46 // blocs numerotes
47 $b = strlen($matches[2])?" cs_bloc$matches[2]":'';
48 // title
49 $title = function_exists('blocs_title')
50 ?"<div class='blocs_title blocs_invisible'>".join(_BLOC_TITLE_SEP, blocs_title($titre, $corps, $matches[2], $h<>'')).'</div>'
51 :''; // valeur par defaut geree en JS
52 return "<div class='cs_blocs$b'><"._BLOC_TITRE_H." class='blocs_titre$h blocs_click'><a href='javascript:;'>$titre</a></"._BLOC_TITRE_H.">"
53 .(strlen($res)?"<div class='blocs_resume$r'>\n$res\n</div>":"")
54 ."<div class='blocs_destination$d'>\n\n".blocs_rempl($corps)."\n\n</div>$title</div>";
55 }
56
57 // cette fonction n'est pas appelee dans les balises html : html|code|cadre|frame|script
58 function blocs_rempl($texte) {
59 if (strpos($texte, '<')===false) return $texte;
60 // balises blocs|visible|invisible : il faut un callback pour analyser l'interieur du texte
61 return preg_replace_callback(',<(bloc#?|visible#?|invisible#?|blocintertitre#?)([0-9]*)>(.*?)</\1\2>,ms', 'blocs_callback', $texte);
62 }
63
64 // fonction pipeline
65 function blocs_pre_typo($texte) {
66 if (strpos($texte, '<')===false) return $texte;
67 // on remplace apres echappement
68 return cs_echappe_balises('', 'blocs_rempl', $texte);
69 }
70
71 // 2 fonctions pour le plugin Porte Plume, s'il est present (SPIP>=2.0)
72 function blocs_CS_pre_charger($flux) {
73 $r = array(array(
74 "id" => 'blocs_bloc',
75 "name" => _T('couteau:pp_blocs_bloc'),
76 "className" => 'blocs_bloc',
77 "replaceWith" => "\n<bloc>"._T('couteau:pp_un_titre')."\n\n"._T('couteau:pp_votre_texte')."\n</bloc>\n",
78 "display" => true), array(
79 "id" => 'blocs_visible',
80 "name" => _T('couteau:pp_blocs_visible'),
81 "className" => 'blocs_visible',
82 "replaceWith" => "\n<visible>"._T('couteau:pp_un_titre')."\n\n"._T('couteau:pp_votre_texte')."\n</visible>\n",
83 "display" => true));
84 foreach(cs_pp_liste_barres('blocs') as $b)
85 $flux[$b] = isset($flux[$b])?array_merge($flux[$b], $r):$r;
86 return $flux;
87 }
88 function blocs_PP_icones($flux) {
89 $flux['blocs_bloc'] = 'bloc_invisible.png';
90 $flux['blocs_visible'] = 'bloc_visible.png';
91 return $flux;
92 }
93
94 ?>