[SPIP] +spip v3.0.17
[lhc/web/clavette_www.git] / www / plugins-dist / textwheel / wheels / spip / spip-listes.php
1 <?php
2
3 if (!defined('_ECRIRE_INC_VERSION')) return;
4 # not useful as this file is included by the engine itself
5 # require_once 'engine/textwheel.php';
6
7 function tw_liste_init($t){
8 charger_fonction('dummy', 'inc', true); // ne sert a rien mais evite un segmentation fault PHP, on dirait
9 return tw_liste_item($t,'init');
10 }
11
12 function tw_liste_close($t){
13 return tw_liste_item($t,'close');
14 }
15
16 function tw_liste_item($t,$quoi='item'){
17 global $class_spip, $class_spip_plus;
18 static $niveau;
19 static $pile_li;
20 static $pile_type;
21 static $type;
22
23 switch ($quoi){
24 case 'init':
25 $niveau = 0;
26 $pile_li = array();
27 $pile_type = array();
28 $type = '';
29 break;
30 case 'close':
31 // retour sur terre
32 $ajout = '';
33 while ($niveau > 0) {
34 $ajout .= $pile_li[$niveau];
35 $ajout .= $pile_type[$niveau];
36 $niveau --;
37 }
38 $t .= $ajout;
39 break;
40
41 case 'ul':
42 case 'ol':
43 $nouv_type = $quoi;
44 break;
45
46 case 'item':
47 default:
48 $profond = 0;
49 if ($l=strlen($t[2])) {
50 $profond=$l;$nouv_type='ul';
51 if (strncmp($t[2],'#',1)==0) $nouv_type='ol';
52 }
53
54 if ($profond > 0) {
55 $ajout='';
56
57 // changement de type de liste au meme niveau : il faut
58 // descendre un niveau plus bas, fermer ce niveau, et
59 // remonter
60 $change_type = ($type AND ($type <> $nouv_type) AND ($profond == $niveau)) ? 1 : 0;
61 $type = $nouv_type;
62
63 // d'abord traiter les descentes
64 while ($niveau > $profond - $change_type) {
65 $ajout .= $pile_li[$niveau];
66 $ajout .= $pile_type[$niveau];
67 if (!$change_type)
68 unset ($pile_li[$niveau]);
69 $niveau --;
70 }
71
72 // puis les identites (y compris en fin de descente)
73 if ($niveau == $profond && !$change_type) {
74 $ajout .= $pile_li[$niveau];
75 }
76
77 // puis les montees (y compris apres une descente un cran trop bas)
78 while ($niveau < $profond) {
79 if ($niveau == 0)
80 $ajout .= "\n\n";
81 elseif (!isset($pile_li[$niveau])) {
82 $ajout .= "<li$class_spip>";
83 $pile_li[$niveau] = "</li>";
84 }
85 $niveau ++;
86 $ajout .= "<$type$class_spip_plus>";
87 $pile_type[$niveau] = "</$type>";
88 }
89
90 $ajout .= "<li$class_spip>";
91 $pile_li[$profond] = "</li>";
92 }
93 else {
94 $ajout = $t[1]; // puce normale ou <hr>
95 }
96
97 $t = $ajout . $t[3];
98 break;
99 }
100
101 return $t;
102 }
103
104 function tw_def_wrap($t){
105 global $class_spip_plus;
106 return "<dl$class_spip_plus>\n$t</dl>\n";
107 }